Java Code Examples for io.vertx.proton.ProtonSender#open()
The following examples show how to use
io.vertx.proton.ProtonSender#open() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSender.java From enmasse with Apache License 2.0 | 6 votes |
@Override public void connectionOpened(ProtonConnection connection) { ProtonSender sender = connection.createSender(linkOptions.getTarget().getAddress()); sender.setTarget(linkOptions.getTarget()); sender.setQoS(clientOptions.getQos()); sender.openHandler(result -> { if (result.succeeded()) { log.info("Sender link '" + sender.getTarget().getAddress() + "' opened, sending messages"); connectPromise.complete(null); sendMessages(connection, sender); } else { handleError(connection, sender.getRemoteCondition()); } }); sender.closeHandler(result -> handleError(connection, sender.getRemoteCondition())); sender.open(); }
Example 2
Source File: AmqpCliClient.java From hono with Eclipse Public License 2.0 | 5 votes |
/** * Creates anonymous sender link on the established connection * to the AMQP org.eclipse.hono.cli.app.adapter. * * @return A future containing the sender. The future will be succeeded * once the link is open. * @throws IllegalStateException if the connection to the org.eclipse.hono.cli.app.adapter is * not established. */ protected Future<ProtonSender> createSender() { if (adapterConnection == null || adapterConnection.isDisconnected()) { throw new IllegalStateException("connection to AMQP org.eclipse.hono.cli.app.adapter not established"); } final Promise<ProtonSender> result = Promise.promise(); final ProtonSender sender = adapterConnection.createSender(null); sender.openHandler(result); sender.open(); return result.future(); }
Example 3
Source File: HelloWorld.java From vertx-proton with Apache License 2.0 | 5 votes |
private static void helloWorldSendAndConsumeExample(ProtonConnection connection) { connection.open(); // Receive messages from queue "foo" (using an ActiveMQ style address as example). String address = "queue://foo"; connection.createReceiver(address).handler((delivery, msg) -> { Section body = msg.getBody(); if (body instanceof AmqpValue) { String content = (String) ((AmqpValue) body).getValue(); System.out.println("Received message with content: " + content); } // By default, the receiver automatically accepts (and settles) 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(); // Create an anonymous (no address) sender, have the message carry its destination ProtonSender sender = connection.createSender(null); // Create a message to send, have it carry its destination for use with the anonymous sender Message message = message(address, "Hello World from client"); // Can optionally add an openHandler or sendQueueDrainHandler // to await remote sender open completing or credit to send being // granted. But here we will just buffer the send immediately. sender.open(); System.out.println("Sending message to server"); sender.send(message, delivery -> { System.out.println(String.format("The message was received by the server: remote state=%s, remotely settled=%s", delivery.getRemoteState(), delivery.remotelySettled())); }); }
Example 4
Source File: RequestResponseEndpoint.java From hono with Eclipse Public License 2.0 | 4 votes |
/** * Handles a client's request to establish a link for receiving responses to service invocations. * <p> * This method registers a consumer on the vert.x event bus for the given reply-to address. Response messages * received over the event bus are transformed into AMQP messages using the {@link #getAmqpReply(EventBusMessage)} * method and sent to the client over the established link. * * @param con The AMQP connection that the link is part of. * @param sender The link to establish. * @param replyToAddress The reply-to address to create a consumer on the event bus for. */ @Override public final void onLinkAttach(final ProtonConnection con, final ProtonSender sender, final ResourceIdentifier replyToAddress) { if (!isValidReplyToAddress(replyToAddress)) { logger.debug("client [{}] provided invalid reply-to address", sender.getName()); sender.setCondition(ProtonHelper.condition(AmqpError.INVALID_FIELD, String.format("reply-to address must have the following format %s/<tenant>/<reply-address>", getName()))); sender.close(); return; } final String replyTo = replyToAddress.toString(); if (this.replyToSenderMap.containsKey(replyTo)) { logger.debug("client [{}] wanted to subscribe to already subscribed reply-to address [{}]", sender.getName(), replyTo); sender.setCondition(ProtonHelper.condition(AmqpError.ILLEGAL_STATE, String.format("reply-to address [%s] is already subscribed", replyTo))); sender.close(); return; } logger.debug("establishing response sender link with client [{}]", sender.getName()); sender.setQoS(ProtonQoS.AT_LEAST_ONCE); sender.setSource(sender.getRemoteSource()); sender.setTarget(sender.getRemoteTarget()); registerSenderForReplyTo(replyTo, sender); HonoProtonHelper.setCloseHandler(sender, remoteClose -> { logger.debug("client [{}] closed sender link", sender.getName()); unregisterSenderForReplyTo(replyTo); sender.close(); }); HonoProtonHelper.setDetachHandler(sender, remoteDetach -> { logger.debug("client [{}] detached sender link", sender.getName()); unregisterSenderForReplyTo(replyTo); sender.close(); }); sender.open(); }
Example 5
Source File: AbstractRequestResponseEndpoint.java From hono with Eclipse Public License 2.0 | 4 votes |
/** * Handles a client's request to establish a link for receiving responses to service invocations. * <p> * This method opens a sender for sending request replies back to the client. * * @param con The AMQP connection that the link is part of. * @param sender The link to establish. * @param replyToAddress The reply-to address to create a consumer on the event bus for. */ @Override public final void onLinkAttach(final ProtonConnection con, final ProtonSender sender, final ResourceIdentifier replyToAddress) { if (!isValidReplyToAddress(replyToAddress)) { logger.debug("client [{}] provided invalid reply-to address", sender.getName()); sender.setCondition(ProtonHelper.condition(AmqpError.INVALID_FIELD, String.format("reply-to address must have the following format %s/<tenant>/<reply-address>", getName()))); sender.close(); return; } final String replyTo = replyToAddress.toString(); if (this.replyToSenderMap.containsKey(replyTo)) { logger.debug("client [{}] wanted to subscribe to already subscribed reply-to address [{}]", sender.getName(), replyTo); sender.setCondition(ProtonHelper.condition(AmqpError.ILLEGAL_STATE, String.format("reply-to address [%s] is already subscribed", replyTo))); sender.close(); return; } logger.debug("establishing response sender link with client [{}]", sender.getName()); sender.setQoS(ProtonQoS.AT_LEAST_ONCE); sender.setSource(sender.getRemoteSource()); sender.setTarget(sender.getRemoteTarget()); registerSenderForReplyTo(replyTo, sender); HonoProtonHelper.setCloseHandler(sender, remoteClose -> { logger.debug("client [{}] closed sender link", sender.getName()); unregisterSenderForReplyTo(replyTo); sender.close(); }); HonoProtonHelper.setDetachHandler(sender, remoteDetach -> { logger.debug("client [{}] detached sender link", sender.getName()); unregisterSenderForReplyTo(replyTo); sender.close(); }); sender.open(); }