C#整合ActiveMQ与SpringBoot整合ActiveMQ数据间交互
一、SpringBoot整合AvtiveMQ部分
1.引入ActiveMQ依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
2.在application中加入配置参数,放在spring配置下
activemq:
broker-url: tcp://127.0.0.1:61616
user: admin
password: admin
in-memory: false
packages:
trust-all: true
pool:
max-connections: 10
enabled: false
idle-timeout: 30000
jms:
pub-sub-domain: true
3.创建topic
package com.mengxiangnongfu.smart_party_school.framework.configure; import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.stereotype.Component; import javax.jms.Topic; /**
* @author Yang
* @version 1.0
* @date 2022/6/23 13:51
*/
@Component
@EnableJms
public class ActiveMqTopicConfig { /**
* 照明的topic
* @return
*/
@Bean(name = "lighting")
public Topic lig() {
return new ActiveMQTopic("lighting-topic");
} }
4.发送数据
@Autowired
@Qualifier(value = "lighting") //注入配置topice的bean 因为可能配置多个topice的bean所以加入 @Qualifier指定name
private Topic lighting;
@Autowired
private JmsMessagingTemplate jmsMessagingTemplate; @Autowired
@Qualifier(value = "lighting")
private Topic lighting; @Release
@GetMapping("/active-mq/send")
public AjaxResult activeMqSend() {
log.debug("【debug】.......");
jmsMessagingTemplate.convertAndSend(lighting, "F1 F2 F3 F4 F4");
return AjaxResult.success();
}
二、C#整合ActiveMQ
1.通过NuGet引入Active依赖
2.建立与activemq的通讯,建议用多线程,在新建的线程中做
public void Receive()
{
try
{
//创建连接池
IConnectionFactory factory = new ConnectionFactory("tcp://127.0.0.1:61616/");
IConnection connection = factory.CreateConnection();
connection.ClientId = SystemConstants.LIGHTING_CLIENT_NAME;
connection.Start(); ISession session = connection.CreateSession(); //创建Consumer
IMessageConsumer consumer = session.CreateDurableConsumer(new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic("lighting-topic"), "Consumer1", null, false);
consumer.Listener += new MessageListener(consumer_Listener); /* connection.Stop();
connection.Close();*/
}
catch (System.Exception e)
{
rtx_result.Text += e.Message;
}
}
void consumer_Listener(IMessage message)
{
try
{
ITextMessage msg = (ITextMessage)message;
//Invoke(new DelegateRevMessage(RevMessage), msg);
rtx_result.Text = rtx_result.Text + msg.Text+"\n";
}
catch (System.Exception e)
{
Console.WriteLine(e.Message);
}
}
public delegate void DelegateRevMessage(ITextMessage message);
public void RevMessage(ITextMessage message)
{
rtx_result.Text += string.Format(@"接收到:{0}{1}", message.Text, Environment.NewLine);
}
C#整合ActiveMQ与SpringBoot整合ActiveMQ数据间交互的更多相关文章
- SpringBoot系列八:SpringBoot整合消息服务(SpringBoot 整合 ActiveMQ、SpringBoot 整合 RabbitMQ、SpringBoot 整合 Kafka)
声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.概念:SpringBoot 整合消息服务 2.具体内容 对于异步消息组件在实际的应用之中会有两类: · JMS:代表作就是 ...
- SpringBoot整合全局异常处理&SpringBoot整合定时任务Task&SpringBoot整合异步任务
============整合全局异常=========== 1.整合web访问的全局异常 如果不做全局异常处理直接访问如果报错,页面会报错500错误,对于界面的显示非常不友好,因此需要做处理. 全局异 ...
- 【SpringBoot整合Elasticsearch】SpringBoot整合ElasticSearch
一.Linux下安装ElasticSearch 1.检测是否安装了Elasticsearch ps aux |grep elasticsearch 2.安装JDK 3.下载Elasticsearch ...
- SpringBoot整合Jsp和Thymeleaf (附工程)
前言 本篇文章主要讲述SpringBoot整合Jsp以及SpringBoot整合Thymeleaf,实现一个简单的用户增删改查示例工程.事先说明,有三个项目,两个是单独整合的,一个是将它们整合在一起的 ...
- Springboot整合druid
目录 Springboot整合druid application.yml DruidConfig 数据监控地址:http://localhost:8080/druid Springboot整合drui ...
- 很详细的SpringBoot整合UEditor教程
很详细的SpringBoot整合UEditor教程 2017年04月10日 20:27:21 小宝2333 阅读数:21529 版权声明:本文为博主原创文章,未经博主允许不得转载. https: ...
- 凭借SpringBoot整合Neo4j,我理清了《雷神》中错综复杂的人物关系
原创:微信公众号 码农参上,欢迎分享,转载请保留出处. 哈喽大家好啊,我是Hydra. 虽然距离中秋放假还要熬过漫长的两天,不过也有个好消息,今天是<雷神4>上线Disney+流媒体的日子 ...
- SpringBoot整合Swagger2,再也不用维护接口文档了!
前后端分离后,维护接口文档基本上是必不可少的工作.一个理想的状态是设计好后,接口文档发给前端和后端,大伙按照既定的规则各自开发,开发好了对接上了就可以上线了.当然这是一种非常理想的状态,实际开发中却很 ...
- Springboot的日志管理&Springboot整合Junit测试&Springboot中AOP的使用
==============Springboot的日志管理============= springboot无需引入日志的包,springboot默认已经依赖了slf4j.logback.log4j等日 ...
- Spring Boot2 系列教程(十七)SpringBoot 整合 Swagger2
前后端分离后,维护接口文档基本上是必不可少的工作. 一个理想的状态是设计好后,接口文档发给前端和后端,大伙按照既定的规则各自开发,开发好了对接上了就可以上线了.当然这是一种非常理想的状态,实际开发中却 ...
随机推荐
- 在GCP上创建GCE的三种方式(Console,gcloud,Terraform)
1 简介 如果要选择GCP为云平台,则经常需要创建GCE(Google Compute Engine),有以下几种方式: (1) 在浏览器创建 (2) 命令 gcloud (3) Terraform ...
- Potree 003 基于Potree Desktop创建自定义工程
1.第三方js库 第三方库js库选择dojo,其官网地址为https://dojotoolkit.org/,git地址为https://github.com/dojo/dojo,demo地址为http ...
- Ubuntu 配置 Oh-my-zsh
注意 oh-my-zsh 这玩意安装简单.卸载难.维护极其繁琐,动不动就报错.体验一下还可以,我个人建议能不装就不装. 下载 zsh sudo apt install zsh 下载 oh-my-zsh ...
- C# 托管堆 遭破坏 问题溯源分析
一:背景 1. 讲故事 年前遇到了好几例托管堆被损坏的案例,有些运气好一些,从被破坏的托管堆内存现场能观测出大概是什么问题,但更多的情况下是无法做出准确判断的,原因就在于生成的dump是第二现场,借用 ...
- JDK的下载与安装-环境变量的配置
JDK的下载与安装 环境变量的配置 配置环境变量作用 开发Java程序,需要使用JDK中提供的工具,工具在JDK9安装目录的 bin 目录下. 在DOS命令行下使用这些工具,就要先进入到JDK的bin ...
- postgresql添加mysql_fdw测试过程
请先确认已经安装好mysql_fdw,如果没有配置好点这:https://www.cnblogs.com/ohsolong/p/13041989.html 1.切换至postgres用户,输入密码登录 ...
- 笔记:C#Datatable 根据某字段数量 自动复制该行的数量
/// <summary> /// 根据Datatable某字段数量自动复制该行查询 /// </summary> /// <param name="dt&qu ...
- 【DS】2.1
线性表:c++各种基础操作里面,有&没&避免错的代码额~ #include <stdio.h> void test(int &x){//没有&就没有带回主函 ...
- j-link "the connected j-link is defective"问题的解决
出现这个原因是 J-link和J-link的驱动不匹配,比如J-link的固件太老,J-link驱动太新.因此要解决的话,要不就是换不同版本的J-link驱动,要不就是换J-Link或升级J-link ...
- Ubuntu18.04 下使用Flatpak稳定安装TIM、微信、迅雷和百度云
https://gitee.com/wszqkzqk/deepin-wine-for-ubuntu git clone https://gitee.com/wszqkzqk/deepin-wine-c ...