org.apache.rocketmq.client.exception.MQClientException: No route info of this topic, TopicTest异常解决

可能性1:
可能是由于mq没启动成功
进入对应bin目录,修改文件runserver.sh runbroker.sh。 把VM参数都改成

-Xms256m -Xmx256m -Xmn128m 

或者你想要的大小。默认给的8G,如果不改,很可能启动不成功。

4、启动 NameServer。

nohup sh bin/mqnamesrv & .

查看是否启动成功

jps

查看启动日志

tail -f ~/logs/rocketmqlogs/namesrv.log

5、启动 BrokerServer。

nohup sh bin/mqbroker -n localhost:9876 & .

查看启动日志

tail -f ~/logs/rocketmqlogs/broker.log

6、关闭服务。

sh bin/mqshutdown broker
sh bin/mqshutdown namesrv

可能性2:

Broker 禁止自动创建Topic,且用户没有通过手动创建此Topic,或者broker 和 Nameserver网络不通

二、解决方案:

  1. 修改broker.properties配置,自动创建topic,添加如下:

    autoCreateTopicEnable=true

    官方文档中启动 Broker是这样的:

    nohup sh bin/mqbroker -n localhost:9876 &

    其实我们可以改成这样:

    nohup sh bin/mqbroker -n localhost:9876 autoCreateTopicEnable=true & 

nginx 反代ws协议进行im在线聊天的 websocket协议

   location /im-api/ {
        proxy_redirect off;
        proxy_pass http://172.26.71.51:9218/;      # 转发
        proxy_set_header Host $host;
        proxy_set_header X-Real_IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr:$remote_port;
        proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;   # 升级协议头 websocket
        proxy_set_header Connection upgrade;
            proxy_set_header Connection $connection_upgrade;
          }

linux定时任务执行

#!/bin/bash

# Define the directory where logs are stored
LOG_DIR="/data/scripts"

# Define the maximum file size in bytes (10GB = 10 * 1024 * 1024 * 1024)
MAX_SIZE=$((10*1024*1024*1024))

# Log file for recording execution logs
LOG_FILE="/var/log/cleanup_logs.log"

# Log the current date/time and action
echo "$(date +'%Y-%m-%d %H:%M:%S') - Starting log cleanup" >> "$LOG_FILE"

# Find and delete log files larger than MAX_SIZE bytes recursively
find "$LOG_DIR" -type f -name "*.log" -size +$MAX_SIZEc -print0 | while IFS= read -r -d '' file; do
    echo "$(date +'%Y-%m-%d %H:%M:%S') - Deleting $file" >> "$LOG_FILE"
    rm -f "$file"
done

# Log the completion
echo "$(date +'%Y-%m-%d %H:%M:%S') - Log cleanup completed" >> "$LOG_FILE"

每30分钟执行一次

*/30 * * * * /home/user/scripts/myscript.sh