RabbitMQ,CloudFoundry和外部发件人 [英] RabbitMQ, CloudFoundry, and an External Sender
问题描述
所以现在我在Cloud Foundry上玩RabbitMQ。我只是使用基础知识并尝试掌握所有内容。
So right now I am messing around with RabbitMQ on cloud foundry. Im just working with the basics and trying to get a handle on it all.
我在我的Cloud Foundry实例上部署了RabbitMQ客户端,并且正在运行spring应用程序,并且可以在云中发送和接收消息。
I have the RabbitMQ client deployed on my cloud foundry instance and I have a spring application running and I can send and receive within the cloud.
示例我一字不漏是这里
现在,我希望从外部应用程序发送到云。我想我可能很难理解这个概念。
Now I am looking to send to the cloud from an exterior application. I think I might be having a hard time grasping this concept.
我试图做的是也使用示例程序创建的消息队列来推送消息。 (我认为这是我的误解)。
What I was trying to do is use the 'messages' queue created by the example program to push messages too. ( I think this is my misunderstanding).
我可以直接向客户端发送消息吗,还是必须将中间人接收器绑定到客户端?
Can I send messages straight to the client or do I have to have a middle man receiver bined to the client?
这就是我试图测试连接并发送消息的方式,但是我得到了java.lang.IllegalArgumentException:URI不是绝对的。
This was how I was trying to test the connection and send a message but I get a java.lang.IllegalArgumentException: URI is not absolute.
用户名,密码,虚拟主机和其他信息直接从客户端本身获取。
The username, password, virtual host, and other information was taken straight from the client itself.
public void testConnection() throws java.io.IOException {
ConnectionFactory factory = new ConnectionFactory();
factory.setUsername("xxxxxxx");
factory.setPassword("xxxxxxxxxxxx");
factory.setVirtualHost("xxxxxxxxxxxx");
factory.setHost("xx.xx.xxx.xx");
factory.setPort(xxxx);
Connection conn = factory.newConnection();
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
String message = "Hello From The Outside!!!";
channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
System.out.println(" [x] Sent '" + message + "'");
channel.close();
conn.close();
我在这里错过了什么主意?发送方,接收方(也许是我所缺少的),客户端来进行排队(这是我现在要结束的地方)
What idea am I missing here? Sender, receiver(maybe what im missing), Client to do the queueing (and this is where I want to end for now)
推荐答案
我在云铸造厂上尝试过RabbitMQ,我没有遵循示例。
I tried RabbitMQ on cloud foundry, I didn't follow the example.
我创建Rabbitmq实例:
I create the Rabbitmq Instance:
然后我打开RabbitMQ管理控制台:
Then I opened the RabbitMQ management console:
我复制了Rabbitmq URL:
I copied the Rabbitmq URL:
我以这种方式使用了您的代码:
And I used your code in this way:
public static void main(String[] args) throws Exception,URISyntaxException {
ConnectionFactory factory = new ConnectionFactory();
factory.setUri("amqp://kobqwlov:GANqOND_L4bxqEwqNSQA5BNqGt-X2NqM@lemur.cloudamqp.com/kobqwlov");
Connection conn = factory.newConnection();
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare("QUEUE_NAME", false, false, false, null);
String message = "Hello From The Outside!!!";
channel.basicPublish("", "QUEUE_NAME", null, message.getBytes());
System.out.println(" [x] Sent '" + message + "'");
channel.close();
conn.close();
}
该示例正确运行。
希望有帮助。
这篇关于RabbitMQ,CloudFoundry和外部发件人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!