
Message Exchange
Exchange Initialisation
To create a message exchange endpoint in a process, the Exchange class is used. When creating an instance of the Exchange class it is necessary to specify whether it is performing the role of a mes- sage exchange server or that of a client. A message exchange server is a process which takes on the role of being a hub for message distribution. That is, a message exchange server is a process which accepts connections from one or more message exchange clients and distributes messages between the client processes as appropriate.
Two different approaches can be taken in regard to the message exchange server. The first is that the message exchange server component can be embedded within an existing application and new clients attach to that existing application. Alternatively, a separate process can be created which embeds just the message exchange server component and the existing application, now modelled as a client, along with any new clients connect to this new process.
In both server configurations, initialisation of the message exchange server endpoint is the same. Sub- sequent to initialisation, the endpoint is then directed to listen on a specific port for any client connec- tions.
port = 11111
exchange = netsvc.Exchange(netsvc.EXCHANGE_SERVER) exchange.listen(port)
In the case of a message exchange client, instead of listening for connections, the endpoint is directed to connect to a message exchange server.
host = "localhost" port = 11111 retry = 5
exchange = netsvc.Exchange(netsvc.EXCHANGE_CLIENT) exchange.connect(host,port,retry)
Because it is possible that the message exchange server is not available, a retry delay can be specified. When supplied this will result in successive attempts to connect to the server until a connection is es- tablished. The retry delay when supplied needs to be specified in seconds.
Note that if a connection to the server is lost, the client will also attempt to reconnect automatically after the retry delay time has expired. This has the affect that a client will always try to stay connected to its server without you needing to take any specific action. Your process will not be prematurely shut- down if a connection cannot be established or if a connection is lost.
Service Availability
Unless the service audience of a service agent has been set so as to restrict its visibility, a service will automatically become visible within connected processes through the service registry of the remote process. That is, if a particular service is located within the same process as the message exchange serv-
72