@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); }); }); } }
/** * Shuts the bridge down, closing the underlying connection. * @param resultHandler the result handler */ public void close(Handler<AsyncResult<Void>> resultHandler) { delegate.close(resultHandler); }
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)); } }
@Test(timeout = 20000) public void testRestrictSaslMechanisms(TestContext context) throws Exception { AmqpBridgeOptions options = new AmqpBridgeOptions(); // Try with the wrong password, with anonymous access disabled, expect start to fail doStartWithGivenCredentialsTestImpl(context, options, USERNAME_GUEST, "wrongpassword", false); // Try with the wrong password, with anonymous access enabled, expect start still to fail anonymousAccessAllowed = true; restartBroker(); doStartWithGivenCredentialsTestImpl(context, options, USERNAME_GUEST, "wrongpassword", false); // Now restrict the allows SASL mechanisms to ANONYMOUS, then expect start to succeed as it wont use the invalid // credentials options.addEnabledSaslMechanism("ANONYMOUS"); doStartWithGivenCredentialsTestImpl(context, options, USERNAME_GUEST, "wrongpassword", true); }
/** * 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())); } } }); }
private void doConnectWithGivenCredentialsTestImpl(TestContext context, String username, String password, boolean expectConnectToSucceed) { doStartWithGivenCredentialsTestImpl(context, new AmqpBridgeOptions(), username, password, expectConnectToSucceed); }
/** * 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); }
public void restartBroker() throws Exception { stopBroker(brokerService); brokerService = restartBroker(brokerService); }
@Test(timeout = 20000) public void testConnectAnonymousWithoutUserPass(TestContext context) throws Exception { doConnectWithGivenCredentialsTestImpl(context, null, null, false); anonymousAccessAllowed = true; restartBroker(); doConnectWithGivenCredentialsTestImpl(context, null, null, true); }
@Test(timeout = 20000) public void testConnectionClosedRemotelyCallsEndHandler(TestContext context) throws Exception { doConnectionEndHandlerCalledTestImpl(context, false); }
@Test(timeout = 20000) public void testSenderClosedRemotelyWithErrorCallsExceptionHandler(TestContext context) throws Exception { doSenderClosedRemotelyCallsExceptionHandlerTestImpl(context, true); }
public void stopBroker() throws Exception { stopBroker(brokerService); brokerService = null; }
@Test(timeout = 20000) public void testConnectionHostnameAndContainerID(TestContext context) throws Exception { doConnectionHostnameAndContainerIDTestImpl(context, true); doConnectionHostnameAndContainerIDTestImpl(context, false); }
@Test(timeout = 20000) public void testConnectWithSslWithRequiredClientKeySucceeds(TestContext context) throws Exception { doClientCertificateTestImpl(context, true); }
@Test(timeout = 20000) public void testConnectWithoutHostnameVerification(TestContext context) throws Exception { doHostnameVerificationTestImpl(context, false); }
@Test(timeout = 20000) public void testConnectWithValidUserPassSucceeds(TestContext context) throws Exception { doConnectWithGivenCredentialsTestImpl(context, USERNAME_GUEST, PASSWORD_GUEST, true); }
/** * 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())); } } }); }
@Test(timeout = 20000) public void testConnectionDisconnectedCallsEndHandler(TestContext context) throws Exception { doConnectionEndHandlerCalledTestImpl(context, false); }
@Test(timeout = 20000) public void testSenderClosedRemotelyCallsExceptionHandler(TestContext context) throws Exception { doSenderClosedRemotelyCallsExceptionHandlerTestImpl(context, false); }