Rabbitmq socket error occurred

Hi, i got a lot of 'Library error: a socket error occurred ' when i set heartbeat values to 6 , when i restart rabbitmq server and never restart the php-fpm i got the error too; i try to ca...

@pinepain yes, reloading php-fpm can solves the issue; php version is 7.0.6 and rabbitmq version is 3.6.5;
when i run the code as follows i get the error. thanks

$conn_args = array(
‘host’ => ‘192.168.204.72’,
‘port’ => ‘5672’,
‘login’ => ‘root’,
‘password’ => ‘root’,
‘heartbeat’ => 6
);
$conn = new AMQPConnection($conn_args);
if ($conn->pconnect()) {
echo «Established a connection to the broker n»;
} else {
echo «Cannot connect to the broker n «;
}
$channel = new AMQPChannel($conn);

$ex = new AMQPExchange($channel);
$ex->setName(‘exchange33’);
$ex->setType(AMQP_EX_TYPE_DIRECT);
$ex->setFlags(AMQP_DURABLE);

echo «exchange status:».$ex->declareExchange();
echo «n»;

$queue = new AMQPQueue($channel);
$queue->setName(‘queue33’);
$queue->setFlags(AMQP_NOPARAM);
$queue->declareQueue();
$queue->bind(‘exchange33′,’key’);

$message = json_encode(array(‘Hello World3!’,’php3′,’c++3:’));
$routingkey=’key’;
$res = $ex->publish($message,$routingkey);

php -version

PHP 7.0.6 (cli) (built: Jun 4 2016 13:48:07) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Xdebug v2.4.1, Copyright (c) 2002-2016, by Derick Rethans

rabbitmqctl status

Status of node rabbit@localhost …
[{pid,27552},
{running_applications,
[{rabbitmq_management,»RabbitMQ Management Console»,»3.6.5″},
{rabbitmq_management_agent,»RabbitMQ Management Agent»,»3.6.5″},
{rabbit,»RabbitMQ»,»3.6.5″},
{os_mon,»CPO CXC 138 46″,»2.4.1″},
{rabbitmq_web_dispatch,»RabbitMQ Web Dispatcher»,»3.6.5″},
{webmachine,»webmachine»,»1.10.3″},
{mochiweb,»MochiMedia Web Server»,»2.13.1″},
{ssl,»Erlang/OTP SSL application»,»8.0.2″},
{public_key,»Public key infrastructure»,»1.2″},
{crypto,»CRYPTO»,»3.7.1″},
{amqp_client,»RabbitMQ AMQP Client»,»3.6.5″},
{rabbit_common,[],»3.6.5″},
{compiler,»ERTS CXC 138 10″,»7.0.2″},
{ranch,»Socket acceptor pool for TCP protocols.»,»1.2.1″},
{asn1,»The Erlang ASN1 compiler version 4.0.4″,»4.0.4″},
{syntax_tools,»Syntax tools»,»2.1″},
{inets,»INETS CXC 138 49″,»6.3.3″},
{xmerl,»XML parser»,»1.3.12″},
{mnesia,»MNESIA CXC 138 12″,»4.14.1″},
{sasl,»SASL CXC 138 11″,»3.0.1″},
{stdlib,»ERTS CXC 138 10″,»3.1″},
{kernel,»ERTS CXC 138 10″,»5.1″}]},
{os,{unix,linux}},
{erlang_version,
«Erlang/OTP 19 [erts-8.1] [source-77fb4f8] [64-bit] [smp:4:4] [async-threads:64] [hipe] [kernel-poll:true]n»},
{memory,
[{total,59202976},
{connection_readers,0},
{connection_writers,0},
{connection_channels,0},
{connection_other,2832},
{queue_procs,209624},
{queue_slave_procs,0},
{plugins,602808},
{other_proc,19381184},
{mnesia,82456},
{mgmt_db,509904},
{msg_index,48168},
{other_ets,1515968},
{binary,34472},
{code,24815589},
{atom,1033401},
{other_system,10966570}]},
{alarms,[]},
{listeners,[{clustering,25672,»::»},{amqp,5672,»::»}]},
{vm_memory_high_watermark,0.4},
{vm_memory_limit,3301144985},
{disk_free_limit,50000000},
{disk_free,52243738624},
{file_descriptors,
[{total_limit,102300},
{total_used,3},
{sockets_limit,92068},
{sockets_used,0}]},
{processes,[{limit,1048576},{used,236}]},
{run_queue,0},
{uptime,39},
{kernel,{net_ticktime,60}}]

Client Exceptions¶

Here is the break-down of exceptions that can be raised by the PHP AMQP Extension:

AMQPChannelException
AMQPConnectionException
AMQPExchangeException
AMQPQueueException

Additionally the Humus AMQP Module throws some of the following exceptions

HumusAmqpModuleExceptionBadFunctionCallException
HumusAmqpModuleExceptionBadMethodCallException
HumusAmqpModuleExceptionExtensionNotLoadedException
HumusAmqpModuleExceptionInvalidArgumentException
HumusAmqpModuleExceptionRuntimeException

The first 3 exceptions only occur, when you don’t have ext-pcntl installed but you try to start
the consumer without the –without-signals switch.

The InvalidArgumentException occurs, when you have a wrong amqp module configuration.

Initial RabbitMQ Connection Failures¶

When applications connect to the broker, they need to handle connection
failures. Networks are not 100% reliable, even with modern system
configuration tools like Chef or Puppet misconfigurations happen and the
broker might also be down. Error detection should happen as early as
possible. To handle TCP connection failure, catch the
AMQPConnection exception.

Authentication Failures¶

Another reason why a connection may fail is authentication failure.
Handling authentication failure is very similar to handling initial TCP
connection failure.

When you try to access RabbitMQ with invalid credentials, you’ll get an
‘AMQPConnectionException’ with message ‘Library error: a socket error occurred — Potential login failure.’.

In case you are wondering why the exception name has “potential” in it:
AMQP 0.9.1
spec requires
broker implementations to simply close TCP connection without sending
any more data when an exception (such as authentication failure) occurs
before AMQP connection is open. In practice, however, when broker closes
TCP connection between successful TCP connection and before AMQP
connection is open, it means that authentication has failed.

Channel-level Exceptions¶

Channel-level exceptions are more common than connection-level ones and
often indicate issues applications can recover from (such as consuming
from or trying to delete a queue that does not exist).

Common channel-level exceptions and what they mean¶

A few channel-level exceptions are common and deserve more attention.

406 Precondition Failed¶

Description

The client requested a method that was not allowed because some
precondition failed.

What might cause it

  • AMQP entity (a queue or exchange) was re-declared with attributes
    different from original declaration. Maybe two applications or pieces of
    code declare the same entity with different attributes. Note that
    different RabbitMQ client libraries historically use slightly different
    defaults for entities and this may cause attribute mismatches.

    • PRECONDITION_FAILED — parameters for queue
      ‘examples.channel_exception’ in vhost ‘/’ not equivalent

    • PRECONDITION_FAILED — channel is not transactional

405 Resource Locked¶

Description

The client attempted to work with a server entity to which it has no
access because another client is working with it.

What might cause it

  • Multiple applications (or different pieces of
    code/threads/processes/routines within a single application) might try
    to declare queues with the same name as exclusive.

  • Multiple consumer across multiple or single app might be registered as
    exclusive for the same queue.

Example RabbitMQ error message

RESOURCE_LOCKED — cannot obtain exclusive access to locked queue
‘examples.queue’ in vhost ‘/’

404 Not Found¶

Description

The client attempted to use (publish to, delete, etc) an entity
(exchange, queue) that does not exist.

What might cause it

Application miscalculates queue or exchange name or tries to use an
entity that was deleted earlier

Example RabbitMQ error message

NOT_FOUND — no queue
‘queue_that_should_not_exist0.6798199937619038’ in vhost ‘/’

403 Access Refused¶

Description

The client attempted to work with a server entity to which it has no
access due to security settings.

What might cause it

Application tries to access a queue or exchange it has no permissions
for (or right kind of permissions, for example, write permissions)

Example RabbitMQ error message

ACCESS_REFUSED — access to queue ‘examples.channel_exception’ in
vhost ‘_testbed’ refused for user ‘_reader’

What to Read Next¶

The documentation is organized as a number of
guides, covering various topics.

We recommend that you read the following guides first, if possible, in
this order:

  • Troubleshooting

Tell Us What You Think!¶

Please take a moment to tell us what you think about this guide: Send an e-mail or raise an issue on Github.

Let us know what was unclear or what has not been covered. Maybe you
do not like the guide style or grammar or discover spelling
mistakes. Reader feedback is key to making the documentation better.

Socket error: could not connect to host.

Как избавиться от таких ошибок в rabbitMQ?

Во-первых, нужно посмотреть сколько для rabbit доступно открытых файлов (см. file descriptors и socket descriptors).

RabbitMQ настраиваем file descriptors и socket descriptors

Это можно сделать либо через админку на вкладке Overview. Либо через консоль с помощью команды sudo rabbitmqctl status:

$ sudo rabbitmqctl status | grep -A 2 file_descriptors 
 {file_descriptors,
     [{total_limit,10140},
      {total_used,8622},

Во-вторых, если количество открытых файлов приближается к максимально доступному (доступные ресурсы см. total_limit в консоли или available в админке), то это значит что ресурсы rabbitMQ заканчиваются и он может «отфутболивать» соединения. Это выглядит будто rabbitMQ подвис.

У rabbitMQ есть некоторые  проблемы с автоматическим освобождением ресурсов. Точнее дело в том, что rabbitMQ освобождает ресурсы в какие то моменты, а мы можем не дождаться этого момента и быть «отфутболенным».

Для увеличения количества свободных файлов нам могут помочь следующие действия:

  1. Перезагрузка rabbitMQ (как временное решение).
  2. Увеличение количества открытых файлов в настройках rabbitMQ. (для вступления изменений в силу все равно требуется перезапуск rabbit).

Как увеличить количество file descriptors / socket descriptors rabbitmq?

Это настраивается в файле /etc/default/rabbitmq-server. Вот всё его содержимое:

$ cat /etc/default/rabbitmq-server
# This file is sourced by /etc/init.d/rabbitmq-server. Its primary
# reason for existing is to allow adjustment of system limits for the
# rabbitmq-server process.
#
# Maximum number of open file handles. This will need to be increased
# to handle many simultaneous connections. Refer to the system
# documentation for ulimit (in man bash) for more information.
#

ulimit -S -n 1024

Нужно изменить единственный параметр ulimit -S -n <VALUE> и установить вместо <VALUE> значение 4096, 8192, 10240,  12288 или то, которое вам ближе. Затем перезапустить кролика.

После этого лимит открытых файлов должен увеличиться. Проверим, так ли это:

$ sudo rabbitmqctl status | grep -A 4 file_descriptors
 {file_descriptors,
     [{total_limit,99900},
      {total_used,5085},
      {sockets_limit,89908},
      {sockets_used,3386}]},

Если у вас не получаетcя задать большой ulimit:

/etc/init.d/rabbitmq-server: 11: ulimit: error setting limit (Invalid argument)

То сначала установите более высокий hard limit, затем soft limit. Т.к. софт лимит не может быть больше hard limit. Задаём в две строки:

ulimit -n 100000 #hard limit
ulimit -S -n 100000 #soft limit

Первый можно с -H.

Дата добавления:
7 лет назад

Понравилась статья? Поделить с друзьями:
  • Rabbit listener error handler
  • Rails translation missing error
  • Rabbit error destiny 2
  • Rails rescue error
  • Rails flash error