Config hazelcastConfig = new Config();
//----------
NetworkConfig network = hazelcastConfig.getNetworkConfig();
network.setPort(40000);
//network.setPortAutoIncrement(false);
JoinConfig join = network.getJoin();
join.getMulticastConfig().setEnabled(false);
join.getTcpIpConfig()
.addMember("10.130.58.254")
.setRequiredMember("10.130.58.16")
.setEnabled(true);
//----------
ClusterManager mgr = new HazelcastClusterManager(hazelcastConfig);
VertxOptions options = new VertxOptions()
.setClusterManager(mgr)
.setClustered(true);
package ru.dellin.math.solver.gurobi.javadeployerverticle;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.eventbus.EventBus;
public class Resiver extends AbstractVerticle {
@Override
public void start(){
EventBus eb = vertx.eventBus();
eb.consumer("serverVerticle", message->{
System.out.println(message.body().toString());
});
System.out.println("-- "+this.getClass().getName()+" --");
}
}
package ru.dellin.math.solver.gurobi.javadeployerverticle;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.eventbus.EventBus;
public class Sender extends AbstractVerticle {
@Override
public void start(){
EventBus eb = vertx.eventBus();
vertx.setPeriodic(2000, handler->{
eb.send("serverVerticle", "test"
, res->{
if (res.succeeded()){
System.out.println("Received reply");
} else {
System.out.println(" No reply");
res.cause().printStackTrace();
}
}
);
});
System.out.println("-- "+this.getClass().getName()+" --");
}
}
Resiver on machine 10.130.58.16 and
Sender
on machine 10.130.58.254
i see (on 10.130.58.254
):INFO: [10.130.58.254]:40000 [dev] [3.5.2] Creating TcpIpJoiner
сен 15, 2016 6:19:32 PM com.hazelcast.core.LifecycleService
INFO: [10.130.58.254]:40000 [dev] [3.5.2] Address[10.130.58.254]:40000 is STARTING
сен 15, 2016 6:19:32 PM com.hazelcast.nio.tcp.SocketConnector
INFO: [10.130.58.254]:40000 [dev] [3.5.2] Connecting to /10.130.58.16:40000, timeout: 0, bind-any: true
сен 15, 2016 6:19:32 PM com.hazelcast.nio.tcp.TcpIpConnectionManager
INFO: [10.130.58.254]:40000 [dev] [3.5.2] Established socket connection between /10.130.58.254:39367
сен 15, 2016 6:19:39 PM com.hazelcast.cluster.ClusterService
INFO: [10.130.58.254]:40000 [dev] [3.5.2]
Members [2] {
Member [10.130.58.16]:40000
Member [10.130.58.254]:40000 this
}
сен 15, 2016 6:19:41 PM com.hazelcast.core.LifecycleService
INFO: [10.130.58.254]:40000 [dev] [3.5.2] Address[10.130.58.254]:40000 is STARTED
-- ru.dellin.math.solver.gurobi.javadeployerverticle.Sender --
No reply
(TIMEOUT,-1) Timed out waiting for a reply
at io.vertx.core.eventbus.impl.HandlerRegistration.sendAsyncResultFailure(HandlerRegistration.java:117)
at io.vertx.core.eventbus.impl.HandlerRegistration.lambda$new$147(HandlerRegistration.java:64)
at io.vertx.core.impl.VertxImpl$InternalTimerHandler.handle(VertxImpl.java:738)
at io.vertx.core.impl.VertxImpl$InternalTimerHandler.handle(VertxImpl.java:709)
at io.vertx.core.impl.ContextImpl.lambda$wrapTask$18(ContextImpl.java:335)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:358)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
at java.lang.Thread.run(Thread.java:745)
String ipAddress = Inet4Address.getLocalHost().getHostAddress();
VertxOptions options = new VertxOptions()
.setClusterHost(ipAddress)
.setClusterManager(mgr)
.setClustered(true);
сен 15, 2016 6:26:27 PM com.hazelcast.core.LifecycleService
INFO: [10.130.58.254]:40000 [dev] [3.5.2] Address[10.130.58.254]:40000 is STARTING
сен 15, 2016 6:26:27 PM com.hazelcast.nio.tcp.SocketConnector
INFO: [10.130.58.254]:40000 [dev] [3.5.2] Connecting to /10.130.58.16:40000, timeout: 0, bind-any: true
сен 15, 2016 6:26:27 PM com.hazelcast.nio.tcp.TcpIpConnectionManager
INFO: [10.130.58.254]:40000 [dev] [3.5.2] Established socket connection between /10.130.58.254:45033
сен 15, 2016 6:26:34 PM com.hazelcast.cluster.ClusterService
INFO: [10.130.58.254]:40000 [dev] [3.5.2]
Members [2] {
Member [10.130.58.16]:40000
Member [10.130.58.254]:40000 this
}
сен 15, 2016 6:26:36 PM com.hazelcast.core.LifecycleService
INFO: [10.130.58.254]:40000 [dev] [3.5.2] Address[10.130.58.254]:40000 is STARTED
-- ru.dellin.math.solver.gurobi.javadeployerverticle.Sender --
No reply
(TIMEOUT,-1) Timed out waiting for a reply
at io.vertx.core.eventbus.impl.HandlerRegistration.sendAsyncResultFailure(HandlerRegistration.java:117)
at io.vertx.core.eventbus.impl.HandlerRegistration.lambda$new$147(HandlerRegistration.java:64)
at io.vertx.core.impl.VertxImpl$InternalTimerHandler.handle(VertxImpl.java:738)
at io.vertx.core.impl.VertxImpl$InternalTimerHandler.handle(VertxImpl.java:709)
at io.vertx.core.impl.ContextImpl.lambda$wrapTask$18(ContextImpl.java:335)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:358)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
at java.lang.Thread.run(Thread.java:745)
VertxOptions options = new VertxOptions()
.setClusterHost("10.130.58.16")
.setClusterManager(mgr)
.setClustered(true);
Members [2] {
Member [10.130.58.16]:40000
Member [10.130.58.254]:40000 this
}
сен 15, 2016 6:33:51 PM com.hazelcast.core.LifecycleService
INFO: [10.130.58.254]:40000 [dev] [3.5.2] Address[10.130.58.254]:40000 is STARTED
сен 15, 2016 6:33:52 PM io.vertx.core.impl.VertxImpl
SEVERE: Failed to start event bus
java.net.BindException: Невозможно назначить запрошенный адрес (Cannot assign requested address)
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:433)
at sun.nio.ch.Net.bind(Net.java:425)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:125)
at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:485)
at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1089)
at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:440)
at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:425)
at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:903)
at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:198)
at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:348)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:358)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
at java.lang.Thread.run(Thread.java:745)
nostroumov@mm-sky-009:~$ ss -lnp | grep 40000
tcp LISTEN 0 100 :::40000 :::*
Inet4Address.getLocalHost().getHostAddress()
in Unix returns 127.0.0.1
solution is public static String getCurrentIp() {
try {
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface
.getNetworkInterfaces();
while (networkInterfaces.hasMoreElements()) {
NetworkInterface ni = (NetworkInterface) networkInterfaces
.nextElement();
Enumeration<InetAddress> nias = ni.getInetAddresses();
while(nias.hasMoreElements()) {
InetAddress ia= (InetAddress) nias.nextElement();
if (!ia.isLinkLocalAddress()
&& !ia.isLoopbackAddress()
&& ia instanceof Inet4Address) {
return ia.getHostAddress();
}
}
}
} catch (SocketException e) {
System.out.println("unable to get current IP ");
e.printStackTrace();
}
return null;
}
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/2322f98f-1ecd-4bc1-8a25-eac11cad42c4%40googlegroups.com.--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/394ba959-f633-41fc-9fdf-81ccd24ee82f%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/b47d443b-3b08-403e-9685-b6d9568c8ff6%40googlegroups.com.