<dependency>
<groupId>link.thingscloud</groupId>
<artifactId>vertx-remoting-impl</artifactId>
<version>${vertx-remoting.version}</version>
</dependency>
<dependency>
<groupId>link.thingscloud</groupId>
<artifactId>vertx-remoting-spring-boot-starter</artifactId>
<version>${vertx-remoting.version}</version>
</dependency>
# RemotingServerProperties or RemotingClientProperties
vertx.remoting.server.serverListenPort=9888
server.shutdown=graceful
@EnableRemotingClientAutoConfiguration
@EnableRemotingServerAutoConfiguration
@SpringBootApplication
public class Bootstrap {
private static final Logger LOG = LoggerFactory.getLogger(Bootstrap.class);
public static void main(String[] args) {
SpringApplication.run(Bootstrap.class, args);
}
@Autowired
RemotingClient remotingClient;
@Autowired
RemotingServer remotingServer;
@Autowired
RemotingCommandFactory factory;
private static final String URI = "/uri/v1";
@PostConstruct
public void start() {
RemotingCommand request = factory.createRequest();
request.cmdCode((short) 13);
remotingClient.invokeOneWay("127.0.0.1:9888", URI, request);
remotingClient.invokeAsync("127.0.0.1:9888", URI, request, new AsyncHandler() {
@Override
public void onFailure(RemotingCommand request, Throwable cause) {
LOG.info("invokeAsync onFailure : {}, cause : ", request, cause);
}
@Override
public void onSuccess(RemotingCommand response) {
LOG.info("invokeAsync onSuccess : {}", response);
}
}, 1000);
remotingClient.invokeOneWay("127.0.0.1:9888", URI, request);
remotingClient.invokeAsync("127.0.0.1:9888", URI, request, new AsyncHandler() {
@Override
public void onFailure(RemotingCommand request, Throwable cause) {
LOG.info("onFailure response : {}", request, cause);
}
@Override
public void onSuccess(RemotingCommand response) {
LOG.info("onSuccess response : {}", response);
}
}, 1000);
}
@RemotingRequestProcessor(uri = URI, code = 12, type = RemotingType.CLIENT)
class RequestProcessorImpl1 implements RequestProcessor {
@Override
public RemotingCommand processRequest(RemotingChannel channel, RemotingCommand request) {
LOG.info("processRequest : {}", request);
return factory.createResponse(request);
}
}
@RemotingRequestProcessor(uri = URI, code = 13, type = RemotingType.SERVER)
class RequestProcessorImpl2 implements RequestProcessor {
@Override
public RemotingCommand processRequest(RemotingChannel channel, RemotingCommand request) {
LOG.info("processRequest : {}", request);
return factory.createResponse(request);
}
}
@RemotingRequestProcessor(uri = URI, code = 14)
class RequestProcessorImpl3 implements RequestProcessor {
@Override
public RemotingCommand processRequest(RemotingChannel channel, RemotingCommand request) {
LOG.info("processRequest : {}", request);
return factory.createResponse(request);
}
}
@RemotingInterceptor
class InterceptorImpl implements Interceptor {
@Override
public void beforeRequest(RequestContext context) {
LOG.info("beforeRequest : {}", context);
}
@Override
public void afterResponseReceived(ResponseContext context) {
LOG.info("afterResponseReceived : {}", context);
}
}
@RemotingChannelEventListener
class ChannelEventListenerImpl implements ChannelEventListener {
@Override
public void onChannelConnect(RemotingChannel channel) {
LOG.info("onChannelConnect : {}", channel);
}
@Override
public void onChannelClose(RemotingChannel channel) {
LOG.info("onChannelClose : {}", channel);
}
@Override
public void onChannelException(RemotingChannel channel, Throwable cause) {
LOG.error("onChannelException : {}", channel, cause);
}
}
}
npm publish
npm install vertx-remoting-client
import vrc from "vertx-remoting-client";
const that = this;
let nonce = '';
let token = '';
vrc
.init(this.vrc.url, true)
.auth(nonce, token)
.onOpened(function () {
console.log("vrc onOpened ...")
// auth
})
.onClosed(function () {
console.log("vrc onClosed ...")
}, function () {
console.log("onClosed set timeout.")
vrc.open(function () {
console.log("open completed....")
}, function (error) {
console.log("open error.", error)
});
}, 5000)
.open(function () {
console.log("open completed.")
}, function (error) {
console.log("open error.", error)
});
Apache License, Version 2.0 Copyright (C) Apache Software Foundation