我知道这个问题以前有人问过,但我找不到任何合适的解决办法,因此再次张贴。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xsi:schemaLocation="http://www.springframework.org/schema/rabbit
http://www.springframework.org/schema/rabbit/spring-rabbit-1.5.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- Spring AMQP Admin -->
<rabbit:admin id="amqpAdmin"
connection-factory="rabbitmqConnectionFactory"
auto-startup="true" />
<!-- Spring AMQP Template -->
<rabbit:template id="amqpTemplate"
connection-factory="rabbitmqConnectionFactory"
routing-key="my.key" exchange="my.exchange"
channel-transacted="true"/>
<!-- Connection Factory -->
<rabbit:connection-factory id="rabbitmqConnectionFactory"
host="${rabbitmq.host:localhost}"
port="${rabbitmq.port:5672}"
username="${rabbitmq.username}"
password="${rabbitmq.password}"
virtual-host="${rabbitmq.vhost:/}"
cache-mode="CONNECTION"
channel-cache-size="${rabbitmq.channel-cache-size:25}" />
<!-- Queue and Exchange -->
<rabbit:queue id="my.queue" durable="false"
auto-declare="true" auto-delete="true" />
<rabbit:direct-exchange name="my.exchange" durable="false"
auto-declare="true" auto-delete="true" declared-by="amqpAdmin">
<rabbit:bindings>
<rabbit:binding queue="my.queue" key="my.key"/>
</rabbit:bindings>
</rabbit:direct-exchange>
</beans>
我只有一个简单的producer类,它使用上面的amqpTemplate发送一条消息。但当我尝试运行我的生产者应用程序时,我得到的只是:在vhost“/”错误中没有exchange“my.exchange”
ERROR CachingConnectionFactory:1089 - Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'my.exchange' in vhost '/', class-id=60, method-id=40)
DEBUG CachingConnectionFactory:842 - Detected closed channel on exception. Re-initializing: AMQChannel(amqp://s3conn@127.0.0.1:5672/,1)
DEBUG RabbitResourceHolder:189 - Rolling back messages to channel: Cached Rabbit Channel: AMQChannel(amqp://s3conn@127.0.0.1:5672/,1), conn: Proxy@17a7f733 Dedicated Rabbit Connection: SimpleConnection@2118cddf [delegate=amqp://s3conn@127.0.0.1:5672/]
TRACE CachingConnectionFactory:906 - Returning cached Channel: AMQChannel(amqp://s3conn@127.0.0.1:5672/,1)
Exception in thread "main"
DEBUG CachingConnectionFactory:1008 - Returning connection 'Proxy@17a7f733 Dedicated Rabbit Connection: SimpleConnection@2118cddf [delegate=amqp://s3conn@127.0.0.1:5672/]' to cache
org.springframework.amqp.AmqpIOException: java.io.IOException
at org.springframework.amqp.rabbit.connection.RabbitUtils.commitIfNecessary(RabbitUtils.java:105)
at org.springframework.amqp.rabbit.core.RabbitTemplate.doSend(RabbitTemplate.java:1354)
at org.springframework.amqp.rabbit.core.RabbitTemplate$3.doInRabbit(RabbitTemplate.java:623)
at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1298)
at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1271)
at org.springframework.amqp.rabbit.core.RabbitTemplate.send(RabbitTemplate.java:619)
at org.springframework.amqp.rabbit.core.RabbitTemplate.send(RabbitTemplate.java:613)
at org.springframework.amqp.rabbit.core.RabbitTemplate.send(RabbitTemplate.java:603)
at com.symantec.spe.cloud.amqpclient.JsonMessagePublisherImpl.sendMessage(JsonMessagePublisherImpl.java:53)
at com.symantec.spe.cloud.amqpclient.test.TestProducer.main(TestProducer.java:50)
Caused by: java.io.IOException
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:106)
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:102)
at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:124)
at com.rabbitmq.client.impl.ChannelN.txCommit(ChannelN.java:1163)
at com.rabbitmq.client.impl.ChannelN.txCommit(ChannelN.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$CachedChannelInvocationHandler.invoke(CachingConnectionFactory.java:835)
at com.sun.proxy.$Proxy7.txCommit(Unknown Source)
at org.springframework.amqp.rabbit.connection.RabbitUtils.commitIfNecessary(RabbitUtils.java:103)
... 9 more
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchang
e 'my.exchange' in vhost '/', class-id=60, method-id=40)
at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67)
at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:33)
at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:361)
at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:226)
at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:118)
... 18 more
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchang
e 'my.exchange' in vhost '/', class-id=60, method-id=40)
at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:484)
at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:321)
at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:144)
at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:91)
at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:554)
at java.lang.Thread.run(Unknown Source)
如果你能在这方面提供帮助,我将不胜感激。多谢了。
你的问题是:
cache-mode="CONNECTION"
参见参考手册:
只有当CachingConnectionFactory
缓存模式为Channel
(默认值)时,才会执行自动声明。存在此限制是因为exlusive和auto-delete队列绑定到连接。
(哎呀!有错别字。很快就会修复:-))
我写一个简单的Rabbitmq生产者与Spring启动2.2.7。 在代理端,我设置了一个直接交换示例,一个名为samples的队列。默认值,并将它们绑定在一起添加示例。默认绑定键。 运行应用程序时,我得到以下错误 rabbitmq服务器配置是正确的,因为我有一个python生产者已经成功地将消息放入“samples.default”队列。 在SpringBoot中,我使用了jackson序列化,
Install $ npm install vhost API var vhost = require('vhost') vhost(hostname, handle) Create a new middleware function to hand off request to handle when the incoming host for the request matches h
这里Java初学者, 我试图用Spring定义我的模型来访问Mongodb数据库中的数据。 我想将性别定义为一个枚举,在数据库中,值存储为字符串:或 但我得到以下错误: 这是我的图POJO: 这是我的性别枚举: 这就是我尝试访问它的方式: @Override public void run(String…args)抛出异常{Optional chronos=figureposition.findB
我正在尝试使用Spring MVC从我的Web服务发出ajax请求: 使用此AJAX请求: 这里的问题是用户正在登录但没有正确的权限,真正的isu是我没有使用Spring Security,那么如何阻止权限,这是我对Spring Boot的配置: spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
我试图通过exchange方法用Spring RestTemplate做一个带有主体的HTTP删除请求,但我总是收到一个400个错误的请求,就像这个问题一样。使用JavaScript和其他工具,可以使用delete调用这个API。我知道java<1.8确实支持DELETE with body,但在1.8中应该可以:参见此处。我使用的是带有jdk 1.8的Spring-Web-4.2.6.Relea
我必须将一个文件从一个java类发送到一个Spring rest web服务。用例:从客户端,这可以选择服务器、服务器上的文件以及保存文件的位置。在服务器上,我必须检索文件(从客户机选择)并发送到客户机。目前我使用字节数组,但当文件超过50MB时,我会收到堆异常,而我将从web页面发送到控制器,即使文件超过500MB,我也使用相同的方法。在客户端,我使用这个spring方法: 这是服务器上的异常