Commit 183042cb by 赵剑炜

RabbitMQ调整

parent d3ae1c75
......@@ -39,3 +39,4 @@
Icon?
ehthumbs.db
Thumbs.db
/*/target/*
package com.junmp.junmpProcess.listener;
import com.junmp.junmpProcess.utils.RabbitMQUtils2;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import lombok.SneakyThrows;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.impl.event.FlowableEntityEventImpl;
......@@ -19,6 +23,7 @@ public class GlobalEndListener extends AbstractFlowableEngineEventListener {
* @Params:
* @Return
*/
@SneakyThrows
@Override
protected void processCompleted(FlowableEngineEntityEvent event) {
//流程结束后工作在这里写
......@@ -26,7 +31,20 @@ public class GlobalEndListener extends AbstractFlowableEngineEventListener {
String processDefinitionId = event.getProcessDefinitionId();
//得到流程实例id
String processInstanceId = event.getProcessInstanceId();
/**
* 生产者不需要绑定队列和交换机,只有生产者才需要
*
* 建立连接
* 建立通道
* 推送消息
*/
Connection connection = RabbitMQUtils2.getConnection();
Channel channel = connection.createChannel();
channel.basicPublish("", "info",null,null);
RabbitMQUtils2.closeChannelAndConnection(connection,channel);
}
}
package com.junmp.junmpProcess.service.Bussiness;public class RabbitNoticeService {
}
package com.junmp.junmpProcess.service.Bussiness.impl;public class RabbitNoticeService {
}
package com.junmp.junmpProcess.utils;public class RabbitMQUtils {
package com.junmp.junmpProcess.utils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import java.util.Properties;
public class RabbitMQUtils {
private static ConnectionFactory connectionFactory;
private static Properties properties;
static{
//重量级资源 类加载执行之执行一次
connectionFactory = new ConnectionFactory();
connectionFactory.setHost("124.222.235.52");
connectionFactory.setPort(5672);
connectionFactory.setVirtualHost("/");
connectionFactory.setUsername("guest");
connectionFactory.setPassword("guest");
}
//定义提供连接对象的方法
public static Connection getConnection() {
try {
return connectionFactory.newConnection();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
//关闭通道和关闭连接工具方法
public static void closeConnectionAndChanel(Channel channel, Connection conn) {
try {
if(channel!=null) {
channel.close();
}
if(conn!=null) {
conn.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
System.out.println("RabbitMQUtils.getConnection() = " + RabbitMQUtils.getConnection());
}
}
package com.junmp.junmpProcess.utils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
@Component
public class RabbitMQUtils2 {
private static final String host = "192.168.3.188";
private static final int port = 5672;
private static final String username = "root";
private static final String password = "123456";
public static void closeChannelAndConnection(Connection connection, Channel channel){
try {
channel.close();
connection.close();
} catch (IOException | TimeoutException e) {
e.printStackTrace();
}
}
public static Connection getConnection() throws IOException, TimeoutException {
ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.setHost(host);
connectionFactory.setPort(port);
connectionFactory.setUsername(username);
connectionFactory.setPassword(password);
return connectionFactory.newConnection();
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论