2016-07-26 2 views
0

basic_publishでファンアウト経由でアレイを送信するにはどうすればよいですか?RabbitMQでファンアウトアレイを公開

// $this->message is the array to send 
$props = array('content_type' => 'application/json'); 
$msg = new AMQPMessage($this->message, $props); 

$channel->basic_publish($msg, $this->fanoutName); 

そして、私はこのエラーを取得:

私はこれをやっている私は多くのことを検索

ErrorException in AMQPChannel.php line 1098: mb_strlen() expects parameter 1 to be string, array given

を、私は、文字列の代わりに配列を送信する方法を見つけることができません。

+0

を使用してJSONに配列を変換しますか?どのようにして与えられた配列のメッセージを定式化することになっていますか? – FirstOne

+0

@FirstOne配列が別の関数から受け取られている場合、配列の内容は次のようになります: '$ this-> message = array( 'a' => 'b');' – pableiros

+0

そして、メッセージを配列に基づいてどのように定式化する必要がありますか?つまり、配列に与えられた予想されるメッセージは何ですか? **編集:**これらの情報を質問に入れてください(回答を得る確率が高くなる可能性があります) – FirstOne

答えて

0

は `ます$ this-> message`でのための一例であるものjson_encode

http://www.dyn-web.com/tutorials/php-js/json/array.php


// $this->message is the array to send 
$props = array('content_type' => 'application/json'); 

// convert the array to json 
$data = json_encode($this->message); 

// send the resulting json data 
$msg = new AMQPMessage($data, $props); 

$channel->basic_publish($msg, $this->fanoutName); 
関連する問題