org.apache.qpid.proton.Proton Java Examples

The following examples show how to use org.apache.qpid.proton.Proton. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AmqpCodecTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
private void doCreateTextMessageFromDataWithContentTypeTestImpl(String contentType, Charset expectedCharset) throws IOException {
    Message message = Proton.message();
    Binary binary = new Binary(new byte[0]);
    message.setBody(new Data(binary));
    message.setContentType(contentType);

    JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage();
    assertNotNull("Message should not be null", jmsMessage);
    assertEquals("Unexpected message class type", JmsTextMessage.class, jmsMessage.getClass());

    JmsMessageFacade facade = jmsMessage.getFacade();
    assertNotNull("Facade should not be null", facade);
    assertEquals("Unexpected facade class type", AmqpJmsTextMessageFacade.class, facade.getClass());

    AmqpJmsTextMessageFacade textFacade = (AmqpJmsTextMessageFacade) facade;
    assertEquals("Unexpected character set", expectedCharset, textFacade.getCharset());
}
 
Example #2
Source File: AMQPPersisterTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private MessageImpl createProtonMessage(String address, byte[] content) {
   MessageImpl message = (MessageImpl) Proton.message();

   Header header = new Header();
   header.setDurable(true);
   header.setPriority(UnsignedByte.valueOf((byte) 9));

   Properties properties = new Properties();
   properties.setCreationTime(new Date(System.currentTimeMillis()));
   properties.setTo(address);
   properties.setMessageId(UUID.randomUUID());

   MessageAnnotations annotations = new MessageAnnotations(new LinkedHashMap<>());
   ApplicationProperties applicationProperties = new ApplicationProperties(new LinkedHashMap<>());

   AmqpValue body = new AmqpValue(Arrays.copyOf(content, content.length));

   message.setHeader(header);
   message.setMessageAnnotations(annotations);
   message.setProperties(properties);
   message.setApplicationProperties(applicationProperties);
   message.setBody(body);

   return message;
}
 
Example #3
Source File: AmqpCodecTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Test that an amqp-value body containing a list results in an ObjectMessage
 * when not otherwise annotated to indicate the type of JMS message it is.
 *
 * @throws Exception if an error occurs during the test.
 */
@Test
public void testCreateAmqpObjectMessageFromAmqpValueWithList() throws Exception {
    Message message = Proton.message();
    List<String> list = new ArrayList<String>();
    message.setBody(new AmqpValue(list));

    JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage();
    assertNotNull("Message should not be null", jmsMessage);
    assertEquals("Unexpected message class type", JmsObjectMessage.class, jmsMessage.getClass());

    JmsMessageFacade facade = jmsMessage.getFacade();
    assertNotNull("Facade should not be null", facade);
    assertEquals("Unexpected facade class type", AmqpJmsObjectMessageFacade.class, facade.getClass());

    AmqpObjectTypeDelegate delegate = ((AmqpJmsObjectMessageFacade) facade).getDelegate();
    assertTrue("Unexpected delegate type: " + delegate, delegate instanceof AmqpTypedObjectDelegate);
}
 
Example #4
Source File: MessageTransformationTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testBodyOnlyEncodeDecode() throws Exception {
   MessageImpl incomingMessage = (MessageImpl) Proton.message();

   incomingMessage.setBody(new AmqpValue("String payload for AMQP message conversion performance testing."));

   ICoreMessage core = encodeAndCreateAMQPMessage(incomingMessage).toCore();
   AMQPMessage outboudMessage = AMQPConverter.getInstance().fromCore(core, null);

   assertNull(outboudMessage.getHeader());

   Section body = outboudMessage.getBody();
   assertNotNull(body);
   assertTrue(body instanceof AmqpValue);
   assertTrue(((AmqpValue) body).getValue() instanceof String);
}
 
Example #5
Source File: AmqpCodecTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Test that a data body containing nothing, but with the content type set to
 * {@value AmqpMessageSupport#OCTET_STREAM_CONTENT_TYPE} results in a BytesMessage when not
 * otherwise annotated to indicate the type of JMS message it is.
 *
 * @throws Exception if an error occurs during the test.
 */
@Test
public void testCreateBytesMessageFromDataWithEmptyBinaryAndContentType() throws Exception {
    Message message = Proton.message();
    Binary binary = new Binary(new byte[0]);
    message.setBody(new Data(binary));
    message.setContentType(AmqpMessageSupport.OCTET_STREAM_CONTENT_TYPE.toString());

    JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage();
    assertNotNull("Message should not be null", jmsMessage);
    assertEquals("Unexpected message class type", JmsBytesMessage.class, jmsMessage.getClass());

    JmsMessageFacade facade = jmsMessage.getFacade();
    assertNotNull("Facade should not be null", facade);
    assertEquals("Unexpected facade class type", AmqpJmsBytesMessageFacade.class, facade.getClass());
}
 
Example #6
Source File: AmqpCodecTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Test that an amqp-value body containing a value which can't be categorised results in
 * an ObjectMessage when not otherwise annotated to indicate the type of JMS message it is.
 *
 * @throws Exception if an error occurs during the test.
 */
@Test
public void testCreateObjectMessageFromAmqpValueWithUncategorisedContent() throws Exception {
    Message message = Proton.message();
    message.setBody(new AmqpValue(UUID.randomUUID()));

    JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage();
    assertNotNull("Message should not be null", jmsMessage);
    assertEquals("Unexpected message class type", JmsObjectMessage.class, jmsMessage.getClass());

    JmsMessageFacade facade = jmsMessage.getFacade();
    assertNotNull("Facade should not be null", facade);
    assertEquals("Unexpected facade class type", AmqpJmsObjectMessageFacade.class, facade.getClass());

    AmqpObjectTypeDelegate delegate = ((AmqpJmsObjectMessageFacade) facade).getDelegate();
    assertTrue("Unexpected delegate type: " + delegate, delegate instanceof AmqpTypedObjectDelegate);
}
 
Example #7
Source File: MessageTransformationTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testHeaderButNoPropertiesEncodeDecode() throws Exception {
   MessageImpl incomingMessage = (MessageImpl) Proton.message();

   incomingMessage.setBody(new AmqpValue("String payload for AMQP message conversion performance testing."));
   incomingMessage.setDurable(true);

   ICoreMessage core = encodeAndCreateAMQPMessage(incomingMessage).toCore();
   AMQPMessage outboudMessage = AMQPConverter.getInstance().fromCore(core, null);

   assertNotNull(outboudMessage.getHeader());

   Section body = outboudMessage.getBody();
   assertNotNull(body);
   assertTrue(body instanceof AmqpValue);
   assertTrue(((AmqpValue) body).getValue() instanceof String);
}
 
Example #8
Source File: DeferredSettlementTest.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
private Delivery sendMessageToClient(String deliveryTag, int messageBody)
{
    byte[] tag = deliveryTag.getBytes(StandardCharsets.UTF_8);

    Message m = Proton.message();
    m.setBody(new AmqpValue(messageBody));

    byte[] encoded = new byte[BUFFER_SIZE];
    int len = m.encode(encoded, 0, BUFFER_SIZE);

    assertTrue("given array was too small", len < BUFFER_SIZE);

    Sender serverSender = getServer().getSender();
    Delivery serverDelivery = serverSender.delivery(tag);
    int sent = serverSender.send(encoded, 0, len);

    assertEquals("sender unable to send all data at once as assumed for simplicity", len, sent);

    boolean senderAdvanced = serverSender.advance();
    assertTrue("sender has not advanced", senderAdvanced);

    return serverDelivery;
}
 
Example #9
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetRedeliveredWhenAlreadyRedeliveredDoesNotChangeDeliveryCount() {
    Message message = Proton.message();
    Header header = new Header();
    header.setDeliveryCount(new UnsignedInteger(1));
    message.setHeader(header);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    // Redelivered state inferred from delivery count
    assertTrue(amqpMessageFacade.isRedelivered());
    assertEquals(1, amqpMessageFacade.getRedeliveryCount());;

    amqpMessageFacade.setRedelivered(true);
    assertTrue(amqpMessageFacade.isRedelivered());
    assertEquals(1, amqpMessageFacade.getRedeliveryCount());;
}
 
Example #10
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Receive message which has a header section with a priority value. Ensure the headers
 * underlying field value is cleared when the priority is set to the default priority of 4.
 */
@Test
public void testSetPriorityToDefaultOnReceivedMessageWithPriorityClearsPriorityField() {
    byte priority = 11;

    Message message = Proton.message();
    Header header = new Header();
    message.setHeader(header);
    header.setPriority(UnsignedByte.valueOf(priority));

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);
    amqpMessageFacade.setPriority(Message.DEFAULT_PRIORITY);

    //check the expected value is still returned
    assertEquals("expected priority value not returned", Message.DEFAULT_PRIORITY, amqpMessageFacade.getPriority());

    //check the underlying header field was actually cleared rather than set to Message.DEFAULT_PRIORITY
    assertNull("underlying header priority field was not cleared", amqpMessageFacade.getHeader());
}
 
Example #11
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Check that getting the ReplyToGroupId returns the expected value from a
 * received messages with a reply-to-group-id.
 */
@Test
public void testGetReplyToGroupIdWithReceivedMessage() {
    String replyToGroupId = "myReplyGroup";

    Message message = Proton.message();

    Properties props = new Properties();
    props.setReplyToGroupId(replyToGroupId);
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    String actual = amqpMessageFacade.getReplyToGroupId();
    assertNotNull("expected ReplyToGroupId on message was not found", actual);
    assertEquals("expected ReplyToGroupId on message was not found", replyToGroupId, actual);
}
 
Example #12
Source File: AmqpCodecTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Test that a message with the {@value AmqpMessageSupport#JMS_MSG_TYPE}
 * annotation set to  {@value AmqpMessageSupport#JMS_BYTES_MESSAGE} is
 * treated as a {@link JmsTextMessage} with {@link AmqpJmsTextMessageFacade}
 *
 * @throws Exception if an error occurs during the test.
 */
@Test
public void testCreateTextMessageFromMessageTypeAnnotation() throws Exception {
    Message message = Proton.message();

    Map<Symbol, Object> map = new HashMap<Symbol, Object>();
    map.put(AmqpMessageSupport.JMS_MSG_TYPE, AmqpMessageSupport.JMS_TEXT_MESSAGE);

    MessageAnnotations messageAnnotations = new MessageAnnotations(map);
    message.setMessageAnnotations(messageAnnotations);

    JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage();
    assertNotNull("Message should not be null", jmsMessage);
    assertEquals("Unexpected message class type", JmsTextMessage.class, jmsMessage.getClass());

    JmsMessageFacade facade = jmsMessage.getFacade();
    assertNotNull("Facade should not be null", facade);
    assertEquals("Unexpected facade class type", AmqpJmsTextMessageFacade.class, facade.getClass());
}
 
Example #13
Source File: AmqpCodecTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Test that receiving a data body containing nothing, but with the content type set to
 * {@value AmqpMessageSupport#SERIALIZED_JAVA_OBJECT_CONTENT_TYPE} results in an ObjectMessage
 * when not otherwise annotated to indicate the type of JMS message it is.
 *
 * @throws Exception if an error occurs during the test.
 */
@Test
public void testCreateObjectMessageFromDataWithContentTypeAndEmptyBinary() throws Exception {
    Message message = Proton.message();
    Binary binary = new Binary(new byte[0]);
    message.setBody(new Data(binary));
    message.setContentType(AmqpMessageSupport.SERIALIZED_JAVA_OBJECT_CONTENT_TYPE.toString());

    JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage();
    assertNotNull("Message should not be null", jmsMessage);
    assertEquals("Unexpected message class type", JmsObjectMessage.class, jmsMessage.getClass());

    JmsMessageFacade facade = jmsMessage.getFacade();
    assertNotNull("Facade should not be null", facade);
    assertEquals("Unexpected facade class type", AmqpJmsObjectMessageFacade.class, facade.getClass());

    AmqpObjectTypeDelegate delegate = ((AmqpJmsObjectMessageFacade) facade).getDelegate();
    assertTrue("Unexpected delegate type: " + delegate, delegate instanceof AmqpSerializedObjectDelegate);
}
 
Example #14
Source File: FrameWriterBenchmark.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
public void initProton() {
    byteBuf = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE);
    this.decoder = new DecoderImpl();
    this.encoder = new EncoderImpl(decoder);
    AMQPDefinedTypes.registerAllTypes(decoder, encoder);

    transport = (TransportImpl) Proton.transport();
    frameWriter = new FrameWriter(encoder, 16 * 1024, (byte) 0, transport);

    transfer = new Transfer();
    transfer.setDeliveryId(UnsignedInteger.ONE);
    transfer.setHandle(UnsignedInteger.valueOf(16));
    transfer.setDeliveryTag(new Binary(new byte[] { 0, 1}));
    transfer.setMessageFormat(UnsignedInteger.ZERO);

    payload = ReadableBuffer.ByteBufferReader.wrap(PAYLOAD_BYTES);
}
 
Example #15
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetCorrelationIdBytesOnReceievedMessageWithBinaryId() throws Exception {
    Binary testCorrelationId = createBinaryId();
    byte[] bytes = testCorrelationId.getArray();

    Data payloadData = Data.Factory.create();
    PropertiesDescribedType props = new PropertiesDescribedType();
    props.setCorrelationId(new Binary(bytes));
    payloadData.putDescribedType(props);
    Binary b = payloadData.encode();

    System.out.println("Using encoded AMQP message payload: " + b);

    Message message = Proton.message();
    int decoded = message.decode(b.getArray(), b.getArrayOffset(), b.getLength());
    assertEquals(decoded, b.getLength());

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    assertEquals("Unexpected correlationId value on underlying AMQP message", testCorrelationId, amqpMessageFacade.getProperties().getCorrelationId());
    assertArrayEquals("Expected correlationId bytes not returned", bytes, amqpMessageFacade.getCorrelationIdBytes());
}
 
Example #16
Source File: AmqpCodecTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Test that a receiving a data body containing nothing and no content type being set
 * results in a BytesMessage when not otherwise annotated to indicate the type of
 * JMS message it is.
 *
 * @throws Exception if an error occurs during the test.
 */
@Test
public void testCreateBytesMessageFromDataWithEmptyBinaryAndNoContentType() throws Exception {
    Message message = Proton.message();
    Binary binary = new Binary(new byte[0]);
    message.setBody(new Data(binary));

    assertNull(message.getContentType());

    JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage();
    assertNotNull("Message should not be null", jmsMessage);
    assertEquals("Unexpected message class type", JmsBytesMessage.class, jmsMessage.getClass());

    JmsMessageFacade facade = jmsMessage.getFacade();
    assertNotNull("Facade should not be null", facade);
    assertEquals("Unexpected facade class type", AmqpJmsBytesMessageFacade.class, facade.getClass());
}
 
Example #17
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetUserIdBytesOnReceievedMessage() throws Exception {
    String userIdString = "testValue";
    byte[] bytes = userIdString.getBytes("UTF-8");

    Message message = Proton.message();

    message.setUserId(bytes);

    Properties props = new Properties();
    props.setUserId(new Binary(bytes));
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    assertNotNull("Expected a userid on received message", amqpMessageFacade.getUserIdBytes());
    assertArrayEquals("Incorrect userid bytes value received", bytes, amqpMessageFacade.getUserIdBytes());
}
 
Example #18
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetDeliveryCountForReceivedMessageWithHeaderWithDeliveryCount() {
    Message message = Proton.message();
    Header header = new Header();
    header.setDeliveryCount(new UnsignedInteger(1));
    message.setHeader(header);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    // JMS delivery count starts at one.
    assertEquals("expected delivery count value not found", 2, amqpMessageFacade.getDeliveryCount());

    // Redelivered state inferred from delivery count
    assertTrue(amqpMessageFacade.isRedelivered());
    assertEquals(1, amqpMessageFacade.getRedeliveryCount());;
}
 
Example #19
Source File: AmqpDefaultMessageConverter.java    From strimzi-kafka-bridge with Apache License 2.0 6 votes vote down vote up
@Override
public Message toMessage(String address, KafkaConsumerRecord<String, byte[]> record) {

    Message message = Proton.message();
    message.setAddress(address);

    // put message annotations about partition, offset and key (if not null)
    Map<Symbol, Object> map = new HashMap<>();
    map.put(Symbol.valueOf(AmqpBridge.AMQP_PARTITION_ANNOTATION), record.partition());
    map.put(Symbol.valueOf(AmqpBridge.AMQP_OFFSET_ANNOTATION), record.offset());
    map.put(Symbol.valueOf(AmqpBridge.AMQP_KEY_ANNOTATION), record.key());
    map.put(Symbol.valueOf(AmqpBridge.AMQP_TOPIC_ANNOTATION), record.topic());

    MessageAnnotations messageAnnotations = new MessageAnnotations(map);
    message.setMessageAnnotations(messageAnnotations);

    message.setBody(new Data(new Binary(record.value())));

    return message;
}
 
Example #20
Source File: JMSTransformationSpeedComparisonTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private MessageImpl createTypicalQpidJMSMessage() {
   Map<String, Object> applicationProperties = new HashMap<>();
   Map<Symbol, Object> messageAnnotations = new HashMap<>();

   applicationProperties.put("property-1", "string");
   applicationProperties.put("property-2", 512);
   applicationProperties.put("property-3", true);

   messageAnnotations.put(Symbol.valueOf("x-opt-jms-msg-type"), 0);
   messageAnnotations.put(Symbol.valueOf("x-opt-jms-dest"), 0);

   MessageImpl message = (MessageImpl) Proton.message();

   message.setAddress("queue://test-queue");
   message.setDeliveryCount(1);
   message.setApplicationProperties(new ApplicationProperties(applicationProperties));
   message.setMessageAnnotations(new MessageAnnotations(messageAnnotations));
   message.setCreationTime(System.currentTimeMillis());
   message.setContentType("text/plain");
   message.setBody(new AmqpValue("String payload for AMQP message conversion performance testing."));

   return message;
}
 
Example #21
Source File: AmqpCodecTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Test that a message with the {@value AmqpMessageSupport#JMS_MSG_TYPE}
 * annotation set to  {@value AmqpMessageSupport#JMS_STREAM_MESSAGE} is
 * treated as a {@link JmsStreamMessage} with {@link AmqpJmsStreamMessageFacade}
 *
 * @throws Exception if an error occurs during the test.
 */
@Test
public void testCreateStreamMessageFromMessageTypeAnnotation() throws Exception {
    Message message = Proton.message();

    Map<Symbol, Object> map = new HashMap<Symbol, Object>();
    map.put(AmqpMessageSupport.JMS_MSG_TYPE, AmqpMessageSupport.JMS_STREAM_MESSAGE);

    MessageAnnotations messageAnnotations = new MessageAnnotations(map);
    message.setMessageAnnotations(messageAnnotations);

    JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage();
    assertNotNull("Message should not be null", jmsMessage);
    assertEquals("Unexpected message class type", JmsStreamMessage.class, jmsMessage.getClass());

    JmsMessageFacade facade = jmsMessage.getFacade();
    assertNotNull("Facade should not be null", facade);
    assertEquals("Unexpected facade class type", AmqpJmsStreamMessageFacade.class, facade.getClass());
}
 
Example #22
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetProperties() throws Exception {
    Map<String, Object> applicationPropertiesMap = new HashMap<>();
    applicationPropertiesMap.put(TEST_PROP_A, TEST_VALUE_STRING_A);
    applicationPropertiesMap.put(TEST_PROP_B, TEST_VALUE_STRING_B);

    Message message2 = Proton.message();
    message2.setApplicationProperties(new ApplicationProperties(applicationPropertiesMap));

    JmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message2);

    Set<String> props = amqpMessageFacade.getPropertyNames();
    assertEquals(2, props.size());
    assertTrue(props.contains(TEST_PROP_A));
    assertEquals(TEST_VALUE_STRING_A, amqpMessageFacade.getProperty(TEST_PROP_A));
    assertTrue(props.contains(TEST_PROP_B));
    assertEquals(TEST_VALUE_STRING_B, amqpMessageFacade.getProperty(TEST_PROP_B));
}
 
Example #23
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetProperty() throws Exception {
    Message message = Proton.message();
    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    assertNull(amqpMessageFacade.getProperty(TEST_PROP_A));
    amqpMessageFacade.setProperty(TEST_PROP_A, TEST_VALUE_STRING_A);
    assertEquals(TEST_VALUE_STRING_A, amqpMessageFacade.getProperty(TEST_PROP_A));

    Map<String, Object> underlyingApplicationProps = amqpMessageFacade.getApplicationProperties().getValue();
    assertTrue(underlyingApplicationProps.containsKey(TEST_PROP_A));
    assertEquals(TEST_VALUE_STRING_A, underlyingApplicationProps.get(TEST_PROP_A));
}
 
Example #24
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
/**
 * When messages have a header section, but lack the priority field,
 * the AMQP spec says the priority has default value of 4.
 */
@Test
public void testGetPriorityIs4ForReceivedMessageWithHeaderButWithoutPriority() {
    Message message = Proton.message();

    Header header = new Header();
    message.setHeader(header);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    assertEquals("expected priority value not found", 4, amqpMessageFacade.getPriority());
}
 
Example #25
Source File: PubSubBroker.java    From enmasse with Apache License 2.0 5 votes vote down vote up
public synchronized void sendMessages(String address, List<String> messages) {
    Queue<Message> queue = queues.computeIfAbsent(address, a -> new ArrayDeque<>());
    for (String data : messages) {
        Message message = Proton.message();
        message.setBody(new AmqpValue(data));
        queue.add(message);
    }
}
 
Example #26
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
/**
 * Test that setting the Priority to the default value on a message with no
 * header section does not result in creating the header section.
 */
@Test
public void testSetDefaultPriorityForMessageWithoutHeaderSection() {
    // Using a received message as new messages to send are set durable by default, which creates the header
    Message message = Proton.message();
    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    assertNull("expected no header section to exist", message.getHeader());

    amqpMessageFacade.setPriority(Message.DEFAULT_PRIORITY);

    assertNull("expected no header section to exist", message.getHeader());
    assertEquals("expected priority to be default", Message.DEFAULT_PRIORITY, amqpMessageFacade.getPriority());
}
 
Example #27
Source File: Send.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    int port = 5672;
    String host = "localhost";
    if (args.length > 0) {
        String[] parts = args[0].split(":", 2);
        host = parts[0];
        if (parts.length > 1) {
            port = Integer.parseInt(parts[1]);
        }
    }
    String content = args.length > 1 ? args[1] : "Hello World!";

    Reactor r = Proton.reactor(new Send(host, port, content));
    r.run();
}
 
Example #28
Source File: CountRandomly.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    // In HelloWorld.java we said the reactor exits when there are no more
    // events to process. While this is true, it's not actually complete.
    // The reactor exits when there are no more events to process and no
    // possibility of future events arising. For that reason the reactor
    // will keep running until there are no more scheduled events and then
    // exit.
    Reactor reactor = Proton.reactor(new CountRandomly());
    reactor.run();
}
 
Example #29
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testClearAllMessageAnnotationsUsingNewMessage() {
    Message message = Proton.message();
    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    amqpMessageFacade.clearMessageAnnotations();

    assertNull(amqpMessageFacade.getMessageAnnotations());
}
 
Example #30
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
/**
 * When messages have a header section, which has a priority value above the
 * JMS range of 0-9 and also outside the signed byte range (given AMQP
 * allowing ubyte priority), ensure it is constrained to 9.
 */
@Test
public void testGetPriorityForReceivedMessageWithPriorityAboveSignedByteRange() {
    String priorityString = String.valueOf(255);

    Message message = Proton.message();
    Header header = new Header();
    message.setHeader(header);
    header.setPriority(UnsignedByte.valueOf(priorityString));

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    assertEquals("expected priority value not found", 9, amqpMessageFacade.getPriority());
}