io.openmessaging.rocketmq.domain.NonStandardKeys Java Examples

The following examples show how to use io.openmessaging.rocketmq.domain.NonStandardKeys. 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: PushConsumerImplTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: PushConsumerImplTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws NoSuchFieldException, IllegalAccessException {
    final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory
        .getMessagingAccessPoint("openmessaging:rocketmq://IP1:9876,IP2:9876/namespace");
    consumer = messagingAccessPoint.createPushConsumer(
        OMS.newKeyValue().put(NonStandardKeys.CONSUMER_GROUP, "TestGroup"));

    Field field = PushConsumerImpl.class.getDeclaredField("rocketmqPushConsumer");
    field.setAccessible(true);
    DefaultMQPushConsumer innerConsumer = (DefaultMQPushConsumer) field.get(consumer);
    field.set(consumer, rocketmqPushConsumer); //Replace

    when(rocketmqPushConsumer.getMessageListener()).thenReturn(innerConsumer.getMessageListener());
    messagingAccessPoint.startup();
    consumer.startup();
}
 
Example #3
Source File: PushConsumerImplTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws NoSuchFieldException, IllegalAccessException {
    final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory
        .getMessagingAccessPoint("openmessaging:rocketmq://IP1:9876,IP2:9876/namespace");
    consumer = messagingAccessPoint.createPushConsumer(
        OMS.newKeyValue().put(NonStandardKeys.CONSUMER_GROUP, "TestGroup"));

    Field field = PushConsumerImpl.class.getDeclaredField("rocketmqPushConsumer");
    field.setAccessible(true);
    DefaultMQPushConsumer innerConsumer = (DefaultMQPushConsumer) field.get(consumer);
    field.set(consumer, rocketmqPushConsumer); //Replace

    when(rocketmqPushConsumer.getMessageListener()).thenReturn(innerConsumer.getMessageListener());
    messagingAccessPoint.startup();
    consumer.startup();
}
 
Example #4
Source File: PushConsumerImplTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #5
Source File: PullConsumerImplTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws NoSuchFieldException, IllegalAccessException {
    final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory
        .getMessagingAccessPoint("openmessaging:rocketmq://IP1:9876,IP2:9876/namespace");

    consumer = messagingAccessPoint.createPullConsumer(queueName,
        OMS.newKeyValue().put(NonStandardKeys.CONSUMER_GROUP, "TestGroup"));

    Field field = PullConsumerImpl.class.getDeclaredField("rocketmqPullConsumer");
    field.setAccessible(true);
    field.set(consumer, rocketmqPullConsumer); //Replace

    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setOmsOperationTimeout(200);
    localMessageCache = spy(new LocalMessageCache(rocketmqPullConsumer, clientConfig));

    field = PullConsumerImpl.class.getDeclaredField("localMessageCache");
    field.setAccessible(true);
    field.set(consumer, localMessageCache);

    messagingAccessPoint.startup();
    consumer.startup();
}
 
Example #6
Source File: PullConsumerImplTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws NoSuchFieldException, IllegalAccessException {
    final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory
        .getMessagingAccessPoint("openmessaging:rocketmq://IP1:9876,IP2:9876/namespace");

    consumer = messagingAccessPoint.createPullConsumer(queueName,
        OMS.newKeyValue().put(NonStandardKeys.CONSUMER_GROUP, "TestGroup"));

    Field field = PullConsumerImpl.class.getDeclaredField("rocketmqPullConsumer");
    field.setAccessible(true);
    field.set(consumer, rocketmqPullConsumer); //Replace

    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setOmsOperationTimeout(200);
    localMessageCache = spy(new LocalMessageCache(rocketmqPullConsumer, clientConfig));

    field = PullConsumerImpl.class.getDeclaredField("localMessageCache");
    field.setAccessible(true);
    field.set(consumer, localMessageCache);

    messagingAccessPoint.startup();
    consumer.startup();
}
 
Example #7
Source File: PushConsumerImplTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@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 onReceived(Message message, Context context) {
            assertThat(message.sysHeaders().getString(Message.BuiltinKeys.MESSAGE_ID)).isEqualTo("NewMsgId");
            assertThat(((BytesMessage) message).getBody(byte[].class)).isEqualTo(testBody);
            context.ack();
        }
    });
    ((MessageListenerConcurrently) rocketmqPushConsumer
        .getMessageListener()).consumeMessage(Collections.singletonList(consumedMsg), null);
}
 
Example #8
Source File: PushConsumerImplTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@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 onReceived(Message message, Context context) {
            assertThat(message.sysHeaders().getString(Message.BuiltinKeys.MESSAGE_ID)).isEqualTo("NewMsgId");
            assertThat(((BytesMessage) message).getBody(byte[].class)).isEqualTo(testBody);
            context.ack();
        }
    });
    ((MessageListenerConcurrently) rocketmqPushConsumer
        .getMessageListener()).consumeMessage(Collections.singletonList(consumedMsg), null);
}
 
Example #9
Source File: PushConsumerImplTest.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@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 onReceived(Message message, Context context) {
            assertThat(message.sysHeaders().getString(Message.BuiltinKeys.MESSAGE_ID)).isEqualTo("NewMsgId");
            assertThat(((BytesMessage) message).getBody(byte[].class)).isEqualTo(testBody);
            context.ack();
        }
    });
    ((MessageListenerConcurrently) rocketmqPushConsumer
        .getMessageListener()).consumeMessage(Collections.singletonList(consumedMsg), null);
}
 
Example #10
Source File: PullConsumerImplTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws NoSuchFieldException, IllegalAccessException {
    final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory
        .getMessagingAccessPoint("openmessaging:rocketmq://IP1:9876,IP2:9876/namespace");
    consumer = messagingAccessPoint.createPullConsumer(queueName,
        OMS.newKeyValue().put(NonStandardKeys.CONSUMER_GROUP, "TestGroup"));

    Field field = PullConsumerImpl.class.getDeclaredField("rocketmqPullConsumer");
    field.setAccessible(true);
    field.set(consumer, rocketmqPullConsumer); //Replace

    field = PullConsumerImpl.class.getDeclaredField("localMessageCache");
    field.setAccessible(true);
    field.set(consumer, localMessageCache);

    messagingAccessPoint.startup();
    consumer.startup();
}
 
Example #11
Source File: PushConsumerImplTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws NoSuchFieldException, IllegalAccessException {
    final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory
        .getMessagingAccessPoint("openmessaging:rocketmq://IP1:9876,IP2:9876/namespace");
    consumer = messagingAccessPoint.createPushConsumer(
        OMS.newKeyValue().put(NonStandardKeys.CONSUMER_GROUP, "TestGroup"));

    Field field = PushConsumerImpl.class.getDeclaredField("rocketmqPushConsumer");
    field.setAccessible(true);
    DefaultMQPushConsumer innerConsumer = (DefaultMQPushConsumer) field.get(consumer);
    field.set(consumer, rocketmqPushConsumer); //Replace

    when(rocketmqPushConsumer.getMessageListener()).thenReturn(innerConsumer.getMessageListener());
    messagingAccessPoint.startup();
    consumer.startup();
}
 
Example #12
Source File: PushConsumerImplTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #13
Source File: SimplePushConsumer.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory
        .getMessagingAccessPoint("openmessaging:rocketmq://IP1:9876,IP2:9876/namespace");

    final PushConsumer consumer = messagingAccessPoint.
        createPushConsumer(OMS.newKeyValue().put(NonStandardKeys.CONSUMER_GROUP, "OMS_CONSUMER"));

    messagingAccessPoint.startup();
    System.out.printf("MessagingAccessPoint startup OK%n");

    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
            consumer.shutdown();
            messagingAccessPoint.shutdown();
        }
    }));

    consumer.attachQueue("OMS_HELLO_TOPIC", new MessageListener() {
        @Override
        public void onMessage(final Message message, final ReceivedMessageContext context) {
            System.out.printf("Received one message: %s%n", message.headers().getString(MessageHeader.MESSAGE_ID));
            context.ack();
        }
    });

    consumer.startup();
    System.out.printf("Consumer startup OK%n");
}
 
Example #14
Source File: LocalMessageCacheTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubmitConsumeRequest() throws Exception {
    byte [] body = new byte[]{'1', '2', '3'};
    MessageExt consumedMsg = new MessageExt();
    consumedMsg.setMsgId("NewMsgId");
    consumedMsg.setBody(body);
    consumedMsg.putUserProperty(NonStandardKeys.MESSAGE_DESTINATION, "TOPIC");
    consumedMsg.setTopic("HELLO_QUEUE");

    when(consumeRequest.getMessageExt()).thenReturn(consumedMsg);
    localMessageCache.submitConsumeRequest(consumeRequest);
    assertThat(localMessageCache.poll()).isEqualTo(consumedMsg);
}
 
Example #15
Source File: SimplePullConsumer.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory
        .getMessagingAccessPoint("openmessaging:rocketmq://IP1:9876,IP2:9876/namespace");

    final PullConsumer consumer = messagingAccessPoint.createPullConsumer("OMS_HELLO_TOPIC",
        OMS.newKeyValue().put(NonStandardKeys.CONSUMER_GROUP, "OMS_CONSUMER"));

    messagingAccessPoint.startup();
    System.out.printf("MessagingAccessPoint startup OK%n");

    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
            consumer.shutdown();
            messagingAccessPoint.shutdown();
        }
    }));

    consumer.startup();
    System.out.printf("Consumer startup OK%n");

    while (true) {
        Message message = consumer.poll();
        if (message != null) {
            String msgId = message.headers().getString(MessageHeader.MESSAGE_ID);
            System.out.printf("Received one message: %s%n", msgId);
            consumer.ack(msgId);
        }
    }
}
 
Example #16
Source File: BeanUtilsTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
    properties.put(NonStandardKeys.MAX_REDELIVERY_TIMES, 120);
    properties.put(CustomizedConfig.STRING_TEST, "kaka");
    properties.put(NonStandardKeys.CONSUMER_GROUP, "Default_Consumer_Group");
    properties.put(NonStandardKeys.MESSAGE_CONSUME_TIMEOUT, 101);

    properties.put(CustomizedConfig.LONG_TEST, 1234567890L);
    properties.put(CustomizedConfig.DOUBLE_TEST, 10.234);
}
 
Example #17
Source File: PullConsumerImplTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #18
Source File: OMSUtil.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
public static BytesMessage msgConvert(org.apache.rocketmq.common.message.MessageExt rmqMsg) {
    BytesMessage omsMsg = new BytesMessageImpl();
    omsMsg.setBody(rmqMsg.getBody());

    KeyValue headers = omsMsg.headers();
    KeyValue properties = omsMsg.properties();

    final Set<Map.Entry<String, String>> entries = rmqMsg.getProperties().entrySet();

    for (final Map.Entry<String, String> entry : entries) {
        if (isOMSHeader(entry.getKey())) {
            headers.put(entry.getKey(), entry.getValue());
        } else {
            properties.put(entry.getKey(), entry.getValue());
        }
    }

    omsMsg.putHeaders(MessageHeader.MESSAGE_ID, rmqMsg.getMsgId());
    if (!rmqMsg.getProperties().containsKey(NonStandardKeys.MESSAGE_DESTINATION) ||
        rmqMsg.getProperties().get(NonStandardKeys.MESSAGE_DESTINATION).equals("TOPIC")) {
        omsMsg.putHeaders(MessageHeader.TOPIC, rmqMsg.getTopic());
    } else {
        omsMsg.putHeaders(MessageHeader.QUEUE, rmqMsg.getTopic());
    }
    omsMsg.putHeaders(MessageHeader.SEARCH_KEY, rmqMsg.getKeys());
    omsMsg.putHeaders(MessageHeader.BORN_HOST, String.valueOf(rmqMsg.getBornHost()));
    omsMsg.putHeaders(MessageHeader.BORN_TIMESTAMP, rmqMsg.getBornTimestamp());
    omsMsg.putHeaders(MessageHeader.STORE_HOST, String.valueOf(rmqMsg.getStoreHost()));
    omsMsg.putHeaders(MessageHeader.STORE_TIMESTAMP, rmqMsg.getStoreTimestamp());
    return omsMsg;
}
 
Example #19
Source File: OMSUtil.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public static BytesMessage msgConvert(org.apache.rocketmq.common.message.MessageExt rmqMsg) {
    BytesMessage omsMsg = new BytesMessageImpl();
    omsMsg.setBody(rmqMsg.getBody());

    KeyValue headers = omsMsg.headers();
    KeyValue properties = omsMsg.properties();

    final Set<Map.Entry<String, String>> entries = rmqMsg.getProperties().entrySet();

    for (final Map.Entry<String, String> entry : entries) {
        if (isOMSHeader(entry.getKey())) {
            headers.put(entry.getKey(), entry.getValue());
        } else {
            properties.put(entry.getKey(), entry.getValue());
        }
    }

    omsMsg.putHeaders(MessageHeader.MESSAGE_ID, rmqMsg.getMsgId());
    if (!rmqMsg.getProperties().containsKey(NonStandardKeys.MESSAGE_DESTINATION) ||
        rmqMsg.getProperties().get(NonStandardKeys.MESSAGE_DESTINATION).equals("TOPIC")) {
        omsMsg.putHeaders(MessageHeader.TOPIC, rmqMsg.getTopic());
    } else {
        omsMsg.putHeaders(MessageHeader.QUEUE, rmqMsg.getTopic());
    }
    omsMsg.putHeaders(MessageHeader.SEARCH_KEY, rmqMsg.getKeys());
    omsMsg.putHeaders(MessageHeader.BORN_HOST, String.valueOf(rmqMsg.getBornHost()));
    omsMsg.putHeaders(MessageHeader.BORN_TIMESTAMP, rmqMsg.getBornTimestamp());
    omsMsg.putHeaders(MessageHeader.STORE_HOST, String.valueOf(rmqMsg.getStoreHost()));
    omsMsg.putHeaders(MessageHeader.STORE_TIMESTAMP, rmqMsg.getStoreTimestamp());
    return omsMsg;
}
 
Example #20
Source File: PullConsumerImplTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #21
Source File: BeanUtilsTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
    properties.put(NonStandardKeys.MAX_REDELIVERY_TIMES, 120);
    properties.put(CustomizedConfig.STRING_TEST, "kaka");
    properties.put(NonStandardKeys.CONSUMER_GROUP, "Default_Consumer_Group");
    properties.put(NonStandardKeys.MESSAGE_CONSUME_TIMEOUT, 101);

    properties.put(CustomizedConfig.LONG_TEST, 1234567890L);
    properties.put(CustomizedConfig.DOUBLE_TEST, 10.234);
}
 
Example #22
Source File: LocalMessageCacheTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubmitConsumeRequest() throws Exception {
    byte[] body = new byte[] {'1', '2', '3'};
    MessageExt consumedMsg = new MessageExt();
    consumedMsg.setMsgId("NewMsgId");
    consumedMsg.setBody(body);
    consumedMsg.putUserProperty(NonStandardKeys.MESSAGE_DESTINATION, "TOPIC");
    consumedMsg.setTopic("HELLO_QUEUE");

    when(consumeRequest.getMessageExt()).thenReturn(consumedMsg);
    localMessageCache.submitConsumeRequest(consumeRequest);
    assertThat(localMessageCache.poll()).isEqualTo(consumedMsg);
}
 
Example #23
Source File: PullConsumerImplTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@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.receive();
    assertThat(message.sysHeaders().getString(Message.BuiltinKeys.MESSAGE_ID)).isEqualTo("NewMsgId");
    assertThat(((BytesMessage) message).getBody(byte[].class)).isEqualTo(testBody);
}
 
Example #24
Source File: BeanUtilsTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
    properties.put(NonStandardKeys.MAX_REDELIVERY_TIMES, 120);
    properties.put(CustomizedConfig.STRING_TEST, "kaka");
    properties.put(NonStandardKeys.CONSUMER_GROUP, "Default_Consumer_Group");
    properties.put(NonStandardKeys.MESSAGE_CONSUME_TIMEOUT, 101);

    properties.put(CustomizedConfig.LONG_TEST, 1234567890L);
    properties.put(CustomizedConfig.DOUBLE_TEST, 10.234);
}
 
Example #25
Source File: PullConsumerImplTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@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.receive();
    assertThat(message.sysHeaders().getString(Message.BuiltinKeys.MESSAGE_ID)).isEqualTo("NewMsgId");
    assertThat(((BytesMessage) message).getBody(byte[].class)).isEqualTo(testBody);
}
 
Example #26
Source File: SimplePushConsumer.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory
        .getMessagingAccessPoint("openmessaging:rocketmq://IP1:9876,IP2:9876/namespace");

    final PushConsumer consumer = messagingAccessPoint.
        createPushConsumer(OMS.newKeyValue().put(NonStandardKeys.CONSUMER_GROUP, "OMS_CONSUMER"));

    messagingAccessPoint.startup();
    System.out.printf("MessagingAccessPoint startup OK%n");

    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
            consumer.shutdown();
            messagingAccessPoint.shutdown();
        }
    }));

    consumer.attachQueue("OMS_HELLO_TOPIC", new MessageListener() {
        @Override
        public void onMessage(final Message message, final ReceivedMessageContext context) {
            System.out.printf("Received one message: %s%n", message.headers().getString(MessageHeader.MESSAGE_ID));
            context.ack();
        }
    });

    consumer.startup();
    System.out.printf("Consumer startup OK%n");
}
 
Example #27
Source File: OMSUtil.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public static BytesMessage msgConvert(org.apache.rocketmq.common.message.MessageExt rmqMsg) {
    BytesMessage omsMsg = new BytesMessageImpl();
    omsMsg.setBody(rmqMsg.getBody());

    KeyValue headers = omsMsg.headers();
    KeyValue properties = omsMsg.properties();

    final Set<Map.Entry<String, String>> entries = rmqMsg.getProperties().entrySet();

    for (final Map.Entry<String, String> entry : entries) {
        if (isOMSHeader(entry.getKey())) {
            headers.put(entry.getKey(), entry.getValue());
        } else {
            properties.put(entry.getKey(), entry.getValue());
        }
    }

    omsMsg.putHeaders(MessageHeader.MESSAGE_ID, rmqMsg.getMsgId());
    if (!rmqMsg.getProperties().containsKey(NonStandardKeys.MESSAGE_DESTINATION) ||
        rmqMsg.getProperties().get(NonStandardKeys.MESSAGE_DESTINATION).equals("TOPIC")) {
        omsMsg.putHeaders(MessageHeader.TOPIC, rmqMsg.getTopic());
    } else {
        omsMsg.putHeaders(MessageHeader.QUEUE, rmqMsg.getTopic());
    }
    omsMsg.putHeaders(MessageHeader.SEARCH_KEY, rmqMsg.getKeys());
    omsMsg.putHeaders(MessageHeader.BORN_HOST, String.valueOf(rmqMsg.getBornHost()));
    omsMsg.putHeaders(MessageHeader.BORN_TIMESTAMP, rmqMsg.getBornTimestamp());
    omsMsg.putHeaders(MessageHeader.STORE_HOST, String.valueOf(rmqMsg.getStoreHost()));
    omsMsg.putHeaders(MessageHeader.STORE_TIMESTAMP, rmqMsg.getStoreTimestamp());
    return omsMsg;
}
 
Example #28
Source File: LocalMessageCacheTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubmitConsumeRequest() throws Exception {
    byte[] body = new byte[] {'1', '2', '3'};
    MessageExt consumedMsg = new MessageExt();
    consumedMsg.setMsgId("NewMsgId");
    consumedMsg.setBody(body);
    consumedMsg.putUserProperty(NonStandardKeys.MESSAGE_DESTINATION, "TOPIC");
    consumedMsg.setTopic("HELLO_QUEUE");

    when(consumeRequest.getMessageExt()).thenReturn(consumedMsg);
    localMessageCache.submitConsumeRequest(consumeRequest);
    assertThat(localMessageCache.poll()).isEqualTo(consumedMsg);
}
 
Example #29
Source File: PullConsumerImplTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #30
Source File: BeanUtilsTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
    properties.put(NonStandardKeys.MAX_REDELIVERY_TIMES, 120);
    properties.put(CustomizedConfig.STRING_TEST, "kaka");
    properties.put(NonStandardKeys.CONSUMER_GROUP, "Default_Consumer_Group");
    properties.put(NonStandardKeys.MESSAGE_CONSUME_TIMEOUT, 101);

    properties.put(CustomizedConfig.LONG_TEST, 1234567890L);
    properties.put(CustomizedConfig.DOUBLE_TEST, 10.234);
}