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

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

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

private void lazyCreateApplicationProperties() {
 if (applicationPropertiesMap == null) {
   applicationPropertiesMap = new HashMap<>();
   message.setApplicationProperties(new ApplicationProperties(applicationPropertiesMap));
 }
}

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

private Message createOperationMessage(String resource, String operation) {
  Message message = Message.Factory.create();
  Map<String, Object> properties = new LinkedHashMap<>();
  properties.put("_AMQ_ResourceName", resource);
  properties.put("_AMQ_OperationName", operation);
  message.setApplicationProperties(new ApplicationProperties(properties));
  return message;
}

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

private Message createAttributeMessage(String resource, String attribute) {
  Message message = Message.Factory.create();
  Map<String, Object> properties = new LinkedHashMap<>();
  properties.put("_AMQ_ResourceName", resource);
  properties.put("_AMQ_Attribute", attribute);
  message.setApplicationProperties(new ApplicationProperties(properties));
  return message;
}

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

/**
 * Set the application properties for a Proton Message but do a check for all properties first if they only contain
 * values that the AMQP 1.0 spec allows.
 *
 * @param msg The Proton message. Must not be null.
 * @param properties The map containing application properties.
 * @throws NullPointerException if the message passed in is null.
 * @throws IllegalArgumentException if the properties contain any value that AMQP 1.0 disallows.
 */
protected static final void setApplicationProperties(final Message msg, final Map<String, ?> properties) {
  if (properties != null) {
    final Map<String, Object> propsToAdd = new HashMap<>();
    // check the three types not allowed by AMQP 1.0 spec for application properties (list, map and array)
    for (final Map.Entry<String, ?> entry: properties.entrySet()) {
      if (entry.getValue() != null) {
        if (entry.getValue() instanceof List) {
          throw new IllegalArgumentException(String.format("Application property %s can't be a List", entry.getKey()));
        } else if (entry.getValue() instanceof Map) {
          throw new IllegalArgumentException(String.format("Application property %s can't be a Map", entry.getKey()));
        } else if (entry.getValue().getClass().isArray()) {
          throw new IllegalArgumentException(String.format("Application property %s can't be an Array", entry.getKey()));
        }
      }
      propsToAdd.put(entry.getKey(), entry.getValue());
    }
    final ApplicationProperties applicationProperties = new ApplicationProperties(propsToAdd);
    msg.setApplicationProperties(applicationProperties);
  }
}

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

/**
 * Adds a property to an AMQP 1.0 message.
 * <p>
 * The property is added to the message's <em>application-properties</em>.
 *
 * @param msg The message.
 * @param key The property key.
 * @param value The property value.
 * @throws NullPointerException if any of th parameters are {@code null}.
 */
public static void addProperty(final Message msg, final String key, final Object value) {
  Objects.requireNonNull(msg);
  Objects.requireNonNull(key);
  Objects.requireNonNull(value);
  final ApplicationProperties props = Optional.ofNullable(msg.getApplicationProperties())
      .orElseGet(() -> {
        final ApplicationProperties result = new ApplicationProperties(new HashMap<String, Object>());
        msg.setApplicationProperties(result);
        return result;
      });
  props.getValue().put(key, value);
}

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

/**
 * Adds a property to an AMQP 1.0 message.
 * <p>
 * The property is added to the message's <em>application-properties</em>.
 *
 * @param msg The message.
 * @param key The property key.
 * @param value The property value.
 * @throws NullPointerException if any of th parameters are {@code null}.
 */
public static void addProperty(final Message msg, final String key, final Object value) {
  Objects.requireNonNull(msg);
  Objects.requireNonNull(key);
  Objects.requireNonNull(value);
  final ApplicationProperties props = Optional.ofNullable(msg.getApplicationProperties())
      .orElseGet(() -> {
        final ApplicationProperties result = new ApplicationProperties(new HashMap<String, Object>());
        msg.setApplicationProperties(result);
        return result;
      });
  props.getValue().put(key, value);
}

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

private static Message createRequestMessageFromValueBody(String operation, Object valueBody, Duration timeout, String associatedLinkName)
{
  Message requestMessage = Message.Factory.create();
  requestMessage.setBody(new AmqpValue(valueBody));
  HashMap applicationPropertiesMap = new HashMap();
  applicationPropertiesMap.put(ClientConstants.REQUEST_RESPONSE_OPERATION_NAME, operation);
  applicationPropertiesMap.put(ClientConstants.REQUEST_RESPONSE_TIMEOUT, timeout.toMillis());
  if(!StringUtil.isNullOrEmpty(associatedLinkName))
  {
    applicationPropertiesMap.put(ClientConstants.REQUEST_RESPONSE_ASSOCIATED_LINK_NAME, associatedLinkName);
  }
  requestMessage.setApplicationProperties(new ApplicationProperties(applicationPropertiesMap));
  return requestMessage;
}

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

private static List<List<String>> collectRouter(SyncRequestClient client, String entityType, List<String> attributeNames) throws Exception {
    Map<String, Object> properties = new LinkedHashMap<>();
    properties.put("operation", "QUERY");
    properties.put("entityType", entityType);
    Map<String, Object> body = new LinkedHashMap<>();

    body.put("attributeNames", attributeNames);

    Message message = Proton.message();
    message.setApplicationProperties(new ApplicationProperties(properties));
    message.setBody(new AmqpValue(body));

    Message response = client.request(message, 10, TimeUnit.SECONDS);
    AmqpValue value = (AmqpValue) response.getBody();
    Map<?,?> values = (Map<?,?>) value.getValue();

    @SuppressWarnings("unchecked")
    List<List<String>> results = (List<List<String>>) values.get("results");
    return results;
  }
}

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

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

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

@Override
  public int getSubscriberCount(AmqpClient queueClient, Destination replyQueue, String queue) throws Exception {
    Message requestMessage = Message.Factory.create();
    Map<String, Object> appProperties = new HashMap<>();
    appProperties.put(resourceProperty, "queue." + queue);
    appProperties.put(operationProperty, "getConsumerCount");
    requestMessage.setAddress(managementAddress);
    requestMessage.setApplicationProperties(new ApplicationProperties(appProperties));
    requestMessage.setReplyTo(replyQueue.getAddress());
    requestMessage.setBody(new AmqpValue("[]"));

    Future<Integer> sent = queueClient.sendMessages(managementAddress, requestMessage);
    assertThat(String.format("Sender failed, expected %d messages", 1),
        sent.get(30, TimeUnit.SECONDS), is(1));
    log.info("request sent");

    Future<List<Message>> received = queueClient.recvMessages(replyQueue.getAddress(), 1);
    assertThat(String.format("Receiver failed, expected %d messages", 1),
        received.get(30, TimeUnit.SECONDS).size(), is(1));

    AmqpValue val = (AmqpValue) received.get().get(0).getBody();
    log.info("answer received: " + val.toString());
    String count = val.getValue().toString().replaceAll("\\[|]|\"", "");

    return Integer.valueOf(count);
  }
}

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

public Message request(Message message, long timeout, TimeUnit timeUnit) {
  Map<String, Object> properties = new HashMap<>();
  if (message.getApplicationProperties() != null) {
    properties.putAll(message.getApplicationProperties().getValue());
  }
  message.setApplicationProperties(new ApplicationProperties(properties));
  if (message.getReplyTo() == null) {
    message.setReplyTo(replyTo);
  }
  context.runOnContext(h -> sender.send(message));
  try {
    return replies.poll(timeout, timeUnit);
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
}

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

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

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

private static Message createResponseMessage(
    final String targetAddress,
    final String correlationId,
    final String contentType,
    final Buffer payload,
    final Map<String, Object> properties,
    final int status) {
  Objects.requireNonNull(targetAddress);
  Objects.requireNonNull(correlationId);
  final Message msg = ProtonHelper.message();
  msg.setCorrelationId(correlationId);
  msg.setAddress(targetAddress);
  MessageHelper.setPayload(msg, contentType, payload);
  if (properties != null) {
    msg.setApplicationProperties(new ApplicationProperties(properties));
  }
  MessageHelper.setCreationTime(msg);
  MessageHelper.addProperty(msg, MessageHelper.APP_PROPERTY_STATUS, status);
  return msg;
}

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

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

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

private int getSize(final EventDataImpl eventData, final boolean isFirst) {

    final Message amqpMessage = this.partitionKey != null ? eventData.toAmqpMessage(this.partitionKey) : eventData.toAmqpMessage();
    int eventSize = amqpMessage.encode(this.eventBytes, 0, maxMessageSize); // actual encoded bytes size
    eventSize += 16; // data section overhead

    if (isFirst) {
      amqpMessage.setBody(null);
      amqpMessage.setApplicationProperties(null);
      amqpMessage.setProperties(null);
      amqpMessage.setDeliveryAnnotations(null);

      eventSize += amqpMessage.encode(this.eventBytes, 0, maxMessageSize);
    }

    return eventSize;
  }
}

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

protonMessage.setApplicationProperties(applicationProperties);

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

/**
 * Verifies that an incoming timestamp AMQP application property is converted to a long [by the translator]
 */
@Test
public void testAMQP_to_JSON_VerifyApplicationPropertyTimestamp() {
 Map<String, Object> props = new HashMap<>();
 ApplicationProperties appProps = new ApplicationProperties(props);
 String timestampPropKey = "timestampPropKey";
 long now = System.currentTimeMillis();
 props.put(timestampPropKey, new Date(now));
 Message protonMsg = Proton.message();
 protonMsg.setApplicationProperties(appProps);
 JsonObject jsonObject = translator.convertToJsonObject(protonMsg);
 assertNotNull("expected converted msg", jsonObject);
 assertTrue("expected application properties element key to be present",
   jsonObject.containsKey(AmqpConstants.APPLICATION_PROPERTIES));
 JsonObject jsonAppProps = jsonObject.getJsonObject(AmqpConstants.APPLICATION_PROPERTIES);
 assertNotNull("expected application properties element value to be non-null", jsonAppProps);
 assertTrue("expected key to be present", jsonAppProps.containsKey(timestampPropKey));
 Map<String, Object> propsMap = jsonAppProps.getMap();
 assertTrue("expected key to be present", propsMap.containsKey(timestampPropKey));
 assertTrue("expected value to be present, as encoded long",
   jsonAppProps.getValue(timestampPropKey) instanceof Long);
 assertEquals("expected value to be equal", now, jsonAppProps.getValue(timestampPropKey));
}

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

/**
 * Verifies that an incoming Binary AMQP application property is converted into an encoded string [by combination of
 * the translator and JsonObject itself]
 */
@Test
public void testAMQP_to_JSON_VerifyApplicationPropertyBinary() {
 Map<String, Object> props = new HashMap<>();
 ApplicationProperties appProps = new ApplicationProperties(props);
 String binaryPropKey = "binaryPropKey";
 String binaryPropValueSource = "binaryPropValueSource";
 Binary bin = new Binary(binaryPropValueSource.getBytes(StandardCharsets.UTF_8));
 props.put(binaryPropKey, bin);
 Message protonMsg = Proton.message();
 protonMsg.setApplicationProperties(appProps);
 JsonObject jsonObject = translator.convertToJsonObject(protonMsg);
 assertNotNull("expected converted msg", jsonObject);
 assertTrue("expected application properties element key to be present",
   jsonObject.containsKey(AmqpConstants.APPLICATION_PROPERTIES));
 JsonObject jsonAppProps = jsonObject.getJsonObject(AmqpConstants.APPLICATION_PROPERTIES);
 assertNotNull("expected application properties element value to be non-null", jsonAppProps);
 assertTrue("expected key to be present", jsonAppProps.containsKey(binaryPropKey));
 Map<String, Object> propsMap = jsonAppProps.getMap();
 assertTrue("expected key to be present", propsMap.containsKey(binaryPropKey));
 assertTrue("expected value to be present, as encoded string",
   jsonAppProps.getValue(binaryPropKey) instanceof String);
 assertArrayEquals("unepected decoded bytes", binaryPropValueSource.getBytes(StandardCharsets.UTF_8),
   jsonAppProps.getBinary(binaryPropKey));
}

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

@Test
public void testAMQP_to_JSON_VerifyMessageApplicationProperties() {
 Map<String, Object> props = new HashMap<>();
 ApplicationProperties appProps = new ApplicationProperties(props);
 String testPropKeyA = "testPropKeyA";
 String testPropValueA = "testPropValueA";
 String testPropKeyB = "testPropKeyB";
 String testPropValueB = "testPropValueB";
 props.put(testPropKeyA, testPropValueA);
 props.put(testPropKeyB, testPropValueB);
 Message protonMsg = Proton.message();
 protonMsg.setApplicationProperties(appProps);
 JsonObject jsonObject = translator.convertToJsonObject(protonMsg);
 assertNotNull("expected converted msg", jsonObject);
 assertTrue("expected application properties element key to be present",
   jsonObject.containsKey(AmqpConstants.APPLICATION_PROPERTIES));
 JsonObject jsonAppProps = jsonObject.getJsonObject(AmqpConstants.APPLICATION_PROPERTIES);
 assertNotNull("expected application properties element value to be non-null", jsonAppProps);
 assertTrue("expected key to be present", jsonAppProps.containsKey(testPropKeyB));
 assertEquals("expected value to be equal", testPropValueB, jsonAppProps.getValue(testPropKeyB));
 assertTrue("expected key to be present", jsonAppProps.containsKey(testPropKeyA));
 assertEquals("expected value to be equal", testPropValueA, jsonAppProps.getValue(testPropKeyA));
}

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

/**
 * Verifies that a Symbol application property is converted to a String [by the JsonObject]
 */
@Test
public void testAMQP_to_JSON_VerifyApplicationPropertySymbol() {
 Map<String, Object> props = new HashMap<>();
 ApplicationProperties appProps = new ApplicationProperties(props);
 String symbolPropKey = "symbolPropKey";
 Symbol symbolPropValue = Symbol.valueOf("symbolPropValue");
 props.put(symbolPropKey, symbolPropValue);
 Message protonMsg = Proton.message();
 protonMsg.setApplicationProperties(appProps);
 JsonObject jsonObject = translator.convertToJsonObject(protonMsg);
 assertNotNull("expected converted msg", jsonObject);
 assertTrue("expected application properties element key to be present",
   jsonObject.containsKey(AmqpConstants.APPLICATION_PROPERTIES));
 JsonObject jsonAppProps = jsonObject.getJsonObject(AmqpConstants.APPLICATION_PROPERTIES);
 assertNotNull("expected application properties element value to be non-null", jsonAppProps);
 assertTrue("expected key to be present", jsonAppProps.containsKey(symbolPropKey));
 assertEquals("expected value to be equal, as a string", symbolPropValue.toString(),
   jsonAppProps.getValue(symbolPropKey));
}

相关文章

微信公众号

最新文章

更多