servicebus - REBUS Send message in Queue ,and receive in another application -
i want implement following scenario using rebus. creating on sender application , 1 receiving application. there class suppose
public class getpersonrequest { public int id { get; set; } public string name { get; set; } } public class getpersonresponse { public int id { get; set; } public string name { get; set; } }
i send class object in queue values. , want display value in receiver. how achieve this?
sender code this:
static void main(string[] args) { getpersonrequest objgetpersonrequest = new getpersonrequest(); objgetpersonrequest.id = 12; objgetpersonrequest.name = "kumar"; using (var activator = new builtinhandleractivator()) { activator.register(() => new printname()); var bus = configure.with(activator) .logging(l => l.none()) .transport(t => t.usemsmq("rebus-application.input")) .routing(r => r.typebased().map<getpersonrequest>("rebus.application.output")) .start(); bus.send(objgetpersonrequest); console.writeline("press enter quit"); console.readline(); }
receiver code in console application:
static void main(string[] args) { using (var activator = new builtinhandleractivator()) { activator.register(() => new printname()); var bus = configure.with(activator) .logging(l => l.none()) .transport(t => t.usemsmq("rebus-application.output")) .routing(r => r.typebased().map<getpersonresponse>("rebus-application.input")) .start(); console.writeline("press enter quit"); console.readline(); } } class printname : ihandlemessages<getpersonresponse> { public async task handle(getpersonresponse objgetpersonresponse) { console.writeline("rebusdetails name {0}", objgetpersonresponse.name); } }
how achieve this?
i suggest take @ the request/reply sample rebussamples repository - shows configuration needed in order proper request/reply.
from glancing on code, can see following issues/misunderstandings:
- rebus methods asynchronous, hence
bus.send(objgetpersonrequest)
execute on thread , not know if failed - eitherawait bus.send(...)
orbus.send(...).wait()
- in many cases, "clients" (*) should have endpoint mappings - in case, should map
getpersonrequest
(or possibly entire assembly containing it?)rebus.application.output
, ,await bus.reply(new getpersonresponse(...))
in handler - way, "server"(*) not have dependencies
moreover - might detail, think leads better understanding , easier communication on time:
- there's no such thing "output queue" - queues input queue of endpoint has input queue - therefore, argue name
rebus-application.output
misleading - i suggest change queue names identifies each endpoint better, e.g. since server seems capable of returning person's details, call
masterdata
,crm
, etc., possibly suffixing.input
if e.g. want have error queue each endpoint (e.g.masterdata.input
,masterdata.error
).
i hope makes sense :)
(*) in experience, it's beneficial have pretty clear distinction between client , server roles endpoints, clients endpoints no (or few) afferent couplings, allows them added/removed/changed, , servers endpoints more afferent couplings.
when await bus.reply(...)
server, allows sender remain client , not have endpoint address configured anywhere in own configuration.
Comments
Post a Comment