@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); }); }); } }
/** * 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())); } } }); }
/** * 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())); } } }); }
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(); } }
bridge.start("localhost", port, res -> {
bridge.start("localhost", getBrokerAmqpConnectorPort(), startResult -> { context.assertTrue(startResult.succeeded());
bridge.start("localhost", getBrokerAmqpConnectorPort(), startResult -> { context.assertTrue(startResult.succeeded());
}); 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(); }
bridge.start("localhost", server.actualPort(), res -> { LOG.trace("Startup complete"); asyncMetaData.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(); }
bridge.start(tcpConnectionHostname, server.actualPort(), res -> { context.assertTrue(res.succeeded(), "Expected start to succeed");
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(); }
bridge.start("localhost", server.actualPort(), res -> { LOG.trace("Startup complete");
@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(); }
bridge.start("localhost", mockServer.actualPort(), res -> { if (supplyClientCert) {