使用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的更多相关文章

  1. golang连接activemq,发送接收数据

    介绍 使用golang连接activemq发送数据的话,需要使用一个叫做stomp的包,直接go get github.com/go-stomp/stomp即可 代码 生产者 package main ...

  2. windows下用golang连接mssql

    版权声明:本文为博主原创文章,未经博主允许不得转载.   目录(?)[+] 安装Microsoft SQL Server Native Client 安装golang的mssql驱动 写测试代码   ...

  3. 消费者端的Spring JMS 连接ActiveMQ接收生产者Oozie Server发送的Oozie作业执行结果

    一,介绍 Oozie是一个Hadoop工作流服务器,接收Client提交的作业(MapReduce作业)请求,并把该作业提交给MapReduce执行.同时,Oozie还可以实现消息通知功能,只要配置好 ...

  4. Golang连接Oracle数据库

    Golang连接Oracle的库有很多,比较常见的如下: 不过,oralce 只提供了 oci8 的接口,必须通过它来调用,所以下面方案都逃不过相关设置. 1.go-db-oracle 地址: htt ...

  5. python使用stomp连接activemq

    一.安装ActiveMQ服务 1. 当使用windows时,安装参考:https://blog.csdn.net/WuLex/article/details/78323811 启动:运行activem ...

  6. php 通过stomp协议连接ActiveMQ

    一.安装php的stomp扩展 http://pecl.php.net/package/stomp 如:stomp-2.0.0.tgz > tar xf stomp-1.0.9.tgz > ...

  7. golang连接达梦数据库的一个坑

    golang连接达梦数据库的一个坑 有一次项目中用到了达梦数据库,后端语言使用的golang,达梦官方并未适配专门的golang连接方式,正一筹莫展的时候发现达梦提供了odbc的连接,这样可以使用类似 ...

  8. eclipse 搭建连接 activemq

    今天我特地写下笔记,希望可以完全掌握这个东西,也希望可以帮助到任何想对学习这个东西的同学. 1.下载activemq压缩包,并解压(如果需要下载请看文章尾部附录) 2.进入bin文件夹,(64位电脑就 ...

  9. golang连接orcale

    使用glang有一段时间了,最开始其实并不太喜欢他的语法,但是后来熟悉之后发现用起来还挺爽的.之前数据库一直使用mysql,连接起来没有什么问题,github上有很多完善的驱动,所以以为连接其他数据库 ...

随机推荐

  1. MATLAB问题小集合

    1.未定义与 'struct' 类型的输入参数相对应的函数 'tb_optparse' 在运行matlab程序时,出现上述错误. 原因是tb_optparse在common文件夹里面,没在robot文 ...

  2. js--获取和设置css属性

    在这一章我们讲述一下如何通过js来操作css中的属性 1,首先,我们想获取元素的一些属性.例如innerHTML,value等值时,我们可以 var object=document.getELemen ...

  3. upd

    今天是中华人民共和国成立70周年,先祝我的祖国母亲生日快乐 由于最近嗓子不太好使,我就不发歌了 分割线 在学校挤了一点本来应该发呆的时间写了点没用的 前一部分是对一点OI知识的复习,后一部分是最近高中 ...

  4. ArcGIS 生成要素轮廓线掩膜

    先说效果: 生成轮廓之前:

  5. Easyui Datagrid扩展fixRownumber方法 转载

    $.extend($.fn.datagrid.methods, { fixRownumber : function (jq) { return jq.each(function () { var pa ...

  6. 前段性能----repaint和reflow

    在前面小节,我们对网页渲染过程做了介绍,其中最后两步就是layout与paint,当渲染对象被创建并添加到树中,它们并没有位置和大小,计算这些值的过程称为layout或reflow.绘制阶段,遍历渲染 ...

  7. spark调优——算子调优

    算子调优一:mapPartitions 普通的map算子对RDD中的每一个元素进行操作,而mapPartitions算子对RDD中每一个分区进行操作.如果是普通的map算子,假设一个partition ...

  8. DOM是什么

    UI—html—DOM(tree-structured representation. manipulate)—Virtual DOM(component) Real DOM强调树状结构的整体:核心是 ...

  9. Java监听器中ServletRequestListener监听Request的创建和销毁

    ServletRequest和HttpServletRequest的区别 HttpServletRequest和ServletRequest都是接口,HttpServletRequest继承自Serv ...

  10. python 日期、时间、字符串相互转换(转载)

    原文链接:https://www.cnblogs.com/huhu-xiaomaomi/p/10338472.html 在python中,日期类型date和日期时间类型dateTime是不能比较的. ...