org.apache.qpid.proton.message.Message.getMessageAnnotations()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(12.8k)|赞(0)|评价(0)|浏览(113)

本文整理了Java中org.apache.qpid.proton.message.Message.getMessageAnnotations()方法的一些代码示例,展示了Message.getMessageAnnotations()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.getMessageAnnotations()方法的具体详情如下:
包路径:org.apache.qpid.proton.message.Message
类名称:Message
方法名:getMessageAnnotations

Message.getMessageAnnotations介绍

暂无

代码示例

代码示例来源:origin: EnMasseProject/enmasse

private static boolean isMessageReplicated(Message message) {
    MessageAnnotations annotations = message.getMessageAnnotations();
    return annotations != null && annotations.getValue().containsKey(replicated);
  }
}

代码示例来源:origin: org.apache.activemq/activemq-all

/**
 * Safe way to access message annotations which will check internal structure and
 * either return the annotation if it exists or null if the annotation or any annotations
 * are present.
 *
 * @param key
 *        the String key to use to lookup an annotation.
 * @param message
 *        the AMQP message object that is being examined.
 *
 * @return the given annotation value or null if not present in the message.
 */
public static Object getMessageAnnotation(String key, Message message) {
  if (message != null && message.getMessageAnnotations() != null) {
    Map<Symbol, Object> annotations = message.getMessageAnnotations().getValue();
    return annotations.get(AmqpMessageSupport.getSymbol(key));
  }
  return null;
}

代码示例来源:origin: org.apache.activemq/activemq-osgi

/**
 * Safe way to access message annotations which will check internal structure and
 * either return the annotation if it exists or null if the annotation or any annotations
 * are present.
 *
 * @param key
 *        the String key to use to lookup an annotation.
 * @param message
 *        the AMQP message object that is being examined.
 *
 * @return the given annotation value or null if not present in the message.
 */
public static Object getMessageAnnotation(String key, Message message) {
  if (message != null && message.getMessageAnnotations() != null) {
    Map<Symbol, Object> annotations = message.getMessageAnnotations().getValue();
    return annotations.get(AmqpMessageSupport.getSymbol(key));
  }
  return null;
}

代码示例来源:origin: org.apache.activemq/artemis-amqp-protocol

/**
* Safe way to access message annotations which will check internal structure and either
* return the annotation if it exists or null if the annotation or any annotations are
* present.
*
* @param key
*        the String key to use to lookup an annotation.
* @param message
*        the AMQP message object that is being examined.
*
* @return the given annotation value or null if not present in the message.
*/
public static Object getMessageAnnotation(String key, Message message) {
 if (message != null && message.getMessageAnnotations() != null) {
   Map<Symbol, Object> annotations = message.getMessageAnnotations().getValue();
   return annotations.get(AMQPMessageSupport.getSymbol(key));
 }
 return null;
}

代码示例来源:origin: apache/activemq-artemis

/**
* Safe way to access message annotations which will check internal structure and either
* return the annotation if it exists or null if the annotation or any annotations are
* present.
*
* @param key
*        the String key to use to lookup an annotation.
* @param message
*        the AMQP message object that is being examined.
*
* @return the given annotation value or null if not present in the message.
*/
public static Object getMessageAnnotation(String key, Message message) {
 if (message != null && message.getMessageAnnotations() != null) {
   Map<Symbol, Object> annotations = message.getMessageAnnotations().getValue();
   return annotations.get(AMQPMessageSupport.getSymbol(key));
 }
 return null;
}

代码示例来源:origin: Azure/azure-event-hubs-java

Message toAmqpMessage(final String partitionKey) {
  final Message amqpMessage = this.toAmqpMessage();
  final MessageAnnotations messageAnnotations = (amqpMessage.getMessageAnnotations() == null)
      ? new MessageAnnotations(new HashMap<>())
      : amqpMessage.getMessageAnnotations();
  messageAnnotations.getValue().put(AmqpConstants.PARTITION_KEY, partitionKey);
  amqpMessage.setMessageAnnotations(messageAnnotations);
  return amqpMessage;
}

代码示例来源:origin: eclipse/hono

/**
 * Returns the value to which the specified key is mapped in the message annotations, or {@code null} if the message
 * annotations contain no mapping for the key.
 *
 * @param <T> the expected type of the property to read.
 * @param msg the message that contains the annotations.
 * @param key the name of the symbol to return a value for.
 * @param type the expected type of the value.
 * @return the annotation's value or {@code null} if no such annotation exists or its value is not of the expected
 *         type.
 */
@SuppressWarnings("unchecked")
public static <T> T getAnnotation(final Message msg, final String key, final Class<T> type) {
  final MessageAnnotations annotations = msg.getMessageAnnotations();
  if (annotations == null) {
    return null;
  } else {
    final Object value = annotations.getValue().get(Symbol.getSymbol(key));
    if (type.isInstance(value)) {
      return (T) value;
    } else {
      return null;
    }
  }
}

代码示例来源:origin: org.eclipse.hono/hono-core

/**
 * Adds a value for a symbol to an AMQP 1.0 message's <em>annotations</em>.
 *
 * @param msg the message to add the symbol to.
 * @param key the name of the symbol to add a value for.
 * @param value the value to add.
 */
public static void addAnnotation(final Message msg, final String key, final Object value) {
  MessageAnnotations annotations = msg.getMessageAnnotations();
  if (annotations == null) {
    annotations = new MessageAnnotations(new HashMap<>());
    msg.setMessageAnnotations(annotations);
  }
  annotations.getValue().put(Symbol.getSymbol(key), value);
}

代码示例来源:origin: org.eclipse.hono/hono-core

/**
 * Returns the value to which the specified key is mapped in the message annotations, or {@code null} if the message
 * annotations contain no mapping for the key.
 *
 * @param <T> the expected type of the property to read.
 * @param msg the message that contains the annotations.
 * @param key the name of the symbol to return a value for.
 * @param type the expected type of the value.
 * @return the annotation's value or {@code null} if no such annotation exists or its value is not of the expected
 *         type.
 */
@SuppressWarnings("unchecked")
public static <T> T getAnnotation(final Message msg, final String key, final Class<T> type) {
  final MessageAnnotations annotations = msg.getMessageAnnotations();
  if (annotations == null) {
    return null;
  } else {
    final Object value = annotations.getValue().get(Symbol.getSymbol(key));
    if (type.isInstance(value)) {
      return (T) value;
    } else {
      return null;
    }
  }
}

代码示例来源:origin: Azure/azure-event-hubs-java

@Override
public Map<Symbol, UnknownDescribedType> getFilter(final Message lastReceivedMessage) {
  String expression;
  if (lastReceivedMessage != null) {
    String lastReceivedOffset = lastReceivedMessage.getMessageAnnotations().getValue().get(AmqpConstants.OFFSET).toString();
    expression = String.format(AmqpConstants.AMQP_ANNOTATION_FORMAT, AmqpConstants.OFFSET_ANNOTATION_NAME, StringUtil.EMPTY, lastReceivedOffset);
  } else {
    expression = this.eventPosition.getExpression();
  }
  if (TRACE_LOGGER.isInfoEnabled()) {
    String logReceivePath = "";
    if (this.internalReceiver == null) {
      // During startup, internalReceiver is still null. Need to handle this special case when logging during startup
      // or the reactor thread crashes with NPE when calling internalReceiver.getReceivePath() and no receiving occurs.
      logReceivePath = "receiverPath[RECEIVER IS NULL]";
    } else {
      logReceivePath = "receiverPath[" + this.internalReceiver.getReceivePath() + "]";
    }
    TRACE_LOGGER.info(String.format("%s, action[createReceiveLink], %s", logReceivePath, this.eventPosition));
  }
  return Collections.singletonMap(AmqpConstants.STRING_FILTER, new UnknownDescribedType(AmqpConstants.STRING_FILTER, expression));
}

代码示例来源:origin: eclipse/hono

/**
 * Adds a value for a symbol to an AMQP 1.0 message's <em>annotations</em>.
 *
 * @param msg the message to add the symbol to.
 * @param key the name of the symbol to add a value for.
 * @param value the value to add.
 */
public static void addAnnotation(final Message msg, final String key, final Object value) {
  MessageAnnotations annotations = msg.getMessageAnnotations();
  if (annotations == null) {
    annotations = new MessageAnnotations(new HashMap<>());
    msg.setMessageAnnotations(annotations);
  }
  annotations.getValue().put(Symbol.getSymbol(key), value);
}

代码示例来源:origin: strimzi/strimzi-kafka-bridge

MessageAnnotations messageAnnotations = message.getMessageAnnotations();

代码示例来源:origin: apache/activemq-artemis

/**
* Creates a new AmqpMessage that wraps the information necessary to handle
* an incoming delivery.
*
* @param receiver the AmqpReceiver that received this message.
* @param message  the Proton message that was received.
* @param delivery the Delivery instance that produced this message.
*/
@SuppressWarnings("unchecked")
public AmqpMessage(AmqpReceiver receiver, Message message, Delivery delivery) {
 this.receiver = receiver;
 this.message = message;
 this.delivery = delivery;
 if (message.getMessageAnnotations() != null) {
   messageAnnotationsMap = message.getMessageAnnotations().getValue();
 }
 if (message.getApplicationProperties() != null) {
   applicationPropertiesMap = message.getApplicationProperties().getValue();
 }
 if (message.getDeliveryAnnotations() != null) {
   deliveryAnnotationsMap = message.getDeliveryAnnotations().getValue();
 }
}

代码示例来源:origin: EnMasseProject/enmasse

private void forwardMessage(ProtonSender protonSender, ProtonReceiver protonReceiver, ProtonDelivery sourceDelivery, Message message) {
  MessageAnnotations annotations = message.getMessageAnnotations();
  if (annotations == null) {
    annotations = new MessageAnnotations(Collections.singletonMap(replicated, true));
  } else {
    annotations.getValue().put(replicated, true);
  }
  message.setMessageAnnotations(annotations);
  protonSender.send(message, protonDelivery -> {
    sourceDelivery.disposition(protonDelivery.getRemoteState(), protonDelivery.remotelySettled());
    protonReceiver.flow(protonSender.getCredit() - protonReceiver.getCredit());
  });
}

代码示例来源:origin: Azure/azure-event-hubs-java

public static int getDataSerializedSize(Message amqpMessage) {
  if (amqpMessage == null) {
    return 0;
  }
  int payloadSize = getPayloadSize(amqpMessage);
  // EventData - accepts only PartitionKey - which is a String & stuffed into MessageAnnotation
  final MessageAnnotations messageAnnotations = amqpMessage.getMessageAnnotations();
  final ApplicationProperties applicationProperties = amqpMessage.getApplicationProperties();
  int annotationsSize = 0;
  int applicationPropertiesSize = 0;
  if (messageAnnotations != null) {
    for (Symbol value : messageAnnotations.getValue().keySet()) {
      annotationsSize += sizeof(value);
    }
    for (Object value : messageAnnotations.getValue().values()) {
      annotationsSize += sizeof(value);
    }
  }
  if (applicationProperties != null) {
    for (Object value : applicationProperties.getValue().keySet()) {
      applicationPropertiesSize += sizeof(value);
    }
    for (Object value : applicationProperties.getValue().values()) {
      applicationPropertiesSize += sizeof(value);
    }
  }
  return annotationsSize + applicationPropertiesSize + payloadSize;
}

代码示例来源:origin: Azure/azure-event-hubs-java

batchMessage.setMessageAnnotations(firstMessage.getMessageAnnotations());

代码示例来源:origin: io.vertx/vertx-amqp-bridge

@Test
public void testJSON_to_AMQP_WithNoMessageAnnotations() {
 JsonObject jsonObject = new JsonObject();
 Message protonMsg = translator.convertToAmqpMessage(jsonObject);
 assertNotNull("Expected converted msg", protonMsg);
 assertNull("expected converted msg to have no message annotations section", protonMsg.getMessageAnnotations());
}

代码示例来源:origin: Azure/azure-service-bus-java

public static int getDataSerializedSize(Message amqpMessage)
{
  if (amqpMessage == null)
  {
    return 0;
  }
  int payloadSize = getPayloadSize(amqpMessage);
  // EventData - accepts only PartitionKey - which is a String & stuffed into MessageAnnotation
  MessageAnnotations messageAnnotations = amqpMessage.getMessageAnnotations();
  ApplicationProperties applicationProperties = amqpMessage.getApplicationProperties();
  
  int annotationsSize = 0;
  int applicationPropertiesSize = 0;
  if (messageAnnotations != null)
  {
    annotationsSize += Util.sizeof(messageAnnotations.getValue());
  }
  
  if (applicationProperties != null)
  {
    applicationPropertiesSize += Util.sizeof(applicationProperties.getValue());    
  }
  
  return annotationsSize + applicationPropertiesSize + payloadSize;
}

代码示例来源:origin: io.vertx/vertx-amqp-bridge

assertNotNull("Expected converted msg", protonMsg);
MessageAnnotations ma = protonMsg.getMessageAnnotations();
assertNotNull("message annotations section not present", ma);

代码示例来源:origin: io.vertx/vertx-amqp-bridge

@Test
public void testJSON_to_AMQP_VerifyMessageAnnotations() {
 String testAnnKeyNameA = "testAnnKeyA";
 String testAnnKeyNameB = "testAnnKeyB";
 Symbol testAnnKeyA = Symbol.valueOf(testAnnKeyNameA);
 String testAnnValueA = "testAnnValueA";
 Symbol testAnnKeyB = Symbol.valueOf(testAnnKeyNameB);
 String testAnnValueB = "testAnnValueB";
 JsonObject jsonAppProps = new JsonObject();
 jsonAppProps.put(testAnnKeyNameA, testAnnValueA);
 jsonAppProps.put(testAnnKeyNameB, testAnnValueB);
 JsonObject jsonObject = new JsonObject();
 jsonObject.put(AmqpConstants.MESSAGE_ANNOTATIONS, jsonAppProps);
 Message protonMsg = translator.convertToAmqpMessage(jsonObject);
 assertNotNull("Expected converted msg", protonMsg);
 MessageAnnotations ma = protonMsg.getMessageAnnotations();
 assertNotNull("message annotations  section not present", ma);
 Map<Symbol, Object> annotations = ma.getValue();
 assertNotNull("message annotations  map not present", ma);
 assertTrue("expected key to be present", annotations.containsKey(testAnnKeyA));
 assertEquals("expected value to be equal", testAnnValueA, annotations.get(testAnnKeyA));
 assertTrue("expected key to be present", annotations.containsKey(testAnnKeyB));
 assertEquals("expected value to be equal", testAnnValueB, annotations.get(testAnnKeyB));
 assertEquals("unexpected number of props", 2, annotations.size());
}

相关文章

微信公众号

最新文章

更多