<>1 Business background
I'm working on new and old systems recently mysql Data synchronization , As the new system switches to micro service , The design of data structure is different , use RocketMQ Asynchronously synchronize data .
The old system already has an old version MQ colony , So in the micro service system , You need to configure two MQ colony , One for the new system , The other one is dedicated to synchronizing data to the old system .
<>2 code
Here, we only set the production group name and name according to the official document example namesrv Cluster address ;
The new system is used as follows MQ:
private DefaultMQProducer producer=new DefaultMQProducer("accountProducer");
producer.setNamesrvAddr(" New system cluster namesrv address "); producer.start(); String msgStr =
" New system business message content "; Message msg = new Message(topicName, key, "", msgStr.getBytes());
producer.sendMsg(msg);
The old system is used as follows MQ:
private DefaultMQProducer producer=new
DefaultMQProducer("asyncToOldSysProducer");
producer.setNamesrvAddr(" Old system cluster namesrv address "); producer.start(); String msgStr =
" Message content that needs to be synchronized to the old system "; Message msg = new Message(topicName, key, "",
msgStr.getBytes()); producer.sendMsg(msg);
<>3 Interface test
Through the console, I found that it should be sent to the old system every time MQ News of , All sent to the new system MQ It's in the cluster , Strange for a long time , Check the performance of the old system namesrv There is no wrong address , It turns out that DefaultMQProducer I use the default one every time MQClient example ,
It should be used in the new system producer Instance time , Add such an explicit setting to the code , The message can be sent to the old system MQ colony .
producer.setInstanceName("AsyncToOldSysProducer");
This will work , Data synchronization to old system .
<>4 Multiple consumer instances
Multiple consumer instances also need to be explicitly set , The details are as follows :
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(
"SyncUserToNewConsumer"); // Multiple registries , Need to set instanceName consumer.setInstanceName(
"SyncUserToNewConsumer"); consumer.setNamesrvAddr(namesrvaddr);
Technology
Daily Recommendation