@Override public void start() throws Exception { ProtonClient client = ProtonClient.create(vertx); client.connect("localhost", 5672, res -> { if(!res.succeeded()) { System.out.println("Connect failed: " + res.cause()); return; } ProtonConnection connection = res.result(); connection.open(); connection.createReceiver(address).handler((delivery, msg) -> { String content = (String) ((AmqpValue) msg.getBody()).getValue(); System.out.println("Received message with content: " + content); // By default, receivers automatically accept (and settle) the delivery // when the handler returns, if no other disposition has been applied. // To change this and always manage dispositions yourself, use the // setAutoAccept method on the receiver. }).open(); }); } }
ProtonClient client = ProtonClient.create(vertx); client.connect("localhost", 5672, res -> { if(!res.succeeded()) { System.out.println("Connect failed: " + res.cause());
public void connect(String host, int port, ProtonClientOptions clientOptions, String address, CompletableFuture<Void> promise) { if (connection != null) { log.debug("Already connected"); promise.complete(null); return; } ProtonClient client = ProtonClient.create(vertx); log.debug("Connecting to {}:{}", host, port); client.connect(clientOptions, host, port, result -> { if (result.succeeded()) { log.debug("Connected to {}:{}", host, port); connection = result.result(); connection.setContainer(containerId); createSender(vertx, address, promise, 0); connection.open(); } else { log.info("Connection to {}:{} failed", host, port, result.cause()); promise.completeExceptionally(result.cause()); } }); }
public void send(String address, List<Message> messages, long timeout, TimeUnit timeUnit) throws InterruptedException { ProtonClient client = ProtonClient.create(vertx); CountDownLatch latch = new CountDownLatch(1); Queue<Message> messageQueue = new ArrayDeque<>(messages); client.connect(host, port, connectEvent -> { if (connectEvent.succeeded()) { ProtonConnection connection = connectEvent.result(); connection.open(); ProtonSender sender = connection.createSender(address); sender.openHandler(senderOpenEvent -> { if (senderOpenEvent.succeeded()) { sendNext(connection, sender, messageQueue, latch); } }); sender.open(); } }); boolean ok = latch.await(timeout, timeUnit); if (!ok) { throw new RuntimeException("Sending messages timed out, " + messageQueue.size() + " messages unsent"); } }
CountDownLatch latch = new CountDownLatch(1); List<Message> messages = new ArrayList<>(); client.connect(host, port, connectEvent -> { if (connectEvent.succeeded()) { ProtonConnection connection = connectEvent.result();
/** * Connect to an AMQP server/router * * @param startFuture */ private void connectAmqpClient(Future<Void> startFuture) { // the health server starts before connection is made to an AMQP server/router // because the bridge is already alive but not ready yet this.startHealthServer(); this.client = ProtonClient.create(this.vertx); String host = this.bridgeConfigProperties.getEndpointConfigProperties().getHost(); int port = this.bridgeConfigProperties.getEndpointConfigProperties().getPort(); ProtonClientOptions options = this.createClientOptions(); this.client.connect(options, host, port, ar -> { if (ar.succeeded()) { ProtonConnection connection = ar.result(); connection.setContainer(CONTAINER_ID); this.processConnection(connection); log.info("AMQP-Kafka Bridge started and connected in client mode to {}:{}", host, port); log.info("Kafka bootstrap servers {}", this.bridgeConfigProperties.getKafkaConfigProperties().getBootstrapServers()); this.isReady = true; startFuture.complete(); } else { log.error("Error connecting AMQP-Kafka Bridge as client", ar.cause()); startFuture.fail(ar.cause()); } }); }
ProtonClient client = ProtonClient.create(vertx); Endpoint endpoint = clientOptions.getEndpoint(); client.connect(clientOptions.getProtonClientOptions(), endpoint.getHost(), endpoint.getPort(), clientOptions.getUsername(), clientOptions.getPassword(), connection -> { if (connection.succeeded()) { ProtonConnection conn = connection.result();
private void startSender() { ProtonClient client = ProtonClient.create(vertx); log.info(this + ": starting sender"); client.connect(getOptions(), to.hostname(), to.port(), event -> { if (event.succeeded()) { ProtonConnection connection = event.result();
@Override public void connect( final ProtonClientOptions options, final String username, final String password, final Handler<AsyncResult<ProtonConnection>> closeHandler, final Handler<ProtonConnection> disconnectHandler, final Handler<AsyncResult<ProtonConnection>> connectionResultHandler) { if (vertx == null) { throw new IllegalStateException("Vert.x instance must be set"); } else if (config == null) { throw new IllegalStateException("Client configuration must be set"); } Objects.requireNonNull(connectionResultHandler); final ProtonClientOptions clientOptions = options != null ? options : createClientOptions(); final String effectiveUsername = username == null ? config.getUsername() : username; final String effectivePassword = password == null ? config.getPassword() : password; addOptions(clientOptions, effectiveUsername, effectivePassword); final ProtonClient client = protonClient != null ? protonClient : ProtonClient.create(vertx); logger.debug("connecting to AMQP 1.0 container [{}://{}:{}]", clientOptions.isSsl() ? "amqps" : "amqp", config.getHost(), config.getPort()); client.connect( clientOptions, config.getHost(), config.getPort(), effectiveUsername, effectivePassword, conAttempt -> handleConnectionAttemptResult(conAttempt, clientOptions, closeHandler, disconnectHandler, connectionResultHandler)); }
@Override public void connect( final ProtonClientOptions options, final String username, final String password, final Handler<AsyncResult<ProtonConnection>> closeHandler, final Handler<ProtonConnection> disconnectHandler, final Handler<AsyncResult<ProtonConnection>> connectionResultHandler) { if (vertx == null) { throw new IllegalStateException("Vert.x instance must be set"); } else if (config == null) { throw new IllegalStateException("Client configuration must be set"); } Objects.requireNonNull(connectionResultHandler); final ProtonClientOptions clientOptions = options != null ? options : createClientOptions(); final String effectiveUsername = username == null ? config.getUsername() : username; final String effectivePassword = password == null ? config.getPassword() : password; addOptions(clientOptions, effectiveUsername, effectivePassword); final ProtonClient client = protonClient != null ? protonClient : ProtonClient.create(vertx); logger.debug("connecting to AMQP 1.0 container [{}://{}:{}]", clientOptions.isSsl() ? "amqps" : "amqp", config.getHost(), config.getPort()); client.connect( clientOptions, config.getHost(), config.getPort(), effectiveUsername, effectivePassword, conAttempt -> handleConnectionAttemptResult(conAttempt, clientOptions, closeHandler, disconnectHandler, connectionResultHandler)); }
private void startReceiver(ProtonSender sender, String containerId) { log.info("Starting receiver"); ProtonClient client = ProtonClient.create(vertx); client.connect(getOptions(), from.hostname(), from.port(), event -> { if (event.succeeded()) { ProtonConnection connection = event.result();
this.client.connect(clientOptions, address, port, userName, password, done -> {
client.connect("localhost", port, res -> { context.assertTrue(res.succeeded());
client.connect("localhost", port, res -> { context.assertTrue(res.succeeded());
client.connect("localhost", port, res -> { context.assertTrue(res.succeeded());
client.connect("localhost", getBrokerAmqpConnectorPort(), res -> { context.assertTrue(res.succeeded());
client.connect("localhost", port, res -> { context.assertTrue(res.succeeded());
client.connect("localhost", port, res -> { context.assertTrue(res.succeeded());