mirror of
https://github.com/apache/activemq-artemis.git
synced 2025-02-06 10:09:01 +00:00
https://issues.apache.org/jira/browse/ACTIVEMQ6-3 We are renaming packages from activemq6 to activemq as that's more generic and version independent The previous commit renamed the directories. On this commit now I'm changing the code. If we changed the code and the directories on the same commit git would remove and add a lot of files without recognizing the renames.
85 lines
3.9 KiB
HTML
85 lines
3.9 KiB
HTML
<html>
|
|
<head>
|
|
<title>HornetQ Vert.x Connector Service Example</title>
|
|
<link rel="stylesheet" type="text/css" href="../../common/common.css" />
|
|
<link rel="stylesheet" type="text/css" href="../../common/prettify.css" />
|
|
<script type="text/javascript" src="../../common/prettify.js"></script>
|
|
</head>
|
|
<body onload="prettyPrint()">
|
|
<h1>Vert.x Connector Service Example</h1>
|
|
|
|
<p>This example shows you how to configure HornetQ to use the Vert.x Connector Service.</p>
|
|
|
|
<p>HornetQ 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.
|
|
</p>
|
|
|
|
<p>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 HornetQ queue by the incoming connector. The outgoing connector listens to
|
|
the HornetQ queue and forwards the message from HornetQ to Vert.x event bus on the outgoing connector's address.
|
|
The verticle finally receives the message from it's event bus.</p>
|
|
|
|
<p>For more information on Vert.x concept please visit the <a href="http://vertx.io/">Vertx site</a></p>
|
|
|
|
<h2>Example step-by-step</h2>
|
|
<p><i>To run the server, simply type <code>mvn verify</code>
|
|
from this directory.</p>
|
|
|
|
<ol>
|
|
<li>First we need to create a Vert.x PlatformManager</li>
|
|
<pre class="prettyprint">
|
|
<code>platformManager = PlatformLocator.factory.createPlatformManager(PORT, HOST);</code>
|
|
</pre>
|
|
|
|
<li>We deploy a Verticle using the platformManager</li>
|
|
<pre class="prettyprint">
|
|
<code>String verticle = "org.apache.activemq.core.example.ExampleVerticle";
|
|
platformManager.deployVerticle(verticle, null, new URL[0], 1, null,
|
|
new Handler<AsyncResult<String>>(){
|
|
|
|
@Override
|
|
public void handle(AsyncResult<String> result)
|
|
{
|
|
if (!result.succeeded())
|
|
{
|
|
throw new RuntimeException("failed to deploy verticle", result.cause());
|
|
}
|
|
latch0.countDown();
|
|
}
|
|
|
|
});</code>
|
|
</pre>
|
|
|
|
<li>We register a message handler with the event bus in the Verticle to listen on the outgoing connector's address.</li>
|
|
<pre class="prettyprint">
|
|
<code>EventBus eventBus = vertx.eventBus();
|
|
eventBus.registerHandler(VertxConnectorExample.OUTGOING,
|
|
new Handler<Message<?>>() {
|
|
@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();
|
|
}
|
|
});
|
|
</code>
|
|
</pre>
|
|
|
|
<li>We send a message to incoming connector's address via event bus</li>
|
|
<pre class="prettyprint">
|
|
<code>
|
|
EventBus bus = platformManager.vertx().eventBus();
|
|
bus.send(INCOMING, MSG);
|
|
</code>
|
|
</pre>
|
|
|
|
<li>The message will eventually arrives at the Verticle's message handler.</li>
|
|
</ol>
|
|
</body>
|
|
</html>
|