AMQPNETLITE - ActiveMQ Artemis (Red Hat AMQ) - 自动创建多消费者多播队列
AMQPNETLITE - ActiveMQ Artemis (Red Hat AMQ) - autocreate multi-consumer multicast queue
这个问题是关于在 .Net 中使用 AMQP 消费消息的。文档推荐amqpnetlite:https://access.redhat.com/documentation/en-us/red_hat_amq/7.0/html-single/using_the_amq_.net_client/index
使用 AMQPNetLite 订阅地址时,将自动创建地址和队列。不过,自动创建的队列始终是 "unicast"。我无法自动创建
- 多播队列
- 允许任意数量的消费者。
代码:
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;
}
也许我遗漏了一些标志?
在 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
代理的 multicastPrefix
和 anycastPrefix
功能未针对 AMQP 实现。 https://issues.jboss.org/browse/ENTMQBR-795
这个问题是关于在 .Net 中使用 AMQP 消费消息的。文档推荐amqpnetlite:https://access.redhat.com/documentation/en-us/red_hat_amq/7.0/html-single/using_the_amq_.net_client/index
使用 AMQPNetLite 订阅地址时,将自动创建地址和队列。不过,自动创建的队列始终是 "unicast"。我无法自动创建
- 多播队列
- 允许任意数量的消费者。
代码:
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;
}
也许我遗漏了一些标志?
在 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
代理的 multicastPrefix
和 anycastPrefix
功能未针对 AMQP 实现。 https://issues.jboss.org/browse/ENTMQBR-795