I implemented a second-level cache with the use of HazelCast with Kubernates.
My configuration of the property file is below.
...
Spring:
jpa:
hibernate:
ddl-auto: none
properties:
hibernate:
cache:
region:
factory_class: com.hazelcast.hibernate.HazelcastCacheRegionFactory
use_second_level_cache: true
...
Hazelcast Configuration
...
#Configuration
#EnableCaching
public class HazelcastConfiguration {
#Autowired
private StaticConfig staticConfig;
#Bean
public CacheManager cacheManager(HazelcastInstance hazelcastInstance) {
return new HazelcastCacheManager(hazelcastInstance);
}
#Bean
public HazelcastInstance hazelcastInstance(Config hazelCastConfig) {
return Hazelcast.newHazelcastInstance(hazelCastConfig);
}
#Bean
public Config hazelCastConfig() {
Config config = new Config();
config.setManagementCenterConfig(new ManagementCenterConfig());
JoinConfig joinConfig = config.getNetworkConfig().getJoin();
joinConfig.getKubernetesConfig().setEnabled(true).
setProperty(HazelcastConstants.NAMESPACE, staticConfig.getHazelcastNamespace())
.setProperty(HazelcastConstants.SERVICE_DNS, staticConfig.getHazelcastServiceDns());
// disable multicast config for demo
joinConfig.getMulticastConfig()
.setEnabled(false);
EvictionConfig evictionConfig = new EvictionConfig();
evictionConfig.setMaxSizePolicy(MaxSizePolicy.FREE_HEAP_SIZE);
evictionConfig.setSize(500);
MapConfig usersMapConfig = new MapConfig()
.setName(ApplicationConstants.CACHE_NAME)
.setTimeToLiveSeconds(Integer.parseInt(staticConfig.getCacheTimeToLive()))
.setEvictionConfig(evictionConfig);
config.addMapConfig(usersMapConfig);
return config;
}
}
...
Exception :
...
Sep 28, 2022 12:54:05 PM com.hazelcast.internal.server.tcp.TcpServerConnection
WARNING: [172.17.0.4]:5702 [dev] [4.1.5] Connection[id=148, /172.17.0.4:49607->/172.17.0.3:9191, qualifier=null, endpoint=[172.17.0.3]:9191, alive=false, connectionType=NONE, planeIndex=-1] closed. Reason: Exception in Connection[id=148, /172.17.0.4:49607->/172.17.0.3:9191, qualifier=null, endpoint=[172.17.0.3]:9191, alive=true, connectionType=NONE, planeIndex=-1], thread=hz.recursing_bhabha.IO.thread-in-2
java.lang.IllegalStateException: Unknown protocol: HTT
at com.hazelcast.internal.server.tcp.UnifiedProtocolDecoder.onRead(UnifiedProtocolDecoder.java:117)
at com.hazelcast.internal.networking.nio.NioInboundPipeline.process(NioInboundPipeline.java:137)
at com.hazelcast.internal.networking.nio.NioThread.processSelectionKey(NioThread.java:383)
at com.hazelcast.internal.networking.nio.NioThread.processSelectionKeys(NioThread.java:368)
at com.hazelcast.internal.networking.nio.NioThread.selectLoop(NioThread.java:294)
at com.hazelcast.internal.networking.nio.NioThread.executeRun(NioThread.java:249)
at com.hazelcast.internal.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:102)
Sep 28, 2022 12:54:05 PM com.hazelcast.internal.server.tcp.TcpServerConnection
WARNING: [172.17.0.4]:5702 [dev] [4.1.5] Connection[id=147, /172.17.0.4:35573->/172.17.0.2:9193, qualifier=null, endpoint=[172.17.0.2]:9193, alive=false, connectionType=NONE, planeIndex=-1] closed. Reason: Exception in Connection[id=147, /172.17.0.4:35573->/172.17.0.2:9193, qualifier=null, endpoint=[172.17.0.2]:9193, alive=true, connectionType=NONE, planeIndex=-1], thread=hz.recursing_bhabha.IO.thread-in-1
java.lang.IllegalStateException: Unknown protocol: HTT
at com.hazelcast.internal.server.tcp.UnifiedProtocolDecoder.onRead(UnifiedProtocolDecoder.java:117)
at com.hazelcast.internal.networking.nio.NioInboundPipeline.process(NioInboundPipeline.java:137)
at com.hazelcast.internal.networking.nio.NioThread.processSelectionKey(NioThread.java:383)
at com.hazelcast.internal.networking.nio.NioThread.processSelectionKeys(NioThread.java:368)
at com.hazelcast.internal.networking.nio.NioThread.selectLoop(NioThread.java:294)
at com.hazelcast.internal.networking.nio.NioThread.executeRun(NioThread.java:249)
at com.hazelcast.internal.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:102)
Sep 28, 2022 12:54:05 PM com.hazelcast.internal.server.tcp.TcpServerConnection
WARNING: [172.17.0.4]:5702 [dev] [4.1.5] Connection[id=149, /172.17.0.4:33017->/172.17.0.2:9193, qualifier=null, endpoint=[172.17.0.2]:9193, alive=false, connectionType=NONE, planeIndex=-1] closed. Reason: Exception in Connection[id=149, /172.17.0.4:33017->/172.17.0.2:9193, qualifier=null, endpoint=[172.17.0.2]:9193, alive=true, connectionType=NONE, planeIndex=-1], thread=hz.recursing_bhabha.IO.thread-in-0
java.lang.IllegalStateException: Unknown protocol: HTT
at com.hazelcast.internal.server.tcp.UnifiedProtocolDecoder.onRead(UnifiedProtocolDecoder.java:117)
at com.hazelcast.internal.networking.nio.NioInboundPipeline.process(NioInboundPipeline.java:137)
at com.hazelcast.internal.networking.nio.NioThread.processSelectionKey(NioThread.java:383)
at com.hazelcast.internal.networking.nio.NioThread.processSelectionKeys(NioThread.java:368)
at com.hazelcast.internal.networking.nio.NioThread.selectLoop(NioThread.java:294)
at com.hazelcast.internal.networking.nio.NioThread.executeRun(NioThread.java:249)
at com.hazelcast.internal.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:102)
Sep 28, 2022 12:54:05 PM com.hazelcast.internal.server.tcp.TcpServerConnection
WARNING: [172.17.0.4]:5702 [dev] [4.1.5] Connection[id=150, /172.17.0.4:59623->/172.17.0.3:9191, qualifier=null, endpoint=[172.17.0.3]:9191, alive=false, connectionType=NONE, planeIndex=-1] closed. Reason: Exception in Connection[id=150, /172.17.0.4:59623->/172.17.0.3:9191, qualifier=null, endpoint=[172.17.0.3]:9191, alive=true, connectionType=NONE, planeIndex=-1], thread=hz.recursing_bhabha.IO.thread-in-1
java.lang.IllegalStateException: Unknown protocol: HTT
at com.hazelcast.internal.server.tcp.UnifiedProtocolDecoder.onRead(UnifiedProtocolDecoder.java:117)
at com.hazelcast.internal.networking.nio.NioInboundPipeline.process(NioInboundPipeline.java:137)
at com.hazelcast.internal.networking.nio.NioThread.processSelectionKey(NioThread.java:383)
at com.hazelcast.internal.networking.nio.NioThread.processSelectionKeys(NioThread.java:368)
at com.hazelcast.internal.networking.nio.NioThread.selectLoop(NioThread.java:294)
at com.hazelcast.internal.networking.nio.NioThread.executeRun(NioThread.java:249)
at com.hazelcast.internal.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:102)
Please any one Help me Out of it
"Unknown protocol: HTT"
Looks like this issue
Using service-name should be your solution.
Also, you should upgrade from 4.1.5, the latest is 5.1.3.
Related
I'm trying to use the spring cloud Kafka streams binder(2.4.3) to consume and produce Avro messages. I'm able to consume the message and produce the records with a single function but I'm looking for a producer which I can use multiple times in the application. StreamBridge seems like an option for this and tried the below approach but it does not work, Did I missed anything
#Autowired
StreamBridge streamBridge;
#Bean
public Consumer<KStream<EventKey, Event>> process(){
return input -> {
input.peek((k,v) -> sendToValue(v)
);
};
}
private Event sendToValue(Event event){
System.out.println(Event);
streamBridge.send("process-out-0",event);
System.out.println("Message sent");
return touchpointEvent;
}
Binder:
spring:
application:
name: ${applicaton-name}
cloud:
stream:
function:
definition: process
bindings:
process-in-0:
destination: ${input-topic-name}
contentType: application/Avro
process-out-0:
destination: ${enriched-topic-name}
contentType: application/Avro
binding-retry-interval: 30
kafka:
streams:
binder:
brokers: ${kafka-broker}
application-id: ${consumer-group-name}
auto-create-topics: false
auto-add-partitions: false
configuration:
processing.guarantee: at_least_once
auto.offset.reset: earliest
schema.registry.url: ${kafka-schema-registry}
auto-register-schema: false
security.protocol: SSL
useNativeEncoding: true
specific.avro.reader: true
Error
[2021-03-16 21:51:52,219] [INFO] [latest-c8b6dd0c-b376-4cdd-a72d-17e97701d1d5-StreamThread-1] [o.s.c.s.b.DefaultBinderFactory DefaultBinderFactory.java:243] Creating binder: ktable
[2021-03-16 21:51:52,312] [INFO] [latest-c8b6dd0c-b376-4cdd-a72d-17e97701d1d5-StreamThread-1] [o.s.c.s.b.DefaultBinderFactory DefaultBinderFactory.java:343] Caching the binder: ktable
[2021-03-16 21:51:52,313] [INFO] [latest-c8b6dd0c-b376-4cdd-a72d-17e97701d1d5-StreamThread-1] [o.s.c.s.b.DefaultBinderFactory DefaultBinderFactory.java:347] Retrieving cached binder: ktable
[2021-03-16 21:51:52,313] [INFO] [latest-c8b6dd0c-b376-4cdd-a72d-17e97701d1d5-StreamThread-1] [o.s.c.s.b.DefaultBinderFactory DefaultBinderFactory.java:243] Creating binder: kafka
[2021-03-16 21:51:52,372] [WARN] [latest-c8b6dd0c-b376-4cdd-a72d-17e97701d1d5-StreamThread-1] [o.s.c.a.AnnotationConfigApplicationContext AbstractApplicationContext.java:559] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kafkaMessageChannelBinder' defined in org.springframework.cloud.stream.binder.kafka.config.KafkaBinderConfiguration: Unexpected exception during bean creation; nested exception is java.lang.NoClassDefFoundError: org/springframework/integration/support/management/ManageableLifecycle
[2021-03-16 21:51:52,374] [INFO] [latest-c8b6dd0c-b376-4cdd-a72d-17e97701d1d5-StreamThread-1] [o.s.b.a.l.ConditionEvaluationReportLoggingListener ConditionEvaluationReportLoggingListener.java:136]
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
[2021-03-16 21:51:52,379] [ERROR] [latest-c8b6dd0c-b376-4cdd-a72d-17e97701d1d5-StreamThread-1] [o.s.b.SpringApplication SpringApplication.java:837] Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kafkaMessageChannelBinder' defined in org.springframework.cloud.stream.binder.kafka.config.KafkaBinderConfiguration: Unexpected exception during bean creation; nested exception is java.lang.NoClassDefFoundError: org/springframework/integration/support/management/ManageableLifecycle
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
update with a version change:
[2021-03-17 09:56:28,043] [INFO] [latest-0ea7c0a5-21a4-464b-bf42-a5c35b6687dc-StreamThread-1] [o.a.k.c.u.AppInfoParser AppInfoParser.java:117] Kafka version: 6.0.1-ccs
[2021-03-17 09:56:28,043] [INFO] [latest-0ea7c0a5-21a4-464b-bf42-a5c35b6687dc-StreamThread-1] [o.a.k.c.u.AppInfoParser AppInfoParser.java:118] Kafka commitId: 9c1fbb3db1e0d69d
[2021-03-17 09:56:28,043] [INFO] [latest-0ea7c0a5-21a4-464b-bf42-a5c35b6687dc-StreamThread-1] [o.a.k.c.u.AppInfoParser AppInfoParser.java:119] Kafka startTimeMs: 1615992988043
[2021-03-17 09:56:28,047] [WARN] [kafka-admin-client-thread | adminclient-2] [o.a.k.c.NetworkClient NetworkClient.java:757] [AdminClient clientId=adminclient-2] Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.
[2021-03-17 09:56:28,151] [WARN] [kafka-admin-client-thread | adminclient-2] [o.a.k.c.NetworkClient NetworkClient.java:757] [AdminClient clientId=adminclient-2] Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.
[2021-03-17 09:56:28,357] [WARN] [kafka-admin-client-thread | adminclient-2] [o.a.k.c.NetworkClient NetworkClient.java:757] [AdminClient clientId=adminclient-2] Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.
[2021-03-17 09:56:28,568] [WARN] [kafka-admin-client-thread | adminclient-2] [o.a.k.c.NetworkClient NetworkClient.java:757] [AdminClient clientId=adminclient-2] Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.
[2021-03-17 09:56:28,987] [WARN] [kafka-admin-client-thread | adminclient-2] [o.a.k.c.NetworkClient NetworkClient.java:757] [AdminClient clientId=adminclient-2] Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.
java.lang.NoClassDefFoundError: org/springframework/integration/support/management/ManageableLifecycle
You have an older version of spring-integration-core on the class path - that class was added in 5.4.
When using Boot, you should never declare versions; let Boot bring in the right version using its dependency management feature.
Im using the below :
Java 8
microsoft-graph : 2.10.0
microsoft-graph-auth : 0.2.0
okhttp : 3.14.9
I want to fetch data from Intune using Microsoft Graph API, want to use proxy and also bypass SSL (for testing). As per documentation, i have used the OKHttpClient. Used the OkHttpClient for configuring the proxy, sslSocketFactory and hostnameVerifier but it is no working.
final ClientCredentialProvider authProvider = new ClientCredentialProvider(this.clientId, this.scopes, this.clientSecret, this.tenantId, NationalCloud.Global);
final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
#Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0] {};
}
#Override
public void checkServerTrusted(final X509Certificate[] arg0, final String arg1)
throws CertificateException {
}
#Override
public void checkClientTrusted(final X509Certificate[] arg0, final String arg1)
throws CertificateException {
}
} };
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
final OkHttpClient httpClient = HttpClients.createDefault(new ICoreAuthenticationProvider() {
#Override
public Request authenticateRequest(final Request request) {
return request;
}
}).newBuilder().proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(this.proxyHost, this.proxyPort)))
.sslSocketFactory(sslSocketFactory, (X509TrustManager) trustAllCerts[0]).hostnameVerifier(new HostnameVerifier() {
#Override
public boolean verify(final String arg0, final SSLSession arg1) {
return true;
}
}).build();
final IHttpProvider httpProvider = DefaultClientConfig.createWithAuthenticationProvider(authProvider)
.getHttpProvider(httpClient);
final IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider(authProvider)
.httpProvider(httpProvider).buildClient();
IUserCollectionPage page = graphClient.users().buildRequest().get();
I get the below errors:
org.apache.oltu.oauth2.common.exception.OAuthSystemException: java.net.UnknownHostException: login.microsoftonline.com
at org.apache.oltu.oauth2.client.URLConnectionClient.execute(URLConnectionClient.java:108)
at org.apache.oltu.oauth2.client.OAuthClient.accessToken(OAuthClient.java:65)
at org.apache.oltu.oauth2.client.OAuthClient.accessToken(OAuthClient.java:55)
at org.apache.oltu.oauth2.client.OAuthClient.accessToken(OAuthClient.java:71)
at com.microsoft.graph.auth.confidentialClient.ClientCredentialProvider.getAccessTokenNewRequest(ClientCredentialProvider.java:102)
at com.microsoft.graph.auth.confidentialClient.ClientCredentialProvider.getAcccessToken(ClientCredentialProvider.java:67)
at com.microsoft.graph.auth.confidentialClient.ClientCredentialProvider.authenticateRequest(ClientCredentialProvider.java:49)
at com.microsoft.graph.http.CoreHttpProvider.sendRequestInternal(CoreHttpProvider.java:395)
at com.microsoft.graph.http.CoreHttpProvider.send(CoreHttpProvider.java:220)
at com.microsoft.graph.http.CoreHttpProvider.send(CoreHttpProvider.java:200)
at com.microsoft.graph.http.BaseCollectionRequest.send(BaseCollectionRequest.java:92)
at com.microsoft.graph.requests.extensions.UserCollectionRequest.get(UserCollectionRequest.java:72)
at com.hsbc.gme.test.graph_test.App.main(App.java:114)
Caused by: java.net.UnknownHostException: login.microsoftonline.com
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1105)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:999)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1283)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1258)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
at org.apache.oltu.oauth2.client.URLConnectionClient.setRequestBody(URLConnectionClient.java:124)
at org.apache.oltu.oauth2.client.URLConnectionClient.execute(URLConnectionClient.java:91)
... 12 more
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220Graph service exception Error code: InvalidAuthenticationToken
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220Error message: CompactToken parsing failed with error code: 80049217
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220GET https://graph.microsoft.com/v1.0/users
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220SdkVersion : graph-java/v2.10.0
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220Authorization : [PII_REDACTED]
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220401 : Unauthorized
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220[...]
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220[Some information was truncated for brevity, enable debug logging for more details]
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: Throwable detail: com.microsoft.graph.http.GraphServiceException: Error code: InvalidAuthenticationToken
Error message: CompactToken parsing failed with error code: 80049217
GET https://graph.microsoft.com/v1.0/users
SdkVersion : graph-java/v2.10.0
Authorization : [PII_REDACTED]
401 : Unauthorized
[...]
[Some information was truncated for brevity, enable debug logging for more details]
Exception in thread "main" com.microsoft.graph.http.GraphServiceException: Error code: InvalidAuthenticationToken
Error message: CompactToken parsing failed with error code: 80049217
GET https://graph.microsoft.com/v1.0/users
SdkVersion : graph-java/v2.10.0
Authorization : [PII_REDACTED]
401 : Unauthorized
[...]
[Some information was truncated for brevity, enable debug logging for more details]
at com.microsoft.graph.http.GraphServiceException.createFromConnection(GraphServiceException.java:496)
at com.microsoft.graph.http.CoreHttpProvider.handleErrorResponse(CoreHttpProvider.java:503)
at com.microsoft.graph.http.CoreHttpProvider.sendRequestInternal(CoreHttpProvider.java:423)
at com.microsoft.graph.http.CoreHttpProvider.send(CoreHttpProvider.java:220)
at com.microsoft.graph.http.CoreHttpProvider.send(CoreHttpProvider.java:200)
at com.microsoft.graph.http.BaseCollectionRequest.send(BaseCollectionRequest.java:92)
at com.microsoft.graph.requests.extensions.UserCollectionRequest.get(UserCollectionRequest.java:72)
at com.hsbc.gme.test.graph_test.App.main(App.java:114)
Note : If i use https.proxyHost and https.proxyPort then the proxy works, however how can i make it working with the OkHttpClient. Also need a way to bypass SSL
I'm using hazelcast in my project and want to move hazelcast host:port information into environment variables. Before that I had default configuration that is:
<hazelcast-client xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hazelcast.com/schema/client-config
http://www.hazelcast.com/schema/client-config/hazelcast-client-config-3.8.xsd"
xmlns="http://www.hazelcast.com/schema/client-config">
<network>
<connection-timeout>3000</connection-timeout>
<connection-attempt-period>1000</connection-attempt-period>
<connection-attempt-limit>259200</connection-attempt-limit>
</network>
</hazelcast-client>
and I've found that there is possibility to add <cluster-members> tag inside <network> to provide custom <address> for hazelcast instances. I've modified my hazelcast.xml file into:
<network>
<cluster-members>
<address>${HAZELCAST_URL}</address>
</cluster-members>
...
But whenever I'm starting my app it shows:
2017-11-10 17:55:45 [service,,,] WARN c.h.c.s.i.ClusterListenerSupport hz.client_0 [dev] [3.8.5] Exception during initial connection to ${HAZELCAST_URL}:5701, exception java.lang.IllegalArgumentException: Can't resolve address: ${HAZELCAST_URL}:5701
2017-11-10 17:55:45 [service,,,] WARN c.h.c.s.i.ClusterListenerSupport hz.client_0 [dev] [3.8.5] Exception during initial connection to ${HAZELCAST_URL}:5702, exception java.lang.IllegalArgumentException: Can't resolve address: ${HAZELCAST_URL}:5702
It means it still tries to connect to default port and variable is not resolved. Is there a way to configure it?
You can pass java.util.Properties into the client config builder. All you need do is build it from Spring's environment.
#Bean
public ClientConfig clientConfig(Environment environment) throws Exception {
Properties properties = new Properties();
String HAZELCAST_URL = "HAZELCAST_URL";
properties.put(HAZELCAST_URL, environment.getProperty(HAZELCAST_URL));
XmlClientConfigBuilder xmlClientConfigBuilder = new XmlClientConfigBuilder("hazelcast-client.xml");
xmlClientConfigBuilder.setProperties(properties);
return xmlClientConfigBuilder.build();
}
#Bean
public HazelcastInstance hazelcastInstance(ClientConfig clientConfig) {
return HazelcastClient.newHazelcastClient(clientConfig);
}
Note, there are more elegant ways to do this, the above is just one solution keeping it as simple as possible
I am new to jersey multi part. While i am starting the tomcat server getting issue.
#POST
#Path("/uploadImagesUsingJersey")
#Consumes(MediaType.MULTIPART_FORM_DATA)
#Produces("text/plain")
public Response uploadImages(#FormDataParam("file") InputStream uploadedInputStream,
#FormDataParam("file") FormDataContentDisposition fileDetail) throws IOException{
String uploadedFileLocation = (String) session.getServletContext().getAttribute("ProfilePhotoPath");
uploadedFileLocation=uploadedFileLocation+236+"/"+fileDetail.getName();
writeToFile(uploadedInputStream, uploadedFileLocation);
String output = "File uploaded to : " + uploadedFileLocation;
employeeVO=new EmployeeInformationVO();
employeeVO=(EmployeeInformationVO) CacheAction.getById(EmployeeInformationVO.class,236);
employeeVO.setPhotoPath(236+"/"+fileDetail.getFileName());
int result=CacheAction.commonAddOrUpdate(employeeVO);
return Response.status(200).entity(result).build();
}
I am using this kind Of jar:
1)jersey-multipart-1.8-ea03.jar
2)mimepull-1.8-sources.jar
3)jersey-server-1.8.jar
4)jersey-bundle-1.8.jar
And i am getting this kind of issue:
INFO: Provider classes found:
class com.owlike.genson.ext.jaxrs.GensonJsonConverter
Nov 13, 2016 10:45:15 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.8 06/24/2011 12:39 PM'
Nov 13, 2016 10:45:17 PM com.sun.jersey.spi.inject.Errors processErrorMessages
SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
SEVERE: Missing dependency for method public javax.ws.rs.core.Response com.hrm.jersey.action.MyServiceAction.uploadImages(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition) throws java.io.IOException at parameter at index 0
SEVERE: Missing dependency for method public javax.ws.rs.core.Response com.hrm.jersey.action.MyServiceAction.uploadImages(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition) throws java.io.IOException at parameter at index 1
SEVERE: Method, public javax.ws.rs.core.Response com.hrm.jersey.action.MyServiceAction.uploadImages(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition) throws java.io.IOException, annotated with POST of resource, class com.hrm.jersey.action.MyServiceAction, is not recognized as valid resource method.
Nov 13, 2016 10:45:17 PM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
com.sun.jersey.spi.inject.Errors$ErrorMessagesException
I am trying to implement Spring integration with MQTT. I am using Mosquitto as MQTT broker. with the reference to docs provided in the following link. I have created a project and added all the required jar files. when i execute MQTTJavaApplication.
public class MqttJavaApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(MqttJavaApplication.class)
.web(false)
.run(args);
}
#Bean
public MessageChannel mqttInputChannel() {
return new DirectChannel();
}
#Bean
public MqttPahoMessageDrivenChannelAdapter inbound() {
MqttPahoMessageDrivenChannelAdapter adapter =
new MqttPahoMessageDrivenChannelAdapter("tcp://localhost:1883", "test",
"sample");
adapter.setCompletionTimeout(5000);
adapter.setConverter(new DefaultPahoMessageConverter());
adapter.setQos(1);
adapter.setOutputChannel(mqttInputChannel());
return adapter;
}
#Bean
#ServiceActivator(inputChannel = "mqttInputChannel")
public MessageHandler handler() {
return new MessageHandler() {
#Override
public void handleMessage(Message<?> message) {
System.out.println("Test##########"+message.getPayload());
}
};
}
}
I am getting following error when i publish a message via MQTT broker.
[2015-11-23 10:08:19.545] boot - 8100 INFO [main] --- AnnotationConfigApplicationContext: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#2d0e1c: startup date [Mon Nov 23 10:08:19 IST 2015]; root of context hierarchy
[2015-11-23 10:08:19.831] boot - 8100 INFO [main] --- PropertiesFactoryBean: Loading properties file from URL [jar:file:/D:/IoTWorkspace/MQTTTest/WebContent/WEB-INF/lib/spring-integration-core-4.2.1.RELEASE.jar!/META-INF/spring.integration.default.properties]
[2015-11-23 10:08:20.001] boot - 8100 INFO [main] --- DefaultLifecycleProcessor: Starting beans in phase 1073741823
[2015-11-23 10:08:20.104] boot - 8100 INFO [main] --- MqttPahoMessageDrivenChannelAdapter: started inbound
[2015-11-23 10:08:20.112] boot - 8100 INFO [main] --- MqttJavaApplication: Started MqttJavaApplication in 1.602 seconds (JVM running for 2.155)
[2015-11-23 10:13:04.564] boot - 8100 ERROR [MQTT Call: test] --- MqttPahoMessageDrivenChannelAdapter: Unhandled exception for GenericMessage [payload=Testing Subscription, headers={timestamp=1448253784563, id=cd5be974-3b19-8317-47eb-1c139725be24, mqtt_qos=0, mqtt_topic=sample, mqtt_retained=false, mqtt_duplicate=false}]
org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'unknown.channel.name'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:81)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:442)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:392)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:45)
at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:105)
at org.springframework.integration.endpoint.MessageProducerSupport.sendMessage(MessageProducerSupport.java:105)
at org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter.messageArrived(MqttPahoMessageDrivenChannelAdapter.java:262)
at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:336)
at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:148)
at java.lang.Thread.run(Thread.java:722)
Caused by: org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:153)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:120)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
... 10 more
[2015-11-23 10:13:04.613] boot - 8100 ERROR [MQTT Call: test] --- MqttPahoMessageDrivenChannelAdapter: Lost connection:MqttException; retrying...
[2015-11-23 10:13:04.614] boot - 8100 ERROR [MQTT Call: test] --- MqttPahoMessageDrivenChannelAdapter: Failed to schedule reconnect
java.lang.NullPointerException
at org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter.scheduleReconnect(MqttPahoMessageDrivenChannelAdapter.java:228)
at org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter.connectionLost(MqttPahoMessageDrivenChannelAdapter.java:255)
at org.eclipse.paho.client.mqttv3.internal.CommsCallback.connectionLost(CommsCallback.java:229)
at org.eclipse.paho.client.mqttv3.internal.ClientComms.shutdownConnection(ClientComms.java:339)
at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:171)
at java.lang.Thread.run(Thread.java:722)
[2015-11-23 10:13:04.617] boot - 8100 INFO [Thread-0] --- AnnotationConfigApplicationContext: Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#2d0e1c: startup date [Mon Nov 23 10:08:19 IST 2015]; root of context hierarchy
[2015-11-23 10:13:04.619] boot - 8100 INFO [Thread-0] --- DefaultLifecycleProcessor: Stopping beans in phase 1073741823
[2015-11-23 10:13:04.622] boot - 8100 ERROR [Thread-0] --- MqttPahoMessageDrivenChannelAdapter: Exception while unsubscribing
Client is not connected (32104)
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:27)
at org.eclipse.paho.client.mqttv3.internal.ClientComms.sendNoWait(ClientComms.java:132)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.unsubscribe(MqttAsyncClient.java:707)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.unsubscribe(MqttAsyncClient.java:682)
at org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter.doStop(MqttPahoMessageDrivenChannelAdapter.java:124)
at org.springframework.integration.endpoint.AbstractEndpoint.doStop(AbstractEndpoint.java:145)
at org.springframework.integration.endpoint.AbstractEndpoint.stop(AbstractEndpoint.java:128)
at org.springframework.context.support.DefaultLifecycleProcessor.doStop(DefaultLifecycleProcessor.java:229)
at org.springframework.context.support.DefaultLifecycleProcessor.access$300(DefaultLifecycleProcessor.java:51)
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.stop(DefaultLifecycleProcessor.java:363)
at org.springframework.context.support.DefaultLifecycleProcessor.stopBeans(DefaultLifecycleProcessor.java:202)
at org.springframework.context.support.DefaultLifecycleProcessor.onClose(DefaultLifecycleProcessor.java:118)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:966)
at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:893)
[2015-11-23 10:13:04.623] boot - 8100 ERROR [Thread-0] --- MqttPahoMessageDrivenChannelAdapter: Exception while disconnecting
Client is disconnected (32101)
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:27)
at org.eclipse.paho.client.mqttv3.internal.ClientComms.disconnect(ClientComms.java:405)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.disconnect(MqttAsyncClient.java:524)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.disconnect(MqttAsyncClient.java:493)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.disconnect(MqttAsyncClient.java:500)
at org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter.doStop(MqttPahoMessageDrivenChannelAdapter.java:131)
at org.springframework.integration.endpoint.AbstractEndpoint.doStop(AbstractEndpoint.java:145)
at org.springframework.integration.endpoint.AbstractEndpoint.stop(AbstractEndpoint.java:128)
at org.springframework.context.support.DefaultLifecycleProcessor.doStop(DefaultLifecycleProcessor.java:229)
at org.springframework.context.support.DefaultLifecycleProcessor.access$300(DefaultLifecycleProcessor.java:51)
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.stop(DefaultLifecycleProcessor.java:363)
at org.springframework.context.support.DefaultLifecycleProcessor.stopBeans(DefaultLifecycleProcessor.java:202)
at org.springframework.context.support.DefaultLifecycleProcessor.onClose(DefaultLifecycleProcessor.java:118)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:966)
at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:893)
[2015-11-23 10:13:04.624] boot - 8100 INFO [Thread-0] --- MqttPahoMessageDrivenChannelAdapter: stopped inbound
Please find below stack trace after adding #SpringBootApplication Annotation
[2015-11-26 10:55:46.571] boot - 5524 INFO [main] --- AnnotationConfigApplicationContext: Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#562d4b: startup date [Thu Nov 26 10:55:46 IST 2015]; root of context hierarchy
[2015-11-26 10:55:46.572] boot - 5524 WARN [main] --- AnnotationConfigApplicationContext: Exception thrown from ApplicationListener handling ContextClosedEvent
java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.context.annotation.AnnotationConfigApplicationContext#562d4b: startup date [Thu Nov 26 10:55:46 IST 2015]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:337)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:324)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1025)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:988)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:329)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:130)
at com.igate.MqttJavaApplication.main(MqttJavaApplication.java:32)
[2015-11-26 10:55:46.594] boot - 5524 WARN [main] --- AnnotationConfigApplicationContext: Exception thrown from LifecycleProcessor on context close
java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: org.springframework.context.annotation.AnnotationConfigApplicationContext#562d4b: startup date [Thu Nov 26 10:55:46 IST 2015]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:350)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1033)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:988)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:329)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:130)
at com.igate.MqttJavaApplication.main(MqttJavaApplication.java:32)
Exception in thread "main" java.lang.IllegalStateException: At least one base package must be specified
at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:121)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:214)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:149)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:135)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:260)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:203)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:617)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:446)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:648)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:311)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:130)
at com.igate.MqttJavaApplication.main(MqttJavaApplication.java:32)
Yep! That's true. Without #SpringBootApplication I have the same StackTrace.
The Spring Boot stuff includes IntegrationAutoConfiguration who is responsible for subscribers and TaskScheduler bean population.
Probably too late to answer but hope it might help some beginner.
Few Things:-
Declare #SpringBootApplication in your main class to let the project know its a spring boot application
For the 2nd Error, Define base package of the project where spring boot will refer for configuration files etc. To do so, add #ComponentScan({"package-name"}) at class level.
Sample Example:-
#SpringBootApplication
#ComponentScan({"package-name"})
public class Main {
...
}