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

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

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

Message.setBody介绍

暂无

代码示例

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

  1. public synchronized void sendMessages(String address, List<String> messages) {
  2. Queue<Message> queue = queues.computeIfAbsent(address, a -> new ArrayDeque<>());
  3. for (String data : messages) {
  4. Message message = Proton.message();
  5. message.setBody(new AmqpValue(data));
  6. queue.add(message);
  7. }
  8. }

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

  1. public Future<Integer> sendMessages(String address, List<String> messages, Predicate<Message> predicate) {
  2. List<Message> messageList = messages.stream()
  3. .map(body -> {
  4. Message message = Message.Factory.create();
  5. message.setBody(new AmqpValue(body));
  6. message.setAddress(address);
  7. return message;
  8. })
  9. .collect(Collectors.toList());
  10. return sendMessages(address, messageList, predicate);
  11. }

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

  1. /**
  2. * Creates a Message object with the given String contained as an AmqpValue body.
  3. *
  4. * @param body
  5. * the string to set as an AmqpValue body
  6. * @return the message
  7. */
  8. public static Message message(String body) {
  9. Message value = message();
  10. value.setBody(new AmqpValue(body));
  11. return value;
  12. }

代码示例来源:origin: org.apache.qpid/proton-hawtdispatch

  1. public Message createTextMessage(String value) {
  2. Message msg = Message.Factory.create();
  3. Section body = new AmqpValue(value);
  4. msg.setBody(body);
  5. return msg;
  6. }

代码示例来源: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: apache/activemq-artemis

  1. /**
  2. * Sets a described type into the body of an outgoing Message, throws
  3. * an exception if this is an incoming message instance.
  4. *
  5. * @param described the described type value to store in the Message body.
  6. * @throws IllegalStateException if the message is read only.
  7. */
  8. public void setDescribedType(DescribedType described) throws IllegalStateException {
  9. checkReadOnly();
  10. AmqpValue body = new AmqpValue(described);
  11. getWrappedMessage().setBody(body);
  12. }

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

  1. /**
  2. * Sets a String value into the body of an outgoing Message, throws
  3. * an exception if this is an incoming message instance.
  4. *
  5. * @param value the String value to store in the Message body.
  6. * @throws IllegalStateException if the message is read only.
  7. */
  8. public void setText(String value) throws IllegalStateException {
  9. checkReadOnly();
  10. AmqpValue body = new AmqpValue(value);
  11. getWrappedMessage().setBody(body);
  12. }

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

  1. /**
  2. * Return a raw AMQP message
  3. *
  4. * @return
  5. */
  6. public Message toAmqp() {
  7. Message message = ProtonHelper.message();
  8. message.setSubject(AMQP_SUBJECT);
  9. message.setCorrelationId(String.format(AmqpHelper.AMQP_CLIENT_PUBLISH_ADDRESS_TEMPLATE, this.clientId));
  10. message.setBody(new AmqpValue(this.topics));
  11. return message;
  12. }

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

  1. private Message doRequestResponse(long timeout, TimeUnit timeUnit, Message message, Object ... parameters) throws TimeoutException {
  2. JsonArray params = new JsonArray();
  3. for (Object param : parameters) {
  4. if (param == null) {
  5. params.addNull();
  6. } else {
  7. params.add(param);
  8. }
  9. }
  10. message.setBody(new AmqpValue(Json.encode(params)));
  11. return syncRequestClient.request(message, timeout, timeUnit);
  12. }

代码示例来源:origin: org.apache.qpid/proton-hawtdispatch

  1. public Message createBinaryMessage(byte value[], int offset, int len) {
  2. Message msg = Message.Factory.create();
  3. Data body = new Data(new Binary(value, offset,len));
  4. msg.setBody(body);
  5. return msg;
  6. }
  7. }

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

  1. /**
  2. * Sets a byte array value into the body of an outgoing Message, throws
  3. * an exception if this is an incoming message instance.
  4. *
  5. * @param bytes the byte array value to store in the Message body.
  6. * @throws IllegalStateException if the message is read only.
  7. */
  8. public void setBytes(byte[] bytes) throws IllegalStateException {
  9. checkReadOnly();
  10. Data body = new Data(new Binary(bytes));
  11. getWrappedMessage().setBody(body);
  12. }

代码示例来源:origin: com.ibm.mqlight/mqlight-api

  1. @Override
  2. public <T> boolean sendJson(String topic, String json,
  3. Map<String, Object> properties, SendOptions sendOptions,
  4. CompletionListener<T> listener, T context)
  5. throws StoppedException {
  6. final String methodName = "sendJson";
  7. logger.entry(this, methodName, topic, json, properties, sendOptions, listener, context);
  8. org.apache.qpid.proton.message.Message protonMsg = Proton.message();
  9. protonMsg.setBody(new AmqpValue(json));
  10. protonMsg.setContentType("application/json");
  11. final boolean result = send(topic, protonMsg, properties, sendOptions == null ? defaultSendOptions : sendOptions, listener, context);
  12. logger.exit(this, methodName, result);
  13. return result;
  14. }

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

  1. /**
  2. * Verifies that the endpoint forwards a request message via the event bus.
  3. */
  4. @Test
  5. public void testProcessMessageSendsRequestViaEventBus() {
  6. final Message msg = ProtonHelper.message();
  7. msg.setMessageId("4711");
  8. msg.setSubject(RegistrationConstants.ACTION_ASSERT);
  9. msg.setBody(new AmqpValue(new JsonObject().put("temp", 15).encode()));
  10. MessageHelper.annotate(msg, resource);
  11. endpoint.processRequest(msg, resource, Constants.PRINCIPAL_ANONYMOUS);
  12. verify(eventBus).send(eq(RegistrationConstants.EVENT_BUS_ADDRESS_REGISTRATION_IN), any(JsonObject.class), any(DeliveryOptions.class));
  13. }
  14. }

代码示例来源: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: org.apache.beam/beam-sdks-java-io-amqp

  1. @Test
  2. public void encodeDecodeLargeMessage() throws Exception {
  3. Message message = Message.Factory.create();
  4. message.setAddress("address");
  5. message.setSubject("subject");
  6. String body = Joiner.on("").join(Collections.nCopies(32 * 1024 * 1024, " "));
  7. message.setBody(new AmqpValue(body));
  8. AmqpMessageCoder coder = AmqpMessageCoder.of();
  9. Message clone = CoderUtils.clone(coder, message);
  10. clone.getBody().toString().equals(message.getBody().toString());
  11. }
  12. }

代码示例来源:origin: org.apache.beam/beam-sdks-java-io-amqp

  1. @Test
  2. public void encodeDecodeTooMuchLargerMessage() throws Exception {
  3. thrown.expect(CoderException.class);
  4. Message message = Message.Factory.create();
  5. message.setAddress("address");
  6. message.setSubject("subject");
  7. String body = Joiner.on("").join(Collections.nCopies(64 * 1024 * 1024, " "));
  8. message.setBody(new AmqpValue(body));
  9. AmqpMessageCoder coder = AmqpMessageCoder.of();
  10. byte[] encoded = CoderUtils.encodeToByteArray(coder, message);
  11. }

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

  1. /**
  2. * Verifies that a message containing a non Data section body
  3. * does not pass the filter.
  4. */
  5. @Test
  6. public void testVerifyFailsForNonDataSectionBody() {
  7. // GIVEN a message with an unsupported subject
  8. final Message msg = givenAValidMessageWithoutBody(CredentialsConstants.CredentialsAction.get);
  9. msg.setBody(new AmqpValue(BILLIE_HASHED_PASSWORD.encode()));
  10. msg.setContentType("application/json");
  11. // WHEN receiving the message via a link with any tenant
  12. final boolean filterResult = CredentialsMessageFilter.verify(target, msg);
  13. // THEN message validation fails
  14. assertFalse(filterResult);
  15. }

代码示例来源:origin: org.apache.beam/beam-sdks-java-io-amqp

  1. @Test
  2. public void encodeDecode() throws Exception {
  3. Message message = Message.Factory.create();
  4. message.setBody(new AmqpValue("body"));
  5. message.setAddress("address");
  6. message.setSubject("test");
  7. AmqpMessageCoder coder = AmqpMessageCoder.of();
  8. Message clone = CoderUtils.clone(coder, message);
  9. assertEquals("AmqpValue{body}", clone.getBody().toString());
  10. assertEquals("address", clone.getAddress());
  11. assertEquals("test", clone.getSubject());
  12. }

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

  1. /**
  2. * Verifies that a valid message passes the filter.
  3. */
  4. @Test
  5. public void testVerifySucceedsForValidGetAction() {
  6. // GIVEN a credentials message for user billie
  7. final Message msg = givenAValidMessageWithoutBody(CredentialsConstants.CredentialsAction.get);
  8. msg.setBody(new Data(new Binary(BILLIE_HASHED_PASSWORD.toBuffer().getBytes())));
  9. msg.setContentType("application/json");
  10. // WHEN receiving the message via a link with any tenant
  11. final boolean filterResult = CredentialsMessageFilter.verify(target, msg);
  12. // THEN message validation succeeds
  13. assertTrue(filterResult);
  14. }

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

  1. @Test
  2. public void testAMQP_to_JSON_VerifyBodyWithAmqpValueString() {
  3. String testContent = "myTestContent";
  4. Message protonMsg = Proton.message();
  5. protonMsg.setBody(new AmqpValue(testContent));
  6. JsonObject jsonObject = translator.convertToJsonObject(protonMsg);
  7. assertNotNull("expected converted msg", jsonObject);
  8. assertTrue("expected body element key to be present", jsonObject.containsKey(AmqpConstants.BODY));
  9. assertNotNull("expected body element value to be non-null", jsonObject.getValue(AmqpConstants.BODY));
  10. assertEquals("body value not as expected", testContent, jsonObject.getValue(AmqpConstants.BODY));
  11. assertTrue("expected body_type element key to be present", jsonObject.containsKey(AmqpConstants.BODY_TYPE));
  12. assertEquals("unexpected body_type value", AmqpConstants.BODY_TYPE_VALUE,
  13. jsonObject.getValue(AmqpConstants.BODY_TYPE));
  14. }

相关文章