Abstracting out existence of service bus/distributed messaging?
I'm working on a system right now that is in a single process space; we are breaking this up into several processes, initially to run on the same box but ultimately to distribute across several separate machines. I'm leaning towards using an ESB (NServiceBus, Rhino ESB) or possibly rolling my own with开发者_运维技巧 WCF + queues to handle the pub/sub and request/response scenarios our app has.
However, I'm struggling with the abstraction: I don't want the various components to know they are talking over the bus. The current APIs connecting the various services translate pretty well to this kind of model, but I want to hide that from the client and server sides. Short of writing a lot of custom proxy code for the client and server, is there a better way to approach this? I realize WCF can auto-generate proxies based on the service definition, but I really like some of the other stuff I get with (say) rhino servicebus.
Ideally, I'd like to be able to swap out different implementations (with and without an ESB/messaging layer) just using IoC (knowing there would have to be limits enforced by convention on what can be passed across the interfaces), but I'm not sure where to go with that. I'd really prefer to not have to change every method call on the current interfaces into its own discrete message class, either.
Any resources/patterns/tools to help me do this? Please ask questions if I'm not clear. Thanks.
There may not be one solution/off-the-shelf component that might help you.
Problem 1:
The basic problem can be solved via an ESB, as it provides location transparency and service aggregation. A regular ESB mediates/brokers requests between service consumer and service provider.
Take a simple example:
Service_A depends on Service_B Service_C depends on Service_B Service_B depends on Service_D
In this scenario, the best way to progress is this:
- Define contracts exposed by
Service_B
andService_D
as external dependencies (possibly as a web service, though an ESB supports multiple protocols) in servicesService_A
,Service_C
andService_B
, and consume via an ESB. - In ESB, to start with, route thes services
Service_B
andService_D
on the same instance. - If you migrate
Service_D
andService_B
asService_Dx
andService_Bx
on a different location, the ESB can be reconfigured to route to the new location. Also, an ESB can be configured to route toService_B
orService_Bx
based on some set of parameters (eg., test data toService_B
and production data toService_Bx
)
Problem 2:
The problem of IOC could probably be hard to achieve; there may not be a need.
I presume the clients, instead of consuming from a known location, are injected with the whereabouts of service location. This in reality transfers the configuration to client side. With this, for every new client added to the system there needs to be a separate configuration control. This might lead to logistical issues.
Please post your final solution, very interested to know your approach.
精彩评论