rabbitmq中python和ruby通信
来源:互联网 发布:心动网络官网电脑版 编辑:程序博客网 时间:2024/06/05 21:18
前面一章已经介绍了rabbitmq在python中传递消息,那么作为比较强大的rabbitmq中间件,他如何实现在ruby上传递消息以及和python中间传递消息呢?
1.安装rabbtmq的服务器,(前一篇已经介绍过了)
2. gem install bunny --安装bunny的gem包,这样就可以在客户端用ruby访问了
我们写一个send.rb
require "bunny" --引入bunnyconn = Bunny.new(:hostname => "localhost") conn.start --链接服务器ch = conn.create_channel --创建通道q = ch.queue("hello") --创建队列hello ch.default_exchange.publish("Hello World!", :routing_key => q.name) puts " [x] Sent 'Hello World!'"conn.close
然后在写一个 receive.rb
require "bunny"conn = Bunny.new conn.start ch = conn.create_channel q = ch.queue("hello")puts " [*] Waiting for messages in #{q.name}. To exit press CTRL+C" q.subscribe(:block => true) do |delivery_info, properties, body| puts " [x] Received #{body}" # cancel the consumer to exit delivery_info.consumer.cancel end 好了,运行下就好了!$ ruby send.rb" [x] Sent 'Hello World!'"
$ ruby receive.rb”[x] Received Hello World!"这是ruby和ruby之间通信,那么我们在加入python的代码send.py
import pikaconnection = pika.BlockingConnection(pika.ConnectionParameters( host='localhost'))channel = connection.channel()channel.queue_declare(queue='hello')channel.basic_publish(exchange='', routing_key='hello', body='Hello World!')print " [x] Sent 'Hello World!'"connection.close()我们在运行下
python send.pyruby receive.rb" [x] Sent 'Hello World!'"
" [x] Receive 'Hello World!'"
- rabbitmq中python和ruby通信
- zeromq中ruby和python的通信
- python队列通信:rabbitMQ使用
- Ruby和Python中单行操作
- Rabbitmq 和 python
- python和ruby对比
- memcacheq 中php 和python的通信
- RabbitMQ-理解消息通信-消费者和生产者
- RabbitMQ-理解消息通信-虚拟主机和隔离
- 用Ruby链接RabbitMQ
- Python和Ruby语言对比
- Python和Ruby语言对比
- Ruby和Python的比较
- ruby和python的比较
- Python 和 Ruby 的对比
- Python 和 Ruby 的对比
- Python下使用pika简单实现RabbitMQ通信
- 在python中引入rabbitmq消息中间件
- 在Matlab中如何快速生成均匀分布的圆带形数据?
- CCAction类详解
- 黑马程序员_03_循环语句
- PKI常见证书格式和转换
- DNS协议及应用
- rabbitmq中python和ruby通信
- 我的FPGA入门学习计划
- 一组简单DP题
- mysql存储过程基本函数
- Java I/0 总体框架图
- 如何优化Html5 App 在IOS/Android 上的性能
- 第六篇 STM复用
- 处理字符串的外部表示(Handling External Representations of Strings)CFString
- mysql 查询缓存相关命令