mirror of
https://github.com/apache/activemq-artemis.git
synced 2025-02-06 10:09:01 +00:00
To reproduce this commit, apply a replace regex rule using: search regex: /\*\*\n \* Licensed replace: /\*\n \* Licensed These files had to be changed manually: artemis-selector/src/main/javacc/HyphenatedParser.jj artemis-selector/src/main/javacc/StrictParser.jj artemis-website/src/main/resources/styles/impact/css/pygmentize.css artemis-website/src/main/resources/styles/impact/css/site.css
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <html> <head> <title>ActiveMQ Artemis 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 ActiveMQ Artemis to use the Vert.x Connector Service.</p> <p>ActiveMQ Artemis 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 ActiveMQ Artemis queue by the incoming connector. The outgoing connector listens to the ActiveMQ Artemis queue and forwards the message from ActiveMQ Artemis 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.artemis.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>