I am trying to use the distributed executor service for hazelcast 3.1 and find that i am unable to use submitToMember(task,member). In my example below 10.69.108.60 is my local machine and 170.194.100.111 is my remote machine. I am able to get return value in my future when the member is my local machine but gives me a TargetNotAMemberException if the member is remote machine.
Below is the code
public class DistExecutionTest {
public static void main(String args[]){
DistributedExecutor dex = new DistributedExecutor();
try {
Member member = new MemberImpl(new Address("170.194.100.111",5701), false );
String msg;
msg = dex.echoOnTheMember("Hey youuuu!", member);
System.out.println(msg);
} catch (UnknownHostException e1) {
e1.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}
}
}
and
public class DistributedExecutor {
Config config;
NetworkConfig network;
JoinConfig join;
DistributedExecutor(){
config = new Config();
network = config.getNetworkConfig();
// network.setPort(5701);
join = network.getJoin();
join.getMulticastConfig().setEnabled(false);
join.getTcpIpConfig().addMember("170.194.100.111").addMember("10.69.108.60").setEnabled(true);
network.getInterfaces().setEnabled(true).addInterface("170.194.100.*").addInterface("10.69.108.*");
}
public String echoOnTheMember(String input, Member member) throws Exception {
Callable<String> task = new DistObject(input);
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
IExecutorService executorService = hz.getExecutorService("default");
Future<String> future = executorService.submitToMember(task, member);
String distObjectResult = future.get();
return distObjectResult;
}
}
and
public class Echo implements Callable<String>, Serializable, HazelcastInstanceAware {
private static final long serialVersionUID = -3164053990811643392L;
String message = null;
transient HazelcastInstance localInstance;
public Echo(String msg){
message = msg;
}
#Override
public String call() throws Exception {
return localInstance.toString() + message;
}
#Override
public void setHazelcastInstance(HazelcastInstance hazelcastInstance) {
this.localInstance = hazelcastInstance;
}
}
Here is the logging on local machine
Dec 17, 2013 1:03:20 PM com.hazelcast.instance.DefaultAddressPicker
INFO: Interfaces is enabled, trying to pick one address matching to one of: [162.124.194.*, 10.38.148.*]
Dec 17, 2013 1:03:20 PM com.hazelcast.instance.DefaultAddressPicker
INFO: Prefer IPv4 stack is true.
Dec 17, 2013 1:03:20 PM com.hazelcast.instance.DefaultAddressPicker
INFO: Picked Address[10.69.108.60]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
Dec 17, 2013 1:03:21 PM com.hazelcast.system
INFO: [10.69.108.60]:5701 [dev] Hazelcast Community Edition 3.1 (20131011) starting at Address[10.69.108.60]:5701
Dec 17, 2013 1:03:21 PM com.hazelcast.system
INFO: [10.69.108.60]:5701 [dev] Copyright (C) 2008-2013 Hazelcast.com
Dec 17, 2013 1:03:21 PM com.hazelcast.instance.Node
INFO: [10.69.108.60]:5701 [dev] Creating TcpIpJoiner
Dec 17, 2013 1:03:21 PM com.hazelcast.core.LifecycleService
INFO: [10.69.108.60]:5701 [dev] Address[10.69.108.60]:5701 is STARTING
Dec 17, 2013 1:03:21 PM com.hazelcast.cluster.TcpIpJoiner
INFO: [10.69.108.60]:5701 [dev] Connecting to possible member: Address[10.69.108.60]:5703
Dec 17, 2013 1:03:21 PM com.hazelcast.cluster.TcpIpJoiner
INFO: [10.69.108.60]:5701 [dev] Connecting to possible member: Address[10.69.108.60]:5702
Dec 17, 2013 1:03:21 PM com.hazelcast.nio.SocketConnector
INFO: [10.69.108.60]:5701 [dev] Connecting to /10.69.108.60:5703, timeout: 0, bind-any: true
Dec 17, 2013 1:03:21 PM com.hazelcast.nio.SocketConnector
INFO: [10.69.108.60]:5701 [dev] Connecting to /10.69.108.60:5702, timeout: 0, bind-any: true
Dec 17, 2013 1:03:21 PM com.hazelcast.cluster.TcpIpJoiner
INFO: [10.69.108.60]:5701 [dev] Connecting to possible member: Address[170.194.100.111]:5703
Dec 17, 2013 1:03:21 PM com.hazelcast.cluster.TcpIpJoiner
INFO: [10.69.108.60]:5701 [dev] Connecting to possible member: Address[170.194.100.111]:5702
Dec 17, 2013 1:03:21 PM com.hazelcast.nio.SocketConnector
INFO: [10.69.108.60]:5701 [dev] Connecting to /170.194.100.111:5703, timeout: 0, bind-any: true
Dec 17, 2013 1:03:21 PM com.hazelcast.nio.SocketConnector
INFO: [10.69.108.60]:5701 [dev] Connecting to /170.194.100.111:5702, timeout: 0, bind-any: true
Dec 17, 2013 1:03:21 PM com.hazelcast.cluster.TcpIpJoiner
INFO: [10.69.108.60]:5701 [dev] Connecting to possible member: Address[170.194.100.111]:5701
Dec 17, 2013 1:03:21 PM com.hazelcast.nio.SocketConnector
INFO: [10.69.108.60]:5701 [dev] Connecting to /170.194.100.111:5701, timeout: 0, bind-any: true
Dec 17, 2013 1:03:22 PM com.hazelcast.nio.SocketConnector
INFO: [10.69.108.60]:5701 [dev] Could not connect to: /10.69.108.60:5703. Reason: SocketException[Connection refused: connect to address /10.69.108.60:5703]
Dec 17, 2013 1:03:22 PM com.hazelcast.nio.SocketConnector
INFO: [10.69.108.60]:5701 [dev] Could not connect to: /10.69.108.60:5702. Reason: SocketException[Connection refused: connect to address /10.69.108.60:5702]
Dec 17, 2013 1:03:22 PM com.hazelcast.nio.SocketConnector
INFO: [10.69.108.60]:5701 [dev] Could not connect to: /170.194.100.111:5703. Reason: SocketException[Connection refused: connect to address /170.194.100.111:5703]
Dec 17, 2013 1:03:22 PM com.hazelcast.nio.SocketConnector
INFO: [10.69.108.60]:5701 [dev] Could not connect to: /170.194.100.111:5702. Reason: SocketException[Connection refused: connect to address /170.194.100.111:5702]
Dec 17, 2013 1:03:22 PM com.hazelcast.nio.SocketConnector
INFO: [10.69.108.60]:5701 [dev] Could not connect to: /170.194.100.111:5701. Reason: SocketException[Connection refused: connect to address /170.194.100.111:5701]
Dec 17, 2013 1:03:23 PM com.hazelcast.cluster.TcpIpJoiner
INFO: [10.69.108.60]:5701 [dev]
Members [1] {
Member [10.69.108.60]:5701 this
}
Dec 17, 2013 1:03:23 PM com.hazelcast.core.LifecycleService
INFO: [10.69.108.60]:5701 [dev] Address[10.69.108.60]:5701 is STARTED
HazelcastInstance{name='_hzInstance_1_dev', node=Address[10.69.108.60]:5701}Hey youuuu!
The logging on the remote machine is on these lines.Couldnt paste all the logging.Managed to get the important part.
INFO: [10.69.108.60]:5701 [dev] Connecting to possible member: Address[10.38.148.60]:5703
Dec 17, 2013 1:03:21 PM com.hazelcast.cluster.TcpIpJoiner
INFO: [10.69.108.60]:5701 [dev] Connecting to possible member: Address[10.38.148.60]:5702
Dec 17, 2013 1:03:21 PM com.hazelcast.cluster.TcpIpJoiner
INFO: [10.69.108.60]:5701 [dev] Connecting to possible member: Address[10.38.148.60]:5701
Dec 17, 2013 1:03:21 PM com.hazelcast.cluster.TcpIpJoiner
INFO: [10.69.108.60]:5701 [dev] Connecting to possible member: Address[170.194.100.111]:5703
Dec 17, 2013 1:03:21 PM com.hazelcast.cluster.TcpIpJoiner
INFO: [10.69.108.60]:5701 [dev] Connecting to possible member: Address[170.194.100.111]:5702
Dec 17, 2013 1:03:21 PM com.hazelcast.nio.SocketConnector
Members [2] {
Member [10.69.108.60]:5701 this
Member [170.194.100.111]:5701
}
Instead of creating a member instance directly, could you get the member instance using the hz.getCluster().getMembers() method and select the one you want to send to? I want to see if it is caused by the way you are creating that member.
I can't format text in comments, so I'll put another answer.
So the problem you are suffering from is why your members don't form a cluster.
You should see logging like:
Members [2] {
Member [192.168.1.104]:5701 this
Member [192.168.1.104]:5702
}
That is why I need more logging that just your stacktrace, but that currently doesn't provide any more value. I need to see what Hazelcast says about joining other clusters.
I need to see something like this:
Dec 17, 2013 7:24:13 PM com.hazelcast.config.XmlConfigBuilder
INFO: Looking for hazelcast.xml config file in classpath.
Dec 17, 2013 7:24:13 PM com.hazelcast.config.XmlConfigBuilder
WARNING: Could not find hazelcast.xml in classpath.
Hazelcast will use hazelcast-default.xml config file in jar.
Dec 17, 2013 7:24:13 PM com.hazelcast.config.XmlConfigBuilder
INFO: Using configuration file /java/projects/Hazelcast/hazelcast/hazelcast/target/classes/hazelcast-default.xml in the classpath.
Dec 17, 2013 7:24:13 PM com.hazelcast.instance.DefaultAddressPicker
INFO: Prefer IPv4 stack is true.
Dec 17, 2013 7:24:13 PM com.hazelcast.instance.DefaultAddressPicker
INFO: Picked Address[192.168.1.102]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
Dec 17, 2013 7:24:13 PM com.hazelcast.system
INFO: [192.168.1.102]:5701 [dev] [3.2-SNAPSHOT] Hazelcast Community Edition 3.2-SNAPSHOT (20131217) starting at Address[192.168.1.102]:5701
Dec 17, 2013 7:24:13 PM com.hazelcast.system
INFO: [192.168.1.102]:5701 [dev] [3.2-SNAPSHOT] Copyright (C) 2008-2013 Hazelcast.com
Dec 17, 2013 7:24:13 PM com.hazelcast.instance.Node
INFO: [192.168.1.102]:5701 [dev] [3.2-SNAPSHOT] Creating MulticastJoiner
Dec 17, 2013 7:24:13 PM com.hazelcast.core.LifecycleService
INFO: [192.168.1.102]:5701 [dev] [3.2-SNAPSHOT] Address[192.168.1.102]:5701 is STARTING
Dec 17, 2013 7:24:15 PM com.hazelcast.cluster.MulticastJoiner
INFO: [192.168.1.102]:5701 [dev] [3.2-SNAPSHOT]
Members [1] {
Member [192.168.1.102]:5701 this
}
Dec 17, 2013 7:24:16 PM com.hazelcast.core.LifecycleService
INFO: [192.168.1.102]:5701 [dev] [3.2-SNAPSHOT] Address[192.168.1.102]:5701 is STARTED
Dec 17, 2013 7:24:16 PM com.hazelcast.partition.PartitionService
INFO: [192.168.1.102]:5701 [dev] [3.2-SNAPSHOT] Initializing cluster partition table first arrangement...
I was also getting the same error.
It is due to this line in echoonthemember function
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
It creates the new hazelcast instance of default or of cfg config. The member is searched in this instance of the hazelcast which is not actually present in it. Thus the error message is displayed as
TargetNotAMemberException.
To have it work properly, just pass the created instance in the echoonthemember function.
E.g by making it the member variable in class DistributedExecutor and setting it by the constructor.
then if your actual instance was 'abcdef', then
use as
IExecutorService executorService = abcdef.getExecutorService("default");
do not create new Hazelcast instance.
Related
I tried all the possible solutions available online. Changed my token with all permissions. Changed the gitlab connection with latest token. Still pipelines in gitlab shows the pending status. These are the logs from jenkins.
Mar 23, 2022 5:37:19 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Retrieving gitlab project ids
Mar 23, 2022 5:37:19 PM WARNING com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
No gitlab client found.
Mar 23, 2022 5:38:13 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Retrieving gitlab project ids
Mar 23, 2022 5:38:13 PM WARNING com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
No gitlab client found.
Mar 23, 2022 5:38:13 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Retrieving gitlab project ids
Mar 23, 2022 5:38:13 PM WARNING com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
No gitlab client found.
Mar 23, 2022 5:38:14 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Retrieving gitlab project ids
Mar 23, 2022 5:38:14 PM WARNING com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
No gitlab client found.
Mar 23, 2022 5:38:14 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Retrieving gitlab project ids
Mar 23, 2022 5:38:14 PM WARNING com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
No gitlab client found.
Mar 23, 2022 5:38:14 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Retrieving gitlab project ids
Mar 23, 2022 5:38:14 PM WARNING com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
No gitlab client found.
Mar 23, 2022 5:38:15 PM INFO org.jenkinsci.plugins.workflow.job.WorkflowRun finish
multi/pipelines-check #79 completed: SUCCESS
Mar 23, 2022 5:38:15 PM INFO io.jenkins.plugins.generic.event.HttpEventSender send
Skipped event sending due to receiver URL not set
Mar 23, 2022 5:38:16 PM WARNING jenkins.util.Listeners lambda$notify$0
null
java.lang.NullPointerException
at io.jenkins.plugins.gitlabbranchsource.helpers.GitLabPipelineStatusNotifier.lambda$getStatusName$0(GitLabPipelineStatusNotifier.java:102)
at java.logging/java.util.logging.Logger.log(Logger.java:1050)
at io.jenkins.plugins.gitlabbranchsource.helpers.GitLabPipelineStatusNotifier.getStatusName(GitLabPipelineStatusNotifier.java:101)
at io.jenkins.plugins.gitlabbranchsource.helpers.GitLabPipelineStatusNotifier.getStatusName(GitLabPipelineStatusNotifier.java:84)
at io.jenkins.plugins.gitlabbranchsource.helpers.GitLabPipelineStatusNotifier.logComment(GitLabPipelineStatusNotifier.java:178)
at io.jenkins.plugins.gitlabbranchsource.helpers.GitLabPipelineStatusNotifier.access$500(GitLabPipelineStatusNotifier.java:52)
at io.jenkins.plugins.gitlabbranchsource.helpers.GitLabPipelineStatusNotifier$JobCompletedListener.onCompleted(GitLabPipelineStatusNotifier.java:484)
at hudson.model.listeners.RunListener.lambda$fireCompleted$0(RunListener.java:207)
at jenkins.util.Listeners.lambda$notify$0(Listeners.java:59)
at jenkins.util.Listeners.notify(Listeners.java:67)
at hudson.model.listeners.RunListener.fireCompleted(RunListener.java:205)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.finish(WorkflowRun.java:627)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.access$800(WorkflowRun.java:138)
at org.jenkinsci.plugins.workflow.job.WorkflowRun$GraphL.onNewHead(WorkflowRun.java:1049)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.notifyListeners(CpsFlowExecution.java:1474)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$3.run(CpsThreadGroup.java:497)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$1.run(CpsVmExecutorService.java:38)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:139)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
JENKINSFILE:
pipeline {
agent {label 'xxx'}
options {
gitLabConnection('xxx')
}
stages {
stage('Code') {
steps {
gitlabCommitStatus(connection: gitLabConnection(gitLabConnection: 'xxx', jobCredentialId: 'xxx-xxx-xxx-xxx-xxxxx', useAlternativeCredential: true), name: 'Code_checkout') {
checkout([$class: 'GitSCM', branches: [[name: '*/develop']], extensions: [[$class: 'GitLFSPull'], [$class: 'RelativeTargetDirectory', relativeTargetDir: 'xxxxxx']], userRemoteConfigs: [[url: 'git#gitlab.com:xxxxx/xxxxxx/root.git']]])
sh'''
cd xxxxxxxxx
git submodule update --init --recursive
cd /home/jenkins/jenkins_slave/workspace/ROOT/vds
git checkout develop
git pull
cd xxxxxxxxxxx
'''
}
}
}
stage('Testing') {
steps {
gitlabCommitStatus(connection: gitLabConnection(gitLabConnection: 'xxxxxx', jobCredentialId: 'xxxxxxx', useAlternativeCredential: true), name: 'Testing') {
echo "checking"
}
}
}
}
all the code checkout part and testing part is happening in shell
You can use these two parameters in optionsblock
options {
gitLabConnection('gitlab')
gitlabBuilds(builds: ['build'])
}
and in post section you can use the updateGitlabCommitStatus like this
post {
failure {
updateGitlabCommitStatus name: 'build', state: 'failed'
}
unstable {
updateGitlabCommitStatus name: 'build', state: 'failed'
}
aborted {
updateGitlabCommitStatus name: 'build', state: 'canceled'
}
success {
updateGitlabCommitStatus name: 'build', state: 'success'
}
always {
}
}
For info checkout this section https://github.com/jenkinsci/gitlab-plugin/blob/master/README.md
I am facing an issue during integration Hazelcast with weblogic 12c. Do i have to change any configuration?
com.hazelcast.instance.NodeExtension
com.hazelcast.instance.DefaultNodeExtension
Step 1: [setDomainEnv.cmd] i have added the path for
SET CLASSPATH=%CLASSPATH%E:lib\hazelcast-all-3.7.1.jar;
Step 2: I have written a sample start-up class for weblogic server
public class HCServer {
public HCServer() {
HazelcastInstance hz = Hazelcast.newHazelcastInstance();
}
public static void main(String[] args) {
try {
Class.forName("server.HCServer").newInstance();
Set<HazelcastInstance> set = Hazelcast.getAllHazelcastInstances();
for (HazelcastInstance hcInstance : set) {
IMap<String, HCTask> iMap = hcInstance.getMap("data");
for (int i = 0; i < 5000; i++) {
iMap.put(String.valueOf(i), new HCTask(i));
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Following error occurs on starting the server
<Nov 22, 2016, 4:07:44,922 PM PKT>
Nov 22, 2016 4:07:45 PM com.hazelcast.config.XmlConfigLocator
INFO: Loading 'hazelcast-default.xml' from classpath.
Nov 22, 2016 4:07:46 PM com.hazelcast.instance.DefaultAddressPicker
INFO: [LOCAL] [dev] [3.7.1] Prefer IPv4 stack is true.
Nov 22, 2016 4:07:46 PM com.hazelcast.instance.DefaultAddressPicker
INFO: [LOCAL] [dev] [3.7.1] Picked [192.168.0.37]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
Nov 22, 2016 4:07:47 PM com.hazelcast.instance.NodeExtensionFactory
WARNING: DefaultNodeExtension class has been loaded by two different class-loaders. Are you running Hazelcast in an OSGi environment? If so, set the bundle class-loader in the Config using the setClassloader() method
<Nov 22, 2016, 4:07:47,256 PM PKT> <com.hazelcast.instance.NodeExtensionFactory> <DefaultNodeExtension class has been loaded by two different class-loaders. Are you running Hazelcast in an OSGi environment? If so, set the bundl
e class-loader in the Config using the setClassloader() method>
com.hazelcast.core.HazelcastException: java.lang.NoSuchMethodException: com.hazelcast.instance.DefaultNodeExtension.(com.hazelcast.instance.Node)
at com.hazelcast.util.ExceptionUtil.peel(ExceptionUtil.java:73)
at com.hazelcast.util.ExceptionUtil.peel(ExceptionUtil.java:52)
at com.hazelcast.util.ExceptionUtil.rethrow(ExceptionUtil.java:83)
at com.hazelcast.instance.NodeExtensionFactory.create(NodeExtensionFactory.java:54)
at com.hazelcast.instance.DefaultNodeContext.createNodeExtension(DefaultNodeContext.java:35)
at com.hazelcast.instance.Node.createNodeExtension(Node.java:290)
at com.hazelcast.instance.Node.(Node.java:177)
at com.hazelcast.instance.HazelcastInstanceImpl.createNode(HazelcastInstanceImpl.java:155)
at com.hazelcast.instance.HazelcastInstanceImpl.(HazelcastInstanceImpl.java:126)
at com.hazelcast.instance.HazelcastInstanceFactory.constructHazelcastInstance
(HazelcastInstanceFactory.java:218)
at com.hazelcast.instance.HazelcastInstanceFactory.newHazelcastInstance
(HazelcastInstanceFactory.java:176)
at com.hazelcast.instance.HazelcastInstanceFactory.newHazelcastInstance
(HazelcastInstanceFactory.java:126)
at com.hazelcast.core.Hazelcast.newHazelcastInstance(Hazelcast.java:87)
at server.HCServer.(HCServer.java:13)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance
(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at java.lang.Class.newInstance(Class.java:442)
at server.HCServer.main(HCServer.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
Do you want to fix constructor of HCServer like this
public HCServer() {
Config config = new XmlConfigBuilder().build();
config.setClassLoader(this.getClass().getClassLoader());
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
}
Let me know if it works!
I have the following code on the hazelcast instance:
ITopic<String> topic;
HazelcastInstance hz = Hazelcast.newHazelcastInstance();
topic = hz.getTopic("data");
Data is repeatedly published to the topic
String event = "abc123"
topic.publish(event);
then on another machine on the LAN I run the client like this:
public class Listener implements MessageListener<String>
{
ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig().addAddress("192.168.21.89:5701");
HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
ITopic<String> topic = client.getTopic("data");
topic.addMessageListener(new Listener());
public void onMessage(Message<String> m) {
System.out.println("onMessage");
}
}
The client finds the hz node and starts, but doesn't see any data message on the iTopic. I thought hz instances and clients would autodiscover each other in default? Do I have to configure hz for the network somehow?
The client log shows:
2015-09-01 15:43:05,518 INFO Listener [main] In main()
In main()
Sep 01, 2015 3:43:05 PM com.hazelcast.core.LifecycleService
INFO: HazelcastClient[hz.client_0_dev][3.5] is STARTING
Sep 01, 2015 3:43:05 PM com.hazelcast.core.LifecycleService
INFO: HazelcastClient[hz.client_0_dev][3.5] is STARTED
Sep 01, 2015 3:43:06 PM com.hazelcast.core.LifecycleService
INFO: HazelcastClient[hz.client_0_dev][3.5] is CLIENT_CONNECTED
Sep 01, 2015 3:43:06 PM com.hazelcast.client.spi.impl.ClientMembershipListener
INFO:
Members [1] {
Member [192.168.21.89]:5701
}
This was my own problem because I was not actually publishing the data I wanted to listen to. Aaargh!
I'm a newbie to spring integration and I'm using the following code,
package services.api;
public interface GreetingService {
public void greetUsers(String userName);
}
package services.impl;
import services.api.GreetingService;
public class GreetServiceImpl implements GreetingService {
#Override
public void greetUsers(String userName) {
if (userName != null && userName.trim().length() > 0) {
System.out.println("Hello " + userName);
}
}
}
package main;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.support.MessageBuilder;
public class Main {
public static void main(String[] args)
{
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
MessageChannel messageChannel = applicationContext.getBean(MessageChannel.class);
Message<String> message = MessageBuilder.withPayload("World").build();
messageChannel.send(message);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://springframework.org/schema/integration http://springframework.org/schema/integration/spring-integration.xsd">
<channel id="pushChannel" />
<service-activator input-channel="pushChannel" ref="service"
method="greetUsers" />
<beans:bean id="service" class="services.impl.GreetServiceImpl" />
</beans:beans>
I'm getting the following error, eventhough I've declared only one message channel
Mar 04, 2014 4:46:23 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext#34d0cdd0: startup date [Tue Mar 04 16:46:23 IST 2014]; root of context hierarchy
Mar 04, 2014 4:46:23 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
Mar 04, 2014 4:46:23 PM org.springframework.beans.factory.config.PropertiesFactoryBean loadProperties
INFO: Loading properties file from URL [jar:file:/D:/Personal%20Data/Softwares/spring-framework-4.0.0.RELEASE-dist/SpringIntegration/spring-integration-3.0.0.RELEASE-dist/spring-integration-3.0.0.RELEASE/libs/spring-integration-core-3.0.0.RELEASE.jar!/META-INF/spring.integration.default.properties]
Mar 04, 2014 4:46:23 PM org.springframework.integration.config.xml.IntegrationNamespaceHandler registerHeaderChannelRegistry
INFO: No bean named 'integrationHeaderChannelRegistry' has been explicitly defined. Therefore, a default DefaultHeaderChannelRegistry will be created.
Mar 04, 2014 4:46:23 PM org.springframework.integration.config.xml.DefaultConfiguringBeanFactoryPostProcessor registerErrorChannel
INFO: No bean named 'errorChannel' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.
Mar 04, 2014 4:46:23 PM org.springframework.integration.config.xml.DefaultConfiguringBeanFactoryPostProcessor registerTaskScheduler
INFO: No bean named 'taskScheduler' has been explicitly defined. Therefore, a default ThreadPoolTaskScheduler will be created.
Mar 04, 2014 4:46:23 PM org.springframework.beans.factory.config.PropertiesFactoryBean loadProperties
INFO: Loading properties file from URL [jar:file:/D:/Personal%20Data/Softwares/spring-framework-4.0.0.RELEASE-dist/SpringIntegration/spring-integration-3.0.0.RELEASE-dist/spring-integration-3.0.0.RELEASE/libs/spring-integration-core-3.0.0.RELEASE.jar!/META-INF/spring.integration.default.properties]
Mar 04, 2014 4:46:23 PM org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler initialize
INFO: Initializing ExecutorService 'taskScheduler'
Mar 04, 2014 4:46:23 PM org.springframework.context.support.DefaultLifecycleProcessor start
INFO: Starting beans in phase -2147483648
Mar 04, 2014 4:46:23 PM org.springframework.integration.endpoint.EventDrivenConsumer logComponentSubscriptionEvent
INFO: Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
Mar 04, 2014 4:46:23 PM org.springframework.integration.channel.PublishSubscribeChannel adjustCounterIfNecessary
INFO: Channel 'org.springframework.context.support.ClassPathXmlApplicationContext#34d0cdd0.errorChannel' has 1 subscriber(s).
Mar 04, 2014 4:46:23 PM org.springframework.integration.endpoint.EventDrivenConsumer start
INFO: started _org.springframework.integration.errorLogger
Mar 04, 2014 4:46:23 PM org.springframework.context.support.DefaultLifecycleProcessor start
INFO: Starting beans in phase 0
Mar 04, 2014 4:46:23 PM org.springframework.integration.endpoint.EventDrivenConsumer logComponentSubscriptionEvent
INFO: Adding {service-activator} as a subscriber to the 'pushChannel' channel
Mar 04, 2014 4:46:23 PM org.springframework.integration.channel.DirectChannel adjustCounterIfNecessary
INFO: Channel 'org.springframework.context.support.ClassPathXmlApplicationContext#34d0cdd0.pushChannel' has 1 subscriber(s).
Mar 04, 2014 4:46:23 PM org.springframework.integration.endpoint.EventDrivenConsumer start
INFO: started org.springframework.integration.config.ConsumerEndpointFactoryBean#0
Exception in thread "main" org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.integration.MessageChannel] is defined: expected single matching bean but found 3: pushChannel,nullChannel,errorChannel
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:312)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:985)
at main.Main.main(Main.java:17)
I suggest you to read more Docs:
http://docs.spring.io/spring-integration/docs/3.0.1.RELEASE/reference/html
http://www.manning.com/fisher
As you see the framework provides two explicit channels: nullChannel, errorChannel.
And they aren't the last beans which are populated by framework.
To fix your issue just provide the id of your channel to applicationContext.getBean
I used following cluster code to fork multiple process for my node app.
if (cluster.isMaster) {
require('os').cpus().forEach(function () {
cluster.fork();
});
cluster.on('exit', function (worker, code, signal) {
cluster.fork();
});
} else if (cluster.isWorker) {
logger.log.info('Worker server started on port %d (ID: %d, PID: %d)', app.get('port'), cluster.worker.id, cluster.worker.process.pid);
}
the output is:
Thu Sep 05 2013 20:30:03 GMT-0700 (PDT) - info: Worker server started on port 3000 (ID: 1, PID: 606)
Thu Sep 05 2013 20:30:03 GMT-0700 (PDT) - info: Worker server started on port 3000 (ID: 2, PID: 607)
Thu Sep 05 2013 20:30:03 GMT-0700 (PDT) - info: Worker server started on port 3000 (ID: 5, PID: 610)
Thu Sep 05 2013 20:30:03 GMT-0700 (PDT) - info: Worker server started on port 3000 (ID: 3, PID: 608)
Thu Sep 05 2013 20:30:03 GMT-0700 (PDT) - info: Worker server started on port 3000 (ID: 4, PID: 609)
Thu Sep 05 2013 20:30:03 GMT-0700 (PDT) - info: Worker server started on port 3000 (ID: 6, PID: 611)
Thu Sep 05 2013 20:30:03 GMT-0700 (PDT) - info: Worker server started on port 3000 (ID: 8, PID: 613)
Thu Sep 05 2013 20:30:03 GMT-0700 (PDT) - info: Worker server started on port 3000 (ID: 7, PID: 612)
There is 8 worker processes but when I checked process using pgrep, I saw 9
$ pgrep -l node
613 node
612 node
611 node
610 node
609 node
608 node
607 node
606 node
605 node
so one process extra must be master process and how do I print out the master process IP?
Thanks
I posted another question related to this one, I think it's might be useful for everyone to look at this as well:
Node.js cluster master process reboot after got kill & pgrep?
You can get the master process pid with process.pid inside if(cluster.isMaster). IP and port are properties of your app so that would be the same.
You can get the master (parent) pid with process.ppid.
This will let you send a signal which is useful for reloads without downtime.
For instance process.kill(process.ppid, 'SIGHUP');