當前位置: 首頁>>代碼示例>>Java>>正文


Java OMS類代碼示例

本文整理匯總了Java中io.openmessaging.OMS的典型用法代碼示例。如果您正苦於以下問題:Java OMS類的具體用法?Java OMS怎麽用?Java OMS使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


OMS類屬於io.openmessaging包,在下文中一共展示了OMS類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import io.openmessaging.OMS; //導入依賴的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();
}
 
開發者ID:lirenzuo,項目名稱:rocketmq-rocketmq-all-4.1.0-incubating,代碼行數:17,代碼來源:PushConsumerImplTest.java

示例2: init

import io.openmessaging.OMS; //導入依賴的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();
}
 
開發者ID:lirenzuo,項目名稱:rocketmq-rocketmq-all-4.1.0-incubating,代碼行數:19,代碼來源:PullConsumerImplTest.java

示例3: getMessagingAccessPoint

import io.openmessaging.OMS; //導入依賴的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);
    }
}
 
開發者ID:openmessaging,項目名稱:openmessaging-java,代碼行數:30,代碼來源:MessagingAccessPointAdapter.java

示例4: init

import io.openmessaging.OMS; //導入依賴的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();
}
 
開發者ID:apache,項目名稱:rocketmq,代碼行數:24,代碼來源:PullConsumerImplTest.java

示例5: main

import io.openmessaging.OMS; //導入依賴的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);
        }
    }
}
 
開發者ID:lirenzuo,項目名稱:rocketmq-rocketmq-all-4.1.0-incubating,代碼行數:31,代碼來源:SimplePullConsumer.java

示例6: main

import io.openmessaging.OMS; //導入依賴的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");
}
 
開發者ID:lirenzuo,項目名稱:rocketmq-rocketmq-all-4.1.0-incubating,代碼行數:30,代碼來源:SimplePushConsumer.java

示例7: buildKeyValue

import io.openmessaging.OMS; //導入依賴的package包/類
public static KeyValue buildKeyValue(KeyValue... keyValues) {
    KeyValue keyValue = OMS.newKeyValue();
    for (KeyValue properties : keyValues) {
        for (String key : properties.keySet()) {
            keyValue.put(key, properties.getString(key));
        }
    }
    return keyValue;
}
 
開發者ID:lirenzuo,項目名稱:rocketmq-rocketmq-all-4.1.0-incubating,代碼行數:10,代碼來源:OMSUtil.java

示例8: testPoll_WithTimeout

import io.openmessaging.OMS; //導入依賴的package包/類
@Test
public void testPoll_WithTimeout() {
    //There is a default timeout value, @see ClientConfig#omsOperationTimeout.
    Message message = consumer.poll();
    assertThat(message).isNull();

    message = consumer.poll(OMS.newKeyValue().put(PropertyKeys.OPERATION_TIMEOUT, 100));
    assertThat(message).isNull();
}
 
開發者ID:lirenzuo,項目名稱:rocketmq-rocketmq-all-4.1.0-incubating,代碼行數:10,代碼來源:PullConsumerImplTest.java

示例9: main

import io.openmessaging.OMS; //導入依賴的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();
        }
    }));
}
 
開發者ID:openmessaging,項目名稱:openmessaging-java,代碼行數:28,代碼來源:PullConsumerApp.java

示例10: BytesMessageImpl

import io.openmessaging.OMS; //導入依賴的package包/類
public BytesMessageImpl() {
    this.headers = OMS.newKeyValue();
    this.properties = OMS.newKeyValue();
}
 
開發者ID:lirenzuo,項目名稱:rocketmq-rocketmq-all-4.1.0-incubating,代碼行數:5,代碼來源:BytesMessageImpl.java

示例11: main

import io.openmessaging.OMS; //導入依賴的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();
        }
    }));
}
 
開發者ID:openmessaging,項目名稱:openmessaging-java,代碼行數:51,代碼來源:PushConsumerApp.java


注:本文中的io.openmessaging.OMS類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。