Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-27 07:41:41

0001 import stomp
0002 import ssl
0003 import time
0004 
0005 class MyListener(stomp.ConnectionListener):
0006     def on_connected(self, frame):
0007         print("Connected to broker:", frame.headers)
0008 
0009     def on_message(self, frame):
0010         print(f"Received message:\n{frame.body}")
0011 
0012     def on_error(self, frame):
0013         print(f"Error from broker: {frame.body}")
0014 
0015     def on_disconnected(self):
0016         print("Disconnected from broker")
0017 
0018 # Broker config
0019 host = 'pandaserver02.sdcc.bnl.gov'
0020 port = 61612
0021 cafile = '<pathname to where full-chain.pem is>'
0022 
0023 # Durable subscription config
0024 client_id = 'test-client'
0025 subscription_name = 'test-durable-sub'
0026 
0027 # Set up STOMP over SSL connection
0028 conn = stomp.Connection(
0029     host_and_ports=[(host, port)],
0030     vhost=host,
0031     try_loopback_connect=False
0032 )
0033 
0034 # SSL settings
0035 conn.transport.set_ssl(
0036     for_hosts=[(host, port)],
0037     ca_certs=cafile,
0038     ssl_version=ssl.PROTOCOL_TLS_CLIENT
0039 )
0040 
0041 # Code above this localtion is common for both sender and receiver
0042 
0043 # Attach listener
0044 conn.set_listener('', MyListener())
0045 #conn.set_listener('debug', stomp.PrintingListener())
0046 
0047 # Connect with a durable client-id
0048 conn.connect(
0049     login='<username>',
0050     passcode='<userpasswd>',
0051     wait=True,
0052     version='1.2',
0053     headers={'client-id': client_id}
0054 )
0055 
0056 # Subscribe with durable subscription name
0057 conn.subscribe(
0058     destination='epictopic',
0059     id='sub-test-001',
0060     ack='auto',
0061     headers={'activemq.subscriptionName': 'test-durable-sub'}
0062 )
0063 
0064 print(f"Listening for messages on 'epictopic' (durable queue: {client_id}.{subscription_name})...")
0065 
0066 # Loop forever
0067 try:
0068     while True:
0069         time.sleep(1)
0070 except KeyboardInterrupt:
0071     print("Exiting...")
0072     conn.disconnect()