Created
August 8, 2019 15:24
-
-
Save phatboyg/eff85c26d5da1f4f56b6f729847dd3ad to your computer and use it in GitHub Desktop.
Sample Channel Usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using MassTransit; | |
namespace ChannelUsage | |
{ | |
class Program | |
{ | |
static IBusControl _serverBus; | |
public static async Task Main() | |
{ | |
_serverBus = Bus.Factory.CreateUsingRabbitMq(c => | |
{ | |
var host = c.Host("localhost", "/"); | |
c.ReceiveEndpoint(host, "channel_test", ep => { ep.Handler<Message>(cx => cx.RespondAsync(new Response())); }); | |
}); | |
await _serverBus.StartAsync(); | |
try | |
{ | |
bool keepGoing = true; | |
Task.Run(() => | |
{ | |
Console.Write("Press enter to exist"); | |
Console.ReadLine(); | |
keepGoing = false; | |
}); | |
int index = 0; | |
while (keepGoing) | |
{ | |
await Task.Delay(100); | |
Console.WriteLine("Request {0}", ++index); | |
var client = Bus.Factory.CreateUsingRabbitMq(c => | |
{ | |
var host = c.Host("localhost", "/"); | |
}); | |
await client.StartAsync(); | |
try | |
{ | |
var request = client.CreatePublishRequestClient<Message, Response>(TimeSpan.FromSeconds(30)); | |
await request.Request(new Message()); | |
} | |
finally | |
{ | |
await client.StopAsync(); | |
} | |
} | |
} | |
finally | |
{ | |
await _serverBus.StopAsync(); | |
} | |
} | |
} | |
class Message | |
{ | |
} | |
class Response | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment