RabbitMQ-C 客户端接口使用说明
rabbitmq-c是一个用于C语言的,与AMQP server进行交互的client库。AMQP协议为版本0-9-1。rabbitmq-c与server进行交互前需要首先进行login操作,在操作后,可以根据AMQP协议规范,执行一系列操作。
这里,根据项目需求,只进行部分接口说明,文后附demo的github地址。
接口描述
- 接口说明:声明一个新的amqp connection
amqp_connection_state_t amqp_new_connection(void);
- 接口说明:获取socket
参数说明:hostname RabbitMQ server所在主机
portnumber RabbitMQ server监听端口
int amqp_open_socket(char const *hostname, int portnumber);
- 接口说明:将amqp connection和sockfd进行绑定
void amqp_set_sockfd(amqp_connection_state_t state,int sockfd);
- 接口说明:用于登录RabbitMQ server,主要目的为了进行权限管理;
参数说明:state amqp connection
vhost rabbit-mq的虚机主机,是rabbit-mq进行权限管理的最小单位
channel_max 最大链接数,此处设成0即可
frame_max 和客户端通信时所允许的最大的frame size.默认值为131072,增大这个值有助于提高吞吐,降低这个值有利于降低时延
heartbeat 含义未知,默认值填0
sasl_method 用于SSL鉴权,默认值参考后文demo
amqp_rpc_reply_t amqp_login(amqp_connection_state_t state, char const *vhost,int channel_max,int frame_max,int heartbeat,amqp_sasl_method_enum sasl_method, ...);
- 接口说明:用于关联conn和channel
amqp_channel_open_ok_t *amqp_channel_open(amqp_connection_state_t state, amqp_channel_t channel);
- 接口说明:声明declare
参数说明:state
channel
exchange
type "fanout" "direct" "topic"三选一
passive
curable
arguments
amqp_exchange_declare_ok_t *amqp_exchange_declare(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t exchange, amqp_bytes_t type, amqp_boolean_t passive, amqp_boolean_t durable, amqp_table_t arguments);
- 接口说明:声明queue
参数说明:state amqp connection
channel
queue queue name
passive
durable 队列是否持久化
exclusive 当前连接不在时,队列是否自动删除
aoto_delete 没有consumer时,队列是否自动删除
arguments 用于拓展参数,比如x-ha-policy用于mirrored queue
amqp_queue_declare_ok_t *amqp_queue_declare(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t queue, amqp_boolean_t passive, amqp_boolean_t durable, amqp_boolean_t exclusive, amqp_boolean_t auto_delete, amqp_table_t arguments);
- 接口说明:声明binding
amqp_queue_bind_ok_t *amqp_queue_bind(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t queue, amqp_bytes_t exchange, amqp_bytes_t routing_key, amqp_tab le_t arguments);
- 接口说明:qos是 quality of service,我们这里使用主要用于控制预取消息数,避免消息按条数均匀分配,需要和no_ack配合使用
参数说明:state
channel
prefetch_size 以bytes为单位,0为unlimited
prefetch_count 预取的消息条数
global
amqp_basic_qos_ok_t *amqp_basic_qos(amqp_connection_state_t state, amqp_channel_t channel, uint32_t prefetch_size, uint16_t prefetch_count, amqp_boolean_t global);
- 接口说明:开始一个queue consumer
参数说明:state
channel
queue
consumer_tag
no_local
no_ack 是否需要确认消息后再从队列中删除消息
exclusive
arguments
amqp_basic_consume_ok_t *amqp_basic_consume(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t queue, amqp_bytes_t consumer_tag, amqp_boolean_t no_local, amqp_boolean_t no_ack, amqp_boolean_t exclusive, amqp_table_t arguments);
- 接口说明:发布消息
参数说明:state
channel
exchange
routing_key 当exchange为默认“”时,此处填写queue_name,当exchange为direct,此处为binding_key
mandatory 参见参考文献2
immediate 同上
properties 更多属性,如何设置消息持久化,参见文后demo
body 消息体
int amqp_basic_publish(amqp_connection_state_t state,amqp_channel_t channel,amqp_bytes_t exchange,amqp_bytes_t routing_key,amqp_boolean_t mandatory,amqp_boolean_t immediate,struct amqp_basic_properties_t_ const *properties,amqp_bytes_t body);
amqp_rpc_reply_t amqp_channel_close(amqp_connection_state_t state,amqp_channel_t channel,int code);
amqp_rpc_reply_t amqp_connection_close(amqp_connection_state_t state,int code);
int amqp_destroy_connection(amqp_connection_state_t state);
如何consume消息,参见文后demo。
demo
https://github.com/liuhaobupt/rabbitmq_work_queues_demo-with-rabbit-c-client-lib
其中 rmq_new_task.c和rmq_worker.c对应于RabbitMQ tutorial里的work queues章节(http://www.rabbitmq.com/tutorials/tutorial-two-python.html),emit_log_direct.c和receive_logs_direct.c对应于RabbitMQ tutorial里的routing章节(http://www.rabbitmq.com/tutorials/tutorial-four-python.html),这两个demo覆盖了RabbitMQ的常用应用场景。
编译需要librabbitmq.a库,同时需要rabbitmq-c提供的几个头文件(amqp.h和amqp_framing.h)以及utils.c文件,这些在github project页面均可获得。
参考文献
RabbitMQ-C 客户端接口使用说明的更多相关文章
- [RabbitMQ]Java客户端:源码概览
本文简要介绍RabbitMQ提供的Java客户端中最基本的功能性接口/类及相关源码. Mavan依赖: <dependency> <groupId>com.rabbitmq&l ...
- cxf的使用及安全校验-02创建简单的客户端接口
上一篇文章中,我们已经讲了如果简单的创建一个webservice接口 http://www.cnblogs.com/snowstar123/p/3395568.html 现在我们创建一个简单客户端接口 ...
- Warensoft Stock Service Api客户端接口说明
Warensoft Stock Service Api客户端接口说明 Warensoft Stock Service Api Client Reference 可使用环境(Available Envi ...
- HBase新的客户端接口
最近学习接触HBase的东西,看了<Habase in Action>,但里面关于HBase接口都是过时的接口,以下为HBase新的客户端接口: package com.n10k; imp ...
- C#基于RabbitMQ实现客户端之间消息通讯实战演练
一.背景介绍和描述 MQ消息队列已经逐渐成为企业IT系统内部通信的核心手段.它具有低耦合.可靠投递.广播.流量控制.最终一致性等一系列功能,成为异步RPC的主要手段之一.何时需要消息队列?当你需要使用 ...
- RabbitMQ GUI客户端工具(RabbitMQ Assistant)
RabbitMQ GUI客户端工具(RabbitMQ Assistant) 平时用控制台或者网页进行管理不免有点不方便,尤其在读取消息的时候不支持过滤和批量发送消息,在此推荐一个漂亮的GUI客户端工具 ...
- 客户端接口AGENDA
日程 周二上午:完善客户端功能.接口定义. 周二下午:助教审查客户端代码.审查完成之后将发布接口定义. 提示 总之谢谢大家的支持.我们会尽量降低交互难度,让各位亲把精力专注于算法设计上面. 可以使用任 ...
- webService 客户端接口调用【java】
最近实际项目中使用到了WebService,简单总结下使用方式: 1.拿到接口:http://*******:8080/osms/services/OrderWebService?wsdl 我们可以将 ...
- CouchDB 简单HTTP接口使用说明
目录 1.简介 2.安装 2.HTTP接口简单使用 2.1.认证接口 2.1.1 Basic Authentication 2.1.2 Cookie Authentication 2.2 创建与删除数 ...
随机推荐
- Alice, Bob, Oranges and Apples CodeForces - 586E
E - Alice, Bob, Oranges and Apples CodeForces - 586E 自己想的时候模拟了一下各个结果 感觉是不是会跟橘子苹果之间的比例有什么关系 搜题解的时候发现了 ...
- 线程池和进程池的通用写法 ProcessPoolExecutor 和 ThreadPoolExecutor
import time from comcurrent.futures import ThreadPoolExecutor,ProcessPoolExccoutor#这个方法可以用进程池或者线程池 d ...
- IDEA2016.3搭建Struts2+Hibernate+Spring项目环境
IDEA搭建SSH环境 1.环境 软件版本:IntelliJ IDEA 2016.3.2 系统:windows 7 32位 / ubuntu 框架:Hibernate3,Spring3.2, Stru ...
- The Concept of a Process
COMPPUTER SCIENCE AN OVERVIEW 11th Edition One of the most fundamental concepts of modern operating ...
- Web终端SSH功能
http://www.laozuo.org/10703.html------ CentOS安装配置GateOne实现Web终端SSH功能
- 【JMeter】JMeter进行简单的数据库(mysql)压力测试
JMeter进行简单的数据库(mysql)压力测试 1.点击测试计划,再点击“浏览”,把JDBC驱动添加进来: 注:JDBC驱动一般的位置在java的安装地址下,路径类似于: \java\jre ...
- Spark Core(三)Executor上是如何launch task(转载)
1. 启动任务 在前面一篇博客中(Driver 启动.分配.调度Task)介绍了Driver是如何调动.启动任务的,Driver向Executor发送了LaunchTask的消息,Executor接收 ...
- opencv之颜色过滤只留下图片中的红色区域
如图,这次需要在图片中找到卷尺的红色刻度,所以需要对图像做过滤,只留下红色部分. 一开始的想法是分别找到RGB值,然后找到红色区域的部分保留就可以了,不过好像很难确定红色区域的RGB取值范围,所以要把 ...
- numpy的prod()函数和pad()函数
1.np.prod()函数用来计算所有元素的乘积,对于有多个维度的数组可以指定轴,如axis=1指定计算每一行的乘积. 2.np.lib.pad()函数用来把原来的list在原来的维度上进行扩展 例1 ...
- unittest之suite测试集(测试套件)
suite 这个表示测试集,不要放在class内,否则会提示"没有这样的测试方法在类里面 ",我觉得它唯一的好处就是调试的时候可以单独调试某个class而已,我一般不用它,调试时可 ...