我有连接代码:
$.ajax({
url: /*url to server file(.php/.aspx) pass value to database*/,
type: 'POST',
cache: false,
data: 'textboxvalue=' + /*value from your textbox. ex: $('#txtInput').val()*/,
success: function(res) {
/*If connect success and server work successfully, what you want to do here*/
},
error: function() {
alert("Connection error");
return;
}
});
但是我收到了错误:
ConnectionFactory factory = new ConnectionFactory();
factory.setUri(System.getenv("CLOUDAMQP_URL"));
我的兔子日志显示连接拒绝
23:16:24 web.1 | started with pid 3098
23:16:27 web.1 | Exception in thread "main" java.io.IOException
23:16:27 web.1 | at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:106)
23:16:27 web.1 | at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:102)
23:16:27 web.1 | at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:124)
23:16:27 web.1 | at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:378)
23:16:27 web.1 | at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:621)
23:16:27 web.1 | at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:648)
23:16:27 web.1 | at Main.run(Main.java:212)
23:16:27 web.1 | at Main.main(Main.java:239)
23:16:27 web.1 | Caused by: com.rabbitmq.client.ShutdownSignalException: connection error
23:16:27 web.1 | at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67)
23:16:27 web.1 | at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:33)
23:16:27 web.1 | at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:361)
23:16:27 web.1 | at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:226)
23:16:27 web.1 | at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:118)
23:16:27 web.1 | ... 5 more
23:16:27 web.1 | Caused by: java.net.SocketException: Connection reset
23:16:27 web.1 | at java.net.SocketInputStream.read(SocketInputStream.java:196)
23:16:27 web.1 | at java.net.SocketInputStream.read(SocketInputStream.java:122)
23:16:27 web.1 | at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
23:16:27 web.1 | at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
23:16:27 web.1 | at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:288)
23:16:27 web.1 | at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:95)
23:16:27 web.1 | at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:139)
23:16:27 web.1 | at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:536)
23:16:27 web.1 | at java.lang.Thread.run(Thread.java:745)
23:16:27 web.1 | exited with code 1
23:16:27 system | sending SIGTERM to all processes
如何使用setUri连接到默认vhost(/)?询问last time这个问题,提问者的解决方案是不使用setUri。什么是uri方式?
令人讨厌的是,同样的URI与pika一起工作;这两个实现(python和java)如何解析URI有什么不同?
编辑:我使用的网址是
=ERROR REPORT==== 21-Jul-2015::23:16:27 ===
closing AMQP connection <0.9858.0> (127.0.0.1:38856 -> 127.0.0.1:5672):
{handshake_error,opening,0,
{amqp_error,access_refused,
"access to vhost '' refused for user 'guest'",
'connection.open'}}
答案 0 :(得分:1)
看起来这与在the source中解析URI的方式不一致。特别是,URI在/ s上分割,然后是URL解码;这意味着我的URI(amqp://guest:guest@localhost:5672/
)返回vhost的空字符串(而不是我使用
factory.setUri(System.getenv("CLOUDAMQP_URL"));
factory.setVirtualHost("/");
覆盖推断的错误值,但这是不好的解决方案。另一个有效的解决方案是更改URL:
CLOUDAMQP_URL=amqp://guest:guest@localhost:5672/%2F
注意URLencoded / via %2F 。我将在库中打开一个问题/ PR,因为python解决方案似乎更直观。
编辑:我与图书馆维护人员进行了交谈。他们指出,他们是权威的实施,而且pika正在the spec之外做一些事情(见附录A)。令人遗憾的是,库存兔实现(使用&#34; /&#34;的vhost)与库存java rabbit mq客户端对默认URI的解释不兼容,但事实如此。使用%2F修复。