54 lines
1.8 KiB
Python
54 lines
1.8 KiB
Python
import pika
|
|
import logging
|
|
import time
|
|
|
|
# Enable debug logging
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
def test_connection(host, port, description):
|
|
print(f"\nTesting {description} connection to {host}:{port}...")
|
|
#credentials = pika.PlainCredentials('well_pipe', 'wellnuo_2024')
|
|
credentials = pika.PlainCredentials('admin', 'Cbx696969!')
|
|
parameters = pika.ConnectionParameters(
|
|
host=host,
|
|
port=port,
|
|
virtual_host='/',
|
|
credentials=credentials,
|
|
heartbeat=600,
|
|
blocked_connection_timeout=300
|
|
)
|
|
|
|
try:
|
|
connection = pika.BlockingConnection(parameters)
|
|
print(f"Successfully connected to {description} RabbitMQ!")
|
|
|
|
channel = connection.channel()
|
|
print("Channel created successfully!")
|
|
|
|
# Using wellpipe_test queue to match permissions
|
|
channel.queue_declare(queue='wellpipe_test', durable=True)
|
|
|
|
message = f"Test message from {description} - {time.time()}"
|
|
channel.basic_publish(
|
|
exchange='',
|
|
routing_key='wellpipe_test',
|
|
body=message,
|
|
properties=pika.BasicProperties(delivery_mode=2)
|
|
)
|
|
print(f"Successfully sent message: {message}")
|
|
|
|
connection.close()
|
|
print("Connection closed successfully!")
|
|
return True
|
|
except Exception as e:
|
|
print(f"Error with {description} connection: {str(e)}")
|
|
return False
|
|
|
|
# Test both local and external connections
|
|
local_success = test_connection('localhost', 5672, 'local')
|
|
print("\n" + "="*50 + "\n")
|
|
external_success = test_connection('eluxnetworks.net', 5003, 'external')
|
|
|
|
print("\nSummary:")
|
|
print(f"Local connection: {'✓' if local_success else '✗'}")
|
|
print(f"External connection: {'✓' if external_success else '✗'}") |