@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); }); }); } }
/** * 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; }
/** * 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; }
String replyContent = "myStringReply"; AmqpBridge bridge = AmqpBridge.create(vertx); bridge.start("localhost", getBrokerAmqpConnectorPort(), startResult -> { context.assertTrue(startResult.succeeded());
AmqpBridge bridge = AmqpBridge.create(vertx, options); bridge.start("localhost", getBrokerAmqpConnectorPort(), startResult -> { context.assertTrue(startResult.succeeded());
public static io.vertx.amqpbridge.AmqpBridge create(io.vertx.amqpbridge.AmqpBridge j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> options) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.amqpbridge.AmqpBridge.create(vertx, options != null ? new io.vertx.amqpbridge.AmqpBridgeOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null)); } }
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(); } }
@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(); } }
AmqpBridge bridge = AmqpBridge.create(vertx, options); bridge.endHandler(x -> { LOG.error("End handler called unexpectedly");
AmqpBridge bridge = AmqpBridge.create(vertx, options); bridge.start("localhost", server.actualPort(), res -> { LOG.trace("Startup complete");
@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(); }
@Test(timeout = 20000) public void testConnectWithSslToServerWhileUsingTrustAll(TestContext context) throws Exception { Async async = context.async(); ProtonServerOptions serverOptions = new ProtonServerOptions(); serverOptions.setSsl(true); PfxOptions serverPfxOptions = new PfxOptions().setPath(KEYSTORE).setPassword(PASSWORD); serverOptions.setPfxKeyCertOptions(serverPfxOptions); mockServer = new MockServer(vertx, conn -> { handleBridgeStartupProcess(conn, context); }, serverOptions); // Try to start the bridge and expect it to succeed due to trusting all certs AmqpBridgeOptions bridgeOptions = new AmqpBridgeOptions(); bridgeOptions.setSsl(true); bridgeOptions.setTrustAll(true); AmqpBridge bridge = AmqpBridge.create(vertx, bridgeOptions); bridge.start("localhost", mockServer.actualPort(), res -> { // Expect start to succeed context.assertTrue(res.succeeded(), "expected start to suceed due to trusting all certs"); async.complete(); }); async.awaitSuccess(); }
AmqpBridge bridge = AmqpBridge.create(vertx, options); bridge.start(tcpConnectionHostname, server.actualPort(), res -> { context.assertTrue(res.succeeded(), "Expected start to succeed");
AmqpBridge bridge = AmqpBridge.create(vertx, bridgeOptions); bridge.start("localhost", mockServer.actualPort(), res -> { if (verifyHost) {
@Test(timeout = 20000) public void testConnectWithSslSucceeds(TestContext context) throws Exception { Async async = context.async(); ProtonServerOptions serverOptions = new ProtonServerOptions(); serverOptions.setSsl(true); PfxOptions serverPfxOptions = new PfxOptions().setPath(KEYSTORE).setPassword(PASSWORD); serverOptions.setPfxKeyCertOptions(serverPfxOptions); mockServer = new MockServer(vertx, conn -> { handleBridgeStartupProcess(conn, context); }, serverOptions); // Start the bridge and verify is succeeds AmqpBridgeOptions bridgeOptions = new AmqpBridgeOptions(); bridgeOptions.setSsl(true); PfxOptions clientPfxOptions = new PfxOptions().setPath(TRUSTSTORE).setPassword(PASSWORD); bridgeOptions.setPfxTrustOptions(clientPfxOptions); AmqpBridge bridge = AmqpBridge.create(vertx, bridgeOptions); bridge.start("localhost", mockServer.actualPort(), res -> { // Expect start to succeed context.assertTrue(res.succeeded(), "expected start to suceed"); async.complete(); }); async.awaitSuccess(); }
@Test(timeout = 20000) public void testConnectWithSslToServerWithUntrustedKeyFails(TestContext context) throws Exception { Async async = context.async(); ProtonServerOptions serverOptions = new ProtonServerOptions(); serverOptions.setSsl(true); PfxOptions serverPfxOptions = new PfxOptions().setPath(KEYSTORE).setPassword(PASSWORD); serverOptions.setPfxKeyCertOptions(serverPfxOptions); mockServer = new MockServer(vertx, conn -> { handleBridgeStartupProcess(conn, context); }, serverOptions); // Try to start the bridge and expect it to fail due to not trusting the server AmqpBridgeOptions bridgeOptions = new AmqpBridgeOptions(); bridgeOptions.setSsl(true); PfxOptions pfxOptions = new PfxOptions().setPath(OTHER_CA_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 being trusted context.assertFalse(res.succeeded(), "expected start to fail due to untrusted server"); async.complete(); }); async.awaitSuccess(); }
@Test(timeout = 20000) public void testBasicStartup(TestContext context) throws Exception { context.assertEquals(0L, getBrokerAdminView(context).getTotalConnectionsCount(), "unexpected total connection count before"); context.assertEquals(0, getBrokerAdminView(context).getCurrentConnectionsCount(), "unexpected current connection count before"); Async async = context.async(); AmqpBridge bridge = AmqpBridge.create(vertx); bridge.start("localhost", getBrokerAmqpConnectorPort(), res -> { LOG.trace("Startup complete"); context.assertTrue(res.succeeded()); context.assertEquals(1L, getBrokerAdminView(context).getTotalConnectionsCount(), "unexpected total connection count during"); context.assertEquals(1, getBrokerAdminView(context).getCurrentConnectionsCount(), "unexpected current connection count during"); bridge.close(shutdownRes -> { LOG.trace("Shutdown complete"); context.assertTrue(shutdownRes.succeeded()); context.assertEquals(1L, getBrokerAdminView(context).getTotalConnectionsCount(), "unexpected total connection count after"); context.assertEquals(0, getBrokerAdminView(context).getCurrentConnectionsCount(), "unexpected current connection count after"); async.complete(); }); }); async.awaitSuccess(); }
AmqpBridge bridge = AmqpBridge.create(vertx, bridgeOptions); bridge.start("localhost", mockServer.actualPort(), res -> { if (supplyClientCert) {