Python Starting Point

Options
stushep
stushep Member Posts: 20

Hi all, am new to Solace and really struggling with the documentation.
Have created a cloud account with a Cluster as per the demo video. Trying the 'try me' within the browser works a treat (thou i am yet to find the config option for try-me to have guaranteed queue option?)
Anyhow, looking at the Python demo's, i have pip install solace-pubsubplus.
I have then copied the api archive to my local test folder, solace\messaging\etc.

This in itself seems odd the messaging service is not part of the package but a custom add-on, is this correct?

My import is working and i am following the example code within the test, i.e. Solace, Solace Python API, SMF protocol, Connect to the service...
Firstly the demo code doesnt include any imports needed? - odd for an intro demo...

For the most basic have worked out:
from solace.messaging.messaging_service import MessagingService, RetryStrategy

Using the demo code for the most basic example then fails:

`broker_props = {
"solace.messaging.transport.host": "",
"solace.messaging.service.vpn-name": "test-service",
"solace.messaging.authentication.scheme.basic.username": "solace-cloud-client",
"solace.messaging.authentication.scheme.basic.password": "xxxxxxxxxxxxx",
}

messaging_service = MessagingService.builder().from_properties(broker_props)\
.with_reconnection_retry_strategy(RetryStrategy.parametrized_retry(20,3))\
.build()

messaging_service.connect()`

(The demo was also missing the \ so that the '.' for the message_service create a python error as default)

Running this (Using Python 3.9.5) I get the error:

2022-01-05 11:31:52,994 [ERROR] solace.messaging.core: [_solace_session.py:664] [[SERVICE: 0x2702cc38fa0] - [APP ID: app_e47cc0a0-xxxx-xxxx-xxxx-459646edb092]] SOLCLIENT_SUBCODE_PARAM_OUT_OF_RANGE
Traceback (most recent call last):
File "C:\Users\xxxx\Desktop\Solace\test.py", line 20, in
messaging_service = MessagingService.builder().from_properties(broker_props)\
File "C:\Users\xxxx\Desktop\Solace\solace\messaging\messaging_service.py", line 1047, in build
return _BasicMessagingService(config=self._stored_config, application_id=application_id)
File "C:\Users\xxxxx\Desktop\Solace\solace\messaging\messaging_service.py", line 548, in init
self._api.create_session(self._config) # create the session as part of Messaging Service build process
File "C:\Users\xxxx\Desktop\Solace\solace\messaging\core_solace_session.py", line 676, in create_session
raise PubSubPlusCoreClientError(message=core_exception_msg, sub_code=info_sub_code)
solace.messaging.errors.pubsubplus_client_error.PubSubPlusCoreClientError: {'caller_description': 'Session Creation', 'return_code': 'Fail', 'sub_code': 'SOLCLIENT_SUBCODE_PARAM_OUT_OF_RANGE', 'error_info_sub_code': 1, 'error_info_contents': "Session '(c0,s1)_test-service' configuration property 'SESSION_HOST' has invalid part ''"}

Trying the other examples, with Secured SMF and Compressed SMF also produce errors.

Praying someone can point me in the right direction.

Thank you

Best Answers

  • amackenzie
    amackenzie Member, Employee Posts: 260 Solace Employee
    #2 Answer ✓
    Options

    @stushep said:
    Hi @amackenzie , if you see the code, the path does link to the pem key "./DigiCert_Global_Root_CA.pem" the pem key being in the root of my python project... if i enter an incorrect filename it fails so i believe the program is setting the pem key and still failing.

    Thank you

    no, my point was it's looking for a folder, not a cert file. So you could just put "." I believe.

  • amackenzie
    amackenzie Member, Employee Posts: 260 Solace Employee
    #3 Answer ✓
    Options

    glad that worked. I am looking into getting the initial experience cleaned up so new users will be successful without a thread like this ;)

Answers

  • amackenzie
    amackenzie Member, Employee Posts: 260 Solace Employee
    Options

    The host is the broker you want to connect to. In the Solace Cloud Console under this broker service under the Connect tab, SMF you will see the necessary host and Message VPN properties you should be setting in your Python app.

  • stushep
    stushep Member Posts: 20
    Options

    Hi amackenzie, Thank you for your quick response....

    I have tried all the settings... its as if the default cloud app does not allow external access...
    Even trying from the 'try me' on the homepage doesnt allow access in...

    Have been hunting the internet for any support which is few and far between unfortauntely.

    Have now added a trust-store-path and also change the host to tcps://xxxxxxxxxx.messaging.solace.cloud:55443.

    I believe a connection maybe going through but now the certificate states its untrusted, even thou downloaded from the direct link within the settings...

    Current error:

    raise PubSubPlusCoreClientError(message=f'{UNTRUSTED_CERTIFICATE_MESSAGE} {core_exception_msg}',
    solace.messaging.errors.pubsubplus_client_error.PubSubPlusCoreClientError: 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': "Se 'do_connect', 'return_code': 'Not ready', 'sub_code': 'SOLCLIEssion '(c0,s1)_test-service': The peer certificate is not trusted, rc='unable to get local issuer certificate'"}

    My very simple code:

    from solace.messaging.messaging_service import MessagingService

    broker_props = {
    "solace.messaging.transport.host": "tcps://xxxxxxxx.messaging.solace.cloud:55443",
    "solace.messaging.service.vpn-name": "test-service",
    "solace.messaging.authentication.scheme.basic.username": "solace-cloud-client",
    "solace.messaging.authentication.scheme.basic.password": "xxxxxxxxxxxxxx",
    "solace.messaging.tls.trust-store-path": "./DigiCert_Global_Root_CA.pem"
    }
    messaging_service = MessagingService.builder().from_properties(broker_props).build()
    messaging_service.connect()

    Any help/support would be greatly appreciated as initial thoughts arnt going too well.

    Thank you.

  • amackenzie
    amackenzie Member, Employee Posts: 260 Solace Employee
    Options

    The code is almost correct, except you put the PEM file in where it is asking for a trust-store-path so if you enter the path where that PEM file is, you should be good to go.

  • stushep
    stushep Member Posts: 20
    Options

    Hi @amackenzie , if you see the code, the path does link to the pem key "./DigiCert_Global_Root_CA.pem" the pem key being in the root of my python project... if i enter an incorrect filename it fails so i believe the program is setting the pem key and still failing.

    Thank you

  • amackenzie
    amackenzie Member, Employee Posts: 260 Solace Employee
    Options

    As for your other concerns:

    This in itself seems odd the messaging service is not part of the package but a custom add-on, is this correct?

    I am not sure what you mean by that. Could you elaborate? The solace-pubsubplus package you got from PyPi is the Solace SMF Python messaging client API. It's not part of the broker, it's a client SDK.

    Firstly the demo code doesnt include any imports needed? - odd for an intro demo...
    (The demo was also missing the \ so that the '.' for the message_service create a python error as default)

    Agreed. These need to be more "intro-ready".
    @Tamimi can you take note of these? It really is a barrier to 1st use of the sample code.

  • amackenzie
    amackenzie Member, Employee Posts: 260 Solace Employee
    #9 Answer ✓
    Options

    @stushep said:
    Hi @amackenzie , if you see the code, the path does link to the pem key "./DigiCert_Global_Root_CA.pem" the pem key being in the root of my python project... if i enter an incorrect filename it fails so i believe the program is setting the pem key and still failing.

    Thank you

    no, my point was it's looking for a folder, not a cert file. So you could just put "." I believe.

  • stushep
    stushep Member Posts: 20
    edited January 2022 #10
    Options

    hi @amackenzie , i think thats done it thank you... i now get no error when running connect... so i need to go investigate the next bit of code.

    Thank you for your help

    For future reference my code at present:

    from solace.messaging.messaging_service import MessagingService,RetryStrategy
    from solace.messaging.config.transport_security_strategy import TLS
    
    broker_props = {
      "solace.messaging.transport.host": "tcps://**xxxxxx**.messaging.solace.cloud:55443",
      "solace.messaging.service.vpn-name": "test-service",
      "solace.messaging.authentication.scheme.basic.username": "solace-cloud-client",
      "solace.messaging.authentication.scheme.basic.password": "**xxxxxxxx**",
      }
    
    transport_security = TLS.create() \
      .with_certificate_validation(True, validate_server_name=False,
            trust_store_file_path=".")
    
    messaging_service = MessagingService.builder().from_properties(broker_props)\
      .with_reconnection_retry_strategy(RetryStrategy.parametrized_retry(20,3))\
      .with_transport_security_strategy(transport_security).build() 
    
    
    messaging_service.connect()
    import time
    time.sleep(30)
    
    

    With the 30s sleep timer im able to see my client connect/disconnect

  • amackenzie
    amackenzie Member, Employee Posts: 260 Solace Employee
    #11 Answer ✓
    Options

    glad that worked. I am looking into getting the initial experience cleaned up so new users will be successful without a thread like this ;)

  • Tamimi
    Tamimi Member, Administrator, Employee Posts: 491 admin
    Options

    Hey @stushep - thanks for you feedback and sharing your comments! Have you checked out the sample code on the Samples github repo? This will be very helpful for you to get started https://github.com/SolaceSamples/solace-samples-python/tree/master/patterns

    I will take a look at the code snippets in the accordion as well and see where they can be improved 👍

  • stushep
    stushep Member Posts: 20
    Options

    Hi @Tamimi , have been through most i think lol.
    Thank you for the link, had seen that and will be useful today as now getting to grips with publishing and subscribing method's.
    Looking through all the Python documentation at present I believe its written towards a target audience which 100% understands solace inside out and all the custom lingo etc. So someone new has a huge hill to climb first.
    I think a good point to start would even be on the connect page where python code is provided but with out the full context (imports required etc.) so the user is left hunting.

    Happy to offer any support if necessary to provide an outsiders perspective as used to be a technical author before coming back into the world of programming and pipelines.

    Thanks again