Console Script - RabbitMQ Pika - 'module' object has no attribute 'SOMAXCONN'

Hi Team,

I am using Ignition 8 and trying to read the data from tags and send it to RabbitMQ queue using pika library.

But when I try to establish a connection using python Pika library it return error as
‘module’ object has no attribute ‘SOMAXCONN’

The script runs fine when executed independently outside the Ignition environment, but the same script fails when executed on Tag or Console script with above error.

Could you please suggest?

mport pika;
import sys


credentials = pika.PlainCredentials('xxxx', 'xxxx')
parameters = pika.ConnectionParameters('',5672,'/',credentials)
connection = pika.BlockingConnection(parameters)

Did someone find out what’s the problem?

Actually I found we can add that “SOMAXCONN = 128” in in jython lib manually.
However pika didn’t work in ignition

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\jython2.7.2\Lib\site-packages\pika\adapters\", line 359, in __init__
    self._impl = self._create_connection(parameters, _impl_class)
  File "C:\jython2.7.2\Lib\site-packages\pika\adapters\", line 450, in _create_connection
    raise self._reap_last_connection_workflow_error(error)

Maybe you already knew, I just found that you can use the “amqp-client-5.9.0.jar” to talk with RabbitMQ

Do you have any experience with this?
Is it wise to use Ignition for AMQP integrations? Can it work as smoothly as the MQTT integration?

There is probably a way to do this the same as MQTT, for now. On my side, I use amqp-client.xxxx.jar. It is not fun great to use, and loading the JAR file is a bit of a pain for update, or if there is any issue. I will say that creating a module to integrate will be a better approach.

I did not have time to watch on how to create a module for it yet

here a code snippet to connect. We are using EasynetQ in C#, so I try to mimic the connection

def getConnection():
    from com.rabbitmq.client import ConnectionFactory
    from com.rabbitmq.client import Address
    from com.rabbitmq.client.impl import AMQConnection 
    from com.rabbitmq.client.impl import LongStringHelper 

    import java.nio.charset.StandardCharsets;
    import socket
    currentEnv = system.tag.readBlocking(["[default]Global/CurrentEnv"])[0].value
    rabbitSrv = system.tag.readBlocking(["[default]Global/rabbitSrv"])[0].value
    applicationName = system.tag.readBlocking(["[System]Gateway/SystemName"])[0].value
    factory = ConnectionFactory()
    connectionProperties = AMQConnection.defaultClientProperties()
    connectionProperties.put("application", LongStringHelper.asLongString(applicationName))
    connectionProperties.put("application_location", LongStringHelper.asLongString("C:\\Program Files\\Inductive Automation\\Ignition"))
    connectionProperties.put("connection_name", LongStringHelper.asLongString(applicationName))
    connectionProperties.put("machine_name", LongStringHelper.asLongString(socket.gethostname()))
    connectionProperties.put("platform", LongStringHelper.asLongString(socket.gethostname()))

    return factory.newConnection([Address(rabbitSrv)])

def consume(exchangeName, handleCallback):
    import system
    localConsumerTag = None
    logger = system.util.getLogger("RabbitMq Consumer")"Connecting to RabbitMq server...")

    connection = rabbitmq.client.getConnection()
    channel = connection.createChannel()
    queueName = exchangeName + ":IgnitionServer"
    channel.exchangeDeclare(exchangeName, "topic", True, True, None)
    channel.queueDeclare(queueName, True, False, False, {"x-expires": 86400000})
    channel.queueBind(queueName, exchangeName, "#");" [*] Waiting for messages.")
    def deliverCallback(consumerTag, delivery):
        message = u''.join([chr(i % 256) for i in delivery.getBody()])

        handleCallback(consumerTag, message)
    def cancelCallback():
    localConsumerTag = channel.basicConsume(queueName, True, deliverCallback, cancelCallback)
    return connection

def handleMessage():
	import rabbitmq
	import system
	def deliverCallback(consumerTag, message):
		data = system.util.jsonDecode(message)
		# ProcessMessage(data)
	connection = consume("ExchangeName", deliverCallback)

@calimero100582 Thanks, I also figured it out how to do it by now.

The JAR file import is indeed not to much fun, definitely when transferring/deploying servers. I will create a module in the near future to support AMQP.