开发者社区 > 云原生 > 云消息队列 > 正文

RocketMQ 5.1.4 已部署但是无法发送消息

@Slf4j
public class SyncProducer {

    public static void sendMessage(String topic, String message) {
        try {
            ClientServiceProvider provider = ClientServiceProvider.loadService();
            ClientConfiguration configuration = ClientConfiguration.newBuilder()
                    .setEndpoints("ip:9181")
                    .build();
            Producer producer = provider.newProducerBuilder()
                    .setClientConfiguration(configuration)
                    .setTopics(topic)
                    .build();
            String tag = "messageTag";
            Message msg = provider.newMessageBuilder()
                    .setTopic(topic)
                    .setTag(tag)
                    .setBody(message.getBytes(StandardCharsets.UTF_8))
                    .build();
            SendReceipt send = producer.send(msg);
            log.info("Send message successfully, messageId={}", send.getMessageId());
            producer.close();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            throw new RuntimeException(e.getMessage());
        }
    }

    public static void main(String[] args) {
        SyncProducer.sendMessage("TestTopic", "TestMessage");
    }

}

报错:

11:26:52.842 [main] ERROR com.xmzn.common.mq.producer.SyncProducer -- Expected the service ProducerImpl-0 [FAILED] to be RUNNING, but the service has FAILED
java.lang.IllegalStateException: Expected the service ProducerImpl-0 [FAILED] to be RUNNING, but the service has FAILED
    at org.apache.rocketmq.shaded.com.google.common.util.concurrent.AbstractService.checkCurrentState(AbstractService.java:381)
    at org.apache.rocketmq.shaded.com.google.common.util.concurrent.AbstractService.awaitRunning(AbstractService.java:305)
    at org.apache.rocketmq.shaded.com.google.common.util.concurrent.AbstractIdleService.awaitRunning(AbstractIdleService.java:165)
    at org.apache.rocketmq.client.java.impl.producer.ProducerBuilderImpl.build(ProducerBuilderImpl.java:93)
    at com.xmzn.common.mq.producer.SyncProducer.sendMessage(SyncProducer.java:29)
    at com.xmzn.common.mq.producer.SyncProducer.main(SyncProducer.java:46)
Caused by: java.util.concurrent.CancellationException: Task was cancelled.
    at org.apache.rocketmq.shaded.com.google.common.util.concurrent.AbstractFuture.cancellationExceptionWithCause(AbstractFuture.java:1543)
    at org.apache.rocketmq.shaded.com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:586)
    at org.apache.rocketmq.shaded.com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:567)
    at org.apache.rocketmq.shaded.com.google.common.util.concurrent.FluentFuture$TrustedFuture.get(FluentFuture.java:91)
    at org.apache.rocketmq.client.java.impl.ClientImpl.startUp(ClientImpl.java:188)
    at org.apache.rocketmq.client.java.impl.producer.ProducerImpl.startUp(ProducerImpl.java:114)
    at org.apache.rocketmq.shaded.com.google.common.util.concurrent.AbstractIdleService$DelegateService$1.run(AbstractIdleService.java:62)
    at org.apache.rocketmq.shaded.com.google.common.util.concurrent.Callables.lambda$threadRenaming$3(Callables.java:103)
    at java.base/java.lang.Thread.run(Thread.java:1583)
Exception in thread "main" java.lang.RuntimeException: Expected the service ProducerImpl-0 [FAILED] to be RUNNING, but the service has FAILED
    at com.xmzn.common.mq.producer.SyncProducer.sendMessage(SyncProducer.java:41)
    at com.xmzn.common.mq.producer.SyncProducer.main(SyncProducer.java:46)

怎么解决?

展开
收起
30650769 2023-11-07 11:49:36 440 0
1 条回答
写回答
取消 提交回答
  • 如果你已经部署了RocketMQ 5.1.4并且无法发送消息,这里有一些可能的原因和解决方案:

    1. 网络连接问题:检查网络连接是否正常。如果可能,请尝试ping RocketMQ服务器以确保可以正常通信。
    2. 客户端配置错误:检查客户端配置是否正确。例如,检查broker地址、namesrv地址以及topic名称是否正确。
    3. 消息体格式错误:检查消息体格式是否符合RocketMQ的要求。例如,消息头中的某些字段可能需要特定值。
    4. 权限问题:确认客户端是否有权限发送消息。你可以在服务器上查看相应的日志文件,看看是否有任何与权限相关的错误信息。
    5. 消息队列已满:如果消息队列已满,则无法再发送消息。你可以检查RocketMQ服务器上的日志文件,看看是否有与此相关的错误信息。

    以上是一些常见的原因和解决方法,但具体问题可能需要结合实际场景分析。希望这些信息对你有所帮助。

    2023-11-07 12:24:55
    赞同 1 展开评论 打赏

涵盖 RocketMQ、Kafka、RabbitMQ、MQTT、轻量消息队列(原MNS) 的消息队列产品体系,全系产品 Serverless 化。RocketMQ 一站式学习:https://rocketmq.io/

相关产品

  • 云消息队列 MQ
  • 相关电子书

    更多
    RocketMQ Client-GO 介绍 立即下载
    RocketMQ Prometheus Exporter 打造定制化 DevOps 平台 立即下载
    基于 RocketMQ Prometheus Exporter 打造定制化 DevOps 平台 立即下载