Try PubSub+

Python connect to solace Pubsub+ cloud

onkar1712onkar1712 Member Posts: 3
edited April 27 in PubSub+ Event Broker #1

I have service created on https://console.solace.cloud/services on GCP platform and I am trying to connect to this service from python 3.7 using solace-pubsubplus pypi package: https://pypi.org/project/solace-pubsubplus/
Here is my code snippet for connecting to the service:

_def publish(message):
    import solace.messaging.messaging_service as service
    from solace.messaging.publisher.outbound_message import OutboundMessageBuilder
    from solace.messaging.publisher.persistent_message_publisher import Topic

    broker_props = {"solace.messaging.transport.host": "https://mr-b7hnxi2xr1c.messaging.solace.cloud:9443",
                    "solace.messaging.service.vpn-name": "test-event-service",
                    "solace.messaging.authentication.scheme.basic.username": "solace-cloud-client",
                    "solace.messaging.authentication.scheme.basic.password": "qaa53j6ih9l8ru646n1l7rjm64"}

    messaging_service = service.MessagingServiceClientBuilder().from_properties(config=broker_props).build()
    messaging_service.connect()
    print("connected")

    # publisher = service.PersistentMessagePublisherBuilder().from_properties(configuration=broker_props).build()
    # message_properties = {'env': 'test', 'application': 'test', 'object': 'sales-order'}
    # out_message = OutboundMessageBuilder().build(payload=message, additional_message_properties=message_properties,
    #                                              converter=None)
    # publisher.publish(message=out_message, destination=Topic.of('test-service/message'))
    # print(f"Message published to solace...")_

After running the code I get error:

2021-04-27 17:22:54,917 [ERROR] solace.messaging.core: [_solace_session.py:580]  [[SERVICE: 0x23cefec66d0] - [APP ID: app_404dc464-c4d0-4bfd-81e9-4be48c078ac2]] SOLCLIENT_SUBCODE_FAILED_LOADING_TRUSTSTORE
2021-04-27 17:22:54,917 [ERROR] solace.messaging.core: [_solace_session.py:582]  [[SERVICE: 0x23cefec66d0] - [APP ID: app_404dc464-c4d0-4bfd-81e9-4be48c078ac2]] SESSION CREATION UNSUCCESSFUL. Failed to load trust store.

What truststore do I need to load to connect to this service in solace cloud?
Can someone please point me towards proper documentation for Python. I am referring to the documentation here: https://www.solace.dev/ and it looks like its incomplete.

Answers

  • TamimiTamimi Member, Administrator, Employee Posts: 162 admin
    edited April 27 #2

    Hey @onkar1712 ! Just from a quick glance, I see that your solace.messaging.transport.host in your broker properties configuration is incorrect. https is not a valid protocol to connect to the broker Update: using http(s) is similar to using websocket to connect to the broker. To do so however you will need to connect to the websocket port if you are not using SMF, and since you are using SMF (Solace Message Format) to connect to the broker (via the Solace Python API) you will need to get the "Solace Messaging" configuration parameters. You can get this by navigating to your cloud service and under the connect tab, expand the "Solace Messaging" section

    You will see the SMF host, and that is what you should be using in your broker properties.

    I hope this helps! Feel free to share any project, tips and tricks or further questions

  • marcmarc Member, Administrator, Moderator, Employee Posts: 361 admin

    Also in the last image in @Tamimi's response you'll see there is a link to download the TrustStore at the bottom of the Connection Details. That's the truststore that you'll want :)

  • TamimiTamimi Member, Administrator, Employee Posts: 162 admin
    edited April 27 #4

    Marc has a good point! If you want to use a secure connection and download the TrustStore, you will need to add this to your broker prop as well

     "solace.messaging.tls.trust-store-path": "path_to_trusted_store"
    

    To have the following broker_props

    broker_props = {"solace.messaging.transport.host": "<protocol>://<host>:<port>",
                        "solace.messaging.service.vpn-name": "<vpn_name>",
                        "solace.messaging.authentication.scheme.basic.username": "<client>",
                        "solace.messaging.authentication.scheme.basic.password": "<passord>",
                         "solace.messaging.tls.trust-store-path": "path_to_trusted_store"}
    
  • onkar1712onkar1712 Member Posts: 3

    Hi @Tamimi , Thanks for the quick response. Okay, so I also tried to connect using SMF (not secured one) like this:

    def publish(message):
    import solace.messaging.messaging_service as service

    broker_props = {"solace.messaging.transport.host": "tcp://mr-b7hnxi2xr1c.messaging.solace.cloud:55555",
                    "solace.messaging.service.vpn-name": "test-event-service",
                    "solace.messaging.authentication.scheme.basic.username": "solace-cloud-client",
                    "solace.messaging.authentication.scheme.basic.password": "<password>"
                    }
    
    messaging_service = service.MessagingServiceClientBuilder().from_properties(
        config=broker_props).build()
    messaging_service.connect()
    print("connected")______
    

    It gives me timeout error:
    2021-04-28 11:02:56,225 [WARNING] solace.messaging.core: [_solace_session.py:768] [[SERVICE: 0x1c29cd85070] - [APP ID: app_184aa5fc-583b-4f49-a0fb-1cfff592097f]] {'caller_description': 'From service event callback', 'return_code': 'Ok', 'sub_code': 'SOLCLIENT_SUBCODE_COMMUNICATION_ERROR', 'error_info_sub_code': 14, 'error_info_contents': 'TCP connection failure for fd 1120, error = Connection timed out (10060)'}
    2021-04-28 11:02:56,226 [WARNING] solace.messaging.core: [_solace_session.py:679] [[SERVICE: 0x1c29cd85070] - [APP ID: app_184aa5fc-583b-4f49-a0fb-1cfff592097f]] {'caller_description': 'do_connect', 'return_code': 'Not ready', 'sub_code': 'SOLCLIENT_SUBCODE_COMMUNICATION_ERROR', 'error_info_sub_code': 14, 'error_info_contents': 'TCP connection failure for fd 1120, error = Connection timed out (10060)'}

    I also tried connecting using SSMF(using tcps) and specifying truststore .pem file path like this:

    def publish(message):
    import solace.messaging.messaging_service as service

    broker_props = {"solace.messaging.transport.host": "tcps://mr-b7hnxi2xr1c.messaging.solace.cloud:55443",
                    "solace.messaging.service.vpn-name": "test-event-service",
                    "solace.messaging.authentication.scheme.basic.username": "solace-cloud-client",
                    "solace.messaging.authentication.scheme.basic.password": "qaa53j6ih9l8ru646n1l7rjm64",
                    "solace.messaging.tls.trust-store-path": "C:\\Users\\onpat\\PycharmProjects\\solace-test\\data\\DigiCert_Global_Root_CA.pem"}
    
    messaging_service = service.MessagingServiceClientBuilder().from_properties(
        config=broker_props).build()
    messaging_service.connect()
    print("connected")
    

    solace.messaging.errors.pubsubplus_client_error.PubSubPlusClientError: (PubSubPlusClientError(...), 'SESSION CREATION UNSUCCESSFUL. Untrusted certificate. {\'caller_description\': \'do_connect\', \'return_code\': \'Not ready\', \'sub_code\': \'SOLCLIENT_SUBCODE_UNTRUSTED_CERTIFICATE\', \'error_info_sub_code\': 99, \'error_info_contents\': "Session \'(c0,s1)_test-event-service\': The peer certificate is not trusted, rc=\'unable to get local issuer certificate\'"}')

  • onkar1712onkar1712 Member Posts: 3

    Hi @Tamimi Thanks for your reply. So, I tried connecting over SMF(using tcp, unsecured) like this:

    def publish(message):
    import solace.messaging.messaging_service as service

    broker_props = {"solace.messaging.transport.host": "tcp://mr-b7hnxi2xr1c.messaging.solace.cloud:55555",
                    "solace.messaging.service.vpn-name": "test-event-service",
                    "solace.messaging.authentication.scheme.basic.username": "solace-cloud-client",
                    "solace.messaging.authentication.scheme.basic.password": "qaa53j6ih9l8ru646n1l7rjm64"
                    }
    
    messaging_service = service.MessagingServiceClientBuilder().from_properties(
        config=broker_props).build()
    messaging_service.connect()
    print("connected")
    

    And I get following error:
    solace.messaging.errors.pubsubplus_client_error.PubSubPlusClientError: (PubSubPlusClientError(...), {'caller_description': 'do_connect', 'return_code': 'Not ready', 'sub_code': 'SOLCLIENT_SUBCODE_COMMUNICATION_ERROR', 'error_info_sub_code': 14, 'error_info_contents': 'TCP connection failure for fd 1136, error = Connection timed out (10060)'})

    I also tried connecting to event broker over tcps(SSMF) like this by giving path to .pem file:

    def publish(message):
    import solace.messaging.messaging_service as service

    broker_props = {"solace.messaging.transport.host": "tcps://mr-b7hnxi2xr1c.messaging.solace.cloud:55443",
                    "solace.messaging.service.vpn-name": "test-event-service",
                    "solace.messaging.authentication.scheme.basic.username": "solace-cloud-client",
                    "solace.messaging.authentication.scheme.basic.password": "qaa53j6ih9l8ru646n1l7rjm64",
                    "solace.messaging.tls.trust-store-path": "C:\\Users\\onpat\\PycharmProjects\\solace-test\\data\\DigiCert_Global_Root_CA.pem"
                    }
    
    messaging_service = service.MessagingServiceClientBuilder().from_properties(
        config=broker_props).build()
    messaging_service.connect()
    print("connected")
    

    This gives me followinf error:
    solace.messaging.errors.pubsubplus_client_error.PubSubPlusClientError: (PubSubPlusClientError(...), 'SESSION CREATION UNSUCCESSFUL. Untrusted certificate. {\'caller_description\': \'do_connect\', \'return_code\': \'Not ready\', \'sub_code\': \'SOLCLIENT_SUBCODE_UNTRUSTED_CERTIFICATE\', \'error_info_sub_code\': 99, \'error_info_contents\': "Session \'(c0,s1)_test-event-service\': The peer certificate is not trusted, rc=\'unable to get local issuer certificate\'"}')
    2021-04-28 11:18:08,282 [WARNING] solace.messaging.core: [_solace_session.py:768] [[SERVICE: 0x230523f5070] - [APP ID: app_03d2829e-4176-4ac8-86c9-980bc3dfc191]] {'caller_description': 'From service event callback', 'return_code': 'Ok', 'sub_code': 'SOLCLIENT_SUBCODE_UNTRUSTED_CERTIFICATE', 'error_info_sub_code': 99, 'error_info_contents': "Session '(c0,s1)_test-event-service': The peer certificate is not trusted, rc='unable to get local issuer certificate'"}
    2021-04-28 11:18:08,284 [WARNING] solace.messaging.core: [_solace_session.py:671] [[SERVICE: 0x230523f5070] - [APP ID: app_03d2829e-4176-4ac8-86c9-980bc3dfc191]] SESSION CREATION UNSUCCESSFUL. Untrusted certificate. {'caller_description': 'do_connect', 'return_code': 'Not ready', 'sub_code': 'SOLCLIENT_SUBCODE_UNTRUSTED_CERTIFICATE', 'error_info_sub_code': 99, 'error_info_contents': "Session '(c0,s1)_test-event-service': The peer certificate is not trusted, rc='unable to get local issuer certificate'"}

Sign In or Register to comment.