此问题是关于使用.Net中的AMQP消耗消息的。该文档建议使用amqpnetlite:https://access.redhat.com/documentation/en-us/red_hat_amq/7.0/html-single/using_the_amq_.net_client/index
使用AMQPNetLite订阅地址时,将自动创建地址和队列。但是,自动创建的队列始终是“单播”的。我无法自动创建
代码:
private async Task RenewSession()
{
Connect = await Connection.Factory.CreateAsync(new Address("amqp://admin:admin@localhost:5672"), new Open() {ContainerId = "client-1"});
MqSession = new Session(Connect);
var receiver = new ReceiverLink(MqSession, DEFAULT_SUBSCRIPTION_NAME, GetSource("test-topic"), null);
receiver.Start(100, OnMessage);
}
private Source GetSource(string address)
{
var source = new Source
{
Address = address,
ExpiryPolicy = new Symbol("never"),
Durable = 2,
DefaultOutcome = new Modified
{
DeliveryFailed = true,
UndeliverableHere = false
}
};
return source;
}
也许我缺少一些标志?
答案 0 :(得分:2)
在AMQP中,您可以通过设置功能来自动创建队列(任意播路由)或主题(组播路由)。
该功能应为new Symbol("queue")
或new Symbol("topic")
。
public class SimpleAmqpTest
{
[Fact]
public async Task TestHelloWorld()
{
Address address = new Address("amqp://guest:guest@localhost:5672");
Connection connection = await Connection.Factory.CreateAsync(address);
Session session = new Session(connection);
Message message = new Message("Hello AMQP");
Target target = new Target
{
Address = "q1",
Capabilities = new Symbol[] { new Symbol("queue") }
};
SenderLink sender = new SenderLink(session, "sender-link", target, null);
await sender.SendAsync(message);
Source source = new Source
{
Address = "q1",
Capabilities = new Symbol[] { new Symbol("queue") }
};
ReceiverLink receiver = new ReceiverLink(session, "receiver-link", source, null);
message = await receiver.ReceiveAsync();
receiver.Accept(message);
await sender.CloseAsync();
await receiver.CloseAsync();
await session.CloseAsync();
await connection.CloseAsync();
}
}
看看代码来自哪里的https://github.com/Azure/amqpnetlite/issues/286。
您可以通过在broker.xml中设置default-address-routing-type
来选择默认路由是多播还是任意广播,所有内容记录在https://activemq.apache.org/artemis/docs/2.6.0/address-model.html
未为AMQP实施经纪人的multicastPrefix
和anycastPrefix
功能。 https://issues.jboss.org/browse/ENTMQBR-795