@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(); }); } }
connection.open(); ProtonReceiver receiver = connection.createReceiver(address); receiver.setPrefetch(0); receiver.openHandler(r -> receiver.flow(1));
private static Future<ProtonReceiver> openReceiver(final ProtonConnection openConnection, final ProtonMessageHandler messageHandler) { final Future<ProtonReceiver> result = Future.future(); openConnection.createReceiver(AuthenticationConstants.ENDPOINT_NAME_AUTHENTICATION).openHandler(result.completer()).handler(messageHandler).open(); return result; } }
/** * Setup all AMQP endpoints */ private void setupAmqpEndpoits() { // NOTE : Last Will and Testament Service endpoint is opened only if MQTT client provides will information // The receiver on the unique client publish address will be opened only after // connection is established (and CONNACK sent to the MQTT client) // setup and open AMQP endpoint for receiving on unique client control/publish addresses ProtonReceiver receiverControl = this.connection.createReceiver(String.format(AmqpReceiverEndpoint.CLIENT_CONTROL_ENDPOINT_TEMPLATE, this.mqttEndpoint.clientIdentifier())); ProtonReceiver receiverPublish = this.connection.createReceiver(String.format(AmqpReceiverEndpoint.CLIENT_PUBLISH_ENDPOINT_TEMPLATE, this.mqttEndpoint.clientIdentifier())); this.rcvEndpoint = new AmqpReceiverEndpoint(new AmqpReceiver(receiverControl, receiverPublish)); // setup and open AMQP endpoint to Subscription Service ProtonSender ssSender = this.connection.createSender(AmqpSubscriptionServiceEndpoint.SUBSCRIPTION_SERVICE_ENDPOINT); this.ssEndpoint = new AmqpSubscriptionServiceEndpoint(ssSender); // setup and open AMQP endpoint for publishing ProtonSender senderPubrel = this.connection.createSender(String.format(AmqpPublishEndpoint.AMQP_CLIENT_PUBREL_ENDPOINT_TEMPLATE, this.mqttEndpoint.clientIdentifier())); this.pubEndpoint = new AmqpPublishEndpoint(senderPubrel); this.rcvEndpoint.openControl(); this.ssEndpoint.open(); this.pubEndpoint.open(); }
private void createReceiver(Vertx vertx, String address, CompletableFuture<Void> promise, int retries) { receiver = connection.createReceiver(address); Source source = new Source(); source.setDynamic(true); receiver.setSource(source); receiver.openHandler(h -> { if (h.succeeded()) { context = vertx.getOrCreateContext(); replyTo = receiver.getRemoteSource().getAddress(); promise.complete(null); } else { if (retries > maxRetries) { promise.completeExceptionally(h.cause()); } else { log.info("Error creating receiver, retries = {}", retries); vertx.setTimer(1000, id -> createReceiver(vertx, address, promise, retries + 1)); } } }); receiver.handler(((protonDelivery, message) -> { try { replies.put(message); ProtonHelper.accepted(protonDelivery, true); } catch (Exception e) { ProtonHelper.rejected(protonDelivery, true); } })); receiver.open(); }
private void connectionOpened(ProtonConnection conn, String linkName, Source source) { ProtonReceiver receiver = conn.createReceiver(source.getAddress(), new ProtonLinkOptions().setLinkName(linkName)); receiver.setSource(source); receiver.setPrefetch(0);
source.setDurable(TerminusDurability.UNSETTLED_STATE); ProtonReceiver receiver = connection.createReceiver(address, new ProtonLinkOptions().setLinkName(containerId));
final ProtonReceiver receiver = con.createReceiver(sourceAddress); receiver.setAutoAccept(true); receiver.setQoS(qos);
ProtonReceiver receiver = conn.createReceiver(testName); receiver.handler((d, m) -> { Section body = m.getBody();