Search in sources :

Example 6 with MessagingAccessPoint

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

the class SequenceProducerImplTest method init.

@Before
public void init() throws NoSuchFieldException, IllegalAccessException {
    final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory.getMessagingAccessPoint("openmessaging:rocketmq://IP1:9876,IP2:9876/namespace");
    producer = messagingAccessPoint.createSequenceProducer();
    Field field = AbstractOMSProducer.class.getDeclaredField("rocketmqProducer");
    field.setAccessible(true);
    field.set(producer, rocketmqProducer);
    messagingAccessPoint.startup();
    producer.startup();
}
Also used : Field(java.lang.reflect.Field) MessagingAccessPoint(io.openmessaging.MessagingAccessPoint) Before(org.junit.Before)

Example 7 with MessagingAccessPoint

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

the class PullConsumerImplTest method init.

@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);
    // Replace
    field.set(consumer, rocketmqPullConsumer);
    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();
}
Also used : Field(java.lang.reflect.Field) MessagingAccessPoint(io.openmessaging.MessagingAccessPoint) ClientConfig(io.openmessaging.rocketmq.config.ClientConfig) Before(org.junit.Before)

Example 8 with MessagingAccessPoint

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

the class ProducerImplTest method init.

@Before
public void init() throws NoSuchFieldException, IllegalAccessException {
    final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory.getMessagingAccessPoint("openmessaging:rocketmq://IP1:9876,IP2:9876/namespace");
    producer = messagingAccessPoint.createProducer();
    Field field = AbstractOMSProducer.class.getDeclaredField("rocketmqProducer");
    field.setAccessible(true);
    field.set(producer, rocketmqProducer);
    messagingAccessPoint.startup();
    producer.startup();
}
Also used : Field(java.lang.reflect.Field) MessagingAccessPoint(io.openmessaging.MessagingAccessPoint) Before(org.junit.Before)

Example 9 with MessagingAccessPoint

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

the class SequenceProducerImplTest method init.

@Before
public void init() throws NoSuchFieldException, IllegalAccessException {
    final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory.getMessagingAccessPoint("openmessaging:rocketmq://IP1:9876,IP2:9876/namespace");
    producer = messagingAccessPoint.createSequenceProducer();
    Field field = AbstractOMSProducer.class.getDeclaredField("rocketmqProducer");
    field.setAccessible(true);
    field.set(producer, rocketmqProducer);
    messagingAccessPoint.startup();
    producer.startup();
}
Also used : Field(java.lang.reflect.Field) MessagingAccessPoint(io.openmessaging.MessagingAccessPoint) Before(org.junit.Before)

Example 10 with MessagingAccessPoint

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

the class SimplePullConsumer method main.

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);
        }
    }
}
Also used : Message(io.openmessaging.Message) MessagingAccessPoint(io.openmessaging.MessagingAccessPoint) PullConsumer(io.openmessaging.PullConsumer)

Aggregations

MessagingAccessPoint (io.openmessaging.MessagingAccessPoint)14 Field (java.lang.reflect.Field)8 Before (org.junit.Before)8 Message (io.openmessaging.Message)6 MessageListener (io.openmessaging.MessageListener)2 Producer (io.openmessaging.Producer)2 Promise (io.openmessaging.Promise)2 PromiseListener (io.openmessaging.PromiseListener)2 PullConsumer (io.openmessaging.PullConsumer)2 PushConsumer (io.openmessaging.PushConsumer)2 ReceivedMessageContext (io.openmessaging.ReceivedMessageContext)2 SendResult (io.openmessaging.SendResult)2 DefaultMQPushConsumer (org.apache.rocketmq.client.consumer.DefaultMQPushConsumer)2 ClientConfig (io.openmessaging.rocketmq.config.ClientConfig)1