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

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

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

Message.setApplicationProperties介绍

暂无

代码示例

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

  1. private void lazyCreateApplicationProperties() {
  2. if (applicationPropertiesMap == null) {
  3. applicationPropertiesMap = new HashMap<>();
  4. message.setApplicationProperties(new ApplicationProperties(applicationPropertiesMap));
  5. }
  6. }

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

  1. private Message createOperationMessage(String resource, String operation) {
  2. Message message = Message.Factory.create();
  3. Map<String, Object> properties = new LinkedHashMap<>();
  4. properties.put("_AMQ_ResourceName", resource);
  5. properties.put("_AMQ_OperationName", operation);
  6. message.setApplicationProperties(new ApplicationProperties(properties));
  7. return message;
  8. }

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

  1. private Message createAttributeMessage(String resource, String attribute) {
  2. Message message = Message.Factory.create();
  3. Map<String, Object> properties = new LinkedHashMap<>();
  4. properties.put("_AMQ_ResourceName", resource);
  5. properties.put("_AMQ_Attribute", attribute);
  6. message.setApplicationProperties(new ApplicationProperties(properties));
  7. return message;
  8. }

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

  1. /**
  2. * Set the application properties for a Proton Message but do a check for all properties first if they only contain
  3. * values that the AMQP 1.0 spec allows.
  4. *
  5. * @param msg The Proton message. Must not be null.
  6. * @param properties The map containing application properties.
  7. * @throws NullPointerException if the message passed in is null.
  8. * @throws IllegalArgumentException if the properties contain any value that AMQP 1.0 disallows.
  9. */
  10. protected static final void setApplicationProperties(final Message msg, final Map<String, ?> properties) {
  11. if (properties != null) {
  12. final Map<String, Object> propsToAdd = new HashMap<>();
  13. // check the three types not allowed by AMQP 1.0 spec for application properties (list, map and array)
  14. for (final Map.Entry<String, ?> entry: properties.entrySet()) {
  15. if (entry.getValue() != null) {
  16. if (entry.getValue() instanceof List) {
  17. throw new IllegalArgumentException(String.format("Application property %s can't be a List", entry.getKey()));
  18. } else if (entry.getValue() instanceof Map) {
  19. throw new IllegalArgumentException(String.format("Application property %s can't be a Map", entry.getKey()));
  20. } else if (entry.getValue().getClass().isArray()) {
  21. throw new IllegalArgumentException(String.format("Application property %s can't be an Array", entry.getKey()));
  22. }
  23. }
  24. propsToAdd.put(entry.getKey(), entry.getValue());
  25. }
  26. final ApplicationProperties applicationProperties = new ApplicationProperties(propsToAdd);
  27. msg.setApplicationProperties(applicationProperties);
  28. }
  29. }

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

  1. /**
  2. * Adds a property to an AMQP 1.0 message.
  3. * <p>
  4. * The property is added to the message's <em>application-properties</em>.
  5. *
  6. * @param msg The message.
  7. * @param key The property key.
  8. * @param value The property value.
  9. * @throws NullPointerException if any of th parameters are {@code null}.
  10. */
  11. public static void addProperty(final Message msg, final String key, final Object value) {
  12. Objects.requireNonNull(msg);
  13. Objects.requireNonNull(key);
  14. Objects.requireNonNull(value);
  15. final ApplicationProperties props = Optional.ofNullable(msg.getApplicationProperties())
  16. .orElseGet(() -> {
  17. final ApplicationProperties result = new ApplicationProperties(new HashMap<String, Object>());
  18. msg.setApplicationProperties(result);
  19. return result;
  20. });
  21. props.getValue().put(key, value);
  22. }

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

  1. /**
  2. * Adds a property to an AMQP 1.0 message.
  3. * <p>
  4. * The property is added to the message's <em>application-properties</em>.
  5. *
  6. * @param msg The message.
  7. * @param key The property key.
  8. * @param value The property value.
  9. * @throws NullPointerException if any of th parameters are {@code null}.
  10. */
  11. public static void addProperty(final Message msg, final String key, final Object value) {
  12. Objects.requireNonNull(msg);
  13. Objects.requireNonNull(key);
  14. Objects.requireNonNull(value);
  15. final ApplicationProperties props = Optional.ofNullable(msg.getApplicationProperties())
  16. .orElseGet(() -> {
  17. final ApplicationProperties result = new ApplicationProperties(new HashMap<String, Object>());
  18. msg.setApplicationProperties(result);
  19. return result;
  20. });
  21. props.getValue().put(key, value);
  22. }

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

  1. private static Message createRequestMessageFromValueBody(String operation, Object valueBody, Duration timeout, String associatedLinkName)
  2. {
  3. Message requestMessage = Message.Factory.create();
  4. requestMessage.setBody(new AmqpValue(valueBody));
  5. HashMap applicationPropertiesMap = new HashMap();
  6. applicationPropertiesMap.put(ClientConstants.REQUEST_RESPONSE_OPERATION_NAME, operation);
  7. applicationPropertiesMap.put(ClientConstants.REQUEST_RESPONSE_TIMEOUT, timeout.toMillis());
  8. if(!StringUtil.isNullOrEmpty(associatedLinkName))
  9. {
  10. applicationPropertiesMap.put(ClientConstants.REQUEST_RESPONSE_ASSOCIATED_LINK_NAME, associatedLinkName);
  11. }
  12. requestMessage.setApplicationProperties(new ApplicationProperties(applicationPropertiesMap));
  13. return requestMessage;
  14. }

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

  1. private static List<List<String>> collectRouter(SyncRequestClient client, String entityType, List<String> attributeNames) throws Exception {
  2. Map<String, Object> properties = new LinkedHashMap<>();
  3. properties.put("operation", "QUERY");
  4. properties.put("entityType", entityType);
  5. Map<String, Object> body = new LinkedHashMap<>();
  6. body.put("attributeNames", attributeNames);
  7. Message message = Proton.message();
  8. message.setApplicationProperties(new ApplicationProperties(properties));
  9. message.setBody(new AmqpValue(body));
  10. Message response = client.request(message, 10, TimeUnit.SECONDS);
  11. AmqpValue value = (AmqpValue) response.getBody();
  12. Map<?,?> values = (Map<?,?>) value.getValue();
  13. @SuppressWarnings("unchecked")
  14. List<List<String>> results = (List<List<String>>) values.get("results");
  15. return results;
  16. }
  17. }

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

  1. @Override
  2. public List<String> getQueueNames(AmqpClient queueClient, Destination replyQueue, String topic) throws Exception {
  3. Message requestMessage = Message.Factory.create();
  4. Map<String, Object> appProperties = new HashMap<>();
  5. appProperties.put(resourceProperty, "address." + topic);
  6. appProperties.put(operationProperty, "getQueueNames");
  7. requestMessage.setAddress(managementAddress);
  8. requestMessage.setApplicationProperties(new ApplicationProperties(appProperties));
  9. requestMessage.setReplyTo(replyQueue.getAddress());
  10. requestMessage.setBody(new AmqpValue("[]"));
  11. Future<Integer> sent = queueClient.sendMessages(managementAddress, requestMessage);
  12. assertThat(String.format("Sender failed, expected %d messages", 1), sent.get(30, TimeUnit.SECONDS), is(1));
  13. log.info("request sent");
  14. Future<List<Message>> received = queueClient.recvMessages(replyQueue.getAddress(), 1);
  15. assertThat(String.format("Receiver failed, expected %d messages", 1),
  16. received.get(30, TimeUnit.SECONDS).size(), is(1));
  17. AmqpValue val = (AmqpValue) received.get().get(0).getBody();
  18. log.info("answer received: " + val.toString());
  19. String queues = val.getValue().toString();
  20. queues = queues.replaceAll("\\[|]|\"", "");
  21. return Arrays.asList(queues.split(","));
  22. }

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

  1. @Override
  2. public int getSubscriberCount(AmqpClient queueClient, Destination replyQueue, String queue) throws Exception {
  3. Message requestMessage = Message.Factory.create();
  4. Map<String, Object> appProperties = new HashMap<>();
  5. appProperties.put(resourceProperty, "queue." + queue);
  6. appProperties.put(operationProperty, "getConsumerCount");
  7. requestMessage.setAddress(managementAddress);
  8. requestMessage.setApplicationProperties(new ApplicationProperties(appProperties));
  9. requestMessage.setReplyTo(replyQueue.getAddress());
  10. requestMessage.setBody(new AmqpValue("[]"));
  11. Future<Integer> sent = queueClient.sendMessages(managementAddress, requestMessage);
  12. assertThat(String.format("Sender failed, expected %d messages", 1),
  13. sent.get(30, TimeUnit.SECONDS), is(1));
  14. log.info("request sent");
  15. Future<List<Message>> received = queueClient.recvMessages(replyQueue.getAddress(), 1);
  16. assertThat(String.format("Receiver failed, expected %d messages", 1),
  17. received.get(30, TimeUnit.SECONDS).size(), is(1));
  18. AmqpValue val = (AmqpValue) received.get().get(0).getBody();
  19. log.info("answer received: " + val.toString());
  20. String count = val.getValue().toString().replaceAll("\\[|]|\"", "");
  21. return Integer.valueOf(count);
  22. }
  23. }

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

  1. public Message request(Message message, long timeout, TimeUnit timeUnit) {
  2. Map<String, Object> properties = new HashMap<>();
  3. if (message.getApplicationProperties() != null) {
  4. properties.putAll(message.getApplicationProperties().getValue());
  5. }
  6. message.setApplicationProperties(new ApplicationProperties(properties));
  7. if (message.getReplyTo() == null) {
  8. message.setReplyTo(replyTo);
  9. }
  10. context.runOnContext(h -> sender.send(message));
  11. try {
  12. return replies.poll(timeout, timeUnit);
  13. } catch (InterruptedException e) {
  14. throw new RuntimeException(e);
  15. }
  16. }

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

  1. properties.put(ClientConstants.PUT_TOKEN_AUDIENCE, tokenAudience);
  2. final ApplicationProperties applicationProperties = new ApplicationProperties(properties);
  3. request.setApplicationProperties(applicationProperties);
  4. request.setBody(new AmqpValue(token));

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

  1. private static Message createResponseMessage(
  2. final String targetAddress,
  3. final String correlationId,
  4. final String contentType,
  5. final Buffer payload,
  6. final Map<String, Object> properties,
  7. final int status) {
  8. Objects.requireNonNull(targetAddress);
  9. Objects.requireNonNull(correlationId);
  10. final Message msg = ProtonHelper.message();
  11. msg.setCorrelationId(correlationId);
  12. msg.setAddress(targetAddress);
  13. MessageHelper.setPayload(msg, contentType, payload);
  14. if (properties != null) {
  15. msg.setApplicationProperties(new ApplicationProperties(properties));
  16. }
  17. MessageHelper.setCreationTime(msg);
  18. MessageHelper.addProperty(msg, MessageHelper.APP_PROPERTY_STATUS, status);
  19. return msg;
  20. }

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

  1. map.put(MessageHelper.APP_PROPERTY_CACHE_CONTROL, cacheDirective);
  2. message.setApplicationProperties(new ApplicationProperties(map));

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

  1. private int getSize(final EventDataImpl eventData, final boolean isFirst) {
  2. final Message amqpMessage = this.partitionKey != null ? eventData.toAmqpMessage(this.partitionKey) : eventData.toAmqpMessage();
  3. int eventSize = amqpMessage.encode(this.eventBytes, 0, maxMessageSize); // actual encoded bytes size
  4. eventSize += 16; // data section overhead
  5. if (isFirst) {
  6. amqpMessage.setBody(null);
  7. amqpMessage.setApplicationProperties(null);
  8. amqpMessage.setProperties(null);
  9. amqpMessage.setDeliveryAnnotations(null);
  10. eventSize += amqpMessage.encode(this.eventBytes, 0, maxMessageSize);
  11. }
  12. return eventSize;
  13. }
  14. }

代码示例来源:origin: Azure/azure-iot-sdk-java

  1. protonMessage.setApplicationProperties(applicationProperties);

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

  1. /**
  2. * Verifies that an incoming timestamp AMQP application property is converted to a long [by the translator]
  3. */
  4. @Test
  5. public void testAMQP_to_JSON_VerifyApplicationPropertyTimestamp() {
  6. Map<String, Object> props = new HashMap<>();
  7. ApplicationProperties appProps = new ApplicationProperties(props);
  8. String timestampPropKey = "timestampPropKey";
  9. long now = System.currentTimeMillis();
  10. props.put(timestampPropKey, new Date(now));
  11. Message protonMsg = Proton.message();
  12. protonMsg.setApplicationProperties(appProps);
  13. JsonObject jsonObject = translator.convertToJsonObject(protonMsg);
  14. assertNotNull("expected converted msg", jsonObject);
  15. assertTrue("expected application properties element key to be present",
  16. jsonObject.containsKey(AmqpConstants.APPLICATION_PROPERTIES));
  17. JsonObject jsonAppProps = jsonObject.getJsonObject(AmqpConstants.APPLICATION_PROPERTIES);
  18. assertNotNull("expected application properties element value to be non-null", jsonAppProps);
  19. assertTrue("expected key to be present", jsonAppProps.containsKey(timestampPropKey));
  20. Map<String, Object> propsMap = jsonAppProps.getMap();
  21. assertTrue("expected key to be present", propsMap.containsKey(timestampPropKey));
  22. assertTrue("expected value to be present, as encoded long",
  23. jsonAppProps.getValue(timestampPropKey) instanceof Long);
  24. assertEquals("expected value to be equal", now, jsonAppProps.getValue(timestampPropKey));
  25. }

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

  1. /**
  2. * Verifies that an incoming Binary AMQP application property is converted into an encoded string [by combination of
  3. * the translator and JsonObject itself]
  4. */
  5. @Test
  6. public void testAMQP_to_JSON_VerifyApplicationPropertyBinary() {
  7. Map<String, Object> props = new HashMap<>();
  8. ApplicationProperties appProps = new ApplicationProperties(props);
  9. String binaryPropKey = "binaryPropKey";
  10. String binaryPropValueSource = "binaryPropValueSource";
  11. Binary bin = new Binary(binaryPropValueSource.getBytes(StandardCharsets.UTF_8));
  12. props.put(binaryPropKey, bin);
  13. Message protonMsg = Proton.message();
  14. protonMsg.setApplicationProperties(appProps);
  15. JsonObject jsonObject = translator.convertToJsonObject(protonMsg);
  16. assertNotNull("expected converted msg", jsonObject);
  17. assertTrue("expected application properties element key to be present",
  18. jsonObject.containsKey(AmqpConstants.APPLICATION_PROPERTIES));
  19. JsonObject jsonAppProps = jsonObject.getJsonObject(AmqpConstants.APPLICATION_PROPERTIES);
  20. assertNotNull("expected application properties element value to be non-null", jsonAppProps);
  21. assertTrue("expected key to be present", jsonAppProps.containsKey(binaryPropKey));
  22. Map<String, Object> propsMap = jsonAppProps.getMap();
  23. assertTrue("expected key to be present", propsMap.containsKey(binaryPropKey));
  24. assertTrue("expected value to be present, as encoded string",
  25. jsonAppProps.getValue(binaryPropKey) instanceof String);
  26. assertArrayEquals("unepected decoded bytes", binaryPropValueSource.getBytes(StandardCharsets.UTF_8),
  27. jsonAppProps.getBinary(binaryPropKey));
  28. }

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

  1. @Test
  2. public void testAMQP_to_JSON_VerifyMessageApplicationProperties() {
  3. Map<String, Object> props = new HashMap<>();
  4. ApplicationProperties appProps = new ApplicationProperties(props);
  5. String testPropKeyA = "testPropKeyA";
  6. String testPropValueA = "testPropValueA";
  7. String testPropKeyB = "testPropKeyB";
  8. String testPropValueB = "testPropValueB";
  9. props.put(testPropKeyA, testPropValueA);
  10. props.put(testPropKeyB, testPropValueB);
  11. Message protonMsg = Proton.message();
  12. protonMsg.setApplicationProperties(appProps);
  13. JsonObject jsonObject = translator.convertToJsonObject(protonMsg);
  14. assertNotNull("expected converted msg", jsonObject);
  15. assertTrue("expected application properties element key to be present",
  16. jsonObject.containsKey(AmqpConstants.APPLICATION_PROPERTIES));
  17. JsonObject jsonAppProps = jsonObject.getJsonObject(AmqpConstants.APPLICATION_PROPERTIES);
  18. assertNotNull("expected application properties element value to be non-null", jsonAppProps);
  19. assertTrue("expected key to be present", jsonAppProps.containsKey(testPropKeyB));
  20. assertEquals("expected value to be equal", testPropValueB, jsonAppProps.getValue(testPropKeyB));
  21. assertTrue("expected key to be present", jsonAppProps.containsKey(testPropKeyA));
  22. assertEquals("expected value to be equal", testPropValueA, jsonAppProps.getValue(testPropKeyA));
  23. }

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

  1. /**
  2. * Verifies that a Symbol application property is converted to a String [by the JsonObject]
  3. */
  4. @Test
  5. public void testAMQP_to_JSON_VerifyApplicationPropertySymbol() {
  6. Map<String, Object> props = new HashMap<>();
  7. ApplicationProperties appProps = new ApplicationProperties(props);
  8. String symbolPropKey = "symbolPropKey";
  9. Symbol symbolPropValue = Symbol.valueOf("symbolPropValue");
  10. props.put(symbolPropKey, symbolPropValue);
  11. Message protonMsg = Proton.message();
  12. protonMsg.setApplicationProperties(appProps);
  13. JsonObject jsonObject = translator.convertToJsonObject(protonMsg);
  14. assertNotNull("expected converted msg", jsonObject);
  15. assertTrue("expected application properties element key to be present",
  16. jsonObject.containsKey(AmqpConstants.APPLICATION_PROPERTIES));
  17. JsonObject jsonAppProps = jsonObject.getJsonObject(AmqpConstants.APPLICATION_PROPERTIES);
  18. assertNotNull("expected application properties element value to be non-null", jsonAppProps);
  19. assertTrue("expected key to be present", jsonAppProps.containsKey(symbolPropKey));
  20. assertEquals("expected value to be equal, as a string", symbolPropValue.toString(),
  21. jsonAppProps.getValue(symbolPropKey));
  22. }

相关文章