设备接口
parent
9ed8f5f895
commit
48d9f577dc
@ -0,0 +1,60 @@
|
||||
package com.foreverwin.mesnac.common.config;
|
||||
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
|
||||
import org.springframework.jms.config.JmsListenerContainerFactory;
|
||||
import org.springframework.jms.core.JmsMessagingTemplate;
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnProperty(prefix = "spring.activemq", value = {"enabled"}, matchIfMissing = true)
|
||||
public class ActiveMQConfig {
|
||||
|
||||
//☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆
|
||||
@Primary
|
||||
@Bean(name = "defaultConnectionFactory")
|
||||
public ActiveMQConnectionFactory defaultConnectionFactory(
|
||||
@Value("${spring.activemq.brokerUrl}") String brokerUrl,
|
||||
@Value("${spring.activemq.user}") String username,
|
||||
@Value("${spring.activemq.password}") String password) {
|
||||
|
||||
return this.createConnectionFactory(brokerUrl, username, password);
|
||||
}
|
||||
|
||||
|
||||
private ActiveMQConnectionFactory createConnectionFactory (String brokerUrl, String username, String password) {
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
|
||||
factory.setBrokerURL(brokerUrl);
|
||||
factory.setUserName(username);
|
||||
factory.setPassword(password);
|
||||
return factory;
|
||||
}
|
||||
|
||||
//**************************************************************************************************************
|
||||
@Primary
|
||||
@Bean(name = "defaultJmsTemplate")
|
||||
public JmsMessagingTemplate defaultJmsTemplate(
|
||||
@Qualifier("defaultConnectionFactory") ActiveMQConnectionFactory connectionFactory) {
|
||||
|
||||
JmsMessagingTemplate template = new JmsMessagingTemplate(connectionFactory);
|
||||
return template;
|
||||
}
|
||||
|
||||
|
||||
//☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆
|
||||
@Primary
|
||||
@Bean(name = "defaultFactory")
|
||||
public JmsListenerContainerFactory defaultFactory(
|
||||
@Qualifier("defaultConnectionFactory") ActiveMQConnectionFactory connectionFactory) {
|
||||
|
||||
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
|
||||
factory.setConnectionFactory(connectionFactory);
|
||||
return factory;
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.foreverwin.mesnac.equip.consumer;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.foreverwin.mesnac.equip.dto.MQResponseDto;
|
||||
import com.foreverwin.mesnac.meapi.service.ResrceService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.jms.annotation.JmsListener;
|
||||
import org.springframework.jms.core.JmsMessagingTemplate;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.jms.Queue;
|
||||
|
||||
|
||||
/**
|
||||
* 设备交互MQ监听类
|
||||
*
|
||||
*
|
||||
* @author Leon
|
||||
* @date 2021-07-21
|
||||
*/
|
||||
@Component
|
||||
@ConditionalOnProperty(prefix = "spring.activemq", value = {"enabled"}, matchIfMissing = true)
|
||||
public class ResourceMQConsume {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ResourceMQConsume.class);
|
||||
|
||||
@Autowired
|
||||
private ResourceMQProcess resourceMQProcess;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("defaultJmsTemplate")
|
||||
private JmsMessagingTemplate template;
|
||||
|
||||
@JmsListener(destination = "resource.status.process", containerFactory = "defaultFactory")
|
||||
public void resourceStatusProcess(String text, MessageHeaders headers) {
|
||||
logger.info("接收设备状态变更数据:" + text);
|
||||
|
||||
String resultString = resourceMQProcess.resourceStatusProcess(text);
|
||||
//返回设备处理结果
|
||||
template.convertAndSend((Queue) headers.get("jms_replyTo"), resultString);
|
||||
}
|
||||
|
||||
@JmsListener(destination = "resource.alarm.process", containerFactory = "defaultFactory")
|
||||
public void resourceAlarmProcess(String text, MessageHeaders headers) {
|
||||
logger.info("接收设备报警数据:" + text);
|
||||
|
||||
template.convertAndSend((Queue) headers.get("jms_replyTo"), "");
|
||||
}
|
||||
|
||||
@JmsListener(destination = "resource.edc.process", containerFactory = "defaultFactory")
|
||||
public void resourceEdcProcess(String text) {
|
||||
logger.info("接收设备参数数据:" + text);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.foreverwin.mesnac.equip.dto;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
|
||||
/**
|
||||
* 设备交互MQ返回值类
|
||||
*
|
||||
*
|
||||
* @author Leon
|
||||
* @date 2021-07-21
|
||||
*/
|
||||
public class MQResponseDto {
|
||||
|
||||
@JSONField
|
||||
private String HANDLE;
|
||||
@JSONField
|
||||
private String STATUS;
|
||||
@JSONField
|
||||
private String MESSAGE;
|
||||
|
||||
public String getHANDLE() {
|
||||
return HANDLE;
|
||||
}
|
||||
|
||||
public void setHANDLE(String HANDLE) {
|
||||
this.HANDLE = HANDLE;
|
||||
}
|
||||
|
||||
public String getSTATUS() {
|
||||
return STATUS;
|
||||
}
|
||||
|
||||
public void setSTATUS(String STATUS) {
|
||||
this.STATUS = STATUS;
|
||||
}
|
||||
|
||||
public String getMESSAGE() {
|
||||
return MESSAGE;
|
||||
}
|
||||
|
||||
public void setMESSAGE(String MESSAGE) {
|
||||
this.MESSAGE = MESSAGE;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue