Search in sources :

Example 1 with BytesMessage

use of io.openmessaging.BytesMessage in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class AbstractOMSProducer method createBytesMessageToQueue.

@Override
public BytesMessage createBytesMessageToQueue(final String queue, final byte[] body) {
    BytesMessage bytesMessage = new BytesMessageImpl();
    bytesMessage.setBody(body);
    bytesMessage.headers().put(MessageHeader.QUEUE, queue);
    return bytesMessage;
}
Also used : BytesMessageImpl(io.openmessaging.rocketmq.domain.BytesMessageImpl) BytesMessage(io.openmessaging.BytesMessage)

Example 2 with BytesMessage

use of io.openmessaging.BytesMessage in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class PullConsumerImplTest method testPoll.

@Test
public void testPoll() {
    final byte[] testBody = new byte[] { 'a', 'b' };
    MessageExt consumedMsg = new MessageExt();
    consumedMsg.setMsgId("NewMsgId");
    consumedMsg.setBody(testBody);
    consumedMsg.putUserProperty(NonStandardKeys.MESSAGE_DESTINATION, "TOPIC");
    consumedMsg.setTopic(queueName);
    when(localMessageCache.poll()).thenReturn(consumedMsg);
    Message message = consumer.poll();
    assertThat(message.headers().getString(MessageHeader.MESSAGE_ID)).isEqualTo("NewMsgId");
    assertThat(((BytesMessage) message).getBody()).isEqualTo(testBody);
}
Also used : MessageExt(org.apache.rocketmq.common.message.MessageExt) Message(io.openmessaging.Message) BytesMessage(io.openmessaging.BytesMessage) BytesMessage(io.openmessaging.BytesMessage) Test(org.junit.Test)

Example 3 with BytesMessage

use of io.openmessaging.BytesMessage in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class PushConsumerImplTest method testConsumeMessage.

@Test
public void testConsumeMessage() {
    final byte[] testBody = new byte[] { 'a', 'b' };
    MessageExt consumedMsg = new MessageExt();
    consumedMsg.setMsgId("NewMsgId");
    consumedMsg.setBody(testBody);
    consumedMsg.putUserProperty(NonStandardKeys.MESSAGE_DESTINATION, "TOPIC");
    consumedMsg.setTopic("HELLO_QUEUE");
    consumer.attachQueue("HELLO_QUEUE", new MessageListener() {

        @Override
        public void onMessage(final Message message, final ReceivedMessageContext context) {
            assertThat(message.headers().getString(MessageHeader.MESSAGE_ID)).isEqualTo("NewMsgId");
            assertThat(((BytesMessage) message).getBody()).isEqualTo(testBody);
            context.ack();
        }
    });
    ((MessageListenerConcurrently) rocketmqPushConsumer.getMessageListener()).consumeMessage(Collections.singletonList(consumedMsg), null);
}
Also used : MessageExt(org.apache.rocketmq.common.message.MessageExt) MessageListenerConcurrently(org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently) Message(io.openmessaging.Message) BytesMessage(io.openmessaging.BytesMessage) MessageListener(io.openmessaging.MessageListener) ReceivedMessageContext(io.openmessaging.ReceivedMessageContext) Test(org.junit.Test)

Example 4 with BytesMessage

use of io.openmessaging.BytesMessage in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class SequenceProducerImplTest method testRollback.

@Test
public void testRollback() {
    when(rocketmqProducer.getMaxMessageSize()).thenReturn(1024);
    final BytesMessage message = producer.createBytesMessageToTopic("HELLO_TOPIC", new byte[] { 'a' });
    producer.send(message);
    producer.rollback();
    // Commit nothing.
    producer.commit();
    assertThat(message.headers().getString(MessageHeader.MESSAGE_ID)).isEqualTo(null);
}
Also used : BytesMessage(io.openmessaging.BytesMessage) Test(org.junit.Test)

Example 5 with BytesMessage

use of io.openmessaging.BytesMessage in project rocketmq by apache.

the class PullConsumerImplTest method testPoll.

@Test
public void testPoll() {
    final byte[] testBody = new byte[] { 'a', 'b' };
    MessageExt consumedMsg = new MessageExt();
    consumedMsg.setMsgId("NewMsgId");
    consumedMsg.setBody(testBody);
    consumedMsg.putUserProperty(NonStandardKeys.MESSAGE_DESTINATION, "TOPIC");
    consumedMsg.setTopic(queueName);
    when(localMessageCache.poll()).thenReturn(consumedMsg);
    Message message = consumer.poll();
    assertThat(message.headers().getString(MessageHeader.MESSAGE_ID)).isEqualTo("NewMsgId");
    assertThat(((BytesMessage) message).getBody()).isEqualTo(testBody);
}
Also used : MessageExt(org.apache.rocketmq.common.message.MessageExt) Message(io.openmessaging.Message) BytesMessage(io.openmessaging.BytesMessage) BytesMessage(io.openmessaging.BytesMessage) Test(org.junit.Test)

Aggregations

BytesMessage (io.openmessaging.BytesMessage)18 Test (org.junit.Test)8 Message (io.openmessaging.Message)6 BytesMessageImpl (io.openmessaging.rocketmq.domain.BytesMessageImpl)6 KeyValue (io.openmessaging.KeyValue)4 SendResult (org.apache.rocketmq.client.producer.SendResult)4 MessageExt (org.apache.rocketmq.common.message.MessageExt)4 MessageListener (io.openmessaging.MessageListener)2 ReceivedMessageContext (io.openmessaging.ReceivedMessageContext)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 MessageListenerConcurrently (org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently)2 MQClientException (org.apache.rocketmq.client.exception.MQClientException)2