ASRequestReplyServer and ASRequestReplyClient

These examples show how two spaces can work together as a reply server and reply client.

The ASRequestReplyClient and ASRequestReplyServer examples work together to demonstrate how two spaces can be used by applications to communicate in a request and reply manner. The two spaces are named request and reply.

In this example, ASRequestReplyServer defines the spaces and ASRequestReplyClient joins the already defined spaces. This is different from most of the other examples where the space is always defined.

Another interesting thing to note about how ASRequestReplyServer is implemented is that it uses the Admin interface to define the 'request' and 'reply' spaces. Most of the other examples define a space using the SpaceDef interface.

ASRequestReplyClient loops, putting messages into the 'request' space. When it is notified of messages in the 'reply' space, ASRequestReplyClient takes the replies from the 'reply' space.

For every 100 replies received, ASRequestReplyClient prints a message indicating the number of requests that have been sent and the number of replies received.

ASRequestReplyServer periodically polls for messages on the 'request' space. When a message is put into the 'request' space, ASRequestReplyServer takes it from the space. The name of the ASRequestReplyServer is added to the original message as the responder to the request. This slightly modified message is then put into the 'reply' space. For every 100 requests received, ASRequestReplyServer prints a message indicating the number of requests it has processed.

The request space has a definition consisting of two fields:

  • A mandatory key field called id of type 'integer'
  • A mandatory key field called requestor of type 'string'

The reply space has a definition consisting of three fields:

  • A mandatory key field called id of type 'integer'
  • A mandatory key field called requestor of type 'string'
  • A mandatory field called responder of type 'string'

ASRequestReplyServer is a seeder for the request space and a leech for the reply space.

ASRequestReplyClient is a leech for the request space and a seeder for the reply space.