public static function send_message($qq, $options) { $connection = new \PhpAmqpLib\Connection\AMQPConnection(static::get_conf()->host, static::get_conf()->port, static::get_conf()->user, static::get_conf()->pasw); $channel = $connection->channel(); $channel->queue_declare($qq, false, true, false, false); $msg = new \PhpAmqpLib\Message\AMQPMessage(json_encode($options), array("content_type" => "json")); $channel->basic_publish($msg, '', $qq); $channel->close(); $connection->close(); }
<?php require_once __DIR__ . '/init.php'; use Rezzza\Jobflow\Extension; $amqpConnection = new \PhpAmqpLib\Connection\AMQPConnection('localhost', 5672, 'guest', 'guest', '/'); $amqpConnection->set_close_on_destruct(false); // Create RabbitMq Client $rmqClient = new Thumper\RpcClient($amqpConnection); $rmqClient->initClient(); // Add rabbitmq Extension $builder->addExtension(new Extension\RabbitMq\RabbitMqExtension($rmqClient)); $builder->addExtension(new Extension\Monolog\MonologExtension(new \Monolog\Logger('jobflow'))); // Creates job factory $jobflowFactory = $builder->getJobflowFactory(); // Create worker $server = new Thumper\RpcServer($amqpConnection); $server->initServer('jobflow'); $server->setCallback(new Extension\RabbitMq\JobWorker($jobflowFactory)); $server->start();
public function send($queueName, $data) { // establish connection to RabbitMQ $connection = new PhpAmqpLib\Connection\AMQPConnection($this->MQserver, $this->port, $this->username, $this->password); $channel = $connection->channel(); //function assumes queue exists $msg = new PhpAmqpLib\Message\AMQPMessage($data, array('delivery_mode' => 2)); $channel->basic_publish($msg, '', $queueName); KalturaLog::info("Message [{$data}] was sent to [{$queueName}]."); }