Configurable Resource - Design patterns
First of all bit of background.
We开发者_运维技巧 are developing an application which receives messages from n
number of sources
. The source
may be a messaging queue
, an FTP
location, a webservice
call to a particular service or any possible orchestration layer we can think of. I have been given a task to design and develop a module which will act as a configurable resource manager which will work in between the module which process the message and application which sends the message.
Could you please suggest any design patterns or any best practices I can use here. We would like to have flexibility of configuring this resources and changing the channels on the fly. Means if the message type A comes in queue today, tomorrow this may be a scheduled webservice call.
Any pointers in this regard would be appreciated.
For a good answer you should post more details, but it looks like you need strategy design pattern.
public interface SourceStrategy{
public Message getMessage();
}
public FtpLocation implements SourceStrategy{...}
public MessageQueue implements SourceStrategy{...}
public WebService implements SourceStrategy{...}
public class Application(){
SourceStrategy s;
public void setStrategy(SourceStrategy s){
this.strategy = s;
}
public void readMessage(){
Message m = this.s.getMessage();
}
}
精彩评论