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

**URL:** <https://forum.inductiveautomation.com/t/console-script-rabbitmq-pika-module-object-has-no-attribute-somaxconn/28366>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [September 18, 2019, 10:05pm UTC](https://forum.inductiveautomation.com/t/console-script-rabbitmq-pika-module-object-has-no-attribute-somaxconn/28366 "2019-09-18T22:05:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![atul.raut](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@atul.raut](https://forum.inductiveautomation.com/u/atul.raut)\
**Post date:** [September 18, 2019, 10:05pm UTC](https://forum.inductiveautomation.com/t/console-script-rabbitmq-pika-module-object-has-no-attribute-somaxconn/28366/1 "2019-09-18T22:05:22Z")

</div>

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

try:

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

---

<div class="post-metadata">

**Author:** ![huyao](https://avatars.discourse-cdn.com/v4/letter/h/aeb1de/32.png) [@huyao](https://forum.inductiveautomation.com/u/huyao)\
**Post date:** [July 12, 2020, 7:18am UTC](https://forum.inductiveautomation.com/t/console-script-rabbitmq-pika-module-object-has-no-attribute-somaxconn/28366/2 "2020-07-12T07:18:33Z")

</div>

Did someone find out what’s the problem?

---

<div class="post-metadata">

**Author:** ![huyao](https://avatars.discourse-cdn.com/v4/letter/h/aeb1de/32.png) [@huyao](https://forum.inductiveautomation.com/u/huyao)\
**Post date:** [July 12, 2020, 11:59am UTC](https://forum.inductiveautomation.com/t/console-script-rabbitmq-pika-module-object-has-no-attribute-somaxconn/28366/3 "2020-07-12T11:59:47Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![huyao](https://avatars.discourse-cdn.com/v4/letter/h/aeb1de/32.png) [@huyao](https://forum.inductiveautomation.com/u/huyao)\
**Post date:** [July 13, 2020, 3:03am UTC](https://forum.inductiveautomation.com/t/console-script-rabbitmq-pika-module-object-has-no-attribute-somaxconn/28366/4 "2020-07-13T03:03:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![louagejasper](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/louagejasper/32/86311_2.png) [@louagejasper](https://forum.inductiveautomation.com/u/louagejasper)\
**Post date:** [June 2, 2022, 12:07pm UTC](https://forum.inductiveautomation.com/t/console-script-rabbitmq-pika-module-object-has-no-attribute-somaxconn/28366/5 "2022-06-02T12:07:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![calimero100582](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/calimero100582/32/18630_2.png) [@calimero100582](https://forum.inductiveautomation.com/u/calimero100582)\
**Post date:** [July 4, 2022, 2:01pm UTC](https://forum.inductiveautomation.com/t/console-script-rabbitmq-pika-module-object-has-no-attribute-somaxconn/28366/6 "2022-07-04T14:01:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![calimero100582](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/calimero100582/32/18630_2.png) [@calimero100582](https://forum.inductiveautomation.com/u/calimero100582)\
**Post date:** [July 4, 2022, 2:05pm UTC](https://forum.inductiveautomation.com/t/console-script-rabbitmq-pika-module-object-has-no-attribute-somaxconn/28366/7 "2022-07-04T14:05:57Z")

</div>

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

```auto
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()
    factory.setVirtualHost(currentEnv)
    factory.setPassword("xxx")
    factory.setUsername("xxx")
    
    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()))
    factory.setClientProperties(connectionProperties)

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

def consume(exchangeName, handleCallback):
    import system
  
    localConsumerTag = None
    
    logger = system.util.getLogger("RabbitMq Consumer")    
    logger.info("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, "#");
    
    logger.info(" [*] Waiting for messages.")
    
    def deliverCallback(consumerTag, delivery):
        message = u''.join([chr(i % 256) for i in delivery.getBody()])

        handleCallback(consumerTag, message)
        
    def cancelCallback():
        pass
    
    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)

```

---

<div class="post-metadata">

**Author:** ![louagejasper](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/louagejasper/32/86311_2.png) [@louagejasper](https://forum.inductiveautomation.com/u/louagejasper)\
**Post date:** [July 4, 2022, 3:17pm UTC](https://forum.inductiveautomation.com/t/console-script-rabbitmq-pika-module-object-has-no-attribute-somaxconn/28366/8 "2022-07-04T15:17:28Z")

</div>

@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.
