Python v1.0.0 PubSub+ API - Connecting to Solace Cloud

solcache
solcache Member Posts: 7
edited March 2021 in Early Access API #1

Continued from: https://solace.community/discussion/comment/2246#Comment_2246

@Tamimi many thanks for your response. I did what you suggested, which is update the broker_props and I had it working locally. The cloud credentials look something like my response below, does that look correct:

Broker Config

broker_props = {
"solace.messaging.transport.host": os.environ.get('SOLACE_HOST') or "tcp://xxxxxx.messaging.solace.cloud:55555",
"solace.messaging.service.vpn-name": os.environ.get('SOLACE_VPN') or "my_vpn",
"solace.messaging.authentication.scheme.basic.username": os.environ.get('SOLACE_USERNAME') or "solace-cloud-client",
"solace.messaging.authentication.scheme.basic.password": os.environ.get('SOLACE_PASSWORD') or "my_password"
}

error I am seeing, which means the connection details might be wrong: SOLCLIENT_SUBCODE_COMMUNICATION_ERROR

Tagged:

Comments

  • Tamimi
    Tamimi Member, Administrator, Employee Posts: 529 admin

    Thanks for the details @solcache. Note that you wouldnt need to change the broker prop as you have it in your example. You have 3 ways to pass the config options depending on your code setup, you can either just pass it as a string

    broker_props = {
    "solace.messaging.transport.host": "tcp://xxxxxx.messaging.solace.cloud:55555",
    "solace.messaging.service.vpn-name": "my_vpn",
    "solace.messaging.authentication.scheme.basic.username": "solace-cloud-client",
    "solace.messaging.authentication.scheme.basic.password": "my_password"
    }
    

    or pass it as an environment variable and keep the os.environ.get(ENV_NAME') in your code, or pass a configuration file that is saved somewhere else containing the broker properties.

    As for your issue of not being able to connect, could you provide more details on the error stack that you got? And are you able to connect to the broker outside the python code? So for example if you navigate to the try me component at the bottom of this page https://solace.com/products/event-broker/software/getting-started/ you can put your broker details and attempt to connect to it for a simple pub/sub interaction.