This example shows you how to configure ActiveMQ to use the Vert.x Connector Service.
ActiveMQ supports 2 types of Vert.x connector, incoming and outgoing. Incoming connector consumes from Vert.x event bus and forwards to a configurable address. Outgoing connector consumes from a configurable address and forwards to a configurable Vert.x event bus.
In this example, an incoming connector and an outgoing connector are configured. A simple java Verticle is deployed. The verticle registers a message handler on the outgoing connector's address ("outgoing.vertx.address"). A String message is sent to Vert.x event bus on the incoming connector's address("incoming.vertx.address"). The message then will be forwarded to a ActiveMQ queue by the incoming connector. The outgoing connector listens to the ActiveMQ queue and forwards the message from ActiveMQ to Vert.x event bus on the outgoing connector's address. The verticle finally receives the message from it's event bus.
For more information on Vert.x concept please visit the Vertx site
To run the server, simply type mvn verify
from this directory.
platformManager = PlatformLocator.factory.createPlatformManager(PORT, HOST);
String verticle = "org.apache.activemq.artemis.core.example.ExampleVerticle";
platformManager.deployVerticle(verticle, null, new URL[0], 1, null,
new Handler>(){
@Override
public void handle(AsyncResult result)
{
if (!result.succeeded())
{
throw new RuntimeException("failed to deploy verticle", result.cause());
}
latch0.countDown();
}
});
EventBus eventBus = vertx.eventBus();
eventBus.registerHandler(VertxConnectorExample.OUTGOING,
new Handler>() {
@Override
public void handle(Message> startMsg)
{
Object body = startMsg.body();
System.out.println("Verticle receives a message: " + body);
VertxConnectorExample.result.set(VertxConnectorExample.MSG.equals(body));
latch0.countDown();
}
});
EventBus bus = platformManager.vertx().eventBus();
bus.send(INCOMING, MSG);