• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SendResult类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.rocketmq.client.producer.SendResult的典型用法代码示例。如果您正苦于以下问题:Java SendResult类的具体用法?Java SendResult怎么用?Java SendResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SendResult类属于org.apache.rocketmq.client.producer包,在下文中一共展示了SendResult类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testSendMessageSync_Success

import org.apache.rocketmq.client.producer.SendResult; //导入依赖的package包/类
@Test
public void testSendMessageSync_Success() throws InterruptedException, RemotingException, MQBrokerException {
    doAnswer(new Answer() {
        @Override public Object answer(InvocationOnMock mock) throws Throwable {
            RemotingCommand request = mock.getArgument(1);
            return createSuccessResponse(request);
        }
    }).when(remotingClient).invokeSync(anyString(), any(RemotingCommand.class), anyLong());

    SendMessageRequestHeader requestHeader = createSendMessageRequestHeader();

    SendResult sendResult = mqClientAPI.sendMessage(brokerAddr, brokerName, msg, requestHeader,
        3 * 1000, CommunicationMode.SYNC, new SendMessageContext(), defaultMQProducerImpl);

    assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK);
    assertThat(sendResult.getOffsetMsgId()).isEqualTo("123");
    assertThat(sendResult.getQueueOffset()).isEqualTo(123L);
    assertThat(sendResult.getMessageQueue().getQueueId()).isEqualTo(1);
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:20,代码来源:MQClientAPIImplTest.java


示例2: sendMessage

import org.apache.rocketmq.client.producer.SendResult; //导入依赖的package包/类
/**
 * 发送消息【同步】
 * @param message
 * @return
 */
public String sendMessage(String message){
    DefaultMQProducer producer=new DefaultMQProducer(RocketMQConfiguration.ROCKETMQ_GROUP);
    producer.setNamesrvAddr(RocketMQConfiguration.ROCKETMQ_NAMESRV);
    producer.setVipChannelEnabled(false);
    try {
        producer.start();
        for (int i = 0; i < 100; i++) {
            SendResult sendResult = producer.send(new Message(RocketMQConfiguration.ROCKETMQ_TOPIC, message!=null?message.getBytes():null));
            System.out.println(sendResult);
        }
        return null;
    } catch (MQClientException|InterruptedException| RemotingException|MQBrokerException e) {
        e.printStackTrace();
        System.exit(1);
    }finally {
        producer.shutdown();
    }
    return null;
}
 
开发者ID:mumudemo,项目名称:mumu-rocketmq,代码行数:25,代码来源:RocketMQProcedure.java


示例3: sendFilterMessage

import org.apache.rocketmq.client.producer.SendResult; //导入依赖的package包/类
/**
 * 发送消息
 * @return
 */
public String sendFilterMessage(){
    DefaultMQProducer producer=new DefaultMQProducer(RocketMQConfiguration.ROCKETMQ_GROUP);
    producer.setNamesrvAddr(RocketMQConfiguration.ROCKETMQ_NAMESRV);
    producer.setVipChannelEnabled(false);
    try {
        producer.start();
        for (int i = 0; i <10 ; i++) {
            Message message1 = new Message(RocketMQConfiguration.ROCKETMQ_TOPIC,"filter",null, ("lovecws"+i).getBytes());
            message1.putUserProperty("a",String.valueOf(i));
            SendResult sendResult = producer.send(message1);
            System.out.println(sendResult);
        }
        return null;
    } catch (MQClientException |InterruptedException| RemotingException |MQBrokerException e) {
        e.printStackTrace();
        System.exit(1);
    }finally {
        producer.shutdown();
    }
    return null;
}
 
开发者ID:mumudemo,项目名称:mumu-rocketmq,代码行数:26,代码来源:RocketMQFilterProcedure.java


示例4: sendAsyncMessage

import org.apache.rocketmq.client.producer.SendResult; //导入依赖的package包/类
/**
 * 发送异步消息
 * @throws InterruptedException
 * @throws RemotingException
 * @throws MQClientException
 * @throws MQBrokerException
 */
@Benchmark
@BenchmarkMode(Mode.Throughput)
public void sendAsyncMessage() throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
    producer.send(new Message(RocketMQConfiguration.ROCKETMQ_TOPIC,message), new SendCallback() {
        @Override
        public void onSuccess(SendResult sendResult) {
            //System.out.println("receive message"+sendResult);
        }

        @Override
        public void onException(Throwable throwable) {
            //System.out.println("receive message error"+throwable.getLocalizedMessage());
        }
    });
}
 
开发者ID:mumudemo,项目名称:mumu-rocketmq,代码行数:23,代码来源:RocketMQAsyncMessage.java


示例5: syncSend

import org.apache.rocketmq.client.producer.SendResult; //导入依赖的package包/类
/**
 * Same to {@link #syncSend(String, Message)} with send timeout specified in addition.
 *
 * @param destination formats: `topicName:tags`
 * @param message     {@link org.springframework.messaging.Message}
 * @param timeout     send timeout with millis
 * @return {@link SendResult}
 */
public SendResult syncSend(String destination, Message<?> message, long timeout) {
    if (Objects.isNull(message) || Objects.isNull(message.getPayload())) {
        log.info("syncSend failed. destination:{}, message is null ", destination);
        throw new IllegalArgumentException("`message` and `message.payload` cannot be null");
    }

    try {
        long now = System.currentTimeMillis();
        org.apache.rocketmq.common.message.Message rocketMsg = convertToRocketMsg(destination, message);
        SendResult sendResult = producer.send(rocketMsg, timeout);
        long costTime = System.currentTimeMillis() - now;
        log.debug("send message cost: {} ms, msgId:{}", costTime, sendResult.getMsgId());
        return sendResult;
    } catch (Exception e) {
        log.info("syncSend failed. destination:{}, message:{} ", destination, message);
        throw new MessagingException(e.getMessage(), e);
    }
}
 
开发者ID:QianmiOpen,项目名称:spring-boot-starter-rocketmq,代码行数:27,代码来源:RocketMQTemplate.java


示例6: syncSendOrderly

import org.apache.rocketmq.client.producer.SendResult; //导入依赖的package包/类
/**
 * Same to {@link #syncSendOrderly(String, Message, String)} with send timeout specified in addition.
 *
 * @param destination formats: `topicName:tags`
 * @param message     {@link org.springframework.messaging.Message}
 * @param hashKey     use this key to select queue. for example: orderId, productId ...
 * @param timeout     send timeout with millis
 * @return {@link SendResult}
 */
public SendResult syncSendOrderly(String destination, Message<?> message, String hashKey, long timeout) {
    if (Objects.isNull(message) || Objects.isNull(message.getPayload())) {
        log.info("syncSendOrderly failed. destination:{}, message is null ", destination);
        throw new IllegalArgumentException("`message` and `message.payload` cannot be null");
    }

    try {
        long now = System.currentTimeMillis();
        org.apache.rocketmq.common.message.Message rocketMsg = convertToRocketMsg(destination, message);
        SendResult sendResult = producer.send(rocketMsg, messageQueueSelector, hashKey, timeout);
        long costTime = System.currentTimeMillis() - now;
        log.debug("send message cost: {} ms, msgId:{}", costTime, sendResult.getMsgId());
        return sendResult;
    } catch (Exception e) {
        log.info("syncSendOrderly failed. destination:{}, message:{} ", destination, message);
        throw new MessagingException(e.getMessage(), e);
    }
}
 
开发者ID:QianmiOpen,项目名称:spring-boot-starter-rocketmq,代码行数:28,代码来源:RocketMQTemplate.java


示例7: main

import org.apache.rocketmq.client.producer.SendResult; //导入依赖的package包/类
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",
                    "TagA",
                    "key113",
                    "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET));
                SendResult sendResult = producer.send(msg);
                System.out.printf("%s%n", sendResult);

                QueryResult queryMessage =
                    producer.queryMessage("TopicTest1", "key113", 10, 0, System.currentTimeMillis());
                for (MessageExt m : queryMessage.getMessageList()) {
                    System.out.printf("%s%n", m);
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    producer.shutdown();
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:27,代码来源:TestProducer.java


示例8: main

import org.apache.rocketmq.client.producer.SendResult; //导入依赖的package包/类
public static void main(String[] args) throws MQClientException, InterruptedException {

        DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName");

        producer.start();

        for (int i = 0; i < 10000000; i++)
            try {
                {
                    Message msg = new Message("TopicTest",
                        "TagA",
                        "OrderID188",
                        "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET));
                    SendResult sendResult = producer.send(msg);
                    System.out.printf("%s%n", sendResult);
                }

            } catch (Exception e) {
                e.printStackTrace();
            }

        producer.shutdown();
    }
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:24,代码来源:Producer.java


示例9: main

import org.apache.rocketmq.client.producer.SendResult; //导入依赖的package包/类
public static void main(String[] args) throws MQClientException, InterruptedException {
    DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName");
    producer.start();

    try {
        for (int i = 0; i < 6000000; i++) {
            Message msg = new Message("TopicFilter7",
                "TagA",
                "OrderID001",
                "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET));

            msg.putUserProperty("SequenceId", String.valueOf(i));
            SendResult sendResult = producer.send(msg);
            System.out.printf("%s%n", sendResult);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    producer.shutdown();
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:21,代码来源:Producer.java


示例10: sendMsg

import org.apache.rocketmq.client.producer.SendResult; //导入依赖的package包/类
private void sendMsg(final DefaultMQAdminExt defaultMQAdminExt, final DefaultMQProducer defaultMQProducer,
    final String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    try {
        MessageExt msg = defaultMQAdminExt.viewMessage(msgId);
        if (msg != null) {
            // resend msg by id
            System.out.printf("prepare resend msg. originalMsgId=" + msgId);
            SendResult result = defaultMQProducer.send(msg);
            System.out.printf("%s", result);
        } else {
            System.out.printf("no message. msgId=" + msgId);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:17,代码来源:QueryMsgByIdSubCommand.java


示例11: execute

import org.apache.rocketmq.client.producer.SendResult; //导入依赖的package包/类
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    final DefaultMQProducer producer = new DefaultMQProducer("PID_SMSC", rpcHook);
    producer.setInstanceName("PID_SMSC_" + System.currentTimeMillis());

    try {
        producer.start();
        String brokerName = commandLine.getOptionValue('b').trim();
        int messageSize = commandLine.hasOption('s') ? Integer.parseInt(commandLine.getOptionValue('s')) : 128;
        int count = commandLine.hasOption('c') ? Integer.parseInt(commandLine.getOptionValue('c')) : 50;

        producer.send(buildMessage(brokerName, 16));

        for (int i = 0; i < count; i++) {
            long begin = System.currentTimeMillis();
            SendResult result = producer.send(buildMessage(brokerName, messageSize));
            System.out.printf("rt:" + (System.currentTimeMillis() - begin) + "ms, SendResult=" + result);
        }
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        producer.shutdown();
    }
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:25,代码来源:SendMsgStatusCommand.java


示例12: testBatchSend_ViewMessage

import org.apache.rocketmq.client.producer.SendResult; //导入依赖的package包/类
@Test
public void testBatchSend_ViewMessage() throws Exception {
    List<Message> messageList = new ArrayList<>();
    int batchNum = 100;
    for (int i = 0; i < batchNum; i++) {
        messageList.add(new Message(topic, RandomUtils.getStringByUUID().getBytes()));
    }

    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    SendResult sendResult = producer.send(messageList);
    Assert.assertEquals(SendStatus.SEND_OK, sendResult.getSendStatus());

    String[] offsetIds = sendResult.getOffsetMsgId().split(",");
    String[] msgIds = sendResult.getMsgId().split(",");
    Assert.assertEquals(messageList.size(), offsetIds.length);
    Assert.assertEquals(messageList.size(), msgIds.length);

    Thread.sleep(2000);

    for (int i = 0; i < 3; i++) {
        producer.viewMessage(offsetIds[random.nextInt(batchNum)]);
    }
    for (int i = 0; i < 3; i++) {
        producer.viewMessage(topic, msgIds[random.nextInt(batchNum)]);
    }
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:27,代码来源:BatchSendIT.java


示例13: sendAsync

import org.apache.rocketmq.client.producer.SendResult; //导入依赖的package包/类
private static void sendAsync() throws MqWapperException, MqBussinessException
{
	producer.sendMsg("topic20170118", "id3", "UU", new SendCallback() {
		@Override
		public void onSuccess(SendResult sendResult)
		{
			System.out.println("success");
		}

		@Override
		public void onException(Throwable e)
		{
			System.out.println("failed");
		}
	});
}
 
开发者ID:netease-lede,项目名称:rocketmq-easyclient,代码行数:17,代码来源:TestProducer.java


示例14: sendAsyncUseConfig

import org.apache.rocketmq.client.producer.SendResult; //导入依赖的package包/类
private static void sendAsyncUseConfig() throws MqWapperException, MqBussinessException
{
	EasyMQMessageConfig config = new EasyMQMessageConfig("topic20170118", "id2", "onlyU");
	config.setTransferMode(ProducerTransferMode.ASYNC);
	config.setCallback(new SendCallback() {
		@Override
		public void onSuccess(SendResult sendResult)
		{
			System.out.println("success");
		}

		@Override
		public void onException(Throwable e)
		{
			System.out.println("failed");
		}
	});
	producer.sendMsg(config);
}
 
开发者ID:netease-lede,项目名称:rocketmq-easyclient,代码行数:20,代码来源:TestProducer.java


示例15: syncSendWithDelay

import org.apache.rocketmq.client.producer.SendResult; //导入依赖的package包/类
/**
 * 同步发送消息
 * @param topic  topic
 * @param tag tag
 * @param msgObj  消息体
 * @param delayTimeLevel  默认延迟等级 : 1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h, 传入1代表1s, 2代表5s, 以此类推
 * @throws MQException 消息异常
 */
public void syncSendWithDelay(String topic, String tag, Object msgObj, int delayTimeLevel) throws MQException {
    if(null == msgObj) {
        return;
    }
    Message delayedMsg = genMessage(topic, tag, msgObj);
    try {
        if(delayTimeLevel > 0 && delayTimeLevel <= DELAY_ARRAY.length) {
            delayedMsg.setDelayTimeLevel(delayTimeLevel);
        }
        SendResult sendResult = producer.send(delayedMsg);
        log.info("sync send rocketmq message with delay, messageId : {}, default delay interval: {}", sendResult.getMsgId(), DELAY_ARRAY[delayTimeLevel-1]);
        this.doAfterSyncSend(delayedMsg, sendResult);
    } catch (Exception e) {
        log.error("消息发送失败,topic : {}, msgObj {}", delayedMsg.getTopic(), msgObj);
        throw new MQException("消息发送失败,topic :" + topic + ",e:" + e.getMessage());
    }
}
 
开发者ID:maihaoche,项目名称:rocketmq-spring-boot-starter,代码行数:26,代码来源:AbstractMQProducer.java


示例16: syncSendOrderly

import org.apache.rocketmq.client.producer.SendResult; //导入依赖的package包/类
/**
 * 同步发送消息
 * @param topic  topic
 * @param tag tag
 * @param msgObj  消息体
 * @param hashKey  用于hash后选择queue的key
 * @throws MQException 消息异常
 */
public void syncSendOrderly(String topic, String tag, Object msgObj, String hashKey) throws MQException {
    if(null == msgObj) {
        return;
    }
    Message msg = genMessage(topic, tag, msgObj);
    if(StringUtils.isEmpty(hashKey)) {
        // fall back to normal
        syncSend(topic, tag, msgObj);
    }
    try {
        SendResult sendResult = producer.send(msg, messageQueueSelector, hashKey);
        log.info("send rocketmq message orderly ,messageId : {}", sendResult.getMsgId());
        this.doAfterSyncSend(msg, sendResult);
    } catch (Exception e) {
        log.error("顺序消息发送失败,topic : {}, msgObj {}", msg.getTopic(), msgObj);
        throw new MQException("顺序消息发送失败,topic :" + topic + ",e:" + e.getMessage());
    }
}
 
开发者ID:maihaoche,项目名称:rocketmq-spring-boot-starter,代码行数:27,代码来源:AbstractMQProducer.java


示例17: execute

import org.apache.rocketmq.client.producer.SendResult; //导入依赖的package包/类
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    final DefaultMQProducer producer = new DefaultMQProducer("PID_SMSC", rpcHook);
    producer.setInstanceName("PID_SMSC_" + System.currentTimeMillis());

    try {
        producer.start();
        String brokerName = commandLine.getOptionValue('b').trim();
        int messageSize = commandLine.hasOption('s') ? Integer.parseInt(commandLine.getOptionValue('s')) : 128;
        int count = commandLine.hasOption('c') ? Integer.parseInt(commandLine.getOptionValue('c')) : 50;

        producer.send(buildMessage(brokerName, 16));

        for (int i = 0; i < count; i++) {
            long begin = System.currentTimeMillis();
            SendResult result = producer.send(buildMessage(brokerName, messageSize));
            System.out.printf("rt:" + (System.currentTimeMillis() - begin) + "ms, SendResult=" + result);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        producer.shutdown();
    }
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:25,代码来源:SendMsgStatusCommand.java


示例18: main

import org.apache.rocketmq.client.producer.SendResult; //导入依赖的package包/类
public static void main(String[] args) throws MQClientException, InterruptedException {

        DefaultMQProducer producer = new DefaultMQProducer("simple_producer_group");
        producer.setNamesrvAddr("127.0.0.1:9876");
        producer.start();

        for (int i = 0; i < 100; i++)
            try {
                {
                    Message msg = new Message("TopicTest",
                        "TagA",
                        "OrderID188",
                        "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET));
                    SendResult sendResult = producer.send(msg);
                    System.out.printf("%s%n", sendResult);
                }

            } catch (Exception e) {
                e.printStackTrace();
            }

        producer.shutdown();
    }
 
开发者ID:javahongxi,项目名称:whatsmars,代码行数:24,代码来源:Producer.java


示例19: testSendMessageSync_Success

import org.apache.rocketmq.client.producer.SendResult; //导入依赖的package包/类
@Test
public void testSendMessageSync_Success() throws InterruptedException, RemotingException, MQBrokerException {
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock mock) throws Throwable {
            RemotingCommand request = mock.getArgument(1);
            return createSuccessResponse(request);
        }
    }).when(remotingClient).invokeSync(anyString(), any(RemotingCommand.class), anyLong());

    SendMessageRequestHeader requestHeader = createSendMessageRequestHeader();

    SendResult sendResult = mqClientAPI.sendMessage(brokerAddr, brokerName, msg, requestHeader,
        3 * 1000, CommunicationMode.SYNC, new SendMessageContext(), defaultMQProducerImpl);

    assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK);
    assertThat(sendResult.getOffsetMsgId()).isEqualTo("123");
    assertThat(sendResult.getQueueOffset()).isEqualTo(123L);
    assertThat(sendResult.getMessageQueue().getQueueId()).isEqualTo(1);
}
 
开发者ID:apache,项目名称:rocketmq,代码行数:21,代码来源:MQClientAPIImplTest.java


示例20: sendMsg

import org.apache.rocketmq.client.producer.SendResult; //导入依赖的package包/类
private void sendMsg(final DefaultMQAdminExt defaultMQAdminExt, final DefaultMQProducer defaultMQProducer,
    final String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    try {
        MessageExt msg = defaultMQAdminExt.viewMessage(msgId);
        if (msg != null) {
            // resend msg by id
            System.out.printf("prepare resend msg. originalMsgId=%s", msgId);
            SendResult result = defaultMQProducer.send(msg);
            System.out.printf("%s", result);
        } else {
            System.out.printf("no message. msgId=%s", msgId);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:apache,项目名称:rocketmq,代码行数:17,代码来源:QueryMsgByIdSubCommand.java



注:本文中的org.apache.rocketmq.client.producer.SendResult类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java I2CDevice类代码示例发布时间:2022-05-21
下一篇:
Java SearchPhaseExecutionException类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap