@Override public void start() throws Exception { AmqpBridge bridge = AmqpBridge.create(vertx); // Start the bridge, then use the event loop thread to process things thereafter. bridge.start("localhost", 5672, res -> { if(!res.succeeded()) { System.out.println("Bridge startup failed: " + res.cause()); return; } // Set up a producer using the bridge, send a message with it. MessageProducer<JsonObject> producer = bridge.createProducer("myAmqpAddress"); // Schedule sending of a message every second System.out.println("Producer created, scheduling sends."); vertx.setPeriodic(1000, v -> { JsonObject amqpMsgPayload = new JsonObject(); amqpMsgPayload.put(AmqpConstants.BODY, "myStringContent" + count); producer.send(amqpMsgPayload); System.out.println("Sent message: " + count++); }); }); }
@Override public void start() throws Exception { AmqpBridge bridge = AmqpBridge.create(vertx); // Start the bridge, then use the event loop thread to process things thereafter. bridge.start("localhost", 5672, res -> { if(!res.succeeded()) { System.out.println("Bridge startup failed: " + res.cause()); return; } // Set up a consumer using the bridge, register a handler for it. MessageConsumer<JsonObject> consumer = bridge.createConsumer("myAmqpAddress"); consumer.handler(vertxMsg -> { JsonObject amqpMsgPayload = vertxMsg.body(); Object amqpBody = amqpMsgPayload.getValue(AmqpConstants.BODY); // Print body of received AMQP message System.out.println("Received a message with body: " + amqpBody); }); }); } }
AmqpBridge bridge = AmqpBridge.create(vertx); bridge.start("localhost", PORT, res -> { if (res.succeeded()) { MessageConsumer<JsonObject> consumer = bridge.createConsumer(ADDRESS); consumer.handler(vertxMsg -> { System.out.println("Received message: " + vertxMsg.body().getValue("body")); AmqpBridge bridge2 = AmqpBridge.create(vertx); bridge2.start("localhost", PORT, res -> { if (res.succeeded()) { MessageProducer<JsonObject> producer = bridge2.createProducer(ADDRESS); vertx.setPeriodic(1000, id -> { producer.send(new JsonObject().put("body", "the-content"));
private void doStartWithGivenCredentialsTestImpl(TestContext context, AmqpBridgeOptions options, String username, String password, boolean expectStartToSucceed) { Async async = context.async(); // Start the bridge and verify whether it succeeds AmqpBridge bridge = AmqpBridge.create(vertx, options); bridge.start("localhost", getBrokerAmqpConnectorPort(), username, password, res -> { if (expectStartToSucceed) { // Expect connect to succeed context.assertTrue(res.succeeded()); } else { // Expect connect to fail context.assertFalse(res.succeeded()); } LOG.trace("Bridge start complete"); async.complete(); }); async.awaitSuccess(); } }
AmqpBridge bridge = AmqpBridge.create(vertx, options); bridge.endHandler(x -> { LOG.error("End handler called unexpectedly"); latch.countDown(); }); bridge.start("localhost", server.actualPort(), res -> { LOG.trace("Startup complete"); bridge.close(shutdownRes -> { context.assertTrue(shutdownRes.succeeded()); LOG.trace("Shutdown complete");
/** * Creates a Bridge. * @param vertx the vertx instance to use * @return the (not-yet-started) bridge. */ public static io.vertx.rxjava.amqpbridge.AmqpBridge create(io.vertx.rxjava.core.Vertx vertx) { io.vertx.rxjava.amqpbridge.AmqpBridge ret = io.vertx.rxjava.amqpbridge.AmqpBridge.newInstance(io.vertx.amqpbridge.AmqpBridge.create(vertx.getDelegate())); return ret; }
@Test(timeout = 20000) public void testCloseBridgeThatWasntStarted(TestContext context) throws Exception { stopBroker(); Async async = context.async(); AmqpBridge bridge = AmqpBridge.create(vertx); bridge.close(shutdownRes -> { LOG.trace("Shutdown complete"); context.assertTrue(shutdownRes.succeeded()); async.complete(); }); async.awaitSuccess(); } }
/** * Starts the bridge, establishing the underlying connection. * @param hostname the host name to connect to * @param port the port to connect to * @param resultHandler the result handler */ public void start(String hostname, int port, Handler<AsyncResult<io.vertx.rxjava.amqpbridge.AmqpBridge>> resultHandler) { delegate.start(hostname, port, new Handler<AsyncResult<io.vertx.amqpbridge.AmqpBridge>>() { public void handle(AsyncResult<io.vertx.amqpbridge.AmqpBridge> ar) { if (ar.succeeded()) { resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.amqpbridge.AmqpBridge.newInstance(ar.result()))); } else { resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); }
/** * Creates a consumer on the given AMQP address. * * This method MUST be called from the bridge Context thread, as used in the result handler callback from the start * methods. The bridge MUST be successfully started before the method is called. * @param amqpAddress the address to consume from * @return the consumer */ public <T> io.vertx.rxjava.core.eventbus.MessageConsumer<T> createConsumer(String amqpAddress) { io.vertx.rxjava.core.eventbus.MessageConsumer<T> ret = io.vertx.rxjava.core.eventbus.MessageConsumer.newInstance(delegate.createConsumer(amqpAddress), io.vertx.lang.rx.TypeArg.unknown()); return ret; }
/** * Creates a producer to the given AMQP address. * * This method MUST be called from the bridge Context thread, as used in the result handler callback from the start * methods. The bridge MUST be successfully started before the method is called. * @param amqpAddress the address to produce to * @return the producer */ public <T> io.vertx.rxjava.core.eventbus.MessageProducer<T> createProducer(String amqpAddress) { io.vertx.rxjava.core.eventbus.MessageProducer<T> ret = io.vertx.rxjava.core.eventbus.MessageProducer.newInstance(delegate.createProducer(amqpAddress), io.vertx.lang.rx.TypeArg.unknown()); return ret; }
/** * Set an end handler. This will fire if the underlying connection is unexpectedly disconnected or remotely closed. * @param endHandler the handler */ public void endHandler(Handler<Void> endHandler) { delegate.endHandler(endHandler); }
/** * Shuts the bridge down, closing the underlying connection. * @param resultHandler the result handler */ public void close(Handler<AsyncResult<Void>> resultHandler) { delegate.close(resultHandler); }
AmqpBridge bridge = AmqpBridge.create(vertx, options); bridge.start("localhost", getBrokerAmqpConnectorPort(), startResult -> { context.assertTrue(startResult.succeeded()); MessageProducer<JsonObject> producer = bridge.createProducer(destinationName); bridge.close(shutdownRes -> { LOG.trace("Shutdown complete"); context.assertTrue(shutdownRes.succeeded());
@Test(timeout = 20000) public void testConnectWithSslToNonSslServerFails(TestContext context) throws Exception { Async async = context.async(); // Create a server that doesn't use ssl ProtonServerOptions serverOptions = new ProtonServerOptions(); serverOptions.setSsl(false); mockServer = new MockServer(vertx, conn -> { handleBridgeStartupProcess(conn, context); }, serverOptions); // Try to start the bridge and expect it to fail AmqpBridgeOptions bridgeOptions = new AmqpBridgeOptions(); bridgeOptions.setSsl(true); PfxOptions pfxOptions = new PfxOptions().setPath(TRUSTSTORE).setPassword(PASSWORD); bridgeOptions.setPfxTrustOptions(pfxOptions); AmqpBridge bridge = AmqpBridge.create(vertx, bridgeOptions); bridge.start("localhost", mockServer.actualPort(), res -> { // Expect start to fail due to remote peer not doing SSL context.assertFalse(res.succeeded(), "expected start to fail due to server not using secure transport"); async.complete(); }); async.awaitSuccess(); }
AmqpBridge bridge = AmqpBridge.create(vertx, options); bridge.endHandler(x -> { LOG.trace("End handler called"); asyncEndHandlerCalled.complete(); bridge.close(shutdownRes -> { context.assertTrue(shutdownRes.succeeded()); LOG.trace("Shutdown complete"); }); bridge.start("localhost", server.actualPort(), res -> { LOG.trace("Startup complete"); });
/** * Creates a Bridge with the given options. * @param vertx the vertx instance to use * @param options the options * @return the (not-yet-started) bridge. */ public static io.vertx.rxjava.amqpbridge.AmqpBridge create(io.vertx.rxjava.core.Vertx vertx, AmqpBridgeOptions options) { io.vertx.rxjava.amqpbridge.AmqpBridge ret = io.vertx.rxjava.amqpbridge.AmqpBridge.newInstance(io.vertx.amqpbridge.AmqpBridge.create(vertx.getDelegate(), options)); return ret; }
/** * Starts the bridge, establishing the underlying connection. * @param hostname the host name to connect to * @param port the port to connect to * @param username the username * @param password the password * @param resultHandler the result handler */ public void start(String hostname, int port, String username, String password, Handler<AsyncResult<io.vertx.rxjava.amqpbridge.AmqpBridge>> resultHandler) { delegate.start(hostname, port, username, password, new Handler<AsyncResult<io.vertx.amqpbridge.AmqpBridge>>() { public void handle(AsyncResult<io.vertx.amqpbridge.AmqpBridge> ar) { if (ar.succeeded()) { resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.amqpbridge.AmqpBridge.newInstance(ar.result()))); } else { resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); }
String replyContent = "myStringReply"; AmqpBridge bridge = AmqpBridge.create(vertx); bridge.start("localhost", getBrokerAmqpConnectorPort(), startResult -> { context.assertTrue(startResult.succeeded()); MessageProducer<JsonObject> producer = bridge.createProducer(destinationName); bridge.close(shutdownRes -> { LOG.trace("Shutdown complete"); context.assertTrue(shutdownRes.succeeded()); LOG.trace("Client sent msg"); MessageConsumer<JsonObject> consumer = bridge.createConsumer(destinationName); consumer.handler(msg -> { JsonObject receivedMsgBody = msg.body();