我知道之前有人问过这个问题,但我找不到任何合适的解决方案来解决我的问题,因此再次发布。
我正在尝试使用 spring-amqp 编写一个 rabbitmq 生产者,以在直接队列上发布我的消息。由于它是生产者应用程序,因此必须创建我的交换和队列。此外,我没有定义任何侦听器 bean,因为我在生产者端不需要它。下面是我的rabbitmq-config.xml:
<?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>
Run Code Online (Sandbox Code Playgroud)
我只有一个简单的生产者类,它使用上面的 …
如果函数Foo()将所有权转移std::unique_ptr到函数Bar()并且说Bar()抛出异常,则包含的对象std::unique_ptr将被销毁.
Foo()在这种情况下,如何处理可能希望保留所有权的案例.
class A
{
public:
std::unique_ptr<SomeData> getSomeData(...);
};
class B
{
public:
pushToQ(std::unique_ptr<SomeData>);
doSomething()
...
popFromQ();
...
};
Run Code Online (Sandbox Code Playgroud)
现在,如果B::pushToQ()抛出,QueueFullException我将丢失getSomeData()我可能不想要的数据.