Search in sources :

Example 56 with SendResult

use of org.apache.rocketmq.client.producer.SendResult in project spring-boot-starter-samples by vindell.

the class Producer method send.

// 每3s执行1次
@Scheduled(fixedDelay = 3000)
public void send() throws Exception {
    /*// send queue.
		
		MessageQueue mq = new MessageQueue("TEST", "brokerName", 1);
		Message msg = new Message("TEST", // topic
				"TEST", // tag
				"KKK", // key用于标识业务的唯一性
				"hi,RocketMQ".getBytes()// body 二进制字节数组
		);

		SendResult result = rocketmqTemplate.send(msg, mq);
		System.out.println(result);*/
    // send topic.
    Message msg2 = new // topic
    Message(// topic
    "Topic-DC-Output", // tag
    "TagA-Output", // key用于标识业务的唯一性; key 消息关键词,多个Key用KEY_SEPARATOR隔开(查询消息使用)
    "KKK", // body 二进制字节数组
    (new Date() + ": hi,RocketMQ(topic) ").getBytes());
    SendResult result2 = rocketmqTemplate.send(msg2);
// System.out.println(result2);
}
Also used : Message(org.apache.rocketmq.common.message.Message) SendResult(org.apache.rocketmq.client.producer.SendResult) Date(java.util.Date) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 57 with SendResult

use of org.apache.rocketmq.client.producer.SendResult in project spring-boot-starter-samples by vindell.

the class BroadcastProducer method main.

public static void main(String[] args) throws Exception {
    DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName");
    producer.start();
    for (int i = 0; i < 100; i++) {
        Message msg = new Message("TopicTest", "TagA", "OrderID188", "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET));
        SendResult sendResult = producer.send(msg);
        System.out.printf("%s%n", sendResult);
    }
    producer.shutdown();
}
Also used : Message(org.apache.rocketmq.common.message.Message) SendResult(org.apache.rocketmq.client.producer.SendResult) DefaultMQProducer(org.apache.rocketmq.client.producer.DefaultMQProducer)

Example 58 with SendResult

use of org.apache.rocketmq.client.producer.SendResult in project spring-boot-starter-samples by vindell.

the class RocketmqApplicationTests method contextLoads.

@Test
public void contextLoads() throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
    // Destination destination = new ActiveMQQueue("mytest.queue");
    Message msg = new // topic
    Message(// topic
    "TEST", // tag
    "TEST", // key用于标识业务的唯一性
    "KKK", // body 二进制字节数组
    "hi,RocketMQ".getBytes());
    for (int i = 0; i < 100; i++) {
        SendResult result = rocketmqTemplate.send(msg);
        System.out.println(result);
    }
}
Also used : Message(org.apache.rocketmq.common.message.Message) SendResult(org.apache.rocketmq.client.producer.SendResult) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 59 with SendResult

use of org.apache.rocketmq.client.producer.SendResult in project spring-boot-starter-samples by vindell.

the class OrderedProducer method main.

public static void main(String[] args) throws Exception {
    // Instantiate with a producer group name.
    MQProducer producer = new DefaultMQProducer("example_group_name");
    // Launch the instance.
    producer.start();
    String[] tags = new String[] { "TagA", "TagB", "TagC", "TagD", "TagE" };
    for (int i = 0; i < 100; i++) {
        int orderId = i % 10;
        // Create a message instance, specifying topic, tag and message body.
        Message msg = new Message("TopicTestjjj", tags[i % tags.length], "KEY" + i, ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET));
        SendResult sendResult = producer.send(msg, new MessageQueueSelector() {

            @Override
            public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
                Integer id = (Integer) arg;
                int index = id % mqs.size();
                return mqs.get(index);
            }
        }, orderId);
        System.out.printf("%s%n", sendResult);
    }
    // server shutdown
    producer.shutdown();
}
Also used : Message(org.apache.rocketmq.common.message.Message) DefaultMQProducer(org.apache.rocketmq.client.producer.DefaultMQProducer) MQProducer(org.apache.rocketmq.client.producer.MQProducer) DefaultMQProducer(org.apache.rocketmq.client.producer.DefaultMQProducer) MessageQueueSelector(org.apache.rocketmq.client.producer.MessageQueueSelector) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) SendResult(org.apache.rocketmq.client.producer.SendResult)

Example 60 with SendResult

use of org.apache.rocketmq.client.producer.SendResult in project spring-boot-starter-samples by vindell.

the class LogProducer method send.

public void send(String text) throws Exception {
    Message msg = new // topic
    Message(// topic
    "Topic-DC-Output", // tag
    "TagB-Output", // key用于标识业务的唯一性; key 消息关键词,多个Key用KEY_SEPARATOR隔开(查询消息使用)
    "KKK", // body 二进制字节数组
    text.getBytes());
    SendResult result = rocketmqTemplate.send(msg);
    System.out.println(result);
}
Also used : Message(org.apache.rocketmq.common.message.Message) SendResult(org.apache.rocketmq.client.producer.SendResult)

Aggregations

SendResult (org.apache.rocketmq.client.producer.SendResult)95 Message (org.apache.rocketmq.common.message.Message)64 DefaultMQProducer (org.apache.rocketmq.client.producer.DefaultMQProducer)42 MQClientException (org.apache.rocketmq.client.exception.MQClientException)39 Test (org.junit.Test)32 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)15 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)15 SendCallback (org.apache.rocketmq.client.producer.SendCallback)13 UnsupportedEncodingException (java.io.UnsupportedEncodingException)11 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)10 ArrayList (java.util.ArrayList)8 SendMessageContext (org.apache.rocketmq.client.hook.SendMessageContext)8 SendMessageRequestHeader (org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader)8 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)8 IOException (java.io.IOException)6 TransactionSendResult (org.apache.rocketmq.client.producer.TransactionSendResult)6 RemotingConnectException (org.apache.rocketmq.remoting.exception.RemotingConnectException)6 RemotingTimeoutException (org.apache.rocketmq.remoting.exception.RemotingTimeoutException)6 MessageExt (org.apache.rocketmq.common.message.MessageExt)5 BytesMessage (io.openmessaging.BytesMessage)4