Are there plans to integrate the service conversation model into the client?
There are no current plans to integrate that pattern, but it is definitely something we could look at in the future. Also, if anyone is feeling ambitious, please fork the client and submit a pull request. 
It looks like the service is still selected round robin. Is there a way to select the service to call? For example I may have multiple versions of a product on the fabric. Is it possible to select the one to use?
You are correct. In my previous code example, the initial service was selected via round-robin. That service was used for all subsequent requests (by obtaining the service_id from the initial response).
If you would like to invoke a specific instance of a service, you can use the "service registry". The topic /mcafee/service/dxl/svcregistry/query is used to query the service registry. The ability to query the registry is pretty limited at this point. If you pass an empty JSON object you will receive information on all of the services registered. If you specify a serviceType in the JSON object you will receive information on all services of that particular type. For example, you could query for all Threat Intelligence Exchange (TIE) services.
The following code example registers 3 different services. The first two services are of the same type ("myService"), while the third service is a different type ("anotherService"). The code then performs two different queries on the service registry. The first query returns all services, while the second query returns services of the type, "myService".
- services = []
- class FakeRequestCallback(RequestCallback):
- def on_request(self, request):
- pass
- with DxlClient(config) as client:
- client.connect()
-
- info = ServiceRegistrationInfo(client, "myService")
- info.metadata = {"version": "1.0.0", "otherProperty": "otherValue"}
- info.add_topic("/myService/topic", FakeRequestCallback())
- services.append(info)
- client.register_service_sync(info, 1000)
-
- info = ServiceRegistrationInfo(client, "myService")
- info.metadata = {"version": "1.0.1", "otherProperty": "otherValue"}
- info.add_topic("/myService/newtopic", FakeRequestCallback())
- services.append(info)
- client.register_service_sync(info, 1000)
-
- info = ServiceRegistrationInfo(client, "anotherService")
- info.metadata = {"version": "4.0.2"}
- info.add_topic("/anotherService/anotherTopic", FakeRequestCallback())
- services.append(info)
- client.register_service_sync(info, 1000)
-
-
-
- req = Request("/mcafee/service/dxl/svcregistry/query")
- req.payload = "{}".encode(encoding="UTF-8")
- res = client.sync_request(req)
-
- if res.message_type != Message.MESSAGE_TYPE_ERROR:
- res_dict = json.loads(res.payload.rstrip("\0").decode(encoding="UTF-8"))
- print json.dumps(res_dict, sort_keys=True, indent=4, separators=(',', ': '))
-
-
-
- req = Request("/mcafee/service/dxl/svcregistry/query")
- req.payload = json.dumps({"serviceType": "myService"}).encode(encoding="UTF-8")
- res = client.sync_request(req)
-
- if res.message_type != Message.MESSAGE_TYPE_ERROR:
- res_dict = json.loads(res.payload.rstrip("\0").decode(encoding="UTF-8"))
- print json.dumps(res_dict, sort_keys=True, indent=4, separators=(',', ': '))
Display More
The output for the first query should appear similar to the following:
- {
- "services": {
- "{16820b2c-c1f8-4468-8c6c-eac102582d4e}": {
- "brokerGuid": "{02bdf380-ce15-11e6-0563-000c29026069}",
- "certificates": [
- "8a5a5b086fd92809f7083074780af5198b4a4c77",
- "c58ea56fece908811d5844cbc55df3740741d04e"
- ],
- "clientGuid": "7968dffc-85c5-49ad-a8f4-4d3584815fd6",
- "local": true,
- "managed": false,
- "metaData": {
- "otherProperty": "otherValue",
- "version": "1.0.1"
- },
- "registrationTime": 1501805716,
- "requestChannels": [
- "/myService/newtopic"
- ],
- "serviceGuid": "{16820b2c-c1f8-4468-8c6c-eac102582d4e}",
- "serviceType": "myService",
- "ttlMins": 60,
- "unauthorizedChannels": []
- },
- "{32c76d40-bc87-4a1f-8fec-2969b64a447a}": {
- "brokerGuid": "{02bdf380-ce15-11e6-0563-000c29026069}",
- "certificates": [
- "8a5a5b086fd92809f7083074780af5198b4a4c77",
- "c58ea56fece908811d5844cbc55df3740741d04e"
- ],
- "clientGuid": "7968dffc-85c5-49ad-a8f4-4d3584815fd6",
- "local": true,
- "managed": false,
- "metaData": {
- "version": "4.0.2"
- },
- "registrationTime": 1501805716,
- "requestChannels": [
- "/anotherService/anotherTopic"
- ],
- "serviceGuid": "{32c76d40-bc87-4a1f-8fec-2969b64a447a}",
- "serviceType": "anotherService",
- "ttlMins": 60,
- "unauthorizedChannels": []
- },
- "{f5253d03-dcbf-4c4d-bdde-24cb573aea25}": {
- "brokerGuid": "{02bdf380-ce15-11e6-0563-000c29026069}",
- "certificates": [
- "8a5a5b086fd92809f7083074780af5198b4a4c77",
- "c58ea56fece908811d5844cbc55df3740741d04e"
- ],
- "clientGuid": "7968dffc-85c5-49ad-a8f4-4d3584815fd6",
- "local": true,
- "managed": false,
- "metaData": {
- "otherProperty": "otherValue",
- "version": "1.0.0"
- },
- "registrationTime": 1501805715,
- "requestChannels": [
- "/myService/topic"
- ],
- "serviceGuid": "{f5253d03-dcbf-4c4d-bdde-24cb573aea25}",
- "serviceType": "myService",
- "ttlMins": 60,
- "unauthorizedChannels": []
- }
- }
- }
Display More
The output for the second query should appear similar to the following:
- {
- "services": {
- "{16820b2c-c1f8-4468-8c6c-eac102582d4e}": {
- "brokerGuid": "{02bdf380-ce15-11e6-0563-000c29026069}",
- "certificates": [
- "8a5a5b086fd92809f7083074780af5198b4a4c77",
- "c58ea56fece908811d5844cbc55df3740741d04e"
- ],
- "clientGuid": "7968dffc-85c5-49ad-a8f4-4d3584815fd6",
- "local": true,
- "managed": false,
- "metaData": {
- "otherProperty": "otherValue",
- "version": "1.0.1"
- },
- "registrationTime": 1501805716,
- "requestChannels": [
- "/myService/newtopic"
- ],
- "serviceGuid": "{16820b2c-c1f8-4468-8c6c-eac102582d4e}",
- "serviceType": "myService",
- "ttlMins": 60,
- "unauthorizedChannels": []
- },
- "{f5253d03-dcbf-4c4d-bdde-24cb573aea25}": {
- "brokerGuid": "{02bdf380-ce15-11e6-0563-000c29026069}",
- "certificates": [
- "8a5a5b086fd92809f7083074780af5198b4a4c77",
- "c58ea56fece908811d5844cbc55df3740741d04e"
- ],
- "clientGuid": "7968dffc-85c5-49ad-a8f4-4d3584815fd6",
- "local": true,
- "managed": false,
- "metaData": {
- "otherProperty": "otherValue",
- "version": "1.0.0"
- },
- "registrationTime": 1501805715,
- "requestChannels": [
- "/myService/topic"
- ],
- "serviceGuid": "{f5253d03-dcbf-4c4d-bdde-24cb573aea25}",
- "serviceType": "myService",
- "ttlMins": 60,
- "unauthorizedChannels": []
- }
- }
- }
Display More
As you can see there is quite a bit of information on each service. It is also important to note that the service registration information includes a serviceGuid. This value can be specified in the service_id of a request message to invoke that particular service. Other useful information includes metaData which could be used as a means of selecting the service to invoke.
Hope this helps,
Chris