Java Code Examples for com.alibaba.rocketmq.client.producer.DefaultMQProducer#queryMessage()
The following examples show how to use
com.alibaba.rocketmq.client.producer.DefaultMQProducer#queryMessage() .
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: TestProducer.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
public static void main(String[] args) throws MQClientException, InterruptedException { DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName"); producer.start(); for (int i = 0; i < 1; i++) try { { Message msg = new Message("TopicTest1",// topic "TagA",// tag "key113",// key ("Hello MetaQ").getBytes());// body SendResult sendResult = producer.send(msg); System.out.println(sendResult); QueryResult queryMessage = producer.queryMessage("TopicTest1", "key113", 10, 0, System.currentTimeMillis()); for (MessageExt m : queryMessage.getMessageList()) { System.out.println(m); } } } catch (Exception e) { e.printStackTrace(); } producer.shutdown(); }
Example 2
Source File: TestProducer.java From rocketmq with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws MQClientException, InterruptedException { DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName"); producer.start(); for (int i = 0; i < 1; i++) try { { Message msg = new Message("TopicTest1",// topic "TagA",// tag "key113",// key ("Hello MetaQ").getBytes(RemotingHelper.DEFAULT_CHARSET));// body SendResult sendResult = producer.send(msg); System.out.println(sendResult); QueryResult queryMessage = producer.queryMessage("TopicTest1", "key113", 10, 0, System.currentTimeMillis()); for (MessageExt m : queryMessage.getMessageList()) { System.out.println(m); } } } catch (Exception e) { e.printStackTrace(); } producer.shutdown(); }
Example 3
Source File: TestProducer.java From RocketMQ-Master-analyze with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws MQClientException, InterruptedException { /** * 一个应用创建一个Producer,由应用来维护此对象,可以设置为全局对象或者单例<br> * 注意:ProducerGroupName需要由应用来保证唯一<br> * ProducerGroup这个概念发送普通的消息时,作用不大,但是发送分布式事务消息时,比较关键, * 因为服务器会回查这个Group下的任意一个Producer */ DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName"); /** * Producer对象在使用之前必须要调用start初始化,初始化一次即可<br> * 注意:切记不可以在每次发送消息时,都调用start方法 */ producer.start(); /** * 下面这段代码表明一个Producer对象可以发送多个topic,多个tag的消息。 * 注意:send方法是同步调用,只要不抛异常就标识成功。但是发送成功也可会有多种状态,<br> * 例如消息写入Master成功,但是Slave不成功,这种情况消息属于成功,但是对于个别应用如果对消息可靠性要求极高,<br> * 需要对这种情况做处理。另外,消息可能会存在发送失败的情况,失败重试由应用来处理。 */ for (int i = 0; i < 1; i++) try { { Message msg = new Message("TopicTest1", // topic "TagA", // tag "key113", // key ("Hello MetaQ").getBytes());// body SendResult sendResult = producer.send(msg); System.out.println(sendResult); QueryResult queryMessage = producer.queryMessage("TopicTest1", "key113", 10, 0, System.currentTimeMillis()); for (MessageExt m : queryMessage.getMessageList()) { System.out.println(m); } } } catch (Exception e) { e.printStackTrace(); } /** * 应用退出时,要调用shutdown来清理资源,关闭网络连接,从MetaQ服务器上注销自己 * 注意:我们建议应用在JBOSS、Tomcat等容器的退出钩子里调用shutdown方法 */ producer.shutdown(); }