diff --git a/src/Kdyby/RabbitMq/DI/RabbitMqExtension.php b/src/Kdyby/RabbitMq/DI/RabbitMqExtension.php index 2a6cf5eb..8240421d 100644 --- a/src/Kdyby/RabbitMq/DI/RabbitMqExtension.php +++ b/src/Kdyby/RabbitMq/DI/RabbitMqExtension.php @@ -89,6 +89,7 @@ class RabbitMqExtension extends Nette\DI\CompilerExtension public $rpcClientDefaults = [ 'connection' => 'default', 'expectSerializedResponse' => TRUE, + 'contentType' => 'text/plain', ]; /** @@ -428,7 +429,7 @@ protected function loadRpcClients($clients) $builder->addDefinition($serviceName = $this->prefix('rpcClient.' . $name)) ->setClass('Kdyby\RabbitMq\RpcClient', ['@' . $this->connectionsMeta[$config['connection']]['serviceId']]) - ->addSetup('initClient', [$config['expectSerializedResponse']]) + ->addSetup('initClient', [$config['expectSerializedResponse'], $config['contentType']]) ->addTag(self::TAG_RPC_CLIENT) ->setAutowired(FALSE); diff --git a/src/Kdyby/RabbitMq/RpcClient.php b/src/Kdyby/RabbitMq/RpcClient.php index 88ff5edb..2a58595a 100644 --- a/src/Kdyby/RabbitMq/RpcClient.php +++ b/src/Kdyby/RabbitMq/RpcClient.php @@ -33,6 +33,11 @@ class RpcClient extends AmqpMember */ protected $expectSerializedResponse; + /** + * @var string + */ + protected $contentType; + /** * @var int */ @@ -40,7 +45,7 @@ class RpcClient extends AmqpMember - public function initClient($expectSerializedResponse = true) + public function initClient($expectSerializedResponse = true, $contentType = 'text/plain') { list($this->queueName,,) = $this->getChannel()->queue_declare( "", @@ -51,6 +56,7 @@ public function initClient($expectSerializedResponse = true) ); $this->expectSerializedResponse = $expectSerializedResponse; + $this->contentType = $contentType; } @@ -62,7 +68,7 @@ public function addRequest($msgBody, $server, $requestId = null, $routingKey = ' } $msg = new AMQPMessage($msgBody, [ - 'content_type' => 'text/plain', + 'content_type' => $this->contentType, 'reply_to' => $this->queueName, 'delivery_mode' => 1, // non durable 'expiration' => $expiration * 1000,