Thanks In Advance!
I have Mqtt installed on Raspberry-Pi and publishing sensor data to mqtt on port 1883. Using Paho client published data is verified on receiver side.
Now i Have RabbitMQ installed on Windows7. How do i send data from mqtt to rabbitmq.
Graph graph = new OrientGraph("remote:localhost:2424/test", "username", "password");
String query = "select @rid ad base, inE('child').outV() as source from V where name='vertex3'";
OrientGraph oGraph = (OrientGraph)graph;
OCommandSQL oCommandSQL = new OCommandSQL(query);
Iterable<Vertex> vertices = oGraph.command(oCommandSQL).execute();
Iterator<Vertex> verticesIterator = vertices.iterator();
Vertex resultVertex = verticesIterator.next();
OrientElementIterable<Element> elements = resultVertex.getProperty("source");
Iterator<Element> elementIterator = elements.iterator();
Vertex sourceVertex = null;
while (elementIterator.hasNext()) {
sourceVertex = (Vertex) elementIterator.next();
}
Vertex v3 = graph.getVertex("#11:0");
Edge edge = graph.addEdge(null, v3, sourceVertex, "new");
graph.shutdown();
Mqtt Connection is made dafault without credentials. Now How can i send data to RabbitMQ.
答案 0 :(得分:1)
您所描述的是MQTT桥。您可以在pi上配置mosquitto实例以连接到RabbitMQ代理(假设它配置为支持MQTT)。
有关如何配置网桥的详细信息,请参见mosquitto.conf手册页here。
基本上,您需要在配置中添加以下内容。
connection rabbitmq
address ip-of-rabbitmq
cleansession true
topic # out 0
答案 1 :(得分:0)
通过从命令提示符运行命令在rabbitmq上启用mqtt插件 打开cmd的cmd提示路径到Rabbitmq / sbin,默认情况下是Windows中的C:\ Program Files \ RabbitMQ Server \ rabbitmq_server-3.6.9 \ sbin然后运行命令。
“rabbitmq-plugins启用rabbitmq_mqtt”
我们需要设置运行rabbitmq的服务器系统的Topic,url。 随机发送clientId。 将Qos设置为0 OR 1 OR 2
String topic = "amq.topic";
String brokerUrlRpi_Mqtt = "tcp://192.168.xxx.xxx:1883/";
String clientId=UUID.randomUUID().toString();
如果从不同的系统发送mqtt数据,用户名和密码应该是在rabbitmq中创建的新用户。 如果mqtt和rabbitmq在本地运行,那么访客用户名和密码就可以了。
`
public SendDataUsingMQTT() throws MqttException {
String tmpDir = System.getProperty("java.io.tmpdir");
// MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersistence(tmpDir);
try {
conOpt = new MqttConnectOptions();
conOpt.setUserName("username");
conOpt.setPassword(new String("password").toCharArray());
conOpt.setCleanSession(true);
client = new MqttClient(brokerUrlRpi_Mqtt,clientId, datastore);
client.setCallback(new MqttCallback() {
// add all anonymous implemented methods of connect
public void messageArrived(String arg0, MqttMessage arg1) throws Exception {
//
}
public void deliveryComplete(IMqttDeliveryToken arg0) { }
public void connectionLost(Throwable arg0) {}
}
catch (MqttException e) {
e.printStackTrace();
System.out.println("Unable to set up client: "+e.toString());
System.exit(1);
}
}