|
@ -57,6 +57,13 @@ public class BlockChainProducer { |
|
|
@PostConstruct |
|
|
@PostConstruct |
|
|
private void postConstruct() { |
|
|
private void postConstruct() { |
|
|
try { |
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
// 如果没有启用,则跳过
|
|
|
|
|
|
if (!rocketMQProperties.getBlockChain().getEnable()) { |
|
|
|
|
|
log.info("未开启区块链的MQ配置,初始化Producer动作取消"); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
producer = new DefaultMQProducer(GROUP_EPMET_CLOUD_PROJECT_SENDER, |
|
|
producer = new DefaultMQProducer(GROUP_EPMET_CLOUD_PROJECT_SENDER, |
|
|
new AclClientRPCHook(new SessionCredentials(rocketMQProperties.getBlockChain().getAccessKey(), rocketMQProperties.getBlockChain().getSecretKey()))); |
|
|
new AclClientRPCHook(new SessionCredentials(rocketMQProperties.getBlockChain().getAccessKey(), rocketMQProperties.getBlockChain().getSecretKey()))); |
|
|
producer.setNamesrvAddr(rocketMQProperties.getBlockChain().getNameServer()); |
|
|
producer.setNamesrvAddr(rocketMQProperties.getBlockChain().getNameServer()); |
|
@ -82,6 +89,13 @@ public class BlockChainProducer { |
|
|
*/ |
|
|
*/ |
|
|
public void sendMsg(String topic, String tag, String content) { |
|
|
public void sendMsg(String topic, String tag, String content) { |
|
|
try { |
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
// 如果没有启用,则跳过
|
|
|
|
|
|
if (!rocketMQProperties.getBlockChain().getEnable()) { |
|
|
|
|
|
log.info("未开启区块链的MQ配置,发送消息到区块链动作取消"); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Message msg = new Message(topic, tag, content.getBytes(RemotingHelper.DEFAULT_CHARSET)); |
|
|
Message msg = new Message(topic, tag, content.getBytes(RemotingHelper.DEFAULT_CHARSET)); |
|
|
SendResult sendResult = producer.send(msg); |
|
|
SendResult sendResult = producer.send(msg); |
|
|
if (SendStatus.SEND_OK == sendResult.getSendStatus() |
|
|
if (SendStatus.SEND_OK == sendResult.getSendStatus() |
|
|