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上有很多完善的驱动,所以以为连接其他数据库 ...
随机推荐
- CSP-S2019 游记
想到正解,不一定赢 全部打满,才是成功 Day 0 首先很感谢各位朋友送的贺卡!!! 早上10点的高铁.今年可以直接在汕头站坐高铁不用专门跑到潮汕站了,1h->15min车程,巨大好评. 虽然离 ...
- The Role of View Controllers
https://developer.apple.com/library/content/featuredarticles/ViewControllerPGforiPhoneOS/index.html# ...
- Web安全之CSRF基本原理与实践
阅读目录 一:CSRF是什么?及它的作用? 二:CSRF 如何实现攻击 三:csrf 防范措施 回到顶部 一:CSRF是什么?及它的作用? CSRF(Cross-site Request Forger ...
- 使用cookie登录网盘账号
①使用Chrome浏览器登录百度网盘网页版 https://pan.baidu.com/ ②查看当前使用的cookie ③获取BDUSS 注意是全选复制,不要直接复制,会不全的. ④获取STOKEN ...
- Numpy | 15 数学函数
NumPy 包含大量的各种数学运算的函数,包括三角函数,算术运算的函数,复数处理函数等. 三角函数 NumPy 提供了标准的三角函数:sin().cos().tan(). import numpy a ...
- bzoj4066: 简单题 K-Dtree
bzoj4066: 简单题 链接 bzoj 思路 强制在线.k-dtree. 卡常啊.空间开1e6就T了. 代码 #include <bits/stdc++.h> #define my_m ...
- 洛谷 P1396
P1396 传送门 扯些题外话 讲真的我刚看到这个题的时候真的傻fufu的..... 大体题意 找出从s走到t的拥挤度最大值最小.. 思路 说最大值最小可能就会有dalao开始二分了. 想我这种的蒟蒻 ...
- 读RAM时的时序风险
读RAM时的时序有两个风险:1.数据已经存储好,读所需的时间.2.数据同时更新,读所需的时间节点.对于前者,只要延时足够节拍就行.对于后者,还必须要考虑数据建立的时间,同样延时的准备可能会因为数据尚未 ...
- shell 脚本接收参数
test.sh #!/bin/bash echo "脚本名$0" echo "第1个参数$1" echo "第2个参数$2" echo &q ...
- Fluent瞬态结果导出为Ensight格式
参考: (1)<ANSYS Fluent User's Guide>的3.13.9. EnSight Case Gold Files (2)https://support.ceisoftw ...