简体   繁体   English

Qpid Erlang模块

[英]Qpid Erlang Module

I am newbie to erlang but managed to get the ActiveMQ talking to my erlang shell using qpid pronton c library as, which is working well and i am getting messages from queue itself on my erlang shell and vice versa. 我是erlang的新手,但是设法使用qpid pronton c库使ActiveMQ与我的erlang Shell进行通信,该库运行良好,并且我从erlang Shell上的队列本身获取消息,反之亦然。

qpidpn:subscribe("amqp://localhost/topic://xxx").
qpidpn:publish(#{address => "amqp://127.0.0.1/topic://xxx", body => "hello"}).

Now, i want to implement the same above stated code using .erl file with some function getting invoked everytime we have new message on the queue and i can take further action of returning the same to origin. 现在,我想使用.erl文件实现与上面所述相同的代码,每次我们在队列上有新消息时都会调用某些函数,并且我可以采取进一步的措施将其返回到原始位置。

You can implement gen_server, as seems the messages are coming from some MQ. 您可以实现gen_server,好像消息来自某些MQ。 So, you can get the messages in handle_info. 因此,您可以在handle_info中获取消息。 Once there you can do whatever you want to do with them. 到达那里后,您可以对它们进行任何处理。

Well, it all depends on how your subscriber is implemented (is it another process, TCP listener, do you use gen_event behaviour, does it decode any data for you .... ). 好吧,这全取决于您的订户的实现方式(这是另一个进程,TCP侦听器,您是否使用gen_event行为,是否为您解码了任何数据...。)。

Since you are using AMQP protocol for communication, you could use RabbitMQ as client. 由于您使用AMQP协议进行通信,因此可以使用RabbitMQ作为客户端。 You would get whole AMQP implementation (with all responses to your broker), and some model for getting messages or subscribing to channels. 您将获得整个AMQP实施(带有对代理的所有响应),以及一些用于获取消息或订阅频道的模型。 Code-base is mature, whole project is stable, and most of logic is written for you, so I would strongly recommend using this approach. 代码库很成熟,整个项目都很稳定,并且大多数逻辑都是为您编写的,因此,我强烈建议您使用这种方法。

The "invoked everytime we have new message on the queue" is somewhat explained in subscibe to que section. “被调用每次我们对队列中的新邮件”中有所解释所有本阙部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM