public class MessageBusMessagingFactory extends java.lang.Object implements IMessagingSystemFactory
public class Program { public static void main(String[] args) throws Exception { // Message Bus will use TCP for the communication. IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
// Input channel to listen to services. IDuplexInputChannel aServiceInputChannel = aMessaging.createDuplexInputChannel("tcp://127.0.0.1:8045/");
// Input channel to listen to clients. IDuplexInputChannel aClientInputChannel = aMessaging.createDuplexInputChannel("tcp://127.0.0.1:8046/");
// Create the message bus. IMessageBus aMessageBus = new MessageBusFactory().createMessageBus();
// Attach channels to the message bus and start listening. aMessageBus.attachDuplexInputChannels(aServiceInputChannel, aClientInputChannel);
System.out.println("Message bus service is running. Press ENTER to stop."); new BufferedReader(new InputStreamReader(System.in)).readLine();
// Detach channels and stop listening. aMessageBus.detachDuplexInputChannels(); } }
public interface IEcho { String hello(String text); }
....
// Simple echo service. class EchoService implements IEcho { @Override public String hello(String text) { return text; }
}
....
public class Program { public static void main(String[] args) throws Exception { // The service will communicate via Message Bus which is listening via TCP. IMessagingSystemFactory aMessageBusUnderlyingMessaging = new TcpMessagingSystemFactory(); // note: only TCP/IP address which is exposed for services is needed. IMessagingSystemFactory aMessaging = new MessageBusMessagingFactory("tcp://127.0.0.1:8045/", null, aMessageBusUnderlyingMessaging);
// Create input channel listening via the message bus. // Note: this is address of the service inside the message bus. IDuplexInputChannel anInputChannel = aMessaging.createDuplexInputChannel("Eneter.Echo");
// Instantiate class implementing the service. IEcho anEcho = new EchoService();
// Create the RPC service. IRpcService<IEcho> anEchoService = new RpcFactory().createService(anEcho, IEcho.class);
// Attach input channel to the service and start listening via the message bus. anEchoService.attachDuplexInputChannel(anInputChannel);
System.out.println("Echo service is running. Press ENTER to stop."); new BufferedReader(new InputStreamReader(System.in)).readLine();
// Detach the input channel and stop listening. anEchoService.detachDuplexInputChannel(); } }
public class Program { public static void main(String[] args) throws Exception { // The client will communicate via Message Bus which is listening via TCP. IMessagingSystemFactory aMessageBusUnderlyingMessaging = new TcpMessagingSystemFactory(); // note: only TCP/IP address which is exposed for clients is needed. IMessagingSystemFactory aMessaging = new MessageBusMessagingFactory(null, "tcp://127.0.0.1:8046/", aMessageBusUnderlyingMessaging);
// Create output channel that will connect the service via the message bus.. // Note: this is address of the service inside the message bus. IDuplexOutputChannel anOutputChannel = aMessaging.createDuplexOutputChannel("Eneter.Echo");
// Create the RPC client for the Echo Service. IRpcClient<IEcho> aClient = new RpcFactory().createClient(IEcho.class);
// Attach the output channel and be able to communicate with the service via the message bus. aClient.attachDuplexOutputChannel(anOutputChannel);
// Get the service proxy and call the echo method. IEcho aProxy = aClient.getProxy(); String aResponse = aProxy.hello("hello");
System.out.println("Echo service returned: " + aResponse);
// Detach the output channel. aClient.detachDuplexOutputChannel(); } }
Constructor and Description |
---|
MessageBusMessagingFactory(java.lang.String serviceConnctingAddress,
java.lang.String clientConnectingAddress,
IMessagingSystemFactory underlyingMessaging)
Constructs the factory.
|
MessageBusMessagingFactory(java.lang.String serviceConnctingAddress,
java.lang.String clientConnectingAddress,
IMessagingSystemFactory serviceUnderlyingMessaging,
IMessagingSystemFactory clientUnderlyingMessaging,
ISerializer serializer) |
MessageBusMessagingFactory(java.lang.String serviceConnctingAddress,
java.lang.String clientConnectingAddress,
IMessagingSystemFactory underlyingMessaging,
ISerializer serializer)
Constructs the factory.
|
Modifier and Type | Method and Description |
---|---|
IDuplexInputChannel |
createDuplexInputChannel(java.lang.String channelId)
Creates the input channel which can receive and send messages to the output channel.
|
IDuplexOutputChannel |
createDuplexOutputChannel(java.lang.String channelId)
Creates the output channel which can sends and receive messages from the input channel.
|
IDuplexOutputChannel |
createDuplexOutputChannel(java.lang.String channelId,
java.lang.String responseReceiverId)
Creates the output channel which can sends and receive messages from the input channel.
|
IMessagingSystemFactory |
getClientMessaging()
Gets messaging used by clients to connect the message bus.
|
int |
getConnectionTimeout()
Returns maximum time for opening connection with the service via the message bus.
|
IThreadDispatcherProvider |
getInputChannelThreading()
Gets threading mode used for input channels.
|
IThreadDispatcherProvider |
getOutputChannelThreading()
Gets threading mode used for output channels.
|
IMessagingSystemFactory |
getServiceMessaging()
Gets messaging used by services to be exposed via the message bus.
|
MessageBusMessagingFactory |
setClientMessaging(IMessagingSystemFactory clientMessaging)
Sets messaging used by clients to connect the message bus.
|
MessageBusMessagingFactory |
setConnectTimeout(int milliseconds)
Sets maximum time for opening connection with the service via the message bus.
|
MessageBusMessagingFactory |
setInputChannelThreading(IThreadDispatcherProvider inputChannelThreading)
Sets threading mode for input channels.
|
MessageBusMessagingFactory |
setOutputChannelThreading(IThreadDispatcherProvider outputChannelThreading)
Sets threading mode for output channels.
|
MessageBusMessagingFactory |
setServiceMessaging(IMessagingSystemFactory serviceMessaging)
messaging used by services to be exposed via the message bus.
|
public MessageBusMessagingFactory(java.lang.String serviceConnctingAddress, java.lang.String clientConnectingAddress, IMessagingSystemFactory underlyingMessaging)
serviceConnctingAddress
- message bus address intended for services which want to register in the message bus.
It can be null if the message bus factory is intended to create only duplex output channels.clientConnectingAddress
- message bus address intended for clients which want to connect a registered service.
It can be null if the message bus factory is intended to create only duplex input channels.underlyingMessaging
- messaging system used by the message bus.public MessageBusMessagingFactory(java.lang.String serviceConnctingAddress, java.lang.String clientConnectingAddress, IMessagingSystemFactory underlyingMessaging, ISerializer serializer)
serviceConnctingAddress
- message bus address intended for services which want to register in the message bus.
It can be null if the message bus factory is intended to create only duplex output channels.clientConnectingAddress
- message bus address intended for clients which want to connect a registered service.
It can be null if the message bus factory is intended to create only duplex input channels.underlyingMessaging
- messaging system used by the message bus.serializer
- serializer which is used to serialize MessageBusMessage
which is internally used for the communication with
the message bus.public MessageBusMessagingFactory(java.lang.String serviceConnctingAddress, java.lang.String clientConnectingAddress, IMessagingSystemFactory serviceUnderlyingMessaging, IMessagingSystemFactory clientUnderlyingMessaging, ISerializer serializer)
public IDuplexOutputChannel createDuplexOutputChannel(java.lang.String channelId) throws java.lang.Exception
IMessagingSystemFactory
createDuplexOutputChannel
in interface IMessagingSystemFactory
channelId
- address of the input channel.java.lang.Exception
public IDuplexOutputChannel createDuplexOutputChannel(java.lang.String channelId, java.lang.String responseReceiverId) throws java.lang.Exception
IMessagingSystemFactory
createDuplexOutputChannel
in interface IMessagingSystemFactory
channelId
- address of the input channel.responseReceiverId
- unique identifier of the output channel. If the value is null then the identifier is genearated automaticallyjava.lang.Exception
public IDuplexInputChannel createDuplexInputChannel(java.lang.String channelId) throws java.lang.Exception
IMessagingSystemFactory
createDuplexInputChannel
in interface IMessagingSystemFactory
channelId
- address of the input channel.java.lang.Exception
public IMessagingSystemFactory getClientMessaging()
public MessageBusMessagingFactory setClientMessaging(IMessagingSystemFactory clientMessaging)
clientMessaging
- messaging which shall be used clients to connect the message bus.public IMessagingSystemFactory getServiceMessaging()
public MessageBusMessagingFactory setServiceMessaging(IMessagingSystemFactory serviceMessaging)
serviceMessaging
- messaging which shall be used by services to expose their API via the message bus.public MessageBusMessagingFactory setInputChannelThreading(IThreadDispatcherProvider inputChannelThreading)
inputChannelThreading
- threading modelpublic IThreadDispatcherProvider getInputChannelThreading()
public MessageBusMessagingFactory setOutputChannelThreading(IThreadDispatcherProvider outputChannelThreading)
outputChannelThreading
- public IThreadDispatcherProvider getOutputChannelThreading()
public MessageBusMessagingFactory setConnectTimeout(int milliseconds)
milliseconds
- public int getConnectionTimeout()