Golang 连接ActiveMQ
使用ActiveMQ库:github.com/go-stomp/stomp
示例代码
package main import (
"net"
"fmt"
"os"
"github.com/gpmgo/gopm/modules/goconfig"
"github.com/go-stomp/stomp"
"strconv"
) // 读取配置文件
func getConfigFile(filePath string) (configFile *goconfig.ConfigFile){
configFile, err := goconfig.LoadConfigFile(filePath)
if err != nil {
fmt.Println("load config file error: " + err.Error())
os.Exit(1)
}
return configFile
} // 使用IP和端口连接到ActiveMQ服务器
// 返回ActiveMQ连接对象
func connActiveMq(host, port string) (stompConn *stomp.Conn){// @todo 实现断开重连
stompConn, err := stomp.Dial("tcp", net.JoinHostPort(host, port))
if err != nil {
fmt.Println("connect to active_mq server service, error: " + err.Error())
os.Exit(1)
} return stompConn
}
// 将消息发送到ActiveMQ中
func activeMqProducer(c chan string, queue string, conn *stomp.Conn){
for{
err := conn.Send(queue, "text/plain", []byte(<-c))
fmt.Println("send active mq..." + queue)
if err != nil {
fmt.Println("active mq message send erorr: " + err.Error())
}
}
} func main() {
configPath := "./config.ini"
configFile := getConfigFile(configPath) host, err := configFile.GetValue("active_mq", "host")
if err != nil {
fmt.Println("get active_mq host error: " + err.Error())
os.Exit(1)
}
port, err:= configFile.GetValue("active_mq", "port")
if err != nil {
fmt.Println("get active_mq port error: " + err.Error())
os.Exit(1)
} queue, err := configFile.GetValue("active_mq", "queue")
if err != nil {
fmt.Println("get active_mq queue error: " + err.Error())
os.Exit(1)
} activeMq := connActiveMq(host, port)
defer activeMq.Disconnect()
c := make(chan string)
// 启动Go routine发送消息
go activeMqProducer(c, queue, activeMq) for i := 0; i < 10000; i ++{
// 发送1万个消息
c <- "hello world" + strconv.Itoa(i)
} }
Golang 连接ActiveMQ的更多相关文章
- golang连接activemq,发送接收数据
介绍 使用golang连接activemq发送数据的话,需要使用一个叫做stomp的包,直接go get github.com/go-stomp/stomp即可 代码 生产者 package main ...
- windows下用golang连接mssql
版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] 安装Microsoft SQL Server Native Client 安装golang的mssql驱动 写测试代码 ...
- 消费者端的Spring JMS 连接ActiveMQ接收生产者Oozie Server发送的Oozie作业执行结果
一,介绍 Oozie是一个Hadoop工作流服务器,接收Client提交的作业(MapReduce作业)请求,并把该作业提交给MapReduce执行.同时,Oozie还可以实现消息通知功能,只要配置好 ...
- Golang连接Oracle数据库
Golang连接Oracle的库有很多,比较常见的如下: 不过,oralce 只提供了 oci8 的接口,必须通过它来调用,所以下面方案都逃不过相关设置. 1.go-db-oracle 地址: htt ...
- python使用stomp连接activemq
一.安装ActiveMQ服务 1. 当使用windows时,安装参考:https://blog.csdn.net/WuLex/article/details/78323811 启动:运行activem ...
- php 通过stomp协议连接ActiveMQ
一.安装php的stomp扩展 http://pecl.php.net/package/stomp 如:stomp-2.0.0.tgz > tar xf stomp-1.0.9.tgz > ...
- golang连接达梦数据库的一个坑
golang连接达梦数据库的一个坑 有一次项目中用到了达梦数据库,后端语言使用的golang,达梦官方并未适配专门的golang连接方式,正一筹莫展的时候发现达梦提供了odbc的连接,这样可以使用类似 ...
- eclipse 搭建连接 activemq
今天我特地写下笔记,希望可以完全掌握这个东西,也希望可以帮助到任何想对学习这个东西的同学. 1.下载activemq压缩包,并解压(如果需要下载请看文章尾部附录) 2.进入bin文件夹,(64位电脑就 ...
- golang连接orcale
使用glang有一段时间了,最开始其实并不太喜欢他的语法,但是后来熟悉之后发现用起来还挺爽的.之前数据库一直使用mysql,连接起来没有什么问题,github上有很多完善的驱动,所以以为连接其他数据库 ...
随机推荐
- LoarRunner脚本录制-Port Mapping
使用LR录制脚本时经常会因为内外网访问限制,或浏览器兼容等问题,导致无法正常录制脚本. 这里简单介绍一下使用LR端口映射的方式进行脚本录制,与之前介绍的<Jmeter脚本录制--HTTP代理服务 ...
- 《团队名称》第八次团队作业:Alpha冲刺day3
项目 内容 这个作业属于哪个课程 2016计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 实验十二 团队作业8-软件测试与ALPHA冲刺 团队名称 快活帮 作业学习目标 (1)掌握 ...
- Linux计划作业练习
1.crontab -eu zh //每天晚上10天提醒用户可以去睡觉了 * */10 * * * go to sleep 2.查询crontab的工作内容 3.当crontab命令格式出错时 ...
- docker 空间清理
https://blog.csdn.net/qq_28001193/article/details/79555177 清理之后,重要的是找到原因,如上连接所示,其中一个占空间比较大的是日志文件,除了考 ...
- luogu_1155: 双栈排序
洛谷1155:双栈排序 题意描述: 给定一个长度为\(n\)的序列\((n\leq 1000)\),两个初始为空的栈,问是否能借助以下四种操作将序列排为升序. \(1:\)如果序列不为空,将第一个元素 ...
- Missing Data Reconstruction in Remote Sensing Image With a Unified Spatial–Temporal–Spectral Deep Convolutional Neural Network(缺失数据补全,时空谱网络)
摘要 文章针对修复坏波段(AQUA B6),恢复条带损失,恢复云污染提出了一个深度学习网络结构,他说 To date, to the best of our knowledge, no studies ...
- MySql的执行计划
一.什么是数据库执行计划: MySQL执行计划是sql语句经过查询优化器后,查询优化器会根据用户的sql语句所包含的字段和内容数量等统计信息,选择出一个执行效率最优(MySQL系统认为最优)的执行计划 ...
- node.js 自启动工具 supervisor
supervisor 会不停的watch 你应用下面的所有文件,发现有文件被修改,就重新载入程序文件这样就实现了部署,修 改了程序文件后马上就能看到变更后的结果.麻麻再也不用担心我的重启 nodejs ...
- yarn一些最佳配置
合理设置队列名 mapreduce.job.queuename设置队列名map读取时进行小文件整合 mapreduce.input.fileinputformat.split.minsize mapr ...
- dateTime格式转换
select Convert(varchar(8),GETDATE(),112) Select replace(CONVERT(varchar(8), GETDATE(), 108),':','')