Java Code Examples for org.apache.qpid.proton.amqp.messaging.Properties#setTo()

The following examples show how to use org.apache.qpid.proton.amqp.messaging.Properties#setTo() . 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: Benchmark.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
private void benchmarkProperties() throws IOException {
    Properties properties = new Properties();
    properties.setTo("queue:1-1024");
    properties.setReplyTo("queue:1-11024-reply");
    properties.setMessageId("ID:255f1297-5a71-4df1-8147-b2cdf850a56f:1");
    properties.setCreationTime(new Date(System.currentTimeMillis()));

    resultSet.start();
    for (int i = 0; i < ITERATIONS; i++) {
        outputBuf.byteBuffer().clear();
        encoder.writeObject(properties);
    }
    resultSet.encodesComplete();

    CompositeReadableBuffer inputBuf = convertToComposite(outputBuf);
    decoder.setBuffer(inputBuf);

    resultSet.start();
    for (int i = 0; i < ITERATIONS; i++) {
        decoder.readObject();
        inputBuf.flip();
    }
    resultSet.decodesComplete();

    time("Properties", resultSet);
}
 
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: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetDestinationWithReceivedMessage() throws JMSException {
    String testToAddress = "myTestAddress";

    Message message = Proton.message();

    Properties props = new Properties();
    props.setTo(testToAddress);
    message.setProperties(props);

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

    JmsDestination dest = amqpMessageFacade.getDestination();
    //We didn't set any destination type annotations, so the consumer destination type will be used: a topic.
    assertTrue(dest instanceof Topic);
    assertEquals(testToAddress, ((Topic) dest).getTopicName());
}
 
Example 4
Source File: PropertiesBenchmark.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
private void initProperties()
{
    properties = new Properties();
    properties.setTo("queue:1");
    properties.setMessageId("ID:Message:1");
    properties.setCreationTime(new Date(System.currentTimeMillis()));
}
 
Example 5
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetSendBufferWithoutDeliveryAnnotations() {
   MessageImpl protonMessage = (MessageImpl) Message.Factory.create();
   Header header = new Header();
   header.setDeliveryCount(new UnsignedInteger(1));
   protonMessage.setHeader(header);
   Properties properties = new Properties();
   properties.setTo("someNiceLocal");
   protonMessage.setProperties(properties);
   protonMessage.setBody(new AmqpValue("Sample payload"));

   DeliveryAnnotations deliveryAnnotations = new DeliveryAnnotations(new HashMap<>());
   final String annotationKey = "annotationKey";
   final String annotationValue = "annotationValue";
   deliveryAnnotations.getValue().put(Symbol.getSymbol(annotationKey), annotationValue);
   protonMessage.setDeliveryAnnotations(deliveryAnnotations);

   AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage);

   ReadableBuffer sendBuffer = decoded.getSendBuffer(1);
   assertEquals(decoded.getEncodeSize(), sendBuffer.capacity());
   AMQPStandardMessage msgFromSendBuffer = new AMQPStandardMessage(0, sendBuffer, null, null);
   assertEquals("someNiceLocal", msgFromSendBuffer.getAddress());
   assertNull(msgFromSendBuffer.getDeliveryAnnotations());

   // again with higher deliveryCount
   ReadableBuffer sendBuffer2 = decoded.getSendBuffer(5);
   assertEquals(decoded.getEncodeSize(), sendBuffer2.capacity());
   AMQPStandardMessage msgFromSendBuffer2 = new AMQPStandardMessage(0, sendBuffer2, null, null);
   assertEquals("someNiceLocal", msgFromSendBuffer2.getAddress());
   assertNull(msgFromSendBuffer2.getDeliveryAnnotations());
}
 
Example 6
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private MessageImpl createProtonMessage() {
   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(TEST_TO_ADDRESS);
   properties.setMessageId(UUID.randomUUID());

   MessageAnnotations annotations = new MessageAnnotations(new LinkedHashMap<>());
   annotations.getValue().put(Symbol.valueOf(TEST_MESSAGE_ANNOTATION_KEY), TEST_MESSAGE_ANNOTATION_VALUE);

   ApplicationProperties applicationProperties = new ApplicationProperties(new LinkedHashMap<>());
   applicationProperties.getValue().put(TEST_APPLICATION_PROPERTY_KEY, TEST_APPLICATION_PROPERTY_VALUE);

   AmqpValue body = new AmqpValue(TEST_STRING_BODY);

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

   return message;
}
 
Example 7
Source File: FastPathPropertiesType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
public Properties readValue() {
    DecoderImpl decoder = getDecoder();
    ReadableBuffer buffer = decoder.getBuffer();
    byte typeCode = decoder.getBuffer().get();

    @SuppressWarnings("unused")
    int size = 0;
    int count = 0;

    switch (typeCode) {
        case EncodingCodes.LIST0:
            break;
        case EncodingCodes.LIST8:
            size = buffer.get() & 0xff;
            count = buffer.get() & 0xff;
            break;
        case EncodingCodes.LIST32:
            size = buffer.getInt();
            count = buffer.getInt();
            break;
        default:
            throw new DecodeException("Incorrect type found in Properties encoding: " + typeCode);
    }

    Properties properties = new Properties();

    for (int index = 0; index < count; ++index) {
        switch (index) {
            case 0:
                properties.setMessageId(decoder.readObject());
                break;
            case 1:
                properties.setUserId(decoder.readBinary(null));
                break;
            case 2:
                properties.setTo(decoder.readString(null));
                break;
            case 3:
                properties.setSubject(decoder.readString(null));
                break;
            case 4:
                properties.setReplyTo(decoder.readString(null));
                break;
            case 5:
                properties.setCorrelationId(decoder.readObject());
                break;
            case 6:
                properties.setContentType(decoder.readSymbol(null));
                break;
            case 7:
                properties.setContentEncoding(decoder.readSymbol(null));
                break;
            case 8:
                properties.setAbsoluteExpiryTime(decoder.readTimestamp(null));
                break;
            case 9:
                properties.setCreationTime(decoder.readTimestamp(null));
                break;
            case 10:
                properties.setGroupId(decoder.readString(null));
                break;
            case 11:
                properties.setGroupSequence(decoder.readUnsignedInteger(null));
                break;
            case 12:
                properties.setReplyToGroupId(decoder.readString(null));
                break;
            default:
                throw new IllegalStateException("To many entries in Properties encoding");
        }
    }

    return properties;
}
 
Example 8
Source File: PropertiesType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
public Properties newInstance(Object described)
{
    List l = (List) described;

    Properties o = new Properties();


    switch(13 - l.size())
    {

        case 0:
            o.setReplyToGroupId( (String) l.get( 12 ) );
        case 1:
            o.setGroupSequence( (UnsignedInteger) l.get( 11 ) );
        case 2:
            o.setGroupId( (String) l.get( 10 ) );
        case 3:
            o.setCreationTime( (Date) l.get( 9 ) );
        case 4:
            o.setAbsoluteExpiryTime( (Date) l.get( 8 ) );
        case 5:
            o.setContentEncoding( (Symbol) l.get( 7 ) );
        case 6:
            o.setContentType( (Symbol) l.get( 6 ) );
        case 7:
            o.setCorrelationId( (Object) l.get( 5 ) );
        case 8:
            o.setReplyTo( (String) l.get( 4 ) );
        case 9:
            o.setSubject( (String) l.get( 3 ) );
        case 10:
            o.setTo( (String) l.get( 2 ) );
        case 11:
            o.setUserId( (Binary) l.get( 1 ) );
        case 12:
            o.setMessageId( (Object) l.get( 0 ) );
    }


    return o;
}
 
Example 9
Source File: PropertiesCodecTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
private void doTestDecodePropertiesSeries(int size) throws IOException {
    Properties properties = new Properties();

    Date timeNow = new Date(System.currentTimeMillis());

    properties.setMessageId("ID:Message-1:1:1:0");
    properties.setUserId(new Binary(new byte[1]));
    properties.setTo("queue:work");
    properties.setSubject("help");
    properties.setReplyTo("queue:temp:me");
    properties.setContentEncoding(Symbol.valueOf("text/UTF-8"));
    properties.setContentType(Symbol.valueOf("text"));
    properties.setCorrelationId("correlation-id");
    properties.setAbsoluteExpiryTime(timeNow);
    properties.setCreationTime(timeNow);
    properties.setGroupId("group-1");
    properties.setGroupSequence(UnsignedInteger.valueOf(1));
    properties.setReplyToGroupId("group-1");

    for (int i = 0; i < size; ++i) {
        encoder.writeObject(properties);
    }

    buffer.clear();

    for (int i = 0; i < size; ++i) {
        final Object result = decoder.readObject();

        assertNotNull(result);
        assertTrue(result instanceof Properties);

        Properties decoded = (Properties) result;

        assertNotNull(decoded.getAbsoluteExpiryTime());
        assertEquals(timeNow, decoded.getAbsoluteExpiryTime());
        assertEquals(Symbol.valueOf("text/UTF-8"), decoded.getContentEncoding());
        assertEquals(Symbol.valueOf("text"), decoded.getContentType());
        assertEquals("correlation-id", decoded.getCorrelationId());
        assertEquals(timeNow, decoded.getCreationTime());
        assertEquals("group-1", decoded.getGroupId());
        assertEquals(UnsignedInteger.valueOf(1), decoded.getGroupSequence());
        assertEquals("ID:Message-1:1:1:0", decoded.getMessageId());
        assertEquals("queue:temp:me", decoded.getReplyTo());
        assertEquals("group-1", decoded.getReplyToGroupId());
        assertEquals("help", decoded.getSubject());
        assertEquals("queue:work", decoded.getTo());
        assertTrue(decoded.getUserId() instanceof Binary);
    }
}
 
Example 10
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testDecodeMultiThreaded() throws Exception {
   MessageImpl protonMessage = (MessageImpl) Message.Factory.create();
   protonMessage.setHeader( new Header());
   Properties properties = new Properties();
   properties.setTo("someNiceLocal");
   protonMessage.setProperties(properties);
   protonMessage.getHeader().setDeliveryCount(new UnsignedInteger(7));
   protonMessage.getHeader().setDurable(Boolean.TRUE);
   protonMessage.setApplicationProperties(new ApplicationProperties(new HashMap<>()));

   final AtomicInteger failures = new AtomicInteger(0);


   for (int testTry = 0; testTry < 100; testTry++) {
      AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage);
      Thread[] threads = new Thread[100];

      CountDownLatch latchAlign = new CountDownLatch(threads.length);
      CountDownLatch go = new CountDownLatch(1);

      Runnable run = new Runnable() {
         @Override
         public void run() {
            try {

               latchAlign.countDown();
               go.await();

               Assert.assertNotNull(decoded.getHeader());
               // this is a method used by Core Converter
               decoded.getProtonMessage();
               Assert.assertNotNull(decoded.getHeader());

            } catch (Throwable e) {
               e.printStackTrace();
               failures.incrementAndGet();
            }
         }
      };

      for (int i = 0; i < threads.length; i++) {
         threads[i] = new Thread(run);
         threads[i].start();
      }

      Assert.assertTrue(latchAlign.await(10, TimeUnit.SECONDS));
      go.countDown();

      for (Thread thread : threads) {
         thread.join(5000);
         Assert.assertFalse(thread.isAlive());
      }

      Assert.assertEquals(0, failures.get());
   }
}
 
Example 11
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetSendBufferWithDeliveryAnnotations() {
   MessageImpl protonMessage = (MessageImpl) Message.Factory.create();
   Header header = new Header();
   header.setDeliveryCount(new UnsignedInteger(1));
   protonMessage.setHeader(header);
   Properties properties = new Properties();
   properties.setTo("someNiceLocal");
   protonMessage.setProperties(properties);
   protonMessage.setBody(new AmqpValue("Sample payload"));

   AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage);

   DeliveryAnnotations newDeliveryAnnotations = new DeliveryAnnotations(new HashMap<>());
   final String annotationKey = "annotationKey";
   final String annotationValue = "annotationValue";
   newDeliveryAnnotations.getValue().put(Symbol.getSymbol(annotationKey), annotationValue);
   decoded.setDeliveryAnnotationsForSendBuffer(newDeliveryAnnotations);

   ReadableBuffer sendBuffer = decoded.getSendBuffer(1);
   assertEquals(decoded.getEncodeSize(), sendBuffer.capacity());
   AMQPStandardMessage msgFromSendBuffer = new AMQPStandardMessage(0, sendBuffer, null, null);
   assertEquals("someNiceLocal", msgFromSendBuffer.getAddress());
   assertNotNull(msgFromSendBuffer.getDeliveryAnnotations());
   assertEquals(1, msgFromSendBuffer.getDeliveryAnnotations().getValue().size());
   assertEquals(annotationValue, msgFromSendBuffer.getDeliveryAnnotations().getValue().get(Symbol.getSymbol(annotationKey)));

   // again with higher deliveryCount
   DeliveryAnnotations newDeliveryAnnotations2 = new DeliveryAnnotations(new HashMap<>());
   final String annotationKey2 = "annotationKey2";
   final String annotationValue2 = "annotationValue2";
   newDeliveryAnnotations2.getValue().put(Symbol.getSymbol(annotationKey2), annotationValue2);
   decoded.setDeliveryAnnotationsForSendBuffer(newDeliveryAnnotations2);

   ReadableBuffer sendBuffer2 = decoded.getSendBuffer(5);
   assertEquals(decoded.getEncodeSize(), sendBuffer2.capacity());
   AMQPStandardMessage msgFromSendBuffer2 = new AMQPStandardMessage(0, sendBuffer2, null, null);
   assertEquals("someNiceLocal", msgFromSendBuffer2.getAddress());
   assertNotNull(msgFromSendBuffer2.getDeliveryAnnotations());
   assertEquals(1, msgFromSendBuffer2.getDeliveryAnnotations().getValue().size());
   assertEquals(annotationValue2, msgFromSendBuffer2.getDeliveryAnnotations().getValue().get(Symbol.getSymbol(annotationKey2)));
}