简体   繁体   English

Rabbitmq异步生产者脚本

[英]Rabbitmq asynchronous producer script

RabbitMQ newbie here, I hope you can help me solve a problem: RabbitMQ新手在这里,希望您能帮助我解决问题:

I have a third-party program which I want use as a "producer" for RabbitMQ. 我有一个第三方程序,想用作RabbitMQ的“生产者”。 It generates a lot of log messages, and can only send them out by triggering a shell script. 它会生成很多日志消息,并且只能通过触发Shell脚本将其发送出去。

I can write a shell script using python and pika, but AFAI understand, that will create a new connection for every single message sent to the RabbitMQ server. 我可以使用python和pika编写shell脚本,但是AFAI理解,它将为发送到RabbitMQ服务器的每条消息创建一个新的连接。 That seems like a bad idea--the reason I'm switching to RabbitMQ in the first place was because my previous solution (wget posts) wasn't fast enough to keep up with the outflow of logs. 这似乎是一个坏主意-我之所以转用RabbitMQ的原因是因为我以前的解决方案(wget帖子)不够快,无法跟上日志的流出。

I'm sure there's a right way to do this, but I can't figure it out. 我敢肯定有正确的方法可以做到这一点,但我无法弄清楚。 I have to call the script every time I have a log to send--I don't know how to persist the connection, or if I'm even thinking in the right direction. 每当我有日志要发送时,我都必须调用脚本-我不知道如何保持连接,或者我是否还在朝着正确的方向思考。

Thanks in advance. 提前致谢。

You can use same connection for multiple operations. 您可以将同一连接用于多项操作。 Normally we reuse it. 通常我们会重用它。

But if script called to send every message than yupp, it will create (and close) new connection every time, which is huge overhead. 但是,如果调用脚本以发送除yupp之外的所有消息,它将每次都创建(并关闭)新的连接,这是巨大的开销。 So some daemon script which establish connection and wait on local port for messages to proxy to rabbitmq may come in handy. 因此,一些建立连接并在本地端口上等待消息以代理到Rabbitmq的守护程序脚本可能会派上用场。

Alternatively, maybe some kind of logstash-forwarder can solve your problem? 或者,也许某种logstash转发器可以解决您的问题?

Also, give RabbitMQ Python examples closer look if you new to it and have not seeing it yet. 另外,如果您还不熟悉RabbitMQ Python示例,请仔细看一下。

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

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