"rocketmq 发送异步消息时出错。但同步消息正常 是怎么回事?[阿里云消息队列MQ]

“rocketmq 发送异步消息时出错。但同步消息正常 是怎么回事?

public static void main(String[] args) throws RemotingException, InterruptedException {

// 创建一个默认的生产者实例
DefaultMQProducer producer = new DefaultMQProducer(""broker-a"",
        new AclClientRPCHook(new SessionCredentials(""xxxx"",""xxxx"")));

// 设置NameServer地址
producer.setNamesrvAddr(""xxxx:xxxx"");
producer.setSendMsgTimeout(30000);

// 获取已设置的NameServer地址
String configuredNamesrvAddr = producer.getNamesrvAddr();
System.out.println(""Configured NameServer address: "" + configuredNamesrvAddr);

try {
    // 启动生产者
    producer.start();

    // 创建消息实例,指定主题、标签和消息内容
    Message message = new Message(""test-topic"", ""test"", (""消息发布测试"" + System.currentTimeMillis())
            .getBytes(RemotingHelper.DEFAULT_CHARSET));

    producer.send(message, new SendCallback() {
        @Override
        public void onSuccess(SendResult sendResult) {
            System.out.println(sendResult.getSendStatus());
            if (!SendStatus.SEND_OK.equals(sendResult.getSendStatus())) {
                System.out.println(""消息发布失败"");
            }
        }

        @Override
        public void onException(Throwable e) {
            e.printStackTrace();
            System.out.println(""消息发布异常"");
        }
    });
} catch (MQClientException e) {
    e.printStackTrace();
} catch (UnsupportedEncodingException e) {
    throw new RuntimeException(e);
} finally {
    // 关闭生产者实例
    producer.shutdown();
}

}
public static void main(String[] args) throws RemotingException, InterruptedException {

// 创建一个默认的生产者实例
DefaultMQProducer producer = new DefaultMQProducer(""broker-a"",
        new AclClientRPCHook(new SessionCredentials(""xxxx"",""xxxx"")));

// 设置NameServer地址
producer.setNamesrvAddr(""xxxx:xxxx"");
producer.setSendMsgTimeout(30000);

// 获取已设置的NameServer地址
String configuredNamesrvAddr = producer.getNamesrvAddr();
System.out.println(""Configured NameServer address: "" + configuredNamesrvAddr);

try {
    // 启动生产者
    producer.start();

    // 创建消息实例,指定主题、标签和消息内容
    Message message = new Message(""test-topic"", ""test"", (""消息发布测试"" + System.currentTimeMillis())
            .getBytes(RemotingHelper.DEFAULT_CHARSET));

    producer.send(message);
} catch (MQClientException e) {
    e.printStackTrace();
} catch (UnsupportedEncodingException e) {
    throw new RuntimeException(e);
} catch (MQBrokerException e) {
    throw new RuntimeException(e);
} finally {
    // 关闭生产者实例
    producer.shutdown();
}

}”

「点点赞赏,手留余香」

    还没有人赞赏,快来当第一个赞赏的人吧!
=====这是一个广告位,招租中,联系qq 78315851====