当前位置: 首页>>代码示例>>Java>>正文


Java ProtonSender.open方法代码示例

本文整理汇总了Java中io.vertx.proton.ProtonSender.open方法的典型用法代码示例。如果您正苦于以下问题:Java ProtonSender.open方法的具体用法?Java ProtonSender.open怎么用?Java ProtonSender.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.vertx.proton.ProtonSender的用法示例。


在下文中一共展示了ProtonSender.open方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newSender

import io.vertx.proton.ProtonSender; //导入方法依赖的package包/类
private Future<ProtonSender> newSender(
        final ProtonConnection connection,
        final ProtonSession session,
        final ResourceIdentifier address,
        final ProtonQoS qos,
        final Handler<ProtonSender> sendQueueDrainHandler) {

    Future<ProtonSender> result = Future.future();
    ProtonSender sender = session.createSender(getTenantOnlyTargetAddress(address));
    sender.setQoS(qos);
    sender.sendQueueDrainHandler(sendQueueDrainHandler);
    sender.openHandler(openAttempt -> {
        if (openAttempt.succeeded()) {
            LOG.debug(
                    "sender [{}] for container [{}] open",
                    address,
                    connection.getRemoteContainer());
            result.complete(openAttempt.result());
        } else {
            LOG.debug("could not open sender [{}] for container [{}]",
                    address,
                    connection.getRemoteContainer(), openAttempt.cause());
            result.fail(openAttempt.cause());
        }
    });
    sender.closeHandler(closed -> {
        if (closed.succeeded()) {
            LOG.debug("sender [{}] for container [{}] closed", address, connection.getRemoteContainer());
        }
    });
    sender.open();
    return result;
}
 
开发者ID:eclipse,项目名称:hono,代码行数:34,代码来源:SenderFactoryImpl.java

示例2: newMockSenderFactory

import io.vertx.proton.ProtonSender; //导入方法依赖的package包/类
public static SenderFactory newMockSenderFactory(final ProtonSender senderToCreate) {

        return (connection, address, qos, drainHandler) -> {
            senderToCreate.sendQueueDrainHandler(drainHandler);
            senderToCreate.open();
            return Future.succeededFuture(senderToCreate);
        };
    }
 
开发者ID:eclipse,项目名称:hono,代码行数:9,代码来源:TestSupport.java

示例3: onLinkAttach

import io.vertx.proton.ProtonSender; //导入方法依赖的package包/类
/**
 * Configure and check the sender link of the endpoint.
 * The sender link is used for the response to a received request and is driven by the vertx event bus.
 * It listens to the provided resource identifier of the endpoint as vertx event address and then sends the
 * constructed response.
 * Since the response is endpoint specific, it is an abstract method {@link #getAmqpReply(io.vertx.core.eventbus.Message)} and needs to be implemented
 * by the subclass.
 *
 * @param con The AMQP connection that the link is part of.
 * @param sender The ProtonSender that has already been created for this endpoint.
 * @param replyToAddress The resource identifier for the responses of this endpoint (see {@link ResourceIdentifier} for details).
 *                      Note that the reply address is different for each client and is passed in during link creation.
 */
@Override
public final void onLinkAttach(final ProtonConnection con, final ProtonSender sender, final ResourceIdentifier replyToAddress) {
    if (replyToAddress.getResourceId() == null) {
        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();
    } else {
        logger.debug("establishing sender link with client [{}]", sender.getName());
        final MessageConsumer<JsonObject> replyConsumer = vertx.eventBus().consumer(replyToAddress.toString(), message -> {
            // TODO check for correct session here...?
            logger.trace("forwarding reply to client [{}]: {}", sender.getName(), message.body());
            final Message amqpReply = getAmqpReply(message);
            sender.send(amqpReply);
        });

        sender.setQoS(ProtonQoS.AT_LEAST_ONCE);
        sender.closeHandler(senderClosed -> {
            logger.debug("client [{}] closed sender link, removing associated event bus consumer [{}]", sender.getName(), replyConsumer.address());
            replyConsumer.unregister();
            if (senderClosed.succeeded()) {
                senderClosed.result().close();
            }
        });
        sender.open();
    }
}
 
开发者ID:eclipse,项目名称:hono,代码行数:41,代码来源:RequestResponseEndpoint.java

示例4: connectionOpened

import io.vertx.proton.ProtonSender; //导入方法依赖的package包/类
@Override
public void connectionOpened(ProtonConnection connection) {
    ProtonSender sender = connection.createSender(linkOptions.getTarget().getAddress());
    sender.setTarget(linkOptions.getTarget());
    sender.setQoS(clientOptions.getQos());
    sender.openHandler(result -> {
        Logging.log.info("Sender link '" + sender.getTarget().getAddress() + "' opened, sending messages");
        connectLatch.countDown();
        sendNext(connection, sender);
    });
    sender.closeHandler(result -> handleError(connection, sender.getCondition()));
    sender.open();
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:14,代码来源:Sender.java

示例5: helloWorldSendAndConsumeExample

import io.vertx.proton.ProtonSender; //导入方法依赖的package包/类
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()));
  });
}
 
开发者ID:vert-x3,项目名称:vertx-proton,代码行数:35,代码来源:HelloWorld.java

示例6: sendMessage

import io.vertx.proton.ProtonSender; //导入方法依赖的package包/类
private void sendMessage(Vertx vertx, ProtonConnection connection) {
	
	connection.open();
	
	String topic = "test";
	
	ProtonSender sender = connection.createSender(null);
	
	sender.open();
	
	vertx.setPeriodic(2000, timer -> {
		
		if (connection.isDisconnected()) {
			vertx.cancelTimer(timer);
		} else {
	
			System.out.println("Sending message to server");
			
			Message message = ProtonHelper.message(topic, "Hello World from " + connection.getContainer());

			// sending on specified partition
			this.addAnnotation(message, Symbol.valueOf(AmqpSourceConnectorConstant.AMQP_PARTITION_ANNOTATION), 0);
			// sending with a key
			this.addAnnotation(message, Symbol.valueOf(AmqpSourceConnectorConstant.AMQP_KEY_ANNOTATION), "my_key");

			sender.send(ProtonHelper.tag("my_tag"), message, delivery -> {
				System.out.println("The message was received by the server");
			});
		}
		
	});
}
 
开发者ID:ppatierno,项目名称:kafka-connect-amqp,代码行数:33,代码来源:AmqpSender.java


注:本文中的io.vertx.proton.ProtonSender.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。