一般情況下,RabbitMQ的默認(rèn)配置就足夠了。如果希望特殊設(shè)置的話,有兩個途徑:
一個是環(huán)境變量的配置文件 rabbitmq-env.conf 花椭;
一個是配置信息的配置文件 rabbitmq.config;
注意房午,這兩個文件默認(rèn)是沒有的个从,如果需要必須自己創(chuàng)建。
根據(jù)需要支持的ip協(xié)議配置 rabbitmq.config,不同版本略有差異,參考:rabbitmq網(wǎng)絡(luò)配置
示例:
[
{rabbit, [
{tcp_listeners, [{"0.0.0.0", 8989},
{"::", 5672}]}
]}
].
驗證配置是否被讀取應(yīng)用:
- 查看/var/log/rabbitmq/下的rabbit@*.log文件嗦锐,是否成功加載了rabbitmq.config
=INFO REPORT==== 5-Jun-2018::21:48:06 ===
node : rabbit@ubuntu
home dir : /root
config file(s) : /etc/rabbitmq/rabbitmq.config #找不到則是not found 或 none
cookie hash : TFJHdEY4Q8wuZDZLdM/OEg==
log : /var/log/rabbitmq/rabbit@ubuntu.log
sasl log : /var/log/rabbitmq/rabbit@ubuntu-sasl.log
database dir : /var/lib/rabbitmq/mnesia/rabbit@ubuntu
- 使用rabbitmq-c下的amqp_listen和amqp_sendstring兩個程序通信
./examples/amqp_listen 2001:0:53aa:64c:341f:f9d6:730c:e4a9 5672 amq.direct test
./examples/amqp_sendstring 2001:0:53aa:64c:341f:f9d6:730c:e4a9 5672 amq.direct test "hello world"
- 使用SimpleAmqpClient庫驗證channel是否成功創(chuàng)建
#include <SimpleAmqpClient/SimpleAmqpClient.h>
#include <iostream>
#include <string>
using namespace std;
using namespace AmqpClient;
int main()
{
char* szBroker = getenv("AMQP_BROKER");
Channel::ptr_t channel;
if (szBroker != NULL)
{
channel = Channel::Create(szBroker);
}
else
{
//channel = Channel::Create("fe80::20c:29ff:fe13:6f4", 5672);
channel = Channel::Create("2001:0:53aa:64c:341f:f9d6:730c:e4a9", 5672);
//channel = Channel::Create("::1",5672);
//channel = Channel::Create("127.0.0.1",8989);
}
BasicMessage::ptr_t the_message = BasicMessage::Create("Body content");
try
{
channel->DeclareQueue("BasicReturnTestQueue");
channel->BasicConsume("BasicReturnTestQueue", "consumer_tag1");
channel->BasicPublish("", "BasicReturnTestQueue", the_message, true, false);
channel->BasicPublish("", "ThisDoesntExist", the_message, true, false);
}
catch (MessageReturnedException& e)
{
cout << "Message got returned: " << e.what();
cout << "\nMessage body: " << e.message()->Body();
}
return 0;
}
可以確認(rèn)在C/C++中rabbitmq對ipv6的支持方式可以是以上步驟。
以下關(guān)于ipv6地址的小坑記錄:
背景:
兩臺可以互相ping6通ipv6地址的虛擬機(jī)(CentOS沪曙、Ubuntu)奕污,地址分別為
fe80::20c:29ff:fe33:3dd4
和
fe80::20c:29ff:fe13:6f4
調(diào)用SimleAmqpClient,
hannel = Channel::Create("ip or hostname", "port");
根據(jù)是否拋出異常以及后續(xù)輸出判定rabbitmq對ipv6的支持
配置ipv6的支持后,代碼執(zhí)行環(huán)境Ubuntu:
參數(shù)為::1(ipv6環(huán)回地址)結(jié)果:ok
參數(shù)為fe80::20c:29ff:fe13:6f4 結(jié)果:faield
參數(shù)為fe80::20c:29ff:fe33:3dd4 結(jié)果:faield
后面往ubuntu添加了一個teredo隧道液走,得到一個ipv6的地址:2001:0:53aa:64c:341f:f9d6:730c:e4a9碳默,參數(shù)為此地址,ok
對于本地測試缘眶,發(fā)現(xiàn)可以不用雙棧嘱根、隧道等過度策略。
參考:https://blog.csdn.net/liuyu60305002/article/details/7821882