本文整理汇总了Java中io.openmessaging.MessagingAccessPoint.createPullConsumer方法的典型用法代码示例。如果您正苦于以下问题:Java MessagingAccessPoint.createPullConsumer方法的具体用法?Java MessagingAccessPoint.createPullConsumer怎么用?Java MessagingAccessPoint.createPullConsumer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.openmessaging.MessagingAccessPoint
的用法示例。
在下文中一共展示了MessagingAccessPoint.createPullConsumer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import io.openmessaging.MessagingAccessPoint; //导入方法依赖的package包/类
@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();
}
示例2: init
import io.openmessaging.MessagingAccessPoint; //导入方法依赖的package包/类
@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();
}
示例3: main
import io.openmessaging.MessagingAccessPoint; //导入方法依赖的package包/类
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);
}
}
}
示例4: main
import io.openmessaging.MessagingAccessPoint; //导入方法依赖的package包/类
public static void main(String[] args) {
final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory
.getMessagingAccessPoint("oms:rocketmq://localhost:10911/us-east:namespace");
messagingAccessPoint.startup();
System.out.println("MessagingAccessPoint startup OK");
ResourceManager resourceManager = messagingAccessPoint.getResourceManager();
resourceManager.createQueue("NS1", "HELLO_QUEUE", OMS.newKeyValue());
//PullConsumer only can pull messages from one queue.
final PullConsumer pullConsumer = messagingAccessPoint.createPullConsumer("HELLO_QUEUE");
pullConsumer.startup();
//Poll one message from queue.
Message message = pullConsumer.poll();
//Acknowledges the consumed message
pullConsumer.ack(message.sysHeaders().getString(Message.BuiltinKeys.MessageId));
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
pullConsumer.shutdown();
messagingAccessPoint.shutdown();
}
}));
}