B
B
borodka_lenina2015-11-24 14:29:21
linux
borodka_lenina, 2015-11-24 14:29:21

How to post many posts in rabbitmq?

Hello. It is necessary to publish a message of the form in the 'queue_example' queue:
{ ID : $number}
More precisely, it is necessary to publish several hundred such messages, and in each the $number variable will be unique.
What is the easiest and fastest way to do this?
Ps I know that I could figure it out myself, but I need to quickly find a solution and there is simply no time to delve into (

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2015-11-24
@rostel

slightly edit the Perl example
, removing all "$ch->consume...", call publish in a loop.
found on puff using php-amqp :

<?php
    $connection = new AMQPConnection(['host'=> '127.0.0.1', 'port' => '5672', 'login' => '', 'password' => '', 'vhost' => 'ejebberd', 'connect_timeout' => 10]);
    $connection->connect();
    $channel = new AMQPChannel($connection);

    $exchangename = IPhonParameters::$rabbit_EXCHANGE;
    $queue = 'ejabberd';
    $routing_key = 'ejabberd';

    $exchange = new AMQPExchange($channel);
    $exchange->setName($exchangename);
    $exchange->setType(AMQP_EX_TYPE_DIRECT);
    $exchange->setFlags(AMQP_DURABLE);
    $exchange->declareExchange();

    $q = new AMQPQueue($channel);
    $q->setName($queue);
    $q->setFlags(AMQP_DURABLE);
    $q->declareQueue();
    $q->bind($exchangename, $routing_key);

    for ($i = 1001; $i < 3001 ; $i++) {
        $aaa = sprintf('%04d', $i);
        $a_body = [
            'server' => 'default'
            , 'domain' => 'test.com'
            , 'action' => 'add'
            , 'login' => 'test'.$aaa
            , 'password' => 'test'.$aaa
        ];
        $msg_body = json_encode($a_body, JSON_UNESCAPED_UNICODE);
        $exchange->publish($msg_body, $routing_key, AMQP_NOPARAM, ['content_type' => 'text/javascript', 'delivery_mode' => 2]);
    }

    $connection->disconnect();
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question