本文整理汇总了Java中io.openmessaging.MessagingAccessPoint类的典型用法代码示例。如果您正苦于以下问题:Java MessagingAccessPoint类的具体用法?Java MessagingAccessPoint怎么用?Java MessagingAccessPoint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessagingAccessPoint类属于io.openmessaging包,在下文中一共展示了MessagingAccessPoint类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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.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();
}
示例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
field = PullConsumerImpl.class.getDeclaredField("localMessageCache");
field.setAccessible(true);
field.set(consumer, localMessageCache);
messagingAccessPoint.startup();
consumer.startup();
}
示例3: getMessagingAccessPoint
import io.openmessaging.MessagingAccessPoint; //导入依赖的package包/类
/**
* Returns a {@code MessagingAccessPoint} instance from the specified OMS driver URL
* with some preset userHeaders.
*
* @param url the driver URL
* @param properties the preset userHeaders
* @return a {@code MessagingAccessPoint} instance
* @throws OMSRuntimeException if the adapter fails to create a {@code MessagingAccessPoint} instance from the URL
*/
public static MessagingAccessPoint getMessagingAccessPoint(String url, KeyValue properties) {
AccessPointURI accessPointURI = new AccessPointURI(url);
String driverImpl = parseDriverImpl(accessPointURI.getDriverType(), properties);
properties.put(OMSBuiltinKeys.NAMESPACE, accessPointURI.getNamespace());
properties.put(OMSBuiltinKeys.ACCESS_POINTS, accessPointURI.getHosts());
properties.put(OMSBuiltinKeys.DRIVER_IMPL, driverImpl);
properties.put(OMSBuiltinKeys.REGION, accessPointURI.getRegion());
properties.put(OMSBuiltinKeys.ACCOUNT_ID, accessPointURI.getAccountId());
try {
Class<?> driverImplClass = Class.forName(driverImpl);
Constructor constructor = driverImplClass.getConstructor(KeyValue.class);
MessagingAccessPoint vendorImpl = (MessagingAccessPoint) constructor.newInstance(properties);
checkSpecVersion(OMS.specVersion, vendorImpl.implVersion());
return vendorImpl;
} catch (Throwable e) {
throw generateInternalException(InternalErrorCode.OMS_DRIVER_URL_UNAVAILABLE, url);
}
}
示例4: 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();
}
示例5: 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);
}
}
}
示例6: 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 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");
}
示例7: 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");
producer = messagingAccessPoint.createProducer();
Field field = AbstractOMSProducer.class.getDeclaredField("rocketmqProducer");
field.setAccessible(true);
field.set(producer, rocketmqProducer);
messagingAccessPoint.startup();
producer.startup();
}
示例8: 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");
producer = messagingAccessPoint.createSequenceProducer();
Field field = AbstractOMSProducer.class.getDeclaredField("rocketmqProducer");
field.setAccessible(true);
field.set(producer, rocketmqProducer);
messagingAccessPoint.startup();
producer.startup();
}
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:14,代码来源:SequenceProducerImplTest.java
示例9: wrapMessagingAccessPoint
import io.openmessaging.MessagingAccessPoint; //导入依赖的package包/类
public static MessagingAccessPoint wrapMessagingAccessPoint(MessagingAccessPoint messagingAccessPoint) {
MessagingAccessPoint newMessagingAccessPoint = messagingAccessPoint;
for (int i = 0; i < listObjectInterceptor.size(); i++) {
try {
final MessagingAccessPoint nextMessagingAccessPoint = newMessagingAccessPoint;
final MessagingAccessPoint thisMessagingAccessPoint = listObjectInterceptor.get(i).constructMessagingAccessPoint(
new MessagingAccessPointInterceptor.ConstructMessagingAccessPointContext() {
@Override
public MessagingAccessPoint messagingAccessPoint() {
return nextMessagingAccessPoint;
}
@Override
public KeyValue properties() {
return nextMessagingAccessPoint.properties();
}
});
if (thisMessagingAccessPoint != null) {
newMessagingAccessPoint = thisMessagingAccessPoint;
}
} catch (Throwable e) {
}
}
return newMessagingAccessPoint;
}
开发者ID:openmessaging,项目名称:openmessaging-java,代码行数:30,代码来源:MessagingAccessPointInterceptorFactory.java
示例10: main
import io.openmessaging.MessagingAccessPoint; //导入依赖的package包/类
public static void main(String[] args) {
final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory
.getMessagingAccessPoint("oms:rocketmq://localhost:10911/us-east:namespace");
final Producer producer = messagingAccessPoint.createProducer();
messagingAccessPoint.startup();
System.out.println("MessagingAccessPoint startup OK");
producer.startup();
System.out.println("Producer startup OK");
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
producer.shutdown();
messagingAccessPoint.shutdown();
}
}));
SendResult result = producer.send(producer.createTopicBytesMessage(
"HELLO_TOPIC1", "HELLO_BODY1".getBytes(Charset.forName("UTF-8"))));
System.out.println("Send first message to topic OK, message id is: " + result.messageId());
producer.send(producer.createTopicBytesMessage(
"HELLO_TOPIC2", "HELLO_BODY2".getBytes(Charset.forName("UTF-8")))
.putUserHeaders("KEY1", 100)
.putUserHeaders("KEY2", 200L)
.putUserHeaders("KEY3", 3.14)
.putUserHeaders("KEY4", "value4")
);
System.out.println("Send second message to topic OK");
producer.send(producer.createQueueBytesMessage(
"HELLO_QUEUE", "HELLO_BODY".getBytes(Charset.forName("UTF-8"))));
System.out.println("send third message to queue OK");
}
示例11: 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();
}
}));
}
示例12: main
import io.openmessaging.MessagingAccessPoint; //导入依赖的package包/类
public static void main(String[] args) throws OMSResourceNotExistException {
final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory
.getMessagingAccessPoint("oms:rocketmq://localhost:10911/us-east:namespace");
messagingAccessPoint.startup();
System.out.println("MessagingAccessPoint startup OK");
ResourceManager resourceManager = messagingAccessPoint.getResourceManager();
final PushConsumer consumer = messagingAccessPoint.createPushConsumer();
// Consume messages from a simple queue.
{
String simpleQueue = "HELLO_QUEUE";
resourceManager.createQueue("NS1", simpleQueue, OMS.newKeyValue());
//This queue doesn't has a source topic, so only the message delivered to the queue directly can
//be consumed by this consumer.
consumer.attachQueue(simpleQueue, new MessageListener() {
@Override
public void onReceived(Message message, Context context) {
System.out.println("Received one message: " + message);
context.ack();
}
});
consumer.startup();
System.out.println("Consumer startup OK");
}
//Consume messages from a complex queue.
final PushConsumer anotherConsumer = messagingAccessPoint.createPushConsumer();
{
String complexQueue = "QUEUE_HAS_SOURCE_TOPIC";
String sourceTopic = "SOURCE_TOPIC";
//Create the complex queue.
resourceManager.createQueue("NS_01", complexQueue, OMS.newKeyValue());
//Create the source topic.
resourceManager.createTopic("NS_01", sourceTopic, OMS.newKeyValue());
}
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
consumer.shutdown();
anotherConsumer.shutdown();
messagingAccessPoint.shutdown();
}
}));
}
示例13: constructMessagingAccessPoint
import io.openmessaging.MessagingAccessPoint; //导入依赖的package包/类
/**
* Constructs a new {@code MessagingAccessPoint} instance based on context.
*
* @param context the construct context
* @return a {@code MessagingAccessPoint} instance
*/
MessagingAccessPoint constructMessagingAccessPoint(ConstructMessagingAccessPointContext context);
示例14: messagingAccessPoint
import io.openmessaging.MessagingAccessPoint; //导入依赖的package包/类
/**
* Returns current {@code MessagingAccessPoint} in this context
*
* @return a {@code MessagingAccessPoint} instance
*/
MessagingAccessPoint messagingAccessPoint();