io.openmessaging.consumer.PushConsumer Java Examples

The following examples show how to use io.openmessaging.consumer.PushConsumer. 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: PushConsumerImpl.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Override
public PushConsumer attachQueue(final String queueName, final MessageListener listener) {
    this.subscribeTable.put(queueName, listener);
    try {
        this.rocketmqPushConsumer.subscribe(queueName, "*");
    } catch (MQClientException e) {
        throw new OMSRuntimeException("-1", String.format("RocketMQ push consumer can't attach to %s.", queueName));
    }
    return this;
}
 
Example #2
Source File: SimplePushConsumer.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    final MessagingAccessPoint messagingAccessPoint = OMS
        .getMessagingAccessPoint("oms:rocketmq://localhost:9876/default:default");

    final PushConsumer consumer = messagingAccessPoint.
        createPushConsumer(OMS.newKeyValue().put(OMSBuiltinKeys.CONSUMER_ID, "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 onReceived(Message message, Context context) {
            System.out.printf("Received one message: %s%n", message.sysHeaders().getString(Message.BuiltinKeys.MESSAGE_ID));
            context.ack();
        }
    });

    consumer.startup();
    System.out.printf("Consumer startup OK%n");
}
 
Example #3
Source File: PushConsumerImpl.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Override
public PushConsumer detachQueue(String queueName) {
    this.subscribeTable.remove(queueName);
    try {
        this.rocketmqPushConsumer.unsubscribe(queueName);
    } catch (Exception e) {
        throw new OMSRuntimeException("-1", String.format("RocketMQ push consumer fails to unsubscribe topic: %s", queueName));
    }
    return null;
}
 
Example #4
Source File: PushConsumerImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Override
public PushConsumer detachQueue(String queueName) {
    this.subscribeTable.remove(queueName);
    try {
        this.rocketmqPushConsumer.unsubscribe(queueName);
    } catch (Exception e) {
        throw new OMSRuntimeException("-1", String.format("RocketMQ push consumer fails to unsubscribe topic: %s", queueName));
    }
    return null;
}
 
Example #5
Source File: SimplePushConsumer.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    final MessagingAccessPoint messagingAccessPoint = OMS
        .getMessagingAccessPoint("oms:rocketmq://localhost:9876/default:default");

    final PushConsumer consumer = messagingAccessPoint.
        createPushConsumer(OMS.newKeyValue().put(OMSBuiltinKeys.CONSUMER_ID, "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 onReceived(Message message, Context context) {
            System.out.printf("Received one message: %s%n", message.sysHeaders().getString(Message.BuiltinKeys.MESSAGE_ID));
            context.ack();
        }
    });

    consumer.startup();
    System.out.printf("Consumer startup OK%n");
}
 
Example #6
Source File: PushConsumerImpl.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Override
public PushConsumer attachQueue(final String queueName, final MessageListener listener) {
    this.subscribeTable.put(queueName, listener);
    try {
        this.rocketmqPushConsumer.subscribe(queueName, "*");
    } catch (MQClientException e) {
        throw new OMSRuntimeException("-1", String.format("RocketMQ push consumer can't attach to %s.", queueName));
    }
    return this;
}
 
Example #7
Source File: PushConsumerImpl.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Override
public PushConsumer detachQueue(String queueName) {
    this.subscribeTable.remove(queueName);
    try {
        this.rocketmqPushConsumer.unsubscribe(queueName);
    } catch (Exception e) {
        throw new OMSRuntimeException("-1", String.format("RocketMQ push consumer fails to unsubscribe topic: %s", queueName));
    }
    return null;
}
 
Example #8
Source File: PushConsumerImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Override
public PushConsumer attachQueue(final String queueName, final MessageListener listener) {
    this.subscribeTable.put(queueName, listener);
    try {
        this.rocketmqPushConsumer.subscribe(queueName, "*");
    } catch (MQClientException e) {
        throw new OMSRuntimeException("-1", String.format("RocketMQ push consumer can't attach to %s.", queueName));
    }
    return this;
}
 
Example #9
Source File: SimplePushConsumer.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    final MessagingAccessPoint messagingAccessPoint = OMS
        .getMessagingAccessPoint("oms:rocketmq://localhost:9876/default:default");

    final PushConsumer consumer = messagingAccessPoint.
        createPushConsumer(OMS.newKeyValue().put(OMSBuiltinKeys.CONSUMER_ID, "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 onReceived(Message message, Context context) {
            System.out.printf("Received one message: %s%n", message.sysHeaders().getString(Message.BuiltinKeys.MESSAGE_ID));
            context.ack();
        }
    });

    consumer.startup();
    System.out.printf("Consumer startup OK%n");
}
 
Example #10
Source File: PushConsumerApp.java    From openmessaging-java with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    //Load and start the vendor implementation from a specific OMS driver URL.
    final MessagingAccessPoint messagingAccessPoint =
        OMS.getMessagingAccessPoint("oms:rocketmq://localhost:10911/us-east");

    //Fetch a ResourceManager to create Queue resource.
    ResourceManager resourceManager = messagingAccessPoint.resourceManager();
    resourceManager.createNamespace("NS://XXXX");
    final PushConsumer consumer = messagingAccessPoint.createPushConsumer();
    consumer.start();

    //Register a shutdown hook to close the opened endpoints.
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
            consumer.stop();
        }
    }));

    //Consume messages from a simple queue.
    String simpleQueue = "NS://HELLO_QUEUE";
    resourceManager.createQueue(simpleQueue);
    //This queue doesn't has a source queue, so only the message delivered to the queue directly can
    //be consumed by this consumer.
    consumer.bindQueue(Arrays.asList(simpleQueue), new MessageListener() {
        @Override
        public void onReceived(Message message, Context context) {
            System.out.println("Received one message: " + message);
            context.ack();
        }

    });

    consumer.unbindQueue(Arrays.asList(simpleQueue));

    consumer.stop();
}
 
Example #11
Source File: MessagingAccessPointImpl.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Override
public PushConsumer createPushConsumer(KeyValue properties) {
    return new PushConsumerImpl(OMSUtil.buildKeyValue(this.accessPointProperties, properties));
}
 
Example #12
Source File: MessagingAccessPointImpl.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Override
public PushConsumer createPushConsumer() {
    return new PushConsumerImpl(accessPointProperties);
}
 
Example #13
Source File: PushConsumerImpl.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Override
public PushConsumer attachQueue(String queueName, MessageListener listener, KeyValue attributes) {
    return this.attachQueue(queueName, listener);
}
 
Example #14
Source File: MessagingAccessPointAdapterTest.java    From openmessaging-java with Apache License 2.0 4 votes vote down vote up
@Override
public PushConsumer createPushConsumer(KeyValue attributes) {
    return null;
}
 
Example #15
Source File: MessagingAccessPointAdapterTest.java    From openmessaging-java with Apache License 2.0 4 votes vote down vote up
@Override
public PushConsumer createPushConsumer() {
    return null;
}
 
Example #16
Source File: MessagingAccessPointImpl.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
@Override
public PushConsumer createPushConsumer(KeyValue properties) {
    return new PushConsumerImpl(OMSUtil.buildKeyValue(this.accessPointProperties, properties));
}
 
Example #17
Source File: MessagingAccessPointImpl.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
@Override
public PushConsumer createPushConsumer() {
    return new PushConsumerImpl(accessPointProperties);
}
 
Example #18
Source File: PushConsumerImpl.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
@Override
public PushConsumer attachQueue(String queueName, MessageListener listener, KeyValue attributes) {
    return this.attachQueue(queueName, listener);
}
 
Example #19
Source File: MessagingAccessPointImpl.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
@Override
public PushConsumer createPushConsumer(KeyValue properties) {
    return new PushConsumerImpl(OMSUtil.buildKeyValue(this.accessPointProperties, properties));
}
 
Example #20
Source File: MessagingAccessPointImpl.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
@Override
public PushConsumer createPushConsumer() {
    return new PushConsumerImpl(accessPointProperties);
}
 
Example #21
Source File: PushConsumerImpl.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
@Override
public PushConsumer attachQueue(String queueName, MessageListener listener, KeyValue attributes) {
    return this.attachQueue(queueName, listener);
}
 
Example #22
Source File: MessagingAccessPoint.java    From openmessaging-java with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new {@code PushConsumer} for the specified {@code MessagingAccessPoint} with some preset attributes.
 *
 * @param attributes the preset attributes
 * @return the created {@code PushConsumer}
 * @throws OMSRuntimeException if the {@code MessagingAccessPoint} fails to handle this request
 * due to some internal error
 */
PushConsumer createPushConsumer(KeyValue attributes);
 
Example #23
Source File: MessagingAccessPoint.java    From openmessaging-java with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new {@code PushConsumer} for the specified {@code MessagingAccessPoint}.
 * The returned {@code PushConsumer} isn't attached to any queue,
 * uses {@link PushConsumer#bindQueue(Collection, MessageListener)} to attach queues.
 *
 * @return the created {@code PushConsumer}
 * @throws OMSRuntimeException if the {@code MessagingAccessPoint} fails to handle this request
 * due to some internal error
 */
PushConsumer createPushConsumer();