rocketMq combat (3)-console and operation and maintenance


 
 Something as complicated as rocketmq can't be done without operation and maintenance tools.

 

Haha, don't worry, the official provides a WEB project, you can view rocketmq data and perform some operations.

And I also added some features myself

Official website: https://github.com/rocketmq/rocketmq-console

Run and modify the address of namesers, note that multiple addresses are separated by semicolons



 

The following is the success page. The cluster queries the tps and dequeue and enqueue of the broker cluster.

topic query production and consumption information

connection queries the connection information between the producer and the consumer.

I won't talk about other things, just try more and you'll understand.

Pay attention to the item of consumer, you can query the message backlog, which is what we are most concerned about.

First of all, to correct a concept, the broker has no concept of backlog, only the consumer has the concept of backlog.

 

 



 Looking at the figure below, you can query the consumption of the consumer. The figure below is to query the production and consumption of the broker corresponding to each queue on the page of the specified consumer.

Diff Total is the total number of squeezes



 

 Focus on a few features I developed myself

1. Query the backlog of all consumers

If you want to query the extrusion situation of all consumers, sorry no, you can only develop it yourself.

The principle of this function is to execute the command through the ssh Java client to obtain the returned data, which can be executed on any broker (if children know a better way to implement it, please let me know).

The command information is as follows

RocketMQ command finishing: http://jameswxx.iteye.com/blog/2091971
 
Official document management commands: https://github.com/alibaba/RocketMQ/wiki/CLI-Admin-Tool

 


 通过sa账号执行 sh /opt/ali-rocketmq/devenv/bin/mqadmin consumerProgress -n \"10.103.16.77:9876;10.103.16.15:9876\"  报出

()

ERROR: Please set the JAVA_HOME variable in your environment, We need java(x64)! !!

解决方法

 在bin/mqadmin 脚本写入 export JAVA_HOME=/usr/local/java .

 

 

具体代码实现见附件

 

 

 二,定时查询某个topic的挤压数 ,报警功能

代码如下

/**
 * 单条consumer的定时提醒
 * @author chenchangqun
 *
 */
public class SingleNotifyTask {
    static final Logger logger = LoggerFactory.getLogger(SingleNotifyTask.class);
	private int delayMils;//延迟启动时间,单位 毫秒
	private int periodMils;//周期时间 间隔,单位 毫秒
	private 	String consumerName;
	   private INotifyInvoke notifyInvoke;//通知操作	
	@Resource(name="consumerService")
    private ConsumerService consumerService;
       private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
            return new Thread(r, "MQNotifyTaskScheduledThread");
        }
    });
	public void init(){
   scheduledExecutorService.scheduleAtFixedRate(new Runnable(){
	@Override
			public void run() {
				try {
					Table table = consumerService.consumerProgress(consumerName);
					String diffCountStr = table.getExtData().get("Diff Total:");
					if (StringUtils.isBlank(diffCountStr)) {
						logger.error("diff Total is null,consumer=" + consumerName);
						return;
					}
					int diffCount = Integer.parseInt(diffCountStr);
					notifyInvoke.invoke(diffCount,consumerName);
				

				} catch (Throwable e) {
					logger.error("queryConsumerState fail, consumer=" + consumerName, e);
				}

			}
	}, delayMils, periodMils, TimeUnit.MILLISECONDS);
	}
 
	public void setDelayMils(int delayMils) {
		this.delayMils = delayMils;
	}
	public void setPeriodMils(int periodMils) {
		this.periodMils = periodMils;
	}
	public void setConsumerName(String consumerName) {
		this.consumerName = consumerName;
	}

	public void setNotifyInvoke(INotifyInvoke notifyInvoke) {
		this.notifyInvoke = notifyInvoke;
	}
	
}

 通过 定时调用rocketmq的API查询挤压数,根据实现类的逻辑执行报警

/**
 * 通知操作 interface
 * @author chenchangqun
 *
 */
public interface INotifyInvoke {

/**
 * 执行通知的具体操作
 * @param diffCount
 */
public void  invoke(int diffCount,String consumerName);
}

 

/**
 * 操作通知具体实现类
 * @author chenchangqun
 *
 */
public class NotifyInvokeImpl implements INotifyInvoke {
private int thresholdValue;//积压阀值,用作是否发出提醒
	@Override
	public void invoke(int diffCount,String  consumerName) {
		if (diffCount > thresholdValue) {
			System.out.println("single check invoke ," + consumerName
					+ "  geater thean thresholdValue ,do something,thresholdValue=" + thresholdValue);
		}
	}
	public void setThresholdValue(int thresholdValue) {
		this.thresholdValue = thresholdValue;
	}
}

 

配置如下

 

  
<bean id="singleNotifyTask" class="com.alibaba.rocketmq.common.SingleNotifyTask" init-method="init">
   <property name="consumerName" value="firstSpringConsumer"></property>
   <property name="delayMils" value="1000"></property>
   <property name="periodMils" value="3000"></property>
   <property name="notifyInvoke" ref="notifyInvoke"></property> 
   </bean>
  <!-- 具体的通知动作 -->   
<bean id="notifyInvoke" class="com.alibaba.rocketmq.common.NotifyInvokeImpl" >
   <property name="thresholdValue" value="1"></property>
   </bean>
    

 

 

附件中给出具体代码,仅供参考

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326545641&siteId=291194637