EasyNetQ
EasyNetQ copied to clipboard
rabbitmq restart and clean when using rpc
1 docker run rabbitmq 2 rpc respond like this:
var bus = RabbitHutch.CreateBus("host=localhost");
bus.RespondAsync<string, string>(req => { Console.WriteLine(req); return Task.FromResult(req); }, c=>c.WithQueueName("test"));
3 rpc request like this:
var bus = RabbitHutch.CreateBus("host=localhost");
while (true)
{
var req = Console.ReadLine();
try
{
var rep = bus.Request<string, string>(req, c => c.WithQueueName("test"));
Console.WriteLine("{0}", rep);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
4 docker stop rabbitmq & docker rm rabbitmq & docker run rabbitmq
5 rpc request catch exception: no exchange easy_net_q_rpc
At last I try to fix in respond project like this:
class Program
{
static IBus bus;
static void Main(string[] args)
{
bus = RabbitHutch.CreateBus("host=localhost");
try
{
bus.Advanced.Connected += Advanced_Connected;
bus.Advanced.Disconnected += Advanced_Disconnected;
var idispose = bus.RespondAsync<string, string>(req => { Console.WriteLine(req); return Task.FromResult(req); }, c=>c.WithQueueName("test"));
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
Console.ReadLine();
}
private static void Advanced_Connected(object sender, EventArgs e)
{
var exchange = bus.Advanced.ExchangeDeclare("easy_net_q_rpc", "direct");
var queue = bus.Advanced.QueueDeclare("test");
bus.Advanced.Bind(exchange, queue, "test");
}
private static void Advanced_Disconnected(object sender, EventArgs e)
{
Console.WriteLine("{0} disconnected", DateTime.Now);
}
}
Then even though rabbitmq redeploy in k8s, I could still use rpc as usual. But maybe easynetq can do this?