有人可以向我解释如何通过logstash触发芹菜任务?有可能吗?
如果我尝试通过" php-amqplib"库在PHP中执行此操作,则可以正常工作:(不使用logstash(
($connection = new AMQPStreamConnection(
'rabbitmq.local',
5672,
'guest',
'guest'
);
$channel = $connection->channel();
$channel->queue_declare(
'celery',
false,
true,
false,
false
);
$taskId = rand(1000, 10000);
$props = array(
'content_type' => 'application/json',
'content_encoding' => 'utf-8',
);
$body = array(
'task' => 'process_next_task',
'lang' => 'py',
'args' => array('ktest' => 'vtest'),
'kwargs' => array('ktest' => 'vtest'),
'origin' => '@'.'mytest',
'id' => $taskId,
);
$msg = new AMQPMessage(json_encode($body), $props);
$channel->basic_publish($msg, 'celery', 'celery');
根据芹菜文档:
http://docs.celeryproject.org/en/latest/internals/protocol.html
我正在尝试以JSON格式发送请求,这是我的LogStash滤镜:
ruby
{
remove_field => ['headers', '@timestamp', '@version', 'host', 'type']
code => "
event.set('properties',
{
:content_type => 'application/json',
:content_encoding => 'utf-8'
})
"
}
和芹菜的答案是:
[2017-05-05 14:35:09,090: WARNING/MainProcess] Received and deleted unknown message. Wrong destination?!
{content_type:None content_encoding:None delivery_info:{'exchange': 'celery', 'routing_key': 'celery', 'redelivered': False, 'consumer_tag': 'None4', 'delivery_tag': 66} headers={}}
基本上,芹菜无法解码我的消息格式或更好...我无法以JSON格式设置请求:(
这让我发疯,谢谢您的任何线索:(
忘记了,这是我在logstash中的输出插件
rabbitmq
{
key => "celery"
exchange => "celery"
exchange_type => "direct"
user => "${RABBITMQ_USER}"
password => "${RABBITMQ_PASSWORD}"
host => "${RABBITMQ_HOST}"
port => "${RABBITMQ_PORT}"
durable => true
persistent => true
codec => json
}
从这个问题中提供的信息,您不能。
当您在Ruby Filter中玩活动时,实际上您正在使用消息正文中的内容进行播放,而您想设置兔子标题和消息的属性。<<<<<<<<<<
直到解决了该功能,除非您自己实施,否则我认为您无法实现它。毕竟,该插件可在GitHub上找到。
现在是不可能的,但我已经为官方项目提出了拉动请求。https://github.com/logstash-plugins/logstash-unput-rabbitmq/pull/59
如果您正在寻找工作版本,请查看我的克隆:
https://github.com/usless-stuff/logstash-unput-rabbitmq
您应该严重害怕该代码:(
我完全遥不可及Ruby Developer
但有效:(