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

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

本文整理了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

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

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

  1. /**
  2. * Safe way to access message annotations which will check internal structure and
  3. * either return the annotation if it exists or null if the annotation or any annotations
  4. * are present.
  5. *
  6. * @param key
  7. * the String key to use to lookup an annotation.
  8. * @param message
  9. * the AMQP message object that is being examined.
  10. *
  11. * @return the given annotation value or null if not present in the message.
  12. */
  13. public static Object getMessageAnnotation(String key, Message message) {
  14. if (message != null && message.getMessageAnnotations() != null) {
  15. Map<Symbol, Object> annotations = message.getMessageAnnotations().getValue();
  16. return annotations.get(AmqpMessageSupport.getSymbol(key));
  17. }
  18. return null;
  19. }

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

  1. /**
  2. * Safe way to access message annotations which will check internal structure and
  3. * either return the annotation if it exists or null if the annotation or any annotations
  4. * are present.
  5. *
  6. * @param key
  7. * the String key to use to lookup an annotation.
  8. * @param message
  9. * the AMQP message object that is being examined.
  10. *
  11. * @return the given annotation value or null if not present in the message.
  12. */
  13. public static Object getMessageAnnotation(String key, Message message) {
  14. if (message != null && message.getMessageAnnotations() != null) {
  15. Map<Symbol, Object> annotations = message.getMessageAnnotations().getValue();
  16. return annotations.get(AmqpMessageSupport.getSymbol(key));
  17. }
  18. return null;
  19. }

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

  1. /**
  2. * Safe way to access message annotations which will check internal structure and either
  3. * return the annotation if it exists or null if the annotation or any annotations are
  4. * present.
  5. *
  6. * @param key
  7. * the String key to use to lookup an annotation.
  8. * @param message
  9. * the AMQP message object that is being examined.
  10. *
  11. * @return the given annotation value or null if not present in the message.
  12. */
  13. public static Object getMessageAnnotation(String key, Message message) {
  14. if (message != null && message.getMessageAnnotations() != null) {
  15. Map<Symbol, Object> annotations = message.getMessageAnnotations().getValue();
  16. return annotations.get(AMQPMessageSupport.getSymbol(key));
  17. }
  18. return null;
  19. }

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

  1. /**
  2. * Safe way to access message annotations which will check internal structure and either
  3. * return the annotation if it exists or null if the annotation or any annotations are
  4. * present.
  5. *
  6. * @param key
  7. * the String key to use to lookup an annotation.
  8. * @param message
  9. * the AMQP message object that is being examined.
  10. *
  11. * @return the given annotation value or null if not present in the message.
  12. */
  13. public static Object getMessageAnnotation(String key, Message message) {
  14. if (message != null && message.getMessageAnnotations() != null) {
  15. Map<Symbol, Object> annotations = message.getMessageAnnotations().getValue();
  16. return annotations.get(AMQPMessageSupport.getSymbol(key));
  17. }
  18. return null;
  19. }

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

  1. Message toAmqpMessage(final String partitionKey) {
  2. final Message amqpMessage = this.toAmqpMessage();
  3. final MessageAnnotations messageAnnotations = (amqpMessage.getMessageAnnotations() == null)
  4. ? new MessageAnnotations(new HashMap<>())
  5. : amqpMessage.getMessageAnnotations();
  6. messageAnnotations.getValue().put(AmqpConstants.PARTITION_KEY, partitionKey);
  7. amqpMessage.setMessageAnnotations(messageAnnotations);
  8. return amqpMessage;
  9. }

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

  1. /**
  2. * Returns the value to which the specified key is mapped in the message annotations, or {@code null} if the message
  3. * annotations contain no mapping for the key.
  4. *
  5. * @param <T> the expected type of the property to read.
  6. * @param msg the message that contains the annotations.
  7. * @param key the name of the symbol to return a value for.
  8. * @param type the expected type of the value.
  9. * @return the annotation's value or {@code null} if no such annotation exists or its value is not of the expected
  10. * type.
  11. */
  12. @SuppressWarnings("unchecked")
  13. public static <T> T getAnnotation(final Message msg, final String key, final Class<T> type) {
  14. final MessageAnnotations annotations = msg.getMessageAnnotations();
  15. if (annotations == null) {
  16. return null;
  17. } else {
  18. final Object value = annotations.getValue().get(Symbol.getSymbol(key));
  19. if (type.isInstance(value)) {
  20. return (T) value;
  21. } else {
  22. return null;
  23. }
  24. }
  25. }

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

  1. /**
  2. * Adds a value for a symbol to an AMQP 1.0 message's <em>annotations</em>.
  3. *
  4. * @param msg the message to add the symbol to.
  5. * @param key the name of the symbol to add a value for.
  6. * @param value the value to add.
  7. */
  8. public static void addAnnotation(final Message msg, final String key, final Object value) {
  9. MessageAnnotations annotations = msg.getMessageAnnotations();
  10. if (annotations == null) {
  11. annotations = new MessageAnnotations(new HashMap<>());
  12. msg.setMessageAnnotations(annotations);
  13. }
  14. annotations.getValue().put(Symbol.getSymbol(key), value);
  15. }

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

  1. /**
  2. * Returns the value to which the specified key is mapped in the message annotations, or {@code null} if the message
  3. * annotations contain no mapping for the key.
  4. *
  5. * @param <T> the expected type of the property to read.
  6. * @param msg the message that contains the annotations.
  7. * @param key the name of the symbol to return a value for.
  8. * @param type the expected type of the value.
  9. * @return the annotation's value or {@code null} if no such annotation exists or its value is not of the expected
  10. * type.
  11. */
  12. @SuppressWarnings("unchecked")
  13. public static <T> T getAnnotation(final Message msg, final String key, final Class<T> type) {
  14. final MessageAnnotations annotations = msg.getMessageAnnotations();
  15. if (annotations == null) {
  16. return null;
  17. } else {
  18. final Object value = annotations.getValue().get(Symbol.getSymbol(key));
  19. if (type.isInstance(value)) {
  20. return (T) value;
  21. } else {
  22. return null;
  23. }
  24. }
  25. }

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

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

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

  1. /**
  2. * Adds a value for a symbol to an AMQP 1.0 message's <em>annotations</em>.
  3. *
  4. * @param msg the message to add the symbol to.
  5. * @param key the name of the symbol to add a value for.
  6. * @param value the value to add.
  7. */
  8. public static void addAnnotation(final Message msg, final String key, final Object value) {
  9. MessageAnnotations annotations = msg.getMessageAnnotations();
  10. if (annotations == null) {
  11. annotations = new MessageAnnotations(new HashMap<>());
  12. msg.setMessageAnnotations(annotations);
  13. }
  14. annotations.getValue().put(Symbol.getSymbol(key), value);
  15. }

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

  1. MessageAnnotations messageAnnotations = message.getMessageAnnotations();

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

  1. /**
  2. * Creates a new AmqpMessage that wraps the information necessary to handle
  3. * an incoming delivery.
  4. *
  5. * @param receiver the AmqpReceiver that received this message.
  6. * @param message the Proton message that was received.
  7. * @param delivery the Delivery instance that produced this message.
  8. */
  9. @SuppressWarnings("unchecked")
  10. public AmqpMessage(AmqpReceiver receiver, Message message, Delivery delivery) {
  11. this.receiver = receiver;
  12. this.message = message;
  13. this.delivery = delivery;
  14. if (message.getMessageAnnotations() != null) {
  15. messageAnnotationsMap = message.getMessageAnnotations().getValue();
  16. }
  17. if (message.getApplicationProperties() != null) {
  18. applicationPropertiesMap = message.getApplicationProperties().getValue();
  19. }
  20. if (message.getDeliveryAnnotations() != null) {
  21. deliveryAnnotationsMap = message.getDeliveryAnnotations().getValue();
  22. }
  23. }

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

  1. private void forwardMessage(ProtonSender protonSender, ProtonReceiver protonReceiver, ProtonDelivery sourceDelivery, Message message) {
  2. MessageAnnotations annotations = message.getMessageAnnotations();
  3. if (annotations == null) {
  4. annotations = new MessageAnnotations(Collections.singletonMap(replicated, true));
  5. } else {
  6. annotations.getValue().put(replicated, true);
  7. }
  8. message.setMessageAnnotations(annotations);
  9. protonSender.send(message, protonDelivery -> {
  10. sourceDelivery.disposition(protonDelivery.getRemoteState(), protonDelivery.remotelySettled());
  11. protonReceiver.flow(protonSender.getCredit() - protonReceiver.getCredit());
  12. });
  13. }

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

  1. public static int getDataSerializedSize(Message amqpMessage) {
  2. if (amqpMessage == null) {
  3. return 0;
  4. }
  5. int payloadSize = getPayloadSize(amqpMessage);
  6. // EventData - accepts only PartitionKey - which is a String & stuffed into MessageAnnotation
  7. final MessageAnnotations messageAnnotations = amqpMessage.getMessageAnnotations();
  8. final ApplicationProperties applicationProperties = amqpMessage.getApplicationProperties();
  9. int annotationsSize = 0;
  10. int applicationPropertiesSize = 0;
  11. if (messageAnnotations != null) {
  12. for (Symbol value : messageAnnotations.getValue().keySet()) {
  13. annotationsSize += sizeof(value);
  14. }
  15. for (Object value : messageAnnotations.getValue().values()) {
  16. annotationsSize += sizeof(value);
  17. }
  18. }
  19. if (applicationProperties != null) {
  20. for (Object value : applicationProperties.getValue().keySet()) {
  21. applicationPropertiesSize += sizeof(value);
  22. }
  23. for (Object value : applicationProperties.getValue().values()) {
  24. applicationPropertiesSize += sizeof(value);
  25. }
  26. }
  27. return annotationsSize + applicationPropertiesSize + payloadSize;
  28. }

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

  1. batchMessage.setMessageAnnotations(firstMessage.getMessageAnnotations());

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

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

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

  1. public static int getDataSerializedSize(Message amqpMessage)
  2. {
  3. if (amqpMessage == null)
  4. {
  5. return 0;
  6. }
  7. int payloadSize = getPayloadSize(amqpMessage);
  8. // EventData - accepts only PartitionKey - which is a String & stuffed into MessageAnnotation
  9. MessageAnnotations messageAnnotations = amqpMessage.getMessageAnnotations();
  10. ApplicationProperties applicationProperties = amqpMessage.getApplicationProperties();
  11. int annotationsSize = 0;
  12. int applicationPropertiesSize = 0;
  13. if (messageAnnotations != null)
  14. {
  15. annotationsSize += Util.sizeof(messageAnnotations.getValue());
  16. }
  17. if (applicationProperties != null)
  18. {
  19. applicationPropertiesSize += Util.sizeof(applicationProperties.getValue());
  20. }
  21. return annotationsSize + applicationPropertiesSize + payloadSize;
  22. }

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

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

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

  1. @Test
  2. public void testJSON_to_AMQP_VerifyMessageAnnotations() {
  3. String testAnnKeyNameA = "testAnnKeyA";
  4. String testAnnKeyNameB = "testAnnKeyB";
  5. Symbol testAnnKeyA = Symbol.valueOf(testAnnKeyNameA);
  6. String testAnnValueA = "testAnnValueA";
  7. Symbol testAnnKeyB = Symbol.valueOf(testAnnKeyNameB);
  8. String testAnnValueB = "testAnnValueB";
  9. JsonObject jsonAppProps = new JsonObject();
  10. jsonAppProps.put(testAnnKeyNameA, testAnnValueA);
  11. jsonAppProps.put(testAnnKeyNameB, testAnnValueB);
  12. JsonObject jsonObject = new JsonObject();
  13. jsonObject.put(AmqpConstants.MESSAGE_ANNOTATIONS, jsonAppProps);
  14. Message protonMsg = translator.convertToAmqpMessage(jsonObject);
  15. assertNotNull("Expected converted msg", protonMsg);
  16. MessageAnnotations ma = protonMsg.getMessageAnnotations();
  17. assertNotNull("message annotations section not present", ma);
  18. Map<Symbol, Object> annotations = ma.getValue();
  19. assertNotNull("message annotations map not present", ma);
  20. assertTrue("expected key to be present", annotations.containsKey(testAnnKeyA));
  21. assertEquals("expected value to be equal", testAnnValueA, annotations.get(testAnnKeyA));
  22. assertTrue("expected key to be present", annotations.containsKey(testAnnKeyB));
  23. assertEquals("expected value to be equal", testAnnValueB, annotations.get(testAnnKeyB));
  24. assertEquals("unexpected number of props", 2, annotations.size());
  25. }

相关文章