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


Java Delivery.setMessageFormat方法代码示例

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


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

示例1: deliverMessage

import org.apache.qpid.proton.engine.Delivery; //导入方法依赖的package包/类
/**
 * handle an out going message from ActiveMQ Artemis, send via the Proton Sender
 */
public int deliverMessage(MessageReference messageReference, int deliveryCount, Connection transportConnection) throws Exception {

   if (closed) {
      return 0;
   }

   AMQPMessage message = CoreAmqpConverter.checkAMQP(messageReference.getMessage());
   sessionSPI.invokeOutgoing(message, (ActiveMQProtonRemotingConnection) transportConnection.getProtocolConnection());

   // presettle means we can settle the message on the dealer side before we send it, i.e.
   // for browsers
   boolean preSettle = sender.getRemoteSenderSettleMode() == SenderSettleMode.SETTLED;

   // we only need a tag if we are going to settle later
   byte[] tag = preSettle ? new byte[0] : protonSession.getTag();

   ByteBuf nettyBuffer = PooledByteBufAllocator.DEFAULT.heapBuffer(message.getEncodeSize());
   try {
      message.sendBuffer(nettyBuffer, deliveryCount);

      int size = nettyBuffer.writerIndex();

      while (!connection.tryLock(1, TimeUnit.SECONDS)) {
         if (closed || sender.getLocalState() == EndpointState.CLOSED) {
            // If we're waiting on the connection lock, the link might be in the process of closing.  If this happens
            // we return.
            return 0;
         } else {
            if (log.isDebugEnabled()) {
               log.debug("Couldn't get lock on deliverMessage " + this);
            }
         }
      }

      try {
         final Delivery delivery;
         delivery = sender.delivery(tag, 0, tag.length);
         delivery.setMessageFormat((int) message.getMessageFormat());
         delivery.setContext(messageReference);

         // this will avoid a copy.. patch provided by Norman using buffer.array()
         sender.send(nettyBuffer.array(), nettyBuffer.arrayOffset() + nettyBuffer.readerIndex(), nettyBuffer.readableBytes());

         if (preSettle) {
            // Presettled means the client implicitly accepts any delivery we send it.
            sessionSPI.ack(null, brokerConsumer, messageReference.getMessage());
            delivery.settle();
         } else {
            sender.advance();
         }
         connection.flush();
      } finally {
         connection.unlock();
      }

      return size;
   } finally {
      nettyBuffer.release();
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:64,代码来源:ProtonServerSenderContext.java

示例2: sendMessageToClient

import org.apache.qpid.proton.engine.Delivery; //导入方法依赖的package包/类
private Delivery sendMessageToClient(String deliveryTag, String messageContent, Integer messageFormat)
{
    byte[] tag = deliveryTag.getBytes(StandardCharsets.UTF_8);

    Message m = Proton.message();
    m.setBody(new AmqpValue(messageContent));

    byte[] encoded = new byte[BUFFER_SIZE];
    int len = m.encode(encoded, 0, BUFFER_SIZE);

    assertTrue("given array was too small", len < BUFFER_SIZE);

    Delivery serverDelivery = getServer().sender.delivery(tag);

    // Verify the default format of 0 is in place
    assertEquals("Unexpected message format", 0, serverDelivery.getMessageFormat());

    // Set the message format explicitly if given, or leave it at the default
    if(messageFormat != null) {
        serverDelivery.setMessageFormat(messageFormat);
    }

    int sent = getServer().sender.send(encoded, 0, len);

    assertEquals("sender unable to send all data at once as assumed for simplicity", len, sent);

    boolean senderAdvanced = getServer().sender.advance();
    assertTrue("sender has not advanced", senderAdvanced);

    return serverDelivery;
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:32,代码来源:DeliveryTest.java


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