enigmare/v2-crawler
1904
1{"id":"stack-49788162","source":"stackoverflow","questionId":49788162,"title":"RabbitMQ - Send a JSON message","tags":["rabbitmq"],"text":"Title: RabbitMQ - Send a JSON message\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI send the following message with content type application/json:\n\nhttps://i.sstatic.net/xJWev.png\n\nHowever whene i get messages from the same RabbitMQ Web console, it shows the payload as String.\n\nhttps://i.sstatic.net/fquDs.png\n\nWhat am I doing wrong? Or am I fundamentally misunderstanding and the Payload is always of type String?\n\n========================================\n\nTop Answer:\nFrom `NodeJS` Context: \n\nIf we want to send JSON object as message, we may get the following error:\n\n The first argument must be of type string or an instance of Buffer,\n ArrayBuffer, or Array or an Array-like Object. Received an instance of\n Object\n\nSo, we can convert the JSON payload as string and parse it in the worker. We stringify the JSON object before sending the data the Queue-\n\n`let payloadAsString = JSON.stringify(payload);`\n\nAnd from worker's end, we can then JSON.parse\n\n```\nlet payload = JSON.parse(msg.content.toString());\n//then access the object as we normally do, i.e. :\nlet id = payload.id;\n```\n\n========================================\n\nCode:\n```text\nusing Newtonsoft.Json;\n```\n\n```text\nbyte[] messagebuffer = Encoding.Default.GetBytes(JsonConvert.SerializeObject(accountMessage) );\n```\n\n```text\nAccountMessage receivedMessage = JsonConvert.DeserializeObject<AccountMessage>(Encoding.UTF8.GetString(body));\n```\n\n```text\nlet payload = JSON.parse(msg.content.toString());\n//then access the object as we normally do, i.e. :\nlet id = payload.id;\n```\n\n```text\nNodeJS\n```\n\n```text\nlet payloadAsString = JSON.stringify(payload);\n```\n\n========================================\n\nComments:\n- This answer below is more consice : stackoverflow.com/a/60583488/5413849\n- The question was about understanding what payload is, which I answered. I dont see any problems here.\n- yes, but I found the other answer more consice. It gets to the point. Its Ok to understand what's going on, but its more important to know how to address the issue\n- Why do you think this question is about .NET?\n- I found this question when searching for how to send objects in Rabbit MQ, I use .Net, so someone else might find the solution I found useful here,.\n- Why is it better to serialize Json into a byte array, and not into just a string?\n- this one works for me and should be the accepted answer.","metadata":{"transformedAt":"2026-08-18T18:33:20.110Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":77,"estimatedTokens":591}}2{"id":"stack-37116615","source":"stackoverflow","questionId":37116615,"title":"Scale Socket.io vertically AND horizontally - what is the \"right\" way to go?","tags":["node.js","redis","socket.io","rabbitmq","scalability"],"text":"Title: Scale Socket.io vertically AND horizontally - what is the \"right\" way to go?\nTags: node.js, redis, socket.io, rabbitmq, scalability\nSource: Stack Overflow\n\nQuestion:\nI want to scale my Node.js Socket application **vertically** and **horizontally** and I haven´t found a sophisticated solution yet.\n\nMy application has two use-cases:\n\n- Broadcast messages from one user to all others\n\n- Push messages from one user to a subset of users\n\nOn one hand, I´ve read that I need Redis for **both** cases together with socket.io-redis\n\nOn the other hand, I´ve watched this video and read this SO answer where it says that **Redis** isn´t reliable and it´s **not guaranteed that the published messages will arrive**, so you should **only use it for clustering/vertical scaling** \n\nMicrosoft Azures solution to use **ServiceBus** is out of question, because I don´t want to use Azure.\n\nInstead of Redis, the guy recommends using **RabbitMQ** for horizontal scaling.\n\nFor the vertical scaling there is also **socket.io-clusterhub**, an IPC for node processes, but it seems to work only on **Socket.io Then there is this guy, who has implemented his own method to pass messages to other nodes via HTTP requests, which makes somehow sense. But why HTTP requests if you could also establish direct socket connections between servers, push the message to all servers simultaneously and overcome the delay of going from one server to another?\n\nAs a conclusion I thought maybe I could go with **Redis** on EACH server, just for the exchange of messages when clustering my application on multiple processes, together with **RabbitMQ** as a **S2S** communication solution.\n\n**But it seems a bit like an overkill to have one Redis per Server and another central RabbitMQ.**\n\nIs there any known shorter/better solution to scale Socket.io reliably in both directions?\n\nEDIT:\nI´ve tried using a single Redis Server for multiple Node.js Servers, where each of them uses Clustering via sticky-session over all cores. While the Clustering at its own works like a charm with redis, there seems to be a problem when using multiple servers. **Messages won´t arrive at the other nodes**.\n\n========================================\n\nComments:\n- RabbitMQ can cover both of your use cases (broadcast and multicast), and you can create a cluster of rabbitmq nodes to which you can later add/remove nodes as needed.\n- Hey can you add some snippets. I am also looking in the same direction as the question.","metadata":{"transformedAt":"2026-08-18T18:33:20.110Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":37,"estimatedTokens":619}}3{"id":"stack-18521196","source":"stackoverflow","questionId":18521196,"title":"Clarification of use-cases for Hadoop versus RabbitMQ+Celery","tags":["python","hadoop","rabbitmq","celery","distributed-computing"],"text":"Title: Clarification of use-cases for Hadoop versus RabbitMQ+Celery\nTags: python, hadoop, rabbitmq, celery, distributed-computing\nSource: Stack Overflow\n\nQuestion:\nI know that there are similar questions to this, such as:\n\n- https://stackoverflow.com/questions/8232194/pros-and-cons-of-celery-vs-disco-vs-hadoop-vs-other-distributed-computing-packag\n\n- Differentiate celery, kombu, PyAMQP and RabbitMQ/ironMQ\n\nbut I'm asking this because I'm looking for a more particular distinction backed by a couple of use-case examples, please. \n\nSo, I'm a python user who wants to make programs that either/both:\n\n- Are too large to\n\n- Take too long to\n\ndo on a single machine, and process them on multiple machines. I am familiar with the (single-machine) multiprocessing package in python, and I write mapreduce style code right now. I know that my function, for example, is easily parallelizable.\n\nIn asking my usual smart CS advice-givers, I have phrased my question as:\n\n\"I want to take a task, split it into a bunch of subtasks that are executed simultaneously on a bunch of machines, then those results to be aggregated and dealt with according to some other function, which may be a reduce, or may be instructions to serially add to a database, for example.\"\n\nAccording to this break-down of my use-case, I think I could equally well use Hadoop or a set of Celery workers + RabbitMQ broker. However, when I ask the sage advice-givers, they respond to me as if I'm totally crazy to look at Hadoop and Celery as comparable solutions. I've read quite a bit about Hadoop, and also about Celery---I think I have a pretty good grasp on what both do---what I do not seem to understand is:\n\n- Why are they considered so separate, so different?\n\n- Given that they seem to be received as totally different technologies---in what ways? What are the use cases that distinguish one from the other or are better for one than another?\n\n- What problems could be solved with both, and what areas would it be particularly foolish to use one or the other for?\n\n- Are there possibly better, simpler ways to achieve multiprocessing-like Pool.map()-functionality to multiple machines? Let's imagine my problem is not constrained by storage, but by CPU and RAM required for calculation, so there isn't an issue in having too little space to hold the results returned from the workers. (ie, I'm doing something like simulation where I need to generate a lot of things on the smaller machines seeded by a value from a database, but these are reduced before they return to the source machine/database.)\n\nI understand Hadoop is the big data standard, but Celery also looks well supported; I appreciate that it isn't java (the streaming API python has to use for hadoop looked uncomfortable to me), so I'd be inclined to use the Celery option.\n\n========================================\n\nComments:\n- I am investigating this, and I believe you're right, and this was super helpful. ZeroMQ is quite amazing so far. This is a weird porous place between distributed computing and proper message routing, network programming. Still trying to sort it out.\n- I love ZeroMQ. Thanks!\n- @Mittenchops Glad to have won you over. It takes some time to come over the initial hurdle, but well worth it.","metadata":{"transformedAt":"2026-08-18T18:33:20.110Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":43,"estimatedTokens":814}}4{"id":"stack-24241880","source":"stackoverflow","questionId":24241880,"title":"Dynamically add new queues, bindings and exchanges as beans","tags":["spring","rabbitmq","spring-amqp","spring-bean","spring-rabbit"],"text":"Title: Dynamically add new queues, bindings and exchanges as beans\nTags: spring, rabbitmq, spring-amqp, spring-bean, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI'm currently working on a rabbit-amqp implementation project and use spring-rabbit to programmatically setup all my queues, bindings and exchanges. (spring-rabbit-1.3.4 and spring-framework versions 3.2.0)\n\nThe declaration in a javaconfiguration class or xml-based configuration are both quite static in my opinion declared. I know how to set a more dynamic value (ex. a name) for a queue, exchange\nor binding like this:\n\n```\n@Configuration\npublic class serverConfiguration {\n private String queueName;\n ...\n @Bean\n public Queue buildQueue() {\n Queue queue = new Queue(this.queueName, false, false, true, getQueueArguments());\n buildRabbitAdmin().declareQueue(queue);\n return queue;\n }\n ...\n}\n```\n\nBut I was wondering if it was possible to create a undefined amount instances of Queue and\nregister them as beans like a factory registering all its instances.\n\nI'm not really familiar with the Spring @Bean annotation and its limitations, but I tried\n\n```\n@Configuration\npublic class serverConfiguration {\n private String queueName;\n ...\n @Bean\n @Scope(\"prototype\")\n public Queue buildQueue() {\n Queue queue = new Queue(this.queueName, false, false, true, getQueueArguments());\n buildRabbitAdmin().declareQueue(queue);\n return queue;\n }\n ...\n}\n```\n\nAnd to see if the multiple beans instances of Queue are registered I call: \n\n```\nMap queueBeans = ((ListableBeanFactory) applicationContext).getBeansOfType(Queue.class);\n```\n\nBut this will only return 1 mapping:\n\n```\nname of the method := the last created instance.\n```\n\nIs it possible to dynamically add beans during runtime to the SpringApplicationContext?\n\n========================================\n\nCode:\n```text\n@Configuration\npublic class serverConfiguration {\n private String queueName;\n ...\n @Bean\n public Queue buildQueue() {\n Queue queue = new Queue(this.queueName, false, false, true, getQueueArguments());\n buildRabbitAdmin().declareQueue(queue);\n return queue;\n }\n ...\n}\n```\n\n```text\n@Configuration\npublic class serverConfiguration {\n private String queueName;\n ...\n @Bean\n @Scope(\"prototype\")\n public Queue buildQueue() {\n Queue queue = new Queue(this.queueName, false, false, true, getQueueArguments());\n buildRabbitAdmin().declareQueue(queue);\n return queue;\n }\n ...\n}\n```\n\n```text\nMap<String, Queue> queueBeans = ((ListableBeanFactory) applicationContext).getBeansOfType(Queue.class);\n```\n\n```text\nname of the method := the last created instance.\n```\n\n```text\ncontext.getBeanFactory().registerSingleton(\"foo\", new Queue(\"foo\"));\n```\n\n```text\nadmin.initialize()\n```\n\n```text\n@Bean\n```\n\n========================================\n\nComments:\n- This sounds like a JMX task.\n- @Gary What about using `addQueues` in case of spring-boot. Could you extend your answer and explain details in case of `spring-boot`, please ?\n- `addQueues` only adds them to the container, it won't cause them to be declared on the broker; they have to be in the context for that. In a boot application, you can get a reference to the application context by `@Autowired` ing it or in the `main` method with `ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);`.","metadata":{"transformedAt":"2026-08-18T18:33:20.110Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":7,"totalLines":120,"estimatedTokens":836}}5{"id":"stack-52494492","source":"stackoverflow","questionId":52494492,"title":"How to test the connection to RabbitMQ Server?","tags":["cmd","rabbitmq","amqp"],"text":"Title: How to test the connection to RabbitMQ Server?\nTags: cmd, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI have the following problem: \nI need to test connection to **RabbitMQ Server** which operates on **AMQ Protocol**, and i need to do it using CMD or something similar, so i can execute the command from script. I don't know if it's possible,the only thing that I found on internet was testing connection through HTTP, and it doesn't work for me.So shortly, **I need cmd command that tests connection to RabbitMQ server which uses AMQP.**\n\nI hope that someone understands what is my problem, maybe i didn't described it good.\n\nThanks in advance.\n\n========================================\n\nTop Answer:\nI found another way to verify basic tcp connectivity using just netcat/telnet.\n\n```\nnc hostname 5672\n```\n\nOR\n\n```\ntelnet hostname 5672\n```\n\nType `HELO` and hit enter 4 times.\n\nYou should see a response of `AMQP`.\n\nexample:\n\n```\n> nc rabbitserver 5672\nHELO\n\nAMQP\n```\n\nThe other tools mentioned here would verify deeper compatibility between the client and server as well as validate other protocols. If you simply need to make sure that port 5672 is open in the firewall between the client and server then this basic test should be enough.\n\n========================================\n\nCode:\n```text\nrabbitmqctl list_connections\n```\n\n```bash\nnc hostname 5672\n```\n\n```bash\ntelnet hostname 5672\n```\n\n```bash\n> nc rabbitserver 5672\nHELO\n\n\n\nAMQP\n```\n\n```text\nHELO\n```\n\n```text\nAMQP\n```\n\n```text\n#!/usr/bin/env python3\n# Check connection to the RabbitMQ server\n\n# import parser for command-line options\nimport argparse\n# import a pure-Python implementation of the AMQP 0-9-1 \nimport pika\nimport ssl\n\n# define and parse command-line options\nparser = argparse.ArgumentParser(description='Check connection to RabbitMQ server')\nparser.add_argument('--server', required=True, help='Define RabbitMQ server')\nparser.add_argument('--virtual_host', default='/', help='Define virtual host')\nparser.add_argument('--ssl', action='store_true', help='Enable SSL (default: %(default)s)')\nparser.add_argument('--port', type=int, default=5672, help='Define port (default: %(default)s)')\nparser.add_argument('--username', default='guest', help='Define username (default: %(default)s)')\nparser.add_argument('--password', default='guest', help='Define password (default: %(default)s)')\nargs = vars(parser.parse_args())\n\n# set amqp credentials\ncredentials = pika.PlainCredentials(args['username'], args['password'])\n\nif args['ssl']:\n context = ssl.create_default_context()\n ssl_options = pika.SSLOptions(context, args['server'])\nelse:\n ssl_options = None\n\nparameters = pika.ConnectionParameters(host=args['server'], port=args['port'], virtual_host=args['virtual_host'], credentials=credentials, ssl_options=ssl_options)\n\n# try to establish connection and check its status\ntry:\n connection = pika.BlockingConnection(parameters)\n if connection.is_open:\n print('OK')\n connection.close()\n exit(0)\nexcept Exception as error:\n print('Error:', error.__class__.__name__)\n exit(1)\n```\n\n```bash\n#!/usr/bin/env bash\n\n: ${RMQHOST:=\"localhost\"}\n: ${RMQPORT:=\"5672\"}\n\ncheck_rabbitmq() {\n exec 3>&- 3<>/dev/tcp/${RMQHOST}/${RMQPORT} || return 1\n printf '%s\\n\\n\\n\\n' \"HELO\" >&3 || return 1\n local ret=$(tr -d '\\0' <&3 || return 1)\n [[ x\"${ret}\" =~ x\"AMQP\" ]] && return 0 || return 1\n} 2>/dev/null\n\ncheck_rabbitmq && echo OK || echo NOK\n```\n\n========================================\n\nComments:\n- Have you looked at `Get-RabbitMQConnection` from github.com/mariuszwojcik/RabbitMQTools? A modern-day machine running cmd.exe cam also have (probably already has) powershell.exe on it.\n- The post that you provided here actually made a little progress, because i didn't know about this repository,but still this is not really the solution for my problem.\n- In a cmd.exe shell, would the command `powershell -NoProfile -Command \"Get-RabbitMQConnection ...\"` identify if RabbitMQ is working?\n- After trying to execute the command that you provided here, I get this error `Get-RabbitMQConnection : The term 'Get-RabbitMQConnection' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + Get-RabbitMQConnection + ~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Get-RabbitMQConnection:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException`\n- Did you install `RabbitMQTools`? See the `Getting Started` section on that page.\n- I find out what was the problem, and its kinda silly. You need to establish connection first, but its kinda tricky to do on local machine, simply said you need to simulate communication between ,in this case, two scripts.Then its easy to list the connections with command `rabbitmqctl list_connections`. And i've done it without any of those RabbitMQTools that you mentioned.\n- Glad to hear you found an answer. `RabbitMQTools` might still be useful.\n- OMG... This needs to be part of the rabbitmq documentation! You can't find this anywhere. One liner in case anyone is interested `printf \"HELO\\n\\n\\n\\n\\n\\n\\n\" | nc rabbit-server-ip-or-domain 5672`\n- Or better yet... just returns `printf \"\\n\\n\\n\\n\\n\\n\\n\\n\" | nc rabbit-server-ip-or-domain 5672`\n- I've used the nc, telnet, etc. connection tests and they are great to make sure you can get to the broker. However, at my work, they limit firewalls by protocols as well. These solutions will not test the AMQP protocol piece of it. Just a word of caution when everything seems OK but you still cannot get your actual app to connect.\n- And if you are testing through a TLS connection: `openssl s_client -connect servername:port -CAfile path_to_root_cert_file` If TLS negotiation appears to be successful (you see: Verify return code: 0 (ok)), then you type HELO and press enter 4 times. You should get AMQP as response.","metadata":{"transformedAt":"2026-08-18T18:33:20.110Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":147,"estimatedTokens":1500}}6{"id":"stack-752214","source":"stackoverflow","questionId":752214,"title":"PHP Daemon/worker environment","tags":["php","parallel-processing","daemon","rabbitmq","process-control"],"text":"Title: PHP Daemon/worker environment\nTags: php, parallel-processing, daemon, rabbitmq, process-control\nSource: Stack Overflow\n\nQuestion:\nProblem: I want to implement several php-worker processes who are listening on a MQ-server queue for asynchronous jobs. The problem now is that simply running this processes as daemons on a server doesn't really give me any level of control over the instances (Load, Status, locked up)...except maybe for dumping ps -aux.\nBecause of that I'm looking for a runtime environment of some kind that lets me monitor and control the instances, either on system (process) level or on a higher layer (some kind of Java-style appserver)\n\nAny pointers?\n\n========================================\n\nTop Answer:\nIt sounds like you already have a MQ up and running on a *nix system and just want a way to manage workers.\n\nA very simple way to do so is to use GNU screen. To start 10 workers you can use:\n\n```\n#!/bin/sh\nfor x in `seq 1 10` ; do\nscreen -dmS worker_$x php /path/to/script.php worker$x\nend\n```\n\nThis will start 10 workers in the background using screens named worker_1,2,3 and so on.\n\nYou can reattach to the screens by running screen -r worker_ and list the running workers by using screen -list.\n\nFor more info this guide may be of help:\nhttp://www.kuro5hin.org/story/2004/3/9/16838/14935\n\nAlso try:\n\n- screen --help\n\n- man screen\n\n- or google.\n\nFor production servers I would normally recommend using the normal system startup scripts, but I have been running screen commands from the startup scripts for years with no problems.\n\n========================================\n\nCode:\n```text\n<?\ndefine('WANT_PROCESSORS', 5);\ndefine('PROCESSOR_EXECUTABLE', '/path/to/your/processor');\nset_time_limit(0);\n$cycles = 0;\n$run = true;\n$reload = false;\ndeclare(ticks = 30);\n\nfunction signal_handler($signal) {\n switch($signal) {\n case SIGTERM :\n global $run;\n $run = false;\n break;\n case SIGHUP :\n global $reload;\n $reload = true;\n break;\n } \n}\n\npcntl_signal(SIGTERM, 'signal_handler');\npcntl_signal(SIGHUP, 'signal_handler');\n\nfunction spawn_processor() {\n $pid = pcntl_fork();\n if($pid) {\n global $processors;\n $processors[] = $pid;\n } else {\n if(posix_setsid() == -1)\n die(\"Forked process could not detach from terminal\\n\");\n fclose(stdin);\n fclose(stdout);\n fclose(stderr);\n pcntl_exec(PROCESSOR_EXECUTABLE);\n die('Failed to fork ' . PROCESSOR_EXECUTABLE . \"\\n\");\n }\n}\n\nfunction spawn_processors() {\n global $processors;\n if($processors)\n kill_processors();\n $processors = array();\n for($ix = 0; $ix < WANT_PROCESSORS; $ix++)\n spawn_processor();\n}\n\nfunction kill_processors() {\n global $processors;\n foreach($processors as $processor)\n posix_kill($processor, SIGTERM);\n foreach($processors as $processor)\n pcntl_waitpid($processor);\n unset($processors);\n}\n\nfunction check_processors() {\n global $processors;\n $valid = array();\n foreach($processors as $processor) {\n pcntl_waitpid($processor, $status, WNOHANG);\n if(posix_getsid($processor))\n $valid[] = $processor;\n }\n $processors = $valid;\n if(count($processors) > WANT_PROCESSORS) {\n for($ix = count($processors) - 1; $ix >= WANT_PROCESSORS; $ix--)\n posix_kill($processors[$ix], SIGTERM);\n for($ix = count($processors) - 1; $ix >= WANT_PROCESSORS; $ix--)\n pcntl_waitpid($processors[$ix]);\n } elseif(count($processors) < WANT_PROCESSORS) {\n for($ix = count($processors); $ix < WANT_PROCESSORS; $ix++)\n spawn_processor();\n }\n}\n\nspawn_processors();\n\nwhile($run) {\n $cycles++;\n if($reload) {\n $reload = false;\n kill_processors();\n spawn_processors();\n } else {\n check_processors();\n }\n usleep(150000);\n}\nkill_processors();\npcntl_wait();\n?>\n```\n\n```text\n#!/bin/sh\nfor x in `seq 1 10` ; do\nscreen -dmS worker_$x php /path/to/script.php worker$x\nend\n```\n\n```text\n<?php\n\ninclude_once dirname( __FILE__ ) . '/path/to/bootstrap.php';\n\ndefine('WANT_PROCESSORS', 5);\ndefine('PROCESSOR_EXECUTABLE', '' . dirname(__FILE__) . '/path/to/worker.php');\nset_time_limit(0);\n\n$run = true;\n$reload = false;\ndeclare(ticks = 30);\n\nfunction restore_processors_state()\n{\n global $processors;\n\n $redis = Zend_Registry::get('redis');\n $pids = $redis->hget('worker_procs', 'pids');\n\n if( !$pids )\n {\n $processors = array();\n }\n else\n {\n $processors = json_decode($pids, true);\n }\n}\n\nfunction save_processors_state()\n{\n global $processors;\n\n $redis = Zend_Registry::get('redis');\n $redis->hset('worker_procs', 'pids', json_encode($processors));\n}\n\nfunction spawn_processor() {\n $pid = pcntl_fork();\n if($pid) {\n global $processors;\n $processors[] = $pid;\n } else {\n if(posix_setsid() == -1)\n die(\"Forked process could not detach from terminal\\n\");\n fclose(STDIN);\n fclose(STDOUT);\n fclose(STDERR);\n pcntl_exec('/usr/bin/php', array(PROCESSOR_EXECUTABLE));\n die('Failed to fork ' . PROCESSOR_EXECUTABLE . \"\\n\");\n }\n}\n\nfunction spawn_processors() {\n restore_processors_state();\n\n check_processors();\n\n save_processors_state();\n}\n\nfunction kill_processors() {\n global $processors;\n foreach($processors as $processor)\n posix_kill($processor, SIGTERM);\n foreach($processors as $processor)\n pcntl_waitpid($processor, $trash);\n unset($processors);\n}\n\nfunction check_processors() {\n global $processors;\n $valid = array();\n foreach($processors as $processor) {\n pcntl_waitpid($processor, $status, WNOHANG);\n if(posix_getsid($processor))\n $valid[] = $processor;\n }\n $processors = $valid;\n if(count($processors) > WANT_PROCESSORS) {\n for($ix = count($processors) - 1; $ix >= WANT_PROCESSORS; $ix--)\n posix_kill($processors[$ix], SIGTERM);\n for($ix = count($processors) - 1; $ix >= WANT_PROCESSORS; $ix--)\n pcntl_waitpid($processors[$ix], $trash);\n }\n elseif(count($processors) < WANT_PROCESSORS) {\n for($ix = count($processors); $ix < WANT_PROCESSORS; $ix++)\n spawn_processor();\n }\n}\n\nif( isset($argv) && count($argv) > 1 ) {\n if( $argv[1] == 'kill' ) {\n restore_processors_state();\n kill_processors();\n save_processors_state();\n\n exit(0);\n }\n}\n\nspawn_processors();\n```\n\n```text\nredis\n```\n\n```text\nkill\n```\n\n```text\nphp script.php kill\n```\n\n========================================\n\nComments:\n- Also see: symfony.com/doc/master/components/process.html\n- Where did you get this? Open source project or your own code? Any documentation or explanation of what exactly is going on here?\n- @gAMBOOKa: You should write that as a separate answer rather than a comment. :)\n- The spawning-aspect isn't a big issue imho because the number of workers is depending on the system performance which is usually constant. More important would be the monitoring aspect of the individual worker status (crashed, whatever). One tool I just discovered for this might be DJBs deamontools\n- That's one option. For monitoring you could also use flock()-ed PID files. Upon crash all locks are released.","metadata":{"transformedAt":"2026-08-18T18:33:20.111Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":274,"estimatedTokens":1839}}7{"id":"stack-28467316","source":"stackoverflow","questionId":28467316,"title":"RabbitMQ: How to prevent QueueDeclare to automatically generate a new Queue","tags":["c#","rabbitmq","message-queue"],"text":"Title: RabbitMQ: How to prevent QueueDeclare to automatically generate a new Queue\nTags: c#, rabbitmq, message-queue\nSource: Stack Overflow\n\nQuestion:\nWith RabbitMQ I am doing something similar to this:\n\n```\nchannel.QueueDeclare(QueueName, true, false, false, null);\n```\n\nBy default RabbitMQ creates a new queue if none of the existing matches the name provided. I would like to have an exception thrown instead.\nIs that possible?\n\nThanks\n\n========================================\n\nTop Answer:\nPassive declarations are made for this. Use `IModel.QueueDeclarePassive()`:\n\n```\nmodel.QueueDeclarePassive(\"queue-name\");\n```\n\nThis does nothing if the queue already exists, and raises an exception otherwise.\n\n========================================\n\nCode:\n```text\nchannel.QueueDeclare(QueueName, true, false, false, null);\n```\n\n```cs\ntry\n{\n channel.QueueBind(queueName, exchange, routingKey);\n}\ncatch (RabbitMQ.Client.Exceptions.OperationInterruptedException ex)\n{\n // Queue not found\n}\n```\n\n```cs\nmodel.QueueDeclarePassive(\"queue-name\");\n```\n\n```text\nIModel.QueueDeclarePassive()\n```\n\n========================================\n\nComments:\n- What are you trying to implement? Have you tried using a Passive declare?\n- I just want to use a queue without declaring it if missing. I will investigate about the Passive declare. Thank you\n- If the queue is missing, then you have to declare it, there's no way around it.\n- if the queue exists it will raise an exception, than it's needed to use try catch. ` try{ ch.queueDeclarePassive(queue); } catch (java.io.IOException ex){ }`","metadata":{"transformedAt":"2026-08-18T18:33:20.111Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":60,"estimatedTokens":394}}8{"id":"stack-24309230","source":"stackoverflow","questionId":24309230,"title":"How does RabbitMQ send messages to consumers?","tags":["rabbitmq","amqp"],"text":"Title: How does RabbitMQ send messages to consumers?\nTags: rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI am a newbie to RabbitMQ, hence need guidance on a basic question: \n\nDoes RabbitMQ send messages to consumer as they arrive? \n\n*OR*\n\nDoes RabbitMQ send messages to consumer as they become available? \n\n- At message consumption endpoint, I am using `com.rabbitmq.client.QueueingConsumer`.\nLooking at the sprint client source code, I could figure out that \n\n- `QueueingConsumer` keeps listening on socket for any messages the broker sends to it\n\n- Any message that is received is parsed and stored as `Delivery` in a `LinkedBlockingQueue` encapsulated inside the QueueingConsumer.\n\n- This implies that even if the message processing endpoint is busy, messages will be pushed to QueueingConsumer\n\nIs this understanding right?\n\n========================================\n\nTop Answer:\nI think best answer is product's own answer. As RMQ has both push + pull mechanism defined as part of the protocol. Have a look : https://www.rabbitmq.com/tutorials/amqp-concepts.html\n\n========================================\n\nCode:\n```text\ncom.rabbitmq.client.QueueingConsumer\n```\n\n```text\nQueueingConsumer\n```\n\n```text\nDelivery\n```\n\n```text\nLinkedBlockingQueue\n```\n\n========================================\n\nComments:\n- Is it more like 'pull queue or push queue' question?\n- Does RabbitMQ send messages to consumer as they arrive? OR Does RabbitMQ send messages to consumer as they become available?","metadata":{"transformedAt":"2026-08-18T18:33:20.111Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":53,"estimatedTokens":372}}9{"id":"stack-51961253","source":"stackoverflow","questionId":51961253,"title":"RabbitMQ not starting with message \"init terminating in do_boot, noproc\" on Ubuntu 18.04","tags":["rabbitmq","erlang","dump"],"text":"Title: RabbitMQ not starting with message \"init terminating in do_boot, noproc\" on Ubuntu 18.04\nTags: rabbitmq, erlang, dump\nSource: Stack Overflow\n\nQuestion:\nI cannot seem to start or install my RabbitMQ server anymore for my Ubuntu 18.04 anymore. I tried to remove and install it again, but it cannot finish the install because configuration fails. When I try to run `sudo apt-get install --fix-broken`. This is the result of it failing:\n\n```\nReading package lists... Done\nBuilding dependency tree \nReading state information... Done\n0 upgraded, 0 newly installed, 0 to remove and 61 not upgraded.\n1 not fully installed or removed.\nAfter this operation, 0 B of additional disk space will be used.\nSetting up rabbitmq-server (3.6.10-1) ...\nJob for rabbitmq-server.service failed because the control process exited with error code.\nSee \"systemctl status rabbitmq-server.service\" and \"journalctl -xe\" for details.\ninvoke-rc.d: initscript rabbitmq-server, action \"start\" failed.\n● rabbitmq-server.service - RabbitMQ Messaging Server\n Loaded: loaded (/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: enabled)\n Active: failed (Result: exit-code) since Wed 2018-08-22 09:16:51 EEST; 5ms ago\n Process: 20997 ExecStartPost=/usr/lib/rabbitmq/bin/rabbitmq-server-wait (code=exited, status=70)\n Process: 20996 ExecStart=/usr/sbin/rabbitmq-server (code=exited, status=0/SUCCESS)\n Main PID: 20996 (code=exited, status=0/SUCCESS)\n\nelo 22 09:16:48 ubuntu-dev systemd[1]: Starting RabbitMQ Messaging Server...\nelo 22 09:16:49 ubuntu-dev rabbitmq[20997]: Waiting for 'rabbit@ubuntu-dev'\nelo 22 09:16:49 ubuntu-dev rabbitmq[20997]: pid is 21001\nelo 22 09:16:51 ubuntu-dev rabbitmq[20997]: Error: process_not_running\nelo 22 09:16:51 ubuntu-dev systemd[1]: rabbitmq-server.service: Control process exited, code=exited status=70\nelo 22 09:16:51 ubuntu-dev systemd[1]: rabbitmq-server.service: Failed with result 'exit-code'.\nelo 22 09:16:51 ubuntu-dev systemd[1]: Failed to start RabbitMQ Messaging Server.\ndpkg: error processing package rabbitmq-server (--configure):\n installed rabbitmq-server package post-installation script subprocess returned error exit status 1\nErrors were encountered while processing:\n rabbitmq-server\nE: Sub-process /usr/bin/dpkg returned an error code (1)\n```\n\nThen when checking the log files they doesn't provide much more information either. Here is startup_err log file content:\n\n```\ninit terminating in do_boot (noproc)\n\nCrash dump is being written to: erl_crash.dump...done'\n```\n\nAnd here is startup_log file content:\n\n```\nBOOT FAILED\n===========\n\nError description:\n noproc\n\nLog files (may contain more information):\n /var/log/rabbitmq/rabbit.log\n /var/log/rabbitmq/rabbit-sasl.log\n\nStack trace:\n [{gen,do_for_proc,2,[{file,\"gen.erl\"},{line,228}]},\n {gen_event,rpc,2,[{file,\"gen_event.erl\"},{line,239}]},\n {rabbit,ensure_working_log_handlers,0,\n [{file,\"src/rabbit.erl\"},{line,842}]},\n {rabbit,'-boot/0-fun-0-',0,[{file,\"src/rabbit.erl\"},{line,281}]},\n {rabbit,start_it,1,[{file,\"src/rabbit.erl\"},{line,417}]},\n {init,start_em,1,[]},\n {init,do_boot,3,[]}]\n\n=INFO REPORT==== 22-Aug-2018::09:16:49.691453 ===\nError description:\n noproc\n\nLog files (may contain more information):\n /var/log/rabbitmq/rabbit.log\n /var/log/rabbitmq/rabbit-sasl.log\n\nStack trace:\n [{gen,do_for_proc,2,[{file,\"gen.erl\"},{line,228}]},\n {gen_event,rpc,2,[{file,\"gen_event.erl\"},{line,239}]},\n {rabbit,ensure_working_log_handlers,0,\n [{file,\"src/rabbit.erl\"},{line,842}]},\n {rabbit,'-boot/0-fun-0-',0,[{file,\"src/rabbit.erl\"},{line,281}]},\n {rabbit,start_it,1,[{file,\"src/rabbit.erl\"},{line,417}]},\n {init,start_em,1,[]},\n {init,do_boot,3,[]}]\n\n{\"init terminating in do_boot\",noproc}\n```\n\nThe other log files it claim to use for logging are empty. For example log file `rabbit@ubuntu-dev.log` and `rabbit@ubuntu-dev-sasl.log`.\n\nI also found this post, which explains to check your hostname in /etc/hostname file but I checked and it's correct.\n\n```\nkazhu@ubuntu-dev:/var/log/rabbitmq$ cat /etc/hostname\nubuntu-dev\n```\n\nI also checked RabbitMQ troubleshoot guide and they said to check log folder permissions and they are right to my eye:\n\n```\nkazhu@ubuntu-dev:/var/log/rabbitmq$ ll\ntotal 48\ndrwxr-xr-x 2 rabbitmq rabbitmq 4096 kesä 14 06:16 ./\ndrwxrwxr-x 16 root syslog 4096 elo 22 00:09 ../\n-rw-r--r-- 1 rabbitmq rabbitmq 0 kesä 14 06:16 'rabbit@ubuntu-dev.log'\n-rw-r--r-- 1 rabbitmq rabbitmq 5247 kesä 14 06:16 'rabbit@ubuntu-dev.log.1'\n-rw-r--r-- 1 rabbitmq rabbitmq 954 touko 28 08:36 'rabbit@ubuntu-dev.log.2.gz'\n-rw-r--r-- 1 rabbitmq rabbitmq 768 touko 21 07:11 'rabbit@ubuntu-dev.log.3.gz'\n-rw-r--r-- 1 rabbitmq rabbitmq 708 touko 16 00:12 'rabbit@ubuntu-dev.log.4.gz'\n-rw-r--r-- 1 rabbitmq rabbitmq 955 touko 7 07:26 'rabbit@ubuntu-dev.log.5.gz'\n-rw-r--r-- 1 rabbitmq rabbitmq 4264 huhti 22 00:07 'rabbit@ubuntu-dev.log.6.gz'\n-rw-r--r-- 1 rabbitmq rabbitmq 0 huhti 17 15:58 'rabbit@ubuntu-dev-sasl.log'\n-rw-r--r-- 1 rabbitmq rabbitmq 95 elo 22 09:16 startup_err\n-rw-r--r-- 1 rabbitmq rabbitmq 1212 elo 22 09:16 startup_log\n```\n\nGuide also stated that perl chrash dump file contains detailed information of the problem and requires Erlang expertises, which I don't have. So decided to upload the file to my Dropbox for you to see.\n\nCan somebody help me solve this? I've tried some time myself but gave up because cannot figure out what the problem seems to be :/\n\n========================================\n\nCode:\n```text\nReading package lists... Done\nBuilding dependency tree \nReading state information... Done\n0 upgraded, 0 newly installed, 0 to remove and 61 not upgraded.\n1 not fully installed or removed.\nAfter this operation, 0 B of additional disk space will be used.\nSetting up rabbitmq-server (3.6.10-1) ...\nJob for rabbitmq-server.service failed because the control process exited with error code.\nSee \"systemctl status rabbitmq-server.service\" and \"journalctl -xe\" for details.\ninvoke-rc.d: initscript rabbitmq-server, action \"start\" failed.\n● rabbitmq-server.service - RabbitMQ Messaging Server\n Loaded: loaded (/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: enabled)\n Active: failed (Result: exit-code) since Wed 2018-08-22 09:16:51 EEST; 5ms ago\n Process: 20997 ExecStartPost=/usr/lib/rabbitmq/bin/rabbitmq-server-wait (code=exited, status=70)\n Process: 20996 ExecStart=/usr/sbin/rabbitmq-server (code=exited, status=0/SUCCESS)\n Main PID: 20996 (code=exited, status=0/SUCCESS)\n\nelo 22 09:16:48 ubuntu-dev systemd[1]: Starting RabbitMQ Messaging Server...\nelo 22 09:16:49 ubuntu-dev rabbitmq[20997]: Waiting for 'rabbit@ubuntu-dev'\nelo 22 09:16:49 ubuntu-dev rabbitmq[20997]: pid is 21001\nelo 22 09:16:51 ubuntu-dev rabbitmq[20997]: Error: process_not_running\nelo 22 09:16:51 ubuntu-dev systemd[1]: rabbitmq-server.service: Control process exited, code=exited status=70\nelo 22 09:16:51 ubuntu-dev systemd[1]: rabbitmq-server.service: Failed with result 'exit-code'.\nelo 22 09:16:51 ubuntu-dev systemd[1]: Failed to start RabbitMQ Messaging Server.\ndpkg: error processing package rabbitmq-server (--configure):\n installed rabbitmq-server package post-installation script subprocess returned error exit status 1\nErrors were encountered while processing:\n rabbitmq-server\nE: Sub-process /usr/bin/dpkg returned an error code (1)\n```\n\n```text\ninit terminating in do_boot (noproc)\n\nCrash dump is being written to: erl_crash.dump...done'\n```\n\n```text\nBOOT FAILED\n===========\n\nError description:\n noproc\n\nLog files (may contain more information):\n /var/log/rabbitmq/rabbit.log\n /var/log/rabbitmq/rabbit-sasl.log\n\nStack trace:\n [{gen,do_for_proc,2,[{file,\"gen.erl\"},{line,228}]},\n {gen_event,rpc,2,[{file,\"gen_event.erl\"},{line,239}]},\n {rabbit,ensure_working_log_handlers,0,\n [{file,\"src/rabbit.erl\"},{line,842}]},\n {rabbit,'-boot/0-fun-0-',0,[{file,\"src/rabbit.erl\"},{line,281}]},\n {rabbit,start_it,1,[{file,\"src/rabbit.erl\"},{line,417}]},\n {init,start_em,1,[]},\n {init,do_boot,3,[]}]\n\n=INFO REPORT==== 22-Aug-2018::09:16:49.691453 ===\nError description:\n noproc\n\nLog files (may contain more information):\n /var/log/rabbitmq/rabbit.log\n /var/log/rabbitmq/rabbit-sasl.log\n\nStack trace:\n [{gen,do_for_proc,2,[{file,\"gen.erl\"},{line,228}]},\n {gen_event,rpc,2,[{file,\"gen_event.erl\"},{line,239}]},\n {rabbit,ensure_working_log_handlers,0,\n [{file,\"src/rabbit.erl\"},{line,842}]},\n {rabbit,'-boot/0-fun-0-',0,[{file,\"src/rabbit.erl\"},{line,281}]},\n {rabbit,start_it,1,[{file,\"src/rabbit.erl\"},{line,417}]},\n {init,start_em,1,[]},\n {init,do_boot,3,[]}]\n\n\n{\"init terminating in do_boot\",noproc}\n```\n\n```text\nkazhu@ubuntu-dev:/var/log/rabbitmq$ cat /etc/hostname\nubuntu-dev\n```\n\n```text\nkazhu@ubuntu-dev:/var/log/rabbitmq$ ll\ntotal 48\ndrwxr-xr-x 2 rabbitmq rabbitmq 4096 kesä 14 06:16 ./\ndrwxrwxr-x 16 root syslog 4096 elo 22 00:09 ../\n-rw-r--r-- 1 rabbitmq rabbitmq 0 kesä 14 06:16 'rabbit@ubuntu-dev.log'\n-rw-r--r-- 1 rabbitmq rabbitmq 5247 kesä 14 06:16 'rabbit@ubuntu-dev.log.1'\n-rw-r--r-- 1 rabbitmq rabbitmq 954 touko 28 08:36 'rabbit@ubuntu-dev.log.2.gz'\n-rw-r--r-- 1 rabbitmq rabbitmq 768 touko 21 07:11 'rabbit@ubuntu-dev.log.3.gz'\n-rw-r--r-- 1 rabbitmq rabbitmq 708 touko 16 00:12 'rabbit@ubuntu-dev.log.4.gz'\n-rw-r--r-- 1 rabbitmq rabbitmq 955 touko 7 07:26 'rabbit@ubuntu-dev.log.5.gz'\n-rw-r--r-- 1 rabbitmq rabbitmq 4264 huhti 22 00:07 'rabbit@ubuntu-dev.log.6.gz'\n-rw-r--r-- 1 rabbitmq rabbitmq 0 huhti 17 15:58 'rabbit@ubuntu-dev-sasl.log'\n-rw-r--r-- 1 rabbitmq rabbitmq 95 elo 22 09:16 startup_err\n-rw-r--r-- 1 rabbitmq rabbitmq 1212 elo 22 09:16 startup_log\n```\n\n```text\nsudo apt-get install --fix-broken\n```\n\n```text\nrabbit@ubuntu-dev.log\n```\n\n```text\nrabbit@ubuntu-dev-sasl.log\n```\n\n```text\nsudo apt purge rabbitmq-server erlang\n```\n\n```text\napt list | grep erlang\n```\n\n```text\nsudo apt install rabbitmq-server\n```\n\n```text\n/etc/apt/sources.list.d/\n```\n\n```text\nsudo apt update\n```\n\n```text\nsudo apt install rabbitmq-server\n```\n\n========================================\n\nComments:\n- Can you please the steps of problem resolution?\n- I updated what I remember. it has been so long since I solved this. Hope this helps and good luck!\n- Thanks a lot, buddy @Kazooie, The rabbitMQ's own site made everything very easy just in a single bash script. that's IT. Sorry, I insisted you edit and write the above answer once again after 2 years. Thanks once again.","metadata":{"transformedAt":"2026-08-18T18:33:20.111Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":14,"totalLines":271,"estimatedTokens":2608}}10{"id":"stack-19912344","source":"stackoverflow","questionId":19912344,"title":"How to delete a queue in rabbit mq","tags":["queue","rabbitmq"],"text":"Title: How to delete a queue in rabbit mq\nTags: queue, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am using rabbitmctl using pika library.\nI use the following code to create a Producer\n\n```\n#!/usr/bin/env python\nimport pika\nimport time\nimport json\nimport datetime\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost'))\nchannel = connection.channel()\n\nchannel.queue_declare(queue='hello')\n\ndef callback(ch, method, properties, body):\n #print \" current time: %s \" % (str(int((time.time())*1000)))\n\n print body\n\nchannel.basic_consume(callback,\n queue='hello',\n no_ack=True)\n\nchannel.start_consuming()\n```\n\nSince I create an existing queue everytime (Over-write the creation of queue in case if queue is not created) The queue has been corrupted due to this.and now I want to delete the queue..how do i do that?\n\n========================================\n\nTop Answer:\nThe detailed answer is as follows (with reference to above very helpful and useful answer)\n\n```\nimport pika\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n 'localhost'))\nchannel = connection.channel()\n\nchannel.queue_delete(queue='hello')\n\nconnection.close()\n```\n\n========================================\n\nCode:\n```text\n#!/usr/bin/env python\nimport pika\nimport time\nimport json\nimport datetime\n\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost'))\nchannel = connection.channel()\n\n\n\nchannel.queue_declare(queue='hello')\n\ndef callback(ch, method, properties, body):\n #print \" current time: %s \" % (str(int((time.time())*1000)))\n\n print body\n\nchannel.basic_consume(callback,\n queue='hello',\n no_ack=True)\n\n\nchannel.start_consuming()\n```\n\n```text\nchannel.queue_delete(queue='hello')\n```\n\n```text\nimport pika\n\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n 'localhost'))\nchannel = connection.channel()\n\n\nchannel.queue_delete(queue='hello')\n\nconnection.close()\n```\n\n```text\n$ sudo rabbitmq-plugins enable rabbitmq_management\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.111Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":105,"estimatedTokens":514}}11{"id":"stack-69828547","source":"stackoverflow","questionId":69828547,"title":"PRECONDITION_FAILED: Delivery Acknowledge Timeout on Celery & RabbitMQ with Gevent and concurrency","tags":["kubernetes","rabbitmq","celery"],"text":"Title: PRECONDITION_FAILED: Delivery Acknowledge Timeout on Celery & RabbitMQ with Gevent and concurrency\nTags: kubernetes, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI just switched from ForkPool to gevent with concurrency (5) as the pool method for Celery workers running in Kubernetes pods. After the switch I've been getting a non recoverable erro in the worker:\n\n`amqp.exceptions.PreconditionFailed: (0, 0): (406) PRECONDITION_FAILED - delivery acknowledgement on channel 1 timed out. Timeout value used: 1800000 ms. This timeout value can be configured, see consumers doc guide to learn more`\n\nThe broker logs gives basically the same message:\n\n`2021-11-01 22:26:17.251 [warning] Consumer None4 on channel 1 has timed out waiting for delivery acknowledgement. Timeout used: 1800000 ms. This timeout value can be configured, see consumers doc guide to learn more`\n\nI have the `CELERY_ACK_LATE` set up, but was not familiar with the necessity to set a timeout for the acknowledgement period. And that never happened before using processes. Tasks can be fairly long (60-120 seconds sometimes), but I can't find a specific setting to allow that.\n\nI've read in another post in other forum a user who set the timeout on the broker configuration to a huge number (like 24 hours), and was also having the same problem, so that makes me think there may be something else related to the issue.\n\nAny ideas or suggestions on how to make worker more resilient?\n\n========================================\n\nTop Answer:\nThe accepted answer is the correct answer. However, if you have an existing RabbitMQ server running and do not want to restart it, you can dynamically set the configuration value by running the following command on the RabbitMQ server:\n\n`rabbitmqctl eval 'application:set_env(rabbit, consumer_timeout, 36000000).'`\n\nThis will set the new timeout to 10 hrs (36000000ms). For this to take effect, you need to restart your workers though. Existing worker connections will continue to use the old timeout.\n\nYou can check the current configured timeout value as well:\n\n`rabbitmqctl eval 'application:get_env(rabbit, consumer_timeout).'`\n\nIf you are running RabbitMQ via Docker image, here's how to set the value: Simply add `-e RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS=\"-rabbit consumer_timeout 36000000\"` to your `docker run` OR set the environment `RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS` to `\"-rabbit consumer_timeout 36000000\"`.\n\nHope this helps!\n\n========================================\n\nCode:\n```text\namqp.exceptions.PreconditionFailed: (0, 0): (406) PRECONDITION_FAILED - delivery acknowledgement on channel 1 timed out. Timeout value used: 1800000 ms. This timeout value can be configured, see consumers doc guide to learn more\n```\n\n```text\n2021-11-01 22:26:17.251 [warning] <0.18574.1> Consumer None4 on channel 1 has timed out waiting for delivery acknowledgement. Timeout used: 1800000 ms. This timeout value can be configured, see consumers doc guide to learn more\n```\n\n```text\nCELERY_ACK_LATE\n```\n\n```yaml\nrabbitmq.conf: |\n consumer_timeout = 31622400000\n```\n\n```text\nconsumer_timeout\n```\n\n```text\nconsumer_timeout\n```\n\n```text\nrabbitmqctl eval 'application:set_env(rabbit, consumer_timeout, 36000000).'\n```\n\n```text\nrabbitmqctl eval 'application:get_env(rabbit, consumer_timeout).'\n```\n\n```text\n-e RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS=\"-rabbit consumer_timeout 36000000\"\n```\n\n```text\ndocker run\n```\n\n```text\nRABBITMQ_SERVER_ADDITIONAL_ERL_ARGS\n```\n\n```text\n\"-rabbit consumer_timeout 36000000\"\n```\n\n```text\n[celery_broker_transport_options]\n consumer_timeout = 31622400000\n```\n\n========================================\n\nComments:\n- Wouldn't the timeout only be for the amount of time it takes for the consumer to ack the task, not run it? If that's the case (unless you have acks_late set), it should ack immediately, not after the task is run.\n- I don't think this can solve the issue for Airflow configurations.","metadata":{"transformedAt":"2026-08-18T18:33:20.111Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":13,"totalLines":98,"estimatedTokens":983}}12{"id":"stack-45250282","source":"stackoverflow","questionId":45250282,"title":"What is the meaning of the vhost in RabbitMQ?","tags":["rabbitmq"],"text":"Title: What is the meaning of the vhost in RabbitMQ?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nWhen I set permissions to the rabbitmq user, there is output the `vhost`: \n\n```\n[root@ha-node1 my.cnf.d]# rabbitmqctl set_permissions openstack \".*\" \".*\" \".*\" \nSetting permissions for user \"openstack\" in vhost \"/\" ...\n```\n\nWhat is the meaning of the `vhost` when I set permission, and what function does it have?\n\n========================================\n\nTop Answer:\nLet me say this by giving you an analogy.\n\n`Vhosts` are to Rabbit what virtual machines are to physical servers: `Vhosts` allow you to run data for multiple applications safely and securely by providing logical separation between instances.\n\nThis is useful for anything from separating multiple customers on the same Rabbit to avoiding naming collisions on queues and exchanges. Where otherwise you might have to run multiple Rabbits\n\nEvery `RabbitMQ` server has a ability to create virtual message brokers called virtual hosts (`vhosts`). Each one is essentially a **mini-RabbitMQ server** with its own queues, exchanges, and bindings ... etc, more important, **with its own permissions**.\n\nFor details information ref: https://livebook.manning.com/book/rabbitmq-in-action/chapter-2/\n\n========================================\n\nCode:\n```text\n[root@ha-node1 my.cnf.d]# rabbitmqctl set_permissions openstack \".*\" \".*\" \".*\" \nSetting permissions for user \"openstack\" in vhost \"/\" ...\n```\n\n```text\nvhost\n```\n\n```text\nvhost\n```\n\n```text\nVhosts\n```\n\n```text\nVhosts\n```\n\n```text\nRabbitMQ\n```\n\n```text\nvhosts\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.111Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":58,"estimatedTokens":394}}13{"id":"stack-47473583","source":"stackoverflow","questionId":47473583,"title":"Celery: Use PostgreSQL instead of RabbitMQ","tags":["postgresql","rabbitmq","celery"],"text":"Title: Celery: Use PostgreSQL instead of RabbitMQ\nTags: postgresql, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nIs it possible to use a different message broker with celery?\n\nFor example: I would like to use PostgreSQL instead of RabbitMQ.\n\nAFAIK it is only supported in the result backend: http://docs.celeryproject.org/en/latest/userguide/configuration.html#database-backend-settings\n\nSince PostgreSQL 9.5 there is `SKIP LOCKED` which enables implementing robust message/work queues. See https://blog.2ndquadrant.com/what-is-select-skip-locked-for-in-postgresql-9-5/\n\n========================================\n\nTop Answer:\nIs it possible to use a different message broker with celery?\n\nbefore Version 4, it's sure yes! i have ever use mongodb for message broker in Celery 3, following the official document。\n\nso if want to use PostgreSQL as the broker,it's ok,Celery also support SQLAlchemy.\n\nHowever, if you want to use it in Celery 4.0, maybe it's a little difficult,one way in my mind is change the code for Kombu,yes,it's Kombu,not Celery!\n\n========================================\n\nCode:\n```text\nSKIP LOCKED\n```\n\n```text\nfrom celery import Celery \n\n\nbroker = 'sqla+postgresql://user:pass@host/dbname'\n\napp = Celery(broker=broker)\n\n@app.task\ndef add(x, y):\n return x + y\n```\n\n```text\nIn [1]: from demo import add\n\nIn [2]: add.delay(1,2)\nOut[2]: <AsyncResult: 4853190f-d355-48ae-8aba-6169d38fad39>\n```\n\n```text\n[2017-12-02 08:11:08,483: INFO/MainProcess] Received task: t.add[809060c0-dc7e-4a38-9e4e-9fdb44dd6a31] \n[2017-12-02 08:11:08,496: INFO/ForkPoolWorker-1] Task t.add[809060c0-dc7e-4a38-9e4e-9fdb44dd6a31] succeeded in 0.0015781960000822437s: 3\n```\n\n========================================\n\nComments:\n- Have you read Celery's documentation on brokers? docs.celeryproject.org/en/latest/userguide/…\n- database transport support code was removed before, but be added back recently: github.com/celery/kombu/tree/master/kombu/transport/sqlalche‌​my\n- @RonanBoiteau according to the docs there are several supported transport schemas. amqp://, redis://, sqs://, and qpid://. This looks like it is not supported to use PostgreSQL.\n- is there an advantage to use postgre, than rabbitMQ?\n- @pelos Yes. Less overhead on maintenance/deployment of another component in your stack. However, it is recommended not to use db as broker if you have high workloads. Relevant discussion at github.com/celery/celery/issues/5149.\n- This does not work anymore. in recent Celery versions, you can't use database as a broker.\n- @RamyM.Mousa Which version are you using? It seems to be working fine with celery==5.0.0 also.\n- at least highly undocumented, if it still works with 5.3?! having to run a rabbit or redis was always a showstopper in smaller projects.\n- Still works with Celery 5.2. It should be documented, having a backend AND broker without no extra tool is highly valuable in local environment IMO.\n- I actually added the removed support back but it is not documented yet and of course need improvements.","metadata":{"transformedAt":"2026-08-18T18:33:20.111Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":69,"estimatedTokens":759}}14{"id":"stack-14953521","source":"stackoverflow","questionId":14953521,"title":"How to route a chain of tasks to a specific queue in celery?","tags":["python","rabbitmq","celery","chain"],"text":"Title: How to route a chain of tasks to a specific queue in celery?\nTags: python, rabbitmq, celery, chain\nSource: Stack Overflow\n\nQuestion:\nWhen I route a task to a particular queue it works:\n\n```\ntask.apply_async(queue='beetroot')\n```\n\nBut if I create a chain:\n\n```\nchain = task | task\n```\n\nAnd then I write\n\n```\nchain.apply_async(queue='beetroot')\n```\n\nIt seems to ignore the queue keyword and assigns to the default 'celery' queue.\n\nIt would be nice if celery supported routing in chains - all tasks executed sequentially in the same queue.\n\n========================================\n\nTop Answer:\nI do it like this:\n\n```\nsubtask = task.s(*myargs, **mykwargs).set(queue=myqueue)\nmychain = celery.chain(subtask, subtask2, ...)\nmychain.apply_async()\n```\n\n========================================\n\nCode:\n```text\ntask.apply_async(queue='beetroot')\n```\n\n```text\nchain = task | task\n```\n\n```text\nchain.apply_async(queue='beetroot')\n```\n\n```text\nfrom celery import subtask\n\nchain = subtask('task', queue = 'beetroot') | subtask('task', queue = 'beetroot')\n```\n\n```text\nchain = task.s().apply_async(queue = 'beetroot') | task.s().apply_async(queue = 'beetroot')\n```\n\n```text\nchain.apply_async()\n```\n\n```text\nchain.delay()\n```\n\n```text\nsubtask = task.s(*myargs, **mykwargs).set(queue=myqueue)\nmychain = celery.chain(subtask, subtask2, ...)\nmychain.apply_async()\n```\n\n```text\nfrom celery import chain\n\nchain(\n module.task1.s(arg),\n module.task2.s()\n).apply_async(countdown=0.1, queue='queuename')\n```\n\n```text\nchain(\n module.task1.s(arg).set(queue='queuename'),\n module.task2.s().set(queue='queuename')\n).apply_async(countdown=0.1)\n```\n\n========================================\n\nComments:\n- Actually it works now on a fresh django (probably was fixed)\n- Hmmm, that partial example didn't work for me, I got back the following error: TypeError: unsupported operand type(s) for |: 'AsyncResult' and 'AsyncResult' (using 3.0.23)\n- I was having issues of my own in trying to get the `chain` to execute the second task. Question: If you're calling `apply_async` on both tasks, is that really a chain still? Won't both tasks execute of their own accord? I tried out your syntax and it failed because in my case the first subtask returns a value which is used by the second.\n- So it works if `queue` is specified on signature but not when it is passed to `apply_async`? do you know if there is some good documentation for this feature?\n- Can different subtasks in the same chain be assigned different queues?","metadata":{"transformedAt":"2026-08-18T18:33:20.111Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":101,"estimatedTokens":626}}15{"id":"stack-12594802","source":"stackoverflow","questionId":12594802,"title":"When does a celery worker acknowledge to RabbitMQ that it has a task?","tags":["rabbitmq","celery"],"text":"Title: When does a celery worker acknowledge to RabbitMQ that it has a task?\nTags: rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI might be misunderstanding how this works (which is why I'm asking), but I think when a celery worker consumes a task from RabbitMQ it puts a lock on it -- so to speak -- and then must acknowledge it completed that task onces it's done. So say I have 4 workers which all have the prefetch setting at 1 and queue of 6 tasks which take a long time. Once I start those workers and I run:\n\n```\nrabbitmqctl -q list_queues name messages messages_ready messages_unacknowledged\n```\n\nI'd expect to see something like:\n\n```\ncelery 6 2 4\n```\n\nindicating that 4 tasks are running (but not yet acknowledged) and 2 are ready to be consumed.\n\nI think my understanding is wrong because what I actually see is:\n\n```\ncelery 2 0 2\n```\n\nSo it's as if the acknowledging happens when a message is received by a worker, but before that worker finishes processing that task.\n\nSo to sum up, my question is, **when does a celery worker acknowledge it has a task?** It seems like it's once it receives that task and starts working on it, not when it completes working on it. Can someone confirm?\n\n========================================\n\nCode:\n```text\nrabbitmqctl -q list_queues name messages messages_ready messages_unacknowledged\n```\n\n```text\ncelery 6 2 4\n```\n\n```text\ncelery 2 0 2\n```\n\n========================================\n\nComments:\n- Yah I guess tagging as Python is overly broad, removed that tag.\n- Awesome, exactly what I was looking for. Thanks for celery btw, it's awesome.","metadata":{"transformedAt":"2026-08-18T18:33:20.111Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":49,"estimatedTokens":406}}16{"id":"stack-40563469","source":"stackoverflow","questionId":40563469,"title":"Connecting to rabbitmq docker container from service in another container","tags":["python","docker","rabbitmq","nameko"],"text":"Title: Connecting to rabbitmq docker container from service in another container\nTags: python, docker, rabbitmq, nameko\nSource: Stack Overflow\n\nQuestion:\nI've done a lot of searching but I cannot fix this issue. \n\nI have a basic Rabbitmq container running via this command:\n\n`docker run -d --hostname rabbitmqhost --name rabbitmq -p 15672:15672 -p 5672:5672 rabbitmq:3-management`\n\nI am using `nameko` to create a microservice which connects to this container. Here's a basic microservice module `main.py`:\n\n```\nfrom nameko.rpc import rpc\nclass Service_Name(object):\n name = \"service_name\"\n\n @rpc\n def service_endpoint(self, arg=None):\n logging.info('service_one endpoint, arg = %s', arg)\n```\n\nThis service runs and connects to the rabbitmq from my host machine with the command: \n\n`nameko run main --broker amqp://guest:guest@localhost`\n\nI wanted to put the service into a Docker container (called `service_one`) but when I do so and run the previous nameko command I get `socket.error: [Errno 111] ECONNREFUSED` no matter how I try and link the two containers.\n\nWhat would be the correct method? The aim is to have each service in a container, all talking to each other through rabbit. Thanks.\n\n========================================\n\nCode:\n```text\nfrom nameko.rpc import rpc\nclass Service_Name(object):\n name = \"service_name\"\n\n @rpc\n def service_endpoint(self, arg=None):\n logging.info('service_one endpoint, arg = %s', arg)\n```\n\n```text\ndocker run -d --hostname rabbitmqhost --name rabbitmq -p 15672:15672 -p 5672:5672 rabbitmq:3-management\n```\n\n```text\nnameko\n```\n\n```text\nmain.py\n```\n\n```text\nnameko run main --broker amqp://guest:guest@localhost\n```\n\n```text\nservice_one\n```\n\n```text\nsocket.error: [Errno 111] ECONNREFUSED\n```\n\n```text\ndocker network create myapp_net\n```\n\n```text\ndocker run -d --network myapp_net --hostname rabbitmqhost \\\n --name rabbitmq -p 15672:15672 -p 5672:5672 rabbitmq:3-management\n```\n\n```text\namqp://guest:guest@localhost\n```\n\n```text\nlocalhost\n```\n\n```text\nECONNREFUSED\n```\n\n```text\nrabbitmq\n```\n\n```text\n--network\n```\n\n```text\n--link\n```\n\n========================================\n\nComments:\n- \"No matter how I try to link the two containers...\" What have you tried?\n- I tried link and network, turns out I was getting the ampq connection values slightly wrong for each method. (I was using localhost rather than AMQ_PORT_5672_TCP_ADDR etc).\n- Thank you. I ended up using --link to connect each service container to rabbit, even though I appreciate the above is the new standard way of doing it.\n- I just wanted to highlight one advantage of the Docker network solution: when using `--link`, if you stop your rabbitmq container, your app is out of luck: you can't \"relink\" the container after starting a new rabbitmq container. On the other hand, using Docker networks, which rely on dns for name resolution, if you start a new container with the same name as the new container, your services will probably be able to recover (presuming that your application code handles disconnections gracefully).\n- Ahh, that's a very good point, thank you. If I were to use the network solution, what would be the address and port of rabbit? i.e. The equivalent of `AMQ_PORT_5672_TCP_ADDR` and `AMQ_PORT_5672_TCP_PORT`\n- The address would just be the name (`--name ...`) of the container (Docker maintains a DNS server that maps container names to address). There is no equivalent to `AMQ_PORT_5672_TCP_PORT`, but in general this isn't an issue.\n- Great, thanks again. The only issue I now have is that I cannot access my Flask app (on 0.0.0.0:5000) anymore when the app's container is connected to that network, any ideas?\n- Turns out I just didn't map the ports correctly, one I ran with -p 5000:5000 it all works.\n- One important point to make here is that all of your service containers need to be started using `--name`. As I found out, without it, container is created but is not put inside the network even if you specify `--network`, thus failing to connect to rabbitMQ","metadata":{"transformedAt":"2026-08-18T18:33:20.111Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":15,"totalLines":113,"estimatedTokens":1005}}17{"id":"stack-7144025","source":"stackoverflow","questionId":7144025,"title":"Temporary queue made in Celery","tags":["rabbitmq","celery"],"text":"Title: Temporary queue made in Celery\nTags: rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI am using Celery with RabbitMQ. Lately, I have noticed that a large number of temporary queues are getting made.\n\nSo, I experimented and found that when a task fails (that is a tasks raises an Exception), then a temporary queue with a random name (like c76861943b0a4f3aaa6a99a6db06952c) is formed and the queue remains. \n\nSome properties of the temporary queue as found in rabbitmqadmin are as follows -\n\nauto_delete : True\nconsumers : 0\ndurable : False\nmessages : 1\nmessages_ready : 1\n\nAnd one such temporary queue is made everytime a task fails (that is, raises an Exception). How to avoid this situation? Because in my production environment a large number of such queues get formed.\n\n========================================\n\nTop Answer:\nIt sounds like you're using the amqp as the results backend. From the docs here are the pitfalls of using that particular setup:\n\n \n Every new task creates a new queue on the server, with thousands of\n tasks the broker may be overloaded with queues and this will affect\n\n performance in negative ways. If you’re using RabbitMQ then each\n\n queue will be a separate Erlang process, so if you’re planning to\n\n keep many results simultaneously you may have to increase the Erlang\n\n process limit, and the maximum number of file descriptors your OS\n\n allows \n Old results will not be cleaned automatically, so you must make\n sure to consume the results or else the number of queues will\n eventually go out of control. If you’re running RabbitMQ 2.1.1 or\n higher you can take advantage of the x-expires argument to queues,\n which will expire queues after a certain time limit after they are\n unused. The queue expiry can be set (in seconds) by the\n CELERY_AMQP_TASK_RESULT_EXPIRES setting (not enabled by default).\n \n\nFrom what I've read in the changelog, this is no longer the default backend in versions >=2.3.0 because users were getting bit in the rear end by this behavior. I'd suggest changing the results backend if this not the functionality you need.\n\n========================================\n\nCode:\n```text\ncelery command\n```\n\n```text\nCELERY_RESULT_BACKEND = 'rpc'\nCELERY_RESULT_PERSISTENT = True\n```\n\n```text\namqp\n```\n\n```text\nrpc\n```\n\n========================================\n\nComments:\n- That is an interesting observation! I, too, would like to know.\n- Hi Elver. I was able to solve the problem. Please have a look at the answer (one by me as well). Hope it helps.\n- CELERY_AMQP_TASK_RESULT_EXPIRES has been deprecated, CELERY_TASK_RESULT_EXPIRES is the new config setting name. Default is now to save it for 1 day, setting it to 0 means keep forever.\n- Wow! This solved it for me. I didn't even realize this was an issue since I was setting ignore_result=True in each task descriptor. But I added CELERY_IGNORE_RESULT = True and CELERY_STORE_ERRORS_EVEN_IF_IGNORED = False and viola - no more extra queues hanging around after processing! I still might look into redis as an alternative backend, but it is really nice to have found this solution. Thank you!\n- @jeffp - Glad to hear that. I have also used Redis lately with Celery - I don't think it is a problem with that. Celery itself forms and maintains the queue. So this configuration is important.\n- I actually discovered another thing in the past day that I think will be very helpful for anyone reading this: It is necessary to have more than one worker and to route different tasks to each worker. It is advisable to learn about celeryd-multi and use it. The documentation does not make this obvious, but it is the key to effectively using available system resources and not letting the queue get backed up.","metadata":{"transformedAt":"2026-08-18T18:33:20.111Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":77,"estimatedTokens":929}}18{"id":"stack-39530787","source":"stackoverflow","questionId":39530787,"title":"How to use Ack or Nack in Spring AMQP","tags":["rabbitmq","spring-amqp","spring-rabbit"],"text":"Title: How to use Ack or Nack in Spring AMQP\nTags: rabbitmq, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI am new to Spring AMQP. I am having an application which is a producer sending messages to the other application which is a consumer.\n\nOnce the consumer receives the message, we will do validation of the data. \n\nIf the data is proper we have to ACK and message should be removed from the Queue.\nIf the data is improper we have to NACK(Negative Acknowledge) the data so that it will be re-queued in RabbitMQ.\n\nI came across\n\n`**factory.setDefaultRequeueRejected(false);**`( It will not requeue the message at all)\n\n`**factory.setDefaultRequeueRejected(true);**`( It will requeue the message when exception occurs)\n\nBut my case i will acknowledge the message based on validation. Then it should remove the message. If NACK then requeue the message.\n\nI have read in RabbitMQ website\n\n**The AMQP specification defines the basic.reject method that allows clients to reject individual, delivered messages, instructing the broker to either discard them or requeue them**\n\nHow to achieve the above scenario? Please provide me some examples.\n\nI tried a small Program\n\n```\nlogger.info(\"Job Queue Handler::::::::::\" + new Date());\n try {\n\n }catch(Exception e){\n\n logger.info(\"Activity Object Not Found Exception so message should be Re-queued the Message::::::::::::::\");\n\n }\n\n factory.setErrorHandler(new ConditionalRejectingErrorHandler(cause ->{\n return cause instanceof XMLException;\n }));\n```\n\nMessage is not re queuing for different exception\n**factory.setDefaultRequeueRejected(true)**\n\n 09:46:38,854 ERROR [stderr] (SimpleAsyncTaskExecutor-1)\n **org.activiti.engine.ActivitiObjectNotFoundException**: no processes deployed with key 'WF89012'\n\n \n 09:46:39,102 INFO \n [com.example.bip.rabbitmq.handler.ErrorQueueHandler]\n (SimpleAsyncTaskExecutor-1) Received from Error Queue: {ERROR=Could\n not commit JPA transaction; nested exception is\n javax.persistence.RollbackException: Transaction marked as\n rollbackOnly}\n\n========================================\n\nCode:\n```text\nlogger.info(\"Job Queue Handler::::::::::\" + new Date());\n try {\n\n }catch(Exception e){\n\n logger.info(\"Activity Object Not Found Exception so message should be Re-queued the Message::::::::::::::\");\n\n }\n\n factory.setErrorHandler(new ConditionalRejectingErrorHandler(cause ->{\n return cause instanceof XMLException;\n }));\n```\n\n```text\n**factory.setDefaultRequeueRejected(false);**\n```\n\n```text\n**factory.setDefaultRequeueRejected(true);**\n```\n\n```text\n@SpringBootApplication\npublic class So39530787Application {\n\n private static final String QUEUE = \"So39530787\";\n\n public static void main(String[] args) throws Exception {\n ConfigurableApplicationContext context = SpringApplication.run(So39530787Application.class, args);\n RabbitTemplate template = context.getBean(RabbitTemplate.class);\n template.convertAndSend(QUEUE, \"foo\");\n template.convertAndSend(QUEUE, \"bar\");\n template.convertAndSend(QUEUE, \"baz\");\n So39530787Application bean = context.getBean(So39530787Application.class);\n bean.latch.await(10, TimeUnit.SECONDS);\n System.out.println(\"Expect 1 foo:\" + bean.fooCount);\n System.out.println(\"Expect 3 bar:\" + bean.barCount);\n System.out.println(\"Expect 1 baz:\" + bean.bazCount);\n context.close();\n }\n\n @Bean\n public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {\n SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();\n factory.setConnectionFactory(connectionFactory);\n factory.setErrorHandler(new ConditionalRejectingErrorHandler(\n t -> t instanceof ListenerExecutionFailedException && t.getCause() instanceof FooException));\n return factory;\n }\n\n @Bean\n public Queue queue() {\n return new Queue(QUEUE, false, false, true);\n }\n private int fooCount;\n\n private int barCount;\n\n private int bazCount;\n\n private final CountDownLatch latch = new CountDownLatch(5);\n\n @RabbitListener(queues = QUEUE)\n public void handle(String in) throws Exception {\n System.out.println(in);\n latch.countDown();\n if (\"foo\".equals(in) && ++this.fooCount < 3) {\n throw new FooException();\n }\n else if (\"bar\".equals(in) && ++this.barCount < 3) {\n throw new BarException();\n }\n else if (\"baz\".equals(in)) {\n this.bazCount++;\n }\n }\n\n @SuppressWarnings(\"serial\")\n public static class FooException extends Exception { }\n\n @SuppressWarnings(\"serial\")\n public static class BarException extends Exception { }\n\n}\n```\n\n```text\nExpect 1 foo:1\nExpect 3 bar:3\nExpect 1 baz:1\n```\n\n```text\ndefaultRequeueRejected=true\n```\n\n```text\nAmqpRejectAndDontRequeueException\n```\n\n```text\nbasicReject(false)\n```\n\n```text\nbasicReject(true)\n```\n\n```text\nAmqpRejectAndDontRequeueException\n```\n\n```text\nAmqpRejectAndDontRequeueException\n```\n\n```text\nMANUAL\n```\n\n```text\nChannelAwareMessageListener\n```\n\n```text\n@RabbitListener\n```\n\n```text\nListenerExecutionFailedException\n```\n\n========================================\n\nComments:\n- Thanks for Explanation. I tried some program. Could you please rectify the mistake ?\n- It doesn't make sense to always throw an `AmqpRejectAndDontRequeueException` from the error handler; for that, simply set `default RequeueRejected=false`. Use the technique in this answer to only throw it for the `XMLException` - your listener must re-throw it.","metadata":{"transformedAt":"2026-08-18T18:33:20.111Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":15,"totalLines":199,"estimatedTokens":1414}}19{"id":"stack-8654053","source":"stackoverflow","questionId":8654053,"title":"RabbitMQ cluster is not reconnecting after network failure","tags":["cluster-computing","rabbitmq"],"text":"Title: RabbitMQ cluster is not reconnecting after network failure\nTags: cluster-computing, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have a RabbitMQ cluster with two nodes in production and the cluster is breaking with these error messages:\n\n```\n=ERROR REPORT==== 23-Dec-2011::04:21:34 ===\n** Node rabbit@rabbitmq02 not responding **\n** Removing (timedout) connection **\n\n=INFO REPORT==== 23-Dec-2011::04:21:35 ===\nnode rabbit@rabbitmq02 lost 'rabbit'\n\n=ERROR REPORT==== 23-Dec-2011::04:21:49 ===\nMnesia(rabbit@rabbitmq01): ** ERROR ** mnesia_event got {inconsistent_database, running_partitioned_network, rabbit@rabbitmq02}\n```\n\nI tried to simulate the problem by killing the connection between the two nodes using \"tcpkill\". The cluster has disconnected, and surprisingly the two nodes are not trying to reconnect!\n\nWhen the cluster breaks, HAProxy load balancer still marks both nodes as active and send requests to both of them, although they are not in a cluster.\n\nMy questions:\n\nIf the nodes are configured to work as a cluster, when I get a network failure, why aren't they trying to reconnect afterwards?\n\nHow can I identify broken cluster and shutdown one of the nodes? I have consistency problems when working with the two nodes separately.\n\n========================================\n\nTop Answer:\nRabbitMQ Clusters do not work well on unreliable networks (part of RabbitMQ documentation). So when the network failure happens (in a two node cluster) each node thinks that it is the master and the only node in the cluster. Two master nodes don't automatically reconnect, because their states are not automatically synchronized (even in case of a RabbitMQ slave - the actual message synchronization does not happen - the slave just \"catches up\" as messages get consumed from the queue and more messages get added).\n\nTo detect whether you have a broken cluster, run the command:\n\n```\nrabbitmqctl cluster_status\n```\n\non each of the nodes that form part of the cluster. If the cluster is broken then you'll only see one node. Something like:\n\n```\nCluster status of node rabbit@rabbitmq1 ...\n[{nodes,[{disc,[rabbit@rabbitmq1]}]},{running_nodes,[rabbit@rabbitmq1]}]\n...done.\n```\n\nIn such cases, you'll need to run the following set of commands on one of the nodes that formed part of the original cluster (so that it joins the other master node (say rabbitmq1) in the cluster as a slave):\n\n```\nrabbitmqctl stop_app\n\nrabbitmqctl reset\n\nrabbitmqctl join_cluster rabbit@rabbitmq1\n\nrabbitmqctl start_app\n```\n\nFinally check the cluster status again .. this time you should see both the nodes.\n\nNote: If you have the RabbitMQ nodes in an HA configuration using a Virtual IP (and the clients are connecting to RabbitMQ using this virtual IP), then the node that should be made the master should be the one that has the Virtual IP.\n\n========================================\n\nCode:\n```text\n=ERROR REPORT==== 23-Dec-2011::04:21:34 ===\n** Node rabbit@rabbitmq02 not responding **\n** Removing (timedout) connection **\n\n=INFO REPORT==== 23-Dec-2011::04:21:35 ===\nnode rabbit@rabbitmq02 lost 'rabbit'\n\n=ERROR REPORT==== 23-Dec-2011::04:21:49 ===\nMnesia(rabbit@rabbitmq01): ** ERROR ** mnesia_event got {inconsistent_database, running_partitioned_network, rabbit@rabbitmq02}\n```\n\n```text\nrabbitmqctl cluster_status\n```\n\n```text\nCluster status of node rabbit@rabbitmq1 ...\n[{nodes,[{disc,[rabbit@rabbitmq1]}]},{running_nodes,[rabbit@rabbitmq1]}]\n...done.\n```\n\n```text\nrabbitmqctl stop_app\n\nrabbitmqctl reset\n\nrabbitmqctl join_cluster rabbit@rabbitmq1\n\nrabbitmqctl start_app\n```\n\n```text\npause-minority\n```\n\n```text\npause-if-all-down\n```\n\n```text\nautoheal\n```\n\n```text\nignore\n```\n\n```text\ncluster_partition_handling\n```\n\n```text\nrabbit\n```\n\n```text\nautoheal\n```\n\n```text\npause_minority\n```\n\n```text\npause_if_all_down\n```\n\n```text\npause_if_all_down\n```\n\n```text\nnodes\n```\n\n```text\nrecover\n```\n\n```text\nignore\n```\n\n```text\nautoheal\n```\n\n```text\nignore\n```\n\n```text\npause_minority\n```\n\n```text\nautoheal\n```\n\n```text\n** ERROR ** (core dumped to file: \"/var/lib/rabbitmq/MnesiaCore.rabbit...)\n```\n\n```text\n** FATAL ** Failed to merge schema: Incompatible schema storage types (remote).\n```\n\n========================================\n\nComments:\n- Is it possible to configure the nodes to DO automatically synchronize their states whenever the network is available again?\n- Not to my knowledge (unless this is available in a newer version of RabbitMQ ... I haven't checked for at least a year now).\n- How reliable works `autoheal` mode in practice? Do a two-node cluster automatically reconnect and synchronize with each other after network failure between them?\n- As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.","metadata":{"transformedAt":"2026-08-18T18:33:20.111Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":23,"totalLines":182,"estimatedTokens":1221}}20{"id":"stack-13005410","source":"stackoverflow","questionId":13005410,"title":"Why do we need message brokers like RabbitMQ over a database like PostgreSQL?","tags":["postgresql","redis","rabbitmq","message-queue","celery"],"text":"Title: Why do we need message brokers like RabbitMQ over a database like PostgreSQL?\nTags: postgresql, redis, rabbitmq, message-queue, celery\nSource: Stack Overflow\n\nQuestion:\nI am new to message brokers like RabbitMQ which we can use to create tasks / message queues for a scheduling system like Celery.\n\nNow, here is the question:\n\nI can create a table in PostgreSQL which can be appended with new tasks and consumed by the consumer program like Celery.\n\nWhy on earth would I want to setup a whole new tech for this like RabbitMQ?\n\nNow, I believe scaling cannot be the answer since our database like PostgreSQL can work in a distributed environment.\n\nI googled for what problems does the database poses for the particular problem, and I found:\n\n- polling keeps the database busy and low performing\n\n- locking of the table -> again low performing\n\n- millions of rows of tasks -> again, polling is low performing\n\nNow, how does RabbitMQ or any other message broker like that solves these problems?\n\nAlso, I found out that `AMQP` protocol is what it follows. What's great in that?\n\nCan Redis also be used as a message broker? I find it more analogous to Memcached than RabbitMQ.\n\nPlease shed some light on this!\n\n========================================\n\nTop Answer:\n### PostgreSQL 9.5\n\nPostgreSQL 9.5 incorporates `SELECT ... FOR UPDATE ... SKIP LOCKED`. This makes implementing working queuing systems a *lot* simpler and easier. You may no longer require an external queueing system since it's now simple to fetch 'n' rows that no other session has locked, and keep them locked until you commit confirmation that the work is done. It even works with two-phase transactions for when external co-ordination is required.\n\nExternal queueing systems remain useful, providing canned functionality, proven performance, integration with other systems, options for horizontal scaling and federation, etc. Nonetheless, for simple cases you don't really need them anymore.\n\n### Older versions\n\nYou don't *need* such tools, but using one may make life easier. Doing queueing in the database looks easy, but you'll discover in practice that high performance, reliable concurrent queuing is *really hard* to do right in a relational database.\n\nThat's why tools like PGQ exist.\n\nYou can get rid of polling in PostgreSQL by using `LISTEN` and `NOTIFY`, but that won't solve the problem of reliably handing out entries off the top of the queue to exactly one consumer while preserving highly concurrent operation and not blocking inserts. All the simple and obvious solutions you think will solve that problem actually don't in the real world, and tend to degenerate into less efficient versions of single-worker queue fetching.\n\nIf you don't need highly concurrent multi-worker queue fetches then using a single queue table in PostgreSQL is entirely reasonable.\n\n========================================\n\nCode:\n```text\nAMQP\n```\n\n```text\nSELECT ... FOR UPDATE ... SKIP LOCKED\n```\n\n```text\nLISTEN\n```\n\n```text\nNOTIFY\n```\n\n========================================\n\nComments:\n- The impact of locking should be a lot less with PostgreSQL because it implements MVCC where readers are not blocked by writers and vice versa. Most of the articles I've found criticising the use of databases as message queues have MySQL in mind.\n- A message broker moves data between nodes, while a database keeps data in one place. The fact that you can access data in a database from multiple nodes does not, on its face, make it a good tool to transfer data quickly between nodes.\n- \"scheduling system like `celery`\" — I just learnt something which will be useful in my design, from the *question*. Now to read the answers...\n- using message broker producer and consumer is decoupled.\n- You can view bellow link. It has a wide description: stackoverflow.com/a/51377756/3073945\n- @CadentOrange your comment can leave readers with the impression MySQL would perform worse than PostgreSQL, but that's rather misleading. In general, there should be no such problem (writers blocking readers) with MySQL either (talking about InnoDB, which has been the default storage engine as of 2010). Same goes for most other popular databases, such as MS SQL Server, Oracle DB, etc. Now, there are many details and differences between those RDBMSs that could have *some* impact on the performance, but those can't be covered in a few sentences.\n- I am surprised that nobody called your question dumb. I believe if I would raise this question in my team, one highly likely call or at least think it is dumb question.\n- the line `reliably handing out entries off the top of the queue to exactly one consumer while preserving highly concurrent operation and not blocking inserts.` summarizes it - Right ?\n- Does Celery use this feature of Postgres? If it doesn't, then this doesn't help.\n- @duality_ If it doesn't, write a patch :)\n- I've implemented a JMS implementation (i.e. a message passing system) on top of a database. I can tell you that it *is* possible, but it's not fun and it doesn't usually pay off to do it. Some of the problems you mention can be worked around, but it does increase the complexity quite a lot. All in all I agree: use a dedicated MQ system, if you need one. For low workloads, you can get away with having it in the DB, however.\n- That's interesting. What about consistency by the way? What if there are hundreds of jobs on a queue and the node holding them in ram crashes?\n- @Mahn There are quite a few options available by way of redundancy, and saving some data to disk: rabbitmq.com/ha.html I feel the best approach is to use a combination of the features offered.\n- Actually, with PostgreSQL there is no polling (see NOTIFY) nor are there table locks (see MVCC). Though PostgreSQL is still not designed for message queuing, it is not completely unsuitable.\n- Like what @jkj said, there's NOTIFY and no tables locks. The only issue seems like the high bandwidth of messages. Couldn't you have a dedicated PostgreSQL instance instead of maintaining an entirely new system like Rabbit? You can 1) use a single PostgreSQL instance until you reach a bottleneck, then 2) use a dedicated Postgres, then finally 3) easily switch to Rabbit as your broker. Seems like starting with Rabbit is pre-optimizing.\n- RabbitMQ support lot of protocol and it make it easy to interact between different kind of device: embedded system, server, mobile... (as you mention it provide lot of feature for messaging)\n- Just to add, some message brokers also allow messages to be transformed in some way before being passed on. That is, you can augment the message with additional information before passing it on from the broker to a client. This can be helpful with legacy or tricky-to-change apps working alongside current apps, in so much as the broker can make messages from them look the same to consumers.\n- \"Rabbit's queues reside in memory and will therefore be much faster than implementing this in a database.\" <- is this generally true, if messages stay in cache in the DB?\n- Postgresql is atomic right? So there is a invisible lock for concurrent write right?\n- The link **eflorenzano.com/blog/2011/02/16/technology-behind-convore** is 404\n- regarding ram, I have heard there is RAM disks. Where database would see it is hard drive but actually it would be in ram.","metadata":{"transformedAt":"2026-08-18T18:33:20.112Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":93,"estimatedTokens":1833}}21{"id":"stack-18418936","source":"stackoverflow","questionId":18418936,"title":"RabbitMQ and relationship between channel and connection","tags":["java","rabbitmq","messaging","amqp","channel"],"text":"Title: RabbitMQ and relationship between channel and connection\nTags: java, rabbitmq, messaging, amqp, channel\nSource: Stack Overflow\n\nQuestion:\nThe RabbitMQ Java client has the following concepts:\n\n- `Connection` - a connection to a RabbitMQ server instance\n\n- `Channel` - ???\n\n- Consumer thread pool - a pool of threads that consume messages off the RabbitMQ server queues\n\n- Queue - a structure that holds messages in FIFO order\n\nI'm trying to understand the relationship, **and more importantly**, the *associations* between them.\n\n- I'm still not quite sure what a `Channel` is, other than the fact that this is the structure that you publish and consume from, and that it is created from an open connection. If someone could explain to me what the \"Channel\" represents, it might help clear a few things up.\n\n- What is the relationship between Channel and Queue? Can the same Channel be used to communicate to multiples Queues, or does it have to be 1:1?\n\n- What is the relationship between Queue and the Consumer Pool? Can multiple Consumers be subscribed to the same Queue? Can multiple Queues be consumed by the same Consumer? Or is the relationship 1:1?\n\n========================================\n\nTop Answer:\nA good conceptual understanding of what the AMQP protocol does \"under the hood\" is useful here. I would offer that the documentation and API that AMQP 0.9.1 chose to deploy makes this particularly confusing, so the question itself is one which many people have to wrestle with.\n\n**TL;DR**\n\nA *connection* is the physical negotiated TCP socket with the AMQP server. Properly-implemented clients will have one of these per application, thread-safe, sharable among threads.\n\nA *channel* is a single application session on the connection. A thread will have one or more of these sessions. AMQP architecture 0.9.1 is that these are not to be shared among threads, and should be closed/destroyed when the thread that created it is finished with it. They are also closed by the server when various protocol violations occur.\n\nA *consumer* is a virtual construct that represents the presence of a \"mailbox\" on a particular channel. The use of a consumer tells the broker to push messages from a particular queue to that channel endpoint.\n\n**Connection Facts**\n\nFirst, as others have correctly pointed out, a **connection** is the object that represents the actual TCP connection to the server. Connections are specified at the protocol level in AMQP, and all communication with the broker happens over one or more connections. \n\n- Since it's an actual TCP connection, it has an IP Address and Port #.\n\n- Protocol parameters are negotiated on a per-client basis as part of setting up the connection (a process known as the *handshake*.\n\n- It is designed to be *long-lived*; there are few cases where connection closure is part of the protocol design.\n\n- From an OSI perspective, it probably resides somewhere around Layer 6\n\n- Heartbeats can be set up to monitor the connection status, as TCP does not contain anything in and of itself to do this.\n\n- It is best to have a dedicated thread manage reads and writes to the underlying TCP socket. Most, if not all, RabbitMQ clients do this. In that regard, they are generally thread-safe.\n\n- Relatively speaking, connections are \"expensive\" to create (due to the handshake), but practically speaking, this really doesn't matter. Most processes really will only need one connection object. But, you can maintain connections in a pool, if you find you need more throughput than a single thread/socket can provide (unlikely with current computing technology).\n\n**Channel Facts**\n\nA **Channel** is the application session that is opened for each piece of your app to communicate with the RabbitMQ broker. It operates over a single *connection*, and represents a *session* with the broker. \n\n- As it represents a logical part of application logic, each channel usually exists on its own thread.\n\n- Typically, all channels opened by your app will a single connection (they are lightweight sessions that operate on top of the connection). Connections are thread-safe, so this is OK.\n\n- Most AMQP operations take place over channels.\n\n- From an OSI Layer perspective, channels are probably around Layer 7.\n\n- **Channels are designed to be transient**; part of the design of AMQP is that the channel is typically closed in response to an error (e.g. re-declaring a queue with different parameters before deleting the existing queue).\n\n- Since they are transient, channels should not be pooled by your app.\n\n- The server uses an integer to identify a channel. When the thread managing the connection receives a packet for a particular channel, it uses this number to tell the broker which channel/session the packet belongs to.\n\n- Channels are not generally thread-safe as it would make no sense to them among threads. **If you have another thread that needs to use the broker, a new channel is needed.**\n\n**Consumer Facts**\n\nA consumer is an object defined by the AMQP protocol. It is neither a channel nor a connection, instead being something that your particular application uses as a \"mailbox\" of sorts to drop messages.\n\n- \"Creating a consumer\" means that you tell the broker (using a *channel* via a *connection*) that you would like messages pushed to you over that channel. In response, the broker will register that you have a *consumer* on the channel and begin pushing messages to you.\n\n- Each message pushed over the connection will reference both a *channel number* and a *consumer number*. In that way, the connection-managing thread (in this case, within the Java API) knows what to do with the message; then, the channel-handling thread also knows what to do with the message.\n\n- Consumer implementation has the widest amount of variation, because it's literally application-specific. In my implementation, I chose to spin off a task each time a message arrived via the consumer; thus, I had a thread managing the connection, a thread managing the channel (and by extension, the consumer), and one or more task threads for each message delivered via the consumer.\n\n- Closing a *connection* closes all channels on the connection. Closing a *channel* closes all consumers on the channel. It is also possible to *cancel* a consumer (without closing the channel). There are various cases when it makes sense to do any of the three things.\n\n- Typically, the implementation of a consumer in an AMQP client will allocate one dedicated channel to the consumer to avoid conflicts with the activities of other threads or code (including publishing).\n\nIn terms of what you mean by consumer thread pool, I suspect that Java client is doing something similar to what I programmed my client to do (mine was based off the .Net client, but heavily modified).\n\n========================================\n\nCode:\n```text\nConnection\n```\n\n```text\nChannel\n```\n\n```text\nChannel\n```\n\n```text\nConnection\n```\n\n```text\nChannel\n```\n\n```text\nChannel\n```\n\n```text\nChannel\n```\n\n```text\nChannel\n```\n\n```text\nQueue\n```\n\n```text\nChannel\n```\n\n```text\nConsumer\n```\n\n```text\nConsumer\n```\n\n```text\nhandleDelivery(...)\n```\n\n```text\nDefaultConsumer\n```\n\n```text\nhandleDelivery(...)\n```\n\n========================================\n\nComments:\n- The answers to this question led to me reporting this issue with the golang client rather than asking the question here.\n- The channel is a logical concept used to multiplex a single physical TCP connection between a client and a node. The channel number is included in the message header of the AMQP frame.\n- Just to add from the documentation: Callbacks to Consumers are dispatched on a thread separate from the thread managed by the Connection. This means that Consumers can safely call blocking methods on the Connection or Channel, such as queueDeclare, txCommit, basicCancel or basicPublish. Each Channel has its own dispatch thread. For the most common use case of one Consumer per Channel, this means Consumers do not hold up other Consumers. If you have multiple Consumers per Channel be aware that a long-running Consumer may hold up dispatch of callbacks to other Consumers on that Channel.\n- If you attach the same Consumer instance to multiple Queues from the same Channel that would mean that the callbacks are dispatched on the same thread. In that case you would not need synchronization, would you?\n- Can I use only one connection and use a pool of channels instead of a connection pool? Will this affect message publishing throughput?\n- As far as I know a pool of channels and only one connection is the standard. However, I know nothing (and haven't made any tests) about the impact on throughput.\n- @Bengt okay, so Channels are not related to Queues, Consumers are not related to Queues (since they can be have multiple queues), Channels are best used single-thread and a Consumer spawns its own thread. Besides, a Channel has one thread where callbacks to Consumers are dispatched. At the end of the day, you're pretty much going to have a single Consumer in a single Channel all the time, because any other configuration would mess things up, right? So, why bother the two concepts?\n- @guillaume31 Good point. I think your question would be more appropriate to be answered by a developer of RabbitMQ, but anyway my guess would be that these concepts were introduced to adhere to the principle of seperation of concerns.\n- I think this reference to the Java Client API is now outdated and in fact today's reference directly contradicts the quote in this answer. Today's reference says \"Channel instances must not be shared between threads\".\n- @EdwinDalorzo - it looks like whomever originally wrote the documentation didn't fully understand the channel-connection dichotomy. The fundamental architecture of AMQP 0.9.1 really treats a channel as a session, so different threads sharing a session really is nonsense. My guess is that's the reason for the change.\n- Java Client API Guide — RabbitMQ - Channels and Concurrency Considerations (Thread Safety) says *As a rule of thumb, sharing Channel instances between threads is something to be avoided. Applications should prefer using a Channel per thread instead of sharing the same Channel across multiple threads.*\n- \"channels should not be pooled\", that's what I'm looking for\n- \"Since they are transient, channels should not be pooled by your app.\" - can you clarify how you came to this conclusion please. The docs recommend channel pooling if the \"one channel per thread\" implementation is using too much resource, see here: rabbitmq.com/channels.html#resource-usage\n- @ymas - The documentation you are referring to is speculative, and in my opinion, poor guidance. I am reading the source code and protocol spec. Channels are not to be pooled, period. Further, one channel per thread is guidance based on this same principle. If you find that you have so many open channels that the server is resource-constrained, you need to reevaluate your architecture (i.e. switch to a high-availability scheme and/or reduce concurrency).\n- @theMayer your position still need to be clarified in my opinion. I'm working on an Api that would have hundreds of thousands clients and thousands/second publishing message rate. I'm thinking to pool channels (guaranteeing once one of them is picked from the pool is used by only one thread), and I don't see any reason not to do that.\n- @MatteoSp, feel free to ask a new question and tag me. I don’t want to end up getting into an architecture discussion on an unrelated question/answer.\n- @theMayer I agree. The question would be a duplicate of this one. Perhaps you can articulate your points there? Thanks.\n- @MatteoSp, unfortunately the accepted answer on that question is absolutely incorrect. I am not here to fix every case of someone being wrong on the Internet.\n- @theMayer I did not ask that. In any case, let's terminate the debate. I just signal to you a paragraph of the official docs: *Those with particularly high concurrency rates (usually such applications are consumers) can start with one channel per thread/process/coroutine and **switch to channel pooling** when metrics suggest that the original model is no longer sustainable, e.g. because it consumes too much memory* (emphasis mine)\n- @MatteoSp, I’m not here to debate you. I am simply offering factual information based on experience and reading the source code. It is up to you if you’d like to learn the hard way or not.\n- @theMayer, great answer, thanks for the information. However, I too think that the part about not pooling channels is an opinion and you seem to confirm this by saying that it is the result of experience and analysis of the source code which means it is your opinion. Therefore, I would really appreciate if you could expand on it and help me understand what undesirable outcomes should I expect if I use a pooling mechanism for channels and how I can get around the limitations that forced me to use pooling in the first place. Thanks\n- @SoroushFalahati I think my answer is sufficiently detailed to provide an understanding of why you would not want to pool channels. However, if in doubt, refer to the adage that there are two hard things in computer science - cache invalidation and naming things. You get both problems with a channel pool!","metadata":{"transformedAt":"2026-08-18T18:33:20.112Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":15,"totalLines":178,"estimatedTokens":3329}}22{"id":"stack-7149074","source":"stackoverflow","questionId":7149074,"title":"Deleting all pending tasks in celery?","tags":["task","rabbitmq","celery","celery-task"],"text":"Title: Deleting all pending tasks in celery?\nTags: task, rabbitmq, celery, celery-task\nSource: Stack Overflow\n\nQuestion:\nHow can I delete all pending tasks without knowing the `task_id` for each task?\n\n========================================\n\nTop Answer:\nFor celery 3.0+:\n\n```\n$ celery purge\n```\n\nTo purge a specific queue:\n\n```\n$ celery -Q queue_name purge\n```\n\n========================================\n\nCode:\n```text\ntask_id\n```\n\n```text\n$ celery -A proj purge\n```\n\n```text\nfrom proj.celery import app\napp.control.purge()\n```\n\n```text\n$ celery purge\n```\n\n```text\n$ celery -Q queue_name purge\n```\n\n```text\n$ sudo rabbitmqctl list_queues -p celery name messages consumers\nListing queues ... # Output sorted, whitespaced for readability\ncelery 0 2\ncelery@web01.celery.pidbox 0 1\ncelery@web02.celery.pidbox 0 1\napns 0 1\napns@web01.celery.pidbox 0 1\nanalytics 1 1\nanalytics@web01.celery.pidbox 0 1\nbcast.361093f1-de68-46c5-adff-d49ea8f164c0 0 1\nbcast.a53632b0-c8b8-46d9-bd59-364afe9998c1 0 1\nceleryev.c27b070d-b07e-4e37-9dca-dbb45d03fd54 0 1\nceleryev.c66a9bed-84bd-40b0-8fe7-4e4d0c002866 0 1\nceleryev.b490f71a-be1a-4cd8-ae17-06a713cc2a99 0 1\nceleryev.9d023165-ab4a-42cb-86f8-90294b80bd1e 0 1\n```\n\n```text\n$ sudo /etc/init.d/celeryd stop # Wait for analytics task to be last one, Ctrl-C\n$ ps -ef | grep analytics # Get the PID of the worker, not the root PID reported by celery\n$ sudo kill <PID>\n$ sudo /etc/init.d/celeryd stop # Confim dead\n$ python manage.py celery amqp queue.purge analytics\n$ sudo rabbitmqctl list_queues -p celery name messages consumers # Confirm messages is 0\n$ sudo /etc/init.d/celeryd start\n```\n\n```text\ncelery purge\n```\n\n```text\ncelery purge\n```\n\n```text\ncelery worker -Q queue1,queue2,queue3\n```\n\n```text\ncelery worker -Q queue1,queue2,queue3 --purge\n```\n\n```text\ncelery amqp queue.delete queue1\ncelery amqp queue.delete queue2\ncelery amqp queue.delete queue3\n```\n\n```text\ncelery purge\n```\n\n```text\n--purge\n```\n\n```text\n$ celery -A proj purge\n```\n\n```text\n>>> from proj.celery import app\n>>> app.control.purge()\n```\n\n```text\ncelery -A proj amqp queue.purge <queue name>\n```\n\n```text\ncelery -A proj purge\n```\n\n```text\n$ sudo rabbitmqctl stop\n```\n\n```text\n$ sudo supervisorctl stop all\n```\n\n```text\n$ cd <source_dir>\n$ celery amqp queue.purge <queue name>\n```\n\n```text\n$ sudo rabbitmqctl start\n```\n\n```text\n$ sudo supervisorctl start all\n```\n\n```text\ncelery -A *APPNAME* purge\n```\n\n```text\nfrom proj.celery import app\napp.control.purge()\n```\n\n```text\nfrom proj.celery import app\nfrom celery.task.control import inspect, revoke\n\n# remove pending tasks\napp.control.purge()\n\n# remove active tasks\ni = inspect()\njobs = i.active()\nfor hostname in jobs:\n tasks = jobs[hostname]\n for task in tasks:\n revoke(task['id'], terminate=True)\n\n# remove reserved tasks\njobs = i.reserved()\nfor hostname in jobs:\n tasks = jobs[hostname]\n for task in tasks:\n revoke(task['id'], terminate=True)\n```\n\n```text\n# proj/celery.py\nfrom celery import Celery\napp = Celery('proj')\n```\n\n```py\nfrom proj.celery import app\nqueues = ['queue_A', 'queue_B', 'queue_C']\nwith app.connection_for_write() as conn:\n conn.connect()\n for queue in queues:\n count = app.amqp.queues[queue].bind(conn).purge()\n print(f'Purge {queue} with {count} message(s)')\n```\n\n```text\ncelery -A APP_NAME purge --queues QUEUE_NAME\n```\n\n```text\n-f\n```\n\n========================================\n\nComments:\n- Or, from Django, for celery 3.0+: `manage.py celery purge` (`celeryctl` is now deprecated and will be gone in 3.1).\n- I found this answer looking for how to do this with a redis backend. Best method I found was `redis-cli KEYS \"celery*\" | xargs redis-cli DEL` which worked for me. This will wipe out all tasks stored on the redis backend you're using.\n- How can i do this in celery 3.0 ?\n- For me, it was simply `celery purge` (inside the relevant virtual env). Ooops - there's an answer with the same below..... stackoverflow.com/a/20404976/1213425\n- For Celery 4.0+ in combination with Django it's again this command, where the argument to `-A` is the Django app where the `celery.py` is located.\n- this doesn't work on scheduled task. after such a `purge` you can still see them scheduled and they WILL run when their. time comes (you can see them with `inspect scheduled`)\n- No idea why, but this just seems to endlessly hang for me. To deal with it, I used `redis-cli --bigkeys` to find the biggest keys, which happened to be my queue names. I `DEL`'ed those keys in redis, and things seem to be OK. This is deletes your whole queue, but I was OK doing that.\n- If you get connection errors, make sure you specify the app, e.g. `celery -A proj purge`.\n- I believe the -Q flag has been deprecated (didn't work for me, \"no such option\"), to delete a specific queue on Celery 5.0.5 you'd run celery -A appname purge --queues queuename\n- Not an answer though, is it? Very informative however!\n- `celeryctl purge` didn't work with named queues. `python manage.py celery amqp queue.purge ` did. I think the context is useful for those with complex setups, so they can figure out what they need to do if `celeryctl purge` fails for them.\n- I cannot find `manage.py` in my Celery 3.1.17, has the file been removed or just spanking new? I found what looks like the corresponding interface (`queue.purge`) in `*/bin/amqp.py`, however. But after trying to correlate the contents of the file with the documentation, I must regrettably admit that Celery is woefully undocumented and also a *very* convoluted piece of work, at least judging it by its source code.\n- `manage.py` is the Django management script, and `manage.py celery` runs celery after loading configuration from Django settings. I haven't used celery outside of Django, but the included `celery` command may be what you are looking for: celery.readthedocs.org/en/latest/userguide/monitoring.html\n- Yes, this is for older (2.x and maybe 3.x) versions of celery. I cannot edit the answer\n- If you also want to revoke scheduled tasks, ie, those waiting due to an `eta` or `countdown`, you also need to revoke tasks in the `i.scheduled()` queue. For these, the `id` is inside a `request` key (at least for me on Redis), ie, you need to run `revoke(task['request']['id'])`. Also, for me on Celery 5.2.7 in Django at least, I needed to run `app.control.inspect`, and `app.control.revoke` - I couldn't import them independently (got an unbound error). My final code is here.","metadata":{"transformedAt":"2026-08-18T18:33:20.112Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":30,"totalLines":216,"estimatedTokens":1676}}23{"id":"stack-31915773","source":"stackoverflow","questionId":31915773,"title":"RabbitMQ\" What are \"Ready\" and \"Unacked\" types of messages?","tags":["rabbitmq"],"text":"Title: RabbitMQ\" What are \"Ready\" and \"Unacked\" types of messages?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm getting confused between these two types of messages in RabbitMQ.\n\nI've seen that some of my queues have 0 \"Unacked\" and 1000 \"Ready\" messages, while some have 1000 \"Unacked\" and 0 \"Ready\" messages.\n\nWhat's the difference between them?\n\nAnd how can I know how many of the messages are read by the consumer(s)?\n\n========================================\n\nTop Answer:\nhttps://i.sstatic.net/JmKg1.png\n\n**Un-acknowledgment**:\nIt is used for Data Safety Considerations. it guaranteed to reach the peer and successfully processed. In case consumer lost in-between of processing of message and not acknowledge the Rabbit MQ. message will not lost and available for cosumer to process it again.\n\n========================================\n\nComments:\n- Worth to mention the Message is ready (waiting) even if there is not a single consumer. `Ready` messages are collected by the RabbitMQ. `Unacked` messages are \"touched\" by consumers but related jobs are not confirmed yet as done.\n- \"When the consumer crashed the queue knows which messages are to be delivered again when the consumer comes online.\" Does that mean you need the same consumer to handle unacked messages? Or can it be a newly launched consumer, for example in case of a full crash.\n- Nice piece of information about what will happen to UnAck messages.","metadata":{"transformedAt":"2026-08-18T18:33:20.112Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":27,"estimatedTokens":357}}24{"id":"stack-12792856","source":"stackoverflow","questionId":12792856,"title":"What ports does RabbitMQ use?","tags":["rabbitmq","port"],"text":"Title: What ports does RabbitMQ use?\nTags: rabbitmq, port\nSource: Stack Overflow\n\nQuestion:\nWhat ports does RabbitMQ Server use or need to have open on the firewall for a cluster of nodes?\n\nMy `/usr/lib/rabbitmq/bin/rabbitmq-env` is set below which I'm assuming are needed (35197).\n\n```\nSERVER_ERL_ARGS=\"+K true +A30 +P 1048576 \\ \n-kernel inet_default_connect_options [{nodelay,true}] \\ \n-kernel inet_dist_listen_min 35197 \\ \n-kernel inet_dist_listen_max 35197\"\n```\n\nI haven't touched the `rabbitmq.config` to set a custom `tcp_listener` so it should be listening on the default 5672.\n\nHere are the relevant netstat lines:\n\n```\ntcp 0 0 0.0.0.0:4369 0.0.0.0:* LISTEN 728/epmd \ntcp 0 0 0.0.0.0:35197 0.0.0.0:* LISTEN 5126/beam\ntcp6 0 0 :::5672 :::* LISTEN 5126/beam\n```\n\nMy questions are:\n\nfor other nodes to be able to connect to the cluster, do all 3 ports 4369, 5672 and 35197 need to be open?\n\nWhy isn't 5672 running on tcp and not just tcp6?\n\n========================================\n\nTop Answer:\n### What ports is RabbitMQ using?\n\nDefault: 5672, the manual has the answer. It's defined in the `RABBITMQ_NODE_PORT` variable.\n\nhttps://www.rabbitmq.com/configure.html#define-environment-variables\n\n**The number might be differently if changed by someone in the rabbitmq configuration file:**\n\n```\nvi /etc/rabbitmq/rabbitmq-env.conf\n```\n\n**Ask the nmap if it can see it:**\n\n```\nsudo nmap -p 1-65535 localhost\n\nStarting Nmap 5.51 ( http://nmap.org ) at 2014-09-19 13:50 EDT\nNmap scan report for localhost (127.0.0.1)\nHost is up (0.00041s latency).\nPORT STATE SERVICE\n443/tcp open https\n5672/tcp open amqp\n15672/tcp open unknown\n35102/tcp open unknown\n59440/tcp open unknown\n```\n\nOh look, 5672, and 15672\n\n**Ask netstat if it can see it:**\n\n```\nnetstat -lntu\nActive Internet connections (only servers)\nProto Recv-Q Send-Q Local Address Foreign Address State\ntcp 0 0 0.0.0.0:15672 0.0.0.0:* LISTEN\ntcp 0 0 0.0.0.0:55672 0.0.0.0:* LISTEN\ntcp 0 0 :::5672 :::* LISTEN\n```\n\nOh look 5672.\n\n**lsof to see ports:**\n\n```\neric@dev ~$ sudo lsof -i | grep beam\nbeam.smp 21216 rabbitmq 17u IPv4 33148214 0t0 TCP *:55672 (LISTEN)\nbeam.smp 21216 rabbitmq 18u IPv4 33148219 0t0 TCP *:15672 (LISTEN)\n```\n\n**use nmap from a different machine, find out if 5672 is open:**\n\n```\nsudo nmap -p 5672 10.0.1.71\nStarting Nmap 5.51 ( http://nmap.org ) at 2014-09-19 13:19 EDT\nNmap scan report for 10.0.1.71\nHost is up (0.00011s latency).\nPORT STATE SERVICE\n5672/tcp open amqp\nMAC Address: 0A:40:0E:8C:75:6C (Unknown) \nNmap done: 1 IP address (1 host up) scanned in 0.13 seconds\n```\n\n**Try to connect to a port manually with telnet, 5671 is CLOSED:**\n\n```\ntelnet localhost 5671\nTrying 127.0.0.1...\ntelnet: connect to address 127.0.0.1: Connection refused\n```\n\n**Try to connect to a port manually with telnet, 5672 is OPEN:**\n\n```\ntelnet localhost 5672\nTrying 127.0.0.1...\nConnected to localhost.\nEscape character is '^]'.\n```\n\n**Check your firewall:**\n\n```\nsudo cat /etc/sysconfig/iptables\n```\n\nIt should tell you what ports are made open:\n\n```\n-A INPUT -p tcp -m tcp --dport 5672 -j ACCEPT\n```\n\n**Reapply your firewall:**\n\n```\nsudo service iptables restart\niptables: Setting chains to policy ACCEPT: filter [ OK ]\niptables: Flushing firewall rules: [ OK ]\niptables: Unloading modules: [ OK ]\niptables: Applying firewall rules: [ OK ]\n```\n\n========================================\n\nCode:\n```text\nSERVER_ERL_ARGS=\"+K true +A30 +P 1048576 \\ \n-kernel inet_default_connect_options [{nodelay,true}] \\ \n-kernel inet_dist_listen_min 35197 \\ \n-kernel inet_dist_listen_max 35197\"\n```\n\n```text\ntcp 0 0 0.0.0.0:4369 0.0.0.0:* LISTEN 728/epmd \ntcp 0 0 0.0.0.0:35197 0.0.0.0:* LISTEN 5126/beam\ntcp6 0 0 :::5672 :::* LISTEN 5126/beam\n```\n\n```text\n/usr/lib/rabbitmq/bin/rabbitmq-env\n```\n\n```text\nrabbitmq.config\n```\n\n```text\ntcp_listener\n```\n\n```text\n5672\n```\n\n```text\n5671\n```\n\n```text\n35197\n```\n\n```text\n4369\n```\n\n```text\n5672\n```\n\n```text\n5672\n```\n\n```text\n5671\n```\n\n```text\n$ epmd -names\n```\n\n```text\nepmd: up and running on port 4369 with data:\nname rabbit at port 25672\n```\n\n```text\nlsof -i :4369\nlsof -i :25672\n```\n\n```text\nvi /etc/rabbitmq/rabbitmq-env.conf\n```\n\n```text\nsudo nmap -p 1-65535 localhost\n\nStarting Nmap 5.51 ( http://nmap.org ) at 2014-09-19 13:50 EDT\nNmap scan report for localhost (127.0.0.1)\nHost is up (0.00041s latency).\nPORT STATE SERVICE\n443/tcp open https\n5672/tcp open amqp\n15672/tcp open unknown\n35102/tcp open unknown\n59440/tcp open unknown\n```\n\n```text\nnetstat -lntu\nActive Internet connections (only servers)\nProto Recv-Q Send-Q Local Address Foreign Address State\ntcp 0 0 0.0.0.0:15672 0.0.0.0:* LISTEN\ntcp 0 0 0.0.0.0:55672 0.0.0.0:* LISTEN\ntcp 0 0 :::5672 :::* LISTEN\n```\n\n```text\neric@dev ~$ sudo lsof -i | grep beam\nbeam.smp 21216 rabbitmq 17u IPv4 33148214 0t0 TCP *:55672 (LISTEN)\nbeam.smp 21216 rabbitmq 18u IPv4 33148219 0t0 TCP *:15672 (LISTEN)\n```\n\n```text\nsudo nmap -p 5672 10.0.1.71\nStarting Nmap 5.51 ( http://nmap.org ) at 2014-09-19 13:19 EDT\nNmap scan report for 10.0.1.71\nHost is up (0.00011s latency).\nPORT STATE SERVICE\n5672/tcp open amqp\nMAC Address: 0A:40:0E:8C:75:6C (Unknown) \nNmap done: 1 IP address (1 host up) scanned in 0.13 seconds\n```\n\n```text\ntelnet localhost 5671\nTrying 127.0.0.1...\ntelnet: connect to address 127.0.0.1: Connection refused\n```\n\n```text\ntelnet localhost 5672\nTrying 127.0.0.1...\nConnected to localhost.\nEscape character is '^]'.\n```\n\n```text\nsudo cat /etc/sysconfig/iptables\n```\n\n```text\n-A INPUT -p tcp -m tcp --dport 5672 -j ACCEPT\n```\n\n```text\nsudo service iptables restart\niptables: Setting chains to policy ACCEPT: filter [ OK ]\niptables: Flushing firewall rules: [ OK ]\niptables: Unloading modules: [ OK ]\niptables: Applying firewall rules: [ OK ]\n```\n\n```text\nRABBITMQ_NODE_PORT\n```\n\n```text\n\\AppData\\Roaming\\RabbitMQ\\log\n```\n\n```text\nstarted TCP listener on [::]\n```\n\n========================================\n\nComments:\n- Might get more response on ServerFault instead of StackOverflow but I'm glad you posted it here as it is exactly what I'm looking for!\n- Looks like the clustering ports are 4369 and 25672 from: rabbitmq.com/clustering.html\n- `lsof` is painfully slow... and it requires root privileges. You can do the same, much more rapidly, with `netstat -an | egrep '\\.(4369|25672).*LISTEN'`\n- does it really require root? I was able to run it fine as a normal user. Maybe something changed in the recent versions?\n- Excellent answer. If anything, you've gone overboard a little.\n- In case somebody was wondering - by default rabbitmq will only bind 4369 port to interface you specify within rabbitmq-env.conf; If you wanted to permitt all rabbitmq-related traffic through specified interface (like myself - through dedicated openvpn link) then you will have to configure rabbitmq to pass all other traffic through that interface within rabbitmq.conf (otherwise other ports won't be bound to interface of your choice but will be listening on all ports instead)","metadata":{"transformedAt":"2026-08-18T18:33:20.112Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":28,"totalLines":302,"estimatedTokens":1839}}25{"id":"stack-42151544","source":"stackoverflow","questionId":42151544,"title":"When to use RabbitMQ over Kafka?","tags":["apache-kafka","rabbitmq","message-queue"],"text":"Title: When to use RabbitMQ over Kafka?\nTags: apache-kafka, rabbitmq, message-queue\nSource: Stack Overflow\n\nQuestion:\nI've been asked to evaluate RabbitMQ instead of Kafka but found it hard to find a situation where a message queue is more suitable than Kafka. Does anyone know use cases where a message queue fits better in terms of throughput, durability, latency, or ease-of-use?\n\n========================================\n\nTop Answer:\nI hear this question every week. While RabbitMQ (like IBM MQ or JMS or other messaging solutions in general) is used for traditional messaging, Apache Kafka is used as a streaming platform (messaging + distributed storage + data processing). Both are built for different use cases.\n\nYou can use Kafka for \"traditional messaging\", but not use MQ for Kafka-specific scenarios.\n\nThe article **Apache Kafka vs. Enterprise Service Bus (ESB)—Friends, Enemies, or Frenemies?** discusses why Kafka is not competitive but complementary to integration and messaging solutions (including RabbitMQ) and how to integrate both.\n\n========================================\n\nComments:\n- primarily opinion-based,Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.\n- @Guillaume That's not necessarily true. There a clients for many languages available for Kafka: cwiki.apache.org/confluence/display/KAFKA/Clients Furthermore, Confluent offers many high performant open source Kafka clients in other languages. Check out \"Confluent Open Source\" offer: confluent.io/product/compare\n- @MatthiasJ.Sax Both RabbitMQ and kafka have a wealth of clients in many languages, but my point was about official clients. In the link you gave it is written black on white: *we are maintaining all but the jvm client external to the main code base*. Regarding confluent, I am indeed a big user, but the additional clients are through the language agnostic rest API, which although quite awesome does not have the same throughput as the official java client.\n- @Guillaume For \"random\" open source clients from the community I agree; not all a high performance (it pretty hard to write a good client) -- that why I put \"That's not **necessarily** true.\" ;) However, Confluent's provided C/C++ and Python clients are high throughput and as efficient as the AK Java clients...\n- I would recommend reading this blog: jack-vanlightly.com/blog/2017/12/4/…\n- @roottraveller's shared bog is worth reading. do give it a read.\n- Panopticum supports both! Web UI for browsing Kafka topics/partitions and RabbitMQ queues. Docker-ready. hub.docker.com/r/sharque/panopticum\n- What does \"high-ingress\" mean?\n- high-ingress = high-throughput ingestion\n- I question your point about RabbitMQ \"mostly designed for vertical scaling\". How so...\n- @Ryan.Bartsch I also wonder how did he come into this understanding.. AFAIK you can horizontally scale both of them just fine..\n- Horizontal scaling (scale by adding more machines) does not give you a better performance in RabbitMQ. Best performance is received when you do vertical scaling (scale by adding more power). I know this because I have been working with thousands of RabbitMQ clusters for many years now. You can do horizontal scaling in Rabbit, but that means that you also set up clustering between your nodes, which will slow down your setup. I wrote a guide about best practice for high performance vs high availability in RabbitMQ: cloudamqp.com/blog/2017-12-29-part1-rabbitmq-best-practice.h‌​tml\n- For \"high-ingress\" imagine streaming big data instead of small transactions\n- \"...while Kafka doesn't, it assumes the consumer keep tracks of what's been consumed and not.\" This is incorrect. Kafka keeps track of the messages consumed by each individual consumer.\n- In order to understand how to read data from Kafka, we first need to understand its consumers and consumer groups. Kafka consumer groups keep track of which offset the group is on. Still a bit more complex to understand than for RabbitMQ, where the message is simply removed from the queue once it's ack:ed.\n- `Kafka doesn't, it assumes the consumers keep track of what's been consumed and not.` Huhh? I don't know what you mean by that. Kafka has the `__consumer_offsets` topic which has all this metadata. If Kafka wasn't keeping track of which consumer consumed what, how would consumers have the ability to go completely offline and switch to totally different hardware (& still be able to pick up where they left)?\n- @akki the same way other streaming platforms do. The consumer maintains record of the last offset that it processed. After it processes a message, it commits the new offset. EventHubs does this using a storage account, EventStore expects you to figure it out on your own -- we used a redis cache in that case. So if a consumer goes offline, when it comes back, the first thing it does is look up the last offset and continues from there.\n- Exactly, when it comes back it looks up \"somewhere\" for the last offset. That means this \"somewhere\" is keeping track of the last offset - that \"somewhere\" BTW is Kafka (or Zookeeper in older versions).\n- Isn't the \"__consumer_offsets\" a fairly recent addition to Kafka, IIRC 2016 and earlier one had to store this on the consumer side manually? The above answer is from 2017. just saying there might be truths that have changed here over time\n- This answer doesn't sound right at all...what complex routing is available in Kafka?\n- The answer doesn't mention RabbitMQ Streams feature rabbitmq.com/docs/streams which are basically kafka like topics with replay (time-travelling) functionality and append-only high volume optimiztion. RabbitMQ streams were introduced in v3.9.0 in 2021\n- It says it's complementary to an already existing MQ and ESB solutions (because rebuilding is probably difficult), but that newer solutions are all Kafka.\n- Kafka has transactions\n- I don't agree how you infer RMQ has \"some complexity\" as if to say Kafka has less complexity.\n- Where is your source for this information? I don't agree with your answer regarding performance in RabbitMQ - that depends on the number of queues, connections etc.\n- Correct. But average variance range is similar as stated above. There are scenario where it does better or worse than above mentioned range. Refer Rabbitmq blog. Latest data points might have changed rabbitmq.com/blog/2012/04/25/…\n- @Shishir - Could you more details/links that explain the different message exchange types - direct, fan out, pub/sub etc? These sound to be helpful in determining the right messaging platform for given requirements. Thanks\n- @Shishir a link from 2012, might have changed, yes.\n- @AndyDufresne, a bit late, but here is a link: cloudamqp.com/blog/…\n- You can achieve both pull and push with RabbitMQ\n- RabbitMQ introduced the streams feature in v3.9.0 rabbitmq.com/docs/streams which brings kafka like queues with streaming semantics to RabbitMQ\n- This is one of the main reasons we decided to use RabbitMQ instead of kafka in our microservice based system. It was very important for use to be flexible in increasing and decreasing consumers according to the message income rate, in RabbitMQ this is easy you simply start more consumers, no repartition is needed like in kafka.\n- But that also does mean, you have to take care of concurrency at application level and not at broker level. So.. ofc, for scenario you mentioned its great. For certain scenario, the benefits turn into issues.\n- Multi subscribers is handled fine, not in a single queue but fanning out to multiple and potentially dynamic queues. Rabbit is certainly not just for 'simple use cases' it's for a completely different paragdim but no less complex than large data sets that need retaining for long periods. Can you expand on the message priority part?\n- \"*...Can you add one more consumer to queue - no you can't do that....*\", why can't we add more than one consumer to the same queue in rabbitmq? RabbitMQ says we can here clearly. The messages are delivered to multiple consumers in a round-robin way.\n- @SkrewEverything you absolutely can. This entire answer is based on a wrongful assumption that you cannot.\n- Rabbitmq official website -> tutorial number 2 (workers) contradicts you\n- You can increase and decrease the number of RabbitMQ consumers anytime without doing anything in RabbitMQ's queue! This is one of the main reasons we used RabbitMQ instead of kafka!\n- [+1] Good explanation, I am sure you have been using them in your projects, could you name some that have used either of them in mounting application message systems?\n- @GingerHead We worked with a radio company that used RabbitMQ for their GUI and ease of setup. It was great for developers to easily check on the status of their microservices. The same company also used Kafka for high-volume streams of data that needed to have retention time of over three days. If you are interested in reading more about the differences between the two technologies here is an article I wrote on the topic: Kafka vs. RabbitMQ article.","metadata":{"transformedAt":"2026-08-18T18:33:20.113Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":59,"estimatedTokens":2300}}26{"id":"stack-10620976","source":"stackoverflow","questionId":10620976,"title":"Single queue, multiple consumers for same message?","tags":["node.js","messaging","rabbitmq","amqp","node-amqp"],"text":"Title: Single queue, multiple consumers for same message?\nTags: node.js, messaging, rabbitmq, amqp, node-amqp\nSource: Stack Overflow\n\nQuestion:\nI am just starting to use RabbitMQ and AMQP in general.\n\n- I have a queue of messages\n\n- I have multiple consumers, which I would like to do different things with the **same message**.\n\nMost of the RabbitMQ documentation seems to be focused on round-robin, ie where a single message is consumed by a single consumer, with the load being spread between each consumer. This is indeed the behavior I witness. \n\nAn example: the producer has a single queue, and send messages every 2 sec:\n\n```\nvar amqp = require('amqp');\nvar connection = amqp.createConnection({ host: \"localhost\", port: 5672 });\nvar count = 1;\n\nconnection.on('ready', function () {\n var sendMessage = function(connection, queue_name, payload) {\n var encoded_payload = JSON.stringify(payload); \n connection.publish(queue_name, encoded_payload);\n }\n\n setInterval( function() { \n var test_message = 'TEST '+count\n sendMessage(connection, \"my_queue_name\", test_message) \n count += 1;\n }, 2000) \n\n})\n```\n\nAnd here's a consumer:\n\n```\nvar amqp = require('amqp');\nvar connection = amqp.createConnection({ host: \"localhost\", port: 5672 });\nconnection.on('ready', function () {\n connection.queue(\"my_queue_name\", function(queue){\n queue.bind('#'); \n queue.subscribe(function (message) {\n var encoded_payload = unescape(message.data)\n var payload = JSON.parse(encoded_payload)\n console.log('Recieved a message:')\n console.log(payload)\n })\n })\n})\n```\n\nIf I start the consumer twice, **I can see that each consumer is consuming alternate messages in round-robin behavior. Eg, I'll see messages 1, 3, 5 in one terminal, 2, 4, 6 in the other**.\n\nMy question is: \n\nCan I have each consumer receive the same messages? Ie, both consumers get message 1, 2, 3, 4, 5, 6? What is this called in AMQP/RabbitMQ speak? How is it normally configured?\n\nIs this commonly done? Should I just have the exchange route the message into two separate queues, with a single consumer, instead?\n\n========================================\n\nTop Answer:\nThe last couple of answers are almost correct - I have tons of apps that generate messages that need to end up with different consumers so the process is very simple.\n\nIf you want multiple consumers to the same message, do the following procedure.\n\nCreate multiple queues, one for each app that is to receive the message, in each queue properties, \"bind\" a routing tag with the amq.direct exchange. Change you publishing app to send to amq.direct and use the routing-tag (not a queue). AMQP will then copy the message into each queue with the same binding. Works like a charm :)\n\nExample: Lets say I have a JSON string I generate, I publish it to the \"amq.direct\" exchange using the routing tag \"new-sales-order\", I have a queue for my order_printer app that prints order, I have a queue for my billing system that will send a copy of the order and invoice the client and I have a web archive system where I archive orders for historic/compliance reasons and I have a client web interface where orders are tracked as other info comes in about an order.\n\nSo my queues are: order_printer, order_billing, order_archive and order_tracking\nAll have the binding tag \"new-sales-order\" bound to them, all 4 will get the JSON data.\n\nThis is an ideal way to send data without the publishing app knowing or caring about the receiving apps.\n\n========================================\n\nCode:\n```text\nvar amqp = require('amqp');\nvar connection = amqp.createConnection({ host: \"localhost\", port: 5672 });\nvar count = 1;\n\nconnection.on('ready', function () {\n var sendMessage = function(connection, queue_name, payload) {\n var encoded_payload = JSON.stringify(payload); \n connection.publish(queue_name, encoded_payload);\n }\n\n setInterval( function() { \n var test_message = 'TEST '+count\n sendMessage(connection, \"my_queue_name\", test_message) \n count += 1;\n }, 2000) \n\n\n})\n```\n\n```text\nvar amqp = require('amqp');\nvar connection = amqp.createConnection({ host: \"localhost\", port: 5672 });\nconnection.on('ready', function () {\n connection.queue(\"my_queue_name\", function(queue){\n queue.bind('#'); \n queue.subscribe(function (message) {\n var encoded_payload = unescape(message.data)\n var payload = JSON.parse(encoded_payload)\n console.log('Recieved a message:')\n console.log(payload)\n })\n })\n})\n```\n\n```text\nvar amqp = require('amqp');\nvar connection = amqp.createConnection({ host: \"localhost\", port: 5672 });\nvar count = 1;\n\nconnection.on('ready', function () {\n connection.exchange(\"my_exchange\", options={type:'fanout'}, function(exchange) { \n \n var sendMessage = function(exchange, payload) {\n console.log('about to publish')\n var encoded_payload = JSON.stringify(payload);\n exchange.publish('', encoded_payload, {})\n }\n\n // Recieve messages\n connection.queue(\"my_queue_name\", function(queue){\n console.log('Created queue')\n queue.bind(exchange, ''); \n queue.subscribe(function (message) {\n console.log('subscribed to queue')\n var encoded_payload = unescape(message.data)\n var payload = JSON.parse(encoded_payload)\n console.log('Recieved a message:')\n console.log(payload)\n })\n })\n \n setInterval( function() { \n var test_message = 'TEST '+count\n sendMessage(exchange, test_message) \n count += 1;\n }, 2000) \n })\n})\n```\n\n```text\nrabbit.on('ready', function () { });\n sockjs_chat.on('connection', function (conn) {\n\n conn.on('data', function (message) {\n try {\n var obj = JSON.parse(message.replace(/\\r/g, '').replace(/\\n/g, ''));\n\n if (obj.header == \"register\") {\n\n // Connect to RabbitMQ\n try {\n conn.exchange = rabbit.exchange(exchange, { type: 'topic',\n autoDelete: false,\n durable: false,\n exclusive: false,\n confirm: true\n });\n\n conn.q = rabbit.queue('my-queue-'+obj.agentID, {\n durable: false,\n autoDelete: false,\n exclusive: false\n }, function () {\n conn.channel = 'my-queue-'+obj.agentID;\n conn.q.bind(conn.exchange, conn.channel);\n\n conn.q.subscribe(function (message) {\n console.log(\"[MSG] ---> \" + JSON.stringify(message));\n conn.write(JSON.stringify(message) + \"\\n\");\n }).addCallback(function(ok) {\n ctag[conn.channel] = ok.consumerTag; });\n });\n } catch (err) {\n console.log(\"Could not create connection to RabbitMQ. \\nStack trace -->\" + err.stack);\n }\n\n } else if (obj.header == \"typing\") {\n\n var reply = {\n type: 'chatMsg',\n msg: utils.escp(obj.msga),\n visitorNick: obj.channel,\n customField1: '',\n time: utils.getDateTime(),\n channel: obj.channel\n };\n\n conn.exchange.publish('my-queue-'+obj.agentID, reply);\n }\n\n } catch (err) {\n console.log(\"ERROR ----> \" + err.stack);\n }\n });\n\n // When the visitor closes or reloads a page we need to unbind from RabbitMQ?\n conn.on('close', function () {\n try {\n\n // Close the socket\n conn.close();\n\n // Close RabbitMQ \n conn.q.unsubscribe(ctag[conn.channel]);\n\n } catch (er) {\n console.log(\":::::::: EXCEPTION SOCKJS (ON-CLOSE) ::::::::>>>>>>> \" + er.stack);\n }\n });\n });\n```\n\n```text\namqp.connect('amqp://<user>:<pass>@<host>:<port>', async (error0, connection) => {\n if (error0) {\n throw error0;\n }\n console.log('RabbitMQ connected')\n try {\n // Create exchange for queues\n channel = await connection.createChannel()\n await channel.assertExchange(process.env.EXCHANGE_NAME, 'fanout', { durable: false });\n await channel.publish(process.env.EXCHANGE_NAME, '', Buffer.from('msg'))\n } catch(error) {\n console.error(error)\n }\n})\n```\n\n```text\namqp.connect('amqp://<user>:<pass>@<host>:<port>', async (error0, connection) => {\n if (error0) {\n throw error0;\n }\n console.log('RabbitMQ connected')\n try {\n // Create/Bind a consumer queue for an exchange broker\n channel = await connection.createChannel()\n await channel.assertExchange(process.env.EXCHANGE_NAME, 'fanout', { durable: false });\n const queue = await channel.assertQueue('', {exclusive: true})\n channel.bindQueue(queue.queue, process.env.EXCHANGE_NAME, '')\n\n console.log(\" [*] Waiting for messages in %s. To exit press CTRL+C\");\n channel.consume('', consumeMessage, {noAck: true});\n } catch(error) {\n console.error(error)\n }\n});\n```\n\n```text\nfanout\n```\n\n```text\nerr = ctx.rmqChannel.Publish(\n rabbitMQExchange, // direct exchange\n rk, // routing key\n false, // mandatory\n false, // immediate\n amqp.Publishing{\n ContentType: \"application/json\",\n Body: v,\n },\n )\n\n q, err := ch.QueueDeclare(\n uuid.New().String(), // random unique name\n true, // durable\n true, // delete when unused\n false, // exclusive\n false, // no-wait\n nil, // arguments\n )\n\n if err := ch.QueueBind(\n q.Name, // queue name\n rk, // routing key matches above rk\n rabbitMQExchange, // direct exchange\n false, // no-wait\n nil, // arguments\n ); err != nil {\n return\n }\n\n msgs, err := ch.Consume(\n q.Name, // queue\n \"\", // id, a uuid is probably good too\n true, // auto-ack\n false, // exclusive\n false, // no-local\n false, // no-wait\n nil, // args\n )\n```\n\n========================================\n\nComments:\n- I am no RabbitMQ expert. However, what you now have is called queue but what you want is topics, see this tutorial: rabbitmq.com/tutorials/tutorial-five-python.html, more on queues vs. topics: msdn.microsoft.com/en-us/library/windowsazure/hh367516.aspx\n- I believe he wants fanout actually though topics will work as well and will give more control later.\n- Thanks @UrbanEsc. Topics seems to solve the problem by having one message hit multiple queues, and therefore be consumed by each queues consumers. Which leans me further towards the multiple queue/single consumer scenario for my particular case.\n- For 2018 (and even for 2016 and earlier) the answer is to use something like Kafka, IMO.\n- great answer, except by 'is this commonly done?' I was referring to 'having each consumer receive the same messages' - which isn't commonly done (consumers on the same queue always round robin). Probably my fault for not being clear enough.\n- Actually I would venture to say that it depends what you want to use it for. You have two basic choices pub/sub or work queues. Your original set up was a work queue but what you wanted was a fanout pub/sub. They point is that common usage here is totally dependent on what you want to do.\n- Sure but in a work queue, the same message (eg, the same message ID) is not handled by different consumers - it's implicitly round robin. Again this is probably my fault for not being clear enough.\n- we appear to be talking at cross purposes here.\n- Sorry about the confusion. If there's some way of having a work queue where consumers on the same queue handle the same message ID, please point me to a reference. Otherwise I'll continue to believe what I've read elsewhere.\n- No. However, you could try having a fanout exchange with multiple queues all receiving the same message. Then each queue has a set of consumers (workers) receiving the messages from the queue in a round robin. You could then get the same message processed as many times as you have queues, and the speed would be determined by how many consumers each queue has.\n- OK. It sounds like we're on the same track.\n- fan out was clearly what you wanted. It would not help you here, but I thought I'd mention round-robin behaviour within a queue is configurable. `int prefetchCount = 1; channel.basicQos(prefetchCount);` This will allow each consumers to receive a message as soon as it's finished with the previous one. Instead of receiving alternating messages. Again doesn't solve your problem, but could be useful for people to know. example here http://www.rabbitmq.com/tutorials/tutorial-two-java.html under Fair Dispatch\n- To clarify: 'default exchange' is not node-amqp specific. It's general AMQP concept with following rules: when any message published to default exchange, the routing key (with which that message published) treated as queue name by AMQP broker. So it seems like you can publish to queues directly. But you are not. The broker simply bind each queue to default exchange with routing key equal to queue name.\n- Is there any alternative to Apache activemq jms topics in rabbitmq where no queues are involved but rather multicasting?\n- If same user login from multiple devices then message get only one device.How can be solved it or any idea please?\n- @Rafiq you should ask a question for this.\n- @mikemaccana Please check it. It is my question. I am not clear how can be solve it. stackoverflow.com/questions/47492996/…\n- This is late but for future reference, it is possible for each consumer to receive the same message, I was able to implement for the scenario that you described\n- @Clint add an answer with details then.\n- sure thing, but right now I'm looking for a way to maintain 1 long running connection among multiple clients\n- Usually, if you want to send the exact same message to different consumers, you would use another tools that works with \"pub/sub\" messaging and topics! It's used a lot when you want to stream events for your apps to react on something.\n- What if the consumers are dynamic? I want different instances of the same app receive the same message. Any alternatives?\n- Each instance should dynamically bind a queue to the exchange, just for itself. (Making it nondurable and autodelete is ideal, so it goes away along with the instance.) The only real difference is that you won't have fixed names for the queues, unless you want collisions (you don't!).\n- I'd highly advice against this, as it does not scale by any means. There is no order for consumers, you cannot guarantee consumer B who will not requeue it, receives the message before consumer A who will process and requeue it, the mentioned loops are a problem. As you say \"this is generally speaking not the right way\", and I cannot think of a scenario where this would be better than the other answers.","metadata":{"transformedAt":"2026-08-18T18:33:20.113Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":337,"estimatedTokens":3856}}27{"id":"stack-22850546","source":"stackoverflow","questionId":22850546,"title":"Can't access RabbitMQ web management interface after fresh install","tags":["rabbitmq"],"text":"Title: Can't access RabbitMQ web management interface after fresh install\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI've installed the latest RabbitMQ server (rabbitmq-server-3.3.0-1.noarch.rpm) on a fresh Centos 5.10 VM according to the instructions on the official site.\n\nI've done this many times before during development and never had any issues. However, this time I cannot log into the management web interface using the default guest/guest user.\n\nIn the logs, I see the following:\n\n```\n=ERROR REPORT==== 4-Apr-2014::00:55:15 ===\nwebmachine error: path=\"api/whoami\"\n\"Unauthorized\"\n```\n\nWhat could be causing this?\n\n========================================\n\nTop Answer:\nIf you still can't access the management console after a fresh install, check if the **management console was enabled.** To enable it:\n\nGo to the RabbitMQ command prompt.\n\nType:\n\n```\nrabbitmq-plugins enable rabbitmq_management\n```\n\n========================================\n\nCode:\n```text\n=ERROR REPORT==== 4-Apr-2014::00:55:15 ===\nwebmachine error: path=\"api/whoami\"\n\"Unauthorized\"\n```\n\n```text\nserver\n------\n\n...\n25603 prevent access using the default guest/guest credentials except via\n localhost.\n```\n\n```text\n# remove guest from loopback_users in rabbitmq.config like this\n[{rabbit, [{loopback_users, []}]}].\n# It is danger for default user and default password for remote access\n# better to change password \nrabbitmqctl change_password guest NEWPASSWORD\n```\n\n```text\nrabbitmqctl add_user test test\nrabbitmqctl set_user_tags test administrator\nrabbitmqctl set_permissions -p / test \".*\" \".*\" \".*\"\n```\n\n```text\nrabbitmq-plugins enable rabbitmq_management\n```\n\n```text\nrabbitmqctl add_user test test\nrabbitmqctl set_user_tags test administrator\nrabbitmqctl set_permissions -p / test \".*\" \".*\" \".*\"\n```\n\n```text\nrabbitmqctl change_password test test\n```\n\n```text\n/usr/local/etc/rabbitmq/rabbitmq-env.conf\n```\n\n```text\nNODE_IP_ADDRESS=\n```\n\n```text\nbrew services restart rabbitmq\n```\n\n```text\nnetsh advfirewall firewall add rule name=\"RabbitMQ Management\" dir=in action=allow protocol=TCP localport=15672\nnetsh advfirewall firewall add rule name=\"RabbitMQ\" dir=in action=allow protocol=TCP localport=5672\n```\n\n========================================\n\nComments:\n- Often checking firewall rules additionally to this answer solve the other wast of majority auth and connection errors.\n- if you followed the instructions to create a new user but still get \"login failed\" then you may need to clear the browser cache (in firefox it is \"clear recent history\") and make sure to clear the \"active logins\" too. See here for more info\n- I couldn't get guest working even though I sorted out the config file, but Im guessing I didn't have permissions set because once I set up this test account i was away running\n- I had a RMQ cluster with my LB managing the traffic, so I had to add the user to both the nodes (Master & Slave) for it to work properly.\n- This was the case after installing with Chocolatety on Windows 10. The installation script said the management plugin was enabled, but in reality, no plugins were enabled.\n- For dummies like myself: 1. Go to folder: C:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.7.3\\sbin. 2. run rabbitmq-plugins enable rabbitmq_management 3. go to services, restart rabbitmq service manually (or run rabbmimq-service restart)\n- Fixed it for me (note the timestamp).\n- fixed it. (you might need `sudo`)\n- With clean installation web interface wasn't enabled with given instructions under this answer. Was able to get to web interface however, guest user login was still not working. Followed the instructions given under this thread (stackoverflow.com/a/40845332/1132288) and able to login with the \"test\" user.\n- After enabling the management plugin, restarting the RabbitMQ service did it for me.","metadata":{"transformedAt":"2026-08-18T18:33:20.113Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":11,"totalLines":108,"estimatedTokens":956}}28{"id":"stack-15150133","source":"stackoverflow","questionId":15150133,"title":"JMS and AMQP - RabbitMQ","tags":["java","jms","rabbitmq","message-queue","amqp"],"text":"Title: JMS and AMQP - RabbitMQ\nTags: java, jms, rabbitmq, message-queue, amqp\nSource: Stack Overflow\n\nQuestion:\nI am trying to understand what JMS and how it is connected to AMQP terminology.\nI know JMS is an API and AMQP is a protocol. \n\nHere are my assumptions (and questions as well)\n\n- RabbitMQ uses AMQP protocol (rather implements AMQP protocol)\n\n- Java clients need to use AMQP protocol client libraries to connect / use RabbitMQ\n\n- Where does JMS API come into play here? JMS API should use AMQP client libraries to connect to RabbitMQ?\n\n- Usually we use JMS to connect Message brokers like RabbitMQ, ActiveMQ, etc. Then what is the default protocol used here instead of AMQP?\n\nSome of the above may be dumb. :-) But trying to wrap my head around it.\n\n========================================\n\nTop Answer:\nLet's start from the basis. \n\n**RabbitMQ** *is a MOM* (Message Oriented Middleware), developed with Erlang (a TLC-oriented programming language) and **implementing the wire protocol AMQP** (Advance Message Queuing Protocol). \nCurrently, many Client APIs (e.g., Java, C++, RESTful, etc.) are available to enable the usage of RabbitMQ messaging services.\n\n**JMS** (Java Messaging Service) is a JCP standard defining a **set of structured APIs** to be implemented by a MOM. An example of MOM that implements (i.e. is compatible with) the JMS APIs is ActiveMQ; there's also HornetMQ, and others. Such middlewares get the JMS APIs and implement the exchange patterns accordingly.\n\nAccording to above, taken the skeleton of JMS APIs, an instance of RabbitMQ and its Java Client APIs, it is possible to develop a JMS implementation making use of RabbitMQ: the only thing that one has to do, at that point, is implementing the exchange pattern (over RabbitMQ) according to the JMS specification.\n\nThe key is: *a set of APIs, like JMS, can be implemented no matter of the technology* (in this case, RabbitMQ).\n\n========================================\n\nComments:\n- @KevinRave: The selected answer is wrong on some main points it makes. I have added a comment so that you can look at it.\n- @KevinRave I have edited the answer.Now The controversial portion has replaced.Now the whole answer is perfectly OK\n- I dont know who edited my answer and gave this improper point which was at num 3.. because I already have asked the thing which kevin is saying at point 2.Always read carefully before down voting or making suggestions\n- Have a look at the JMS section in this article. It has a very detailed explanation saipraveenblog.wordpress.com/2014/12/08/…\n- RabbitMQ Tutorial - jstobigdata.com/rabbitmq/complete-rabbitmq-tutorial-in-java\n- `I am not sure but I believe that AMQP also uses HTTP/S protocol but AMQP is enhacement is messaging protocol over HTTP` : **No. That is not correct.** `JMS uses simple HTTP but for RabbitMQ/ActiveMq, they uses enhanced protocol.` : **No. That is not correct.** JMS is only a API spec. It doesnt use any protocol. A JMS provider (like ActiveMQ) could be using any underlying protocol to realize the JMS API. For ex: Apache ActiveMQ can use any of the following protocols: AMQP, MQTT, OpenWire, REST(HTTP), RSS and Atom, Stomp, WSIF, WS Notification, XMPP.\n- I have edited the answer.Now The controversial portion has replaced.\n- @brainOverflow I dont know who edited my answer and gave this improper point which was at num 3.. because I have asked the thing which you are saying at point 2.Always read carefully before down voting or making suggestions\n- i already added stuff from that PDF so you can go to some other links too\n- AMQP is not a wire-level protocol. Wikipedia is wrong , omg, who would have thunk it\n- Nope. Its not the one I was looking at. But similar.\n- What does TLC stand for?\n- @mvmm TLC stands for Telecommunication. Please, have a look to [1]. [1] allacronyms.com/TLC/Telecommunication","metadata":{"transformedAt":"2026-08-18T18:33:20.113Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":50,"estimatedTokens":967}}29{"id":"stack-28687295","source":"stackoverflow","questionId":28687295,"title":"SQS vs RabbitMQ","tags":["amazon-web-services","rabbitmq","amazon-sqs"],"text":"Title: SQS vs RabbitMQ\nTags: amazon-web-services, rabbitmq, amazon-sqs\nSource: Stack Overflow\n\nQuestion:\nI need to create a queue for processing. The queue itself is relatively low-volume. There might be about 1,000 writes to it per hour. The execution of each task might take about a minute each, and are processed almost as soon as the item is added to the queue.\n\nIs there any reason that I might want to implement RabbitMQ instead of something off-the-shelf like Amazon SQS? What are some reasons why an application would need its own queueing system instead of something like SQS?\n\n========================================\n\nTop Answer:\nSQS would be my preference over RabbitMQ, here is why.\n\n- SQS is a managed service. So you don't have to worry about operational aspects of running a messaging system including administration, security, monitoring etc. Amazon will do this for you and will provide support if something were to go wrong.\n\n- SQS is Elastic and can scale to very large rate/volumes (unlimited according to AWS ;))\n\n- Availability of SQS has a lot of 9's in it and is backed by Amazon, which is one less thing to worry about in your application.\n\nHowever RabbitMQ might provide faster response times for puts and gets, typically in 10s of thousands of TPS from my testing. For SQS to provide that kind of throughput, you will have to scale up horizontally with multiple instances. So if you are looking for under 5ms puts , RabbitMQ might be an option to consider because i have seen close to 20ms-30ms put time from my SQS testing at 1000s of TPS, which is slightly higher than RabbitMQ.\n\nWe just moved our messaging infrastructure from ActiveMQ to SQS and can't be any more happier. We have found it to be cheaper than maintaining our own ActiveMQ cluster in the cloud.\n\n========================================\n\nCode:\n```text\n- Very large legacy code base that uses RabbitMQ with extensive tooling and knowledgeable support staff\n- Messages that needs to be in the same work stream for > 14 days\n- Very large messages that has very low latency requirements with it\n- Cloud agnostic code base requirements. If you must run your code on other platforms (e.g. Azure/Google/bare metal), then SQS is not an option\n- Large volume of data for a single pipeline that can't be broke up and other solutions (e.g. Kafka) are not viable. But at a super large volume, Kafka is a lot faster. While SQS will push large payloads to S3, you are now incurring additional cost.\n```\n\n========================================\n\nComments:\n- 1000 writes per hour is fine. If you have time and enough knowledge, then run RabbitMq instance by yourself, it saves money as well if compare with Amazon SQS service. For SQS, it was just there. It was convenient, simple, and reasonably quick to code at.\n- With SQS, you get the extensibility and scalability of Lambda triggers.\n- What do you mean by \"Amazon SQS has a wide portability with almost all the major platforms, not sure that is the case with RabbitMQ\". RabbitMQ runs on all major platforms (Windows, Linux and Mac), plus in all major languages (Java, .Net, PHP, Python, Ruby, etc)\n- @old_sound Thank you for pointing that out. I have updated my answer to omit that part.\n- cool. You also mention costs of operating RabbitMQ, AFAIK SQS has a cost too, per operation, or something like that, right?\n- @old_sound I am not sure I understood that. Can you rephrase your question ?\n- You wrote \"Your own RabbitMQ server means maintenance cost down the line which is not the case with Amazon SQS\". For that to be a fair statement in your comparison, I think it has to mention that SQS is not a free service, therefore you will also incur costs when running SQS\n- @old_sound The difference is that running SQS you only pay for usage (sending and receiving messages) while running RabbitMQ has the hidden costs (above the EC2 usage) of making sure the service is running, monitored, and patched including both the app and underlying operating system. With SQS AWS will take care of all of that \"undifferentiated heavy lifting\" so you can just focus on your app.\n- Amazon SQS now supports FIFO\n- Please update the top of the post to show that it now supports FIFO queues, I almost stopped reading when I read that\n- -1 This answer really needs some attention to be useful. Suggestions: Remove FIFO constraint entirely, focus on IaaS -- scaling, configuration, etc -- and differences in message delivery (e.g., polling).\n- I second @andymccullough. It's not good to state an untruth only to correct it in a footnote.\n- In my opinion, the trade-off to choice between RabbitMQ and SQS is the LOCK-IN. Nowadays cloud services is each time more popular and for some companies marrie with a platform solution can be a risk for the business. Using docker and scaling your rabbitMQ service you can change of cloud platforms avoiding this Lock-in problem. As people said this brings more problems like manage all your solution when AWS give you that.\n- Voted down due to the now false claims about FIFO.\n- AWS now also has a managed service for RabbitMQ. Another argument for this post needs rewrite.\n- Also there are open source implementations of SQS so you can indeed run it by yourself now, for example: github.com/softwaremill/elasticmq\n- @ssekhar We are also planning to migrate activemq to SES.. How big are the changes on client end ? We are on java and latest version of activemq.\n- I’ve been running SQS-based apps for years with median put latency around 7ms per put - if you’re getting 20-30ms then something is horribly wrong, either in your measurement or your test. Are you running from within same AWS region/AZ? How are you measuring?\n- @DeepakSinghal - I am sure you probably already found the answer to your question. Sorry for being a few years late to catch the question here :). Going from ActiveMQ to SQS - Here are some challenges we had to deal with. 1) SQS provides an at-least once delivery guarantee vs. once and only once like JMS, so we had to solve for duplicate delivery (our approach shown here -> angularthinking.blogspot.com) 2) SQS uses a pull pattern vs. push into the clients as in JMS, which makes consumption easier. We implemented our own listener and async delivery processor on our to simplify dev.\n- 1. If you want to push > 1000 requests/sec then check Kinesis. 2. Very large messages if you don't need microseconds - put the message body in s3 and just the key (file) name in the message body\n- if you send infrequent messages (like dev environment), you pay almost nothing. Idle SQS=$0","metadata":{"transformedAt":"2026-08-18T18:33:20.113Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":59,"estimatedTokens":1642}}30{"id":"stack-9077687","source":"stackoverflow","questionId":9077687,"title":"Why use Celery instead of RabbitMQ?","tags":["python","message-queue","rabbitmq","celery"],"text":"Title: Why use Celery instead of RabbitMQ?\nTags: python, message-queue, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nFrom my understanding, Celery is a distributed task queue, which means the only thing that it should do is dispatching tasks/jobs to others servers and get the result back. RabbitMQ is a message queue, and nothing more. However, a worker could just listen to the MQ and execute the task when a message is received. This achieves exactly what Celery offers, so why need Celery at all?\n\n========================================\n\nTop Answer:\nCelery basically provides a nice interface to doing just what you said, and deals with all the configuration for you. Yes you could do it by hand, but you'd just be rewriting celery.\n\n========================================\n\nComments:\n- There's also the operations element. Huge parts of Celery is there for reliability (e.g. not crashing when a particular exception is serialized, etc), and managing workers, and clusters of workers.\n- \"Rabbit has a rich set of options that Celery basically ignores\". That's true but a little misleading. You can for example set up routing rules in the Rabbit layer that are not controlled by Celery, but do affect the routing and consumption of Celery tasks. It's a design issue whether you want routing to be handled by the caller, a Celery custom router, or the exchange mechanism. It's true those Rabbit configs can be \"invisible\" to Celery but that doesn't mean they don't have a useful effect.","metadata":{"transformedAt":"2026-08-18T18:33:20.113Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":17,"estimatedTokens":375}}31{"id":"stack-5313027","source":"stackoverflow","questionId":5313027,"title":"How do I delete all messages from a single queue using the CLI?","tags":["rabbitmq"],"text":"Title: How do I delete all messages from a single queue using the CLI?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nHow do I delete all messages from a single queue using the cli?\nI have the queue name and I want to clean it.\n\n========================================\n\nTop Answer:\nyou can directly run this command\n\n```\nsudo rabbitmqctl purge_queue queue_name\n```\n\n========================================\n\nCode:\n```text\nrabbitmqadmin purge queue name=name_of_the_queue_to_be_purged\n```\n\n```text\nrabbitmqctl stop_app\nrabbitmqctl reset\nrabbitmqctl start_app\n```\n\n```text\ncurl -i -u guest:guest -XDELETE http://localhost:15672/api/queues/vhost_name/queue_name/contents\n```\n\n```text\ngit clone https://github.com/dougbarth/amqp-utils.git\ncd amqp-utils\n# extracted from Rakefile\necho \"source 'https://rubygems.org'\ngem 'amqp', '~> 0.7.1'\ngem 'trollop', '~> 1.16.2'\ngem 'facets', '~> 2.9'\ngem 'clio', '~> 0.3.0'\ngem 'json', '~> 1.5'\ngem 'heredoc_unindent', '~> 1.1.2'\ngem 'msgpack', '~> 0.4.5'\" > Gemfile\nbundle install --path=$PWD/gems\nexport RUBYLIB=.\nexport GEM_HOME=$PWD/gems/ruby/1.9.1\n\nruby bin/amqp-purge -v -V /vhost -u user -p queue\n# paste password at prompt\n```\n\n```text\nampq-purge\n```\n\n```text\nimport pika\nhost_ip = #host ip\nchannel = pika.BlockingConnection(pika.ConnectionParameters(host_ip,\n 5672,\n \"/\",\ncredentials=pika.PlainCredentials(\"username\",\"pwd\"))).channel()\nprint \"deleting queue..\", channel.queue_delete(queue=queue_name)\n```\n\n```text\nsudo apt-get install amqp-tools\namqp-delete-queue -q celery # where celery is the name of the queue to delete\namqp-declare-queue -d -q celery # where celery is the name of the queue to delete and the \"-d\" creates a durable/persistent queue\n```\n\n```text\nsudo rabbitmqctl purge_queue queue_name\n```\n\n```text\nsudo rabbitmqctl --node <nodename> purge_queue <queue_name>\n```\n\n```text\nsudo rabbitmqctl --node <nodename> delete_queue <queue_name> --if-empty\n```\n\n```text\nsudo rabbitmqctl --node <nodename> delete_queue <queue_name> --if-unused\n```\n\n```text\ncelery -A <app_name> -Q <queue_name> purge\n```\n\n```text\nrabbitmqclt\n```\n\n```text\nrabbitmqadmin\n```\n\n========================================\n\nComments:\n- I had a hard time finding the tool in my rabbitmq installation. I finally downloaded it from here: hg.rabbitmq.com/rabbitmq-management/raw-file/rabbitmq_v3_3_5‌​/…\n- If you have the management plugin already installed, you can downloaded it from `http://rabbitserver:15672/cli/`\n- Also to list available queues try rabbitmqctl list_queues\n- That also resets your users and other configs!\n- I used this as part of unit tests. e.g. I clear everything, then set it all up programmically via stackoverflow.com/questions/4545660/… then populate some messages and do black box testing to make sure messages went through. Works great for this purpose. :)\n- zeroing your storage and reinstalling the OS also gets rid of the data; this is not what OP is asking\n- Kind of scary how well this worked. Any way to protect against this happening unintentionally? Such as a config for production servers that disables this functionality to prevent accidental data loss?\n- Yeah, the protection would be to delete the user \"guest\" using the \"delete_user\" command\n- hi @prajnavantha is pika has any method clear message only? (not delete queue)\n- That's a good solution for some version do not have rabbitmqadmin.\n- This deletes the whole queue, doesn't just purge it. So the queue doesn't exist anymore and you have to re-initialize the empty queue afterwards.\n- That's true. Luckily, ampq-tools also has a command to create a queue. The intention of this Answer was to show how we can achieve what the question asks using generic tools or when getting rabbitmqadmin isn't feasible.\n- or, if you have a virtual host, do `rabbitmqctl purge_queue queue_name -p my_virt_host`\n- run sudo rabbitmqctl -h and check list of cammand listed by your current rabbitmq. if it is not there it means current version of rabbitmq does not support this feature.\n- This didn't work for me -- as soon as my consumer fired up, the queue was still full of tasks.\n- This could have been implemented in either 3.5.4 or 3.6.0, based on github.com/rabbitmq/rabbitmq-server/pull/215 and rabbitmq.com/changelog.html . If you have an older version, rabbitmqadmin as per stackoverflow.com/a/18267342/272387 might help.\n- ...and checking in github.com/rabbitmq/rabbitmq-server/releases/tag/… , this feature appeared in 3.5.4.\n- It might seem simple, but this was the answer I needed.\n- Why would it be different if one would purge the queue from outside the docker container? Isn't the queue completely oblivious to **whom** (or rather **what**) is using it? I am not suggesting anything, I am just asking.","metadata":{"transformedAt":"2026-08-18T18:33:20.113Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":14,"totalLines":124,"estimatedTokens":1221}}32{"id":"stack-7593269","source":"stackoverflow","questionId":7593269,"title":"RabbitMQ: Verify version of rabbitmq","tags":["rabbitmq"],"text":"Title: RabbitMQ: Verify version of rabbitmq\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nHow can I verify which version of rabbitmq is running on a server?\n\nIs there a command to verify that rabbitmq is running?\n\n========================================\n\nTop Answer:\nYou can simply execute from the command line:\n\n```\nsudo rabbitmqctl status | grep rabbit\n```\n\n========================================\n\nCode:\n```bash\nsudo rabbitmqctl status\n```\n\n```erlang\n{rabbit,\"RabbitMQ\",\"2.6.1\"},\n```\n\n```text\nfrom amqplib import client_0_8 as amqp\nimport sys\n\nconn = amqp.Connection(host=sys.argv[1], userid=\"guest\", password=\"guest\", virtual_host=\"/\", insist=False)\n\nfor k, v in conn.server_properties.items():\n print k, v\n```\n\n```text\n% python checkVersion.py dev.rabbitmq.com\ninformation Licensed under the MPL. See http://www.rabbitmq.com/\nproduct RabbitMQ\ncopyright Copyright (C) 2007-2011 VMware, Inc.\ncapabilities {}\nplatform Erlang/OTP\nversion 2.6.0\n```\n\n```text\ncheckVersion.py\n```\n\n```text\npython checkVersion.py dev.rabbitmq.com\n```\n\n```text\nsudo rabbitmqctl status | grep rabbit\n```\n\n```text\ndpkg -s rabbitmq-server | grep Version\n```\n\n```cs\npublic string GetRabbitMqVersion()\n{\n string prefix = \"rabbitmq_server-\";\n var dirs = System.IO.Directory.EnumerateDirectories(@\"C:\\Program Files (x86)\\RabbitMQ Server\", string.Format(\"{0}*\",prefix));\n\n foreach (var dir in dirs)\n {\n //Just grab the text after 'rabbitmq_server-' and return the first item found\n var i = dir.LastIndexOf(prefix);\n return dir.Substring(i+16);\n }\n return \"Unknown\";\n}\n```\n\n```cs\nusing (var connection = connectionFactory.CreateConnection())\n{\n if (connection.ServerProperties.ContainsKey(\"version\"))\n Console.WriteLine(\"Version={0}\",\n Encoding.UTF8.GetString((byte[])connection.ServerProperties[\"version\"]));\n}\n```\n\n```text\n# sudo bash\n```\n\n```text\n# rabbitmqctl status | grep rabbit\n```\n\n```text\ndpkg-query --showformat='${Version}' --show rabbitmq-server\n```\n\n```text\nrabbitmqctl status | grep \"{rabbit,\\\"RabbitMQ\\\"\"\n```\n\n```text\n{rabbit,\"RabbitMQ\",\"3.7.3\"},\n```\n\n```text\nls /usr/lib/rabbitmq/lib/\n```\n\n```text\nrabbitmq_server-3.5.6\n```\n\n```text\nyum list rabbitmq-server\n```\n\n========================================\n\nComments:\n- I got this instead on Archlinux - [{rabbit,34362},{rabbitmqctl23794,40359}] though I installed rabbitmq 3.1.3-1 :)\n- And if rabbitmq services are stopped? It doesn't works. How can I retrieve version of a \"shut down\" rabbitmq?\n- In Windows this is very similar. \"C:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.6.5\\sbin\\rabbitmqctl status\" Folder name may vary with your version of Rabbit.\n- This worked for me but wonly with Python3 and I had to create checkVersion.py under the folder client_0_8 (in windows)\n- Maybe the format has changed - as of version `3.8.4`, a better search string is `sudo rabbitmqctl status | grep -i \"version\"`.\n- or `yum list rabbitmq-server` for Rhel/Centos/Fedora\n- var mqtt = require('mqtt'); var mqttUrl = 'mqtt://localhost'; var device_id = \"5\"; var mqttOption = { clientId: \"52\", port: 1883, username: \"\", password: \"\", // port: 8883, // username: \"iothub.azure-devices.net/\"+device_id+\"/?api-version=2018-06‌​-30\", // password: \"sas token\", // rejectUnauthorized: false, // reconnecting: true, // reconnectPeriod: 25000, // connectTimeout: 50000 }; var mqttClient = \"\"; var pubTopic = \"devices/\" + device_id + \"/messages/events/\"; var subTopic = \"devices/\" + device_id + \"/messages/devicebound/#\";\n- try { mqttClient = mqtt.connect(mqttUrl, mqttOption); mqttClient.on('connect', function () { console.log(\"Device connected 12\"); setInterval(() => { var data = { id: device_id, temp: RandFunc(15, 20), humid: RandFunc(30, 50), mot: RandFuncFromArray([\"ON\", \"OFF\"]), }; console.log(data); mqttClient.publish(pubTopic, JSON.stringify(data)); }, 5000);\n- mqttClient.publish(\"devices/\" + device_id + \"/messages/events/\", '{\"id\":123}', qos=1) mqttClient.subscribe(subTopic); }) mqttClient.on(\"message\", function (topic, payload) { console.log(\"new command :::::::::::::::::::: \", topic, JSON.stringify(JSON.parse(payload)) ); }) mqttClient.on('error', function (err) { console.log(\"Error => \", err.message); }); mqttClient.on('close', function () { console.log(\"Connection closed => \"); })\n- } catch (error) { console.log(\"close => \", error.message); } function RandFunc(min, max) { return (Math.random() * (max - min) + min).toFixed(0); } function RandFuncFromArray(array) { return array[Math.floor(Math.random() * array.length)]; }","metadata":{"transformedAt":"2026-08-18T18:33:20.113Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":18,"totalLines":135,"estimatedTokens":1138}}33{"id":"stack-11459676","source":"stackoverflow","questionId":11459676,"title":"Delete all the queues from RabbitMQ?","tags":["rabbitmq","rabbitmqctl"],"text":"Title: Delete all the queues from RabbitMQ?\nTags: rabbitmq, rabbitmqctl\nSource: Stack Overflow\n\nQuestion:\nI installed `rabbitmqadmin` and was able to list all the exchanges and queues. How can I use `rabbitmqadmin` or `rabbitmqctl` to delete all the queues.\n\n========================================\n\nTop Answer:\n**Actually super easy with management plugin and policies:**\n\nGoto **Management Console** (localhost:15672)\n\nGoto **Admin** tab\n\nGoto **Policies** tab(on the right side)\n\nAdd **Policy**\n\nFill Fields\n\n- **Virtual Host:** Select\n\n- **Name:** Expire All Policies(Delete Later)\n\n- **Pattern:** .*\n\n- **Apply to:** Queues\n\n- **Definition:** **expires** with value **1** (change type from String to Number)\n\nSave\n\nCheckout **Queues** tab again\n\nAll Queues must be deleted\n\n**And don't forget to remove policy!!!!!!**.\n\n========================================\n\nCode:\n```text\nrabbitmqadmin\n```\n\n```text\nrabbitmqadmin\n```\n\n```text\nrabbitmqctl\n```\n\n```text\nrabbitmqctl stop_app\nrabbitmqctl reset # Be sure you really want to do this!\nrabbitmqctl start_app\n```\n\n```text\nrabbitmqadmin list queues name\n```\n\n```text\nrabbitmqadmin delete queue name='queuename'\n```\n\n```text\nlist queues\n```\n\n```text\nfor word in \"$@\"\ndo\n args=true\n newQueues=$(rabbitmqctl list_queues name | grep \"$word\")\n queues=\"$queues\n$newQueues\"\ndone\nif [ $# -eq 0 ]; then\n queues=$(rabbitmqctl list_queues name | grep -v \"\\.\\.\\.\")\nfi\n\nqueues=$(echo \"$queues\" | sed '/^[[:space:]]*$/d')\n\nif [ \"x$queues\" == \"x\" ]; then\n echo \"No queues to delete, giving up.\"\n exit 0\nfi\n\nread -p \"Deleting the following queues:\n${queues}\n[CTRL+C quit | ENTER proceed]\n\"\n\nwhile read -r line; do\n rabbitmqadmin delete queue name=\"$line\"\ndone <<< \"$queues\"\n```\n\n```text\nrabbitmqadmin list queues|awk 'NR>3{print $4}'|head -n-1|xargs -I qname rabbitmqadmin delete queue name=qname\n```\n\n```text\nrabbitmqadmin -f tsv -q list queues name | while read queue; do rabbitmqadmin -q delete queue name=${queue}; done\n```\n\n```text\nrabbitmqadmin\n```\n\n```text\n$cred = Get-Credential\n iwr -ContentType 'application/json' -Method Get -Credential $cred 'http://localhost:15672/api/queues' | % { \n ConvertFrom-Json $_.Content } | % { $_ } | ? { $_.messages -gt 0} | % {\n iwr -method DELETE -Credential $cred -uri $(\"http://localhost:15672/api/queues/{0}/{1}\" -f [System.Web.HttpUtility]::UrlEncode($_.vhost), $_.name)\n }\n```\n\n```text\nrabbitmqadmin list queues name | awk '{print $2}' | xargs -I qn rabbitmqadmin delete queue name=qn\n```\n\n```text\nparallel\n```\n\n```text\nparallel -j 50 rabbitmqadmin -H YOUR_HOST_OR_LOCALHOST -q delete queue name={} ::: $(rabbitmqadmin -H YOUR_HOST_OR_LOCALHOST -f tsv -q list queues name)\n```\n\n```text\npython rabbitmqadmin.py \\\n -H YOURHOST -u guest -p guest -f bash list queues | \\\nxargs -n1 | \\\nxargs -I{} \\\n python rabbitmqadmin.py -H YOURHOST -u guest -p guest delete queue name={}\n```\n\n```text\n-f bash\n```\n\n```text\nxargs -n1\n```\n\n```text\nxargs -I{}\n```\n\n```text\n{}\n```\n\n```text\n/\n```\n\n```text\nrabbitmqctl.bat set_policy delq \".*\" '{\"expires\": 1}' --apply-to queues\n```\n\n```text\nrabbitmqctl clear_policy delq\n```\n\n```text\nrabbitmqctl eval 'IfUnused = false, IfEmpty = true, MatchRegex = \n<<\"^prefix-\">>, [rabbit_amqqueue:delete(Q, IfUnused, IfEmpty) || Q <- \nrabbit_amqqueue:list(), re:run(element(4, element(2, Q)), MatchRegex) \n=/= nomatch ].'\n```\n\n```text\nrabbitmqctl list_queues | awk '{ print $1 }' | xargs -L1 rabbitmqctl purge_queue\n```\n\n```text\nbrew list --versions\n```\n\n```text\nrabbitmqctl list_queues -p <VIRTUAL_HOSTNAME> name | sed 1,2d | xargs -I qname rabbitmqadmin --vhost <VIRTUAL_HOSTNAME> delete queue name=qname\n```\n\n```text\nrabbitmqctl list_queues | awk '{ print $1 }' | sed 's/Listing//' | xargs -L1 rabbitmqctl purge_queue\n```\n\n```text\nrabbitmqctl list_queues | awk '$2!=0 { print $1 }' | sed 's/Listing//' | xargs -L1 rabbitmqctl purge_queue\n```\n\n```text\n#!/bin/bash\n\n# Stop on error\nset -eo pipefail\n\nUSER='guest'\nPASSWORD='guest'\n\ncurl -sSL -u $USER:$PASSWORD http://localhost:15672/api/queues/%2f/ | jq '.[].name' | sed 's/\"//g' | xargs -L 1 -I@ curl -XDELETE -sSL -u $USER:$PASSWORD http://localhost:15672/api/queues/%2f/@\n# To also delete exchanges uncomment next line\n# curl -sSL -u $USER:$PASSWORD http://localhost:15672/api/exchanges/%2f/ | jq '.[].name' | sed 's/\"//g' | xargs -L 1 -I@ curl -XDELETE -sSL -u $USER:$PASSWORD http://localhost:15672/api/exchanges/%2f/@\n```\n\n```text\n./rabbitmqadmin -f tsv -q list queues\n```\n\n```text\n./rabbitmqadmin delete queue name=name_of_queue\n```\n\n```text\nrabbitmqctl list_queues | awk '{ print $1 }' | xargs -L1 rabbitmqctl delete_queue\n```\n\n```text\nsudo rabbitmqctl list_queues | awk '{print $1}' > queues.txt; for line in $(cat queues.txt); do sudo rabbitmqctl delete_queue \"$line\"; done\n```\n\n```text\nwhile read ...\n```\n\n```text\npython rabbitmqadmin declare policy name='expire_all_policies' pattern=.* definition={\\\"expires\\\":1} apply-to=queues\n```\n\n```text\npython rabbitmqadmin delete policy name='expire_all_policies'\n```\n\n```text\nhttp://{hostname}:15672/cli/rabbitmqadmin\n```\n\n```text\npython rabbitmqadmin list queues\n```\n\n```text\npython rabbitmqadmin delete queue name=Name_of_queue\n```\n\n```sh\nVhost=the_vhost_name\nUser=user_name\nPassword=the_passworld\n\nfor i in `rabbitmqctl list_queues -p $Vhost | awk '{ print $1 }'`\ndo\n echo \"queu_name: $i\"\n curl -u $User:$Passworld -H \"content-type:application/json\" -XDELETE http://localhost:15672/api/queues/$Vhost/$i\ndone\n```\n\n```text\nsudo rabbitmqctl list_queues | awk '{print $1}' | xargs -I qn sudo rabbitmqctl delete_queue qn\n```\n\n```text\nrabbitmqctl list_queues -q name > q.txt\nIFS=$'\\n' read -d '' -r -a queues < q.txt\ncount=${#queues[@]}\ni=1; while (($i < $count)); do echo ${queues[$i]};rabbitmqctl delete_queue ${queues[$i]};i=$((i+1)); done\n```\n\n```bash\ncurl -X PUT --data '{\"pattern\":\".*\",\"apply-to\":\"all\",\"definition\":{\"expires\":1},\"priority\":0}' -u guest:guest 'http://localhost:15672/api/policies/%2f/clear' && \\\ncurl -X DELETE -u guest:guest 'http://localhost:15672/api/policies/%2f/clear'\n```\n\n```text\n%2f\n```\n\n```text\n/\n```\n\n```text\nguest:guest\n```\n\n========================================\n\nComments:\n- to see all pending tasks in rabbitmq: `rabbitmqctl list_queues name messages messages_ready \\ messages_unacknowledged`\n- just grabbing the empty queues. `rabbitmqctl list_queues | grep 0 | awk '{print $1}' | xargs -I qn rabbitmqadmin delete queue name=qn`\n- @austin 's receipt works perfectly. Just make sure you have root privilege before you run that.\n- @au_stan That will delete all queues with a 0 in the name or the count. Might want to do `grep $'\\t0'` or something.\n- Is the rabbitmqctl \"reset\" flavor supposed to be compatible with rabbitmq installed via Homebrew? Didn't seem to work work for me. I ended up using one of the one liner answers.\n- @lukiffer i know it's a bit dumb question, but where one should run these commands ??\n- @ZeeshanAjmal you can run them from whatever shell you want, so long as they're in your `PATH`.\n- seeing answers below this answer seems like a horrible idea. Why would I want to return my all settings to default just because I want to remove some queues.\n- Thanks! Only rabbitmqctl reset helped me with queues in a 'stopped' status. Before resetting, you can export the Definitions file, and after resetting, import the Definitions file, and all queues will be in a running status.\n- I receive this when running it: head: illegal line count -- -1\n- The \"head -n-1\" should be either \"head -1\" or \"head -n 1\"\n- In my case queues are prefixed with keyword by which I can simply use `egrep`, so my command will look like this: `rabbitmqadmin -f tsv -q list queues name | egrep \"%search word%\" | while read queue; do rabbitmqadmin -q delete queue name=${queue}; done`\n- You may have to use -H to specify host and -u and -p parameters to specify the credentials to connect to server\n- Note, this only deletes non-empty queues. Remove the -gt clause to delete all queues\n- This worked for me, but also showed `*** Not found: /api/queues/%2F/name` because the output is a ASCII table with a \"name\" column. I tweaked the command to be `rabbitmqadmin list queues name | awk '!/--|name/ {print $2}' | xargs -I qn rabbitmqadmin delete queue name=qn` to fix it.\n- `rabbitmqadmin list queues name | awk {'print$2'} | egrep [^name] | xargs -I qname rabbitmqadmin delete queue name=qname`\n- BTW, to get rabbitmqadmin, you need to go to `http://yourhost:15672/cli/` and download it.\n- including durable queues? I don't think so. I'll qualify your answer.\n- No, durable queues cannot be deleted by stopping the server. They can be deleted from RabbitMQ Management web interface under queues.\n- Actually yes, this helped me and all about 4500 automatically generated queues are gone. It seems that these were non-durable ones. Thanks!\n- Perfect for when `rabbitmqadmin` is not accessible.\n- I found this much faster than list_queues\n- Has anyone tried this solution with RabbitMQ v3.8.2 or higher? I seem to be running into some undefined Erlang error. Maybe the solution needs to be updated to reflect newer versions?\n- I tried similar command as above but get a syntax error before ^ Below is my command. kubectl exec -n kayaks svc/rabbitmq-ha -- rabbitmqctl --vhost=AM-Dev eval 'IfUnused = false, IfEmpty = true, MatchRegex = >, [rabbit_amqqueue:delete(Q, IfUnused, IfEmpty) || Q <- rabbit_amqqueue:list(), re:run(element(4, element(2, Q)), MatchRegex) =/= nomatch ].'\n- There is no `delete_queue` nor `purge_queue` commands in `rabbitmqctl`. I would like to purge a lot of queues that seem to be automatically generated and I would not like to install extra software like `rabbitmqadmin`...\n- `rabbitmqctl purge_queue` worked here manually. I only needed to add -p\n- Contrary to what @Rolice stated above, both `delete_queue` and `purge_queue` are available in `rabbitmqctl` and I've just run them successfully. Perhaps you're on an old version.\n- This is a great approach and can be improved only a bit. We can get a cleaner output from rabbitmqctl if we use -q --no-table-headers. We will get rid of the table header and the \"Timeout: 60 sec\" prelude. So, you could optimise your answer by changing it to `rabbitmqctl list_queues -q --no-table-headers | awk '$2!=0 { print $1 }' | sed 's/Listing//' | while read queue; do rabbitmqctl -q purge_queue ${queue}; done`\n- select \"Number\" at Definition. Does not work with default (\"String\")\n- Pity nobody explains how to install management plugin and policies\n- @Mesut A. @Mathias Is there any particular reason this does not work for me in 3.8.3? I'm using `.*guid.*` pattern to delete only exchanges/queues that have `guid` string in them, and the policy have no effect.\n- @Jaded Number vs String was for the definition field, not for pattern. An older version of this answer did not contain the information to change the type from string to number.\n- @Mathias Number vs String for definition is not the case for underlying RabbitMQ version because they've added validator to value field that does not give you ability to add expires = \"1\", only expires = 1 (Number). To expand on the problem, what I've noticed after adding this policy, it appeared in the \"features\" column for target exchange ( \"D\", \"ha-all\", \"NameOfMyPolicy\") once (?).\n- how can i delete all the exchanges at once ?\n- Hmm, I have ran it on Unix based OS and it works successfully, just make sure the result that passed to xargs command is ok.\n- for alpine, if you are experiencing `unrecognized option: L`, install `findutils` package - it will get you a GNU version of xargs\n- Your answer could be improved by adding more information on what the code does and how it helps the OP.","metadata":{"transformedAt":"2026-08-18T18:33:20.114Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":47,"totalLines":331,"estimatedTokens":2943}}34{"id":"stack-18353898","source":"stackoverflow","questionId":18353898,"title":"What are the limits of messages, queues and exchanges?","tags":["rabbitmq","message-queue","message","amqp","rabbitmq-exchange"],"text":"Title: What are the limits of messages, queues and exchanges?\nTags: rabbitmq, message-queue, message, amqp, rabbitmq-exchange\nSource: Stack Overflow\n\nQuestion:\n- What are the allowed types of messages (strings, bytes, integers, etc.)?\n\n- What is the maximum size of a message?\n\n- What is the maximum number of queues and exchanges?\n\n========================================\n\nTop Answer:\nWhat is the maximum size of a message?\n\nIt used to be **2 GiB** before version 3.8.0:\n\n```\n%% Trying to send a term across a cluster larger than 2^31 bytes will\n%% cause the VM to exit with \"Absurdly large distribution output data\n%% buffer\". So we limit the max message size to 2^31 - 10^6 bytes (1MB\n%% to allow plenty of leeway for the #basic_message{} and #content{}\n%% wrapping the message body).\n-define(MAX_MSG_SIZE, 2147383648).\n```\n\nReference: https://github.com/rabbitmq/rabbitmq-common/blob/v3.7.21/include/rabbit.hrl#L279\n\nIt has been **512 MiB** since version 3.8.0:\n\n```\n%% Max message size is hard limited to 512 MiB.\n%% If user configures a greater rabbit.max_message_size,\n%% this value is used instead.\n-define(MAX_MSG_SIZE, 536870912).\n```\n\nReference: https://github.com/rabbitmq/rabbitmq-common/blob/v3.8.0/include/rabbit.hrl#L238\n\n========================================\n\nCode:\n```text\ntoBytes\n```\n\n```text\nfromBytes\n```\n\n```text\n%% Trying to send a term across a cluster larger than 2^31 bytes will\n%% cause the VM to exit with \"Absurdly large distribution output data\n%% buffer\". So we limit the max message size to 2^31 - 10^6 bytes (1MB\n%% to allow plenty of leeway for the #basic_message{} and #content{}\n%% wrapping the message body).\n-define(MAX_MSG_SIZE, 2147383648).\n```\n\n```text\n%% Max message size is hard limited to 512 MiB.\n%% If user configures a greater rabbit.max_message_size,\n%% this value is used instead.\n-define(MAX_MSG_SIZE, 536870912).\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.114Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":66,"estimatedTokens":468}}35{"id":"stack-41744506","source":"stackoverflow","questionId":41744506,"title":"Difference between stream processing and message processing","tags":["stream","queue","rabbitmq","apache-kafka","messaging"],"text":"Title: Difference between stream processing and message processing\nTags: stream, queue, rabbitmq, apache-kafka, messaging\nSource: Stack Overflow\n\nQuestion:\nWhat is the basic difference between stream processing and traditional message processing? As people say that kafka is good choice for stream processing but essentially kafka is a messaging framework similar to ActiveMQ, RabbitMQ etc.\n\nWhy do we generally not say that ActiveMQ is good for stream processing as well.\n\nIs it the speed at which messages are consumed by the consumer determines if it is a stream?\n\n========================================\n\nTop Answer:\nIf you like splitting hairs:\nMessaging is communication between two or more processes or components whereas streaming is the passing of event log as they occur. Messages carry raw data whereas events contain information about the occurrence of and activity such as an order.\nSo Kafka does both, messaging and streaming. A topic in Kafka can be raw messages or and event log that is normally retained for hours or days. Events can further be aggregated to more complex events.\n\n========================================\n\nComments:\n- Kafka very much is NOT \"a messaging framework similar to ActivMQ, RabbitMQ etc\", as described in this post: azure.microsoft.com/en-us/blog/…","metadata":{"transformedAt":"2026-08-18T18:33:20.114Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":22,"estimatedTokens":325}}36{"id":"stack-29539443","source":"stackoverflow","questionId":29539443,"title":"Redis Vs RabbitMQ as a data broker/messaging system in between Logstash and elasticsearch","tags":["elasticsearch","redis","rabbitmq","logstash"],"text":"Title: Redis Vs RabbitMQ as a data broker/messaging system in between Logstash and elasticsearch\nTags: elasticsearch, redis, rabbitmq, logstash\nSource: Stack Overflow\n\nQuestion:\nWe are defining an architecture to collect log information by Logstash shippers which are installed in various machines and index the data in one elasticsearch server centrally and use Kibana as the graphical layer. We need a reliable messaging system in between Logstash shippers and elasticsearch to grantee the delivery. What factors should be considered when selecting Redis over RabbitMQ as a data broker/messaging system in between Logstash shippers and the elasticsearch or vice versa?\n\n========================================\n\nTop Answer:\nRedis is created as a key value data store despite having **some basic** message broker capabilities.\n\nRabbitMQ is created as a message broker. It has lots of message broker capabilities naturally.\n\n========================================\n\nComments:\n- Does Redis have any stronger points comparing to RabbitMQ? Redis seems easier to configure. And if you do not need huge throughput and security is being handled by other means, RabbitMQ might not be necessary. Please, correct me if I'm wrong.\n- You are correct but in order to be sure you'll need to compare the performance between the two products\n- \"RabbitMQ is a very stable product that can handle large amounts of events per seconds and many connections without being the bottle neck.\" - I'm pretty sure that is true is reddis as well. So this is NOT an advantage of rabbitmq over Reddit\n- \"RabbitMQ allows you to use a built in layer of security by using SSL\" - doesn't reddis allow transport layer encryption as well?\n- When I tested it in 2015 Redis did not support SSL\n- 2019 still redis does not have built in TLS\n- Redis has made a conscious choice not to include TLS etc in the name of minimalism, and because the simplicity of its protocol makes it trivial to pipe client connections through an encrypted channel (ssh etc) with very minimal overhead and configuration. See redis.io/topics/encryption\n- Your statement about Redis is no more accurate with the introduction of Stream in Redis 5. RabbitMQ is definitely a better choice for large scale scenarios. For a small to a medium scale scenario (which most projects in the world are), Redis is a reliable, fast, and easy to configure alternative.\n- Thanks for the commitment, it would be good if someone writes here his experience about new features of Redis.\n- Redis has `Sorted Sets` which allow priority queue-like interactions. Redis can also be clustered/sharded to send different messages to to different queues on different servers even. Not sure about SSL directly for Redis, but I'm looking at AWS Elasticache and their Redis 3.2.6 allows at-rest and in-transit encryption. Note: not at all saying Redis is better for this case; just pointing out those may not be reasons to choose RabbitMQ over Redis.\n- Also don't forget that Redis is single threaded so if you have a lot of publisher/consumers that can be an issue.","metadata":{"transformedAt":"2026-08-18T18:33:20.114Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":28,"estimatedTokens":768}}37{"id":"stack-40436425","source":"stackoverflow","questionId":40436425,"title":"How do I create or add a user to rabbitmq?","tags":["rabbitmq"],"text":"Title: How do I create or add a user to rabbitmq?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nThis seems like a question that should be easily be googleable. It is not though. Can anybody help?\n\nHow do I create a new user for rabbitmq?\n\n========================================\n\nTop Answer:\nI have found this very useful\n\n### This adds a new user and password\n\n```\nrabbitmqctl add_user username password\n```\n\n### This makes the user a administrator\n\n```\nrabbitmqctl set_user_tags username administrator\n```\n\n### This sets permissions for the user\n\n```\nrabbitmqctl set_permissions -p / username \".*\" \".*\" \".*\"\n```\n\nSee more here https://www.rabbitmq.com/rabbitmqctl.8.html#User_Management\n\n========================================\n\nCode:\n```text\n$ rabbitmqctl add_user myUser myPass\n```\n\n```text\n$ rabbitmqctl set_user_tags myUser administrator\n```\n\n```text\nrabbitmqctl add_user username password\n```\n\n```text\nrabbitmqctl set_user_tags username administrator\n```\n\n```text\nrabbitmqctl set_permissions -p / username \".*\" \".*\" \".*\"\n```\n\n```text\nrabbitmqctl add_user test test\n```\n\n```text\nrabbitmqctl set_user_tags test administrator\n```\n\n```text\nrabbitmqctl set_permissions -p / test \".*\" \".*\" \".*\"\n```\n\n```text\nrabbitmqctl add_user daniel daniel\n```\n\n```text\nrabbitmqctl set_user_tags daniel administrator\n```\n\n```text\nrabbitmqctl set_permissions -p / daniel \".*\" \".*\" \".*\"\n```\n\n```text\nPUT /api/users/name\n```\n\n========================================\n\nComments:\n- Can you please elaborate on this cantSleepNow? What boggles my mind is that the official docs rabbitmq.com/access-control.html say absolutely nothing about an administrator user. What I'm trying to figure out is why do I need to set a tag (administrator) if apparently I need to set permissions on vhost anyway? (at least that's what the other people suggest in this thread) so what is the purpose of the tag? The thing is I have a User on my RabbitMQ installation that has the tag administrator but he has no rights to maintain certain vHosts. That confuses the hell out of me.\n- seems based on stackoverflow.com/a/52295727/11971304 the tag is just for viewing purpose and doesn't actually do anything on its own. so when the tagged user is provided with admin rights by setting permissions, then it gives a pseudo feeling of a admin user (visibly)\n- @mahee96 So something that happened before another thing is based on it? Look at the timestamps of the both answers. I did edit it later for formatting purpose I think, but still...","metadata":{"transformedAt":"2026-08-18T18:33:20.114Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":91,"estimatedTokens":626}}38{"id":"stack-4545660","source":"stackoverflow","questionId":4545660,"title":"RabbitMQ creating queues and bindings from command line","tags":["rabbitmq"],"text":"Title: RabbitMQ creating queues and bindings from command line\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nIf I have RabbitMQ installed on my machine, is there a way to create a message queue from the command line and bind it to a certain exchange without using a client?\n\nI think it is not possible, but I want to be sure.\n\n========================================\n\nTop Answer:\n**Summary:**\n\nOther answers are good alternatives to what was asked for. Below are commands you can use from the command line.\n\nFirst, do all the necessary prep work, e.g. install rabbit, `rabbitmqadmin`, and `rabbitctl`. The idea is to use commands from `rabbitmqctl` and `rabbitmqadmin`. You can see some command examples: https://www.rabbitmq.com/management-cli.html\n\n**Example Commands/Setup:**\n\nThe following commands should give you the majority if not all of what you need:\n\n```\n# Get the cli and make it available to use.\nwget http://127.0.0.1:15672/cli/rabbitmqadmin\nchmod +x rabbitmqadmin\nmv rabbitmqadmin /etc/rabbitmq\n```\n\n**Add a user and permissions**\n\n```\nrabbitmqctl add_user testuser testpassword\nrabbitmqctl set_user_tags testuser administrator\nrabbitmqctl set_permissions -p / testuser \".*\" \".*\" \".*\"\n```\n\n**Make a virtual host and Set Permissions**\n\n```\nrabbitmqctl add_vhost Some_Virtual_Host\nrabbitmqctl set_permissions -p Some_Virtual_Host guest \".*\" \".*\" \".*\"\n```\n\n**Make an Exchange**\n\n```\n./rabbitmqadmin declare exchange --vhost=Some_Virtual_Host name=some_exchange type=direct\n```\n\n**Make a Queue**\n\n```\n./rabbitmqadmin declare queue --vhost=Some_Virtual_Host name=some_outgoing_queue durable=true\n```\n\n**Make a Binding**\n\n```\n./rabbitmqadmin --vhost=\"Some_Virtual_Host\" declare binding source=\"some_exchange\" destination_type=\"queue\" destination=\"some_incoming_queue\" routing_key=\"some_routing_key\"\n```\n\n**Alternative Way to Bind with Python**\n\nThe following is an alternative to command line binding, as I've had issues with it sometimes and found the following python code to be more reliable.\n\n```\n#!/usr/bin/env python\nimport pika\n\nrabbitmq_host = \"127.0.0.1\"\nrabbitmq_port = 5672\nrabbitmq_virtual_host = \"Some_Virtual_Host\"\nrabbitmq_send_exchange = \"some_exchange\" \nrabbitmq_rcv_exchange = \"some_exchange\"\nrabbitmq_rcv_queue = \"some_incoming_queue\"\nrabbitmq_rcv_key = \"some_routing_key\"\n\noutgoingRoutingKeys = [\"outgoing_routing_key\"]\noutgoingQueues = [\"some_outgoing_queue \"]\n\n# The binding area\ncredentials = pika.PlainCredentials(rabbitmq_user, rabbitmq_password)\nconnection = pika.BlockingConnection(pika.ConnectionParameters(rabbitmq_host, rabbitmq_port, rabbitmq_virtual_host, credentials))\nchannel = connection.channel()\nchannel.queue_bind(exchange=rabbitmq_rcv_exchange, queue=rabbitmq_rcv_queue, routing_key=rabbitmq_rcv_key)\n\nfor index in range(len(outgoingRoutingKeys)):\n channel.queue_bind(exchange=rabbitmq_send_exchange, queue=outgoingQueues[index], routing_key=outgoingRoutingKeys[index])\n```\n\nThe above can be run as part of a script using python. Notice I put the outgoing stuff into arrays, which will allow you to iterate through them. This should make things easy for deploys.\n\n**Last Thoughts**\n\nI think the above should get you moving in the right direction, use google if any specific commands don't make sense or read more with `rabbitmqadmin help subcommands`. I tried to use variables that explain themselves.\n\n========================================\n\nCode:\n```text\n#do some work to connect\n#do some work to open a channel\nchannel.queue_declare(queue='helloworld')\n```\n\n```text\nrabbitmqctl\n```\n\n```text\nchannel.queue_bind(queueName, exchange)\n```\n\n```text\nsudo rabbitmqctl list_queues\n[sudo] password for eric:\nListing queues ...\n...done.\n```\n\n```text\nimport com.rabbitmq.client.ConnectionFactory;\nimport com.rabbitmq.client.Connection;\nimport com.rabbitmq.client.Channel;\nimport java.util.*;\npublic class CreateQueue {\n public static void main(String[] argv) throws Exception {\n ConnectionFactory factory = new ConnectionFactory();\n factory.setHost(\"localhost\");\n Connection connection = factory.newConnection();\n Channel channel = connection.createChannel();\n Map<String, Object> args = new HashMap<String, Object>();\n args.put(\"x-message-ttl\", 60000);\n channel.queueDeclare(\"kowalski\", false, false, false, args);\n channel.close();\n connection.close();\n }\n}\n```\n\n```text\njavac -cp .:rabbitmq-client.jar CreateQueue.java\njava -cp .:rabbitmq-client.jar CreateQueue\n```\n\n```text\nsudo rabbitmqctl list_queues\nListing queues ...\nkowalski 0\n...done.\n```\n\n```text\n3.3.5\n```\n\n```text\n# Get the cli and make it available to use.\nwget http://127.0.0.1:15672/cli/rabbitmqadmin\nchmod +x rabbitmqadmin\nmv rabbitmqadmin /etc/rabbitmq\n```\n\n```text\nrabbitmqctl add_user testuser testpassword\nrabbitmqctl set_user_tags testuser administrator\nrabbitmqctl set_permissions -p / testuser \".*\" \".*\" \".*\"\n```\n\n```text\nrabbitmqctl add_vhost Some_Virtual_Host\nrabbitmqctl set_permissions -p Some_Virtual_Host guest \".*\" \".*\" \".*\"\n```\n\n```text\n./rabbitmqadmin declare exchange --vhost=Some_Virtual_Host name=some_exchange type=direct\n```\n\n```text\n./rabbitmqadmin declare queue --vhost=Some_Virtual_Host name=some_outgoing_queue durable=true\n```\n\n```text\n./rabbitmqadmin --vhost=\"Some_Virtual_Host\" declare binding source=\"some_exchange\" destination_type=\"queue\" destination=\"some_incoming_queue\" routing_key=\"some_routing_key\"\n```\n\n```text\n#!/usr/bin/env python\nimport pika\n\nrabbitmq_host = \"127.0.0.1\"\nrabbitmq_port = 5672\nrabbitmq_virtual_host = \"Some_Virtual_Host\"\nrabbitmq_send_exchange = \"some_exchange\" \nrabbitmq_rcv_exchange = \"some_exchange\"\nrabbitmq_rcv_queue = \"some_incoming_queue\"\nrabbitmq_rcv_key = \"some_routing_key\"\n\noutgoingRoutingKeys = [\"outgoing_routing_key\"]\noutgoingQueues = [\"some_outgoing_queue \"]\n\n# The binding area\ncredentials = pika.PlainCredentials(rabbitmq_user, rabbitmq_password)\nconnection = pika.BlockingConnection(pika.ConnectionParameters(rabbitmq_host, rabbitmq_port, rabbitmq_virtual_host, credentials))\nchannel = connection.channel()\nchannel.queue_bind(exchange=rabbitmq_rcv_exchange, queue=rabbitmq_rcv_queue, routing_key=rabbitmq_rcv_key)\n\nfor index in range(len(outgoingRoutingKeys)):\n channel.queue_bind(exchange=rabbitmq_send_exchange, queue=outgoingQueues[index], routing_key=outgoingRoutingKeys[index])\n```\n\n```text\nrabbitmqadmin\n```\n\n```text\nrabbitctl\n```\n\n```text\nrabbitmqctl\n```\n\n```text\nrabbitmqadmin\n```\n\n```text\nrabbitmqadmin help subcommands\n```\n\n```text\napt-get install amqp-tools\n```\n\n```text\namqp-publish -e exchange_name -b \"your message\"\n```\n\n```text\namqp-get -q queue_name\n```\n\n```text\namqp-consume -q queue_name\n```\n\n```text\namqp_sendstring localhost 5672 amq.direct test \"hello world\"\n```\n\n```text\nc:\\python26\\python.exe rabbitmqadmin.exe declare exchange name=*ExchangeName1* type=topic durable=true\n```\n\n```text\nc:\\python26\\python.exe rabbitmqadmin.exe declare queue name=*NameofQueue1* durable=true\n```\n\n```text\nc:\\python26\\python.exe rabbitmqadmin.exe declare binding source=ExchangeName1 destination_type=queue destination=*NameofQueue1* routing_key=*RoutingKey1*\n```\n\n```text\nrabbitmqadmin -u {user} -p {password} -V {vhost} declare exchange name={name} type={type}\n```\n\n```text\nrabbitmqadmin -u {user} -p {password} -V {vhost} declare queue name={name}\n```\n\n```text\nrabbitmqadmin -u {user} -p {password} -V {vhost} declare binding source={Exchange} destination={queue}\n```\n\n```text\ncurl -i -u RABBITUSER:RABBITPASSWORD -H \"content-type:application/json\" \\\n-XPUT -d'{\"durable\":true}' \\\nhttp://192.168.99.100:15672/api/queues/%2f/QUEUENAME\n```\n\n```text\ncurl -i -u RABBITUSER:RABBITPASSWORD -H \"content-type:application/json\" \\\n-XPOST -d\"{\\\"routing_key\\\":\\\"QUEUENAME\\\"}\" \\\nhttp://192.168.99.100:15672/api/bindings/%2f/e/EXCHANGENAME/q/QUEUENAME\n```\n\n```sh\nsudo easy_install pika\n# (or use pip)\n```\n\n```py\nimport pika\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))\nchannel = connection.channel()\n\nchannel.queue_declare(queue='test-queue')\nchannel.basic_publish(exchange='', routing_key='test-queue', body='Hello World!')\n```\n\n```text\npython rabbitmqadmin.py declare exchange --vhost=/ name=CompletedMessageExchange type=direct\n```\n\n```text\nrabbitmqadmin.py\n```\n\n```text\nsbin\n```\n\n```text\npython\n```\n\n```text\nPATH\n```\n\n```text\nFunction createQueue([string]$QueueName){\n$headers = New-Object \"System.Collections.Generic.Dictionary[[String],[String]]\"\n$headers.Add(\"content-type\", \"application/json\")\n$headers.Add(\"Authorization\", \"Basic Z3Vlc3Q6Z3Vlc3Q=\")\n\n$body = \"{\n`n `\"vhost`\": `\"/`\",\n`n `\"name`\": `\"$QueueName`\",\n`n `\"durable`\": `\"true`\",\n`n `\"arguments`\": {}\n`n}\"\n\n# Write-Host $body\n\n$url='http://localhost:15672/api/queues/%2f/'+$QueueName\n\n# Write-Host $url\n\n$response = Invoke-RestMethod $url -Method 'PUT' -Headers $headers -Body $body\n$response | ConvertTo-Json\n}\n```\n\n```text\n$queueNames = 'my-queue-name'\n\n. .\\helper.ps1\n\ncreateQueue($queueName)\n```\n\n========================================\n\nComments:\n- Can you expand on this a bit? Visiting that page doesn't reveal anything like what you've described. Are you talking about the `load_definitions` variable and corresponding file? Or the description of using the HTTP API with `curl`? I was hoping for something a little more user-friendly than manually building http reqs.\n- To answer my own question, use `rabbitmqadmin` on the command line. `rabbitmqadmin help subcommands` seems to be the best documentation.\n- Great! thanks for the step by step guide. In case rabbitmqadmin is throwing Access refused error, consider adding '-u testuser -p testpassword' at the end of command.\n- How would you create a queue and exchange using this?\n- Only this helped me... Added this inside my DockerFile... works like a charm. Thank you. :-)\n- This returned 404 for me but this worked: `curl -i -u RABBITUSER:RABBITPASSWORD -H \"content-type:application/json\" -XPUT -d'{\"durable\":true}' http://localhost:15672/rabbitmq/api/queues/%2f/QUEUENAME`\n- Here's the API reference in general (which is unreasonably hard to find, imo) - raw.githack.com/rabbitmq/rabbitmq-management/rabbitmq_v3_6_9‌​/…","metadata":{"transformedAt":"2026-08-18T18:33:20.114Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":42,"totalLines":365,"estimatedTokens":2539}}39{"id":"stack-6742938","source":"stackoverflow","questionId":6742938,"title":"Deleting queues in RabbitMQ","tags":["queue","rabbitmq"],"text":"Title: Deleting queues in RabbitMQ\nTags: queue, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have a few queues running with RabbitMQ. A few of them are of no use now, how can I delete them? Unfortunately I had not set the `auto_delete` option.\n\nIf I set it now, will it be deleted?\n\nIs there a way to delete those queues now?\n\n========================================\n\nTop Answer:\n```\nimport pika\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n 'localhost'))\nchannel = connection.channel()\n\nchannel.queue_delete(queue='queue-name')\n\nconnection.close()\n```\n\nInstall pika package as follows\n\n```\n$ sudo pip install pika==0.9.8\n```\n\nThe installation depends on pip and git-core packages, you may need to install them first.\n\nOn Ubuntu:\n\n```\n$ sudo apt-get install python-pip git-core\n```\n\nOn Debian:\n\n```\n$ sudo apt-get install python-setuptools git-core\n$ sudo easy_install pip\n```\n\nOn Windows: To install easy_install, run the MS Windows Installer for setuptools\n\n```\n> easy_install pip\n> pip install pika==0.9.8\n```\n\n========================================\n\nCode:\n```text\nauto_delete\n```\n\n```text\nrabbitmqctl stop_app\nrabbitmqctl reset\nrabbitmqctl start_app\n```\n\n```text\nusers\n```\n\n```text\nvhosts\n```\n\n```text\nmessages\n```\n\n```text\nqueues\n```\n\n```text\nreset\n```\n\n```text\nusers\n```\n\n```text\nvhosts\n```\n\n```text\nmessages\n```\n\n```text\nreset\n```\n\n```text\npython tmp/rabbitmqadmin --vhost=... --username=... --password=... list queues > tmp/q\n\nvi tmp/q # remove all queues which you want to keep\n\ncut -d' ' -f4 tmp/q| while read q; \n do python tmp/rabbitmqadmin --vhost=... --username=... --password=... delete queue name=$q; \ndone\n```\n\n```text\n$ curl -i -u guest:guest -H \"content-type:application/json\" -XDELETE http://localhost:15672/api/queues/test/testqueue\nHTTP/1.1 204 No Content\nServer: MochiWeb/1.1 WebMachine/1.9.0 (someone had painted it blue)\nDate: Tue, 16 Apr 2013 10:37:48 GMT\nContent-Type: application/json\nContent-Length: 0\n```\n\n```text\nimport pika\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n 'localhost'))\nchannel = connection.channel()\n\nchannel.queue_delete(queue='queue-name')\n\nconnection.close()\n```\n\n```text\n$ sudo pip install pika==0.9.8\n```\n\n```text\n$ sudo apt-get install python-pip git-core\n```\n\n```text\n$ sudo apt-get install python-setuptools git-core\n$ sudo easy_install pip\n```\n\n```text\n> easy_install pip\n> pip install pika==0.9.8\n```\n\n```text\nalias qclean=\"rabbitmqctl list_queues | python ~/bin/qclean.py\"\n```\n\n```text\nimport sys\nimport pika\nconnection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))\nchannel = connection.channel()\n\nqueues = sys.stdin.readlines()[1:-1]\nfor x in queues:\n q = x.split()[0]\n print 'Deleting %s...' %(q)\n channel.queue_delete(queue=q)\n\nconnection.close()\n```\n\n```text\n.profile\n```\n\n```text\nqclean.py\n```\n\n```text\nfunction zeroPad(num, places) {\n var zero = places - num.toString().length + 1;\n return Array(+(zero > 0 && zero)).join(\"0\") + num;\n}\nvar queuePrefix = \"PREFIX\"\nfor(var i=0; i<255; i++){ \n var queueid = zeroPad(i, 4);\n $.ajax({url: '/api/queues/vhost/'+queuePrefix+queueid, type: 'DELETE', success: function(result) {console.log('deleted '+queuePrefix+queueid)}});\n}\n```\n\n```text\nhttp://{server}:15672/cli/rabbitmqadmin\n```\n\n```text\nrabbitmqadmin -u {user} -p {password} -V {vhost} delete queue name={name}\n```\n\n```text\nrabbitmqadmin -c /var/lib/rabbitmq/.rabbitmqadmin.conf -V {vhost} delete queue name={name}\n```\n\n```text\nhostname = localhost\nport = 15672\nusername = {user}\npassword = {password}\n```\n\n```text\ncurl -O http://localhost:15672/cli/rabbitmqadmin\nchmod u+x rabbitmqadmin\n./rabbitmqadmin delete queue name=myQueueName\n```\n\n```text\nrabbitmqctl -p / list_queues | grep 'amq.gen' | cut -f1 -d$'\\t' | xargs -I % ./rabbitmqadmin -V / delete queue name=%\n```\n\n```text\nfunction deleteQueues(vhost, queuePrefix) {\n if (vhost === '/') vhost = '%2F'; // html encode forward slashes\n $.ajax({\n url: '/api/queues/'+vhost, \n success: function(result) {\n $.each(result, function(i, queue) {\n if (queuePrefix && !queue.name.startsWith(queuePrefix)) return true;\n $.ajax({\n url: '/api/queues/'+vhost+'/'+queue.name, \n type: 'DELETE', \n success: function(result) { console.log('deleted '+ queue.name)}\n });\n });\n }\n });\n};\n```\n\n```text\ndeleteQueues('/');\n```\n\n```text\ndeleteQueues('/', 'test');\n```\n\n```text\ndeleteQueues('dev', 'foo');\n```\n\n```text\nvhost\n```\n\n```text\nqueuePrefix\n```\n\n```text\nrabbitmqctl list_queues -p vhost_name |\\\ngrep -v \"fast\\|medium\\|slow\" |\\\ntr \"[:blank:]\" \" \" |\\\ncut -d \" \" -f 1 |\\\nxargs -I {} curl -i -u guest:guest -H \"content-type:application/json\" -XDELETE http://localhost:15672/api/queues/<vhost_name>/{}\n```\n\n```text\nrabbitmqctl list_queues -p vhost_name\n```\n\n```text\ngrep -v \"fast\\|medium\\|slow\"\n```\n\n```text\ntr \"[:blank:]\" \" \"\n```\n\n```text\ncut -d \" \" -f 1\n```\n\n```text\nxargs -I {} curl -i -u guest:guest -H \"content-type:application/json\" -XDELETE http://localhost:15672/api/queues/<vhost>/{}\n```\n\n```text\n{}\n```\n\n```text\n$ sudo rabbitmq-plugins enable rabbitmq_management\n```\n\n```text\nusername: guest\n```\n\n```text\npassword: guest\n```\n\n```text\nsudo rabbitmqctl list_queues | awk '{print $1}' > queues.txt; for line in $(cat queues.txt); do sudo rabbitmqctl delete_queue \"$line\"; done\n```\n\n```text\nwhile read ...\n```\n\n```text\ndo sudo rabbitmqctl delete_queue queue_name\n```\n\n```text\nrabbitmqctl\n```\n\n```text\nrabbitmqadmin\n```\n\n```text\nrabbitmqctl delete_queue <queue_name>\n```\n\n```text\nrabbitmqadmin\n```\n\n```text\nvar result = await _services.GetService<IBrokerObjectFactory>()\n .DeleteQueue(\"queue\", \"vhost\");\n```\n\n```text\nvar result = await _services.GetService<IBrokerObjectFactory>()\n .DeleteQueue(\"queue\", \"vhost\", x =>\n {\n x.WhenHasNoConsumers();\n x.WhenEmpty();\n });\n```\n\n```bash\nsudo rabbitmqctl delete_queue --vhost <vhost-name> <queue-name>\n```\n\n```bash\nsudo rabbitmqctl purge_queue --vhost <vhost-name> <queue-name>\n```\n\n```text\n--vhost <vhost-name>\n```\n\n```text\n<vhost-name>\n```\n\n```text\n<queue-name>\n```\n\n```text\nsudo rabbitmqctl list_queues --vhost <vhost-name>\n```\n\n========================================\n\nComments:\n- I've done this but my management_plugin is in a different state than my commandline interface\n- WARNING: this will also delete any users and vhosts you have configured on your rabbit server. I found this out the hard way :)\n- Oops, sorry about that. I haven't noticed it since I had a really basic configuration at the time I was involved with rabbitmq. I will update the answer. Thanks!\n- this is a really extreme answer. you could also say \"shut down the server and wipe the disk\" to \"delete\" the queues.\n- Make sure your user is tagged as `administrator` otherwise they can't use certain parts of the API.\n- I am getting: `$ curl -i -u 'user:pass' -H \"content-type:application/json\" -XDELETE 'http://localhost:15672/api/queues/vhostname/name.portal' HTTP/1.1 204 No Content Server: MochiWeb/1.1 WebMachine/1.10.0 (never breaks eye contact) Date: Wed, 30 Jul 2014 11:23:47 GMT Content-Type: application/json Content-Length: 0` However the queue still remains :( - any ideas?\n- Definitely easier for those already working with pika, thanks a lot\n- this returns ` Could not connect: [Errno 111] Connection refused` for me any way to debug to see what's going on?\n- Check auth logs, rabbit logs... User might not have permission to work on VHost... Quit difficult to say where to start\n- the solution was setting the user with 'administrator' tag\n- This worked perfectly for removing a huge number of queues with the same prefix using only the web-admin. Thanks!\n- Thanks to @phriscage for the inspiration :)\n- Man... thanks a lot. I found your answer very helpful.\n- It looks like you're including a link to your own product or service, or a link to a product or service that you're affiliated with. If this is the case, you *must* disclose your affiliation in the answer itself..\n- HareDu is an OSS project that is 100% free and it solves the problem if using a .NET language like C#.","metadata":{"transformedAt":"2026-08-18T18:33:20.114Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":60,"totalLines":387,"estimatedTokens":2059}}40{"id":"stack-14699873","source":"stackoverflow","questionId":14699873,"title":"How to reset user for rabbitmq management","tags":["rabbitmq"],"text":"Title: How to reset user for rabbitmq management\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nUsing rabbitmq, we can install management plugin. Then we access via browser using `http://localhost:55672/` using guest:guest.\nThe problem is, I can not login anymore because i changed password and entered blank for role.\n\nIs there any way to reset user for rabbitmq management?\n\n========================================\n\nTop Answer:\nThe simplest way I found is to use this command to reset the password for any user in RabbitMQ\n\n```\nrabbitmqctl change_password \n```\n\n========================================\n\nCode:\n```text\nhttp://localhost:55672/\n```\n\n```text\nadd_user {username} {password}\n```\n\n```text\nset_permissions [-p vhostpath] {user} {conf} {write} {read}\n```\n\n```text\nrabbitmqctl add_user newadmin s0m3p4ssw0rd\nrabbitmqctl set_user_tags newadmin administrator\nrabbitmqctl set_permissions -p / newadmin \".*\" \".*\" \".*\"\n```\n\n```text\nrabbitmqctl\n```\n\n```text\nrabbitmqctl add_vhost statuscheckvhost\nrabbitmqctl add_user heartbeat alive\nrabbitmqctl set_permissions -p statuscheckvhost heartbeat \".*\" \".*\" \".*\"\nrabbitmqctl set_user_tags heartbeat management\n\ncurl -i -u heartbeat:alive http://127.0.0.1:55672/api/aliveness-test/statuscheckvhost\nHTTP/1.1 200 OK\nServer: MochiWeb/1.1 WebMachine/1.9.0 (someone had painted it blue)\nDate: Thu, 21 Feb 2013 22:20:10 GMT\nContent-Type: application/json\nContent-Length: 15\nCache-Control: no-cache\n{\"status\":\"ok\"}\n```\n\n```text\nrabbitmqctl change_password <USERNAME> <NEWPASSWORD>\n```\n\n```text\ndocker exec -it <YOUR_CONTAINER> /bin/bash\n```\n\n```text\nrabbitmqctl change_password <USERNAME> <NEWPASSWORD>\n```\n\n========================================\n\nComments:\n- thanks, i try this to set permission: rabbitmqctl set_user_tags khad administrator\n- @Superbiji you should consider converting this comment into an answer. I know it is old but this was the solution that worked for me.\n- `set_permissions -p / newadmin \".*\" \".*\" \".*\"` this worked perfectly fine!! thanks\n- You should be logged in as root or use \"sudo\"\n- `\"/man/rabbitmqctl.1.man.html\" not found` received when I clicked on that \"...this page\" link. It's 27-July-2023 by the way. : )\n- Thanks to this answer, I was able to figure out that passwords MUST NOT contain a `$` ... apparently.\n- Indeed, that took me a while to figure out: it is recommended to use an alphanumeric value with a very limited set of symbols (e.g. :, =). See RabbitMQ documentation: rabbitmq.com/access-control.html#passwords-and-shell-escapin‌​g\n- Found this after ChatGPT advising me to delete and recreate the user and I was like \"must be a better way...\"","metadata":{"transformedAt":"2026-08-18T18:33:20.114Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":83,"estimatedTokens":665}}41{"id":"stack-38103412","source":"stackoverflow","questionId":38103412,"title":"NServiceBus and Rabbit MQ or Kafka","tags":["rabbitmq","apache-kafka","message-queue","nservicebus"],"text":"Title: NServiceBus and Rabbit MQ or Kafka\nTags: rabbitmq, apache-kafka, message-queue, nservicebus\nSource: Stack Overflow\n\nQuestion:\nI am trying to learn messaging system. I have found that RabbitMq and NServiceBus are using together in few places. My questions are\n\n- If I am using the RabbitMQ then why do i need NServiceBus? and vice versa\n\n- What NServiceBus can do but RabbitMQ or Kafka cannot?\n\n- Can I use NServiceBus and kafka together? Or Apache-Kafka does not require NServiceBus\n\n========================================\n\nTop Answer:\nIt seems there is community support for Kafka transport in NServiceBus now: https://docs.particular.net/nservicebus/kafka/\n(haven't tried it myself yet).\n\n========================================\n\nComments:\n- Related to your second question\n- @vappolinario Thanks for this. Is it same for Kafka?\n- To your question about Kafka: particular.net/blog/lets-talk-about-kafka\n- I finally have a concise answer! \"The equivalent question of why would you need NServiceBus with RabbitMQ, is to ask why you would need the .NET Framework with ASP.NET MVC, or WinForms, or XAML, or any of the built-in libraries that .NET ships with, when you have the Command Language Runtime.\" annnd I'm going to tweet that.\n- A very nice clear explanation @Derick. Many thanks for taking your time to explan this. It is now clear enough\n- You can always take a look at www.masstransit-project.com/\n- Perfect! I have been scratching my head around this question since the product I support involves NServiceBus but i never got why it is required in first place!!\n- I've been struggling explaining our reasoning of choosing NServiceBus over just going with RabbitMQ and your summary nails it. We decided early that we would like to have all these features for free and not reinvent the wheel. The small drawback of this was that we didn't learn from our own mistakes and those lessons last longer.\n- This recently came up for my org which has been working with rabbitmq for a while now and our org has done exactly what you've outlined in your answer - poor rmq wrapper.\n- @ChristianPaulin \"for free\" is maybe exaggerated when talking about NServiceBus :)\n- That's a dead link now I'm afraid.\n- github.com/pablocastilla/NServiceBus.Kafka It doesn't seem to be maintained though.\n- Check out particular.net/blog/lets-talk-about-kafka for Particular's viewpoint on Kafka.","metadata":{"transformedAt":"2026-08-18T18:33:20.114Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":35,"estimatedTokens":597}}42{"id":"stack-47290108","source":"stackoverflow","questionId":47290108,"title":"How to open rabbitmq in browser using docker container?","tags":["windows","docker","rabbitmq"],"text":"Title: How to open rabbitmq in browser using docker container?\nTags: windows, docker, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nThis was probably asked already, but so far I can't find any detailed explanation at all, and the existing documentation seems as if it was written for some kind on psychic who supposed to know everything.\n\nAs per this manual, I added the container\n\n```\ndocker run -d --hostname my-rabbit --name some-rabbit rabbitmq:latest\n```\n\nThen I checked it to receive the container ip\n\n```\ndocker inspect some-rabbit\n```\n\nChecked ports with\n\n```\ndocker ps\n```\n\nAnd tried to connect in the browser with this formula\n\n```\nhttps://{container-ip}:{port}\n```\n\nIt did't work.\n\nAm I'm doing something wrong, or maybe I am supposed to add something additional, like a container for apache or other stuff?\n\n**EDIT**\n\nAs I understand, after creating some-rabbit container, now I need to run Dockerfile to create image? (This whole thing is confusing to me). How am I supposed to do that? I mean, I saw command `docker build -f /path/to/a/Dockerfile` but if for example I placed the Dockerfile in second path `D:\\Docker\\rabbitmq`, how I supposed to get there? (the path doesn't seems to be recognized)\n\n========================================\n\nTop Answer:\nFirst off, you need the management image (eg. `rabbitmq:3-management`) to access it through the browser. If your docker is running locally, then you should be able to access it by navigating to `http://localhost:{port}` or `http://127.0.0.1:{port}` (`15672` by default).\n\nHere is an example of a simple `docker-compose.yml`: \n\n```\nversion: \"3\"\nservices:\n rabbitmq:\n image: \"rabbitmq:3-management\"\n ports:\n - \"5672:5672\"\n - \"15672:15672\"\n volumes:\n - 'rabbitmq_data:/data'\n\nvolumes:\n rabbitmq_data:\n```\n\nAfter starting the container, Rabbitmq is now accessible at `http://127.0.0.1:15672`. The default username and password should be `guest:guest`. More details here.\n\nhttps://i.sstatic.net/LOciz.png\n\n========================================\n\nCode:\n```text\ndocker run -d --hostname my-rabbit --name some-rabbit rabbitmq:latest\n```\n\n```text\ndocker inspect some-rabbit\n```\n\n```text\ndocker ps\n```\n\n```text\nhttps://{container-ip}:{port}\n```\n\n```text\ndocker build -f /path/to/a/Dockerfile\n```\n\n```text\nD:\\Docker\\rabbitmq\n```\n\n```text\ndocker run -d --hostname my-rabbit --name some-rabbit rabbitmq:3-management\n```\n\n```text\nFROM rabbitmq\n\nRUN rabbitmq-plugins enable --offline rabbitmq_management\n\nEXPOSE 15671 15672\n```\n\n```text\nrabbitmq:latest\n```\n\n```text\nrabbitmq:management\n```\n\n```text\nlocalhost:15672\n```\n\n```text\n-p 15672:15672\n```\n\n```text\nrabbitmq:management\n```\n\n```text\nversion: \"3\"\nservices:\n rabbitmq:\n image: \"rabbitmq:3-management\"\n ports:\n - \"5672:5672\"\n - \"15672:15672\"\n volumes:\n - 'rabbitmq_data:/data'\n\nvolumes:\n rabbitmq_data:\n```\n\n```text\nrabbitmq:3-management\n```\n\n```text\nhttp://localhost:{port}\n```\n\n```text\nhttp://127.0.0.1:{port}\n```\n\n```text\n15672\n```\n\n```text\ndocker-compose.yml\n```\n\n```text\nhttp://127.0.0.1:15672\n```\n\n```text\nguest:guest\n```\n\n```text\nversion: '3'\nservices:\n rabbitmq:\n image: rabbitmq:management\n ports:\n - '5672:5672'\n - '15672:15672'\n volumes:\n - rabbitmq_data\n```\n\n```text\ndocker inspect\n```\n\n```text\ndocker run -d --name some-rabbit -p 5672:5672 -p 5673:5673 -p 15672:15672 rabbitmq:3-management\n```\n\n```text\ndocker run -d --name some-rabbit -p 4369:4369 -p 5671:5671 -p 5672:5672 -p 15672:15672 rabbitmq\n```\n\n```text\ndocker container exec -it some-rabbit rabbitmq-plugins enable rabbitmq_management\n```\n\n```text\nguest\n```\n\n```text\nguest\n```\n\n```text\nipconfig\n```\n\n```text\ndocker run -d --name same-rabbit \\\n--hostname my-rabbit \\\n-e RABBITMQ_DEFAULT_USER=USERNAME \\\n-e RABBITMQ_DEFAULT_PASS=PASSWORD \\\n-v /home/USER/rabbitmq/:/var/lib/rabbitmq \\\n-p 5673:5672 \\\n-p 15673:15672 \\\nrabbitmq:management\n```\n\n```text\nversion: '3.3'\nservices:\n rabbitmq:\n container_name: same-rabbit\n environment:\n - RABBITMQ_DEFAULT_USER=USERNAME\n - RABBITMQ_DEFAULT_PASS=PASSWORD\n volumes:\n - '/home/USER/rabbitmq/:/var/lib/rabbitmq'\n ports:\n - '5673:5672'\n - '15673:15672'\n image: 'rabbitmq:management'\n```\n\n```text\nval rabbitMQContainer = new RabbitMQContainer(\"rabbitmq:management\")\n rabbitMQContainer.start()\n if (os == \"mac os x\") Process(s\"open ${rabbitMQContainer.getHttpUrl}\").!\n```\n\n```text\nFROM rabbitmq:3.8-management\nRUN rabbitmq-plugins enable --offline rabbitmq_mqtt rabbitmq_federation_management rabbitmq_stomp\nWORKDIR /usr/src/app\nENV RABBITMQ_ERLANG_COOKIE: 'secret cookie here'\nVOLUME ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/mnesia/\nEXPOSE 5672 15672\n```\n\n```text\ndocker pull rabbitmq:management\n```\n\n```text\ndocker run -p 15672:15672 -p 5672:5672 --name rabbit-image-name rabbitmq:management\n```\n\n```text\ndocker run -d --hostname rmq --name rabbit-server \n-p 8085:15672 -p 5672:5672 rabbitmq:3-management\n```\n\n```text\ndocker container exec -it container-name rabbitmq-plugins enable rabbitmq_management\n```\n\n```text\n--network host\n```\n\n========================================\n\nComments:\n- Still unclear with the Dockerfile, how I supposed to run it at all? I mean, it supposed to be `docker build -f [path]` but for example I placed it in D:\\Docker\\rabbitmq\\ and here Dockerfile. It seems that I am unable to find it\n- @OlegsJasjko Don't build the dockerfile. I just posted it to show you the difference between the `rabbitmq` image and `rabbitmq:management` image. If you want to access UI, just run `rabbitmq:3-management` instead of `rabbitmq:3-latest`. The management image is already built on dockerhub\n- Hm, then I still have a problem. I removed previous container, added new one with -management. Checked if it is started and tried to open localhost:15672 (default port as I understand) and nope, nothing happened, can't open this link\n- @OlegsJasjko If you want to use `localhost` make sure to expose the port by adding `-p 15672:15672`, then you can connect to `localhost:15672`. Otherwise, use `:15672`\n- Recreated container with port (is there a way to add port to existing one?) and yep, now it works on localhost:15672. But for some reason, it didn't worked with container-ip, could you please add to yours answer words about port? (will accept it anyway, but still it will be more full then)\n- maybe management plugin is not enable in your container. so just do this command: `docker exec [CONTAINER_NAME] rabbitmq-plugins enable rabbitmq_management`\n- This is not a dockerfile... it's a docker-compose file and the format is not correct.\n- This worked for me although I had to use localhost rather than 127.0.0.1\n- Weird, exactly the opposite as for @JohnHunt here. `localhost` doesn't resolve, and only `127.0.0.1` works.\n- For me this worked because I just had rabbitmq without management plugin\n- After navigating to this URL, I am getting the RabbitMQ login page, But Its showing PAGE UNRESPONSIVE error. any idea or solution why??","metadata":{"transformedAt":"2026-08-18T18:33:20.114Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":38,"totalLines":284,"estimatedTokens":1754}}43{"id":"stack-26811924","source":"stackoverflow","questionId":26811924,"title":"Spring AMQP + RabbitMQ 3.3.5 ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN","tags":["rabbitmq","spring-integration","spring-amqp"],"text":"Title: Spring AMQP + RabbitMQ 3.3.5 ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN\nTags: rabbitmq, spring-integration, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI am getting below exception\n\n org.springframework.amqp.AmqpAuthenticationException: com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.\n\nConfiguration: RabbitMQ 3.3.5 on windows\n\nOn Config file in `%APPDATA%\\RabbitMQ\\rabbit.config`\nI have done below change as per https://www.rabbitmq.com/access-control.html\n\n```\n[{rabbit, [{loopback_users, []}]}].\n```\n\nI also tried creating a user/pwd - test/test doesn't seem to make it work.\n\nTried the Steps from this post.\n\nOther Configuration Details are as below:\n\nTomcat hosted Spring Application Context:\n\n```\n\n \n \n\n \n \n\n \n \n\n \n\n \n \n \n \n \n```\n\nIn my Controller Class\n\n```\n@Autowired\nRmqMessageSender rmqMessageSender;\n\n//Inside a method\nrmqMessageSender.submitToECLDown(orderInSession.getOrderNo());\n```\n\nIn My Message sender:\n\n```\nimport org.springframework.amqp.core.AmqpTemplate;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Component;\n\n@Component(\"messageSender\")\npublic class RmqMessageSender {\n\n @Autowired\n AmqpTemplate rabbitTemplate;\n\n public void submitToRMQ(String orderId){\n try{\n rabbitTemplate.convertAndSend(\"Hello World\");\n } catch (Exception e){\n LOGGER.error(e.getMessage());\n }\n } \n}\n```\n\nAbove exception Block gives below Exception\n\n org.springframework.amqp.AmqpAuthenticationException: com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.\n\nError Log\n\n```\n=ERROR REPORT==== 7-Nov-2014::18:04:37 ===\nclosing AMQP connection (10.1.XX.2XX:52298 -> 10.1.XX.2XX:5672):\n {handshake_error,starting,0,\n {amqp_error,access_refused,\n \"PLAIN login refused: user 'guest' can only connect via localhost\",\n 'connection.start_ok'}}\n```\n\nPls find below the pom.xml entry\n\n```\n\n org.springframework.amqp\n spring-rabbit\n 1.3.6.RELEASE\n \n \n org.springframework.integration\n spring-integration-amqp\n 4.0.4.RELEASE\n \n```\n\nPlease let me know if you have any thoughts/suggestions\n\n========================================\n\nTop Answer:\nTo complete @cpu-100 answer,\n\nin case you don't want to enable/use web interface, you can create a new credentials using command line like below and use it in your code to connect to RabbitMQ.\n\n```\n$ rabbitmqctl add_user YOUR_USERNAME YOUR_PASSWORD\n$ rabbitmqctl set_user_tags YOUR_USERNAME administrator\n$ rabbitmqctl set_permissions -p / YOUR_USERNAME \".*\" \".*\" \".*\"\n```\n\n========================================\n\nCode:\n```text\n[{rabbit, [{loopback_users, []}]}].\n```\n\n```text\n<!-- Rabbit MQ configuration Start -->\n <!-- Connection Factory -->\n <rabbit:connection-factory id=\"rabbitConnFactory\" virtual-host=\"/\" username=\"guest\" password=\"guest\" port=\"5672\"/>\n\n <!-- Spring AMQP Template -->\n <rabbit:template id=\"rabbitTemplate\" connection-factory=\"rabbitConnFactory\" routing-key=\"ecl.down.queue\" queue=\"ecl.down.queue\" />\n\n <!-- Spring AMQP Admin -->\n <rabbit:admin id=\"admin\" connection-factory=\"rabbitConnFactory\"/>\n\n <rabbit:queue id=\"ecl.down.queue\" name=\"ecl.down.queue\" />\n\n <rabbit:direct-exchange name=\"ecl.down.exchange\">\n <rabbit:bindings>\n <rabbit:binding key=\"ecl.down.key\" queue=\"ecl.down.queue\"/>\n </rabbit:bindings>\n </rabbit:direct-exchange>\n```\n\n```text\n@Autowired\nRmqMessageSender rmqMessageSender;\n\n//Inside a method\nrmqMessageSender.submitToECLDown(orderInSession.getOrderNo());\n```\n\n```text\nimport org.springframework.amqp.core.AmqpTemplate;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Component;\n\n@Component(\"messageSender\")\npublic class RmqMessageSender {\n\n @Autowired\n AmqpTemplate rabbitTemplate;\n\n public void submitToRMQ(String orderId){\n try{\n rabbitTemplate.convertAndSend(\"Hello World\");\n } catch (Exception e){\n LOGGER.error(e.getMessage());\n }\n } \n}\n```\n\n```text\n=ERROR REPORT==== 7-Nov-2014::18:04:37 ===\nclosing AMQP connection <0.489.0> (10.1.XX.2XX:52298 -> 10.1.XX.2XX:5672):\n {handshake_error,starting,0,\n {amqp_error,access_refused,\n \"PLAIN login refused: user 'guest' can only connect via localhost\",\n 'connection.start_ok'}}\n```\n\n```text\n<dependency>\n <groupId>org.springframework.amqp</groupId>\n <artifactId>spring-rabbit</artifactId>\n <version>1.3.6.RELEASE</version>\n </dependency>\n <dependency>\n <groupId>org.springframework.integration</groupId>\n <artifactId>spring-integration-amqp</artifactId>\n <version>4.0.4.RELEASE</version>\n </dependency>\n```\n\n```text\n%APPDATA%\\RabbitMQ\\rabbit.config\n```\n\n```text\nCaused by: com.rabbitmq.client.AuthenticationFailureException: \nACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. \nFor details see the\n```\n\n```text\n127.0.0.1\n```\n\n```text\nhost\n```\n\n```text\nConnectionFactory\n```\n\n```text\nACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.\n```\n\n```text\nweb.config\n```\n\n```text\n\"\"\n```\n\n```text\n[{rabbit, [{loopback_users, []}]}].\n```\n\n```text\nc:\\Users\\[your user name]\\AppData\\Roaming\\RabbitMQ\\rabbitmq.config\n```\n\n```text\n$ rabbitmqctl add_user YOUR_USERNAME YOUR_PASSWORD\n$ rabbitmqctl set_user_tags YOUR_USERNAME administrator\n$ rabbitmqctl set_permissions -p / YOUR_USERNAME \".*\" \".*\" \".*\"\n```\n\n```text\n:\n```\n\n```text\n: . ? + %\n```\n\n```text\nPLAIN\n```\n\n```text\namqp://\n```\n\n```text\namqps://\n```\n\n```text\ns\n```\n\n```text\nCachingConnectionFactory connectionFactory = \n new CachingConnectionFactory(\"rabbit_host\");\n\n connectionFactory.setUsername(\"login\");\n connectionFactory.setPassword(\"password\");\n```\n\n```text\nConnectionFactory factory = new ConnectionFactory();\nfactory.setHost(\"your-host-ip\");\nfactory.setUsername(\"username-you-created\");\nfactory.setPassword(\"username-password\");\n```\n\n```text\nConnectionFactory factory = new ConnectionFactory();\nfactory.UserName = \"tester001\";\nfactory.Password = \"testing\";\nfactory.VirtualHost = \"/\";\nfactory.HostName = \"192.168.1.101\";\nfactory.Port = AmqpTcpEndpoint.UseDefaultPort;\n```\n\n========================================\n\nComments:\n- Make sure that config you edit loaded.\n- zaq178miami, I have done few steps to make sure its loaded. Restart the service, re-boot the machine & even re-install the RabbitMQ.\n- Hi Artem , I have added pom.xml entry for versions of jar. Ideally I would like to stay away from using guest username & password. Could you please let me know if you have any pointers usable for a prod ready Use Case/Proof of concept in above senario?\n- Sorry, it ins't clear what you mean regarding ` prod ready Use Case/Proof of concept in above senario`, because I don't see any use case questions here. Feel free to creat any user on the RabbitMQ Broker.\n- The simple solution is to specify `localhost` like so: `ConnectionFactory(\"localhost\")`\n- For azure UbuntuVM, with the azure assigned ip `guest/guest` account works globally! :(\n- It is not working for me either. Connection with guest:guest is fine. Connection with newUser:newPwd is giving this error. No idea why !!\n- I had the same problem. Following this suggestion it solved this problem.\n- It worked. No LLM could figure this out\n- Yes - Watch out for typos. :-)\n- Not only typos but if you are using the URL mode to connect, then only use A-Za-z0-9 set. and do not try to go to more complex URL encoding scheme.\n- My lord, my pass was incorrect.\n- I had trouble locating where is the rabbitmq.config file located. Neither `rabbitmqctl status` nor `rabbitmq-diagnostics status` listed anything in Config files sections. I ended up setting `RABBITMQ_CONFIG_FILES` env variable to `C:\\Users\\UserName\\AppData\\Roaming\\RabbitMQ` and placed file called `rabbitmq.conf` there with following line: `loopback_users = none` See here: Using a Directory of .conf Files\n- Thank-you, I have zero experience with RabbitMQ, and this was a quick solution to getting a remote connection to a server brought up from an AWS AMI for experimenting on to see if I should look into it further.\n- I was just digging into the code and this was indeed a bug that has been fixed later in 2017 :-)\n- You can encode special characters , see this post: stackoverflow.com/questions/29346686/…\n- This works after change 127.0.0.1 to localhost for docker-hosted local rabbitmq instance.","metadata":{"transformedAt":"2026-08-18T18:33:20.114Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":26,"totalLines":318,"estimatedTokens":2192}}44{"id":"stack-43264838","source":"stackoverflow","questionId":43264838,"title":"Celery: When should you choose Redis as a message broker over RabbitMQ?","tags":["python","django","redis","rabbitmq","celery"],"text":"Title: Celery: When should you choose Redis as a message broker over RabbitMQ?\nTags: python, django, redis, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nMy rough understanding is that Redis is better if you need the in-memory key-value store feature, however I am not sure how that has anything to do with distributing tasks?\n\nDoes that mean we should use Redis as a message broker IF we are already using it for something else?\n\n========================================\n\nTop Answer:\nThe Redis broker gives tasks to workers in a fair round robin between different queues. Rabbit is FIFO always. For me, a fair round robin was preferable and I tried both. Rabbit seems a tad more stable though.\n\n========================================\n\nComments:\n- Celery clearly recommends using AMQP over Redis. I wouldn't use Redis.\n- @Apero Though Rabbitmq has been supported longer than Redis (and is the default), both are listed as stable. I don't see a clear recommendation either way. I'd be curious to read about if you've seen otherwise, however. docs.celeryproject.org/en/master/getting-started/brokers/…\n- @DanilaGanchar the article mentioned: It is apparent that RabbitMQ takes 75% of Redis’ time to add a message and 86% of the time to process a message. why Redis is faster?\n- Updated link to the brokers in the docs: docs.celeryproject.org/en/stable/getting-started/…\n- One annoyance with using Redis / python 3.7 / Celery 4.2 is that the results backend doesn't work because `async` is now part of python ( see github.com/celery/celery/issues/4849 ) -- this should be fixed with celery 4.3 . I don't know if this also affects RabbitMQ.\n- However, Celery 4.3 is now released, so this is no longer an issue -- results backend works again with Redis.\n- You can also use Celery with Amazon SQS which is super simple to deploy and run\n- @JasonGenX SQS support is experimental, though. I wonder what the unstable/missing bits are...\n- As of July 2019, SQS is marked as stable. Yet, it is missing monitoring and control channels. Also, SQS behavior is a bit of counter-intuitive. We've got messages processed up to 14 times due to at-least-once delivery policy.\n- According to this ticket github.com/celery/celery/issues/5001 you can not use Amazon MQ as replacement for RabbitMQ. They implement different verions of AMQP protocol (1.0 vs 0.9.1)\n- Now Amazon MQ also offers rabbitmq brokers in addition to activemq, I've used it and it works fine.\n- I've personally moved away from SQS so I don't know if this works/is appropriate for Celery, but for those reading along: SQS now supports FIFO queues that guarantee FIFO and exactly-once delivery.\n- \"The Redis broker gives tasks to workers in a fair round robin between different queues.\" Can you provide a reference for this?\n- docs.celeryq.dev/projects/kombu/en/v4.0.2/reference/… Believe me - I tried all the different transport options. I'm actually using SQS now and to me, it's the best one but it's also not round robin.","metadata":{"transformedAt":"2026-08-18T18:33:20.115Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":31,"estimatedTokens":750}}45{"id":"stack-6636213","source":"stackoverflow","questionId":6636213,"title":"RabbitMQ vs Socket.io?","tags":["node.js","websocket","rabbitmq","amqp","socket.io"],"text":"Title: RabbitMQ vs Socket.io?\nTags: node.js, websocket, rabbitmq, amqp, socket.io\nSource: Stack Overflow\n\nQuestion:\nI'm doing real time live web app development.\n\nBrowser users should be able to communicate with eachother through a node.js server. One of the user writes a message and all other users will get it.\n\nI don't quite get how RabbitMQ works. But from quick reading it seems that it handles publication/subscription of messages.\n\nA user (in a browser) publishes something and subscribers (in other browsers) get that message. Isn't that what Socket.io is doing with websockets?\n\nHere are my questions:\n\n- What are the advantages/disadvantages for each one of them?\n\n- Can Socket.io replace RabbitMQ?\n\n- Are there scenarios I need RabbitMQ for web apps where Socket.io doesn't suffice?\n\n========================================\n\nTop Answer:\nRabbitMQ is a really flexibly way of creating network topologies. It's mature, supported, and comes from a finance space (in finance they've been doing messaging for a long long time). I use RabbitMQ server-side, and use other protocols to connect to RabbitMQ over a \"gateway\". \n\nBehind the scenes, RabbitMQ is written in an ultra concise functional language called Erlang. That's no big deal in and of itself, but the contention is that if you know what you are doing, and can say it in less lines of code, then it's ultimately more reliable and testable.\n\nbtw: Erlang is used by Facebook and Twitter for their behind the scenes stuff.\n\nNow, RabbitMQ is more than just a network sockets type thing... it's based on \"guaranteed delivery\". That feature is important for enterprise situations. RabbitMQ, alternatively could be used to scale... actually, there's more than that... I'm not doing it justice.\n\nI can't comment on node.js as I haven't had a chance to play with it yet. I'm happy with RabbitMQ.\n\nre: socket.io (are we talking websockets?) -- if this is for the browser (as the post above suggests), you could potentially bridge that into RabbitMQ. i.e. RabbitMQ is that flexible.","metadata":{"transformedAt":"2026-08-18T18:33:20.115Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":35,"estimatedTokens":510}}46{"id":"stack-21363302","source":"stackoverflow","questionId":21363302,"title":"RabbitMQ - Message order of delivery","tags":["queue","rabbitmq","message-queue"],"text":"Title: RabbitMQ - Message order of delivery\nTags: queue, rabbitmq, message-queue\nSource: Stack Overflow\n\nQuestion:\nI need to choose a new Queue broker for my new project. \n\nThis time I need a scalable queue that supports pub/sub, and keeping message ordering is a must. \n\nI read Alexis comment: He writes:\n\n \"Indeed, we think RabbitMQ provides stronger ordering than Kafka\"\n\nI read the message ordering section in rabbitmq docs:\n\n \"Messages can be returned to the queue using AMQP methods that feature\n a requeue\n parameter (basic.recover, basic.reject and basic.nack), or due to a channel \n closing while holding unacknowledged messages...With release 2.7.0 and later \n it is still possible for individual consumers to observe messages out of \n order if the queue has multiple subscribers. This is due to the actions of \n other subscribers who may requeue messages. From the perspective of the queue \n the messages are always held in the publication order.\"\n\nIf I need to handle messages by their order, I can only use rabbitMQ with an exclusive queue to each consumer? \n\nIs RabbitMQ still considered a good solution for ordered message queuing?\n\n========================================\n\nTop Answer:\nMessage ordering is preserved in Kafka, but only within partitions rather than globally. If your data need both global ordering and partitions, this does make things difficult. However, if you just need to make sure that all of the same events for the same user, etc... end up in the same partition so that they are properly ordered, you may do so. The producer is in charge of the partition that they write to, so if you are able to logically partition your data this may be preferable.\n\n========================================\n\nCode:\n```text\ntry (Connection connection2 = factory.newConnection();\n Channel channel2 = connection.createChannel()) {\n // publish messages alternating to two different topics\n for (int i = 0; i < messageCount; i++) {\n final String routingKey = i % 2 == 0 ? routingEven : routingOdd;\n channel2.basicPublish(exchange, routingKey, null, (\"Hello\" + i).getBytes(UTF_8));\n }\n}\n```\n\n```text\n// declare a queue for the consumer\nfinal String queueName = channel.queueDeclare().getQueue();\n\n// we bind to queue with the two different routingKeys\nfinal String routingEven = \"even\";\nfinal String routingOdd = \"odd\";\nchannel.queueBind(queueName, exchange, routingEven);\nchannel.queueBind(queueName, exchange, routingOdd);\nchannel.basicConsume(queueName, true, new DefaultConsumer(channel) { ... });\n```\n\n```text\nExecutorService\n```\n\n```text\nConnectionFactory.setSharedExecutor(...)\n```\n\n```text\nExecutors.newSingleThreadExecutor()\n```\n\n```text\nConsumer\n```\n\n```text\nConsumer\n```\n\n========================================\n\nComments:\n- Is there a way to configure rabbit to requeue the messages at the end of the queue instead of the front?\n- Probably, but what are you trying to achieve and what is the importance of this?\n- Thanks for pointing out the differences between RabbitMQ = 2.7.0, that saved my day :-)\n- @Ryan: No you cannot. But there's a workaround: you can clone the message and publish it into the same queue, like a completely new message, then it will go to the end of the queue. In this case the attribute `redelivered` of the message will be `false` instead of `true` like a normal requeue.\n- Kafka allows for parallelization with an app level defined partial order by the way of partitions, which is very practical for real tasks. RabbitMQ appears to either offer global order with no parallelization, or no order at all. Whose guarantees are better? )\n- I'm not sure what is meant by \"app-level defined partial order.\" This seems to be some type of partition lower than the queue level, which would not really make sense to do in Rabbit since a queue can be defined to hold whatever combination of messages make sense. Unless I'm misunderstanding what you mean by that.\n- Sorry for coming back to a 4 year old answer. Whilst the order of messages through one channel, one exchange, one queue and one channel may be preserved, things can go wrong on the client. For instance the C# client library spawns a thread per received message. With my mean-spirited mind I say, so how does OS scheduling then interfere with the order of processing received messages? Surely there is in effect a race condition between two threads processing two closely timed messages? The client lib won't wait for the first thread to complete before spawning the next. Makes debug hard. Any clues?\n- @bazza - Ask as a new question and I'll give a stab at it :)\n- @theMayer, thanks for the offer! I've actually gone off and read the manual a bit more, and realised that all the code samples I've seen implement `IBasicConsumer` (the callbacks for which are indeed called concurrently, hence the threads; I don't quite believe the manual's statement about processing order; the tasks might get launched in order, but then it is down to the OS scheduler). Looks like the \"pull\" API `channel.BasicGet()` is more like it. Now all I need to find is the equivalent of `select()`...\n- It's possible they re-wrote the client implementation. The one I used years ago was horrid, and I hacked it myself (not high enough quality to re-contribute). It would not surprise me if that's what they did because I did the same thing myself. Messaging is not designed for serial processing, plain and simple - so don't count on it when you design your app.\n- @bazza - the other thing you could do is set auto-ack to false, or pre-fetch to 1. That will ensure serial delivery, though again, it's not a good idea to design serial requirements using a parallel platform structure.\n- @theMayer It depends; some of the uses I've seen other devs use RabbitMQ for are simply as a tcp socket replacement with no hint of parallel messaging architectures. The other features that RabbitMQ provides (like durability, etc) are attractive all by themselves! Used like that (so not exercising the messaging patterns at all, which is almost a travesty) it's useful to have message order preserved.\n- @theMayer, and thank you for the tips on auto-ack and pre-fetch.\n- I’ll agree with that. At least you have solid rationale.\n- This is accurate information, but there is no practical significance of \"consumption order.\" Message *processing* is what results in a change of state in the system. As messages can be re-queued after \"consumption\" but ostensibly before \"processing\", all this deals with is the temporary state of the processor before it is done - which hopefully you don't care about.\n- I would also add that if you go with option one and you are receiving events from RMQ in passive mode and you use an event loop like in NodeJS you need to use a single channel with a prefetch of 1 because otherwise you may end up with multiple messages in parallel which may be processed at different speeds.\n- One way to solve this is to have a order number with message, and consumer(s) keep track of messages and their order in DB. If consumer A haven't finished processing of message-order-1 for entity-record-id-100, consumer B shouldn't start processing the message-order-2 for entity-record-id-100. Consumer B should wait and retry in a loop with wait.","metadata":{"transformedAt":"2026-08-18T18:33:20.115Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":99,"estimatedTokens":1817}}47{"id":"stack-23158310","source":"stackoverflow","questionId":23158310,"title":"How do I set a number of retry attempts in RabbitMQ?","tags":[".net","queue","rabbitmq","consumer"],"text":"Title: How do I set a number of retry attempts in RabbitMQ?\nTags: .net, queue, rabbitmq, consumer\nSource: Stack Overflow\n\nQuestion:\nI am using RabbitMQ and I have a queue that holds email messages. My consumer service de-queues messages and attempts to send them. If, for any reason, my consumer cannot send the message, I would like to re-queue the message to send again.\n\nI realize I can do a basicNack and set the requeue flag to be true, however, I don't want to requeue the message indefinitely (say, if our email system goes down, I don't want to continuously requeue unsent messages). I would like to define a finite number of times that I can requeue the message to be sent again.\n\nI can't set a field on the email message object, however, when I dequeue it and send a nack. The updated field is not present on the message in the queue.\n\nIs there any other way in which I can approach this?\n\n========================================\n\nTop Answer:\nAlthough this is an old question I think you can now easily do this with the combination of dead letter exchanges and the x-death header array added once a message is dead lettered:\n\nThe dead-lettering process adds an array to the header of each dead-lettered message named x-death. This array contains an entry for each dead lettering event, identified by a pair of {queue, reason}. Each such entry is a table that consists of several fields:\n\nqueue: the name of the queue the message was in before it was\ndead-lettered\n\nreason: reason for dead lettering, see below\n\ntime: the date and time the message was dead lettered as a 64-bit AMQP 0-9-1 timestamp\n\nexchange - the exchange the message was published to (note that this will be a dead letter exchange if the message is dead lettered\nmultiple times)\n\nrouting-keys: the routing keys (including CC keys but excluding BCC ones) the message was published with\n\ncount: how many times this message was dead-lettered in this queue for this reason\n\noriginal-expiration (if the message was dead-letterered due to per-message TTL): the original expiration property of the message. The\nexpiration property is removed from the message on dead-lettering in\norder to prevent it from expiring again in any queues it is routed to.\n\nRead this great article for more info\n\nCheck this diagram:\n\nhttps://i.sstatic.net/kpS6X.png\n\n========================================\n\nCode:\n```text\nredelivered\n```\n\n```text\nbasic.deliver\n```\n\n```text\nx-redelivered-count\n```\n\n```text\nttl\n```\n\n```text\nx-queue-type: quorum\nx-delivery-limit: 3 // it means rabbitmq will make 3 attempts to deliver a message before deleting it\n```\n\n```text\nnack\n```\n\n```text\npublish\n```\n\n```text\nx-delay\n```\n\n========================================\n\nComments:\n- This blog post does a pretty good job explaining why you'd want to use a framework like NServiceBus or MassTransit on top of RabbitMQ in .net to solve these kinds of problems: make-awesome.com/2017/12/sure-you-can-just-use-rabbitmq\n- @UdiDahan is there an equivalent to MassTransit/NServiceBus in the Java world?\n- @Datz I think the closest thing would be Apache Caml.\n- @Datz - if still relevant, for JAVA see: github.com/spring-cloud/spring-cloud-stream-binder-rabbit\n- Thanks very much. I think I will go the dead letter exchange route.\n- Also, if you don't mind time limiting the message life time rather that limiting the number of retries, you could always set a TTL.\n- Writing a plugin does not seem possible at the moment. There is no behaviour in rabbit that lets you hook into message consumption and modify the message. You can only modify the message header during publishing using the rabbit_channel_interceptor, but this does not help here.\n- Maybe I'm misreading this, but should the branch labelled \"Fail (above max retries)\" not be labelled as \"ack\"? The article seems to imply this with its example under \"Option 2: Reject + DLX topology\", which I think this is referring to. If you were to perform a nack when you are above the max count, this would just send all messages to the DLX forever, no?\n- @ollien `nack` can be used to requeue the message or discard (dead-letter if there's one) it, there is a third parameter `requeue` that controls this behavior rabbitmq.com/amqp-0-9-1-reference.html#basic.nack . I would prefer here to use `nack` over `ack`, since it's semantically more relevant as it means the consumption failed and the message is not processed correctly.\n- Yes, but when you NACK it, it will go to the DLX, no? In other words, it will never break out of the retry loop if you NACK after the retry count is reached.\n- +1 for simplicity, but the downside for large applications would be higher RAM usage while messages sit in the consumer's RAM waiting to be retried (or lower throughput if you cap the number of concurrent messages being processed to prevent excess RAM usage). probably works best if you intend to have shorter retry delays and fewer total attempts.","metadata":{"transformedAt":"2026-08-18T18:33:20.115Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":94,"estimatedTokens":1230}}48{"id":"stack-30747469","source":"stackoverflow","questionId":30747469,"title":"How to add initial users when starting a RabbitMQ Docker container?","tags":["docker","rabbitmq"],"text":"Title: How to add initial users when starting a RabbitMQ Docker container?\nTags: docker, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nCurrently i am starting RabbitMQ Docker container using the default RabbitMQ image from DockerHub. Using the following commands.\n\n```\ndocker run --restart=always \\\n-d \\\n-e RABBITMQ_NODENAME=rabbitmq \\\n-v /opt/docker/rabbitmq/data:/var/lib/rabbitmq/mnesia/rabbitmq \\\n-p 5672:5672 \\\n-p 15672:15672 \\\n--name rabbitmq rabbitmq:3-management\n```\n\nI have a need where i want to provide defaults users / and virtual-hosts when the image is first started. For example to create a default 'test-user'.\n\nCurrently i have to do that manually by using the management plugin and adding the users / virtual-hosts via the web ui. Is there a way i can provide default settings when starting the RabbitMQ image?\n\n========================================\n\nTop Answer:\nCame up with a solution that suits my needs, leaving it here in case anybody else needs it.\n\n### Summary\n\nThe idea is to take a standard rabbitmq container with management plugin enabled and use it to create the required configuration, then export and use it to start new containers. The below solution creates a derived docker image but it also works to just mount the two files at runtime (e.g. using docker compose).\n\n### References\n\n- the info I started from\n\n- complete rabbitmq.config example\n\n### Components\n\nofficial rabbitmq image, management plugin version (*rabbitmq:management*)\n\ncustom image based on the original one, with this Dockerfile (using version 3.6.6):\n\n```\nFROM rabbitmq:3.6.6-management\n ADD rabbitmq.config /etc/rabbitmq/\n ADD definitions.json /etc/rabbitmq/\n RUN chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq.config /etc/rabbitmq/definitions.json\n CMD [\"rabbitmq-server\"]\n```\n\n*rabbitmq.config* just tells rabbitmq to load definitions from the json file\n\n*definitions.json* contains the users, vhosts, etc. and can be generated by the export function of the management web interface\n\n*rabbitmq.config* example:\n\n```\n[\n {rabbit, [\n {loopback_users, []}\n ]},\n {rabbitmq_management, [\n {load_definitions, \"/etc/rabbitmq/definitions.json\"}\n ]}\n].\n```\n\n*definitions.json* example:\n\n```\n{\n \"rabbit_version\": \"3.6.6\",\n \"users\": [\n {\n \"name\": \"user1\",\n \"password_hash\": \"pass1\",\n \"hashing_algorithm\": \"rabbit_password_hashing_sha256\",\n \"tags\": \"\"\n },\n {\n \"name\": \"adminuser\",\n \"password_hash\": \"adminpass\",\n \"hashing_algorithm\": \"rabbit_password_hashing_sha256\",\n \"tags\": \"administrator\"\n }\n ],\n \"vhosts\": [\n {\n \"name\": \"\\/vhost1\"\n },\n {\n \"name\": \"\\/vhost2\"\n }\n ],\n \"permissions\": [\n {\n \"user\": \"user1\",\n \"vhost\": \"\\/vhost1\",\n \"configure\": \".*\",\n \"write\": \".*\",\n \"read\": \".*\"\n }\n ],\n \"parameters\": [],\n \"policies\": [],\n \"queues\": [],\n \"exchanges\": [],\n \"bindings\": []\n}\n```\n\n### Alternave version\n\nDeriving a new docker image is just one solution and works best when portability is key, since it avoids including host-based file management in the picture.\n\nIn some situations using the official image and providing configuration files from storage local to the host might be preferred.\n\nThe rabbitmq.config and definitions.json files are produced the same way, then *mounted* at runtime.\n\nNotes:\n\n- I'm assuming they have been placed in /etc/so/ for the sake of these examples\n\n- files need to either be world readable or owned by the rabbitmq user or group (numerical id inside the docker container is 999), this needs to be handled by the host's sysadmin\n\n*docker run* example:\n\n```\ndocker run --rm -it \\\n -v /etc/so/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro \\\n -v /etc/so/definitions.json:/etc/rabbitmq/definitions.json:ro \\\n rabbitmq:3.6-management\n```\n\n*docker compose* example:\n\n```\nversion: '2.1'\n services:\n rabbitmq:\n image: \"rabbitmq:3.6-management\"\n ports:\n - 5672:5672\n - 15672:15672\n volumes:\n - /etc/so/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro\n - /etc/so/definitions.json:/etc/rabbitmq/definitions.json:ro\n```\n\n========================================\n\nCode:\n```text\ndocker run --restart=always \\\n-d \\\n-e RABBITMQ_NODENAME=rabbitmq \\\n-v /opt/docker/rabbitmq/data:/var/lib/rabbitmq/mnesia/rabbitmq \\\n-p 5672:5672 \\\n-p 15672:15672 \\\n--name rabbitmq rabbitmq:3-management\n```\n\n```text\nFROM rabbitmq\n\n# Define environment variables.\nENV RABBITMQ_USER user\nENV RABBITMQ_PASSWORD user\nENV RABBITMQ_PID_FILE /var/lib/rabbitmq/mnesia/rabbitmq\n\nADD init.sh /init.sh\nRUN chmod +x /init.sh\nEXPOSE 15672\n\n# Define default command\nCMD [\"/init.sh\"]\n```\n\n```text\n#!/bin/sh\n\n# Ensure the nodename doesn't change, e.g. if docker restarts.\n# Important because rabbitmq stores data per node name (or 'IP')\necho 'NODENAME=rabbit@localhost' > /etc/rabbitmq/rabbitmq-env.conf\n\n# Create Rabbitmq user\n(rabbitmqctl wait --timeout 60 $RABBITMQ_PID_FILE ; \\\nrabbitmqctl add_user $RABBITMQ_USER $RABBITMQ_PASSWORD 2>/dev/null ; \\\nrabbitmqctl set_user_tags $RABBITMQ_USER administrator ; \\\nrabbitmqctl set_permissions -p / $RABBITMQ_USER \".*\" \".*\" \".*\" ; \\\necho \"*** User '$RABBITMQ_USER' with password '$RABBITMQ_PASSWORD' completed. ***\" ; \\\necho \"*** Log in the WebUI at port 15672 (example: http:/localhost:15672) ***\") &\n\n# $@ is used to pass arguments to the rabbitmq-server command.\n# For example if you use it like this: docker run -d rabbitmq arg1 arg2,\n# it will be as you run in the container rabbitmq-server arg1 arg2\nrabbitmq-server $@\n```\n\n```text\nRUN useradd -d /home/gg -m -s /bin/bash gg\nRUN echo gg:gg | chpasswd\nRUN echo 'gg ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/gg\nRUN chmod 0440 /etc/sudoers.d/gg\n```\n\n```text\nFROM rabbitmq:3.6.6-management\n ADD rabbitmq.config /etc/rabbitmq/\n ADD definitions.json /etc/rabbitmq/\n RUN chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq.config /etc/rabbitmq/definitions.json\n CMD [\"rabbitmq-server\"]\n```\n\n```text\n[\n {rabbit, [\n {loopback_users, []}\n ]},\n {rabbitmq_management, [\n {load_definitions, \"/etc/rabbitmq/definitions.json\"}\n ]}\n].\n```\n\n```text\n{\n \"rabbit_version\": \"3.6.6\",\n \"users\": [\n {\n \"name\": \"user1\",\n \"password_hash\": \"pass1\",\n \"hashing_algorithm\": \"rabbit_password_hashing_sha256\",\n \"tags\": \"\"\n },\n {\n \"name\": \"adminuser\",\n \"password_hash\": \"adminpass\",\n \"hashing_algorithm\": \"rabbit_password_hashing_sha256\",\n \"tags\": \"administrator\"\n }\n ],\n \"vhosts\": [\n {\n \"name\": \"\\/vhost1\"\n },\n {\n \"name\": \"\\/vhost2\"\n }\n ],\n \"permissions\": [\n {\n \"user\": \"user1\",\n \"vhost\": \"\\/vhost1\",\n \"configure\": \".*\",\n \"write\": \".*\",\n \"read\": \".*\"\n }\n ],\n \"parameters\": [],\n \"policies\": [],\n \"queues\": [],\n \"exchanges\": [],\n \"bindings\": []\n}\n```\n\n```text\ndocker run --rm -it \\\n -v /etc/so/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro \\\n -v /etc/so/definitions.json:/etc/rabbitmq/definitions.json:ro \\\n rabbitmq:3.6-management\n```\n\n```text\nversion: '2.1'\n services:\n rabbitmq:\n image: \"rabbitmq:3.6-management\"\n ports:\n - 5672:5672\n - 15672:15672\n volumes:\n - /etc/so/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro\n - /etc/so/definitions.json:/etc/rabbitmq/definitions.json:ro\n```\n\n```text\nFROM rabbitmq:3-management-alpine\nADD definitions.json /etc/rabbitmq/\nADD rabbitmq.config /etc/rabbitmq/\nRUN chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq.config /etc/rabbitmq/definitions.json\n\nEXPOSE 4369 5671 5672 15671 15672 25672\n\nCMD [\"rabbitmq-server\"]\n```\n\n```text\n[\n { rabbit, [\n {loopback_users, []},\n { tcp_listeners, [ 5672 ]},\n { ssl_listeners, [ ]},\n { hipe_compile, false } \n ]},\n { rabbitmq_management, [\n { load_definitions, \"/etc/rabbitmq/definitions.json\"},\n { listeners, [\n { port, 15672 },\n { ssl, false } \n\n ]}\n ]}\n].\n```\n\n```text\nrabbitmq.config\n```\n\n```text\nFROM rabbitmq:3-management\nADD init.sh /\nADD config_rabbit.sh /\nRUN chmod +x /init.sh /config_rabbit.sh\nENTRYPOINT [\"/init.sh\"]\n```\n\n```text\n#!/bin/bash\n\n# Launch config script in background\n# Note there is no RabbitMQ Docker image support for executing commands after server (PID 1) is running (something like \"ADD schema.sql /docker-entrypoint-initdb.d\" in MySql image), so we are using this trick\n/config_rabbit.sh &\n\n# Launch\n/docker-entrypoint.sh rabbitmq-server\n```\n\n```text\n#!/bin/bash\n\n# This script needs to be executed just once\nif [ -f /$0.completed ] ; then\n echo \"$0 `date` /$0.completed found, skipping run\"\n exit 0\nfi\n\n# Wait for RabbitMQ startup\nfor (( ; ; )) ; do\n sleep 5\n rabbitmqctl -q node_health_check > /dev/null 2>&1\n if [ $? -eq 0 ] ; then\n echo \"$0 `date` rabbitmq is now running\"\n break\n else\n echo \"$0 `date` waiting for rabbitmq startup\"\n fi\ndone\n\n# Execute RabbitMQ config commands here\n\n# Create user\nrabbitmqctl add_user USER PASSWORD\nrabbitmqctl set_permissions -p / USER \".*\" \".*\" \".*\"\necho \"$0 `date` user USER created\"\n\n# Create queue\nrabbitmqadmin declare queue name=QUEUE durable=true\necho \"$0 `date` queues created\"\n\n# Create mark so script is not ran again\ntouch /$0.completed\n```\n\n```text\nsleep 5\n```\n\n```text\ndocker run \\\n-e RABBITMQ_DEFAULT_USER=test-user \\\n-e RABBITMQ_DEFAULT_PASS=test-user \\\n-p 5672:5672 \\\nrabbitmq\n```\n\n```text\nFROM rabbitmq\n\n# Define environment variables.\nENV RABBITMQ_USER user\nENV RABBITMQ_PASSWORD user\n\nADD init.sh /init.sh\nEXPOSE 15672\n\n# Define default command\nCMD [\"/init.sh\"]\n```\n\n```text\n#!/bin/sh\n( sleep 10 && \\\nrabbitmqctl add_user $RABBITMQ_USER $RABBITMQ_PASSWORD && \\\nrabbitmqctl set_user_tags $RABBITMQ_USER administrator && \\\nrabbitmqctl set_permissions -p / $RABBITMQ_USER \".*\" \".*\" \".*\" ) & \\\nrabbitmq-server\n```\n\n```text\nRUN rabbitmqctl add_user {username} {password}\nRUN rabbitmqctl set_user_tags {username} administrator\nRUN rabbitmqctl set_permissions ...\n```\n\n```text\n# Default user\ndefault_user = testuser\ndefault_pass = testpassword\n\n## The default \"guest\" user is only permitted to access the server\n## via a loopback interface (e.g. localhost).\nloopback_users.guest = true\n\n# IPv4\nlisteners.tcp.default = 5672\n\n## HTTP listener and embedded Web server settings.\nmanagement.tcp.port = 15672\n\n# Load queue definitions\nmanagement.load_definitions = /etc/rabbitmq/definitions.json\n\n#Ignore SSL\nssl_options.verify = verify_peer\nssl_options.fail_if_no_peer_cert = true\n```\n\n```text\n{\n \"rabbit_version\": \"3.7.11\",\n \"users\": [\n {\n \"name\": \"testuser\",\n \"password_hash\": \"txn+nsYVkAaIMvDsH8Fsyb3RWMCMWihRUVCk/wICL1NBKKvz\",\n \"hashing_algorithm\": \"rabbit_password_hashing_sha256\",\n \"tags\": \"administrator\"\n }\n ],\n \"vhosts\": [ { \"name\": \"test-vhost\" } ],\n \"permissions\": [\n {\n \"user\": \"testuser\",\n \"vhost\": \"test-vhost\",\n \"configure\": \".*\",\n \"write\": \".*\",\n \"read\": \".*\"\n }\n ],\n \"topic_permissions\": [],\n \"parameters\": [],\n \"global_parameters\": [\n {\n \"name\": \"cluster_name\",\n \"value\": \"rabbit@test-rabbit\"\n }\n ],\n \"policies\": [],\n \"queues\": [\n {\n \"name\": \"testqueue\",\n \"vhost\": \"test-vhost\",\n \"durable\": true,\n \"auto_delete\": false,\n \"arguments\": {}\n }\n ],\n \"exchanges\": [],\n \"bindings\": []\n}\n```\n\n```text\nFROM rabbitmq:3.7-management\n\nCOPY rabbitmq.conf /etc/rabbitmq\nCOPY definitions.json /etc/rabbitmq\n\nRUN ls /etc/rabbitmq\nRUN cat /etc/rabbitmq/rabbitmq.conf\n```\n\n```text\ndocker build -t rabbitmq-with-queue .\ndocker run --rm -it --hostname my-rabbit -p 5672:5672 -p 15672:15672 rabbitmq-with-queue\n```\n\n```text\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: rabbitmq-deployment\nspec:\n selector:\n matchLabels:\n app: rabbitmq-deployment\n replicas: 1\n template:\n metadata:\n labels:\n app: rabbitmq-deployment\n spec:\n volumes:\n - name: rabbitmq-definitions\n configMap:\n name: rabbitmq-definitions-configmap\n containers:\n - name: rabbitmq\n image: rabbitmq:3.7.18-management-alpine\n imagePullPolicy: IfNotPresent\n envFrom:\n - configMapRef:\n name: rabbitmq-configmap\n - secretRef:\n name: rabbitmq-secrets\n volumeMounts:\n - name: rabbitmq-definitions\n mountPath: /etc/rabbitmq/definitions.json\n subPath: rabbitmq-definitions\n```\n\n```text\nrabbitmq-definitions-configmap\n```\n\n```text\nrabbitmq.config\n```\n\n```text\nmountPath\n```\n\n```text\nsubPath\n```\n\n```text\nmountPath\n```\n\n```text\n{\n \"users\": [\n {\n \"name\": \"guest\",\n \"password_hash\": \"R184F4Fs6JLdo8tFqRjWnkJL2DlAZJupxEqkO/8kfV/G63+z\",\n \"hashing_algorithm\": \"rabbit_password_hashing_sha256\",\n \"tags\": \"administrator\"\n },\n {\n \"name\": \"admin\",\n \"password_hash\": \"FGA5ZeTOLHnIp4ZjxIj0PsShW/DpLgdYAlHsbli7KMMa8Z0O\",\n \"hashing_algorithm\": \"rabbit_password_hashing_sha256\",\n \"tags\": \"administrator\"\n }\n ],\n \"vhosts\": [\n {\n \"name\": \"/\"\n }\n ],\n \"permissions\": [\n {\n \"user\": \"guest\",\n \"vhost\": \"/\",\n \"configure\": \".*\",\n \"write\": \".*\",\n \"read\": \".*\"\n },\n {\n \"user\": \"admin\",\n \"vhost\": \"/\",\n \"configure\": \".*\",\n \"write\": \".*\",\n \"read\": \".*\"\n }\n ],\n \"parameters\": [],\n \"policies\": [],\n \"queues\": [],\n \"exchanges\": [],\n \"bindings\": []\n}\n```\n\n```text\nFROM rabbitmq:3.8.3-management\n\nADD --chown=rabbitmq ./definitions.json /etc/rabbitmq/\n\nENV RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS=\"-rabbitmq_management load_definitions \\\"/etc/rabbitmq/definitions.json\\\"\"\n```\n\n```text\ndocker-entrypoint.sh\n```\n\n```text\nadmin\n```\n\n```text\nadmin\n```\n\n```text\nguest\n```\n\n```text\ndefinitions.json\n```\n\n```text\ndefinitions.json\n```\n\n```text\nRABBITMQ_SERVER_ADDITIONAL_ERL_ARGS\n```\n\n```text\nrabbitmq.conf\n```\n\n```text\ndefinitions.json\n```\n\n```text\nDockerfile\n```\n\n```text\ndocker build --tag myrabbit:1.0.0 .\n```\n\n```text\ndocker run -d -p 5672:5672 -p 15672:15672 --restart unless-stopped --name rabbitmq myrabbit:1.0.0\n```\n\n```text\nroot@268bac197c69:~/mnesia# ls -alh /var/lib/rabbitmq/mnesia\ntotal 100K\ndrwxr-xr-x. 14 rabbitmq rabbitmq 4.0K Jun 13 13:43 .\ndrwxr-xr-x. 5 rabbitmq root 4.0K Jun 13 13:42 ..\ndrwxr-xr-x. 4 rabbitmq rabbitmq 4.0K Mar 6 2020 rabbit@0df72ae1a7a5\n-rw-r--r--. 1 rabbitmq rabbitmq 64 Mar 6 2020 rabbit@0df72ae1a7a5-feature_flags\ndrwxr-xr-x. 2 rabbitmq rabbitmq 4.0K Mar 6 2020 rabbit@0df72ae1a7a5-plugins-expand\n-rw-r--r--. 1 rabbitmq rabbitmq 2 Mar 6 2020 rabbit@0df72ae1a7a5.pid\ndrwxr-xr-x. 4 rabbitmq rabbitmq 4.0K Jun 13 13:43 rabbit@268bac197c69\n-rw-r--r--. 1 rabbitmq rabbitmq 148 Jun 13 13:43 rabbit@268bac197c69-feature_flags\ndrwxr-xr-x. 10 rabbitmq rabbitmq 4.0K Jun 13 13:43 rabbit@268bac197c69-plugins-expand\n-rw-r--r--. 1 rabbitmq rabbitmq 3 Jun 13 13:43 rabbit@268bac197c69.pid\n```\n\n```text\nrabbitmqctl eval 'rabbit_mnesia:dir().'\n```\n\n```text\nrabbitmq:\n image: rabbitmq:management\n container_name: rabbitmq\n restart: always\n hostname: 0df72ae1a7a5\n environment:\n RABBITMQ_DEFAULT_USER: rabbit\n RABBITMQ_DEFAULT_PASS: rabbit\n volumes:\n - /var/docker/rabbitmq/var/lib/rabbitmq:/var/lib/rabbitmq\n```\n\n```text\n/var/lib/rabbitmq\n```\n\n```text\n0df72ae1a7a5\n```\n\n```text\n268bac197c69\n```\n\n```text\n\"/var/lib/rabbitmq/mnesia/rabbit@268bac197c69\"\n```\n\n```text\nhostname\n```\n\n```text\nFROM rabbitmq:3.8.2-management\nADD definitions.json /etc/rabbitmq/\nRUN chown rabbitmq:rabbitmq /etc/rabbitmq/definitions.json\n```\n\n```text\n{\n\"users\": [\n {\n \"name\": \"guest\",\n \"password_hash\": \"R184F4Fs6JLdo8tFqRjWnkJL2DlAZJupxEqkO/8kfV/G63+z\",\n \"hashing_algorithm\": \"rabbit_password_hashing_sha256\",\n \"tags\": \"administrator\"\n },\n {\n \"name\": \"admin\",\n \"password_hash\": \"FGA5ZeTOLHnIp4ZjxIj0PsShW/DpLgdYAlHsbli7KMMa8Z0O\",\n \"hashing_algorithm\": \"rabbit_password_hashing_sha256\",\n \"tags\": \"administrator\"\n }\n],\n\"vhosts\": [\n {\n \"name\": \"/\"\n }\n],\n\"permissions\": [\n {\n \"user\": \"guest\",\n \"vhost\": \"/\",\n \"configure\": \".*\",\n \"write\": \".*\",\n \"read\": \".*\"\n },\n {\n \"user\": \"admin\",\n \"vhost\": \"/\",\n \"configure\": \".*\",\n \"write\": \".*\",\n \"read\": \".*\"\n }\n],\n\"parameters\": [],\n\"policies\": [],\n\"queues\": [],\n\"exchanges\": [],\n\"bindings\": []\n}\n```\n\n```text\n# add rabbitmq user with /usr/sbin/rabbitmqctl at boot time.\nRUN echo \"@reboot root sleep 5 && rabbitmqctl add_user admin admin && rabbitmqctl set_user_tags admin administrator && rabbitmqctl set_permissions -p / admin \\\".*\\\" \\\".*\\\" \\\".*\\\"\" >> /etc/crontab\n```\n\n```text\nFROM rockylinux/rockylinux:latest\nLABEL maintainer=\"acool@example.com\"\n\n# remove unecessary systemd unit files\nENV container docker\nRUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \\\nsystemd-tmpfiles-setup.service ] || rm -f $i; done); \\\nrm -f /lib/systemd/system/multi-user.target.wants/*;\\\nrm -f /etc/systemd/system/*.wants/*;\\\nrm -f /lib/systemd/system/local-fs.target.wants/*; \\\nrm -f /lib/systemd/system/sockets.target.wants/*udev*; \\\nrm -f /lib/systemd/system/sockets.target.wants/*initctl*; \\\nrm -f /lib/systemd/system/basic.target.wants/*;\\\nrm -f /lib/systemd/system/anaconda.target.wants/*;\n\n# import rabbitmq repo signatures\nRUN rpm --import https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc && \\\nrpm --import 'https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/gpg.E495BB49CC4BBE5B.key' && \\\nrpm --import 'https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-server/gpg.9F4587F226208342.key'\n\n# copy rabbitmq repo config\nCOPY config/rabbitmq.repo /etc/yum.repos.d/rabbitmq.repo\n\n# install packages\nRUN dnf -y update \\\n&& dnf -y install epel-release.noarch \\\nhttp://rpms.remirepo.net/enterprise/remi-release-8.rpm \\\n&& dnf module -y install php:remi-8.0 \\\n&& dnf -y install rabbitmq-server \\\nsupervisor \\\nmemcached \\\niproute \\\n# postfix \\\nmailx \\\nvim \\\nnano \\\ndos2unix \\\nwget \\\nopenssh \\\nrsync \\\nunzip \\\nImageMagick \\\nncurses \\\ncronie \\\n&& dnf clean all\n\n# create admin user account\nARG UID=1000\nRUN useradd --create-home --uid $UID admin\n\n# enable services\nRUN systemctl enable rabbitmq-server.service memcached.service \\\n&& rabbitmq-plugins enable rabbitmq_management\n\n# add rabbitmq user with /usr/sbin/rabbitmqctl at boot time.\nRUN echo \"@reboot root sleep 5 && rabbitmqctl add_user admin admin && rabbitmqctl set_user_tags admin administrator && rabbitmqctl set_permissions -p / admin \\\".*\\\" \\\".*\\\" \\\".*\\\"\" >> /etc/crontab\n\nEXPOSE 15672 9001\nENTRYPOINT [\"/sbin/init\"]\n```\n\n```text\ndocker build --build-arg UID=$(id -u) -t customRockyLinux:customRockyLinux .\n```\n\n```text\ndocker run --name customRL_container -d --privileged -p 15672:15672 -p 9001:9001 customRockyLinux:customRockyLinux\n```\n\n```text\ndocker exec -it customRL_container bash\n```\n\n```text\ndocker exec -it --user admin customRL_container bash\n```\n\n```text\nroot@a2dc7498de45 /]# rabbitmqctl list_users\nuser tags\nadmin [administrator]\nguest [administrator]\n[root@a2dc7498de45 /]#\n[root@a2dc7498de45 /]#\n[root@a2dc7498de45 /]# rabbitmqctl --version\n3.9.5\n[root@a2dc7498de45 /]# cat /etc/redhat-release \nRocky Linux release 8.4 (Green Obsidian)\n```\n\n```text\n[rabbitmq_management,rabbitmq_prometheus].\n```\n\n```text\nauth_mechanisms.1 = PLAIN\n auth_mechanisms.2 = AMQPLAIN\n loopback_users.guest = false\n listeners.tcp.default = 5672\n #default_pass = admin\n #default_user = admin\n hipe_compile = false\n #management.listener.port = 15672\n #management.listener.ssl = false\n management.tcp.port = 15672\n management.load_definitions = /etc/rabbitmq/definitions.json\n```\n\n```text\n{\n \"users\": [\n {\n \"name\": \"admin\",\n \"password\": \"admin\",\n \"tags\": \"administrator\"\n }\n ],\n \"vhosts\": [\n {\n \"name\": \"/\"\n }\n ],\n \"policies\": [\n {\n \"vhost\": \"/\",\n \"name\": \"ha\",\n \"pattern\": \"\",\n \"apply-to\": \"all\",\n \"definition\": {\n \"ha-mode\": \"all\",\n \"ha-sync-batch-size\": 256,\n \"ha-sync-mode\": \"automatic\"\n },\n \"priority\": 0\n }\n ],\n \"permissions\": [\n {\n \"user\": \"admin\",\n \"vhost\": \"/\",\n \"configure\": \".*\",\n \"write\": \".*\",\n \"read\": \".*\"\n }\n ],\n \"queues\": [\n {\n \"name\": \"job-import.triggered.queue\",\n \"vhost\": \"/\",\n \"durable\": true,\n \"auto_delete\": false,\n \"arguments\": {}\n }\n ],\n \"exchanges\": [\n {\n \"name\": \"lob-proj-dx\",\n \"vhost\": \"/\",\n \"type\": \"direct\",\n \"durable\": true,\n \"auto_delete\": false,\n \"internal\": false,\n \"arguments\": {}\n }\n ],\n \"bindings\": [\n {\n \"source\": \"lob-proj-dx\",\n \"vhost\": \"/\",\n \"destination\": \"job-import.triggered.queue\",\n \"destination_type\": \"queue\",\n \"routing_key\": \"job-import.event.triggered\",\n \"arguments\": {}\n }\n ]\n }\n```\n\n```text\ndocker run --restart=always -d -p 5672:5672 -p 15672:15672 --mount type=bind,source=E:\\docker\\rabbit\\data,target=/var/lib/rabbitmq/ --mount type=bind,source=E:\\docker\\rabbit\\etc,target=/etc/rabbitmq/ --name rabbitmq --hostname my-rabbit rabbitmq:3.7.28-management\n```\n\n```text\n$ docker run -d --hostname my-rabbit --name some-rabbit -e\nRABBITMQ_DEFAULT_USER=user -e RABBITMQ_DEFAULT_PASS=password\nrabbitmq:3-management\n```\n\n```text\n$ docker run -d --hostname my-rabbit --name some-rabbit -e\nRABBITMQ_DEFAULT_VHOST=my_vhost rabbitmq:3-management\n```\n\n```text\ndefinitions.json\n```\n\n```text\nload_definitions\n```\n\n```yaml\nversion: \"3.7\"\n\nnetworks:\n default:\n driver: bridge\n\nservices:\n broker-service-rabbitmq:\n image: rabbitmq:3.12.4-management-alpine\n container_name: broker-test_rabbitmq-server\n restart: unless-stopped\n volumes:\n - ${PWD}/dev-resources/volumes/rabbitmq/advanced.config:/etc/rabbitmq/advanced.config:ro\n - ${PWD}/dev-resources/volumes/rabbitmq/definitions.json:/etc/rabbitmq/definitions.json:ro\n ports:\n - \"${BROKER_UI_PORT:-8083}:15672\"\n networks:\n - default\n healthcheck:\n test: [ \"CMD\", \"rabbitmqctl\", \"node_health_check\" ]\n interval: 15s\n timeout: 5s\n retries: 5\n start_period: 30s\n```\n\n```erlang\n[\n {rabbit, [\n {loopback_users, []}\n ]},\n {rabbitmq_management, [\n {load_definitions, \"/etc/rabbitmq/definitions.json\"}\n ]}\n].\n```\n\n```json\n{\n \"rabbit_version\": \"3.12.4\",\n \"rabbitmq_version\": \"3.12.4\",\n \"product_name\": \"RabbitMQ\",\n \"product_version\": \"3.12.4\",\n \"users\": [\n {\n \"name\": \"admin\",\n \"password_hash\": \"FT36tPaTkj3IXlMTg6MhTrz86evp4hdt2p60IxaJnmRWy7Ry\",\n \"hashing_algorithm\": \"rabbit_password_hashing_sha256\",\n \"tags\": [\n \"administrator\"\n ],\n \"limits\": {}\n },\n {\n \"name\": \"service-test\",\n \"password_hash\": \"36VESrI5GlnMSum5o6ytxm58GbCd05zlJmcdTNIVehmrX2Cs\",\n \"hashing_algorithm\": \"rabbit_password_hashing_sha256\",\n \"tags\": [\n \"None\"\n ],\n \"limits\": {}\n }\n ],\n \"vhosts\": [\n {\n \"name\": \"service-test\"\n },\n {\n \"name\": \"/\"\n }\n ],\n \"permissions\": [\n {\n \"user\": \"admin\",\n \"vhost\": \"service-test\",\n \"configure\": \".*\",\n \"write\": \".*\",\n \"read\": \".*\"\n },\n {\n \"user\": \"service-test\",\n \"vhost\": \"service-test\",\n \"configure\": \".*\",\n \"write\": \".*\",\n \"read\": \".*\"\n },\n {\n \"user\": \"admin\",\n \"vhost\": \"/\",\n \"configure\": \".*\",\n \"write\": \".*\",\n \"read\": \".*\"\n }\n ],\n \"topic_permissions\": [],\n \"parameters\": [],\n \"global_parameters\": [\n {\n \"name\": \"cluster_name\",\n \"value\": \"rabbitmq-dev-service\"\n },\n {\n \"name\": \"internal_cluster_id\",\n \"value\": \"rabbitmq-cluster-id-oIZB0WpqtbIh5aYiNw_PDw\"\n }\n ],\n \"policies\": [],\n \"exchanges\": [],\n \"bindings\": []\n}\n```\n\n```text\nrabbitmq:3.12.4-management-alpine\n```\n\n```text\nrabbitmq.config\n```\n\n```text\nrabbitmq.conf\n```\n\n```text\nadvanced.config\n```\n\n```text\ndefinitions.json\n```\n\n```text\nRUN chown rabbitmq:rabbitmq /etc/rabbitmq/definitions.json\n```\n\n```text\nFROM rabbitmq:management\n\nADD ./definitions.json /etc/rabbitmq/\n\nENV RABBITMQ_DEFAULT_USER=admin\n\nENV RABBITMQ_DEFAULT_PASS=admin\n\nENV RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS=\"-rabbitmq_management load_definitions \\\"/etc/rabbitmq/definitions.json\\\"\"\n\nEXPOSE 15672 5672 15692\n\nRUN rabbitmq-plugins enable rabbitmq_prometheus\n```\n\n```text\nservices:\n rabbitmq:\n build: ./rabbitmq\n hostname: 'myrabbit'\n ports:\n - '5672:5672'\n - '15672:15672'\n - '15692:15692'\n container_name: rabbitmq\n volumes:\n - rabbit-data:/var/lib/rabbitmq\n```\n\n```text\ndefinitons.json\n```\n\n```text\nRABBITMQ_DEFAULT_USER\n```\n\n```text\nRABBITMQ_DEFAULT_PASS\n```\n\n```text\ndefinitions.json\n```\n\n```text\nRABBITMQ_SERVER_ADDITIONAL_ERL_ARGS\n```\n\n```text\ndefinitions.json\n```\n\n```text\nversion: \"3.8\"\n\nservices:\n rabbitmq:\n image: rabbitmq:3.13.2-management\n container_name: 'rabbitmq'\n ports:\n - 5672:5672\n - 15672:15672\n volumes:\n - /_data/rabbitmq/data:/var/lib/rabbitmq/\n - /_data/rabbitmq/log:/var/log/rabbitmq/\n - ./rabbitmq/definitions.json:/etc/rabbitmq/definitions.json\n - ./rabbitmq/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf\n```\n\n```text\n{\n \"rabbit_version\": \"3.13\",\n \"users\": [\n {\n \"name\": \"admin\",\n \"password_hash\": \"<<Your hash>>\",\n \"hashing_algorithm\": \"rabbit_password_hashing_sha256\",\n \"tags\": \"administrator\"\n }\n ],\n \"vhosts\": [\n {\n \"name\": \"\\/\"\n }\n ],\n \"permissions\": [\n {\n \"user\": \"admin\",\n \"vhost\": \"\\/\",\n \"configure\": \".*\",\n \"write\": \".*\",\n \"read\": \".*\"\n }\n ],\n \"parameters\": [],\n \"policies\": [],\n \"queues\": [],\n \"exchanges\": [],\n \"bindings\": []\n }\n```\n\n```text\nloopback_users.guest = false\nmanagement.load_definitions = /etc/rabbitmq/definitions.json\n```\n\n========================================\n\nComments:\n- Thanks for your suggestion, but somehow the users do not get persisted.\n- Got it working, but i have maybe a stupid question.. what does the $@ at the rabbitmq-server do?\n- $@ is used to pass arguments to the `rabbitmq-server` command. For example if you use it like this: `docker run -d rabbitmq [arg1] [arg2]`, it will be as you run in the container `rabbitmq-server [arg1] [arg2]`.\n- `cd /tmp ; \\ wget http://localhost:15672/cli/rabbitmqadmin ; \\ mv ./rabbitmqadmin /rabbitmqadmin ; \\ chmod +x /rabbitmqadmin ; \\` I think these lines can be removed, as the admin command is already available inside the container.\n- @JorisMans: and wget is not available in the base rabbitmq image\n- @JanuszSkonieczny Maybe something wrong with your line endings? I just tried the instructions again and it worked.\n- @Marco, thx line ending where wrong. But I'm not sure why passing env `RABBITMQ_DEFAULT_USER` and `RABBITMQ_DEFAULT_PASS` settings don'g have any effect. You end up with `guest` admin user with `guest` password, which is not desirable ;)\n- @JanuszSkonieczny The post was just an example on how stuff could be done. You can pull the RABBITMQ_DEFAULT_USER etc into the init.sh and create the correct user\n- @JorisMans: Thanks, great suggestion, I edited the answer and removed the rabbitmqadmin installation.\n- I get this error: /usr/local/bin/docker-entrypoint.sh: line 296: /init.sh: Permission denied. Did I miss something?\n- Does this actually work? On 3.6.6 I can't add any users without first having the node/application running. It looks like you are adding them before running `rabbitmq-server`.\n- Add `RUN [\"chmod\", \"+x\", \"/init.sh\"]`, otherwise it doesn't work.\n- @MihailPetkov You should be setting the `init.sh` file to executable before `COPY`ing the shell script and building the image. That'll eliminate the need for this step, as file attributes are preserved by default.\n- for anyone trying to use this approach with docker-compose. I had to replace `;` with `&&` inside of the `init.sh` file and this will work like a charm.\n- I tried and the user is not created. I set `sleep 10` in init.sh file and user was created...\n- You will need to account for rabbitmq startup time. It's running all user commands in the background. The reason this works is because of the `sleep 5` statement. It's basically saying do these commands in the background, while starting rabbitmq. @Derek If you have a cluster with a lot of established queues/exchanges you will need to make `sleep 5` a lot longer, OR write some type of loop that waits for rabbit to come back to life first. @MihailPetkov your suggestion can't work because of how Docker treats CMD\n- About the `sleep 5`, If you want a more reliable way to wait for rabbitmq to be initalized, I would suggest to use this instead : `rabbitmqctl wait /var/lib/rabbitmq/mnesia/rabbitmq.pid`. I'm using a docker-compose running a lot of containers and it worked for me.\n- Using `rabbitmqctl wait /var/lib/rabbitmq/mnesia/rabbitmq.pid` worked for me as well, but I had to manually set the environment variable `RABBITMQ_PID_FILE` to that location as well or the pid file would be generated with a random name.\n- Thank you all for the valid comments. @user3793803 I incorporated your suggestion, very nice one! I also added a `--timeout 60` param to override the default 10 seconds waiting time to stay on the safe side and wait even if ReabbitMQ takes a little bit longer to load.\n- i have a clarifying question: do we add `rabbitmq-server $@` at the end of the bash script because we override the default start command in the `Dockerfiles` with `CMD [\"/init.sh\"]`?\n- How to deal with output: `/init.sh: line 1: syntax error near unexpected token rabbitmqctl' 'init.sh: line 1: ( rabbitmqctl wait --timeout 60 $RABBITMQ_PID_FILE ; ` ?\n- Is it just me or the init.sh will be executed every time the container is started ? Would try to create users who already exist ?\n- The `rabbitmq-server` should be `exec rabbitmq-server` to allow passing signals such as SIGTERM from the docker container into RabbitMQ.\n- This is a great solution. @Tom.P adds a little to this with the definitions export from Rabbit. Combine the two and that should be the accepted answer. This worked for me!\n- @KentJohnson the fact that \"definitions.json [...] can be generated by the export function of the management web interface\" is already one of my points, that's how I did it too (the provided examples are just to get an idea right away)\n- Added chown command to make sure permissions are ok (thanks @Tom P.) and added an alternate solution that uses the official image + configuration files mounted at runtime\n- I've found this password hashing script which was pretty useful for me also gist.github.com/lukebakken/7b4da46ed9abb7ed14f7a60b49f9e52e\n- Great solution. The main problem is to find documentation for the definitions.json. But you can do manually all the configuration and then export the definiton medium.com/@thomasdecaux/…\n- Since RabbitMQ 3.8.2, it's possible to load definitions at node boot time `load_definitions = /path/to/definitions/file.json` in *rabbitmq.conf* . docs\n- convert `'/etc/rabbitmq/rabbitmq.config'` to the newer sysctl format (`'/etc/rabbitmq/rabbitmq.conf'`); see https://www.rabbitmq.com/configure.html#config-file\n- I think you have enough content to make this an answer. So rather delete all the sentences that prevent this from being an answer (like saying: should be a comment). And that comment-needs-50 rule exists for good reasons.\n- Sorry those reputation roles are a sore point. There's been many times I felt like wanting to contribute something in a comment, an upvote and for everything I would get the 'this requires x reputation' message. Makes it a really high boundary to start contributing. In any case, thanks for the comment, I've made those changes. :)\n- The problem is that a **very high** number of people get accounts here. Too many of them give *zip nada niente* about quality. It only takes 1,2 well received questions to get to \"upvote\", and 1,2 well received answers and you are up to \"comment\".\n- @TomP. That was great recommending the export from Rabbit. That really saved me time! And it is completely accurate. This should be combined with sudo's answer as the accepted answer.\n- I've found this password hashing script which was pretty useful for me also gist.github.com/lukebakken/7b4da46ed9abb7ed14f7a60b49f9e52e\n- Unfortunately it doesn't seem possible to combine this with a definitions file :(\n- At first I thought this wasn't supported because of the comment of 'WARNING' -- but the actual variables the warning is for are NOT these. I added the other ports : `-p 15672:15672 -p 15692:15692` -- but this answer is good for what I was looking for - something *very* simple, easy to pass on to team - thanks! It would have saved me a bit of time if I didn't read that warning comment!\n- Thank you! This is the only one that worked\n- Perfect advice, thanks. I used this idea together with the kubernetes docs on configmap (didn't know about this feature) for increasing the heartbeat of my rabbitmq server by saving a file under /etc/rabbitmq/conf.d/. But I didn't need to use subPath. Thank you so much for your contribution\n- Thanks. This worked for me, the env variable was the key\n- Thanks, I needed to customize the definitions.json path, and the RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS variable was exactly what I needed.\n- Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.\n- This worked fine for me in version 4","metadata":{"transformedAt":"2026-08-18T18:33:20.115Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":89,"totalLines":1256,"estimatedTokens":8516}}49{"id":"stack-23500014","source":"stackoverflow","questionId":23500014,"title":"RabbitMQ started but can't access management interface","tags":["rabbitmq"],"text":"Title: RabbitMQ started but can't access management interface\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have Rabbit MQ started and installed. The service is running as well. However, when I try to open the management interface in Firefox, I get this error:\n\nFirefox can't establish a connection to the server at localhost:#####. (##### being several port numbers i tried).\n\nI checked the ports and made sure that they were correct as well as trying to reinstall RabbitMQ.\n\nAny ideas on how to fix this?\n\n========================================\n\nTop Answer:\nThe problem is because you need to enable the plugins in RabbitMQ, in order to enable that open \"**RabbitMQ Command Prompt (sbin dir)**\" and run the following command\n\n```\nrabbitmq-plugins enable rabbitmq_management\n```\n\nIt will enable all the plugins that is associated with the RabbitMQ.\nNow open the browser and type http://localhost:15672 it will open a RabbitMQ console login with `guest` as username and `guest` as password.\n\n========================================\n\nCode:\n```text\nrabbitmq-plugins enable rabbitmq_management\n```\n\n```text\n15672\n```\n\n```text\nrabbitmq-plugins enable rabbitmq_management\n```\n\n```text\nguest\n```\n\n```text\nguest\n```\n\n```text\nrabbitmq-plugins enable rabbitmq_management\n```\n\n```text\n> docker stop <container-id> \n> docker start <container-id>\n```\n\n```text\nrabbitmq\n```\n\n```text\nc:\\Users\\xxx\\AppData\\Roaming\\RabbitMQ\\db\\\n```\n\n```text\nnet start rabbitmq\n```\n\n```text\nservice rabbitmqctl status\n```\n\n```text\nhttp://localhost:15672/\n```\n\n```text\nhttp://localhost:5672/\n```\n\n```text\nVariable name : PATH\nVariable value: `%ERLANG_HOME%\\bin`\n```\n\n```text\nERLANG_HOME\n```\n\n```text\nC:\\Program Files (x86)\\erl6.4\n```\n\n```text\n%ERLANG_HOME%\\bin\n```\n\n```text\n.\\rabbitmq-plugins enable rabbitmq_management\n```\n\n```text\nVariable name : ERLANG_HOME\nVariable value: C:\\Program Files (x86)\\erl6.4\n\nnote: don't include bin on above step.\n```\n\n```text\nVariable name : PATH\nVariable value: `%ERLANG_HOME%\\bin`\nrestart\n```\n\n```text\nrabbitmq-plugins enable rabbitmq_management\n```\n\n```text\nhttp://localhost:15672/\n```\n\n```text\nc:\\Users\\--USERNAME--\\AppData\\Roaming\\RabbitMQ\\db\\\n```\n\n```text\ndocker pull rabbitmq:management\n```\n\n```text\nmanagement\n```\n\n```text\nhttp://localhost:15672/\n```\n\n```text\nguest\n```\n\n```text\ndocker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3.12.14-management-alpine\n```\n\n```text\ndocker version\n```\n\n```text\ncommand prompt\n```\n\n```text\nmanagement portal\n```\n\n```text\nguest\n```\n\n```text\n.\\rabbitmq-service.bat remove\n.\\rabbitmq-service.bat install\n.\\rabbitmq-service.bat start\n```\n\n```text\nC:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.13.7\\sbin\n```\n\n```text\nenabling the plugin\n```\n\n```text\nhttp://localhost:15672/\n```\n\n```text\n$serverCookiePaths = @(\n \"$env:APPDATA\\RabbitMQ\\.erlang.cookie\",\n \"$env:WINDIR\\system32\\config\\systemprofile\\AppData\\Roaming\\RabbitMQ\\.erlang.cookie\"\n)\n\n$userCookiePath = \"$env:USERPROFILE\\.erlang.cookie\"\n\nforeach ($path in $serverCookiePaths) {\n if (Test-Path $path) {\n Copy-Item $path $userCookiePath -Force\n Write-Host \"content of these files .erlang.cookie synchronized.\"\n break\n }\n}\n```\n\n```text\nrabbitmq-service.bat stop\nrabbitmq-service.bat start\nrabbitmqctl.bat status\nrabbitmq-plugins.bat enable rabbitmq_management\n```\n\n========================================\n\nComments:\n- You have to run the above command from 'sbin' folder in RabbitMQ installtion path (e.g. C:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.7.4\\sbin)\n- yes, it run on `http://localhost:15672/` but In code, I have to specify the port as `5672` not `15672`. any idea why?\n- @roottraveller 5672 is the port of the actual server, 15672 is the port of the web-based management interface tool\n- For anytone with the same issue, you need to open the sbin RabbitMQ Server folder under Program Files on the console. It does not work on the PowerShell\n- cd C:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.8.16\\sbin and then ./rabbitmq-plugins enable rabbitmq_management and than go to localhost:15672\n- Same problem, in my case the solution was restart after apply the command\n- I run the command. Console write success message with plugin enabled. But still cann not access localhost:15672\n- Regular Command line only, power shell does not seem to work. Thanks\n- Worked for me, but before that had to set env variable correctly for erl, see my answer below. Thanks!\n- worked for me. i then restarted the services\n- Thanks, I reinstalled and it started working (Windows 7 Enterprise)\n- Thanks a lot, reinstalling works for me, Windows 10 Pro\n- Before reinstalling, try just restarting your PC.\n- You can also do this by clicking the Play button in the Docker Desktop windows app on the container itself.\n- In chrome stopped working but worked in Edge, crazy","metadata":{"transformedAt":"2026-08-18T18:33:20.115Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":38,"totalLines":223,"estimatedTokens":1210}}50{"id":"stack-14572020","source":"stackoverflow","questionId":14572020,"title":"Handling long running tasks in pika / RabbitMQ","tags":["rabbitmq","pika"],"text":"Title: Handling long running tasks in pika / RabbitMQ\nTags: rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nWe're trying to set up a basic directed queue system where a producer will generate several tasks and one or more consumers will grab a task at a time, process it, and acknowledge the message.\n\nThe problem is, the processing can take 10-20 minutes, and we're not responding to messages at that time, causing the server to disconnect us.\n\nHere's some pseudo code for our consumer:\n\n```\n#!/usr/bin/env python\nimport pika\nimport time\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost'))\nchannel = connection.channel()\n\nchannel.queue_declare(queue='task_queue', durable=True)\nprint ' [*] Waiting for messages. To exit press CTRL+C'\n\ndef callback(ch, method, properties, body):\n long_running_task(connection)\n ch.basic_ack(delivery_tag = method.delivery_tag)\n\nchannel.basic_qos(prefetch_count=1)\nchannel.basic_consume(callback,\n queue='task_queue')\n\nchannel.start_consuming()\n```\n\nAfter the first task completes, an exception is thrown somewhere deep inside of BlockingConnection, complaining that the socket was reset. In addition, the RabbitMQ logs show that the consumer was disconnected for not responding in time (why it resets the connection rather than sending a FIN is strange, but we won't worry about that).\n\nWe searched around a lot because we believed this was the normal use case for RabbitMQ (having a lot of long running tasks that should be split up among many consumers), but it seems like nobody else really had this issue. Finally we stumbled upon a thread where it was recommended to use heartbeats and to spawn the `long_running_task()` in a separate thread.\n\nSo the code has become:\n\n```\n#!/usr/bin/env python\nimport pika\nimport time\nimport threading\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost',\n heartbeat_interval=20))\nchannel = connection.channel()\n\nchannel.queue_declare(queue='task_queue', durable=True)\nprint ' [*] Waiting for messages. To exit press CTRL+C'\n\ndef thread_func(ch, method, body):\n long_running_task(connection)\n ch.basic_ack(delivery_tag = method.delivery_tag)\n\ndef callback(ch, method, properties, body):\n threading.Thread(target=thread_func, args=(ch, method, body)).start()\n\nchannel.basic_qos(prefetch_count=1)\nchannel.basic_consume(callback,\n queue='task_queue')\n\nchannel.start_consuming()\n```\n\nAnd this seems to work, but it's very messy. Are we sure that the `ch` object is thread safe? In addition, imagine that `long_running_task()` is using that connection parameter to add a task to a new queue (i.e. the first part of this long process is done, let's send the task on to the second part). So, the thread is using the `connection` object. Is that thread safe?\n\nMore to the point, what's the preferred way of doing this? I feel like this is very messy and possibly not thread safe, so maybe we're not doing it right. Thanks!\n\n========================================\n\nTop Answer:\nPlease don't disable heartbeats!\n\nAs of Pika `0.12.0`, please use the technique described in this example code to run your long-running task on a separate thread and then acknowledge the message from that thread.\n\n========================================\n\nCode:\n```text\n#!/usr/bin/env python\nimport pika\nimport time\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost'))\nchannel = connection.channel()\n\nchannel.queue_declare(queue='task_queue', durable=True)\nprint ' [*] Waiting for messages. To exit press CTRL+C'\n\ndef callback(ch, method, properties, body):\n long_running_task(connection)\n ch.basic_ack(delivery_tag = method.delivery_tag)\n\nchannel.basic_qos(prefetch_count=1)\nchannel.basic_consume(callback,\n queue='task_queue')\n\nchannel.start_consuming()\n```\n\n```text\n#!/usr/bin/env python\nimport pika\nimport time\nimport threading\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost',\n heartbeat_interval=20))\nchannel = connection.channel()\n\nchannel.queue_declare(queue='task_queue', durable=True)\nprint ' [*] Waiting for messages. To exit press CTRL+C'\n\ndef thread_func(ch, method, body):\n long_running_task(connection)\n ch.basic_ack(delivery_tag = method.delivery_tag)\n\ndef callback(ch, method, properties, body):\n threading.Thread(target=thread_func, args=(ch, method, body)).start()\n\nchannel.basic_qos(prefetch_count=1)\nchannel.basic_consume(callback,\n queue='task_queue')\n\nchannel.start_consuming()\n```\n\n```text\nlong_running_task()\n```\n\n```text\nch\n```\n\n```text\nlong_running_task()\n```\n\n```text\nconnection\n```\n\n```text\nConnectionParameters(heartbeat=0)\n```\n\n```text\nprefetch_count\n```\n\n```text\n1\n```\n\n```text\nchannel.basic_qos(prefetch_count=1)\n```\n\n```text\nconnection.process_data_events()\n```\n\n```text\nlong_running_task(connection)\n```\n\n```text\nconnection.process_data_events()\n```\n\n```text\nBlockingConnection\n```\n\n```text\n0.12.0\n```\n\n```py\nimport re\nimport json\nimport threading\n\nfrom google.cloud import bigquery\nimport pandas as pd\nimport pika\nfrom unidecode import unidecode\n\ndef process_export(url, tablename):\n df = pd.read_csv(csvURL, encoding=\"utf-8\")\n print(\"read in the csv\")\n columns = list(df)\n ascii_only_name = [unidecode(name) for name in columns]\n cleaned_column_names = [re.sub(\"[^a-zA-Z0-9_ ]\", \"\", name) for name in ascii_only_name]\n underscored_names = [name.replace(\" \", \"_\") for name in cleaned_column_names]\n valid_gbq_tablename = \"test.\" + tablename\n df.columns = underscored_names\n\n # try:\n df.to_gbq(valid_gbq_tablename, \"some_project\", if_exists=\"append\", verbose=True, chunksize=10000)\n # print(\"Finished Exporting\")\n # except Exception as error:\n # print(\"unable to export due to: \")\n # print(error)\n # print()\n\ndef data_handler(channel, method, properties, body):\n body = json.loads(body)\n\n thread = threading.Thread(target=process_export, args=(body[\"csvURL\"], body[\"tablename\"]))\n thread.start()\n while thread.is_alive(): # Loop while the thread is processing\n channel._connection.sleep(1.0)\n print('Back from thread')\n channel.basic_ack(delivery_tag=method.delivery_tag)\n\n\ndef main():\n params = pika.ConnectionParameters(host='localhost', heartbeat=60)\n connection = pika.BlockingConnection(params)\n channel = connection.channel()\n channel.queue_declare(queue=\"some_queue\", durable=True)\n channel.basic_qos(prefetch_count=1)\n channel.basic_consume(data_handler, queue=\"some_queue\")\n try:\n channel.start_consuming()\n except KeyboardInterrupt:\n channel.stop_consuming()\n channel.close()\n\nif __name__ == '__main__':\n main()\n```\n\n```text\n.sleep\n```\n\n```text\nimport time\nimport pika\nfrom threading import Thread\nfrom functools import partial\n\nrmqconn = pika.BlockingConnection( ... )\nrmqchan = rmqconn.channel()\nrmqchan.basic_consume(\n queue='test',\n on_message_callback=partial(launch_process,rmqconn)\n)\nrmqchan.start_consuming()\n\ndef launch_process(conn,ch,method,properties,body):\n runthread = Thread(target=run_process,args=body)\n runthread.start()\n while runthread.is_alive():\n time.sleep(2)\n conn.process_data_events()\n ch.basic_ack(delivery_tag=method.delivery_tag)\n\ndef run_process(body):\n #do the long-running thing\n time.sleep(10)\n```\n\n========================================\n\nComments:\n- I am having the same problem. The docs says pika connection is not thread safe pika.readthedocs.org/en/latest/faq.html\n- As @Gavin mentioned the best bet as of now is to turn off the heartbeat in pika while setting up the connection. `connection = pika.BlockingConnection(pika.ConnectionParameters(host='loca‌​lhost', virtual_host='TestVirtualHost', credentials=credentials, heartbeat_interval=0, port=5672))`\n- Pika `0.12.0` has a better solution, please see this answer\n- Thanks, It works. If its still not working for you. Note that `heartbeat` parameter should be set to both peers (consumer and producer). That's what happened in my case.\n- Set `ConnectionParameters(heartbeat=0)` is safe. Because when you have killed this process, the connection is automatically closed immediately. You can go rabbit_mq_server:15672/#/connections to verify it.\n- how do you turn on client heartbeat? can't find anything about how to do it.\n- You could try something like this: `params = pika.ConnectionParameters(host=self.__host, port=self.__port, credentials=credentials, heartbeat_interval=)`\n- I should have tried your approach first, saved me tons of headache and hairs. thank you for your helpful insight.\n- `connection.process_data_events()` help me\n- My long-running tasks were largely waiting/sleeping, so this helped a ton. I'm rather surprised how buried and non-intuitive \"please tell the server I'm still alive\" functionality is in pika, but glad to have finally found it.\n- Why is it a bad thing to disable heartbeats?\n- Neither RabbitMQ nor your application will detect a lost TCP connection until the next operation is attempted on that connection.\n- I get that, but depending on the use case, that's not necessarily a bad thing. In my case I'd rather have an error when trying to ack a message because the connection was lost, than having an error when trying to ack a message because the connection was closed due to my processing taking too long. That's why a general warning not to disable heartbeats seems unjustified IMO. It all depends on the use case, so I believe it would be more productive to say why you maybe should consider not disabling them instead of going \"disabling = bad\" without any further information.\n- @LukeBakken Is there any way to use this method with channel.basic_get? I need my consumer to consume one message, acknowledge it and then die/quit, I can get it to consume only one message with basic_get, but then I cannot get it to acknowledge the (long-running) message.\n- This is the best & correct solution. Thanks @LukeBakken.\n- If there are a large number of items queued up and the average time to process each one is very high, then the spawning an individual thread for processing a item would lead to an explosion of active threads which finally ends up in OOM error. I have experienced this.\n- Stackoverflow answers should be self-contained. In addition to linking to example code, include the example code inline.\n- Please refer to the solution provided by Luke Bakken. It's Thread Safe & refers to an official example from pika documentation.","metadata":{"transformedAt":"2026-08-18T18:33:20.116Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":18,"totalLines":293,"estimatedTokens":2637}}51{"id":"stack-17054533","source":"stackoverflow","questionId":17054533,"title":"Allowing RabbitMQ-Server Connections","tags":["django","rabbitmq","celery"],"text":"Title: Allowing RabbitMQ-Server Connections\nTags: django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI'm trying to get a Django Celery worker to connect to a RabbitMQ server, all running on the same host.\n\nHowever, when I run `manage.py celery worker` all I get is:\n\n```\n[2013-06-11 17:33:41,185: WARNING/MainProcess] celery@localhost has started.\n[2013-06-11 17:33:44,192: ERROR/MainProcess] Consumer: Connection Error: Socket closed. Trying again in 2 seconds...\n[2013-06-11 17:33:50,203: ERROR/MainProcess] Consumer: Connection Error: Socket closed. Trying again in 4 seconds...\n[2013-06-11 17:34:03,214: ERROR/MainProcess] Consumer: Connection Error: Socket closed. Trying again in 6 seconds...\n[2013-06-11 17:34:27,232: ERROR/MainProcess] Consumer: Connection Error: Socket closed. Trying again in 8 seconds...\n```\n\nWhen I inspect my `/var/log/rabbitmq/rabbit@localhost.log` I see several messages like:\n\n```\n=ERROR REPORT==== 11-Jun-2013::17:33:44 ===\nexception on TCP connection from 127.0.0.1:43461\n{channel0_error,opening,\n {amqp_error,access_refused,\n \"access to vhost 'myapp' refused for user 'guest'\",\n 'connection.open'}}\n```\n\nI'm using the standard package out of Ubuntu 12.04's repo, with the default settings and my django-celery settings look like:\n\n```\nBROKER_HOST = \"localhost\"\nBROKER_PORT = 5672\nBROKER_USER = \"guest\"\nBROKER_PASSWORD = \"guest\"\nBROKER_VHOST = \"myapp\"\n```\n\nWhy is RabbitMQ refusing connections?\n\n========================================\n\nCode:\n```text\n[2013-06-11 17:33:41,185: WARNING/MainProcess] celery@localhost has started.\n[2013-06-11 17:33:44,192: ERROR/MainProcess] Consumer: Connection Error: Socket closed. Trying again in 2 seconds...\n[2013-06-11 17:33:50,203: ERROR/MainProcess] Consumer: Connection Error: Socket closed. Trying again in 4 seconds...\n[2013-06-11 17:34:03,214: ERROR/MainProcess] Consumer: Connection Error: Socket closed. Trying again in 6 seconds...\n[2013-06-11 17:34:27,232: ERROR/MainProcess] Consumer: Connection Error: Socket closed. Trying again in 8 seconds...\n```\n\n```text\n=ERROR REPORT==== 11-Jun-2013::17:33:44 ===\nexception on TCP connection <0.201.0> from 127.0.0.1:43461\n{channel0_error,opening,\n {amqp_error,access_refused,\n \"access to vhost 'myapp' refused for user 'guest'\",\n 'connection.open'}}\n```\n\n```text\nBROKER_HOST = \"localhost\"\nBROKER_PORT = 5672\nBROKER_USER = \"guest\"\nBROKER_PASSWORD = \"guest\"\nBROKER_VHOST = \"myapp\"\n```\n\n```text\nmanage.py celery worker\n```\n\n```text\n/var/log/rabbitmq/rabbit@localhost.log\n```\n\n```text\nset_permissions [-p vhostpath] {user} {conf} {write} {read}\n```\n\n```text\nrabbitmqctl set_permissions -p /myvhost guest \".*\" \".*\" \".*\"\n```\n\n========================================\n\nComments:\n- What if, I want to give by default full access to my vhost while creating from rabbitmq image? because if we run the application in docker container, then, in that case, we don't want any manual permissions to get the app working, in general.","metadata":{"transformedAt":"2026-08-18T18:33:20.116Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":7,"totalLines":88,"estimatedTokens":755}}52{"id":"stack-41210688","source":"stackoverflow","questionId":41210688,"title":"multiple Rabbitmq queues with spring boot","tags":["spring-boot","rabbitmq","amqp","spring-amqp","rabbitmq-exchange"],"text":"Title: multiple Rabbitmq queues with spring boot\nTags: spring-boot, rabbitmq, amqp, spring-amqp, rabbitmq-exchange\nSource: Stack Overflow\n\nQuestion:\nFrom spring boot tutorial:\nhttps://spring.io/guides/gs/messaging-rabbitmq/\n\nThey give an example of creating 1 queue and 1 queue only, but, what if I want to be able to create more then 1 queue? how would it be possible?\n\nObviously, I can't just create the same bean twice:\n\n```\n@Bean\nQueue queue() {\n return new Queue(queueNameAAA, false);\n}\n\n@Bean\nQueue queue() {\n return new Queue(queueNameBBB, false);\n}\n```\n\nYou can't create the same bean twice, it will make ambiguous.\n\n========================================\n\nCode:\n```text\n@Bean\nQueue queue() {\n return new Queue(queueNameAAA, false);\n}\n\n@Bean\nQueue queue() {\n return new Queue(queueNameBBB, false);\n}\n```\n\n```text\n@Bean\nQueue queue1() {\n return new Queue(queueNameAAA, false);\n}\n\n@Bean\nQueue queue2() {\n return new Queue(queueNameBBB, false); \n}\n```\n\n```text\n@Bean\nBinding binding1(@Qualifier(\"queue1\") Queue queue, TopicExchange exchange) {\n return BindingBuilder.bind(queue).to(exchange).with(queueNameAAA);\n}\n\n@Bean\nBinding binding2(@Qualifier(\"queue2\") Queue queue, TopicExchange exchange) {\n return BindingBuilder.bind(queue).to(exchange).with(queueNameBBB);\n}\n```\n\n```text\n@Bean\nBinding binding1(TopicExchange exchange) {\n return BindingBuilder.bind(queue1()).to(exchange).with(queueNameAAA);\n}\n\n@Bean\nBinding binding2(TopicExchange exchange) {\n return BindingBuilder.bind(queue2()).to(exchange).with(queueNameBBB);\n}\n```\n\n```text\n@Bean\nBinding binding1(TopicExchange exchange) {\n return BindingBuilder.bind(queue1()).to(exchange).with(queue1().getName());\n}\n\n@Bean\nBinding binding2(TopicExchange exchange) {\n return BindingBuilder.bind(queue2()).to(exchange).with(queue2().getName());\n}\n```\n\n========================================\n\nComments:\n- but, once i have 2 beans, as you can see in the link to tutorial, the method name \"binding\" you only get 1 queue, so how would you bind this based on your own needs? I mean, I'm trying to bind multiple queue into 1 exchange, using different keys for the queues. but spring boot doesn't provide this.\n- Ah, I see you are just not yet familiar with Spring configuration - see my edit.\n- OMG, seems like a lot of things which are unrelated to this question, become crazingly clear....Thank you very much, u made me a super human :)","metadata":{"transformedAt":"2026-08-18T18:33:20.116Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":95,"estimatedTokens":605}}53{"id":"stack-30918557","source":"stackoverflow","questionId":30918557,"title":"Embedded AMQP Java Broker","tags":["java","rabbitmq","automated-tests","integration-testing","amqp"],"text":"Title: Embedded AMQP Java Broker\nTags: java, rabbitmq, automated-tests, integration-testing, amqp\nSource: Stack Overflow\n\nQuestion:\nI am trying to create integration test for a Scala / Java application that connects to a RabbitMQ broker. To achieve this I would like an embedded broker that speaks AMQP that I start and stop before each test. Originally I tried to introduce ActiveMQ as an embedded broker with AMQP however the application uses RabbitMQ so only speaks AMQP version 0.9.3 whereas ActiveMQ requires AMQP version 1.0.\n\nIs there another embedded broker I can use in place of ActiveMQ?\n\n========================================\n\nTop Answer:\nI've developed a wrapper around the process of downloading, extracting, starting and managing RabbitMQ so it can work like an embedded service controlled by any JVM project. \n\nCheck it out: https://github.com/AlejandroRivera/embedded-rabbitmq\n\nIt's as simple as:\n\n```\nEmbeddedRabbitMqConfig config = new EmbeddedRabbitMqConfig.Builder()\n .version(PredefinedVersion.V3_5_7)\n .build();\nEmbeddedRabbitMq rabbitMq = new EmbeddedRabbitMq(config);\nrabbitMq.start();\n...\nrabbitMq.stop();\n```\n\nWorks on Linux, Mac and Windows.\n\n========================================\n\nCode:\n```text\n<dependency>\n <groupId>org.apache.qpid</groupId>\n <artifactId>qpid-broker</artifactId>\n <version>6.1.1</version>\n <scope>test</scope>\n</dependency>\n```\n\n```text\npublic class EmbeddedBroker {\n public void start() {\n Broker broker = new Broker();\n BrokerOptions brokerOptions = new BrokerOptions();\n brokerOptions.setConfigProperty(\"qpid.amqp_port\", environment.getProperty(\"spring.rabbitmq.port\"));\n brokerOptions.setConfigProperty(\"qpid.broker.defaultPreferenceStoreAttributes\", \"{\\\"type\\\": \\\"Noop\\\"}\");\n brokerOptions.setConfigProperty(\"qpid.vhost\", environment.getProperty(\"spring.rabbitmq.virtual-host\"));\n brokerOptions.setConfigurationStoreType(\"Memory\");\n brokerOptions.setStartupLoggedToSystemOut(false);\n broker.startup(brokerOptions);\n }\n}\n```\n\n```text\n{\n \"name\": \"Embedded Test Broker\",\n \"modelVersion\": \"6.1\",\n \"authenticationproviders\" : [{\n \"name\": \"password\",\n \"type\": \"Plain\",\n \"secureOnlyMechanisms\": [],\n \"users\": [{\"name\": \"guest\", \"password\": \"guest\", \"type\": \"managed\"}]\n }],\n \"ports\": [{\n \"name\": \"AMQP\",\n \"port\": \"${qpid.amqp_port}\",\n \"authenticationProvider\": \"password\",\n \"protocols\": [ \"AMQP_0_9_1\" ],\n \"transports\": [ \"TCP\" ],\n \"virtualhostaliases\": [{\n \"name\": \"${qpid.vhost}\",\n \"type\": \"nameAlias\"\n }]\n }],\n \"virtualhostnodes\" : [{\n \"name\": \"${qpid.vhost}\",\n \"type\": \"Memory\",\n \"virtualHostInitialConfiguration\": \"{ \\\"type\\\": \\\"Memory\\\" }\"\n }]\n}\n```\n\n```text\nspring.*\n```\n\n```text\ninitial-config.json\n```\n\n```text\nEmbeddedRabbitMqConfig config = new EmbeddedRabbitMqConfig.Builder()\n .version(PredefinedVersion.V3_5_7)\n .build();\nEmbeddedRabbitMq rabbitMq = new EmbeddedRabbitMq(config);\nrabbitMq.start();\n...\nrabbitMq.stop();\n```\n\n```text\n...\n<properties>\n ...\n <qpid-broker.version>7.0.2</qpid-broker.version>\n</properties>\n\n<dependencies>\n ...\n <dependency>\n <groupId>org.apache.qpid</groupId>\n <artifactId>qpid-broker-core</artifactId>\n <version>${qpid-broker.version}</version>\n <scope>test</scope>\n </dependency>\n <dependency>\n <groupId>org.apache.qpid</groupId>\n <artifactId>qpid-broker-plugins-amqp-0-8-protocol</artifactId>\n <version>${qpid-broker.version}</version>\n <scope>test</scope>\n </dependency>\n <dependency>\n <groupId>org.apache.qpid</groupId>\n <artifactId>qpid-broker-plugins-memory-store</artifactId>\n <version>${qpid-broker.version}</version>\n <scope>test</scope>\n </dependency>\n</dependecies>\n...\n```\n\n```text\n{\n \"name\": \"EmbeddedBroker\",\n \"modelVersion\": \"7.0\",\n \"authenticationproviders\": [\n {\n \"name\": \"password\",\n \"type\": \"Plain\",\n \"secureOnlyMechanisms\": [],\n \"users\": [{\"name\": \"guest\", \"password\": \"guest\", \"type\": \"managed\"}]\n }\n ],\n \"ports\": [\n {\n \"name\": \"AMQP\",\n \"port\": \"${qpid.amqp_port}\",\n \"authenticationProvider\": \"password\",\n \"virtualhostaliases\": [\n {\n \"name\": \"defaultAlias\",\n \"type\": \"defaultAlias\"\n }\n ]\n }\n ],\n \"virtualhostnodes\": [\n {\n \"name\": \"default\",\n \"defaultVirtualHostNode\": \"true\",\n \"type\": \"Memory\",\n \"virtualHostInitialConfiguration\": \"{\\\"type\\\": \\\"Memory\\\" }\"\n }\n ]\n}\n```\n\n```text\npublic class EmbeddedAMQPBroker extends ExternalResource {\n\n private final SystemLauncher broker = new SystemLauncher();\n\n @Override\n protected void before() throws Throwable {\n startQpidBroker();\n //createExchange();\n }\n\n @Override\n protected void after() {\n broker.shutdown();\n }\n\n private void startQpidBroker() throws Exception {\n Map<String, Object> attributes = new HashMap<>();\n attributes.put(\"type\", \"Memory\");\n attributes.put(\"initialConfigurationLocation\", findResourcePath(\"qpid-config.json\"));\n broker.startup(attributes);\n }\n\n private String findResourcePath(final String fileName) {\n return EmbeddedAMQPBroker.class.getClassLoader().getResource(fileName).toExternalForm();\n }\n}\n```\n\n```text\npublic class MessagingIT{\n @ClassRule\n public static EmbeddedAMQPBroker embeddedAMQPBroker = new EmbeddedAMQPBroker();\n\n ...\n}\n```\n\n```text\nqpid-broker-plugins-amqp-0-8-protocol\n```\n\n```text\nqpid-broker-plugins-memory-store\n```\n\n```text\npom.xml\n```\n\n```text\nqpid-config.json\n```\n\n```text\nExternalResource\n```\n\n```text\nClassRule\n```\n\n```text\n@BeforeClass\n```\n\n```text\n@AfterClass\n```\n\n```text\nEmbeddedAMQPBroker.java\n```\n\n========================================\n\nComments:\n- RabbitMQ implements AMQP 0.8; 0.9.1 and AMQP 1.0. If you are using a mac, it's quite easy to start/stop rabbitmq for your tests. This is for PHP but might help you in your use case videlalvaro.github.io/2013/04/using-rabbitmq-in-unit-tests.h‌​tml\n- Hi @old_sound, thanks for looking into it. Ideally I would like to avoid requiring rabbitmq on the box to test, our tests run on a CI server that we can't install RabbitMQ easily.\n- Does that CI server has Erlang installed at least? If yes, you can just download the rabbit tarball, uncompress it, and start/stop it for the tests\n- Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers.\n- Works great but ERL need to be pre installed is a problem for me.\n- Be aware that if your application connects to RabbitMQ in prod, you might discover inconsistencies if you bind to Apache QPid for integration tests. RabbitMQ has extended AMQP to provide additional functionality that your application might be relying on (eg. TTLs, DLE/Qs, routing, ...). More info rabbitmq.com/extensions.html\n- QPid has most of that too, just with different names.\n- I can't use it because they hard code the logger class. Such a pity... org.apache.logging.slf4j.Log4jLogger cannot be cast to ch.qos.logback.classic.Logger java.lang.ClassCastException: org.apache.logging.slf4j.Log4jLogger cannot be cast to ch.qos.logback.classic.Logger\n- @JanGoyvaerts huh? It uses slf4j - there's no hard-coding anywhere. You can configure it to use Logback instead if for some reason you need direct access to the logger implementations.\n- @OrangeDog, then what do you call this in `Broker.startup()`? `ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);`\n- @Timi oh yeah. The whole structure has been rewritten for 7.x though, so that may have been fixed.\n- @OrangeDog, thanks for pointing that out! Can you point me to some embedded examples using 7.x? The whole API seems to be changed and I found hardly any examples of how to use it. This is all I could find, but I can't get it to work with a password file.\n- @Timi sorry, I haven't looked at this for a while. I suggest chatting to the devs on IRC. I know they took a lot of my feedback while I was coming up with this answer in the first place. It should be a bit simpler now.","metadata":{"transformedAt":"2026-08-18T18:33:20.116Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":19,"totalLines":261,"estimatedTokens":2128}}54{"id":"stack-21248563","source":"stackoverflow","questionId":21248563,"title":"RabbitMQ difference between exclusive and auto-delete?","tags":["rabbitmq"],"text":"Title: RabbitMQ difference between exclusive and auto-delete?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nThe \"RabbitMQ in Action\" book on page 19 gives these descriptions of exclusive and auto-delete:\n\n exclusive - When set to true, your queue becomes private and can only\n be consumed by your app. This is useful when you need to limit a queue\n to only one consumer.\n\n \n auto-delete - The queue is automatically deleted when the last\n consumer unsubscribes. If you need a temporary queue used only by one\n consumer, combine auto-delete with exclusive. When the consumer\n disconnects, the queue will be removed.\n\nBut as far as I can see when using exclusive, auto-delete is redundant. Only exclusive is needed. The RabbitMQ tutorial seems to say that is the case\n\n ...once we disconnect the consumer the queue should be deleted. There's\n an exclusive flag for that:\n\n```\nresult = channel.queue_declare(exclusive=True)\n```\n\nThere is no mention in that tutorial about auto-delete and `sudo rabbitmqctl list_bindings` seems to indicate that the queue is in fact deleted after the receiver goes away.\n\n========================================\n\nTop Answer:\nIn contrast to what theMayer described, my testing showed that there is a difference in behavior when auto-delete is toggled while exclusive is set to true.\n\nIf auto-delete is set to false, the queue is indeed tied to the connection and will disappear when the connection is terminated.\n\nIf auto-delete is set to true, the queue will be deleted after the last consumer is cancelled.\n\nThere is a difference between a connection and a consumer. You can be connected, but not consuming a given queue. If you need the queue's lifecycle to be tied to your connection rather than to whether or not you're actively consuming it, set auto-delete to false in conjunction with exclusive=true.\n\n========================================\n\nCode:\n```text\nresult = channel.queue_declare(exclusive=True)\n```\n\n```text\nsudo rabbitmqctl list_bindings\n```\n\n```text\nexclusive\n```\n\n========================================\n\nComments:\n- But the link says \"are deleted when that connection closes\" (and says nothing about consumers).\n- Yes, that is correct for `exclusive` - the question dealt with the difference between `exclusive` and `auto-delete` - and hopefully I was able to illustrate that there is an important difference and valid scenarios when you might want to use both.\n- We had numerous issues with auto-delete and exclusive flags - queues are deleted even during short network interruptions, which in our case caused major headaches, but once we followed theMayer's advice to simply use expiration, all the problems were magically solved.\n- This is entirely consistent with the documentation. I believe the issue is that the question references some third-party source, and that source is not exactly accurate. It would have been better if that book simply quoted from the documentation, but it chose to paraphrase, and did so poorly, thus creating the question.","metadata":{"transformedAt":"2026-08-18T18:33:20.116Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":61,"estimatedTokens":753}}55{"id":"stack-17806977","source":"stackoverflow","questionId":17806977,"title":"Comparison between RabbitMQ and MSMQ","tags":["performance","rabbitmq","msmq","message-queue"],"text":"Title: Comparison between RabbitMQ and MSMQ\nTags: performance, rabbitmq, msmq, message-queue\nSource: Stack Overflow\n\nQuestion:\nCan I get the comparison between RabbitMQ and MSMQ. It will be helpful performance information on different factors are available.\n\n========================================\n\nComments:\n- Hi! Would you mind to refresh your answer since it was written 3 years ago. Thank you!\n- @Dimi you are more than invited to do that.\n- What does DR mean?\n- @RajaAnbazhagan Disaster Recovery\n- \"MSMQ is a simple store-and-forward queue. It doesn't provide any messaging patterns, such as pub/sub, or routing.\" This is not accurate. MSMQ does support multicasting (pub/sub) and offers correlation Id's for identifying unique messages in the same queue.","metadata":{"transformedAt":"2026-08-18T18:33:20.116Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":15,"estimatedTokens":191}}56{"id":"stack-1823705","source":"stackoverflow","questionId":1823705,"title":"Why use AMQP/ZeroMQ/RabbitMQ","tags":["rabbitmq","messaging","zeromq","amqp"],"text":"Title: Why use AMQP/ZeroMQ/RabbitMQ\nTags: rabbitmq, messaging, zeromq, amqp\nSource: Stack Overflow\n\nQuestion:\nas opposed to writing your own library.\n\nWe're working on a project here that will be a self-dividing server pool, if one section grows too heavy, the manager would divide it and put it on another machine as a separate process. It would also alert all connected clients this affects to connect to the new server.\n\nI am curious about using ZeroMQ for inter-server and inter-process communication. My partner would prefer to roll his own. I'm looking to the community to answer this question.\n\nI'm a fairly novice programmer myself and just learned about messaging queues. As i've googled and read, it seems everyone is using messaging queues for all sorts of things, but why? What makes them better than writing your own library? Why are they so common and why are there so many?\n\n========================================\n\nTop Answer:\nThat's very much like asking: why use a database when you can write your own?\n\nThe answer is that using a tool that has been around for a while and is well understood in lots of different use cases, pays off more and more over time and as your requirements evolve. This is especially true if more than one developer is involved in a project. Do you want to become support staff for a queueing system if you change to a new project? Using a tool prevents that from happening. It becomes someone else's problem.\n\nCase in point: persistence. Writing a tool to store one message on disk is easy. Writing a persistor that scales and performs well *and* stably, in many different use cases, and is manageable, and cheap to support, is hard. If you want to see someone complaining about how hard it is then look at this: http://www.lshift.net/blog/2009/12/07/rabbitmq-at-the-skills-matter-functional-programming-exchange\n\nAnyway, I hope this helps. By all means write your own tool. Many many people have done so. Whatever solves your problem, is good.\n\n========================================\n\nComments:\n- The reason you should not write your own library is because, in your own words, you are \"a fairly novice programmer\". Why would you want to use an MQ library written by a novice programmer?\n- Writing your own library as a novice programmer would be a great exercise in learning, so long as you don't publish/expect others to *use* your learning experiment of a library.\n- I've been thinking about this for a short while. What exactly do you mean by Transactions and Persistence? I understand the words but not the context here. Simply stated, it rings of buzz words.\n- I would not call these buzzwords; persistence and transactions have been known under these names for several decades. I've edited my answer to elaborate these points in the context of messaging.\n- Interesting, but what makes these so hard to get right? From my perspective it seems, if I'm writing a server and client, you send the message, make sure the message is received in full, and keep a duplicate of the message stored to disk. That is the end of it. why are there so many versions of such a simplistic system? I mean alot of them are fairly small code wise, once you have a comprehension of how they work it doesnt seem to require that much to implement. So it comes back to why use a pre-written messaging queue.\n- Transactions are very easy to implement if you don't care about latency and/or correctness. See here for an overview of some typical implementation challenges: jroller.com/pyrasun/category/XA\n- If I've understood the official zeromq guide correctly, it is not persistent. You have to build persistence on top of it.\n- According to the official zeromq guide, zeromq doesn't provide persistence. The guide shows you how to do this, but I'd rather have something that has persistence baked into the framework, not using some poorly-tested tutorial code!\n- Disagree on \"when rolling out the first version of your app, probably nothing\" You finish by saying the first version will get rewritten with a library anyway, may as well start with something you don't end up throwing away. Otherwise, I agree.\n- @O.O most of the time the initial features needed are small and you cannot always justify importing 3rd party stuff easily: need approval, security screening of the code etc. depending on who you work for these take much more time than dev time. Hence you start small, do it yourself with the tools already in the comnpany, and then when your code is in prod, heavily used, using the 3rd party stuff becomes easier. Your mileage may vary, but usually companies don't want use a gazillion 3rd party stuff/framework/library.\n- Or a compiler. Why bother using a compiled language when one can write pure, unadulterated assembly language all the time? :-)\n- i tend to agree with you up to a point.. ive been working with a few programs over the last few months in C++ since this question was asked.. and ive run in to the hell that is 3rd party libs.. some are relatively painless.. but alot of them add more trouble than they are worth.. just trying to install them. I still am unsure as to why anyone would have requirements for zeroMQ.. one of the first things i learned to write was how to send a message from one program to another through TCP and sockets for a very simple chat program, it was relatively easy..\n- Completely agree that many (maybe most?) third party libs are more trouble than they are worth. I guess I've found some real gems over the years that I'm more than happy to work with. I've just compiled ZeroMQ and run their tests. It's looks pretty good. It doesn't have \"gem\" status just yet, but we'll see...\n- Just to up - I've found ZeroMQ to be quite good. It certainly is very light weight and fast. I don't like the way that their Socket has thread affinity as I want to use two threads to access the socket - one for reading messages and one for writing messages. It think that the \"ZeroMQ\" way of doing this is to use in-process message queues to marshal messages between threads... more thought required.\n- Interesting, please more with more experience!\n- I spent yesterday writing an alternative messaging implementation for my app based on Boost.Asio (boost.org/doc/libs/1_37_0/doc/html/boost_asio.html). This fits my needs much better. I've not measured it's performance yet, but I expect it will be quite good. I think it's just as easy to use ZeroMQ when, assuming you don't need all their fruit (like pubish/subscribe pattern), but has far better documentation.\n- They have done some \"hard parts\" in tutorial fashion in the guide (e.g. persistence). I would rather use a battle-tested implementation than some poorly-tested tutorial code.\n- If you want battle-tested implementation, then you would choose AMQP instead of ZMQ and use something like RabbitMQ","metadata":{"transformedAt":"2026-08-18T18:33:20.116Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":45,"estimatedTokens":1707}}57{"id":"stack-35438843","source":"stackoverflow","questionId":35438843,"title":"RabbitMQ error timeout","tags":["php","ubuntu","nginx","rabbitmq","php-amqplib"],"text":"Title: RabbitMQ error timeout\nTags: php, ubuntu, nginx, rabbitmq, php-amqplib\nSource: Stack Overflow\n\nQuestion:\nI've set up RabbitMQ in order to parse some 20.000 requests from an external API but it keeps timing out after a few minutes. It does get to correctly parse about 2000 out of the total 20.000 requests.\n\nThe log file says:\n\n```\n=INFO REPORT==== 16-Feb-2016::17:02:50 ===\naccepting AMQP connection (127.0.0.1:33091 -> 127.0.0.1:5672)\n\n=ERROR REPORT==== 16-Feb-2016::17:03:21 ===\nclosing AMQP connection (127.0.0.1:33091 -> 127.0.0.1:5672):\n{writer,send_failed,{error,timeout}}\n```\n\nI've already increased the heartbeat value but I cannot figure out why it's timing out. Configuration is: Ubuntu 14.04, NGINX 1.8.1, RabbitMQ 3.6.0\n\nI'd appreciate your time and input !\n\n========================================\n\nTop Answer:\nAdd more to @tul's answer.\n\n```\nsubChannel.basicQos(10);\n```\n\nReducing consumer prefetch count does eliminate this timeout exception.\n\nThe default prefetch count is unlimited.\n\n========================================\n\nCode:\n```text\n=INFO REPORT==== 16-Feb-2016::17:02:50 ===\naccepting AMQP connection <0.1648.0> (127.0.0.1:33091 -> 127.0.0.1:5672)\n\n=ERROR REPORT==== 16-Feb-2016::17:03:21 ===\nclosing AMQP connection <0.1648.0> (127.0.0.1:33091 -> 127.0.0.1:5672):\n{writer,send_failed,{error,timeout}}\n```\n\n```text\nsubChannel.basicQos(10);\n```\n\n```text\nsubChannel.basicQos(10);\n```\n\n========================================\n\nComments:\n- There seem to be some details missing here: What is doing the \"parsing\"? Where is this log message taken from? Is the timeout happening while publishing messages *to* RabbitMQ, or while consuming them *from* it? Your tags mention PHP, so is there some relevant PHP code you could show us?\n- Thank you for replying ! Indeed, a consumer written in PHP is parsing some JSON data from an external API. The log messages have been taken from the main RabbitMQ log file: /var/log/rabbitmq/rabbit@hostname.log . I wouldn't say the PHP code is relevant to the error but it does write a brief output to a .txt file.\n- It might be worth posting (or creating a minimal reproducible example of) your PHP code, just in case there's something you're doing that could be triggering the timeout. At the moment, we don't have much to go other than \"there's a timeout error somewhere\". Similarly, any code around the way the messages are published (presumably there's something picking items from the API and putting them into Rabbit somehow?)\n- It sounds logical. Will test this for sure, thank you !\n- subChannel.basicQos(10); Reducing consumer prefetch count does eliminate this\n- At PHP you have to use this before calling `basic_consume`: `$channel->basic_qos(null, 1, null)` and can help if you use `ack` instead of `no_ack`.\n- I also was able to solve server connection timeouts setting `prefetch_count`to 10 or less. Use following code in Python using library Pika: `channel.basic_qos(prefetch_count=10)`\n- Thanks for providing a code snippet, this saved me today","metadata":{"transformedAt":"2026-08-18T18:33:20.116Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":66,"estimatedTokens":756}}58{"id":"stack-23050120","source":"stackoverflow","questionId":23050120,"title":"RabbitMQ command doesn't exist?","tags":["macos","rabbitmq"],"text":"Title: RabbitMQ command doesn't exist?\nTags: macos, rabbitmq\nSource: Stack Overflow\n\nQuestion:\n**OS: Mac OSX 10.9**\n\nI have `rabbitmq` installed via home brew and when I go to `/usr/local/sbin` and run `rabbitmq-server` it states that: `rabbitmq-server: command not found` even as sudo it states the same error.\n\nHow do I get rabbitmq to start if it's not a command? I have also tried `chmod +x rabbitmq-server` in that directory to get it be an executable, same issue.\n\n========================================\n\nTop Answer:\nMy OS: macOS Sierra 10.12.5\n\nMy RabbitMQ was installed using:\n\n```\nbrew install rabbitmq\n```\n\nAnd it was installed into `/usr/local/Cellar`, just in case if someone has same situation with me, you would need to do similarly:\n\nIn terminal:\n\n```\nls /usr/local/Cellar/rabbitmq/\n```\n\nto check which version you have installed, and then add to `.bash_profile`:\n\n```\nexport PATH=/usr/local/Cellar/rabbitmq//sbin:$PATH\n```\n\n========================================\n\nCode:\n```text\nrabbitmq\n```\n\n```text\n/usr/local/sbin\n```\n\n```text\nrabbitmq-server\n```\n\n```text\nrabbitmq-server: command not found\n```\n\n```text\nchmod +x rabbitmq-server\n```\n\n```text\n/usr/local/sbin/rabbitmq-server\n```\n\n```text\n.\n```\n\n```text\n$PATH\n```\n\n```text\n/usr/local/sbin\n```\n\n```text\nrabbitmq-server\n```\n\n```text\nrabbitmq-server\n```\n\n```text\n$PATH\n```\n\n```text\n/usr/local/sbin\n```\n\n```text\n./rabbitmq-server\n```\n\n```text\nrabbitmq-server\n```\n\n```text\n/usr/local/sbin/rabbitmq-server\n```\n\n```text\n.\n```\n\n```text\n/usr/local/sbin\n```\n\n```text\nexport PATH=/usr/local/sbin:$PATH\n```\n\n```text\n/usr/local/sbin\n```\n\n```text\nbrew services start rabbitmq\nbrew services stop rabbitmq\nbrew services restart rabbitmq\n```\n\n```text\nbrew install rabbitmq\n```\n\n```text\nls /usr/local/Cellar/rabbitmq/\n```\n\n```text\nexport PATH=/usr/local/Cellar/rabbitmq/<version>/sbin:$PATH\n```\n\n```text\n/usr/local/Cellar\n```\n\n```text\n.bash_profile\n```\n\n```text\nbrew install rabbitmq.\n```\n\n```text\n1. chown -R `whoami`:admin /usr/local/sbin\n2. chown -R `whoami`:admin /usr/local/share\n3. brew install rabbitmq\n4. /usr/local/sbin/rabbitmq-server\n```\n\n```text\nhttp://localhost:15672/\nuserame: guest\npassword: guest\n```\n\n```text\nPATH=$PATH:/usr/local/Cellar\n```\n\n```text\nsudo nano ./bash_profile\n```\n\n```text\nbash_profile\n```\n\n```text\n.profile\n```\n\n```text\nPATH=$PATH:/usr/local/sbin\n```\n\n```text\nsource ~/.bash_profile\n```\n\n```text\nbrew services start rabbitmq\n```\n\n```text\n/usr/local/sbin/rabbitmq-server\n```\n\n```text\nsbin\n```\n\n```text\n/usr/local/\n```\n\n```text\nrabbitmq-server\n```\n\n```text\n/usr/local/Cellar/rabbitmq/3.7.9/sbin/rabbitmq-server\n```\n\n```text\n~ $ rabbitmq-server\n\n ## ##\n ## ## RabbitMQ 3.7.15. Copyright (C) 2007-2019 Pivotal Software, Inc.\n ########## Licensed under the MPL. See https://www.rabbitmq.com/\n ###### ##\n ########## Logs: /Users/santoshsindham/homebrew/var/log/rabbitmq/rabbit@localhost.log\n /Users/santoshsindham/homebrew/var/log/rabbitmq/rabbit@localhost_upgrade.log\n\n Starting broker...\n completed with 6 plugins.\n```\n\n```text\n/usr/local/sbin/\n```\n\n```text\n/usr/local/Cellar/rabbitmq/\n```\n\n```text\nFinder\n```\n\n```text\nrabbitmq-server\n```\n\n```text\nFinder\n```\n\n```text\nrabbitmq-server\n```\n\n```text\n/Users/${USER}/homebrew/Cellar/rabbitmq/3.7.15/sbin\n```\n\n```text\n~/.bash_profile\n```\n\n```text\nPATH\n```\n\n```text\nexport PATH=$PATH:/Users/${USER}/homebrew/Cellar/rabbitmq/3.7.15/sbin\n```\n\n```text\nsource ~/.bash_profile\n```\n\n```text\nexport PATH=$PATH:/usr/local/opt/rabbitmq/sbin\n```\n\n========================================\n\nComments:\n- Strangely, I don't see to have a `/usr/local/sbin` folder in the first place.\n- Strange, I only see the directory after installing rabbitmq on OSX using homebrew. What is your OS?\n- I'm using Sierra 10.12.3 ... your command did not work for me. However, this command worked when I put it inside my `.zshrc` file: `PATH=$PATH:/usr/local/sbin`\n- Don't forget to restart your terminal after this... (on mac)\n- FYI to **stop** `brew services stop rabbitmq`\n- In case you're using the Fish shell, add `set PATH $PATH /usr/local/Cellar/rabbitmq/3.7.16/sbin` (with the appropriate version number) to `~/.config/fish/config.fish`.","metadata":{"transformedAt":"2026-08-18T18:33:20.116Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":54,"totalLines":281,"estimatedTokens":1062}}59{"id":"stack-52819237","source":"stackoverflow","questionId":52819237,"title":"How to add plugin to RabbitMQ docker image?","tags":["docker","rabbitmq"],"text":"Title: How to add plugin to RabbitMQ docker image?\nTags: docker, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am using `rabbitmq:3-management` from https://hub.docker.com/_/rabbitmq/ however, it is missing a plugin that I need `rabbitmq_delayed_message_exchange`. \n\nHow can I enable this plugin if it is not available in the image?\n\n========================================\n\nTop Answer:\nAccording to https://hub.docker.com/_/rabbitmq it seems there is a second option not yet evoked here.\nI feel accepted answer is the best solution for it allows more tweaks, but one might prefer the other method:\n\n### Enabling Plugins\n\n*[Accepted answer...]*\n\n**You can also mount a file at `/etc/rabbitmq/enabled_plugins` with contents as an erlang list of atoms ending with a period.**\n\n**Example `enabled_plugins`**\n\n```\n[rabbitmq_federation_management,rabbitmq_management,rabbitmq_mqtt,rabbitmq_stomp].\n```\n\n**DISCLAIMER**: I have not tried it yet.\n\n========================================\n\nCode:\n```text\nrabbitmq:3-management\n```\n\n```text\nrabbitmq_delayed_message_exchange\n```\n\n```text\nFROM rabbitmq:3.7-management\n\nRUN apt-get update && \\\napt-get install -y curl unzip\n\nRUN curl https://dl.bintray.com/rabbitmq/community-plugins/3.7.x/rabbitmq_delayed_message_exchange/rabbitmq_delayed_message_exchange-20171201-3.7.x.zip > rabbitmq_delayed_message_exchange-20171201-3.7.x.zip && \\\nunzip rabbitmq_delayed_message_exchange-20171201-3.7.x.zip && \\\nrm -f rabbitmq_delayed_message_exchange-20171201-3.7.x.zip && \\\nmv rabbitmq_delayed_message_exchange-20171201-3.7.x.ez plugins/\n\nRUN rabbitmq-plugins enable rabbitmq_delayed_message_exchange\n```\n\n```text\nFROM rabbitmq:3.7.18-management\n COPY ./rabbitmq_delayed_message_exchange-20171201-3.7.x.ez /opt/rabbitmq/plugins/\n RUN rabbitmq-plugins enable rabbitmq_delayed_message_exchange\n```\n\n```text\nrabbitmq:\n image: rabbitmq-custom\n ports:\n - \"5672:5672\"\n - \"15672:15672\"\n```\n\n```text\ndocker build -t rabbitmq-custom .\n```\n\n```text\ndocker-compose up\n```\n\n```text\n[rabbitmq_federation_management,rabbitmq_management,rabbitmq_mqtt,rabbitmq_stomp].\n```\n\n```text\n/etc/rabbitmq/enabled_plugins\n```\n\n```text\nenabled_plugins\n```\n\n```text\nFROM rabbitmq:3.9-management\n\nCOPY rabbitmq.conf /etc/rabbitmq/rabbitmq.conf\n\nRUN apt-get -o Acquire::Check-Date=false update && apt-get install -y curl\n\nRUN curl -L https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/releases/download/3.9.0/rabbitmq_delayed_message_exchange-3.9.0.ez > $RABBITMQ_HOME/plugins/rabbitmq_delayed_message_exchange-3.9.0.ez\n\nRUN chown rabbitmq:rabbitmq $RABBITMQ_HOME/plugins/rabbitmq_delayed_message_exchange-3.9.0.ez\n\nRUN rabbitmq-plugins enable rabbitmq_delayed_message_exchange\n```\n\n```text\nrabbitmq3:\n container_name: \"rabbitmq\"\n image: rabbitmq:3.8-management-alpine\n environment:\n - RABBITMQ_DEFAULT_USER=local\n - RABBITMQ_DEFAULT_PASS=localpwd\n - RABBITMQ_PLUGINS_DIR=/opt/rabbitmq/plugins:/usr/lib/rabbitmq/plugins\n ports:\n # AMQP protocol port\n - '5672:5672'\n # HTTP management UI\n - '15672:15672'\n volumes:\n - ./rabbit/enabled_plugins:/etc/rabbitmq/enabled_plugins\n - ./rabbit/plugins:/usr/lib/rabbitmq/plugins\n```\n\n```text\n[rabbitmq_management, rabbitmq_message_deduplication].\n```\n\n```text\nFROM rabbitmq:3.10-management-alpine\n\nRUN apk --no-cache add curl\n\nRUN curl -L https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/releases/download/3.10.2/rabbitmq_delayed_message_exchange-3.10.2.ez > rabbitmq_delayed_message_exchange-3.10.2.ez && \\\nmv rabbitmq_delayed_message_exchange-3.10.2.ez plugins/\n\nRUN rabbitmq-plugins enable rabbitmq_delayed_message_exchange\n```\n\n```text\ndocker run --rm --name rabbitmq --hostname rabbitmq -p 5672:5672 -p 15672:15672 -p 15674:15674 \\\n -e RABBITMQ_DEFAULT_USER=test -e RABBITMQ_DEFAULT_PASS=test \\\n -e RABBITMQ_STOMP_DEFAULT_USER=test -e RABBITMQ_STOMP_DEFAULT_PASS=test \\\n -v ./enabled_plugins:/etc/rabbitmq/enabled_plugins \\\n rabbitmq:4-management\n```\n\n```text\n2025-04-25 11:00:27.639324+00:00 [info] <0.609.0> Server startup complete; 6 plugins started.\n2025-04-25 11:00:27.639324+00:00 [info] <0.609.0> * rabbitmq_prometheus\n2025-04-25 11:00:27.639324+00:00 [info] <0.609.0> * rabbitmq_web_stomp\n2025-04-25 11:00:27.639324+00:00 [info] <0.609.0> * rabbitmq_stomp\n2025-04-25 11:00:27.639324+00:00 [info] <0.609.0> * rabbitmq_management\n2025-04-25 11:00:27.639324+00:00 [info] <0.609.0> * rabbitmq_management_agent\n2025-04-25 11:00:27.639324+00:00 [info] <0.609.0> * rabbitmq_web_dispatch\n```\n\n```text\nenabled_plugins\n```\n\n```text\n[rabbitmq_management,rabbitmq_prometheus,rabbitmq_web_stomp].\n```\n\n```text\n-v ./<path-to-file>/enabled_plugins:/etc/rabbitmq/enabled_plugins\n```\n\n========================================\n\nComments:\n- Have you considered creating your own Docker image using the `rabbimq:3-management` as a base and just installing the plugin?\n- @UroshT. Thanks! I've never done that before, but I gave it a shot and posted an answer. It seems to work. How's my custom Docker image look? I found it strange that I had to install basics like curl and unzip.\n- \"I found it strange that I had to install basics like curl/unzip\" - they're not needed in most images, so why include them?\n- @SergioTulentsev Well to install the RabbitMQ plugin it seems like I needed curl to download it, then I had to unzip it to get the .ez file.\n- @kayla but they were not needed to *run* rabbitmq from the base image, so no wonder they aren't there.\n- Yes, Sergio has a point, the images are optimized so that they include only the necessary for deployment of rabbitmq. If it worked, accept your own answer so that the people having the same issue as you know how to solve it.\n- The Link to the (currently) latest version can be found here: dl.bintray.com/rabbitmq/community-plugins/3.8.x/…\n- A built a different version based on @atkayla one justo to obtain the ez file from official github repository. check here: stackoverflow.com/a/73615616/6548978\n- This really should be marked as the most effective solution.\n- I think this solution would only work for the plugins included in rabbitmq by default. The plugin in this question is not one of the core plugins listed here: rabbitmq.com/plugins.html\n- `RABBITMQ_PLUGINS_DIR=/opt/rabbitmq/plugins:/usr/lib/rabbitmq‌​/plugins` this trick helped me to enable plugin","metadata":{"transformedAt":"2026-08-18T18:33:20.120Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":19,"totalLines":179,"estimatedTokens":1594}}60{"id":"stack-22989833","source":"stackoverflow","questionId":22989833,"title":"RabbitMQ - How many queues can RabbitMQ handle on a single server?","tags":["rabbitmq","message-queue","amqp"],"text":"Title: RabbitMQ - How many queues can RabbitMQ handle on a single server?\nTags: rabbitmq, message-queue, amqp\nSource: Stack Overflow\n\nQuestion:\nWhat's the maximum number of queues that RabbitMQ can handle on a single server?\n\nDoes it depend on RAM? Does it depends on erlang processes?\n\n========================================\n\nTop Answer:\nThis post can help you:\n\nhttp://rabbitmq.1065348.n5.nabble.com/Max-messages-allowed-in-a-queue-in-RabbitMQ-tp26063p26066.html\n\n- Max queues allowed in RabbitMQ?\n\nThousands (or even tens of thousands) of queues should be no problem\nat all, though each object (e.g., queues, exchanges, bindings, etc)\nwill take up some memory and/or disk space. By default, Erlang will\nenforce a maximum number of concurrent processes (i.e., lightweight\nthreads) at around 32768 IIRC. Each queue is managed by its own\nprocess and each connection can result in several more, so if you're\nplanning on having a very large number of active queues in a single\nnode (?) and using them all at the same time, then you may need to\ntweak the emulator arguments rabbit passes the VM by setting +P to a higher limit.\n\nYou're also likely to use up many Gb just with the overhead for each\nqueue / connection pretty fast, so you're going to need a pretty meaty\nserver to handle millions of both. Tens of thousands should be no\nproblem at all, providing they fit into RAM.\n\n========================================\n\nComments:\n- Can RabbitMQ Server handle 10 million queues? how much memory will my server need?\n- @N.B. - No its not hardware related :) , its about processing requests about RabbitMQ\n- I do agree that i should consider hardware into consideration but hardware engineer cannot answer this question :) ..this question needs knowledge of rabbitMQ server, messaging queue protocol and last but not least how much % of memory rabbitMQ takes ( i think its 40% of total RAM )\n- and ofcourse people like you can award this post with -1 but I don't mine, people who understand this question will answer surely :)\n- Nice post. basically I want technical answer For Ex. 1Gb RAM can hangle this much request ..like this - so that I can decide should I increase RAM\n- As you can read on the post: \"so if you're planning on having a very large number of active queues in a single node (?) and using them all at the same time, then you may need to tweak the emulator arguments rabbit passes the VM by setting +P to a higher limit. \" So you have to create an real simulation, beacuse the numer depends form the activies.. connections.. then you can dedice.","metadata":{"transformedAt":"2026-08-18T18:33:20.120Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":42,"estimatedTokens":641}}61{"id":"stack-29872998","source":"stackoverflow","questionId":29872998,"title":"Capture Heroku SIGTERM in Celery workers to shutdown worker gracefully","tags":["python","heroku","rabbitmq","celery","sigterm"],"text":"Title: Capture Heroku SIGTERM in Celery workers to shutdown worker gracefully\nTags: python, heroku, rabbitmq, celery, sigterm\nSource: Stack Overflow\n\nQuestion:\nI've done a ton of research on this, and I'm surprised I haven't found a good answer to this yet anywhere.\n\nI'm running a large application on Heroku, and I have certain celery tasks that run for a very long time processing, and at the end of the task save a result. Every time I redeploy on Heroku, it sends SIGTERM (and eventually, SIGKILL) and kills my running worker. I'm trying to find a way for the worker instance to shut itself down gracefully and re-queue itself for processing later so that eventually we can save the required result instead of losing the queued task.\n\nI cannot find a way that works to have the worker listen for SIGTERM properly. The closest I've gotten, which works when running `python manage.py celeryd` directly but **NOT** when emulating Heroku using foreman, is the following:\n\n```\n@app.task(bind=True, max_retries=1)\ndef slow(self, x):\n try:\n for x in range(100):\n print 'x: ' + unicode(x)\n time.sleep(10)\n except exceptions.MaxRetriesExceededError:\n logger.error('whoa')\n except (exceptions.WorkerShutdown, exceptions.WorkerTerminate) as exc:\n logger.error(u'retrying, ' + unicode(exc))\n raise self.retry(exc=exc, countdown=10)\n except (KeyboardInterrupt, SystemExit) as exc:\n print 'retrying'\n raise self.retry(exc=exc, countdown=10)\n else:\n return x\n finally:\n logger.info('task ended!')\n```\n\nWhen I start this celery task running within foreman and hit Ctrl+C, the following happens:\n\n```\n^CSIGINT received\n22:20:59 system | sending SIGTERM to all processes\n22:20:59 web.1 | exited with code 0\n22:21:04 system | sending SIGKILL to all processes\nKilled: 9\n```\n\nSo it's clear that none of the celery exceptions, nor the `KeyboardInterrupt` or `SystemExit` exceptions I've seen in other posts, properly catch SIGTERM and shut down the worker.\n\nWhat is the right way to do this?\n\n========================================\n\nTop Answer:\ncelery was unfortunately not designed to do clean shutdown. EVER. I mean it. celery workers respond to SIGTERM but if a task is incomplete, the worker processes will wait to finish the task and only then exit. In which case, you can send it SIGKILL if the workers don't shut down in a reasonable time but there will be a loss of information in this case i.e. you may not know which jobs remained incomplete.\n\n========================================\n\nCode:\n```text\n@app.task(bind=True, max_retries=1)\ndef slow(self, x):\n try:\n for x in range(100):\n print 'x: ' + unicode(x)\n time.sleep(10)\n except exceptions.MaxRetriesExceededError:\n logger.error('whoa')\n except (exceptions.WorkerShutdown, exceptions.WorkerTerminate) as exc:\n logger.error(u'retrying, ' + unicode(exc))\n raise self.retry(exc=exc, countdown=10)\n except (KeyboardInterrupt, SystemExit) as exc:\n print 'retrying'\n raise self.retry(exc=exc, countdown=10)\n else:\n return x\n finally:\n logger.info('task ended!')\n```\n\n```text\n^CSIGINT received\n22:20:59 system | sending SIGTERM to all processes\n22:20:59 web.1 | exited with code 0\n22:21:04 system | sending SIGKILL to all processes\nKilled: 9\n```\n\n```text\npython manage.py celeryd\n```\n\n```text\nKeyboardInterrupt\n```\n\n```text\nSystemExit\n```\n\n```text\n$ REMAP_SIGTERM=SIGQUIT celery -A proj worker -l info\n```\n\n========================================\n\nComments:\n- celery.readthedocs.org/en/latest/userguide/… seems to indicate that the main worker will always intercept SIGTERM.\n- Right--so is there any way to have the main worker propagate it to the children?\n- This is a problem which I have also never found a great solution. I tend to handle it in application logic by making sure my tasks are idempotent and tracking started and completed tasks such that I can automatically restart a given task when my application starts.\n- Has anyone solved this already? I'm also trying to find a solution for this - I need to correctly stop running tasks before deployment, so that they're either finished completely or rescheduled for after the deployment restart.\n- As you can persist the task result, therefore it should be feasible to check on task status etc. at the application layer and recover the situation.\n- just out of curiosity, how does the broker (say.. rabbitmq) distinguish between an anacknowledged message (task) because: a) the task is still being processed b) the worker died, it should be re-delivered","metadata":{"transformedAt":"2026-08-18T18:33:20.120Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":108,"estimatedTokens":1142}}62{"id":"stack-29226590","source":"stackoverflow","questionId":29226590,"title":"RabbitMQ: how to limit consuming rate","tags":["node.js","performance","rabbitmq","message-queue"],"text":"Title: RabbitMQ: how to limit consuming rate\nTags: node.js, performance, rabbitmq, message-queue\nSource: Stack Overflow\n\nQuestion:\nI need to limit the rate of consuming messages from rabbitmq queue.\n\nI have found many suggestions, but most of them offer to use prefetch option. But this option doesn't do what I need. Even if I set prefetch to 1 the rate is about 6000 messages/sec. This is too many for consumer.\n\nI need to limit for example about 70 to 200 messages per second. This means consuming one message every 5-14ms. No simultaneous messages.\n\nI'm using Node.JS with amqp.node library.\n\n========================================\n\nTop Answer:\nImplementing a token bucket might help:\nhttps://en.wikipedia.org/wiki/Token_bucket\n\nYou can write a producer that produces to the \"token bucket queue\" at a fixed rate with a TTL on the message (maybe expires after a second?) or just set a maximum queue size equal to your rate per second. Consumers that receive a \"normal queue\" message must also receive a \"token bucket queue\" message in order to process the message effectively rate limiting the application.\n\nNodeJS + amqplib Example:\n\n```\nvar queueName = 'my_token_bucket';\nrabbitChannel.assertQueue(queueName, {durable: true, messageTtl: 1000, maxLength: bucket.ratePerSecond});\nwriteToken();\n\nfunction writeToken() {\n rabbitChannel.sendToQueue(queueName, new Buffer(new Date().toISOString()), {persistent: true});\n setTimeout(writeToken, 1000 / bucket.ratePerSecond);\n}\n```\n\n========================================\n\nCode:\n```text\nvar queueName = 'my_token_bucket';\nrabbitChannel.assertQueue(queueName, {durable: true, messageTtl: 1000, maxLength: bucket.ratePerSecond});\nwriteToken();\n\nfunction writeToken() {\n rabbitChannel.sendToQueue(queueName, new Buffer(new Date().toISOString()), {persistent: true});\n setTimeout(writeToken, 1000 / bucket.ratePerSecond);\n}\n```\n\n```text\nchannel.consume(transactionQueueName, async (data) => {\n let dataNew = JSON.parse(data.content);\n const processedTransaction = await seperateATransaction(dataNew);\n // delay ack to avoid duplicate entry !important dont remove the settimeout\n setTimeout(function(){\n channel.ack(data);\n },200);\n });\n```\n\n========================================\n\nComments:\n- Look at this answer: stackoverflow.com/a/19163868/952310\n- I'd assume that you are using prefetch count in combination with message acks, otherwise prefetch count is meaningless\n- Yep. I've already found a solution. I use module nanotimer from npm for calculation delays. Then I calculate delay = 1 / [message_per_second] in nanoseconds. Then I consume message with prefetch = 1 Then I calculate really delay as delay - [processing_message_time] Then I make timeout = really delay before sending ack for the message It works perfectly. Thank to all.\n- One way to do it without having to write code into each consumer is to start another queue at the front of the existing queue and write a rate limited broker between the two queues. So messages will go \"Main Input\"->\"New Queue\"->\"Rate limiter\" ->\"Existing Queue\"->\"Many Consumers\". This way the connection between the existing queue and the multiple consumers is left untouched.\n- This will work fine as long as you only have one consumer: One of the big selling points to using RabbitMQ of course would be the ability to scale up to many consumers.\n- Great suggestion for a dedicated token bucket queue, thank you!\n- No problem, it is working great for me right now with minimal work required!\n- May I ask where are you producing token bucket messages? Of course implementing producing process is trivial, but if feels less then optimal both from performance and reliability point of view. I'm trying to find some way to generate messages at constant rate on RabbitMQ side (may be special exchange type), but I don't see anything readily available.\n- @MichaelKorbakov writing your own on the TCP socket level would definitely be more efficient but lots more could go wrong. This works fine for me (in Node.js)\n- This is an elegant solution to a vexing problem. Thank you for the suggestion!\n- Great idea @JohnCulviner, that helped me a lot. Can you also explain how you are consuming the tokens on your \"workers\"? I thought I would just always set prefetch to 5 for instance so that I have always 5 tokens in spare and once I acknowledge these I will get new ones. \"Unfortunately\" I constantly get new tokens once they are expired, so I assume you are simply checking if you can use this token once you receive it, instead of keeping it idling for the next second right?\n- @kentor this was awhile ago but i don't think I had any issue with getting expired tokens due to the messageTtl and maxLength settings. if you have that issue maybe check for the message having expired when you get it though. This was in nodejs perhaps that could be a difference too","metadata":{"transformedAt":"2026-08-18T18:33:20.120Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":74,"estimatedTokens":1224}}63{"id":"stack-6148381","source":"stackoverflow","questionId":6148381,"title":"Persistent message with topic exchange","tags":["rabbitmq","amqp"],"text":"Title: Persistent message with topic exchange\nTags: rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI have set up a 'topic' exchange. The consumers may be started after the publisher. I'd like the consumers to be able to receive messages that have been sent before they were up, and that was not consumed yet.\n\nThe exchange is set up with the following parameters:\n\n```\nexchange_type => 'topic'\ndurable => 1\nauto_delete => 0\npassive => 0\n```\n\nThe messages are published with this parameter:\n\n```\ndelivery_mode => 2\n```\n\nConsumers use get() to retrieve the messages from the exchange.\n\nUnfortunately, any message published before any client was up is lost. I have used different combinations.\n\nI guess my problem is that the exchange does not hold messages. Maybe I need to have a queue between the publisher and the consumer. But this does not seem to work with a 'topic' exchange where messages are routed by a key.\n\nHow should I proceed? I use the `Perl` binding `Net::RabbitMQ` (shouldn't matter) and `RabbitMQ 2.2.0`.\n\n========================================\n\nTop Answer:\nAs mentioned by Brian an exchange does not store messages and is mainly responsible for routing messages to either another exchange/s or queue/s. If the exchange is not bound to a queue, then all messages sent to that exchange will be 'lost'.\n\nYou should not need to declare fixed client queues in the publisher script since this might not be scalable. Queues can be created dynamically by your publishers and routed internally using exchange-to-exchange binding.\n\nRabbitMQ supports exchange-to-exchange bindings that will allow for topology flexibility, decoupling and other benefits. You can read more here at RabbitMQ Exchange to Exchange Bindings [AMPQ]\n\nRabbitMQ Exchange To Exchange Binding\n\nExample Python code to create exchange-to-exchange binding with persistence if no consumer is present using queue.\n\n```\n#!/usr/bin/env python\nimport pika\nimport sys\n \n \nconnection = pika.BlockingConnection(pika.ConnectionParameters(\nhost='localhost'))\nchannel = connection.channel()\n \n \n#Declares the entry exchange to be used by all producers to send messages. Could be external producers as well\nchannel.exchange_declare(exchange='data_gateway',\nexchange_type='fanout',\ndurable=True,\nauto_delete=False)\n \n#Declares the processing exchange to be used.Routes messages to various queues. For internal use only\nchannel.exchange_declare(exchange='data_distributor',\nexchange_type='topic',\ndurable=True,\nauto_delete=False)\n \n#Binds the external/producer facing exchange to the internal exchange\nchannel.exchange_bind(destination='data_distributor',source='data_gateway')\n \n##Create Durable Queues binded to the data_distributor exchange\nchannel.queue_declare(queue='trade_db',durable=True)\nchannel.queue_declare(queue='trade_stream_service',durable=True)\nchannel.queue_declare(queue='ticker_db',durable=True)\nchannel.queue_declare(queue='ticker_stream_service',durable=True)\nchannel.queue_declare(queue='orderbook_db',durable=True)\nchannel.queue_declare(queue='orderbook_stream_service',durable=True)\n \n#Bind queues to exchanges and correct routing key. Allows for messages to be saved when no consumer is present\nchannel.queue_bind(queue='orderbook_db',exchange='data_distributor',routing_key='*.*.orderbook')\nchannel.queue_bind(queue='orderbook_stream_service',exchange='data_distributor',routing_key='*.*.orderbook')\nchannel.queue_bind(queue='ticker_db',exchange='data_distributor',routing_key='*.*.ticker')\nchannel.queue_bind(queue='ticker_stream_service',exchange='data_distributor',routing_key='*.*.ticker')\nchannel.queue_bind(queue='trade_db',exchange='data_distributor',routing_key='*.*.trade')\nchannel.queue_bind(queue='trade_stream_service',exchange='data_distributor',routing_key='*.*.trade')\n```\n\n========================================\n\nCode:\n```text\nexchange_type => 'topic'\ndurable => 1\nauto_delete => 0\npassive => 0\n```\n\n```text\ndelivery_mode => 2\n```\n\n```text\nPerl\n```\n\n```text\nNet::RabbitMQ\n```\n\n```text\nRabbitMQ 2.2.0\n```\n\n```py\n#!/usr/bin/env python\nimport pika\nimport sys\n \n \nconnection = pika.BlockingConnection(pika.ConnectionParameters(\nhost='localhost'))\nchannel = connection.channel()\n \n \n#Declares the entry exchange to be used by all producers to send messages. Could be external producers as well\nchannel.exchange_declare(exchange='data_gateway',\nexchange_type='fanout',\ndurable=True,\nauto_delete=False)\n \n#Declares the processing exchange to be used.Routes messages to various queues. For internal use only\nchannel.exchange_declare(exchange='data_distributor',\nexchange_type='topic',\ndurable=True,\nauto_delete=False)\n \n#Binds the external/producer facing exchange to the internal exchange\nchannel.exchange_bind(destination='data_distributor',source='data_gateway')\n \n##Create Durable Queues binded to the data_distributor exchange\nchannel.queue_declare(queue='trade_db',durable=True)\nchannel.queue_declare(queue='trade_stream_service',durable=True)\nchannel.queue_declare(queue='ticker_db',durable=True)\nchannel.queue_declare(queue='ticker_stream_service',durable=True)\nchannel.queue_declare(queue='orderbook_db',durable=True)\nchannel.queue_declare(queue='orderbook_stream_service',durable=True)\n \n#Bind queues to exchanges and correct routing key. Allows for messages to be saved when no consumer is present\nchannel.queue_bind(queue='orderbook_db',exchange='data_distributor',routing_key='*.*.orderbook')\nchannel.queue_bind(queue='orderbook_stream_service',exchange='data_distributor',routing_key='*.*.orderbook')\nchannel.queue_bind(queue='ticker_db',exchange='data_distributor',routing_key='*.*.ticker')\nchannel.queue_bind(queue='ticker_stream_service',exchange='data_distributor',routing_key='*.*.ticker')\nchannel.queue_bind(queue='trade_db',exchange='data_distributor',routing_key='*.*.trade')\nchannel.queue_bind(queue='trade_stream_service',exchange='data_distributor',routing_key='*.*.trade')\n```\n\n```text\nchannel.QueueDeclare(queue: \"hello\",\n durable: true,\n ....);\n```\n\n```text\nvar properties = channel.CreateBasicProperties();\nproperties.Persistent = true;\n```\n\n```text\nqueue\n```\n\n```text\nmessages\n```\n\n```text\nqueue\n```\n\n```text\nRabbitMQ\n```\n\n```text\nIBasicProperties.SetPersistent\n```\n\n========================================\n\nComments:\n- OK, so the solution is to declare fixed client queues in the publisher script. Of course this requires me to know in advances how many consumers there will be.\n- That's true, assuming that each consumer will need its own queue. But the main question you need to answer is, \"Will those consumers need all your historical messages which were sent before they ever came into being?\". If they won't care about old messages, they can just declare their own queue on startup and receive all messages from that point on, but nothing older.\n- Applications \"declare\" queues and then the MQ broker creates them if they do not yet exist. Although it makes sense for listener applications to declare queues, and not sender applications, you run into the problem that you have seen. It is probably the best solution to declare queues, declare exchanges, create vhost, etc. before running an app.\n- The \"Eat All Messages\" queue is missing, and according to me the messages will still not arrive at 'late' subscribers\n- Explain ? It definitely answers the OP questions and works. Be more constructive with your comments\n- This is actually could work @KurtPattyn and @flyer as you at anytime can create a new consumer for `Eat All Messages` that can \"recover\" not processed messages from there, and route them to right place\n- what @Kostanos said, just adding: recovering consumers must not consume the messages (no auto ack, close connection to that queue once you've seen all messages). This way you can use rabbitmq as event store - not sure they intended that.\n- This \"smells\". As mbx wrote, this configures rabbitmq to be kind of an event store, and that's not how it is supposed to be used, imho. Rather look into using Kafka for your use case. The answer from Brian Kelly explains it perfectly.\n- It is not being used as an event store. As the poster requested and stated clients might not be connected and so the messages have to be temporarily queued before they get delivered. The new and shinny \"Kafka\" was not really ready at that time. How about submitting a full answer? Enjoy the rest of your day.","metadata":{"transformedAt":"2026-08-18T18:33:20.120Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":13,"totalLines":198,"estimatedTokens":2098}}64{"id":"stack-19806313","source":"stackoverflow","questionId":19806313,"title":"How to disable RabbitMQ default tcp listening port - 5672","tags":["rabbitmq"],"text":"Title: How to disable RabbitMQ default tcp listening port - 5672\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have configured the RabbitMQ `rabbitmq.config` file with new port number i.e. 5671 with SSL.\n\nNow I want to disable the default port i.e. 5672.\n\n**Config file as below :-**\n\n```\n[\n {rabbit, [\n {ssl_listeners, [5671]},\n {ssl_options, [{cacertfile,\"/ay/app/xxx/softwares/rabbitmq_server-3.1.1/etc/ssl/cacert.pem\"},\n {certfile,\"/ay/app/xxx/softwares/rabbitmq_server-3.1.1/etc/ssl/cert.pem\"},\n {keyfile,\"/ay/app/xxx/softwares/rabbitmq_server-3.1.1/etc/ssl/key.pem\"},\n {verify,verify_peer},\n {fail_if_no_peer_cert,false},\n\n {ciphers,[{dhe_rsa,aes_256_cbc,sha},\n {dhe_dss,aes_256_cbc,sha},\n {rsa,aes_256_cbc,sha}]}\n\n ]\n\n }\n ]}\n].\n```\n\nNow its working on both port 5671 and 5672.But I need to disable the port 5672.\nGive some comments or suggestion.\n\nThanks in advance.\n\n========================================\n\nTop Answer:\nIt appears that to disable non-ssl listening with the new file format, you can do the following:\n\n```\nlisteners.tcp = none\n```\n\nThis has the same effect as the other 3.7 answer, but removes the need to do it in the advanced.config.\n\n========================================\n\nCode:\n```text\n[\n {rabbit, [\n {ssl_listeners, [5671]},\n {ssl_options, [{cacertfile,\"/ay/app/xxx/softwares/rabbitmq_server-3.1.1/etc/ssl/cacert.pem\"},\n {certfile,\"/ay/app/xxx/softwares/rabbitmq_server-3.1.1/etc/ssl/cert.pem\"},\n {keyfile,\"/ay/app/xxx/softwares/rabbitmq_server-3.1.1/etc/ssl/key.pem\"},\n {verify,verify_peer},\n {fail_if_no_peer_cert,false},\n\n {ciphers,[{dhe_rsa,aes_256_cbc,sha},\n {dhe_dss,aes_256_cbc,sha},\n {rsa,aes_256_cbc,sha}]}\n\n ]\n\n }\n ]}\n].\n```\n\n```text\nrabbitmq.config\n```\n\n```text\n[\n {rabbit, [\n {tcp_listeners, []},\n {ssl_listeners, [5671]},\n {ssl_options, [{cacertfile,\"/ay/app/xxx/softwares/rabbitmq_server-3.1.1/etc/ssl/cacert.pem\"},\n {certfile,\"/ay/app/xxx/softwares/rabbitmq_server-3.1.1/etc/ssl/cert.pem\"},\n {keyfile,\"/ay/app/xxx/softwares/rabbitmq_server-3.1.1/etc/ssl/key.pem\"},\n {verify,verify_peer},\n {fail_if_no_peer_cert,false},\n\n {ciphers,[{dhe_rsa,aes_256_cbc,sha},\n {dhe_dss,aes_256_cbc,sha},\n {rsa,aes_256_cbc,sha}]}\n\n ]\n\n }\n ]}\n].\n```\n\n```text\n{tcp_listeners, []}\n```\n\n```text\nlisteners.ssl.1 = 5671\nssl_options.cacertfile = /path/to/testca/cacert.pem\nssl_options.certfile = /path/to/server/cert.pem\nssl_options.keyfile = /path/to/server/key.pem\nssl_options.verify = verify_peer\nssl_options.fail_if_no_peer_cert = false\n```\n\n```text\n[\n {rabbit,\n [{tcp_listeners, []}\n ]}\n].\n```\n\n```text\nlisteners.tcp = none\n```\n\n========================================\n\nComments:\n- Fix numbers of ports in question. 572 -> 5672 and etc\n- Be arware that the option `fail_if_no_peer_cert, false` still allows clients without a certificate to connect. Read more here for information on the `fail_if_no_peer_cert` setting...\n- Is it significant whether advanced.config is used for the second part, instead of rabbitmq.conf?\n- I tried a few things to get it working in rabbitmq.conf (not rabbitmq.config) but didn't have any luck. Feel free to edit my answer if you get it working!\n- From rabbitmq documentation: `Some configuration settings are not possible or are difficult to configure using the sysctl format. As such, it is possible to use an additional config file in the Erlang term format (same as rabbitmq.config). That file is commonly named advanced.config. It will be merged with the configuration provided in rabbitmq.conf.` I guess this is why up to date...\n- I didn't work for me in rabbitmq-server-3.8. Have you had a chance to test this setting in 3.8?\n- @mrc02_kr That's the documentation recommended way, rabbitmq.com/networking.html#single-stack-ipv4. Seems to have worked for me with 3.8.11.","metadata":{"transformedAt":"2026-08-18T18:33:20.120Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":133,"estimatedTokens":1001}}65{"id":"stack-28258392","source":"stackoverflow","questionId":28258392,"title":"RabbitMQ fails on Error: unable to connect to node rabbit@TPAJ05421843: nodedown","tags":["windows","erlang","rabbitmq"],"text":"Title: RabbitMQ fails on Error: unable to connect to node rabbit@TPAJ05421843: nodedown\nTags: windows, erlang, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nOn a Windows 7 Enterprise machine, I made a fresh install of Erlang 17.4 and RabbitMQ 3.4.3 x64. The installation was successful and uneventful. \n\nI have not yet tried to create my first queue or exchange, but I already see trouble. This problem is similar to another SO post, but that other post appears to involve clustering, which I don't have. Furthermore, that other poster can circumvent his issue by restarting the RabbitMQ service; that approach does not work for me.\n\nMy \"nodedown\" problem is evident at the RabbitMQ command prompt:\n\n C:\\Program Files (x86)\\RabbitMQ Server\\rabbitmq_server-3.4.3\\sbin>rabbitmqctl status\n Status of node rabbit@TPAJ05421843 ...\n\n Error: unable to connect to node rabbit@TPAJ05421843: nodedown\n\n \n \n\n### DIAGNOSTICS\n\n \n attempted to contact: [rabbit@TPAJ05421843]\n\n \n rabbit@TPAJ05421843:\n\n * connected to epmd (port 4369) on TPAJ05421843\n\n * epmd reports: node 'rabbit' not running at all\n\n other nodes on TPAJ05421843: ['RabbitMQ']\n\n * suggestion: start the node\n\n \n current node details:\n\n - node name: 'rabbitmqctl-19884@TPAJ05421843'\n\n - home dir: H:\\\n\n - cookie hash: PD4QQCYrf0TME9vIko3Xuw==\n\nBased on the above, I chose to check the status of the node explicitly named 'RabbitMQ'. I get this:\n\n C:\\Program Files (x86)\\RabbitMQ Server\\rabbitmq_server-3.4.3\\sbin>rabbitmqctl -n RabbitMQ status\n\n Status of node 'RabbitMQ@TPAJ05421843' ...\n\n Error: unable to connect to node 'RabbitMQ@TPAJ05421843': nodedown\n\n \n \n\n### DIAGNOSTICS\n\n \n attempted to contact: ['RabbitMQ@TPAJ05421843']\n\n \n RabbitMQ@TPAJ05421843:\n\n * connected to epmd (port 4369) on TPAJ05421843\n\n * epmd reports node 'RabbitMQ' running on port 59301\n\n * TCP connection succeeded but Erlang distribution failed\n\n * suggestion: hostname mismatch?\n\n * suggestion: is the cookie set correctly?\n\n \n current node details:\n\n - node name: 'rabbitmqctl-23076@TPAJ05421843'\n\n - home dir: H:\\\n\n - cookie hash: PD4QQCYrf0TME9vIko3Xuw==\n\nOk, this is barely better since at least it acknowledges 'RabbitMQ' running on port 59301. But what the heck could it mean that \"Erlang distribution failed\"?\n\nWhen I try to research this topic, I found articles saying \"be sure you have matched cookies.\" Based on that I found this article, which claims the \"cookie mismatch\" does not pertain to me, because I have not created (nor intend to create) a RabbitMQ cluster.\n\nWhat should I do?\n\n========================================\n\nTop Answer:\nAs @eddyP commented, I had two different Erlang cookie files:\n\n- A *server* cookie file, located at `$env:WINDIR\\system32\\config\\systemprofile\\.erlang.cookie` (prior to Erlang 20.2 it was located at `$env:WINDIR\\.erlang.cookie`).\n\n- A *client* cookie file, located at `$env:USERPROFILE\\.erlang.cookie`.\n\nCopying the server cookie file over the client one, so that both files were the same, fixed the problem for me.\n\nFor further details, see \"How Nodes (and CLI tools) Authenticate to Each Other: the Erlang Cookie\".\n\n========================================\n\nCode:\n```text\nrabbitmqctl\n```\n\n```text\nrabbitmq-server restart\n```\n\n```text\nc:\\Users\\xxx\\AppData\\Roaming\\RabbitMQ\\db\\\n```\n\n```text\nxxx\n```\n\n```text\nnet start rabbitmq\n```\n\n```text\nrabbitmqctl status\n```\n\n```text\n$env:WINDIR\\system32\\config\\systemprofile\\.erlang.cookie\n```\n\n```text\n$env:WINDIR\\.erlang.cookie\n```\n\n```text\n$env:USERPROFILE\\.erlang.cookie\n```\n\n```text\nsudo service rabbitmq-server start\n```\n\n```text\nProgram Files/RabbitMQ/rabbitmq_server_x.x/etc/\n```\n\n```text\nrabbitmq.config\n```\n\n```text\nrabbitmq-server restart\n```\n\n```text\nProgram Files/RabbitMQ/rabbitmq_server_x.x/sbin/\n```\n\n```text\nrabbitmq.config\n```\n\n```text\nrabbitmq.config.example\n```\n\n========================================\n\nComments:\n- In my case it's because I installed it as Administrator and then tried to use the sbin scripts as a regular user.\n- In my case, cookies didn't match `C:\\Windows\\.erlang.cookie` and `C:\\Users\\my_user_name\\.erlang.cookie`. Copying one over another fixed the issue.\n- Yeah, it seems to be an issue within the RabbitMQ installer not registering the service correctly.\n- Confirmed this works also when the service **is** correctly visible in the Windows Services view but still doesn't work for some reason without this posted solution. Something relatively new, though, we've been installing rmq on multiple servers for few years now and this issue seem to be introduced somewhere lately. Thanks for this workaround then.\n- Just to confirm, this is still an issue as of April 2017. Went through rounds and rounds of \"homedir\" and cookies and telnetting. This is the one solution that works (though maybe using the manual install from .ZIP may work as well).\n- @Jerdev What do you mean of the `Run RabbitMQ sbin command prompt as administrator`?\n- @244boy what he means is to run command prompt as administrator and navigate to the RabbitMQ\\sbin folder. like C:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.6.6\\sbin Then run the commands to remove and reinstall the service. It worked for me. Thank you.\n- for me running above mentioned command followed by rabbitmq-server restart command worked.\n- What is `RabbitMQ sbin`? I don't find anything related to rabbit in `/sbin`\n- This command is helpful. It showed me the location of the logs where I was able to find the real error (erlang version too old for me)\n- this is a blocking command.. server gets restarted fine but the command doesn't return to terminal.. had to do ctrl+q to exit out which stopped the server.. jerdev answer above worked very well\n- This worked for me having broken my Rabbit installation following an upgrade from windows 7 to windows 10!\n- This answer in combination with top answer fixed it for me. Thanks\n- This one did it for me (with the top answer too). Thanks I was about ready to launch my laptop out the window.\n- Works for me too. This is by far the simplest solution !\n- When multiple install/uninstall could not help, this solution did help. Thanks. I copied from users to windows, but make sure both the files are same.\n- Possible duplicity with the stackoverflow.com/questions/40528775/….\n- @Lapacho, this question/answer is not a duplicate. This question was asked Feb 1, 15. I posted my working answer on Sep 1, 2016. That question (stackoverflow.com/questions/40528775/…) was posted 2 months later (Nov 11, 2016). You added a comment on that question 1 year 3 months later (Feb 13, 2018). Which one, according to you, is a duplicate ?\n- Great stuff - sorted me out too! :~D","metadata":{"transformedAt":"2026-08-18T18:33:20.120Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":16,"totalLines":190,"estimatedTokens":1661}}66{"id":"stack-6386117","source":"stackoverflow","questionId":6386117,"title":"RabbitMQ use of immediate and mandatory bits","tags":["rabbitmq","amqp"],"text":"Title: RabbitMQ use of immediate and mandatory bits\nTags: rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI am using RabbitMQ server.\n\nFor publishing messages, I set the **immediate** field to *true* and tried sending 50,000 messages. Using `rabbitmqctl list_queues`, I saw that the number of messages in the queue was **zero**.\n\nThen, I changed the **immediate** flag to *false* and again tried sending 50,000 messages. Using `rabbitmqctl list_queues`, I saw that a total of 100,000 messages were in queues (till now, no consumer was present).\n\nAfter that, I started a consumer and it consumed all the 100,000 messages.\n\nCan anybody please help me in understanding about the **immediate** bit field and this behavior too? Also, I could not understand the concept of the **mandatory** bit field.\n\n========================================\n\nTop Answer:\nhttp://www.rabbitmq.com/blog/2012/11/19/breaking-things-with-rabbitmq-3-0/\n\n**Removal of \"immediate\" flag**\n\n**What changed?** We removed support for the\nrarely-used \"immediate\" flag on AMQP's basic.publish.\n\n**Why on earth did you do that?** Support for \"immediate\" made many parts\nof the codebase more complex, particularly around mirrored queues. It\nalso stood in the way of our being able to deliver substantial\nperformance improvements in mirrored queues.\n\n**What do I need to do?** If you just want to be able to publish messages\nthat will be dropped if they are not consumed immediately, you can\npublish to a queue with a TTL of 0.\n\nIf you also need your publisher to be able to determine that this has\nhappened, you can also use the DLX feature to route such messages to\nanother queue, from which the publisher can consume them.\n\nJust copied the announcement here for a quick reference.\n\n========================================\n\nCode:\n```text\nrabbitmqctl list_queues\n```\n\n```text\nrabbitmqctl list_queues\n```\n\n```text\nimmediate\n```\n\n```text\nmandatory\n```\n\n========================================\n\nComments:\n- What happens if the lucky consumer crashes before acking the receipt and there are no other consumers on the queue? Does the message still just sit in the queue? Or does it get returned?\n- I did not test it, but I can guess that crashed consumer is another story, and the behaviour of that related to requeueing or dead letter.\n- Sorry to add a comment almost 5 years later... It looks to me that the `immediate` flag is not exposed through RabbitMQ's API? At least not in the .Net API. The only way I found that the `immediate` flag is settable in the library is through an internal `BasicPublish` class's constructor that's never used in the library. Is `immediate` in some way deprecated or discouraged?\n- Ah, found the answer to my question: immediate was removed in Rabbit v3.0 because it was rarely used, complicated the codebase and had an alternative.\n- loved the \"Or in my words\". I wish all tech specs were like that :)","metadata":{"transformedAt":"2026-08-18T18:33:20.120Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":67,"estimatedTokens":725}}67{"id":"stack-8548983","source":"stackoverflow","questionId":8548983,"title":"How to install rabbitmq management plugin (rabbitmq-plugins)","tags":["ubuntu","rabbitmq"],"text":"Title: How to install rabbitmq management plugin (rabbitmq-plugins)\nTags: ubuntu, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nBrief:\nIs there a way to install rabbitmq-plugins via a ubuntu package?\n\nDetails:\n\nI have rabbitmq running ok in my ubuntu system, and now I'm trying to monitor what's going on via the management plugin. I'm following rabbitmq.com/management.html instructions, but can't execute\n\n```\nrabbitmq-plugins enable rabbitmq_management\n```\n\nbecause my system does not have rabbitmq-plugins installed.\n\nIt's Ubuntu 1110, and came with rabbitmq installed as a package (aptitude install rabbitmq-server librabbitmq-dev). The config and the server are running fine (the installed version is 2.5.0).\n\nThought that the plugin would get installed by installing \"sudo aptitude install rabbitmq-plugins-common\", but doing that does not install rabbitmq-plugins.\n\nIs there a package that will install the plugin? I'd like to avoid if possible having to purge the rabbitmq server that is running ok, and then reinstall it via a download + build from source, all just to get the plugin.\n\nThanks.\n\n========================================\n\nTop Answer:\nIf you are using Ubuntu 12.04 \n\nSteps are:-- \n\nMy rabbitmq server version\n\n```\n# dpkg -l rabbitmq-server\nDesired=Unknown/Install/Remove/Purge/Hold\n| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend\n|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)\n||/ Name Version Description\n+++-===================-===================-======================================================\nii rabbitmq-server 2.7.1-0ubuntu4 An AMQP server written in Erlang\n\n# apt-get install rabbitmq-server\n\n# /usr/lib/rabbitmq/lib/rabbitmq_server-2.7.1/sbin/rabbitmq-plugins list\n[ ] amqp_client 0.0.0\n[ ] eldap 0.0.0-git\n[ ] erlando 0.0.0\n[ ] mochiweb 1.3-rmq0.0.0-git\n[ ] rabbitmq_auth_backend_ldap 0.0.0\n[ ] rabbitmq_auth_mechanism_ssl 0.0.0\n[ ] rabbitmq_consistent_hash_exchange 0.0.0\n[ ] rabbitmq_federation 0.0.0\n[ ] rabbitmq_jsonrpc 0.0.0\n[ ] rabbitmq_jsonrpc_channel 0.0.0\n[ ] rabbitmq_jsonrpc_channel_examples 0.0.0\n[ ] rabbitmq_management 0.0.0\n[ ] rabbitmq_management_agent 0.0.0\n[ ] rabbitmq_management_visualiser 0.0.0\n[ ] rabbitmq_mochiweb 0.0.0\n[ ] rabbitmq_shovel 0.0.0\n[ ] rabbitmq_shovel_management 0.0.0\n[ ] rabbitmq_stomp 0.0.0\n[ ] rabbitmq_tracing 0.0.0\n[ ] rfc4627_jsonrpc 0.0.0-git\n[ ] webmachine 1.7.0-rmq0.0.0-hg\n```\n\nNow to enable the web UI plugin\n\n```\n# /usr/lib/rabbitmq/lib/rabbitmq_server-2.7.1/sbin/rabbitmq-plugins enable rabbitmq_management\nThe following plugins have been enabled:\n mochiweb\n webmachine\n rabbitmq_mochiweb\n amqp_client\n rabbitmq_management_agent\n rabbitmq_management\n```\n\nPlugin configuration has changed. Restart RabbitMQ for changes to take effect.\n\n```\nroot@ubuntu:/usr/lib/rabbitmq/lib/rabbitmq_server-2.7.1/sbin# service rabbitmq-server restart\nRestarting rabbitmq-server: SUCCESS\nrabbitmq-server\n```\n\n.\n\n```\nroot@ubuntu:/usr/lib/rabbitmq/lib/rabbitmq_server-2.7.1/sbin# /usr/lib/rabbitmq/lib/rabbitmq_server-2.7.1/sbin/rabbitmq-plugins list\n\n[e] amqp_client 0.0.0\n[ ] eldap 0.0.0-git\n[ ] erlando 0.0.0\n[e] mochiweb 1.3-rmq0.0.0-git\n[ ] rabbitmq_auth_backend_ldap 0.0.0\n[ ] rabbitmq_auth_mechanism_ssl 0.0.0\n[ ] rabbitmq_consistent_hash_exchange 0.0.0\n[ ] rabbitmq_federation 0.0.0\n[ ] rabbitmq_jsonrpc 0.0.0\n[ ] rabbitmq_jsonrpc_channel 0.0.0\n[ ] rabbitmq_jsonrpc_channel_examples 0.0.0\n[E] rabbitmq_management 0.0.0\n[e] rabbitmq_management_agent 0.0.0\n[ ] rabbitmq_management_visualiser 0.0.0\n[e] rabbitmq_mochiweb 0.0.0\n[ ] rabbitmq_shovel 0.0.0\n[ ] rabbitmq_shovel_management 0.0.0\n[ ] rabbitmq_stomp 0.0.0\n[ ] rabbitmq_tracing 0.0.0\n[ ] rfc4627_jsonrpc 0.0.0-git\n[e] webmachine 1.7.0-rmq0.0.0-hg\n```\n\nCheck the Web UI\n\non your browser try `http://localhost:55672` (or `http://localhost:15672` for newer versions of rabbitmq) & login via default user and password which is guest:guest & you will be able to see it all.\n\nHope it helps.\n\n========================================\n\nCode:\n```text\nrabbitmq-plugins enable rabbitmq_management\n```\n\n```text\n# dpkg -l rabbitmq-server\nDesired=Unknown/Install/Remove/Purge/Hold\n| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend\n|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)\n||/ Name Version Description\n+++-===================-===================-======================================================\nii rabbitmq-server 2.7.1-0ubuntu4 An AMQP server written in Erlang\n\n# apt-get install rabbitmq-server\n\n# /usr/lib/rabbitmq/lib/rabbitmq_server-2.7.1/sbin/rabbitmq-plugins list\n[ ] amqp_client 0.0.0\n[ ] eldap 0.0.0-git\n[ ] erlando 0.0.0\n[ ] mochiweb 1.3-rmq0.0.0-git\n[ ] rabbitmq_auth_backend_ldap 0.0.0\n[ ] rabbitmq_auth_mechanism_ssl 0.0.0\n[ ] rabbitmq_consistent_hash_exchange 0.0.0\n[ ] rabbitmq_federation 0.0.0\n[ ] rabbitmq_jsonrpc 0.0.0\n[ ] rabbitmq_jsonrpc_channel 0.0.0\n[ ] rabbitmq_jsonrpc_channel_examples 0.0.0\n[ ] rabbitmq_management 0.0.0\n[ ] rabbitmq_management_agent 0.0.0\n[ ] rabbitmq_management_visualiser 0.0.0\n[ ] rabbitmq_mochiweb 0.0.0\n[ ] rabbitmq_shovel 0.0.0\n[ ] rabbitmq_shovel_management 0.0.0\n[ ] rabbitmq_stomp 0.0.0\n[ ] rabbitmq_tracing 0.0.0\n[ ] rfc4627_jsonrpc 0.0.0-git\n[ ] webmachine 1.7.0-rmq0.0.0-hg\n```\n\n```text\n# /usr/lib/rabbitmq/lib/rabbitmq_server-2.7.1/sbin/rabbitmq-plugins enable rabbitmq_management\nThe following plugins have been enabled:\n mochiweb\n webmachine\n rabbitmq_mochiweb\n amqp_client\n rabbitmq_management_agent\n rabbitmq_management\n```\n\n```text\nroot@ubuntu:/usr/lib/rabbitmq/lib/rabbitmq_server-2.7.1/sbin# service rabbitmq-server restart\nRestarting rabbitmq-server: SUCCESS\nrabbitmq-server\n```\n\n```text\nroot@ubuntu:/usr/lib/rabbitmq/lib/rabbitmq_server-2.7.1/sbin# /usr/lib/rabbitmq/lib/rabbitmq_server-2.7.1/sbin/rabbitmq-plugins list\n\n[e] amqp_client 0.0.0\n[ ] eldap 0.0.0-git\n[ ] erlando 0.0.0\n[e] mochiweb 1.3-rmq0.0.0-git\n[ ] rabbitmq_auth_backend_ldap 0.0.0\n[ ] rabbitmq_auth_mechanism_ssl 0.0.0\n[ ] rabbitmq_consistent_hash_exchange 0.0.0\n[ ] rabbitmq_federation 0.0.0\n[ ] rabbitmq_jsonrpc 0.0.0\n[ ] rabbitmq_jsonrpc_channel 0.0.0\n[ ] rabbitmq_jsonrpc_channel_examples 0.0.0\n[E] rabbitmq_management 0.0.0\n[e] rabbitmq_management_agent 0.0.0\n[ ] rabbitmq_management_visualiser 0.0.0\n[e] rabbitmq_mochiweb 0.0.0\n[ ] rabbitmq_shovel 0.0.0\n[ ] rabbitmq_shovel_management 0.0.0\n[ ] rabbitmq_stomp 0.0.0\n[ ] rabbitmq_tracing 0.0.0\n[ ] rfc4627_jsonrpc 0.0.0-git\n[e] webmachine 1.7.0-rmq0.0.0-hg\n```\n\n```text\nhttp://localhost:55672\n```\n\n```text\nhttp://localhost:15672\n```\n\n```text\n/usr/lib/rabbitmq/bin/rabbitmq-plugins\n```\n\n```text\nsudo ln -s /usr/lib/rabbitmq/bin/rabbitmq-plugins /usr/local/bin/rabbitmq-plugins\n```\n\n```text\nsudo vim /etc/rabbitmq/enabled_plugins\n```\n\n```text\nsudo apt-get remove rabbitmq-server\nsudo apt-get install rabbitmq-server\nsudo systemctl enable rabbitmq-server\nsudo systemctl start rabbitmq-server\nsudo systemctl status rabbitmq-server (to check status only)\nsudo rabbitmq-plugins enable rabbitmq_management\nsudo rabbitmqctl add_user admin admin\nsudo rabbitmqctl set_user_tags admin administrator\n```\n\n========================================\n\nComments:\n- Beau, thanks for the pointer. I re-posted the question in askubuntu, but will leave it here as well a little longer since it seems to draw a much larger number of rabbitmq community members than ubuntu, and someone may have had the same issue.\n- I have ubuntu 12.04 and rabbitmq 2.7.1 but no rabbitmq-plugins?!\n- @Stefano have a look in the following location /usr/lib/rabbitmq/lib/rabbitmq_server-2.7.1/sbin/ which is where I found the rabbitmq-plugins file\n- @AidenMontgomery thanks indeed!! but why isn't that on the /usr/bin path by default?!\n- I tried to copy management plugin as per the above...but rabbitmq refuses to start. The other plugins seem to work OK. Strange.\n- I want to install v3.7.4 from source. Its building fine but I dont see any plugins there how do I get to start management plugin and access the UI?\n- I want to install v3.7.4 from source. Its building fine but I dont see any plugins there how do I get to start management plugin and access the UI?\n- Port 15672 from Rabbitmq version 3.0 onwards. The answer worked for version 3.1.5 except the port number (Rabbitmq version check (sudo rabbitmqctl status).","metadata":{"transformedAt":"2026-08-18T18:33:20.121Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":11,"totalLines":252,"estimatedTokens":2230}}68{"id":"stack-25114230","source":"stackoverflow","questionId":25114230,"title":"RabbitMQ - purge a queue from all of its unacked messages","tags":["rabbitmq"],"text":"Title: RabbitMQ - purge a queue from all of its unacked messages\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have thousands of unacked messages in my dev environment which I can't restart.\n\nIs there a way to remove (purge) all messages even if they are unacknowledged?\n\n========================================\n\nTop Answer:\nYou have to make consumer `ack` them (or `nack`) and only after that they will be removed. Alternatively you can shutdown consumers and purge the queue completely.\n\nIf you are looking for some way to purge all unacked messages - there are no such feature nor in AMQP protocol neither in RabbitMQ.\n\nIt looks like your consumer is the cause of the problem, so you have to adjust it (rewrite) to release message immediately after it processed or failed.\n\n========================================\n\nCode:\n```text\nack\n```\n\n```text\nnack\n```\n\n```text\nqueue.purge\n```\n\n```text\nbasic.recover\n```\n\n========================================\n\nComments:\n- There is queue purge in AMQP: rabbitmq.com/amqp-0-9-1-reference.html#queue.purge\n- It doesn't purge unacked messages. From the `queue.purge` method doc block: `This method removes all messages from a queue which are >>> not awaiting acknowledgment <<<`, which is strict AMQP protocol implementation.\n- @pinepain i spent a while writing code to find queues with messages. then call the `purge` command and then wait in a loop but the queues never emptied. thanks for the clarification. i'll have to rethink my approach.\n- How do you find the channel that the unacked message resides on?\n- @grayaii in you rabbitmq console..if you click on the queue with unacked meesages there will be a consumers section inside that you will find channels related to it.\n- Thanks! This has worked for me: I stopped the consumer for the queue, then the messages have moved into the bucket and then I was able to delete them with the Purge button.\n- How do you \"Close the channel\"?\n- @GeraldMurphy cloudamqp.com/blog/…\n- And then get fired.","metadata":{"transformedAt":"2026-08-18T18:33:20.121Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":49,"estimatedTokens":500}}69{"id":"stack-10407760","source":"stackoverflow","questionId":10407760,"title":"Is there a performance difference between pooling connections or channels in rabbitmq?","tags":["queue","message-queue","rabbitmq","task-queue"],"text":"Title: Is there a performance difference between pooling connections or channels in rabbitmq?\nTags: queue, message-queue, rabbitmq, task-queue\nSource: Stack Overflow\n\nQuestion:\nI'm a newbie with Rabbitmq(and programming) so sorry in advance if this is obvious. I am creating a pool to between threads that are working on a queue but I'm not sure if I should use connections or channels in the pool. \n\nI know I need channels to do the actual work but is there a performance benefit of having one channel per connection(in terms of more throughput from the queue)? or am I better off just using a single connection per application and pool many channels?\n\nnote: because I'm pooling the resources the initial cost is not a factor, as I know connections are more expensive than channels. I'm more interested in throughput.\n\n========================================\n\nTop Answer:\nIn addition to the accepted answer:\n\nIf you have a cluster of RabbitMQ nodes with either a load-balancer in front, or a short-lived DNS (making it possible to connect to a different rabbit node each time), then a single, long-lived connection would mean that one application node works exclusively with a single RabbitMQ node. This may lead to one RabbitMQ node being more heavily utilized than the others. \n\nThe other concern mentioned above is that the publishing and consuming are blocking operations, which leads to queueing messages. Having more connections will ensure that 1. processing time for each messages doesn't block other messages 2. big messages aren't blocking other messages.\n\nThat's why it's worth considering having a small connection pool (having in mind the resource concerns raised above)\n\n========================================\n\nCode:\n```text\namq.rabbitmq.reply-to\n```\n\n========================================\n\nComments:\n- False - \"Channel thread-safety Channel instances are safe for use by multiple threads. Requests into a Channel are serialized, with only one thread being able to run a command on the Channel at a time. Even so, applications should prefer using a Channel per thread instead of sharing the same Channel across multiple threads.\" per the API docs.\n- ok edited. It is weird that I wrote that, is it possible the documentation has changed? doubt it. Just a mistake on my part, apologies. The recommendation stays the same though. 1 consumer, 1 channel, 1 thread.\n- Whether channels are thread-safe depends on the implementation. The Java impl is safe, whereas the .net one is not. See stackoverflow.com/a/17829906/709537\n- and this small connection pool you suggest, is it provided or is it something I should implement myself?\n- Isn't this caution related only to client side of RPC (i.e. who sends a message with replyTo set as `amq.rabbitmq.reply-to`)?\n- @SerG Did you have a look at the Google user group? The example there is for an RPC client. I didn't pursue this more though. :) I dropped RabbitMQ shortly after in favor of ZMQ that was closser to my needs.","metadata":{"transformedAt":"2026-08-18T18:33:20.121Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":38,"estimatedTokens":746}}70{"id":"stack-65355892","source":"stackoverflow","questionId":65355892,"title":"Can you import a NestJS module on condition","tags":["module","rabbitmq","nestjs"],"text":"Title: Can you import a NestJS module on condition\nTags: module, rabbitmq, nestjs\nSource: Stack Overflow\n\nQuestion:\nI'am creating a microservice in NestJS. Now I want to use RabbitMQ to send messages to another service.\n\nMy question is: is it possible to import the RabbitmqModule based on a `.env` variable? Such as:\n`USE_BROKER=false`. If this variable is false, than don't import the module?\n\nRabbitMQ is imported in the GraphQLModule below.\n\n```\n@Module({\n imports: [\n GraphQLFederationModule.forRoot({\n autoSchemaFile: true,\n context: ({ req }) => ({ req }),\n }),\n DatabaseModule,\n AuthModule,\n RabbitmqModule,\n ],\n providers: [UserResolver, FamilyResolver, AuthResolver],\n})\nexport class GraphQLModule {}\n```\n\nRabbitmqModule:\n\n```\nimport { Global, Module } from '@nestjs/common';\nimport { ConfigService } from '@nestjs/config';\nimport { RabbitMQModule } from '@golevelup/nestjs-rabbitmq';\nimport { UserProducer } from './producers/user.producer';\n\n@Global()\n@Module({\n imports: [\n RabbitMQModule.forRootAsync(RabbitMQModule, {\n useFactory: async (config: ConfigService) => ({\n exchanges: [\n {\n name: config.get('rabbitMQ.exchange'),\n type: config.get('rabbitMQ.exchangeType'),\n },\n ],\n uri: config.get('rabbitMQ.url'),\n connectionInitOptions: { wait: false },\n }),\n inject: [ConfigService],\n }),\n ],\n providers: [UserProducer],\n exports: [UserProducer],\n})\nexport class RabbitmqModule {}\n```\n\n========================================\n\nTop Answer:\nWell I tried a simple workaround, in a small nest project, and it worked just fine. Check it out:\n\n```\nconst mymodules = [TypeOrmModule.forRoot(typeOrmConfig), UsersModule];\nif (config.get('importModule')) {\n mymodules.push(PoopModule);\n}\n@Module({\n imports: mymodules,\n controllers: [AppController],\n providers: [AppService],\n})\nexport class AppModule {}\n```\n\nI created an \"importModule\" in my env/config, and tested it with true and false. If true my Poop module gets deployed, else it doesn't deploy, only the other modules.\n\nCan you try the same in your project?\n\n========================================\n\nCode:\n```javascript\n@Module({\n imports: [\n GraphQLFederationModule.forRoot({\n autoSchemaFile: true,\n context: ({ req }) => ({ req }),\n }),\n DatabaseModule,\n AuthModule,\n RabbitmqModule,\n ],\n providers: [UserResolver, FamilyResolver, AuthResolver],\n})\nexport class GraphQLModule {}\n```\n\n```javascript\nimport { Global, Module } from '@nestjs/common';\nimport { ConfigService } from '@nestjs/config';\nimport { RabbitMQModule } from '@golevelup/nestjs-rabbitmq';\nimport { UserProducer } from './producers/user.producer';\n\n@Global()\n@Module({\n imports: [\n RabbitMQModule.forRootAsync(RabbitMQModule, {\n useFactory: async (config: ConfigService) => ({\n exchanges: [\n {\n name: config.get('rabbitMQ.exchange'),\n type: config.get('rabbitMQ.exchangeType'),\n },\n ],\n uri: config.get('rabbitMQ.url'),\n connectionInitOptions: { wait: false },\n }),\n inject: [ConfigService],\n }),\n ],\n providers: [UserProducer],\n exports: [UserProducer],\n})\nexport class RabbitmqModule {}\n```\n\n```text\n.env\n```\n\n```text\nUSE_BROKER=false\n```\n\n```js\n@Module({})\nexport class GraphQLModule {\n static register(): DynamicModule {\n const imports = [\n GraphQLFederationModule.forRoot({\n autoSchemaFile: true,\n context: ({ req }) => ({ req }),\n }),\n DatabaseModule,\n AuthModule]\n if (process.env.USE_BROKER) {\n imports.push(RabbitmqModule)\n }\n return {\n imports,\n providers: [UserResolver, FamilyResolver, AuthResolver],\n };\n }\n}\n```\n\n```javascript\nconst mymodules = [TypeOrmModule.forRoot(typeOrmConfig), UsersModule];\nif (config.get('importModule')) {\n mymodules.push(PoopModule);\n}\n@Module({\n imports: mymodules,\n controllers: [AppController],\n providers: [AppService],\n})\nexport class AppModule {}\n```\n\n```text\nConditionalModule.registerWhen\n```\n\n```text\n@nestjs/config\n```\n\n========================================\n\nComments:\n- Yes, calculating the imports array based on a condition is the easiest way to accomplish this functionality\n- Where did you define config in this example?\n- @jm18457 I don't have the sample project with me anymore, but I guess you can just use `dotenv` or similar library. The one described in my code is npmjs.com/package/config. You can just install it, create a `/config/default.json` in your project, and store values in there (I'm using `/config/default.yml` in a different project and it also seems to work fine). I import this lib using the syntax `import * as config from 'config';`\n- Ok, thx. I thought you were using the config service from Nest.js. I want to read .env variables from the configService.\n- I did try to use sometimes, but usually I give up on this module and install dotenv instead, sry =]\n- But what if we want to make use of ConfigService to determine whether the RabbitmqModule should be loaded or not? Instead of having process.env hardcoded\n- Any answer to above question? How do we implement this solution using ConfigService instead of process.env?\n- To use ConfigService in register method, see stackoverflow.com/a/54310397/901597\n- this is seem to be the best option\n- but can the ConditionalModule using config value instead of env?\n- The idea is neat, and the demand is there, but the implementation seems very clumsy (as of June 2024). It seems as though conditional module import can't be implemented with the intuitive syntax, but the authors wanted to give it a try anyway, and ended up with a hacky compromise. I expect this feature to be significantly improved in a year or two (or faster, if this comment is seen by NestJS collaborators 🙋).\n- @Parzh well, it hasn't improved :)\n- still no improvement here, mid 2026 😅 -> it is great! But the use of only `env` is a little limiting... It passes the need we currently have, but, it does need a better implementation from nestjs. But, it will do for now 🥲\n- @Peter No it can't. It only provides the `env`, which is not ideal, but it can get the job done. It's the cleanest solution currently in 2026, but, I think they need to improve their interface a little","metadata":{"transformedAt":"2026-08-18T18:33:20.121Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":197,"estimatedTokens":1556}}71{"id":"stack-9704590","source":"stackoverflow","questionId":9704590,"title":"Topic Exchange vs Direct Exchange in RabbitMQ","tags":["rabbitmq","message-queue","rabbitmq-exchange"],"text":"Title: Topic Exchange vs Direct Exchange in RabbitMQ\nTags: rabbitmq, message-queue, rabbitmq-exchange\nSource: Stack Overflow\n\nQuestion:\nWe've got an application which will be using RabbitMQ and have several different queues for passing messages between tiers.\n\nInitially, I was planning to use multiple direct exchanges, with one for each message type, but it looks like having a single topic exchange with queues using different routing key bindings will achieve the same thing.\n\nHaving a single exchange also seems like it would be a bit easier to maintain, but I was wondering if there is any benefit (if any) of doing it one way over the other?\n\nOption 1, using multiple direct exchanges:\n\n```\nExchangeA (type: direct)\n-QueueA\n\nExchangeB (type: direct)\n-QueueB\n\nExchangeC (type: direct)\n-QueueC\n```\n\nOption 2, using single topic exchange:\n\n```\nExchange (type: topic)\n-QueueA (receives messages from exchange with routing key of \"TypeA\")\n-QueueB (receives messages from exchange with routing key of \"TypeB\")\n-QueueC (receives messages from exchange with routing key of \"TypeC\")\n```\n\n========================================\n\nTop Answer:\nIndeed approach 2 is better as it gives you flexibility to use a single queue for multiple routing keys.\n\n**Exchange Topic**\n\n```\nQueueA-- binding key = India.Karnataka.*\n```\n\nYou can route a message to topic exchange with routing key as India.Karnataka.bangalore,India.Karnataka.Mysore.\n\nAll the above messages goes to QueueA.\n\n**Direct Exchange**\n\nBut I did not understand on why are you creating multiple direct exchanges in approach 1. You can have single direct exchange and have multiple queues with each queue binding with a unique key.\n\n```\nQueueA-- binding key = Key1\nQueueB-- binding Key = Key2\nQueueC-- binding Key = Key3\n```\n\nAll key1 messages goes to QueueA.Key2 goes to QueueB ... You can still maintain single direct exchange.\n\n========================================\n\nCode:\n```text\nExchangeA (type: direct)\n-QueueA\n\nExchangeB (type: direct)\n-QueueB\n\nExchangeC (type: direct)\n-QueueC\n```\n\n```text\nExchange (type: topic)\n-QueueA (receives messages from exchange with routing key of \"TypeA\")\n-QueueB (receives messages from exchange with routing key of \"TypeB\")\n-QueueC (receives messages from exchange with routing key of \"TypeC\")\n```\n\n```text\n#\n```\n\n```text\n*\n```\n\n```text\nQueueA-- binding key = India.Karnataka.*\n```\n\n```text\nQueueA-- binding key = Key1\nQueueB-- binding Key = Key2\nQueueC-- binding Key = Key3\n```\n\n```text\nExchangeA (type: direct)\n-QueueA\n-RoutingA\n\nExchangeB (type: direct)\n-QueueB\n-RoutingB\n\nExchangeC (type: direct)\n-QueueC\n-RoutingC\n```\n\n========================================\n\nComments:\n- You can possibly learn the differences here stackoverflow.com/questions/9704590/… jstobigdata.com/rabbitmq/topic-exchange-in-amqp-rabbitmq\n- I concur. Multiple queues with appropriate routing keys is far easier to manage. The only advantage of option 1 that springs to mind is that multiple exchanges could be hosted on separate hardware thereby achieving vertical scaling. However, if your hardware rocks then you may never need to take this route.\n- I think the advantage of using Topic is if it happens in the future that you need to send the same message to multiple queues in your exchange, your option 2 would be more desirable.\n- Note that using Direct Exchange when having multiple consumers it will work as a fanout and send the message to all connected users.Meanwhile, the topic Exchange queues will handle consumers in a round robin based\n- Will keeping a single direct exchange affect the performance?\n- Why cant we use fanout instead of topic?\n- @ujwaldhakal because it is not so versatile, the topic can act like direct and fanout. BTW fanout will just blindly distribute messages to queues.","metadata":{"transformedAt":"2026-08-18T18:33:20.121Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":123,"estimatedTokens":947}}72{"id":"stack-10608950","source":"stackoverflow","questionId":10608950,"title":"How do I stop the RabbitMQ server on localhost","tags":["rabbitmq","amqp"],"text":"Title: How do I stop the RabbitMQ server on localhost\nTags: rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI installed RabbitMQ server on OS X, and started it on command line. Now, it is not obvious that how I should stop it from running? After I did:\n\n```\nsudo rabbitmq-server -detached\n```\n\nI get:\n\n```\nActivating RabbitMQ plugins ...\n0 plugins activated:\n```\n\nThat was it. How should I properly shut it down? In the document, it mentions using `rabbitmqctl(1)`, but it's not clear to me what that means. Thanks.\n\nEdit: As per comment below, this is what I get for running `sudo rabbitmqctl stop`:\n\n```\n(project_env)mlstr-1:Package mlstr$ sudo rabbitmqctl stop\nPassword:\nStopping and halting node rabbit@h002 ...\nError: unable to connect to node rabbit@h002: nodedown\n\nDIAGNOSTICS\n===========\n\nnodes in question: [rabbit@h002]\n\nhosts, their running nodes and ports:\n- h002: [{rabbit,62428},{rabbitmqctl7069,64735}]\n\ncurrent node details:\n- node name: rabbitmqctl7069@h002\n- home dir: /opt/local/var/lib/rabbitmq\n- cookie hash: q7VU0JjCd0VG7jOEF9Hf/g==\n```\n\nWhy is there still a 'current node'? I have not run any client program but only the RabbitMQ server, does that mean a server is still running?\n\n========================================\n\nTop Answer:\nIn my dev environment where I keep it running all the time, I use:\n\n```\nlaunchctl unload ~/Library/LaunchAgents/homebrew.mxcl.rabbitmq.plist\n```\n\nand to start it\n\n```\nlaunchctl load ~/Library/LaunchAgents/homebrew.mxcl.rabbitmq.plist\n```\n\nEven easier....\n\n```\nbrew services stop rabbitmq\nbrew services start rabbitmq\n```\n\n========================================\n\nCode:\n```text\nsudo rabbitmq-server -detached\n```\n\n```text\nActivating RabbitMQ plugins ...\n0 plugins activated:\n```\n\n```text\n(project_env)mlstr-1:Package mlstr$ sudo rabbitmqctl stop\nPassword:\nStopping and halting node rabbit@h002 ...\nError: unable to connect to node rabbit@h002: nodedown\n\nDIAGNOSTICS\n===========\n\nnodes in question: [rabbit@h002]\n\nhosts, their running nodes and ports:\n- h002: [{rabbit,62428},{rabbitmqctl7069,64735}]\n\ncurrent node details:\n- node name: rabbitmqctl7069@h002\n- home dir: /opt/local/var/lib/rabbitmq\n- cookie hash: q7VU0JjCd0VG7jOEF9Hf/g==\n```\n\n```text\nrabbitmqctl(1)\n```\n\n```text\nsudo rabbitmqctl stop\n```\n\n```text\nsudo -u rabbitmq rabbitmqctl stop\n```\n\n```text\nrabbitmqctl stop\n```\n\n```text\n-n rabbit@[hostname]\n```\n\n```text\nlaunchctl unload ~/Library/LaunchAgents/homebrew.mxcl.rabbitmq.plist\n```\n\n```text\nlaunchctl load ~/Library/LaunchAgents/homebrew.mxcl.rabbitmq.plist\n```\n\n```text\nbrew services stop rabbitmq\nbrew services start rabbitmq\n```\n\n```text\n.\\rabbitmq-service.bat stop\n```\n\n```text\nstop\n```\n\n```text\nbrew services stop rabbitmq\n```\n\n```text\nbrew services start rabbitmq\n```\n\n```text\nbrew services restart rabbitmq\n```\n\n```text\nbrew services info rabbitmq\n```\n\n========================================\n\nComments:\n- I like this answer! The command is different than in Windows, and may confuse people.","metadata":{"transformedAt":"2026-08-18T18:33:20.121Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":17,"totalLines":159,"estimatedTokens":744}}73{"id":"stack-8737754","source":"stackoverflow","questionId":8737754,"title":"\"node with name \"rabbit\" already running\", but also \"unable to connect to node 'rabbit'\"","tags":["rabbitmq"],"text":"Title: \"node with name \"rabbit\" already running\", but also \"unable to connect to node 'rabbit'\"\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nRabbitmq server does not start, saying it's already running: \n\n```\n$: rabbitmq-server\nActivating RabbitMQ plugins ...\n0 plugins activated:\n\nnode with name \"rabbit\" already running on \"android-d1af002161676bee\"\ndiagnostics:\n- nodes and their ports on android-d1af002161676bee: [{rabbit,52176},\n {rabbitmqprelaunch2254,\n 59205}]\n- current node: 'rabbitmqprelaunch2254@android-d1af002161676bee'\n- current node home dir: /Users/Jordan\n- current node cookie hash: ZSx3slRJURGK/nHXDTBRqQ==\n```\n\n**But**, rabbitmqctl seems to think otherwise:\n\n```\nrabbitmqctl -n rabbit status\nStatus of node 'rabbit@android-d1af002161676bee' ...\nError: unable to connect to node 'rabbit@android-d1af002161676bee': nodedown\ndiagnostics:\n- nodes and their ports on android-d1af002161676bee: [{rabbit,52176},\n {rabbitmqctl2462,59256}]\n- current node: 'rabbitmqctl2462@android-d1af002161676bee'\n- current node home dir: /Users/Jordan\n- current node cookie hash: ZSx3slRJURGK/nHXDTBRqQ==\n```\n\nAny takers?\n\n========================================\n\nTop Answer:\ni was having the same problem then I realized I was not issuing the right command.\n\n```\n./rabbitmqctl stop\n```\n\nthis works everytime, although it does take down erlang runtime too. also mind where your config file.\n\n========================================\n\nCode:\n```text\n$: rabbitmq-server\nActivating RabbitMQ plugins ...\n0 plugins activated:\n\nnode with name \"rabbit\" already running on \"android-d1af002161676bee\"\ndiagnostics:\n- nodes and their ports on android-d1af002161676bee: [{rabbit,52176},\n {rabbitmqprelaunch2254,\n 59205}]\n- current node: 'rabbitmqprelaunch2254@android-d1af002161676bee'\n- current node home dir: /Users/Jordan\n- current node cookie hash: ZSx3slRJURGK/nHXDTBRqQ==\n```\n\n```text\nrabbitmqctl -n rabbit status\nStatus of node 'rabbit@android-d1af002161676bee' ...\nError: unable to connect to node 'rabbit@android-d1af002161676bee': nodedown\ndiagnostics:\n- nodes and their ports on android-d1af002161676bee: [{rabbit,52176},\n {rabbitmqctl2462,59256}]\n- current node: 'rabbitmqctl2462@android-d1af002161676bee'\n- current node home dir: /Users/Jordan\n- current node cookie hash: ZSx3slRJURGK/nHXDTBRqQ==\n```\n\n```text\n$: ps aux | grep epmd\n$: ps aux | grep erl\n```\n\n```text\nkill -9 {pid of rabbitmq process}\n```\n\n```text\n#rabbitmqctl cluster MASTER SLAVE\n#rabbitmqctl start_app\n```\n\n```text\n./rabbitmqctl stop\n```\n\n```text\nrabbitmqctl stop\n```\n\n```text\nrabbitmq-server\n```\n\n========================================\n\nComments:\n- NB: `kill -9` is not usually needed, `kill [pid]` works just fine.\n- Killing the erlang interpreter will cause problems and errors like \"unable to connect to node \".\n- Can also do `sudo pkill -9 -f erl`\n- this is a much more elegant solution than the kill suggested above IMO\n- Thanks - to get this to work issue the following command 'rabbitmqctl stop' into command prompt and then issue 'rabbitmq-server' to restart the server.\n- Yeah that /etc/hosts gets me every time. So for everyone else, make sure the /etc/hosts file contains the name of your server e.g. \"127.0.0.1 server2452 server2452.site.com\"\n- `root@48c0c0dafaed:/# rabbitmq-service remove bash: rabbitmq-service: command not found`\n- @KarlMorrison Your command is from a bash shell. This answer was referring to commands from the Windows command prompt. This answer worked for me on Windows 10.\n- this should be the best answer","metadata":{"transformedAt":"2026-08-18T18:33:20.121Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":117,"estimatedTokens":920}}74{"id":"stack-61374796","source":"stackoverflow","questionId":61374796,"title":"C# Convert ReadOnlyMemory to byte[]","tags":["c#","rabbitmq"],"text":"Title: C# Convert ReadOnlyMemory to byte[]\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nGiven ReadOnlyMemory Struct I want to convert the stream into a string\n\nI have the following code:\n\n```\nvar body = ea.Body; //ea.Body is of Type ReadOnlyMemory\nvar message = Encoding.UTF8.GetString(body);\nConsole.WriteLine(\" [x] Received {0}\", message);\n```\n\nAnd it gives the following error. I am using the latest C# with .NET CORE 3.1\n\nhttps://i.sstatic.net/1XIJU.png\n\nWhich is funny because I am literally copy pasting the Hello World example of a major product called RabbitMQ and it doesn't compile.\n\n========================================\n\nTop Answer:\nUse Span property to convert message to string without additional memory allocation\n\n```\nvar body = ea.Body; //ea.Body is of Type ReadOnlyMemory\nvar message = Encoding.UTF8.GetString(body.Span);\nConsole.WriteLine(\" [x] Received {0}\", message);\n```\n\n========================================\n\nCode:\n```text\nvar body = ea.Body; //ea.Body is of Type ReadOnlyMemory<byte>\nvar message = Encoding.UTF8.GetString(body);\nConsole.WriteLine(\" [x] Received {0}\", message);\n```\n\n```cs\nvar body = ea.Body.ToArray();\nvar message = Encoding.UTF8.GetString(body);\nConsole.WriteLine(\" [x] Received {0}\", message);\n```\n\n```cs\nvar body = ea.Body.Span;\nvar message = Encoding.UTF8.GetString(body);\nConsole.WriteLine(\" [x] Received {0}\", message);\n```\n\n```text\nbyte[]\n```\n\n```text\nbyte[]\n```\n\n```text\n.ToArray()\n```\n\n```text\n.Span\n```\n\n```text\nvar body = ea.Body; //ea.Body is of Type ReadOnlyMemory<byte>\nvar message = Encoding.UTF8.GetString(body.Span);\nConsole.WriteLine(\" [x] Received {0}\", message);\n```\n\n```text\nvar data = new byte[] { 72, 101, 108, 108, 111 };\nvar body = new ReadOnlyMemory<byte>(data);\nvar text = Encoding.UTF8.GetString(body.Span);\n\nConsole.WriteLine(text);\n```\n\n```text\nSpan\n```\n\n```text\nEncoding.UTF8.GetString\n```\n\n```text\nReadOnlySpan<byte>\n```\n\n```cs\nprivate static void Consumer_Received(object sender, BasicDeliverEventArgs e)\n // Code\n```\n\n```text\nBasicDeliverEventArgs\n```\n\n```text\nBody\n```\n\n```text\npublic ReadOnlyMemory<byte> Body { get; set; }\n```\n\n```text\nvar message = Encoding.UTF8.GetString(e.Body.ToArray());\n```\n\n```text\npublic override void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, ReadOnlyMemory<byte> body) {\n var msg = body.ToArray();\n var message = Encoding.UTF8.GetString(msg);\n```\n\n```text\nprivate void RabbitMsg_Received(object sender, BasicDeliverEventArgs e)\n {\n /**************************************************************\n * Copy BasicDeliverEventArgs to make sure Body is not altered\n * by RabbitMQ.Client. Versions > 6.0 changed memory handling\n **************************************************************/\n BasicDeliverEventArgs bdea = new BasicDeliverEventArgs(\n e.ConsumerTag,\n e.DeliveryTag,\n e.Redelivered,\n e.Exchange,\n e.RoutingKey,\n e.BasicProperties, new ReadOnlyMemory<byte>(e.Body.Span.ToArray())\n );\n\n _queue.Add(bdea);\n }\n```\n\n========================================\n\nComments:\n- I created an issue so that RabbitMQ can adapt the documentation: github.com/rabbitmq/rabbitmq-website/issues/963\n- Note that the overload on GetString is not included in .Net Framework.\n- Does using Span give a memory limitation e.g. only takes first 100 characters out of a 150 message?\n- You can use Span's Slice method to access any slice of the allocated memory region, by default Span returns all allocated region","metadata":{"transformedAt":"2026-08-18T18:33:20.121Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":19,"totalLines":149,"estimatedTokens":911}}75{"id":"stack-9520914","source":"stackoverflow","questionId":9520914,"title":"Installing AMQP through PECL","tags":["php","rabbitmq","amqp","pecl"],"text":"Title: Installing AMQP through PECL\nTags: php, rabbitmq, amqp, pecl\nSource: Stack Overflow\n\nQuestion:\nI'm trying to install the RabbitMQ PECL extension but after running\n\n```\nsudo pecl install amqp\n```\n\nI get the following cryptic error message, which extensive googling hasn't helped resolve.\n\nI have these packages installed:\n\n- librabbitmq - RabbitMQ C client itself)\n\n- librabbitmq-dev - dev headers etc.\n\nand RabbitMQ running successfully on localhost\n\nMaybe it could be a mismatch in the version of the C client and what the PECL extension expects, anybody else come across this one?\n\nMake output below....\n\nCheers\n\n```\nrunning: make\n/bin/bash /tmp/pear/temp/pear-build-rootZNUmac/amqp-1.0.0/libtool --mode=compile cc -I. -I/tmp/pear/temp/amqp -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootZNUmac/amqp- 1.0.0/include -I/tmp/pear/temp/pear-build-rootZNUmac/amqp-1.0.0/main -I/tmp/pear/temp/amqp - I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM - I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib - D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/amqp/amqp.c -o amqp.lo\nlibtool: compile: cc -I. -I/tmp/pear/temp/amqp -DPHP_ATOM_INC -I/tmp/pear/temp/pear- build-rootZNUmac/amqp-1.0.0/include -I/tmp/pear/temp/pear-build-rootZNUmac/amqp-1.0.0/main - I/tmp/pear/temp/amqp -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM - I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib - D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/amqp/amqp.c -fPIC -DPIC -o .libs/amqp.o\n/bin/bash /tmp/pear/temp/pear-build-rootZNUmac/amqp-1.0.0/libtool --mode=compile cc -I. -I/tmp/pear/temp/amqp -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootZNUmac/amqp- 1.0.0/include -I/tmp/pear/temp/pear-build-rootZNUmac/amqp-1.0.0/main -I/tmp/pear/temp/amqp - I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM - I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib - D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/amqp/amqp_exchange.c -o amqp_exchange.lo\nlibtool: compile: cc -I. -I/tmp/pear/temp/amqp -DPHP_ATOM_INC -I/tmp/pear/temp/pear- build-rootZNUmac/amqp-1.0.0/include -I/tmp/pear/temp/pear-build-rootZNUmac/amqp-1.0.0/main - I/tmp/pear/temp/amqp -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM - I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib - D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/amqp/amqp_exchange.c -fPIC -DPIC -o .libs/amqp_exchange.o\n/bin/bash /tmp/pear/temp/pear-build-rootZNUmac/amqp-1.0.0/libtool --mode=compile cc -I. -I/tmp/pear/temp/amqp -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootZNUmac/amqp- 1.0.0/include -I/tmp/pear/temp/pear-build-rootZNUmac/amqp-1.0.0/main -I/tmp/pear/temp/amqp - I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM - I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib - D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/amqp/amqp_queue.c -o amqp_queue.lo\nlibtool: compile: cc -I. -I/tmp/pear/temp/amqp -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootZNUmac/amqp-1.0.0/include -I/tmp/pear/temp/pear-build-rootZNUmac/amqp-1.0.0/main - I/tmp/pear/temp/amqp -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM - I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib - D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/amqp/amqp_queue.c -fPIC -DPIC -o .libs/amqp_queue.o\n/tmp/pear/temp/amqp/amqp_queue.c: In function 'read_message_from_channel':\n/tmp/pear/temp/amqp/amqp_queue.c:316:11: error: 'AMQP_FIELD_KIND_U64' undeclared (first use in this function)\n/tmp/pear/temp/amqp/amqp_queue.c:316:11: note: each undeclared identifier is reported only once for each function it appears in\n/tmp/pear/temp/amqp/amqp_queue.c: In function 'zim_amqp_queue_class_nack':\n/tmp/pear/temp/amqp/amqp_queue.c:1020:2: error: unknown type name 'amqp_basic_nack_t'\n/tmp/pear/temp/amqp/amqp_queue.c:1039:3: error: request for member 'delivery_tag' in something not a structure or union\n/tmp/pear/temp/amqp/amqp_queue.c:1040:3: error: request for member 'multiple' in something not a structure or union\n/tmp/pear/temp/amqp/amqp_queue.c:1041:3: error: request for member 'requeue' in something not a structure or union\n/tmp/pear/temp/amqp/amqp_queue.c:1046:3: error: 'AMQP_BASIC_NACK_METHOD' undeclared (first use in this function)\nmake: *** [amqp_queue.lo] Error 1\nERROR: `make' failed\n```\n\n========================================\n\nTop Answer:\nI had to install it applying following steps found here:\n\n```\n# Download the rabbitmq-c library @ version 0-9-1\n git clone git://github.com/alanxz/rabbitmq-c.git\n cd rabbitmq-c\n # Enable and update the codegen git submodule\n git submodule init\n git submodule update\n # Configure, compile and install\n autoreconf -i && ./configure && make && sudo make install\n```\n\nAfter that, `sudo pecl install amqp` did the work.\n\nUsing Ubuntu 12.10 with PHP 5.4.3.\n\n========================================\n\nCode:\n```text\nsudo pecl install amqp\n```\n\n```text\nrunning: make\n/bin/bash /tmp/pear/temp/pear-build-rootZNUmac/amqp-1.0.0/libtool --mode=compile cc -I. -I/tmp/pear/temp/amqp -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootZNUmac/amqp- 1.0.0/include -I/tmp/pear/temp/pear-build-rootZNUmac/amqp-1.0.0/main -I/tmp/pear/temp/amqp - I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM - I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib - D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/amqp/amqp.c -o amqp.lo\nlibtool: compile: cc -I. -I/tmp/pear/temp/amqp -DPHP_ATOM_INC -I/tmp/pear/temp/pear- build-rootZNUmac/amqp-1.0.0/include -I/tmp/pear/temp/pear-build-rootZNUmac/amqp-1.0.0/main - I/tmp/pear/temp/amqp -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM - I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib - D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/amqp/amqp.c -fPIC -DPIC -o .libs/amqp.o\n/bin/bash /tmp/pear/temp/pear-build-rootZNUmac/amqp-1.0.0/libtool --mode=compile cc -I. -I/tmp/pear/temp/amqp -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootZNUmac/amqp- 1.0.0/include -I/tmp/pear/temp/pear-build-rootZNUmac/amqp-1.0.0/main -I/tmp/pear/temp/amqp - I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM - I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib - D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/amqp/amqp_exchange.c -o amqp_exchange.lo\nlibtool: compile: cc -I. -I/tmp/pear/temp/amqp -DPHP_ATOM_INC -I/tmp/pear/temp/pear- build-rootZNUmac/amqp-1.0.0/include -I/tmp/pear/temp/pear-build-rootZNUmac/amqp-1.0.0/main - I/tmp/pear/temp/amqp -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM - I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib - D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/amqp/amqp_exchange.c -fPIC -DPIC -o .libs/amqp_exchange.o\n/bin/bash /tmp/pear/temp/pear-build-rootZNUmac/amqp-1.0.0/libtool --mode=compile cc -I. -I/tmp/pear/temp/amqp -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootZNUmac/amqp- 1.0.0/include -I/tmp/pear/temp/pear-build-rootZNUmac/amqp-1.0.0/main -I/tmp/pear/temp/amqp - I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM - I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib - D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/amqp/amqp_queue.c -o amqp_queue.lo\nlibtool: compile: cc -I. -I/tmp/pear/temp/amqp -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootZNUmac/amqp-1.0.0/include -I/tmp/pear/temp/pear-build-rootZNUmac/amqp-1.0.0/main - I/tmp/pear/temp/amqp -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM - I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib - D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/amqp/amqp_queue.c -fPIC -DPIC -o .libs/amqp_queue.o\n/tmp/pear/temp/amqp/amqp_queue.c: In function 'read_message_from_channel':\n/tmp/pear/temp/amqp/amqp_queue.c:316:11: error: 'AMQP_FIELD_KIND_U64' undeclared (first use in this function)\n/tmp/pear/temp/amqp/amqp_queue.c:316:11: note: each undeclared identifier is reported only once for each function it appears in\n/tmp/pear/temp/amqp/amqp_queue.c: In function 'zim_amqp_queue_class_nack':\n/tmp/pear/temp/amqp/amqp_queue.c:1020:2: error: unknown type name 'amqp_basic_nack_t'\n/tmp/pear/temp/amqp/amqp_queue.c:1039:3: error: request for member 'delivery_tag' in something not a structure or union\n/tmp/pear/temp/amqp/amqp_queue.c:1040:3: error: request for member 'multiple' in something not a structure or union\n/tmp/pear/temp/amqp/amqp_queue.c:1041:3: error: request for member 'requeue' in something not a structure or union\n/tmp/pear/temp/amqp/amqp_queue.c:1046:3: error: 'AMQP_BASIC_NACK_METHOD' undeclared (first use in this function)\nmake: *** [amqp_queue.lo] Error 1\nERROR: `make' failed\n```\n\n```text\nhg clone http://hg.rabbitmq.com/rabbitmq-c/rev/b01825ecc112 rabbitmq-c\ncd rabbitmq-c\n# Add the codegen requirement. To find the full list, go here: http://hg.rabbitmq.com/rabbitmq-codegen/tags\n# and copy the URL for the appropriate broker version.\nhg clone http://hg.rabbitmq.com/rabbitmq-codegen/rev/16bbcb711380 codegen\n# Configure, compile and install\nautoreconf -i && ./configure && make && sudo make install\n```\n\n```text\n# Download the rabbitmq-c library @ version 0-9-1\n git clone git://github.com/alanxz/rabbitmq-c.git\n cd rabbitmq-c\n # Enable and update the codegen git submodule\n git submodule init\n git submodule update\n # Configure, compile and install\n autoreconf -i && ./configure && make && sudo make install\n```\n\n```text\nsudo pecl install amqp\n```\n\n```text\npecl install amqp-1.2.0\n```\n\n```text\napt-get install pkg-config librabbitmq-dev librabbitmq0\n\ngit clone https://github.com/alanxz/rabbitmq-c\ncd rabbitmq-c/\nautoreconf -i\n./configure\nmake\nmake install\npecl install amqp\n```\n\n```text\ngit clone https://github.com/alanxz/rabbitmq-c\ncd rabbitmq-c\ngit checkout tags/v0.5.2\ngit submodule init\ngit submodule update\nautoreconf -i && ./configure && make && make install\npecl install amqp\n```\n\n```text\napt-get update\n\nwget http://in.archive.ubuntu.com/ubuntu/ubuntu/pool/universe/libr/librabbitmq/librabbitmq1_0.5.2-2_amd64.deb\ndpkg -i librabbitmq1_0.5.2-2_amd64.deb\n\nwget http://in.archive.ubuntu.com/ubuntu/ubuntu/pool/universe/libr/librabbitmq/librabbitmq-dev_0.5.2-2_amd64.deb\ndpkg -i librabbitmq-dev_0.5.2-2_amd64.deb\n\napt-get install php7.0 php7.0-mbstring php7.0-mcrypt php7.0-mysql php7.0-xml php7.0-dev\n\npecl install amqp\n\necho \"extension=amqp.so\" >> /etc/php/7.0/cli/php.ini\necho \"extension=amqp.so\" >> /etc/php/7.0/fpm/php.ini\n```\n\n```text\nbento/ubuntu-16.04\n```\n\n```text\nphp7.0\n```\n\n```text\nLibrabbitmq-dev\n```\n\n========================================\n\nComments:\n- I've experienced this also. On a Ubuntu Lucid system, I pulled rabbitmq-server from Ubuntu repositories, and librabbitmq-dev from the Drizzle PPA. Then doing `pecl install amqp-beta` results in the above error message. The same exact message also results from `pecl install amqp`.\n- Or use the PHP only github.com/php-amqplib/php-amqplib library\n- Yep, Having looked at the RabbitMQ C library they make it clear it's experimental and finding a version that the PECL extension will compile against is hit and miss Instead I'm just going with a pure PHP implementation php-amqplib Cheers\n- This also worked for me on 32bit 12.04 PHP 5.3. However on 13.04 64bit PHP 5.4 the PECL extension compiles but loading it in apache gives the following error: \"PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20100525/amqp.so' - /usr/lib/php5/20100525/amqp.so: undefined symbol: amqp_open_socket in Unknown on line 0.\" Have you managed to get this to work? Any ideas?\n- On newer release versions such as Ubuntu 14.04 and PHP 5.6, you need to checkout the latest tag on the rabbitmq-c repository.pph\n- nice tip! It's Werd but only 1.6.beta version worked for me ubuntu 14/PHP 5.6\n- This worked for me when all the other solutions failed (compilation errors galore). Thank you!","metadata":{"transformedAt":"2026-08-18T18:33:20.121Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":186,"estimatedTokens":3164}}76{"id":"stack-45208766","source":"stackoverflow","questionId":45208766,"title":"Microservices Why Use RabbitMQ?","tags":["rabbitmq","microservices"],"text":"Title: Microservices Why Use RabbitMQ?\nTags: rabbitmq, microservices\nSource: Stack Overflow\n\nQuestion:\nI haven't found an existing post asking this but apologize if I missed it. \n\nI'm trying to get my head round microservices and have come across articles where RabbitMQ is used. I'm confused why RabbitMQ is needed. Is the intention that the services will use a web api to communicate with the outside world and RabbitMQ to communicate with each other?\n\n========================================\n\nTop Answer:\nA message queue provide an **asynchronous communications protocol** - You have the option to send a message from one service to another without having to know if another service is able to handle it immediately or not. Messages can wait until the responsible service is ready. A service publishing a message does not need know anything about the inner workings of the services that will process that message. This way of handling messages **decouple** the producer from the consumer.\n\nA message queue will keep the processes in your application separated and independent of each other; this way of handling messages could create a system that is **easy to maintain and easy to scale**.\n\nSimply put, two obvious cases can be used as examples of when message queues really shine:\n\n- For long-running processes and background jobs\n\n- As the middleman in between microservices\n\n**For long-running processes and background jobs:**\n\nWhen requests take a significant amount of time, it is the perfect scenario to incorporate a message queue.\n\nImagine a web service that handles multiple requests per second and cannot under any circumstances lose one. Plus the requests are handled through time-consuming processes, but the system cannot afford to be bogged down. Some real-life examples could include:\n\n- Images Scaling\n\n- Sending large/many emails (like newsletters)\n\n- Search engine indexing\n\n- File scanning\n\n- Video encoding\n\n- Delivering notifications\n\n- PDF processing\n\n- Calculations\n\n**The middleman in between microservices:**\n\nFor communication and integration within and between applications, i.e. as the middleman between microservices, a message queue is also useful. Think of a system that needs to notify another part of the system to start to work on a task or when there are a lot of requests coming in at the same time, as in the following scenarios:\n\n- Order handling (Order placed, update order status, send an order, payment, etc.)\n\n- Food delivery service (Place an order, prepare an order, deliver food)\n\n- Any web service that needs to handle multiple requests\n\nHere is a story explaining how Parkster (a digital parking service) are breaking down their system into multiple microservices by using RabbitMQ.\n\nThis guide a scenario where a web application allows users to upload information to a web site. The site will handle this information and generate a PDF and email it back to the user. Handling the information, generating the PDF and sending the email will in this example case take several seconds and that is one of the reasons of why a message queue will be used.\n\nHere is a story about *how* and *why* CloudAMQP used message queues and RabbitMQ between microservices.\n\nHere is a story about the usage of RabbitMQ in an event-based microservices architecture to support 100 million users a month.\n\nAnd finally a link to Kontena, about why they chose RabbitMQ for their microservice architecture: \"Because we needed a stable, manageable and highly-available solution for messaging.\".\n\nPlease note that I work for the company behind CloudAMQP (hosting provider of RabbitMQ).\n\n========================================\n\nComments:\n- You can view bellow link. It has a wide description: stackoverflow.com/a/51377756/3073945\n- If you are on the .net Platform check out NServiceBus (particular.net) for asynchronous messaging (and can run RabbitMQ as a transport)\n- You say synchrnous mode results in dependency. If you have a central hub that sits outside if microservice, doesnt that also imply dependency?\n- @mko, it is. It's even called \"Single point of failure\".There is no silver bullet, one must weight the pros and cons of both approaches\n- @mko I dont really agree with you here. Adding just a central hub is going towards synchronous system. You could also add a message queue locally to (each) microservice. That would be a true async communication.\n- @mko ,In that case, how are you going to implement the communication between service A and service B? A must know that B (or it's queue) exists, which is in fact synchronous communication.\n- I dont agree with you. You didnt consider loosing an event due to unavailability of a central hub. That is what async is all about\n- @mko but the point is that you don't need to know which service is responsible for the message. When you (service A) are contacting service B or multiple services. Therefore -> tightly coupled. With message queues, you don't need to care which services are responsible for the message being processed. You just publish it and the services will read it from the queue. The queue is not really a \"single point of failure\" if you have a fault-tolerant cluster of many queues for instance.\n- Remember that you have to disclose your affiliation with the content of the answers that you post. Since you've written those posts for the company that you work for (a wild guess based on your account name and the author's name) you also have to state that as expressed in the behavior description for Stack Exchange sites: `Post good, relevant answers, and if some (but not all) happen to be about your product or website, that’s okay. However, you *must* disclose your affiliation in your answers.`\n- Thank you for your comment. You are right, I should add more information from other sources, and I added information about where I work. I will look into the answer again and also into the link you posted. Thanks!","metadata":{"transformedAt":"2026-08-18T18:33:20.122Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":79,"estimatedTokens":1481}}77{"id":"stack-10745084","source":"stackoverflow","questionId":10745084,"title":"RabbitMQ and message priority","tags":["rabbitmq"],"text":"Title: RabbitMQ and message priority\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nDoes RabbitMQ have any concept of message priority? I have an issue where some more important messages are being slowed down due to less important messages sitting before them in the queue. I want the high-priority ones to take precedence and move to the front of the queue.\n\nI know I can approximate this using two queues, a \"fast\" queue and a \"slow\" queue, but that seems like a hack.\n\nDoes anyone know of a better solution using RabbitMQ?\n\n========================================\n\nTop Answer:\nRabbit has no concept of priority other than, as Brian succinctly puts it, the one in front gets there first. ;-)\n\nI would suggest implementing a set of queues that serve to service your particular messaging need and have these queues model your prioritisation need by, say, calling them 'MyQueueP1', 'MyQueueP2' and so on and then have our consumer(s) check P1 before P2 (etc.) and service messages from there first.\n\nIf you then have a message that is high priority you would publish it to the appropriate priority queue by way of a suitable routing key and voila.\n\n[update]\nCheck this question:\nIn a FIFO Qeueing system, what's the best way the to implement priority messaging\n\n[update]\n**As per recent RabbitMQ release 3.5.0 this answer is now outdated** and should be considered valid for only versions prior to this release.\nhttps://stackoverflow.com/a/29068288/489888\n\n========================================\n\nCode:\n```text\nMessages may have a priority level. A high priority message is sent ahead of lower priority messages\nwaiting in the same message queue. When messages must be discarded in order to maintain a specific\nservice quality level the server will first discard low-priority messages.\n```\n\n```text\nNote that in the presence of multiple readers from a queue, or client transactions, or use of priority fields,\nor use of message selectors, or implementation-specific delivery optimisations the queue MAY NOT\nexhibit true FIFO characteristics.\n```\n\n```text\nMap<String, Object> props = new HashMap<>();\nprops.put(\"x-max-priority\", 10); // max priority number as 10\nchannel.queueDeclare(QUEUE_NAME, durable, false, false, props);\n```\n\n```text\nString message = \"My message with priority 7\";\nAMQP.BasicProperties.Builder basicProps = new AMQP.BasicProperties.Builder();\nbasicProps.contentType(\"text/plain\")\n .priority(7);\nchannel.basicPublish(\"\", QUEUE_NAME, basicProps.build(), message.getBytes());\n```\n\n```text\nx-max-priority\n```\n\n```text\nx-max-priority\n```\n\n```text\nusing RabbitMQ.Client;\npublic void Setup()\n{\n ConnectionFactory factory = new() { host = \"\", username = \"\", password = \"\" };\n var connection = factory.CreateConnection();\n var model = connection.CreateModel();\n var args = new Dictionary<string, object>\n {\n { \"x-min-priority\", 0 },\n { \"x-max-priority\", 9 }\n };\n model.QueueDeclare(\"Queue1\", arguments: args);\n}\n```\n\n```text\nprivate static void Send(IModel model, string queue, string message, byte priority)\n{\n var body = Encoding.UTF8.GetBytes(message);\n\n var basicProperties = model.CreateBasicProperties();\n basicProperties.Priority = priority;\n\n model.BasicPublish(exchange: \"\",\n routingKey: queue,\n basicProperties: basicProperties,\n body: body);\n}\n```\n\n========================================\n\nComments:\n- pretty sure the point of a queue is that its FIFO, therefore there concept of priority goes out the window.\n- Many technologies such as ActiveMQ have a message priority concept as well. This lets the queue be a hybrid FIFO/Priority queue.\n- Outdated answer, Rabbit supports priority\n- This answer was incorrect until a week ago when RabbitMQ 3.5.0 was released and announced support for priority queues ;-)\n- Thanks for the reply, I was hoping to avoid setting up multiple queues for this but it looks like it the way to go.\n- Some info from [www.rabbitmq.com/api-guide.html] : Section **Publishing messages** : This sends a message with delivery mode 2 (persistent), priority 0 and content-type \"text/plain\". You can build your message properties object, using a Builder class mentioning as many properties as you like, for example: channel.basicPublish(exchangeName, routingKey, new AMQP.BasicProperties.Builder() .contentType(\"text/plain\").deliveryMode(2) .priority(1).userId(\"bob\") .build()), messageBodyBytes);\n- But there is no other explanation about \"priority\", and what do they mean\n- As of 3.5.0 - RabbitMQ supports priority queues: rabbitmq.com/priority.html\n- is it only the java implementation that works? I'm struggling to make it work in C#. I've asked a question here: http://stackoverflow.com/questions/29221020/rabbitmq-3-5-and‌​-message-priority?lq‌​=1\n- This answer is out-of-date. As it is the accepted answer, would you mind updating it to reflect the current state?\n- @womble, I did, 9 days ago :-)\n- The opening sentence says \"Rabbit has no concept of priority\". This is incorrect.\n- @womble - I agree, though this was correct at the time of posting. The answer remains as is in order to preserve the context. I have appended an update indicating that the answer is no longer relevant. I'm pretty sure that folk are able to this. Feel free to flag this with a community moderator if you feel that my actions aren't sufficient.\n- There are plenty of message queues (HornetQ, ActiveMQ...etc) that implement message priority and plenty of use cases that support it.\n- In effect these are simply logical extensions of the idea of independent queues. The term priority seldom has any real meaning as far as the pipeline goes. It is semantic sugar. I didnt say dont use them, I said it is a potential trap to be aware of. Many programmers presume that high priority means faster execution time. When they have a coupled process they figure put it in the low priority queue and that is good enough. If it works much of the time it is accepted and adopted as correct. Then systems start to fail unaccountably and it is horrible to debug.\n- Tangential, but I don't see how email would guarantee order of delivery. In fact, email *does* have (crude) transport priorities, by way of the `Precedence:` header.\n- Oh how the turntables\n- hello @Womble, I've read the doc and had a bit of trouble implementing it. Other documentation is pretty sparse. If you've got any insight. My question is here\n- it seems it is not a message priority but consumer priority, which I think are different concepts and not answers to above question.\n- Changed this to the correct answer since RabbitMQ now supports priority queues.\n- One thing about RabbitMq message priorities is that consumers are hungry. If you publish a load of messages with different priorities then they will tend towards the priority, but it isn't exactly guaranteed because the receive endpoint gets messages as they arrive. Another way to do this is to have two consumers with different max priorities enabled. The one with the higher max will process all messages, whilst the lower priority consumer will process only up to that max setting.\n- How to set priority for consumer, who have to get message first or last?","metadata":{"transformedAt":"2026-08-18T18:33:20.122Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":121,"estimatedTokens":1817}}78{"id":"stack-1038318","source":"stackoverflow","questionId":1038318,"title":"Check RabbitMQ queue size from client","tags":[".net","message-queue","rabbitmq","amqp"],"text":"Title: Check RabbitMQ queue size from client\nTags: .net, message-queue, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nDoes anyone know if there's a way to check the number of messages in a RabbitMQ queue from a client application?\n\nI'm using the .NET client library.\n\n========================================\n\nTop Answer:\nI am 2 years too late but I was searching for it myself and found that rabbitmq gives u simple script to communicate to erlang nodes..its in sbin folder where the starting script for RabbitMQ is located..so you can basically say\n\n```\n./rabbitmqctl list_queues\n```\n\nthis will display the queues along with the count of messages pending to those queues\nsimilarly you can also say \n\n```\n./rabbitmqctl list_channels\n./rabbitmqctl list_connections\n```\n\netc.\nFor more info you can visit here\n\n========================================\n\nCode:\n```python\nname, jobs, consumers = chan.queue_declare(queue=queuename, passive=True)\n```\n\n```text\nqueue_declare\n```\n\n```text\n(<queue name>, <message count>, <consumer count>)\n```\n\n```text\npassive\n```\n\n```text\nqueue_declare\n```\n\n```text\nqueue_declare\n```\n\n```text\npassive\n```\n\n```text\n./rabbitmqctl list_queues\n```\n\n```text\n./rabbitmqctl list_channels\n./rabbitmqctl list_connections\n```\n\n```text\ndef cbInspect(qb):\n messagesInQueue = qb.method.message_count\n print \"There are %d messages in myQueue\" % messagesInQueue\n\n consumersInQueue = qb.method.consumer_count\n print \"There are %d consumers in myQueue\" % consumersInQueue\n\n return\n\nmyChannel = channel.queue_declare(callback=cbInspect, queue='myQueue', passive=True)\n```\n\n```text\n'myQueue'\n```\n\n```text\nBasicGetResult result = channel.BasicGet(\"QueueName\", false);\nuint count = result != null ? result.MessageCount : 0;\n```\n\n```text\nQueueDeclareOk result = channel.QueueDeclare();\nuint count = result.MessageCount;\n```\n\n```text\n<InstallPathToRabbitMq>\\sbin\\rabbitmqctl.bat list_queues\n```\n\n```text\nQueueDeclareOk result = channel.QueueDeclarePassive(queueName);\nuint count = result != null ? result.MessageCount : 0;\n```\n\n```text\n// The last segment of the URL is the RabbitMQ \"virtual host name\". \n// The default virtual host name is \"/\", represented urlEncoded by \"%2F\".\nstring queuesUrl = \"http://MY_RABBITMQ_SERVER:15672/api/queues/%2F\";\n\nWebClient webClient = new WebClient { Credentials = new NetworkCredential(\"MY_RABBITMQ_USERNAME\", \"MY_RABBITMQ_PASSWORD\") };\nstring response = webClient.DownloadString(queuesUrl);\n```\n\n```text\npublic uint GetMessageCount(string queueName)\n{\n using (IConnection connection = factory.CreateConnection())\n using (IModel channel = connection.CreateModel())\n {\n return channel.MessageCount(queueName);\n }\n}\n```\n\n```text\nfrom pyrabbit.api import Client\n cl = Client('10.111.123.54:15672', 'userid', 'password',5)\n depth = cl.get_queue_depth('vhost', 'queue_name')\n```\n\n```text\nconn = kombu.Connection('amqp://userid:password@10.111.123.54:5672/vhost')\nconn.connect()\nclient = conn.get_manager()\nqueues = client.get_queues('vhost')\nfor queue in queues:\n if queue == queue_name:\n print(\"tasks waiting in queue:\"+str(queue.get(\"messages_ready\")))\n print(\"tasks currently running:\"+str(queue.get(\"messages_unacknowledged\")))\n```\n\n```text\ncurl -s -i -u $user:$password http://$host_ip_address:15672/api/queues/$vhost_name/$queue_name | sed 's/,/\\n/g' | grep '\"messages\"' | sed 's/\"messages\"://g'\n```\n\n========================================\n\nComments:\n- This should be the accepted answer, even if he did miss Basic.Get as the 2nd source of this info.\n- What is chan here and how to import it ?\n- This is no longer the best way to do it.\n- @Theyouthis It's very frustrating to find comments like \"This is no longer the best way to do it\" without any sort of reference to the improved way that you are referring to. Why not your findings?\n- Use the MessageCount() function on your IModel. If you scroll down you will see two answers mention the function on this very question.\n- This is done differently nowadays: `result = channel.queue_declare(queue=queuename, passive=True).method`. And then you would just access `result.message_count` because the result is not unpackable. ``\n- Used this passive declaration in java for some time, but seems that lately it is so slow to update. I switched to http client requesting rabbit api, since it was not updating as it should (almost always it showed to have 0 total messages).\n- channel.queue_declare returns an object that contains the current message count so if you want to avoid a callback, you can also access the message count like this: myChannel.method.message_count\n- This is the first time I have seen this mentioned. Why is that?!!","metadata":{"transformedAt":"2026-08-18T18:33:20.122Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":20,"totalLines":158,"estimatedTokens":1171}}79{"id":"stack-9874234","source":"stackoverflow","questionId":9874234,"title":"Why can't you look at messages in the Rabbit Queue","tags":["rabbitmq"],"text":"Title: Why can't you look at messages in the Rabbit Queue\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nIf my understanding is correct, you can't actually look at messages in the rabbit queue without taking them out and putting them back in. There's no way to use rabbitmqctl to inspect a queue.\n\nIn some debugging contexts, knowing what is currently in the queue is very useful. Is there a way to get at the messages? Also, what is it about the design of Rabbit that makes this process cumbersome?\n\n========================================\n\nTop Answer:\nThere is a \"Get Messages\" section for each queue in the management API. However this causes the message to be consumed and hence is a destructive action. We can re-queue this message to the queue only at the expense of sacrificing the ordering of messages [for rabbitmq versions A more viable alternative would be to use the firehose tracer, http://www.rabbitmq.com/firehose.html [for rabbitmq versions> 2.5]. This essentially publishes the message to a different exchange (amq.rabbitmq.trace) just for debugging purposes.\n\nHere is another GUI written on top of firehose for better visibility, http://www.rabbitmq.com/blog/2011/09/09/rabbitmq-tracing-a-ui-for-the-firehose/\n\n========================================\n\nCode:\n```text\nQueues\n```\n\n```text\nRequeue\n```\n\n```text\nYes\n```\n\n========================================\n\nComments:\n- Yes, and it's quite useful! Unfortunately, that tool mostly provides aggregate statistics, and no mechanism to see what's inside the queue (unless I'm mistaken).\n- @archgoon now you got me interested even more because I had assumed the plugin did this. I looked at the mailing list and some people were building plugins for something similar lists.rabbitmq.com/pipermail/rabbitmq-discuss/2011-March/… I hope this exists but if the features does not, I might just have my program write this data as a quick query to mysql or a file so I can monitor. I hope something exists, sorry I couldn't be of more help.\n- According to Brian Kelly, it appears you can in fact look at message contents from the web interface. I'll go look at it again.\n- @archgoon I thought so too but didn't get around to testing it yet. Glad to see you got the answer. I learned something too, thanks!\n- Ah, so the web interface does do that. I guess I'll have to look at it again. Thank you.\n- It's in \"Queues\", pick a queue, scroll down to \"Get messages\".\n- Sure, but doing that eats the message in question. Not the intended result.\n- @Matthias not if you don't ack them.\n- @BrianKelly So you get them again if nobody else picks them up. Or you miss some if somebody else picks them up first. Both don't match my definition of \"monitor\".\n- @MatthiasUrlichs neither the question nor this answer mentioned \"monitor\".\n- If it's something you're going to do quite often, then you can sort of do this yourself - have your Exchange post to your normal queue and a secondary 'monitoring' queue, which either consumes all messages and provides some way to see them, or else expires them when the queue gets too long or too old.\n- Good solution. I believe you can also simply have your exchange fan out to each queue it knows, and your logger can just attach (bind) a queue when it needs. rabbitmq.com/tutorials/tutorial-three-python.html\n- it won't be lost, but unfortunately it will be requeued so the original order (and possibly timestamp) of the messages will be lost\n- Not sure that's how it works -- it seems to leave the top message at the top after the requeue -- I use this interface to first view the top message, and then set requeue to no to get rid of the first message. So perhaps 'Requeue' really means get it without acking it, and put it back to ready by destroying the consumer.\n- Official documentation says \"When a message is requeued, it will be placed to its original position in its queue, if possible. If not (due to concurrent deliveries and acknowledgements from other consumers when multiple consumers a queue), the message will be requeued to a position closer to queue head.\" rabbitmq.com/nack.html\n- Not sure if Queue Viewer still exist but, I found that QueueExplorer works perfectly with RabbitMQ, exactly what I needed.","metadata":{"transformedAt":"2026-08-18T18:33:20.122Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":50,"estimatedTokens":1055}}80{"id":"stack-21742232","source":"stackoverflow","questionId":21742232,"title":"RabbitMQ dead letter exchange never getting messages","tags":["rabbitmq","dead-letter"],"text":"Title: RabbitMQ dead letter exchange never getting messages\nTags: rabbitmq, dead-letter\nSource: Stack Overflow\n\nQuestion:\nI'm trying to setup my first RabbitMQ dead letter exchange, here are the steps I'm using through the web admin interface:\n\n- Create new DIRECT exchange with the name \"dead.letter.test\"\n\n- Create new queue \"dead.letter.queue\"\n\n- Bind \"dead.letter.queue\" to \"dead.letter.test\"\n\n- Create new queue \"test1\" with the dead letter exchange set to \"dead.letter.test\"\n\n- Send a message into \"test1\"\n\n- Nack (with requeue = false) the message in \"test1\"\n\nI am expecting that these steps should put a record into the \"dead.letter.queue\" through the \"dead.letter.test\" exchange. This is not happening. \n\nI can manually put a message into the \"dead.letter.test\" exchange and it shows up in \"dead.letter.queue\" so I know that is fine.\n\nWhen I look at the admin UI it shows that the DLX parameter is setup on the queue \"test1\".\n\nWhere am I going wrong?\n\n========================================\n\nTop Answer:\n### Dead Letter Exchange without routing key and with direct exchange\n\n \n\n the steps these will work for sure:-\n\n 1. Create a new queue named '**dead_queue**'. \n\n 2. Create an exchange named '**dead_exchange**' and type of exchange should be 'direct'.\n\n 3. Bind '**dead_queue**' and '**dead_exchange**' without routing key.\n\n 4. Create a new queue named '**test_queue**' and set its '**x-dead-letter-exchange**' name as '**dead_exchange**'\n\n 5. Create an exchange named '**test_exchange**' and type of exchange should be 'direct'\n\n 6. Bind '**test_exchange**' and '**test_queue**' without routing key.\n\nAnd at last we will check it. For this publish something on '**test_exchange**' with argument '**expiration**' set to 10000. After this when a message is publish on '**test_exchange**' it will go to '**test_queue**' and when a message is expired with in a queue it will look for DLX Parameter(Dead Letter Exchange name) there that message find the name '**dead_exchange**' then that message will reach '**dead_exchange**' deliver it to '**dead queue**' ..\nIf still you have any problem regarding this and if i miss understood your problem... write your problem i will surely look over it... Thanks..\n\n**Note:** Must publish the message on '**test_exchange**' because that test_queue and test_exchange binding is without routing key and it will work fine but If you publish message on '**test_queue**' default exchange and routing key will be used.Then after expiration of message queue tries to deliver that dead message to dead_exchange with some default routing key and message will not go to that queue.\n\n========================================\n\nCode:\n```text\nx-dead-letter-routing-key\n```\n\n```text\ntest1\n```\n\n```text\nx-dead-letter-exchange=dead.letter.test\n```\n\n```text\nx-dead-letter-routing-key=dead.letter.queue\n```\n\n```text\ntest1\n```\n\n```text\nsudo rabbitmqctl -p /my/vhost/path set_policy DLX \".*\" '{\"dead-letter-exchange\":\"MyExchange.DEAD\"}' --apply-to queues\n```\n\n```text\nvar amqp = require(\"amqplib/callback_api\");\nvar crontab = require('node-crontab');\n\namqp.connect(\"amqp://localhost\", function (err, conn) {\nconn.createChannel(function (err, ch) {\n var ex = 'direct_logs';\n var ex2 = 'dead-letter-test';\n var severity = 'enterprise-1-key';\n\n //assert \"direct\" exchange\n ch.assertExchange(ex, 'direct', { durable: true });\n //assert \"dead-letter-test\" exchange\n ch.assertExchange(ex2, 'direct', { durable: true });\n\n //if acknowledgement is nack() then message will be stored in second exchange i.e. ex2=\"dead-letter-test\"\n ch.assertQueue('enterprise-11', { exclusive: false, deadLetterExchange: ex2 }, function (err, q) {\n var n = 0;\n console.log(' [*] Waiting for logs. To exit press CTRL+C');\n console.log(q);\n\n //Binding queue with \"direct_logs\" exchange\n ch.bindQueue(q.queue, ex, severity);\n //Binding the same queue with \"dead-letter-test\"\n ch.bindQueue(q.queue, ex2, severity);\n\n ch.consume(q.queue, function (msg) {\n // consume messages via \"dead-letter-exchange\" exchange at every second.\n if (msg.fields.exchange === ex2) {\n crontab.scheduleJob(\"* * * * * *\", function () {\n console.log(\"Received by latest exchange %s\", msg.fields.routingKey, msg.content.toString());\n });\n } else {\n console.log(\"Received %s\", msg.fields.routingKey, msg.content.toString());\n }\n\n if (n < 1) {\n // this will executes first time only. Here I'm sending nack() so message will be stored in \"deadLetterExchange\"\n ch.nack(msg, false, false);\n n += 1;\n } else {\n ch.ack(msg)\n n = 0\n }\n }, { noAck: false });\n });\n });\n});\n```\n\n```text\nackMode=\"MANUAL\"\n```\n\n```text\nspring.rabbitmq.listener.simple.default-requeue-rejected=false\nspring.rabbitmq.listener.simple.concurrency=5\nspring.rabbitmq.listener.simple.max-concurrency=10\n```\n\n```java\n@Bean\n public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {\n SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();\n factory.setConnectionFactory(connectionFactory);\n factory.setConcurrentConsumers(5);\n factory.setMaxConcurrentConsumers(10);\n factory.setDefaultRequeueRejected(false);\n return factory;\n }\n```\n\n```text\nx-dead-letter-exchange\n```\n\n```text\nx-dead-letter-routing-key\n```\n\n```text\nspring.rabbitmq.listener.simple.default-requeue-rejected=false\n```\n\n```text\napplication.properties\n```\n\n```text\nSimpleRabbitListenerContainerFactory\n```\n\n```text\ndefaultRequeueRejected\n```\n\n```text\nSimpleRabbitListenerContainerFactory\n```\n\n```text\n@Configuration\n```\n\n```text\nSimpleRabbitListenerContainerFactory\n```\n\n```text\n@Config\n```\n\n========================================\n\nComments:\n- What routing key are you using?\n- Atul, the \"test1\" queue is not bound to any exchange, I'm just publishing directly to it for testing purposes. What I want is that when any message from \"test1\" is nacked that the message be put into the \"dead.letter.test\" exchange.\n- You will have to bind it to dead.letter.test. BTW how did you created queue without mentioning which exchange?\n- My guess, if you have not mentioned exchange then your queue is automatically binded to default exchange so your messages are getting published to default exchange\n- Atul, you are correct, if you don't say what exchange a queue is on (which is valid) then when you send messages directly to the queue it goes through the default exchange. Either way though, if a message is nacked on a queue (regardless of how it got into that queue) shouldn't it then be sent to the dead-letter-queue associated with the original queue (test1)?\n- The core idea in the messaging model in RabbitMQ is that the producer never sends any messages directly to a queue. Actually, quite often the producer doesn't even know if a message will be delivered to any queue at all. Instead, the producer sends messages to an exchange. An exchange is a very simple thing it receives messages from producers and the pushes them to queues. The exchange must know exactly what to do with a message it receives. Should it be appended to a particular queue? Should it be appended to many queues? Or should it get discarded.\n- Zaq, thanks for the response, I tried adding the x-dead-letter-exchange and the x-dead-letter-routing-key but I'm still not getting nacked messages to go into the dead letter exchange. My goal is simple: any message in the \"test1\" queue that is nacked will get put into the \"dead.letter.test\" exchange and then any queue that is attached to that exchange will receive the message. Do I need custom routing keys on the message to accomplish this?\n- Specify in question language and library you are using to deal with amqp broker. And add some code that reproduce your problem. Also specify RabbitMQ version.\n- In addition, setup Alternate Exchange, just in case your messages can't be routed. One of possible solution is to experiment on FANOUT exchange which definitely will rout message everywhere.\n- @jhilden did you solve you problem ? I have the same issue\n- What if i want a dead letter queue with single exchange and redirect based on the route key . Is it possible with fanout ?\n- Solution to K-lyer's question: the only thing \"special\" about the dead letter exchange usage is that you bind it with the x-dead-letter-exchange and optional x-dead-letter-routing-key properties. If you want to redirect on a routing key just make it a direct exchange, and bind your queues to it.\n- for someone who want this to work with direct exchange and single queue, while binding the queue and add queue name as routing key property\n- Do you have any node js code for reference, I am trying to find where do I define the dead_exchange in publisher ? I already have set up a topic exchange.\n- @user269867 Sure, I will look into it. Because now a days I am working on node js. We can directly talk over skype `sahil.gulati1991@outlook.com`\n- I really recommend this approach as it far more flexible and the recommended approach from the rabbitmq team. I implemented both approaches and the policy one resulted in a lot less complex code and makes it very easy to dynamically change the behavior without backing up and recreating queues. See why you should use policies instead here: rabbitmq.com/parameters.html#policies\n- I've tried policies on both the exchange and queue level and messages never end up in my dead letter exchange, despite it working fine if I declare through arguments when declaring queue. I agree with ^^, this is a much nicer solution, not least because I don't have to redeclare/recreate/migrate queues when I want to update the policy.","metadata":{"transformedAt":"2026-08-18T18:33:20.122Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":20,"totalLines":212,"estimatedTokens":2481}}81{"id":"stack-16838416","source":"stackoverflow","questionId":16838416,"title":"Service Oriented Architecture - AMQP or HTTP","tags":["http","rabbitmq","soa","scaling","amqp"],"text":"Title: Service Oriented Architecture - AMQP or HTTP\nTags: http, rabbitmq, soa, scaling, amqp\nSource: Stack Overflow\n\nQuestion:\nA little background.\n\nVery big monolithic Django application. All components use the same database. We need to separate services so we can independently upgrade some parts of the system without affecting the rest. \n\nWe use RabbitMQ as a broker to Celery.\n\nRight now we have two options:\n\n- HTTP Services using a REST interface.\n\n- JSONRPC over AMQP to a event loop service\n\nMy team is leaning towards HTTP because that's what they are familiar with but I think the advantages of using RPC over AMQP far outweigh it.\n\nAMQP provides us with the capabilities to easily add in load balancing, and high availability, with guaranteed message deliveries. \n\nWhereas with HTTP we have to create client HTTP wrappers to work with the REST interfaces, we have to put in a load balancer and set up that infrastructure in order to have HA etc.\n\nWith AMQP I can just spawn another instance of the service, it will connect to the same queue as the other instances and bam, HA and load balancing.\n\nAm I missing something with my thoughts on AMQP?\n\n========================================\n\nTop Answer:\nThe irony of the solution OP had to accept is, AMQP or other MQ solutions are often used to insulate callers from the inherent unreliability of HTTP-only services -- to provide some level of timeout & retry logic and message persistence so the caller doesn't have to implement its own HTTP insulation code. A very thin HTTP gateway or adapter layer over a reliable AMQP core, with option to go straight to AMQP using a more reliable client protocol like JSONRPC would often be the best solution for this scenario.\n\n========================================\n\nCode:\n```text\npickle\n```\n\n========================================\n\nComments:\n- We ended up going with HTTP/REST. I really wanted to go the AMQP route because it fit so nicely into our architecture but my team didnt want to try something new so that's a bummer. So much more work is needed for development of a redudant and highly available SOA system using HTTP instead of AMQP and RPC.\n- @pinepain I think one thing to mention (and correct me if Iam wrong) is that with AMQP you can actually push messages to the destination where as with HTTP you cant (working on request-response method)\n- @rayman HTTP and AMQP are different concepts, so I'd prefer not use such criteria for their comparison.\n- @pinepain I agree but still thats a capability which should be considered when thinking about solution messaging solution (to http or not to http)\n- @rayman exactly, AMQP is very different from HTTP by many factors, like already mentioned advanced routing, connection multiplexing (which added in http2) and so on. Same for HTTP, caching, proxying, methods and so on. My original point is HTTP and AMQP are on the different level and comparing them may be like comparing car and train: while both are vehicles, they are different in many aspects.\n- Here is a good read from the comparison point of view :blogs.perficient.com/ibm/2012/06/07/mq-vs-http\n- @pinepain I know this is an old question, but as a clarification why does AMQP scale better than HTTP? Intuitively, AMQP forces all traffic through a broker and I would assume that the broker then becomes a bottleneck especially if all message passing in the architecture is based on funneling traffic through a broker? In that sense HTTP would seen to scale better even if inferior in other respects?\n- @Kevin Thank you for a good question. At that time of writing here's what was in my mind: speaking about particular implementation of AMQP - RabbitMQ, scaling horizontally would mean adding a node in a cluster and enabling queue mirroring, then scaling application horizontally would mean adding more workers, so eventually we have no SPOF, while with REST solutions, we normally have to have LB in front of it which became a real bottleneck. Nowadays I would say that with service discovery and k8s it shouldn't make any significant difference in terms of scaling infra nowadays.\n- @Kevin Though as long as broker/LB is not a bottleneck, scaling *application* with adding more workers to AMQP looks easier to me, and giving that AMQP and MQ in general fits a long-running tasks processing far more better and used for tasks which doesn't require realtime processing, broker is rarely a bottleneck, unlike LB in HTTP.\n- I don't know one way or the other but it would be surprising to me if a broker scales better than a load balancer. I would assume it generally scales worse but message queues generally provide desirable extra features on top of HTTP and that would be a key trade off.\n- In case of RabbitMQ, if clustering used and queue has HA option on, single broker is rarely and issue (at some cost, obviously). I see your point, I agree that `scales better` is a subjective opinion which may be influenced by experience with technologies in question and to state this I should backed it by more facts. What I'm going to do is to alter original answer to point that both solutions scales well. The issue comparing HTTP and AMQP is that it's like apple to oranges to some extent. Thanks a lot for bringing this up! Merry Xmas!\n- I have a lot more experience then when I originally asked this question. I am very glad that my team stopped me and we stuck with the standard approach. For what it's worth though I have personally 100% abandoned using REST in any future projects and try to exclusively use gRPC or Cap'n Proto. When I need a message queue I use NATS and if I need guarantees I use NATS streaming. These are all just personal choices. I think at the end of the day unless you have extreme requirements any solution that is well thought out and tested will work just fine.","metadata":{"transformedAt":"2026-08-18T18:33:20.122Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":54,"estimatedTokens":1454}}82{"id":"stack-13946153","source":"stackoverflow","questionId":13946153,"title":"Rabbitmq server connection closing abruptly","tags":["connection","rabbitmq"],"text":"Title: Rabbitmq server connection closing abruptly\nTags: connection, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have tried to use Rabbitmq server for some reason the connection closes abruptly even though I passed the correct username and password.\n\nRabbitmq server is running on port 5672 and telneting to my server at port 5672 says its running fine.\n\nI have installed rabbitmq server in CentOS and my rabbitmq server log are as follows:\n\n```\n=INFO REPORT==== 19-Dec-2012::06:25:44 ===\naccepted TCP connection on [::]:5672 from :42048\n\n=INFO REPORT==== 19-Dec-2012::06:25:44 ===\nstarting TCP connection from :42048\n\n=WARNING REPORT==== 19-Dec-2012::06:25:44 ===\nexception on TCP connection from :42048\nconnection_closed_abruptly\n\n=INFO REPORT==== 19-Dec-2012::06:25:44 ===\nclosing TCP connection from :42048\n```\n\nWhat might be the possible reasons for this to happen.\n\nThanks\n\n========================================\n\nTop Answer:\nCheck your connection limit\n\nYour connection is time short, there is usually caused by your client improper use\n\n========================================\n\nCode:\n```text\n=INFO REPORT==== 19-Dec-2012::06:25:44 ===\naccepted TCP connection on [::]:5672 from <host>:42048\n\n=INFO REPORT==== 19-Dec-2012::06:25:44 ===\nstarting TCP connection <0.357.0> from <host>:42048\n\n=WARNING REPORT==== 19-Dec-2012::06:25:44 ===\nexception on TCP connection <0.357.0> from <host>:42048\nconnection_closed_abruptly\n\n=INFO REPORT==== 19-Dec-2012::06:25:44 ===\nclosing TCP connection <0.357.0> from <host>:42048\n```\n\n```text\nconnection_closed_abruptly\n```\n\n========================================\n\nComments:\n- I'm writing python 2.6 code that uses `pika.BlockingConnection` and each time I call the `.close()` on it, I get the warning. I also noticed that since I have it as a loop, that it increases the port number it listens to next. I found moving my connection declaration and closing out of my loop reduced the number of warnings, but didn't really solve the underlying issue, but I avoid disk spaces issues from the log file. I also tried the `.close()` with the code and string to have the same error. I also am running on CentOS 5.x (think I got the same problem with CentOS 6.x too)\n- For me it was the LBs doing a health check, once per second. Thanks!","metadata":{"transformedAt":"2026-08-18T18:33:20.122Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":64,"estimatedTokens":569}}83{"id":"stack-14636534","source":"stackoverflow","questionId":14636534,"title":"Why does celery add thousands of queues to rabbitmq that seem to persist long after the tasks completel?","tags":["rabbitmq","celery"],"text":"Title: Why does celery add thousands of queues to rabbitmq that seem to persist long after the tasks completel?\nTags: rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI am using celery with a rabbitmq backend. It is producing thousands of queues with 0 or 1 items in them in rabbitmq like this:\n\n```\n$ sudo rabbitmqctl list_queues\nListing queues ...\nc2e9b4beefc7468ea7c9005009a57e1d 1\n1162a89dd72840b19fbe9151c63a4eaa 0\n07638a97896744a190f8131c3ba063de 0\nb34f8d6d7402408c92c77ff93cdd7cf8 1\nf388839917ff4afa9338ef81c28aad75 0\n8b898d0c7c7e4be4aa8007b38ccc00ea 1\n3fb4be51aaaa4ac097af535301084b01 1\n```\n\nThis seems to be inefficient, but further I have observed that these queues persist long after processing is finished.\n\nI have found the task that appears to be doing this:\n\n```\n@celery.task(ignore_result=True)\ndef write_pages(page_generator): \n g = group(render_page.s(page) for page in page_generator)\n res = g.apply_async()\n\n for rendered_page in res:\n print rendered_page # TODO: print to file\n```\n\nIt seems that because these tasks are being called in a group, they are being thrown into the queue but never being released. However, I am clearly consuming the results (as I can view them being printed when I iterate through `res`. So, I do not understand why those tasks are persisting in the queue.\n\nAdditionally, I am wondering if the large number queues that are being created is some indication that I am doing something wrong.\n\nThanks for any help with this!\n\n========================================\n\nTop Answer:\nUse `CELERY_TASK_RESULT_EXPIRES` (or on 4.1 `CELERY_RESULT_EXPIRES`) to have a periodic cleanup task remove old data from rabbitmq.\n\nhttp://docs.celeryproject.org/en/master/userguide/configuration.html#std:setting-result_expires\n\n========================================\n\nCode:\n```text\n$ sudo rabbitmqctl list_queues\nListing queues ...\nc2e9b4beefc7468ea7c9005009a57e1d 1\n1162a89dd72840b19fbe9151c63a4eaa 0\n07638a97896744a190f8131c3ba063de 0\nb34f8d6d7402408c92c77ff93cdd7cf8 1\nf388839917ff4afa9338ef81c28aad75 0\n8b898d0c7c7e4be4aa8007b38ccc00ea 1\n3fb4be51aaaa4ac097af535301084b01 1\n```\n\n```text\n@celery.task(ignore_result=True)\ndef write_pages(page_generator): \n g = group(render_page.s(page) for page in page_generator)\n res = g.apply_async()\n\n for rendered_page in res:\n print rendered_page # TODO: print to file\n```\n\n```text\nres\n```\n\n```text\nCELERY_TASK_RESULT_EXPIRES\n```\n\n```text\nCELERY_RESULT_EXPIRES\n```\n\n========================================\n\nComments:\n- Thank you for explaining this. I just observed that I can actually call this twice and get results both times: for page_str in res.join(): print page_str\n- I was under the impression that rabbitmq will only persist results for a single usage. Is redis considered better for passing hundreds of thousands of very small tasks? What about memcached as a backend?\n- You wouldn't be passing tasks via the storage backend, just storing the results. The task producing/consuming would still occur via an AMQP queue. Redis performs much better as the storage backend.\n- Can anyone weigh in on whether using the RPC backend over AMPQ results in a ton of random queues being generated as well?\n- The docs seems to imply that it defaults to being on and removes any results older than one day provided celery-beat is running.","metadata":{"transformedAt":"2026-08-18T18:33:20.122Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":91,"estimatedTokens":843}}84{"id":"stack-9652295","source":"stackoverflow","questionId":9652295,"title":"Is there any way to list queues in rabbitmq via pika?","tags":["python","queue","rabbitmq","pika"],"text":"Title: Is there any way to list queues in rabbitmq via pika?\nTags: python, queue, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI know that we can do this to list queue in a rabbitmq:\n\n```\nrabbitmqctl list_queues\n```\n\nbut how can I do this via pika?\n\n========================================\n\nTop Answer:\nWhile pika does not work, you can use the rabbitmq web api for this, e.g.\n\n```\nrequests.get('https://' + hostname + \"/api/queues\", auth=('user', 'password'))\n```\n\nThis is documented on your rabbitmq web frontend, just click *HTTP API*:\n\nhttps://i.sstatic.net/PDY0g.png\n\n========================================\n\nCode:\n```text\nrabbitmqctl list_queues\n```\n\n```text\nrequests.get('https://' + hostname + \"/api/queues\", auth=('user', 'password'))\n```\n\n========================================\n\nComments:\n- so the AMQP protocal itself does not support 'listing queue', right? then, do rabbitmq provide this kind of api?","metadata":{"transformedAt":"2026-08-18T18:33:20.122Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":41,"estimatedTokens":231}}85{"id":"stack-12597006","source":"stackoverflow","questionId":12597006,"title":"RabbitMQ: Exchanges, queues and bindings - who does setup what?","tags":["rabbitmq","message-queue","publish-subscribe"],"text":"Title: RabbitMQ: Exchanges, queues and bindings - who does setup what?\nTags: rabbitmq, message-queue, publish-subscribe\nSource: Stack Overflow\n\nQuestion:\nWhen using RabbitMQ for sending messages you basically have exchanges, queues and bindings. I've understood their idea and how they relate to each other, but I am not quite sure who sets up what.\n\nBasically, I have three scenarios in my application.\n\n### Scenario 1: One publisher, several worker processes\n\nWhat I want to achieve is one component that sends messages to a queue, and there shall be several worker processes that handle items in that queue. This seems quite easy to me. The setup is as follows:\n\n- Exchange: 1 exchange with type 'direct'\n\n- Queue: 1 queue\n\n- Binding: The queue is bound to the exchange\n\nWhenever a message is sent to the exchange, it gets delivered to the queue, and the worker processes get their tasks.\n\nEverything shall be durable.\n\nSo who sets up what? In my opinion:\n\n- Producer creates exchange\n\n- Producer creates queue (as there currently may be no worker processes running, and the message would be lost otherwise if there was no queue)\n\n- Producer does the binding of the queue to the exchange\n\n- Consumers simply listen on the queue\n\nRight?\n\n### Scenario 2: One publisher, several subscribers, volatile messages\n\nThe second scenario is quite different. Basically, it's a pub / sub scenario where each message is send to every currently listening client. If a client goes offline, it does not receive messages any longer and they are not stored anywhere for him. This means the following setup:\n\n- Exchange: 1 exchange with type 'fanout'\n\n- Queue: n queues, one for each consumer\n\n- Binding: Each queue needs to be bound to the exchange\n\nSo who sets up what? In my opinion:\n\n- Producer creates exchange\n\n- Consumer creates queue (as it is its own queue, and the producer can not know whoever is interested in the messages)\n\n- Consumer creates binding for its queue to the exchange\n\n- Consumer listens to its queue\n\nRight?\n\n### Scenario 3: One publisher, several subscribers, durable messages\n\nBasically the same as scenario 2, but the messages should not be lost if a consumer goes offline. In my opinion this should not change anything - right?\n\n========================================\n\nComments:\n- There's a third persona available to do setup: an external administrator. See this answer to another question for more info: stackoverflow.com/questions/6148381/…\n- I didn't write that explicitly, but the system shall be self-contained without the need for an external administrator.","metadata":{"transformedAt":"2026-08-18T18:33:20.123Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":66,"estimatedTokens":647}}86{"id":"stack-35445391","source":"stackoverflow","questionId":35445391,"title":"When to declare/bind Queues and Exchanges with RabbitMQ","tags":["rabbitmq","amqp"],"text":"Title: When to declare/bind Queues and Exchanges with RabbitMQ\nTags: rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nWe have a wrapper library around RabbitMQ at my workplace, created by someone who no longer works here. I'm designing a new system using Rabbit, and am working out the best approach for declaring queues, exchanges and bindings. Our Rabbit architecture has a few federated global zones, and each zone has multiple Rabbit nodes.\n\nThe wrapper code to publish messages and subscribe to queues re-declares the relevant exchanges, queues and bindings each time. My concern is that this may introduce significant latency into every message publish, especially if it needs to wait for confirmation the queue/exchange exists in the remote global zones. I expect the benchmark of millions of messages a second don't re-declare the exchange for each publish.\n\nIn short, this approach seems a bit wasteful and paranoid to me, but perhaps I'm missing something.\n\nSo I have a few questions:\n\n- Is re-declaring the queues and exchanges a significant performance hit, given global federation?\n\n- Is re-declaring on each use a good approach because it handles queues/exchanges disappearing due to broker restarts or explicit deletion?\nShould we just declare queues and exchanges once per process\nand expect them to last the whole lifetime?\n\n- Should durable exchanges and queues be declared in Rabbit config and not declared by the applications at all?\n\n- How should config changes for queues/exchanges be handled if applications may continue to declare them with old config? Should applications just handle the declare failure and continue to publish/consume?","metadata":{"transformedAt":"2026-08-18T18:33:20.123Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":22,"estimatedTokens":416}}87{"id":"stack-4700292","source":"stackoverflow","questionId":4700292,"title":"Using RabbitMQ is there a way to look at the queue contents without a dequeue operation?","tags":["python","rabbitmq","esb","amqp"],"text":"Title: Using RabbitMQ is there a way to look at the queue contents without a dequeue operation?\nTags: python, rabbitmq, esb, amqp\nSource: Stack Overflow\n\nQuestion:\nAs a way to learn RabbitMQ and python I'm working on a project that allows me to distribute h264 encodes between a number of computers. The basics are done, I have a daemon that runs on Linux or Mac that attaches to queue, accepts jobs and encodes them using HandBrakeCLI and acks the message once the encode is complete. I've also built a simple tool to push items into the queue. \n\nNow I want to expand the capabilities of the tool that pushes items into the queue so that I can view what is in the queue. I'm aware of the ability to see how many items are in the queue, but I want to be able to get the actual messages so I can show what movie or TV show is waiting to be encoded yet. The idea is that the queue manager would receive messages from the encoder clients when a job has completed and then refresh the queue list. \n\nI know there is a convoluted way of keeping the queue manager's list in sync with the actual work queue but I'd like this to be \"persistent\" in that I should be able to close the queue manager and reopen it later to see the queue.\n\n========================================\n\nTop Answer:\n@MichaelDillon based on your answer to make others life easier I am putting here a no_ack example:\n\n```\n#!/usr/bin/env python\nimport pika\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))\nchannel = connection.channel()\n\nchannel.queue_declare(queue='Q.hello')\n\ndef callback(ch, method, properties, body):\n print(\" [x] Received %r\" % body)\n # ch.basic_ack(delivery_tag=method.delivery_tag)\n\nchannel.basic_consume(callback, queue='Q.hello')\n\nprint(' [*] Waiting for messages. To exit press CTRL+C')\nchannel.start_consuming()\n```\n\n========================================\n\nCode:\n```text\n#!/usr/bin/env python\nimport pika\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))\nchannel = connection.channel()\n\nchannel.queue_declare(queue='Q.hello')\n\n\ndef callback(ch, method, properties, body):\n print(\" [x] Received %r\" % body)\n # ch.basic_ack(delivery_tag=method.delivery_tag)\n\nchannel.basic_consume(callback, queue='Q.hello')\n\nprint(' [*] Waiting for messages. To exit press CTRL+C')\nchannel.start_consuming()\n```\n\n========================================\n\nComments:\n- I received this via twitter - \"no - RabbitMQ's queues are pure FIFO structures and there's no peek. However, look at basic.consume/get with acks\"\n- Just to expand on the message count getting, you can declare a queue with passive=True which will not create a queue if it doesn't exist. If it does, you'll get back number of messages and consumers.\n- RabbitMQ has a proprietary extension called Firehose Tracer which gives access to all posted messages. Details here: rabbitmq.com/firehose.html\n- The `ch.basic_ack(delivery_tag=method.delivery_tag)` effectively works as a \"delete from queue\" command this case. +1\n- This is super helpful, but I'm having trouble figuring out a way to do this that doesn't block indefinitely. Basically I just want to peek once at the queue at a fixed number of messages, and don't need to sit and wait for more messages to come in. Any ideas?","metadata":{"transformedAt":"2026-08-18T18:33:20.123Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":66,"estimatedTokens":823}}88{"id":"stack-8261654","source":"stackoverflow","questionId":8261654,"title":"Messaging Confusion: Pub/Sub vs Multicast vs Fan Out","tags":["message-queue","messaging","rabbitmq","publish-subscribe","amqp"],"text":"Title: Messaging Confusion: Pub/Sub vs Multicast vs Fan Out\nTags: message-queue, messaging, rabbitmq, publish-subscribe, amqp\nSource: Stack Overflow\n\nQuestion:\nI've been evaluating messaging technologies for my company but I've become very confused by the conceptual differences between a few terms:\n\n**Pub/Sub** vs **Multicast** vs **Fan Out**\nI am working with the following definitions:\n\n**Pub/Sub** has publishers delivering a separate copy of each message to\neach subscriber which means that the opportunity to guarantee delivery exists\n**Fan Out** has a single queue pushing to all listening\nclients. \n**Multicast** just spams out data and if someone is listening\nthen fine, if not, it doesn't matter. No possibility to guarantee a client definitely gets a message.\n\nAre these definitions right? Or is Pub/Sub the pattern and multicast, direct, fanout etc. ways to acheive the pattern?\n\nI'm trying to work the out-of-the-box RabbitMQ definitions into our architecture but I'm just going around in circles at the moment trying to write the specs for our app.\n\nPlease could someone advise me whether I am right?\n\n========================================\n\nTop Answer:\nYour definitions are pretty much correct. Note that guaranteed delivery is not limited to pub/sub only, and it can be done with fanout too. And yes, pub/sub is a very basic description which can be realized with specific methods like fanout, direct and so on.\n\nThere are more messaging patterns which you might find useful. Have a look at Enterprise Integration Patterns for more details.\n\n========================================\n\nCode:\n```text\n*\n```\n\n========================================\n\nComments:\n- this is the kind of answer I was hoping for. Didn't know that topics could simulate the other exchange types so thats useful.\n- Note: Using a Topic exchange to simulate either fanout or direct is *slightly* slower than using either of the specific exchange types. It's the classic performance / flexibility trade off.\n- It's not true. You cant simulate fanout with task queues. It's because after first consuming the story is ended.\n- @iddqd: I don:t understand what you are saying. There is no such thing as task queues in AMQP. You simulate a fanout exchange with a topic exchange. Your consumers declare different queue names with the same binding key and the messages to this topic exchange which have a routing key matching the binding key, get fanned out (copied) to each one of the queues. Consuming messages happens AFTER the message is routed to the queue. See this question for more info stackoverflow.com/questions/5253557/…\n- Sorry, my mistake i fount it answer during searching AMQP+celery.","metadata":{"transformedAt":"2026-08-18T18:33:20.123Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":45,"estimatedTokens":672}}89{"id":"stack-14659335","source":"stackoverflow","questionId":14659335,"title":"rabbitmq-server fails to start after hostname has changed for first time","tags":["ubuntu","rabbitmq","django-celery"],"text":"Title: rabbitmq-server fails to start after hostname has changed for first time\nTags: ubuntu, rabbitmq, django-celery\nSource: Stack Overflow\n\nQuestion:\nI am using django-celery for my django project. Last day I have changed my computer's hostname (I am using Ubuntu 12.04, edited file '/etc/hostname'), and after next restart django-celery was failing with error \n\n```\nConsumer: Connection Error: [Errno 111] Connection refused. Trying again in 4 seconds...\n```\n\nAfter some research on this error I could find that, changing my host name caused this error from here. My rabbitmq startup log shows\n\nfile: /var/log/rabbitmq/startup_log\n\n```\nActivating RabbitMQ plugins ...\n\n********************************************************************************\n********************************************************************************\n\n0 plugins activated:\n\nERROR: epmd error for host \"jinesh\": nxdomain (non-existing domain)\n```\n\nMy startup_err file is empty. \n\nwhen I run \n\n```\nroot@jinesh:/home/jinesh# rabbitmqctl list_users\nListing users ...\nError: unable to connect to node rabbit@jinesh: nodedown\n\nDIAGNOSTICS\n===========\n\nnodes in question: [rabbit@jinesh]\n\nhosts, their running nodes and ports:\n- unable to connect to epmd on jinesh: nxdomain\n\ncurrent node details:\n- node name: rabbitmqctl4956@jinesh\n- home dir: /var/lib/rabbitmq\n- cookie hash: RGhmB2JR1LbZ57j7xWWTxg==\n```\n\nI hope changing the nodename may fix this issue. But I couldn't found a way to do this. Anyone have idea about how solve this issue?\n\n**update**\n\nwhile changing hostname you have to change both `/etc/hostname` and `/etc/hosts` files.\n\nI reinstalled rabbitmq and solved this issue, Will answer this question.\n\n========================================\n\nTop Answer:\nThanks to Richard H Fung.\n\n **His steps helped me to solve this issue.**\n\n \n **But I did not have to re-install the rabbitmq**.\n\nWhen I opened my `/etc/hosts` file I found that `IP` assigned to my hostname is different than the actual `ip(192.168.1.200 [static])`. \n\n```\n#/etc/hosts \n127.0.0.1 localhost \n192.168.1.115 HOSTNAME\n```\n\nso I just changed **IP address** to `192.168.1.200` in my `/etc/hosts` file and it worked fine.\n\n========================================\n\nCode:\n```text\nConsumer: Connection Error: [Errno 111] Connection refused. Trying again in 4 seconds...\n```\n\n```text\nActivating RabbitMQ plugins ...\n\n********************************************************************************\n********************************************************************************\n\n0 plugins activated:\n\nERROR: epmd error for host \"jinesh\": nxdomain (non-existing domain)\n```\n\n```text\nroot@jinesh:/home/jinesh# rabbitmqctl list_users\nListing users ...\nError: unable to connect to node rabbit@jinesh: nodedown\n\nDIAGNOSTICS\n===========\n\nnodes in question: [rabbit@jinesh]\n\nhosts, their running nodes and ports:\n- unable to connect to epmd on jinesh: nxdomain\n\ncurrent node details:\n- node name: rabbitmqctl4956@jinesh\n- home dir: /var/lib/rabbitmq\n- cookie hash: RGhmB2JR1LbZ57j7xWWTxg==\n```\n\n```text\n/etc/hostname\n```\n\n```text\n/etc/hosts\n```\n\n```text\nrabbitmqctl stop\n```\n\n```text\n/etc/hosts\n```\n\n```text\n/etc/hostname\n```\n\n```text\ndpkg -P rabbitmq-server\n```\n\n```text\nrm -rf /var/lib/rabbitmq\n```\n\n```text\nps ax | grep rabbit\n```\n\n```text\napt-get install rabbitmq-server\n```\n\n```text\ndpkg -P rabbitmq-server\n```\n\n```text\nThe Erlang Mnesia database is host specific (because it is a distributed DB). The simplest way to get you fixed is to clear out the database dir.\n```\n\n```text\n$HOSTNAME\n```\n\n```text\n/etc/hostname\n```\n\n```text\nexport HOSTNAME=the.correct.hostname\n```\n\n```text\n#/etc/hosts \n127.0.0.1 localhost \n192.168.1.115 HOSTNAME\n```\n\n```text\n/etc/hosts\n```\n\n```text\nIP\n```\n\n```text\nip(192.168.1.200 [static])\n```\n\n```text\n192.168.1.200\n```\n\n```text\n/etc/hosts\n```\n\n```text\nrm -rf /var/lib/rabbitmq/*\n```\n\n```text\nsudo netstat -lnp\n```\n\n```text\nNODENAME=rabbit@OLDHOSTNAME\n```\n\n```text\nrabbitmq-env.conf\n```\n\n```text\n/etc/rabbitmq\n```\n\n```text\nrabbitmq-env.conf\n```\n\n```text\nservice rabbitmq-server restart\n```\n\n```text\nsudo\n```\n\n```text\n127.0.0.1 <hostname>\n```\n\n```text\n/etc/hosts\n```\n\n```text\n<hostname>\n```\n\n```text\nhostname\n```\n\n```text\nzypper remove erlang erlang-epmd rabbitmq-server\nrm -rf /var/lib/rabbitmq/*\nzypper install erlang erlang-epmd rabbitmq-server\nsystemctl enable rabbitmq-server.service\nsystemctl start rabbitmq-server.service\n```\n\n```text\nerlang erlang-epmd rabbitmq-server\n```\n\n```text\napt-get\n```\n\n```text\nNODENAME=rabbit@YOUR_NEW_HOSTNAME\nNODE_IP_ADDRESS=127.0.0.1\nNODE_PORT=5672\n```\n\n```text\n/etc/hostname\n```\n\n```text\nrm -rf /var/lib/rabbitmq/mnesia/*\n```\n\n```text\nsudo service rabbitmq-server restart\n```\n\n```text\n/etc/rabbitmq/rabbitmq-env.conf\n```\n\n```text\nsudo service rabbitmq-server restart\n```\n\n```text\napt-get purge rabbitmq-server\napt-get purge erlang\napt-get autoremove\nreboot\n```\n\n```text\nsudo apt-get -y install socat logrotate init-system-helpers adduser\nsudo apt-get -y install wget\n```\n\n```text\nwget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb\nsudo dpkg -i erlang-solutions_1.0_all.deb\nsudo apt-get update\nsudo apt-get install erlang\n```\n\n```text\nsudo apt-get update\nwget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.17/rabbitmq-server_3.7.17-1_all.deb\nsudo dpkg -i rabbitmq-server_3.7.17-1_all.deb\nrm rabbitmq-server_3.7.17-1_all.deb\n```\n\n```text\nrabbitmq-service.bat remove\nrabbitmq-service.bat install\n```\n\n```text\nRabbitMQ\n```\n\n```text\nC:\\Program Files\\RabbitMQ Server\\rabbitmq_server-<version>\\sbin\n```\n\n```text\nHKEY_LOCAL_MACHINE\\SOFTWARE\\Ericsson\\Erlang\\ErlSrv\\1.1\\RabbitMQ\\@SName\n```\n\n========================================\n\nComments:\n- On centos/rhel, if you rename your network interfaces via /etc/udev/rules/70-persistant-net.rules and reboot --> doing so will also cause you to get an error message from `rabbitmqctl status` \"unable to connect to epmd\". --> The fix is the same as the accepted answer by @RichardHFung for this question.\n- \"systemctl restart rabbitmq-server.service\" solved the same issue I had.\n- If on Ubuntu 16.04 or 18.04, do NOT install RabbitMQ via the repository (they're outdated). Head here rabbitmq.com/install-debian.html and save yourself some headache down the line, by installing both Erlang and RabbitMQ from one of the proposed repositories. I had a while ago installed Erlang from erlang solutions and had much later installed RabbitMQ via its Ubuntu repo and it originally worked without fuss. After a recent upgrade something went wrong and I spent 5 hours trying to fix it to no avail. I removed both packages and reinstalled Bintray's versions as explained. Fixed.\n- How do you find the Erlang Mnesia Database?\n- Hi @MatthewCanty: I followed the second method.\n- @MattCanty At rabbitmq 3.6.9-1, just `rm -rf /var/lib/rabbitmq/mnesia/`. And the Erlang Mnesia Database is under the file path of `/var/lib/rabbitmq/mnesia/`.\n- Note that I didn't have to stop rabbit (because it wasn't running) or remove the `/var/lib/rabbitmq` folder (because it wasn't there); YMMV.\n- on ubuntu (14.04.1 LTS) this did not work for me. I needed to `apt-get purge rabbitmq-server` and then run `apt-get install rabbitmq-server` to get it all working again after a hostname change.\n- RabbitMQ breaks for no good reason, and the only way to fix it is to uninstall and reinstall?This is alarming...\n- Neither the manual instructions nor the `apt-get` instructions worked for me. As of yet, still no solution. Is this an erlang problem?\n- Anyway of doing this without losing data?\n- my problem was that there was an erlang process running, killed it and rabbit started as normal.\n- i gave downvote because of solution is not a real solution. what if i change hostname again? remove rabbit again, install again ....\n- Check @Kishor Pawar answer if you don't want to lose data\n- This helped me. been straggling with that for 2 hours, Disabled it and worked like magic, Thanks!\n- It worked, without even uninstalling rabbitmq-server\n- this is the exact situation i had and same solution worked - no need to reinstall and fixed ip and worked\n- This should be accepted as the correct solution. On xenial I had /etc/hosts associating a GloballyRoutableIP with the `hostname` name (not fqdn), and found that associating the NetworkTenIP with that name repaired epmd. Killing epmd and restarting rabbit sufficed.\n- Phew! Didn't have to re-install either. My issue after changing the hostname was that I don't use a FQDN in /etc/hostname. This is OK, but you then need to put that short alias in `/etc/hosts` for 127.0.0.1 or the erlang system can't resolve it. *I did however loose all queue contents*, presumably that store is associated with the old hostname. Possibly this could be solved by putting an IP address in the conf file...\n- Be careful while doing this. You will lose all data\n- This helped me. I updated to the latest version of rabbitmq (3.6.6-1) on ArchLinux and was unable to start it. Took a look in `/etc/rabbitmq/rabbitmq-env.conf` and 'lo and behold, the `NODENAME` was all wrong. Instead of `rabbit@machine`, it had become `rabbit@machine@machine` during the upgrade. A simple removal of the last `@machine` fixed the problem.\n- This is the proper answer IMHO...@Chewtoy it's even in the Arch wiki :-D wiki.archlinux.org/index.php/Rabbitmq#Changed_hostname\n- So awesome!. Thank you. I changed my hostname and I didn't wanted to lose any information (usernames, etc). The env.conf file fixed my problem.\n- Where is this file on Windows?\n- For me, this was the answer which worked. However I'm still puzzled why the default `127.0.0.1 localhost.localadmin localhost` line didn't resolve to the appropriate nodename. Thank you very much!\n- I had similiar problem, rabbitmq had issues after i changed the hostname. And this worked for me. Thanks","metadata":{"transformedAt":"2026-08-18T18:33:20.123Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":52,"totalLines":358,"estimatedTokens":2478}}90{"id":"stack-7063224","source":"stackoverflow","questionId":7063224,"title":"How can I recover unacknowledged AMQP messages from other channels than my connection's own?","tags":["rabbitmq","celery","amqp","pika","celeryd"],"text":"Title: How can I recover unacknowledged AMQP messages from other channels than my connection's own?\nTags: rabbitmq, celery, amqp, pika, celeryd\nSource: Stack Overflow\n\nQuestion:\nIt seems the longer I keep my rabbitmq server running, the more trouble I have with unacknowledged messages. I would love to requeue them. In fact there seems to be an amqp command to do this, but it only applies to the channel that your connection is using. I built a little pika script to at least try it out, but I am either missing something or it cannot be done this way (how about with rabbitmqctl?)\n\n```\nimport pika\n\ncredentials = pika.PlainCredentials('***', '***')\nparameters = pika.ConnectionParameters(host='localhost',port=5672,\\\n credentials=credentials, virtual_host='***')\n\ndef handle_delivery(body):\n \"\"\"Called when we receive a message from RabbitMQ\"\"\"\n print body\n\ndef on_connected(connection):\n \"\"\"Called when we are fully connected to RabbitMQ\"\"\"\n connection.channel(on_channel_open) \n\ndef on_channel_open(new_channel):\n \"\"\"Called when our channel has opened\"\"\"\n global channel\n channel = new_channel\n channel.basic_recover(callback=handle_delivery,requeue=True) \n\ntry:\n connection = pika.SelectConnection(parameters=parameters,\\\n on_open_callback=on_connected) \n\n # Loop so we can communicate with RabbitMQ\n connection.ioloop.start()\nexcept KeyboardInterrupt:\n # Gracefully close the connection\n connection.close()\n # Loop until we're fully closed, will stop on its own\n connection.ioloop.start()\n```\n\n========================================\n\nTop Answer:\nIf messages are unacked there are only two ways to get them back into the queue:\n\n**basic.nack**\n\nThis command will cause the message to be placed back into the queue and redelivered.\n\n**Disconnect from the broker**\n\nThis action will force all unacked messages from this channel to be put back into the queue.\n\n**NOTE**: basic.recover will try to republish unacked messages on the same channel (to the same consumer), which is sometimes the desired behaviour.\n\nRabbitMQ spec for basic.recover and basic.nack\n\nThe real question is: Why are the messages unacknowledged?\n\n*Possible scenarios to cause unacked messages:*\n\nConsumer fetching too many messages, then not processing and acking them quickly enough.\n\nSolution: Prefetch as few messages as appropriate.\n\nBuggy client library (I have this issue currently with **pika 0.9.13**. If the queue has a lot of messages, a certain number of messages will get stuck unacked, even hours later.\n\nSolution: I have to restart the consumer several times until all unacked messages are gone from the queue.\n\n========================================\n\nCode:\n```text\nimport pika\n\ncredentials = pika.PlainCredentials('***', '***')\nparameters = pika.ConnectionParameters(host='localhost',port=5672,\\\n credentials=credentials, virtual_host='***')\n\ndef handle_delivery(body):\n \"\"\"Called when we receive a message from RabbitMQ\"\"\"\n print body\n\ndef on_connected(connection):\n \"\"\"Called when we are fully connected to RabbitMQ\"\"\"\n connection.channel(on_channel_open) \n\ndef on_channel_open(new_channel):\n \"\"\"Called when our channel has opened\"\"\"\n global channel\n channel = new_channel\n channel.basic_recover(callback=handle_delivery,requeue=True) \n\ntry:\n connection = pika.SelectConnection(parameters=parameters,\\\n on_open_callback=on_connected) \n\n # Loop so we can communicate with RabbitMQ\n connection.ioloop.start()\nexcept KeyboardInterrupt:\n # Gracefully close the connection\n connection.close()\n # Loop until we're fully closed, will stop on its own\n connection.ioloop.start()\n```\n\n```text\ngrep\n```\n\n```text\nps aux\n```\n\n========================================\n\nComments:\n- Have you been able to resolve this?\n- stackoverflow.com/questions/8296201/… SO answer has potentially what is needed depending on why you have other channels still hanging around with unacked messages. Zombie channels. Not dup, since this topic is about messages in other channels, and not the channels itself.\n- so the basic.recover *must* be called by the consumer? im using celeryd to manage connections. it might be possible to send that recover command to poorly responsive queues with celeryctl (if youre familiar with that...)\n- @will my condolences that you are using Celery. The celery developers simply do not understand AMQP and have created a badly broken implementation. You need to make a choice, either get rid of celery and do AMQP right, or stop using AMQP with celery and use something simple like Redis instead. I chose to drop celery and stay with AMQP.\n- thats quite an indictment. if you don't mind me asking, what about celery's AMQP implementation is not executed properly?\n- I agree, I'd like to hear why you think Celery is so badly broken. It's very widely used and this is the first time I've heard this complaint.\n- Has your issue with pika been reported? Can you provide a link?\n- It's a python recursion limit that kicked in. Something about not being able to recurse >1000 times, which is what was apparently happening with pika 0.9.13. Not seeing it with 0.9.14.\n- Finally found where the issue was reported: github.com/pika/pika/issues/286\n- rabbitmq.com/consumers.html#acknowledgement-timeout this setting is there in new version to avoid consumer timeout.\n- Another possible scenario: Glitch on internet connection when getting messages in RabbitMQ between them being sent and my computer acking them.\n- You can also determine if a rabbit connection is being held up by a zombie process, by using the RabbitMQ managment console, as I described here: stackoverflow.com/questions/11926077/…","metadata":{"transformedAt":"2026-08-18T18:33:20.123Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":130,"estimatedTokens":1417}}91{"id":"stack-12296787","source":"stackoverflow","questionId":12296787,"title":"What does MassTransit add to RabbitMQ?","tags":["rabbitmq","masstransit"],"text":"Title: What does MassTransit add to RabbitMQ?\nTags: rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nWhat is the benefit of building on top of MassTransit compared to building directly on top of RabbitMQ?\n\nI believe one benefit provided by MassTransit is 'type' exchange (publish subscribe by interface / type) so the content of the message is structured, compared to plain RabbitMQ exchanges where the content of the message is unstructured text / blob.\n\nWhat other benefits provided by MassTransit?\n\n========================================\n\nComments:\n- The abstraction is also nice. We use Azure Service Buses in the cloud and RabbitMQ when deploying on customer premises without any significant code changes.\n- Thanks for such an articulate explanation suitable for business. Switching between GRPC to a SB is liberating, contracts all in C# is great, learning one pattern, great, speed of delivery great. It's just a facade but it delivers so much. Programming by Contract is old, but this makes it easy.","metadata":{"transformedAt":"2026-08-18T18:33:20.123Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":16,"estimatedTokens":254}}92{"id":"stack-2868800","source":"stackoverflow","questionId":2868800,"title":"What is an MQ and why do I want to use it?","tags":["activemq-classic","rabbitmq","ibm-mq"],"text":"Title: What is an MQ and why do I want to use it?\nTags: activemq-classic, rabbitmq, ibm-mq\nSource: Stack Overflow\n\nQuestion:\nOn my team at work, we use the IBM MQ technology a lot for cross-application communication. I've seen lately on Hacker News and other places about other MQ technologies like RabbitMQ. I have a basic understanding of what it is (a commonly checked area to put and get messages), but what I want to know what exactly is it good at? How will I know where I want to use it and when? Why not just stick with more rudimentary forms of interprocess messaging?\n\n========================================\n\nTop Answer:\nMQ stands for messaging queue.\n\nIt's an abstraction layer that allows multiple processes (likely on different machines) to communicate via various models (e.g., point-to-point, publish subscribe, etc.). Depending on the implementation, it can be configured for things like guaranteed reliability, error reporting, security, discovery, performance, etc. \n\nYou can do all this manually with sockets, but it's very difficult.\n\nFor example: Suppose you want to processes to communicate, but one of them can die in the middle and later get reconnected. How would you ensure that interim messages were not lost? MQ solutions can do that for you.\n\n========================================\n\nComments:\n- So it sounds like MQs are technologies that sacrifice performance for reliability generally?\n- So what do you do if the MQ server is down? It's no more resilient than a web service, is it?\n- @RobHolmes: typically, you can still *enqueue* it into your local queue - it will be transmitted to the queue server when it's back up - and **yes**, it **IS** more resilient than a typical web service .....\n- @marc_s, how do we enqueue to local queue in RabbitMQ? How does it get synchronized to queue on MQ Server?\n- how do you measure software resilience? why we should accept a mq is more resilient than a web service?","metadata":{"transformedAt":"2026-08-18T18:33:20.123Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":26,"estimatedTokens":486}}93{"id":"stack-28794123","source":"stackoverflow","questionId":28794123,"title":"Ack or Nack in rabbitMQ","tags":["rabbitmq","amqp"],"text":"Title: Ack or Nack in rabbitMQ\nTags: rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI'm using rabbitMQ, I take every message from queue with basic_get without automatically acking procedure, which means the message remain in queue until I ack or nack the message.\n\nSometimes I've messages that can't be processed because of some exception thrown, which prevented them from being fully processed.\n\nQuestion is what does it matter if I both ack the messages in success and exception thrown, I mean in terms of result messages will always get out of the queue, so what does it matter if I use ack or nack in this scenario?\nMaybe I miss something about when using each opration?\n\n========================================\n\nTop Answer:\nAck and Nack both remove the message from the queue, the difference is that when you Nack a message it goes into the DLX (dead letter queue) if there is one defined for that queue.\n\n========================================\n\nCode:\n```text\nrequeue\n```\n\n```text\nnack\n```\n\n```text\nreject\n```\n\n```text\nrequeue=1\n```\n\n```text\nnack\n```\n\n```text\nreject\n```\n\n```text\nrequeue=0\n```\n\n```text\nnack\n```\n\n```text\nreject\n```\n\n```text\nrequeue=0\n```\n\n```text\nack\n```\n\n```text\nack\n```\n\n```text\nnack\n```\n\n```text\nreject\n```\n\n```text\nrequeue=0\n```\n\n```text\nnack\n```\n\n========================================\n\nComments:\n- Is the only difference is that nack allow requeue, while ack doesn't?\n- Not if you use Nack with the requeue option set to true. Setting it to true will remove the message from the consumer's fetch and added it back to the original queue for reprocessing.\n- Spectacular answer! However can you clarify a bit if the DLX is already considered as a queue.,and what the difference between queue and exchange?\n- @JavaSa One common analogy (which may or may not make sense to you) is that an exchange is like a Post Office, and a queue is like a PO Box. You only ever publish a new message to an exchange (even if it's the default exchange); the exchange will then route it to zero, one, or multiple queues, generally based on its \"routing key\". So the simplest DLX would be one which routed everything into a single queue, but it could be as complex as you needed.\n- `nack` stands for negative acknowledgement.","metadata":{"transformedAt":"2026-08-18T18:33:20.123Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":16,"totalLines":92,"estimatedTokens":560}}94{"id":"stack-10347751","source":"stackoverflow","questionId":10347751,"title":"rabbitmq refusing to start","tags":["rabbitmq"],"text":"Title: rabbitmq refusing to start\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have installed rabbitmq on `ubuntu` and trying to start it using `rabbitmq-server start`, however, I'm getting this error:\n\n```\nActivating RabbitMQ plugins ...\n\n0 plugins activated:\n\nnode with name \"rabbit\" already running on \"mybox\"\n\ndiagnostics:\n\n- nodes and their ports on mybox: [{rabbit,38618},\n {rabbitmqprelaunch13346,41776}]\n- current node: rabbitmqprelaunch13346@mybox\n- current node home dir: /var/lib/rabbitmq\n- current node cookie hash: 8QRKGluOJOcZ4AAkEdFwQg==\n```\n\nso I try to stop it or restart it using `service rabbitmq-server restart` but I get the following error: `Restarting rabbitmq-server: RabbitMQ is not running`\n\nThe server's host name `hostname -s` is mybox.\n\nHow do I stop the currently running instance, or at least, how do I manage it? I have no access to it and yet I'm not able to run rabbitmq properly. \n\nThank you.\n\n========================================\n\nTop Answer:\n`rabbitmq-server` refuses to start if the `hostname -s` value has changed.\n\nThe solution suggested here is **only for test/development environments**.\n\nI had to delete the database to fix it locally.\ni.e empty folder `/var/lib/rabbitmq` (ubuntu) or `/usr/local/var/lib/rabbitmq/`(mac)\n\n========================================\n\nCode:\n```text\nActivating RabbitMQ plugins ...\n\n0 plugins activated:\n\nnode with name \"rabbit\" already running on \"mybox\"\n\ndiagnostics:\n\n- nodes and their ports on mybox: [{rabbit,38618},\n {rabbitmqprelaunch13346,41776}]\n- current node: rabbitmqprelaunch13346@mybox\n- current node home dir: /var/lib/rabbitmq\n- current node cookie hash: 8QRKGluOJOcZ4AAkEdFwQg==\n```\n\n```text\nubuntu\n```\n\n```text\nrabbitmq-server start\n```\n\n```text\nservice rabbitmq-server restart\n```\n\n```text\nRestarting rabbitmq-server: RabbitMQ is not running\n```\n\n```text\nhostname -s\n```\n\n```text\nsudo rabbitmqctl status\n```\n\n```text\nsudo rabbitmqctl stop\n```\n\n```text\nsudo invoke-rc.d rabbitmq-server start\n```\n\n```text\nps -ef | grep rabbit\n```\n\n```text\nservice\n```\n\n```text\n$/ rabbitmq-server\n\n\nBOOT FAILED\n===========\n\nError description:\n {error,{cannot_log_to_file,\"/var/log/rabbitmq/rabbit@haber01.log\",\n {error,eacces}}}\n....\n```\n\n```text\n/var/log/rabbigmq/$ chmod g+w *\n```\n\n```text\nrabbitmq-server\n```\n\n```text\n/var/log/rabbitmq/rabbit@haber01.log\n```\n\n```text\nrabbitmq-server\n```\n\n```text\nhostname -s\n```\n\n```text\n/var/lib/rabbitmq\n```\n\n```text\n/usr/local/var/lib/rabbitmq/\n```\n\n```text\nrabbitmqctl\n```\n\n```text\n/var/lib/rabbitmq/mnesia/rabbit@<host>/queues\n```\n\n```text\nps aux | grep rabbitmq\n```\n\n```text\nkill -9 {process id}\n```\n\n```text\nsudo service rabbitmq-server start\n```\n\n```text\n$ cat /usr/local/etc/rabbitmq/rabbitmq-env.conf\nCONFIG_FILE=/usr/local/etc/rabbitmq/rabbitmq\nNODE_IP_ADDRESS=127.0.0.1\nNODENAME=rabbit@localhost\nRABBITMQ_LOG_BASE=/usr/local/var/log/rabbitmq\n```\n\n```text\nrabbit@\n```\n\n```text\nNODENAME\n```\n\n```text\nbrew services restart rabbitmq\n```\n\n```text\nError trying to stop RabbitMQ: :throw:{:error, {:missing_dependencies, [:eldap], [:rabbitmq_auth_backend_ldap]}}\n```\n\n```text\n#NODENAME=rabbit\n```\n\n```text\nNODENAME=s1\n```\n\n```text\n/etc/rabbitmq/rabbitmq-env.conf\n```\n\n```text\ns1\n```\n\n========================================\n\nComments:\n- thanks for the reply. `rabbitmqctl status` is giving the same not running error quoted in my post. `rabbitmqctl stop` is throwing an error saying that rabbit is not running!! `invoke-rc.d rabbitmq-server start` same error saying that rabbit is already running :-\\\n- if you do `ps -ef | grep rabbit` you should see a number of processes there - do you? are they running as the rabbitmq user?\n- Hate to get all microsoft on you, but I suggest you reboot. I have the same list, except 2 things: 1 I'm using erlang 5.7.4 so probably an older install, 2 (more important) I don't have the three processes initiated as root: 11823 11829 11833 - the others are virtually identical. - ps it does look like it's actually running.\n- The restart solved the issue. Please update your post so I could accept your answer.\n- +1 for this really good answer @GregHNZ. Killing the running processes worked for me. Many thanks\n- `chmod 777 /var/log/rabbitmq/` worked for me.Thanks\n- DON'T change directory permissions to 777, it's insecure, you should change the owner of the directory instead (probably to `rabbitmq`)\n- That's `/usr/local/var/lib/rabbitmq/` on Mac with homebrew\n- Any idea what folder this is in Windows?\n- This was the issue causing my problems as well, thanks.\n- I changed mine to localhost to get it working: `sudo hostname localhost`\n- Worked for me after those files got corrupt due to insufficient disk space.\n- Answer of @nezda solve my issue. Is there any issue doing that?\n- Your answer was helpful to deal with a downed RabbitMQ because the disk was full. The path has slightly changed in 3.7.4. It is something like `sudo rm -rf /var/lib/rabbitmq/mnesia/rabbit@/msg_stores/vhosts//queues/‌​`\n- This solved my issue but is there any downside of doing this?","metadata":{"transformedAt":"2026-08-18T18:33:20.123Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":33,"totalLines":219,"estimatedTokens":1296}}95{"id":"stack-40611683","source":"stackoverflow","questionId":40611683,"title":"Accessing ASP.NET Core DI Container From Static Factory Class","tags":["c#","asp.net-core","dependency-injection","rabbitmq","service-locator"],"text":"Title: Accessing ASP.NET Core DI Container From Static Factory Class\nTags: c#, asp.net-core, dependency-injection, rabbitmq, service-locator\nSource: Stack Overflow\n\nQuestion:\nI've created an ASP.NET Core MVC/WebApi site that has a RabbitMQ subscriber based off James Still's blog article Real-World PubSub Messaging with RabbitMQ.\n\nIn his article he uses a static class to start the queue subscriber and define the event handler for queued events. This static method then instantiates the event handler classes via a static factory class.\n\n```\nusing RabbitMQ.Client;\nusing RabbitMQ.Client.Events;\nusing System;\nusing System.Text;\n\nnamespace NST.Web.MessageProcessing\n{\n public static class MessageListener\n {\n private static IConnection _connection;\n private static IModel _channel;\n\n public static void Start(string hostName, string userName, string password, int port)\n {\n var factory = new ConnectionFactory\n {\n HostName = hostName,\n Port = port,\n UserName = userName,\n Password = password,\n VirtualHost = \"/\",\n AutomaticRecoveryEnabled = true,\n NetworkRecoveryInterval = TimeSpan.FromSeconds(15)\n };\n\n _connection = factory.CreateConnection();\n _channel = _connection.CreateModel();\n _channel.ExchangeDeclare(exchange: \"myExchange\", type: \"direct\", durable: true);\n\n var queueName = \"myQueue\";\n\n QueueDeclareOk ok = _channel.QueueDeclare(queueName, true, false, false, null);\n\n _channel.QueueBind(queue: queueName, exchange: \"myExchange\", routingKey: \"myRoutingKey\");\n\n var consumer = new EventingBasicConsumer(_channel);\n consumer.Received += ConsumerOnReceived;\n\n _channel.BasicConsume(queue: queueName, noAck: false, consumer: consumer);\n\n }\n\n public static void Stop()\n {\n _channel.Close(200, \"Goodbye\");\n _connection.Close();\n }\n\n private static void ConsumerOnReceived(object sender, BasicDeliverEventArgs ea)\n {\n // get the details from the event\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n var messageType = \"endpoint\"; // hardcoding the message type while we dev...\n\n // instantiate the appropriate handler based on the message type\n IMessageProcessor processor = MessageHandlerFactory.Create(messageType);\n processor.Process(message);\n\n // Ack the event on the queue\n IBasicConsumer consumer = (IBasicConsumer)sender;\n consumer.Model.BasicAck(ea.DeliveryTag, false);\n }\n\n }\n}\n```\n\nIt works great up to the point where I now need to resolve a service in my message processor factory rather than just write to the console.\n\n```\nusing NST.Web.Services;\nusing System;\n\nnamespace NST.Web.MessageProcessing\n{\n public static class MessageHandlerFactory\n {\n public static IMessageProcessor Create(string messageType)\n {\n switch (messageType.ToLower())\n {\n case \"ipset\":\n // need to resolve IIpSetService here...\n IIpSetService ipService = ???????\n\n return new IpSetMessageProcessor(ipService);\n\n case \"endpoint\":\n // need to resolve IEndpointService here...\n IEndpointService epService = ???????\n\n // create new message processor\n return new EndpointMessageProcessor(epService);\n\n default:\n throw new Exception(\"Unknown message type\");\n }\n }\n }\n}\n```\n\nIs there any way to access the ASP.NET Core IoC container to resolve the dependencies? I don't really want to have to spin up the whole stack of dependencies by hand :(\n\nOr, is there a better way to subscribe to RabbitMQ from an ASP.NET Core application? I found RestBus but it's not been updated for Core 1.x\n\n========================================\n\nTop Answer:\nEven though using Dependency Injection is a better solution, but in some cases you have to use static methods (like in Extension Methods).\n\nFor those cases you can add a static property to your static class and initialize it in your ConfigureServices method.\n\nFor example:\n\n```\npublic static class EnumExtentions\n{\n static public IStringLocalizerFactory StringLocalizerFactory { set; get; }\n\n public static string GetDisplayName(this Enum e)\n {\n var resourceManager = StringLocalizerFactory.Create(e.GetType());\n var key = e.ToString();\n var resourceDisplayName = resourceManager.GetString(key);\n\n return resourceDisplayName;\n }\n}\n```\n\nand in your ConfigureServices:\n\n```\nEnumExtentions.StringLocalizerFactory = services.BuildServiceProvider().GetService();\n```\n\n========================================\n\nCode:\n```text\nusing RabbitMQ.Client;\nusing RabbitMQ.Client.Events;\nusing System;\nusing System.Text;\n\nnamespace NST.Web.MessageProcessing\n{\n public static class MessageListener\n {\n private static IConnection _connection;\n private static IModel _channel;\n\n public static void Start(string hostName, string userName, string password, int port)\n {\n var factory = new ConnectionFactory\n {\n HostName = hostName,\n Port = port,\n UserName = userName,\n Password = password,\n VirtualHost = \"/\",\n AutomaticRecoveryEnabled = true,\n NetworkRecoveryInterval = TimeSpan.FromSeconds(15)\n };\n\n _connection = factory.CreateConnection();\n _channel = _connection.CreateModel();\n _channel.ExchangeDeclare(exchange: \"myExchange\", type: \"direct\", durable: true);\n\n var queueName = \"myQueue\";\n\n QueueDeclareOk ok = _channel.QueueDeclare(queueName, true, false, false, null);\n\n _channel.QueueBind(queue: queueName, exchange: \"myExchange\", routingKey: \"myRoutingKey\");\n\n var consumer = new EventingBasicConsumer(_channel);\n consumer.Received += ConsumerOnReceived;\n\n _channel.BasicConsume(queue: queueName, noAck: false, consumer: consumer);\n\n }\n\n public static void Stop()\n {\n _channel.Close(200, \"Goodbye\");\n _connection.Close();\n }\n\n private static void ConsumerOnReceived(object sender, BasicDeliverEventArgs ea)\n {\n // get the details from the event\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n var messageType = \"endpoint\"; // hardcoding the message type while we dev...\n\n // instantiate the appropriate handler based on the message type\n IMessageProcessor processor = MessageHandlerFactory.Create(messageType);\n processor.Process(message);\n\n // Ack the event on the queue\n IBasicConsumer consumer = (IBasicConsumer)sender;\n consumer.Model.BasicAck(ea.DeliveryTag, false);\n }\n\n }\n}\n```\n\n```text\nusing NST.Web.Services;\nusing System;\n\nnamespace NST.Web.MessageProcessing\n{\n public static class MessageHandlerFactory\n {\n public static IMessageProcessor Create(string messageType)\n {\n switch (messageType.ToLower())\n {\n case \"ipset\":\n // need to resolve IIpSetService here...\n IIpSetService ipService = ???????\n\n return new IpSetMessageProcessor(ipService);\n\n case \"endpoint\":\n // need to resolve IEndpointService here...\n IEndpointService epService = ???????\n\n // create new message processor\n return new EndpointMessageProcessor(epService);\n\n default:\n throw new Exception(\"Unknown message type\");\n }\n }\n }\n}\n```\n\n```text\npublic class RabbitOptions\n{\n public string HostName { get; set; }\n public string UserName { get; set; }\n public string Password { get; set; }\n public int Port { get; set; }\n}\n\n// In appsettings.json:\n{\n \"Rabbit\": {\n \"hostName\": \"192.168.99.100\",\n \"username\": \"guest\",\n \"password\": \"guest\",\n \"port\": 5672\n }\n}\n```\n\n```text\npublic class MessageHandlerFactory\n{\n private readonly IServiceProvider services;\n public MessageHandlerFactory(IServiceProvider services)\n {\n this.services = services;\n }\n\n public IMessageProcessor Create(string messageType)\n {\n switch (messageType.ToLower())\n {\n case \"ipset\":\n return services.GetService<IpSetMessageProcessor>(); \n case \"endpoint\":\n return services.GetService<EndpointMessageProcessor>();\n default:\n throw new Exception(\"Unknown message type\");\n }\n }\n}\n```\n\n```text\npublic class IpSetMessageProcessor : IMessageProcessor\n{\n private ILogger<IpSetMessageProcessor> logger;\n public IpSetMessageProcessor(ILogger<IpSetMessageProcessor> logger)\n {\n this.logger = logger;\n }\n\n public void Process(string message)\n {\n logger.LogInformation(\"Received message: {0}\", message);\n }\n}\n```\n\n```text\npublic class MessageListener\n{\n private readonly RabbitOptions opts;\n private readonly MessageHandlerFactory handlerFactory;\n private IConnection _connection;\n private IModel _channel;\n\n public MessageListener(IOptions<RabbitOptions> opts, MessageHandlerFactory handlerFactory)\n {\n this.opts = opts.Value;\n this.handlerFactory = handlerFactory;\n }\n\n public void Start()\n {\n var factory = new ConnectionFactory\n {\n HostName = opts.HostName,\n Port = opts.Port,\n UserName = opts.UserName,\n Password = opts.Password,\n VirtualHost = \"/\",\n AutomaticRecoveryEnabled = true,\n NetworkRecoveryInterval = TimeSpan.FromSeconds(15)\n };\n\n _connection = factory.CreateConnection();\n _channel = _connection.CreateModel();\n _channel.ExchangeDeclare(exchange: \"myExchange\", type: \"direct\", durable: true);\n\n var queueName = \"myQueue\";\n\n QueueDeclareOk ok = _channel.QueueDeclare(queueName, true, false, false, null);\n\n _channel.QueueBind(queue: queueName, exchange: \"myExchange\", routingKey: \"myRoutingKey\");\n\n var consumer = new EventingBasicConsumer(_channel);\n consumer.Received += ConsumerOnReceived;\n\n _channel.BasicConsume(queue: queueName, noAck: false, consumer: consumer);\n\n }\n\n public void Stop()\n {\n _channel.Close(200, \"Goodbye\");\n _connection.Close();\n }\n\n private void ConsumerOnReceived(object sender, BasicDeliverEventArgs ea)\n {\n // get the details from the event\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n var messageType = \"endpoint\"; // hardcoding the message type while we dev...\n //var messageType = Encoding.UTF8.GetString(ea.BasicProperties.Headers[\"message-type\"] as byte[]);\n\n // instantiate the appropriate handler based on the message type\n IMessageProcessor processor = handlerFactory.Create(messageType);\n processor.Process(message);\n\n // Ack the event on the queue\n IBasicConsumer consumer = (IBasicConsumer)sender;\n consumer.Model.BasicAck(ea.DeliveryTag, false);\n }\n}\n```\n\n```text\npublic void ConfigureServices(IServiceCollection services)\n{ \n // ...\n\n // Add RabbitMQ services\n services.Configure<RabbitOptions>(Configuration.GetSection(\"rabbit\"));\n services.AddTransient<MessageListener>();\n services.AddTransient<MessageHandlerFactory>();\n services.AddTransient<IpSetMessageProcessor>();\n services.AddTransient<EndpointMessageProcessor>();\n}\n```\n\n```text\npublic MessageListener MessageListener { get; private set; }\npublic void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime appLifetime)\n{\n appLifetime.ApplicationStarted.Register(() =>\n {\n MessageListener = app.ApplicationServices.GetService<MessageListener>();\n MessageListener.Start();\n });\n appLifetime.ApplicationStopping.Register(() =>\n {\n MessageListener.Stop();\n });\n\n // ...\n}\n```\n\n```text\nIApplicationLifetime\n```\n\n```text\nIServiceProvider\n```\n\n```text\nMessageHandlerFactory\n```\n\n```text\nIServiceProvider\n```\n\n```text\nStartup.ConfigureServices\n```\n\n```text\nMessageListener\n```\n\n```text\nIOptions<RabbitOptions>\n```\n\n```text\nMessageHandlerFactory\n```\n\n```text\nStartup.ConfigureServices\n```\n\n```text\nStartup.Configure\n```\n\n```text\nIApplicationLifetime\n```\n\n```text\nApplicationStarted\n```\n\n```text\nApplicationStopped\n```\n\n```text\npublic static IMessageProcessor Create(string messageType, IIpSetService ipService)\n{\n //\n}\n```\n\n```text\n// configure method\npublic IApplicationBuilder Configure(IApplicationBuilder app)\n{\n var ipService = app.ApplicationServices.GetService<IIpSetService>();\n MessageHandlerFactory.IIpSetService = ipService;\n}\n\n// static class\npublic static IIpSetService IpSetService;\n\npublic static IMessageProcessor Create(string messageType)\n{\n // use IpSetService\n}\n```\n\n```text\n//Startup.cs\npublic void ConfigureServices(IServiceCollection services)\n{\n services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();\n}\n\npublic IApplicationBuilder Configure(IApplicationBuilder app)\n{\n var httpContextAccessor= app.ApplicationServices.GetService<IHttpContextAccessor>();\n MessageHandlerFactory.HttpContextAccessor = httpContextAccessor;\n}\n\n// static class\npublic static IHttpContextAccessor HttpContextAccessor;\n\npublic static IMessageProcessor Create(string messageType)\n{\n var ipSetService = HttpContextAccessor.HttpContext.RequestServices.GetService<IIpSetService>();\n // use it\n}\n```\n\n```text\npublic static class EnumExtentions\n{\n static public IStringLocalizerFactory StringLocalizerFactory { set; get; }\n\n public static string GetDisplayName(this Enum e)\n {\n var resourceManager = StringLocalizerFactory.Create(e.GetType());\n var key = e.ToString();\n var resourceDisplayName = resourceManager.GetString(key);\n\n return resourceDisplayName;\n }\n}\n```\n\n```text\nEnumExtentions.StringLocalizerFactory = services.BuildServiceProvider().GetService<IStringLocalizerFactory>();\n```\n\n```text\npublic interface IServiceProviderProxy\n{\n T GetService<T>();\n IEnumerable<T> GetServices<T>();\n object GetService(Type type);\n IEnumerable<object> GetServices(Type type);\n}\n```\n\n```text\npublic static class ServiceLocator\n{\n private static IServiceProviderProxy diProxy;\n\n public static IServiceProviderProxy ServiceProvider => diProxy ?? throw new Exception(\"You should Initialize the ServiceProvider before using it.\");\n\n public static void Initialize(IServiceProviderProxy proxy)\n {\n diProxy = proxy;\n }\n}\n```\n\n```text\npublic class HttpContextServiceProviderProxy : IServiceProviderProxy\n{\n private readonly IHttpContextAccessor contextAccessor;\n\n public HttpContextServiceProviderProxy(IHttpContextAccessor contextAccessor)\n {\n this.contextAccessor = contextAccessor;\n }\n\n public T GetService<T>()\n {\n return contextAccessor.HttpContext.RequestServices.GetService<T>();\n }\n\n public IEnumerable<T> GetServices<T>()\n {\n return contextAccessor.HttpContext.RequestServices.GetServices<T>();\n }\n\n public object GetService(Type type)\n {\n return contextAccessor.HttpContext.RequestServices.GetService(type);\n }\n\n public IEnumerable<object> GetServices(Type type)\n {\n return contextAccessor.HttpContext.RequestServices.GetServices(type);\n }\n}\n```\n\n```text\npublic void ConfigureServices(IServiceCollection services)\n{\n services.AddHttpContextAccessor();\n services.AddSingleton<IServiceProviderProxy, HttpContextServiceProviderProxy>();\n .......\n}\n```\n\n```text\npublic void Configure(IApplicationBuilder app, IHostingEnvironment env,IServiceProvider sp)\n{\n ServiceLocator.Initialize(sp.GetService<IServiceProviderProxy>());\n}\n```\n\n```text\npublic class FakeModel\n{\n public FakeModel(Guid id, string value)\n {\n Id = id;\n Value = value;\n }\n\n public Guid Id { get; }\n public string Value { get; private set; }\n\n public async Task UpdateAsync(string value)\n {\n Value = value;\n var mediator = ServiceLocator.ServiceProvider.GetService<IMediator>();\n await mediator.Send(new FakeModelUpdated(this));\n }\n}\n```\n\n```text\nHttpContext\n```\n\n```text\nIServiceProvider\n```\n\n```text\nIServiceProviderProxy\n```\n\n```text\nIHttpContextAccessor\n```\n\n```text\nIServiceProviderProxy\n```\n\n```text\nServiceLocator\n```\n\n```text\nIServiceProviderProxy\n```\n\n```text\napp.UseMvc();\nvar myServiceRef = app.ApplicationServices.GetService<MyService>();\n```\n\n```text\nConfigure\n```\n\n```text\nServiceActivator.Configure(app.ApplicationServices);\n```\n\n```text\nbuilder.Services.AddSingleton<IServiceProviderProxy, HttpContextServiceProviderProxy>();\n\nServiceLocator.Initialize(app.Services.GetService<IServiceProviderProxy>());\n```\n\n========================================\n\nComments:\n- Can you convert the MessageListener into a dependency and inject it wherever you need it with its own injected dependencies?\n- I am curious, did the answers below helped?\n- upvoted. but why not just use httpcontextaccessor regardless if it is scoped or singleton? is there a danger on using it in singleton?\n- I wonder how dependencies registered as transient AND implement IDisposable behave in this case. In asp.net core, if you resolve transient dependency - it will be disposed after request is finished. But here there is no request.\n- The built-in DI is relatively simple in some aspects like lifetime management. It might be worth considering hooking a 3rd party container like Autofact, StructureMap, Unity, etc in a case like this and create a scope per message for example\n- Yes but if you wont do this and use default one, I hope it at least won't get disposed by container?\n- You could do `using (var scope = services.CreateScope())` and then resolve services from `scope.ServiceProvider` which will get disposed of when the scope is disposed.\n- Thanks for this. I've not had time to try it, but I'd love to get away from the static implementation and this looks like it makes a lot of sense.\n- No worries! The ugliest part using the built-in DI container is that you cannot register multiple named `IMessageProcessor` and resolve them by name, so the abstract factory end a bit ugly. I wouldn't discard 3rd party containers (Autofact, StructureMap, Unity, etc). There are a few questions around that topic like this and this\n- Thanks @HamedH. I was looking for this `services.BuildServiceProvider().GetService();`\n- I get a warning: `Warnin\tASP0000\tCalling 'BuildServiceProvider' from application code results in an additional copy of singleton services being created. Consider alternatives such as dependency injecting services as parameters to 'Configure'.`\n- This was a practical solution for using extension methods with a singleton from the container. Note: set the static object in `Configure()`, not `ConfigureServices()` (for .Net Core 3+ anyway). e.g `public void Configure(IApplicationBuilder app, IStringLocalizerFactory factory)`\n- Thank you! This is EXACTLY what I am attempting to do, as I want to raise the events with Mediatr from within my domain.\n- Thank you! Your answer helped me a lot. I have one question that has came to my mind seeing this solution. How would it be possible to resolve your dependencies for a service that can handle HTTP requests, and messages from a message bus (or a scheduled job)? Because for handling messages that come from a message bus event handler, the IHttpContextAccessor is not going to have any HttpContext Initialised. Thanks in advance :)\n- @pablocom96 in that case you need to define your scope and create IoC Scope before calling the background message. For example, if you're receiving a message from a service bus, your scope most probably will be on the message received. `await using var scope = serviceProvider.CreateAsyncScope(); var dbContext = scope.ServiceProvider.GetRequiredService();`\n- Okay I see, and how we would access to the same Scope we created for a message handle in our ServiceLocator? I'm trying to see if either Masstransit or NServiceBus provides a way to do it similar to IHttpContextAccessor\n- @pablocom96 I guess you can use the Middleware idea in Masstransit masstransit-project.com/advanced/middleware I'm not experienced in NServiceBus but for sure they have the same feature. You can create a middleware to create and dispose your scopes\n- Thanks a lot! It worked by using a middleware in Masstransit that intercepts the IServiceScope in the ConsumeContext, and then setting it into an AsyncLocal property in BusEventHandlerContextAccessor (as singleton), that mimics how HttpContextAccessor behaves. So then I'm able to resolve scoped services inside my static DomainEvents class. Again thank you very much! :) :)\n- Why would a domain object need to talk to MediatR in the first place, the domain models should raise domain events and the propogation to infrastructure concerns such as MediatR would be handled in the outer layer of the onion.\n- @craigw in my case, I was using the Mediatr to raise the events\n- @WahidBitar it's worth reading up onion architecture and domain modelling to avoid this. If you can correctly the principles of DDD then you wouldn't need to cater to domain objects implementing technical concerns.\n- Great solution for allowing access of scoped services from a singleton.\n- Could you please update your answer. The first link doesn't work. Also, please provide the class (in case the link breaks). I know it will be a long answer but community needs it.\n- This gives a strong impression of saying thanks for an existing answer. Is this meant to be an answer according to How to Answer? If so please edit to make that more obvious. Otherwise please delete this.\n- The only thing thast keeps me from flagging this as \"Not An Answer; thanks for most upvoted existing answer\" is that I cannot pinpoint which part of the existing answer this is thanking for. That in turn makes me suspect that there might be an answer hidden in here. Can somebody please either confirm that this is an answer or help me dissamble it into \"thanks\" + quote from existing answers? After a day of no feedback I think we need to turn this into an answer without the help of the author - or get it deleted.","metadata":{"transformedAt":"2026-08-18T18:33:20.124Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":43,"totalLines":701,"estimatedTokens":5548}}96{"id":"stack-3280576","source":"stackoverflow","questionId":3280576,"title":"How does RabbitMQ compare to Mule","tags":["jms","esb","rabbitmq","mule","eai"],"text":"Title: How does RabbitMQ compare to Mule\nTags: jms, esb, rabbitmq, mule, eai\nSource: Stack Overflow\n\nQuestion:\nHow does RabbitMQ compare to Mule, I am going to build an application using message oriented architecture and AMQP (RabbitMQ) provides everything i want, but i am perplexed with so many related technology choice and similar concepts like ESB. I am having a doubt if i am making a choice without considering other alternatives.\n\nI am mostly clear that RabbitMQ is a message broker and it helps me in mediating message between producer and consumer (all forms or publish subscribe and i could understand how its used from real examples like twitter , or Facebook updates, etc)\n\nWhat is Mule, if i could achieve what i do in RabbitMQ using mule, should i consider mule similar to RabbitMQ?\n\nDoes mule has a different objective than that of a message broker?\n\nDoes mule assumes that underlying it there is a message broker that delivers message to the appropriate mule listeners (i could easily write a listener in RabbitMQ)\n\nIs mule a complete Java bases system ( The current experiment i did with RabbitMQ took me less than 30 Min to write a simple RPC Client Server with client as C# and Server as Java , will such things be done in Mule easily).\n\n========================================\n\nTop Answer:\nMule is a \"higher level\" service implemented with message broker. From the docs\n\n The messaging backbone of the ESB is\n usually implemented using JMS, but any\n other message server implementation\n could be used\n\nYou can build an ESB with rabbit; however, you're going to be limited to sending byte[] packages, and you'll have to build your system out of messaging primitives like topics and queues. It might be a bit faster (based on absolutely no benchmarking, testing or data) because there are fewer layers of translation. Mule provides an abstraction on top of this, speaks a variety of transports, and can handle some routing logic.\n\n========================================\n\nComments:\n- This is quite a web-centric view of a message broker - the idea the the webpage must return but some task may take longer than the user would want to wait - but message brokers have a much wider variety of applications than this.\n- @Dunk not sure how any of that message broker text has anything specific to the web, unless you commented on a previous version that somehow isn't appearing in the edit history.\n- @RobertGrant Yes, that doesn't make much sense. I remember writing this and distinctly recall a description that centred exclusively on \"I am a web developer and I need to do a thing that takes longer than a web request that's what brokers are for\". I do not know how or why, but the current answer doesn't say that at all. Happy to delete that comment.\n- Duplicate of the Answer provided by Henrik","metadata":{"transformedAt":"2026-08-18T18:33:20.124Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":36,"estimatedTokens":704}}97{"id":"stack-35583735","source":"stackoverflow","questionId":35583735,"title":"Unmarshaling Into an Interface{} and Then Performing Type Assertion","tags":["go","rabbitmq"],"text":"Title: Unmarshaling Into an Interface{} and Then Performing Type Assertion\nTags: go, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI get a `string` through a rabbitmq message system. Before sending,\n\nI use `json.Marshal`, convert the outcome to `string` and send through \nrabbitmq.\n\nThe structs that I convert and send can be: (changed the names and the size of the structs but it should not matter)\n\n```\ntype Somthing1 struct{\n Thing string `json:\"thing\"`\n OtherThing int64 `json:\"other_thing\"`\n}\n```\n\nor\n\n```\ntype Somthing2 struct{\n Croc int `json:\"croc\"`\n Odile bool `json:\"odile\"`\n}\n```\n\nThe message goes through perfectly as a `string` and is printed \non the other side (some server)\n\nUp until now everything works.\nNow I'm trying to convert them back into their structs and assert the types. \n\nfirst attempt is by:\n\n```\nfunc typeAssert(msg string) {\n\n var input interface{}\n\n json.Unmarshal([]byte(msg), &input)\n\n switch input.(type){\n case Somthing1:\n job := Somthing1{}\n job = input.(Somthing1)\n queueResults(job)\n\n case Somthing2:\n stats := Somthing2{}\n stats = input.(Somthing2)\n queueStatsRes(stats)\n default:\n}\n```\n\nThis does not work. When Printing the type of `input` after Unmarshaling\nit I get `map[string]interface{}` (?!?)\n\nand even stranger than that, the map key is the string I got and the map value is empty.\n\nI did some other attempts like:\n\n```\nfunc typeAssert(msg string) {\n\n var input interface{}\n\n json.Unmarshal([]byte(msg), &input)\n\n switch v := input.(type){\n case Somthing1:\n v = input.(Somthing1)\n queueResults(v)\n\n case Somthing2:\n v = input.(Somthing2)\n queueStatsRes(v)\n default:\n}\n```\n\nand also tried writing the switch like was explained in this answer:\nGolang: cannot type switch on non-interface value\n\n```\nswitch v := interface{}(input).(type)\n```\n\nstill with no success...\n\nAny ideas?\n\n========================================\n\nTop Answer:\nYou have encountered a typical json vs typed language problem! \nSince json is untyped and schemaless, it is not possible to infer what data is \"under the string\" without actually decoding it.\n\nSo your only option is to unmarshal into an `interface{}` which always produces a `map[string]interface{}`. You could do some reflection magic here to build the final struct, but that's a lot of manual work and error prone.\nHere are some possible solutions:\n\n### Quick 'n' dirty\n\nLet the `json` package do the reflection stuff. Attempt to unmarshal into every expected type:\n\n```\nfunc typeAssert(msg string) {\n\n var thing1 Something1\n\n err := json.Unmarshal([]byte(msg), &thing1)\n if err == nil{\n // do something with thing1\n return\n } \n\n var thing2 Something2\n\n err = json.Unmarshal([]byte(msg), &thing2)\n if err == nil{\n // do something with thing2\n return\n } \n\n //handle unsupported type\n\n}\n```\n\n### Build your own \"type system\" on top of json\n\nDefer the encoding until you know what's inside. Use this struct as an intermediate representation of your data:\n\n```\ntype TypedJson struct{\n Type string \n Data json.RawMessage\n}\n```\n\nMarshal: \n\n```\nthing := Something1{\"asd\",123}\ntempJson, _ := json.Marshal(thing)\n\ntypedThing := TypedJson{\"something1\", tempJson}\nfinalJson, _ := json.Marshal(typedThing)\n```\n\nUnmarshal:\n\n```\nfunc typeAssert(msg string) {\n\n var input TypedJson \n json.Unmarshal([]byte(msg), &input)\n\n switch input.Type{\n case \"something1\":\n var thing Something1\n json.Unmarshal(input.Data, &thing)\n queueStatsRes(thing) \n case \"something2\":\n var thing Something2\n json.Unmarshal(input.Data, &thing)\n queueStatsRes(thing)\n default:\n //handle unsupported type\n}\n```\n\n### Use a typed serialization format\n\n- Go's own gob encoding\n\n- Protocol Buffers\n\n- and many more...\n\n========================================\n\nCode:\n```text\ntype Somthing1 struct{\n Thing string `json:\"thing\"`\n OtherThing int64 `json:\"other_thing\"`\n}\n```\n\n```text\ntype Somthing2 struct{\n Croc int `json:\"croc\"`\n Odile bool `json:\"odile\"`\n}\n```\n\n```text\nfunc typeAssert(msg string) {\n\n var input interface{}\n\n json.Unmarshal([]byte(msg), &input)\n\n switch input.(type){\n case Somthing1:\n job := Somthing1{}\n job = input.(Somthing1)\n queueResults(job)\n\n case Somthing2:\n stats := Somthing2{}\n stats = input.(Somthing2)\n queueStatsRes(stats)\n default:\n}\n```\n\n```text\nfunc typeAssert(msg string) {\n\n var input interface{}\n\n json.Unmarshal([]byte(msg), &input)\n\n switch v := input.(type){\n case Somthing1:\n v = input.(Somthing1)\n queueResults(v)\n\n case Somthing2:\n v = input.(Somthing2)\n queueStatsRes(v)\n default:\n}\n```\n\n```text\nswitch v := interface{}(input).(type)\n```\n\n```text\nstring\n```\n\n```text\njson.Marshal\n```\n\n```text\nstring\n```\n\n```text\nstring\n```\n\n```text\ninput\n```\n\n```text\nmap[string]interface{}\n```\n\n```text\nbool, for JSON booleans\nfloat64, for JSON numbers\nstring, for JSON strings\n[]interface{}, for JSON arrays\nmap[string]interface{}, for JSON objects\nnil for JSON null\n```\n\n```text\ntype Something1 struct {\n Thing string `json:\"thing\"`\n OtherThing int64 `json:\"other_thing\"`\n}\n\ntype Something2 struct {\n Croc int `json:\"croc\"`\n Odile bool `json:\"odile\"`\n}\n\ntype Unpacker struct {\n Data interface{}\n}\n\nfunc (u *Unpacker) UnmarshalJSON(b []byte) error {\n smth1 := &Something1{}\n err := json.Unmarshal(b, smth1)\n\n // no error, but we also need to make sure we unmarshaled something\n if err == nil && smth1.Thing != \"\" {\n u.Data = smth1\n return nil\n }\n\n // abort if we have an error other than the wrong type\n if _, ok := err.(*json.UnmarshalTypeError); err != nil && !ok {\n return err\n }\n\n smth2 := &Something2{}\n err = json.Unmarshal(b, smth2)\n if err != nil {\n return err\n }\n\n u.Data = smth2\n return nil\n}\n```\n\n```text\njson\n```\n\n```text\nUnmarshal\n```\n\n```text\ninterface{}\n```\n\n```text\njson\n```\n\n```text\nSomething1\n```\n\n```text\nSomething2\n```\n\n```text\nmap[string]interface{}\n```\n\n```text\nfunc typeAssert(msg string) {\n\n var thing1 Something1\n\n err := json.Unmarshal([]byte(msg), &thing1)\n if err == nil{\n // do something with thing1\n return\n } \n\n var thing2 Something2\n\n err = json.Unmarshal([]byte(msg), &thing2)\n if err == nil{\n // do something with thing2\n return\n } \n\n //handle unsupported type\n\n}\n```\n\n```text\ntype TypedJson struct{\n Type string \n Data json.RawMessage\n}\n```\n\n```text\nthing := Something1{\"asd\",123}\ntempJson, _ := json.Marshal(thing)\n\ntypedThing := TypedJson{\"something1\", tempJson}\nfinalJson, _ := json.Marshal(typedThing)\n```\n\n```text\nfunc typeAssert(msg string) {\n\n var input TypedJson \n json.Unmarshal([]byte(msg), &input)\n\n switch input.Type{\n case \"something1\":\n var thing Something1\n json.Unmarshal(input.Data, &thing)\n queueStatsRes(thing) \n case \"something2\":\n var thing Something2\n json.Unmarshal(input.Data, &thing)\n queueStatsRes(thing)\n default:\n //handle unsupported type\n}\n```\n\n```text\ninterface{}\n```\n\n```text\nmap[string]interface{}\n```\n\n```text\njson\n```\n\n```text\ntype Somthing1 struct{\n Thing string `json:\"thing\"`\n OtherThing int64 `json:\"other_thing\"`\n}\n\ntype Somthing2 struct{\n Croc int `json:\"croc\"`\n Odile bool `json:\"odile\"`\n}\n\ntype Message struct{\n Type string // enum type here would be nice, but string for brevity\n\n // pointers, because only one of these will be populated, and the other will be nil. Can add as many as you want as you add message types.\n Somthing1 *Somthing1\n Somthing2 *Somthing2\n}\n\nfunc (m *Message) UnmarshalJSON(b []byte) error {\n var s1 Somthing1\n err := json.Unmarshal(b, &s1)\n if err == nil {\n // this line is some sort of check s1 is a valid Somthing1. Will depend on use case/data model\n if s1.Thing != \"\" {\n m.Type = \"Somthing1\"\n m.Somthing1 = &s1\n return nil\n }\n }\n\n var s2 Somthing2\n err = json.Unmarshal(b, &s2)\n if err == nil {\n // this line is some sort of check s2 is a valid Somthing2. Will depend on use case/data model\n if s2.Croc > 0 {\n m.Type = \"Somthing2\"\n m.Somthing2 = &s2\n return nil\n }\n }\n\n return errors.New(\"Invalid message\")\n}\n```\n\n```text\nUnmarshalJSON\n```\n\n```text\n{\"messageType\":\"Somthing1\", \"messageData\":{...}}\n```\n\n========================================\n\nComments:\n- That's my problem, I don't know what type I'm getting, \"under\" the string. So the secound option is not good. About the first one, how can I convert the `map[string]interface{}` if I dont know what key to use? @JimB\n- @darthydarth: What you do you mean \"under the string\"? In the map? play.golang.org/p/0zZ8fsmO17\n- EDIT: Sorry just commented now before looking at your playground solution. That is exactly what I was missing! thank you! Please post it as an solution for others and I'll up-vote. Thanks again @JimB\n- @darthydarth: You're not getting a struct, you can only get one of those 6 default types when unmarshaling into an `interface{}`, and you can't assert an interface to a type that it isn't. Take the data out of the map you're getting and create a new struct of the type you want.\n- Yes I understand that. I was missing the part about using range... If add your soulution to my original code I can assert back to the new instances of the original structs. I think...\n- @darthydarth: a type assertion only asserts that in interface contains a specific type; you can't change the type it contains. The range statement doesn't change anything, it was just an easy way to display the contents of the map.\n- JimB: Perfect thanks, after trying different things in the play ground I think this is the best solution to this, Thanks!\n- It seems that this method entirely depends on a field in one of the structs. Is there another way possibly - I cannot think of anything BUT that?\n- Liked the first solution, its exactly as you named it...but still will do the job perfectly. The second one is not that practical because in real life I have a very large struct constructed out of lots of other complex structs used by many places in the program so building a struct just to name the transferred main struct seems wrong to me and not pretty at all.\n- @darthydarth This \"wrapper struct\" will just be used for sending and receiving data. You can still use the original structs in the program. I think it's the better solution, but you are of course free to choose what fit's your case best.\n- I do agree in a way, yet it still looks weird to me specifying the type in a string. I mite be wrong about that. Still, thanks for both solutions- upvoted\n- @darthydarth The `Type` could be anything that qualifies as an identifier (e.g. distinct int values). It looks weird because it really is just a hack to get around the limitations of json.\n- yep a hack indeed, it's ok, I just really hate adding to many objects to a type if its not necessary. In this guess you are right\n- Great answer, `json.RawMessage` is exactly the right solution for this type of problem.","metadata":{"transformedAt":"2026-08-18T18:33:20.124Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":30,"totalLines":487,"estimatedTokens":2736}}98{"id":"stack-8839094","source":"stackoverflow","questionId":8839094,"title":"Why do my RabbitMQ channels keep closing?","tags":["java","rabbitmq"],"text":"Title: Why do my RabbitMQ channels keep closing?\nTags: java, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm debugging some Java code that uses Apache POI to pull data out of Microsoft Office documents. Occasionally, it encounter a large document and POI crashes when it runs out of memory. At that point, it tries to publish the error to RabbitMQ, so that other components can know that this step failed and take the appropriate actions. However, when it tries to publish to the queue, it gets a `com.rabbitmq.client.AlreadyClosedException (clean connection shutdown; reason: Attempt to use closed channel)`.\n\nHere's the error handler code: \n\n```\ntry {\n //Extraction and indexing code\n}\ncatch(Throwable t) {\n // Something went wrong! We'll publish the error and then move on with\n // our lives\n System.out.println(\"Error received when indexing message: \");\n t.printStackTrace();\n System.out.println();\n String error = PrintExc.format(t);\n message.put(\"error\", error);\n\n if(mime == null) {\n mime = \"application/vnd.unknown\";\n }\n\n message.put(\"mime\", mime);\n publish(\"IndexFailure\", \"\", MessageProperties.PERSISTENT_BASIC, message);\n}\n```\n\nFor completeness, here's the publish method:\n\n```\nprivate void publish(String exch, String route, \n AMQP.BasicProperties props, Map message) throws Exception{\n chan.basicPublish(exch, route, props, \n JSONValue.toJSONString(message).getBytes()); \n}\n```\n\nI can't find any code within the try block that appears to close the RabbitMQ channel. Are there any circumstances in which the channel could be closed implicitly?\n\n**EDIT**: I should note that the AlreadyClosedException is thrown by the `basicPublish` call inside publish.\n\n========================================\n\nTop Answer:\nAnother reason in my case was that by mistake I acknowledged a message twice. This lead to RabbitMQ errors in the log like this after the second acknowledgment. \n\n```\n=ERROR REPORT==== 11-Dec-2012::09:48:29 ===\nconnection , channel 1 - error:\n{amqp_error,precondition_failed,\"unknown delivery tag 1\",'basic.ack'}\n```\n\nAfter I removed the duplicate acknowledgement then the errors went away and the channel did not close anymore and also the AlreadyClosedException were gone.\n\n========================================\n\nCode:\n```text\ntry {\n //Extraction and indexing code\n}\ncatch(Throwable t) {\n // Something went wrong! We'll publish the error and then move on with\n // our lives\n System.out.println(\"Error received when indexing message: \");\n t.printStackTrace();\n System.out.println();\n String error = PrintExc.format(t);\n message.put(\"error\", error);\n\n if(mime == null) {\n mime = \"application/vnd.unknown\";\n }\n\n message.put(\"mime\", mime);\n publish(\"IndexFailure\", \"\", MessageProperties.PERSISTENT_BASIC, message);\n}\n```\n\n```text\nprivate void publish(String exch, String route, \n AMQP.BasicProperties props, Map<String, Object> message) throws Exception{\n chan.basicPublish(exch, route, props, \n JSONValue.toJSONString(message).getBytes()); \n}\n```\n\n```text\ncom.rabbitmq.client.AlreadyClosedException (clean connection shutdown; reason: Attempt to use closed channel)\n```\n\n```text\nbasicPublish\n```\n\n```text\n=ERROR REPORT==== 11-Dec-2012::09:48:29 ===\nconnection <0.6792.0>, channel 1 - error:\n{amqp_error,precondition_failed,\"unknown delivery tag 1\",'basic.ack'}\n```\n\n```text\nchannel.queueDeclare(\"task_queue\", durable, false, false, null);\n```\n\n```text\nchannel.queueDeclare(\"task_queue\", false, false, false, null);\n```\n\n```text\nRabbitMQ doesn't allow you to redefine an existing queue with different parameters and will return an error to any program that tries to do that\n```\n\n```text\nrabbitmqctl list_queues\n```\n\n```text\nrabbitmqctl stop_app\nrabbitmqctl reset\nrabbitmqctl start_app\n```\n\n```text\nchannel.basicQos(100);\n```\n\n========================================\n\nComments:\n- how you resolved this issue ?\n- It turns out that the AMQP connection was being closed by the JVM when it ran out of memory. However, for some reason, the shutdown listener on the channel wasn't firing when the connection was closing.\n- That double ack scenario is a very good point. Hard to see the problem. Thanks for the comment I totally helped me.\n- I encountered the same issue, and it was due to double NACK. good point here.\n- Once a queue is declared its properties are immutable. Why not just delete the queue then change the queue properties? Restarting the whole broker just to change one queue's properties seems a bit drastic\n- Thank you so much, I've been looking for a solution for days.\n- Why is this happening? Checking in documentation I didn't find any explaination","metadata":{"transformedAt":"2026-08-18T18:33:20.124Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":11,"totalLines":141,"estimatedTokens":1161}}99{"id":"stack-19357272","source":"stackoverflow","questionId":19357272,"title":"When to use RabbitMQ shovels and when Federation plugin?","tags":["rabbitmq","rabbitmq-shovel","rabbitmq-federation"],"text":"Title: When to use RabbitMQ shovels and when Federation plugin?\nTags: rabbitmq, rabbitmq-shovel, rabbitmq-federation\nSource: Stack Overflow\n\nQuestion:\nFor the company I work for we would like to use RabbitMQ as our main message bus. The idea we have is that every single application uses their own vhost for internal communication and that via the shovel or federation plugin we would make it possible to certain type of the events across multiple vhosts (maybe even multiple machines (non-clustered)).\nWe chose for application per vhost to separate internal communication from public events and to keep the security adjustable per application.\n\nBased on the information published on the RabbitMQ website I don't get it when I have to choose for shovels or when I have to choose for the federation plugin.\n\nRabbitMQ has the following explanation when to use what:\n\n Typically you would use the shovel to link brokers across the internet when you need more control than federation provides.\n\nWhat is the fine grain control in shovels which I am missing when I choose for federation?\n\nAt this moment I think I would prefer the federation plugin because I could automate the inter-vhost-communication via the REST API provided by the federation plugin.\nIn case of shovels I would need to change the shovel configuration and reboot the RabbitMQ instance every time we would like to an event between vhosts. Are my thoughts correct about this?\n\nWe are currently running RMQ on Windows with clients connecting from .NET. In the near future Java/Perl/PHP clients will join.\n\nTo summarize my questions:\n\nWhat is the fine grain control in shovels which I am missing when I\n\nchoose for federation?\nIs it correct that the only way to change the \ninter-vhost-communication when I use shovels is by changing theconfig file and rebooting the instance? \n\n- Does the setup (vhost per application) make sense or am I missing the point completely?\n\n========================================\n\nTop Answer:\n**Shovel** acts like a well-designed built-in consumer. It can consume messages from a source broker and queue, and publish them into a destination broker and exchange. You could write an application to do that, but shovel already got it right - if all you need is to move messages from a queue to an exchange in the same or another broker, shovel can do it for you. Just as a well-behaving app, it can declare exchanges/queues/bindings, reconnect, change the routing key etc. You can set it up on the source or on the destination broker, or even use a third broker. It's basically an AMQP client.\n\n**Federation**, on the other hand is used to connect your broker to one or multiple upstream brokers, or you can even create chains of brokers, bending the topology any way you like. You can federate exchanges or queues, and e.g. distribute messages to multiple brokers without the need to bind additional queues to a topic exchange or using a fanout exchange, and shoveling messages from each queue to a downstream broker.\n\nTo recap, federation operates at a higher level, while shovel is mostly \"just\" a well-written client.\n\nTo reconfigure shovel, you have to restart the broker, unfortunately.\n\nI don't think you really need a per app vhost. You can add a per-app user to the broker without separate vhosts. Not sure what you mean on \" an event between vhosts\", though.\n\n========================================\n\nCode:\n```text\nrabbitmqctl eval 'application:stop(rabbitmq_shovel), {ok, [[{rabbit, _}|[{rabbitmq_shovel, [{shovels, Shovels}] }]]]} = file:consult(\"/etc/rabbitmq/rabbitmq.config\"), application:set_env(rabbitmq_shovel, shovels, Shovels), application:start(rabbitmq_shovel).'\n```\n\n```text\nrabbitmq.config\n```\n\n```text\n/etc/rabbitmq/rabbitmq.config\n```\n\n========================================\n\nComments:\n- RabbitMQ now supports \"dynamic shovels\", which doesn't require a restart: rabbitmq.com/shovel.html","metadata":{"transformedAt":"2026-08-18T18:33:20.124Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":63,"estimatedTokens":976}}100{"id":"stack-4287941","source":"stackoverflow","questionId":4287941,"title":"How can I list or discover queues on a RabbitMQ exchange using python?","tags":["python","rabbitmq","amqp"],"text":"Title: How can I list or discover queues on a RabbitMQ exchange using python?\nTags: python, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI need to have a python client that can discover queues on a restarted RabbitMQ server exchange, and then start up a clients to resume consuming messages from each queue. How can I discover queues from some RabbitMQ compatible python api/library?\n\n========================================\n\nTop Answer:\nThere does not seem to be a direct AMQP-way to manage the server but there is a way you can do it from Python. I would recommend using a *subprocess* module combined with the `rabbitmqctl` command to check the status of the queues.\n\nI am assuming that you are running this on Linux. From a command line, running:\n\n```\nrabbitmqctl list_queues\n```\n\nwill result in:\n\n```\nListing queues ...\npings 0\nreceptions 0\nshoveled 0\ntest1 55199\n...done.\n```\n\n(well, it did in my case due to my specific queues)\n\nIn your code, use this code to get output of `rabbitmqctl`:\n\n```\nimport subprocess\n\nproc = subprocess.Popen(\"/usr/sbin/rabbitmqctl list_queues\", shell=True, stdout=subprocess.PIPE)\nstdout_value = proc.communicate()[0]\nprint stdout_value\n```\n\nThen, just come up with your own code to parse `stdout_value` for your own use.\n\n========================================\n\nCode:\n```text\nrabbitmqctl list_queues\n```\n\n```text\nListing queues ...\npings 0\nreceptions 0\nshoveled 0\ntest1 55199\n...done.\n```\n\n```text\nimport subprocess\n\nproc = subprocess.Popen(\"/usr/sbin/rabbitmqctl list_queues\", shell=True, stdout=subprocess.PIPE)\nstdout_value = proc.communicate()[0]\nprint stdout_value\n```\n\n```text\nrabbitmqctl\n```\n\n```text\nrabbitmqctl\n```\n\n```text\nstdout_value\n```\n\n```text\nhttp://localhost:15672/cli/\n```\n\n```text\nsudo /usr/lib/rabbitmq/bin/rabbitmq-plugins enable rabbitmq_management\nsudo service rabbitmq-server restart\n```\n\n```text\nimport requests\n\ndef rest_queue_list(user='guest', password='guest', host='localhost', port=15672, virtual_host=None):\n url = 'http://%s:%s/api/queues/%s' % (host, port, virtual_host or '')\n response = requests.get(url, auth=(user, password))\n queues = [q['name'] for q in response.json()]\n return queues\n```\n\n```text\nfrom pyrabbit.api import Client\ncl = Client('localhost:15672', 'guest', 'guest')\nqueues = [q['name'] for q in cl.get_queues()]\n```\n\n```text\nrabbitmqctl list_queues --vhost /els\n```\n\n```text\nimport requests\nimport json\n\ndef call_rabbitmq_api(host, port, user, passwd):\n url = 'http://%s:%s/api/queues' % (host, port)\n r = requests.get(url, auth=(user,passwd))\n return r\n\ndef get_queue_name(json_list):\n res = []\n for json in json_list:\n res.append(json[\"name\"])\n return res\n\nif __name__ == '__main__':\n host = 'rabbitmq_host'\n port = 55672\n user = 'guest'\n passwd = 'guest'\n res = call_rabbitmq_api(host, port, user, passwd)\n print (\"--- dump json ---\")\n print (json.dumps(res.json(), indent=4))\n print (\"--- get queue name ---\")\n q_name = get_queue_name(res.json())\n print (q_name)\n```\n\n========================================\n\nComments:\n- For me, this runs a wrapper script which refuses to continue if I'm not root. I can run the underlying binary (/usr/lib/rabbitmq/bin/rabbitmqctl) directly, though, if I make sure that my ~/.erlang.cookie file matches RabbitMQ's.\n- Running `rabbitmqctl list_queues` results in `Error: could not recognise command`\n- How do we get if the consumer is onine/ running ?\n- I suspect this will only show queues that the node has seen. There might be other queues on other nodes.","metadata":{"transformedAt":"2026-08-18T18:33:20.124Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":143,"estimatedTokens":886}}101{"id":"stack-17014584","source":"stackoverflow","questionId":17014584,"title":"How to create a delayed queue in RabbitMQ?","tags":["python","queue","rabbitmq","delay","pika"],"text":"Title: How to create a delayed queue in RabbitMQ?\nTags: python, queue, rabbitmq, delay, pika\nSource: Stack Overflow\n\nQuestion:\nWhat is the easiest way to create a delay (or parking) queue with Python, Pika and RabbitMQ? I have seen an similar questions, but none for Python. \n\nI find this an useful idea when designing applications, as it allows us to throttle messages that needs to be re-queued again.\n\nThere are always the possibility that you will receive more messages than you can handle, maybe the HTTP server is slow, or the database is under too much stress.\n\nI also found it very useful when something went wrong in scenarios where there is a zero tolerance to losing messages, and while re-queuing messages that could not be handled may solve that. It can also cause problems where the message will be queued over and over again. Potentially causing performance issues, and log spam.\n\n========================================\n\nTop Answer:\nYou can use RabbitMQ official plugin: **x-delayed-message** .\n\nFirstly, download and copy the ez file into *Your_rabbitmq_root_path/plugins*\n\nSecondly, enable the plugin (do not need to restart the server):\n\n```\nrabbitmq-plugins enable rabbitmq_delayed_message_exchange\n```\n\nFinally, publish your message with \"x-delay\" headers like:\n\n```\nheaders.put(\"x-delay\", 5000);\n```\n\n**Notice:**\n\nIt does not ensure your message's safety, cause if your message expires just during your rabbitmq-server's downtime, unfortunately the message is lost. So **be careful** when you use this scheme.\n\nEnjoy it and more info in rabbitmq-delayed-message-exchange\n\n========================================\n\nCode:\n```text\nchannel.queue_bind(exchange='amq.direct',\n queue='hello')\n```\n\n```text\ndelay_channel.queue_declare(queue='hello_delay', durable=True, arguments={\n 'x-message-ttl' : 5000,\n 'x-dead-letter-exchange' : 'amq.direct',\n 'x-dead-letter-routing-key' : 'hello'\n})\n```\n\n```text\ndelay_channel.basic_publish(exchange='',\n routing_key='hello_delay',\n body=\"test\",\n properties=pika.BasicProperties(delivery_mode=2))\n```\n\n```text\nimport pika\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n 'localhost'))\n\n# Create normal 'Hello World' type channel.\nchannel = connection.channel()\nchannel.confirm_delivery()\nchannel.queue_declare(queue='hello', durable=True)\n\n# We need to bind this channel to an exchange, that will be used to transfer \n# messages from our delay queue.\nchannel.queue_bind(exchange='amq.direct',\n queue='hello')\n\n# Create our delay channel.\ndelay_channel = connection.channel()\ndelay_channel.confirm_delivery()\n\n# This is where we declare the delay, and routing for our delay channel.\ndelay_channel.queue_declare(queue='hello_delay', durable=True, arguments={\n 'x-message-ttl' : 5000, # Delay until the message is transferred in milliseconds.\n 'x-dead-letter-exchange' : 'amq.direct', # Exchange used to transfer the message from A to B.\n 'x-dead-letter-routing-key' : 'hello' # Name of the queue we want the message transferred to.\n})\n\ndelay_channel.basic_publish(exchange='',\n routing_key='hello_delay',\n body=\"test\",\n properties=pika.BasicProperties(delivery_mode=2))\n\nprint \" [x] Sent\"\n```\n\n```text\nconfirm delivery\n```\n\n```text\ndelivery_mode\n```\n\n```text\ndurable\n```\n\n```text\n<rabbit:queue name=\"delayQueue\" durable=\"true\" queue-arguments=\"delayQueueArguments\"/>\n\n<rabbit:queue-arguments id=\"delayQueueArguments\">\n <entry key=\"x-message-ttl\">\n <value type=\"java.lang.Long\">10000</value>\n </entry>\n <entry key=\"x-dead-letter-exchange\" value=\"finalDestinationTopic\"/>\n <entry key=\"x-dead-letter-routing-key\" value=\"finalDestinationQueue\"/>\n</rabbit:queue-arguments>\n\n\n<rabbit:fanout-exchange name=\"finalDestinationTopic\">\n <rabbit:bindings>\n <rabbit:binding queue=\"finalDestinationQueue\"/>\n </rabbit:bindings>\n</rabbit:fanout-exchange>\n```\n\n```text\nrabbitmq-plugins enable rabbitmq_delayed_message_exchange\n```\n\n```text\nheaders.put(\"x-delay\", 5000);\n```\n\n```text\nvar ch = channel;\nch.assertExchange(\"my_intermediate_exchange\", 'fanout', {durable: false});\nch.assertExchange(\"my_final_delayed_exchange\", 'fanout', {durable: false});\n\n// setup intermediate queue which will never be listened.\n// all messages are TTLed so when they are \"dead\", they come to another exchange\nch.assertQueue(\"my_intermediate_queue\", {\n deadLetterExchange: \"my_final_delayed_exchange\",\n messageTtl: 5000, // 5sec\n}, function (err, q) {\n ch.bindQueue(q.queue, \"my_intermediate_exchange\", '');\n});\n\nch.assertQueue(\"my_final_delayed_queue\", {}, function (err, q) {\n ch.bindQueue(q.queue, \"my_final_delayed_exchange\", '');\n\n ch.consume(q.queue, function (msg) {\n console.log(\"delayed - [x] %s\", msg.content.toString());\n }, {noAck: true});\n});\n```\n\n```text\ndef delay_publish(self, messages, queue, headers=None, expiration=0):\n \"\"\"\n Connect to RabbitMQ and publish messages to the queue\n Args:\n queue (string): queue name\n messages (list or single item): messages to publish to rabbit queue\n expiration(int): TTL in milliseconds for message\n \"\"\"\n delay_queue = \"\".join([queue, \"_delay\"])\n logging.info('Publishing To Queue: {queue}'.format(queue=delay_queue))\n logging.info('Connecting to RabbitMQ: {host}'.format(\n host=self.rabbit_host))\n credentials = pika.PlainCredentials(\n RABBIT_MQ_USER, RABBIT_MQ_PASS)\n parameters = pika.ConnectionParameters(\n rabbit_host, RABBIT_MQ_PORT,\n RABBIT_MQ_VHOST, credentials, heartbeat_interval=0)\n connection = pika.BlockingConnection(parameters)\n\n channel = connection.channel()\n channel.queue_declare(queue=queue, durable=True)\n\n channel.queue_bind(exchange='amq.direct',\n queue=queue)\n delay_channel = connection.channel()\n delay_channel.queue_declare(queue=delay_queue, durable=True,\n arguments={\n 'x-dead-letter-exchange': 'amq.direct',\n 'x-dead-letter-routing-key': queue\n })\n\n properties = pika.BasicProperties(\n delivery_mode=2, headers=headers, expiration=str(expiration))\n\n if type(messages) not in (list, tuple):\n messages = [messages]\n\n try:\n for message in messages:\n try:\n json_data = json.dumps(message)\n except Exception as err:\n logging.error(\n 'Error Jsonify Payload: {err}, {payload}'.format(\n err=err, payload=repr(message)), exc_info=True\n )\n if (type(message) is dict) and ('data' in message):\n message['data'] = {}\n message['error'] = 'Payload Invalid For JSON'\n json_data = json.dumps(message)\n else:\n raise\n\n try:\n delay_channel.basic_publish(\n exchange='', routing_key=delay_queue,\n body=json_data, properties=properties)\n except Exception as err:\n logging.error(\n 'Error Publishing Data: {err}, {payload}'.format(\n err=err, payload=json_data), exc_info=True\n )\n raise\n\n except Exception:\n raise\n\n finally:\n logging.info(\n 'Done Publishing. Closing Connection to {queue}'.format(\n queue=delay_queue\n )\n )\n connection.close()\n```\n\n========================================\n\nComments:\n- what happens when each message to be published has varying ttl? how do I do that?\n- There shouldn't be much difference. Simply move the `TTL` to the Message properties instead. Feel free to open a new question and link it here and I'll answer it.\n- Thanks, I think you've answered it already but after some reading I found that its not reliable since a dead message can be stuck behind healthy ones and so even though they expire they still cant move on.\n- You could probably combine it with a high queue TTL, and then set the per message TTL to a lower value, but like you mentioned it might not work as intended. I have never tried this with a per message TTL.\n- I was looking a similar solution for hours. Thanks for that! Works perfect. \"X-\" arguments should be better documented.\n- @Marconi , could you please link to the articles that you read to come to that conclusion or further explain the downside?\n- @ManuelZubieta sorry its been some time now so I don't remember exactly where I read it.\n- @ManuelZubieta The caveats sub-section of the Per-Message TTL section in the RabbitMQ TTL docs linked to above (rabbitmq.com/ttl.html) explains how expired messages are only expired from the head of the queue. That appears to kill this answer as a viable solution for per message TTL.\n- @Caolite: is there an issue in creating a queue for each set of delayed messages?\n- @eandersson I like this solution, but what if the topology is so that there are dozens of main queues, and dozens of delay queues?","metadata":{"transformedAt":"2026-08-18T18:33:20.124Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":248,"estimatedTokens":2315}}102{"id":"stack-20128124","source":"stackoverflow","questionId":20128124,"title":"amqp vs amqplib - which Node.js amqp client library is better?","tags":["node.js","rabbitmq","amqp"],"text":"Title: amqp vs amqplib - which Node.js amqp client library is better?\nTags: node.js, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nWhat are the differences between those amqp client libraries?\nWhich one is the most recommended?\nWhat are the major differences?\n\n========================================\n\nTop Answer:\nI'm the guy that wrote the bramqp library. So I'm going to admit from the start I may be a bit biased. :P \n\nIn my opinion, as long as you know the spec, bramqp should work fine. Otherwise, use amqp.node\n\nThe following are the amqp libraries available for node.js. \n\n**amqplib** / **amqp.node** - promise style, still updated, looks pretty stable and easy\n\n**bramqp** - provides a full low level access to AMQP functions, not recommended for starting out\n\n**amqp-coffee** - coffeescript implementation similar to amqp/node-amqp\n\n**amqp** / **node-amqp** - popular, fixed API, not updated as often, a few odd bugs, stable but limited\n\nThe following libraries use one of the previous libraries, while providing an easier to use interface or adding features\n\n**rabbit.js** uses amqplib/amqp.node\n\n**wascally** uses amqplib/amqp.node\n\n**amq** uses amqplib/amqp.node\n\n**amqpea** uses bramqp\n\n**easy-amqp** uses amqp/node-amqp\n\n**rabbus** uses wascally\n\nI am also going to add **node-amqp10** separately, as it can connect to amqp 1.0 servers. \n\nIf there are any more that I should add, just let me know.\n\n========================================\n\nCode:\n```text\nnpm install amqp\n```\n\n```text\nhttps://github.com/LeanKit-Labs/wascally\n```\n\n========================================\n\nComments:\n- \"Which one is most recommended\" is a broad question. The other two are good, though.\n- Can you create channel in node-amqp?\n- Note that your link was posted in 2010.\n- I have been working with bramqp and amqplib, and bramqp points to be by the moment a complete library solution. I like the 'direct' use of the amqp commands throug the \"handle\" object, so the point for you ;) Thanks mate!\n- +1 for pointing node-amqp hides \"channel\" concept which i was exploring in that from 2 days.\n- I can second that node-amqp is kind of a poor module. Currently using amqplib and have been pleased so far.\n- The first answered is dated from 2013. Carl, do you still think the same? Any update about this topic? In my case I am using node-amqp because it is pointed from the official web of Rabbitmq, but there are not too much updated.\n- Yes, node-amqp is still barley ever updated, but amqp.node is. github.com/LeanKit-Labs/wascally is also a good alternative, very easy to use.\n- when shall i use rabbit.js ?? Rabbit.js is also same as amqp.node ? right\n- Wascally is now dead. I won't recommend a winning lib, but do your own research!\n- Totally agree, bramqp looks looks more robust and direct, but require a bit more of effort to start using and understand it. In other libraries each one has is own methods and technics for the same or simply lacks of certain funtions of amqp. Is my reason to have choosen bramqp this time\n- Useful comparison from creator of one of good libraries. There are multiple discussions on Node and RabbitMQ using node-amqp library. I was also installed that but subsequently found use of channels over single TCP connection for better resource management. But couldn't find its handling in node-amqp. As pointed by Carl, above, and you now planning to use amqp.node now because in am new but surely explore bramqp when gets better control on RabbitMQ.","metadata":{"transformedAt":"2026-08-18T18:33:20.124Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":70,"estimatedTokens":870}}103{"id":"stack-34534178","source":"stackoverflow","questionId":34534178,"title":"RabbitMQ: How to send Python dictionary between Python producer and consumer?","tags":["python","rabbitmq"],"text":"Title: RabbitMQ: How to send Python dictionary between Python producer and consumer?\nTags: python, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm trying to send a python dictionary from a python producer to a python consumer using RabbitMQ. The producer first establishes the connection to local RabbitMQ server. Then it creates a queue to which the message will be delivered, and finally sends the message. The consumer first connects to RabbitMQ server and then makes sure the queue exists by creating the same queue. It then receives the message from producer within the callback function, and prints the 'id' value (1). Here are the scripts for producer and consumer:\n\nproducer.py script:\n\n```\nimport pika\nimport sys\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))\nchannel = connection.channel()\n\nchannel.queue_declare(queue='task_queue', durable=True)\n\nmessage = {'id': 1, 'name': 'name1'}\nchannel.basic_publish(exchange='',\n routing_key='task_queue',\n body=message,\n properties=pika.BasicProperties(\n delivery_mode = 2, # make message persistent\n ))\nprint(\" [x] Sent %r\" % message)\nconnection.close()\n```\n\nconsumer.py script:\n\n```\nimport pika\nimport time\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))\nchannel = connection.channel()\n\nchannel.queue_declare(queue='task_queue', durable=True)\nprint(' [*] Waiting for messages. To exit press CTRL+C')\n\ndef callback(ch, method, properties, body):\n print(\" [x] Received %r\" % body)\n print(body['id'])\n print(\" [x] Done\")\n ch.basic_ack(delivery_tag = method.delivery_tag)\n\nchannel.basic_qos(prefetch_count=1)\nchannel.basic_consume(callback,\n queue='task_queue')\n\nchannel.start_consuming()\n```\n\nBut, when I run the producer.py, I get this error:\n\n```\nline 18, in \n delivery_mode = 2, # make message persistent\n File \"/Library/Python/2.7/site-packages/pika/adapters/blocking_connection.py\", line 1978, in basic_publish\n mandatory, immediate)\n File \"/Library/Python/2.7/site-packages/pika/adapters/blocking_connection.py\", line 2064, in publish\n immediate=immediate)\n File \"/Library/Python/2.7/site-packages/pika/channel.py\", line 338, in basic_publish\n (properties, body))\n File \"/Library/Python/2.7/site-packages/pika/channel.py\", line 1150, in _send_method\n self.connection._send_method(self.channel_number, method_frame, content)\n File \"/Library/Python/2.7/site-packages/pika/connection.py\", line 1571, in _send_method\n self._send_message(channel_number, method_frame, content)\n File \"/Library/Python/2.7/site-packages/pika/connection.py\", line 1596, in _send_message\n content[1][s:e]).marshal())\nTypeError: unhashable type\n```\n\nCould anybody help me? Thanks!\n\n========================================\n\nCode:\n```text\nimport pika\nimport sys\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))\nchannel = connection.channel()\n\nchannel.queue_declare(queue='task_queue', durable=True)\n\nmessage = {'id': 1, 'name': 'name1'}\nchannel.basic_publish(exchange='',\n routing_key='task_queue',\n body=message,\n properties=pika.BasicProperties(\n delivery_mode = 2, # make message persistent\n ))\nprint(\" [x] Sent %r\" % message)\nconnection.close()\n```\n\n```text\nimport pika\nimport time\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))\nchannel = connection.channel()\n\nchannel.queue_declare(queue='task_queue', durable=True)\nprint(' [*] Waiting for messages. To exit press CTRL+C')\n\ndef callback(ch, method, properties, body):\n print(\" [x] Received %r\" % body)\n print(body['id'])\n print(\" [x] Done\")\n ch.basic_ack(delivery_tag = method.delivery_tag)\n\nchannel.basic_qos(prefetch_count=1)\nchannel.basic_consume(callback,\n queue='task_queue')\n\nchannel.start_consuming()\n```\n\n```text\nline 18, in <module>\n delivery_mode = 2, # make message persistent\n File \"/Library/Python/2.7/site-packages/pika/adapters/blocking_connection.py\", line 1978, in basic_publish\n mandatory, immediate)\n File \"/Library/Python/2.7/site-packages/pika/adapters/blocking_connection.py\", line 2064, in publish\n immediate=immediate)\n File \"/Library/Python/2.7/site-packages/pika/channel.py\", line 338, in basic_publish\n (properties, body))\n File \"/Library/Python/2.7/site-packages/pika/channel.py\", line 1150, in _send_method\n self.connection._send_method(self.channel_number, method_frame, content)\n File \"/Library/Python/2.7/site-packages/pika/connection.py\", line 1571, in _send_method\n self._send_message(channel_number, method_frame, content)\n File \"/Library/Python/2.7/site-packages/pika/connection.py\", line 1596, in _send_message\n content[1][s:e]).marshal())\nTypeError: unhashable type\n```\n\n```text\nimport json\nchannel.basic_publish(exchange='',\n routing_key='task_queue',\n body=json.dumps(message),\n properties=pika.BasicProperties(\n delivery_mode = 2, # make message persistent\n ))\n```\n\n```text\ndef callback(ch, method, properties, body):\nprint(\" [x] Received %r\" % json.loads(body))\n```\n\n========================================\n\nComments:\n- Can you try converting your message to a json object and then send.\n- Thanks! I've sent the message successfully, but got this error after running the consumer: ValueError: No JSON object could be decoded\n- Well you can just print out `body` to see what it looks like. JSON is just a string so it is pretty easily human-parseable.\n- No error after fixing the json message format. Thanks a lot for your solution. You've saved my day :)\n- thanks for short and straight forward answer. It works on python3.8","metadata":{"transformedAt":"2026-08-18T18:33:20.124Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":163,"estimatedTokens":1442}}104{"id":"stack-18403623","source":"stackoverflow","questionId":18403623,"title":"RabbitMQ AMQP.BasicProperties.Builder values","tags":["java","rabbitmq","messaging","amqp"],"text":"Title: RabbitMQ AMQP.BasicProperties.Builder values\nTags: java, rabbitmq, messaging, amqp\nSource: Stack Overflow\n\nQuestion:\nIn the RabbitMQ/AMQP Java client, you can create an `AMQP.BasicProperties.Builder`, and use it to `build()` an instance of `AMQP.BasicProperties`. This built properties instance can then be used for all sorts of important things. There are lots of \"builder\"-style methods available on this builder class:\n\n```\nBasicProperties.Builder propsBuilder = new BasicProperties.Builder();\npropsBuilder\n .appId(???)\n .clusterId(???)\n .contentEncoding(???)\n .contentType(???)\n .correlationId(???)\n .deliveryMode(2)\n .expiration(???)\n .headers(???)\n .messageId(???)\n .priority(???)\n .replyTo(???)\n .timestamp(???)\n .type(???)\n .userId(???);\n```\n\nI'm looking for what fields these builer methods help \"build-up\", **and most importantly, what valid values exist for each field**. For instance, what is a `clusterId`, and what are its valid values? What is `type`, and what are its valid values? Etc.\n\nI have spent all morning scouring:\n\n- The Java client documentation; and\n\n- The Javadocs; and\n\n- The RabbitMQ full reference guide; and\n\n- The AMQP specification\n\nIn all these docs, I cannot find clear definitions (besides some *vague* explanation of what `priority`, `contentEncoding` and `deliveryMode` are) of what each of these fields are, and what their valid values are. Does anybody know? More importantly, does anybody know where these are even documented? Thanks in advance!\n\n========================================\n\nTop Answer:\nAt time of writing:\n\n- The latest AMQP standard is AMQP 1.0 OASIS Standard.\n\n- The latest version of RabbitMQ is 3.1.5 (server and client), which claims to support AMQP 0.9.1 (pdf and XML schemas zipped).\n\n- RabbitMQ provides it's own description of the protocol as XML schema including extensions (i.e. non-standard), plus XML schema without extensions (which is identical to the schema linked via (2)) and pdf doc.\n\nIn this answer: \n\n- links in (3) are the primary source of detail\n\n- (2) pdf doc is used as secondary detail if (3) is inadequate\n\n- The source code (java client, erlang server) is used as tertiary detail if (2) is inadequate.\n\n- (1) is generally not used - the protocol and schema have been (fairly) significantly evolved for/by OASIS and should apply to future versions of RabbitMQ, but do not apply now. The two exceptions where (1) was used was for textual descriptions of `contentType` and `contentEncoding` - which is safe, because these are standard fields with good descriptions in AMQP 1.0.\n\nThe following text is paraphrased from these sources by me to make a little more concise or clear.\n\n- **content-type** (AMQP XML type=\"shortstr\"; java type=\"String\"): Optional. The RFC-2046 MIME type for the message’s application-data section (body). Can contain a charset parameter defining the character encoding used: e.g., ’text/plain; charset=“utf-8”’. Where the content type is unknown the content-type SHOULD NOT be set, allowing the recipient to determine the actual type. Where the section is known to be truly opaque binary data, the content-type SHOULD be set to application/octet-stream.\n\n- **content-encoding** (AMQP XML type=\"shortstr\"; java type=\"String\"): Optional. When present, describes additional content encodings applied to the application-data, and thus what decoding mechanisms need to be applied in order to obtain the media-type referenced by the content-type header field. Primarily used to allow a document to be compressed without losing the identity of its underlying content type. A modifier to the content-type, interpreted as per section 3.5 of RFC 2616. Valid content-encodings are registered at IANA. Implementations SHOULD NOT use the compress encoding, except as to remain compatible with messages originally sent with other protocols, e.g. HTTP or SMTP. Implementations SHOULD NOT specify multiple content-encoding values except as to be compatible with messages originally sent with other protocols, e.g. HTTP or SMTP.\n\n- **headers** (AMQP XML type=\"table\"; java type=\"Map\"): Optional. An application-specified list of header parameters and their values. These may be setup for application-only use. Additionally, it is possible to create queues with \"Header Exchange Type\" - when the queue is created, it is given a series of header property names to match, each with optional values to be matched, so that routing to this queue occurs via header-matching.\n**deliveryMode** (RabbitMQ XML type=\"octet\"; java type=\"Integer\"): **1** (non-persistent) or **2** (persistent). Only works for queues that implement persistence. A persistent message is held securely on disk and guaranteed to be delivered\neven if there is a serious network failure, server crash, overflow etc.\n\n- **priority** (AMQP XML type=\"octet\"; java type=\"Integer\"): The relative message priority (**0 to 9**). A high priority message is [MAY BE?? - GB] sent ahead of lower priority messages waiting in the same message queue. When messages must be discarded in order to maintain a specific service quality level the server will first discard low-priority messages. Only works for queues that implement priorities.\n\n- **correlation-id** (AMQP XML type=\"octet\"; java type=\"String\"): Optional. For application use, no formal (RabbitMQ) behaviour. A client-specific id that can be used to mark or identify messages between clients.\n\n- **replyTo** (AMQP XML type=\"shortstr\"; java type=\"String\"): Optional. For application use, no formal (RabbitMQ) behaviour but may hold the name of a private response queue, when used in request messages. The address of the node to send replies to.\n\n- **expiration** (AMQP XML type=\"shortstr\"; java type=\"String\"): Optional. RabbitMQ AMQP 0.9.1 schema from (3) states \"For implementation use, no formal behaviour\". The AMQP 0.9.1 schema pdf from (2) states an absolute time when this message is considered to be expired. However, **both these descriptions must be ignored** because this TTL link and the client/server code indicate the following is true. From the client, expiration is only be populated via custom application initialisation of BasicProperties. At the server, this is used to determine TTL from the point the message is received at the server, prior to queuing. The server selects TTL as the minimum of (1) message TTL (client **BasicProperties expiration** as a *relative time in milliseconds*) and (2) queue TTL (configured **x-message-ttl** in milliseconds). Format: string quoted integer representing number of milliseconds; time of expiry from message being received at server.\n\n- **message-id** (AMQP XML type=\"shortstr\"; java type=\"String\"): Optional. For application use, no formal (RabbitMQ) behaviour. If set, the message producer should set it to a globally unique value. In future (AMQP 1.0), a broker MAY discard a message as a duplicate if the value of the message-id matches that of a previously received message sent to the same node.\n\n- **timestamp** (AMQP XML type=\"timestamp\"; java type=\"java.util.Date\"): Optional. For application use, no formal (RabbitMQ) behaviour. An absolute time when this message was created.\n\n- **type** (AMQP XML type=\"shortstr\"; java type=\"String\"): Optional. For application use, no formal (RabbitMQ) behaviour. [Describes the message as being of / belonging to an application-specific \"type\" or \"form\" or \"business transaction\" - GB]\n\n- **userId** (AMQP XML type=\"shortstr\"; java type=\"String\"): Optional. XML Schema states \"For application use, no formal (RabbitMQ) behaviour\" - but I believe this has changed in the latest release (read on). If set, the client sets this value as identity of the user responsible for producing the message. From RabbitMQ: If this property is set by a publisher, its value must be equal to the name of the user used to open the connection (i.e. validation occurs to ensure it is the connected/authenticated user). If the user-id property is not set, the publisher's identity remains private.\n\n- **appId** (RabbitMQ XML type=\"shortstr\"; java type=\"String\"): Optional. For application use, no formal (RabbitMQ) behaviour. The creating application id. Can be populated by producers and read by consumers. (Looking at R-MQ server code, this is not used at all by the server, although the \"webmachine-wrapper\" plugin provides a script and matching templates to create a webmachine - where an admin can provide an appId to the script.)\n\n- **cluster Id** (RabbitMQ XML type=\"N/A\"; java type=\"String\"): **Deprecated in AMQP 0.9.1 - i.e. not used.** In previous versions, was the intra-cluster routing identifier, for use by cluster applications, which should not be used by client applications (i.e. not populated). However, this has been deprecated and removed from the current schema and is not used by R-MQ server code.\n\nAs you can see above, the vast majority of these properties do not have enumerated / constrained / recommended values because they are \"application use only\" and are not used by RabbitMQ. So you have an easy job. You're free to write/read values that are useful to your application - as long as they match datatype and compile :). `ContentType` and `contentEncoding` are as per standard HTTP use. `DeliveryMode` and `priority` are constrained numbers. \n\nNote: Useful, but simple constants for AMQP.BasicProperties are available in class MessageProperties.\n\nCheers :)\n\n**UPDATE TO POST:**\n\nWith many thanks to Renat (see comments), have looked at erlang server code in rabbit_amqqueue_process.erl and documentation at RabbitMQ TTL Extensions to AMQP. Message expiration (time-to-live) can be specified \n\nper queue via:\n\n```\nMap args = new HashMap();\nargs.put(\"x-message-ttl\", 60000);\nchannel.queueDeclare(\"myqueue\", false, false, false, args);\n```\n\nor per message via:\n\n```\nbyte[] messageBodyBytes = \"Hello, world!\".getBytes();\nAMQP.BasicProperties properties = new AMQP.BasicProperties();\nproperties.setExpiration(\"60000\");\nchannel.basicPublish(\"my-exchange\", \"routing-key\", properties, messageBodyBytes);\n```\n\nHere, the ttl/expiration is in millisecs, so 60 sec in each case.\nHave updated above definition of **expiration** to reflect this.\n\n========================================\n\nCode:\n```text\nBasicProperties.Builder propsBuilder = new BasicProperties.Builder();\npropsBuilder\n .appId(???)\n .clusterId(???)\n .contentEncoding(???)\n .contentType(???)\n .correlationId(???)\n .deliveryMode(2)\n .expiration(???)\n .headers(???)\n .messageId(???)\n .priority(???)\n .replyTo(???)\n .timestamp(???)\n .type(???)\n .userId(???);\n```\n\n```text\nAMQP.BasicProperties.Builder\n```\n\n```text\nbuild()\n```\n\n```text\nAMQP.BasicProperties\n```\n\n```text\nclusterId\n```\n\n```text\ntype\n```\n\n```text\npriority\n```\n\n```text\ncontentEncoding\n```\n\n```text\ndeliveryMode\n```\n\n```text\ncontent_type = <<\"text/plain\">>,\n content_encoding = <<\"UTF-8\">>,\n delivery_mode = 2,\n priority = 1,\n correlation_id = <<\"123\">>,\n reply_to = <<\"something\">>,\n expiration = <<\"my-expiration\">>,\n message_id = <<\"M123\">>,\n timestamp = 123456,\n type = <<\"freshly-squeezed\">>,\n user_id = <<\"joe\">>,\n app_id = <<\"joe's app\">>,\n headers = [{<<\"str\">>, longstr, <<\"foo\">>},\n {<<\"int\">>, longstr, <<\"123\">>}]\n```\n\n```text\nexpiration\n```\n\n```text\nttl\n```\n\n```text\nAMQP\n```\n\n```text\nexpiration\n```\n\n```text\nMap<String, Object> args = new HashMap<String, Object>();\nargs.put(\"x-message-ttl\", 60000);\nchannel.queueDeclare(\"myqueue\", false, false, false, args);\n```\n\n```text\nbyte[] messageBodyBytes = \"Hello, world!\".getBytes();\nAMQP.BasicProperties properties = new AMQP.BasicProperties();\nproperties.setExpiration(\"60000\");\nchannel.basicPublish(\"my-exchange\", \"routing-key\", properties, messageBodyBytes);\n```\n\n```text\ncontentType\n```\n\n```text\ncontentEncoding\n```\n\n```text\nContentType\n```\n\n```text\ncontentEncoding\n```\n\n```text\nDeliveryMode\n```\n\n```text\npriority\n```\n\n========================================\n\nComments:\n- One day, people who write these APIs for Java will find out about ENUMS.\n- The value descriptions for Content Encoding and Content Type have to be swapped.\n- @SlavenRezic, you are very right. Sorry for the mistake and thank you.\n- Great answer, thanks. The 'Additional source 2' link is broken though.\n- at the Time-stamp field the type is really a timestamp not a number (containing milisecs), the rabbit admin page displaying it as number but if you are receiving the msg you can see it, and the declaration tell you too that he expecting a timestamp\n- @Glen_Best, **expiration** is not for application use. Please check *rabbit_amqqueue_process.erl* or see my update.\n- Have checked the code - you're correct. Edited post. Thanks!\n- Clarification: is for application use as per rabbitmq.com/ttl.html; my explanation indicated no formal processing by Rabbit - there is such. i.e. RabbitMQ 0.9.1 schema comment is out of date / wrong.","metadata":{"transformedAt":"2026-08-18T18:33:20.125Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":22,"totalLines":256,"estimatedTokens":3288}}105{"id":"stack-3457305","source":"stackoverflow","questionId":3457305,"title":"How can I check whether a RabbitMQ message queue exists or not?","tags":[".net","queue","rabbitmq","message-queue","not-exists"],"text":"Title: How can I check whether a RabbitMQ message queue exists or not?\nTags: .net, queue, rabbitmq, message-queue, not-exists\nSource: Stack Overflow\n\nQuestion:\nHow can I check whether a message Queue already exists or not?\n\nI have 2 different applications, one creating a queue and the other reading from that queue.\n\nSo if I run the Client which reads from the queue first, than it crashes.\n\nSo to avoid that i would like to check first whether the queue exists or not.\n\nhere is the code snippet of how I read the queue:\n\n```\nQueueingBasicConsumer = new QueueingBasicConsumer(); \n.BasicConsume(\"\", null, ); \nBasicDeliverEventArgs e = (BasicDeliverEventArgs).Queue.Dequeue();\n```\n\n========================================\n\nTop Answer:\nPut below code inside try catch section. If queue or exchange doesn't exist then it will throw error. if exists it will not do anything. \n\n```\nvar channel = connection.CreateModel();\n\n channel.ExchangeDeclarePassive(sExchangeName);\n\n QueueDeclareOk ok = channel.QueueDeclarePassive(sQueueName);\n\n if (ok.MessageCount > 0)\n {\n // Bind the queue to the exchange\n\n channel.QueueBind(sQueueName, sExchangeName, string.Empty);\n }\n```\n\n========================================\n\nCode:\n```text\nQueueingBasicConsumer <ConsumerName> = new QueueingBasicConsumer(<ChannelName>); \n<ChannelName>.BasicConsume(\"<queuename>\", null, <ConsumerName>); \nBasicDeliverEventArgs e = (BasicDeliverEventArgs)<ConsumerName>.Queue.Dequeue();\n```\n\n```text\nvar channel = connection.CreateModel();\n\n\n channel.ExchangeDeclarePassive(sExchangeName);\n\n QueueDeclareOk ok = channel.QueueDeclarePassive(sQueueName);\n\n if (ok.MessageCount > 0)\n {\n // Bind the queue to the exchange\n\n channel.QueueBind(sQueueName, sExchangeName, string.Empty);\n }\n```\n\n```text\n@Autowired\npublic RabbitAdmin rabbitAdmin;\n\n//###############get you queue details##############\nProperties properties = rabbitAdmin.getQueueProperties(queueName);\n\n//do your custom logic\nif( properties == null)\n{\n createQueue(queueName);\n}\n```\n\n```text\n@SpringBootApplication\n @EnableAutoConfiguration(exclude \n {org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration.class})\n public class MyApplication {\n\n public static void main(String[] args) {\n SpringApplication.run(MyApplication.class, args);\n }\n\n}\n```\n\n```text\n...\n rabbitmq.queue=my-queue\n...\n```\n\n```text\n@Component\n@EnableRabbit\n@PropertySource(\"classpath:rabbitmq.properties\")\npublic class RabbitMQConfiguration\n{\n...\n @Value(\"${rabbitmq.queue}\")\n private String queueName;\n\n...\n\n @Bean\n public Queue queue() {\n return new Queue(queueName, false);\n }\n...\n```\n\n```text\n@Component\n@PropertySource(\"classpath:rabbitmq.properties\")\npublic class MyConsumer\n{\n private static Logger LOG = LogManager.getLogger(MyConsumer.class.toString());\n\n @RabbitListener(queues = {\"${rabbitmq.queue}\"})\n public void receive(@Payload Object data) {\n LOG.info(\"Message: \" + data) ;\n }\n```\n\n```text\nchannel.QueueDeclarePassive(QueueName)\n```\n\n```text\nQueueDeclarePassive()\n```\n\n```text\nQueueDeclare()\n```\n\n```text\nRabbitMQ.Client.Exceptions.OperationInterruptedException\n```\n\n========================================\n\nComments:\n- here is the code snippet of how i read the queue QueueingBasicConsumer = new QueueingBasicConsumer(); .BasicConsume(\"\", null, ); BasicDeliverEventArgs e = (BasicDeliverEventArgs).Queue.Dequeue();\n- I have added that code snippet to your post. In the future, please click the **edit** link when adding more context, instead of adding a comment. For more information, see the section ***When Should I Comment?*** on the Help page for Comments.\n- Can you please Mention the Syntax for declaring the queue passively in c# api\n- Use IModel.QueueDeclare and set passive to true. rabbitmq.com/releases/rabbitmq-dotnet-client/v1.8.1/…\n- Really? I just tried using C# QueueDeclare(); and it produced two identical queues on the RabbitMQ dashboard.\n- Queue declaration might be idempotent, but if you don't know the parameters of the queue you are trying to publish to (auto-deleted etc.), queue redeclaration will fail, because of different queue settings.\n- Checking queue existence might be useful. For example, if you're writing a RPC service, you may want to ensure that RPC client hasn't gone away before processing the message.\n- that passive thing from @scvalex doesn't exist anymore in the new versions of rabbitmq c# client. queue.declare is idempotent as long as you pass in the same params (e.g. durable, exclusive, etc)\n- That will only work if the user have configure permissions to the queue. Sometimes you have different users for writing and reading. So i don´t think this is the best solution\n- You can't tell for everyone that \"Don't bother checking.\" What if I want a single consumer for single query? Just need to check. And your answer doesn't answer the question. I have an active queue declaring and do not want passive, still need to know that the queue exists. Whats then?\n- API links is dead, this may be a more generalized one to the subject.\n- Perhaps this is the working link: rawcdn.githack.com/rabbitmq/rabbitmq-management/v3.8.3/priv/‌​www/…\n- Get a live person to log into the console and maybe give the interested party a phone call or send an email? That's not a serious solution.\n- I am looking at the split approach of Publishers declaring Exchanges and Consumers declaring Queues and binding them to Exchanges. However, if the Exchange is not declared when the consumer tries to bind the Queue to it, an exception is thrown. Do you ensure that the Publisher is initialized first, are you also declaring the exchanges in the consumer, are you manually creating exchanges the the UI/CLI, or are you doing something else to prevent the issue?\n- We made the consumer announce it's stuck, and then await for the Exchange to appear (looping on the exception occurring), or for the app to be closed/killed. This allows the system to be started up in any order and for it to be restarted as needed without the publishers or consumers having to be ordered in their startup.\n- Actually, this is the correct answer. the one that has been chosen as correct, emits a potential risk of declaring and creating abandoned Queues in RabbitMQ server. The QueueDeclarePassive method has been designed to be used in such a situation.\n- Thank you +1. One point worth noting is to keep channel only for this checking, because if the check fails, channel becomes useless. See: github.com/streadway/amqp/issues/167 . Unrelated note: channel is `IDisposable`.","metadata":{"transformedAt":"2026-08-18T18:33:20.125Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":11,"totalLines":167,"estimatedTokens":1655}}106{"id":"stack-38444425","source":"stackoverflow","questionId":38444425,"title":"How does RabbitMQ actually store the message physically?","tags":["rabbitmq"],"text":"Title: How does RabbitMQ actually store the message physically?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI want to know how does RabbitMQ store the messages physically in its RAM and Disk?\n\nI know that RabbitMQ tries to keep the messages in memory (But I don't know how the messages are put in the Ram). But the messages can be spilled into disk when the messages are with persistent mode or when the broker has the memory pressure. (But I don't know how the messages are stored in Disk.)\n\nI'd like to know the internals about these. Unfortunately, the official documentation in its homepage do not expose the internal details.\n\nWhich document should I read for this?\n\n========================================\n\nCode:\n```text\n/var/lib/rabbitmq/mnesia/rabbit@hostname/queues\n```\n\n========================================\n\nComments:\n- and would it be possible to use MSMQ instead for persisting the messages?\n- @Marco do you mean \"Microsoft Message Queuing\" ? In general (right now) RabbitMQ does not support external databases to store the messages\n- Yes that's what I meant, fair enough, I wasn't sure it would support it. Thanks @Gabriele","metadata":{"transformedAt":"2026-08-18T18:33:20.125Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":26,"estimatedTokens":287}}107{"id":"stack-41306350","source":"stackoverflow","questionId":41306350,"title":"How to generate password_hash for RabbitMQ Management HTTP API","tags":["c#","rabbitmq","rabbitmqadmin"],"text":"Title: How to generate password_hash for RabbitMQ Management HTTP API\nTags: c#, rabbitmq, rabbitmqadmin\nSource: Stack Overflow\n\nQuestion:\nThe beloved RabbitMQ Management Plugin has a HTTP API to manage the RabbitMQ through plain HTTP requests.\n\nWe need to create users programatically, and the HTTP API was the chosen way to go. The documentation is scarce, but the API it's pretty simple and intuitive. \n\nConcerned about the security, we don't want to pass the user password in plain text, and the API offers a field to send the password hash instead. Quote from there:\n\n [ GET | PUT | DELETE ] /api/users/*name*\n\n \n An individual user. To PUT a user, you will need a body looking\n something like this:\n\n```\n{\"password\":\"secret\",\"tags\":\"administrator\"}\n```\n\n \n or:\n\n```\n{\"password_hash\":\"2lmoth8l4H0DViLaK9Fxi6l9ds8=\", \"tags\":\"administrator\"}\n```\n\n \n The tags key is mandatory. Either `password` or `password_hash` must be set.\n\nSo far, so good, the problem is: **how to correctly generate the `password_hash`?** \n\nThe password hashing algorithm is configured in RabbitMQ's configuration file, and our is configured as the default SHA256.\n\nI'm using C#, and the following code to generate the hash:\n\n```\nvar cr = new SHA256Managed();\nvar simplestPassword = \"1\";\nvar bytes = cr.ComputeHash(Encoding.UTF8.GetBytes(simplestPassword));\nvar sb = new StringBuilder();\nforeach (var b in bytes) sb.Append(b.ToString(\"x2\"));\nvar hash = sb.ToString();\n```\n\nThis doesn't work. Testing in some online tools for SHA256 encryption, the code is generating the expected output. However, if we go to the management page and set the user password manually to \"1\" then it works like a charm.\n\nThis answer led me to export the configurations and take a look at the hashes RabbitMQ are generating, and I realized a few things:\n\n- hash example of \"1\": \"y4xPTRVfzXg68sz9ALqeQzARam3CwnGo53xS752cDV5+Utzh\"\n\n- all the user's hashes have fixed length\n\n- the hashes change every time (even if the password is the same). I know PB2K also do this to passwords, but don't know the name of this cryptographic property.\n\n- if I pass the `password_hash` the RabbitMQ stores it without changes\n\nI'm accepting suggestions in another programming languages as well, not just C#.\n\n========================================\n\nTop Answer:\nAnd for the fun the bash version !\n\n```\n#!/bin/bash\n\nfunction encode_password()\n{\n SALT=$(od -A n -t x -N 4 /dev/urandom)\n PASS=$SALT$(echo -n $1 | xxd -ps | tr -d '\\n' | tr -d ' ')\n PASS=$(echo -n $PASS | xxd -r -p | sha256sum | head -c 128)\n PASS=$(echo -n $SALT$PASS | xxd -r -p | base64 | tr -d '\\n')\n echo $PASS\n}\n\nencode_password \"some-password\"\n```\n\n========================================\n\nCode:\n```text\n{\"password\":\"secret\",\"tags\":\"administrator\"}\n```\n\n```text\n{\"password_hash\":\"2lmoth8l4H0DViLaK9Fxi6l9ds8=\", \"tags\":\"administrator\"}\n```\n\n```text\nvar cr = new SHA256Managed();\nvar simplestPassword = \"1\";\nvar bytes = cr.ComputeHash(Encoding.UTF8.GetBytes(simplestPassword));\nvar sb = new StringBuilder();\nforeach (var b in bytes) sb.Append(b.ToString(\"x2\"));\nvar hash = sb.ToString();\n```\n\n```text\npassword\n```\n\n```text\npassword_hash\n```\n\n```text\npassword_hash\n```\n\n```text\npassword_hash\n```\n\n```text\npublic static class RabbitMqPasswordHelper\n{\n public static string EncodePassword(string password)\n {\n using (RandomNumberGenerator rand = RandomNumberGenerator.Create())\n using (var sha512 = SHA512.Create())\n {\n byte[] salt = new byte[4];\n\n rand.GetBytes(salt);\n\n byte[] saltedPassword = MergeByteArray(salt, Encoding.UTF8.GetBytes(password));\n byte[] saltedPasswordHash = sha512.ComputeHash(saltedPassword);\n\n return Convert.ToBase64String(MergeByteArray(salt, saltedPasswordHash));\n }\n }\n\n private static byte[] MergeByteArray(byte[] array1, byte[] array2)\n {\n byte[] merge = new byte[array1.Length + array2.Length];\n array1.CopyTo(merge, 0);\n array2.CopyTo(merge, array1.Length);\n\n return merge;\n }\n}\n```\n\n```text\n//Rextester.Program.Main is the entry point for your code. Don't change it.\n//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5\n\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text.RegularExpressions;\nusing System.Security.Cryptography;\nusing System.Text;\n\nnamespace Rextester\n{\n public static class RabbitMqPasswordHelper\n{\n public static string EncodePassword(string password)\n {\n using (RandomNumberGenerator rand = RandomNumberGenerator.Create())\n using (var sha256 = SHA256.Create())\n {\n byte[] salt = new byte[4];\n\n rand.GetBytes(salt);\n\n byte[] saltedPassword = MergeByteArray(salt, Encoding.UTF8.GetBytes(password));\n byte[] saltedPasswordHash = sha256.ComputeHash(saltedPassword);\n\n return Convert.ToBase64String(MergeByteArray(salt, saltedPasswordHash));\n }\n }\n\n private static byte[] MergeByteArray(byte[] array1, byte[] array2)\n {\n byte[] merge = new byte[array1.Length + array2.Length];\n array1.CopyTo(merge, 0);\n array2.CopyTo(merge, array1.Length);\n\n return merge;\n }\n}\n\n public class Program\n {\n public static void Main(string[] args)\n {\n //Your code goes here\n Console.WriteLine(Rextester.RabbitMqPasswordHelper.EncodePassword(\"MyPassword\"));\n }\n }\n}\n```\n\n```text\n#!/bin/env/python\nimport hashlib\nimport binascii\n\n# Utility methods for generating and comparing RabbitMQ user password hashes.\n#\n# Rabbit Password Hash Algorithm:\n# \n# Generate a random 32 bit salt: \n# CA D5 08 9B \n\n# Concatenate that with the UTF-8 representation of the password (in this \n# case \"simon\"): \n# CA D5 08 9B 73 69 6D 6F 6E \n\n# Take the MD5 hash: \n# CB 37 02 72 AC 5D 08 E9 B6 99 4A 17 2B 5F 57 12 \n\n# Concatenate the salt again: \n# CA D5 08 9B CB 37 02 72 AC 5D 08 E9 B6 99 4A 17 2B 5F 57 12 \n\n# And convert to base64 encoding: \n# ytUIm8s3AnKsXQjptplKFytfVxI= \n# \n# Sources:\n# http://rabbitmq.1065348.n5.nabble.com/Password-Hashing-td276.html\n# http://hg.rabbitmq.com/rabbitmq-server/file/df7aa5d114ae/src/rabbit_auth_backend_internal.erl#l204 \n\n# Test Case:\n# print encode_rabbit_password_hash('CAD5089B', \"simon\")\n# print decode_rabbit_password_hash('ytUIm8s3AnKsXQjptplKFytfVxI=')\n# print check_rabbit_password('simon','ytUIm8s3AnKsXQjptplKFytfVxI=')\n\ndef encode_rabbit_password_hash(salt, password):\n salt_and_password = salt + password.encode('utf-8').encode('hex')\n salt_and_password = bytearray.fromhex(salt_and_password)\n salted_md5 = hashlib.md5(salt_and_password).hexdigest()\n password_hash = bytearray.fromhex(salt + salted_md5)\n password_hash = binascii.b2a_base64(password_hash).strip()\n return password_hash\n\ndef decode_rabbit_password_hash(password_hash):\n password_hash = binascii.a2b_base64(password_hash)\n decoded_hash = password_hash.encode('hex')\n return (decoded_hash[0:8], decoded_hash[8:])\n\ndef check_rabbit_password(test_password, password_hash):\n salt, hash_md5sum = decode_rabbit_password_hash(password_hash)\n test_password_hash = encode_rabbit_password_hash(salt, test_password)\n return test_password_hash == password_hash\n```\n\n```text\npackage main\n\nimport (\n \"crypto/rand\"\n \"crypto/sha256\"\n \"encoding/base64\"\n \"flag\"\n \"fmt\"\n mRand \"math/rand\"\n \"time\"\n)\n\nvar src = mRand.NewSource(time.Now().UnixNano())\n\nfunc main() {\n\n input := flag.String(\"password\", \"\", \"The password to be encoded. One will be generated if not supplied\")\n\n flag.Parse()\n\n salt := [4]byte{}\n _, err := rand.Read(salt[:])\n if err != nil {\n panic(err)\n }\n\n pass := *input\n\n if len(pass) == 0 {\n pass = randomString(32)\n }\n\n saltedP := append(salt[:], []byte(pass)...)\n\n hash := sha256.New()\n\n _, err = hash.Write(saltedP)\n\n if err != nil {\n panic(err)\n }\n\n hashPass := hash.Sum(nil)\n\n saltedP = append(salt[:], hashPass...)\n\n b64 := base64.StdEncoding.EncodeToString(saltedP)\n\n fmt.Printf(\"Password: %s\\n\", string(pass))\n fmt.Printf(\"Hash: %s\\n\", b64)\n}\n\nconst (\n letterBytes = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\"\n letterIdxBits = 6 // 6 bits to represent a letter index\n letterIdxMask = 1<<letterIdxBits - 1 // All 1-bits, as many as letterIdxBits\n letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits\n)\n\nfunc randomString(size int) string {\n b := make([]byte, size)\n // A src.Int63() generates 63 random bits, enough for letterIdxMax letters!\n for i, cache, remain := size-1, src.Int63(), letterIdxMax; i >= 0; {\n if remain == 0 {\n cache, remain = src.Int63(), letterIdxMax\n }\n if idx := int(cache & letterIdxMask); idx < len(letterBytes) {\n b[i] = letterBytes[idx]\n i--\n }\n cache >>= letterIdxBits\n remain--\n }\n\n return string(b)\n\n}\n```\n\n```text\n#!/usr/bin/env python3\n\n# rabbitMQ password hashing algo as laid out in:\n# http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/2011-May/012765.html\n\nfrom __future__ import print_function\nimport base64\nimport os\nimport hashlib\nimport struct\nimport sys\n\n# This is the password we wish to encode\npassword = sys.argv[1]\n\n# 1.Generate a random 32 bit salt:\n# This will generate 32 bits of random data:\nsalt = os.urandom(4)\n\n# 2.Concatenate that with the UTF-8 representation of the plaintext password\ntmp0 = salt + password.encode('utf-8')\n\n# 3. Take the SHA256 hash and get the bytes back\ntmp1 = hashlib.sha256(tmp0).digest()\n\n# 4. Concatenate the salt again:\nsalted_hash = salt + tmp1\n\n# 5. convert to base64 encoding:\npass_hash = base64.b64encode(salted_hash)\n\nprint(pass_hash.decode(\"utf-8\"))\n```\n\n```text\n#!/bin/bash\n\nfunction encode_password()\n{\n SALT=$(od -A n -t x -N 4 /dev/urandom)\n PASS=$SALT$(echo -n $1 | xxd -ps | tr -d '\\n' | tr -d ' ')\n PASS=$(echo -n $PASS | xxd -r -p | sha256sum | head -c 128)\n PASS=$(echo -n $SALT$PASS | xxd -r -p | base64 | tr -d '\\n')\n echo $PASS\n}\n\nencode_password \"some-password\"\n```\n\n```text\n/**\n * Generates a salted SHA-256 hash of a given password.\n */\n private String getPasswordHash(String password) {\n var salt = getSalt();\n try {\n var saltedPassword = concatenateByteArray(salt, password.getBytes(StandardCharsets.UTF_8));\n MessageDigest digest = MessageDigest.getInstance(\"SHA-256\");\n byte[] hash = digest.digest(saltedPassword);\n\n return Base64.getEncoder().encodeToString(concatenateByteArray(salt,hash));\n } catch (NoSuchAlgorithmException e) {\n e.printStackTrace();\n }\n }\n\n /**\n * Generates a 32 bit random salt.\n */\n private byte[] getSalt() {\n var ba = new byte[4];\n new SecureRandom().nextBytes(ba);\n return ba;\n }\n\n /**\n * Concatenates two byte arrays.\n */\n private byte[] concatenateByteArray(byte[] a, byte[] b) {\n int lenA = a.length;\n int lenB = b.length;\n byte[] c = Arrays.copyOf(a, lenA + lenB);\n System.arraycopy(b, 0, c, lenA, lenB);\n return c;\n }\n```\n\n```text\nparam (\n $password\n)\n\n$rand = [System.Security.Cryptography.RandomNumberGenerator]::Create()\n$hash = [System.Security.Cryptography.SHA512]::Create()\n\n[byte[]]$salt = New-Object byte[] 4\n$rand.GetBytes($salt)\n\n#Uncomment the next 2 to replicate derick baileys sample\n#[byte[]]$salt = 0xCA, 0xD5, 0x08, 0x9B\n#$hash = [System.Security.Cryptography.Md5]::Create()\n\n#Write-Host \"Salt\"\n#[System.BitConverter]::ToString($salt)\n\n[byte[]]$utf8PasswordBytes = [Text.Encoding]::UTF8.GetBytes($password)\n#Write-Host \"UTF8 Bytes\"\n#[System.BitConverter]::ToString($utf8PasswordBytes)\n\n[byte[]]$concatenated = $salt + $utf8PasswordBytes\n#Write-Host \"Concatenated\"\n#[System.BitConverter]::ToString($concatenated)\n\n[byte[]]$saltedHash = $hash.ComputeHash($concatenated)\n#Write-Host \"SHA512:\"\n#[System.BitConverter]::ToString($saltedHash)\n\n[byte[]]$concatenatedAgain = $salt + $saltedHash\n#Write-Host \"Concatenated Again\"\n#[System.BitConverter]::ToString($concatenatedAgain)\n\n$base64 = [System.Convert]::ToBase64String($concatenatedAgain)\nWrite-Host \"BASE64\"\n$base64\n```\n\n```text\n$hash\n```\n\n```text\n$salt\n```\n\n```sh\n#!/bin/bash\n\nfunction get_byte()\n{\n local BYTE=$(head -c 1 /dev/random | tr -d '\\0')\n\n if [ -z \"$BYTE\" ]; then\n BYTE=$(get_byte)\n fi\n\n echo \"$BYTE\"\n}\n\nfunction encode_password()\n{\n BYTE1=$(get_byte)\n BYTE2=$(get_byte)\n BYTE3=$(get_byte)\n BYTE4=$(get_byte)\n\n SALT=\"${BYTE1}${BYTE2}${BYTE3}${BYTE4}\"\n PASS=\"$SALT$1\"\n TEMP=$(echo -n \"$PASS\" | openssl sha256 -binary)\n PASS=\"$SALT$TEMP\"\n PASS=$(echo -n \"$PASS\" | base64)\n echo \"$PASS\"\n}\n\nencode_password $1\n```\n\n```text\nvar result = await services.GetService<IBrokerObjectFactory>()\n.CreateUser(\"testuser3\", \"testuserpwd3\", \"gkgfjjhfjh\".ComputePasswordHash(),\n x =>\n {\n x.WithTags(t =>\n {\n t.Administrator();\n });\n });\n```\n\n```ruby\nrequire 'securerandom' \nrequire 'digest'\nrequire 'base64'\n\ndef generate_password_hash(plain_text)\n salt = SecureRandom.random_bytes(4).bytes.to_a\n pass = plain_text.bytes.to_a\n\n #Known sample values. Should return kI3GCqW5JLMJa4iX1lo7X4D6XbYqlLgxIs30+P6tENUV2POR\n # salt = [\"908DC60A\"].pack(\"H*\").unpack(\"C*\")\n # pass = \"test12\".bytes.to_a\n\n arr = salt + pass\n sha256 = Digest::SHA256.base64digest(arr.pack('C*').force_encoding('utf-8'))\n\n sha256_bytes = Base64.strict_decode64(sha256).bytes.to_a\n\n arr = salt + sha256_bytes\n password_hash = Base64.encode64(arr.pack('c*')).strip!\n\n return password_hash\nend\n```\n\n```text\n$ rabbitmqctl hash_password foobar\nWill hash password foobar\nc9KkB60KtKFwksRUg3EBYzRCG7Te5l4t4PLaM/7D0DoTdxiZ\n\n$ curl -4su guest:guest -X GET localhost:15672/api/auth/hash_password/foobar\n{\"ok\":\"erB0SI9prHWeqeHwcUFdJPziTYn4ZCcepfAFY7XWsjfN70Ln\"}\n```\n\n```text\n3.11.8\n```\n\n```text\nrabbitmqctl hash_password foobar\n```\n\n```text\ncurl -u api_user:api_pass rabbitmq-server:15672/api/auth/hash_password/foobar\n```\n\n```text\nARG PASSWORD\n\nFROM rabbitmq:3-management\nCOPY definitions.json /etc/rabbitmq/definitions.json\nRUN sh -c 'hash_password=\"$(rabbitmqctl hash_password --quiet $$PASSWORD)\"; sed -i -e \"s/{{PASSWORD}}/$hash_password/g\" \"/etc/rabbitmq/definitions.json\";'\n```\n\n```text\n{{PASSWORD}}\n```\n\n========================================\n\nComments:\n- I believe they hash not a password but encrypted password. They may use some RSA algorithm to get ecnrypted password and then calculate hash for it.\n- To be able to generate hashes you need to find the key that is used for encrypting passwords.\n- I tried to understand what they do in the source code ( github.com/rabbitmq/rabbitmq-management/blob/master/src/… ), but I know nothing of Erlang and functional languages\n- RabbitMQ 3.11.8 and newer includes a command and API to hash a string according to the currently configured password hashing algorithm - stackoverflow.com/a/75575617/1466825\n- Thanks Derick, it worked like a charm. Advice for future readers: it's not always MD5, it depends on what is configured on rabbitmq.config (default is SHA256 since v3.6.0)\n- stackoverflow.com/a/75575617/1466825\n- It also works for sha256. You've to just replace `SHA512` to `SHA256`.\n- Any way to do it in the template language.?\n- Fun fact: be careful when passing passwords in Powershell (in order to use this script): it interprets whatever is after an \"$\" character as a variabile.\n- For Mac users: `brew install coreutils`\n- ha love this great answer\n- To whoever finds this answer useful: please check also Luke Bakken's answer\n- I didn't close the page hoping that someone must have posted a java solution for sure. Hope in Humanity restored. <3\n- Try and add --quiet to the rabbitmqctl call to get rid of the first line \"Will hash password etc\" and only get the hash.\n- At least one of those must show an incorrect result, because `foobar` can have only one hash :)","metadata":{"transformedAt":"2026-08-18T18:33:20.125Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":26,"totalLines":586,"estimatedTokens":4023}}108{"id":"stack-4405992","source":"stackoverflow","questionId":4405992,"title":"Best PHP client library for accessing RabbitMQ (AMQP)?","tags":["php","rabbitmq","amqp"],"text":"Title: Best PHP client library for accessing RabbitMQ (AMQP)?\nTags: php, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nThere is a list of PHP clients on the RabbitMQ site. I'm asking this question in hopes that people who have used any of these can their experiences here. E.g.\n\n- Did you have any trouble installing?\n\n- Is it stable?\n\n- Were there any performance issues?\n\n- How is the documentation / support?\n\nEven if you've just used one of these libraries, please your experiences.\n\nFor reference, here are some of the clients listed:\n\n- PHP manual page for AMQP\n\n- php-amqp - a client developed and used by StudiVZ, originally based on RabbitMQ-C\n\n- php-amqplib a port of py-amqplib\n\n- php-amqplib a fork of php-amqplib updated to support PHP 5.3\n\n- PECL release of the AMQP client\n\nP.S. I know that \"Best ...\" is \"subjective\", but the point of this question is to collect experiences and help people make an informed decision about these AMQP libraries. Please don't knee-jerk close this question just because it has the word \"best\" in it.\n\nP.P.S. I'm using PHP 5.3 on RHEL 5.\n\n========================================\n\nTop Answer:\nThis library seem to be alive and succeeding the original from code.google:\n\nhttps://github.com/videlalvaro/php-amqplib\n\nThere are also tests and Travis CI.\n\n========================================\n\nComments:\n- Hmm, it is subjective indeed and has no definite answers. Might be better suited for *programmers*?\n- Maybe, but I'd like to see the discussion. This is a problem our big project is facing at the moment.\n- The list of clients is now at rabbitmq.com/download.html with additional \"clients for other languages\" at rabbitmq.com/devtools.html\n- Yeah. I prefered php-amqplib because it was most like python-amqplib. I (yes, tom.bioinf is me) wrote the patch that should've been applied, and wouldn't have broken the trunk ;) But there we go.\n- @Tom, Are you still using php-amqplib?\n- Not personally. I wrote that patch when I was at another job, they're still using it, I think, but I doubt they've upgraded since.. In the purposes of testing, I'm more than happy to use php-amqplib again\n- Interesting. I was drawn to the simplicity of a PHP-only client, but you raise good points.\n- BTW github.com/bkw/php-amqp requires bc_math library php.net/manual/en/ref.bc.php\n- According to the documentation to the *tnc* version, it has moved here: github.com/videlalvaro/php-amqplib .\n- Thanks for posting, @Pieter. Can you comment on the level of ongoing development and resources your team has? How closely (if at all) do you work with or coordinate releases with either the librabbitmq team or RabbitMQ itself (both of which will be changing as AMQP matures to 1.0 etc.)?\n- How can we help port it to Windows? What are the dependencies?\n- @dkamins: We have two resources that are tasked with keeping this extension bug free and compatible with the latest versions of RabbitMQ and the underlying C client. The latter is experimental, so this is sometimes difficult, but it a production level requirement, so we have to make the effort. We are not at a point where we are coordinating releases yet, but I hope to be able to for the next major versions.\n- @aib: The dependency is the underlying C library which we use. Much like the memcache extensions, we wrap a standard C library, and since the C library is not 100% on Windows yet, we are stuck. There is a significant push by the entire RabbitMQ community to make it work on Windows, and AFAIK, we are very close to having one.\n- @Pieter Can you please look into this question with +50 bounty. I am exploring RabbitMq implementation with PHP and will greatly appreciate your help. Thanks stackoverflow.com/questions/9151698\n- We are trying to get a script to work for 24/7 in our server ... and I know there are things like heartbeats and keepalive which I can 'hack' in but why aren't there any straight forward way of telling it to not layoff idle consumers (either in the connection constructor and no public way of setting heartbeat)?\n- Also, have a look at this post for compiling rabbitmq-c and installing PECL ampq: thegeekstuff.com/2013/05/amqp-php-extension/comment-page-1/…\n- There seems to be something wrong with the link posted in the answer. Where can I find the end-user documentation for this extension?\n- The other drawback is that you have to be really lucky guy to make it connect over SSL/TLS , with all the certificates issues which will face.\n- I have been using this library with good results so far. Just found my first drawback: when adopting Monolog (github.com/Seldaek/monolog) I found out that it depends on the PECL php-amqp module and can't get it to work directly with php-amqplib because it does not expose the AMQPExchange as an object like the previous one. Need to change Monolog's AMQP handler or php-amqplib to mate them correctly.","metadata":{"transformedAt":"2026-08-18T18:33:20.125Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":64,"estimatedTokens":1219}}109{"id":"stack-42200317","source":"stackoverflow","questionId":42200317,"title":"How to configure RabbitMQ connection with spring-rabbit?","tags":["spring-boot","rabbitmq","spring-amqp","spring-rabbit"],"text":"Title: How to configure RabbitMQ connection with spring-rabbit?\nTags: spring-boot, rabbitmq, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI'm following this guide to learn how to use `spring-rabbit` with RabbitMQ. However in this guide, the RabbitMQ configuration is as default(localhost server and with credential as guest/guest). What should I do if I want to connect to an remote RabbitMQ with ip address and credential? I don't know where to set these information in my application.\n\n========================================\n\nCode:\n```text\nspring-rabbit\n```\n\n```text\n...\nspring.rabbitmq.host=localhost # RabbitMQ host.\n...\nspring.rabbitmq.password= # Login to authenticate against the broker.\nspring.rabbitmq.port=5672 # RabbitMQ port.\n...\nspring.rabbitmq.username= # Login user to authenticate to the broker.\n...\n```\n\n```text\nspring.rabbitmq.addresses= # Comma-separated list of addresses to which the client should connect.\n```\n\n```text\napplication.properties\n```\n\n```text\nsrc/main/resources\n```\n\n```text\nserver1:5672,server2:5672\n```\n\n```text\nCachingConnectionFactory\n```\n\n```text\n@Bean\n```\n\n========================================\n\nComments:\n- It's weird, I added these properties into `application.properties` as you suggested. However, these properties seems haven't been loaded into the running application. Anything I missed?\n- I just downloaded the guide, added `application.properties` to `src/main/resources` for the `complete` version and pointed it to a remote rabbitmq instance and it worked just fine - I see the queue created on the rabbit instance and the output messages. How are you running the guide?\n- My bad, sorry, your solution works like a charm. It didn't work here because I added `@Bean MessageListenerAdapter listenerAdapter(Receiver receiver) { return new MessageListenerAdapter(receiver, \"receiveMessage\");}` in my configuration class.\n- How do you achieve this programatically?\n- It's not clear what you mean; see the documentation and samples. It's better to ask a completely new question rather than asking a new question in a comment on an old one.\n- @GaryRussell with spring boot I am using application.yml and configured all ssl properties from Appendix A except ssl algorithm. In this case my application always tries PLAIN authentication. I know that defining EXTERNAL sasl config can resolve it, I am looking for any configuration I need to make to do that without defining any beans. Can I add any property in application yml and achieve it?\n- As I stated above; you must not ask new questions in a comment on a very old answer; ask a new question showing your current configuration and exactly what you are trying to achieve.\n- @GaryRussell Thanks for quick response - I have asked a new question here request your help : stackoverflow.com/questions/53752686/…\n- Hi! Do you know how can I connect a kubernetes rabbitmq cluster using your the addresses properties? Or any approach. Currently I've tried bellow approach but no success. The rabbitmq-service is of loadbalancer type. spring.rabbitmq.addresses=rabbitmq-0.rabbitmq-service:5672,h‌​ttp://…\n- Don't ask questions in comments on 3 year old answers; I am not a k8s expert; people from the Kubernetes community won't see it; ask a new question instead, tagged with the relevant technologies. Why do you have `http:` in there?","metadata":{"transformedAt":"2026-08-18T18:33:20.125Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":62,"estimatedTokens":845}}110{"id":"stack-24945112","source":"stackoverflow","questionId":24945112,"title":"Can I specify RabbitMQ credentials in node.js?","tags":["node.js","rabbitmq"],"text":"Title: Can I specify RabbitMQ credentials in node.js?\nTags: node.js, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI started to use rabbit.js to connect to RabbitMQ from a node.js application.\n\nI'm blocked at:\n\n Error: Channel closed by server: 403 (ACCESS-REFUSED) with message \"ACCESS_REFUSED -operation not permitted on the default exchange\"\n\n at Channel.C.accept (/.../rabbit.js/node_modules/amqplib/lib/channel.js:398:24)\n\n at Connection.mainAccept [as accept] (/.../rabbit.js/node_modules/amqplib/lib/connection.js:63:33)\n\n at Socket.go (/.../rabbit.js/node_modules/amqplib/lib/connection.js:448:48)\n\n at Socket.EventEmitter.emit (events.js:92:17)\n\n ...\n\nwhich is expected, since the instance of RabbitMQ I use is configured to require the publishers and subscribers to provide credentials before being able to use the message queue, and guest account is disabled.\n\nThe official documentation of rabbit.js has no mention of credentials. Google searches for “rabbit.js specify credentials” and “rabbit.js login password” were inconclusive.\n\nAre credentials supported by rabbit.js? If not, what other RabbitMQ clients for node.js support them?\n\n========================================\n\nTop Answer:\n```\nconst amqp = require('amqplib/callback_api');\n\nconst opt = { credentials: require('amqplib').credentials.plain('user', 'password') };\namqp.connect('amqp://localhost', opt, (err, conn) => {});\n\n//\n```\n\n========================================\n\nCode:\n```text\namqp://user:pass@host.com/vhost\n```\n\n```text\namqp://user:pass@sub.example.com:8080\n```\n\n```text\nvar amqp = require('amqplib/callback_api');\n\namqp.connect('amqp://example.username:example.password@localhost', (err, conn) => {});\n```\n\n```text\nconst amqp = require('amqplib/callback_api');\n\nconst opt = { credentials: require('amqplib').credentials.plain('user', 'password') };\namqp.connect('amqp://localhost', opt, (err, conn) => {});\n\n//\n```\n\n```text\nconst opt = { credentials: require('amqplib').credentials.plain('user', 'password') };\n```\n\n```text\n{\n protocol: 'amqp',\n hostname: 'localhost',\n port: 5672,\n username: 'guest',\n password: 'guest',\n locale: 'en_US',\n frameMax: 0,\n heartbeat: 0,\n vhost: '/',\n}\n```\n\n```text\nexport function connect(url: string | Options.Connect, socketOptions?: any): Promise<Connection>;\n```\n\n```text\nconst connect = {\n hostname: 'example.com',\n port: 8080,\n username: 'user',\n password: 'pass'\n};\n```\n\n```text\nconst hostname = 'example.com';\nconst port = 8080;\nconst username = 'user';\nconst password = 'pass';\n\n// Option 1\nconst url = `amqp://${username}:${password}@${hostname}:${port}`;\nawait amqplib.connect(url);\n\n// Option 2\nconst connect = {\n hostname: hostname,\n port: port,\n username: username,\n password: password\n};\nawait amqplib.connect(connect);\n```\n\n```text\namqp://user:pass@example.com:8080\n```\n\n```text\nOptions.Connect\n```\n\n```text\nprotocol\n```\n\n```text\nlocale\n```\n\n```text\nframeMax\n```\n\n```text\nheartbeat\n```\n\n```text\nvhost\n```\n\n========================================\n\nComments:\n- Normally, fields in a connection string must be URL encoded (`%20` etc.) but it looks like the module can't handle this properly. At least a `:` in the password leads to an error even when encoded properly. Avoid special http chars like `/`, `.`, `:`, `?` in the password field!\n- I was just digging into the code and this was indeed a bug that has been fixed later in 2017 :-)","metadata":{"transformedAt":"2026-08-18T18:33:20.125Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":16,"totalLines":149,"estimatedTokens":853}}111{"id":"stack-24107913","source":"stackoverflow","questionId":24107913,"title":"How to requeue messages in RabbitMQ","tags":["rabbitmq","amqp","node-amqp"],"text":"Title: How to requeue messages in RabbitMQ\nTags: rabbitmq, amqp, node-amqp\nSource: Stack Overflow\n\nQuestion:\nAfter the consumer gets a message, consumer/worker does some validations and then call web service. In this phase, if any error occurs or validation fails, we want the message put back to the queue it was originally consumed from.\n\nI have read RabbitMQ documentation. But I am confused about differences between reject, nack and cancel methods.\n\n========================================\n\nCode:\n```text\nQueue(main) (tail) { [4] [3] [2] [1] [0] } (head)\n```\n\n```text\nQueue(main) (tail) { [4] [3] [2*] [1*] [0*] } (head)\n```\n\n```text\nExchange(e-main) Exchange(e-dead) \n Queue(main){x-dead-letter-exchange: \"e-dead\"} Queue(dead)\n```\n\n```text\nQueue(main) (tail) { [4] [3] [2] [1] [0] } (head)\nQueue(dead) (tail) { }(head)\n```\n\n```text\nQueue(main) (tail) { [2!] [1!] [0!] } (head)\nQueue(dead) (tail) { [4*] [3*] } (head)\n```\n\n```text\nQueue(main) (tail) { } (head)\nQueue(dead) (tail) { [2*] [1*] [0*] [4*] [3*] } (head)\n```\n\n```text\nbasic.reject\n```\n\n```text\nbasic.nack\n```\n\n```text\nmultiple\n```\n\n```text\nbasic.consume\n```\n\n```text\nbasic.recover\n```\n\n```text\nbasic.reject\n```\n\n```text\nbasic.nack\n```\n\n```text\nbasic.nack\n```\n\n```text\nbasic.reject\n```\n\n```text\nbasic.reject\n```\n\n```text\nbasic.reject\n```\n\n```text\nbasic.nack\n```\n\n```text\nbasic.reject\n```\n\n```text\nmultiple\n```\n\n```text\nbasic.nack\n```\n\n```text\ntrue\n```\n\n```text\ndelivery_tag\n```\n\n```text\nbasic.nack\n```\n\n```text\nbasic.nack\n```\n\n```text\nbasic.ack\n```\n\n```text\nbasic.nack\n```\n\n```text\nbasic.reject\n```\n\n```text\nbasic.cancel\n```\n\n```text\nbasic.cancel\n```\n\n```text\ncancel-ok\n```\n\n```text\nbasic.recover\n```\n\n```text\nbasic.recover\n```\n\n```text\nbasic.consume\n```\n\n```text\nbasic.consume\n```\n\n```text\nnoack=false\n```\n\n```text\n*\n```\n\n```text\nredelivered\n```\n\n```text\ntrue\n```\n\n```text\nexpire\n```\n\n```text\n5000\n```\n\n```text\nmain\n```\n\n```text\n!\n```\n\n```text\nbasic.get\n```\n\n========================================\n\nComments:\n- If basic.nack is exactly like basic.reject but supports bulk messages processing, when is basic.reject preferred over basic.nack? Why don't one just use basic.nack in all situations then?\n- `basic.nack` is RabbitMQ-specific extension.\n- by \"RabbitMQ-specific extension\" you mean outside of the extension is not used? Meaning if I used Spring AMQP to integrate with RabbitMQ then I can't use basic.nack?\n- I mean that `basic.nack` is not part of AMQP standard and is RabbitMQ specific extension (I added note about this to answer to make it visible for further readers). If you use RabbitMQ as AMQP broker, `basic.nack` can be used instead of `basic.reject`.\n- `basic.consume calling may also results to messages redelivering if you are using message acknowledge and there are un-acknowledged message on consumer at specific time.` Is this statement correct?? AFAIK, if ACK is not received, the message will wait until it reaches TTL.\n- @NeoWang yeah, I probably mean that if `basic.consume` started with without auto-ack (`no­ack=false`) and there are some pending messages non-acked messages then when consumer get canceled (dies, fatal error, exception, whatever) that pending messages will be redelivered. Technically, that pending messages will not be processed (even dead-lettered) until consumer release them (ack/nack/reject/recover). Only after that they will be processed (e.g. dedlettered). But thanks for pointing on this ambiguity in original answer, I will add this explanation and example.\n- Even though `basic.reject` is supposed to be standardised, I have observed other implementations handling it differently to RabbitMQ.","metadata":{"transformedAt":"2026-08-18T18:33:20.126Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":44,"totalLines":202,"estimatedTokens":917}}112{"id":"stack-43609345","source":"stackoverflow","questionId":43609345,"title":"Setup RabbitMQ consumer in ASP.NET Core application","tags":["c#","asp.net-core","rabbitmq",".net-core"],"text":"Title: Setup RabbitMQ consumer in ASP.NET Core application\nTags: c#, asp.net-core, rabbitmq, .net-core\nSource: Stack Overflow\n\nQuestion:\nI have an ASP.NET Core application where I would like to consume RabbitMQ messages.\n\nI have successfully set up the publishers and consumers in command line applications, but I'm not sure how to set it up properly in a web application.\n\nI was thinking of initializing it in `Startup.cs`, but of course it dies once startup is complete.\n\nHow to initialize the consumer in a the right way from a web app?\n\n========================================\n\nTop Answer:\nThis is My Listener:\n\n```\npublic class RabbitListener\n{\n ConnectionFactory factory { get; set; }\n IConnection connection { get; set; }\n IModel channel { get; set; }\n\n public void Register()\n {\n channel.QueueDeclare(queue: \"hello\", durable: false, exclusive: false, autoDelete: false, arguments: null);\n\n var consumer = new EventingBasicConsumer(channel);\n consumer.Received += (model, ea) =>\n {\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n int m = 0;\n };\n channel.BasicConsume(queue: \"hello\", autoAck: true, consumer: consumer);\n }\n\n public void Deregister()\n {\n this.connection.Close();\n }\n\n public RabbitListener()\n {\n this.factory = new ConnectionFactory() { HostName = \"localhost\" };\n this.connection = factory.CreateConnection();\n this.channel = connection.CreateModel();\n\n }\n}\n```\n\n========================================\n\nCode:\n```text\nStartup.cs\n```\n\n```text\npublic class Startup\n{\n public void ConfigureServices(IServiceCollection services)\n {\n services.AddSingleton<RabbitListener>();\n }\n\n\n public void Configure(IApplicationBuilder app)\n {\n app.UseRabbitListener();\n }\n}\n\npublic static class ApplicationBuilderExtentions\n{\n //the simplest way to store a single long-living object, just for example.\n private static RabbitListener _listener { get; set; }\n\n public static IApplicationBuilder UseRabbitListener(this IApplicationBuilder app)\n {\n _listener = app.ApplicationServices.GetService<RabbitListener>();\n\n var lifetime = app.ApplicationServices.GetService<IApplicationLifetime>();\n\n lifetime.ApplicationStarted.Register(OnStarted);\n\n //press Ctrl+C to reproduce if your app runs in Kestrel as a console app\n lifetime.ApplicationStopping.Register(OnStopping);\n\n return app;\n }\n\n private static void OnStarted()\n {\n _listener.Register();\n }\n\n private static void OnStopping()\n {\n _listener.Deregister(); \n }\n}\n```\n\n```text\nIApplicationLifetime\n```\n\n```text\npublic class RabbitListener\n{\n ConnectionFactory factory { get; set; }\n IConnection connection { get; set; }\n IModel channel { get; set; }\n\n public void Register()\n {\n channel.QueueDeclare(queue: \"hello\", durable: false, exclusive: false, autoDelete: false, arguments: null);\n\n var consumer = new EventingBasicConsumer(channel);\n consumer.Received += (model, ea) =>\n {\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n int m = 0;\n };\n channel.BasicConsume(queue: \"hello\", autoAck: true, consumer: consumer);\n }\n\n public void Deregister()\n {\n this.connection.Close();\n }\n\n public RabbitListener()\n {\n this.factory = new ConnectionFactory() { HostName = \"localhost\" };\n this.connection = factory.CreateConnection();\n this.channel = connection.CreateModel();\n\n\n }\n}\n```\n\n```text\npublic interface IConsumerService\n{\n Task ReadMessgaes();\n}\n\npublic class ConsumerService : IConsumerService, IDisposable\n{\n private readonly IModel _model;\n private readonly IConnection _connection;\n public ConsumerService(IRabbitMqService rabbitMqService)\n {\n _connection = rabbitMqService.CreateChannel();\n _model = _connection.CreateModel();\n _model.QueueDeclare(_queueName, durable: true, exclusive: false, autoDelete: false);\n _model.ExchangeDeclare(\"your.exchange.name\", ExchangeType.Fanout, durable: true, autoDelete: false);\n _model.QueueBind(_queueName, \"your.exchange.name\", string.Empty);\n }\n const string _queueName = \"your.queue.name\";\n public async Task ReadMessgaes()\n {\n var consumer = new AsyncEventingBasicConsumer(_model);\n consumer.Received += async (ch, ea) =>\n {\n var body = ea.Body.ToArray();\n var text = System.Text.Encoding.UTF8.GetString(body);\n Console.WriteLine(text);\n await Task.CompletedTask;\n _model.BasicAck(ea.DeliveryTag, false);\n };\n _model.BasicConsume(_queueName, false, consumer);\n await Task.CompletedTask;\n }\n\n public void Dispose()\n {\n if (_model.IsOpen)\n _model.Close();\n if (_connection.IsOpen)\n _connection.Close();\n }\n}\n```\n\n```text\npublic interface IRabbitMqService\n{\n IConnection CreateChannel();\n}\n\npublic class RabbitMqService : IRabbitMqService\n{\n private readonly RabbitMqConfiguration _configuration;\n public RabbitMqService(IOptions<RabbitMqConfiguration> options)\n {\n _configuration = options.Value;\n }\n public IConnection CreateChannel()\n {\n ConnectionFactory connection = new ConnectionFactory()\n {\n UserName = _configuration.Username,\n Password = _configuration.Password,\n HostName = _configuration.HostName\n };\n connection.DispatchConsumersAsync = true;\n var channel = connection.CreateConnection();\n return channel;\n }\n}\n```\n\n```text\npublic class ConsumerHostedService : BackgroundService\n{\n private readonly IConsumerService _consumerService;\n\n public ConsumerHostedService(IConsumerService consumerService)\n {\n _consumerService = consumerService;\n }\n\n protected override async Task ExecuteAsync(CancellationToken stoppingToken)\n {\n await _consumerService.ReadMessgaes();\n }\n}\n```\n\n```cs\nservices.AddSingleton<IRabbitMqService, RabbitMqService>();\nservices.AddSingleton<IConsumerService, ConsumerService>();\nservices.AddHostedService<ConsumerHostedService>();\n```\n\n```text\n{\n \"RabbitMqConfiguration\": {\n \"HostName\": \"localhost\",\n \"Username\": \"guest\",\n \"Password\": \"guest\"\n }\n}\n```\n\n```text\npublic class RabbitMqConfiguration\n{\n public string HostName { get; set; }\n public string Username { get; set; }\n public string Password { get; set; }\n}\n```\n\n```text\nRabbitMq\n```\n\n```text\npublic class TempConsumer : BackgroundService\n{\n private readonly ConnectionFactory _factory;\n private IConnection _connection;\n private IModel _channel;\n\n public TempConsumer()\n {\n _factory = new ConnectionFactory()\n {\n HostName = \"localhost\",\n UserName = \"guest\",\n Password = \"password\",\n VirtualHost = \"/\",\n };\n _connection = _factory.CreateConnection() ;\n _channel = _connection.CreateModel();\n _channel.QueueDeclare(queue: \"queue\",\n durable: false,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n }\n \n protected override Task ExecuteAsync(CancellationToken stoppingToken)\n {\n stoppingToken.ThrowIfCancellationRequested();\n \n var consumer = new EventingBasicConsumer(_channel);\n\n consumer.Shutdown += OnConsumerShutdown;\n consumer.Registered += OnConsumerRegistered;\n consumer.Unregistered += OnConsumerUnregistered;\n consumer.ConsumerCancelled += OnConsumerConsumerCancelled;\n\n\n consumer.Received += (model, ea) =>\n {\n Console.WriteLine(\"Recieved\");\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body.ToArray());\n _channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);\n Console.WriteLine(message);\n };\n\n\n _channel.BasicConsume(queue: \"queue\",\n autoAck: false,\n consumer: consumer);\n\n return Task.CompletedTask;\n }\n\n private void OnConsumerConsumerCancelled(object sender, ConsumerEventArgs e) { }\n private void OnConsumerUnregistered(object sender, ConsumerEventArgs e) { }\n private void OnConsumerRegistered(object sender, ConsumerEventArgs e) { }\n private void OnConsumerShutdown(object sender, ShutdownEventArgs e) { }\n private void RabbitMQ_ConnectionShutdown(object sender, ShutdownEventArgs e) { }\n```\n\n```text\nBackgroundService\n```\n\n```text\nservices.AddHostedService<EmailConsumer>();\n```\n\n```text\nusing RabbitMQ.Client;\n\npublic interface IRabbitMqService\n{\n Task<IConnection> CreateConnectionAsync();\n}\n\npublic class RabbitMqService : IRabbitMqService\n{\n private readonly RabbitMqConfiguration _configuration;\n public RabbitMqService(IOptions<RabbitMqConfiguration> options)\n {\n _configuration = options.Value;\n }\n\n public async Task<IConnection> CreateConnectionAsync()\n {\n var connectionFactory = new ConnectionFactory()\n {\n UserName = _configuration.Username,\n Password = _configuration.Password,\n HostName = _configuration.HostName, // in my case just IP address, w/o http/s, slashaes, port \n Port = _rmqPort, // if exists, has to be defined separately\n VirtualHost = \"/\", // has to be defined, at least in my case\n };\n connectionFactory.ConsumerDispatchConcurrency = 1;\n var connection = await connectionFactory.CreateConnectionAsync();\n return connection;\n }\n}\n```\n\n```text\nusing RabbitMQ.Client;\nusing RabbitMQ.Client.Events;\n\npublic interface IConsumerService\n{\n Task ReadMessgaes();\n}\n\npublic class ConsumerService : IConsumerService, IDisposable\n{\n private readonly IConnection _connection;\n private readonly IChannel _channel;\n private readonly string _queueName = \"your.queue.name\";\n\n public ConsumerService(IRabbitMqService rabbitMqService)\n {\n _connection = rabbitMqService.CreateConnectionAsync().Result;\n _channel = _connection.CreateChannelAsync().Result;\n }\n\n public async Task ReadMessgaes()\n {\n var consumer = new AsyncEventingBasicConsumer(_channel);\n consumer.ReceivedAsync += async (ch, ea) =>\n {\n // that might not be text, so watch what you take from ea.Body\n var message = System.Text.Encoding.Default.GetString(ea.Body.ToArray());\n\n // ...do whatever you need with payload\n\n await _channel.BasicAckAsync(ea.DeliveryTag, false); // or BasicNackAsync if you cannot process message now and want to try one more time\n };\n // this consumer tag identifies the subscription\n // when it has to be cancelled\n string consumerTag = await _channel.BasicConsumeAsync(_queueName, false, consumer);\n }\n\n public void Dispose()\n {\n _channel.CloseAsync().Wait();\n _connection.CloseAsync().Wait();\n _channel.DisposeAsync();\n _connection.DisposeAsync();\n }\n}\n```\n\n========================================\n\nComments:\n- Are you sure ASP.NET is the right place to host the RabbitMQ consumer ? Can you have command line app consuming RabbitMQ messages, and upon receiving them post to ASP.NET ?\n- I'm not sure, but it would be the most convenient because we don't currently have a regime to deploy and run other types of apps. I suppose a Windows Service would do the trick, but if there is a safe and sound way to do it from our web app that would be great\n- It could also be worth mentioning that the web app in question already does related background jobs with Hangfire, so it feels like a logical place to place it\n- Hangfire!!! Check out Integrate HangFire With ASP.NET Core. I think that can be a good starting point since you have both - HangFire & ASP.NET Core.\n- Hangfire is not about long lived objects. Huge overhead.\n- I see many problems with using a request/response host (a web server) for hosting a long-lived eventing consumer. Keeping a stable number of consumers across recycles, IIS shutting down the process etc adds extra complexity and web servers are simply not designed for this use case. I see that hangfire also supports hosting in Windows Services, so that way you might be able to get the benefit of hangfire and an appropriate host.\n- what is RabbitListener here ?\n- @Prageeth it is just the code to take messages from the queue. Your own implementation would depend on the system requirements and the queue definition. You can find a lot of examples in the web, and one of those is github.com/plwestaxiom/RabbitMQ/blob/master/RabbitMQ_Tutoria‌​ls/…\n- consumer.Received += (model, ea) => this called only once when application startup and not listening.I dont know if I miss anything Llya.\n- I miss this line Console.ReadLine(); if I put this it works charm.\n- When use `Console.ReadLine()` you don't have any problem but when removing `Conosle.ReadLine()` just one time execute consumer, but i use IHostService but these make me run tow console app at a same time, one for **ASP.NET Core MVC 2** project and one for **RabbitMQ Client**\n- @IlyaChumakov Can you provide the whole example using the RabbitListener ?\n- @JustDontKnow the general pattern is close to the Paldi's example stackoverflow.com/a/52494986/5112433. You operate the same set of RabbitMQ API's and add a real-world stuff to it (serialization, error handling) if needed.\n- it's work only if go to web page. If i leave 1-2 minuts and rabit channel off. How i can fix it?\n- or if start iis and don't open page, rabbit not start\n- Alternatively you can still use DI but inject the whole MQClient and then use it; while manage the connectivity out of the consumers but actually inside the Rabbit MQClient class - so this approach is fairly straight forward. See the example implementation: programmer.ink/think/…\n- The code is not working. it is showing DI error.\n- @sina_Islam your error message\n- nore even the consumer consume the message.\n- @sina_Islam I don't know how you implement `rabbitmq` . For more information you can check this link\n- thanks brother, it is working. Actually, I am implementing it at nopCommerce as a plugin to consume order place event and missed some configuration that is why it was not working properly. Your code is perfect and working as expected.\n- awesome! for anyone following this code example, don't forget to link the configuration to the configuration class in **Program.cs**: `builder.Services.Configure(builder.Co‌​nfiguration.GetSecti‌​on(\"RabbitMqConfigur‌​ation\"));`","metadata":{"transformedAt":"2026-08-18T18:33:20.126Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":16,"totalLines":441,"estimatedTokens":3706}}113{"id":"stack-12323621","source":"stackoverflow","questionId":12323621,"title":"Windows x64 RabbitMQ install error with Erlang environment var (ERLANG_HOME)","tags":["erlang","rabbitmq","config"],"text":"Title: Windows x64 RabbitMQ install error with Erlang environment var (ERLANG_HOME)\nTags: erlang, rabbitmq, config\nSource: Stack Overflow\n\nQuestion:\nI'm ask/answering this question because it hung me up & it's likely someone else will have the same problem.\n\nInstall of RabbitMQ x64 v2.8.6 on Windows Server 2008 x64. \n\nAfter Erlang install using default install location to C:\\Program Files\\erl5.9.2, I'm attempting to start the server via running the rabbitmq-service.bat. Fail:\n\n```\nPlease either set ERLANG_HOME to point to your Erlang installation \nor place the RabbitMQ server distribution in the Erlang lib folder.\n```\n\nProblem is the .bat file does not have the correct subpath. with 5.9.2 (R15B02) version of erlang. My ERLANG_HOME directory is set correctly, but the script does not use it correctly for this version of Erlang, which, it appears to this Erlang noob to have a new subdirectory called \"erts-5.9.2\" which is causing the problems. Maybe someone intimate with these scripts can describe how to make this work correctly without the hack workaround I'm about to describe?\n\n========================================\n\nTop Answer:\n1- Set environment variable: \n\nVariable name : `ERLANG_HOME`\n\nVariable value: `C:\\Program Files (x86)\\erl6.4`\n\nnote: don't include bin on above step.\n\n2- Add `%ERLANG_HOME%\\bin` to the `PATH` environmental variable:\n\nVariable name : `PATH`\n\nVariable value: `%ERLANG_HOME%\\bin`\n\nThis works well.\n\n========================================\n\nCode:\n```text\nPlease either set ERLANG_HOME to point to your Erlang installation \nor place the RabbitMQ server distribution in the Erlang lib folder.\n```\n\n```text\nif not exist \"!ERLANG_HOME!\\bin\\erl.exe\" (\n```\n\n```text\n\"!ERLANG_HOME!\\bin\\erl.exe\"\n```\n\n```text\n\"C:\\Program Files\\erl5.9.2\\erts-5.9.2\\bin\\erl.exe\"\n```\n\n```text\n%ERLANG_HOME%\\bin\n```\n\n```text\nERLANG_HOME\n```\n\n```text\nC:\\Program Files (x86)\\erl6.4\n```\n\n```text\n%ERLANG_HOME%\\bin\n```\n\n```text\nPATH\n```\n\n```text\nPATH\n```\n\n```text\n%ERLANG_HOME%\\bin\n```\n\n```text\n\"ERLANG_HOME\" : \"C:\\Program Files\\erl8.0\"\n```\n\n```text\n\"Path\" : \";%ERLANG_HOME%\\bin;\"\n```\n\n```text\n\"Program Files\"\n```\n\n```text\n!ERLANG_HOME!\\bin\\erl.exe\n```\n\n```text\nC:\\Program Files\\erl10.3\\erts-10.3\\bin\\erl.exe\n```\n\n```text\n%RABBITMQ_HOME%\\escript\\rabbitmq-plugins\n```\n\n```text\nC:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.7.14\\escript\\rabbitmq-plugins\n```\n\n```text\nrabbitmq-plugins enable rabbitmq_management\n```\n\n```text\nERLANG_HOME\n```\n\n```text\nC:\\Program Files\\erl-23.1\n```\n\n```text\n%ERLANG_HOME%\\bin\n```\n\n========================================\n\nComments:\n- restart will solve the problem, i was facing same issue, but it is resolved once i restart my machine\n- Before editing the .bat files, I suggest verifying the ERLANG_HOME variable in the Environment Variables. Somehow the erlang installer set it with a typo. Use the Windows Explorer to copy the path and paste it so that it fits nicely when inserted into this expression \"!ERLANG_HOME!\\bin\\erl.exe\" (avoid \\\\ for example)\n- Your ERLANG_HOME was probably C:\\Program Files\\erl5.9.2, and just changing to C:\\Program Files\\erl5.9.2\\erts-5.9.2, should have fixed the problem. Main point being RabbitMQ and likely anything else using erlang is expecting the home folder to be the parent of \"bin\" so making sure the variable points to that folder should make for happy apps.\n- restarting the server after erlang/rabbit mq installation worked for me. thanks!\n- Any idea why a reboot is required? Environment variables can be set without a reboot normally.\n- Response to my own question: the global environment variable seems to get loaded when a new 'session' (cmd or PS window) gets opened. On the other hand, if the script sets the variable and tries to use it, it doesn't seem to work quite right. I found also that I had to set the variable, start a new session, then install RabbitMQ for it to use the new context. Otherwise, RabbitMQ would install in the user context rather than the new variable context. Else, I had to use the \"(re)install\" option to reset it to the new context.\n- I would guess this is likely standard environment variable behavior; you'd just need to open a new shell so that it gets the new environment variable, not completely restart your system.\n- Images of code are bad practice. Please read Why should I not upload images of code/data/errors when asking a question?. While that article is about question, it applies all the same for answers.","metadata":{"transformedAt":"2026-08-18T18:33:20.126Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":22,"totalLines":140,"estimatedTokens":1112}}114{"id":"stack-9673172","source":"stackoverflow","questionId":9673172,"title":"RabbitMQ, Erlang: How to \"make sure the erlang cookies are the same\"","tags":["cookies","erlang","rabbitmq"],"text":"Title: RabbitMQ, Erlang: How to \"make sure the erlang cookies are the same\"\nTags: cookies, erlang, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am using RabbitMQ with Grails, and a problem cropped up this morning. When I run `rabbitmqctl` status it tells me:\n\n```\nC:\\Users\\BuildnTest2>rabbitmqctl status\nStatus of node 'rabbit@BUILDNTEST2-PC' ...\nError: unable to connect to node 'rabbit@BUILDNTEST2-PC': nodedown diagnostics:\n- nodes and their ports on BUILDNTEST2-PC: [{rabbit,49164},\n {rabbitmqctl27693,49286}]\n- current node: 'rabbitmqctl27693@BuildnTest2-PC'\n- current node home dir: C:\\Users\\BuildnTest2\n- current node cookie hash: cSYB8tsT4mGGZHSUGQi08w==\n```\n\nWhen I go to the Rabbit troubleshooting page they say:\n\n```\nthen you should make sure the Erlang cookies are the same.\n```\n\nWhat does this mean and how is it accomplished?\n\nGoogling found this forum thread which claims to have instructions to solving this problem, but alas it just redirects back to the rabbit site where there is no answer.\n\n========================================\n\nTop Answer:\nFor what it's worth, in 2018, the docs are WRONG. In windows 10, the default location of the cookie file appears to be: \n\n```\nC:\\Windows\\System32\\config\\systemprofile\n```\n\nand NOT\n\n```\nC:\\Windows\n```\n\nas the docs say. \n\nThe best thing to do is to look at the log file, which is typically located in your user `%AppData%\\Roaming\\RabbitMQ\\log` directory.\n\nThe log file contains this entry, which helped me determine the cookie location:\n\n```\nnode : rabbit@computername\nhome dir : C:\\WINDOWS\\system32\\config\\systemprofile\n```\n\n========================================\n\nCode:\n```text\nC:\\Users\\BuildnTest2>rabbitmqctl status\nStatus of node 'rabbit@BUILDNTEST2-PC' ...\nError: unable to connect to node 'rabbit@BUILDNTEST2-PC': nodedown diagnostics:\n- nodes and their ports on BUILDNTEST2-PC: [{rabbit,49164},\n {rabbitmqctl27693,49286}]\n- current node: 'rabbitmqctl27693@BuildnTest2-PC'\n- current node home dir: C:\\Users\\BuildnTest2\n- current node cookie hash: cSYB8tsT4mGGZHSUGQi08w==\n```\n\n```text\nthen you should make sure the Erlang cookies are the same.\n```\n\n```text\nrabbitmqctl\n```\n\n```text\n.erlang.cookie\n```\n\n```text\nC:\\Windows\\\n```\n\n```text\n%HOMEDRIVE%\n```\n\n```text\n%HOMEPATH%\n```\n\n```text\nC:\\\n```\n\n```text\nC:\\Windows\n```\n\n```text\nNODENAME=rabbit\nNODE_IP_ADDRESS=0.0.0.0\nNODE_PORT=5672\n\nLOG_BASE=/var/log/rabbitmq\nMNESIA_BASE=/var/lib/rabbitmq/mnesia\n```\n\n```text\nNODENAME=rabbit\nNODE_IP_ADDRESS=127.0.0.1\nNODE_PORT=5672\n\nHOME=/var/lib/rabbitmq\nLOG_BASE=/var/log/rabbitmq\nMNESIA_BASE=/var/lib/rabbitmq/mnesia\n```\n\n```text\nHOME\n```\n\n```text\nsystemctl start rabbitmq\n```\n\n```text\nrabbitmqctl status\n```\n\n```text\nC:\\Windows\n```\n\n```text\nC:\\Users\\Current User\\.erlang.cookie\n```\n\n```text\nC:\\Windows\\System32\\config\\systemprofile\n```\n\n```text\nC:\\Windows\n```\n\n```text\nnode : rabbit@computername\nhome dir : C:\\WINDOWS\\system32\\config\\systemprofile\n```\n\n```text\n%AppData%\\Roaming\\RabbitMQ\\log\n```\n\n```text\npkill beam\npkill epmd\necho 'CUSTOMCOOKIE' > /var/lib/rabbitmq/.erlang.cookie\npkill beam\npkill epmd\n```\n\n```text\nrabbitmqctl start_app\n```\n\n```text\nerlang.cookie\n```\n\n========================================\n\nComments:\n- check the node `home dir` and for each node, modify a file called `.erlang.cookie` and have the file contain the same value e.g. `echo mycookie > $NODE_HOME_DIR/.erlang.cookie` for each node.\n- If people are not running a cluster, they might be interested to read this very similar issue.\n- I try that and still get auth failed...but only on my rackspace vms\n- ah so the service can be running without rabbit running?\n- Indeed. The service is a host to the RabbitMQ server which can be started and stopped. Much like IIS and the hosted web sites within.\n- The solution is described in official documentation: rabbitmq.com/install-windows-manual.html\n- This is the correct answer. Thank you very much, you saved me from pain.\n- Yes this works on Windows 10 where I had the same issue.\n- Is this definitely a Windows 10 issue and not a result of upgrading to Erlang 20.2? From rabbitmq.com/clustering.html : For the RabbitMQ Windows service - %USERPROFILE%\\\\.erlang.cookie (usually C:\\\\WINDOWS\\\\system32\\\\config\\\\systemprofile)\n- Also applies to 2008R2, where I installed both erlang (20.3) and rabbitmq (3.7.3) through chocolatey.\n- Can confirm that this is the proper location for the cookie in Windows Server 2016 aswell.\n- `rabbitmqctl status` was returning Authentication failed (rejected by the remote node) `effective user's home directory: C:\\Users\\Administrator` I copied over the .erlang to `C:\\WINDOWS\\system32\\config\\systemprofile` and it worked.\n- Their docs are kinda ambiguous across versions! On Windows 10, I now no longer find .erlang.cookie. Looked up both `C:\\WINDOWS\\system32\\config\\systemprofile` and `c:\\windows` with no luck.\n- Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.","metadata":{"transformedAt":"2026-08-18T18:33:20.126Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":23,"totalLines":189,"estimatedTokens":1293}}115{"id":"stack-58266688","source":"stackoverflow","questionId":58266688,"title":"How to create a queue in RabbitMQ upon startup","tags":["docker","rabbitmq"],"text":"Title: How to create a queue in RabbitMQ upon startup\nTags: docker, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am trying to start RMQ inside docker container, with precreated queue `qwer`.\n\nPrior to this, I was using simple `docker-compose.yml` file:\n\n```\nrabbit:\n image: rabbitmq:management-alpine\n environment:\n RABBITMQ_DEFAULT_USER: guest\n RABBITMQ_DEFAULT_PASS: guest\n```\n\nAnd it worked fine, except that it has no queues pre-created at start.\nNow I've switched to custom image, with following `Dockerfile`:\n\n```\nFROM rabbitmq:management-alpine\n\nADD rabbitmq.conf /etc/rabbitmq/\nADD definitions.json /etc/rabbitmq/\n\nRUN chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq.conf /etc/rabbitmq/definitions.json\n```\n\nwhere `rabbitmq.conf` is v3.7+ sysctl-styled config, with line:\n\n```\nmanagement.load_definitions = /etc/rabbitmq/definitions.json\n```\n\nand `definitions.json` contains attempt to create queue:\n\n```\n{\n \"vhosts\":[\n {\"name\":\"/\"}\n ],\n \"queues\":[\n {\"name\":\"qwer\",\"vhost\":\"/\",\"durable\":true,\"auto_delete\":false,\"arguments\":{}}\n ]\n}\n```\n\nNow it started to refuse login:\n\n```\nError on AMQP connection (172.18.0.6:48916 -> 172.18.0.10:5672, state: starting):\nPLAIN login refused: user 'guest' - invalid credentials\n```\n\nI thought that the task is somewhat simple, but configuration process of rabbit itself is most complex task, and documentation is somewhat unclear.\n\nI was unable to figure out how should it work, even after 4 days of trials and googling..\n\nCould you help me, how to write configuration file, in order to create a queue and preserve ability to connect and talk to it?\n\n========================================\n\nTop Answer:\nYou can predefine queues and exchanges without creating own rabbit-mq docker image.\n\nYour docker-compose should look like this:\n\n```\nrabbit:\ncontainer_name: rabbitmq-preload-conf\nimage: rabbitmq:3-management\nvolumes:\n - ./init/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf:ro\n - ./init/definitions.json:/etc/rabbitmq/definitions.json:ro\nports:\n - \"5672:5672\"\n - \"15672:15672\"\n```\n\nIn this case rabbitmq.conf and definitions.json files should be in init folder in the same parent folder as docker-compose file\n\nrabbitmq.conf file\n\n```\nmanagement.load_definitions = /etc/rabbitmq/definitions.json\n```\n\ndefinitions.json file\n\n```\n{\n\"queues\": [\n {\n \"name\": \"externally_configured_queue\",\n \"vhost\": \"/\",\n \"durable\": true,\n \"auto_delete\": false,\n \"arguments\": {\n \"x-queue-type\": \"classic\"\n }\n }\n],\n\"exchanges\": [\n {\n \"name\": \"externally_configured_exchange\",\n \"vhost\": \"/\",\n \"type\": \"direct\",\n \"durable\": true,\n \"auto_delete\": false,\n \"internal\": false,\n \"arguments\": {}\n }\n],\n\"bindings\": [\n {\n \"source\": \"externally_configured_exchange\",\n \"vhost\": \"/\",\n \"destination\": \"externally_configured_queue\",\n \"destination_type\": \"queue\",\n \"routing_key\": \"externally_configured_queue\",\n \"arguments\": {}\n }\n ]\n }\n```\n\n**NOTE**: After update in rabbit images, additional configuration may be required. If rabbit container failed to start with the configuration mentioned above (error message contains \"Exception during startup:\nexit:{error,{no_such_vhost,>}}\") following configuration should be added into definitions file:\n\n```\n\"users\": [\n {\n \"name\": \"guest\",\n \"password_hash\": \"BMfxN8drrYcIqXZMr+pWTpDT0nMcOagMduLX0bjr4jwud/pN\",\n \"hashing_algorithm\": \"rabbit_password_hashing_sha256\",\n \"tags\": [\n \"administrator\"\n ],\n \"limits\": {}\n }\n ],\n \"vhosts\": [\n {\n \"name\": \"/\"\n }\n ],\n \"permissions\": [\n {\n \"user\": \"guest\",\n \"vhost\": \"/\",\n \"configure\": \".*\",\n \"write\": \".*\",\n \"read\": \".*\"\n }\n ]\n```\n\nUsing this additional configuration, default user will be guest with password guest.\n\nApart from queues, exchanges and bindings, definitions.json file can contain additional configuration\n\n========================================\n\nCode:\n```text\nrabbit:\n image: rabbitmq:management-alpine\n environment:\n RABBITMQ_DEFAULT_USER: guest\n RABBITMQ_DEFAULT_PASS: guest\n```\n\n```text\nFROM rabbitmq:management-alpine\n\nADD rabbitmq.conf /etc/rabbitmq/\nADD definitions.json /etc/rabbitmq/\n\nRUN chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq.conf /etc/rabbitmq/definitions.json\n```\n\n```text\nmanagement.load_definitions = /etc/rabbitmq/definitions.json\n```\n\n```text\n{\n \"vhosts\":[\n {\"name\":\"/\"}\n ],\n \"queues\":[\n {\"name\":\"qwer\",\"vhost\":\"/\",\"durable\":true,\"auto_delete\":false,\"arguments\":{}}\n ]\n}\n```\n\n```text\nError on AMQP connection <0.660.0> (172.18.0.6:48916 -> 172.18.0.10:5672, state: starting):\nPLAIN login refused: user 'guest' - invalid credentials\n```\n\n```text\nqwer\n```\n\n```text\ndocker-compose.yml\n```\n\n```text\nDockerfile\n```\n\n```text\nrabbitmq.conf\n```\n\n```text\ndefinitions.json\n```\n\n```text\nrabbit:\n image: rabbitmq:management-alpine\n environment:\n RABBITMQ_DEFAULT_USER: user\n RABBITMQ_DEFAULT_PASS: password\n```\n\n```text\n{\n \"users\": [\n {\n \"name\": \"user\", \n \"password_hash\": \"password\",\n \"hashing_algorithm\": \"rabbit_password_hashing_sha256\",\n \"tags\": \"administrator\"\n }\n ],\n\n \"vhosts\":[\n {\"name\":\"/\"}\n ],\n \"queues\":[\n {\"name\":\"qwer\",\"vhost\":\"/\",\"durable\":true,\"auto_delete\":false,\"arguments\":{}}\n ]\n}\n```\n\n```text\nFROM rabbitmq\n\n# Define environment variables.\nENV RABBITMQ_USER user\nENV RABBITMQ_PASSWORD password\n\nADD init.sh /init.sh\nEXPOSE 15672\n\n# Define default command\nCMD [\"/init.sh\"]\n```\n\n```text\n#!/bin/sh\n\n# Create Rabbitmq user\n( sleep 5 ; \\\nrabbitmqctl add_user $RABBITMQ_USER $RABBITMQ_PASSWORD 2>/dev/null ; \\\nrabbitmqctl set_user_tags $RABBITMQ_USER administrator ; \\\nrabbitmqctl set_permissions -p / $RABBITMQ_USER \".*\" \".*\" \".*\" ; \\\necho \"*** User '$RABBITMQ_USER' with password '$RABBITMQ_PASSWORD' completed. ***\" ; \\\necho \"*** Log in the WebUI at port 15672 (example: http:/localhost:15672) ***\") &\n\n# $@ is used to pass arguments to the rabbitmq-server command.\n# For example if you use it like this: docker run -d rabbitmq arg1 arg2,\n# it will be as you run in the container rabbitmq-server arg1 arg2\nrabbitmq-server $@\n```\n\n```text\ndocker run <rabbitmq-docker-img> -p 15672:15672\n```\n\n```text\nEXPOSE 15672\n```\n\n```text\ndocker run -p 8080:15672 rabbitmq:3.9-management\n```\n\n```text\n$ tree .\n.\n└── conf\n └── definitions.json\n```\n\n```text\nload_definitions = /etc/rabbitmq/definitions.json\n```\n\n```text\n$ tree .\n.\n└── conf\n ├── definitions.json\n └── rabbitmq.conf\n```\n\n```text\nFROM rabbitmq:3.9-management\nCOPY conf/rabbitmq.conf /etc/rabbitmq/\nCOPY conf/definitions.json /etc/rabbitmq/\n```\n\n```text\nversion: \"3.9\"\nservices:\n\n my-rabbitmq:\n build: .\n ports:\n - 8082:15672\n```\n\n```text\n$ tree .\n.\n├── Dockerfile\n├── conf\n│ ├── definitions.json\n│ └── rabbitmq.conf\n└── docker-compose.yml\n```\n\n```text\n$ docker-compose -f docker-compose.yml up --build\n```\n\n```text\ninit.sh\n```\n\n```text\ndefinitions.json\n```\n\n```text\nrabbitmq:3.9-management\n```\n\n```text\ndefinitions.json\n```\n\n```text\nconf\n```\n\n```text\nrabbitmq.conf\n```\n\n```text\nconf\n```\n\n```text\ndocker-compose.yml\n```\n\n```text\ndefinitions.json\n```\n\n```text\nrabbit:\ncontainer_name: rabbitmq-preload-conf\nimage: rabbitmq:3-management\nvolumes:\n - ./init/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf:ro\n - ./init/definitions.json:/etc/rabbitmq/definitions.json:ro\nports:\n - \"5672:5672\"\n - \"15672:15672\"\n```\n\n```text\nmanagement.load_definitions = /etc/rabbitmq/definitions.json\n```\n\n```text\n{\n\"queues\": [\n {\n \"name\": \"externally_configured_queue\",\n \"vhost\": \"/\",\n \"durable\": true,\n \"auto_delete\": false,\n \"arguments\": {\n \"x-queue-type\": \"classic\"\n }\n }\n],\n\"exchanges\": [\n {\n \"name\": \"externally_configured_exchange\",\n \"vhost\": \"/\",\n \"type\": \"direct\",\n \"durable\": true,\n \"auto_delete\": false,\n \"internal\": false,\n \"arguments\": {}\n }\n],\n\"bindings\": [\n {\n \"source\": \"externally_configured_exchange\",\n \"vhost\": \"/\",\n \"destination\": \"externally_configured_queue\",\n \"destination_type\": \"queue\",\n \"routing_key\": \"externally_configured_queue\",\n \"arguments\": {}\n }\n ]\n }\n```\n\n```text\n\"users\": [\n {\n \"name\": \"guest\",\n \"password_hash\": \"BMfxN8drrYcIqXZMr+pWTpDT0nMcOagMduLX0bjr4jwud/pN\",\n \"hashing_algorithm\": \"rabbit_password_hashing_sha256\",\n \"tags\": [\n \"administrator\"\n ],\n \"limits\": {}\n }\n ],\n \"vhosts\": [\n {\n \"name\": \"/\"\n }\n ],\n \"permissions\": [\n {\n \"user\": \"guest\",\n \"vhost\": \"/\",\n \"configure\": \".*\",\n \"write\": \".*\",\n \"read\": \".*\"\n }\n ]\n```\n\n========================================\n\nComments:\n- Hello, thanks for your input. It crashes on `[info] Importing users... CRASH REPORT Process with 0 neighbours exited with reason: {error,>}\">>} in application_master:init/4 line 138 [info] Application rabbit exited with reason: {error,>}\">>}`\n- I've renamed `user` `password` to `guest` `guest`, because all stack is configured to use that credentials\n- Connection is done with endpoint: `amqp://guest:guest@rabbit:5672/`\n- Changed `password_hash` to `password` , added `loopback_users = none`. Now another problem arised: `access to vhost '/' refused for user 'guest'`\n- can you please post your entire Dockerfile? You cannot use \"guest\" because guest is only allowed access on localhost.\n- Editted my answer, have a look at that link .You need to add \"user\" to vhost \"/\"\n- Your Dockerfile isn't actually leveraging your `rabbitmq.conf` or `definitions.json` files. You can see this in the logs when running the image, it uses the default: `Successfully set user tags for user 'guest' to [administrator]`. You need to add to your Dockerfile `COPY rabbitmq.conf /etc/rabbitmq` and `COPY definitions.json /etc/rabbitmq` Although you don't need to create a user in `definitions.json` and in your `init.sh`, so you can omit the json file.","metadata":{"transformedAt":"2026-08-18T18:33:20.126Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":37,"totalLines":469,"estimatedTokens":2462}}116{"id":"stack-31961261","source":"stackoverflow","questionId":31961261,"title":"RabbitMQ asynchronous support","tags":["c#","asynchronous","rabbitmq"],"text":"Title: RabbitMQ asynchronous support\nTags: c#, asynchronous, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nDoes the RabbitMQ .NET client have any sort of asynchronous support? I'd like to be able to connect and consume messages asynchronously, but haven't found a way to do either so far.\n\n*(For consuming messages I can use the EventingBasicConsumer, but that's not a complete solution.)*\n\nJust to give some context, this is an example of how I'm working with RabbitMQ at the moment (code taken from my blog):\n\n```\nvar factory = new ConnectionFactory() { HostName = \"localhost\" };\n\nusing (var connection = factory.CreateConnection())\n{\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(\"testqueue\", true, false, false, null);\n\n var consumer = new EventingBasicConsumer(channel);\n consumer.Received += Consumer_Received;\n channel.BasicConsume(\"testqueue\", true, consumer);\n\n Console.ReadLine();\n }\n}\n```\n\n========================================\n\nTop Answer:\nthere is no async/await support built in to the RabbitMQ .NET client at this point. There is an open ticket for this on the RabbitMQ .NET Client repository\n\n========================================\n\nCode:\n```text\nvar factory = new ConnectionFactory() { HostName = \"localhost\" };\n\nusing (var connection = factory.CreateConnection())\n{\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(\"testqueue\", true, false, false, null);\n\n var consumer = new EventingBasicConsumer(channel);\n consumer.Received += Consumer_Received;\n channel.BasicConsume(\"testqueue\", true, consumer);\n\n Console.ReadLine();\n }\n}\n```\n\n```text\nvar factory = new ConnectionFactory\n{\n HostName = \"localhost\",\n DispatchConsumersAsync = true\n};\n\nusing(var connection = cf.CreateConnection())\n{\n using(var channel = conn.CreateModel())\n {\n channel.QueueDeclare(\"testqueue\", true, false, false, null);\n\n var consumer = new AsyncEventingBasicConsumer(model);\n\n consumer.Received += async (o, a) =>\n {\n Console.WriteLine(\"Message Get\" + a.DeliveryTag);\n await Task.Yield();\n };\n }\n\n Console.ReadLine();\n}\n```\n\n```text\nAsyncEventingBasicConsumer\n```\n\n```text\nEventingBasicConsumer\n```\n\n```text\nTask\n```\n\n```text\nTask\n```\n\n```text\nasync\n```\n\n```text\nTPL\n```\n\n```text\nAsyncEventingBasicConsumer\n```\n\n```text\nTask\n```\n\n```text\nAsyncDefaultBasicConsumer\n```\n\n```text\nHandleBasicDeliver\n```\n\n```text\nTask\n```\n\n```text\nasync\n```\n\n```text\nAsyncEventingBasicConsumer\n```\n\n```text\nawait\n```\n\n```text\nActionBlock\n```\n\n```text\nActionBlock\n```\n\n```text\nEventingBasicConsumer\n```\n\n```text\nactionBlock.Post(something)\n```\n\n```text\nack\n```\n\n```text\nmodel.BasicQos(0, N, true);\n```\n\n```text\nMaxDegreeOfParallelism\n```\n\n```text\nasync Task\n```\n\n```text\nCancellationToken\n```\n\n```text\nactionBlock.Complete(); await actionBlock.Completion;\n```\n\n========================================\n\nComments:\n- can you be a little more specific? what do you mean by \"asynchronous\" in this case? what are you trying to accomplish?\n- async/await... so I'm looking for equivalents that are awaitable and return a task, like System.IO has e.g. ConnectAsync(), ReadAsync(), etc.\n- This is really ridiculous after all these years for such a popular platform....\n- I can't quite pinpoint which release this was added in, but the relevant commits are from February 2017.\n- Seems like it's been available since 5.0.0-pre3.\n- @Gigi Do we have async support for Producer?\n- @Pingpong not that I know of.\n- Take a look to gist.github.com/kjnilsson/732c0883c7807647e84ba5be2c3027f5\n- As of today thats not true. I tested this yesterday and also code outside of the event handler is executed when an await is met inside the event handler.","metadata":{"transformedAt":"2026-08-18T18:33:20.126Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":26,"totalLines":189,"estimatedTokens":943}}117{"id":"stack-11987838","source":"stackoverflow","questionId":11987838,"title":"Which form of connection to use with pika","tags":["python","rabbitmq","pika"],"text":"Title: Which form of connection to use with pika\nTags: python, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI've been trying to figure out which form of connection i should use when using pika, I've got two alternatives as far as I understand.\n\nEither the `BlockingConnection` or the `SelectConnection`, however I'm not really sure about the differences between these two (i.e. what is the BlockingConnection blocking? and more) \n\nThe documentation for `pika` says that `SelectConnection` is the preferred way to connect to rabbit since it provides \"multiple event notification methods including select, epoll, kqueue and poll.\"\n\nSo I'm wondering what are the implications of these two different kinds of connections?\n\nPS: I know I shouldn't put a tag in the title but in this case I think it does help to clarify the question.\n\n========================================\n\nTop Answer:\nThe Pika documentation is quite clear about the differences between the connection types. The main difference is that the `pika.adapters.blocking_connection.BlockingConnection()` adapter is used for non-asynchronous programming and that the `pika.adapters.select_connection.SelectConnection()` adapter is used for asynchronous programming.\n\nIf you don't know what the difference is between non-asynchronous/synchronous and asynchronous programming I suggest that you read this question or for the more deeper technical explanation this article.\n\nNow let's dive into the different Pika adapters and see what they do, for the example purpose I imagine that we use Pika for setting up a client connection with RabbitMQ as AMQP message broker.\n\n### BlockingConnection()\n\nIn the following example, a connection is made to RabbitMQ listening to port *5672* on *localhost* using the username *guest* and password *guest* and virtual host '/'. Once connected, a channel is opened and a message is published to the *test_exchange* exchange using the *test_routing_key* routing key. The BasicProperties value passed in sets the message to delivery mode 1 (non-persisted) with a content-type of *text/plain*. Once the message is published, the connection is closed:\n\n```\nimport pika\n\nparameters = pika.URLParameters('amqp://guest:guest@localhost:5672/%2F')\n\nconnection = pika.BlockingConnection(parameters)\n\nchannel = connection.channel()\n\nchannel.basic_publish('test_exchange',\n 'test_routing_key',\n 'message body value',\n pika.BasicProperties(content_type='text/plain',\n delivery_mode=1))\n\nconnection.close()\n```\n\n### SelectConnection()\n\nIn contrast, using this connection adapter is more complicated and less pythonic, but when used with other asynchronous services it can have tremendous performance improvements. In the following code example, all of the same parameters and values are used as were used in the previous example:\n\n```\nimport pika\n\n# Step #3\ndef on_open(connection):\n\n connection.channel(on_open_callback=on_channel_open)\n\n# Step #4\ndef on_channel_open(channel):\n\n channel.basic_publish('test_exchange',\n 'test_routing_key',\n 'message body value',\n pika.BasicProperties(content_type='text/plain',\n delivery_mode=1))\n\n connection.close()\n\n# Step #1: Connect to RabbitMQ\nparameters = pika.URLParameters('amqp://guest:guest@localhost:5672/%2F')\n\nconnection = pika.SelectConnection(parameters=parameters,\n on_open_callback=on_open)\n\ntry:\n\n # Step #2 - Block on the IOLoop\n connection.ioloop.start()\n\n# Catch a Keyboard Interrupt to make sure that the connection is closed cleanly\nexcept KeyboardInterrupt:\n\n # Gracefully close the connection\n connection.close()\n\n # Start the IOLoop again so Pika can communicate, it will stop on its own when the connection is closed\n connection.ioloop.start()\n```\n\n### Conclusion\n\nFor those doing simple, non-asynchronous/synchronous programming, the `BlockingConnection()` adapter proves to be the easiest way to get up and running with Pika to publish messages. But if you are looking for a way to implement asynchronous message handling, the `SelectConnection()` handler is your better choice.\n\n*Happy coding!*\n\n========================================\n\nCode:\n```text\nBlockingConnection\n```\n\n```text\nSelectConnection\n```\n\n```text\npika\n```\n\n```text\nSelectConnection\n```\n\n```text\nimport pika\n\nparameters = pika.URLParameters('amqp://guest:guest@localhost:5672/%2F')\n\nconnection = pika.BlockingConnection(parameters)\n\nchannel = connection.channel()\n\nchannel.basic_publish('test_exchange',\n 'test_routing_key',\n 'message body value',\n pika.BasicProperties(content_type='text/plain',\n delivery_mode=1))\n\nconnection.close()\n```\n\n```text\nimport pika\n\n# Step #3\ndef on_open(connection):\n\n connection.channel(on_open_callback=on_channel_open)\n\n# Step #4\ndef on_channel_open(channel):\n\n channel.basic_publish('test_exchange',\n 'test_routing_key',\n 'message body value',\n pika.BasicProperties(content_type='text/plain',\n delivery_mode=1))\n\n connection.close()\n\n# Step #1: Connect to RabbitMQ\nparameters = pika.URLParameters('amqp://guest:guest@localhost:5672/%2F')\n\nconnection = pika.SelectConnection(parameters=parameters,\n on_open_callback=on_open)\n\ntry:\n\n # Step #2 - Block on the IOLoop\n connection.ioloop.start()\n\n# Catch a Keyboard Interrupt to make sure that the connection is closed cleanly\nexcept KeyboardInterrupt:\n\n # Gracefully close the connection\n connection.close()\n\n # Start the IOLoop again so Pika can communicate, it will stop on its own when the connection is closed\n connection.ioloop.start()\n```\n\n```text\npika.adapters.blocking_connection.BlockingConnection()\n```\n\n```text\npika.adapters.select_connection.SelectConnection()\n```\n\n```text\nBlockingConnection()\n```\n\n```text\nSelectConnection()\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.126Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":188,"estimatedTokens":1483}}118{"id":"stack-12499174","source":"stackoverflow","questionId":12499174,"title":"RabbitMQ C# driver stops receiving messages","tags":["c#","rabbitmq"],"text":"Title: RabbitMQ C# driver stops receiving messages\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nDo you have any pointers how to determine when a subscription problem has occurred so I can reconnect?\n\nMy service uses RabbitMQ.Client.MessagePatterns.Subscription for it's subscription. After some time, my client silently stops receiving messages. I suspect network issues as I our VPN connection is not the most reliable.\n\nI've read through the docs for awhile looking for a key to find out when this subscription might be broken due to a network issue without much luck. I've tried checking that the connection and channel are still open, but it always seems to report that it is still open.\n\nThe messages it does process work quite well and are acknowledged back to the queue so I don't think it's an issue with the \"ack\".\n\nI'm sure I must be just missing something simple, but I haven't yet found it.\n\n```\npublic void Run(string brokerUri, Action handler)\n{\n log.Debug(\"Connecting to broker: {0}\".Fill(brokerUri));\n ConnectionFactory factory = new ConnectionFactory { Uri = brokerUri };\n\n using (IConnection connection = factory.CreateConnection())\n {\n using (IModel channel = connection.CreateModel())\n {\n channel.QueueDeclare(queueName, true, false, false, null);\n\n using (Subscription subscription = new Subscription(channel, queueName, false))\n {\n while (!Cancelled)\n {\n BasicDeliverEventArgs args;\n\n if (!channel.IsOpen)\n {\n log.Error(\"The channel is no longer open, but we are still trying to process messages.\");\n throw new InvalidOperationException(\"Channel is closed.\");\n }\n else if (!connection.IsOpen)\n {\n log.Error(\"The connection is no longer open, but we are still trying to process message.\");\n throw new InvalidOperationException(\"Connection is closed.\");\n }\n\n bool gotMessage = subscription.Next(250, out args);\n\n if (gotMessage)\n {\n log.Debug(\"Received message\");\n try\n {\n handler(args.Body);\n }\n catch (Exception e)\n {\n log.Debug(\"Exception caught while processing message. Will be bubbled up.\", e);\n throw;\n }\n\n log.Debug(\"Acknowledging message completion\");\n subscription.Ack(args);\n }\n }\n }\n }\n }\n}\n```\n\nUPDATE:\n\nI simulated a network failure by running the server in a virtual machine and I *do* get an exception (RabbitMQ.Client.Exceptions.OperationInterruptedException: The AMQP operation was interrupted) when I break the connection for long enough so perhaps it isn't a network issue. Now I don't know what it would be but it fails after just a couple hours of running.\n\n========================================\n\nCode:\n```text\npublic void Run(string brokerUri, Action<byte[]> handler)\n{\n log.Debug(\"Connecting to broker: {0}\".Fill(brokerUri));\n ConnectionFactory factory = new ConnectionFactory { Uri = brokerUri };\n\n using (IConnection connection = factory.CreateConnection())\n {\n using (IModel channel = connection.CreateModel())\n {\n channel.QueueDeclare(queueName, true, false, false, null);\n\n using (Subscription subscription = new Subscription(channel, queueName, false))\n {\n while (!Cancelled)\n {\n BasicDeliverEventArgs args;\n\n if (!channel.IsOpen)\n {\n log.Error(\"The channel is no longer open, but we are still trying to process messages.\");\n throw new InvalidOperationException(\"Channel is closed.\");\n }\n else if (!connection.IsOpen)\n {\n log.Error(\"The connection is no longer open, but we are still trying to process message.\");\n throw new InvalidOperationException(\"Connection is closed.\");\n }\n\n bool gotMessage = subscription.Next(250, out args);\n\n if (gotMessage)\n {\n log.Debug(\"Received message\");\n try\n {\n handler(args.Body);\n }\n catch (Exception e)\n {\n log.Debug(\"Exception caught while processing message. Will be bubbled up.\", e);\n throw;\n }\n\n log.Debug(\"Acknowledging message completion\");\n subscription.Ack(args);\n }\n }\n }\n }\n }\n}\n```\n\n```text\nConnectionFactory factory = new ConnectionFactory() \n{\n Uri = brokerUri,\n RequestedHeartbeat = 30,\n};\n```\n\n```text\npublic bool Cancelled { get; set; }\n\nIConnection _connection = null;\nIModel _channel = null;\nSubscription _subscription = null;\n\npublic void Run(string brokerUri, string queueName, Action<byte[]> handler)\n{\n ConnectionFactory factory = new ConnectionFactory() \n {\n Uri = brokerUri,\n RequestedHeartbeat = 30,\n };\n\n while (!Cancelled)\n { \n try\n {\n if(_subscription == null)\n {\n try\n {\n _connection = factory.CreateConnection();\n }\n catch(BrokerUnreachableException)\n {\n //You probably want to log the error and cancel after N tries, \n //otherwise start the loop over to try to connect again after a second or so.\n continue;\n }\n\n _channel = _connection.CreateModel();\n _channel.QueueDeclare(queueName, true, false, false, null);\n _subscription = new Subscription(_channel, queueName, false);\n }\n\n BasicDeliverEventArgs args;\n bool gotMessage = _subscription.Next(250, out args);\n if (gotMessage)\n {\n if(args == null)\n {\n //This means the connection is closed.\n DisposeAllConnectionObjects();\n continue;\n }\n\n handler(args.Body);\n _subscription.Ack(args);\n }\n }\n catch(OperationInterruptedException ex)\n {\n DisposeAllConnectionObjects();\n }\n }\n DisposeAllConnectionObjects();\n}\n\nprivate void DisposeAllConnectionObjects()\n{\n if(_subscription != null)\n {\n //IDisposable is implemented explicitly for some reason.\n ((IDisposable)_subscription).Dispose();\n _subscription = null;\n }\n\n if(_channel != null)\n {\n _channel.Dispose();\n _channel = null;\n }\n\n if(_connection != null)\n {\n try\n {\n _connection.Dispose();\n }\n catch(EndOfStreamException) \n {\n }\n _connection = null;\n }\n}\n```\n\n```text\nOperationInterruptedException\n```\n\n```text\nIModel.QueueDeclare()\n```\n\n```text\nQueueingBasicConsumer\n```\n\n```text\nEndOfStreamException\n```\n\n```text\nQueueingBasicConsumer.Queue.Dequeue\n```\n\n```text\nEventingBasicConsumer\n```\n\n```text\nSubscription\n```\n\n```text\nSubscription.Next\n```\n\n```text\nargs\n```\n\n```text\nconnection.IsOpen\n```\n\n```text\nsubscription.Next()\n```\n\n```text\nIConnection.Dispose()\n```\n\n```text\nEndOfStreamException\n```\n\n```text\nIDisposable\n```\n\n========================================\n\nComments:\n- Wow. This looks great. I've coded into my service this morning and deployed it. You've saved me tons of time.","metadata":{"transformedAt":"2026-08-18T18:33:20.126Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":17,"totalLines":287,"estimatedTokens":1872}}119{"id":"stack-36302341","source":"stackoverflow","questionId":36302341,"title":"Why do we need routing key in RabbitMQ?","tags":["rabbitmq","rabbitmq-exchange","rabbitmqctl"],"text":"Title: Why do we need routing key in RabbitMQ?\nTags: rabbitmq, rabbitmq-exchange, rabbitmqctl\nSource: Stack Overflow\n\nQuestion:\nWhy do we need routing key to route messages from exchange to queue? Can't we simply use the queue name to route the message? Also, in case of publishing to multiple queues, we can use multiple queue names. Can anyone point out the scenario where we actually need routing key and queue name won't be suffice?\n\n========================================\n\nTop Answer:\nThere are several types of exchanges. The `fanout` exchange ignores the routing key and sends messages to all queues. But pretty much all other exchange types use the routing key to determine which queue, if any, will receive a message.\n\nThe tutorials on the RabbitMQ website describes several usecases where different exchange types are useful and where the routing key is relevant.\n\nFor instance, tutorial 5 demonstrates how to use a `topic` exchange to route log messages to different queues depending on the log level of each message.\n\nIf you want to target multiple queues, you need to bind them to a `fanout` exchange and use that exchange in your publisher.\n\nYou can't specify multiple queue names in your publisher. In AMQP, you do not publish a message to queues, you publish a message to an exchange. It's the exchange responsability to determine the relevant queues. It's possible that a message is routed to no queue at all and just dropped.\n\n========================================\n\nCode:\n```text\nfanout\n```\n\n```text\ntopic\n```\n\n```text\nfanout\n```\n\n========================================\n\nComments:\n- The routing-key is a not optional for AMQP basic.publish. So the trite answer is that \"AMQP requires it\".\n- It is similar to asking why can not we use localhost addresses to host out websites on internet. The routing key is required for when you are testing some application which uses RabbitMQ for passing the messages. And the environment is a cluster environment where exchange contains other applications also. There you can not use Fanout Exchange (for sending the same message to all the queues) or Topic Exchange(matching with binding-key.) You have a single publisher(test publisher) and one or 2 subscribers (test subscriber(s)).\n- ok. Why do we need routing key in between exchange and queue. We can use fan out exchange to send the messsages to all the queues. Similarly if we want to send to a particular or multiple queues. Can't we use the name of queue itself. Why do we need special \"routing key\" concept\n- You can put the queue name in the routing key and publish to the \"\" default exchange (an echange named with the empty string): your message will end up in the queue you want. Routing keys and different types of exchanges give more flexibility in how you can route messages to queues. It also allows you to further decouple publishers and consumers. One more advantage: it moves the routing knowledge from the publisher to the bus where it belongs.\n- RMQ web interface lets you publish to queues, so I guess it is possible, but seldom used anyway.","metadata":{"transformedAt":"2026-08-18T18:33:20.126Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":43,"estimatedTokens":770}}120{"id":"stack-24946181","source":"stackoverflow","questionId":24946181,"title":"RabbitMQ: What is the default x-message-ttl value","tags":["rabbitmq","amqp"],"text":"Title: RabbitMQ: What is the default x-message-ttl value\nTags: rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI couldn't find in RabbitMQ documentation the default x-message-ttl value comes with the installation.\n\nI know how to set it to a desired value but I am curious to know the default value.\n\n========================================\n\nCode:\n```text\nx-message-ttl\n```\n\n========================================\n\nComments:\n- Messages stay in the queue not until they \"reach queue head\" but until they are delivered to a consumer and acknowledged or rejected (without re-queueing). With automatic acknowledgement mode, this means \"as soon as they are sent out\". AMQP 0-9-1 queues are FIFO but with re-queueing this is not clear how it should work. RabbitMQ tries to preserve the original order of messages.\n- When per-message TTL expires, that message will not be removed from queue (it still utilize some resources like memory or disc) until it will not reach the queue head. See rabbitmq.com/ttl.html#per-message-ttl-caveats for details. And with re-queuing it is also very clear, messages are not removed from queue until they are ack'ed (when auto-ack used they ack'ed automatically on broker side, regardless they are actually consumed by client).","metadata":{"transformedAt":"2026-08-18T18:33:20.126Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":21,"estimatedTokens":314}}121{"id":"stack-11429774","source":"stackoverflow","questionId":11429774,"title":"How to communicate Web and Worker dynos with Node.js on Heroku?","tags":["node.js","heroku","redis","rabbitmq","kue"],"text":"Title: How to communicate Web and Worker dynos with Node.js on Heroku?\nTags: node.js, heroku, redis, rabbitmq, kue\nSource: Stack Overflow\n\nQuestion:\n**Web Dynos** can handle HTTP Requests\n\nand while **Web Dynos** handles them **Worker Dynos** can handle jobs from it.\n\nBut I don't know how to make **Web Dynos** and **Worker Dynos** to communicate each other.\n\nFor example, I want to receive a HTTP request by **Web Dynos**\n\n, send it to **Worker Dynos**\n\n, process the job and send back result to **Web Dynos**\n\n, show results on Web.\n\nIs this possible in Node.js? (With RabbitMQ or Kue or etc)?\n\nI could not find an example in Heroku Documentation \n\nOr Should I implement all codes in **Web Dynos** and scaling **Web Dynos** only?\n\n========================================\n\nTop Answer:\nFrom what I can tell, Heroku does not supply a way of communicating for you, so you will have to build that yourself. In order to communicate to another process using Node, you will probably have to deal with the process' stdin/out/err manually, something like this:\n\n```\nvar attachToProcess = function(pid) {\n return {\n stdin: fs.createWriteStream('/proc/' + pid + '/fd/0'),\n stdout: fs.createReadStream('/proc/' + pid + '/fd/1'),\n stderr: fs.createReadStream('/proc/' + pid + '/fd/2')\n };\n};\n\nvar pid = fs.readFile('/path/to/worker.pid', 'utf8', function(err, pid) {\n if (err) {throw err;}\n var worker = attachToProcess(Number(pid));\n worker.stdin.write(...);\n});\n```\n\nThen, in your worker process, you will have to store the pid in that pid file:\n\n```\nfs.writeFile('/path/to/worker.pid', process.pid, function(err) {\n if (err) {throw err;}\n});\n```\n\nI haven't actually tested any of this, so it will likely take some working and building on it, but I think the basic idea is clear.\n\n### Edit\n\nI *just* noticed that you tagged this with \"redis\" as well, and thought I should add that you can also use redis pub/sub to communicate between your various processes as explained in the node_redis readme.\n\n========================================\n\nCode:\n```text\nvar attachToProcess = function(pid) {\n return {\n stdin: fs.createWriteStream('/proc/' + pid + '/fd/0'),\n stdout: fs.createReadStream('/proc/' + pid + '/fd/1'),\n stderr: fs.createReadStream('/proc/' + pid + '/fd/2')\n };\n};\n\nvar pid = fs.readFile('/path/to/worker.pid', 'utf8', function(err, pid) {\n if (err) {throw err;}\n var worker = attachToProcess(Number(pid));\n worker.stdin.write(...);\n});\n```\n\n```text\nfs.writeFile('/path/to/worker.pid', process.pid, function(err) {\n if (err) {throw err;}\n});\n```\n\n========================================\n\nComments:\n- Heroku dynos are each virtualized meaning they do not the same filesystem, even within the same app. So, communicating via process ids from one dyno to another won't work.\n- @RyanDaigle yeah, i thought there might be some issue there. the idea about redis is still valid, though.\n- definitely. Using Redis as an intermediary (or some other queue lib) is the right approach.\n- I have one more question on this. When I use AMQP, how would you guarantee that processing each jobs are handled by one worker dyno but not duplicating? To me, AMQP is similar to TCP Socket, broadcast event and listen to the event and do something. If an \"enqueue\" event happened, multiple worker dynos would react to the \"enqueue\" event and try to \"dequeue\" event in same time. How can I handle this problem?\n- While queue behavior varies between each queue and client libraries the default behavior is usually *not* to broadcast. So by default, when a message is consumed off the queue it is done so by the first receiver to get there and is then removed from the queue.\n- In AMQP you have Exchanges to which you publish messages, and you have Queues from which you get messages, then you have \"bindings\" between them which routes the messages from an Exchange to one or more Queues. If you only have one binding between an Exchange and a Queue (which is the default), you're guaranteed to only get unique messages to each subscriber of that Queue.\n- Also, AMQP has other nice benefits like in-order guarantees, and features like message persistance, high availability (mirrored) queues etc. (Disclosure, I own CloudAMQP)","metadata":{"transformedAt":"2026-08-18T18:33:20.127Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":95,"estimatedTokens":1061}}122{"id":"stack-10030227","source":"stackoverflow","questionId":10030227,"title":"Maximize throughput with RabbitMQ","tags":["rabbitmq"],"text":"Title: Maximize throughput with RabbitMQ\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nIn our project, we want to use the RabbitMQ in \"Task Queues\" pattern to pass data.\n\nOn the producer side, we build a few TCP server(in node.js) to recv\nhigh concurrent data and send it to MQ without doing anything.\n\nOn the consumer side, we use JAVA client to get the task data from\nMQ, handle it and then ack.\n\nSo the question is:\nTo get the maximum message passing throughput/performance( For example, 400,000 msg/second) , How many queues is best? Does that more queue means better throughput/performance? And is there anything else should I notice?\nAny known best practices guide for using RabbitMQ in such scenario?\n\nAny comments are highly appreciated!!\n\n========================================\n\nTop Answer:\nAccording to a response I once got from the rabbitmq-discuss mailing group there are other things that you can try to increase throughput and reduce latency:\n\n \n Use a larger prefetch count. Small values hurt performance.\n\n A topic exchange is slower than a direct or a fanout exchange.\n\n Make sure queues stay short. Longer queues impose more processing\n overhead.\n\n If you care about latency and message rates then use smaller messages.\n Use an efficient format (e.g. avoid XML) or compress the payload.\n\n Experiment with HiPE, which helps performance.\n\n Avoid transactions and persistence. Also avoid publishing in immediate\n or mandatory mode. Avoid HA. Clustering can also impact performance.\n\n You will achieve better throughput on a multi-core system if you have\n multiple queues and consumers.\n\n Use at least v2.8.1, which introduces flow control. Make sure the\n memory and disk space alarms never trigger.\n\n Virtualisation can impose a small performance penalty.\n\n Tune your OS and network stack. Make sure you provide more than enough\n RAM. Provide fast cores and RAM.\n\n========================================\n\nComments:\n- That's stream processing, not queue-ing. They should rename it \"RabbitMS\" (Rabbit Message Stream).\n- Is a topic exchange slower because it takes the exchange longer time to compute to which queue it needs to send a message?\n- Unfortunately a lot of generalized noise and low-impact to irrelevant advice. I'm surprised they didn't list \"just send fewer messages\" as a performance tip. You cannot use direct if you need topic queues. Increasing your prefetch can dramatically INCREASE latency, too. You have to the docs and guidance for setting the correct value for your situation. Multicore systems are faster? Yeah, water is wet. Keep queues short? Um, just throw away extra messages? Some of this is just plain silly. HiPE is going to buy you practically ZERO benefit in most applications.\n- Sorry, just patently false: \"you will increase the throughput with a larger prefetch count\". Prefetch requires tuning and it's not a constant even then. The documentation details this.\n- @RickO'Shea Please read carefully both the question and the answer, and then add a comment.","metadata":{"transformedAt":"2026-08-18T18:33:20.127Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":59,"estimatedTokens":753}}123{"id":"stack-53031439","source":"stackoverflow","questionId":53031439,"title":"Connecting to RabbitMQ container with docker-compose","tags":["docker","network-programming","rabbitmq","docker-compose"],"text":"Title: Connecting to RabbitMQ container with docker-compose\nTags: docker, network-programming, rabbitmq, docker-compose\nSource: Stack Overflow\n\nQuestion:\nI want to run RabbitMQ in one container, and a worker process in another. The worker process needs to access RabbitMQ.\n\nI'd like these to be managed through `docker-compose`.\n\nThis is my `docker-compose.yml` file so far:\n\n```\nversion: \"3\"\n\nservices:\n\n rabbitmq:\n image: rabbitmq\n command: rabbitmq-server\n expose:\n - \"5672\"\n - \"15672\"\n\n worker:\n build: ./worker\n depends_on:\n - rabbitmq\n # Allow access to docker daemon\n volumes:\n - /var/run/docker.sock:/var/run/docker.sock\n```\n\nSo I've exposed the RabbitMQ ports. The worker process accesses RabbitMQ using the following URL:\n\n```\namqp://guest:guest@rabbitmq:5672/\n```\n\nWhich is what they use in the official tutorial, but `localhost` has been swapped for `rabbitmq`, since the the containers should be discoverable with a hostname identical to the container name:\n\nBy default Compose sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.\n\nWhenever I run this, I get an connection refused error:\n\n```\nRecreating ci_rabbitmq_1 ... done \nRecreating ci_worker_1 ... done \nAttaching to ci_rabbitmq_1, ci_worker_1 \nworker_1 | dial tcp 127.0.0.1:5672: connect: connection refused \nci_worker_1 exited with code 1\n```\n\nI find this interesting because it's using the IP `127.0.0.1` which (I think) is `localhost`, even though I specified `rabbitmq` as the hostname. I'm not an expert on docker networking, so maybe this is desired.\n\nI'm happy to supply more information if needed!\n\n**Edit**\n\nThere is an almost identical question here. I think I need to wait until `rabbitmq` is up and running before starting `worker`. I tried doing this with a healthcheck:\n\n```\nversion: \"2.1\"\n\nservices:\n\n rabbitmq:\n image: rabbitmq\n command: rabbitmq-server\n expose:\n - \"5672\"\n - \"15672\"\n healthcheck:\n test: [ \"CMD\", \"nc\", \"-z\", \"localhost\", \"5672\" ]\n interval: 10s\n timeout: 10s\n retries: 5\n\n worker:\n build: .\n depends_on:\n rabbitmq:\n condition: service_healthy\n```\n\n(Note the different version). This doesn't work, however - it will always fail as not-healthy.\n\n========================================\n\nTop Answer:\nAha! I fixed it. @Ijaz was totally correct - the RabbitMQ service takes a while to start, and my worker tries to connect before it's running.\n\nI tried using a delay, but this failed when the RabbitMQ took longer than usual.\n\nThis is also indicative of a larger architectural problem - what happens if the queuing service (RabbitMQ in my case) goes offline during production? Right now, my entire site fails. There needs to be some built-in redundancy and polling.\n\nAs described this this related answer, we can use healthchecks in docker-compose `3+`:\n\n```\nversion: \"3\"\n\nservices:\n\n rabbitmq:\n image: rabbitmq\n command: rabbitmq-server\n expose:\n - 5672\n - 15672\n healthcheck:\n test: [ \"CMD\", \"nc\", \"-z\", \"localhost\", \"5672\" ]\n interval: 5s\n timeout: 15s\n retries: 1\n\n worker:\n image: worker\n restart: on-failure\n depends_on:\n - rabbitmq\n```\n\nNow, the `worker` container will restart a few times while the `rabbitmq` container stays unhealthy. `rabbitmq` immediately becomes healthy when `nc -z localhost 5672` succeeds - i.e. when the queuing is live!\n\n========================================\n\nCode:\n```yaml\nversion: \"3\"\n\nservices:\n\n rabbitmq:\n image: rabbitmq\n command: rabbitmq-server\n expose:\n - \"5672\"\n - \"15672\"\n\n worker:\n build: ./worker\n depends_on:\n - rabbitmq\n # Allow access to docker daemon\n volumes:\n - /var/run/docker.sock:/var/run/docker.sock\n```\n\n```text\namqp://guest:guest@rabbitmq:5672/\n```\n\n```text\nRecreating ci_rabbitmq_1 ... done \nRecreating ci_worker_1 ... done \nAttaching to ci_rabbitmq_1, ci_worker_1 \nworker_1 | dial tcp 127.0.0.1:5672: connect: connection refused \nci_worker_1 exited with code 1\n```\n\n```yaml\nversion: \"2.1\"\n\nservices:\n\n rabbitmq:\n image: rabbitmq\n command: rabbitmq-server\n expose:\n - \"5672\"\n - \"15672\"\n healthcheck:\n test: [ \"CMD\", \"nc\", \"-z\", \"localhost\", \"5672\" ]\n interval: 10s\n timeout: 10s\n retries: 5\n\n worker:\n build: .\n depends_on:\n rabbitmq:\n condition: service_healthy\n```\n\n```text\ndocker-compose\n```\n\n```text\ndocker-compose.yml\n```\n\n```text\nlocalhost\n```\n\n```text\nrabbitmq\n```\n\n```text\n127.0.0.1\n```\n\n```text\nlocalhost\n```\n\n```text\nrabbitmq\n```\n\n```text\nrabbitmq\n```\n\n```text\nworker\n```\n\n```text\nhealthcheck:\n test: rabbitmq-diagnostics -q ping\n interval: 30s\n timeout: 30s\n retries: 3\n```\n\n```text\nexpose:\n - \"3000\"\n - \"8000\"\n```\n\n```text\nversion: \"3\"\n\nservices:\n\n rabbitmq:\n image: rabbitmq\n command: rabbitmq-server\n expose:\n - \"5672\"\n - \"15672\"\n\n worker:\n build: ./worker\n depends_on:\n - rabbitmq\n # Allow access to docker daemon\n volumes:\n - /var/run/docker.sock:/var/run/docker.sock\n```\n\n```yaml\nversion: \"3\"\n\nservices:\n\n rabbitmq:\n image: rabbitmq\n command: rabbitmq-server\n expose:\n - 5672\n - 15672\n healthcheck:\n test: [ \"CMD\", \"nc\", \"-z\", \"localhost\", \"5672\" ]\n interval: 5s\n timeout: 15s\n retries: 1\n\n worker:\n image: worker\n restart: on-failure\n depends_on:\n - rabbitmq\n```\n\n```text\n3+\n```\n\n```text\nworker\n```\n\n```text\nrabbitmq\n```\n\n```text\nrabbitmq\n```\n\n```text\nnc -z localhost 5672\n```\n\n```text\nversion: \"3.8\"\n\n services:\n\n rabbitmq:\n image: rabbitmq:3.7.28-management\n #container_name: rabbitmq\n volumes:\n - ./etc/rabbitmq/conf:/etc/rabbitmq/\n - ./etc/rabbitmq/data/:/var/lib/rabbitmq/\n - ./etc/rabbitmq/logs/:/var/log/rabbitmq/\n environment:\n RABBITMQ_ERLANG_COOKIE: ${RABBITMQ_ERLANG_COOKIE:-secret_cookie}\n RABBITMQ_DEFAULT_USER: ${RABBITMQ_DEFAULT_USER:-admin}\n RABBITMQ_DEFAULT_PASS: ${RABBITMQ_DEFAULT_PASS:-admin}\n ports:\n - 5672:5672 #amqp\n - 15672:15672 #http\n - 15692:15692 #prometheus\n healthcheck:\n test: [ \"CMD\", \"rabbitmqctl\", \"status\"]\n interval: 5s\n timeout: 20s\n retries: 5\n\n mysql:\n image: mysql\n restart: always\n volumes:\n - ./etc/mysql/data:/var/lib/mysql\n - ./etc/mysql/scripts:/docker-entrypoint-initdb.d\n environment:\n MYSQL_ROOT_PASSWORD: root\n MYSQL_DATABASE: mysqldb\n MYSQL_USER: ${MYSQL_DEFAULT_USER:-testuser}\n MYSQL_PASSWORD: ${MYSQL_DEFAULT_PASSWORD:-testuser}\n ports:\n - \"3306:3306\"\n healthcheck:\n test: [\"CMD\", \"mysqladmin\" ,\"ping\", \"-h\", \"localhost\"]\n timeout: 20s\n retries: 10\n\n trigger-batch-process-job:\n build: .\n environment:\n - RMQ_USER=${RABBITMQ_DEFAULT_USER:-admin}\n - RMQ_PASS=${RABBITMQ_DEFAULT_PASS:-admin}\n - RMQ_HOST=${RABBITMQ_DEFAULT_HOST:-rabbitmq}\n - RMQ_PORT=${RABBITMQ_DEFAULT_PORT:-5672}\n - DB_USER=${MYSQL_DEFAULT_USER:-testuser}\n - DB_PASS=${MYSQL_DEFAULT_PASSWORD:-testuser}\n - DB_SERVER=mysql\n - DB_NAME=mysqldb\n - DB_PORT=3306\n depends_on:\n mysql:\n condition: service_healthy\n rabbitmq:\n condition: service_healthy\n```\n\n```yaml\nversion: \"3.8\"\n\nservices:\n\n worker:\n build: ./worker\n rabbitmq:\n condition: service_healthy\n\n rabbitmq:\n image: library/rabbitmq\n ports:\n - 5671:5671\n - 5672:5672\n healthcheck:\n test: [ \"CMD\", \"nc\", \"-z\", \"localhost\", \"5672\" ]\n interval: 5s\n timeout: 10s\n retries: 3\n```\n\n```text\ndocker compose v3.8\n```\n\n========================================\n\nComments:\n- why you need to expose the ports on the host?\n- You're definitely right - I don't need to expose the ports on the host, but only to other containers. Unfortunately this doesn't fix the connection problem, but I still learned something new :)\n- @haz the connection problem maybe related to the fact the the rabitmq service doesnt start fast enough for the worker to connect , put some delay in worker , you can also test using some dummy container and see if you can connect from that instead\n- No, it's wrong. Compose 3+ does not support `condition: service_healthy` under `depends on`\n- Test this out: github.com/mnadeem/lob-proj-job-trigger-batch-process/blob/m‌​ain/…\n- Your example did not run on my machine after running `docker-compose up -d`, but i managed to figure out why `condition: service_healthy` was not working for me in the first place thanks to you. So you are right. Thanks!\n- this is actually the correct answer\n- Do you not need the \"rabbitmq\" line to be nested under another field? I'm getting an error with this solution that says the keyword is not defined\n- @HarrisonCramer you are right. there is a \"services\" keyword missing. thanks, answer modified","metadata":{"transformedAt":"2026-08-18T18:33:20.127Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":25,"totalLines":399,"estimatedTokens":2405}}124{"id":"stack-16001047","source":"stackoverflow","questionId":16001047,"title":"RabbitMQ fails to start","tags":["windows","rabbitmq"],"text":"Title: RabbitMQ fails to start\nTags: windows, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nThe RabbitMQ windows service will not start:\n\n```\nC:\\Program Files (x86)\\RabbitMQ Server\\rabbitmq_server-3.0.4\\sbin>rabbitmq-service.bat start\nC:\\Program Files (x86)\\erl5.10.1\\erts-5.10.1\\bin\\erlsrv: Failed to start service RabbitMQ.\nError: The process terminated unexpectedly.\n```\n\nI can run rabbitmq-server.bat without any problems.\n\nNo log entries are made to %appdata%\\RabbitMQ\\log\\ directory when trying to start the service.\n\nHow to make it work?\n\n========================================\n\nTop Answer:\nI faced the same problem and was able to solve the problem following the steps mentioned below.\n\n- Run the command prompt as Administrator\n\n- Navigate to the sbin directory and uninstall the service `rabbitmq-service remove`\n\n- Reinstall the service `rabbitmq-service install`\n\n- Enable the plugins `rabbitmq-plugins enable rabbitmq_management`\n\n- Start the service `rabbitmq-service start`\n\n- Go to \"http://localhost:15672/\"\n\n========================================\n\nCode:\n```text\nC:\\Program Files (x86)\\RabbitMQ Server\\rabbitmq_server-3.0.4\\sbin>rabbitmq-service.bat start\nC:\\Program Files (x86)\\erl5.10.1\\erts-5.10.1\\bin\\erlsrv: Failed to start service RabbitMQ.\nError: The process terminated unexpectedly.\n```\n\n```text\nRabbitMQ Server\\rabbitmq_server-3.6.9\\sbin>rabbitmq-plugins enable rabbitmq_management\n```\n\n```text\nrabbitmq-service remove\n```\n\n```text\nrabbitmq-service install\n```\n\n```text\nrabbitmq-plugins enable rabbitmq_management\n```\n\n```text\nrabbitmq-service start\n```\n\n```text\nC:\\Users\\IPS\\AppData\\Roaming\\RabbitMQ\\advanced.config\n```\n\n```text\nrabbitmq.conf\n```\n\n```text\nrabbitmq.conf\n```\n\n```text\nadvanced.config\n```\n\n```text\nYour-Path\\rabbitmq_server-3.7.13\\sbin\n```\n\n```text\nrabbitmq-plugins.bat enable rabbitmq_management\n```\n\n```text\nHKEY_LOCAL_MACHINE\\SOFTWARE\\Ericsson\\Erlang\\ErlSrv\\1.1\\RabbitMQ\n```\n\n```text\nC:\\Users\\<USERNAME>\\AppData\\Roaming\\RabbitMQ\n```\n\n```text\n./rabbitmq-server.bat\n```\n\n```text\nsbin\n```\n\n```text\nC:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.7.14\\sbin\n```\n\n========================================\n\nComments:\n- I had my own issues with this, and setting the environment variable RABBITMQ_SERVER to the installed dir and reinstalling the service worked for me.\n- Thanks. Additionally, for me, on windows, it was forgetting to add ERLANG_HOME to system variable. rabbitmq.com/install-windows-manual.html\n- I had to restart a couple of times, add RABBITMQ_BASE and RABBITMQ_SERVER (path to install dir of RabbitMQ) to Environment Variables.\n- Thanks a lot for the idea of starting /rabbitmq-server.bat!","metadata":{"transformedAt":"2026-08-18T18:33:20.127Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":17,"totalLines":116,"estimatedTokens":662}}125{"id":"stack-4987438","source":"stackoverflow","questionId":4987438,"title":"RabbitMQ C# connection trouble when using a username and password","tags":["c#",".net","rabbitmq"],"text":"Title: RabbitMQ C# connection trouble when using a username and password\nTags: c#, .net, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am at a loss here so I'm reaching out to the collective knowledge in hope of a miracle.\n\nI have installed RabbitMQ on a Linux box using the defaults.\n\nWhen I use this code (and the default RabbitMQ installation configuration) everything works nice.\n\n```\nvar connectionFactory = new ConnectionFactory();\nconnectionFactory.HostName = \"192.168.0.12\";\nIConnection connection = connectionFactory.CreateConnection();\n```\n\nBut when I add a user to RabbitMQ and try to use the following code (username and password has been changed to protect the innocent. :) )\n\n```\nvar connectionFactory = new ConnectionFactory();\nconnectionFactory.HostName = \"192.168.0.12\";\nconnectionFactory.UserName = \"user\";\nconnectionFactory.Password = \"password\";\nIConnection connection = connectionFactory.CreateConnection();\n```\n\nthe `connectionFactory.CreateConnection()` method throws the following exception:\n\n```\nBrokerUnreachableException \nNone of the specified endpoints were reachable\n```\n\nChecking the RabbitMQ logfile I can see it complaining about the credentials:\n\n```\n{amqp_error,access_refused,\n\"PLAIN login refused: user 'user' - invalid credentials\",\n'connection.start_ok'}}\n```\n\nThe thing is that I am confident about the username and password and I cannot for the love of coding find a solution to this anywhere.\n\nI must be missing something obvious but I can't figure out what it is.\nI would be grateful for any helpful pointers.\n\n========================================\n\nTop Answer:\nHere is how to create a user called `agent` with password `agent`, set it to be `administrator` and give it `read` and `write` access to all queues in the vhost /\n\n```\nrabbitmqctl add_user agent agent\nrabbitmqctl set_user_tags agent administrator\nrabbitmqctl set_permissions -p / agent \".*\" \".*\" \".*\"\n```\n\n========================================\n\nCode:\n```text\nvar connectionFactory = new ConnectionFactory();\nconnectionFactory.HostName = \"192.168.0.12\";\nIConnection connection = connectionFactory.CreateConnection();\n```\n\n```text\nvar connectionFactory = new ConnectionFactory();\nconnectionFactory.HostName = \"192.168.0.12\";\nconnectionFactory.UserName = \"user\";\nconnectionFactory.Password = \"password\";\nIConnection connection = connectionFactory.CreateConnection();\n```\n\n```text\nBrokerUnreachableException \nNone of the specified endpoints were reachable\n```\n\n```text\n{amqp_error,access_refused,\n\"PLAIN login refused: user 'user' - invalid credentials\",\n'connection.start_ok'}}\n```\n\n```text\nconnectionFactory.CreateConnection()\n```\n\n```text\nConnectionFactory factory = new ConnectionFactory();\nfactory.UserName = \"user\";\nfactory.Password = \"password\";\nfactory.VirtualHost = \"/\";\nfactory.Protocol = Protocols.FromEnvironment();\nfactory.HostName = \"192.168.0.12\";\nfactory.Port = AmqpTcpEndpoint.UseDefaultPort;\nIConnection conn = factory.CreateConnection();\n```\n\n```text\nrabbitmq-plugins enable rabbitmq_management\n```\n\n```text\ninstall-package easynetq\n```\n\n```text\nhttp://localhost:15672\n```\n\n```text\nThis user does not have permission to access any virtual hosts.\nUse \"Set Permission\" below to grant permission to access virtual hosts.\n```\n\n```text\nrabbitmqctl add_user agent agent\nrabbitmqctl set_user_tags agent administrator\nrabbitmqctl set_permissions -p / agent \".*\" \".*\" \".*\"\n```\n\n```text\nagent\n```\n\n```text\nagent\n```\n\n```text\nadministrator\n```\n\n```text\nread\n```\n\n```text\nwrite\n```\n\n========================================\n\nComments:\n- Hi ! I am also trying to establish connection to send messages. I have searched but not satisfied. Can you please suggest me something. That, do we also need to install rabbitMQ server before using the above code. I am using above code after adding reference of DLL so there is no error in the project but it stll gives the above said exception. Do we also need to add some things in WEB.Config File. Please help. Your point of view will really help me\n- Hi! Sorry for not answering earlier. I played with RabbitMQ for only a short while so I have not much experience with it. I do remember having a RabbitMQ instance running so you'd probably need that as well. Regarding the web.config file I'm afraid I don't know if I ever used it.\n- FWIW, the salient lines for me were setting the `VirtualHost` and `Protocol`.\n- Additionally: make sure the user actually has access rights to the Virtual Host\n- Does it work for username/password as guest? Mine not working :( and it doesn't recognize FromEnvironment()\n- Hi Imad. Sorry but I am unable to answer your question as I don't have a setup to test in anymore. Hopefully some other kind Stackoverflow:er can help you.\n- As of year 2020, this is no need to specify Protocol. One thing to highlight is make sure the user has been configured correctly on the RabbitMQ-Server, it has to be admin, has permissions to read and write like @mihail said and also has access to \"/\" virtualHost","metadata":{"transformedAt":"2026-08-18T18:33:20.127Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":16,"totalLines":154,"estimatedTokens":1246}}126{"id":"stack-18110077","source":"stackoverflow","questionId":18110077,"title":"RabbitMQ queue messages","tags":["rabbitmq","amqp"],"text":"Title: RabbitMQ queue messages\nTags: rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nAt the rabbitMQ web interface at the queue tab I see \"Overview\" panel where I found these:\n\nQueued messages :\n\n- Ready\n\n- Unacknowledged\n\n- Total\n\nI guess what is the \"Total\" messages. But what is \"Ready\" and \"Unacknowledged\" ?\n\"Ready\" - messages that were delivered to the consumer?\n\"Unacknowledged\" - ?\n\nMessage rates:\n\n- Publish\n\n- Deliver\n\n- Redelivered\n\n- Acknowledge\n\nAnd what are these messages? Especially \"Redelivered\" and \"Acknowledge\"? What does this mean?\n\n========================================\n\nComments:\n- This is almost the same as in the help dialog. @Rene can you clarify what the 'ready' number means? In my case I see that number increasing, but it never comes back down again, it just flatttens out after we have priocessed some tasks. Everything seems to function like expected, bet the graph just repeatedly goes up and flattens out.\n- @RicoSuave \"ready\" means how many messages are inside your queue. Small Example: If you push 100 messages to the queue, the size of total and ready will be 100. If you consume(without acknowledge) 20 messages from this queue you have 80 messages ready, 20 messages unacknowledged and 100 messages in total. If you acknowledge now from this 20 consumed messages just 10, then the other 10 messages will be again ready after a given time. This means you have now 90 ready and 90 in total. Your case sounds for me that you publish faster messages to the queue then consuming them.","metadata":{"transformedAt":"2026-08-18T18:33:20.127Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":36,"estimatedTokens":381}}127{"id":"stack-42567689","source":"stackoverflow","questionId":42567689,"title":"RabbitMQ PRECONDITION_FAILED - unknown delivery tag","tags":["php","rabbitmq","amqp"],"text":"Title: RabbitMQ PRECONDITION_FAILED - unknown delivery tag\nTags: php, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nWe have a PHP app that forwards messages from RabbitMQ to connected devices down a WebSocket connection (PHP AMQP pecl extension v1.7.1 & RabbitMQ 3.6.6).\n\nMessages are consumed from an array of queues (1 per websocket connection), and are acknowledged by the consumer when we receive confirmation over the websocket that the message has been received (so we can requeue messages that are not delivered in an acceptable timeframe). This is done in a non-blocking fashion.\n\n99% of the time, this works perfectly, but very occasionally we receive an error \"RabbitMQ PRECONDITION_FAILED - unknown delivery tag \". This closes the channel. In my understanding, this exception is a result of one of the following conditions:\n\n- The message has *already* been acked or rejected.\n\n- An ack is attempted over a channel the message was not delivered on.\n\n- An ack is attempted after the message timeout (ttl) has expired.\n\nWe have implemented protections for each of the above cases but yet the problem continues. \n\nI realise there are number of implementation details that could impact this, but at a conceptual level, are there any other failure cases that we have not considered and should be handling? or is there a better way of achieving the functionality described above?\n\n========================================\n\nTop Answer:\n(Solution below)\n\n**Quoting Jan Grzegorowski from his blog:**\n\nIf you are struggling with the 406 error message which is included in\ntitle of this post you may be interested in reading the whole story.\n\n**Problem**\n\nI was using amqplib for conneting NodeJS based messages processor with\nRabbitMQ broker. Everything seems to be working fine, but from time to\ntime 406 (PRECONDINTION-FAILED) message shows up in the log:\n\n```\n\"Error: Channel closed by server: 406 (PRECONDITION-FAILED) with message \"PRECONDITION_FAILED - unknown delivery tag 1\"\n```\n\n**Solution** Keeping things simple:\n\n- You have to ACK messages in same order as they arrive to your system\nYou can't ACK messages on a different channel than that they arrive on If you break any of these rules you will face 406\n(PRECONDITION-FAILED) error message.\n\nOriginal answer\n\n========================================\n\nCode:\n```text\nbasic.ack\n```\n\n```text\nbasic.ack\n```\n\n```text\n\"Error: Channel closed by server: 406 (PRECONDITION-FAILED) with message \"PRECONDITION_FAILED - unknown delivery tag 1\"\n```\n\n```text\nno-ack\n```\n\n```text\ntrue\n```\n\n```text\nack\n```\n\n```text\nno-ack\n```\n\n```text\nfalse\n```\n\n```text\nspring.rabbitmq.listener.simple.acknowledge-mode=manual\n```\n\n```text\nspring.rabbitmq.listener.direct.acknowledge-mode=manual\n```\n\n```text\nmultiple\n```\n\n```js\nif (!hasMatchingSubscriptions(context)) {\n channel.nack(mqMsg, false, false);\n // return; <-- forgot to exit\n}\nchannel.ack(mqMsg);\n```\n\n========================================\n\nComments:\n- As answered by @DenisKolodin, I think first we should check if the `auto_ack` is set to `False`. If it is true, we get the same error on acknowledging manually.\n- Thanks, my case is `ack-ing messages that should not be ack-ed`\n- Tried to edit to make your answer clearer. hit the \"edit queue is full\" problem. try dviding it into paragraphs with the lines in following comments\n- A variation of what they said above about ack'ing it twice:\n- there is an \"obscure\" situation where you are ack'ing a message more than once, which is when you ack a message with multiple parameters set to true, which means all previous messages to the one you are trying to ack, will be ack'ed too.\n- and so if you try to ack one of the messages that were \"auto ack'ed\" by setting multiple to true, then you would be trying to \"ack\" it multiple times and so the error\n- ok, improved it a little. Thanks","metadata":{"transformedAt":"2026-08-18T18:33:20.127Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":114,"estimatedTokens":961}}128{"id":"stack-18495874","source":"stackoverflow","questionId":18495874,"title":"Failed to Create Cookie file RabbitMQ in Windows","tags":["erlang","rabbitmq"],"text":"Title: Failed to Create Cookie file RabbitMQ in Windows\nTags: erlang, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am trying to run the following command \n\n```\nrabbitmq-plugins.bat enable rabbitmq_management\n```\n\nand its giving me an error like this:\n\n 11:36:55.464 [error] Failed to create cookie file 'h:/.erlang.cookie': enoent\n\nI am using windows 7, Erlang Version R16B01 and RabbitMQ-Server version 3.1.5\n\nI am using my work PC and our Corporate policy sets the HOMEDRIVE to h: and HOMEPATH to /\nand i dont think they will let me change this.\n\nI can see the .erlang.cookie file under C:\\Windows.\n\nCould someone let me know of a workaround for this ?\n\nThanks in advance !\n\n========================================\n\nTop Answer:\nI solved the problem by following the steps below:\n\nOpen the file: \"Program Files/RabbitMQ Server/rabbitmq_server-/sbin/rabbitmq-env\"\n\nAt the end of the file, append the line:\n\n```\nREM Environment cleanup\nset BOOT_MODULE=\nset CONFIG_FILE=\nset FEATURE_FLAGS_FILE=\nset ENABLED_PLUGINS_FILE=\nset LOG_BASE=\nset MNESIA_BASE=\nset PLUGINS_DIR=\nset SCRIPT_DIR=\nset SCRIPT_NAME=\nset TDP0=\nset HOMEDRIVE=C: \nOpen the RabbitMQ console\n\nwrite:\n\n4.1. `rabbitmq-service stop`\n\n4.2. `rabbitmq-service remove`\n\n4.3. `rabbitmq-service install`\n\n4.4. `rabbitmq-service start`\n\n========================================\n\nCode:\n```text\nrabbitmq-plugins.bat enable rabbitmq_management\n```\n\n```bash\nset HOMEDRIVE=C:/conf/rabbitmq :: Or your favorite dir \n\nrabbitmq-plugins.bat enable rabbitmq_management\n```\n\n```text\nset HOMEDRIVE=[location of \".erlang.cookie\"]\nrabbitmq-plugins.bat enable rabbitmq_management\n```\n\n```text\n\"!ERLANG_HOME!\\bin\\erl.exe\" ^\n -pa \"!RABBITMQ_EBIN_ROOT!\" ^\n -boot !CLEAN_BOOT_FILE! ^\n -noinput -hidden ^\n -s rabbit_prelaunch ^\n -setcookie \"C:\\Users\\userName\\\" ^ <<< this is a place of your cookie\n !RABBITMQ_NAME_TYPE! rabbitmqprelaunch!RANDOM!!TIME:~9!@localhost ^\n -conf_advanced \"!RABBITMQ_ADVANCED_CONFIG_FILE!\" ^\n ...\"\n```\n\n```text\nrabbitmq-service remove\n```\n\n```text\nset HOMEDRIVE=C:\\Users\\userName\n```\n\n```text\nrabbitmq-service install\n```\n\n```text\nREM Environment cleanup\nset BOOT_MODULE=\nset CONFIG_FILE=\nset FEATURE_FLAGS_FILE=\nset ENABLED_PLUGINS_FILE=\nset LOG_BASE=\nset MNESIA_BASE=\nset PLUGINS_DIR=\nset SCRIPT_DIR=\nset SCRIPT_NAME=\nset TDP0=\nset HOMEDRIVE=C: <<< the new path of the .erlang.cookie\n```\n\n```text\nrabbitmq-service stop\n```\n\n```text\nrabbitmq-service remove\n```\n\n```text\nrabbitmq-service install\n```\n\n```text\nrabbitmq-service start\n```\n\n========================================\n\nComments:\n- you could cheat and copy the cookie file over to your home dir. Just the content is relevant ;)\n- Thanks ! will try that .for now the H:drive is not accessible to me, not sure why some corporate policies give us inaccessible home drives :)\n- This only works in Cmd, not in PowerShell.","metadata":{"transformedAt":"2026-08-18T18:33:20.127Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":139,"estimatedTokens":715}}129{"id":"stack-47060893","source":"stackoverflow","questionId":47060893,"title":"What are advantages of using NServiceBus + RabbitMQ against pure RabbitMQ?","tags":["rabbitmq","nservicebus"],"text":"Title: What are advantages of using NServiceBus + RabbitMQ against pure RabbitMQ?\nTags: rabbitmq, nservicebus\nSource: Stack Overflow\n\nQuestion:\nWhat are advantages of using NServiceBus + RabbitMQ against pure RabbitMQ?\nI guess it provides additional infrastracture. But what else?\n\n========================================\n\nTop Answer:\nI'll try and put down the main points:\n\n- NServiceBus deals with all the communication with its underlying transport i.e. Rabbit\n\n- NServiceBus has a clean api to code your business logic.\n\n- NServiceBus is easy to extend, if you want to get some custom behaviour.\n\n- NServiceBus deals with all aspects of fault tolerance\n\n- NServiceBus has many features like:\n\nSagas (long running process management), \n\nOutbox (reliability with non DTC transports)\n\nThe Particular Platform for monitoring, debugging and visualizing\n\nDoes this answer your question?\n\n========================================\n\nComments:\n- Good answer. Thanks\n- Is this a blog post? It should be.","metadata":{"transformedAt":"2026-08-18T18:33:20.127Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":36,"estimatedTokens":250}}130{"id":"stack-19163021","source":"stackoverflow","questionId":19163021,"title":"RabbitMQ how to throttle the consumer","tags":["rabbitmq"],"text":"Title: RabbitMQ how to throttle the consumer\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am using RabbitMQ successfully. However, I have a problem where if I get in the situation where there are lots of messages on the queue then the consumer (a Windows service) tries to get them all and then just holds on to them but never actions or acknowledges them.\n\nWhen the number of messages in the ready state is low then the consumers deal with the throughput fine, it is just if there has been an issue and there is a backlog then it gets far too greedy.\n\nIs there a way to configure the maximum number of messages that a consumer will try and take responsibility for at any one time?\n\nI can see the `RequestedChannelMax` field on `RabbitMQ.Client.ConnectionFactory` is that the correct setting to limit this?\n\nThanks\n\n========================================\n\nCode:\n```text\nRequestedChannelMax\n```\n\n```text\nRabbitMQ.Client.ConnectionFactory\n```\n\n========================================\n\nComments:\n- Related: stackoverflow.com/questions/29841690/how-to-consume-one-mess‌​age\n- Thanks this is a very comprehensive answer and got me right to what I needed. `_model.BasicQos(0,100,false);`","metadata":{"transformedAt":"2026-08-18T18:33:20.127Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":31,"estimatedTokens":301}}131{"id":"stack-47869390","source":"stackoverflow","questionId":47869390,"title":"RabbitMQ Connection Error \" None of the specified endpoints were reachable\"","tags":["c#","asp.net","rabbitmq"],"text":"Title: RabbitMQ Connection Error \" None of the specified endpoints were reachable\"\nTags: c#, asp.net, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI installed rabbitmq service on the server and on my system.\nI want to use RPC pattern:\n\n```\nvar factory = new ConnectionFactory() { \n HostName = \"158.2.14.42\", \n Port = Protocols.DefaultProtocol.DefaultPort, \n UserName = \"Administrator\", \n Password = \"@server@\", \n VirtualHost = \"/\"\n ContinuationTimeout = new TimeSpan(10, 0, 0, 0) \n};\n\nconnection = factory.CreateConnection();\n```\n\nI have an error on creating connection with this message:\n\nNone of the specified endpoints were reachable\n\nWhen I use it on localhost instance of the server it works, but when I create the connection from local to that server,it returned the error.\nIt not work with local ip and username and password of the my local computer.\n\nCan anyone help me?\n\n========================================\n\nTop Answer:\nI was also facing the same issue and later realized I have to open both ports i.e. 15672 and 5672.\n\nThe below command works for me in the docker container model.\n\n```\ndocker run -it --rm --name mymq -p 5672:5672 -p 15672:15672 rabbitmq:3-management\n```\n\nCode snippet:\n\n```\nvar factory = new RabbitMQ.Client.ConnectionFactory\n {\n Uri = new Uri(\"amqp://guest:guest@localhost:5672/\")\n };\n```\n\nor\n\n```\nvar factory = new ConnectionFactory() { HostName = \"localhost\" };\n```\n\n========================================\n\nCode:\n```text\nvar factory = new ConnectionFactory() { \n HostName = \"158.2.14.42\", \n Port = Protocols.DefaultProtocol.DefaultPort, \n UserName = \"Administrator\", \n Password = \"@server@\", \n VirtualHost = \"/\"\n ContinuationTimeout = new TimeSpan(10, 0, 0, 0) \n};\n\nconnection = factory.CreateConnection();\n```\n\n```text\nrabbitmq-plugins enable rabbitmq_management\n```\n\n```text\nservices.msc\n```\n\n```text\nhttp://localhost:15672\n```\n\n```text\n158.2.14.42\n```\n\n```text\n/\n```\n\n```text\n5672\n```\n\n```text\nrabbit.tcp_listeners\n```\n\n```text\nvar factory = new ConnectionFactory() { \n HostName = \"192.168.1.121\",\n Port = 5672,\n UserName = \"fancky\", \n Password = \"123456\" \n};\n```\n\n```text\nException information: \n Exception type: FileLoadException \n Exception message: Could not load file or assembly 'System.Threading.Channels, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)\n at RabbitMQ.Client.Framing.Impl.AutorecoveringConnection..ctor(ConnectionFactory factory, String clientProvidedName)\n at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName) in /_/projects/RabbitMQ.Client/client/api/ConnectionFactory.cs:line 494\n```\n\n```text\nSystem.Threading.Tasks.Extensions\n```\n\n```text\nInnerException\n```\n\n```text\ndocker run -it --rm --name mymq -p 5672:5672 -p 15672:15672 rabbitmq:3-management\n```\n\n```text\nvar factory = new RabbitMQ.Client.ConnectionFactory\n {\n Uri = new Uri(\"amqp://guest:guest@localhost:5672/\")\n };\n```\n\n```text\nvar factory = new ConnectionFactory() { HostName = \"localhost\" };\n```\n\n```text\nversion: '3'\nservices:\nrabbitmq:\ncontainer_name: rabbitmq\nhostname: \"rabbitmq\"\nimage: rabbitmq:3-management\nports:\n- \"5672:5672\"\n- \"15672:15672\"\nvolumes:\n- rabbitmq:/rabbitmq\nhealthcheck:\ntest: [\"CMD\", \"curl\", \"-f\", \"http://localhost:15672\"]\ninterval: 30s\ntimeout: 10s\nretries: 5\n\nisp_hub:\ndepends_on:\n- rabbitmq\nbuild:\ncontext: .\ndockerfile: Dockerfile\nports:\n- \"9090:80\"\n\nvolumes:\nrabbitmq:\n\nafter running the cmd docker-compose up the image is created and container is started and i am using Jmeter client to hit the container .net code is working but while trying to pass the data in queue getting below exception -\n\n\"log\":\"info: Microsoft.Hosting.Lifetime[0]\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:25:22.6109672Z\"}\n{\"log\":\" Application is shutting down...\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:25:22.6109672Z\"}\n{\"log\":\"info: Microsoft.Hosting.Lifetime[0]\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:25:38.4488984Z\"}\n{\"log\":\" Now listening on: http://[::]:80\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:25:38.4488984Z\"}\n{\"log\":\"info: Microsoft.Hosting.Lifetime[0]\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:25:38.4498991Z\"}\n{\"log\":\" Application started. Press Ctrl+C to shut down.\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:25:38.4498991Z\"}\n{\"log\":\"info: Microsoft.Hosting.Lifetime[0]\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:25:38.4498991Z\"}\n{\"log\":\" Hosting environment: Production\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:25:38.4498991Z\"}\n{\"log\":\"info: Microsoft.Hosting.Lifetime[0]\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:25:38.4498991Z\"}\n{\"log\":\" Content root path: C:\\app\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:25:38.4498991Z\"}\n{\"log\":\"fail: Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher[8]\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" Failed to invoke hub method 'SendToMessageBroker'.\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" ---\\u003e System.AggregateException: One or more errors occurred. (Connection failed)\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" ---\\u003e RabbitMQ.Client.Exceptions.ConnectFailureException: Connection failed\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" ---\\u003e System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it.\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" at System.Threading.Tasks.ValueTask.ValueTaskSourceAsTask.\\u003c\\u003ec.\\u003c.cctor\\u003eb__4_0(Object state)\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" --- End of stack trace from previous location ---\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" at RabbitMQ.Client.Impl.TcpClientAdapter.ConnectAsync(String host, Int32 port)\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" at RabbitMQ.Client.Impl.TaskExtensions.TimeoutAfter(Task task, TimeSpan timeout)\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectOrFail(ITcpClient socket, AmqpTcpEndpoint endpoint, TimeSpan timeout)\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" --- End of inner exception stack trace ---\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectOrFail(ITcpClient socket, AmqpTcpEndpoint endpoint, TimeSpan timeout)\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectUsingAddressFamily(AmqpTcpEndpoint endpoint, Func2 socketFactory, TimeSpan timeout, AddressFamily family)\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"} {\"log\":\" at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectUsingIPv4(AmqpTcpEndpoint endpoint, Func2 socketFactory, TimeSpan timeout)\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" at RabbitMQ.Client.Impl.SocketFrameHandler..ctor(AmqpTcpEndpoint endpoint, Func2 socketFactory, TimeSpan connectionTimeout, TimeSpan readTimeout, TimeSpan writeTimeout)\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"} {\"log\":\" at RabbitMQ.Client.Framing.Impl.IProtocolExtensions.CreateFrameHandler(IProtocol protocol, AmqpTcpEndpoint endpoint, Func2 socketFactory, TimeSpan connectionTimeout, TimeSpan readTimeout, TimeSpan writeTimeout)\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" at RabbitMQ.Client.ConnectionFactory.CreateFrameHandler(AmqpTcpEndpoint endpoint)\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" at RabbitMQ.Client.EndpointResolverExtensions.SelectOne[T](IEndpointResolver resolver, Func2 selector)\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"} {\"log\":\" --- End of inner exception stack trace ---\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"} {\"log\":\" at RabbitMQ.Client.EndpointResolverExtensions.SelectOne[T](IEndpointResolver resolver, Func2 selector)\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" at RabbitMQ.Client.Framing.Impl.AutorecoveringConnection.Init(IEndpointResolver endpoints)\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName)\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" --- End of inner exception stack trace ---\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName)\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" at RabbitMQ.Client.ConnectionFactory.CreateConnection(String clientProvidedName)\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" at RabbitMQ.Client.ConnectionFactory.CreateConnection()\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" at ISP_Hub.HubConfig.CenterHub.SendToMessageBroker(String requestData) in C:\\src\\ISP_Hub\\HubConfig\\CenterHub.cs:line 38\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" at Microsoft.Extensions.Internal.ObjectMethodExecutor.\\u003c\\u003ec__DisplayClass33_0.\\u003cWrapVoidMethod\\u003eb__0(Object target, Object[] parameters)\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n{\"log\":\" at Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher1.ExecuteMethod(ObjectMethodExecutor methodExecutor, Hub hub, Object[] arguments)\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"} {\"log\":\" at Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher1.\\u003c\\u003ec__DisplayClass16_0.\\u003c\\u003cInvoke\\u003eg__ExecuteInvocation|0\\u003ed.MoveNext()\\r\\n\",\"stream\":\"stdout\",\"time\":\"2022-04-04T08:26:55.7889752Z\"}\n\nrabbitmq connection code -\n\npublic void SendToMessageBroker(string requestData)\n{\nvar trace = JsonConvert.DeserializeObject(requestData);\n// string rabbitMqUrl = \"127.0.0.1\";\n// var factory = new ConnectionFactory() { HostName = \"172.24.17.225\", Port = 5672 };\n//var factory = new ConnectionFactory\n//{\n// HostName = rabbitMqUrl,\n// UserName = \"guest\",\n// Password = \"guest\",\n// Port = AmqpTcpEndpoint.UseDefaultPort,\n// VirtualHost = \"/\",\n// RequestedHeartbeat = new TimeSpan(60),\n// Ssl = { ServerName = rabbitMqUrl, Enabled = false }\n//};\nvar factory = new RabbitMQ.Client.ConnectionFactory\n{\nUri = new Uri(\"amqp://guest:guest@localhost:5672/\")\n};\nusing var conn = factory.CreateConnection();\nusing var channel = conn.CreateModel();\nRabbitMQPublisher.Publish(channel, trace);\nClients.All.SendAsync(\"test\");\nchannel.Close();\nconn.Close();\nDebug.WriteLine(\"Show Message: \" + requestData);\n\n }\ni am new to docker . please help me to understand the issue and how to resolve it\n```\n\n```text\nguest\n```\n\n```text\nguest\n```\n\n```text\nhost.docker.internal\n```\n\n```text\nlocalhost\n```\n\n========================================\n\nComments:\n- Possible duplicate of RabbitMQ C# connection trouble when using a username and password\n- @RazvanDumitru , I do like that but still have the error. and code doesn't recognize **FromEnvironment**\n- @RazvanDumitru Thank you,your guidance helped me.\n- @parsa what you have done for FromEnvironment ?\n- I Add **5672** port on widnows firewall of server, but it not solved.\n- Any recommendation? is there any solution that I must be do that?\n- It says as the default, RabbitMQ will listen on port 5672 on all available interfaces. on config file,must be I change on anything?\n- In my case I was working with another VHost, so go to \"Users\" => and then click on the \"virtual host\" dropdown, select your VHost and click on \"set permission\". Works like a charm\n- This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review","metadata":{"transformedAt":"2026-08-18T18:33:20.127Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":20,"totalLines":272,"estimatedTokens":3222}}132{"id":"stack-11142071","source":"stackoverflow","questionId":11142071,"title":"RabbitMQ-- selectively retrieving messages from a queue","tags":["rabbitmq"],"text":"Title: RabbitMQ-- selectively retrieving messages from a queue\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm new to RabbitMQ and was wondering of a good approach to this problem I'm mulling over. I want to create a service that subscribes to a queue and only pulls messages that meet a specific criteria; for instance, if a specific subject header is in the message.\n\nI'm still learning about RabbitMQ, and was looking for tips on how to approach this. My questions include: how can the consumer pull only specific messages from the queue? How can the producer set a subject header in the message (if that's even the right term?)\n\n========================================\n\nTop Answer:\nMaking the best of exchange/routing of rabbitmq is recommended. If you do want to check according to the message content, the following code is a viable solution.\n\nRetrieve messages from a queue and check, selectively ack the messages in which you're interested.\n\n**pull one message**\n\n```\nGetResponse resp = channel.basicGet(QUEUE_NAME, false);\n```\n\n**ack one message**\n\n```\nchannel.basicAck(resp.getEnvelope().getDeliveryTag(), false);\n```\n\nExample\n\n```\nimport com.rabbitmq.client.*;\n\npublic class ReceiveLogs {\n private final static String QUEUE_NAME = \"hello\";\n\n public static void main(String[] argv) throws Exception {\n ConnectionFactory factory = new ConnectionFactory();\n factory.setHost(\"localhost\");\n try(Connection connection = factory.newConnection();\n Channel channel = connection.createChannel();){\n\n channel.queueDeclare(QUEUE_NAME, true, false, false, null);\n\n // pull one message and ack manually and exit\n GetResponse resp = channel.basicGet(QUEUE_NAME, false);\n if( resp != null ){\n String message = new String(resp.getBody(), \"UTF-8\");\n System.out.println(\" [x] Received '\" + message + \"'\");\n channel.basicAck(resp.getEnvelope().getDeliveryTag(), false);\n }\n System.out.println();\n }\n }\n}\n```\n\n**dependency**\n\n```\ncompile group: 'com.rabbitmq', name: 'amqp-client', version: '5.8.0'\n```\n\n========================================\n\nCode:\n```cs\npublic WebClient GetRabbitMqConnection(string userName, string password)\n{\n var client = new WebClient(); \n client.Credentials = new NetworkCredential(userName, password);\n return client;\n}\n```\n\n```cs\npublic string GetRabbitMQMessages(string domainName, string port, \n string queueName, string virtualHost, WebClient client, string methodType)\n{\n string messageResult = string.Empty;\n string strUri = \"http://\" + domainName + \":\" + port + \n \"/api/queues/\" + virtualHost + \"/\";\n var data = client.DownloadString(strUri + queueName + \"/\");\n var queueInfo = JsonConvert.DeserializeObject<QueueInfo>(data);\n if (queueInfo == null || queueInfo.messages == 0)\n return string.Empty;\n if (methodType == \"POST\")\n {\n string postbody = \" \n {\\\"ackmode\\\":\\\"ack_requeue_true\\\",\\\"count\\\":\n \\\"$totalMessageCount\\\",\\\"name\\\":\\\"${DomainName}\\\",\n \\\"requeue\\\":\\\"false\\\",\\\"encoding\\\":\\\"auto\\\",\\\"vhost\\\" :\n \\\"${QueueName}\\\"}\";\n postbody = postbody\n .Replace(\"$totalMessageCount\", queueInfo.messages.ToString())\n .Replace(\"${DomainName}\", domainName)\n .Replace(\"${QueueName}\", queueName);\n messageResult = client.UploadString(strUri + queueName + \n \"/get\", \"POST\", postbody);\n }\n return messageResult;\n}\n```\n\n```text\nBoolean autoAck = false;\nmodel.BasicConsume(Queuename, autoAck);\nmodel.BasicGet(\"Queuename\", false);\nmodel.BasicGet(\"Queuename\", false);\n```\n\n```text\nGetResponse resp = channel.basicGet(QUEUE_NAME, false);\n```\n\n```text\nchannel.basicAck(resp.getEnvelope().getDeliveryTag(), false);\n```\n\n```text\nimport com.rabbitmq.client.*;\n\npublic class ReceiveLogs {\n private final static String QUEUE_NAME = \"hello\";\n\n public static void main(String[] argv) throws Exception {\n ConnectionFactory factory = new ConnectionFactory();\n factory.setHost(\"localhost\");\n try(Connection connection = factory.newConnection();\n Channel channel = connection.createChannel();){\n\n channel.queueDeclare(QUEUE_NAME, true, false, false, null);\n\n // pull one message and ack manually and exit\n GetResponse resp = channel.basicGet(QUEUE_NAME, false);\n if( resp != null ){\n String message = new String(resp.getBody(), \"UTF-8\");\n System.out.println(\" [x] Received '\" + message + \"'\");\n channel.basicAck(resp.getEnvelope().getDeliveryTag(), false);\n }\n System.out.println();\n }\n }\n}\n```\n\n```text\ncompile group: 'com.rabbitmq', name: 'amqp-client', version: '5.8.0'\n```\n\n========================================\n\nComments:\n- If really your consumer has to **subscribe** (not interested in messages being published *before* the subscription), the subscription (and binding with selection rule) is not to an existing *queue* but to an existing *exchange* (as answered below).. Then, the question's wording should be edited.\n- Do you mean consumer can retrieve message with specific routing-key in one queue? It looks like consumer don't have choice, it just receive all messages from queue.\n- @ThemeZ consumers receive all messages from the queue. I think that is by definition. The point here is that they are filtered at the exchange level. With a topic exchange the queue will only receive certain messages. That way a consumer will on read the messages they want because the queue only receives the messages that the consumer wants.\n- I don't think this answers the question. The question is about having a single queue called \"log\" and the Consumer able to consume only 'info' logs from the queue.\n- In fairness the author wants to do something that queues are specifically not designed to do. I was merely proposing a solution that would work.\n- Hello Punit. Welcome to StackOverflow. It seems like your answer doesn't answer the question. He was asking \"how can the consumer **pull only specific messages** from the queue\" and \"how can the producer **set a subject header in the message**\". Your answer seems to be about connecting to the `RabbitMQ` server and retrieving data in general. He wants to pull specific messages that may have headers in the message. Please consider revising your answer. Additionally, please take the time to reformat it as it appears that there are sections that aren't code, but are formatted as code.\n- Hey bro Ishaan, this is rabbitmq you need to retrieve messages from perticular Queue to user define list then apply linq to filter your perticular message .... you need to apply your own logic .... All the best !\n- Hi, this is quite far from answering the question. Also the existing answers provide better explanation on how to get specific messages out of a queue.","metadata":{"transformedAt":"2026-08-18T18:33:20.127Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":161,"estimatedTokens":1724}}133{"id":"stack-60407082","source":"stackoverflow","questionId":60407082,"title":"Rabbit mq - Error while waiting for Mnesia tables","tags":["kubernetes","rabbitmq","google-kubernetes-engine","kubernetes-helm","rabbitmq-exchange"],"text":"Title: Rabbit mq - Error while waiting for Mnesia tables\nTags: kubernetes, rabbitmq, google-kubernetes-engine, kubernetes-helm, rabbitmq-exchange\nSource: Stack Overflow\n\nQuestion:\nI have installed rabbitmq using helm chart on a kubernetes cluster. The rabbitmq pod keeps restarting. On inspecting the pod logs I get the below error\n\n```\n2020-02-26 04:42:31.582 [warning] Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_durable_queue]}\n2020-02-26 04:42:31.582 [info] Waiting for Mnesia tables for 30000 ms, 6 retries left\n```\n\nWhen I try to do kubectl describe pod I get this error\n\n```\nConditions:\n Type Status\n Initialized True\n Ready False\n ContainersReady False\n PodScheduled True\nVolumes:\n data:\n Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)\n ClaimName: data-rabbitmq-0\n ReadOnly: false\n config-volume:\n Type: ConfigMap (a volume populated by a ConfigMap)\n Name: rabbitmq-config\n Optional: false\n healthchecks:\n Type: ConfigMap (a volume populated by a ConfigMap)\n Name: rabbitmq-healthchecks\n Optional: false\n rabbitmq-token-w74kb:\n Type: Secret (a volume populated by a Secret)\n SecretName: rabbitmq-token-w74kb\n Optional: false\nQoS Class: Burstable\nNode-Selectors: beta.kubernetes.io/arch=amd64\nTolerations: node.kubernetes.io/not-ready:NoExecute for 300s\n node.kubernetes.io/unreachable:NoExecute for 300s\nEvents:\n Type Reason Age From Message\n ---- ------ ---- ---- -------\n Warning Unhealthy 3m27s (x878 over 7h21m) kubelet, gke-analytics-default-pool-918f5943-w0t0 Readiness probe failed: Timeout: 70 seconds ...\nChecking health of node rabbit@rabbitmq-0.rabbitmq-headless.default.svc.cluster.local ...\nStatus of node rabbit@rabbitmq-0.rabbitmq-headless.default.svc.cluster.local ...\nError:\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\"$1\", :_, :_}, [], [:\"$1\"]}]]}}\nError:\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\"$1\", :_, :_}, [], [:\"$1\"]}]]}}\n```\n\nI have provisioned the above on Google Cloud on a kubernetes cluster. I am not sure during what specific situation it started failing. I had to restart the pod and since then it has been failing. \n\nWhat is the issue here ?\n\n========================================\n\nTop Answer:\n**Edit**\n\nApparently, this is not a good approach, even though it „works“. See @Michael Klishin answer below.\n\n### Original answer\n\n**TLDR**\n\n`helm upgrade rabbitmq --set clustering.forceBoot=true`\n\n**Problem**\n\nThe problem happens for the following reason:\n\n- All RMQ pods are terminated at the same time due to some reason (maybe because you explicitly set the StatefulSet replicas to 0, or something else)\n\n- One of them is the last one to stop (maybe just a tiny bit after the others). It stores this condition (\"I'm standalone now\") in its filesystem, which in k8s is the PersistentVolume(Claim). Let's say this pod is rabbitmq-1.\n\n- When you spin the StatefulSet back up, the pod rabbitmq-0 is always the first to start (see here).\n\n- During startup, pod rabbitmq-0 first checks whether it's supposed to run standalone. But as far as it can see on its own filesystem, it's part of a cluster. So it checks for its peers and doesn't find any. This results in a startup failure by default.\n\n- rabbitmq-0 thus never becomes ready.\n\n- rabbitmq-1 is never starting because that's how StatefulSets are deployed - one after another. If it were to start, it would start successfully because it sees that it can run standalone as well.\n\nSo in the end, it's a bit of a mismatch between how RabbitMQ and StatefulSets work. RMQ says: \"if everything goes down, just start everything and the same time, one will be able to start and as soon as this one is up, the others can rejoin the cluster.\" k8s StatefulSets say: \"starting everything all at once is not possible, we'll start with the 0\".\n\n**Solution**\n\nTo fix this, there is a force_boot command for rabbitmqctl which basically tells an instance to start standalone if it doesn't find any peers. How you can use this from Kubernetes depends on the Helm chart and container you're using. In the Bitnami Chart, which uses the Bitnami Docker image, there is a value `clustering.forceBoot = true`, which translates to an env variable `RABBITMQ_FORCE_BOOT = yes` in the container, which will then issue the above command for you.\n\nBut looking at the problem, you can also see why deleting PVCs will work (other answer). The pods will just all \"forget\" that they were part of a RMQ cluster the last time around, and happily start. I would prefer the above solution though, as no data is being lost.\n\n========================================\n\nCode:\n```text\n2020-02-26 04:42:31.582 [warning] <0.314.0> Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_durable_queue]}\n2020-02-26 04:42:31.582 [info] <0.314.0> Waiting for Mnesia tables for 30000 ms, 6 retries left\n```\n\n```text\nConditions:\n Type Status\n Initialized True\n Ready False\n ContainersReady False\n PodScheduled True\nVolumes:\n data:\n Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)\n ClaimName: data-rabbitmq-0\n ReadOnly: false\n config-volume:\n Type: ConfigMap (a volume populated by a ConfigMap)\n Name: rabbitmq-config\n Optional: false\n healthchecks:\n Type: ConfigMap (a volume populated by a ConfigMap)\n Name: rabbitmq-healthchecks\n Optional: false\n rabbitmq-token-w74kb:\n Type: Secret (a volume populated by a Secret)\n SecretName: rabbitmq-token-w74kb\n Optional: false\nQoS Class: Burstable\nNode-Selectors: beta.kubernetes.io/arch=amd64\nTolerations: node.kubernetes.io/not-ready:NoExecute for 300s\n node.kubernetes.io/unreachable:NoExecute for 300s\nEvents:\n Type Reason Age From Message\n ---- ------ ---- ---- -------\n Warning Unhealthy 3m27s (x878 over 7h21m) kubelet, gke-analytics-default-pool-918f5943-w0t0 Readiness probe failed: Timeout: 70 seconds ...\nChecking health of node rabbit@rabbitmq-0.rabbitmq-headless.default.svc.cluster.local ...\nStatus of node rabbit@rabbitmq-0.rabbitmq-headless.default.svc.cluster.local ...\nError:\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\"$1\", :_, :_}, [], [:\"$1\"]}]]}}\nError:\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\"$1\", :_, :_}, [], [:\"$1\"]}]]}}\n```\n\n```text\nkind: Service\napiVersion: v1\nmetadata:\n namespace: rabbitmq-namespace\n name: rabbitmq\n labels:\n app: rabbitmq\n type: LoadBalancer \nspec:\n type: NodePort\n ports:\n - name: http\n protocol: TCP\n port: 15672\n targetPort: 15672\n nodePort: 31672\n - name: amqp\n protocol: TCP\n port: 5672\n targetPort: 5672\n nodePort: 30672\n - name: stomp\n protocol: TCP\n port: 61613\n targetPort: 61613\n selector:\n app: rabbitmq\n---\nkind: Service \napiVersion: v1\nmetadata:\n namespace: rabbitmq-namespace\n name: rabbitmq-lb\n labels:\n app: rabbitmq\nspec:\n # Headless service to give the StatefulSet a DNS which is known in the cluster (hostname-#.app.namespace.svc.cluster.local, )\n # in our case - rabbitmq-#.rabbitmq.rabbitmq-namespace.svc.cluster.local \n clusterIP: None\n ports:\n - name: http\n protocol: TCP\n port: 15672\n targetPort: 15672\n - name: amqp\n protocol: TCP\n port: 5672\n targetPort: 5672\n - name: stomp\n port: 61613\n selector:\n app: rabbitmq\n---\napiVersion: v1\nkind: ConfigMap\nmetadata:\n name: rabbitmq-config\n namespace: rabbitmq-namespace\ndata:\n enabled_plugins: |\n [rabbitmq_management,rabbitmq_peer_discovery_k8s,rabbitmq_stomp].\n\n rabbitmq.conf: |\n ## Cluster formation. See http://www.rabbitmq.com/cluster-formation.html to learn more.\n cluster_formation.peer_discovery_backend = rabbit_peer_discovery_k8s\n cluster_formation.k8s.host = kubernetes.default.svc.cluster.local\n ## Should RabbitMQ node name be computed from the pod's hostname or IP address?\n ## IP addresses are not stable, so using [stable] hostnames is recommended when possible.\n ## Set to \"hostname\" to use pod hostnames.\n ## When this value is changed, so should the variable used to set the RABBITMQ_NODENAME\n ## environment variable.\n cluster_formation.k8s.address_type = hostname \n ## Important - this is the suffix of the hostname, as each node gets \"rabbitmq-#\", we need to tell what's the suffix\n ## it will give each new node that enters the way to contact the other peer node and join the cluster (if using hostname)\n cluster_formation.k8s.hostname_suffix = .rabbitmq.rabbitmq-namespace.svc.cluster.local\n ## How often should node cleanup checks run?\n cluster_formation.node_cleanup.interval = 30\n ## Set to false if automatic removal of unknown/absent nodes\n ## is desired. This can be dangerous, see\n ## * http://www.rabbitmq.com/cluster-formation.html#node-health-checks-and-cleanup\n ## * https://groups.google.com/forum/#!msg/rabbitmq-users/wuOfzEywHXo/k8z_HWIkBgAJ\n cluster_formation.node_cleanup.only_log_warning = true\n cluster_partition_handling = autoheal\n ## See http://www.rabbitmq.com/ha.html#master-migration-data-locality\n queue_master_locator=min-masters\n ## See http://www.rabbitmq.com/access-control.html#loopback-users\n loopback_users.guest = false\n---\napiVersion: apps/v1\nkind: StatefulSet\nmetadata:\n name: rabbitmq\n namespace: rabbitmq-namespace\nspec:\n serviceName: rabbitmq\n replicas: 3\n selector:\n matchLabels:\n name: rabbitmq\n template:\n metadata:\n labels:\n app: rabbitmq\n name: rabbitmq\n state: rabbitmq\n annotations:\n pod.alpha.kubernetes.io/initialized: \"true\"\n spec:\n serviceAccountName: rabbitmq\n terminationGracePeriodSeconds: 10\n containers: \n - name: rabbitmq-k8s\n image: rabbitmq:3.8.3\n volumeMounts:\n - name: config-volume\n mountPath: /etc/rabbitmq\n - name: data\n mountPath: /var/lib/rabbitmq/mnesia\n ports:\n - name: http\n protocol: TCP\n containerPort: 15672\n - name: amqp\n protocol: TCP\n containerPort: 5672\n livenessProbe:\n exec:\n command: [\"rabbitmqctl\", \"status\"]\n initialDelaySeconds: 60\n periodSeconds: 60\n timeoutSeconds: 10\n resources:\n requests:\n memory: \"0\"\n cpu: \"0\"\n limits:\n memory: \"2048Mi\"\n cpu: \"1000m\"\n readinessProbe:\n exec:\n command: [\"rabbitmqctl\", \"status\"]\n initialDelaySeconds: 20\n periodSeconds: 60\n timeoutSeconds: 10\n imagePullPolicy: Always\n env:\n - name: MY_POD_IP\n valueFrom:\n fieldRef:\n fieldPath: status.podIP\n - name: NAMESPACE\n valueFrom:\n fieldRef:\n fieldPath: metadata.namespace\n - name: HOSTNAME\n valueFrom:\n fieldRef:\n fieldPath: metadata.name\n - name: RABBITMQ_USE_LONGNAME\n value: \"true\"\n # See a note on cluster_formation.k8s.address_type in the config file section\n - name: RABBITMQ_NODENAME\n value: \"rabbit@$(HOSTNAME).rabbitmq.$(NAMESPACE).svc.cluster.local\"\n - name: K8S_SERVICE_NAME\n value: \"rabbitmq\"\n - name: RABBITMQ_ERLANG_COOKIE\n value: \"mycookie\" \n volumes:\n - name: config-volume\n configMap:\n name: rabbitmq-config\n items:\n - key: rabbitmq.conf\n path: rabbitmq.conf\n - key: enabled_plugins\n path: enabled_plugins\n volumeClaimTemplates:\n - metadata:\n name: data\n spec:\n accessModes:\n - \"ReadWriteOnce\"\n storageClassName: \"default\"\n resources:\n requests:\n storage: 3Gi\n\n---\napiVersion: v1\nkind: ServiceAccount\nmetadata:\n name: rabbitmq \n namespace: rabbitmq-namespace \n---\nkind: Role\napiVersion: rbac.authorization.k8s.io/v1beta1\nmetadata:\n name: endpoint-reader\n namespace: rabbitmq-namespace \nrules:\n- apiGroups: [\"\"]\n resources: [\"endpoints\"]\n verbs: [\"get\"]\n---\nkind: RoleBinding\napiVersion: rbac.authorization.k8s.io/v1beta1\nmetadata:\n name: endpoint-reader\n namespace: rabbitmq-namespace\nsubjects:\n- kind: ServiceAccount\n name: rabbitmq\nroleRef:\n apiGroup: rbac.authorization.k8s.io\n kind: Role\n name: endpoint-reader\n```\n\n```text\nhelm upgrade rabbitmq --set clustering.forceBoot=true\n```\n\n```text\nclustering.forceBoot = true\n```\n\n```text\nRABBITMQ_FORCE_BOOT = yes\n```\n\n```text\nkubectl scale statefulsets rabbitmq-1-rabbitmq --namespace teps-rabbitmq --replicas=1\n```\n\n```text\nkubectl exec -it rabbitmq-1-rabbitmq-0 -n Rabbit\n```\n\n```text\nrabbitmqctl stop_app\nrabbitmqctl force_boot\n```\n\n```text\nkubectl scale statefulsets rabbitmq-1-rabbitmq --namespace teps-rabbitmq --replicas=4\n```\n\n```text\nspec:\n containers:\n - env:\n - name: RABBITMQ_FORCE_BOOT # New Line 1 Added\n value: \"yes\" # New Line 2 Added\n```\n\n```text\nkubectl -n rabbitmq edit statefulsets.apps rabbitmq\n```\n\n```text\nforce_boot\n```\n\n```text\npodManagementPolicy: parallel\n```\n\n```text\npodManagementPolicy: parallel\n```\n\n```text\nlifecycle:\n postStart:\n exec:\n command:\n - /bin/bash\n - -c\n - rabbitmqctl force_boot\n - rabbitmqctl start_app\n - ... (unchanged)\n```\n\n```text\n- rabbitmqctl\n- stop_app\n```\n\n```text\nspec:\n template:\n spec:\n containers:\n - name: rabbitmq\n lifecycle:\n postStart:\n exec:\n command:\n - /bin/bash\n - -c\n - |\n # Existing postStart logic (unchanged)\n preStop:\n exec:\n command:\n - rabbitmqctl\n - stop_app\n```\n\n```text\nrabbitmqctl force_boot, rabbitmqctl start_app\n```\n\n========================================\n\nComments:\n- Have you tried to describe the running pod? Could you provide more information about your setup? Is it cloud provisioned? Is it failing on specific terms or just fails after the `helm install`?\n- This is the error I get. I have updated the question with the error details `Error: {:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\"$1\", :_, :_}, [], [:\"$1\"]}]]}} Error: {:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\"$1\", :_, :_}, [], [:\"$1\"]}]]}}`\n- Which exactly helm chart did you use?\n- ok let me test with the latest helm chart and try once again\n- This is the helm chart that I used. github.com/helm/charts/tree/master/stable/rabbitmq. These are values that I used - github.com/helm/charts/blob/master/stable/rabbitmq/… This part alone was commented in values-production.yaml # extraPlugins: \"rabbitmq_auth_backend_ldap\n- When I uninstalled and installed rabbitmq using helm it was using the same persistent volume. I tried deleting the persistent volume and reinstalled rabbitmq. The pods are running now without any error. Thanks for the help\n- Could you solve your problem?\n- @AmirSoleimani - Your solutions works\n- Be aware that deleting persistent volume claims may destroy your data. Wouldn't do this in production.\n- i agree that generally deleting persistent volumes can make you lose your data. but specifically for rabbitmq developers (and many other rabbitmq users i know) we don't need or want or use any rabbitmq persistance features. my colleague informed me that he sets the helm `persistance` to false and doesn't have any `pvc` for rabbitmq. which is what i'll try too.\n- your solution of deleting the pod and pvc worked for me. i think rabbitmq was not shutdown gracefully and that resulted in the mnesia files getting corrupted and so by deleting the pvc and pod i got a new pod with an empty pvc and so the helm chart for rabbitmq was able to finally come back online successfully.\n- running rabbitmq helm chart with persistance set to `false` definitely is better: 1. more simple config 2. less resources requested from kubernetes 3. better robustness to coming up and down 4. more reliable (no need for me to write a custom script to check for bad state and then deleting pod/pvc)\n- For anyone else here else experiencing the same issue in tandem with Docker. I experienced this as well and saw this answer.Deleting the RabbitMQ Docker container and having it re-pull the image fixed the issue for our application.\n- I tried a lot to solve the problem, in the end, I used the RabbitMQ operator. rabbitmq.com/kubernetes/operator/operator-overview.html\n- To be honest, this is not really helpful. Why would somebody want to just try it out, along with a bunch of configuration which is not relevant to him/her?\n- @HarisOsmanagić you can edit configmap depends on your usage.\n- No, I can't, because there's too much in it. Everybody would appreciate seeing the exact parameter which fixes an issue, and not having to experiment with another config map.\n- Also, there is a section about recovery at the Bitnami github, which mentions both forceBoot and one more option (using Parallel podManagementPolicy) github.com/bitnami/charts/tree/master/bitnami/…\n- (1.) FYI the same issue \"Error while waiting for Mnesia tables\" happens when you have 3 machines running rabbitmq and configured for clustering. so it's not just a kubernetes, helm issue. (2.) unfortunately for rabbitmq there is no config file setting for clustering.forceBoot. so i will have to clear out the /var/lib/rabbitmq/mnesia to get the servers to start. all of them right now are stuck in a boot loop... \"inconsistent_database\". (3.) in my case if you stop your rabbit cluster with server1,2,3 then then you MUST start in LIFO order i.e. 3,2,1. this allows you to start without issue.\n- relevant rabbitmq docs: rabbitmq.com/clustering.html#restarting\n- This should be marked as answer. Thank you Ulli, you saved me hours of troubleshooting!\n- I had to add `podManagementPolicy=Parallel` as well. Even with the `forceBoot` option `rabbitmq-0` was not starting\n- I am right now in a situation in single node docker swarm (where ordering isn't enforced by statefulset). I started all three rabbitmq nodes (3 services, not 1 with 2 replicas) at the same time after docker upgrade and they are all waiting on each other. Somehow the shutdown caused by containerd restart caused them to think that none of them is the master now and they refuse to elect one. I will set rabbit1 forceBoot=true and see what happens. (Related issue here: github.com/helm/charts/issues/13485)\n- this is dangerous advice and should not be used as a standard way of running RabbitMQ. See details in stackoverflow.com/a/78439528/659818 by @Michael Klishin\n- FYI i found out a discussion about this on the bitnami repository github.com/bitnami/charts/issues/16081 there is no need to force-reboot. Just set the sts podManagementPolicy as Parallel\n- Fully agree here\n- What are the required changes for RabbitMQ version `4.1` . I have been trying `podManagementPolicy: parallel` with the readiness probe `rabbitmq-diagnostics ping`. This was *working fine* with `3.*` and stopped working after upgrading to `4.1`. For `4.1`, it works right away with `podManagementPolicy: \"OrderedReady\"`. Only after stopping an Azure AKS Kubernetes cluster with the command `az aks stop --name --resource-group ` and then starting, the RabbitMQ cluster gets stuck at the first rabbitmq-0 replica - I have 3 replicas. Deleting of PVCs required?","metadata":{"transformedAt":"2026-08-18T18:33:20.128Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":19,"totalLines":487,"estimatedTokens":4947}}134{"id":"stack-10375137","source":"stackoverflow","questionId":10375137,"title":"Is there a FIFO message queuing service offering the high availability of Amazon SQS?","tags":["amazon-ec2","activemq-classic","rabbitmq","zeromq","amazon-sqs"],"text":"Title: Is there a FIFO message queuing service offering the high availability of Amazon SQS?\nTags: amazon-ec2, activemq-classic, rabbitmq, zeromq, amazon-sqs\nSource: Stack Overflow\n\nQuestion:\nWould have loved to use Amazon SQS if it provided some semblance of FIFO access, but the sequence seems to completely random.\n\nIs there something that would provide me FIFO queuing as-a-cloud-service with the high availability of SQS?\n\nIf that is asking for too much - what would be the easiest way of putting together something with the above requirements in EC2? Or maybe in other words, what's the easiest highly available queuing solution that works in EC2?\n\nThanks for your insights!\n\n========================================\n\nTop Answer:\nCheck out RabitMQ and StormMQ.\n\n========================================\n\nComments:\n- StormMQ looks interesting, but it seems hard to find information about their pricing from their website. Also they seem to be in a closed BETA. On RabbitMQ I didn't find any hosted solution on their website - is there one that you can point me to?\n- I work at Iron.io and can confirm that IronMQ orders messages FIFO.\n- @EvanShaw: Thanks much, proactive support like this is highly appreciated :)\n- Thanks a bunch. I will go research these options and post back.\n- @EvanShaw: is it only FIFO or is EOIO (Exactly Once In Order)?\n- Rabbitmq: From 2.7.0 the relative order of re-queued messages from a single consumer is preserved. Therefore, if another consumer receives them later, they will be consumed in the same order they originally appeared. Of course, if two or more consumers on the same queue fail, there is no guarantee that messages re-queued by distinct consumers will retain their relative order. But in the majority of cases where order matters, this guarantee should be enough\n- The only way to access IronMQ's pricing is through Archive.org (anno 2014 or 2015); unfortunately it seems IronMQ doesn't qualify for \"How to sell software in 2017\".","metadata":{"transformedAt":"2026-08-18T18:33:20.128Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":28,"estimatedTokens":495}}135{"id":"stack-57258424","source":"stackoverflow","questionId":57258424,"title":"What is the difference between ConcurrencyLimit and PrefetchCount?","tags":["c#","rabbitmq","masstransit"],"text":"Title: What is the difference between ConcurrencyLimit and PrefetchCount?\nTags: c#, rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nWhat is the difference between ConcurrencyLimit and PrefetchCount in masstransit? and what is the optimize configuration for them.\n\n========================================\n\nCode:\n```text\nPrefetchCount\n```\n\n```text\nConcurrentMessageLimit\n```\n\n========================================\n\nComments:\n- From this page: *\"PrefetchCount should be relatively high, a multiple of your concurrency limit for all message types so that RabbitMQ doesn't choke delivery messages due to network delays.\"*\n- @RobertHarvey i read that page before, but i dont know what PrefetchCount and ConcurrencyLimit exactly do and what conditions i should consider to set their values","metadata":{"transformedAt":"2026-08-18T18:33:20.128Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":23,"estimatedTokens":199}}136{"id":"stack-7734597","source":"stackoverflow","questionId":7734597,"title":"How to know when a set of RabbitMQ tasks are complete?","tags":["sql","messaging","rabbitmq"],"text":"Title: How to know when a set of RabbitMQ tasks are complete?\nTags: sql, messaging, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am using RabbitMQ to have worker processes encode video files. I would like to know when all of the files are complete - that is, when all of the worker processes have finished.\n\nThe only way I can think to do this is by using a database. When a video finishes encoding:\n\n```\nUPDATE videos SET status = 'complete' WHERE filename = 'foo.wmv'\n-- etc etc etc as each worker finishes --\n```\n\nAnd then to check whether or not all of the videos have been encoded:\n\n```\nSELECT count(*) FROM videos WHERE status != 'complete'\n```\n\nBut if I'm going to do this, then I feel like I am losing the benefit of RabbitMQ as a mechanism for multiple distributed worker processes, since I still have to manually maintain a database queue.\n\nIs there a standard mechanism for RabbitMQ dependencies? That is, a way to say \"wait for these 5 tasks to finish, and once they are done, then kick off a new task?\"\n\nI don't want to have a parent process add these tasks to a queue and then \"wait\" for each of them to return a \"completed\" status. Then I have to maintain a separate process for each group of videos, at which point I've lost the advantage of decoupled worker processes as compared to a single ThreadPool concept.\n\nAm I asking for something which is impossible? Or, are there standard widely-adopted solutions to manage the overall state of tasks in a queue that I have missed?\n\nEdit: after searching, I found this similar question: Getting result of a long running task with RabbitMQ\n\nAre there any particular thoughts that people have about this?\n\n========================================\n\nTop Answer:\nhttps://i.sstatic.net/SEop7.png\n\nBased on Brendan's extremely helpful answer, which should be accepted, I knocked up this quick diagram which be helpful to some.\n\n========================================\n\nCode:\n```text\nUPDATE videos SET status = 'complete' WHERE filename = 'foo.wmv'\n-- etc etc etc as each worker finishes --\n```\n\n```text\nSELECT count(*) FROM videos WHERE status != 'complete'\n```\n\n```text\nnumSent == numResponded\n```\n\n========================================\n\nComments:\n- Thumbs up for referring to the pattern name.","metadata":{"transformedAt":"2026-08-18T18:33:20.128Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":59,"estimatedTokens":564}}137{"id":"stack-47874958","source":"stackoverflow","questionId":47874958,"title":"RabbitMQ failed to start, TCP connection succeeded but Erlang distribution failed","tags":["server","rabbitmq","erlang"],"text":"Title: RabbitMQ failed to start, TCP connection succeeded but Erlang distribution failed\nTags: server, rabbitmq, erlang\nSource: Stack Overflow\n\nQuestion:\nI'm a new one just start to learn and install RabbitMQ on Windows System.\n\nI install Erlang VM and RabbitMQ in custom folder, not default folder (Both of them).\n\nThen I have restarted my computer.\n\n**By the way,My Computer name is \"NULL\"**\n\nI cd to the **RabbitMQ/sbin** folder and use command:\n\n`rabbitmqctl status`\n\nBut the return message is:\n\n Status of node rabbit@NULL ...\n\n \n Error: unable to perform an operation on node 'rabbit@NULL'. \n Please see diagnostics information and suggestions below.\n\n \n Most common reasons for this are:\n\n \n \n \n- Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)\n \n- CLI tool fails to authenticate with the server (e.g. due to CLI tool's Erlang cookie not matching that of the server)\n \n- Target node is not running\n \n \n In addition to the diagnostics info below:\n\n \n \n \n- See the CLI, clustering and networking guides on http://rabbitmq.com/documentation.html to learn more\n \n- Consult server logs on node rabbit@NULL\n \n \n DIAGNOSTICS\n\n \n attempted to contact: [rabbit@NULL]\n\n \n rabbit@NULL:\n\n \n \n \n- connected to epmd (port 4369) on NULL\n \n- epmd reports node 'rabbit' uses port 25672 for inter-node and CLI tool traffic\n TCP connection succeeded but Erlang distribution failed\n\n Authentication failed (rejected by the remote node), please check the Erlang cookie\n\n \n \n Current node details:\n\n \n \n \n- node name: rabbitmqcli70@NULL\n \n- effective user's home directory: C:\\Users\\Jerry Song\n \n- Erlang cookie hash: 51gvGHZpn0gIK86cfiS7vp==\n \n\nI have try to RESTART RabbitMQ, What I get is:\n\n ERROR: node with name \"rabbit\" already running on \"NULL\"\n\n **By the way,My Computer name is \"NULL\"**\n **And I have enable all ports in firewall.**\n\n========================================\n\nTop Answer:\nhttps://groups.google.com/forum/#!topic/rabbitmq-users/a6sqrAUX_Fg\ndescribes the problem where there is a cookie mismatch on a fresh installation of Rabbit MQ. The easy solution on windows is to synchronize the cookies \n\nAlso described here: http://www.rabbitmq.com/clustering.html#erlang-cookie\n\nEnsure cookies are synchronized across 1, 2 and Optionally 3 below \n\n`%HOMEDRIVE%%HOMEPATH%\\.erlang.cookie` (usually `C:\\Users\\%USERNAME%\\.erlang.cookie` for user %USERNAME%) if both the HOMEDRIVE and HOMEPATH environment variables are set\n\n`%USERPROFILE%\\.erlang.cookie` (usually `C:\\Users\\%USERNAME%\\.erlang.cookie`) if **HOMEDRIVE** and **HOMEPATH** are not both set\n\n- For the RabbitMQ Windows service - `%USERPROFILE%\\.erlang.cookie` (usually `C:\\WINDOWS\\system32\\config\\systemprofile`)\n\nThe cookie file used by the *Windows service account* and the user running CLI tools must be synchronized by copying the one from `C:\\WINDOWS\\system32\\config\\systemprofile` folder.\n\n========================================\n\nCode:\n```text\nrabbitmqctl status\n```\n\n```text\nrabbitmqctl status\n```\n\n```text\n%HOMEDRIVE%%HOMEPATH%\\.erlang.cookie\n```\n\n```text\nC:\\Users\\%USERNAME%\\.erlang.cookie\n```\n\n```text\n%USERPROFILE%\\.erlang.cookie\n```\n\n```text\nC:\\Users\\%USERNAME%\\.erlang.cookie\n```\n\n```text\n%USERPROFILE%\\.erlang.cookie\n```\n\n```text\nC:\\WINDOWS\\system32\\config\\systemprofile\n```\n\n```text\nC:\\WINDOWS\\system32\\config\\systemprofile\n```\n\n```text\n$pathvargs = {cmd.exe /c \"rabbitmqctl.bat\" add_user Username Password}\nInvoke-Command -ScriptBlock $pathvargs\n$pathvargs = {cmd.exe /c \"rabbitmqctl.bat\" set_user_tags User administrator}\nInvoke-Command -ScriptBlock $pathvargs\n$pathvargs = {cmd.exe /c \"rabbitmqctl.bat\" set_permissions -p \"/\" User \"^User-.*\" \".*\" \".*\"}\nInvoke-Command -ScriptBlock $pathvargs\nWrite-Host \"Did RabbitMQ\"\n```\n\n```text\ncopy \"C:\\Windows\\system32\\config\\systemprofile\\.erlang.cookie\" \"C:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.7.17\\sbin\\.erlang.cookie\"\ncopy \"C:\\Windows\\system32\\config\\systemprofile\\.erlang.cookie\" $env:userprofile\\.erlang.cookie -force\n```\n\n```text\n\"winrm_username\": \"Administrator\",\n```\n\n```text\n%HOMEDRIVE%%HOMEPATH%\n```\n\n```text\n%USERPROFILE%\n```\n\n```text\nC:\\WINDOWS\\system32\\config\\systemprofile\n```\n\n```text\nc:\\\\Windows\\.erlang.cookie\n```\n\n```text\nkill -9 $(lsof -t -i:25672)\n```\n\n```text\n1. copy the .erlang.cookie file from C:\\Windows\\System32\\config\\systemprofile paste it into \nC:\\Users\\[\"your user nameusername\"] folder\n\n2. run rabbitmq-service.bat stop and rabbitmq-service.bat start\n```\n\n```html\nHTTP/1.1 200 OK\n cache-control: no-cache\n content-length: 186\n content-security-policy: script-src 'self' 'unsafe-eval' 'unsafe-inline'; \n object-src 'self'\n content-type: application/json\n date: Tue, 13 Jul 2021 11:21:12 GMT\n server: Cowboy\n vary: accept, accept-encoding, origin\n [{\"cluster_state\":{\"rabbit@hostname\":\"running\"},\"description\":\"Default virtual host\",\"metadata\":{\"description\":\"Default virtual host\",\"tags\":[]},\"name\":\"/\",\"tags\":[],\"tracing\":false}]\n```\n\n```text\n.erlang.cookie\n```\n\n```text\nWindows\n```\n\n```text\nC:\\Windows\\system32\\config\\systemprofile\\.erlang.cookie\n```\n\n```text\n%HOMEDRIVE%%HOMEPATH%\\.erlang.cookie\n```\n\n```text\n%HOMEDRIVE%\n```\n\n```text\nH:\n```\n\n```text\n%HOMEPATH%\n```\n\n```text\n\\\n```\n\n```text\nERLANG_HOME\n```\n\n```text\nRABBITMQ_SERVER\n```\n\n```text\n%PATH%\n```\n\n```text\n;%RABBITMQ_SERVER%\\sbin\n```\n\n```text\n%RABBITMQ_SERVER%/sbin/rabbitmq-plugins.bat enable rabbitmq_management\n```\n\n```text\n%USERPROFILEDIR%/AppData/Roaming/RabbitMQ/enabled_plugins\n```\n\n```text\n%RABBITMQ_SERVER%/sbin/rabbitmq-plugins.bat enable rabbitmq_management\n```\n\n```text\ncurl -i -u guest:guest http://localhost:15672/api/vhosts\n```\n\n```text\n%RABBITMQ_SERVER%/sbin/rabbitmqctl start_app\n```\n\n```text\n%RABBITMQ_SERVER%/sbin/rabbitmqctl stop_app\n```\n\n```text\n%RABBITMQ_SERVER%/sbin/rabbitmqctl status\n```\n\n========================================\n\nComments:\n- > I install Erlang VM and RabbitMQ in custom folder, not default folder (Both of them).\n- that's an awful name!\n- I did find a solution on some website. My issues was that I had renamed my computer. All I had to do was go to the `sbin`, anad use the service controller batch file to uninstall and then re-install the service to use the new name. There's a registry key that gets deleted when the service is removed. However, I have to admit that I found out about this method after I had completely removed Rabbit and Erlang and all its data altogether. In the end, though, I had a working clean version.\n- Also, setting `RABBITMQ_NODENAME` env variable will make sure that future hostname changes don't affect rabbit\n- Also this cookie may locate directly in `C:\\WINDOWS\\system32`\n- I'm running on linux single node and having same issue. Any steps to simply regenerate the dern cookie?\n- With Erlang versions prior to 20.2, the cookie file location might also be `C:\\Windows\\.erlang.cookie` (when running as Windows service).\n- This saved me a bunch of time, thank you!\n- This answer worked for me. All I needed was to skip to the last part. Copy the file from C:\\WINDOWS\\system32\\config\\systemprofile to your user folder. That's it. It should now work.\n- ummm... My operating system is Windows 10\n- restarting the rabbitmq-server service on slave helped me.\n- Hi, but in my case I do have file at the same location and I am still getting the error `TCP connection succeeded but Erlang distribution failed`\n- @Ciastopiekarz have you by any chance found a resolution to this error? Please update your findings if you still remember them\n- This solution \"C:\\Windows\\system32\\config\\systemprofile\\.erlang.cookie\" to \"C:\\Users\\%USERNAME%\\.erlang.cookie\" works for me finally.\n- Please include your error messages as text so other people can search them in the future\n- my erorr is RabbitMQ failed to start, TCP connection succeeded but Erlang distribution failed i solve my problm with kill rabbitMQ port (25672) then restart the rabbitmq\n- I can read that, you should include the full error message as text in your question.\n- I know this comment is old but this solved my issue on a fresh installation of RabbitMQ. Make sure to overwrite the cookie file in your users folder.\n- I wasn't able to copy the file due to permissions even with an elevated command prompt but I finally found a command that works. `xcopy \"C:\\Windows\\System32\\config\\systemprofile\\.erlang.cookie\" \"C:\\Users\\%USERNAME%\" /H /R /Y`. The /H flag copies hidden and system files, /R overwrites read-only files, and /Y suppresses prompt to overwrite files. Also, I already had the .erlang.cookie file in my C:\\Users\\%USERNAME%\\ directory, but overwriting it fixed the issue, so it is definitely worth a try.\n- please how you did this","metadata":{"transformedAt":"2026-08-18T18:33:20.128Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":38,"totalLines":302,"estimatedTokens":2172}}138{"id":"stack-33951516","source":"stackoverflow","questionId":33951516,"title":"Cannot enable rabbitmq-management plugin on Windows","tags":["rabbitmq"],"text":"Title: Cannot enable rabbitmq-management plugin on Windows\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nSo, this is what I've done:\n\n- Installed Erlang on my Windows x64 bit machine\n\n- Installed RabbitMQ\n\n- Started RabbitMQ service\n\nAt this step I have no errors. When, however, I try to enabe rabbitmq-management, I get some error messages in the console. The way I try to enable it is this one:\n\n```\nC:\\...\\rabbitmq-server-3.5.6\\sbin>rabbitmq-plugins.bat enable rabbitmq_management\n```\n\nThis results in:\n\n Applying plugin configuration to rabbit@Jacobian... failed\n\nTo add to this, I know about this thread, but I'm not sure what this command means `SET HOMEDRIVE=C:`. Nevertheless, I tried it like so:\n\n```\nC:\\...\\rabbitmq-server-3.5.6\\sbin> SET HOMEDRIVE=C:\nC:\\...\\rabbitmq-server-3.5.6\\sbin> rabbitmq-plugins.bat enable rabbitmq_management\n```\n\nBut I still got the same error message. Thanks!\n\nEDIT:\n\nhttps://i.sstatic.net/qDYDq.png\n\n**EDIT**\n\nIt seems, like `RabbitMQ` became `RubbishMQ`. The catch is I followed very standard and very basic steps to install `RabbitMQ` now on Ubuntu machine and got a terrible list of error messages once again. These are the steps I followed:\n\n```\napt-get install pkg-config automake autoconf libsigc++-2.0-dev \ngit clone git://github.com/alanxz/rabbitmq-c.git\ncd rabbitmq-c\n# Enable and update the codegen git submodule\ngit submodule init\ngit submodule update\n# Configure, compile and install\nautoreconf -i && ./configure && make && sudo make install \nrabbitmq-plugins enable rabbitmq_management\n```\n\nWhen I run the last command I get tons of error messages. Among them I see such as \"error_logger ... Error when reading ./.erlang.cookie: eaccess\". So, I guess there are some secret missing steps or some voodoo spell, that can make it work. But I do not know all that stuff and hope to hear some advice. This is what I expect to see - 1) step by step installation of RabbitMQ on Windows and step by step test, that all works 2) the same for Ubuntu. Ready, Steady, Go!\n\n========================================\n\nTop Answer:\nSomehow, this solved my issue from Command Prompt run as administrator.\n\n`C:\\...\\rabbitmq-server-3.5.6\\sbin> SET HOMEDRIVE=C:\nC:\\...\\rabbitmq-server-3.5.6\\sbin> rabbitmq-service remove\nC:\\...\\rabbitmq-server-3.5.6\\sbin> rabbitmq-service install\nC:\\...\\rabbitmq-server-3.5.6\\sbin> rabbitmq-plugins.bat enable rabbitmq_management`\n\nThanks @jacboian\n\n========================================\n\nCode:\n```text\nC:\\...\\rabbitmq-server-3.5.6\\sbin>rabbitmq-plugins.bat enable rabbitmq_management\n```\n\n```text\nC:\\...\\rabbitmq-server-3.5.6\\sbin> SET HOMEDRIVE=C:\nC:\\...\\rabbitmq-server-3.5.6\\sbin> rabbitmq-plugins.bat enable rabbitmq_management\n```\n\n```text\napt-get install pkg-config automake autoconf libsigc++-2.0-dev \ngit clone git://github.com/alanxz/rabbitmq-c.git\ncd rabbitmq-c\n# Enable and update the codegen git submodule\ngit submodule init\ngit submodule update\n# Configure, compile and install\nautoreconf -i && ./configure && make && sudo make install \nrabbitmq-plugins enable rabbitmq_management\n```\n\n```text\nSET HOMEDRIVE=C:\n```\n\n```text\nRabbitMQ\n```\n\n```text\nRubbishMQ\n```\n\n```text\nRabbitMQ\n```\n\n```text\nC:\\Windows\\.erlang.cookie\n```\n\n```text\nC:\\Users\\youruser\\.erlang.cookie\n```\n\n```text\nC:\\Windows\\.erlang.cookie\n```\n\n```text\nC:\\Users\\youruser\\.erlang.cookie\n```\n\n```text\nyouruser\n```\n\n```text\nC:\\Users\\gabriele\\.erlang.cookie\n```\n\n```text\nC:\\...\\rabbitmq-server-3.5.6\\sbin> SET HOMEDRIVE=C:\nC:\\...\\rabbitmq-server-3.5.6\\sbin> rabbitmq-service remove\nC:\\...\\rabbitmq-server-3.5.6\\sbin> rabbitmq-service install\nC:\\...\\rabbitmq-server-3.5.6\\sbin> rabbitmq-plugins.bat enable rabbitmq_management\n```\n\n```text\nrabbitmq-service.bat install\n```\n\n```text\nrabbitmq-plugins.bat enable rabbitmq_management\n```\n\n```text\nrabbitmq-plugins enable rabbitmq_management\n```\n\n```text\n******************************\n ERLANG_HOME not set correctly.\n ******************************\n\n Please either set ERLANG_HOME to point to your Erlang installation or place \n the RabbitMQ server distribution in the Erlang lib folder.\n```\n\n```text\nC:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.7.14\\sbin>\n```\n\n```text\n.\\rabbitmq-plugins.bat enable rabbitmq_management\n```\n\n```text\nrabbitmq-service.bat install\n```\n\n```text\nrabbitmq-service.bat start\n```\n\n```text\nRabbitMQ\n```\n\n```text\nsbin\n```\n\n```text\nrabbitmq-service.bat stop\n```\n\n```text\nrabbitmq-service.bat remove\n```\n\n```text\nrabbitmq-plugins.bat enable rabbitmq_management\n```\n\n```text\nrabbitmq-plugins.bat enable rabbitmq-management\n```\n\n```bash\nrabbitmq-plugins enable rabbitmq_management\n```\n\n```bash\nrabbitmq-service remove\n```\n\n```bash\nrabbitmq-service install\n```\n\n```bash\nrabbitmq-plugins enable rabbitmq_management\n```\n\n========================================\n\nComments:\n- What's the full stack error?\n- @Gabriele. Please, have a look.\n- It is a `.erlang.cookie` problem, please read this: rabbitmq.com/windows-quirks.html Copy the file .erlang.cookie manually from %SystemRoot% to %HOMEDRIVE%%HOMEPATH%.\n- And in terms of Windows, what these paths mean? What systemroot? What homepath? You can make a full answer from this and I will definitely accept it!\n- It seems like nobody knows how to install and use RabbitMQ on Windows or Linux. Fantastic!\n- See this, May Helpful. stackoverflow.com/questions/18661791/…\n- @Dhaval Asodariya. I've already mentioned that thread in my own question (\"To add to this, I know about this thread....\" <-- have a look above), and I must confess that it is not useful any more.\n- Unfortunatelly, sir, I must confess, that it does not help. I copied `C:\\Windows\\.erlang.cookie` to my home directory and restarted RabbitMQ, but to no avail. I still get thoese error messages when I try to enable plugins :(\n- That's strange, try to do the same executing the `rabbitmq-server.bat` and not service\n- At what stage should I do that? Before trying to enable plugins?\n- I tried to execute `rabbitmq-server.bat` and got `BOOT FAILED`. So, my all dozens attempts ended in failure.\n- you don't have to execute it using doubleclick, go to the `cmd` and execute it.\n- Actually, I ran it through `cmd` and not by doubleclicking.\n- This worked - Please make sure you remove the \"Read Only\" from users cookie - Right click on file - Security - Uncheck \"Read Only\", Then copy it from C:\\windows to home directory\n- Does not work. I'm getting \"init terminating in do_boot\" error message\n- I followed the same steps, still i am getting same error.\n- This should've been a comments instead of an answer ;P\n- Note: You need to stop and start rabbitmq-service after these instructions\n- worked as a charm\n- this should be the slected answer for new versions of rabbit mq.\n- As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.\n- This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review","metadata":{"transformedAt":"2026-08-18T18:33:20.128Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":32,"totalLines":239,"estimatedTokens":1792}}139{"id":"stack-17148683","source":"stackoverflow","questionId":17148683,"title":"Verify rabbitmq credentials are valid","tags":["python","rabbitmq"],"text":"Title: Verify rabbitmq credentials are valid\nTags: python, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'd like to write a simple smoke test that runs after deployment to verify that the RabbitMQ credentials are valid. What's the simplest way to check that rabbitmq username/password/vhost are valid?\n\n*Edit:* Preferably, check using a bash script. Alternatively, using a Python script.\n\n========================================\n\nTop Answer:\nHere's a way to check using Python:\n\n```\n#!/usr/bin/env python\nimport socket\nfrom kombu import Connection\nhost = \"localhost\"\nport = 5672\nuser = \"guest\"\npassword = \"guest\"\nvhost = \"/\"\nurl = 'amqp://{0}:{1}@{2}:{3}/{4}'.format(user, password, host, port, vhost)\nwith Connection(url) as c:\n try:\n c.connect()\n except socket.error:\n raise ValueError(\"Received socket.error, \"\n \"rabbitmq server probably isn't running\")\n except IOError:\n raise ValueError(\"Received IOError, probably bad credentials\")\n else:\n print \"Credentials are valid\"\n```\n\n========================================\n\nCode:\n```text\n$ curl -i -u guest:guest http://localhost:15672/api/whoami\n```\n\n```text\n#!/usr/bin/env python\nimport socket\nfrom kombu import Connection\nhost = \"localhost\"\nport = 5672\nuser = \"guest\"\npassword = \"guest\"\nvhost = \"/\"\nurl = 'amqp://{0}:{1}@{2}:{3}/{4}'.format(user, password, host, port, vhost)\nwith Connection(url) as c:\n try:\n c.connect()\n except socket.error:\n raise ValueError(\"Received socket.error, \"\n \"rabbitmq server probably isn't running\")\n except IOError:\n raise ValueError(\"Received IOError, probably bad credentials\")\n else:\n print \"Credentials are valid\"\n```\n\n```text\nrabbitmqctl authenticate_user username password\n```\n\n```text\nrabbitmqctl\n```\n\n```text\n>>> import pika\n>>> URL = 'amqp://guest:guest@localhost:5672/%2F'\n>>> parameters = pika.URLParameters(URL)\n>>> connection = pika.BlockingConnection(parameters)\n>>> connection.is_open\nTrue\n>>> connection.close()\n```\n\n========================================\n\nComments:\n- differentiate between `\"reason\":\"Login failed\"` and `\"reason\":\"Not management user\"` and you can tell if the credentials work even if the user is not an admin\n- On Ubuntu 16.04 it shows `Error: could not recognise command` and the help about the comment. What are the requirements for the `authenticate_user` command?\n- It's probably your RabbitMQ version being not recent. Could you check if `rabbitmqctl --help` lists the command `authenticate_user`?","metadata":{"transformedAt":"2026-08-18T18:33:20.128Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":89,"estimatedTokens":622}}140{"id":"stack-30546977","source":"stackoverflow","questionId":30546977,"title":"Is there a timeout for acking RabbitMQ messages?","tags":["c#","rabbitmq"],"text":"Title: Is there a timeout for acking RabbitMQ messages?\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI would like to set a timeout after which a dequeued message is automatically NACKed.\n\nWhen I dequeue a message I wait until it is transfered over a socket and the other party confirms its reception.\n\nDo I need to keep a list of Timers or can RMQ handle this automatically?\n\n```\nprivate void Run()\n{\n _rmqConnection = _queueConnectionFactory.CreateFactory().CreateConnection();\n\n _rmqReadchannel = _rmqConnection.CreateModel();\n\n _rmqReadchannel.QueueDeclare(QueueIdOutgoing(), true, false, false, null);\n\n _rmqReadchannel.BasicQos(0, 1, false);\n var consumer = new QueueingBasicConsumer(_rmqReadchannel);\n _rmqReadchannel.BasicConsume(QueueIdOutgoing(), false, consumer);\n while (true)\n {\n if (!_rmqReadchannel.IsOpen)\n {\n throw new Exception(\"Channel is closed\");\n }\n var ea = consumer.Queue.Dequeue();\n string jsonData = Encoding.UTF8.GetString(ea.Body);\n if (OnOutgoingMessageReady != null)\n {\n OnOutgoingMessageReady(this, new QueueDataEventArgs(jsonData, ea.DeliveryTag));\n }\n //waiting for ACK from a different thread\n }\n}\n```\n\n========================================\n\nTop Answer:\nModern versions of RabbitMQ have ack timeout.\nSo be careful with updates to new versions if you have consumers that spend a lot of time before delivery acknowledgement.\n\nIf a consumer does not ack its delivery for more than the timeout value (30 minutes by default), its channel will be closed with a PRECONDITION_FAILED channel exception.\n\n**UPD:**\nUpdated doc contains instruction for disabling timeout:\n\nThe timeout can be deactivated using advanced.config. This is not recommended:\n\n```\n%% advanced.config\n[\n {rabbit, [\n {consumer_timeout, undefined}\n ]}\n].\n```\n\nInstead of disabling the timeout entirely, consider using a high value (for example, a few hours).\n\n========================================\n\nCode:\n```text\nprivate void Run()\n{\n _rmqConnection = _queueConnectionFactory.CreateFactory().CreateConnection();\n\n _rmqReadchannel = _rmqConnection.CreateModel();\n\n _rmqReadchannel.QueueDeclare(QueueIdOutgoing(), true, false, false, null);\n\n _rmqReadchannel.BasicQos(0, 1, false);\n var consumer = new QueueingBasicConsumer(_rmqReadchannel);\n _rmqReadchannel.BasicConsume(QueueIdOutgoing(), false, consumer);\n while (true)\n {\n if (!_rmqReadchannel.IsOpen)\n {\n throw new Exception(\"Channel is closed\");\n }\n var ea = consumer.Queue.Dequeue();\n string jsonData = Encoding.UTF8.GetString(ea.Body);\n if (OnOutgoingMessageReady != null)\n {\n OnOutgoingMessageReady(this, new QueueDataEventArgs(jsonData, ea.DeliveryTag));\n }\n //waiting for ACK from a different thread\n }\n}\n```\n\n```text\n%% advanced.config\n[\n {rabbit, [\n {consumer_timeout, undefined}\n ]}\n].\n```\n\n========================================\n\nComments:\n- thank you, so this is can be set to maximum? What is the max value?\n- @toha I don't know what the max size of this property, rabbit docs don't have any info about it. But I have just noticed an update in rabbit docs that allows to deactivate all timeouts. I added it to my answer.\n- very good. I will try to make it for some hours. After trial I hope nothing happened again","metadata":{"transformedAt":"2026-08-18T18:33:20.128Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":111,"estimatedTokens":827}}141{"id":"stack-27692045","source":"stackoverflow","questionId":27692045,"title":"RabbitMQ error in config file \"/etc/rabbitmq/rabbitmq.config\": syntax error before: ']'","tags":["rabbitmq"],"text":"Title: RabbitMQ error in config file \"/etc/rabbitmq/rabbitmq.config\": syntax error before: ']'\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am on Ubuntu 14.04 and I installed rabbitmq. As I was reading through the configuration documentation, I wanted to create my own rabbitmq.config file in `/etc/rabbitmq/rabbitmq.config`, so I searched for an example of a configuration file which I found under `/usr//doc/rabbitmq-server/rabbitmq.config.example.gz`.\n\nI unzipped it in `/etc/rabbitmq/rabbitmq.config` and started to uncomment many options. Once I tried to restart rabbitmq through `sudo service rabbitmq-server restart` it failed. I looked in the logs and I found the following error:\n\n```\n==> /var/log/rabbitmq/startup_log So I though I didn't write one of the option correctly and I tried to fixed the line 214 but the line 214 is the end of the configuration dictionary for the first section. I erased the file and restarted from scratch thinking that I would uncomment line by line also by restarting rabbitmq between each uncomment to find on which line I did an error.\n\nFirst thing I did was to uncomment a line I don't have to modify like this one: \n\n```\n%% {reverse_dns_lookups, true}, %% I only removed the % signs\n```\n\nIt didn't change anything it was unable to restart rabbitmq-server throwing exactly the same syntax error at line 214. I checked where the list and the dictionary were starting and ending and everything looks fine to me. By the way if you leave the file unchanged it will allow you to restart rabbitmq.\n\nDid I forget to uncomment something in this file?\n\nOriginal example file: \n\n```\n%% -*- mode: erlang -*-\n%% ----------------------------------------------------------------------------\n%% RabbitMQ Sample Configuration File.\n%%\n%% See http://www.rabbitmq.com/configure.html for details.\n%% ----------------------------------------------------------------------------\n[\n {rabbit,\n [%%\n %% Network Connectivity\n %% ====================\n %%\n\n %% By default, RabbitMQ will listen on all interfaces, using\n %% the standard (reserved) AMQP port.\n %%\n %% {tcp_listeners, [5672]},\n\n %% To listen on a specific interface, provide a tuple of {IpAddress, Port}.\n %% For example, to listen only on localhost for both IPv4 and IPv6:\n %%\n %% {tcp_listeners, [{\"127.0.0.1\", 5672},\n %% {\"::1\", 5672}]},\n\n %% SSL listeners are configured in the same fashion as TCP listeners,\n %% including the option to control the choice of interface.\n %%\n %% {ssl_listeners, [5671]},\n\n %% Log levels (currently just used for connection logging).\n %% One of 'info', 'warning', 'error' or 'none', in decreasing order\n %% of verbosity. Defaults to 'info'.\n %%\n %% {log_levels, [{connection, info}]},\n\n %% Set to 'true' to perform reverse DNS lookups when accepting a\n %% connection. Hostnames will then be shown instead of IP addresses\n %% in rabbitmqctl and the management plugin.\n %%\n %% {reverse_dns_lookups, true},\n\n %%\n %% Security / AAA\n %% ==============\n %%\n\n %% Configuring SSL.\n %% See http://www.rabbitmq.com/ssl.html for full documentation.\n %%\n %% {ssl_options, [{cacertfile, \"/path/to/testca/cacert.pem\"},\n %% {certfile, \"/path/to/server/cert.pem\"},\n %% {keyfile, \"/path/to/server/key.pem\"},\n %% {verify, verify_peer},\n %% {fail_if_no_peer_cert, false}]},\n\n %% Choose the available SASL mechanism(s) to expose.\n %% The two default (built in) mechanisms are 'PLAIN' and\n %% 'AMQPLAIN'. Additional mechanisms can be added via\n %% plugins.\n %%\n %% See http://www.rabbitmq.com/authentication.html for more details.\n %%\n %% {auth_mechanisms, ['PLAIN', 'AMQPLAIN']},\n\n %% Select an authentication database to use. RabbitMQ comes bundled\n %% with a built-in auth-database, based on mnesia.\n %%\n %% {auth_backends, [rabbit_auth_backend_internal]},\n\n %% Configurations supporting the rabbitmq_auth_mechanism_ssl and\n %% rabbitmq_auth_backend_ldap plugins.\n %%\n %% NB: These options require that the relevant plugin is enabled.\n %% See http://www.rabbitmq.com/plugins.html for further details.\n\n %% The RabbitMQ-auth-mechanism-ssl plugin makes it possible to\n %% authenticate a user based on the client's SSL certificate.\n %%\n %% To use auth-mechanism-ssl, add to or replace the auth_mechanisms\n %% list with the entry 'EXTERNAL'.\n %%\n %% {auth_mechanisms, ['EXTERNAL']},\n\n %% The rabbitmq_auth_backend_ldap plugin allows the broker to\n %% perform authentication and authorisation by deferring to an\n %% external LDAP server.\n %%\n %% For more information about configuring the LDAP backend, see\n %% http://www.rabbitmq.com/ldap.html.\n %%\n %% Enable the LDAP auth backend by adding to or replacing the\n %% auth_backends entry:\n %%\n %% {auth_backends, [rabbit_auth_backend_ldap]},\n\n %% This pertains to both the rabbitmq_auth_mechanism_ssl plugin and\n %% STOMP ssl_cert_login configurations. See the rabbitmq_stomp\n %% configuration section later in this fail and the README in\n %% https://github.com/rabbitmq/rabbitmq-auth-mechanism-ssl for further\n %% details.\n %%\n %% To use the SSL cert's CN instead of its DN as the username\n %%\n %% {ssl_cert_login_from, common_name},\n\n %%\n %% Default User / VHost\n %% ====================\n %%\n\n %% On first start RabbitMQ will create a vhost and a user. These\n %% config items control what gets created. See\n %% http://www.rabbitmq.com/access-control.html for further\n %% information about vhosts and access control.\n %%\n %% {default_vhost, >},\n %% {default_user, >},\n %% {default_pass, >},\n %% {default_permissions, [>, >, >]},\n\n %% Tags for default user\n %%\n %% For more details about tags, see the documentation for the\n %% Management Plugin at http://www.rabbitmq.com/management.html.\n %%\n %% {default_user_tags, [administrator]},\n\n %%\n %% Additional network and protocol related configuration\n %% =====================================================\n %%\n\n %% Set the default AMQP heartbeat delay (in seconds).\n %%\n %% {heartbeat, 600},\n\n %% Set the max permissible size of an AMQP frame (in bytes).\n %%\n %% {frame_max, 131072},\n\n %% Customising Socket Options.\n %%\n %% See (http://www.erlang.org/doc/man/inet.html#setopts-2) for\n %% further documentation.\n %%\n %% {tcp_listen_options, [binary,\n %% {packet, raw},\n %% {reuseaddr, true},\n %% {backlog, 128},\n %% {nodelay, true},\n %% {exit_on_close, false}]},\n\n %%\n %% Resource Limits & Flow Control\n %% ==============================\n %%\n %% See http://www.rabbitmq.com/memory.html for full details.\n\n %% Memory-based Flow Control threshold.\n %%\n %% {vm_memory_high_watermark, 0.4},\n\n %% Fraction of the high watermark limit at which queues start to\n %% page message out to disc in order to free up memory.\n %%\n %% {vm_memory_high_watermark_paging_ratio, 0.5},\n\n %% Set disk free limit (in bytes). Once free disk space reaches this\n %% lower bound, a disk alarm will be set - see the documentation\n %% listed above for more details.\n %%\n %% {disk_free_limit, 50000000},\n\n %% Alternatively, we can set a limit relative to total available RAM.\n %%\n %% {disk_free_limit, {mem_relative, 1.0}},\n\n %%\n %% Misc/Advanced Options\n %% =====================\n %%\n %% NB: Change these only if you understand what you are doing!\n %%\n\n %% To announce custom properties to clients on connection:\n %%\n %% {server_properties, []},\n\n %% How to respond to cluster partitions.\n %% See http://www.rabbitmq.com/partitions.html for further details.\n %%\n %% {cluster_partition_handling, ignore},\n\n %% Make clustering happen *automatically* at startup - only applied\n %% to nodes that have just been reset or started for the first time.\n %% See http://www.rabbitmq.com/clustering.html#auto-config for\n %% further details.\n %%\n %% {cluster_nodes, {['rabbit@my.host.com'], disc}},\n\n %% Set (internal) statistics collection granularity.\n %%\n %% {collect_statistics, none},\n\n %% Statistics collection interval (in milliseconds).\n %%\n %% {collect_statistics_interval, 5000},\n\n %% Explicitly enable/disable hipe compilation.\n %%\n %% {hipe_compile, true}\n\n ]},\n\n %% ----------------------------------------------------------------------------\n %% Advanced Erlang Networking/Clustering Options.\n %%\n %% See http://www.rabbitmq.com/clustering.html for details\n %% ----------------------------------------------------------------------------\n {kernel,\n [%% Provide an explicit port-range for inter-node communications.\n %% See http://www.rabbitmq.com/clustering.html#firewall for further details.\n\n %% Sets the minimum / maximum port numbers\n %%\n %% {inet_dist_listen_min, 10000},\n %% {inet_dist_listen_max, 10005},\n\n %% Sets the net_kernel tick time.\n %% Please see http://erlang.org/doc/man/kernel_app.html and\n %% http://www.rabbitmq.com/nettick.html for further details.\n %%\n %% {net_ticktime, 60}\n ]},\n\n %% ----------------------------------------------------------------------------\n %% RabbitMQ Management Plugin\n %%\n %% See http://www.rabbitmq.com/management.html for details\n %% ----------------------------------------------------------------------------\n\n {rabbitmq_management,\n [%% Pre-Load schema definitions from the following JSON file. See\n %% http://www.rabbitmq.com/management.html#load-definitions\n %%\n %% {load_definitions, \"/path/to/schema.json\"},\n\n %% Log all requests to the management HTTP API to a file.\n %%\n %% {http_log_dir, \"/path/to/access.log\"},\n\n %% Change the port on which the HTTP listener listens,\n %% specifying an interface for the web server to bind to.\n %% Also set the listener to use SSL and provide SSL options.\n %%\n %% {listener, [{port, 12345},\n %% {ip, \"127.0.0.1\"},\n %% {ssl, true},\n %% {ssl_opts, [{cacertfile, \"/path/to/cacert.pem\"},\n %% {certfile, \"/path/to/cert.pem\"},\n %% {keyfile, \"/path/to/key.pem\"}]}]},\n\n %% Configure how long aggregated data (such as message rates and queue\n %% lengths) is retained. Please read the plugin's documentation in\n %% https://www.rabbitmq.com/management.html#configuration for more\n %% details.\n %%\n %% {sample_retention_policies,\n %% [{global, [{60, 5}, {3600, 60}, {86400, 1200}]},\n %% {basic, [{60, 5}, {3600, 60}]},\n %% {detailed, [{10, 5}]}]}\n ]},\n\n {rabbitmq_management_agent,\n [%% Misc/Advanced Options\n %%\n %% NB: Change these only if you understand what you are doing!\n %%\n %% {force_fine_statistics, true}\n ]},\n\n %% ----------------------------------------------------------------------------\n %% RabbitMQ Shovel Plugin\n %%\n %% See http://www.rabbitmq.com/shovel.html for details\n %% ----------------------------------------------------------------------------\n\n {rabbitmq_shovel,\n [{shovels,\n [%% A named shovel worker.\n %% {my_first_shovel,\n %% [\n\n %% List the source broker(s) from which to consume.\n %%\n %% {sources,\n %% [%% URI(s) and pre-declarations for all source broker(s).\n %% {brokers, [\"amqp://user:password@host.domain/my_vhost\"]},\n %% {declarations, []}\n %% ]},\n\n %% List the destination broker(s) to publish to.\n %% {destinations,\n %% [%% A singular version of the 'brokers' element.\n %% {broker, \"amqp://\"},\n %% {declarations, []}\n %% ]},\n\n %% Name of the queue to shovel messages from.\n %%\n %% {queue, >},\n\n %% Optional prefetch count.\n %%\n %% {prefetch_count, 10},\n\n %% when to acknowledge messages:\n %% - no_ack: never (auto)\n %% - on_publish: after each message is republished\n %% - on_confirm: when the destination broker confirms receipt\n %%\n %% {ack_mode, on_confirm},\n\n %% Overwrite fields of the outbound basic.publish.\n %%\n %% {publish_fields, [{exchange, >},\n %% {routing_key, >}]},\n\n %% Static list of basic.properties to set on re-publication.\n %%\n %% {publish_properties, [{delivery_mode, 2}]},\n\n %% The number of seconds to wait before attempting to\n %% reconnect in the event of a connection failure.\n %%\n %% {reconnect_delay, 2.5}\n\n %% ]} %% End of my_first_shovel\n ]}\n %% Rather than specifying some values per-shovel, you can specify\n %% them for all shovels here.\n %%\n %% {defaults, [{prefetch_count, 0},\n %% {ack_mode, on_confirm},\n %% {publish_fields, []},\n %% {publish_properties, [{delivery_mode, 2}]},\n %% {reconnect_delay, 2.5}]}\n ]},\n\n %% ----------------------------------------------------------------------------\n %% RabbitMQ Stomp Adapter\n %%\n %% See http://www.rabbitmq.com/stomp.html for details\n %% ----------------------------------------------------------------------------\n\n {rabbitmq_stomp,\n [%% Network Configuration - the format is generally the same as for the broker\n\n %% Listen only on localhost (ipv4 & ipv6) on a specific port.\n %% {tcp_listeners, [{\"127.0.0.1\", 61613},\n %% {\"::1\", 61613}]},\n\n %% Listen for SSL connections on a specific port.\n %% {ssl_listeners, [61614]},\n\n %% Additional SSL options\n\n %% Extract a name from the client's certificate when using SSL.\n %%\n %% {ssl_cert_login, true},\n\n %% Set a default user name and password. This is used as the default login\n %% whenever a CONNECT frame omits the login and passcode headers.\n %%\n %% Please note that setting this will allow clients to connect without\n %% authenticating!\n %%\n %% {default_user, [{login, \"guest\"},\n %% {passcode, \"guest\"}]},\n\n %% If a default user is configured, or you have configured use SSL client\n %% certificate based authentication, you can choose to allow clients to\n %% omit the CONNECT frame entirely. If set to true, the client is\n %% automatically connected as the default user or user supplied in the\n %% SSL certificate whenever the first frame sent on a session is not a\n %% CONNECT frame.\n %%\n %% {implicit_connect, true}\n ]},\n\n %% ----------------------------------------------------------------------------\n %% RabbitMQ MQTT Adapter\n %%\n %% See http://hg.rabbitmq.com/rabbitmq-mqtt/file/stable/README.md for details\n %% ----------------------------------------------------------------------------\n\n {rabbitmq_mqtt,\n [%% Set the default user name and password. Will be used as the default login\n %% if a connecting client provides no other login details.\n %%\n %% Please note that setting this will allow clients to connect without\n %% authenticating!\n %%\n %% {default_user, >},\n %% {default_pass, >},\n\n %% Enable anonymous access. If this is set to false, clients MUST provide\n %% login information in order to connect. See the default_user/default_pass\n %% configuration elements for managing logins without authentication.\n %%\n %% {allow_anonymous, true},\n\n %% If you have multiple chosts, specify the one to which the\n %% adapter connects.\n %%\n %% {vhost, >},\n\n %% Specify the exchange to which messages from MQTT clients are published.\n %%\n %% {exchange, >},\n\n %% Specify TTL (time to live) to control the lifetime of non-clean sessions.\n %%\n %% {subscription_ttl, 1800000},\n\n %% Set the prefetch count (governing the maximum number of unacknowledged\n %% messages that will be delivered).\n %%\n %% {prefetch, 10},\n\n %% TCP/SSL Configuration (as per the broker configuration).\n %%\n %% {tcp_listeners, [1883]},\n %% {ssl_listeners, []},\n\n %% TCP/Socket options (as per the broker configuration).\n %%\n %% {tcp_listen_options, [binary,\n %% {packet, raw},\n %% {reuseaddr, true},\n %% {backlog, 128},\n %% {nodelay, true}]}\n ]},\n\n %% ----------------------------------------------------------------------------\n %% RabbitMQ AMQP 1.0 Support\n %%\n %% See http://hg.rabbitmq.com/rabbitmq-amqp1.0/file/default/README.md\n %% for details\n %% ----------------------------------------------------------------------------\n\n {rabbitmq_amqp1_0,\n [%% Connections that are not authenticated with SASL will connect as this\n %% account. See the README for more information.\n %%\n %% Please note that setting this will allow clients to connect without\n %% authenticating!\n %%\n %% {default_user, \"guest\"},\n\n %% Enable protocol strict mode. See the README for more information.\n %%\n %% {protocol_strict_mode, false}\n ]},\n\n %% ----------------------------------------------------------------------------\n %% RabbitMQ LDAP Plugin\n %%\n %% See http://www.rabbitmq.com/ldap.html for details.\n %%\n %% ----------------------------------------------------------------------------\n\n {rabbitmq_auth_backend_ldap,\n [%%\n %% Connecting to the LDAP server(s)\n %% ================================\n %%\n\n %% Specify servers to bind to. You *must* set this in order for the plugin\n %% to work properly.\n %%\n %% {servers, [\"your-server-name-goes-here\"]},\n\n %% Connect to the LDAP server using SSL\n %%\n %% {use_ssl, false},\n\n %% Specify the LDAP port to connect to\n %%\n %% {port, 389},\n\n %% Enable logging of LDAP queries.\n %% One of\n %% - false (no logging is performed)\n %% - true (verbose logging of the logic used by the plugin)\n %% - network (as true, but additionally logs LDAP network traffic)\n %%\n %% Defaults to false.\n %%\n %% {log, false},\n\n %%\n %% Authentication\n %% ==============\n %%\n\n %% Pattern to convert the username given through AMQP to a DN before\n %% binding\n %%\n %% {user_dn_pattern, \"cn=${username},ou=People,dc=example,dc=com\"},\n\n %% Alternatively, you can convert a username to a Distinguished\n %% Name via an LDAP lookup after binding. See the documentation for\n %% full details.\n\n %% When converting a username to a dn via a lookup, set these to\n %% the name of the attribute that represents the user name, and the\n %% base DN for the lookup query.\n %%\n %% {dn_lookup_attribute, \"userPrincipalName\"},\n %% {dn_lookup_base, \"DC=gopivotal,DC=com\"},\n\n %% Controls how to bind for authorisation queries and also to\n %% retrieve the details of users logging in without presenting a\n %% password (e.g., SASL EXTERNAL).\n %% One of\n %% - as_user (to bind as the authenticated user - requires a password)\n %% - anon (to bind anonymously)\n %% - {UserDN, Password} (to bind with a specified user name and password)\n %%\n %% Defaults to 'as_user'.\n %%\n %% {other_bind, as_user},\n\n %%\n %% Authorisation\n %% =============\n %%\n\n %% The LDAP plugin can perform a variety of queries against your\n %% LDAP server to determine questions of authorisation. See\n %% http://www.rabbitmq.com/ldap.html#authorisation for more\n %% information.\n\n %% Set the query to use when determining vhost access\n %%\n %% {vhost_access_query, {in_group,\n %% \"ou=${vhost}-users,ou=vhosts,dc=example,dc=com\"}},\n\n %% Set the query to use when determining resource (e.g., queue) access\n %%\n %% {resource_access_query, {constant, true}},\n\n %% Set queries to determine which tags a user has\n %%\n %% {tag_queries, []}\n ]}\n].\n```\n\n========================================\n\nTop Answer:\nI had a same problem. i solved it by Renaming rabbitmq.config to rabbitmq.conf.\n\n========================================\n\nCode:\n```text\n==> /var/log/rabbitmq/startup_log <==\n{\"could not start kernel pid\",application_controller,\"error in config file \\\"/etc/rabbitmq/rabbitmq.config\\\" (214): syntax error before: ']'\"}\n```\n\n```text\n%% {reverse_dns_lookups, true}, %% I only removed the % signs\n```\n\n```text\n%% -*- mode: erlang -*-\n%% ----------------------------------------------------------------------------\n%% RabbitMQ Sample Configuration File.\n%%\n%% See http://www.rabbitmq.com/configure.html for details.\n%% ----------------------------------------------------------------------------\n[\n {rabbit,\n [%%\n %% Network Connectivity\n %% ====================\n %%\n\n %% By default, RabbitMQ will listen on all interfaces, using\n %% the standard (reserved) AMQP port.\n %%\n %% {tcp_listeners, [5672]},\n\n %% To listen on a specific interface, provide a tuple of {IpAddress, Port}.\n %% For example, to listen only on localhost for both IPv4 and IPv6:\n %%\n %% {tcp_listeners, [{\"127.0.0.1\", 5672},\n %% {\"::1\", 5672}]},\n\n %% SSL listeners are configured in the same fashion as TCP listeners,\n %% including the option to control the choice of interface.\n %%\n %% {ssl_listeners, [5671]},\n\n %% Log levels (currently just used for connection logging).\n %% One of 'info', 'warning', 'error' or 'none', in decreasing order\n %% of verbosity. Defaults to 'info'.\n %%\n %% {log_levels, [{connection, info}]},\n\n %% Set to 'true' to perform reverse DNS lookups when accepting a\n %% connection. Hostnames will then be shown instead of IP addresses\n %% in rabbitmqctl and the management plugin.\n %%\n %% {reverse_dns_lookups, true},\n\n %%\n %% Security / AAA\n %% ==============\n %%\n\n %% Configuring SSL.\n %% See http://www.rabbitmq.com/ssl.html for full documentation.\n %%\n %% {ssl_options, [{cacertfile, \"/path/to/testca/cacert.pem\"},\n %% {certfile, \"/path/to/server/cert.pem\"},\n %% {keyfile, \"/path/to/server/key.pem\"},\n %% {verify, verify_peer},\n %% {fail_if_no_peer_cert, false}]},\n\n %% Choose the available SASL mechanism(s) to expose.\n %% The two default (built in) mechanisms are 'PLAIN' and\n %% 'AMQPLAIN'. Additional mechanisms can be added via\n %% plugins.\n %%\n %% See http://www.rabbitmq.com/authentication.html for more details.\n %%\n %% {auth_mechanisms, ['PLAIN', 'AMQPLAIN']},\n\n %% Select an authentication database to use. RabbitMQ comes bundled\n %% with a built-in auth-database, based on mnesia.\n %%\n %% {auth_backends, [rabbit_auth_backend_internal]},\n\n %% Configurations supporting the rabbitmq_auth_mechanism_ssl and\n %% rabbitmq_auth_backend_ldap plugins.\n %%\n %% NB: These options require that the relevant plugin is enabled.\n %% See http://www.rabbitmq.com/plugins.html for further details.\n\n %% The RabbitMQ-auth-mechanism-ssl plugin makes it possible to\n %% authenticate a user based on the client's SSL certificate.\n %%\n %% To use auth-mechanism-ssl, add to or replace the auth_mechanisms\n %% list with the entry 'EXTERNAL'.\n %%\n %% {auth_mechanisms, ['EXTERNAL']},\n\n %% The rabbitmq_auth_backend_ldap plugin allows the broker to\n %% perform authentication and authorisation by deferring to an\n %% external LDAP server.\n %%\n %% For more information about configuring the LDAP backend, see\n %% http://www.rabbitmq.com/ldap.html.\n %%\n %% Enable the LDAP auth backend by adding to or replacing the\n %% auth_backends entry:\n %%\n %% {auth_backends, [rabbit_auth_backend_ldap]},\n\n %% This pertains to both the rabbitmq_auth_mechanism_ssl plugin and\n %% STOMP ssl_cert_login configurations. See the rabbitmq_stomp\n %% configuration section later in this fail and the README in\n %% https://github.com/rabbitmq/rabbitmq-auth-mechanism-ssl for further\n %% details.\n %%\n %% To use the SSL cert's CN instead of its DN as the username\n %%\n %% {ssl_cert_login_from, common_name},\n\n %%\n %% Default User / VHost\n %% ====================\n %%\n\n %% On first start RabbitMQ will create a vhost and a user. These\n %% config items control what gets created. See\n %% http://www.rabbitmq.com/access-control.html for further\n %% information about vhosts and access control.\n %%\n %% {default_vhost, <<\"/\">>},\n %% {default_user, <<\"guest\">>},\n %% {default_pass, <<\"guest\">>},\n %% {default_permissions, [<<\".*\">>, <<\".*\">>, <<\".*\">>]},\n\n %% Tags for default user\n %%\n %% For more details about tags, see the documentation for the\n %% Management Plugin at http://www.rabbitmq.com/management.html.\n %%\n %% {default_user_tags, [administrator]},\n\n %%\n %% Additional network and protocol related configuration\n %% =====================================================\n %%\n\n %% Set the default AMQP heartbeat delay (in seconds).\n %%\n %% {heartbeat, 600},\n\n %% Set the max permissible size of an AMQP frame (in bytes).\n %%\n %% {frame_max, 131072},\n\n %% Customising Socket Options.\n %%\n %% See (http://www.erlang.org/doc/man/inet.html#setopts-2) for\n %% further documentation.\n %%\n %% {tcp_listen_options, [binary,\n %% {packet, raw},\n %% {reuseaddr, true},\n %% {backlog, 128},\n %% {nodelay, true},\n %% {exit_on_close, false}]},\n\n %%\n %% Resource Limits & Flow Control\n %% ==============================\n %%\n %% See http://www.rabbitmq.com/memory.html for full details.\n\n %% Memory-based Flow Control threshold.\n %%\n %% {vm_memory_high_watermark, 0.4},\n\n %% Fraction of the high watermark limit at which queues start to\n %% page message out to disc in order to free up memory.\n %%\n %% {vm_memory_high_watermark_paging_ratio, 0.5},\n\n %% Set disk free limit (in bytes). Once free disk space reaches this\n %% lower bound, a disk alarm will be set - see the documentation\n %% listed above for more details.\n %%\n %% {disk_free_limit, 50000000},\n\n %% Alternatively, we can set a limit relative to total available RAM.\n %%\n %% {disk_free_limit, {mem_relative, 1.0}},\n\n %%\n %% Misc/Advanced Options\n %% =====================\n %%\n %% NB: Change these only if you understand what you are doing!\n %%\n\n %% To announce custom properties to clients on connection:\n %%\n %% {server_properties, []},\n\n %% How to respond to cluster partitions.\n %% See http://www.rabbitmq.com/partitions.html for further details.\n %%\n %% {cluster_partition_handling, ignore},\n\n %% Make clustering happen *automatically* at startup - only applied\n %% to nodes that have just been reset or started for the first time.\n %% See http://www.rabbitmq.com/clustering.html#auto-config for\n %% further details.\n %%\n %% {cluster_nodes, {['rabbit@my.host.com'], disc}},\n\n %% Set (internal) statistics collection granularity.\n %%\n %% {collect_statistics, none},\n\n %% Statistics collection interval (in milliseconds).\n %%\n %% {collect_statistics_interval, 5000},\n\n %% Explicitly enable/disable hipe compilation.\n %%\n %% {hipe_compile, true}\n\n ]},\n\n %% ----------------------------------------------------------------------------\n %% Advanced Erlang Networking/Clustering Options.\n %%\n %% See http://www.rabbitmq.com/clustering.html for details\n %% ----------------------------------------------------------------------------\n {kernel,\n [%% Provide an explicit port-range for inter-node communications.\n %% See http://www.rabbitmq.com/clustering.html#firewall for further details.\n\n %% Sets the minimum / maximum port numbers\n %%\n %% {inet_dist_listen_min, 10000},\n %% {inet_dist_listen_max, 10005},\n\n %% Sets the net_kernel tick time.\n %% Please see http://erlang.org/doc/man/kernel_app.html and\n %% http://www.rabbitmq.com/nettick.html for further details.\n %%\n %% {net_ticktime, 60}\n ]},\n\n %% ----------------------------------------------------------------------------\n %% RabbitMQ Management Plugin\n %%\n %% See http://www.rabbitmq.com/management.html for details\n %% ----------------------------------------------------------------------------\n\n {rabbitmq_management,\n [%% Pre-Load schema definitions from the following JSON file. See\n %% http://www.rabbitmq.com/management.html#load-definitions\n %%\n %% {load_definitions, \"/path/to/schema.json\"},\n\n %% Log all requests to the management HTTP API to a file.\n %%\n %% {http_log_dir, \"/path/to/access.log\"},\n\n %% Change the port on which the HTTP listener listens,\n %% specifying an interface for the web server to bind to.\n %% Also set the listener to use SSL and provide SSL options.\n %%\n %% {listener, [{port, 12345},\n %% {ip, \"127.0.0.1\"},\n %% {ssl, true},\n %% {ssl_opts, [{cacertfile, \"/path/to/cacert.pem\"},\n %% {certfile, \"/path/to/cert.pem\"},\n %% {keyfile, \"/path/to/key.pem\"}]}]},\n\n %% Configure how long aggregated data (such as message rates and queue\n %% lengths) is retained. Please read the plugin's documentation in\n %% https://www.rabbitmq.com/management.html#configuration for more\n %% details.\n %%\n %% {sample_retention_policies,\n %% [{global, [{60, 5}, {3600, 60}, {86400, 1200}]},\n %% {basic, [{60, 5}, {3600, 60}]},\n %% {detailed, [{10, 5}]}]}\n ]},\n\n {rabbitmq_management_agent,\n [%% Misc/Advanced Options\n %%\n %% NB: Change these only if you understand what you are doing!\n %%\n %% {force_fine_statistics, true}\n ]},\n\n %% ----------------------------------------------------------------------------\n %% RabbitMQ Shovel Plugin\n %%\n %% See http://www.rabbitmq.com/shovel.html for details\n %% ----------------------------------------------------------------------------\n\n {rabbitmq_shovel,\n [{shovels,\n [%% A named shovel worker.\n %% {my_first_shovel,\n %% [\n\n %% List the source broker(s) from which to consume.\n %%\n %% {sources,\n %% [%% URI(s) and pre-declarations for all source broker(s).\n %% {brokers, [\"amqp://user:password@host.domain/my_vhost\"]},\n %% {declarations, []}\n %% ]},\n\n %% List the destination broker(s) to publish to.\n %% {destinations,\n %% [%% A singular version of the 'brokers' element.\n %% {broker, \"amqp://\"},\n %% {declarations, []}\n %% ]},\n\n %% Name of the queue to shovel messages from.\n %%\n %% {queue, <<\"your-queue-name-goes-here\">>},\n\n %% Optional prefetch count.\n %%\n %% {prefetch_count, 10},\n\n %% when to acknowledge messages:\n %% - no_ack: never (auto)\n %% - on_publish: after each message is republished\n %% - on_confirm: when the destination broker confirms receipt\n %%\n %% {ack_mode, on_confirm},\n\n %% Overwrite fields of the outbound basic.publish.\n %%\n %% {publish_fields, [{exchange, <<\"my_exchange\">>},\n %% {routing_key, <<\"from_shovel\">>}]},\n\n %% Static list of basic.properties to set on re-publication.\n %%\n %% {publish_properties, [{delivery_mode, 2}]},\n\n %% The number of seconds to wait before attempting to\n %% reconnect in the event of a connection failure.\n %%\n %% {reconnect_delay, 2.5}\n\n %% ]} %% End of my_first_shovel\n ]}\n %% Rather than specifying some values per-shovel, you can specify\n %% them for all shovels here.\n %%\n %% {defaults, [{prefetch_count, 0},\n %% {ack_mode, on_confirm},\n %% {publish_fields, []},\n %% {publish_properties, [{delivery_mode, 2}]},\n %% {reconnect_delay, 2.5}]}\n ]},\n\n %% ----------------------------------------------------------------------------\n %% RabbitMQ Stomp Adapter\n %%\n %% See http://www.rabbitmq.com/stomp.html for details\n %% ----------------------------------------------------------------------------\n\n {rabbitmq_stomp,\n [%% Network Configuration - the format is generally the same as for the broker\n\n %% Listen only on localhost (ipv4 & ipv6) on a specific port.\n %% {tcp_listeners, [{\"127.0.0.1\", 61613},\n %% {\"::1\", 61613}]},\n\n %% Listen for SSL connections on a specific port.\n %% {ssl_listeners, [61614]},\n\n %% Additional SSL options\n\n %% Extract a name from the client's certificate when using SSL.\n %%\n %% {ssl_cert_login, true},\n\n %% Set a default user name and password. This is used as the default login\n %% whenever a CONNECT frame omits the login and passcode headers.\n %%\n %% Please note that setting this will allow clients to connect without\n %% authenticating!\n %%\n %% {default_user, [{login, \"guest\"},\n %% {passcode, \"guest\"}]},\n\n %% If a default user is configured, or you have configured use SSL client\n %% certificate based authentication, you can choose to allow clients to\n %% omit the CONNECT frame entirely. If set to true, the client is\n %% automatically connected as the default user or user supplied in the\n %% SSL certificate whenever the first frame sent on a session is not a\n %% CONNECT frame.\n %%\n %% {implicit_connect, true}\n ]},\n\n %% ----------------------------------------------------------------------------\n %% RabbitMQ MQTT Adapter\n %%\n %% See http://hg.rabbitmq.com/rabbitmq-mqtt/file/stable/README.md for details\n %% ----------------------------------------------------------------------------\n\n {rabbitmq_mqtt,\n [%% Set the default user name and password. Will be used as the default login\n %% if a connecting client provides no other login details.\n %%\n %% Please note that setting this will allow clients to connect without\n %% authenticating!\n %%\n %% {default_user, <<\"guest\">>},\n %% {default_pass, <<\"guest\">>},\n\n %% Enable anonymous access. If this is set to false, clients MUST provide\n %% login information in order to connect. See the default_user/default_pass\n %% configuration elements for managing logins without authentication.\n %%\n %% {allow_anonymous, true},\n\n %% If you have multiple chosts, specify the one to which the\n %% adapter connects.\n %%\n %% {vhost, <<\"/\">>},\n\n %% Specify the exchange to which messages from MQTT clients are published.\n %%\n %% {exchange, <<\"amq.topic\">>},\n\n %% Specify TTL (time to live) to control the lifetime of non-clean sessions.\n %%\n %% {subscription_ttl, 1800000},\n\n %% Set the prefetch count (governing the maximum number of unacknowledged\n %% messages that will be delivered).\n %%\n %% {prefetch, 10},\n\n %% TCP/SSL Configuration (as per the broker configuration).\n %%\n %% {tcp_listeners, [1883]},\n %% {ssl_listeners, []},\n\n %% TCP/Socket options (as per the broker configuration).\n %%\n %% {tcp_listen_options, [binary,\n %% {packet, raw},\n %% {reuseaddr, true},\n %% {backlog, 128},\n %% {nodelay, true}]}\n ]},\n\n %% ----------------------------------------------------------------------------\n %% RabbitMQ AMQP 1.0 Support\n %%\n %% See http://hg.rabbitmq.com/rabbitmq-amqp1.0/file/default/README.md\n %% for details\n %% ----------------------------------------------------------------------------\n\n {rabbitmq_amqp1_0,\n [%% Connections that are not authenticated with SASL will connect as this\n %% account. See the README for more information.\n %%\n %% Please note that setting this will allow clients to connect without\n %% authenticating!\n %%\n %% {default_user, \"guest\"},\n\n %% Enable protocol strict mode. See the README for more information.\n %%\n %% {protocol_strict_mode, false}\n ]},\n\n %% ----------------------------------------------------------------------------\n %% RabbitMQ LDAP Plugin\n %%\n %% See http://www.rabbitmq.com/ldap.html for details.\n %%\n %% ----------------------------------------------------------------------------\n\n {rabbitmq_auth_backend_ldap,\n [%%\n %% Connecting to the LDAP server(s)\n %% ================================\n %%\n\n %% Specify servers to bind to. You *must* set this in order for the plugin\n %% to work properly.\n %%\n %% {servers, [\"your-server-name-goes-here\"]},\n\n %% Connect to the LDAP server using SSL\n %%\n %% {use_ssl, false},\n\n %% Specify the LDAP port to connect to\n %%\n %% {port, 389},\n\n %% Enable logging of LDAP queries.\n %% One of\n %% - false (no logging is performed)\n %% - true (verbose logging of the logic used by the plugin)\n %% - network (as true, but additionally logs LDAP network traffic)\n %%\n %% Defaults to false.\n %%\n %% {log, false},\n\n %%\n %% Authentication\n %% ==============\n %%\n\n %% Pattern to convert the username given through AMQP to a DN before\n %% binding\n %%\n %% {user_dn_pattern, \"cn=${username},ou=People,dc=example,dc=com\"},\n\n %% Alternatively, you can convert a username to a Distinguished\n %% Name via an LDAP lookup after binding. See the documentation for\n %% full details.\n\n %% When converting a username to a dn via a lookup, set these to\n %% the name of the attribute that represents the user name, and the\n %% base DN for the lookup query.\n %%\n %% {dn_lookup_attribute, \"userPrincipalName\"},\n %% {dn_lookup_base, \"DC=gopivotal,DC=com\"},\n\n %% Controls how to bind for authorisation queries and also to\n %% retrieve the details of users logging in without presenting a\n %% password (e.g., SASL EXTERNAL).\n %% One of\n %% - as_user (to bind as the authenticated user - requires a password)\n %% - anon (to bind anonymously)\n %% - {UserDN, Password} (to bind with a specified user name and password)\n %%\n %% Defaults to 'as_user'.\n %%\n %% {other_bind, as_user},\n\n %%\n %% Authorisation\n %% =============\n %%\n\n %% The LDAP plugin can perform a variety of queries against your\n %% LDAP server to determine questions of authorisation. See\n %% http://www.rabbitmq.com/ldap.html#authorisation for more\n %% information.\n\n %% Set the query to use when determining vhost access\n %%\n %% {vhost_access_query, {in_group,\n %% \"ou=${vhost}-users,ou=vhosts,dc=example,dc=com\"}},\n\n %% Set the query to use when determining resource (e.g., queue) access\n %%\n %% {resource_access_query, {constant, true}},\n\n %% Set queries to determine which tags a user has\n %%\n %% {tag_queries, []}\n ]}\n].\n```\n\n```text\n/etc/rabbitmq/rabbitmq.config\n```\n\n```text\n/usr/share/doc/rabbitmq-server/rabbitmq.config.example.gz\n```\n\n```text\n/etc/rabbitmq/rabbitmq.config\n```\n\n```text\nsudo service rabbitmq-server restart\n```\n\n```text\nerl -noshell -eval 'io:format(\"~p~n\", [file:consult(\"/etc/rabbitmq/rabbitmq.config\")]).' -eval 'init:stop().'\n```\n\n========================================\n\nComments:\n- Yes it is right. I figured it out with your answer. In the array the last element MUST not be followed by a trailing comma. Thanks, it will help to finish my ansible profile.\n- Must have come with a system update and only just picked it up with a reboot as that worked for me on the default queue row, training , But server been fine for weeks, before the restart\n- in log(`/var/log/rabbitmq/rabbit@nur-VirtualBox.log`) I see the line below: `config file(s) : /etc/rabbitmq/rabbitmq.config` It looks for `/etc/rabbitmq/rabbitmq.config` file. If you rename it rabbitmq just ignores(`not found` in log) it.\n- BTW, changing the file name to .conf , cause the rabbit to ignore the file. that mean you can rename it to .bla... rabbit read only rabbitmq.config file.\n- another option is that the owner of the file is not rabbitmq . it should look that: -rw-r-----. 1 rabbitmq rabbitmq 21012 Sep 5 12:00 rabbitmq.config","metadata":{"transformedAt":"2026-08-18T18:33:20.129Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":1191,"estimatedTokens":9573}}142{"id":"stack-9558128","source":"stackoverflow","questionId":9558128,"title":"Specific advantages of NServiceBus over plain RabbitMQ","tags":["nservicebus","rabbitmq","amqp"],"text":"Title: Specific advantages of NServiceBus over plain RabbitMQ\nTags: nservicebus, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nAre there any advantages of using NServiceBus over simply using the .net driver for RabbitMQ (assuming we can replace MSMQ with AMQP). Does NSB provide any additional functionality or abstractions that are not available directly in AMQP.\n\n========================================\n\nTop Answer:\nNSB most often uses MSMQ as the underlying transport. It could use RabbitMQ or some other AMQP compliant transport. NSB provides support for all the basic messaging patterns including point to point communication, pub/sub etc. The decision to use a particular transport would be different than that of choosing NSB itself. It has many features and you can get and idea from the Documentation page.\n\n========================================\n\nComments:\n- Another good answer: stackoverflow.com/a/38125057/151350\n- To add to this excellent answer, if you use RabbitMQ directly, you will, by necessity, end up building your own service bus, and that is not a trivial undertaking – particular.net/videos/so-you-want-to-build-a-service-bus","metadata":{"transformedAt":"2026-08-18T18:33:20.129Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":17,"estimatedTokens":289}}143{"id":"stack-15033848","source":"stackoverflow","questionId":15033848,"title":"How can a RabbitMQ Client tell when it loses connection to the server?","tags":["rabbitmq"],"text":"Title: How can a RabbitMQ Client tell when it loses connection to the server?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nIf I'm connected to RabbitMQ and listening for events using an EventingBasicConsumer, how can I tell if I've been disconnected from the server? \n\nI know there is a Shutdown event, but it doesn't fire if I unplug my network cable to simulate a failure. \n\nI've also tried the ModelShutdown event, and CallbackException on the model but none seem to work.\n\nEDIT-----\nThe one I marked as the answer is correct, but it was only part of the solution for me. There is also HeartBeat functionality built into RabbitMQ. The server specifies it in the configuration file. It defaults to 10 minutes but of course you can change that. \n\nThe client can also request a different interval for the heartbeat by setting the RequestedHeartbeat value on the ConnectionFactory instance.\n\n========================================\n\nTop Answer:\nThis is an example of it, but the marked answer is what lead me to this.\n\n```\nvar factory = new ConnectionFactory\n{\n HostName = \"MY_HOST_NAME\",\n UserName = \"USERNAME\",\n Password = \"PASSWORD\",\n RequestedHeartbeat = 30\n};\n\nusing (var connection = factory.CreateConnection())\n{\n connection.ConnectionShutdown += (o, e) =>\n { \n //handle disconnect \n };\n\n using (var model = connection.CreateModel())\n {\n model.ExchangeDeclare(EXCHANGE_NAME, \"topic\");\n var queueName = model.QueueDeclare();\n\n model.QueueBind(queueName, EXCHANGE_NAME, \"#\"); \n\n var consumer = new QueueingBasicConsumer(model);\n model.BasicConsume(queueName, true, consumer);\n\n while (!stop)\n {\n BasicDeliverEventArgs args; \n consumer.Queue.Dequeue(5000, out args);\n\n if (stop) return;\n\n if (args == null) continue;\n if (args.Body.Length == 0) continue;\n\n Task.Factory.StartNew(() =>\n {\n //Do work here on different thread then this one\n }, TaskCreationOptions.PreferFairness);\n }\n }\n}\n```\n\nA few things to note about this. \n\nI'm using # for the topic. This grabs everything. Usually you want to limit by a topic.\n\nI'm setting a variable called \"stop\" to determine when the process should end. You'll notice the loop runs forever until that variable is true. \n\nThe Dequeue waits 5 seconds then leaves without getting data if there is no new message. This is to ensure we listen for that stop variable and actually quit at some point. Change the value to your liking.\n\nWhen a message comes in I spawn the handling code on a new thread. The current thread is being reserved for just listening to the rabbitmq messages and if a handler takes too long to process I don't want it slowing down the other messages. You may or may not need this depending on your implementation. Be careful however writing the code to handle the messages. If it takes a minute to run and your getting messages at sub-second times you will run out of memory or at least into severe performance issues.\n\n========================================\n\nCode:\n```cs\npublic class MyRabbitConsumer\n{\n private IConnection connection;\n\n public void Connect()\n {\n connection = CreateAndOpenConnection();\n connection.ConnectionShutdown += connection_ConnectionShutdown;\n }\n\n public IConnection CreateAndOpenConnection() { ... }\n\n private void connection_ConnectionShutdown(IConnection connection, ShutdownEventArgs reason)\n {\n\n }\n}\n```\n\n```text\nvar factory = new ConnectionFactory\n{\n HostName = \"MY_HOST_NAME\",\n UserName = \"USERNAME\",\n Password = \"PASSWORD\",\n RequestedHeartbeat = 30\n};\n\nusing (var connection = factory.CreateConnection())\n{\n connection.ConnectionShutdown += (o, e) =>\n { \n //handle disconnect \n };\n\n using (var model = connection.CreateModel())\n {\n model.ExchangeDeclare(EXCHANGE_NAME, \"topic\");\n var queueName = model.QueueDeclare();\n\n model.QueueBind(queueName, EXCHANGE_NAME, \"#\"); \n\n var consumer = new QueueingBasicConsumer(model);\n model.BasicConsume(queueName, true, consumer);\n\n while (!stop)\n {\n BasicDeliverEventArgs args; \n consumer.Queue.Dequeue(5000, out args);\n\n if (stop) return;\n\n if (args == null) continue;\n if (args.Body.Length == 0) continue;\n\n Task.Factory.StartNew(() =>\n {\n //Do work here on different thread then this one\n }, TaskCreationOptions.PreferFairness);\n }\n }\n}\n```\n\n```text\nConnectionFactory factory = new ConnectionFactory();\nfactory.setHost(\"localhost\");\nfactory.setUsername(\"user\");\nfactory.setPassword(\"yourpass\");\nfactory.setPort(\"5671\");\nConnection conn = factory.newConnection();\nChannel channel = conn.createChannel();\nconn.addShutdownListener(new ShutdownListener() {\n public void shutdownCompleted(ShutdownSignalException cause) {\n System.out.println(\"Connection closed by a reason\" + cause.toString())\n }\n});\n```\n\n========================================\n\nComments:\n- You can add a heartbeat to the connection which will detect service interuption\n- Can you post your whole code? I am facing same issue. Thanks in advance.\n- You really need 3 things. 1 the ConnectionFactory needs to set a RequestedHeartBeat. 2 after you create a connection define the ConnectionShutdown event as described in the marked answer. 3 ensure you have it setup correctly in the rabbitmq config file. (sorry I don't have that part around currently.) I'll see if I can extract the code without any implementation specific stuff.\n- I posted an example as an answer below that I hope helps.","metadata":{"transformedAt":"2026-08-18T18:33:20.129Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":166,"estimatedTokens":1398}}144{"id":"stack-57706037","source":"stackoverflow","questionId":57706037,"title":"How to pass the content of a file to Helm values.yaml","tags":["kubernetes","rabbitmq","kubernetes-helm"],"text":"Title: How to pass the content of a file to Helm values.yaml\nTags: kubernetes, rabbitmq, kubernetes-helm\nSource: Stack Overflow\n\nQuestion:\nI want to use Helm chart of RabbitMQ to set up a cluster but when I try to pass the configuration files that we have at the moment to the values.yaml it doesn't work.\n\nThe command that I use:\n\n```\nhelm install --dry-run --debug stable/rabbitmq --name testrmq --namespace rmq -f rabbit-values.yaml\n```\n\nrabbit-values.yaml:\n\n```\nrabbitmq:\n plugins: \"rabbitmq_management rabbitmq_federation rabbitmq_federation_management rabbitmq_shovel rabbitmq_shovel_management rabbitmq_mqtt rabbitmq_web_stomp rabbitmq_peer_discovery_k8s\"\n advancedConfiguration: |-\n {{ .Files.Get \"rabbitmq.config\" | quote}}\n```\n\nAnd what I get for `advancedConfiguration`:\n\n```\nNAME: testrmq\nREVISION: 1\nRELEASED: Thu Aug 29 10:09:26 2019\nCHART: rabbitmq-5.5.0\nUSER-SUPPLIED VALUES:\nrabbitmq:\n advancedConfiguration: '{{ .Files.Get \"rabbitmq.config\" | quote}}'\n plugins: rabbitmq_management rabbitmq_federation rabbitmq_federation_management\n rabbitmq_shovel rabbitmq_shovel_management rabbitmq_mqtt rabbitmq_web_stomp rabbitmq_peer_discovery_k8s\n```\n\nI have to mention that:\n\n- rabbitmq.config is an Erlang file\n\n- I tried different things including indentation (`indent 4`)\n\n========================================\n\nTop Answer:\nAs this is google top result, here is some related issue with the solution:\n\nI have some chart, that has a subchart as well as a config folder. I want to pass the content of the config folder down to the subchart, to be used as some file based configmap.\n\n```\napiVersion: v1\nkind: ConfigMap\n...\ndata:\n{{ if .Values.files}}\n{{- range $k, $v := .Values.files }}\n {{ $k }}:\n {{ $v | indent 2}}\n{{- end }}\n{{end}}\n```\n\nand calling `helm` with this beauty:\n\n```\nhelm ... $(for i in $(ls config/); do echo --set-file mySubChart.files.${i//./\\\\.}=config/$i;done)\"\n```\n\nThanks to @Alfageme for the hint about the dot.\n\n========================================\n\nCode:\n```text\nhelm install --dry-run --debug stable/rabbitmq --name testrmq --namespace rmq -f rabbit-values.yaml\n```\n\n```text\nrabbitmq:\n plugins: \"rabbitmq_management rabbitmq_federation rabbitmq_federation_management rabbitmq_shovel rabbitmq_shovel_management rabbitmq_mqtt rabbitmq_web_stomp rabbitmq_peer_discovery_k8s\"\n advancedConfiguration: |-\n {{ .Files.Get \"rabbitmq.config\" | quote}}\n```\n\n```text\nNAME: testrmq\nREVISION: 1\nRELEASED: Thu Aug 29 10:09:26 2019\nCHART: rabbitmq-5.5.0\nUSER-SUPPLIED VALUES:\nrabbitmq:\n advancedConfiguration: '{{ .Files.Get \"rabbitmq.config\" | quote}}'\n plugins: rabbitmq_management rabbitmq_federation rabbitmq_federation_management\n rabbitmq_shovel rabbitmq_shovel_management rabbitmq_mqtt rabbitmq_web_stomp rabbitmq_peer_discovery_k8s\n```\n\n```text\nadvancedConfiguration\n```\n\n```text\nindent 4\n```\n\n```bash\nhelm install --dry-run --debug \\\n stable/rabbitmq \\\n --name testrmq \\\n --namespace rmq \\\n -f rabbit-values.yaml \\\n --set-file rabbitmq.advancedConfig=rabbitmq.config\n```\n\n```text\nvalues.yaml\n```\n\n```text\ntpl\n```\n\n```text\nvalues.yaml\n```\n\n```text\n--set-file\n```\n\n```text\n--set-file\n```\n\n```yaml\napiVersion: v1\nkind: ConfigMap\n...\ndata:\n{{ if .Values.files}}\n{{- range $k, $v := .Values.files }}\n {{ $k }}:\n {{ $v | indent 2}}\n{{- end }}\n{{end}}\n```\n\n```bash\nhelm ... $(for i in $(ls config/); do echo --set-file mySubChart.files.${i//./\\\\.}=config/$i;done)\"\n```\n\n```text\nhelm\n```\n\n========================================\n\nComments:\n- you are trying to call .Files.Get inside a values file, which is not parsed as a template\n- see this issue\n- In case anyone comes wondering how to pass a nested file name with `--set-file`, the key is also in the docs: \"*Sometimes you need to use special characters in your `--set` lines. You can use a backslash to escape the characters*\" - e.g. `--set-file 'configFiles.config\\.toml'=custom-config.toml` will do the trick for you.","metadata":{"transformedAt":"2026-08-18T18:33:20.129Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":14,"totalLines":160,"estimatedTokens":987}}145{"id":"stack-38728668","source":"stackoverflow","questionId":38728668,"title":"Spring RabbitMQ - using manual channel acknowledgement on a service with @RabbitListener configuration","tags":["java","rabbitmq","spring-amqp","spring-rabbit"],"text":"Title: Spring RabbitMQ - using manual channel acknowledgement on a service with @RabbitListener configuration\nTags: java, rabbitmq, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nHow to acknowledge the messages manually without using auto acknowledgement. \nIs there a way to use this along with the `@RabbitListener` and `@EnableRabbit` style of configuration. \nMost of the documentation tells us to use `SimpleMessageListenerContainer` along with `ChannelAwareMessageListener`. \nHowever using that we lose the flexibility that is provided with the annotations. \nI have configured my service as below :\n\n```\n@Service\npublic class EventReceiver {\n\n@Autowired\nprivate MessageSender messageSender;\n\n@RabbitListener(queues = \"${eventqueue}\")\npublic void receiveMessage(Order order) throws Exception {\n\n // code for processing order\n}\n```\n\n### My RabbitConfiguration is as below\n\n```\n@EnableRabbit\npublic class RabbitApplication implements RabbitListenerConfigurer {\n\npublic static void main(String[] args) {\n SpringApplication.run(RabbitApplication.class, args);\n}\n\n@Bean\n\npublic MappingJackson2MessageConverter jackson2Converter() {\n MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();\n return converter;\n @Bean\npublic SimpleRabbitListenerContainerFactory myRabbitListenerContainerFactory() {\n SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();\n factory.setConnectionFactory(rabbitConnectionFactory());\n factory.setMaxConcurrentConsumers(5);\n factory.setMessageConverter((MessageConverter) jackson2Converter());\n factory.setAcknowledgeMode(AcknowledgeMode.MANUAL);\n return factory;\n }\n\n@Bean\npublic ConnectionFactory rabbitConnectionFactory() {\n CachingConnectionFactory connectionFactory = new CachingConnectionFactory();\n connectionFactory.setHost(\"localhost\");\n return connectionFactory;\n}\n\n@Override\npublic void configureRabbitListeners(RabbitListenerEndpointRegistrar registrar) {\n registrar.setContainerFactory(myRabbitListenerContainerFactory());\n}\n\n@Autowired\nprivate EventReceiver receiver;\n}\n}\n```\n\nAny help will be appreciated on how to adapt manual channel acknowledgement along with the above style of configuration.\nIf we implement the ChannelAwareMessageListener then the onMessage signature will change. \nCan we implement ChannelAwareMessageListener on a service ?\n\n========================================\n\nTop Answer:\nJust in case you need to use #onMessage() from ChannelAwareMessageListener class. Then you can do it this way.\n\n```\n@Component\npublic class MyMessageListener implements ChannelAwareMessageListener {\n\n @Override\n public void onMessage(Message message, Channel channel) {\n log.info(\"Message received.\");\n // do something with the message\n channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);\n }\n}\n```\n\nAnd for the rabbitConfiguration\n\n```\n@Configuration\npublic class RabbitConfig {\n\n public static final String topicExchangeName = \"exchange1\";\n\n public static final String queueName = \"queue1\";\n\n public static final String routingKey = \"queue1.route.#\";\n\n @Bean\n public ConnectionFactory connectionFactory() {\n CachingConnectionFactory connectionFactory = new CachingConnectionFactory(\"localhost\");\n connectionFactory.setUsername(\"xxxx\");\n connectionFactory.setPassword(\"xxxxxxxxxx\");\n connectionFactory.setPort(5672);\n connectionFactory.setVirtualHost(\"vHost1\");\n return connectionFactory;\n }\n\n @Bean\n public RabbitTemplate rabbitTemplate() {\n return new RabbitTemplate(connectionFactory());\n }\n\n @Bean\n Queue queue() {\n return new Queue(queueName, true);\n }\n\n @Bean\n TopicExchange exchange() {\n return new TopicExchange(topicExchangeName);\n }\n\n @Bean\n Binding binding(Queue queue, TopicExchange exchange) {\n return BindingBuilder.bind(queue).to(exchange).with(routingKey);\n }\n\n @Bean\n public SimpleMessageListenerContainer listenerContainer(MyMessageListener myRabbitMessageListener) {\n SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer();\n listenerContainer.setConnectionFactory(connectionFactory());\n listenerContainer.setQueueNames(queueName);\n listenerContainer.setMessageListener(myRabbitMessageListener);\n listenerContainer.setAcknowledgeMode(AcknowledgeMode.MANUAL);\n listenerContainer.setConcurrency(\"4\");\n listenerContainer.setPrefetchCount(20);\n return listenerContainer;\n }\n}\n```\n\n========================================\n\nCode:\n```text\n@Service\npublic class EventReceiver {\n\n@Autowired\nprivate MessageSender messageSender;\n\n@RabbitListener(queues = \"${eventqueue}\")\npublic void receiveMessage(Order order) throws Exception {\n\n // code for processing order\n}\n```\n\n```text\n@EnableRabbit\npublic class RabbitApplication implements RabbitListenerConfigurer {\n\npublic static void main(String[] args) {\n SpringApplication.run(RabbitApplication.class, args);\n}\n\n@Bean\n\n\npublic MappingJackson2MessageConverter jackson2Converter() {\n MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();\n return converter;\n @Bean\npublic SimpleRabbitListenerContainerFactory myRabbitListenerContainerFactory() {\n SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();\n factory.setConnectionFactory(rabbitConnectionFactory());\n factory.setMaxConcurrentConsumers(5);\n factory.setMessageConverter((MessageConverter) jackson2Converter());\n factory.setAcknowledgeMode(AcknowledgeMode.MANUAL);\n return factory;\n }\n\n@Bean\npublic ConnectionFactory rabbitConnectionFactory() {\n CachingConnectionFactory connectionFactory = new CachingConnectionFactory();\n connectionFactory.setHost(\"localhost\");\n return connectionFactory;\n}\n\n@Override\npublic void configureRabbitListeners(RabbitListenerEndpointRegistrar registrar) {\n registrar.setContainerFactory(myRabbitListenerContainerFactory());\n}\n\n@Autowired\nprivate EventReceiver receiver;\n}\n}\n```\n\n```text\n@RabbitListener\n```\n\n```text\n@EnableRabbit\n```\n\n```text\nSimpleMessageListenerContainer\n```\n\n```text\nChannelAwareMessageListener\n```\n\n```text\n@RabbitListener(queues = \"${eventqueue}\")\npublic void receiveMessage(Order order, Channel channel,\n @Header(AmqpHeaders.DELIVERY_TAG) long tag) throws Exception {\n ...\n}\n```\n\n```text\n@SpringBootApplication\n@EnableRabbit\npublic class So38728668Application {\n\n public static void main(String[] args) throws Exception {\n ConfigurableApplicationContext context = SpringApplication.run(So38728668Application.class, args);\n context.getBean(RabbitTemplate.class).convertAndSend(\"\", \"so38728668\", \"foo\");\n context.getBean(Listener.class).latch.await(60, TimeUnit.SECONDS);\n context.close();\n }\n\n @Bean\n public Queue so38728668() {\n return new Queue(\"so38728668\");\n }\n\n @Bean\n public Listener listener() {\n return new Listener();\n }\n\n public static class Listener {\n\n private final CountDownLatch latch = new CountDownLatch(1);\n\n @RabbitListener(queues = \"so38728668\")\n public void receive(String payload, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag)\n throws IOException {\n System.out.println(payload);\n channel.basicAck(tag, false);\n latch.countDown();\n }\n\n }\n\n}\n```\n\n```text\nspring.rabbitmq.listener.acknowledge-mode=manual\n```\n\n```text\nChannel\n```\n\n```text\n@RabbitListener\n```\n\n```text\nbasicAck\n```\n\n```text\nbasicReject\n```\n\n```text\n@Service\n public class Consumer {\n\n @RabbitListener(queues = \"${eventqueue}\")\n public void receiveMessage(Order order, Channel channel) throws Exception {\n\n\n\n // the above methodname can be anything but should have channel as second signature\n\n channel.basicConsume(eventQueue, false, channel.getDefaultConsumer()); \n // Get the delivery tag\n long deliveryTag = channel.basicGet(eventQueue, false).getEnvelope().getDeliveryTag();\n try {\n\n // code for processing order\n\n catch(Exception) {\n // handle exception\n channel.basicReject(deliveryTag, true);\n }\n // If all logic is successful \n channel.basicAck(deliveryTag, false);\n}\n```\n\n```text\npublic class RabbitApplication implements RabbitListenerConfigurer {\n\n private static final Logger log = LoggerFactory.getLogger(RabbitApplication .class);\n\n public static void main(String[] args) {\n SpringApplication.run(RabbitApplication.class, args);\n }\n\n @Bean\n public MappingJackson2MessageConverter jackson2Converter() {\n MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();\n return converter;\n }\n\n @Bean\n public DefaultMessageHandlerMethodFactory myHandlerMethodFactory() {\n DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();\n factory.setMessageConverter(jackson2Converter());\n return factory;\n }\n\n @Autowired\n private Consumer consumer;\n\n @Override\n public void configureRabbitListeners(RabbitListenerEndpointRegistrar registrar) {\n registrar.setMessageHandlerMethodFactory(myHandlerMethodFactory());\n }\n\n ...\n}\n```\n\n```java\n@Component\npublic class MyMessageListener implements ChannelAwareMessageListener {\n\n @Override\n public void onMessage(Message message, Channel channel) {\n log.info(\"Message received.\");\n // do something with the message\n channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);\n }\n}\n```\n\n```java\n@Configuration\npublic class RabbitConfig {\n\n public static final String topicExchangeName = \"exchange1\";\n\n public static final String queueName = \"queue1\";\n\n public static final String routingKey = \"queue1.route.#\";\n\n @Bean\n public ConnectionFactory connectionFactory() {\n CachingConnectionFactory connectionFactory = new CachingConnectionFactory(\"localhost\");\n connectionFactory.setUsername(\"xxxx\");\n connectionFactory.setPassword(\"xxxxxxxxxx\");\n connectionFactory.setPort(5672);\n connectionFactory.setVirtualHost(\"vHost1\");\n return connectionFactory;\n }\n\n @Bean\n public RabbitTemplate rabbitTemplate() {\n return new RabbitTemplate(connectionFactory());\n }\n\n @Bean\n Queue queue() {\n return new Queue(queueName, true);\n }\n\n @Bean\n TopicExchange exchange() {\n return new TopicExchange(topicExchangeName);\n }\n\n @Bean\n Binding binding(Queue queue, TopicExchange exchange) {\n return BindingBuilder.bind(queue).to(exchange).with(routingKey);\n }\n\n\n @Bean\n public SimpleMessageListenerContainer listenerContainer(MyMessageListener myRabbitMessageListener) {\n SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer();\n listenerContainer.setConnectionFactory(connectionFactory());\n listenerContainer.setQueueNames(queueName);\n listenerContainer.setMessageListener(myRabbitMessageListener);\n listenerContainer.setAcknowledgeMode(AcknowledgeMode.MANUAL);\n listenerContainer.setConcurrency(\"4\");\n listenerContainer.setPrefetchCount(20);\n return listenerContainer;\n }\n}\n```\n\n========================================\n\nComments:\n- One question is why you even need to do this. If your code is like in your answer below, (reject on failure, ack otherwise), the container will do that automatically for you with AUTO ack mode - if the listener throws an exception the message will be rejected; otherwise acked.\n- Thanks for the suggestion and we tried your suggestion and put in the line `channel.basicAck('100001', false)`. Now irrespective of whether i put \"true\" or \"false\" in the above line of code the listener and queue go in infinite loop. So can you help me how to get around this.\n- We finally solved the issue. Iam documenting this for the benefit of others.\n- I got an error that spring.rabbitmq.listener.acknowledge-mode is a deprecated property. I ended up setting this property on my RabbitListenerContainerFactory Bean and got it working that way.\n- The property was moved to `spring.rabbitmq.listener.simple.acknowledge-mode`. In Spring Boot 2.0 it can be `spring.rabbitmq.listener.simple.acknowledge-mode` or `spring.rabbitmq.listener.direct.acknowledge-mode` because Spring AMQP now supports 2 container types. See the documentation.\n- Could someone explain to me why java programmers refuse to put the imports in their code examples? I feel like it would save me hours.\n- Too much noise - if you use an IDE (e.g. eclipse/Intellij) it will make suggestions and it's usually pretty obvious if there are multiple matches. This particular example is in my sandbox github repo.\n- The info how to use the application properties to set acknowledge-mode to manual is very important! One expects to configure this in the parameters of the @RabbitListener annotation.\n- NO - you should NOT issue a `basicConsume` or `basicGet` against the channel - `basicGet` will fetch another message. The listener container is already consuming from it and the message being used to invoke the method has a different delivery tag. Instead, use `@Header(AmqpHeaders.DELIVERY_TAG) long tag`. See my answer (edit).\n- Gary, removed basicConsume and basicGet and used the @Header(AmqpHeaders.DELIVERY_TAG) long tag in basicAck/ basicReject The flow stopped working. Queue is fetched again and again in an infinite loop and the destination queue is populated. Reverted the code back to basicGet and basicConsume and it is working.\n- But it's NOT working - you are acking (and dropping) the next message.\n- so you mean i should use some sort of consume to avoid it. It is not clear since you said earlier that we should not be using basicConsume.\n- The listener container **is** the consumer - `getDefaultConsumer()` does nothing in this case (returns `null`) and `basicGet` fetches the next message in the queue.\n- I just wrote a quick Spring Boot app and it works exactly as I described - I edited my answer with the code. The full project is here and the commit. If you set a breakpoint on `basicAck` you can see the un-acked message in the Rabbit Admin UI; step over, and the message is acked.\n- Hi Pari, what is POCRabbitMessageListener here?\n- I didn't quite get your question, can you please rephrase\n- @java1977 POCRabbitMessageListener is the MyMessageListener. My bad I didn't notice it. Edited, thanks.","metadata":{"transformedAt":"2026-08-18T18:33:20.129Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":17,"totalLines":437,"estimatedTokens":3601}}146{"id":"stack-35231690","source":"stackoverflow","questionId":35231690,"title":"Celery: how to limit number of tasks in queue and stop feeding when full?","tags":["python","multithreading","rabbitmq","multiprocessing","celery"],"text":"Title: Celery: how to limit number of tasks in queue and stop feeding when full?\nTags: python, multithreading, rabbitmq, multiprocessing, celery\nSource: Stack Overflow\n\nQuestion:\nI am very new to Celery and here is the question I have:\n\nSuppose I have a script that is constantly supposed to fetch new data from DB and send it to workers using Celery.\n\ntasks.py\n\n```\n# Celery Task\nfrom celery import Celery\n\napp = Celery('tasks', broker='amqp://guest@localhost//')\n\n@app.task\ndef process_data(x):\n # Do something with x\n pass\n```\n\nfetch_db.py\n\n```\n# Fetch new data from DB and dispatch to workers.\nfrom tasks import process_data\n\nwhile True:\n # Run DB query here to fetch new data from DB fetched_data\n\n process_data.delay(fetched_data)\n\n sleep(30);\n```\n\nHere is my concern: the data is being fetched every 30 seconds. process_data() function could take much longer and depending on the amount of workers (especially if too few) the queue might get throttled as I understand. \n\n- I cannot increase number of workers.\n\n- I can modify the code to refrain from feeding the queue when it is full.\n\nThe question is how do I set queue size and how do I know it is full? In general, how to deal with this situation?\n\n========================================\n\nCode:\n```text\n# Celery Task\nfrom celery import Celery\n\napp = Celery('tasks', broker='amqp://guest@localhost//')\n\n@app.task\ndef process_data(x):\n # Do something with x\n pass\n```\n\n```text\n# Fetch new data from DB and dispatch to workers.\nfrom tasks import process_data\n\nwhile True:\n # Run DB query here to fetch new data from DB fetched_data\n\n process_data.delay(fetched_data)\n\n sleep(30);\n```\n\n```text\nimport time\nfrom celery import Celery\nfrom kombu import Queue, Exchange\n\nclass Config(object):\n BROKER_URL = \"amqp://guest@localhost//\"\n\n CELERY_QUEUES = (\n Queue(\n 'important',\n exchange=Exchange('important'),\n routing_key=\"important\",\n queue_arguments={'x-max-length': 10}\n ),\n )\n\napp = Celery('tasks')\napp.config_from_object(Config)\n\n\n@app.task(queue='important')\ndef process_data(x):\n pass\n```\n\n```text\nrabbitmqctl set_policy Ten \"^one-meg$\" '{\"max-length-bytes\":1000000}' --apply-to queues\n```\n\n```text\nx-max-length\n```\n\n========================================\n\nComments:\n- Add more workers to catch up with the queue\n- @noorul: this was not my question. I can't add more workers. I can only refrain from feeding the queue if it is full. My question is how do I set its size and how do I know it is full.\n- I am not sure how we can define the fullness of a Celery queue. May be you can put another queue in front of Celery queue and control that.\n- the queue will not get throttled unless you configure it. however it would say that it looks like you need to rethink your design. it's hard to say how, since the code you give is too generic.\n- Can you change process_data so it records a status somewhere, so you can check how many of them are still running?\n- What happens with the .delay() call in this case?\n- task will be added to the queue, but if queue limit reached `Messages will be dropped or dead-lettered from the front of the queue to make room for new messages once the limit is reached.`rabbit. By issue in github Block publishers when queue length limit is reached is imposible right now","metadata":{"transformedAt":"2026-08-18T18:33:20.129Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":116,"estimatedTokens":837}}147{"id":"stack-30695375","source":"stackoverflow","questionId":30695375,"title":"RabbitMQ and channels Java thread safety","tags":["java","multithreading","rabbitmq"],"text":"Title: RabbitMQ and channels Java thread safety\nTags: java, multithreading, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nin this guide https://www.rabbitmq.com/api-guide.html RabbitMQ guys state:\n\nChannels and Concurrency Considerations (Thread Safety)\n\nChannel instances must not be shared between threads. Applications should prefer using a Channel per thread instead of sharing the same Channel across multiple threads. While some operations on channels are safe to invoke concurrently, some are not and will result in incorrect frame interleaving on the wire. Sharing channels between threads will also interfere with * Publisher Confirms.\n\nThread safety is very important so I tried to be as diligent as possible, but here's the problem:\n\nI have this application that receives messages from Rabbit. When a message is received, it processes it and then acks when it's done. The application can process just 2 items at the same time in a fixed thread pool with 2 threads. The QOS prefetch for Rabbit is set to 2, because I don't want to feed the app with more than it can handle in a time frame.\n\nNow, my consumer's handleDelivery does the following:\n\n```\nTask run = new Task(JSON.parse(message)); \nservice.execute(new TestWrapperThread(getChannel(),run,envelope.getDeliveryTag()));\n```\n\nAt this point, you already figured out that TestWrapperThread does the `channel.basicAck(deliveryTag, false);` call as last operation.\n\nBy my understanding of the documentation, this is incorrect and potentially harmful because channel is not thread safe and this behavior could screw things up. But how I am supposed to do then? I mean, I have a few ideas but they would def make everything more complex and I'd like to figure it out if it's really necessary or not.\n\nThanks in advance\n\n========================================\n\nCode:\n```text\nTask run = new Task(JSON.parse(message)); \nservice.execute(new TestWrapperThread(getChannel(),run,envelope.getDeliveryTag()));\n```\n\n```text\nchannel.basicAck(deliveryTag, false);\n```\n\n```text\nchannel.basicAck(deliveryTag, false);\n```\n\n```text\npublic void basicAck(long deliveryTag, boolean multiple)\n throws IOException\n{\n transmit(new Basic.Ack(deliveryTag, multiple));\n}\n```\n\n```text\npublic void transmit(Method m) throws IOException {\n synchronized (_channelMutex) {\n transmit(new AMQCommand(m));\n }\n}\n```\n\n```text\nChannel\n```\n\n```text\nChannelN.java\n```\n\n```text\ntransmit\n```\n\n```text\n_channelMutex\n```\n\n```text\nprotected final Object _channelMutex = new Object();\n```\n\n========================================\n\nComments:\n- If I understood, your question is about multithreading channel.basicAck(deliveryTag, false); is that right?\n- Correct. That is my only concern\n- Only the consumer. So you're substantially confirming it shouldn't be a problem? Do you think the documentation actually meant \"be thread safe in promiscuous receive/send situations\"?\n- Thanks Gas. I think I have a theory on why they substantially say you shouldn't multi-thread a channel, also explicitly mentioning the acknowledgement operation. I think the problem is if you massively use the channel in various threads, in send operations of big amount of data you basically block the channel until they're done. Now if you need to send back acknowledgements as well, they might delay a lot, possibly having your system to trigger \"recovery\" procedures when it's actually not needed.\n- Note that consuming (basicConsume) and acking from more than one thread is a common rabbitmq pattern that is already used by the java client.\n- @SimonePezzano it is more about `incorrect frame interleaving on the wire.` than blocking.\n- Thanks everyone for the great help. At this point, all I had to do was trying to figure out what frame interleaving actually is in the RabbitMQ context. And I found it out. Every time you publish a non-empty message, your client sends 3 (or more) frames on the wire: `[method: basic.publish] [content headers] [content body]+` When publishing on the same channel from multiple threads, you may end up with incorrect interleaving, e.g. `[method: basic.publish] [content headers] [method: basic.publish] [content body] [content headers] [content body]` All clear then, thanks!","metadata":{"transformedAt":"2026-08-18T18:33:20.129Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":10,"totalLines":90,"estimatedTokens":1056}}148{"id":"stack-10268613","source":"stackoverflow","questionId":10268613,"title":"What are the language and product alternatives to Akka?","tags":["playframework","rabbitmq","akka","actor"],"text":"Title: What are the language and product alternatives to Akka?\nTags: playframework, rabbitmq, akka, actor\nSource: Stack Overflow\n\nQuestion:\nRight now I'm looking at Play Framework and like it a lot. One of the parts heavy advertised amongst the features offered in Play is Akka.\n\nIn order to better understand Akka and how to use it properly, can you tell me what are the alternatives in other languages or products?\n\nHow does RabbitMQ compare to it? Is there a lot of overlap? Is it practical using them together? IN what use cases?\n\n========================================\n\nTop Answer:\nI use RabbitMQ + Spring AMQP + Guava's EventBus to automatically register Actor-like messengers using Guava's EventBus for pattern matching the received messages. \n\nThe similarity to Spring AMQP and Akka is uncanny. Spring AMQP's SimpleMessageListenerContainer + MessageListener is pretty much equivalent to an Actor.\n\nHowever for all intents and purposes RabbitMQ is more *powerful* than Akka in that it has many client **implementations** in different languages, **provides persistence** (durable queues), **topological routing** and **pluggable QoS algorithms**. \n\nThat being said Akka is way more convenient and in theory Akka can do all of the above and some people have written extensions but most just use Akka and then have Akka deliver the messages over RabbitMQ. Also Spring AMQP SimpleMessageListener container is kind of heavy and its unclear what would happen if you created a couple of million of them.\n\n**In hindsight I would consider using Akka to RabbbitMQ instead of Spring AMQP for future projects.**\n\n========================================\n\nComments:\n- RabbitMQ is an AMQP broker, i.e. a transport. Akka is a concurrency/scalability/fault-tolerance toolkit. You can use AMQP as Akka Actor mailboxes or as Akka remoting transport.\n- Thanks for the answer,just to clerify, if I have multiple java applicatons, i want them to communicate, i will need rabbitmq. For example 2 seperate play 2 apps, seperate machines, akka can't be the joining framework, i will need jms or rabbitmq, is this correct?\n- You can “join” JVMs using remote actors, they come with a default transport which is based on Netty.\n- @ViktorKlang using AMQP as a durable mailbox doesn't feel right. AMQP shines in a pubsub/messaging scenario, whereas for a durable mailbox I'd rather consider a dedicated store of some sort (Redis, filesystem, etc)\n- Small correction with large impact: actors can ONLY be passed messages, that is the essence of the concept. Actors are a model of computation while rabbitMQ is a means to pass messages, hence they live on different levels of abstraction.\n- Akka supports durable mailboxes which are similar to the persistent queues that RabbitMQ provides.\n- Yes I found that out recently. My main beef with Akka is that if your using Java to interface with it you seem to have to do a lot of casting. The other thing is there are amqp clients in other languages like python.\n- According to letitcrash.com/post/29988753572/akka-amqp-proxies, Akka can use AMQP as a transport. AMQP is a standard wire-level protocol so doesn't preclude Akka or any programming language or operating environment from using it as a transport to communicate with clients written in other programming languages.\n- Yes that is right just like I noted In my answer there are extensions for Akka. Still you need some on top of Akka to talk to other technologies. There are couple of other issues with Akka in that you have to be very mindful of threadlocals.\n- As for a comparison with Quasar, I also suggest to take a look at blog.paralleluniverse.co/2015/05/21/quasar-vs-akka. Note that Galaxy is not yet production-ready (it'll be soon though) but on the other hand Quasar Actors are so similar to Erlang's (and thus so straightforward) that integrating with practically any messaging solution is extremely easy and we'll soon write more about that. DISCLAIMER: I'm part of the Quasar team.\n- It seems that it hasn't got anything for persistance. Maybe, different beast?","metadata":{"transformedAt":"2026-08-18T18:33:20.130Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":38,"estimatedTokens":1015}}149{"id":"stack-42003640","source":"stackoverflow","questionId":42003640,"title":"How to configure rabbitmq.config inside Docker containers?","tags":["docker","rabbitmq","docker-swarm-mode"],"text":"Title: How to configure rabbitmq.config inside Docker containers?\nTags: docker, rabbitmq, docker-swarm-mode\nSource: Stack Overflow\n\nQuestion:\nI'm using the official RabbitMQ Docker image (https://hub.docker.com/_/rabbitmq/) \n\nI've tried editing the `rabbitmq.config` file inside the container after running \n\n`docker exec -it /bin/bash`\n\nHowever, this seems to have no effect on the rabbitmq server running in the container. Restarting the container obviously didn't help either since Docker starts a completely new instance.\n\nSo I assumed that the only way to configure `rabbitmq.config` for a Docker container was to set it up before the container starts running, which I was able to partly do using the image's supported environment variables. \n\nUnfortunately, not all configuration options are supported by environment variables. For instance, I want to set `{auth_mechanisms, ['PLAIN', 'AMQPLAIN', 'EXTERNAL']}` in `rabbitmq.config`. \n\nI then found the `RABBITMQ_CONFIG_FILE` environment variable, which should allow me to point to the file I want to use as my conifg file. However, I've tried the following with no luck:\n\n```\ndocker service create --name rabbitmq --network rabbitnet \\\n-e RABBITMQ_ERLANG_COOKIE='mycookie' --hostname = \"{{Service.Name}}{{.Task.Slot}}\" \\\n--mount type=bind,source=/root/mounted,destination=/root \\\n-e RABBITMQ_CONFIG_FILE=/root/rabbitmq.config rabbitmq\n```\n\nThe default `rabbitmq.config` file containing:\n\n```\n[ { rabbit, [ { loopback_users, [ ] } ] } ]\n```\n\nis what's in the container once it starts\n\nWhat's the best way to configure `rabbitmq.config` inside Docker containers?\n\n========================================\n\nTop Answer:\nI'm able to run RabbitMQ with a mounted config using the following `bash` script: \n\n```\n#RabbitMQ props\nenv=dev\nrabbitmq_name=dev_rabbitmq\nrabbitmq_port=5672\n\n#RabbitMQ container\nif [ \"$(docker ps -aq -f name=${rabbitmq_name})\" ]; then\n echo Cleanup the existed ${rabbitmq_name} container\n docker stop ${rabbitmq_name} && docker rm ${rabbitmq_name} \n echo Create and start new ${rabbitmq_name} container\n docker run --name ${rabbitmq_name} -d -p ${rabbitmq_port}:15672 -v $PWD/rabbitmq/${env}/data:/var/lib/rabbitmq:rw -v $PWD/rabbitmq/${env}/definitions.json:/opt/definitions.json:ro -v $PWD/rabbitmq/${env}/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro rabbitmq:3-management\nelse\n echo Create and start new ${rabbitmq_name} container\n docker run --name ${rabbitmq_name} -d -p ${rabbitmq_port}:15672 -v $PWD/rabbitmq/${env}/data:/var/lib/rabbitmq:rw -v $PWD/rabbitmq/${env}/definitions.json:/opt/definitions.json:ro -v $PWD/rabbitmq/${env}/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro rabbitmq:3-management \nfi\n```\n\nI also have the following `config` files in my `rabbitmq/dev` dir\n\ndefinitions.json\n\n```\n{\n \"rabbit_version\": \"3.7.3\",\n \"users\": [{\n \"name\": \"welib\",\n \"password_hash\": \"su55YoHBYdenGuMVUvMERIyUAqJoBKeknxYsGcixXf/C4rMp\",\n \"hashing_algorithm\": \"rabbit_password_hashing_sha256\",\n \"tags\": \"\"\n }, {\n \"name\": \"admin\",\n \"password_hash\": \"x5RW/n1lq35QfY7jbJaUI+lgJsZp2Ioh6P8CGkPgW3sM2/86\",\n \"hashing_algorithm\": \"rabbit_password_hashing_sha256\",\n \"tags\": \"administrator\"\n }],\n \"vhosts\": [{\n \"name\": \"/\"\n }, {\n \"name\": \"dev\"\n }],\n \"permissions\": [{\n \"user\": \"welib\",\n \"vhost\": \"dev\",\n \"configure\": \".*\",\n \"write\": \".*\",\n \"read\": \".*\"\n }, {\n \"user\": \"admin\",\n \"vhost\": \"/\",\n \"configure\": \".*\",\n \"write\": \".*\",\n \"read\": \".*\"\n }],\n \"topic_permissions\": [],\n \"parameters\": [],\n \"global_parameters\": [{\n \"name\": \"cluster_name\",\n \"value\": \"rabbit@98c821300e49\"\n }],\n \"policies\": [],\n \"queues\": [],\n \"exchanges\": [],\n \"bindings\": []\n }\n```\n\nrabbitmq.config\n\n```\n[\n {rabbit, [\n {loopback_users, []},\n {vm_memory_high_watermark, 0.7},\n {vm_memory_high_watermark_paging_ratio, 0.8},\n {log_levels, [{channel, warning}, {connection, warning}, {federation, warning}, {mirroring, info}]},\n {heartbeat, 10}\n ]},\n {rabbitmq_management, [\n {load_definitions, \"/opt/definitions.json\"}\n ]}\n].\n```\n\n========================================\n\nCode:\n```text\ndocker service create --name rabbitmq --network rabbitnet \\\n-e RABBITMQ_ERLANG_COOKIE='mycookie' --hostname = \"{{Service.Name}}{{.Task.Slot}}\" \\\n--mount type=bind,source=/root/mounted,destination=/root \\\n-e RABBITMQ_CONFIG_FILE=/root/rabbitmq.config rabbitmq\n```\n\n```text\n[ { rabbit, [ { loopback_users, [ ] } ] } ]\n```\n\n```text\nrabbitmq.config\n```\n\n```text\ndocker exec -it <container-id> /bin/bash\n```\n\n```text\nrabbitmq.config\n```\n\n```text\n{auth_mechanisms, ['PLAIN', 'AMQPLAIN', 'EXTERNAL']}\n```\n\n```text\nrabbitmq.config\n```\n\n```text\nRABBITMQ_CONFIG_FILE\n```\n\n```text\nrabbitmq.config\n```\n\n```text\nrabbitmq.config\n```\n\n```text\nvolumes:\n- ./conf/myrabbit.conf:/etc/rabbitmq/rabbitmq.config\n```\n\n```text\n/etc/rabbitmq/rabbitmq.config\n```\n\n```text\n#RabbitMQ props\nenv=dev\nrabbitmq_name=dev_rabbitmq\nrabbitmq_port=5672\n\n#RabbitMQ container\nif [ \"$(docker ps -aq -f name=${rabbitmq_name})\" ]; then\n echo Cleanup the existed ${rabbitmq_name} container\n docker stop ${rabbitmq_name} && docker rm ${rabbitmq_name} \n echo Create and start new ${rabbitmq_name} container\n docker run --name ${rabbitmq_name} -d -p ${rabbitmq_port}:15672 -v $PWD/rabbitmq/${env}/data:/var/lib/rabbitmq:rw -v $PWD/rabbitmq/${env}/definitions.json:/opt/definitions.json:ro -v $PWD/rabbitmq/${env}/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro rabbitmq:3-management\nelse\n echo Create and start new ${rabbitmq_name} container\n docker run --name ${rabbitmq_name} -d -p ${rabbitmq_port}:15672 -v $PWD/rabbitmq/${env}/data:/var/lib/rabbitmq:rw -v $PWD/rabbitmq/${env}/definitions.json:/opt/definitions.json:ro -v $PWD/rabbitmq/${env}/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro rabbitmq:3-management \nfi\n```\n\n```text\n{\n \"rabbit_version\": \"3.7.3\",\n \"users\": [{\n \"name\": \"welib\",\n \"password_hash\": \"su55YoHBYdenGuMVUvMERIyUAqJoBKeknxYsGcixXf/C4rMp\",\n \"hashing_algorithm\": \"rabbit_password_hashing_sha256\",\n \"tags\": \"\"\n }, {\n \"name\": \"admin\",\n \"password_hash\": \"x5RW/n1lq35QfY7jbJaUI+lgJsZp2Ioh6P8CGkPgW3sM2/86\",\n \"hashing_algorithm\": \"rabbit_password_hashing_sha256\",\n \"tags\": \"administrator\"\n }],\n \"vhosts\": [{\n \"name\": \"/\"\n }, {\n \"name\": \"dev\"\n }],\n \"permissions\": [{\n \"user\": \"welib\",\n \"vhost\": \"dev\",\n \"configure\": \".*\",\n \"write\": \".*\",\n \"read\": \".*\"\n }, {\n \"user\": \"admin\",\n \"vhost\": \"/\",\n \"configure\": \".*\",\n \"write\": \".*\",\n \"read\": \".*\"\n }],\n \"topic_permissions\": [],\n \"parameters\": [],\n \"global_parameters\": [{\n \"name\": \"cluster_name\",\n \"value\": \"rabbit@98c821300e49\"\n }],\n \"policies\": [],\n \"queues\": [],\n \"exchanges\": [],\n \"bindings\": []\n }\n```\n\n```text\n[\n {rabbit, [\n {loopback_users, []},\n {vm_memory_high_watermark, 0.7},\n {vm_memory_high_watermark_paging_ratio, 0.8},\n {log_levels, [{channel, warning}, {connection, warning}, {federation, warning}, {mirroring, info}]},\n {heartbeat, 10}\n ]},\n {rabbitmq_management, [\n {load_definitions, \"/opt/definitions.json\"}\n ]}\n].\n```\n\n```text\nbash\n```\n\n```text\nconfig\n```\n\n```text\nrabbitmq/dev\n```\n\n========================================\n\nComments:\n- I am trying to add config file to my own image with `COPY ./rabbitmq.config /etc/rabbitmq/rabbitmq.config` and then `CMD [\"rabbitmq-server\"]` but it seems that the file I add gets overwritten by default config file. it might be that default config file is created by \"rabbit-server\" command\n- Yes, the file just gets overwritten by Rabbit, and some of the values such as default_permissions get deleted. Extremely irritating.\n- @KirillG. According to docker-entrypoint.sh of that image, it happens because you provide env vars that are starting from RABBITMQ_. If you place everything in own config initially and do not feed anything from env then it doesn't override. Though this becomes more problematic as saving password in config and sending to git looks even worse.\n- for old erland conf -> - ./conf/myrabbit.conf:/etc/rabbitmq/rabbitmq.config for newer version -> - ./conf/myrabbit.conf:/etc/rabbitmq/rabbitmq.conf\n- In my case the location for the config file inside the docker container was `/etc/rabbitmq/conf.d/my_config.conf`","metadata":{"transformedAt":"2026-08-18T18:33:20.130Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":18,"totalLines":278,"estimatedTokens":2129}}150{"id":"stack-16691161","source":"stackoverflow","questionId":16691161,"title":"Getting number of messages in a RabbitMQ queue","tags":["python","rabbitmq","message-queue","py-amqplib"],"text":"Title: Getting number of messages in a RabbitMQ queue\nTags: python, rabbitmq, message-queue, py-amqplib\nSource: Stack Overflow\n\nQuestion:\nWe're using amqplib to publish/consume messages. I want to be able to read the number of messages on a queue (ideally both acknowledged and unacknowledged). This will allow me to show a nice status diagram to the admin users and detect if a certain component is not keeping up with the load.\n\nI can't find any information in the amqplib docs about reading queue status.\n\nCan someone point me in the right direction?\n\n========================================\n\nTop Answer:\nfollowing the answer of ChillarAnand you can get the value easily. the data is in the object.\n\n```\nimport pika\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost',\n port=5672,\n credentials=pika.credentials.PlainCredentials('guest', 'guest'),\n )\nchannel = connection.channel()\nprint(channel.queue_declare(queue=\"your_queue\", durable=True, exclusive=False,\n auto_delete=False).method.message_count)\n```\n\nand you will get the exact message number\n\n========================================\n\nCode:\n```text\nimport pika\n\npika_conn_params = pika.ConnectionParameters(\n host='localhost', port=5672,\n credentials=pika.credentials.PlainCredentials('guest', 'guest'),\n)\nconnection = pika.BlockingConnection(pika_conn_params)\nchannel = connection.channel()\nqueue = channel.queue_declare(\n queue=\"your_queue\", durable=True,\n exclusive=False, auto_delete=False\n)\n\nprint(queue.method.message_count)\n```\n\n```text\nfrom pyrabbit.api import Client\ncl = Client('localhost:55672', 'guest', 'guest')\ncl.get_messages('example_vhost', 'example_queue')[0]['message_count']\n```\n\n```text\ncurl -i -u user:password http://localhost:15672/api/queues/vhost/queue\n```\n\n```text\ncurl -i -u guest:guest http://localhost:15672/api/queues/%2f/celery\n```\n\n```text\n$ sudo rabbitmqctl list_queues | grep 'my_queue'\n```\n\n```text\n/\n```\n\n```text\n%2f\n```\n\n```text\nchannel.queueDeclarePassive(queueName).getMessageCount()\n```\n\n```text\nqueue_declare()\n```\n\n```text\nimport pika\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost',\n port=5672,\n credentials=pika.credentials.PlainCredentials('guest', 'guest'),\n )\nchannel = connection.channel()\nprint(channel.queue_declare(queue=\"your_queue\", durable=True, exclusive=False,\n auto_delete=False).method.message_count)\n```\n\n========================================\n\nComments:\n- Check this answer stackoverflow.com/questions/8192584/…\n- Thanks @mike, that's largely what I ended up doing when I had to reimplement some of this in C#. For the Python approach, I ended up hitting the rabbitmq-admin plugin and querying that instead. In any case, I appreciate the pointer.\n- \"Q: Using Python how to I...\" - \"A: Using Java you do...\" -> -1\n- as of today, `Python` is not mentioned in the OP\n- amqplib is a python library and the question *is* tagged Python but I agree I could've been a lot clearer, so apologies for the confusion\n- The `PyRabbit` solution retrieves a message from the queue. I think you want to use `cl.get_queue(\"example_vhost\", \"example_queue\")['messages']` instead.\n- How would you get the number of unack'd messages in a queue?\n- For pika: Just leaving this here because it bit me and cost me a couple of hours. It's important to understand that this is only the \"true\" number of messages if the consumers haven't prefetched too many messages. Refer to pika.readthedocs.io/en/stable/modules/… for the `prefetch_count`.\n- I believe queue declare with pika should be done this way: `queue = channel.queue_declare(queue=\"your_queue\", passive=True)` This won't fail if say, the durable value of your declare statement mismatches that of the currently existing queue.\n- Why did you just copy Chillar's answer over a year later?\n- It was a different answer when i answered. look at the edit log...","metadata":{"transformedAt":"2026-08-18T18:33:20.130Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":112,"estimatedTokens":990}}151{"id":"stack-11926077","source":"stackoverflow","questionId":11926077,"title":"RabbitMQ: messages remain \"Unacknowledged\"","tags":["java","message-queue","rabbitmq","amqp"],"text":"Title: RabbitMQ: messages remain \"Unacknowledged\"\nTags: java, message-queue, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nMy Java application sends messages to RabbitMQ exchange, then exchange redirects messages to binded queue.\nI use Springframework AMQP java plugin with RabbitMQ.\n\nThe problem: message comes to queue, but it stays in \"Unacknowledged\" state, it never becomes \"Ready\". \n\nWhat could be the reason?\n\n========================================\n\nTop Answer:\nJust to add my 2 cents for another possible reason for messages staying in an unacknowledged state, even though the consumer makes sure to use the basicAck method-\n\nSometimes multiple instances of a process with an open RabbitMQ connection stay running, one of which may cause a message to get stuck in an unacknowledged state, preventing another instance of the consumer to ever refetch this message.\n\nYou can access the RabbitMQ management console (for a local machine this should be available at localhost:15672), and check whether multiple instances get hold of the channel, or if only a single instance is currently active:\n\nhttps://i.sstatic.net/6j0zO.png\n\nFind the redundant running task (in this case - java) and terminate it. After removing the rogue process, you should see the message jumps to Ready state again.\n\n========================================\n\nCode:\n```text\nchannel.queueDeclare(queueName, ....)\n```\n\n```text\nbool ackMode = false;\nQueueingConsumer consumer = new QueueingConsumer(channel);\nchannel.basicConsume(queueName, ackMode, consumer);\n```\n\n```text\nQueueingConsumer.Delivery delivery = consumer.nextDelivery();\n//...do something with the message...\nchannel.basicAck(delivery.getEnvelope().getDeliveryTag(), false); //the false flag is to do with multiple message acknowledgement\n```\n\n========================================\n\nComments:\n- This answer is just amazing. I was stuck on this without knowing the reason why few minutes ago my messages were being delivered flawlessly and then why they werent after i restarted my mac. Do you know why that would happed?\n- Just want to add to the above, this is what happened to me. I tried to view messages in a queue from the management console, and for some reason the page never loaded and the messages were stuck in unacknowledged. I hoped they would just time out overnight, but they didn't. The above advice lead me to find an open connection with my user. As soon as i forced that closed, the messages all went back to ready. Thankfully these messages were unimportant so the delay doesn't matter. However, recovering from this is valuable information to know.\n- This appears to be the case for me as well, however I do not understand why. I have two separate connections one for Publisher and one for Consumer. When I close the Consumer connection and the connection is re-established, the message is delivered. This makes little sense to me right now since I'd expect long running connections to work. I know I'm missing some configuration somewhere, just not sure what yet.","metadata":{"transformedAt":"2026-08-18T18:33:20.130Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":50,"estimatedTokens":758}}152{"id":"stack-48524536","source":"stackoverflow","questionId":48524536,"title":"Can anyone please tell me what are the differences between pika and kombu messaging library in python?","tags":["python-2.7","rabbitmq","amqp","pika","kombu"],"text":"Title: Can anyone please tell me what are the differences between pika and kombu messaging library in python?\nTags: python-2.7, rabbitmq, amqp, pika, kombu\nSource: Stack Overflow\n\nQuestion:\nI want to use messaging library in my application to interact with rabbitmq. Can anyone please explain the differences between pika and kombu library?\n\n========================================\n\nCode:\n```text\npy-amqp\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.130Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":13,"estimatedTokens":103}}153{"id":"stack-8224482","source":"stackoverflow","questionId":8224482,"title":"Examples of Django and Celery: Periodic Tasks","tags":["django","rabbitmq","celery","django-celery"],"text":"Title: Examples of Django and Celery: Periodic Tasks\nTags: django, rabbitmq, celery, django-celery\nSource: Stack Overflow\n\nQuestion:\nI have been fighting the Django/Celery documentation for a while now and need some help.\n\nI would like to be able to run Periodic Tasks using django-celery. I have seen around the internet (and the documentation) several different formats and schemas for how one should go about achieving this using Celery...\n\nCan someone help with a basic, functioning example of the creation, registration and execution of a django-celery periodic task? In particular, I want to know whether I should write a task that extends the PeriodicTask class and register that, or whether I should use the @periodic_task decorator, or whether I should use the @task decorator and then set up a schedule for the task's execution.\n\nI don't mind if all three ways are possible, but I would like to see an example of at least one way that works. Really appreciate your help.\n\n========================================\n\nCode:\n```text\nfrom celery.task import PeriodicTask\nfrom clickmuncher.messaging import process_clicks\nfrom datetime import timedelta\n\n\nclass ProcessClicksTask(PeriodicTask):\n run_every = timedelta(minutes=30)\n\n def run(self, **kwargs):\n process_clicks()\n```\n\n```text\nfrom celery.task.schedules import crontab\nfrom celery.task import periodic_task\n\n@periodic_task(run_every=crontab(minute=\"*/30\"))\ndef process_clicks():\n ....\n```\n\n========================================\n\nComments:\n- Thanks for your answer. It's good to know what exactly the decorator is for and why two forms of the same thing exist. Is it correct that I do not have to register PeriodicTasks then? I found this example hard to find in the documentation and it could do with simplification (as you have done above). Thanks again.\n- Hey, here is another example from the docs: ask.github.com/celery/reference/celery.decorators.html You don't have to explicitly register the task if you use the decorator. It's pretty similar to the options you have registering your templatetags and filters in Django (docs.djangoproject.com/en/dev/howto/custom-template-tags/…)‌​, if you're more familiar with that.\n- How do you check that celery has picked up the scheduled tasks? I can see that the task is registered when I run `manage.py celery inspect registered`, but it is not in `manage.py celery inspect scheduled`. I have workers, and beat is running.\n- The `@periodic_task` decorator is deprecated as of Celery 3.1. github.com/celery/celery/issues/1764","metadata":{"transformedAt":"2026-08-18T18:33:20.130Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":45,"estimatedTokens":643}}154{"id":"stack-23766658","source":"stackoverflow","questionId":23766658,"title":"RabbitMQ: What Does Celery Offer That Pika Doesn't?","tags":["python","rabbitmq","celery","task-queue","pika"],"text":"Title: RabbitMQ: What Does Celery Offer That Pika Doesn't?\nTags: python, rabbitmq, celery, task-queue, pika\nSource: Stack Overflow\n\nQuestion:\nI've been working on getting some distributed tasks working via RabbitMQ.\n\nI spent some time trying to get Celery to do what I wanted and couldn't make it work.\n\nThen I tried using Pika and things just worked, flawlessly, and within minutes.\n\nIs there anything I'm missing out on by using Pika instead of Celery?\n\n========================================\n\nTop Answer:\nI’m going to add an answer here because this is the second time today someone has recommended celery when not needed based on this answer I suspect. So the difference between a distributed task queue and a broker is that a broker just passes messages. Nothing more, nothing less. Celery recommends using RabbitMQ as the default broker for IPC and places on top of that adapters to manage task/queues with daemon processes. While this is useful especially for distributed tasks where you need something generic very quickly. It’s just construct for the publisher/consumer process. Actual tasks where you have defined workflow that you need to step through and ensure message durability based on your specific needs, you’d be better off writing your own publisher/consumer than relying on celery. Obviously you still have to do all of the durability checking etc. With most web related services one doesn’t control the actual “work” units but rather, passes them off to a service. Thus it makes little sense for a distributed tasks queue unless you’re hitting some arbitrary API call limit based on ip/geographical region or account number... Or something along those lines. So using celery doesn’t stop you from having to write or deal with state code or management of workflow etc and it exposes the AMQP in a way that makes it easy for you to avoid writing the constructs of publisher/consumer code. \n\nSo in short if you need a simple tasks queue to chew through work and you aren’t really concerned about the nuances of performance, the intricacies of durability through your workflow or the actual publish/consume processes. Celery works. If you are just passing messages to an api or service you don't actually control, sure, you could use Celery but you could just as easily whip up your own publisher/consumer with Pika in a couple of minutes. If you need something robust or that adheres to your own durability scenarios, write your own publish/consumer code like everyone else.\n\n========================================\n\nCode:\n```text\n>>> from proj.tasks import add\n\n>>> res = add.chunks(zip(range(100), range(100)), 10)()\n>>> res.get()\n[[0, 2, 4, 6, 8, 10, 12, 14, 16, 18],\n [20, 22, 24, 26, 28, 30, 32, 34, 36, 38],\n [40, 42, 44, 46, 48, 50, 52, 54, 56, 58],\n [60, 62, 64, 66, 68, 70, 72, 74, 76, 78],\n [80, 82, 84, 86, 88, 90, 92, 94, 96, 98],\n [100, 102, 104, 106, 108, 110, 112, 114, 116, 118],\n [120, 122, 124, 126, 128, 130, 132, 134, 136, 138],\n [140, 142, 144, 146, 148, 150, 152, 154, 156, 158],\n [160, 162, 164, 166, 168, 170, 172, 174, 176, 178],\n [180, 182, 184, 186, 188, 190, 192, 194, 196, 198]]\n```\n\n```text\nrange(0, 100)\n```\n\n```text\nrange(0,100)\n```\n\n```text\nadd\n```\n\n```text\n1+1\n```\n\n```text\n2+2\n```\n\n```text\n3+3\n```\n\n```text\nadd\n```\n\n```text\nres.get()\n```\n\n========================================\n\nComments:\n- What did you try to do that you couldn't get to work? Can you show us the code or perhaps describe the distributed algorithm you were attempting to use?","metadata":{"transformedAt":"2026-08-18T18:33:20.130Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":76,"estimatedTokens":876}}155{"id":"stack-52592796","source":"stackoverflow","questionId":52592796,"title":"Redis Pub/Sub vs Rabbit MQ","tags":["redis","rabbitmq","masstransit"],"text":"Title: Redis Pub/Sub vs Rabbit MQ\nTags: redis, rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nMy team wants to move to microservices architecture. Currently we are using Redis Pub/Sub as message broker for some legacy parts of our system. My colleagues think that it is naturally to continue use redis as service bus as they don't want spend their time on studying new product. But in my opinion RabbitMQ (especially with MassTransit) is a better approach for microservices. Could you please compare Redis Pub/Sub with Rabbit MQ and give me some arguments for Rabbit?\n\n========================================\n\nTop Answer:\nRabbitMQ is far more stable and robust than Redis for passing messages. \n\nRabbitMQ is able to hold and **store** a message if there is no consumer for it (e.g. your listener crashed , etc).\n\nRabbitMQ has different methods for communication: Pub/Sub , Queue. That you can use for load balancing , etc\n\nRedis is convenient for simple cases. If you can afford losing a message and you don't need queues then I think Redis is also a good option.\nIf you however can not afford losing a message then Redis is not a good option.\n\n========================================\n\nCode:\n```text\nRedis streaming\n```\n\n```text\nRedis streaming\n```\n\n```text\nMQTT\n```\n\n```text\nRMQ\n```\n\n========================================\n\nComments:\n- You might want to show this twitter.com/tastapod/status/1010462778207981569 to your colleagues, Dan North about the \"best programmer I know\".\n- Thanks a lot! What do you mean by \"RabbitMQ is far more stable and robust\"?\n- RabbitMQ supports persistent messages and transient messages. When it sends messages to the persistent queue, it writes data to permanent storage as soon as it arrives. RabbitMQ also writes transient messages to the disk, but only if they exceed the memory’s capacity. Redis does not support persistent messages by default. Developers must enable a feature called Redis Database (RDB) to take periodic snapshots of the RAM and store them on disk. Enabling data persistence on Redis adds overhead to data operations, which slows down message delivery.","metadata":{"transformedAt":"2026-08-18T18:33:20.130Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":44,"estimatedTokens":531}}156{"id":"stack-20740114","source":"stackoverflow","questionId":20740114,"title":"RX vs messaging queues like rabbitmq or zeromq?","tags":["rabbitmq","system.reactive","zeromq","reactive-programming"],"text":"Title: RX vs messaging queues like rabbitmq or zeromq?\nTags: rabbitmq, system.reactive, zeromq, reactive-programming\nSource: Stack Overflow\n\nQuestion:\nI'm quite new to these high level concurrency paradigms, and I've started using the scala RX bindings. So I'm trying to understand how RX differs from messaging queues like RabbitMQ or ZeroMQ?\n\nThey both appear to use the subscribe/publish paradigm. Somewhere I saw a tweet about RX being run atop RabbitMQ.\n\nCould someone explain the differences between RX and messaging queues? Why would I choose one over the other? Can one be substituted for the other, or are they mutually exclusive? In what areas do they overlap?\n\n========================================\n\nTop Answer:\nCould someone explain the differences between RX and these other messaging queues?\n\nRx is simply an abstraction over Events (any kind of event!). Receiving a message from a distributed queue **is** an Event, and often, ZeroMQ / RabbitMQ solutions often have to use and combine different Events quite a bit, which Rx is very good at.\n\nSo often, Rx makes writing ZeroMQ / RabbitMQ apps much *easier* than it would be otherwise :)\n\n========================================\n\nCode:\n```text\n[system.reactive]\n```\n\n```text\nIQueryable<T>\n```\n\n```text\nIQbservable<T>\n```\n\n```text\nWhere\n```\n\n```text\nSubject\n```\n\n========================================\n\nComments:\n- Queues do queueing. Rx does not. Rx is not distributed. Rx is event processing paradigm, not just pub/sub. Events are pub/sub paradigm.\n- Nice answer! However,you need be careful with your definition of Reactive Extensions (Rx) and which implementation you are referring to. For example, Rx extensions for Javascript do not incorporate Schedulers etc.\n- Bear in mind that `system.reactive` tag is the original .NET version, so I assumed that when answering.\n- fair point, but I am less clear whether the OP was asking for a .NET specific answer. No mention of that in the question. My comment is not to criticise your excellent answer, only to enhance it by considering other implementation perspectives too.\n- Worth pointing out. A lot of people do use this tag just because it gets more action than a lot of the ports.\n- @arcseldon You're right, indeed I was referring to rx-java when I asked the question, but at the time I wasn't aware it wasn't the first or only implementation; but this isn't clear from the question or tags.\n- Queuing technologies such as RabbitMQ and ZeroMQ make great candidates for Reactive. I'm in the process of changing a system using RabbitMQ to use Reactive on the client. The system takes a pub/sub stream and makes it an Observer to use anywhere in the client.\n- Here's a brand new opensourced rxjava-based client library for RabbitMQ that could be of interest: github.com/meltwater/rxrabbit\n- The link is broken, could you please recheck THanks\n- It was a decade ago @kuldeep ! :) Still, amazingly managed to find a working link to the demo video for you, now fixed.\n- Your answer sounds good - please can you link to examples where Rx and RabbitMQ are being used cooperatively - for instance do you have Github repo demos etc where Rx is being used as the Consumer of a Rabbit queue etc. Or can you please include skeleton code in your answer.\n- I *could* name several investment banks that do this, but I don't want to get sued. :) Suffice to say I can confirm it's a common scenario.","metadata":{"transformedAt":"2026-08-18T18:33:20.130Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":58,"estimatedTokens":851}}157{"id":"stack-28207327","source":"stackoverflow","questionId":28207327,"title":"How load balancer works in RabbitMQ","tags":["rabbitmq","load-balancing"],"text":"Title: How load balancer works in RabbitMQ\nTags: rabbitmq, load-balancing\nSource: Stack Overflow\n\nQuestion:\nI am new to RabbitMQ, so please excuse me for asking some trivial questions:\n\nWhen running a RabbitMQ cluster, if a node fails the load shifts to another node (without stopping the other nodes). Similarly, we can also add new nodes to the existing cluster without stopping existing nodes in the cluster. Is that correct?\n\nAssume that we start with a single RabbitMQ node, and create 100 queues on it. Now let's say that producers start sending messages at a faster rate. To handle this load, we add more nodes and make a cluster. But queues exist on the first node only. How does the load get balanced among nodes now? And if we need to add more queues, on which node should we add them? Or can we add them using the load balancer?\n\n========================================\n\nTop Answer:\nLet me try to answer your questions in a way that will help most developers.\n\n**Question 1.** When running a RabbitMQ cluster, if a node fails the load shifts to another node (without stopping the other nodes). Similarly, we can also add new nodes to the existing cluster without stopping existing nodes in the cluster. Is that correct?\n\nYou are absolutely correct, assuming RabbitMQ is running on a single host, but RabbitMQ's queue behaves differently in the cluster. By default, each queue lives on only one node in the cluster. As of Rabbit 2.6.0, however, we have a built-in active-active redundancy option for queues: **mirrored queues**. Declaring a mirrored queue is just like declaring a normal queue, but you pass an extra argument called `x-ha-policy`. The extra argument tells RabbitMQ that you want the queue to be mirrored across all nodes in the cluster. **This means that if a new node is added to the cluster after the queue is declared, it'll automatically begin hosting a slave copy of the queue.**\n\n**Question 2.** Assume that we start with a single RabbitMQ node, and create 100 queues on it. Now let's say that producers start sending messages at a faster rate. To handle this load, we add more nodes and make a cluster. But queues exist on the first node only. How does the load get balanced among nodes now? And if we need to add more queues, on which node should we add them? Or can we add them using the load balancer?\n\nThis question has multiple sub-questions.\n\nHow does the load get balanced among nodes now? On which node should we add the queues?\n\nSet to all, `x-ha-policy` tells RabbitMQ that you want the queue to be mirrored across all nodes in the cluster. This means that if a new node is added to the cluster after the queue is declared, it'll automatically begin hosting a slave copy of the queue.\n\nCan we add the queues using a load balancer?\n\nYou shouldn't, although you technically can (you would have to call the RabbitMQ API within a LB, which is not a good practice). A load balancer is used for resilient messaging infrastructure. Your cluster nodes are the servers behind the load balancer, and your producers and consumers are the customers.\n\n========================================\n\nCode:\n```text\nx-ha-policy\n```\n\n```text\nx-ha-policy\n```\n\n========================================\n\nComments:\n- Do we really need a Load balancer like HA Proxy for RabbitMQ cluster?\n- There is no one-line answer, but mostly for critical project yes, you did need.","metadata":{"transformedAt":"2026-08-18T18:33:20.130Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":48,"estimatedTokens":847}}158{"id":"stack-39664283","source":"stackoverflow","questionId":39664283,"title":"How to remove Rabbitmq so I can reinstall","tags":["rabbitmq"],"text":"Title: How to remove Rabbitmq so I can reinstall\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI was having trouble, so I went into the registry and removed the service entry for rabbitmq. Now when I try to reinstall it says it already exists but it doesn't start (since I removed it) and I can do a `sc delete rabbitmq`. How do I totally remove all traces of it and reinstall from scratch? I guess it exists somewhere and the registry entry is all that is gone and the install program says it us just updating it when I do the `rabbitmq-service install`. I tried \n`rabbitmq-service remove` but it says it doesn't exist.\n\n========================================\n\nTop Answer:\nRabbitMQ writes the service information into `HKEY_LOCAL_MACHINE\\SOFTWARE\\Ericsson\\Erlang\\ErlSrv\\1.1\\RabbitMQ`\n\nTo remove RabbitMQ manually you have to:\n\n- remove the key `HKEY_LOCAL_MACHINE\\SOFTWARE\\Ericsson\\Erlang\\ErlSrv\\1.1\\RabbitMQ`\n\n- remove the directory `C:\\Users\\%USERNAME%\\AppData\\Roaming\\RabbitMQ`\n\n- remove the installation-folder.\n\nNext time I suggest to use the `rabbitmq-service.bat` command to install and remove the service.\n\nyou have to execute it as `administrator`\n\n========================================\n\nCode:\n```text\nsc delete rabbitmq\n```\n\n```text\nrabbitmq-service install\n```\n\n```text\nrabbitmq-service remove\n```\n\n```py\nsudo apt-get remove --auto-remove rabbitmq-server\nsudo apt-get purge --auto-remove rabbitmq-server\n```\n\n```text\nrabbitmq\n```\n\n```text\nHKEY_LOCAL_MACHINE\\SOFTWARE\\Ericsson\\Erlang\\ErlSrv\\1.1\\RabbitMQ\n```\n\n```text\nHKEY_LOCAL_MACHINE\\SOFTWARE\\Ericsson\\Erlang\\ErlSrv\\1.1\\RabbitMQ\n```\n\n```text\nC:\\Users\\%USERNAME%\\AppData\\Roaming\\RabbitMQ\n```\n\n```text\nrabbitmq-service.bat\n```\n\n```text\nadministrator\n```\n\n```text\nbrew services stop rabbitmq\nbrew uninstall rabbitmq\n```\n\n```text\nrm -r /opt/homebrew/etc/rabbitmq \nrm -r /opt/homebrew/var/lib/rabbitmq\nrm -r /opt/homebrew/var/log/rabbitmq\n```\n\n```text\nbrew update\nbrew install rabbitmq\nbrew services start rabbitmq\n```\n\n```text\nbrew services restart rabbitmq\n```\n\n```text\nrabbitmq-server\n```\n\n```text\nbrew services stop rabbitmq\n brew services start rabbitmq\n```\n\n========================================\n\nComments:\n- Your question is on Windows and you have accepted answer for Ubuntu, that's a good change indeed\n- you don't need to remove Erlang\n- Yes but, sometimes it's necessary for compatibility reasons\n- The mention of `rabbitmq-service.bat` is very helpful here!! It's not easy to find in the rabbitmq documentation how to \"re-install\" the windows service, which is required sometimes. (\"Restart the server after [configuration] changes. Windows service users will need to re-install the service after adding or removing a configuration file.\"\n- Ahhhh, my `pstree` output on Ubuntu 16 looks so much more compact now. Not sure how it got on my machine in the first place.\n- @sashaboulouds thanks, Only these two commands are required to uninstall RabbitMQ\n- @HemantKumar which command?\n- @chrisFrisina I have removed that comment. You can easily uninstall RabbitMQ using the above command dont worry.","metadata":{"transformedAt":"2026-08-18T18:33:20.130Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":16,"totalLines":110,"estimatedTokens":773}}159{"id":"stack-8808909","source":"stackoverflow","questionId":8808909,"title":"Simple way to install RabbitMQ in Ubuntu?","tags":["ubuntu","rabbitmq","amqp"],"text":"Title: Simple way to install RabbitMQ in Ubuntu?\nTags: ubuntu, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nIs there any simple way to install RabbitMQ for Ubuntu? I did the the following:\n\nAdd the following line to `/etc/apt/sources.list`:\n\n```\ndeb http://www.rabbitmq.com/debian/ testing main\n```\n\nthen install with `apt-get`:\n\n```\n$ sudo apt-get install rabbitmq-server\n```\n\nBut I get the following error every time:\n\n```\nReading package lists... Done\nBuilding dependency tree \nReading state information... Done\nSome packages could not be installed. This may mean that you have\nrequested an impossible situation or if you are using the unstable\ndistribution that some required packages have not yet been created\nor been moved out of Incoming.\n\nSince you only requested a single operation it is extremely likely that\nthe package is simply not installable and a bug report against\nthat package should be filed.\nThe following information may help to resolve the situation:\n\nThe following packages have unmet dependencies:\n rabbitmq-server: Depends: erlang-nox (>= 1:12.b.3) but 1:11.b.5dfsg-11 is to be installed\n E: Broken packages\n```\n\nHow am I supposed to install dependencies and to control the version of `erlang-nox` since it is installed already?\n\n========================================\n\nTop Answer:\nSimplest way to install rabbitMQ in ubuntu:\n\n```\necho \"deb http://www.rabbitmq.com/debian/ testing main\" | sudo tee /etc/apt/sources.list.d/rabbitmq.list > /dev/null\nwget https://www.rabbitmq.com/rabbitmq-signing-key-public.asc\nsudo apt-key add rabbitmq-signing-key-public.asc\nsudo apt-get update\nsudo apt-get install rabbitmq-server -y\nsudo service rabbitmq-server start\nsudo rabbitmq-plugins enable rabbitmq_management\nsudo service rabbitmq-server restart\n```\n\nDefault username / password will be guest / guest and port for will be 15672; for UI - http://localhost:15672\n\nif you want to change the username and password or add new user please these \n\n```\nsudo rabbitmqctl add_user user_name password_for_this_user\nsudo rabbitmqctl set_user_tags user_name administrator\nsudo rabbitmqctl set_permissions -p / user_name \".*\" \".*\" \".*\"\n```\n\nand to delete guest user please run this command\n\n```\nsudo rabbitmqctl delete_user guest\n```\n\n========================================\n\nCode:\n```text\ndeb http://www.rabbitmq.com/debian/ testing main\n```\n\n```text\n$ sudo apt-get install rabbitmq-server\n```\n\n```text\nReading package lists... Done\nBuilding dependency tree \nReading state information... Done\nSome packages could not be installed. This may mean that you have\nrequested an impossible situation or if you are using the unstable\ndistribution that some required packages have not yet been created\nor been moved out of Incoming.\n\nSince you only requested a single operation it is extremely likely that\nthe package is simply not installable and a bug report against\nthat package should be filed.\nThe following information may help to resolve the situation:\n\nThe following packages have unmet dependencies:\n rabbitmq-server: Depends: erlang-nox (>= 1:12.b.3) but 1:11.b.5dfsg-11 is to be installed\n E: Broken packages\n```\n\n```text\n/etc/apt/sources.list\n```\n\n```text\napt-get\n```\n\n```text\nerlang-nox\n```\n\n```text\nsudo apt-get remove erlang-nox\n```\n\n```text\necho \"deb http://www.rabbitmq.com/debian/ testing main\" | sudo tee /etc/apt/sources.list.d/rabbitmq.list > /dev/null\nwget https://www.rabbitmq.com/rabbitmq-signing-key-public.asc\nsudo apt-key add rabbitmq-signing-key-public.asc\nsudo apt-get update\nsudo apt-get install rabbitmq-server -y\nsudo service rabbitmq-server start\nsudo rabbitmq-plugins enable rabbitmq_management\nsudo service rabbitmq-server restart\n```\n\n```text\nsudo rabbitmqctl add_user user_name password_for_this_user\nsudo rabbitmqctl set_user_tags user_name administrator\nsudo rabbitmqctl set_permissions -p / user_name \".*\" \".*\" \".*\"\n```\n\n```text\nsudo rabbitmqctl delete_user guest\n```\n\n```text\nwget http://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc\nsudo apt-key add erlang_solutions.asc\nsudo apt-get update\nsudo apt-get install erlang\nsudo apt-get install erlang-nox\nsudo dpkg -i rabbitmq-server_3.2.1-1_all.deb\n```\n\n```text\n/etc/apt/sources.list\n```\n\n```text\ndeb http://packages.erlang-solutions.com/ubuntu precise contrib\n```\n\n```text\necho \"deb http://www.rabbitmq.com/debian/ testing main\" | sudo tee -a /etc/apt/sources.list\necho \"deb http://packages.erlang-solutions.com/ubuntu wheezy contrib\" | sudo tee -a /etc/apt/sources.list\nwget http://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc\nsudo apt-key add erlang_solutions.asc\nsudo apt-get update\nsudo apt-get -y install erlang erlang-nox\nsudo apt-get -y --force-yes install rabbitmq-server\n# Enable the web interface\nsudo rabbitmq-plugins enable rabbitmq_management\nsudo service rabbitmq-server restart\n```\n\n```text\nwheezy\n```\n\n```text\ncat /etc/*-release | grep Debian\n```\n\n```text\necho \"deb http://www.rabbitmq.com/debian/ testing main\" | sudo tee /etc/apt/sources.list.d/rabbitmq.list > /dev/null\nwget https://www.rabbitmq.com/rabbitmq-signing-key-public.asc\nsudo apt-key add rabbitmq-signing-key-public.asc\nsudo apt-get update\nsudo apt-get install rabbitmq-server -y\nsudo service rabbitmq-server start\nsudo rabbitmq-plugins enable rabbitmq_management\nsudo service rabbitmq-server restart\n```\n\n========================================\n\nComments:\n- Thanks for your willing to help here , anyways I don't think it is the case here, I think it is something related with this virsion of Ubuntu which is 8, and with the new erlang, I removed erlang-nox , and then tried to install but didn't work , check this out plz gist.github.com/a588340f3743190ecd0a\n- The first link is dead.\n- The first link: - erlang-solutions.com/resources/download.html\n- It seems `sudo wget https://www.rabbitmq.com/rabbitmq-signing-key-public.asc` work well under Ubuntu 14.04. Rather than `http://www.rabbitmq.com/rabbitmq-signing-key-public.asc`\n- This didn't work for me, I got the same error when installing rabbitmq-server: `rabbitmq-server : Depends: erlang-nox (>= 1:16.b.3) but 1:15.b.1-dfsg-4+deb7u1 is to be installed or esl-erlang but it is not installable`\n- I had an error while `apt-get update` and this answer fixed it.\n- sudo apt-get install rabbitmq-server -y --allow-unauthenticated need to be appended\n- This answer is not solving the problem. It doesn't work. As described in the question, some issues with `erlang` arise.\n- On `sudo apt get update` I am getting `Failed to fetch https://www.rabbitmq.com/debian/dists/testing/main/binary-am‌​d64/Packages 404`. Any ideas?\n- please check Frankie Drake answer try it\n- Solved my problem, thanks. Though raabitmq-server can be installed by `sudo apt-get install rabbitmq-server` after adding repository, without downloading the binary.","metadata":{"transformedAt":"2026-08-18T18:33:20.130Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":17,"totalLines":204,"estimatedTokens":1717}}160{"id":"stack-39191238","source":"stackoverflow","questionId":39191238,"title":"Revoke a task from celery","tags":["python","rabbitmq","celery"],"text":"Title: Revoke a task from celery\nTags: python, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI want to explicitly revoke a task from celery. This is how I'm currently doing:-\n\n```\nfrom celery.task.control import revoke\n\nrevoke(task_id, terminate=True)\n```\n\nwhere task_id is `string`(have also tried converting it into UUID `uuid.UUID(task_id).hex)`.\n\nAfter the above procedure, when I start celery again `celery worker -A proj` it still consumes the same message and starts processing it. Why?\n\nWhen viewed via `flower`, the message is still there in the broker section. how do I delete the message so that it cant be consumed again?\n\n========================================\n\nCode:\n```text\nfrom celery.task.control import revoke\n\nrevoke(task_id, terminate=True)\n```\n\n```text\nstring\n```\n\n```text\nuuid.UUID(task_id).hex)\n```\n\n```text\ncelery worker -A proj\n```\n\n```text\nflower\n```\n\n```text\nrevoke\n```\n\n```text\nrevoke\n```\n\n```text\ntask_id\n```\n\n```text\nset\n```\n\n```text\nrevoke\n```\n\n```text\nset\n```\n\n```text\ncelery worker -A proj --statedb=/var/run/celery/worker.state\n```\n\n========================================\n\nComments:\n- How many workers are you using? Revoking tasks works by sending a broadcast message to all the workers, the workers then keep a list of revoked tasks in memory. When a worker starts up it will synchronize revoked tasks with other workers in the cluster. docs.celeryproject.org/en/latest/userguide/…\n- I’ve been trying to `revoke()` a task but it actually executes despite being marked as revoked: github.com/celery/celery/issues/4300 Any ideas what I might miss?\n- revoke also require state parameter which I don't know what is? did u know it ?\n- here is an issue that describes and ask for the workaround (to remove the task from the broker) github.com/celery/celery/issues/8888\n- I understand the search Implications, but what if you have to frequently create these tasks and then cancel frequently as well. That would also grow the list of tasks. You still have to iterate through the list anyway, to find the expired tasks to see whether you want to revoke it or executed. this way it becomes a memory problem. and this girl is drastically with longer ETAs","metadata":{"transformedAt":"2026-08-18T18:33:20.130Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":12,"totalLines":80,"estimatedTokens":549}}161{"id":"stack-18460016","source":"stackoverflow","questionId":18460016,"title":"Connect from one Docker container to another","tags":["rabbitmq","celery","docker"],"text":"Title: Connect from one Docker container to another\nTags: rabbitmq, celery, docker\nSource: Stack Overflow\n\nQuestion:\nI want to run rabbitmq-server in one docker container and connect to it from another container using celery (http://celeryproject.org/)\n\nI have rabbitmq running using the below command...\n\n```\nsudo docker run -d -p :5672 markellul/rabbitmq /usr/sbin/rabbitmq-server\n```\n\nand running the celery via\n\n```\nsudo docker run -i -t markellul/celery /bin/bash\n```\n\nWhen I am trying to do the very basic tutorial to validate the connection on http://docs.celeryproject.org/en/latest/getting-started/first-steps-with-celery.html\n\nI am getting a connection refused error:\n\n consumer: Cannot connect to amqp://guest@127.0.0.1:5672//: [Errno 111]\n Connection refused.\n\nWhen I install rabbitmq on the same container as celery it works fine.\n\nWhat do I need to do to have container interacting with each other?\n\n========================================\n\nTop Answer:\nJust get your container ip, and connect to it from another container:\n\n```\nCONTAINER_IP=$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' $CONTAINER_ID)\necho $CONTAINER_IP\n```\n\n========================================\n\nCode:\n```text\nsudo docker run -d -p :5672 markellul/rabbitmq /usr/sbin/rabbitmq-server\n```\n\n```text\nsudo docker run -i -t markellul/celery /bin/bash\n```\n\n```text\ndocker run --name rabbitmq -d -p :5672 markellul/rabbitmq /usr/sbin/rabbitmq-server\ndocker run --name celery -it markellul/celery /bin/bash\n```\n\n```text\ndocker network create -d bridge --subnet 172.25.0.0/16 mynetwork\n```\n\n```text\ndocker network connect mynetwork rabbitmq\ndocker network connect mynetwork celery\n```\n\n```text\ndocker run --name rabbitmq -d -p :5672 markellul/rabbitmq /usr/sbin/rabbitmq-server\n```\n\n```text\ndocker run --link rabbitmq:amq -i -t markellul/celery /bin/bash\n```\n\n```text\n$AMQ_PORT_5672_TCP_ADDR\n$AMQ_PORT_5672_TCP_PORT\n```\n\n```text\n/etc/hosts\n```\n\n```text\namq\n```\n\n```text\nsudo docker ps -a\n```\n\n```text\namqp://guest@HOST_IP:49xxx\n```\n\n```text\nCID=$(sudo docker run -d -p :5672 markellul/rabbitmq /usr/sbin/rabbitmq-server); sudo docker inspect $CID | grep IPAddress\n```\n\n```text\nCONTAINER_IP=$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' $CONTAINER_ID)\necho $CONTAINER_IP\n```\n\n```text\ndocker build -t \"imagename1\" .\n docker build -t \"imagename2\" .\n```\n\n```text\ndocker run -it -p 8000:8000 --name=imagename1 imagename1\ndocker run -it -p 8080:8080 --name=imagename2 imagename2\n```\n\n```text\ndocker network create -d bridge \"networkname\"\n```\n\n```text\ndocker network connect \"networkname\" \"imagename1\"\ndocker network connect \"networkname\" \"imagename2\"\n```\n\n```text\ndocker network inspect ''networkname\"\n```\n\n========================================\n\nComments:\n- Whats interesting in maestro, is they have a example todos app which does connect a node container to a mongodb container. Today I am investigating how the node app finds the mongodb one.\n- and can you get the HOST_IP automatically ?\n- @amattn did you install ifconfig in your container?\n- The container doesn't usually need it... I almost always install it on the host.\n- So how do you pass it to the container - I guess that would nicely finish up this line of information :)\n- ifconfig lists a whole bunch of info. there might be flags to get just the host, but I just run ifconfig, then copy paste the ip address into where ever it needs to go.\n- You can also check your /etc/hosts file, or docker inspect from the host\n- Pipework might be necessary in some scenarios, but not this one.\n- Your answer is great @alp, and since you updated it I would also mention Docker Compose as a long-term solution.\n- Docker compose is a great tool for bootstrapping and running, but not exactly in the scope of this question imo. Thanks nonetheless.","metadata":{"transformedAt":"2026-08-18T18:33:20.130Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":19,"totalLines":139,"estimatedTokens":953}}162{"id":"stack-39613476","source":"stackoverflow","questionId":39613476,"title":"How to handle SQLAlchemy Connections in ProcessPool?","tags":["python","sqlalchemy","rabbitmq","python-multiprocessing","python-asyncio"],"text":"Title: How to handle SQLAlchemy Connections in ProcessPool?\nTags: python, sqlalchemy, rabbitmq, python-multiprocessing, python-asyncio\nSource: Stack Overflow\n\nQuestion:\nI have a reactor that fetches messages from a RabbitMQ broker and triggers worker methods to process these messages in a process pool, something like this:\n\nhttps://i.sstatic.net/eKbAK.png\n\nThis is implemented using python `asyncio`, `loop.run_in_executor()` and `concurrent.futures.ProcessPoolExecutor`.\n\nNow I want to access the database in the worker methods using SQLAlchemy. Mostly the processing will be very straightforward and quick CRUD operations.\n\nThe reactor will process 10-50 messages per second in the beginning, so it is not acceptable to open a new database connection for every request. Rather I would like to maintain one persistent connection per process.\n\nMy questions are: How can I do this? Can I just store them in a global variable? Will the SQA connection pool handle this for me? How to clean up when the reactor stops?\n\n**[Update]**\n\n- The database is MySQL with InnoDB.\n\n**Why choosing this pattern with a process pool?**\n\nThe current implementation uses a different pattern where each consumer runs in its own thread. Somehow this does not work very well. There are already about 200 consumers each running in their own thread, and the system is growing quickly. To scale better, the idea was to separate concerns and to consume messages in an I/O loop and delegate the processing to a pool. Of course, the performance of the whole system is mainly I/O bound. However, CPU is an issue when processing large result sets.\n\nThe other reason was \"ease of use.\" While the connection handling and consumption of messages is implemented asynchronously, the code in the worker can be synchronous and simple. \n\nSoon it became evident that accessing remote systems through persistent network connections from within the worker are an issue. This is what the CommunicationChannels are for: Inside the worker, I can grant requests to the message bus through these channels.\n\nOne of my current ideas is to handle DB access in a similar way: Pass statements through a queue to the event loop where they are sent to the DB. However, I have no idea how to do this with SQLAlchemy. \nWhere would be the entry point? \nObjects need to be `pickled` when they are passed through a queue. How do I get such an object from an SQA query?\nThe communication with the database has to work asynchronously in order not to block the event loop. Can I use e.g. aiomysql as a database driver for SQA?\n\n========================================\n\nTop Answer:\n@roman: Nice challenge you have there.\n\nI have being in a similar scenario before so here is my *2 cents*: unless this consumer only *\"read\"* and *\"write\"* the message, without do any real proccessing of it, you could *re-design* this consumer as a consumer/producer that will *consume* the message, it will process the message and then will put result in another queue, that queue (processed messages for say) could be read by 1..N non-pooled asynchronous processes that would have open the DB connection in it's own entire life-cycle.\n\nI can extend my answer, but I don't know if this approach fits for your needs, if so, I can give you more detail about the extended design.\n\n========================================\n\nCode:\n```text\nasyncio\n```\n\n```text\nloop.run_in_executor()\n```\n\n```text\nconcurrent.futures.ProcessPoolExecutor\n```\n\n```text\npickled\n```\n\n```text\n# db.py\nengine = create_engine(\"connection_uri\", pool_size=1, max_overflow=0)\nDBSession = scoped_session(sessionmaker(bind=engine))\n```\n\n```text\n# task.py\nfrom db import engine, DBSession\ndef task():\n DBSession.begin() # each task will get its own transaction over the global connection\n ...\n DBSession.query(...)\n ...\n DBSession.close() # cleanup on task end\n```\n\n```text\nsession\n```\n\n```text\npool_size\n```\n\n```text\nmax_overflow\n```\n\n```text\npool_size\n```\n\n```text\nDBSession.remove()\n```\n\n```text\nrecycle\n```\n\n========================================\n\nComments:\n- So each worker is its own process? Can't connections then, so maybe you should instantiate each (local) SQA pools with max 1 or 2 connection limits. Then observe, maybe via database (which db ?) what connections are being spawned/killed. Having gotten badly burned on just this - what you **don't** want to do is implement your own naive conn pool on top of SQA's. Or try to identify if an SQA conn is closed or not.\n- @JLPeyret: I updated the question with the info you requested. And no ... I'm not planing to implement my own connection pool.\n- So, I think I remember that connections can't cross processes (in the OS sense of the word, to differentiate from threads). And I know connections don't pickle well at all. You should be able to message \"dead\" (string) sql statements but I believe you'll have a hard time passing around db conns, I think including probably SQA results. Speculation on my end, but with some extent of playing with odd SQA usage to justify it.\n- I was considering such an approach however I think it will be very hard to get the transaction handling right. I think I don't want to try building my own distributed transaction manager.\n- When I say CPU is an issue, I don't mean the major work load is CPU bound! It is not ... As with the other approach above, I see a serious issues with transaction handling here. To have a stateless network connection in between the business logic and the persistence layer sounds scary.\n- So you basically you suggest that I should not worry because the SQA pool will handle that right out of the box? This would be nice! I will migrate our main app with +200 consumers and +20000 lines of code to the new software architecture within the next few days and see if it works.\n- @roman Good luck with your refactor, if you have any issues don't hesitate to post a comment here, and if you feel that i covered your question it would be nice to mark this as accepted :) .\n- Seems to work fine so far! :) This section in the docs should be mentioned I think docs.sqlalchemy.org/en/rel_1_1/core/…. One has to take special care regarding multiprocessing.","metadata":{"transformedAt":"2026-08-18T18:33:20.131Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":114,"estimatedTokens":1547}}163{"id":"stack-28402374","source":"stackoverflow","questionId":28402374,"title":"AMQP 0-9-1 vs 1-0","tags":["rabbitmq","activemq-classic","messaging","amqp"],"text":"Title: AMQP 0-9-1 vs 1-0\nTags: rabbitmq, activemq-classic, messaging, amqp\nSource: Stack Overflow\n\nQuestion:\nI am looking for a messaging service that will have to interface some C# applications with some Java applications. I really like RabbitMQ because it seems to have amazing support for both technologies. I see in the RabbitMQ specs that at the moment only AMQP 0-9-1 model is provided.\n\nIs that a show stopper? Should I maybe address to ActiveMQ which provides AMQP 1.0?\n\n========================================\n\nComments:\n- Could you link to any evidence you saw regarding RabbitMQ's full support of AMQP 1.0. From what I'm reading they plan on supporting AMQP 0-9-1 'indefinitely' and only supporting AMQP 1.0 via plugin\n- Its supported by the plugin, they will maintain it and fix any bugs. Its kinda full support then?\n- Full support != native support. Native support would be (in my view) part of the core without a plugin. But a plugin can be used to fully support something, it is just part of a plugin since it isn't the normal use case for the software.\n- Just my two cents, but RabbitMQ is architected in such a way that almost everything is a plugin. So the name \"plugin\" doesn't mean it's not the normal use case for the software.","metadata":{"transformedAt":"2026-08-18T18:33:20.131Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":16,"estimatedTokens":313}}164{"id":"stack-5031606","source":"stackoverflow","questionId":5031606,"title":"Good Python library for AMQP","tags":["python","rabbitmq","amqp"],"text":"Title: Good Python library for AMQP\nTags: python, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nCan you recommend what Python library to use for accessing AMQP (RabbitMQ)? From my research `pika` seems to be the preferred one.\n\n========================================\n\nTop Answer:\nMy own research led me to believe that the right library to use would be Kombu, as this is also what Celery (mentioned by @SteveMc) has transitioned to. I am also using RabbitMQ and have used Kombu with the default amqplib backend successfully.\n\nKombu also supports other transports behind the same API. Useful if you need to replace AMQP or add something like redis to the mix. Haven't tried that though.\n\nSidenote: Kombu does currently not support the latest pika release (should you rely on it for some reason). Only 5.2.0 is currently supported, this bit me a while back.\n\n========================================\n\nCode:\n```text\npika\n```\n\n========================================\n\nComments:\n- github.com/mosquito/aio-pika, has typehints, supports asyncio\n- I just discovered that celery creates a queue per task which is a disappointing weakness celeryproject.org/docs/userguide/tasks.html#amqp-result-back‌​end\n- We haven't found that to be an issue; our usage tasks get consumed quickly (we very rarely expect anything to be sitting around longer than a few seconds). It may be implementation-specific, too - they specifically mention RabbitMQ there. I'd be interested to know if it's causing you difficulties though.\n- Never tried celery because it just didn't seem to fit with the overall AMQP architecture. Message queueuing is not just for distributing tasks to pools of workers.\n- Ok, good to know. Yeah.. the main plus for celery was that it took a lot of coding away. If we find problems we may end up writing a thin wrapper around pika, as you have done. Good luck with your project!\n- There are a lot of problems on pika, such as publish large message fail, heart-beat timeout fail;\n- Celery can be easily configured to use custom queues and send tasks to those queues instead of creating one queue per task.\n- The old \"amqp\" result backend creates one queue per task, this was to have an amqp based result backend that behaves like a database (any process can retrieve the result). The old \"amqp\" result backend should probably never be used in production. The \"rpc\" result backend however is non-persistent, creates one queue per client and is to be used if you need RPC style calls.\n- I briefly looked at txAMQP but development seems to have stagnated\n- You should update this response now that, according to the issue you link to, you discovered your mistake and that it was not Kombu that was broken.\n- @Brandon Craig Rhodes: done :)\n- stackoverflow.com/questions/48524536/… this provides a comparison between kombu and pika and will probably help future users more than just 'use this library'","metadata":{"transformedAt":"2026-08-18T18:33:20.131Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":38,"estimatedTokens":730}}165{"id":"stack-16370911","source":"stackoverflow","questionId":16370911,"title":"How to get Spring RabbitMQ to create a new Queue?","tags":["java","spring","rabbitmq","amqp"],"text":"Title: How to get Spring RabbitMQ to create a new Queue?\nTags: java, spring, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nIn my (limited) experience with rabbit-mq, if you create a new listener for a queue that doesn't exist yet, the queue is automatically created. I'm trying to use the Spring AMQP project with rabbit-mq to set up a listener, and I'm getting an error instead. This is my xml config:\n\n```\n\n \n\n \n\n```\n\nI get this in my RabbitMq logs:\n\n```\n=ERROR REPORT==== 3-May-2013::23:17:24 ===\nconnection , channel 1 - soft error:\n{amqp_error,not_found,\"no queue 'test' in vhost '/'\",'queue.declare'}\n```\n\nAnd a similar error from AMQP:\n\n```\n2013-05-03 23:17:24,059 ERROR [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-1) - Consumer received fatal exception on startup\norg.springframework.amqp.rabbit.listener.FatalListenerStartupException: Cannot prepare queue for listener. Either the queue doesn't exist or the broker will not allow us to use it.\n```\n\nIt would seem from the stack trace that the queue is getting created in a \"passive\" mode- Can anyone point out how I would create the queue not using the passive mode so I don't see this error? Or am I missing something else?\n\n========================================\n\nTop Answer:\nOlder thread, but this still shows up pretty high on Google, so here's some newer information:\n\n### 2015-11-23\n\nSince **Spring 4.2.x** with Spring-Messaging and **Spring-Amqp 1.4.5.RELEASE** and **Spring-Rabbit 1.4.5.RELEASE**, declaring exchanges, queues and bindings has become very simple through an @Configuration class some annotations:\n\n```\n@EnableRabbit\n@Configuration\n@PropertySources({\n @PropertySource(\"classpath:rabbitMq.properties\")\n})\npublic class RabbitMqConfig { \n private static final Logger logger = LoggerFactory.getLogger(RabbitMqConfig.class);\n\n @Value(\"${rabbitmq.host}\")\n private String host;\n\n @Value(\"${rabbitmq.port:5672}\")\n private int port;\n\n @Value(\"${rabbitmq.username}\")\n private String username;\n\n @Value(\"${rabbitmq.password}\")\n private String password;\n\n @Bean\n public ConnectionFactory connectionFactory() {\n CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host, port);\n connectionFactory.setUsername(username);\n connectionFactory.setPassword(password);\n\n logger.info(\"Creating connection factory with: \" + username + \"@\" + host + \":\" + port);\n\n return connectionFactory;\n }\n\n /**\n * Required for executing adminstration functions against an AMQP Broker\n */\n @Bean\n public AmqpAdmin amqpAdmin() {\n return new RabbitAdmin(connectionFactory());\n }\n\n /**\n * This queue will be declared. This means it will be created if it does not exist. Once declared, you can do something\n * like the following:\n * \n * @RabbitListener(queues = \"#{@myDurableQueue}\")\n * @Transactional\n * public void handleMyDurableQueueMessage(CustomDurableDto myMessage) {\n * // Anything you want! This can also return a non-void which will queue it back in to the queue attached to @RabbitListener\n * }\n */\n @Bean\n public Queue myDurableQueue() {\n // This queue has the following properties:\n // name: my_durable\n // durable: true\n // exclusive: false\n // auto_delete: false\n return new Queue(\"my_durable\", true, false, false);\n }\n\n /**\n * The following is a complete declaration of an exchange, a queue and a exchange-queue binding\n */\n @Bean\n public TopicExchange emailExchange() {\n return new TopicExchange(\"email\", true, false);\n }\n\n @Bean\n public Queue inboundEmailQueue() {\n return new Queue(\"email_inbound\", true, false, false);\n }\n\n @Bean\n public Binding inboundEmailExchangeBinding() {\n // Important part is the routing key -- this is just an example\n return BindingBuilder.bind(inboundEmailQueue()).to(emailExchange()).with(\"from.*\");\n }\n}\n```\n\nSome sources and documentation to help:\n\n- Spring annotations\n\n- Declaring/configuration RabbitMQ for queue/binding support\n\n- Direct exchange binding (for when routing key doesn't matter)\n\n**Note**: Looks like I missed a version -- starting with **Spring AMQP 1.5**, things get even easier as you can declare the full binding right at the listener!\n\n========================================\n\nCode:\n```text\n<rabbit:connection-factory id=\"rabbitConnectionFactory\" host=\"172.16.45.1\" username=\"test\" password=\"password\" />\n\n<rabbit:listener-container connection-factory=\"rabbitConnectionFactory\" >\n <rabbit:listener ref=\"testQueueListener\" queue-names=\"test\" />\n</rabbit:listener-container>\n\n<bean id=\"testQueueListener\" class=\"com.levelsbeyond.rabbit.TestQueueListener\"> \n</bean>\n```\n\n```text\n=ERROR REPORT==== 3-May-2013::23:17:24 ===\nconnection <0.1652.0>, channel 1 - soft error:\n{amqp_error,not_found,\"no queue 'test' in vhost '/'\",'queue.declare'}\n```\n\n```text\n2013-05-03 23:17:24,059 ERROR [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-1) - Consumer received fatal exception on startup\norg.springframework.amqp.rabbit.listener.FatalListenerStartupException: Cannot prepare queue for listener. Either the queue doesn't exist or the broker will not allow us to use it.\n```\n\n```text\n<rabbit:listener-container connection-factory=\"rabbitConnectionFactory\" >\n <rabbit:listener ref=\"orderQueueListener\" queues=\"test.order\" />\n</rabbit:listener-container>\n\n<rabbit:queue name=\"test.order\"></rabbit:queue>\n\n<rabbit:admin id=\"amqpAdmin\" connection-factory=\"rabbitConnectionFactory\"/>\n\n<bean id=\"orderQueueListener\" class=\"com.levelsbeyond.rabbit.OrderQueueListener\"> \n</bean>\n```\n\n```text\n<rabbit:queue name=\"test\" auto-delete=\"true\" durable=\"false\" passive=\"false\" />\n```\n\n```text\n@EnableRabbit\n@Configuration\n@PropertySources({\n @PropertySource(\"classpath:rabbitMq.properties\")\n})\npublic class RabbitMqConfig { \n private static final Logger logger = LoggerFactory.getLogger(RabbitMqConfig.class);\n\n @Value(\"${rabbitmq.host}\")\n private String host;\n\n @Value(\"${rabbitmq.port:5672}\")\n private int port;\n\n @Value(\"${rabbitmq.username}\")\n private String username;\n\n @Value(\"${rabbitmq.password}\")\n private String password;\n\n @Bean\n public ConnectionFactory connectionFactory() {\n CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host, port);\n connectionFactory.setUsername(username);\n connectionFactory.setPassword(password);\n\n logger.info(\"Creating connection factory with: \" + username + \"@\" + host + \":\" + port);\n\n return connectionFactory;\n }\n\n /**\n * Required for executing adminstration functions against an AMQP Broker\n */\n @Bean\n public AmqpAdmin amqpAdmin() {\n return new RabbitAdmin(connectionFactory());\n }\n\n /**\n * This queue will be declared. This means it will be created if it does not exist. Once declared, you can do something\n * like the following:\n * \n * @RabbitListener(queues = \"#{@myDurableQueue}\")\n * @Transactional\n * public void handleMyDurableQueueMessage(CustomDurableDto myMessage) {\n * // Anything you want! This can also return a non-void which will queue it back in to the queue attached to @RabbitListener\n * }\n */\n @Bean\n public Queue myDurableQueue() {\n // This queue has the following properties:\n // name: my_durable\n // durable: true\n // exclusive: false\n // auto_delete: false\n return new Queue(\"my_durable\", true, false, false);\n }\n\n /**\n * The following is a complete declaration of an exchange, a queue and a exchange-queue binding\n */\n @Bean\n public TopicExchange emailExchange() {\n return new TopicExchange(\"email\", true, false);\n }\n\n @Bean\n public Queue inboundEmailQueue() {\n return new Queue(\"email_inbound\", true, false, false);\n }\n\n @Bean\n public Binding inboundEmailExchangeBinding() {\n // Important part is the routing key -- this is just an example\n return BindingBuilder.bind(inboundEmailQueue()).to(emailExchange()).with(\"from.*\");\n }\n}\n```\n\n```java\n@Component\npublic class QueueConfig {\n\n private AmqpAdmin amqpAdmin;\n\n public QueueConfig(AmqpAdmin amqpAdmin) {\n this.amqpAdmin = amqpAdmin;\n }\n\n @PostConstruct\n public void createQueues() {\n amqpAdmin.declareQueue(new Queue(\"queue_one\", true));\n amqpAdmin.declareQueue(new Queue(\"queue_two\", true));\n }\n}\n```\n\n========================================\n\nComments:\n- Unfortunately, I get an error that the \"passive\" attribute isn't allowed in the queue element on startup. It is weird that the \"declare\" method takes the passive argument, but I can't seem to define it in xml.\n- Sorry I'm being dense- I don't see what I'm missing. I see you're saying it's not valid xml according to the xsd and I can ignore the error eclipse gives me- but I actually get a runtime error as well.\n- That's okay. My middle name is dense. :-) I think we're saying the same thing. IMHO, the above passive parameter should be present if it's a full rabbit interface. Spring RabbitMQ is missing it. I would file a bug report with them and link back to this question in your bug report. They may know something that we're both missing or it may just be a legitimate omission.\n- Yes, you have to add a `RabbitAdmin` to your config to auto-declared queues, exchanges, bindings.\n- Also, the queue won't be declared until a message is sent to it.\n- It worked in Java annotation mode too: adding an autowired `AmqpAdmin` and declaring the queue with the dedicated method autocreates the queue when not present !\n- Using the rabbit:listener element, how can one get rabbit to declare a randomly named queue for use with a fanout exchange?\n- You create beans and create objects again with methods invocation.","metadata":{"transformedAt":"2026-08-18T18:33:20.131Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":284,"estimatedTokens":2437}}166{"id":"stack-63384705","source":"stackoverflow","questionId":63384705,"title":"Docker rabbitmq image fails with [error] Too short cookie string","tags":["docker","rabbitmq"],"text":"Title: Docker rabbitmq image fails with [error] Too short cookie string\nTags: docker, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nit seems like I do have a problem with the rabbitmq and rabbitmq-management docker image on my Windows machine running docker-desktop.\n\nWhen trying to run it, the following log comes up before it shuts down:\n\n```\n21:01:21.726 [error] Failed to write to cookie file '/var/lib/rabbitmq/.erlang.cookie': enospc\n\n21:01:22.355 [error] Too short cookie string\n\n21:01:22.356 [error] Too short cookie string\n\n21:01:23.161 [error] Too short cookie string\n\n21:01:23.162 [error] Too short cookie string\n\n21:01:23.783 [error] Too short cookie string\n\n21:01:23.784 [error] Too short cookie string\n\n21:01:24.405 [error] Too short cookie string\n\n21:01:24.406 [error] Too short cookie string\n\n21:01:25.027 [error] Too short cookie string\n\n21:01:25.028 [error] Too short cookie string\n\n21:01:25.661 [error] Too short cookie string\n\n21:01:25.662 [error] Too short cookie string\n\n21:01:26.281 [error] Too short cookie string\n\n21:01:26.282 [error] Too short cookie string\n\n21:01:26.910 [error] Too short cookie string\n\n21:01:26.911 [error] Too short cookie string\n\n21:01:27.533 [error] Too short cookie string\n\n21:01:27.534 [error] Too short cookie string\n\n21:01:28.161 [error] Too short cookie string\nDistribution failed: {{:shutdown, {:failed_to_start_child, :auth, {'Too short cookie string', [{:auth, :init_cookie, 0, [file: 'auth.erl', line: 290]}, {:auth, :init, 1, [file: 'auth.erl', line: 144]}, {:gen_server, :init_it, 2, [file: 'gen_server.erl', line: 417]}, {:gen_server, :init_it, 6, [file: 'gen_server.erl', line: 385]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 226]}]}}}, {:child, :undefined, :net_sup_dynamic, {:erl_distribution, :start_link, [[:\"rabbitmqcli-47-rabbit@90cc77cefcb8\", :shortnames, 15000], false, :net_sup_dynamic]}, :permanent, 1000, :supervisor, [:erl_distribution]}}\nConfiguring logger redirection\n\n21:01:29.717 [error]\n21:01:29.715 [error] Too short cookie string\n21:01:29.715 [error] Supervisor net_sup had child auth started with auth:start_link() at undefined exit with reason \"Too short cookie string\" in auth:init_cookie/0 line 290 in context start_error\n21:01:29.715 [error] CRASH REPORT Process with 0 neighbours crashed with reason: \"Too short cookie string\" in auth:init_cookie/0 line 290\n21:01:29.719 [error] BOOT FAILED\nBOOT FAILED\n21:01:29.719 [error] ===========\n===========\n21:01:29.719 [error] Exception during startup:\nException during startup:\n21:01:29.720 [error]\n\n21:01:29.720 [error] supervisor:children_map/4 line 1171\n supervisor:children_map/4 line 1171\n supervisor:'-start_children/2-fun-0-'/3 line 355\n21:01:29.721 [error] supervisor:'-start_children/2-fun-0-'/3 line 355\n21:01:29.721 [error] supervisor:do_start_child/2 line 371\n supervisor:do_start_child/2 line 371\n21:01:29.721 [error] supervisor:do_start_child_i/3 line 385\n supervisor:do_start_child_i/3 line 385\n21:01:29.721 [error] rabbit_prelaunch:run_prelaunch_first_phase/0 line 27\n rabbit_prelaunch:run_prelaunch_first_phase/0 line 27\n21:01:29.721 [error] rabbit_prelaunch:do_run/0 line 111\n rabbit_prelaunch:do_run/0 line 111\n21:01:29.722 [error] rabbit_prelaunch_dist:setup/1 line 15\n rabbit_prelaunch_dist:setup/1 line 15\n rabbit_prelaunch_dist:duplicate_node_check/1 line 51\n21:01:29.722 [error] rabbit_prelaunch_dist:duplicate_node_check/1 line 51\n21:01:29.722 [error] error:{badmatch,\nerror:{badmatch,\n {error,\n21:01:29.722 [error] {error,\n21:01:29.722 [error] {{shutdown,\n {{shutdown,\n21:01:29.722 [error] {failed_to_start_child,auth,\n {failed_to_start_child,auth,\n21:01:29.723 [error] {\"Too short cookie string\",\n {\"Too short cookie string\",\n21:01:29.723 [error] [{auth,init_cookie,0,[{file,\"auth.erl\"},{line,290}]},\n [{auth,init_cookie,0,[{file,\"auth.erl\"},{line,290}]},\n21:01:29.723 [error] {auth,init,1,[{file,\"auth.erl\"},{line,144}]},\n {auth,init,1,[{file,\"auth.erl\"},{line,144}]},\n21:01:29.723 [error] {gen_server,init_it,2,\n {gen_server,init_it,2,\n [{file,\"gen_server.erl\"},{line,417}]},\n21:01:29.723 [error] [{file,\"gen_server.erl\"},{line,417}]},\n21:01:29.724 [error] {gen_server,init_it,6,\n {gen_server,init_it,6,\n [{file,\"gen_server.erl\"},{line,385}]},\n21:01:29.724 [error] [{file,\"gen_server.erl\"},{line,385}]},\n21:01:29.724 [error] {proc_lib,init_p_do_apply,3,\n {proc_lib,init_p_do_apply,3,\n21:01:29.724 [error] [{file,\"proc_lib.erl\"},{line,226}]}]}}},\n [{file,\"proc_lib.erl\"},{line,226}]}]}}},\n21:01:29.724 [error] {child,undefined,net_sup_dynamic,\n {child,undefined,net_sup_dynamic,\n21:01:29.725 [error] {erl_distribution,start_link,\n {erl_distribution,start_link,\n21:01:29.725 [error] [[rabbit_prelaunch_510@localhost,shortnames],\n [[rabbit_prelaunch_510@localhost,shortnames],\n21:01:29.725 [error] false,net_sup_dynamic]},\n false,net_sup_dynamic]},\n21:01:29.725 [error] permanent,1000,supervisor,\n permanent,1000,supervisor,\n21:01:29.725 [error] [erl_distribution]}}}}\n21:01:29.726 [error]\n [erl_distribution]}}}}\n\n21:01:30.726 [error] Supervisor rabbit_prelaunch_sup had child prelaunch started with rabbit_prelaunch:run_prelaunch_first_phase() at undefined exit with reason {badmatch,{error,{{shutdown,{failed_to_start_child,auth,{\"Too short cookie string\",[{auth,init_cookie,0,[{file,\"auth.erl\"},{line,290}]},{auth,init,1,[{file,\"auth.erl\"},{line,144}]},{gen_server,init_it,2,[{file,\"gen_server.erl\"},{line,417}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,385}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,226}]}]}}},{child,undefined,net_sup_dynamic,{erl_distribution,start_link,[[rabbit_prelaunch_510@localhost,shortnames],false,net_sup_dynamic]},...}}}} in context start_error\n21:01:30.726 [error] CRASH REPORT Process with 0 neighbours exited with reason: {{shutdown,{failed_to_start_child,prelaunch,{badmatch,{error,{{shutdown,{failed_to_start_child,auth,{\"Too short cookie string\",[{auth,init_cookie,0,[{file,\"auth.erl\"},{line,290}]},{auth,init,1,[{file,\"auth.erl\"},{line,144}]},{gen_server,init_it,2,[{file,\"gen_server.erl\"},{line,417}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,385}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,226}]}]}}},{child,undefined,net_sup_dynamic,{erl_distribution,start_link,[[rabbit_prelaunch_510@localhost,...],...]},...}}}}}},...} in application_master:init/4 line 138\n{\"Kernel pid terminated\",application_controller,\"{application_start_failure,rabbitmq_prelaunch,{{shutdown,{failed_to_start_child,prelaunch,{badmatch,{error,{{shutdown,{failed_to_start_child,auth,{\\\"Too short cookie string\\\",[{auth,init_cookie,0,[{file,\\\"auth.erl\\\"},{line,290}]},{auth,init,1,[{file,\\\"auth.erl\\\"},{line,144}]},{gen_server,init_it,2,[{file,\\\"gen_server.erl\\\"},{line,417}]},{gen_server,init_it,6,[{file,\\\"gen_server.erl\\\"},{line,385}]},{proc_lib,init_p_do_apply,3,[{file,\\\"proc_lib.erl\\\"},{line,226}]}]}}},{child,undefined,net_sup_dynamic,{erl_distribution,start_link,[[rabbit_prelaunch_510@localhost,shortnames],false,net_sup_dynamic]},permanent,1000,supervisor,[erl_distribution]}}}}}},{rabbit_prelaunch_app,start,[normal,[]]}}}\"}\nKernel pid terminated (application_controller) ({application_start_failure,rabbitmq_prelaunch,{{shutdown,{failed_to_start_child,prelaunch,{badmatch,{error,{{shutdown,{failed_to_start_child,auth,{\"Too\n\nCrash dump is being written to: erl_crash.dump...\n```\n\nI've been using this image for months now without any problems, but all of sudden it doesn't work anymore.\n\nI also tried running this on my raspberry pi. Turns out it works there, so it has to be more of a local thing for me, which is kind of weird as docker is basically meant to avoid these problems.\n\nI also tried setting the `RABBITMQ_ERLANG_COOKIE` environment variable to a long name, but with no success. Any ideas?\n\n========================================\n\nTop Answer:\nI had exactly the same error and followed the advice of Owen Brown. Unfortunately, deleting the rabbitmq images could not solve my problems but deleting all other redundant images as well (especially the ones of big size) did it for me.\n\nIn case you are wondering how much all images are in size, you can check these statistics with\n\n`docker system df`\n\nEdit:\n\nAs i encountered the same issue again just a couple of hours later i researched again and found this answer which resolved my troubles.\n\nMore important than deleting images is the deletion of volumes using:\n\n`docker volume rm $(docker volume ls -f dangling=true -q)` // removes all volumes\n\n========================================\n\nCode:\n```text\n21:01:21.726 [error] Failed to write to cookie file '/var/lib/rabbitmq/.erlang.cookie': enospc\n\n21:01:22.355 [error] Too short cookie string\n\n21:01:22.356 [error] Too short cookie string\n\n21:01:23.161 [error] Too short cookie string\n\n21:01:23.162 [error] Too short cookie string\n\n21:01:23.783 [error] Too short cookie string\n\n21:01:23.784 [error] Too short cookie string\n\n21:01:24.405 [error] Too short cookie string\n\n21:01:24.406 [error] Too short cookie string\n\n21:01:25.027 [error] Too short cookie string\n\n21:01:25.028 [error] Too short cookie string\n\n21:01:25.661 [error] Too short cookie string\n\n21:01:25.662 [error] Too short cookie string\n\n21:01:26.281 [error] Too short cookie string\n\n21:01:26.282 [error] Too short cookie string\n\n21:01:26.910 [error] Too short cookie string\n\n21:01:26.911 [error] Too short cookie string\n\n21:01:27.533 [error] Too short cookie string\n\n21:01:27.534 [error] Too short cookie string\n\n21:01:28.161 [error] Too short cookie string\nDistribution failed: {{:shutdown, {:failed_to_start_child, :auth, {'Too short cookie string', [{:auth, :init_cookie, 0, [file: 'auth.erl', line: 290]}, {:auth, :init, 1, [file: 'auth.erl', line: 144]}, {:gen_server, :init_it, 2, [file: 'gen_server.erl', line: 417]}, {:gen_server, :init_it, 6, [file: 'gen_server.erl', line: 385]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 226]}]}}}, {:child, :undefined, :net_sup_dynamic, {:erl_distribution, :start_link, [[:\"rabbitmqcli-47-rabbit@90cc77cefcb8\", :shortnames, 15000], false, :net_sup_dynamic]}, :permanent, 1000, :supervisor, [:erl_distribution]}}\nConfiguring logger redirection\n\n21:01:29.717 [error]\n21:01:29.715 [error] Too short cookie string\n21:01:29.715 [error] Supervisor net_sup had child auth started with auth:start_link() at undefined exit with reason \"Too short cookie string\" in auth:init_cookie/0 line 290 in context start_error\n21:01:29.715 [error] CRASH REPORT Process <0.201.0> with 0 neighbours crashed with reason: \"Too short cookie string\" in auth:init_cookie/0 line 290\n21:01:29.719 [error] BOOT FAILED\nBOOT FAILED\n21:01:29.719 [error] ===========\n===========\n21:01:29.719 [error] Exception during startup:\nException during startup:\n21:01:29.720 [error]\n\n21:01:29.720 [error] supervisor:children_map/4 line 1171\n supervisor:children_map/4 line 1171\n supervisor:'-start_children/2-fun-0-'/3 line 355\n21:01:29.721 [error] supervisor:'-start_children/2-fun-0-'/3 line 355\n21:01:29.721 [error] supervisor:do_start_child/2 line 371\n supervisor:do_start_child/2 line 371\n21:01:29.721 [error] supervisor:do_start_child_i/3 line 385\n supervisor:do_start_child_i/3 line 385\n21:01:29.721 [error] rabbit_prelaunch:run_prelaunch_first_phase/0 line 27\n rabbit_prelaunch:run_prelaunch_first_phase/0 line 27\n21:01:29.721 [error] rabbit_prelaunch:do_run/0 line 111\n rabbit_prelaunch:do_run/0 line 111\n21:01:29.722 [error] rabbit_prelaunch_dist:setup/1 line 15\n rabbit_prelaunch_dist:setup/1 line 15\n rabbit_prelaunch_dist:duplicate_node_check/1 line 51\n21:01:29.722 [error] rabbit_prelaunch_dist:duplicate_node_check/1 line 51\n21:01:29.722 [error] error:{badmatch,\nerror:{badmatch,\n {error,\n21:01:29.722 [error] {error,\n21:01:29.722 [error] {{shutdown,\n {{shutdown,\n21:01:29.722 [error] {failed_to_start_child,auth,\n {failed_to_start_child,auth,\n21:01:29.723 [error] {\"Too short cookie string\",\n {\"Too short cookie string\",\n21:01:29.723 [error] [{auth,init_cookie,0,[{file,\"auth.erl\"},{line,290}]},\n [{auth,init_cookie,0,[{file,\"auth.erl\"},{line,290}]},\n21:01:29.723 [error] {auth,init,1,[{file,\"auth.erl\"},{line,144}]},\n {auth,init,1,[{file,\"auth.erl\"},{line,144}]},\n21:01:29.723 [error] {gen_server,init_it,2,\n {gen_server,init_it,2,\n [{file,\"gen_server.erl\"},{line,417}]},\n21:01:29.723 [error] [{file,\"gen_server.erl\"},{line,417}]},\n21:01:29.724 [error] {gen_server,init_it,6,\n {gen_server,init_it,6,\n [{file,\"gen_server.erl\"},{line,385}]},\n21:01:29.724 [error] [{file,\"gen_server.erl\"},{line,385}]},\n21:01:29.724 [error] {proc_lib,init_p_do_apply,3,\n {proc_lib,init_p_do_apply,3,\n21:01:29.724 [error] [{file,\"proc_lib.erl\"},{line,226}]}]}}},\n [{file,\"proc_lib.erl\"},{line,226}]}]}}},\n21:01:29.724 [error] {child,undefined,net_sup_dynamic,\n {child,undefined,net_sup_dynamic,\n21:01:29.725 [error] {erl_distribution,start_link,\n {erl_distribution,start_link,\n21:01:29.725 [error] [[rabbit_prelaunch_510@localhost,shortnames],\n [[rabbit_prelaunch_510@localhost,shortnames],\n21:01:29.725 [error] false,net_sup_dynamic]},\n false,net_sup_dynamic]},\n21:01:29.725 [error] permanent,1000,supervisor,\n permanent,1000,supervisor,\n21:01:29.725 [error] [erl_distribution]}}}}\n21:01:29.726 [error]\n [erl_distribution]}}}}\n\n21:01:30.726 [error] Supervisor rabbit_prelaunch_sup had child prelaunch started with rabbit_prelaunch:run_prelaunch_first_phase() at undefined exit with reason {badmatch,{error,{{shutdown,{failed_to_start_child,auth,{\"Too short cookie string\",[{auth,init_cookie,0,[{file,\"auth.erl\"},{line,290}]},{auth,init,1,[{file,\"auth.erl\"},{line,144}]},{gen_server,init_it,2,[{file,\"gen_server.erl\"},{line,417}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,385}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,226}]}]}}},{child,undefined,net_sup_dynamic,{erl_distribution,start_link,[[rabbit_prelaunch_510@localhost,shortnames],false,net_sup_dynamic]},...}}}} in context start_error\n21:01:30.726 [error] CRASH REPORT Process <0.153.0> with 0 neighbours exited with reason: {{shutdown,{failed_to_start_child,prelaunch,{badmatch,{error,{{shutdown,{failed_to_start_child,auth,{\"Too short cookie string\",[{auth,init_cookie,0,[{file,\"auth.erl\"},{line,290}]},{auth,init,1,[{file,\"auth.erl\"},{line,144}]},{gen_server,init_it,2,[{file,\"gen_server.erl\"},{line,417}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,385}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,226}]}]}}},{child,undefined,net_sup_dynamic,{erl_distribution,start_link,[[rabbit_prelaunch_510@localhost,...],...]},...}}}}}},...} in application_master:init/4 line 138\n{\"Kernel pid terminated\",application_controller,\"{application_start_failure,rabbitmq_prelaunch,{{shutdown,{failed_to_start_child,prelaunch,{badmatch,{error,{{shutdown,{failed_to_start_child,auth,{\\\"Too short cookie string\\\",[{auth,init_cookie,0,[{file,\\\"auth.erl\\\"},{line,290}]},{auth,init,1,[{file,\\\"auth.erl\\\"},{line,144}]},{gen_server,init_it,2,[{file,\\\"gen_server.erl\\\"},{line,417}]},{gen_server,init_it,6,[{file,\\\"gen_server.erl\\\"},{line,385}]},{proc_lib,init_p_do_apply,3,[{file,\\\"proc_lib.erl\\\"},{line,226}]}]}}},{child,undefined,net_sup_dynamic,{erl_distribution,start_link,[[rabbit_prelaunch_510@localhost,shortnames],false,net_sup_dynamic]},permanent,1000,supervisor,[erl_distribution]}}}}}},{rabbit_prelaunch_app,start,[normal,[]]}}}\"}\nKernel pid terminated (application_controller) ({application_start_failure,rabbitmq_prelaunch,{{shutdown,{failed_to_start_child,prelaunch,{badmatch,{error,{{shutdown,{failed_to_start_child,auth,{\"Too\n\nCrash dump is being written to: erl_crash.dump...\n```\n\n```text\nRABBITMQ_ERLANG_COOKIE\n```\n\n```text\n21:01:21.726 [error] Failed to write to cookie file '/var/lib/rabbitmq/.erlang.cookie': enospc\n```\n\n```text\ndocker run rabbitmq:management\n```\n\n```text\ndocker images | grep rabbit\n```\n\n```text\nrun docker rmi <image_id(s)>\n```\n\n```text\n$ docker images --filter \"dangling=true\n```\n\n```text\n$ docker rmi $(docker images -f \"dangling=true\" -q)\n```\n\n```text\ndocker run rabbitmq:management\n```\n\n```text\ndocker system df\n```\n\n```text\ndocker volume rm $(docker volume ls -f dangling=true -q)\n```\n\n```text\ndocker-compose down\n```\n\n```text\ndocker-compose up\n```\n\n```text\ndocker prune\n```\n\n```text\ndocker-compose down -v\n```\n\n```text\ndocker system prune\n```\n\n```text\ndocker volume prune\n```\n\n========================================\n\nComments:\n- Yes, this was my problem. Somehow my docker-desktop didn't have any space left.\n- `docker system prune` works as well","metadata":{"transformedAt":"2026-08-18T18:33:20.131Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":17,"totalLines":342,"estimatedTokens":4315}}167{"id":"stack-17810112","source":"stackoverflow","questionId":17810112,"title":"Integrating RabbitMQ with database transactions","tags":["transactions","rabbitmq"],"text":"Title: Integrating RabbitMQ with database transactions\nTags: transactions, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nImagine the situation:\n\n```\nvar txn = new DatabaseTransaction();\n\nvar entry = txn.Database.Load(id);\nentry.Token = \"123\";\ntxn.Database.Update(entry);\n\nPublishRabbitMqMessage(new EntryUpdatedMessage { ID = entry.ID });\n\n// A bit more of processing\n\ntxn.Commit();\n```\n\nNow a consumer of `EntryUpdatedMessage` can potentially get this message *before* the transaction `txn` is committed and therefore will not be able to see the update.\n\nNow, I know that RabbitMQ does support transactions by itself, but we cannot really use them because we create a new `IModel` for each publish and having a per-thread model is really cumbersome in our scenario (ASP.NET web application).\n\nI thought of having a list of messages due to be published when a DB transaction is committed, but that's a really smelly solution.\n\nWhat is the correct way of handling this?\n\n========================================\n\nCode:\n```text\nvar txn = new DatabaseTransaction();\n\nvar entry = txn.Database.Load<Entry>(id);\nentry.Token = \"123\";\ntxn.Database.Update(entry);\n\nPublishRabbitMqMessage(new EntryUpdatedMessage { ID = entry.ID });\n\n// A bit more of processing\n\ntxn.Commit();\n```\n\n```text\nEntryUpdatedMessage\n```\n\n```text\ntxn\n```\n\n```text\nIModel\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.131Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":57,"estimatedTokens":335}}168{"id":"stack-32486398","source":"stackoverflow","questionId":32486398,"title":"Publishing to the default rabbitmq exchange using the http api","tags":["http","rabbitmq","amqp"],"text":"Title: Publishing to the default rabbitmq exchange using the http api\nTags: http, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nSo I am using rabbitmqs http api to do some very basic actions in rabbit. It works great in most situations but I am having an issue figuring out how to use it to publish a message to the default rabbitmq exchange. This exchange is always present, cannot be deleted and has a binding to every queue with a routing key equal to the queue name. \n\nMy problem is that this queue does not have a name, or rather, it's name is an empty string \"\". And the URL I have to use to publish this message with the HTTP api includes the name of the exchange.\n\nhttp://localhost:15672/api/exchanges/vhost/name/publish\n(Source: http://hg.rabbitmq.com/rabbitmq-management/raw-file/rabbitmq_v3_3_4/priv/www/api/index.html)\n\nThe same article mentions that in order to use the default vhost which has a name of \"/\", you must use %2f in place of the vhost name. This makes me think there should be a similar way to represent the deafault exchange in the url.\n\nI tried a few different things and none of them worked:\n\n```\n/api/exchanges/vhost//publish\n/api/exchanges/vhost/\"\"/publish\n/api/exchanges/vhost/''/publish\n/api/exchanges/vhost/ /publish\n/api/exchanges/vhost/%00/publish\n```\n\nI'm sure I can't be the only person that has run into this issue. any help would be much appreciated. \n\nthanks,\nTom\n\n========================================\n\nTop Answer:\nHere is curl to publish Message:\n\n```\ncurl -4vvv -u admin:admin \\\n'localhost:15672/api/exchanges/%2F/amq.default/publish' \\\n-H 'Content-Type: text/plain;charset=UTF-8' \\\n--data-binary '{\"vhost\":\"/\",\"name\":\"amq.default\",\"properties\":{\"delivery_mode\":1,\"headers\":{}},\"routing_key\":\"MY-QUEUE-NAME\",\"delivery_mode\":\"1\",\"payload\":\"TEST\",\"headers\":{},\"props\":{},\"payload_encoding\":\"string\"}'\n```\n\nMy Sample Request:\n\nUsername: admin\n\nPassword: admin\n\nRouting Key: `sample.load.work` (My queue)\n\n```\ncurl --location --request POST 'localhost:15672/api/exchanges/%2F/amq.default/publish' \\\n--header 'Content-Type: text/plain;charset=UTF-8' \\\n--header 'Authorization: Basic YWRtaW46YWRtaW4=' \\\n--data-raw '{\"vhost\":\"/\",\"name\":\"amq.default\",\"properties\":{\"delivery_mode\":1,\"headers\":{}},\"routing_key\":\"sample.load.work\",\"delivery_mode\":\"1\",\"payload\":\"TEST\",\"headers\":{},\"props\":{},\"payload_encoding\":\"string\"}'\n```\n\nPostman Snippet:\nhttps://i.sstatic.net/VEIFe.png\n\n========================================\n\nCode:\n```text\n/api/exchanges/vhost//publish\n/api/exchanges/vhost/\"\"/publish\n/api/exchanges/vhost/''/publish\n/api/exchanges/vhost/ /publish\n/api/exchanges/vhost/%00/publish\n```\n\n```text\n{\"properties\":{},\n \"routing_key\":\"queue_test\",\n \"payload\":\"message test \",\n \"payload_encoding\":\"string\"}\n```\n\n```text\namq.default\n```\n\n```text\nrouting_key\n```\n\n```text\ncurl -4vvv -u admin:admin \\\n'localhost:15672/api/exchanges/%2F/amq.default/publish' \\\n-H 'Content-Type: text/plain;charset=UTF-8' \\\n--data-binary '{\"vhost\":\"/\",\"name\":\"amq.default\",\"properties\":{\"delivery_mode\":1,\"headers\":{}},\"routing_key\":\"MY-QUEUE-NAME\",\"delivery_mode\":\"1\",\"payload\":\"TEST\",\"headers\":{},\"props\":{},\"payload_encoding\":\"string\"}'\n```\n\n```text\ncurl --location --request POST 'localhost:15672/api/exchanges/%2F/amq.default/publish' \\\n--header 'Content-Type: text/plain;charset=UTF-8' \\\n--header 'Authorization: Basic YWRtaW46YWRtaW4=' \\\n--data-raw '{\"vhost\":\"/\",\"name\":\"amq.default\",\"properties\":{\"delivery_mode\":1,\"headers\":{}},\"routing_key\":\"sample.load.work\",\"delivery_mode\":\"1\",\"payload\":\"TEST\",\"headers\":{},\"props\":{},\"payload_encoding\":\"string\"}'\n```\n\n```text\nsample.load.work\n```\n\n========================================\n\nComments:\n- How do you add message publish headers?\n- If you create the `exchange` using the publisher of the demo code of the RabbitMQ example codes, and the automatic created queue has a strange name, just use `\"routing_key\":\"\"` on that JSON body.\n- can you help me with source document so I can dive in more\n- Just to add the obvious, to publish to another vhost, replace the `%2f` part with vhost name\n- If you need to send a custom header, add it to properties: {\"properties\":{ \"header\": {\"myheader\": value} } ...}","metadata":{"transformedAt":"2026-08-18T18:33:20.131Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":111,"estimatedTokens":1045}}169{"id":"stack-36336071","source":"stackoverflow","questionId":36336071,"title":"Install rabbitmqadmin on linux","tags":["linux","rabbitmq","rabbitmqadmin"],"text":"Title: Install rabbitmqadmin on linux\nTags: linux, rabbitmq, rabbitmqadmin\nSource: Stack Overflow\n\nQuestion:\nI'm trying to install and be able to run rabbitmqadmin on a linux machine. Following the instructions described here do not help.\n\nAfter downloading the file linked, it prompts to copy the file (which looks like a python script) into `/usr/local/bin`.\n\nTrying to run it by simply invoking `rabbitmqadmin` results in `rabbitmqadmin: command not found`. There seems to be no information anywhere about how to get this to work and assumes that all the steps listed on the site should work for all. It seems odd that simply copying a python script to the `bin` folder should allow it to become a recognised command without having to invoke the python interpreter every time.\n\nAny help is appreciated.\n\n========================================\n\nTop Answer:\nI spent several hours to figure out this, use rabbitmqadmin on linux environment, Finally below steps solve my issue.\n\nOn my ubuntu server, python3 was installed, I checked it using below command,\n\n```\npython3 -V\n```\n\nStep 1: download the python script to your linux server\n\n```\nwget https://raw.githubusercontent.com/rabbitmq/rabbitmq-management/v3.7.8/bin/rabbitmqadmin\n```\n\nStep2: change the permission\n\n```\nchmod 777 rabbitmqadmin\n```\n\nStep3: change the header of the script as below(first line)\n\n```\n#!/usr/bin/env python3\n```\n\nThant's all, Now you can run below commands,\n\nTo list down queues,\n\n```\n./rabbitmqadmin -f tsv -q list queues\n```\n\nTo Delete ques,\n\n```\n./rabbitmqadmin delete queue name=name_of_queue\n```\n\nTo add binding between exchange and queue\n\n```\n./rabbitmqadmin declare binding source=\"exchangename\" destination_type=\"queue\" destination=\"queuename\" routing_key=\"routingkey\"\n```\n\n========================================\n\nCode:\n```text\n/usr/local/bin\n```\n\n```text\nrabbitmqadmin\n```\n\n```text\nrabbitmqadmin: command not found\n```\n\n```text\nbin\n```\n\n```text\nchmod +x\n```\n\n```text\nrabbitmq-plugins enable rabbitmq_management\n```\n\n```text\npython3 -V\n```\n\n```text\nwget https://raw.githubusercontent.com/rabbitmq/rabbitmq-management/v3.7.8/bin/rabbitmqadmin\n```\n\n```text\nchmod 777 rabbitmqadmin\n```\n\n```text\n#!/usr/bin/env python3\n```\n\n```text\n./rabbitmqadmin -f tsv -q list queues\n```\n\n```text\n./rabbitmqadmin delete queue name=name_of_queue\n```\n\n```text\n./rabbitmqadmin declare binding source=\"exchangename\" destination_type=\"queue\" destination=\"queuename\" routing_key=\"routingkey\"\n```\n\n```text\nsudo rabbitmq-plugins enable rabbitmq_management\nwget 'https://raw.githubusercontent.com/rabbitmq/rabbitmq-management/v3.7.15/bin/rabbitmqadmin'\nchmod +x rabbitmqadmin\nsed -i 's|#!/usr/bin/env python|#!/usr/bin/env python3|' rabbitmqadmin\nmv rabbitmqadmin .local/bin/\nrabbitmqadmin -q list queues\n```\n\n```text\ncd /usr/local/bin/\nwget http://127.0.0.1:15672/cli/rabbitmqadmin\nchmod 777 rabbitmqadmin\n```\n\n========================================\n\nComments:\n- That should work fine unless, for some strange reason, `/usr/local/bin` is not specified on your `$PATH`.\n- \"without having to invoke the python interpreter\" — see en.wikipedia.org/wiki/Shebang_(Unix)\n- `/usr/local/bin` is indeed specified on my `$PATH`.\n- This helped, however I disagree with the chmod 777 and agree with @Shiri in regard to the only adding of the execute permissions. I would further that to only the user/group of that will be running the commands as well.","metadata":{"transformedAt":"2026-08-18T18:33:20.131Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":15,"totalLines":139,"estimatedTokens":858}}170{"id":"stack-44358076","source":"stackoverflow","questionId":44358076,"title":"Should I close the channel/connection after every publish?","tags":["rabbitmq","node-amqp"],"text":"Title: Should I close the channel/connection after every publish?\nTags: rabbitmq, node-amqp\nSource: Stack Overflow\n\nQuestion:\nI am using amqplib in Node.js, and I am not clear about the best practices in my code. \n\nBasically, my current code calls the `amqp.connect()` when the Node server starts up, and then uses a different channel for each producer and each consumer, never actually closing any of them. I'd like to know if that makes any sense, or should I create the channel, publish and close it every time I want to publish a message. And what about the connection? Is that a \"good practice\" to connect once, and then keep it open for the lifetime of my server?\n\nOn the Consumer side - can I use a single connection and a single channel to listen on multiple queues?\n\nThank you for any clarifications\n\n========================================\n\nCode:\n```text\namqp.connect()\n```\n\n========================================\n\nComments:\n- \"It is recommended to have a channel per thread\" What is a thread?\n- Take a look at this question: stackoverflow.com/questions/5201852/what-is-a-thread-really","metadata":{"transformedAt":"2026-08-18T18:33:20.131Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":25,"estimatedTokens":275}}171{"id":"stack-22070639","source":"stackoverflow","questionId":22070639,"title":"Sending binary file through RabbitMQ","tags":["rabbitmq"],"text":"Title: Sending binary file through RabbitMQ\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm spec'ing a design right now that uses RabbitMQ as a message queue. The message are going to have a JSON body, and for one message in particular I'd like to add a small binary file. \n\nWhat I'd like to know is, should the binary file's data be part of the JSON message, or can it be appended to the message separately?\n\n========================================\n\nTop Answer:\nSince RabbitMQ message payload is just a binary array you should encode your message body with 3 fields: \n\n- File size\n\n- Binary data of a file\n\n- Json\n\nI disagree with a previous answer about embedding a file in json.\nIf you encode file data inside of json you will get wasted space because of json escaping + unnecessary CPU usage because of json encoding/decoding of the file data + you will need to read file data twice (once for json deserialization and once more to copy it where it needs to go)\n\n========================================\n\nComments:\n- Those were my thoughts exactly, it's reassuring to hear them come from somebody else. Thank you!\n- Binary data needs to be escaped before it can be serialized into JSON. See stackoverflow.com/q/1443158/1196816. It is probably better to just pass the binary data as the body of the RabbitMQ publish call.\n- *duable* - doable or durable?\n- @mbx, Why not both?\n- Sorry for the type, it's doable in my case. Here an additional trick. Since our Server is connected to our home network, our external IP may change a few times per year. Therefore, we put the IP-address in a file on our marketing website. So a customer first reads this file, then knows what IP address to connect. Also,, every configuration file where the IP-address/password is stored should be written encrypted, backwards, upside down, contain 90% rubbish data etc to fool hackers.","metadata":{"transformedAt":"2026-08-18T18:33:20.131Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":31,"estimatedTokens":468}}172{"id":"stack-43777807","source":"stackoverflow","questionId":43777807,"title":"Publish/Subscribe reliable messaging: Redis VS RabbitMQ","tags":["javascript","node.js","redis","rabbitmq","publish-subscribe"],"text":"Title: Publish/Subscribe reliable messaging: Redis VS RabbitMQ\nTags: javascript, node.js, redis, rabbitmq, publish-subscribe\nSource: Stack Overflow\n\nQuestion:\n### Background\n\nI am making a publish/subscribe typical application where a publisher sends messages to a consumer. \n\nThe publisher and the consumer are on different machines and the connection between them can break occasionally. \n\n### Objective\n\nThe goal here is to make sure that no matter what happens to the connection, or to the machines themselves, a message sent by a publisher is **always** received by the **consumer**. \n\nOrdering of messages is not a must.\n\n### Problem\n\nAccording to my research, RabbitMQ is the right choice for this scenario:\n\n- Redis Vs RabbitMQ as a data broker/messaging system in between Logstash and elasticsearch\n\nHowever, although RabbitMQ has a tutorial about publish and subscriber this tutorial does not present us to persistent queues nor does it mention confirms which I believe are the key to making sure messages are delivered.\n\nOn the other hand, Redis is also capable of doing this:\n\n- http://abhinavsingh.com/customizing-redis-pubsub-for-message-persistence-part-2/\n\nbut I couldn't find any official tutorials or examples and my current understatement leads to me to believe that persistent queues and message confirms must be done by us, as Redis is mainly an in memory-datastore instead of a message broker like RabbitMQ. \n\n### Questions\n\n- For this use case, which solution would be the easiest to implement? (Redis solution or RabbitMQ solution?)\n\n- Please provide a link to an example with what you think would be best!\n\n========================================\n\nTop Answer:\nRegarding implementation, they should both be easy - they both have libraries in various languages, check here for redis and here for rabbitmq. I'll just be honest here: I don't use javascript so I don't know how are the respected libraries implemented or supported.\n\nRegarding what you didn't find in the tutorial (or maybe missed in the second one where there are a few words about durable queues and persistent messages and acknowledging messages) there are some nicely explained things:\n\n- about persistence\n\n- about confirms (same link as you've provided in the question, just listing it here for clarity)\n\n- about reliability\n\nPublisher confirms are indeed not in the tutorial but there is an example on github in amqp.node's repo.\n\nWith rabbit mq message travels (in most cases) like this\n\n`publisher -> exchange -> queue -> consumer`\n and on each of these stops there is some sort of persistence to be achieved. Also if you get to clusters and queue mirroring you'll achieve even greater reliability (and availability of course).\n\n========================================\n\nCode:\n```text\nseneca\n```\n\n```text\npublisher -> exchange -> queue -> consumer\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.131Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":67,"estimatedTokens":712}}173{"id":"stack-37124375","source":"stackoverflow","questionId":37124375,"title":"How to api-query for the default vhost","tags":["rabbitmq"],"text":"Title: How to api-query for the default vhost\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nThe RabbitMQ documentation states:\n\n```\nDefault Virtual Host and User\n\nWhen the server first starts running, and detects that its database is uninitialised or has been deleted, it initialises a fresh database with the following resources:\n\na virtual host named /\n```\n\nThe api has things like:\n\n```\n/api/exchanges/#vhost#/?name?/bindings\n```\n\nwhere \"?name?\" is a specific exchange-name.\n\nHowever, what does one put in for the **#vhost#** for the ***default***-vhost?\n\n========================================\n\nCode:\n```text\nDefault Virtual Host and User\n\nWhen the server first starts running, and detects that its database is uninitialised or has been deleted, it initialises a fresh database with the following resources:\n\na virtual host named /\n```\n\n```text\n/api/exchanges/#vhost#/?name?/bindings\n```\n\n```text\n/api/exchanges/%2f/{exchange_name}/bindings/source\n```\n\n```text\nhttp://localhost:15672/api/exchanges/%2f/test_ex/bindings/source\n```\n\n```text\n[{\"source\":\"test_ex\",\"vhost\":\"/\",\"destination\":\"test_queue\",\"destination_type\":\"queue\",\"routing_key\":\"\",\"arguments\":{},\"properties_key\":\"~\"}]\n```\n\n========================================\n\nComments:\n- Gaaaaaaaaaaaaaa! It was there the whole time. Thx.\n- This is a real awkward design decision for a great product. As a consumer, you will only end up here and learn the simple true answer by starting to think like \"hmm, default vhost is a slash char and I must use it in a http url, so there must be some kind of escape or encoding? let's google that\". Thanks a lot for the simple truth though.\n- This is not a RABBITMQ decision, but if from AMQP protocol. @BeytanKurt :)","metadata":{"transformedAt":"2026-08-18T18:33:20.131Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":58,"estimatedTokens":430}}174{"id":"stack-33935430","source":"stackoverflow","questionId":33935430,"title":"RabbitMQ undefined: There is no template at js/tmpl/login.ejs","tags":["c#",".net","asp.net-mvc","asp.net-mvc-4","rabbitmq"],"text":"Title: RabbitMQ undefined: There is no template at js/tmpl/login.ejs\nTags: c#, .net, asp.net-mvc, asp.net-mvc-4, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nAll of a sudden when I try to access RabbitMQ it only displays this on screen:\n\n undefined: There is no template at js/tmpl/login.ejs\n\nAny help will be appreciated. \n\nUPDATE:\n\nNow it is showing browser default error:\n`Connection Refused`\n\n========================================\n\nTop Answer:\nyou can:\n\n```\ndocker exec -it rabbitmq\nrabbitmq-plugins enable rabbitmq_management\n```\n\n========================================\n\nCode:\n```text\nConnection Refused\n```\n\n```text\nrabbit@[SERVER_NAME_HERE].log\n```\n\n```text\nC:\\Users\\[ADMIN_ACCOUNT_USERNAME_HERE]\\AppData\\Roaming\\RabbitMQ\\log\n```\n\n```text\nrabbit@[SERVER_NAME_HERE].log\n```\n\n```text\ncannot_delete,\n \"c:/Users/[ADMIN_ACCOUNT_USERNAME_HERE]/AppData/Roaming/RabbitMQ/db/rabbit@[SERVER_NAME_HERE]-plugins-expand/rabbitmq_management-3.3.5/priv/www/cli\",\n```\n\n```text\ncli\n```\n\n```text\ncli\n```\n\n```text\nrundll32.exe\n```\n\n```text\nrundll32.exe\n```\n\n```text\nC:\\Users\\[ADMIN_ACCOUNT_USERNAME]\\AppData\\Roaming\\RabbitMQ\n```\n\n```text\ndocker-compose stop\n```\n\n```text\ndocker exec -it rabbitmq\nrabbitmq-plugins enable rabbitmq_management\n```\n\n========================================\n\nComments:\n- So is this Classic ASP or ASP.NET? Have you tried looking to see if the requested file exists?\n- It is ASP .NET MVC, it is installed on command line linux and I am not good with command line. I haven't touched the server in a month so why would the file disappear?\n- Why would the file disappear? Who knows, but that's the start for where you should be looking, based on the error message provided.\n- now it is showing default browser error: `connection` refused\n- Which RabbitMQ version ? are you using `guest` `guest` as credentials?\n- I am using v 3.3.5. I am not using any credentials as it does not load the login page. As soon as I go to the server. It either shows `Connection Refused` as default browser error or it shows `undefined: There is no template at js/tmpl/login.ejs`. When I check Firefox console it says `/js/tmpl/login.ejs?0.7230313879240866 1.99s` and `Error: 404 Not Found get` I have just checked the directory on linux server and the login.ejs is available\n- Above the 404 Error, it shows this `runRoute get` Another point which might help you understand the problem. On windows server's website log file shows: `server:5672 unavailable. Error: No connection could be made because the target machine actively refused it`.\n- had the same issue, node was down. deletd node from /var/lib/mnesia dir and started the rabbitmq worked for me\n- I was running RabbitMQ locally, restarting my Mac helped.\n- This did not work for me. Running RabbitMQ in Docker. Restarted my entire laptop. Error persists.\n- okay, why does this work\n- removed some extension and the issue was resolved\n- Toss your cookies... same effect.","metadata":{"transformedAt":"2026-08-18T18:33:20.131Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":95,"estimatedTokens":740}}175{"id":"stack-25274182","source":"stackoverflow","questionId":25274182,"title":"RabbitMQ change queue parameters on a production system","tags":["rabbitmq","pika","bunny"],"text":"Title: RabbitMQ change queue parameters on a production system\nTags: rabbitmq, pika, bunny\nSource: Stack Overflow\n\nQuestion:\nI'm using RabbitMQ as a message queue in a service-oriented architecture, where many separate web services publish messages bound for RabbitMQ queues. Those queues are in turn subscribed to by various consumers, which perform background work; a pretty vanilla use-case for RabbitMQ. \n\nNow I'd like to change some of the queue parameters (specifically, I'd like to bind queues to a new dead-letter exchange with a certain routing key). My problem is that making this change in place on a production system is problematic for a couple reasons.\n\nWhats the best way for me to transition to these new queues without losing messages in a production system?\n\nI've considered everything from versioning queue names to making a new vhost with the new settings to doing all the changes in place.\n\nHere are some of the problems I'm facing:\n\nBecause RabbitMQ queues are idempotent, the disparate web services have been declaring the queues before publishing to them (in case they don't already exist). Once you change the queue parameters (but maintain the same routing key), the queue declare fails and RabbitMQ closes the channel.\n\nI'd like to not lose messages when changing a queue (here I'm planning on subscribing an exclusive consumer that saves the messages and then republishes to the new queue).\n\nGeneral coordination between disparate publishers and the consumer base (or, even better, a way to avoid needing to coordinate them).\n\n========================================\n\nCode:\n```text\nx-message-ttl=0\n```\n\n========================================\n\nComments:\n- Thanks for the answer. The vhost solution has felt like the cleanest to me as well, but it introduced one problem: all the distributed publishers have to keep track of where they are publishing and be updated accordingly every time we make a change. Is there an easy way to make it so that they can just point to the same place and somewhere else we can route it to the correct Vhost? I don't think publishers should have to concern themselves with the those details if it is avoidable. But maybe this is more of a system admin question than a RabbitMQ question.\n- Usually vhost is configurable option (or at least should be), so changing it should not be a problem. Note, that if you doesn't want (or you cant afford it) downtime, just run new publishers and consumers in parallel and then stop original one migrate messages from old vhost to new. But if you can, make your app survives after queue declaration failure at first stage and then just apply new changes to producers and consumers.\n- I've added a solution (Fast and safe solution) which may come in handy to make hot changes to queues declaration, for example, set it to durable or auto-delete or exclusive, etc. But make sure you understand what you are doing before following this way.\n- If you not sure about any cases you can double check the solutions by asking the same question in rabbitmq user group - groups.google.com/forum/#!forum/rabbitmq-discuss and point a link to our discussion.\n- I updated my answer with shovel plugin note, hope it will help someone.\n- Note that x-message-ttl can be 0, for immediate delivery.","metadata":{"transformedAt":"2026-08-18T18:33:20.132Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":37,"estimatedTokens":820}}176{"id":"stack-25226080","source":"stackoverflow","questionId":25226080,"title":"RabbitMQ: How to requeue message with counter","tags":["go","rabbitmq","amqp"],"text":"Title: RabbitMQ: How to requeue message with counter\nTags: go, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nIs there any way to count how many time a job is requeued (via Reject or Nak) without manually requeu the job?\nI need to retry a job for 'n' time and then drop it after 'n' time.\n\nps : Currently I requeue a job manually (drop old job, create a new job with the exact content and an extra Counter header if the Counter is not there or the value is less than 'n')\n\n========================================\n\nTop Answer:\nIn the case that the message was actually dead-lettered, you can check the contents of the `x-death` message header.\n\nThis would for example be the case when you `reject`/`nack` with `requeue = false` and the queue has an associated dead letter exchange.\n\nIn that case, the contents of this header is an array. Each element describes a failed delivery attempt, containing information such as the time it was attempted delivered, routing information, etc.\n\nThis works for RabbitMQ - I don't know if it is applicable to AMQP in general.\n\n**EDIT**\n\nSince I originally wrote this answer, the `x-death` header structure has been changed. \n\nIt is generally a very bad thing that headers changes format, but \nin this particular case the reason was that the message size would grow indefinitely if the message was continuously dead-lettered.\n\nI have therefore removed the piece of code that used to be here to get the no of deaths for a message.\n\nIt is still possible to get the number of deaths from the new header format.\n\n========================================\n\nCode:\n```text\nredelivered\n```\n\n```text\nx-death\n```\n\n```text\nreject\n```\n\n```text\nnack\n```\n\n```text\nrequeue = false\n```\n\n```text\nx-death\n```\n\n========================================\n\nComments:\n- It's worth noting that counting retries on the RabbitMQ side is not implemented and is not so easy to do so, since it would require changing quite a bit of data structures used to store messages. We might implement that in the future, but there's no actually ETA\n- Exactly, I posted retries counting on application side as a workaround. And it is true that consuming, modifying and then publishing message again has a lot of cons, like stability and performance potential issues, but as a workaround it works. If you will ever think to implement that it would be great (at least it looks like) to have separate plugin for that that utilizes headers modification and respecting, say incrementing `x-redelivered-count` or decrementing `x-redeliveries-left` until it reaches zero and then apllying DLX or AE mechanism or simply drop the message.\n- `x-death` is only added when the message is dead-lettered.\n- @MartinSchröder - good point - I took the code from an example where we are using dead-letter exchanges to handle redelivery at a later time. I updated the answer to reflect this","metadata":{"transformedAt":"2026-08-18T18:33:20.132Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":66,"estimatedTokens":718}}177{"id":"stack-33119611","source":"stackoverflow","questionId":33119611,"title":"How to make RabbitMQ API calls with vhost \"/\"?","tags":["rabbitmq","urlencode"],"text":"Title: How to make RabbitMQ API calls with vhost \"/\"?\nTags: rabbitmq, urlencode\nSource: Stack Overflow\n\nQuestion:\nThe following API call to RabbitMQ:\n\n```\nhttp -a USER:PASS localhost:15001/api/queues/\n```\n\nReturns a list of queues:\n\n```\n[\n {\n ...\n \"messages_unacknowledged_ram\": 0,\n \"name\": \"foo_queue\",\n \"node\": \"rabbit@queue-monster-01\",\n \"policy\": \"\",\n \"state\": \"running\",\n \"vhost\": \"/\"\n },\n ...\n]\n```\n\nNote that the `vhost` parameter is `/`.\n\n**How do I use a `/` `vhost` for the `/api/queues/vhost/name` call, which returns the details for a specific queue?**\n\nI have tried:\n\n- `localhost:15001/api/queues/\\//foo_queue`\n\n- `localhost:15001/api/queues///foo_queue`\n\nBut both failed with `404 Object Not Found`:\n\nhttps://i.sstatic.net/Fxg4q.png\n\n========================================\n\nTop Answer:\nTo answer Avishake's issue with the original answer (Not Found).\n\nThe reason you got Not Found is because you should replace **%2F** with **base**. Unicode encoding is the wrong approach.\n\nNote that the vhost parameter is / when you query for all queues.\n\n```\n[\n {\n ...\n \"messages_unacknowledged_ram\": 0,\n \"name\": \"q.somequeue\",\n \"node\": \"rabbit@queue-monster-01\",\n \"policy\": \"\",\n \"state\": \"running\",\n \"vhost\": \"/\"\n },\n ...\n ]\n```\n\nIf you replace the / with %2F (the unicode approach) you will get not found. By replacing / with base (the non-unicode approach) you will get a response that is successful.\n\n**Incorrect**: http://RabbitMQHost:port/api/queues/%2F/q.somequeue\n\n**Correct** http://RabbitMQHost:port/api/queues/base/q.somequeue\n\n========================================\n\nCode:\n```text\nhttp -a USER:PASS localhost:15001/api/queues/\n```\n\n```text\n[\n {\n ...\n \"messages_unacknowledged_ram\": 0,\n \"name\": \"foo_queue\",\n \"node\": \"rabbit@queue-monster-01\",\n \"policy\": \"\",\n \"state\": \"running\",\n \"vhost\": \"/\"\n },\n ...\n]\n```\n\n```text\nvhost\n```\n\n```text\n/\n```\n\n```text\n/\n```\n\n```text\nvhost\n```\n\n```text\n/api/queues/vhost/name\n```\n\n```text\nlocalhost:15001/api/queues/\\//foo_queue\n```\n\n```text\nlocalhost:15001/api/queues///foo_queue\n```\n\n```text\n404 Object Not Found\n```\n\n```text\nlocalhost:15001/api/queues/%2F/foo_queue\n ⬆⬆⬆\n```\n\n```text\n/\n```\n\n```text\n[\n {\n ...\n \"messages_unacknowledged_ram\": 0,\n \"name\": \"q.somequeue\",\n \"node\": \"rabbit@queue-monster-01\",\n \"policy\": \"\",\n \"state\": \"running\",\n \"vhost\": \"/\"\n },\n ...\n ]\n```\n\n========================================\n\nComments:\n- I change as per your answer. Still I have the same message in return `[error] => Object Not Found [reason] => \"Not Found\"`\n- I disagree. Using \"%2F\" works but with \"base\" I get \"Object not Found\"","metadata":{"transformedAt":"2026-08-18T18:33:20.132Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":13,"totalLines":155,"estimatedTokens":684}}178{"id":"stack-11928655","source":"stackoverflow","questionId":11928655,"title":"Where are the AMQP 1.0 implementations? Would it make sense to wait?","tags":["rabbitmq","amqp","qpid"],"text":"Title: Where are the AMQP 1.0 implementations? Would it make sense to wait?\nTags: rabbitmq, amqp, qpid\nSource: Stack Overflow\n\nQuestion:\nI'm doing research to figure out what messaging solution to settle on for our future products and I can't really figure this one out.\n\nThere is a bunch of AMQP 0.9.1 implementations (RabbitMQ, Apache Qpid, OpenAMQ, to name a few), but no AMQP 1.0 implementation, although 1.0 has been finalized October 2011. Well, except for SwiftMQ [1].\n\nReading up on 1.0, it seems to be a major departure from the pre-1.0 spec, so it seems understandable that there's little enthusiasm for a major rewrite of something that is working fine. In fact, I can't see why RabbitMQ and others wouldn't just decide to migrate to ZeroMQ instead of AMQP 1.0.\n\nStill, I cannot find any clear statement on that by implementors of the pre-1.0 AMQP spec, except some vague commitments like 'striving to always implement the latest AMQP spec'.\n\n**Edit:** RabbitMQ actually does say\n\n A future version of RabbitMQ will implement AMQP 1.0. Please contact us for details.\n\nHowever, something tells me that statement is more than 3 years old, i.e. it predates the release of AMQP 1.0.\n\nSo are there any indications AMQP 1.0 could become a standard, except for the fact that major banks - and Microsoft - are behind it? The latter btw. without an implementation of its own.\n\nIt almost seems like AMQP 0.9.1 is more standard than 1.0 will be.\n\nWell, there's https://github.com/rabbitmq/rabbitmq-amqp1.0, it's self-proclaimed status is *prototype*, with no work on it apparently for half a year.\n\n[1] My first impression of SwiftMQ I got by means of its author's rant on Spring's lacking AMQP support, which is why I'm not considering it for the time being. I wouldn't want to count on *support* from that guy.\n\n========================================\n\nTop Answer:\nAMQP 1.0 is an alternative to AMQP 0-9-1 in name only. The two are so different that it might have been clearer to give them different names.\n\nChoosing a current 0-9-1 implementation does not limit you:\n\n0-9-1 defines a broker and messaging model, while 1.0 defines a messaging transport. Therefore it is possible to combine the AMQP 1.0 transport with 0-9-1, as RabbitMQ demonstrated at the AMQP 1.0 conference in NYC in 2011. Because it is a transport, AMQP 1.0 can also be attached to proprietary and/or closed non-royalty-free brokers. \n\nAMQP 1.0 has just entered \"a 60-day public review period in preparation for a member ballot to consider its approval as an OASIS Standard\".\n\n\"The 60-day public review starts 14 August 2012 and ends 13 October 2012.\n\nThis is an open invitation to comment. OASIS solicits feedback from potential users, developers and others, whether OASIS members or not, for the sake of improving the interoperability and quality of its technical work.\"\n\nFull details here:\n\nhttps://www.oasis-open.org/news/announcements/60-day-public-review-for-advanced-message-queueing-protocol-amqp-v1-0-candidate-o\n\n========================================\n\nCode:\n```text\nAMQP\n```\n\n```text\nService Bus for Windows Server\n```\n\n```text\nthe upcoming Qpid release (probably available in the next couple of weeks) will have 1.0 support for the JMS client and the Java broker\n```\n\n========================================\n\nComments:\n- Interesting background on this from iMatix (of ZeroMQ fame): imatix.com/articles:whither-amqp\n- The article on pre-1.0 background that Eugene mentions above was redacted and moved to imatix.com/articles:whats-wrong-with-amqp.\n- What makes me hesitate to take this as an indication of broad adoption of AMQP 1.0 in the future, however, is the fact that a bunch of people most involved in refactoring AMQP into what became version 1.0 (John O'Hara, Robert Godfrey) are part of Qpid (qpid.apache.org/people.html), so everything but Qpid adopting 1.0 would be rather surprising. Actually it is surprising that it's taking a whole year after the finalization of the spec.\n- I can understand that and ultimately time will tell. However I am very confident there will be other implementations. You mentioned SwiftMQ, and Microsoft (Azure). I know there are plans to add AMQP 1.0 support to ActiveMQ. One of the nice things about AMQP 1.0 is that it is much easier to support it in existing messaging infrastructure. While existing AMQP implementation will rightly continue to support older versions to ease transition, it seems very unlikely to me that any new brokers based on those older versions will be implemented.\n- I guess your statement that 0.9.1 adoption won't get stronger going forward is fair enough - no one would want to bet on a dead horse.\n- At present for 0.9.1 you have the choice of two brokers, of which only one has commercial support available (i.e. RabbitMQ). I personally don't see that choice expanding (though I do see bridges between the two versions being available). The 0.9.1 protocol pretty much *requires* a broker (with 1.0 both brokered and peer-to-peer communication is possible). So I think the question is whether you standardise on an implementation or a protocol. Both are reasonable approaches.\n- Thanks for pointing to Microsoft Azure, but so far couldn't really find firm evidence for support. I spun that off into stackoverflow.com/questions/11962897\n- +1 Thanks for the link that contains references to the *statements of use* by 5 companies.\n- The 0.18 release of Qpid which was relased som etime ago now *did* contain 1.0 support in Java Broker and and 1.0 based JMS client. The 0.20 release is now in alpha and contains basic 1.0 support in the c++ broker and client - that will (I hope!) be improved prior to beta.\n- AMQP 1.0 support for ActiveMQ is also being developed. Microsoft have done a couple of presentations of their AMQP 1.0 support in ServiceBus and are scheduled to do another at ApacheCon EU (including an interop demo with Qpid and SwitfMQ).\n- If Qpid supports 1.0, why is it not advertised? qpid.apache.org/download.html lists the supported AMQP versions of Qpid 0.18, but there's only `0-8/0-9` and `0-10`. I double-checked, and `0-10` must be different from `1.0`, as the former was published in February 2008, according to Wikipedia. Btw. it would make sense to move Qpid out of the list of \"net yet AMQP 1.0\" list on en.wikipedia.org/wiki/AMQP#AMQP_1.0_Broker_Implementations\n- I agree, that is our failure for not updating the website. I will try to rectify that.\n- @Starship - I think this is an answer, since the question specifically notes that *A future version of RabbitMQ will implement AMQP 1.0. Please contact us for details.* This answer states that has finally happened.","metadata":{"transformedAt":"2026-08-18T18:33:20.132Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":77,"estimatedTokens":1665}}179{"id":"stack-23487238","source":"stackoverflow","questionId":23487238,"title":"RabbitMQ client can't connect to remote RabbitMQ server","tags":["connection","rabbitmq","remote-access"],"text":"Title: RabbitMQ client can't connect to remote RabbitMQ server\nTags: connection, rabbitmq, remote-access\nSource: Stack Overflow\n\nQuestion:\nI have a nodejs client that uses bramqp for connecting to RabbitMQ server. My client can connect to a Rabbit MQ server in localhost and works well. But it's unable to connect to a remote RabbitMQ server on other machine. I opened port 5672 in the remote server, so I think that the problem is in the configuration of rabbitMQ server. How can I solve this problem?\n\n========================================\n\nComments:\n- Which rabbitmq version ? are you using guest guest?\n- None of those links helped me. Updating loopback_users or creating a separate admin user still results in the same error. RabbitMQ refuses all non-local connections.\n- @Cerin this is not a good reason to vote down, maybe you have some other problem. Did you check the log?\n- @Cerin FYI I ran into the same thing (i.e. created new non-guest user but still couldn't log in with non-guest user). As per Gabriele's suggestion, I checked the rabbitmq sasl log (Simple Authentication and Security Layer) and saw that each log in was being shown as \"guest\". I tried doing firefox \"private mode\" with the new user and was successful. I went back to the regular firefox and did a \"clear recent history\" and made sure to \"clear active logins\". After this I was able to log into the management web-ui remotely.\n- for all who didn't found the solution use following steps rabbitmqctl add_user test test rabbitmqctl set_user_tags test administrator rabbitmqctl set_permissions -p / test \".*\" \".*\" \".*\"","metadata":{"transformedAt":"2026-08-18T18:33:20.132Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":15,"estimatedTokens":400}}180{"id":"stack-41914665","source":"stackoverflow","questionId":41914665,"title":"Spring amqp converter issue using rabbit listener","tags":["rabbitmq","amqp","spring-amqp","spring-rabbit"],"text":"Title: Spring amqp converter issue using rabbit listener\nTags: rabbitmq, amqp, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI think I am missing something here..I am trying to create simple rabbit listner which can accept custom object as message type. Now as per doc it says\n\n*In versions prior to 1.6, the type information to convert the JSON had to be provided in message headers, or a custom ClassMapper was required. Starting with version 1.6, if there are no type information headers, the type can be inferred from the target method arguments.*\n\nI am putting message manually in to queue using rabbit mq adm in dashboard,getting error like\n\n```\nCaused by: org.springframework.messaging.converter.MessageConversionException: Cannot convert from [[B] to [com.example.Customer] for GenericMessage [payload=byte[21], headers={amqp_receivedDeliveryMode=NON_PERSISTENT, amqp_receivedRoutingKey=customer, amqp_deliveryTag=1, amqp_consumerQueue=customer, amqp_redelivered=false, id=81e8a562-71aa-b430-df03-f60e6a37c5dc, amqp_consumerTag=amq.ctag-LQARUDrR6sUcn7FqAKKVDA, timestamp=1485635555742}]\n```\n\nMy configuration:\n\n```\n@Bean\n public ConnectionFactory connectionFactory() {\n CachingConnectionFactory connectionFactory = new CachingConnectionFactory(\"localhost\");\n connectionFactory.setUsername(\"test\");\n connectionFactory.setPassword(\"test1234\");\n connectionFactory.setVirtualHost(\"/\");\n return connectionFactory;\n }\n\n @Bean\n RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {\n RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);\n rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());\n return rabbitTemplate;\n }\n\n @Bean\n public AmqpAdmin amqpAdmin() {\n RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory());\n return rabbitAdmin;\n }\n\n @Bean\n public Jackson2JsonMessageConverter jackson2JsonMessageConverter() {\n return new Jackson2JsonMessageConverter();\n }\n```\n\nAlso question is with this exception message is not put back in the queue.\n\nI am using spring boot 1.4 which brings amqp 1.6.1.\n\nEdit1 : I added jackson converter as above (prob not required with spring boot) and given contenty type on rmq admin but still got below, as you can see above I am not configuring any listener container yet.\n\n```\nCaused by: org.springframework.messaging.converter.MessageConversionException: Cannot convert from [[B] to [com.example.Customer] for GenericMessage [payload=byte[21], headers={amqp_receivedDeliveryMode=NON_PERSISTENT, amqp_receivedRoutingKey=customer, content_type=application/json, amqp_deliveryTag=3, amqp_consumerQueue=customer, amqp_redelivered=false, id=7f84d49d-037a-9ea3-e936-ed5552d9f535, amqp_consumerTag=amq.ctag-YSemzbIW6Q8JGYUS70WWtA, timestamp=1485643437271}]\n```\n\n========================================\n\nTop Answer:\nRan into the same issue, turns out that, git stash/merge messed up with my config, I need to include this package again in my main again:\n\n```\n@SpringBootApplication(scanBasePackages = {\n \"com.example.amqp\" // <- git merge messed this up\n})\npublic class TeamActivityApplication {\n\n public static void main(String[] args) {\n SpringApplication.run(TeamActivityApplication.class, args);\n }\n}\n```\n\n========================================\n\nCode:\n```text\nCaused by: org.springframework.messaging.converter.MessageConversionException: Cannot convert from [[B] to [com.example.Customer] for GenericMessage [payload=byte[21], headers={amqp_receivedDeliveryMode=NON_PERSISTENT, amqp_receivedRoutingKey=customer, amqp_deliveryTag=1, amqp_consumerQueue=customer, amqp_redelivered=false, id=81e8a562-71aa-b430-df03-f60e6a37c5dc, amqp_consumerTag=amq.ctag-LQARUDrR6sUcn7FqAKKVDA, timestamp=1485635555742}]\n```\n\n```text\n@Bean\n public ConnectionFactory connectionFactory() {\n CachingConnectionFactory connectionFactory = new CachingConnectionFactory(\"localhost\");\n connectionFactory.setUsername(\"test\");\n connectionFactory.setPassword(\"test1234\");\n connectionFactory.setVirtualHost(\"/\");\n return connectionFactory;\n }\n\n @Bean\n RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {\n RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);\n rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());\n return rabbitTemplate;\n }\n\n @Bean\n public AmqpAdmin amqpAdmin() {\n RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory());\n return rabbitAdmin;\n }\n\n @Bean\n public Jackson2JsonMessageConverter jackson2JsonMessageConverter() {\n return new Jackson2JsonMessageConverter();\n }\n```\n\n```text\nCaused by: org.springframework.messaging.converter.MessageConversionException: Cannot convert from [[B] to [com.example.Customer] for GenericMessage [payload=byte[21], headers={amqp_receivedDeliveryMode=NON_PERSISTENT, amqp_receivedRoutingKey=customer, content_type=application/json, amqp_deliveryTag=3, amqp_consumerQueue=customer, amqp_redelivered=false, id=7f84d49d-037a-9ea3-e936-ed5552d9f535, amqp_consumerTag=amq.ctag-YSemzbIW6Q8JGYUS70WWtA, timestamp=1485643437271}]\n```\n\n```text\n@SpringBootApplication\npublic class So41914665Application {\n\n public static void main(String[] args) {\n SpringApplication.run(So41914665Application.class, args);\n }\n\n @Bean\n public Queue queue() {\n return new Queue(\"foo\", false, false, true);\n }\n\n @Bean\n public Jackson2JsonMessageConverter converter() {\n return new Jackson2JsonMessageConverter();\n }\n\n @RabbitListener(queues = \"foo\")\n public void listen(Foo foo) {\n System.out.println(foo);\n }\n\n\n public static class Foo {\n\n public String bar;\n\n public String getBar() {\n return this.bar;\n }\n\n public void setBar(String bar) {\n this.bar = bar;\n }\n\n @Override\n public String toString() {\n return \"Foo [bar=\" + this.bar + \"]\";\n }\n\n }\n\n}\n```\n\n```text\n2017-01-28 21:49:45.509 INFO 11453 --- [ main] com.example.So41914665Application : Started So41914665Application in 4.404 seconds (JVM running for 5.298)\nFoo [bar=baz]\n```\n\n```text\nJackson2JsonMessageConverter\n```\n\n```text\n@Bean\n```\n\n```text\ncontent_type\n```\n\n```text\napplication/json\n```\n\n```java\n@SpringBootApplication(scanBasePackages = {\n \"com.example.amqp\" // <- git merge messed this up\n})\npublic class TeamActivityApplication {\n\n public static void main(String[] args) {\n SpringApplication.run(TeamActivityApplication.class, args);\n }\n}\n```\n\n========================================\n\nComments:\n- here you go - github.com/stackspring/sample . This will be best to identify issue. Pull that and give a try.\n- You need to add `@Configuration` to your `RabbitConfig` class - boot does not see the converter bean and therefore doesn't wire it in. BTW, you don't need admin and template beans; boot's autoconfig will add them for you. You also don't need a `ConnectionFactory`; you can put your credentials in application.yml (or .properties). See the boot reference documentation about RabbitMQ auto configuration. Your sample works for me when I added `@Configuration`. I'd also recommend upgrading to 1.4.4.\n- Extremely sorry for wasting your time :(. I should have paid more attention. I will do double checking before posting next time. Ya I dont need those beans just for what I did, but I am planning to experiment few more things on this.","metadata":{"transformedAt":"2026-08-18T18:33:20.132Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":198,"estimatedTokens":1871}}181{"id":"stack-12426927","source":"stackoverflow","questionId":12426927,"title":"Pika + RabbitMQ: setting basic_qos to prefetch=1 still appears to consume all messages in the queue","tags":["rabbitmq","pika","qos"],"text":"Title: Pika + RabbitMQ: setting basic_qos to prefetch=1 still appears to consume all messages in the queue\nTags: rabbitmq, pika, qos\nSource: Stack Overflow\n\nQuestion:\nI've got a python worker client that spins up a 10 workers which each hook onto a RabbitMQ queue. A bit like this:\n\n```\n#!/usr/bin/python\nworker_count=10\n\ndef mqworker(queue, configurer):\n connection = pika.BlockingConnection(pika.ConnectionParameters(host='mqhost'))\n channel = connection.channel()\n channel.queue_declare(queue=qname, durable=True)\n channel.basic_consume(callback,queue=qname,no_ack=False)\n channel.basic_qos(prefetch_count=1)\n channel.start_consuming()\n\ndef callback(ch, method, properties, body):\n doSomeWork();\n ch.basic_ack(delivery_tag = method.delivery_tag)\n\nif __name__ == '__main__':\n for i in range(worker_count):\n worker = multiprocessing.Process(target=mqworker)\n worker.start()\n```\n\nThe issue I have is that despite setting basic_qos on the channel, the first worker to start accepts all the messages off the queue, whilst the others sit there idle. I can see this in the rabbitmq interface, that even when I set `worker_count` to be 1 and dump 50 messages on the queue, all 50 go into the 'unacknowledged' bucket, whereas I'd expect 1 to become unacknowledged and the other 49 to be ready.\n\nWhy isn't this working?\n\n========================================\n\nCode:\n```text\n#!/usr/bin/python\nworker_count=10\n\ndef mqworker(queue, configurer):\n connection = pika.BlockingConnection(pika.ConnectionParameters(host='mqhost'))\n channel = connection.channel()\n channel.queue_declare(queue=qname, durable=True)\n channel.basic_consume(callback,queue=qname,no_ack=False)\n channel.basic_qos(prefetch_count=1)\n channel.start_consuming()\n\n\ndef callback(ch, method, properties, body):\n doSomeWork();\n ch.basic_ack(delivery_tag = method.delivery_tag)\n\nif __name__ == '__main__':\n for i in range(worker_count):\n worker = multiprocessing.Process(target=mqworker)\n worker.start()\n```\n\n```text\nworker_count\n```\n\n```text\nbasic_qos\n```\n\n```text\nchannel = connection.channel()\n```\n\n========================================\n\nComments:\n- thank you! that did solve the issue. and btw this is very hard to debug..\n- @Hiagara yeah just ran into this today myself. Amazing that almost 5 years later this is still not clear or documented in the API.\n- I think that we should to declarate `basic_qos` before `basic_consume`. Because basic_consume use this setting when initialized.\n- agreed with @rborodinov. I had `basic_qos` right after `basic_consume` and it didn't work. Switched them, now it works fine.\n- I also had to set `auto_ack=False` when setting up the `basic_consume` for it to work. Otherwise it still consumed more messages than expected.\n- My `.ack()` was in the loop inside the callback, so it was trying to call it more than once for every `delivery_tag` thus resulting in a RabbitMQ 406 PRECONDITION_FAILED - unknown delivery tag.\n- @Tobias RE needing to set both `basic_qos(prefetch_count=1)` AND `auto_ack=False` is because of the AMQP spec \"The prefetch-count is ignored if the no-ack option is set\". Please note: In pika they use the word `auto_ack` and in the AMQP spec they use the word `no-ack`. kind of confusing IMO.","metadata":{"transformedAt":"2026-08-18T18:33:20.132Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":81,"estimatedTokens":814}}182{"id":"stack-37785061","source":"stackoverflow","questionId":37785061,"title":"Unable to start Airflow worker/flower and need clarification on Airflow architecture to confirm that the installation is correct","tags":["python","rabbitmq","celery","airflow"],"text":"Title: Unable to start Airflow worker/flower and need clarification on Airflow architecture to confirm that the installation is correct\nTags: python, rabbitmq, celery, airflow\nSource: Stack Overflow\n\nQuestion:\nRunning a worker on a different machine results in errors specified below. I have followed the configuration instructions and have sync the dags folder.\n\nI would also like to confirm that RabbitMQ and PostgreSQL only needs to be installed on the Airflow core machine and does not need to be installed on the workers (the workers only connect to the core).\n\nThe specification of the setup is detailed below:\n\n### Airflow core/server computer\n\n**Has the following installed:**\n\nPython 2.7 with \n\n- airflow (AIRFLOW_HOME = ~/airflow)\n\n- celery\n\n- psycogp2\n\n- RabbitMQ\n\n- PostgreSQL\n\n**Configurations made in airflow.cfg:**\n\n- `sql_alchemy_conn = postgresql+psycopg2://username:password@192.168.1.2:5432/airflow`\n\n- `executor = CeleryExecutor`\n\n- `broker_url = amqp://username:password@192.168.1.2:5672//`\n\n- `celery_result_backend = postgresql+psycopg2://username:password@192.168.1.2:5432/airflow`\n\n**Tests performed:**\n\n- RabbitMQ is running\n\n- Can connect to PostgreSQL and have confirmed that Airflow has created tables\n\n- Can start and view the webserver (including custom dags)\n\n.\n\n.\n\n### Airflow worker computer\n\n**Has the following installed:**\n\nPython 2.7 with \n\n- airflow (AIRFLOW_HOME = ~/airflow)\n\n- celery\n\n- psycogp2\n\n**Configurations made in airflow.cfg are exactly the same as in the server:**\n\n- `sql_alchemy_conn = postgresql+psycopg2://username:password@192.168.1.2:5432/airflow`\n\n- `executor = CeleryExecutor`\n\n- `broker_url = amqp://username:password@192.168.1.2:5672//`\n\n- `celery_result_backend = postgresql+psycopg2://username:password@192.168.1.2:5432/airflow`\n\n**Output from commands run on the worker machine:**\n\nWhen running `airflow flower`:\n\n```\nubuntu@airflow_client:~/airflow$ airflow flower\n[2016-06-13 04:19:42,814] {__init__.py:36} INFO - Using executor CeleryExecutor\nTraceback (most recent call last):\n File \"/home/ubuntu/anaconda2/bin/airflow\", line 15, in \n args.func(args)\n File \"/home/ubuntu/anaconda2/lib/python2.7/site-packages/airflow/bin/cli.py\", line 576, in flower\n os.execvp(\"flower\", ['flower', '-b', broka, port, api])\n File \"/home/ubuntu/anaconda2/lib/python2.7/os.py\", line 346, in execvp\n _execvpe(file, args)\n File \"/home/ubuntu/anaconda2/lib/python2.7/os.py\", line 382, in _execvpe\n func(fullname, *argrest)\nOSError: [Errno 2] No such file or directory\n```\n\nWhen running `airflow worker`:\n\n```\nubuntu@airflow_client:~$ airflow worker\n[2016-06-13 04:08:43,573] {__init__.py:36} INFO - Using executor CeleryExecutor\n[2016-06-13 04:08:43,935: ERROR/MainProcess] Unrecoverable error: ImportError('No module named postgresql',)\nTraceback (most recent call last):\n File \"/home/ubuntu/anaconda2/lib/python2.7/site-packages/celery/worker/__init__.py\", line 206, in start\n self.blueprint.start(self)\n File \"/home/ubuntu/anaconda2/lib/python2.7/site-packages/celery/bootsteps.py\", line 119, in start\n self.on_start()\n File \"/home/ubuntu/anaconda2/lib/python2.7/site-packages/celery/apps/worker.py\", line 169, in on_start\n string(self.colored.cyan(' \\n', self.startup_info())),\n File \"/home/ubuntu/anaconda2/lib/python2.7/site-packages/celery/apps/worker.py\", line 230, in startup_info\n results=self.app.backend.as_uri(),\n File \"/home/ubuntu/anaconda2/lib/python2.7/site-packages/kombu/utils/__init__.py\", line 325, in __get__\n value = obj.__dict__[self.__name__] = self.__get(obj)\n File \"/home/ubuntu/anaconda2/lib/python2.7/site-packages/celery/app/base.py\", line 626, in backend\n return self._get_backend()\n File \"/home/ubuntu/anaconda2/lib/python2.7/site-packages/celery/app/base.py\", line 444, in _get_backend\n self.loader)\n File \"/home/ubuntu/anaconda2/lib/python2.7/site-packages/celery/backends/__init__.py\", line 68, in get_backend_by_url\n return get_backend_cls(backend, loader), url\n File \"/home/ubuntu/anaconda2/lib/python2.7/site-packages/celery/backends/__init__.py\", line 49, in get_backend_cls\n cls = symbol_by_name(backend, aliases)\n File \"/home/ubuntu/anaconda2/lib/python2.7/site-packages/kombu/utils/__init__.py\", line 96, in symbol_by_name\n module = imp(module_name, package=package, **kwargs)\n File \"/home/ubuntu/anaconda2/lib/python2.7/importlib/__init__.py\", line 37, in import_module\n __import__(name)\nImportError: No module named postgresql\n```\n\nWhen `celery_result_backend` is changed to the default `db+mysql://airflow:airflow@localhost:3306/airflow` and the `airflow worker` is run again the result is:\n\n```\nubuntu@airflow_client:~/airflow$ airflow worker \n[2016-06-13 04:17:32,387] {__init__.py:36} INFO - Using executor CeleryExecutor\n\n -------------- celery@airflow_client2 v3.1.23 (Cipater)\n---- **** ----- \n--- * *** * -- Linux-3.19.0-59-generic-x86_64-with-debian-jessie-sid\n-- * - **** --- \n- ** ---------- [config]\n- ** ---------- .> app: airflow.executors.celery_executor:0x7f5cb65cb510\n- ** ---------- .> transport: amqp://username:**@192.168.1.2:5672//\n- ** ---------- .> results: mysql://airflow:**@localhost:3306/airflow\n- *** --- * --- .> concurrency: 16 (prefork)\n-- ******* ---- \n--- ***** ----- [queues]\n -------------- .> default exchange=default(direct) key=celery\n\n[2016-06-13 04:17:33,385] {__init__.py:36} INFO - Using executor CeleryExecutor\nStarting flask\n[2016-06-13 04:17:33,737] {_internal.py:87} INFO - * Running on http://0.0.0.0:8793/ (Press CTRL+C to quit)\n[2016-06-13 04:17:34,536: WARNING/MainProcess] celery@airflow_client2 ready.\n```\n\nWhat am I missing? How can I diagnose this further?\n\n========================================\n\nTop Answer:\nYou need to ensure to install Celery Flower. That is, `pip install flower`.\n\n========================================\n\nCode:\n```text\nubuntu@airflow_client:~/airflow$ airflow flower\n[2016-06-13 04:19:42,814] {__init__.py:36} INFO - Using executor CeleryExecutor\nTraceback (most recent call last):\n File \"/home/ubuntu/anaconda2/bin/airflow\", line 15, in <module>\n args.func(args)\n File \"/home/ubuntu/anaconda2/lib/python2.7/site-packages/airflow/bin/cli.py\", line 576, in flower\n os.execvp(\"flower\", ['flower', '-b', broka, port, api])\n File \"/home/ubuntu/anaconda2/lib/python2.7/os.py\", line 346, in execvp\n _execvpe(file, args)\n File \"/home/ubuntu/anaconda2/lib/python2.7/os.py\", line 382, in _execvpe\n func(fullname, *argrest)\nOSError: [Errno 2] No such file or directory\n```\n\n```text\nubuntu@airflow_client:~$ airflow worker\n[2016-06-13 04:08:43,573] {__init__.py:36} INFO - Using executor CeleryExecutor\n[2016-06-13 04:08:43,935: ERROR/MainProcess] Unrecoverable error: ImportError('No module named postgresql',)\nTraceback (most recent call last):\n File \"/home/ubuntu/anaconda2/lib/python2.7/site-packages/celery/worker/__init__.py\", line 206, in start\n self.blueprint.start(self)\n File \"/home/ubuntu/anaconda2/lib/python2.7/site-packages/celery/bootsteps.py\", line 119, in start\n self.on_start()\n File \"/home/ubuntu/anaconda2/lib/python2.7/site-packages/celery/apps/worker.py\", line 169, in on_start\n string(self.colored.cyan(' \\n', self.startup_info())),\n File \"/home/ubuntu/anaconda2/lib/python2.7/site-packages/celery/apps/worker.py\", line 230, in startup_info\n results=self.app.backend.as_uri(),\n File \"/home/ubuntu/anaconda2/lib/python2.7/site-packages/kombu/utils/__init__.py\", line 325, in __get__\n value = obj.__dict__[self.__name__] = self.__get(obj)\n File \"/home/ubuntu/anaconda2/lib/python2.7/site-packages/celery/app/base.py\", line 626, in backend\n return self._get_backend()\n File \"/home/ubuntu/anaconda2/lib/python2.7/site-packages/celery/app/base.py\", line 444, in _get_backend\n self.loader)\n File \"/home/ubuntu/anaconda2/lib/python2.7/site-packages/celery/backends/__init__.py\", line 68, in get_backend_by_url\n return get_backend_cls(backend, loader), url\n File \"/home/ubuntu/anaconda2/lib/python2.7/site-packages/celery/backends/__init__.py\", line 49, in get_backend_cls\n cls = symbol_by_name(backend, aliases)\n File \"/home/ubuntu/anaconda2/lib/python2.7/site-packages/kombu/utils/__init__.py\", line 96, in symbol_by_name\n module = imp(module_name, package=package, **kwargs)\n File \"/home/ubuntu/anaconda2/lib/python2.7/importlib/__init__.py\", line 37, in import_module\n __import__(name)\nImportError: No module named postgresql\n```\n\n```text\nubuntu@airflow_client:~/airflow$ airflow worker \n[2016-06-13 04:17:32,387] {__init__.py:36} INFO - Using executor CeleryExecutor\n\n -------------- celery@airflow_client2 v3.1.23 (Cipater)\n---- **** ----- \n--- * *** * -- Linux-3.19.0-59-generic-x86_64-with-debian-jessie-sid\n-- * - **** --- \n- ** ---------- [config]\n- ** ---------- .> app: airflow.executors.celery_executor:0x7f5cb65cb510\n- ** ---------- .> transport: amqp://username:**@192.168.1.2:5672//\n- ** ---------- .> results: mysql://airflow:**@localhost:3306/airflow\n- *** --- * --- .> concurrency: 16 (prefork)\n-- ******* ---- \n--- ***** ----- [queues]\n -------------- .> default exchange=default(direct) key=celery\n\n\n[2016-06-13 04:17:33,385] {__init__.py:36} INFO - Using executor CeleryExecutor\nStarting flask\n[2016-06-13 04:17:33,737] {_internal.py:87} INFO - * Running on http://0.0.0.0:8793/ (Press CTRL+C to quit)\n[2016-06-13 04:17:34,536: WARNING/MainProcess] celery@airflow_client2 ready.\n```\n\n```text\nsql_alchemy_conn = postgresql+psycopg2://username:password@192.168.1.2:5432/airflow\n```\n\n```text\nexecutor = CeleryExecutor\n```\n\n```text\nbroker_url = amqp://username:password@192.168.1.2:5672//\n```\n\n```text\ncelery_result_backend = postgresql+psycopg2://username:password@192.168.1.2:5432/airflow\n```\n\n```text\nsql_alchemy_conn = postgresql+psycopg2://username:password@192.168.1.2:5432/airflow\n```\n\n```text\nexecutor = CeleryExecutor\n```\n\n```text\nbroker_url = amqp://username:password@192.168.1.2:5672//\n```\n\n```text\ncelery_result_backend = postgresql+psycopg2://username:password@192.168.1.2:5432/airflow\n```\n\n```text\nairflow flower\n```\n\n```text\nairflow worker\n```\n\n```text\ncelery_result_backend\n```\n\n```text\ndb+mysql://airflow:airflow@localhost:3306/airflow\n```\n\n```text\nairflow worker\n```\n\n```text\ncelery_result_backend = postgresql+psycopg2://username:password@192.168.1.2:5432/airflow\n```\n\n```text\ncelery_result_backend = db+postgresql://username:password@192.168.1.2:5432/airflow\n```\n\n```text\nImportError: No module named postgresql\n```\n\n```text\ncelery_result_backend\n```\n\n```text\ndb+\n```\n\n```text\npip install flower\n```\n\n========================================\n\nComments:\n- Broker URL is correct? Ends with two slashes... What's the exchange name?\n- The celery docs have the two slashes docs.celeryproject.org/en/latest/… and removing the two slashes from the config did not change the output.","metadata":{"transformedAt":"2026-08-18T18:33:20.132Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":22,"totalLines":307,"estimatedTokens":2714}}183{"id":"stack-30914640","source":"stackoverflow","questionId":30914640,"title":"How to do error handling with EasyNetQ / RabbitMQ","tags":["c#","error-handling","rabbitmq","message-queue","easynetq"],"text":"Title: How to do error handling with EasyNetQ / RabbitMQ\nTags: c#, error-handling, rabbitmq, message-queue, easynetq\nSource: Stack Overflow\n\nQuestion:\nI'm using RabbitMQ in C# with the EasyNetQ library. I'm using a pub/sub pattern here. I still have a few issues that I hope anyone can help me with:\n\n- When there's an error while consuming a message, it's automatically moved to an error queue. How can I implement retries (so that it's placed back on the originating queue, and when it fails to process X times, it's moved to a dead letter queue)?\n\n- As far as I can see there's always 1 error queue that's used to dump messages from all other queues. How can I have 1 error queue per type, so that each queue has its own associated error queue?\n\n- How can I easily retry messages that are in an error queue? I tried Hosepipe, but it justs republishes the messages to the error queue instead of the originating queue. I don't really like this option either because I don't want to be fiddling around in a console. Preferably I'd just program against the error queue.\n\nAnyone?\n\n========================================\n\nTop Answer:\nI've implemented exactly what you describe. Here are some tips based on my experience and related to each of your questions.\n\n**Q1 (how to retry X times):** \n\nFor this, you can use `IMessage.Body.BasicProperties.Headers`. When you consume a message off an error queue, just add a header with a name that you choose. Look for this header on each message that comes into the error queue and increment it. This will give you a running retry count. \n\nIt's *very important* that you have a strategy for what to do when a message exceeds the retry limit of X. You don't want to lose that message. In my case, I write the message to disk at that point. It gives you lots of helpful debugging information to come back to later, because EasyNetQ automatically wraps your originating message with error info. It also has the original message so that you can, if you like, manually (or maybe automated, through some batch re-processing code) requeue the message later in some controlled way.\n\nYou can look at the code in the Hosepipe utility to see a good way of doing this. In fact, if you the pattern you see there then you can even use Hosepipe later to requeue the messages if you need to.\n\n**Q2 (how to create an error queue per originating queue):** \n\nYou can use the EasyNetQ Advanced Bus to do this cleanly. Use `IBus.Advanced.Container.Resolve` to get at the conventions interface. Then you can set the conventions for the error queue naming with `conventions.ErrorExchangeNamingConvention` and `conventions.ErrorQueueNamingConvention`. In my case I set the convention to be based on the name of the originating queue so that I get a queue/queue_error pair of queues every time I create a queue.\n\n**Q3 (how to process messages in the error queues):** \n\nYou can declare a consumer for the error queue the same way you do any other queue. Again, the AdvancedBus lets you do this cleanly by specifying that the type coming off of the queue is `EasyNetQ.SystemMessage.Error`. So, `IAdvancedBus.Consume()` will get you there. Retrying simply means republishing to the original exchange (paying attention to the retry count you put in the header (see my answer to Q1, above), and information in the Error message that you consumed off the error queue can help you find the target for republishing.\n\n========================================\n\nCode:\n```text\nIMessage.Body.BasicProperties.Headers\n```\n\n```text\nIBus.Advanced.Container.Resolve<IConventions>\n```\n\n```text\nconventions.ErrorExchangeNamingConvention\n```\n\n```text\nconventions.ErrorQueueNamingConvention\n```\n\n```text\nEasyNetQ.SystemMessage.Error\n```\n\n```text\nIAdvancedBus.Consume<EasyNetQ.SystemMessage.Error>()\n```\n\n```text\npublic interface IMessageType\n{\n int MsgTypeId { get; }\n\n Dictionary<string, TryInfo> MsgTryInfo {get; set;}\n\n}\n```\n\n```text\npublic class RetryEnabledErrorMessageSerializer<T> : IErrorMessageSerializer where T : class, IMessageType\n {\n public string Serialize(byte[] messageBody)\n {\n string stringifiedMsgBody = Encoding.UTF8.GetString(messageBody);\n var objectifiedMsgBody = JObject.Parse(stringifiedMsgBody);\n\n // Add/update RetryInformation into objectifiedMsgBody here\n // I have a dictionary that saves <key:consumerId, val: TryInfoObj>\n\n return JsonConvert.SerializeObject(objectifiedMsgBody);\n }\n }\n```\n\n```text\npublic void SetupMessageBroker(string givenSubscriptionId, bool enableRetry = false)\n {\n if (enableRetry)\n {\n _defaultBus = RabbitHutch.CreateBus(currentConnString,\n serviceRegister => serviceRegister.Register<IErrorMessageSerializer>(serviceProvider => new RetryEnabledErrorMessageSerializer<IMessageType>(givenSubscriptionId))\n );\n }\n else // EasyNetQ's DefaultErrorMessageSerializer will wrap error messages\n {\n _defaultBus = RabbitHutch.CreateBus(currentConnString);\n }\n }\n\n public bool SubscribeAsync<T>(Func<T, Task> eventHandler, string subscriptionId)\n {\n IMsgHandler<T> currMsgHandler = new MsgHandler<T>(eventHandler, subscriptionId);\n // Using the msgHandler allows to add a mediator between EasyNetQ and the actual callback function\n // The mediator can transmit the retried msg or choose to ignore it\n return _defaultBus.SubscribeAsync<T>(subscriptionId, currMsgHandler.InvokeMsgCallbackFunc).Queue != null;\n }\n```\n\n```text\nvar client = new ManagementClient(AppConfig.BaseAddress, AppConfig.RabbitUsername, AppConfig.RabbitPassword);\nvar vhost = client.GetVhostAsync(\"/\").Result;\nvar aliveRes = client.IsAliveAsync(vhost).Result;\nvar errQueue = client.GetQueueAsync(Constants.EasyNetQErrorQueueName, vhost).Result;\nvar crit = new GetMessagesCriteria(long.MaxValue, Ackmodes.ack_requeue_false);\nvar errMsgs = client.GetMessagesFromQueueAsync(errQueue, crit).Result;\nforeach (var errMsg in errMsgs)\n{\n var innerMsg = JsonConvert.DeserializeObject<Error>(errMsg.Payload);\n var pubInfo = new PublishInfo(innerMsg.RoutingKey, innerMsg.Message);\n pubInfo.Properties.Add(\"type\", innerMsg.BasicProperties.Type);\n pubInfo.Properties.Add(\"correlation_id\", innerMsg.BasicProperties.CorrelationId);\n pubInfo.Properties.Add(\"delivery_mode\", innerMsg.BasicProperties.DeliveryMode);\n var pubRes = client.PublishAsync(client.GetExchangeAsync(innerMsg.Exchange, vhost).Result, pubInfo).Result;\n}\n```\n\n```text\npublic interface IMsgHandler<T> where T: class, IMessageType\n{\n Task InvokeMsgCallbackFunc(T msg);\n Func<T, Task> MsgCallbackFunc { get; set; }\n bool IsTryValid(T msg, string refSubscriptionId); // Calls callback only \n // if Retry is valid\n}\n```\n\n```text\npublic async Task InvokeMsgCallbackFunc(T msg)\n {\n if (IsTryValid(msg, CurrSubscriptionId))\n {\n await this.MsgCallbackFunc(msg);\n }\n else\n {\n // Do whatever you want\n }\n }\n```\n\n```text\nDictionary<consumerId, RetryInfo>\n```\n\n```text\nclass RetryEnabledErrorMessageSerializer : IErrorMessageSerializer\n```\n\n```text\nMsgHandler\n```\n\n```text\n[Queue(“Product.Report”, ExchangeName = “Product.Report”)]\n public class ProductReport { }\n```\n\n```text\n[Queue(“Product.Report.DeadLetter”, ExchangeName = \n“Product.Report.DeadLetter”)]\npublic class ProductReportDeadLetter : ProductReport { }\n```\n\n```text\n[EasyDeadLetter(DeadLetterType = \n typeof(ProductReportDeadLetter))]\n[Queue(“Product.Report”, ExchangeName = “Product.Report”)]\npublic class ProductReport { }\n```\n\n```text\nservices.AddSingleton<IBus> \n (RabbitHutch.CreateBus(“connectionString”,\n serviceRegister =>\n {\n serviceRegister.Register<IConsumerErrorStrategy, \n EasyDeadLetterStrategy>();\n }));\n```\n\n```cs\npublic TimeSpan BaseDelay { get; init; } = TimeSpan.FromSeconds(2); // Balance chance to succeed with throughput\n\nprivate ResiliencePipeline HandlerRetryPipeline => _handlerRetryPipeline ??= new ResiliencePipelineBuilder()\n .AddRetry(new RetryStrategyOptions()\n {\n ShouldHandle = new PredicateBuilder().Handle<Exception>(),\n BackoffType = DelayBackoffType.Exponential,\n MaxRetryAttempts = 4,\n // Balance chance to succeed with throughput\n DelayGenerator = args => ValueTask.FromResult(args.AttemptNumber switch\n {\n 0 => TimeSpan.Zero, // E.g. at 00.000\n 1 => 1 * BaseDelay, // E.g. at 02.000\n 2 => 2 * BaseDelay, // E.g. at 06.000\n 3 => 3 * BaseDelay, // E.g. at 14.000\n _ => (TimeSpan?)null,\n }),\n OnRetry = _ => ValueTask.CompletedTask,\n })\n .Build();\nprivate ResiliencePipeline? _handlerRetryPipeline;\n\nprivate async Task ExecuteWithRetriesAsync<TMessage>(\n string stableHandlerName,\n Func<TMessage, CancellationToken, Task> handler,\n TMessage @event,\n CancellationToken cancellationToken)\n{\n try\n {\n await HandlerRetryPipeline.ExecuteAsync(\n callback: (state, cancellationToken) => new ValueTask(\n state.Handler.Invoke(state.Event, cancellationToken)),\n state: (Handler: handler, Event: @event),\n cancellationToken: cancellationToken);\n }\n catch (Exception e)\n {\n logger.LogError(e,\n \"{Event} handler failed, now requiring the problem to be fixed and the problematic messages to be shoveled back to {MainQueue} from the error queue: {Message}\",\n typeof(TMessage).Name, stableHandlerName, e.Message);\n\n throw;\n }\n}\n```\n\n```cs\nservices.RegisterEasyNetQ(\"ConnectionString\", services =>\n{\n services.Register<IConventions>(serviceProvider => serviceProvider.Resolve<CustomNamingConvention>());\n\n // Snip\n});\n\npublic sealed class CustomNamingConvention : Conventions\n{\n public CustomNamingConvention(ITypeNameSerializer typeNameSerializer)\n : base(typeNameSerializer)\n {\n QueueNamingConvention = this.GetQueueName; // Own method\n ExchangeNamingConvention = this.GetExchangeName; // Own method\n ErrorQueueNamingConvention = info => $\"{info.Queue}_error\";\n ErrorExchangeNamingConvention = info => $\"{info.Exchange}_error\";\n }\n\n // Snip\n}\n```\n\n```cs\nservices.RegisterEasyNetQ(\"ConnectionString\", services =>\n{\n services.EnableSystemTextJsonWithErrorUnwrapping(new JsonSerializerOptions(JsonSerializerDefaults.General)\n {\n // Or whatever options you like\n Converters = { new JsonStringEnumConverter() },\n });\n\n // Snip\n});\n\n/// <summary>\n/// Registers a <see cref=\"System.Text.Json\"/> serializer for <see cref=\"EasyNetQ\"/> that also unwraps error messages, to enable shoveling.\n/// </summary>\nprivate static IServiceRegister EnableSystemTextJsonWithErrorUnwrapping(this IServiceRegister serviceRegister, JsonSerializerOptions options)\n{\n serviceRegister.Register(Options.Create(options));\n serviceRegister.Register<SystemTextJsonSerializerWithErrorUnwrapping>(Lifetime.Singleton);\n serviceRegister.Register<ISerializer>(register => register.Resolve<SystemTextJsonSerializerWithErrorUnwrapping>());\n serviceRegister.Register<IConsumerErrorStrategy>(register => register.Resolve<SystemTextJsonSerializerWithErrorUnwrapping>());\n\n return serviceRegister;\n}\n\n\n/// <summary>\n/// <para>\n/// A combined <see cref=\"System.Text.Json\"/> serializer and error handler for <see cref=\"EasyNetQ\"/> that also unwraps <see cref=\"EasyNetQ.SystemMessages.Error\"/> messages, to enable shoveling.\n/// </para>\n/// <para>\n/// By default, <see cref=\"EasyNetQ\"/> stores an <see cref=\"EasyNetQ.SystemMessages.Error\"/> wrapper that cannot be handled.\n/// </para>\n/// </summary>\ninternal sealed class SystemTextJsonSerializerWithErrorUnwrapping : ISerializer, IConsumerErrorStrategy\n{\n private CustomizableTypeNameSerializer TypeNameSerializer { get; }\n private EasyNetQ.Serialization.SystemTextJson.SystemTextJsonSerializer DecoratedSerializer { get; } // TODO: Move to SystemTextJsonSerializerV2 once 8.0.0 is released\n private DefaultConsumerErrorStrategy DecoratedErrorStrategy { get; }\n\n public SystemTextJsonSerializerWithErrorUnwrapping(\n IOptions<JsonSerializerOptions> serializerOptions,\n EasyNetQ.Logging.ILogger<DefaultConsumerErrorStrategy> logger,\n IConsumerConnection connection,\n IConventions conventions,\n ITypeNameSerializer typeNameSerializer,\n IErrorMessageSerializer errorMessageSerializer,\n ConnectionConfiguration configuration)\n {\n TypeNameSerializer = new CustomizableTypeNameSerializer(typeNameSerializer);\n DecoratedSerializer = new EasyNetQ.Serialization.SystemTextJson.SystemTextJsonSerializer(serializerOptions.Value);\n DecoratedErrorStrategy = new DefaultConsumerErrorStrategy(logger, connection, serializer: this, conventions, TypeNameSerializer, errorMessageSerializer, configuration);\n }\n\n public void Dispose()\n {\n }\n\n public IMemoryOwner<byte> MessageToBytes(Type messageType, object message)\n {\n if (messageType == typeof(EasyNetQ.SystemMessages.Error) && message is EasyNetQ.SystemMessages.Error error)\n return SerializeMessageFromError(error);\n\n return DecoratedSerializer.MessageToBytes(messageType, message);\n\n // Local function that serializes the message that was wrapped in an Error object\n static IMemoryOwner<byte> SerializeMessageFromError(EasyNetQ.SystemMessages.Error error)\n {\n ArrayPooledMemoryStream? result = null;\n try\n {\n result = new ArrayPooledMemoryStream();\n result.SetLength(4 * error.Message.Length);\n Encoding.UTF8.TryGetBytes(error.Message, result.Memory.Span, out var byteCount);\n result.SetLength(byteCount);\n return result;\n }\n catch\n {\n result?.Dispose();\n throw;\n }\n }\n }\n\n public object BytesToMessage(Type messageType, in ReadOnlyMemory<byte> bytes)\n {\n return DecoratedSerializer.BytesToMessage(messageType, in bytes);\n }\n\n public async Task<AckStrategy> HandleConsumerErrorAsync(ConsumerExecutionContext context, Exception exception, CancellationToken cancellationToken)\n {\n // Ambiently customize the TypeNameSerializer to use the actual message's type (instead of Error)\n // This affects only the current flow of execution\n TypeNameSerializer.CurrentTypeName.Value = context.Properties.Type;\n\n // The handler will delegate to the type name serializer and the serializer, which will return the unwrapped message type and message\n var result = await DecoratedErrorStrategy.HandleConsumerErrorAsync(context, exception, cancellationToken);\n return result;\n }\n\n public Task<AckStrategy> HandleConsumerCancelledAsync(ConsumerExecutionContext context, CancellationToken cancellationToken = default)\n {\n return DecoratedErrorStrategy.HandleConsumerCancelledAsync(context, cancellationToken);\n }\n\n /// <summary>\n /// An <see cref=\"ITypeNameSerializer\"/> decorator that allows the serialized result to be customized.\n /// </summary>\n private sealed class CustomizableTypeNameSerializer(\n ITypeNameSerializer decoratedTypeNameSerializer)\n : ITypeNameSerializer\n {\n /// <summary>\n /// Assign the <see cref=\"AsyncLocal{T}.Value\"/> to customize the serialized result in the current execution flow.\n /// </summary>\n internal AsyncLocal<string> CurrentTypeName { get; } = new AsyncLocal<string>();\n\n public string Serialize(Type type)\n {\n return CurrentTypeName.Value ?? decoratedTypeNameSerializer.Serialize(type);\n }\n\n public Type DeSerialize(string typeName)\n {\n return decoratedTypeNameSerializer.DeSerialize(typeName);\n }\n }\n}\n```\n\n```text\nIConventions\n```\n\n```text\nConventions\n```\n\n```text\nError\n```\n\n```text\nDefaultConsumerErrorStrategy\n```\n\n```text\nISerializer\n```\n\n```text\nITypeNameSerializer\n```\n\n```text\nISerializer.MessageToBytes()\n```\n\n```text\nError\n```\n\n```text\nMessage\n```\n\n```text\nITypeNameSerializer.Serialize()\n```\n\n```text\nType\n```\n\n```text\nError\n```\n\n```text\nAsyncLocal<T>\n```\n\n```text\nSerialize()\n```\n\n```text\nSystem.Text.Json\n```\n\n========================================\n\nComments:\n- We found there was really no practical use for the standard EasyNetQ implementation outside of a single quick demonstration, tied to some shared .NET classes, for first-time users. After that, switch to Easy's super-simple \"advanced\" API. Yes, you can do advanced things but honestly it's a beautifully simple API to use. Definitely a fan of Easy's Advanced API for any and all work.\n- I got it working, see example here stackoverflow.com/questions/32077044/…","metadata":{"transformedAt":"2026-08-18T18:33:20.132Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":37,"totalLines":462,"estimatedTokens":4275}}184{"id":"stack-5336645","source":"stackoverflow","questionId":5336645,"title":"Retry Lost or Failed Tasks (Celery, Django and RabbitMQ)","tags":["rabbitmq","celery","django-celery"],"text":"Title: Retry Lost or Failed Tasks (Celery, Django and RabbitMQ)\nTags: rabbitmq, celery, django-celery\nSource: Stack Overflow\n\nQuestion:\nIs there a way to determine if any task is lost and retry it? \n\nI think that the reason for lost can be dispatcher bug or worker thread crash. \n\nI was planning to retry them but I'm not sure how to determine which tasks need to be retired? \n\nAnd how to make this process automatically? Can I use my own custom scheduler which will create new tasks?\n\nEdit: I found from the documentation that RabbitMQ never loose tasks, but what happens when worker thread crash in the middle of task execution?\n\n========================================\n\nCode:\n```py\ndef __call__(self, *args, **kwargs):\n \"\"\"In celery task this function call the run method, here you can\n set some environment variable before the run of the task\"\"\"\n\n #Inizialize context managers \n\n self.taskLogger = TaskLogger(args, kwargs)\n self.taskLogger.__enter__()\n\n return self.run(*args, **kwargs)\n\ndef after_return(self, status, retval, task_id, args, kwargs, einfo):\n #exit point for context managers\n self.taskLogger.__exit__(status, retval, task_id, args, kwargs, einfo)\n```\n\n```text\n__call__\n```\n\n```text\nafter_return\n```\n\n========================================\n\nComments:\n- 2 doubts regarding `CELERY_ACKS_LATE=True` [1] how does (if at all) `Celery` ensure that same `task` is not picked up by multiple `worker`s? [2] if `Celery` tasks should ideally be `idempotent`, then what's the problem with them running multiple times? (for the 2nd ques, actually here they say that its okay, but I'm looking for an explicit affirmative)\n- Even with ack_late the broker is aware message has been picked so it will never be picked from another worker.\n- Where should I write the above mentioned code blocks in the project. Any idea?","metadata":{"transformedAt":"2026-08-18T18:33:20.132Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":49,"estimatedTokens":463}}185{"id":"stack-15434810","source":"stackoverflow","questionId":15434810,"title":"RabbitMQ \"Hello World\" example gives \"Connection Refused\"","tags":["java","exception","rabbitmq"],"text":"Title: RabbitMQ \"Hello World\" example gives \"Connection Refused\"\nTags: java, exception, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nII'm trying to make the \"hello world\" application from here: RabbitMQ Hello World\n\nHere is the code of my producer class:\n\n```\npackage com.mdnaRabbit.producer;\n\nimport com.rabbitmq.client.ConnectionFactory;\nimport com.rabbitmq.client.Connection;\nimport com.rabbitmq.client.Channel;\n\nimport java.io.IOException;\n\npublic class App {\n\n private final static String QUEUE_NAME = \"hello\";\n\n public static void main( String[] argv) throws IOException{\n ConnectionFactory factory = new ConnectionFactory();\n factory.setHost(\"localhost\");\n Connection connection = factory.newConnection();\n Channel channel = connection.createChannel();\n\n channel.queueDeclare(QUEUE_NAME, false, false, false, null);\n String message = \"Hello World!\";\n channel.basicPublish(\"\", QUEUE_NAME, null, message.getBytes());\n System.out.println(\" [x] Sent\" + \"'\");\n channel.close();\n connection.close();\n }\n}\n```\n\nAnd here what I get when implement this:\n\n```\nException in thread \"main\" java.net.ConnectException: Connection refused\nat java.net.PlainSocketImpl.socketConnect(Native Method)\nat java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)\nat java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)\nat java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)\nat java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)\nat java.net.Socket.connect(Socket.java:579)\nat com.rabbitmq.client.ConnectionFactory.createFrameHandler(ConnectionFactory.java:445)\nat com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:504)\nat com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:533)\nat com.mdnaRabbit.producer.App.main(App.java:16)\nat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\nat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\nat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\nat java.lang.reflect.Method.invoke(Method.java:601)\nat com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)\n\nProcess finished with exit code 1\n```\n\nWhat is causing this?\n\nI found the solution to my problem here Error in making a socket connection\n\n========================================\n\nTop Answer:\n**I got this \"Connection Refused\" error as well:**\n\n```\nException in thread \"main\" java.net.ConnectException: Connection refused\nat java.net.PlainSocketImpl.socketConnect(Native Method)\nat java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)\nat java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)\nat java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)\nat java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)\nat java.net.Socket.connect(Socket.java:579)\nat com.rabbitmq.client.impl.FrameHandlerFactory.create(FrameHandlerFactory.java:32)\nat com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:588)\nat com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:612)\nat ReceiveLogs.main(ReceiveLogs.java:14)\n```\n\nI had made a mistake by setting the IP address from inside `/etc/rabbitmq/rabbitmq-env.conf` to the wrong ip address:\n\n```\nNODE_IP_ADDRESS=10.0.1.45\n```\n\nI removed this configuration parameter and the error goes away.\n\n========================================\n\nCode:\n```text\npackage com.mdnaRabbit.producer;\n\nimport com.rabbitmq.client.ConnectionFactory;\nimport com.rabbitmq.client.Connection;\nimport com.rabbitmq.client.Channel;\n\nimport java.io.IOException;\n\npublic class App {\n\n private final static String QUEUE_NAME = \"hello\";\n\n public static void main( String[] argv) throws IOException{\n ConnectionFactory factory = new ConnectionFactory();\n factory.setHost(\"localhost\");\n Connection connection = factory.newConnection();\n Channel channel = connection.createChannel();\n\n channel.queueDeclare(QUEUE_NAME, false, false, false, null);\n String message = \"Hello World!\";\n channel.basicPublish(\"\", QUEUE_NAME, null, message.getBytes());\n System.out.println(\" [x] Sent\" + \"'\");\n channel.close();\n connection.close();\n }\n}\n```\n\n```text\nException in thread \"main\" java.net.ConnectException: Connection refused\nat java.net.PlainSocketImpl.socketConnect(Native Method)\nat java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)\nat java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)\nat java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)\nat java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)\nat java.net.Socket.connect(Socket.java:579)\nat com.rabbitmq.client.ConnectionFactory.createFrameHandler(ConnectionFactory.java:445)\nat com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:504)\nat com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:533)\nat com.mdnaRabbit.producer.App.main(App.java:16)\nat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\nat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\nat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\nat java.lang.reflect.Method.invoke(Method.java:601)\nat com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)\n\nProcess finished with exit code 1\n```\n\n```text\nException in thread \"main\" java.net.ConnectException: Connection refused\nat java.net.PlainSocketImpl.socketConnect(Native Method)\nat java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)\nat java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)\nat java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)\nat java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)\nat java.net.Socket.connect(Socket.java:579)\nat com.rabbitmq.client.impl.FrameHandlerFactory.create(FrameHandlerFactory.java:32)\nat com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:588)\nat com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:612)\nat ReceiveLogs.main(ReceiveLogs.java:14)\n```\n\n```text\nNODE_IP_ADDRESS=10.0.1.45\n```\n\n```text\n/etc/rabbitmq/rabbitmq-env.conf\n```\n\n```text\nsudo rabbitmq-server\n```\n\n```text\n<Rabbit intall path>\\rabbitmq_server-3.6.0\\sbin>rabbitmq-server.bat start\nERROR: epmd error for host Protocol: inet_tcp: register/listen error: econnrefused: nxdomain (non-existing domain)\n```\n\n```text\nhost\n```\n\n```text\n127.0.0.1 localhost\n```\n\n```text\nconnection refuse\n```\n\n```text\nimport java.io.IOException;\nimport java.util.ResourceBundle;\nimport java.util.concurrent.TimeoutException;\nimport com.rabbitmq.client.Channel;\nimport com.rabbitmq.client.Connection;\nimport com.rabbitmq.client.ConnectionFactory;\n\npublic class NewTaskController implements Runnable {\n private final String message;\n\n private static final String EXCHANGE_NAME = \"test\";\n\n private static final String ROUTING_KEY = \"test\";\n\n public NewTaskController(final String message) {\n this.message = message;\n }\n\n @Override\n public void run() {\n\n //getting data from application.properties\n //for the rabbit_mq configuration\n\n ResourceBundle mRB = ResourceBundle.getBundle(\"application\");\n\n\n System.out.println(\"*****NewTaskController************\"+mRB.getString(\"rabbitmq.port\"));\n String rabbitmq_username = mRB.getString(\"rabbitmq.username\");\n String rabbitmq_password = mRB.getString(\"rabbitmq.password\");\n String rabbitmq_hostname = mRB.getString(\"rabbitmq.hostname\");\n int rabbitmq_port = Integer.parseInt(mRB.getString(\"rabbitmq.port\"));\n ConnectionFactory factory = new ConnectionFactory();\n factory.setUsername(rabbitmq_username);\n factory.setPassword(rabbitmq_password);\n factory.setHost(rabbitmq_hostname);\n factory.setPort(rabbitmq_port);\n Connection conn;\n try {\n conn = factory.newConnection();\n Channel channel = conn.createChannel();\n\n channel.exchangeDeclare(EXCHANGE_NAME, \"direct\", true);\n String queueName = channel.queueDeclare().getQueue();\n System.out.println(queueName);\n channel.queueBind(queueName, EXCHANGE_NAME, ROUTING_KEY);\n System.out.println(\"Producing message: \" + message + \" in thread: \" + Thread.currentThread().getName());\n channel.basicPublish(EXCHANGE_NAME, ROUTING_KEY, null, message.getBytes());\n\n try {\n channel.close();\n } catch (TimeoutException e) {\n e.printStackTrace();\n }\n conn.close();\n } catch (IOException | TimeoutException e) {\n e.printStackTrace();\n }\n}\n}\n```\n\n```text\nrabbitmq.username=guest\nrabbitmq.password=guest\nrabbitmq.hostname=localhost\nrabbitmq.port=5672\n```\n\n```text\nrabbitmq-server\n```\n\n```text\nConnection Refused\n```\n\n```text\nbrew uninstall rabbitmq\n```\n\n```text\nbrew install rabbitmq\n```\n\n```text\nrabbitmq-server\n```\n\n```text\nbrew upgrade\n```\n\n========================================\n\nComments:\n- For reference, Google says В соединении отказано translates to Connection Refused.\n- Does this question help with your problem? stackoverflow.com/questions/8939074/…\n- I'm sorry that didn't translate this. I didn't noticed it. well, thegrinner, that post descrybes the way of solving my problem, but I've solved it little earlier than see that post. thank you very much anyway.\n- More specifically, this error will be thrown if RabbitMQ is not running.\n- this. worked for me. We had set NODE_IP_ADDRESS to 127.0.0.1 so the listener were not able to connect to it, when I set the server IP address there, listeners started working.","metadata":{"transformedAt":"2026-08-18T18:33:20.132Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":18,"totalLines":290,"estimatedTokens":2456}}186{"id":"stack-7843345","source":"stackoverflow","questionId":7843345,"title":"Book for Django + Celery + RabbitMQ?","tags":["python","django","rabbitmq","celery"],"text":"Title: Book for Django + Celery + RabbitMQ?\nTags: python, django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nOK, I have been reading about the `celery` and `rabbitmq`, while I appreciate the effort of the project and the documentation, I am still confused about a lot of things. \n\nhttp://www.celeryproject.org/\n\nhttp://ask.github.com/django-celery/\n\nI am super confused about if celery is only for Django or a standalone server, as the second link claims `celery` is tightly used with Django. Both sites show different ways of setting up and using `celery`, which to me is chaotic.\n\nEnough rant, is there a proper book available that I can buy?\n\n========================================\n\nTop Answer:\nI don't know of a book, I guess a quick Amazon search would dig that up. \n\nThe bottom line is, celery is run as a separate server and works just as well for a standalone python program as Django, so it is not tied directly to Django. You can also run the `celeryd` worker software on multiple computers so they can all process the same queue concurrently. Often a separate queueing server, such as RabbitMQ is run to store the queue message.\n\nKeep in mind, `django-celery` is just an integration app that acts as glue between Django and Celery.\n\n========================================\n\nCode:\n```text\ncelery\n```\n\n```text\nrabbitmq\n```\n\n```text\ncelery\n```\n\n```text\ncelery\n```\n\n```text\nceleryd\n```\n\n```text\ndjango-celery\n```\n\n========================================\n\nComments:\n- also, I am not able to find much info about what celeryd_multi really is, when I run the first time, it looks like a command line server, but running celeryd_multi it puts the server in background as daemon. Any ideas? 1) CELERYD=\"/var/www/queuemanager/manage.py celeryd\" 2) CELERYD_MULTI=\"/var/www/queuemanager/manage.py celeryd_multi\"","metadata":{"transformedAt":"2026-08-18T18:33:20.132Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":55,"estimatedTokens":456}}187{"id":"stack-22546840","source":"stackoverflow","questionId":22546840,"title":"RabbitMQ - Wildcard in routing key vs binding key","tags":["routes","rabbitmq"],"text":"Title: RabbitMQ - Wildcard in routing key vs binding key\nTags: routes, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm using rabbitmq to send messages from a single server to multiple clients. I want to send a message to all clients so I have created an exchange which they all bind to. This works great. However, what if I want to send a message to a handful of these clients based on a wildcard in the routing key (not the binding key). For instance, I have say red clients, blue clients and green clients. Sometimes I want all clients to receive the message, sometimes I want just the blue, or just the blue and the red. This is a simplified example. To extend this to my actual system, imagine I have hundreds of \"color\" distinctions. I can't figure out how to do this as wildcards seem to only exist in binding keys not routing keys. \n\nAny advice will be greatly appreciated.\n\n========================================\n\nComments:\n- There are nice tuttorial on RabbitMQ site, look through Topic exchange, it should helps you.\n- Thanks but a topic exchange isn't quite what I need. I guess another way to phrase this: I want the server to control message distribution, not the client. A client can put a wild card in its binding key to receive all messages, but the server can't put a wildcard in the routing key so all clients receive that message, no matter their binding key. Is there a way to obtain this functionality? I want the server to send one message and have it go to a list of specific clients.\n- Thanks! I think you are right. I would give you an upvote but I don't have enough rep yet.","metadata":{"transformedAt":"2026-08-18T18:33:20.133Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":15,"estimatedTokens":401}}188{"id":"stack-12175156","source":"stackoverflow","questionId":12175156,"title":"RabbitMQ + Memory Limits","tags":["memory","memory-management","rabbitmq"],"text":"Title: RabbitMQ + Memory Limits\nTags: memory, memory-management, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm just looking in to the config details of RabbitMQ and came across\n\n```\n[{rabbit, [{vm_memory_high_watermark, 0}, \n {disk_free_limit, {mem_relative, 1.0}}\n ]\n}]\n```\n\nWhat does this config mean?\n\n`vm_memory_high_watermark` set to 0 means => Block all publishers immediately the rabbitmq app starts? But we still see rabbitmq able to queue whatever msgs we send. \n\n```\n16720 rabbitmq 20 0 142m 62m 2408 S 0 **1.6** 0:06.88 beam.smp\n```\n\nWhenever we send msgs to the broker we se this process' memory usage increasing. So, Does this mean the msgs are in memory although the watermark is set to 0? \n\nWe are curious to know what happens if the mem limit of ram reaches and still msgs are being sent? Either publishers are blocked? or The messages are swapped out to disk if available?\n\n========================================\n\nCode:\n```text\n[{rabbit, [{vm_memory_high_watermark, 0}, \n {disk_free_limit, {mem_relative, 1.0}}\n ]\n}]\n```\n\n```text\n16720 rabbitmq 20 0 142m 62m 2408 S 0 **1.6** 0:06.88 beam.smp\n```\n\n```text\nvm_memory_high_watermark\n```\n\n========================================\n\nComments:\n- Ya I had gone through that doc. What do you mean by throttled [% of msgs might be dropped] and blocked [no msgs can be sent]? If I specify 0% then alarm should be turned on the moment app starts rite? then all publisher messages should be blocked rite? or throttled? what happens if I had completely disabled memory-based flow control [0%]?\n- Throttled in this situation will result in the publishers being blocked completely (because the alarm has been triggered). If you specify 0% then you're right, the alarm will be triggered and all the publishers will be blocked. If you want to disable memory based flow control set the value to 100, 0 will just block everything\n- Actually we just ran the basic sender example and found that msgs being sent but now we noticed that msgs are not being received. So, as a whole we should have some ram mem for messages so that rmq can atleast swap out msgs in need to disk\n- \"set the vm_memory_high_watermark to 100\" Shouldn't that be 1 as it is fractional number?\n- @dmourati is correct, it should be set to `1` to be the equivalent of `100%`. so if you wish to keep it but at a lower amount, let's say `90%` the value should be `0.9`","metadata":{"transformedAt":"2026-08-18T18:33:20.133Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":52,"estimatedTokens":604}}189{"id":"stack-38111122","source":"stackoverflow","questionId":38111122,"title":"Celery: how can I route a failed task to a dead-letter queue","tags":["python","rabbitmq","celery"],"text":"Title: Celery: how can I route a failed task to a dead-letter queue\nTags: python, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI'm a newcomer to celery and I try to integrate this task queue into my project but I still don't figure out how celery handles the failed tasks and I'd like to keep all those in a amqp dead-letter queue.\n\nAccording to the doc here it seems that raising Reject in a Task having acks_late enabled produces the same effect as acking the message and then we have a few words about dead-letter queues.\n\nSo I added a custom default queue to my celery config\n\n```\ncelery_app.conf.update(CELERY_ACCEPT_CONTENT=['application/json'],\n CELERY_TASK_SERIALIZER='json',\n CELERY_QUEUES=[CELERY_QUEUE,\n CELERY_DLX_QUEUE],\n CELERY_DEFAULT_QUEUE=CELERY_QUEUE_NAME,\n CELERY_DEFAULT_EXCHANGE=CELERY_EXCHANGE\n )\n```\n\nand my kombu objects are looking like\n\n```\nCELERY_DLX_EXCHANGE = Exchange(CELERY_DLX_EXCHANGE_NAME, type='direct')\nCELERY_DLX_QUEUE = Queue(CELERY_DLX_QUEUE_NAME, exchange=DLX_EXCHANGE,\n routing_key='celery-dlq')\n\nDEAD_LETTER_CELERY_OPTIONS = {'x-dead-letter-exchange': CELERY_DLX_EXCHANGE_NAME,\n 'x-dead-letter-routing-key': 'celery-dlq'}\n\nCELERY_EXCHANGE = Exchange(CELERY_EXCHANGE_NAME,\n arguments=DEAD_LETTER_CELERY_OPTIONS,\n type='direct')\n\nCELERY_QUEUE = Queue(CELERY_QUEUE_NAME,\n exchange=CELERY_EXCHANGE,\n routing_key='celery-q')\n```\n\nAnd the task I'm executing is:\n\n```\nclass HookTask(Task):\n acks_late = True\n\ndef run(self, ctx, data):\n logger.info('{0} starting {1.name}[{1.request.id}]'.format(self.__class__.__name__.upper(), self))\n self.hook_process(ctx, data)\n\ndef on_failure(self, exc, task_id, args, kwargs, einfo):\n logger.error('task_id %s failed, message: %s', task_id, exc.message)\n\ndef hook_process(self, t_ctx, body):\n # Build context\n ctx = TaskContext(self.request, t_ctx)\n logger.info('Task_id: %s, handling request %s', ctx.task_id, ctx.req_id)\n raise Reject('no_reason', requeue=False)\n```\n\nI made a little test with it but with no results when raising a Reject exception.\n\nNow I'm wondering if it's a good idea to force the failed task route to the dead-letter queue by overriding the Task.on_failure. I think this would work but I also think that this solution is not so clean because according to what I red celery should do this all alone.\n\nThanks for your help.\n\n========================================\n\nTop Answer:\nI am having a similar case and I faced the same problems. I also wanted a solution that was based on configuration and not hard coded values. The proposed solution of Hengfeng Li was very helpfull and helped me understand the mechanism and the concepts. But there was a problem with the declaration of dead-letter queues. Specifically if you injected the DLQ in the `task_default_queues`, the Celery was consuming the queue and it was always empty. So a manual way of declaring DL(X/Q) was needed.\n\nI used Celery's Bootsteps as they provide a good control on the stage that the code was run. My initial experiment was to create them exactly after the app creation but this created stalled connection after the forking of processes and it created an ugly exception. With a bootstep that runs exactly after the `Pool` step you can be guaranteed that it runs in the begining of each worker after it is forked and the connection pool is ready.\n\nFinally I created a decorator that converts uncaught exceptions to task rejections by reraising with celery's `Reject`. Special care is taken for cases where a task is already decided on how to be handled, such as retries.\n\nHere is a full working example. Try to run the task `div.delay(1, 0)` and see how it works.\n\n```\nfrom celery import Celery\nfrom celery.exceptions import Reject, TaskPredicate\nfrom functools import wraps\nfrom kombu import Exchange, Queue\n\nfrom celery import bootsteps\n\nclass Config(object):\n\n APP_NAME = 'test'\n\n task_default_queue = '%s_celery' % APP_NAME\n task_default_exchange = \"%s_celery\" % APP_NAME\n task_default_exchange_type = 'direct'\n task_default_routing_key = task_default_queue\n task_create_missing_queues = False\n task_acks_late = True\n\n # Configuration for DLQ support\n dead_letter_exchange = '%s_dlx' % APP_NAME\n dead_letter_exchange_type = 'direct'\n dead_letter_queue = '%s_dlq' % APP_NAME\n dead_letter_routing_key = dead_letter_queue\n\nclass DeclareDLXnDLQ(bootsteps.StartStopStep):\n \"\"\"\n Celery Bootstep to declare the DL exchange and queues before the worker starts\n processing tasks\n \"\"\"\n requires = {'celery.worker.components:Pool'}\n\n def start(self, worker):\n app = worker.app\n\n # Declare DLX and DLQ\n dlx = Exchange(\n app.conf.dead_letter_exchange,\n type=app.conf.dead_letter_exchange_type)\n\n dead_letter_queue = Queue(\n app.conf.dead_letter_queue,\n dlx,\n routing_key=app.conf.dead_letter_routing_key)\n\n with worker.app.pool.acquire() as conn:\n dead_letter_queue.bind(conn).declare()\n\napp = Celery('tasks', broker='pyamqp://guest@localhost//')\napp.config_from_object(Config)\n\n# Declare default queues\n# We bypass the default mechanism tha creates queues in order to declare special queue arguments for DLX support\ndefault_exchange = Exchange(\n app.conf.task_default_exchange,\n type=app.conf.task_default_exchange_type)\ndefault_queue = Queue(\n app.conf.task_default_queue,\n default_exchange,\n routing_key=app.conf.task_default_routing_key,\n queue_arguments={\n 'x-dead-letter-exchange': app.conf.dead_letter_exchange,\n 'x-dead-letter-routing-key': app.conf.dead_letter_routing_key\n })\n\n# Inject the default queue in celery application\napp.conf.task_queues = (default_queue,)\n\n# Inject extra bootstep that declares DLX and DLQ\napp.steps['worker'].add(DeclareDLXnDLQ)\n\ndef onfailure_reject(requeue=False):\n \"\"\"\n When a task has failed it will raise a Reject exception so\n that the message will be requeued or marked for insertation in Dead Letter Exchange\n \"\"\"\n\n def _decorator(f):\n @wraps(f)\n def _wrapper(*args, **kwargs):\n\n try:\n return f(*args, **kwargs)\n except TaskPredicate:\n raise # Do not handle TaskPredicate like Retry or Reject\n except Exception as e:\n print(\"Rejecting\")\n raise Reject(str(e), requeue=requeue)\n return _wrapper\n\n return _decorator\n\n@app.task()\n@onfailure_reject()\ndef div(x, y):\n return x / y\n```\n\n**Edit:** I updated the code to use the new configuration schema of celery (lower-case) as I found some compatibility issues in Celery 4.1.0.\n\n========================================\n\nCode:\n```text\ncelery_app.conf.update(CELERY_ACCEPT_CONTENT=['application/json'],\n CELERY_TASK_SERIALIZER='json',\n CELERY_QUEUES=[CELERY_QUEUE,\n CELERY_DLX_QUEUE],\n CELERY_DEFAULT_QUEUE=CELERY_QUEUE_NAME,\n CELERY_DEFAULT_EXCHANGE=CELERY_EXCHANGE\n )\n```\n\n```text\nCELERY_DLX_EXCHANGE = Exchange(CELERY_DLX_EXCHANGE_NAME, type='direct')\nCELERY_DLX_QUEUE = Queue(CELERY_DLX_QUEUE_NAME, exchange=DLX_EXCHANGE,\n routing_key='celery-dlq')\n\nDEAD_LETTER_CELERY_OPTIONS = {'x-dead-letter-exchange': CELERY_DLX_EXCHANGE_NAME,\n 'x-dead-letter-routing-key': 'celery-dlq'}\n\nCELERY_EXCHANGE = Exchange(CELERY_EXCHANGE_NAME,\n arguments=DEAD_LETTER_CELERY_OPTIONS,\n type='direct')\n\nCELERY_QUEUE = Queue(CELERY_QUEUE_NAME,\n exchange=CELERY_EXCHANGE,\n routing_key='celery-q')\n```\n\n```text\nclass HookTask(Task):\n acks_late = True\n\ndef run(self, ctx, data):\n logger.info('{0} starting {1.name}[{1.request.id}]'.format(self.__class__.__name__.upper(), self))\n self.hook_process(ctx, data)\n\n\ndef on_failure(self, exc, task_id, args, kwargs, einfo):\n logger.error('task_id %s failed, message: %s', task_id, exc.message)\n\ndef hook_process(self, t_ctx, body):\n # Build context\n ctx = TaskContext(self.request, t_ctx)\n logger.info('Task_id: %s, handling request %s', ctx.task_id, ctx.req_id)\n raise Reject('no_reason', requeue=False)\n```\n\n```text\nfrom celery import Celery\nfrom kombu import Exchange, Queue\nfrom celery.exceptions import Reject\n\napp = Celery(\n 'tasks',\n broker='amqp://guest@localhost:5672//',\n backend='redis://localhost:6379/0')\n\ndead_letter_queue_option = {\n 'x-dead-letter-exchange': 'dlx',\n 'x-dead-letter-routing-key': 'dead_letter'\n}\n\ndefault_exchange = Exchange('default', type='direct')\ndlx_exchange = Exchange('dlx', type='direct')\n\ndefault_queue = Queue(\n 'default',\n default_exchange,\n routing_key='default',\n queue_arguments=dead_letter_queue_option)\ndead_letter_queue = Queue(\n 'dead_letter', dlx_exchange, routing_key='dead_letter')\n\napp.conf.task_queues = (default_queue, dead_letter_queue)\n\napp.conf.task_default_queue = 'default'\napp.conf.task_default_exchange = 'default'\napp.conf.task_default_routing_key = 'default'\n\n\n@app.task\ndef add(x, y):\n return x + y\n\n\n@app.task(acks_late=True)\ndef div(x, y):\n try:\n z = x / y\n return z\n except ZeroDivisionError as exc:\n raise Reject(exc, requeue=False)\n```\n\n```text\narguments=DEAD_LETTER_CELERY_OPTIONS\n```\n\n```text\nqueue_arguments=DEAD_LETTER_CELERY_OPTIONS\n```\n\n```text\nDLX\n```\n\n```text\nDLK\n```\n\n```text\nfrom celery import Celery\nfrom celery.exceptions import Reject, TaskPredicate\nfrom functools import wraps\nfrom kombu import Exchange, Queue\n\nfrom celery import bootsteps\n\n\nclass Config(object):\n\n APP_NAME = 'test'\n\n task_default_queue = '%s_celery' % APP_NAME\n task_default_exchange = \"%s_celery\" % APP_NAME\n task_default_exchange_type = 'direct'\n task_default_routing_key = task_default_queue\n task_create_missing_queues = False\n task_acks_late = True\n\n # Configuration for DLQ support\n dead_letter_exchange = '%s_dlx' % APP_NAME\n dead_letter_exchange_type = 'direct'\n dead_letter_queue = '%s_dlq' % APP_NAME\n dead_letter_routing_key = dead_letter_queue\n\n\nclass DeclareDLXnDLQ(bootsteps.StartStopStep):\n \"\"\"\n Celery Bootstep to declare the DL exchange and queues before the worker starts\n processing tasks\n \"\"\"\n requires = {'celery.worker.components:Pool'}\n\n def start(self, worker):\n app = worker.app\n\n # Declare DLX and DLQ\n dlx = Exchange(\n app.conf.dead_letter_exchange,\n type=app.conf.dead_letter_exchange_type)\n\n dead_letter_queue = Queue(\n app.conf.dead_letter_queue,\n dlx,\n routing_key=app.conf.dead_letter_routing_key)\n\n with worker.app.pool.acquire() as conn:\n dead_letter_queue.bind(conn).declare()\n\n\napp = Celery('tasks', broker='pyamqp://guest@localhost//')\napp.config_from_object(Config)\n\n\n# Declare default queues\n# We bypass the default mechanism tha creates queues in order to declare special queue arguments for DLX support\ndefault_exchange = Exchange(\n app.conf.task_default_exchange,\n type=app.conf.task_default_exchange_type)\ndefault_queue = Queue(\n app.conf.task_default_queue,\n default_exchange,\n routing_key=app.conf.task_default_routing_key,\n queue_arguments={\n 'x-dead-letter-exchange': app.conf.dead_letter_exchange,\n 'x-dead-letter-routing-key': app.conf.dead_letter_routing_key\n })\n\n# Inject the default queue in celery application\napp.conf.task_queues = (default_queue,)\n\n# Inject extra bootstep that declares DLX and DLQ\napp.steps['worker'].add(DeclareDLXnDLQ)\n\n\ndef onfailure_reject(requeue=False):\n \"\"\"\n When a task has failed it will raise a Reject exception so\n that the message will be requeued or marked for insertation in Dead Letter Exchange\n \"\"\"\n\n def _decorator(f):\n @wraps(f)\n def _wrapper(*args, **kwargs):\n\n try:\n return f(*args, **kwargs)\n except TaskPredicate:\n raise # Do not handle TaskPredicate like Retry or Reject\n except Exception as e:\n print(\"Rejecting\")\n raise Reject(str(e), requeue=requeue)\n return _wrapper\n\n return _decorator\n\n\n@app.task()\n@onfailure_reject()\ndef div(x, y):\n return x / y\n```\n\n```text\ntask_default_queues\n```\n\n```text\nPool\n```\n\n```text\nReject\n```\n\n```text\ndiv.delay(1, 0)\n```\n\n========================================\n\nComments:\n- Your example does not work for me. You have to remove `dead_letter_queue` from the `task_queues` otherwise celery worker will connect on this queue and consume the messages (without processing). Though an alternative way is needed to create these queues.\n- @K.P. I met the same issue as well. You are absolutely correct. Thanks for your solution. I tested it and it works great! :-)\n- Thanks for the decorator. I still had issues with timeouts after raising Reject, and managed to find a nice workaround over here, if you would care to comment: stackoverflow.com/questions/79590801/calling-update-state-be‌​fore-raising-reject","metadata":{"transformedAt":"2026-08-18T18:33:20.133Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":13,"totalLines":415,"estimatedTokens":3233}}190{"id":"stack-18673319","source":"stackoverflow","questionId":18673319,"title":"Celery node fail, on pidbox already using on restart","tags":["rabbitmq","celeryd"],"text":"Title: Celery node fail, on pidbox already using on restart\nTags: rabbitmq, celeryd\nSource: Stack Overflow\n\nQuestion:\nI have Celery running with RabbitMQ broker.\nToday, I have a failure of a Celery node, it doesn't execute tasks and doesn't respond on `service celeryd stop` command. After few repeats, the node stopped, but on start I get this message:\n\n```\n[WARNING/MainProcess] celery@nodename ready.\n[WARNING/MainProcess] /home/ubuntu/virtualenv/project_1/local/lib/python2.7/site-packages/kombu/pidbox.py:73: UserWarning: A node named u'nodename' is already using this process mailbox!\n\nMaybe you forgot to shutdown the other node or did not do so properly?\nOr if you meant to start multiple nodes on the same host please make sure\nyou give each node a unique node name!\n\n warnings.warn(W_PIDBOX_IN_USE % {'hostname': self.hostname})\n```\n\nCan anyone suggest how to unlock process mailbox?\n\n========================================\n\nTop Answer:\nFrom here http://celery.readthedocs.org/en/latest/userguide/workers.html#starting-the-worker you might need to name each node uniquely. Example:\n\n```\n$ celery -A proj worker --loglevel=INFO --concurrency=10 -n worker1.%h\n```\n\nIn supervisor escape by using `%%h`.\n\n========================================\n\nCode:\n```text\n[WARNING/MainProcess] celery@nodename ready.\n[WARNING/MainProcess] /home/ubuntu/virtualenv/project_1/local/lib/python2.7/site-packages/kombu/pidbox.py:73: UserWarning: A node named u'nodename' is already using this process mailbox!\n\nMaybe you forgot to shutdown the other node or did not do so properly?\nOr if you meant to start multiple nodes on the same host please make sure\nyou give each node a unique node name!\n\n warnings.warn(W_PIDBOX_IN_USE % {'hostname': self.hostname})\n```\n\n```text\nservice celeryd stop\n```\n\n```text\n$ celery -A proj worker --loglevel=INFO --concurrency=10 -n worker1.%h\n```\n\n```text\n%%h\n```\n\n========================================\n\nComments:\n- I can confirm Jamal's answer. It seems that RabbitMQ requires as much free disk space as RAM. We got very low on disk space on the box -- when we cleared up lots of space, this message stopped occurring\n- I have the same problem, and deleted all the logs and checked the space on disk. It seems all good, but I keep getting the same error...\n- This answer is incorrect. See @f01 answer for correct explanation. I was also having the same problem and was solved using the explanation given in the link in the that answer.\n- @Jamal, you are probably confusing different issues because your tests were not isolated. You probably had an already-running process when you started another one, got your error. You stopped the original one and you also deleted for new \"space\", and it got fixed, making you think it was due to the free space.\n- This actually worked for me as well. I think he should've specified that you should be freeing space in the rabbitmq server (I was using amqp)\n- Where would this log file be located?\n- Note, if you don't use `--concurrency`, and instead rely on another service like `supervisor` to handle concurrency, this will still result in conflicting node names.","metadata":{"transformedAt":"2026-08-18T18:33:20.133Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":68,"estimatedTokens":783}}191{"id":"stack-2073477","source":"stackoverflow","questionId":2073477,"title":"Can I use Mozilla Public License 1.1 (MPL) in a commercial app?","tags":["rabbitmq","mozilla"],"text":"Title: Can I use Mozilla Public License 1.1 (MPL) in a commercial app?\nTags: rabbitmq, mozilla\nSource: Stack Overflow\n\nQuestion:\nThere are a couple of threads talking about license issue. Mostly focusing on GPL/LGPL/BSD. I am trying to use RabbitMQ in commercial applications, which is licensed under Mozilla Public License(MPL). Is MPL friendly to commercial use?\n\nI found a different question on Stack Overflow, and one of the comments mentions:\n\n MPL: people can take your code, modify it, but if they distribute the modifications, they need to make sure modifications are publicly available for 3 years.\n\nIf I don't touch the source code at all, but only use the .jar files in my code, do I need to license my code under MPL as well?\n\n========================================\n\nTop Answer:\nI'm not sure if this is what you need but this is the exact diff between MPL 1.1 and Apache 2.0 licenses.\n\n```\n--- C:/Users/AlbertEin/Desktop/mozilla.txt vie ene 15 10:20:46 2010\n+++ C:/Users/Albertein/Desktop/apache.txt vie ene 15 10:20:53 2010\n@@ -1,470 +1,201 @@\n- MOZILLA PUBLIC LICENSE\n- Version 1.1\n+ Apache License\n+ Version 2.0, January 2004\n+ http://www.apache.org/licenses/\n\n- ---------------\n+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n-1. Definitions.\n+ 1. Definitions.\n\n- 1.0.1. \"Commercial Use\" means distribution or otherwise making the\n- Covered Code available to a third party.\n+ \"License\" shall mean the terms and conditions for use, reproduction,\n+ and distribution as defined by Sections 1 through 9 of this document.\n\n- 1.1. \"Contributor\" means each entity that creates or contributes to\n- the creation of Modifications.\n+ \"Licensor\" shall mean the copyright owner or entity authorized by\n+ the copyright owner that is granting the License.\n\n- 1.2. \"Contributor Version\" means the combination of the Original\n- Code, prior Modifications used by a Contributor, and the Modifications\n- made by that particular Contributor.\n+ \"Legal Entity\" shall mean the union of the acting entity and all\n+ other entities that control, are controlled by, or are under common\n+ control with that entity. For the purposes of this definition,\n+ \"control\" means (i) the power, direct or indirect, to cause the\n+ direction or management of such entity, whether by contract or\n+ otherwise, or (ii) ownership of fifty percent (50%) or more of the\n+ outstanding shares, or (iii) beneficial ownership of such entity.\n\n- 1.3. \"Covered Code\" means the Original Code or Modifications or the\n- combination of the Original Code and Modifications, in each case\n- including portions thereof.\n+ \"You\" (or \"Your\") shall mean an individual or Legal Entity\n+ exercising permissions granted by this License.\n\n- 1.4. \"Electronic Distribution Mechanism\" means a mechanism generally\n- accepted in the software development community for the electronic\n- transfer of data.\n+ \"Source\" form shall mean the preferred form for making modifications,\n+ including but not limited to software source code, documentation\n+ source, and configuration files.\n\n- 1.5. \"Executable\" means Covered Code in any form other than Source\n- Code.\n+ \"Object\" form shall mean any form resulting from mechanical\n+ transformation or translation of a Source form, including but\n+ not limited to compiled object code, generated documentation,\n+ and conversions to other media types.\n\n- 1.6. \"Initial Developer\" means the individual or entity identified\n- as the Initial Developer in the Source Code notice required by Exhibit\n- A.\n+ \"Work\" shall mean the work of authorship, whether in Source or\n+ Object form, made available under the License, as indicated by a\n+ copyright notice that is included in or attached to the work\n+ (an example is provided in the Appendix below).\n\n- 1.7. \"Larger Work\" means a work which combines Covered Code or\n- portions thereof with code not governed by the terms of this License.\n+ \"Derivative Works\" shall mean any work, whether in Source or Object\n+ form, that is based on (or derived from) the Work and for which the\n+ editorial revisions, annotations, elaborations, or other modifications\n+ represent, as a whole, an original work of authorship. For the purposes\n+ of this License, Derivative Works shall not include works that remain\n+ separable from, or merely link (or bind by name) to the interfaces of,\n+ the Work and Derivative Works thereof.\n\n- 1.8. \"License\" means this document.\n+ \"Contribution\" shall mean any work of authorship, including\n+ the original version of the Work and any modifications or additions\n+ to that Work or Derivative Works thereof, that is intentionally\n+ submitted to Licensor for inclusion in the Work by the copyright owner\n+ or by an individual or Legal Entity authorized to submit on behalf of\n+ the copyright owner. For the purposes of this definition, \"submitted\"\n+ means any form of electronic, verbal, or written communication sent\n+ to the Licensor or its representatives, including but not limited to\n+ communication on electronic mailing lists, source code control systems,\n+ and issue tracking systems that are managed by, or on behalf of, the\n+ Licensor for the purpose of discussing and improving the Work, but\n+ excluding communication that is conspicuously marked or otherwise\n+ designated in writing by the copyright owner as \"Not a Contribution.\"\n\n- 1.8.1. \"Licensable\" means having the right to grant, to the maximum\n- extent possible, whether at the time of the initial grant or\n- subsequently acquired, any and all of the rights conveyed herein.\n+ \"Contributor\" shall mean Licensor and any individual or Legal Entity\n+ on behalf of whom a Contribution has been received by Licensor and\n+ subsequently incorporated within the Work.\n\n- 1.9. \"Modifications\" means any addition to or deletion from the\n- substance or structure of either the Original Code or any previous\n- Modifications. When Covered Code is released as a series of files, a\n- Modification is:\n- A. Any addition to or deletion from the contents of a file\n- containing Original Code or previous Modifications.\n+ 2. Grant of Copyright License. Subject to the terms and conditions of\n+ this License, each Contributor hereby grants to You a perpetual,\n+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n+ copyright license to reproduce, prepare Derivative Works of,\n+ publicly display, publicly perform, sublicense, and distribute the\n+ Work and such Derivative Works in Source or Object form.\n\n- B. Any new file that contains any part of the Original Code or\n- previous Modifications.\n+ 3. Grant of Patent License. Subject to the terms and conditions of\n+ this License, each Contributor hereby grants to You a perpetual,\n+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n+ (except as stated in this section) patent license to make, have made,\n+ use, offer to sell, sell, import, and otherwise transfer the Work,\n+ where such license applies only to those patent claims licensable\n+ by such Contributor that are necessarily infringed by their\n+ Contribution(s) alone or by combination of their Contribution(s)\n+ with the Work to which such Contribution(s) was submitted. If You\n+ institute patent litigation against any entity (including a\n+ cross-claim or counterclaim in a lawsuit) alleging that the Work\n+ or a Contribution incorporated within the Work constitutes direct\n+ or contributory patent infringement, then any patent licenses\n+ granted to You under this License for that Work shall terminate\n+ as of the date such litigation is filed.\n\n- 1.10. \"Original Code\" means Source Code of computer software code\n- which is described in the Source Code notice required by Exhibit A as\n- Original Code, and which, at the time of its release under this\n- License is not already Covered Code governed by this License.\n+ 4. Redistribution. You may reproduce and distribute copies of the\n+ Work or Derivative Works thereof in any medium, with or without\n+ modifications, and in Source or Object form, provided that You\n+ meet the following conditions:\n\n- 1.10.1. \"Patent Claims\" means any patent claim(s), now owned or\n- hereafter acquired, including without limitation, method, process,\n- and apparatus claims, in any patent Licensable by grantor.\n+ (a) You must give any other recipients of the Work or\n+ Derivative Works a copy of this License; and\n\n- 1.11. \"Source Code\" means the preferred form of the Covered Code for\n- making modifications to it, including all modules it contains, plus\n- any associated interface definition files, scripts used to control\n- compilation and installation of an Executable, or source code\n- differential comparisons against either the Original Code or another\n- well known, available Covered Code of the Contributor's choice. The\n- Source Code can be in a compressed or archival form, provided the\n- appropriate decompression or de-archiving software is widely available\n- for no charge.\n+ (b) You must cause any modified files to carry prominent notices\n+ stating that You changed the files; and\n\n- 1.12. \"You\" (or \"Your\") means an individual or a legal entity\n- exercising rights under, and complying with all of the terms of, this\n- License or a future version of this License issued under Section 6.1.\n- For legal entities, \"You\" includes any entity which controls, is\n- controlled by, or is under common control with You. For purposes of\n- this definition, \"control\" means (a) the power, direct or indirect,\n- to cause the direction or management of such entity, whether by\n- contract or otherwise, or (b) ownership of more than fifty percent\n- (50%) of the outstanding shares or beneficial ownership of such\n- entity.\n+ (c) You must retain, in the Source form of any Derivative Works\n+ that You distribute, all copyright, patent, trademark, and\n+ attribution notices from the Source form of the Work,\n+ excluding those notices that do not pertain to any part of\n+ the Derivative Works; and\n\n-2. Source Code License.\n+ (d) If the Work includes a \"NOTICE\" text file as part of its\n+ distribution, then any Derivative Works that You distribute must\n+ include a readable copy of the attribution notices contained\n+ within such NOTICE file, excluding those notices that do not\n+ pertain to any part of the Derivative Works, in at least one\n+ of the following places: within a NOTICE text file distributed\n+ as part of the Derivative Works; within the Source form or\n+ documentation, if provided along with the Derivative Works; or,\n+ within a display generated by the Derivative Works, if and\n+ wherever such third-party notices normally appear. The contents\n+ of the NOTICE file are for informational purposes only and\n+ do not modify the License. You may add Your own attribution\n+ notices within Derivative Works that You distribute, alongside\n+ or as an addendum to the NOTICE text from the Work, provided\n+ that such additional attribution notices cannot be construed\n+ as modifying the License.\n\n- 2.1. The Initial Developer Grant.\n- The Initial Developer hereby grants You a world-wide, royalty-free,\n- non-exclusive license, subject to third party intellectual property\n- claims:\n- (a) under intellectual property rights (other than patent or\n- trademark) Licensable by Initial Developer to use, reproduce,\n- modify, display, perform, sublicense and distribute the Original\n- Code (or portions thereof) with or without Modifications, and/or\n- as part of a Larger Work; and\n+ You may add Your own copyright statement to Your modifications and\n+ may provide additional or different license terms and conditions\n+ for use, reproduction, or distribution of Your modifications, or\n+ for any such Derivative Works as a whole, provided Your use,\n+ reproduction, and distribution of the Work otherwise complies with\n+ the conditions stated in this License.\n\n- (b) under Patents Claims infringed by the making, using or\n- selling of Original Code, to make, have made, use, practice,\n- sell, and offer for sale, and/or otherwise dispose of the\n- Original Code (or portions thereof).\n+ 5. Submission of Contributions. Unless You explicitly state otherwise,\n+ any Contribution intentionally submitted for inclusion in the Work\n+ by You to the Licensor shall be under the terms and conditions of\n+ this License, without any additional terms or conditions.\n+ Notwithstanding the above, nothing herein shall supersede or modify\n+ the terms of any separate license agreement you may have executed\n+ with Licensor regarding such Contributions.\n\n- (c) the licenses granted in this Section 2.1(a) and (b) are\n- effective on the date Initial Developer first distributes\n- Original Code under the terms of this License.\n+ 6. Trademarks. This License does not grant permission to use the trade\n+ names, trademarks, service marks, or product names of the Licensor,\n+ except as required for reasonable and customary use in describing the\n+ origin of the Work and reproducing the content of the NOTICE file.\n\n- (d) Notwithstanding Section 2.1(b) above, no patent license is\n- granted: 1) for code that You delete from the Original Code; 2)\n- separate from the Original Code; or 3) for infringements caused\n- by: i) the modification of the Original Code or ii) the\n- combination of the Original Code with other software or devices.\n+ 7. Disclaimer of Warranty. Unless required by applicable law or\n+ agreed to in writing, Licensor provides the Work (and each\n+ Contributor provides its Contributions) on an \"AS IS\" BASIS,\n+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n+ implied, including, without limitation, any warranties or conditions\n+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n+ PARTICULAR PURPOSE. You are solely responsible for determining the\n+ appropriateness of using or redistributing the Work and assume any\n+ risks associated with Your exercise of permissions under this License.\n\n- 2.2. Contributor Grant.\n- Subject to third party intellectual property claims, each Contributor\n- hereby grants You a world-wide, royalty-free, non-exclusive license\n+ 8. Limitation of Liability. In no event and under no legal theory,\n+ whether in tort (including negligence), contract, or otherwise,\n+ unless required by applicable law (such as deliberate and grossly\n+ negligent acts) or agreed to in writing, shall any Contributor be\n+ liable to You for damages, including any direct, indirect, special,\n+ incidental, or consequential damages of any character arising as a\n+ result of this License or out of the use or inability to use the\n+ Work (including but not limited to damages for loss of goodwill,\n+ work stoppage, computer failure or malfunction, or any and all\n+ other commercial damages or losses), even if such Contributor\n+ has been advised of the possibility of such damages.\n\n- (a) under intellectual property rights (other than patent or\n- trademark) Licensable by Contributor, to use, reproduce, modify,\n- display, perform, sublicense and distribute the Modifications\n- created by such Contributor (or portions thereof) either on an\n- unmodified basis, with other Modifications, as Covered Code\n- and/or as part of a Larger Work; and\n+ 9. Accepting Warranty or Additional Liability. While redistributing\n+ the Work or Derivative Works thereof, You may choose to offer,\n+ and charge a fee for, acceptance of support, warranty, indemnity,\n+ or other liability obligations and/or rights consistent with this\n+ License. However, in accepting such obligations, You may act only\n+ on Your own behalf and on Your sole responsibility, not on behalf\n+ of any other Contributor, and only if You agree to indemnify,\n+ defend, and hold each Contributor harmless for any liability\n+ incurred by, or claims asserted against, such Contributor by reason\n+ of your accepting any such warranty or additional liability.\n\n- (b) under Patent Claims infringed by the making, using, or\n- selling of Modifications made by that Contributor either alone\n- and/or in combination with its Contributor Version (or portions\n- of such combination), to make, use, sell, offer for sale, have\n- made, and/or otherwise dispose of: 1) Modifications made by that\n- Contributor (or portions thereof); and 2) the combination of\n- Modifications made by that Contributor with its Contributor\n- Version (or portions of such combination).\n+ END OF TERMS AND CONDITIONS\n\n- (c) the licenses granted in Sections 2.2(a) and 2.2(b) are\n- effective on the date Contributor first makes Commercial Use of\n- the Covered Code.\n+ APPENDIX: How to apply the Apache License to your work.\n\n- (d) Notwithstanding Section 2.2(b) above, no patent license is\n- granted: 1) for any code that Contributor has deleted from the\n- Contributor Version; 2) separate from the Contributor Version;\n- 3) for infringements caused by: i) third party modifications of\n- Contributor Version or ii) the combination of Modifications made\n- by that Contributor with other software (except as part of the\n- Contributor Version) or other devices; or 4) under Patent Claims\n- infringed by Covered Code in the absence of Modifications made by\n- that Contributor.\n+ To apply the Apache License to your work, attach the following\n+ boilerplate notice, with the fields enclosed by brackets \"[]\"\n+ replaced with your own identifying information. (Don't include\n+ the brackets!) The text should be enclosed in the appropriate\n+ comment syntax for the file format. We also recommend that a\n+ file or class name and description of purpose be included on the\n+ same \"printed page\" as the copyright notice for easier\n+ identification within third-party archives.\n\n-3. Distribution Obligations.\n+ Copyright [yyyy] [name of copyright owner]\n\n- 3.1. Application of License.\n- The Modifications which You create or to which You contribute are\n- governed by the terms of this License, including without limitation\n- Section 2.2. The Source Code version of Covered Code may be\n- distributed only under the terms of this License or a future version\n- of this License released under Section 6.1, and You must include a\n- copy of this License with every copy of the Source Code You\n- distribute. You may not offer or impose any terms on any Source Code\n- version that alters or restricts the applicable version of this\n- License or the recipients' rights hereunder. However, You may include\n- an additional document offering the additional rights described in\n- Section 3.5.\n+ Licensed under the Apache License, Version 2.0 (the \"License\");\n+ you may not use this file except in compliance with the License.\n+ You may obtain a copy of the License at\n\n- 3.2. Availability of Source Code.\n- Any Modification which You create or to which You contribute must be\n- made available in Source Code form under the terms of this License\n- either on the same media as an Executable version or via an accepted\n- Electronic Distribution Mechanism to anyone to whom you made an\n- Executable version available; and if made available via Electronic\n- Distribution Mechanism, must remain available for at least twelve (12)\n- months after the date it initially became available, or at least six\n- (6) months after a subsequent version of that particular Modification\n- has been made available to such recipients. You are responsible for\n- ensuring that the Source Code version remains available even if the\n- Electronic Distribution Mechanism is maintained by a third party.\n+ http://www.apache.org/licenses/LICENSE-2.0\n\n- 3.3. Description of Modifications.\n- You must cause all Covered Code to which You contribute to contain a\n- file documenting the changes You made to create that Covered Code and\n- the date of any change. You must include a prominent statement that\n- the Modification is derived, directly or indirectly, from Original\n- Code provided by the Initial Developer and including the name of the\n- Initial Developer in (a) the Source Code, and (b) in any notice in an\n- Executable version or related documentation in which You describe the\n- origin or ownership of the Covered Code.\n-\n- 3.4. Intellectual Property Matters\n- (a) Third Party Claims.\n- If Contributor has knowledge that a license under a third party's\n- intellectual property rights is required to exercise the rights\n- granted by such Contributor under Sections 2.1 or 2.2,\n- Contributor must include a text file with the Source Code\n- distribution titled \"LEGAL\" which describes the claim and the\n- party making the claim in sufficient detail that a recipient will\n- know whom to contact. If Contributor obtains such knowledge after\n- the Modification is made available as described in Section 3.2,\n- Contributor shall promptly modify the LEGAL file in all copies\n- Contributor makes available thereafter and shall take other steps\n- (such as notifying appropriate mailing lists or newsgroups)\n- reasonably calculated to inform those who received the Covered\n- Code that new knowledge has been obtained.\n-\n- (b) Contributor APIs.\n- If Contributor's Modifications include an application programming\n- interface and Contributor has knowledge of patent licenses which\n- are reasonably necessary to implement that API, Contributor must\n- also include this information in the LEGAL file.\n-\n- (c) Representations.\n- Contributor represents that, except as disclosed pursuant to\n- Section 3.4(a) above, Contributor believes that Contributor's\n- Modifications are Contributor's original creation(s) and/or\n- Contributor has sufficient rights to grant the rights conveyed by\n- this License.\n-\n- 3.5. Required Notices.\n- You must duplicate the notice in Exhibit A in each file of the Source\n- Code. If it is not possible to put such notice in a particular Source\n- Code file due to its structure, then You must include such notice in a\n- location (such as a relevant directory) where a user would be likely\n- to look for such a notice. If You created one or more Modification(s)\n- You may add your name as a Contributor to the notice described in\n- Exhibit A. You must also duplicate this License in any documentation\n- for the Source Code where You describe recipients' rights or ownership\n- rights relating to Covered Code. You may choose to offer, and to\n- charge a fee for, warranty, support, indemnity or liability\n- obligations to one or more recipients of Covered Code. However, You\n- may do so only on Your own behalf, and not on behalf of the Initial\n- Developer or any Contributor. You must make it absolutely clear than\n- any such warranty, support, indemnity or liability obligation is\n- offered by You alone, and You hereby agree to indemnify the Initial\n- Developer and every Contributor for any liability incurred by the\n- Initial Developer or such Contributor as a result of warranty,\n- support, indemnity or liability terms You offer.\n-\n- 3.6. Distribution of Executable Versions.\n- You may distribute Covered Code in Executable form only if the\n- requirements of Section 3.1-3.5 have been met for that Covered Code,\n- and if You include a notice stating that the Source Code version of\n- the Covered Code is available under the terms of this License,\n- including a description of how and where You have fulfilled the\n- obligations of Section 3.2. The notice must be conspicuously included\n- in any notice in an Executable version, related documentation or\n- collateral in which You describe recipients' rights relating to the\n- Covered Code. You may distribute the Executable version of Covered\n- Code or ownership rights under a license of Your choice, which may\n- contain terms different from this License, provided that You are in\n- compliance with the terms of this License and that the license for the\n- Executable version does not attempt to limit or alter the recipient's\n- rights in the Source Code version from the rights set forth in this\n- License. If You distribute the Executable version under a different\n- license You must make it absolutely clear that any terms which differ\n- from this License are offered by You alone, not by the Initial\n- Developer or any Contributor. You hereby agree to indemnify the\n- Initial Developer and every Contributor for any liability incurred by\n- the Initial Developer or such Contributor as a result of any such\n- terms You offer.\n-\n- 3.7. Larger Works.\n- You may create a Larger Work by combining Covered Code with other code\n- not governed by the terms of this License and distribute the Larger\n- Work as a single product. In such a case, You must make sure the\n- requirements of this License are fulfilled for the Covered Code.\n-\n-4. Inability to Comply Due to Statute or Regulation.\n-\n- If it is impossible for You to comply with any of the terms of this\n- License with respect to some or all of the Covered Code due to\n- statute, judicial order, or regulation then You must: (a) comply with\n- the terms of this License to the maximum extent possible; and (b)\n- describe the limitations and the code they affect. Such description\n- must be included in the LEGAL file described in Section 3.4 and must\n- be included with all distributions of the Source Code. Except to the\n- extent prohibited by statute or regulation, such description must be\n- sufficiently detailed for a recipient of ordinary skill to be able to\n- understand it.\n-\n-5. Application of this License.\n-\n- This License applies to code to which the Initial Developer has\n- attached the notice in Exhibit A and to related Covered Code.\n-\n-6. Versions of the License.\n-\n- 6.1. New Versions.\n- Netscape Communications Corporation (\"Netscape\") may publish revised\n- and/or new versions of the License from time to time. Each version\n- will be given a distinguishing version number.\n-\n- 6.2. Effect of New Versions.\n- Once Covered Code has been published under a particular version of the\n- License, You may always continue to use it under the terms of that\n- version. You may also choose to use such Covered Code under the terms\n- of any subsequent version of the License published by Netscape. No one\n- other than Netscape has the right to modify the terms applicable to\n- Covered Code created under this License.\n-\n- 6.3. Derivative Works.\n- If You create or use a modified version of this License (which you may\n- only do in order to apply it to code which is not already Covered Code\n- governed by this L\n```\n\n========================================\n\nCode:\n```text\n--- C:/Users/AlbertEin/Desktop/mozilla.txt vie ene 15 10:20:46 2010\n+++ C:/Users/Albertein/Desktop/apache.txt vie ene 15 10:20:53 2010\n@@ -1,470 +1,201 @@\n- MOZILLA PUBLIC LICENSE\n- Version 1.1\n+ Apache License\n+ Version 2.0, January 2004\n+ http://www.apache.org/licenses/\n\n- ---------------\n+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n-1. Definitions.\n+ 1. Definitions.\n\n- 1.0.1. \"Commercial Use\" means distribution or otherwise making the\n- Covered Code available to a third party.\n+ \"License\" shall mean the terms and conditions for use, reproduction,\n+ and distribution as defined by Sections 1 through 9 of this document.\n\n- 1.1. \"Contributor\" means each entity that creates or contributes to\n- the creation of Modifications.\n+ \"Licensor\" shall mean the copyright owner or entity authorized by\n+ the copyright owner that is granting the License.\n\n- 1.2. \"Contributor Version\" means the combination of the Original\n- Code, prior Modifications used by a Contributor, and the Modifications\n- made by that particular Contributor.\n+ \"Legal Entity\" shall mean the union of the acting entity and all\n+ other entities that control, are controlled by, or are under common\n+ control with that entity. For the purposes of this definition,\n+ \"control\" means (i) the power, direct or indirect, to cause the\n+ direction or management of such entity, whether by contract or\n+ otherwise, or (ii) ownership of fifty percent (50%) or more of the\n+ outstanding shares, or (iii) beneficial ownership of such entity.\n\n- 1.3. \"Covered Code\" means the Original Code or Modifications or the\n- combination of the Original Code and Modifications, in each case\n- including portions thereof.\n+ \"You\" (or \"Your\") shall mean an individual or Legal Entity\n+ exercising permissions granted by this License.\n\n- 1.4. \"Electronic Distribution Mechanism\" means a mechanism generally\n- accepted in the software development community for the electronic\n- transfer of data.\n+ \"Source\" form shall mean the preferred form for making modifications,\n+ including but not limited to software source code, documentation\n+ source, and configuration files.\n\n- 1.5. \"Executable\" means Covered Code in any form other than Source\n- Code.\n+ \"Object\" form shall mean any form resulting from mechanical\n+ transformation or translation of a Source form, including but\n+ not limited to compiled object code, generated documentation,\n+ and conversions to other media types.\n\n- 1.6. \"Initial Developer\" means the individual or entity identified\n- as the Initial Developer in the Source Code notice required by Exhibit\n- A.\n+ \"Work\" shall mean the work of authorship, whether in Source or\n+ Object form, made available under the License, as indicated by a\n+ copyright notice that is included in or attached to the work\n+ (an example is provided in the Appendix below).\n\n- 1.7. \"Larger Work\" means a work which combines Covered Code or\n- portions thereof with code not governed by the terms of this License.\n+ \"Derivative Works\" shall mean any work, whether in Source or Object\n+ form, that is based on (or derived from) the Work and for which the\n+ editorial revisions, annotations, elaborations, or other modifications\n+ represent, as a whole, an original work of authorship. For the purposes\n+ of this License, Derivative Works shall not include works that remain\n+ separable from, or merely link (or bind by name) to the interfaces of,\n+ the Work and Derivative Works thereof.\n\n- 1.8. \"License\" means this document.\n+ \"Contribution\" shall mean any work of authorship, including\n+ the original version of the Work and any modifications or additions\n+ to that Work or Derivative Works thereof, that is intentionally\n+ submitted to Licensor for inclusion in the Work by the copyright owner\n+ or by an individual or Legal Entity authorized to submit on behalf of\n+ the copyright owner. For the purposes of this definition, \"submitted\"\n+ means any form of electronic, verbal, or written communication sent\n+ to the Licensor or its representatives, including but not limited to\n+ communication on electronic mailing lists, source code control systems,\n+ and issue tracking systems that are managed by, or on behalf of, the\n+ Licensor for the purpose of discussing and improving the Work, but\n+ excluding communication that is conspicuously marked or otherwise\n+ designated in writing by the copyright owner as \"Not a Contribution.\"\n\n- 1.8.1. \"Licensable\" means having the right to grant, to the maximum\n- extent possible, whether at the time of the initial grant or\n- subsequently acquired, any and all of the rights conveyed herein.\n+ \"Contributor\" shall mean Licensor and any individual or Legal Entity\n+ on behalf of whom a Contribution has been received by Licensor and\n+ subsequently incorporated within the Work.\n\n- 1.9. \"Modifications\" means any addition to or deletion from the\n- substance or structure of either the Original Code or any previous\n- Modifications. When Covered Code is released as a series of files, a\n- Modification is:\n- A. Any addition to or deletion from the contents of a file\n- containing Original Code or previous Modifications.\n+ 2. Grant of Copyright License. Subject to the terms and conditions of\n+ this License, each Contributor hereby grants to You a perpetual,\n+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n+ copyright license to reproduce, prepare Derivative Works of,\n+ publicly display, publicly perform, sublicense, and distribute the\n+ Work and such Derivative Works in Source or Object form.\n\n- B. Any new file that contains any part of the Original Code or\n- previous Modifications.\n+ 3. Grant of Patent License. Subject to the terms and conditions of\n+ this License, each Contributor hereby grants to You a perpetual,\n+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n+ (except as stated in this section) patent license to make, have made,\n+ use, offer to sell, sell, import, and otherwise transfer the Work,\n+ where such license applies only to those patent claims licensable\n+ by such Contributor that are necessarily infringed by their\n+ Contribution(s) alone or by combination of their Contribution(s)\n+ with the Work to which such Contribution(s) was submitted. If You\n+ institute patent litigation against any entity (including a\n+ cross-claim or counterclaim in a lawsuit) alleging that the Work\n+ or a Contribution incorporated within the Work constitutes direct\n+ or contributory patent infringement, then any patent licenses\n+ granted to You under this License for that Work shall terminate\n+ as of the date such litigation is filed.\n\n- 1.10. \"Original Code\" means Source Code of computer software code\n- which is described in the Source Code notice required by Exhibit A as\n- Original Code, and which, at the time of its release under this\n- License is not already Covered Code governed by this License.\n+ 4. Redistribution. You may reproduce and distribute copies of the\n+ Work or Derivative Works thereof in any medium, with or without\n+ modifications, and in Source or Object form, provided that You\n+ meet the following conditions:\n\n- 1.10.1. \"Patent Claims\" means any patent claim(s), now owned or\n- hereafter acquired, including without limitation, method, process,\n- and apparatus claims, in any patent Licensable by grantor.\n+ (a) You must give any other recipients of the Work or\n+ Derivative Works a copy of this License; and\n\n- 1.11. \"Source Code\" means the preferred form of the Covered Code for\n- making modifications to it, including all modules it contains, plus\n- any associated interface definition files, scripts used to control\n- compilation and installation of an Executable, or source code\n- differential comparisons against either the Original Code or another\n- well known, available Covered Code of the Contributor's choice. The\n- Source Code can be in a compressed or archival form, provided the\n- appropriate decompression or de-archiving software is widely available\n- for no charge.\n+ (b) You must cause any modified files to carry prominent notices\n+ stating that You changed the files; and\n\n- 1.12. \"You\" (or \"Your\") means an individual or a legal entity\n- exercising rights under, and complying with all of the terms of, this\n- License or a future version of this License issued under Section 6.1.\n- For legal entities, \"You\" includes any entity which controls, is\n- controlled by, or is under common control with You. For purposes of\n- this definition, \"control\" means (a) the power, direct or indirect,\n- to cause the direction or management of such entity, whether by\n- contract or otherwise, or (b) ownership of more than fifty percent\n- (50%) of the outstanding shares or beneficial ownership of such\n- entity.\n+ (c) You must retain, in the Source form of any Derivative Works\n+ that You distribute, all copyright, patent, trademark, and\n+ attribution notices from the Source form of the Work,\n+ excluding those notices that do not pertain to any part of\n+ the Derivative Works; and\n\n-2. Source Code License.\n+ (d) If the Work includes a \"NOTICE\" text file as part of its\n+ distribution, then any Derivative Works that You distribute must\n+ include a readable copy of the attribution notices contained\n+ within such NOTICE file, excluding those notices that do not\n+ pertain to any part of the Derivative Works, in at least one\n+ of the following places: within a NOTICE text file distributed\n+ as part of the Derivative Works; within the Source form or\n+ documentation, if provided along with the Derivative Works; or,\n+ within a display generated by the Derivative Works, if and\n+ wherever such third-party notices normally appear. The contents\n+ of the NOTICE file are for informational purposes only and\n+ do not modify the License. You may add Your own attribution\n+ notices within Derivative Works that You distribute, alongside\n+ or as an addendum to the NOTICE text from the Work, provided\n+ that such additional attribution notices cannot be construed\n+ as modifying the License.\n\n- 2.1. The Initial Developer Grant.\n- The Initial Developer hereby grants You a world-wide, royalty-free,\n- non-exclusive license, subject to third party intellectual property\n- claims:\n- (a) under intellectual property rights (other than patent or\n- trademark) Licensable by Initial Developer to use, reproduce,\n- modify, display, perform, sublicense and distribute the Original\n- Code (or portions thereof) with or without Modifications, and/or\n- as part of a Larger Work; and\n+ You may add Your own copyright statement to Your modifications and\n+ may provide additional or different license terms and conditions\n+ for use, reproduction, or distribution of Your modifications, or\n+ for any such Derivative Works as a whole, provided Your use,\n+ reproduction, and distribution of the Work otherwise complies with\n+ the conditions stated in this License.\n\n- (b) under Patents Claims infringed by the making, using or\n- selling of Original Code, to make, have made, use, practice,\n- sell, and offer for sale, and/or otherwise dispose of the\n- Original Code (or portions thereof).\n+ 5. Submission of Contributions. Unless You explicitly state otherwise,\n+ any Contribution intentionally submitted for inclusion in the Work\n+ by You to the Licensor shall be under the terms and conditions of\n+ this License, without any additional terms or conditions.\n+ Notwithstanding the above, nothing herein shall supersede or modify\n+ the terms of any separate license agreement you may have executed\n+ with Licensor regarding such Contributions.\n\n- (c) the licenses granted in this Section 2.1(a) and (b) are\n- effective on the date Initial Developer first distributes\n- Original Code under the terms of this License.\n+ 6. Trademarks. This License does not grant permission to use the trade\n+ names, trademarks, service marks, or product names of the Licensor,\n+ except as required for reasonable and customary use in describing the\n+ origin of the Work and reproducing the content of the NOTICE file.\n\n- (d) Notwithstanding Section 2.1(b) above, no patent license is\n- granted: 1) for code that You delete from the Original Code; 2)\n- separate from the Original Code; or 3) for infringements caused\n- by: i) the modification of the Original Code or ii) the\n- combination of the Original Code with other software or devices.\n+ 7. Disclaimer of Warranty. Unless required by applicable law or\n+ agreed to in writing, Licensor provides the Work (and each\n+ Contributor provides its Contributions) on an \"AS IS\" BASIS,\n+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n+ implied, including, without limitation, any warranties or conditions\n+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n+ PARTICULAR PURPOSE. You are solely responsible for determining the\n+ appropriateness of using or redistributing the Work and assume any\n+ risks associated with Your exercise of permissions under this License.\n\n- 2.2. Contributor Grant.\n- Subject to third party intellectual property claims, each Contributor\n- hereby grants You a world-wide, royalty-free, non-exclusive license\n+ 8. Limitation of Liability. In no event and under no legal theory,\n+ whether in tort (including negligence), contract, or otherwise,\n+ unless required by applicable law (such as deliberate and grossly\n+ negligent acts) or agreed to in writing, shall any Contributor be\n+ liable to You for damages, including any direct, indirect, special,\n+ incidental, or consequential damages of any character arising as a\n+ result of this License or out of the use or inability to use the\n+ Work (including but not limited to damages for loss of goodwill,\n+ work stoppage, computer failure or malfunction, or any and all\n+ other commercial damages or losses), even if such Contributor\n+ has been advised of the possibility of such damages.\n\n- (a) under intellectual property rights (other than patent or\n- trademark) Licensable by Contributor, to use, reproduce, modify,\n- display, perform, sublicense and distribute the Modifications\n- created by such Contributor (or portions thereof) either on an\n- unmodified basis, with other Modifications, as Covered Code\n- and/or as part of a Larger Work; and\n+ 9. Accepting Warranty or Additional Liability. While redistributing\n+ the Work or Derivative Works thereof, You may choose to offer,\n+ and charge a fee for, acceptance of support, warranty, indemnity,\n+ or other liability obligations and/or rights consistent with this\n+ License. However, in accepting such obligations, You may act only\n+ on Your own behalf and on Your sole responsibility, not on behalf\n+ of any other Contributor, and only if You agree to indemnify,\n+ defend, and hold each Contributor harmless for any liability\n+ incurred by, or claims asserted against, such Contributor by reason\n+ of your accepting any such warranty or additional liability.\n\n- (b) under Patent Claims infringed by the making, using, or\n- selling of Modifications made by that Contributor either alone\n- and/or in combination with its Contributor Version (or portions\n- of such combination), to make, use, sell, offer for sale, have\n- made, and/or otherwise dispose of: 1) Modifications made by that\n- Contributor (or portions thereof); and 2) the combination of\n- Modifications made by that Contributor with its Contributor\n- Version (or portions of such combination).\n+ END OF TERMS AND CONDITIONS\n\n- (c) the licenses granted in Sections 2.2(a) and 2.2(b) are\n- effective on the date Contributor first makes Commercial Use of\n- the Covered Code.\n+ APPENDIX: How to apply the Apache License to your work.\n\n- (d) Notwithstanding Section 2.2(b) above, no patent license is\n- granted: 1) for any code that Contributor has deleted from the\n- Contributor Version; 2) separate from the Contributor Version;\n- 3) for infringements caused by: i) third party modifications of\n- Contributor Version or ii) the combination of Modifications made\n- by that Contributor with other software (except as part of the\n- Contributor Version) or other devices; or 4) under Patent Claims\n- infringed by Covered Code in the absence of Modifications made by\n- that Contributor.\n+ To apply the Apache License to your work, attach the following\n+ boilerplate notice, with the fields enclosed by brackets \"[]\"\n+ replaced with your own identifying information. (Don't include\n+ the brackets!) The text should be enclosed in the appropriate\n+ comment syntax for the file format. We also recommend that a\n+ file or class name and description of purpose be included on the\n+ same \"printed page\" as the copyright notice for easier\n+ identification within third-party archives.\n\n-3. Distribution Obligations.\n+ Copyright [yyyy] [name of copyright owner]\n\n- 3.1. Application of License.\n- The Modifications which You create or to which You contribute are\n- governed by the terms of this License, including without limitation\n- Section 2.2. The Source Code version of Covered Code may be\n- distributed only under the terms of this License or a future version\n- of this License released under Section 6.1, and You must include a\n- copy of this License with every copy of the Source Code You\n- distribute. You may not offer or impose any terms on any Source Code\n- version that alters or restricts the applicable version of this\n- License or the recipients' rights hereunder. However, You may include\n- an additional document offering the additional rights described in\n- Section 3.5.\n+ Licensed under the Apache License, Version 2.0 (the \"License\");\n+ you may not use this file except in compliance with the License.\n+ You may obtain a copy of the License at\n\n- 3.2. Availability of Source Code.\n- Any Modification which You create or to which You contribute must be\n- made available in Source Code form under the terms of this License\n- either on the same media as an Executable version or via an accepted\n- Electronic Distribution Mechanism to anyone to whom you made an\n- Executable version available; and if made available via Electronic\n- Distribution Mechanism, must remain available for at least twelve (12)\n- months after the date it initially became available, or at least six\n- (6) months after a subsequent version of that particular Modification\n- has been made available to such recipients. You are responsible for\n- ensuring that the Source Code version remains available even if the\n- Electronic Distribution Mechanism is maintained by a third party.\n+ http://www.apache.org/licenses/LICENSE-2.0\n\n- 3.3. Description of Modifications.\n- You must cause all Covered Code to which You contribute to contain a\n- file documenting the changes You made to create that Covered Code and\n- the date of any change. You must include a prominent statement that\n- the Modification is derived, directly or indirectly, from Original\n- Code provided by the Initial Developer and including the name of the\n- Initial Developer in (a) the Source Code, and (b) in any notice in an\n- Executable version or related documentation in which You describe the\n- origin or ownership of the Covered Code.\n-\n- 3.4. Intellectual Property Matters\n- (a) Third Party Claims.\n- If Contributor has knowledge that a license under a third party's\n- intellectual property rights is required to exercise the rights\n- granted by such Contributor under Sections 2.1 or 2.2,\n- Contributor must include a text file with the Source Code\n- distribution titled \"LEGAL\" which describes the claim and the\n- party making the claim in sufficient detail that a recipient will\n- know whom to contact. If Contributor obtains such knowledge after\n- the Modification is made available as described in Section 3.2,\n- Contributor shall promptly modify the LEGAL file in all copies\n- Contributor makes available thereafter and shall take other steps\n- (such as notifying appropriate mailing lists or newsgroups)\n- reasonably calculated to inform those who received the Covered\n- Code that new knowledge has been obtained.\n-\n- (b) Contributor APIs.\n- If Contributor's Modifications include an application programming\n- interface and Contributor has knowledge of patent licenses which\n- are reasonably necessary to implement that API, Contributor must\n- also include this information in the LEGAL file.\n-\n- (c) Representations.\n- Contributor represents that, except as disclosed pursuant to\n- Section 3.4(a) above, Contributor believes that Contributor's\n- Modifications are Contributor's original creation(s) and/or\n- Contributor has sufficient rights to grant the rights conveyed by\n- this License.\n-\n- 3.5. Required Notices.\n- You must duplicate the notice in Exhibit A in each file of the Source\n- Code. If it is not possible to put such notice in a particular Source\n- Code file due to its structure, then You must include such notice in a\n- location (such as a relevant directory) where a user would be likely\n- to look for such a notice. If You created one or more Modification(s)\n- You may add your name as a Contributor to the notice described in\n- Exhibit A. You must also duplicate this License in any documentation\n- for the Source Code where You describe recipients' rights or ownership\n- rights relating to Covered Code. You may choose to offer, and to\n- charge a fee for, warranty, support, indemnity or liability\n- obligations to one or more recipients of Covered Code. However, You\n- may do so only on Your own behalf, and not on behalf of the Initial\n- Developer or any Contributor. You must make it absolutely clear than\n- any such warranty, support, indemnity or liability obligation is\n- offered by You alone, and You hereby agree to indemnify the Initial\n- Developer and every Contributor for any liability incurred by the\n- Initial Developer or such Contributor as a result of warranty,\n- support, indemnity or liability terms You offer.\n-\n- 3.6. Distribution of Executable Versions.\n- You may distribute Covered Code in Executable form only if the\n- requirements of Section 3.1-3.5 have been met for that Covered Code,\n- and if You include a notice stating that the Source Code version of\n- the Covered Code is available under the terms of this License,\n- including a description of how and where You have fulfilled the\n- obligations of Section 3.2. The notice must be conspicuously included\n- in any notice in an Executable version, related documentation or\n- collateral in which You describe recipients' rights relating to the\n- Covered Code. You may distribute the Executable version of Covered\n- Code or ownership rights under a license of Your choice, which may\n- contain terms different from this License, provided that You are in\n- compliance with the terms of this License and that the license for the\n- Executable version does not attempt to limit or alter the recipient's\n- rights in the Source Code version from the rights set forth in this\n- License. If You distribute the Executable version under a different\n- license You must make it absolutely clear that any terms which differ\n- from this License are offered by You alone, not by the Initial\n- Developer or any Contributor. You hereby agree to indemnify the\n- Initial Developer and every Contributor for any liability incurred by\n- the Initial Developer or such Contributor as a result of any such\n- terms You offer.\n-\n- 3.7. Larger Works.\n- You may create a Larger Work by combining Covered Code with other code\n- not governed by the terms of this License and distribute the Larger\n- Work as a single product. In such a case, You must make sure the\n- requirements of this License are fulfilled for the Covered Code.\n-\n-4. Inability to Comply Due to Statute or Regulation.\n-\n- If it is impossible for You to comply with any of the terms of this\n- License with respect to some or all of the Covered Code due to\n- statute, judicial order, or regulation then You must: (a) comply with\n- the terms of this License to the maximum extent possible; and (b)\n- describe the limitations and the code they affect. Such description\n- must be included in the LEGAL file described in Section 3.4 and must\n- be included with all distributions of the Source Code. Except to the\n- extent prohibited by statute or regulation, such description must be\n- sufficiently detailed for a recipient of ordinary skill to be able to\n- understand it.\n-\n-5. Application of this License.\n-\n- This License applies to code to which the Initial Developer has\n- attached the notice in Exhibit A and to related Covered Code.\n-\n-6. Versions of the License.\n-\n- 6.1. New Versions.\n- Netscape Communications Corporation (\"Netscape\") may publish revised\n- and/or new versions of the License from time to time. Each version\n- will be given a distinguishing version number.\n-\n- 6.2. Effect of New Versions.\n- Once Covered Code has been published under a particular version of the\n- License, You may always continue to use it under the terms of that\n- version. You may also choose to use such Covered Code under the terms\n- of any subsequent version of the License published by Netscape. No one\n- other than Netscape has the right to modify the terms applicable to\n- Covered Code created under this License.\n-\n- 6.3. Derivative Works.\n- If You create or use a modified version of this License (which you may\n- only do in order to apply it to code which is not already Covered Code\n- governed by this L\n```\n\n========================================\n\nComments:\n- I'm voting to close this question as off-topic because **it is about licensing or legal issues**, not programming or software development. See here for details, and the help center for more.\n- @KevinBrown What else could you do? You haven't answered it as well.\n- This is perhaps the least useful answer in the world, +1\n- +1 for answering the question that was asked...just not the question that was intended.\n- This made me laugh. Well done!\n- I actually find this answer highly relevant as I know what apache license v2 means: stackoverflow.com/questions/1007338/…","metadata":{"transformedAt":"2026-08-18T18:33:20.136Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":960,"estimatedTokens":13591}}192{"id":"stack-57209798","source":"stackoverflow","questionId":57209798,"title":"MassTransit - Can Multiple Consumers All Receive Same Message?","tags":["c#",".net",".net-core","rabbitmq","masstransit"],"text":"Title: MassTransit - Can Multiple Consumers All Receive Same Message?\nTags: c#, .net, .net-core, rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nI have one .NET 4.5.2 Service Publishing messages to RabbitMq via MassTransit. \n\nAnd **multiple** instances of a .NET Core 2.1 Service Consuming those messages.\n\nAt the moment competing instances of the .NET core consumer service steal messages from the others. \n\n**i.e. The first one to consume the message takes it off the queue and the rest of the service instances don't get to consume it.**\n\nI want **ALL** instances to consume the same message.\n\nHow can I achieve this?\n\nPublisher Service is configured as follows:\n\n```\nbuilder.Register(context =>\n {\n MessageCorrelation.UseCorrelationId(x => x.CorrelationId);\n\n return Bus.Factory.CreateUsingRabbitMq(configurator =>\n {\n configurator.Host(new Uri(\"rabbitmq://localhost:5671\"), host =>\n {\n host.Username(***);\n host.Password(***);\n });\n configurator.Message(x => { x.SetEntityName(\"my.exchange\"); });\n configurator.Publish(x =>\n {\n x.AutoDelete = true;\n x.Durable = true;\n x.ExchangeType = true;\n });\n\n });\n })\n .As()\n .As()\n .SingleInstance();\n```\n\nAnd the .NET Core Consumer Services are configured as follows:\n\n```\nserviceCollection.AddScoped();\n\n serviceCollection.AddMassTransit(serviceConfigurator =>\n {\n serviceConfigurator.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(cfg =>\n {\n var host = cfg.Host(new Uri(\"rabbitmq://localhost:5671\"), hostConfigurator =>\n {\n hostConfigurator.Username(***);\n hostConfigurator.Password(***);\n\n });\n cfg.ReceiveEndpoint(host, \"my.exchange\", exchangeConfigurator =>\n {\n exchangeConfigurator.AutoDelete = true;\n exchangeConfigurator.Durable = true;\n exchangeConfigurator.ExchangeType = \"topic\";\n exchangeConfigurator.Consumer(provider);\n });\n }));\n });\n serviceCollection.AddSingleton();\n```\n\nAnd then MyWrapperConsumer looks like this:\n\n```\npublic class MyWrapperConsumer :\n IConsumer\n{\n .\n .\n\n public MyWrapperConsumer(...) => (..) = (..);\n\n public async Task Consume(ConsumeContext context)\n {\n //Do Stuff \n }\n}\n```\n\n========================================\n\nTop Answer:\nIt sounds like you want to publish messages and have multiple consumer service instances receive them. In that case, each service instance needs to have its own queue. That way, every published message will result in a copy being delivered to each queue. Then, each receive endpoint will read that message from its own queue and consume it.\n\nAll that excessive configuration you're doing is going against what you want. To make it work, remove all that exchange type configuration, and just configure each service instance with a unique queue name (you can generate it from host, machine, whatever) and just call Publish on the message producer.\n\nYou can see how RabbitMQ topology is configured: https://masstransit-project.com/advanced/topology/rabbitmq.html\n\n========================================\n\nCode:\n```text\nbuilder.Register(context =>\n {\n MessageCorrelation.UseCorrelationId<MyWrapper>(x => x.CorrelationId);\n\n return Bus.Factory.CreateUsingRabbitMq(configurator =>\n {\n configurator.Host(new Uri(\"rabbitmq://localhost:5671\"), host =>\n {\n host.Username(***);\n host.Password(***);\n });\n configurator.Message<MyWrapper>(x => { x.SetEntityName(\"my.exchange\"); });\n configurator.Publish<MyWrapper>(x =>\n {\n x.AutoDelete = true;\n x.Durable = true;\n x.ExchangeType = true;\n });\n\n });\n })\n .As<IBusControl>()\n .As<IBus>()\n .SingleInstance();\n```\n\n```text\nserviceCollection.AddScoped<MyWrapperConsumer>();\n\n serviceCollection.AddMassTransit(serviceConfigurator =>\n {\n serviceConfigurator.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(cfg =>\n {\n var host = cfg.Host(new Uri(\"rabbitmq://localhost:5671\"), hostConfigurator =>\n {\n hostConfigurator.Username(***);\n hostConfigurator.Password(***);\n\n });\n cfg.ReceiveEndpoint(host, \"my.exchange\", exchangeConfigurator =>\n {\n exchangeConfigurator.AutoDelete = true;\n exchangeConfigurator.Durable = true;\n exchangeConfigurator.ExchangeType = \"topic\";\n exchangeConfigurator.Consumer<MyWrapperConsumer>(provider);\n });\n }));\n });\n serviceCollection.AddSingleton<IHostedService, BusService>();\n```\n\n```text\npublic class MyWrapperConsumer :\n IConsumer<MyWrapper>\n{\n .\n .\n\n public MyWrapperConsumer(...) => (..) = (..);\n\n public async Task Consume(ConsumeContext<MyWrapper> context)\n {\n //Do Stuff \n }\n}\n```\n\n```text\nconfigurator.Message<MyWrapper>(x => { x.SetEntityName(\"my.exchange\"); });\n configurator.Publish<MyWrapper>(x =>\n {\n x.AutoDelete = true;\n x.Durable = true;\n x.ExchangeType = true;\n });\n```\n\n```text\nconfigurator.Message<MyWrapper>(x => { });\n configurator.AutoDelete = true;\n```\n\n```text\ncfg.ReceiveEndpoint(host, \"my.exchange\", exchangeConfigurator =>\n {\n exchangeConfigurator.AutoDelete = true;\n exchangeConfigurator.Durable = true;\n exchangeConfigurator.ExchangeType = \"topic\";\n exchangeConfigurator.Consumer<MyWrapperConsumer>(provider);\n });\n```\n\n```text\ncfg.ReceiveEndpoint(host, Environment.MachineName, queueConfigurator =>\n {\n queueConfigurator.AutoDelete = true;\n queueConfigurator.Consumer<MyWrapperConsumer>(provider);\n });\n```\n\n```text\nMyWrapper\n```\n\n```text\nIConsumer\n```\n\n```text\nMyWrapperConsumer\n```\n\n```text\nReceiveEndpoint\n```\n\n```text\nEnvironment.MachineName\n```\n\n```text\nservices.AddMassTransit(x => {\n x.SetKebabCaseEndpointNameFormatter();\n Guid instanceId = Guid.NewGuid();\n x.AddConsumer<MyConsumer>()\n .Endpoint(c => c.InstanceId = instanceId.ToString());\n\n x.UsingRabbitMq((context, cfg) => {\n ...\n cfg.ConfigureEndpoints(context);\n });\n });\n```\n\n```text\nnamespace Masstransit.Message\n{\n public interface ICustomerRegistered\n {\n Guid Id { get; }\n DateTime RegisteredUtc { get; }\n string Name { get; }\n string Address { get; }\n }\n}\n\nnamespace Masstransit.Message\n{\n public interface IRegisterCustomer\n {\n Guid Id { get; }\n DateTime RegisteredUtc { get; }\n string Name { get; }\n string Address { get; }\n }\n}\n```\n\n```text\nnamespace Masstransit.Publisher\n{\n class Program\n {\n static void Main(string[] args)\n {\n Console.WriteLine(\"CUSTOMER REGISTRATION COMMAND PUBLISHER\");\n Console.Title = \"Publisher window\";\n RunMassTransitPublisher();\n }\n\n private static void RunMassTransitPublisher()\n {\n string rabbitMqAddress = \"rabbitmq://localhost:5672\";\n string rabbitMqQueue = \"mycompany.domains.queues\";\n Uri rabbitMqRootUri = new Uri(rabbitMqAddress);\n\n IBusControl rabbitBusControl = Bus.Factory.CreateUsingRabbitMq(rabbit =>\n {\n rabbit.Host(rabbitMqRootUri, settings =>\n {\n settings.Password(\"guest\");\n settings.Username(\"guest\");\n });\n });\n\n Task<ISendEndpoint> sendEndpointTask = rabbitBusControl.GetSendEndpoint(new Uri(string.Concat(rabbitMqAddress, \"/\", rabbitMqQueue)));\n ISendEndpoint sendEndpoint = sendEndpointTask.Result;\n\n Task sendTask = sendEndpoint.Send<IRegisterCustomer>(new\n {\n Address = \"New Street\",\n Id = Guid.NewGuid(), \n RegisteredUtc = DateTime.UtcNow,\n Name = \"Nice people LTD\" \n }, c =>\n {\n c.FaultAddress = new Uri(\"rabbitmq://localhost:5672/accounting/mycompany.queues.errors.newcustomers\");\n });\n\n Console.ReadKey();\n }\n }\n}\n```\n\n```text\nnamespace Masstransit.Receiver.Management\n{\n class Program\n {\n static void Main(string[] args)\n {\n Console.Title = \"Management consumer\";\n Console.WriteLine(\"MANAGEMENT\");\n RunMassTransitReceiver();\n }\n\n private static void RunMassTransitReceiver()\n {\n IBusControl rabbitBusControl = Bus.Factory.CreateUsingRabbitMq(rabbit =>\n {\n rabbit.Host(new Uri(\"rabbitmq://localhost:5672\"), settings =>\n {\n settings.Password(\"guest\");\n settings.Username(\"guest\");\n });\n\n rabbit.ReceiveEndpoint(\"mycompany.domains.queues.events.mgmt\", conf =>\n {\n conf.Consumer<CustomerRegisteredConsumerMgmt>();\n });\n });\n rabbitBusControl.Start();\n Console.ReadKey();\n rabbitBusControl.Stop();\n }\n }\n}\n```\n\n```text\nnamespace Masstransit.Receiver.Sales\n{\n class Program\n {\n static void Main(string[] args)\n {\n Console.Title = \"Sales consumer\";\n Console.WriteLine(\"SALES\");\n RunMassTransitReceiver();\n }\n\n private static void RunMassTransitReceiver()\n {\n IBusControl rabbitBusControl = Bus.Factory.CreateUsingRabbitMq(rabbit =>\n {\n rabbit.Host(new Uri(\"rabbitmq://localhost:5672\"), settings =>\n {\n settings.Password(\"guest\");\n settings.Username(\"guest\");\n });\n\n rabbit.ReceiveEndpoint(\"mycompany.domains.queues.events.sales\", conf =>\n {\n conf.Consumer<CustomerRegisteredConsumerSls>();\n });\n });\n\n rabbitBusControl.Start();\n Console.ReadKey();\n\n rabbitBusControl.Stop();\n }\n }\n}\n```\n\n```text\npublic class OrderChecked\n{\n public Guid OrderId { get; set; }\n}\n```\n\n```text\npublic class OrderSuccessfullyCheckedConsumer : IConsumer<OrderChecked>\n{\n public async Task Consume(ConsumeContext<OrderChecked> context)\n {\n // some your consuming code\n }\n}\n\npublic class OrderSuccessfullyCheckedConsumer2 : IConsumer<OrderChecked>\n{\n public async Task Consume(ConsumeContext<OrderChecked> context)\n {\n // some your second consuming code\n }\n}\n```\n\n```text\nservices.AddMassTransit(c =>\n{\n c.AddConsumer<OrderSuccessfullyCheckedConsumer>();\n c.AddConsumer<OrderSuccessfullyCheckedConsumer2>();\n \n c.SetKebabCaseEndpointNameFormatter();\n c.UsingRabbitMq((context, cfg) =>\n {\n cfg.ConfigureEndpoints(context);\n });\n});\nservices.AddMassTransitHostedService(true);\n```\n\n```text\nvar endpoint = await _bus.GetPublishSendEndpoint<OrderChecked>();\nawait endpoint.Send(new OrderChecked\n{\n OrderId = newOrder.Id\n});\n```\n\n```text\nIConsumer\n```\n\n```text\nPublish\n```\n\n```text\nSend\n```\n\n========================================\n\nComments:\n- Thanks for the reply. I am having a hard time getting this, which is my bad. Newbie. I have tried what i think you are saying by changing my consuming service receive endpoint to the following. But no luck. I would be very grateful if you could answer with a code example of the config changes i should make please? Cant figure out how to bind each queue to the publisher exchange. Thank you cfg.ReceiveEndpoint(host, \"my.exchange.123\", exchangeConfigurator => { exchangeConfigurator.Consumer(provider); });\n- Forget exchanges for a moment, Each service that has a different code for to consume that message should have a different endpoint name and it will get its own message. Endpoints that have the same name will be competing consumers in one queue. All those patterns are described in the Enterprise Integration Patterns boom and that specific case is mentioned in MT docs in the Common Gotchas section.\n- Thanks Alexey. I think I need a concrete code example posted here. I've read the common gotchas but can't translate it into code. When I change the config of the consumer service to what I posted in my previous comment the consumer stops consuming.\n- Gents, i have upvoted your answers & comments. And will mark my own answer as the answer because it contains the specific code. (any issues with that let me know) Thank you for the advise, took me a while but i got there with your help.\n- @chris-patterson I guess I misunderstood the difference between publish and send then still while I thought I got it :) ... I thought publish was to send the message to all your consumers where as send would send it to only one of them. But, what is the difference then?\n- While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review\n- @Labu: This is clearly more than *just* a link. If you remove the link, it still offers a solution. That said, the author should take care to read Stack Overflow's rules on self-promotion when linking to their own external content.\n- Sure - problem was that this was the only real option I had to choose from for the moderation tasks. The only other relevant one was \"no comment\" – which seemed unhelpful.\n- @Labu: The reasons are only there to aid in offering common feedback. In a case where none of the canned comments fit, you should add your own comment. That said, in this case, a more appropriate option might have been to reflag the answer as spam since it links to the author’s own repository without disclosing their affiliation.","metadata":{"transformedAt":"2026-08-18T18:33:20.136Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":24,"totalLines":453,"estimatedTokens":3555}}193{"id":"stack-7506118","source":"stackoverflow","questionId":7506118,"title":"RabbitMQ / ActiveMQ or Redis for over 250,000 msg/s","tags":["performance","redis","message-queue","activemq-classic","rabbitmq"],"text":"Title: RabbitMQ / ActiveMQ or Redis for over 250,000 msg/s\nTags: performance, redis, message-queue, activemq-classic, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nEventhough redis and message queueing software are usually used for different purposes, I would like to ask pros and cons of using redis for the following use case:\n\n- group of event collectors write incoming messages as key/value . consumers fetch and delete processed keys\n\n- load starting from 100k msg/s and going beyond 250k in short period of time (like months) target is to achieve million msg/s\n\n- persistency is not strictly required. it is ok to lose non-journaled messages during failure\n\n- performance is very important (so, the number of systems required to handle load)\n\n- messages does not have to be processed in the order they arrive\n\ndo you know such use cases where redis chosen over traditional message queueing software ? or would you consider something else ? \n\nnote: I have also seen this but did not help: \nReal-time application newbie - Node.JS + Redis or RabbitMQ -> client/server how? \n\nthanks","metadata":{"transformedAt":"2026-08-18T18:33:20.136Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":23,"estimatedTokens":271}}194{"id":"stack-24402399","source":"stackoverflow","questionId":24402399,"title":"Curl to get Rabbitmq queue size","tags":["curl","rabbitmq"],"text":"Title: Curl to get Rabbitmq queue size\nTags: curl, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nIs there a way to get the size (remaining messages) of a queue in rabbitmq with a simple Curl?\n\nSomething like `curl -xget http://host:1234/api/queue/test/stats`\n\nThank you\n\n========================================\n\nTop Answer:\nAs much as I love hacky sed one-liners this is probably the cleanest solution:\n\n```\ncurl -s -u : http://:/api/queues// | jq .messages\n```\n\n========================================\n\nCode:\n```text\ncurl -xget http://host:1234/api/queue/test/stats\n```\n\n```text\ncurl -s -i -u guest:guest http://host:port/api/queues/vhost/queue_name | sed 's/,/\\n/g' | grep '\"messages\"' | sed 's/\"messages\"://g'\n```\n\n```text\n/api/queues/(vhost)/(name)\n```\n\n```text\nmessages\n```\n\n```text\ncurl -u login:password http://localhost:15672/api/queues | sed 's/,/\\n/g' | grep '\"messages\"\\:'\n```\n\n```text\ncurl -s -u <user>:<password> http://<host>:<port>/api/queues/<virtual-host>/<queue> | jq .messages\n```\n\n========================================\n\nComments:\n- the hg.rabbitmq.com/rabbitmq-management/raw-file/86f7d33a6284/pr‌​iv/… is broken\n- Anything which looks like `sed | grep | sed` should probably be refactored. I would go for `curl ... | sed -n 's/.*\"messages:\" *\\([^ ]*\\).*/\\1/p'` but YMMV. If the output is proper JSON, `... | jq -r .messages` is simpler and more readable. (Not in a place where I can test.)\n- Also the `curl -i` option appears to be rather useless if you are throwing away the headers anyway. I was tripped by the requrement to percent-code the vhost parameter; `curl -s -u guest:guest http://localhost:55672/api/queues/%2F/queuename | grep -o '\"messages\":[0-9]*'` works for me.\n- If you just happen to be using the default vhost of \"/\" use the encoded version of \"/\", which is \"%2F\".","metadata":{"transformedAt":"2026-08-18T18:33:20.136Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":54,"estimatedTokens":465}}195{"id":"stack-63263177","source":"stackoverflow","questionId":63263177,"title":"can't start rabbitmq-server after installation","tags":["rabbitmq"],"text":"Title: can't start rabbitmq-server after installation\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm trying to use rabbitmq for a django tutorial but when I want to start the server I get this error:\n\n```\n~$ sudo rabbitmq-server \nConfiguring logger redirection\n14:49:57.041 [error] \n\n14:49:57.044 [error] BOOT FAILED\nBOOT FAILED\n14:49:57.044 [error] ===========\n===========\n14:49:57.044 [error] ERROR: could not bind to distribution port 25672, it is in use by another node: rabbit@wss\nERROR: could not bind to distribution port 25672, it is in use by another node: rabbit@wss\n14:49:57.045 [error] \n\n14:49:58.046 [error] Supervisor rabbit_prelaunch_sup had child prelaunch started with rabbit_prelaunch:run_prelaunch_first_phase() at undefined exit with reason {dist_port_already_used,25672,\"rabbit\",\"wss\"} in context start_error\n14:49:58.046 [error] CRASH REPORT Process with 0 neighbours exited with reason: {{shutdown,{failed_to_start_child,prelaunch,{dist_port_already_used,25672,\"rabbit\",\"wss\"}}},{rabbit_prelaunch_app,start,[normal,[]]}} in application_master:init/4 line 138\n{\"Kernel pid terminated\",application_controller,\"{application_start_failure,rabbitmq_prelaunch,{{shutdown,{failed_to_start_child,prelaunch,{dist_port_already_used,25672,\\\"rabbit\\\",\\\"wss\\\"}}},{rabbit_prelaunch_app,start,[normal,[]]}}}\"}\nKernel pid terminated (application_controller) ({application_start_failure,rabbitmq_prelaunch,{{shutdown,{failed_to_start_child,prelaunch,{dist_port_already_used,25672,\"rabbit\",\"wss\"}}},{rabbit_prelau\n\nCrash dump is being written to: erl_crash.dump...done\n```\n\nI've searched for port to see that if it's in use or not and I used `lsof -i :25672` and I get nothing.\n\nI don't know too much about these things so if you need anything please tell me.\n\n========================================\n\nTop Answer:\nI have encountered this issue. I figured out that this issue is coming because the rabbitmq-server is already running on the machine.\n\nI have used the following command\n\n`rabbitmqctl.bat status` to know the status of the rabbitmq-server. This helped me to know if the server is up or down.\n\nIf it is up, this could the reason you are getting the error that you have specified in your post.\n\nYou can issue the following command to make the server down\n\nrabbitmqctl.bat stop\n\nNow you can try starting the rabbitmq-server by issuing the following command\n\nrabbitmq-server start\n\nNote that I am using Windows. And I have executed these commands by pointing the command prompt to `C:\\Program Files\\RabbitMQ\\rabbitmq_server-3.8.14\\sbin` as my rabbitmq installation directory is `C:\\Program Files\\RabbitMQ\\rabbitmq_server-3.8.14`.\n\n========================================\n\nCode:\n```text\n~$ sudo rabbitmq-server \nConfiguring logger redirection\n14:49:57.041 [error] \n\n14:49:57.044 [error] BOOT FAILED\nBOOT FAILED\n14:49:57.044 [error] ===========\n===========\n14:49:57.044 [error] ERROR: could not bind to distribution port 25672, it is in use by another node: rabbit@wss\nERROR: could not bind to distribution port 25672, it is in use by another node: rabbit@wss\n14:49:57.045 [error] \n\n14:49:58.046 [error] Supervisor rabbit_prelaunch_sup had child prelaunch started with rabbit_prelaunch:run_prelaunch_first_phase() at undefined exit with reason {dist_port_already_used,25672,\"rabbit\",\"wss\"} in context start_error\n14:49:58.046 [error] CRASH REPORT Process <0.153.0> with 0 neighbours exited with reason: {{shutdown,{failed_to_start_child,prelaunch,{dist_port_already_used,25672,\"rabbit\",\"wss\"}}},{rabbit_prelaunch_app,start,[normal,[]]}} in application_master:init/4 line 138\n{\"Kernel pid terminated\",application_controller,\"{application_start_failure,rabbitmq_prelaunch,{{shutdown,{failed_to_start_child,prelaunch,{dist_port_already_used,25672,\\\"rabbit\\\",\\\"wss\\\"}}},{rabbit_prelaunch_app,start,[normal,[]]}}}\"}\nKernel pid terminated (application_controller) ({application_start_failure,rabbitmq_prelaunch,{{shutdown,{failed_to_start_child,prelaunch,{dist_port_already_used,25672,\"rabbit\",\"wss\"}}},{rabbit_prelau\n\nCrash dump is being written to: erl_crash.dump...done\n```\n\n```text\nlsof -i :25672\n```\n\n```text\nsudo lsof -i :25672\n```\n\n```text\nsudo kill <PID>\n```\n\n```text\nsudo rabbitmq-server\n```\n\n```text\n<PID>\n```\n\n```text\nsudo lsof -i :25672\n```\n\n```text\nsudo kill <PID>\n```\n\n```text\nsudo rabbitmq-server\n```\n\n```text\nsudo kill 1301\n```\n\n```text\nrabbitmqctl.bat status\n```\n\n```text\nC:\\Program Files\\RabbitMQ\\rabbitmq_server-3.8.14\\sbin\n```\n\n```text\nC:\\Program Files\\RabbitMQ\\rabbitmq_server-3.8.14\n```\n\n```text\nrabbitmq-server\n```\n\n```text\nLinux\n```\n\n```text\nWindows\n```\n\n```text\nCtrl+Alt+delete\n```\n\n```text\ntask management\n```\n\n```text\nerlang\n```\n\n```text\nAdministrator\n```\n\n```text\nrabbitmq-server\n```\n\n```text\nstartup services\n```\n\n```text\nrabbitmq-plugins enable management_plugin\n```\n\n```text\n25672\n```\n\n```text\nsudo lsof -i :25672\n```\n\n```text\nsudo kill <PID>\n```\n\n```text\nsudo rabbitmq-server\n```\n\n========================================\n\nComments:\n- we need captain in here\n- Thanks! I was having this problem when running RabbitMQ and Celery on my Mac. I tried your suggestion and it worked nicely :)\n- Worked like a charm! Ubuntu 22.04\n- Good, actually this was the issue for me. Thank you.\n- management_plugin Error: {:plugins_not_found, [:management_plugin]}","metadata":{"transformedAt":"2026-08-18T18:33:20.136Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":27,"totalLines":189,"estimatedTokens":1323}}196{"id":"stack-17541452","source":"stackoverflow","questionId":17541452,"title":"Celery does not release memory","tags":["python","rabbitmq","celery","amqp"],"text":"Title: Celery does not release memory\nTags: python, rabbitmq, celery, amqp\nSource: Stack Overflow\n\nQuestion:\nIt looks like celery does not release memory after task finished. Every time a task finishes, there would be 5m-10m memory leak. So with thousands of tasks, soon it will use up all memory.\n\n```\nBROKER_URL = 'amqp://user@localhost:5672/vhost'\n# CELERY_RESULT_BACKEND = 'amqp://user@localhost:5672/vhost'\n\nCELERY_IMPORTS = (\n 'tasks.tasks',\n)\n\nCELERY_IGNORE_RESULT = True\nCELERY_DISABLE_RATE_LIMITS = True\n# CELERY_ACKS_LATE = True\nCELERY_TASK_RESULT_EXPIRES = 3600\n# maximum time for a task to execute\nCELERYD_TASK_TIME_LIMIT = 600\nCELERY_DEFAULT_ROUTING_KEY = \"default\"\nCELERY_DEFAULT_QUEUE = 'default'\nCELERY_DEFAULT_EXCHANGE = \"default\"\nCELERY_DEFAULT_EXCHANGE_TYPE = \"direct\"\n# CELERYD_MAX_TASKS_PER_CHILD = 50\nCELERY_DISABLE_RATE_LIMITS = True\nCELERYD_CONCURRENCY = 2\n```\n\nMight be same with issue, but it does not has an answer:\nRabbitMQ/Celery/Django Memory Leak?\n\nI am not using django, and my packages are:\n\n```\nChameleon==2.11\nFabric==1.6.0\nMako==0.8.0\nMarkupSafe==0.15\nMySQL-python==1.2.4\nPaste==1.7.5.1\nPasteDeploy==1.5.0\nSQLAlchemy==0.8.1\nWebOb==1.2.3\naltgraph==0.10.2\namqp==1.0.11\nanyjson==0.3.3\nargparse==1.2.1\nbilliard==2.7.3.28\nbiplist==0.5\ncelery==3.0.19\nchaussette==0.9\ndistribute==0.6.34\nflower==0.5.1\ngevent==0.13.8\ngreenlet==0.4.1\nkombu==2.5.10\nmacholib==1.5.1\nobjgraph==1.7.2\nparamiko==1.10.1\npycrypto==2.6\npyes==0.20.0\npyramid==1.4.1\npython-dateutil==2.1\nredis==2.7.6\nrepoze.lru==0.6\nrequests==1.2.3\nsix==1.3.0\ntornado==3.1\ntranslationstring==1.1\nurllib3==1.6\nvenusian==1.0a8\nwsgiref==0.1.2\nzope.deprecation==4.0.2\nzope.interface==4.0.5\n```\n\nI just added a test task like, test_string is a big string, and it still has memory leak:\n\n```\n@celery.task(ignore_result=True)\ndef process_crash_xml(test_string, client_ip, request_timestamp):\n logger.info(\"%s %s\" % (client_ip, request_timestamp))\n test = [test_string] * 5\n```\n\n========================================\n\nTop Answer:\nThere are two settings which can help you mitigate growing memory consumption of celery workers:\n\n- Max tasks per child setting (v2.0+):\n\nWith this option you can configure the maximum number of tasks a worker can execute before it’s replaced by a new process. This is useful if you have memory leaks you have no control over for example from closed source C extensions.\n\n- Max memory per child setting (v4.0+):\n\nWith this option you can configure the maximum amount of resident memory a worker can execute before it’s replaced by a new process.\nThis is useful if you have memory leaks you have no control over for example from closed source C extensions.\n\nHowever, those options only work with the default pool (prefork).\n\nFor safe guarding against memory leaks for threads and gevent pools you can add an utility process called memmon, which is part of the superlance extension to supervisor.\n\nMemmon can monitor all running worker processes and will restart them automatically when they exceed a predefined memory limit.\n\nHere is an example configuration for your supervisor.conf:\n\n```\n[eventlistener:memmon]\ncommand=/path/to/memmon -p worker=512MB\nevents=TICK_60\n```\n\n========================================\n\nCode:\n```text\nBROKER_URL = 'amqp://user@localhost:5672/vhost'\n# CELERY_RESULT_BACKEND = 'amqp://user@localhost:5672/vhost'\n\nCELERY_IMPORTS = (\n 'tasks.tasks',\n)\n\nCELERY_IGNORE_RESULT = True\nCELERY_DISABLE_RATE_LIMITS = True\n# CELERY_ACKS_LATE = True\nCELERY_TASK_RESULT_EXPIRES = 3600\n# maximum time for a task to execute\nCELERYD_TASK_TIME_LIMIT = 600\nCELERY_DEFAULT_ROUTING_KEY = \"default\"\nCELERY_DEFAULT_QUEUE = 'default'\nCELERY_DEFAULT_EXCHANGE = \"default\"\nCELERY_DEFAULT_EXCHANGE_TYPE = \"direct\"\n# CELERYD_MAX_TASKS_PER_CHILD = 50\nCELERY_DISABLE_RATE_LIMITS = True\nCELERYD_CONCURRENCY = 2\n```\n\n```text\nChameleon==2.11\nFabric==1.6.0\nMako==0.8.0\nMarkupSafe==0.15\nMySQL-python==1.2.4\nPaste==1.7.5.1\nPasteDeploy==1.5.0\nSQLAlchemy==0.8.1\nWebOb==1.2.3\naltgraph==0.10.2\namqp==1.0.11\nanyjson==0.3.3\nargparse==1.2.1\nbilliard==2.7.3.28\nbiplist==0.5\ncelery==3.0.19\nchaussette==0.9\ndistribute==0.6.34\nflower==0.5.1\ngevent==0.13.8\ngreenlet==0.4.1\nkombu==2.5.10\nmacholib==1.5.1\nobjgraph==1.7.2\nparamiko==1.10.1\npycrypto==2.6\npyes==0.20.0\npyramid==1.4.1\npython-dateutil==2.1\nredis==2.7.6\nrepoze.lru==0.6\nrequests==1.2.3\nsix==1.3.0\ntornado==3.1\ntranslationstring==1.1\nurllib3==1.6\nvenusian==1.0a8\nwsgiref==0.1.2\nzope.deprecation==4.0.2\nzope.interface==4.0.5\n```\n\n```text\n@celery.task(ignore_result=True)\ndef process_crash_xml(test_string, client_ip, request_timestamp):\n logger.info(\"%s %s\" % (client_ip, request_timestamp))\n test = [test_string] * 5\n```\n\n```text\nCELERYD_TASK_TIME_LIMIT = 600\n```\n\n```text\nlibrabbitmq\n```\n\n```text\nlibrabbitmq>=1.0.1\n```\n\n```text\npip install librabbitmq>=1.0.1\n```\n\n```text\n[eventlistener:memmon]\ncommand=/path/to/memmon -p worker=512MB\nevents=TICK_60\n```\n\n```text\ncelery -A app worker --loglevel=info --max-tasks-per-child=1\n```\n\n========================================\n\nComments:\n- are you using `virtualenv`? do you have the list of packages/versions you are using?\n- if you are using django make sure DEBUG = False\n- I am not using librabbitmq. Celery requires \"amqp>=1.0.11,<1.1.0\" to run.","metadata":{"transformedAt":"2026-08-18T18:33:20.136Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":223,"estimatedTokens":1312}}197{"id":"stack-3434763","source":"stackoverflow","questionId":3434763,"title":"How to selectively delete messages from an AMQP (RabbitMQ) queue?","tags":["message-queue","messaging","rabbitmq","amqp"],"text":"Title: How to selectively delete messages from an AMQP (RabbitMQ) queue?\nTags: message-queue, messaging, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI'd like to selectively delete messages from an AMQP queue without even reading them.\n\nThe scenario is as follows:\n\nSending side wants to expire messages of type X based on a fact that new information of type X arrived. Because it's very probable that the subscriber didn't consume latest message of type X yet, publisher should just delete previous X-type messages and put a newest one into the queue. The whole operation should be transparent to the subscriber - in fact he should use something as simple as STOMP to get the messages.\n\nHow to do it using AMQP? Or maybe it's more convenient in another messaging protocol? \n\nI'd like to avoid a complicated infrastructure. The whole messaging needed is as simple as above: one queue, one subscriber, one publisher, but the publisher must have an ability to ad-hoc deleting the messages for a given criteria.\n\nThe publisher client will use Ruby but actually I'd deal with any language as soon as I discover how to do it in the protocol.\n\n========================================\n\nTop Answer:\nYou do not want a message queue, you want a key-value database. For instance you could use Redis or Tokyo Tyrant to get a simple network-accessible key-value database. Or just use a memcache.\n\nEach message type is a key. When you write a new message with the same key, it overwrites the previous value so the reader of this database will never be able to get out of date information.\n\nAt this point, you only need a message queue to establish the order in which keys should be read, if that is important. Otherwise, just continually scan the database. If you do continually scan the database, it is best to put the database near the readers to reduce network traffic.\n\nI would probably do something like this\n`key: typecode\nvalue: lastUpdated, important data`\n\nThen I would send messages that contain\n`typecode, lastUpdated` That way the reader can compare lastupdated for that key to the one that they last read from the database and skip reading it because they are already up to date.\n\nIf you really need to do this with AMQP, then use RabbitMQ and a custom exchange type, specifically a Last Value Cache Exchange. Example code is here https://github.com/squaremo/rabbitmq-lvc-plugin\n\n========================================\n\nCode:\n```text\nkey: typecode\nvalue: lastUpdated, important data\n```\n\n```text\ntypecode, lastUpdated\n```\n\n```text\nrabbitmqadmin get queue=queuename requeue=false count=1\n```\n\n```text\nsudo python rabbitmqadmin -V virtualhostname -u user -p pass get queue=queuename requeue=false count=1 payload_file=~/origmsg\n```\n\n========================================\n\nComments:\n- In my case the sole reason for using a queue is that X, Y, Z events are interleaved and subscriber should read them in the same order as they come - but only the latest X, latest Y and latest Z. Also, the number of types is order of thousands, so the subscriber won't listen on thousands of queues.\n- Ah. Listening to thousands of queues wouldn't have been a problem (there's next to no overhead). You cannot really selectively delete messages once they're on a queue. It occurs to me that what you want is a fileserver that supports atomic move operations: publisher starts wrtiting into a temporary file, and when it's done it, moves (renames) that file to X; the client then just reads the file X.","metadata":{"transformedAt":"2026-08-18T18:33:20.136Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":60,"estimatedTokens":873}}198{"id":"stack-1102254","source":"stackoverflow","questionId":1102254,"title":"Should I use Celery or Carrot for a Django project?","tags":["python","django","message-queue","rabbitmq","amqp"],"text":"Title: Should I use Celery or Carrot for a Django project?\nTags: python, django, message-queue, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI'm a little confused as to which one I should use. I think either will work, but is one better or more appropriate than the other?\n\nhttp://github.com/ask/carrot/tree/master\n\nhttp://github.com/ask/celery/tree/master\n\n========================================\n\nTop Answer:\nMay you should see this http://www.slideshare.net/idangazit/an-introduction-to-celery\n\n========================================\n\nCode:\n```text\ncarrot\n```\n\n```text\ncelery\n```\n\n========================================\n\nComments:\n- Hmm, which one is preferred by pink ponies? ;-)\n- I was searching in google for anything like \"Soup\" related to task queue framework .. funny names!!\n- Isn't your explanation a little bit simplistic? How about celery worker - easy management, configuration, startup scripts, rate limits etc.","metadata":{"transformedAt":"2026-08-18T18:33:20.137Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":33,"estimatedTokens":234}}199{"id":"stack-9876227","source":"stackoverflow","questionId":9876227,"title":"RabbitMQ consume one message if exists and quit","tags":["python","rabbitmq","amqp"],"text":"Title: RabbitMQ consume one message if exists and quit\nTags: python, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI am running code on python to send and receive from RabbitMQ queue from another application where I can't allow threading. \nThis is very newbie question but, is there a possibility to just check if there is message and if there are no any then just quit listening ? How should I change basic \"Hello world\" example for such task? Currently I've managed to stop consuming if I get a message, but if there are no messages my method receive() just continue waiting. How to force it not to wait if there are no messages? Or maybe wait only for given amount of time?\n\n```\nimport pika\n\nglobal answer\n\ndef send(msg):\n connection = pika.BlockingConnection(pika.ConnectionParameters())\n channel = connection.channel()\n channel.queue_declare(queue='toJ')\n channel.basic_publish(exchange='', routing_key='toJ', body=msg)\n connection.close()\n\ndef receive():\n connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))\n channel = connection.channel()\n channel.queue_declare(queue='toM')\n channel.basic_consume(callback, queue='toM', no_ack=True)\n global answer\n return answer\n\ndef callback(ch, method, properties, body):\n ch.stop_consuming()\n global answer\n answer = body\n```\n\n========================================\n\nCode:\n```text\nimport pika\n\nglobal answer\n\ndef send(msg):\n connection = pika.BlockingConnection(pika.ConnectionParameters())\n channel = connection.channel()\n channel.queue_declare(queue='toJ')\n channel.basic_publish(exchange='', routing_key='toJ', body=msg)\n connection.close()\n\ndef receive():\n connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))\n channel = connection.channel()\n channel.queue_declare(queue='toM')\n channel.basic_consume(callback, queue='toM', no_ack=True)\n global answer\n return answer\n\ndef callback(ch, method, properties, body):\n ch.stop_consuming()\n global answer\n answer = body\n```\n\n```text\ndef receive():\n parameters = pika.ConnectionParameters(RabbitMQ_server)\n connection = pika.BlockingConnection(parameters)\n channel = connection.channel()\n channel.queue_declare(queue='toM')\n method_frame, header_frame, body = channel.basic_get(queue = 'toM') \n if method_frame.NAME == 'Basic.GetEmpty':\n connection.close()\n return ''\n else: \n channel.basic_ack(delivery_tag=method_frame.delivery_tag)\n connection.close() \n return body\n```\n\n========================================\n\nComments:\n- the ruby API has a method to check the length of the queue.. have you checked the python docs?\n- Should also be important to check if method_frame is None. If there are no further messages in the queue, the channel.basic_get(queue = 'toM') will return with None-s.\n- @GrayR Is there any way to do this and acknowledge the message after completion?\n- `method_frame.NAME` does not seem to exist for pika >0.10.0. Simply testing for `if method_frame is None:` works fine with pika 1.1.0","metadata":{"transformedAt":"2026-08-18T18:33:20.137Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":86,"estimatedTokens":771}}200{"id":"stack-21265242","source":"stackoverflow","questionId":21265242,"title":"Dynamic queue creation with RabbitMQ","tags":["rabbitmq","task-queue"],"text":"Title: Dynamic queue creation with RabbitMQ\nTags: rabbitmq, task-queue\nSource: Stack Overflow\n\nQuestion:\nI've been learning RabbitMQ various topologies, however, I couldn't find any reference to dynamic queue creation (aka Declare Queue) emitted from a producer.\nThe idea would be to create queues dynamically depending on a particular event (e.g a HTTP request). The queue would be temporary with a TTL set and named after the event ID.\nA consumer could then, subscribe to the topic \"event.*\" and merge all the messages related to it.\n\n**Example:**\n\n- HTTP POST \"Create user\" received\n\n- producer creates a queue user.ID\n\n- push all the subsequent messages concerning the user in his queue (e.g \"Add username\", \"Add email\" ...)\n\n- worker gets assigned to a random queue \"user.*\" and merges everything into a user account\n\n- queue is automatically deleted after the TTL expired\n\nNow, is this scenario feasible with RabbitMQ ?\n\n========================================\n\nComments:\n- That's what I was trying to avoid, knowing in advance the queues in the consuming side. Isn't there something to consume by pattern ? say I want a worker to consume whatever queue matching log.* ?\n- Consuming does not work like publishing. You MUST know the queue you want to consume from in RabbitMQ. It would be relatively trivial to enumerate the queues from the RabbitMQ api to determine what they are.\n- No problem. I am curious to know why you would not just want to have all the messages dump into one queue (based on a topic routing)?\n- well, simplicity and efficiency I guess. In this design workers are just \"mergers\" they take a queue, build an object merging all the message in it and switch to another one (queue being garbage collected by RMQ). This doesn't require extra steps involving sorting and dispatching by message ID. No ?\n- Yeah, it is interesting.","metadata":{"transformedAt":"2026-08-18T18:33:20.137Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":31,"estimatedTokens":464}}201{"id":"stack-6169658","source":"stackoverflow","questionId":6169658,"title":"Real-time application newbie - Node.JS + Redis or RabbitMQ -> client/server how?","tags":["apache","node.js","redis","rabbitmq","publish-subscribe"],"text":"Title: Real-time application newbie - Node.JS + Redis or RabbitMQ -> client/server how?\nTags: apache, node.js, redis, rabbitmq, publish-subscribe\nSource: Stack Overflow\n\nQuestion:\nI am a newbie to real-time application development and am trying to wrap my head around the myriad options out there. I have read as many blog posts, notes and essays out there that people have been kind enough to . Yet, a simple problem seems unanswered in my tiny brain. I thought a number of other people might have the same issues, so I might as well sign up and post here on SO. Here goes:\n\nI am building a tiny real-time app which is asynchronous chat + another fun feature. I boiled my choices down to the following two options:\n\n- LAMP + RabbitMQ\n\n- Node.JS + Redis + Pub-Sub\n\nI believe that I get the basics to start learning and building this out. However, my (seriously n00b) questions are:\n\n- How do I communicate with the end-user -> Client to/from Server in both of those? Would that be simple Javascript long/infinite polling?\n\n- Of the two, which might more efficient to build out and manage from a single Slice (assuming 100 - 1,000 users)?\n\n- Should I just build everything out with jQuery in the 'old school' paradigm and then identify which stack might make more sense? Just so that I can get the product fleshed out as a prototype and then 'optimize' it. Or is writing in one over the other more than mere optimization? ( I feel so, but I am not 100% on this personally )\n\nI hope this isn't a crazy question and won't get flamed right away. Would love some constructive feedback, love this community! \n\nThank you.\n\n========================================\n\nTop Answer:\nShould I just build everything out with jQuery in the 'old school' paradigm and then identify which stack might make more sense? Just so that I can get the product fleshed out as a prototype and then 'optimize' it. Or is writing in one over the other more than mere optimization? ( I feel so, but I am not 100% on this personally )\n\nThis is usually called RAD (rapid application design/development) and it is what I would recommend right now. This lets you build the proof of concept that you can use to work off of later to get what you want to happen.\n\nAs for how to talk to the clients from the server, and vice versa, have you read at all on websockets?\n\nGiven the choice between LAMP or event based programming, for what you're suggesting, I would tell you to go with the event based programming, so nodejs. But that's just one man's opinion.\n\n========================================\n\nCode:\n```text\nrabbitmqctl\n```\n\n```text\nvhost\n```\n\n========================================\n\nComments:\n- Thank you jcolebrand. I have been reading a lot on WebSockets (and socket.io and pusherapp.com) but the problem is that it just doesn't have ubiquitous or near ubiquitous acceptance yet. Especially on mobile browsers (even upto gingerbread afaik).\n- The other concern I have is do I end up building the classic sql way and redo all of the db stuff later in the k-v model for Redis or just go all in now?\n- You have to pick your battles. I didn't see your requirements for mobile up above, so I presumed you wanted a RIA with the full support of a desktop app. You're just going to have to go for what you can get.\n- do the RAD the way it works best for you, so long as those things are clearly defined in comments and intent, then converting later will be easy enough.\n- I hear you on this, thank you. Any ideas on 'How do I communicate with the end-user -> Client to/from Server in both of those? Would that be simple Javascript long/infinite polling?'\n- websockets replaces javascript longpolling. I suggest you read on that before we continue this discussion, as it were ;) Also, see chat.stackoverflow.com/rooms/17/javascript for more targeted javascript questions that you don't have a clear question about.\n- This was super useful! Thank you! Sorry can't vote it up just yet :)\n- This is what I am thinking - 1. Build out on LAMP and jQuery for myself, just to prototype the entire thing. 2. Setup Mongo or Redis to handle the real-time data in-memory or virtualized, test everything still works. 3. Use Pub/Sub or RabbitMQ to optimize the transport layer, test. 4. Do I need anything for the client-server side, like cometd or do I just use long-polling? I don't want to use websockets with their limited adoption currently. Thank you.\n- use a client library like socket.io to avoid the slow adoption of websockets -- it falls back on long polling/flash socket etc. Modules exist for both client and server.\n- Using socket.io, that makes sense :)","metadata":{"transformedAt":"2026-08-18T18:33:20.137Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":60,"estimatedTokens":1155}}202{"id":"stack-12209652","source":"stackoverflow","questionId":12209652,"title":"Multi Celery projects with same RabbitMQ broker backend process","tags":["python","rabbitmq","celery"],"text":"Title: Multi Celery projects with same RabbitMQ broker backend process\nTags: python, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nHow can I use **two different celery project** which consumes messages from **single RabbitMQ installation**.\n\nGenerally, these scripts work fine if I use different rabbitmq for them. But on production machine, I need to the same RabbitMQ backend for them.\n\nNote: Due to some constraint, I cannot merge new projects in existing, so it will be two different project.\n\n========================================\n\nCode:\n```text\nrabbitmqctl add_vhost new_host\nrabbitmqctl add_vhost /another_host\n```\n\n```text\nrabbitmqctl add_vhost\n```\n\n========================================\n\nComments:\n- Worked great. Before implementing this method, I was trying with different Queue/Exchange config, but that didn't worked. With different VHOST, there is no conflict and both Celery apps are working fine to me.","metadata":{"transformedAt":"2026-08-18T18:33:20.137Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":27,"estimatedTokens":233}}203{"id":"stack-34200756","source":"stackoverflow","questionId":34200756,"title":"How to send JSON payload to RabbitMQ using the web plugin?","tags":["python","json","queue","rabbitmq"],"text":"Title: How to send JSON payload to RabbitMQ using the web plugin?\nTags: python, json, queue, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have a RabbitMQ 3.4.2 instance with a web management plugin installed.\n\nWhen I push to the message `{'operationId': 194}` to the queue using Python's kombu queue package, the message is read on the other end as a dictionary.\n\nHowever, when I send the message using the web console:\n\nhttps://i.sstatic.net/Ebi2M.png\n\nI get the following error on the receiving end:\n\n```\noperation_id = payload['operationId']\nTypeError: string indices must be integers\n```\n\nI have tried adding a `content-type` header and property, with no success.\n\nSince the reader code is the same, it means that the web sender does not mark the sent message as a JSON / dictionary payload, and therefore it is read as a string on the other end.\n\n**Any idea how to mark a message as a JSON message using the RabbitMQ web console?**\n\n========================================\n\nTop Answer:\nYou need to de-serialize the output.\n\n```\nimport json\npayload = json.loads(payload)\noperation_id = payload['operationId']\n```\n\nIn addition `{'operationId': 194}` is not valid JSON. Although it looks like you use double quotes in the screenshot, but make sure you replace the single quotes with double quotes.\n\n**Edit:**\nSo you are correct, kombu should handle this. Looking at the code it's likely that the header is case-sensitive. Change the properties header from `Content-Type` to `content-type`.\n\n========================================\n\nCode:\n```text\noperation_id = payload['operationId']\nTypeError: string indices must be integers\n```\n\n```text\n{'operationId': 194}\n```\n\n```text\ncontent-type\n```\n\n```text\ncontent_type\n```\n\n```text\ncontent-type\n```\n\n```text\ncontent-type\n```\n\n```text\nimport json\npayload = json.loads(payload)\noperation_id = payload['operationId']\n```\n\n```text\n{'operationId': 194}\n```\n\n```text\nContent-Type\n```\n\n```text\ncontent-type\n```\n\n========================================\n\nComments:\n- The funny thing is that messages sent from Python code requires no deserialization on the receiving end; therefore, I guess there is some metadata that does the job for me. When I send `{'operationId': 194}` it is received as a dictionary on the other end. I want to have this behaviour when sending from the web console, too.\n- @AdamMatan You are right. I think this might be as silly as the Header name being case-sensitive.\n- I should have picked up on that. I have the same implementation using a `_` in my own amqp library. github.com/eandersson/amqp-storm/blob/master/amqpstorm/…\n- Nice one! Why did you build your own instead of using Kombu or alike?\n- I wanted something much simpler, with a background thread to keep track of heartbeats etc.\n- It's not a HTTP Header... It's to distinguish that from said key as well as adhere to the RabbitMQ convention of using underscores for its properties.","metadata":{"transformedAt":"2026-08-18T18:33:20.137Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":97,"estimatedTokens":730}}204{"id":"stack-24639448","source":"stackoverflow","questionId":24639448,"title":"RabbitMQ set_permissions syntax","tags":["rabbitmq","celery","django-celery"],"text":"Title: RabbitMQ set_permissions syntax\nTags: rabbitmq, celery, django-celery\nSource: Stack Overflow\n\nQuestion:\nI've installed `rabbitmq` and it's running.\n\nI've successfully `add_user` as well as `add_vhost`. But in the next step of the documentation it says to `set_permissions` and I'm failing.\n\nI get `Error: could not recognise command` when I enter the following:\n\n```\n$ sudo rabbitmqctl set_permissions -p myvhost myuser \".*\" \".*\" \".*\"\n```\n\n(this is copy and pasted verbatim from the documentation so it seems a bit ridiculous that it doesn't work.. And 'recognise' being misspelled in the error msg isn't helping)\n\nMy question is what does `\".*\" \".*\" \".*\"` mean/stand for?\n\n========================================\n\nTop Answer:\n.* means you have full permissions\n^$ means you don't have any permissons\n\n========================================\n\nCode:\n```text\n$ sudo rabbitmqctl set_permissions -p myvhost myuser \".*\" \".*\" \".*\"\n```\n\n```text\nrabbitmq\n```\n\n```text\nadd_user\n```\n\n```text\nadd_vhost\n```\n\n```text\nset_permissions\n```\n\n```text\nError: could not recognise command\n```\n\n```text\n\".*\" \".*\" \".*\"\n```\n\n```text\n\".*\" \".*\" \".*\"\n```\n\n```text\n.\n```\n\n```text\n*\n```\n\n========================================\n\nComments:\n- What does word \"resource\" exactly mean? Exchange? Queue? Routing key? Or all of them?\n- Thanks, was looking for the \"no permissions\" syntax.","metadata":{"transformedAt":"2026-08-18T18:33:20.137Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":73,"estimatedTokens":341}}205{"id":"stack-17654475","source":"stackoverflow","questionId":17654475,"title":"Consuming not acknowledge messages from RabbitMq","tags":["php","rabbitmq","amqp"],"text":"Title: Consuming not acknowledge messages from RabbitMq\nTags: php, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI have create a simple publisher and a consumer which subscribes on the queue using `basic.consume`. \n\nMy consumer acknowledges the messages when the job runs without an exception. Whenever I run into an exception I don´t ack the message and return early. Only the acknowledged messages disappear from the queue, so that´s working correctly.\n\nNow I want the consumer to pick up the failed messages again, but the only way to reconsume those messages is by restarting the consumer. \n\nHow do I need to approach this use case?\n\n**Setup code**\n\n```\n$channel = new AMQPChannel($connection);\n\n$exchange = new AMQPExchange($channel);\n\n$exchange->setName('my-exchange');\n$exchange->setType('fanout');\n$exchange->declare();\n\n$queue = new AMQPQueue($channel);\n$queue->setName('my-queue');\n$queue->declare();\n$queue->bind('my-exchange');\n```\n\n**Consumer code**\n\n```\n$queue->consume(array($this, 'callback'));\n\npublic function callback(AMQPEnvelope $msg)\n{\n try {\n //Do some business logic\n } catch (Exception $ex) {\n //Log exception\n return;\n }\n return $queue->ack($msg->getDeliveryTag());\n}\n```\n\n**Producer code**\n\n```\n$exchange->publish('message');\n```\n\n========================================\n\nTop Answer:\nIf you do not want to restart the consumer, then `basic.recover` AMQP command may be what you want. According to AMQP protocol:\n\n```\nbasic.recover(bit requeue)\n\nRedeliver unacknowledged messages.\n\nThis method asks the server to redeliver all unacknowledged messages on a specified channel. \nZero or more messages may be redelivered. This method replaces the asynchronous Recover.\n```\n\n========================================\n\nCode:\n```text\n$channel = new AMQPChannel($connection);\n\n$exchange = new AMQPExchange($channel);\n\n$exchange->setName('my-exchange');\n$exchange->setType('fanout');\n$exchange->declare();\n\n$queue = new AMQPQueue($channel);\n$queue->setName('my-queue');\n$queue->declare();\n$queue->bind('my-exchange');\n```\n\n```text\n$queue->consume(array($this, 'callback'));\n\npublic function callback(AMQPEnvelope $msg)\n{\n try {\n //Do some business logic\n } catch (Exception $ex) {\n //Log exception\n return;\n }\n return $queue->ack($msg->getDeliveryTag());\n}\n```\n\n```text\n$exchange->publish('message');\n```\n\n```text\nbasic.consume\n```\n\n```text\ntry {\n //Do some business logic\n } catch (Exception $ex) {\n //Log exception\n return $queue->nack($msg->getDeliveryTag(), AMQP_REQUEUE);\n }\n```\n\n```text\n$queue = new AMQPQueue($channel);\n$queue->setName('my-queue');\n$queue->declareQueue();\n$queue->bind('my-exchange');\n\n$exchange->publish(\n 'message at ' . microtime(true),\n null,\n AMQP_NOPARAM,\n array(\n 'expiration' => '1000'\n )\n);\n```\n\n```text\n$queue = new AMQPQueue($channel);\n$queue->setName('my-queue');\n$queue->setArgument('x-message-ttl', 1000);\n$queue->declareQueue();\n$queue->bind('my-exchange');\n\n$exchange->publish('message at ' . microtime(true));\n```\n\n```text\n$queue = new AMQPQueue($channel);\n$queue->setName('my-queue');\n$queue->declareQueue();\n$queue->bind('my-exchange');\n\n$exchange->publish(\n 'message at ' . microtime(true),\n null,\n AMQP_NOPARAM,\n array(\n 'headers' => array(\n 'ttl' => 100\n )\n )\n);\n\n$queue->consume(\n function (AMQPEnvelope $msg, AMQPQueue $queue) use ($exchange) {\n $headers = $msg->getHeaders();\n echo $msg->isRedelivery() ? 'redelivered' : 'origin', ' ';\n echo $msg->getDeliveryTag(), ' ';\n echo isset($headers['ttl']) ? $headers['ttl'] : 'no ttl' , ' ';\n echo $msg->getBody(), PHP_EOL;\n\n try {\n //Do some business logic\n throw new Exception('business logic failed');\n } catch (Exception $ex) {\n //Log exception\n if (isset($headers['ttl'])) {\n // with ttl logic\n\n if ($headers['ttl'] > 0) {\n $headers['ttl']--;\n\n $exchange->publish($msg->getBody(), $msg->getRoutingKey(), AMQP_NOPARAM, array('headers' => $headers));\n }\n\n return $queue->ack($msg->getDeliveryTag());\n } else {\n // without ttl logic\n return $queue->nack($msg->getDeliveryTag(), AMQP_REQUEUE); // or drop it without requeue\n }\n\n }\n\n return $queue->ack($msg->getDeliveryTag());\n }\n);\n```\n\n```text\nredelivered\n```\n\n```text\ntrue\n```\n\n```text\nno-ack = true\n```\n\n```text\nnack\n```\n\n```text\nx-delivery-count\n```\n\n```text\nsleep()\n```\n\n```text\nusleep()\n```\n\n```text\nnack\n```\n\n```text\nbasic.recover(bit requeue)\n\nRedeliver unacknowledged messages.\n\nThis method asks the server to redeliver all unacknowledged messages on a specified channel. \nZero or more messages may be redelivered. This method replaces the asynchronous Recover.\n```\n\n```text\nbasic.recover\n```\n\n========================================\n\nComments:\n- Which language do you use and can you provide some code?\n- @zaq178miami, see my edited message\n- Thanks for your answer. `redelivered` is indeed set to `true`, but I have to restart my blocking consumer to reconsume the message.\n- Thanks, this is exactly what I needed. Could you give me some directions/suggestions how to prevent infinitely redelivered messages? It would be nice if I can delay the requeing to the queue by a given amount of second, so I don't overload my consuming server.\n- thanks for the chrystal clear update, this would be a very good resource for others struggeling with a similar issue. I already started implementing use a DLX and got it working now. It is behaving exactly as I want.\n- Dead Letter Exchange ;)\n- @pinepain could you please be more specific why \"Use per message or per queue TTL cons: with long queues you may loose some message\" ? I was not able to find any proofs of this behavior.\n- @profuel the reason for saying that is that in case of long queue and short TTL the processing time might be the bottleneck, so some messages might expire before they actually be consumed. So it is all working as expected, but from the user perspective it might not be desirable. E.g. there is 1M messages with 1sec TTL, obviously, many messages will be lost. With uneven per-message TTL if the consuming/processing speed is uneven, some messages might expire. So it is not that they will magically disappear due to a bug, it is that it might come as a surprise to those who are new to RabbitMQ\n- also, this answer is 10+ years old, things have changed since, the \"redelivery count doesn't implemented in RabbitMQ\" is no longer completely true, since there is quorum queue type now which has `x-delivery-count`\n- This method doesn't seem part of the client API I'm using. php.net/manual/en/book.amqp.php\n- RabbitMQ has partial support of this method, see official doc on it","metadata":{"transformedAt":"2026-08-18T18:33:20.137Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":18,"totalLines":254,"estimatedTokens":1727}}206{"id":"stack-44710248","source":"stackoverflow","questionId":44710248,"title":"consumer: Cannot connect to amqp://user:**@localhost:5672//: [Errno 111] Connection refused","tags":["docker","rabbitmq","airflow"],"text":"Title: consumer: Cannot connect to amqp://user:**@localhost:5672//: [Errno 111] Connection refused\nTags: docker, rabbitmq, airflow\nSource: Stack Overflow\n\nQuestion:\nI am trying to build my airflow using docker and rabbitMQ. I am using rabbitmq:3-management image. And I am able to access rabbitMQ UI, and API.\n\nIn airflow I am building airflow webserver, airflow scheduler, airflow worker and airflow flower. Airflow.cfg file is used to config airflow.\n\nWhere I am using `broker_url = amqp://user:password@127.0.0.1:5672/` and `celery_result_backend = amqp://user:password@127.0.0.1:5672/`\n\nMy docker compose file is as follows\n\n```\nversion: '3'\nservices:\n rabbit1:\n image: \"rabbitmq:3-management\"\n hostname: \"rabbit1\"\n environment:\n RABBITMQ_ERLANG_COOKIE: \"SWQOKODSQALRPCLNMEQG\"\n RABBITMQ_DEFAULT_USER: \"user\"\n RABBITMQ_DEFAULT_PASS: \"password\"\n RABBITMQ_DEFAULT_VHOST: \"/\"\n ports:\n - \"5672:5672\"\n - \"15672:15672\"\n\n labels:\n NAME: \"rabbitmq1\"\n\n webserver:\n build: \"airflow/\"\n hostname: \"webserver\"\n restart: always\n environment:\n - EXECUTOR=Celery\n ports:\n - \"8080:8080\"\n depends_on:\n - rabbit1\n command: webserver\n\n scheduler:\n build: \"airflow/\"\n hostname: \"scheduler\"\n restart: always\n environment:\n - EXECUTOR=Celery\n depends_on:\n - webserver\n - flower\n - worker\n command: scheduler\n\n worker:\n build: \"airflow/\"\n hostname: \"worker\"\n restart: always\n depends_on:\n - webserver\n environment:\n - EXECUTOR=Celery\n command: worker\n\n flower:\n build: \"airflow/\"\n hostname: \"flower\"\n restart: always\n environment:\n - EXECUTOR=Celery\n ports:\n - \"5555:5555\"\n depends_on:\n - rabbit1\n - webserver\n - worker\n command: flower\n```\n\nI am able to build images using docker compose. However, I am not able to connect my airflow scheduler to rabbitMQ. I am getting following error:\n\n consumer: Cannot connect to amqp://user:**@localhost:5672//: [Errno\n 111] Connection refused.\n\nI have tried using 127.0.0.1 and localhost both.\n\nWhat I am doing wrong ?\n\n========================================\n\nTop Answer:\nI solved this issue by installing rabbitMQ server into my system with command `sudo apt install rabbitmq-server`.\n\n========================================\n\nCode:\n```text\nversion: '3'\nservices:\n rabbit1:\n image: \"rabbitmq:3-management\"\n hostname: \"rabbit1\"\n environment:\n RABBITMQ_ERLANG_COOKIE: \"SWQOKODSQALRPCLNMEQG\"\n RABBITMQ_DEFAULT_USER: \"user\"\n RABBITMQ_DEFAULT_PASS: \"password\"\n RABBITMQ_DEFAULT_VHOST: \"/\"\n ports:\n - \"5672:5672\"\n - \"15672:15672\"\n\n labels:\n NAME: \"rabbitmq1\"\n\n webserver:\n build: \"airflow/\"\n hostname: \"webserver\"\n restart: always\n environment:\n - EXECUTOR=Celery\n ports:\n - \"8080:8080\"\n depends_on:\n - rabbit1\n command: webserver\n\n scheduler:\n build: \"airflow/\"\n hostname: \"scheduler\"\n restart: always\n environment:\n - EXECUTOR=Celery\n depends_on:\n - webserver\n - flower\n - worker\n command: scheduler\n\n worker:\n build: \"airflow/\"\n hostname: \"worker\"\n restart: always\n depends_on:\n - webserver\n environment:\n - EXECUTOR=Celery\n command: worker\n\n flower:\n build: \"airflow/\"\n hostname: \"flower\"\n restart: always\n environment:\n - EXECUTOR=Celery\n ports:\n - \"5555:5555\"\n depends_on:\n - rabbit1\n - webserver\n - worker\n command: flower\n```\n\n```text\nbroker_url = amqp://user:password@127.0.0.1:5672/\n```\n\n```text\ncelery_result_backend = amqp://user:password@127.0.0.1:5672/\n```\n\n```text\nairflow\n```\n\n```text\nrabbit1\n```\n\n```text\namqp://user:**@localhost:5672//:\n```\n\n```text\namqp://user:**@rabbit1:5672//:\n```\n\n```text\nsudo apt install rabbitmq-server\n```\n\n========================================\n\nComments:\n- My django project was using rabbitMQ, helped!\n- Tip: This works especially if you aren't using docker","metadata":{"transformedAt":"2026-08-18T18:33:20.137Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":197,"estimatedTokens":957}}207{"id":"stack-36979840","source":"stackoverflow","questionId":36979840,"title":"How to ask RabbitMQ to retry when business Exception occurs in Spring Asynchronous MessageListener use case","tags":["java","spring","rabbitmq"],"text":"Title: How to ask RabbitMQ to retry when business Exception occurs in Spring Asynchronous MessageListener use case\nTags: java, spring, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have a Spring AMQP message listener running.\n\n```\npublic class ConsumerService implements MessageListener {\n\n @Autowired\n RabbitTemplate rabbitTemplate;\n\n @Override\n public void onMessage(Message message) {\n try {\n testService.process(message); //This process method can throw Business Exception\n } catch (BusinessException e) {\n //Here we can just log the exception. How the retry attempt is made?\n } catch (Exception e) {\n //Here we can just log the exception. How the retry attempt is made?\n }\n }\n}\n```\n\nAs you can see, there could be exception coming out during process. I want to retry because of a particular error in Catch block. I cannot through exception in onMessage. \nHow to tell RabbitMQ to there is an exception and retry?\n\n========================================\n\nCode:\n```text\npublic class ConsumerService implements MessageListener {\n\n @Autowired\n RabbitTemplate rabbitTemplate;\n\n @Override\n public void onMessage(Message message) {\n try {\n testService.process(message); //This process method can throw Business Exception\n } catch (BusinessException e) {\n //Here we can just log the exception. How the retry attempt is made?\n } catch (Exception e) {\n //Here we can just log the exception. How the retry attempt is made?\n }\n }\n}\n```\n\n```text\ntry {\n testService.process(message);\n} catch (BusinessException e) {\n throw new RuntimeException(e);\n}\n```\n\n```text\ncontainer.setDefaultRequeueRejected(false)\n```\n\n```text\ncontainer.setAdviceChain(new Advice[] {\n org.springframework.amqp.rabbit.config.RetryInterceptorBuilder\n .stateless()\n .maxAttempts(5)\n .backOffOptions(1000, 2, 5000)\n .build()\n});\n```\n\n```text\nonMessage()\n```\n\n```text\nRuntimeException\n```\n\n```text\nSimpleMessageListenerContainer\n```\n\n```text\nAmqpRejectAndDontRequeueException\n```\n\n```text\nSimpleMessageListenerContainer\n```\n\n```text\nRetryOperationsInterceptor\n```\n\n```text\nThread.sleep()\n```\n\n```text\nRepublishMessageRecoverer\n```\n\n```text\nMessageRecoverer\n```\n\n```text\nRetryOperationsInterceptor\n```\n\n```text\nThread.sleep()\n```\n\n```text\nThread\n```\n\n```text\n\"x-message-ttl\": <delay time in milliseconds>\n```\n\n```text\n\"x-dead-letter-exchange\":\"<name of the original queue>\"\n```\n\n```text\n\"x-dead-letter-exchange\":\"<name of the queue with the TTL>\"\n```\n\n```text\nx-death\n```\n\n========================================\n\nComments:\n- Thans Nazreet for your very detailed explanation. I have few more doubts. It is clear that I have to throw a Runtime Exception to go for message retry. Also use a RetryInterceptor which limits the retry attempts. 1. On what cases we would go with Stateful interceptor/Stateless Interceptor? 2. Also, with Retry option configured, wil the other messages left unattended till this all retry completes? It should be a separate thread to retry rt? 3. How about creating a separate queue for retry and custom retry implementation?\n- I'm glad it was helpful. To answer your questions: 1) Stateful/Stateless retry interceptors are generally used in Spring (batch, integration, amqp, etc) so they have various use cases. But in the AMQP message consumers case, I don't think stateful provides a very big benefit as I mentioned. The difference is that stateful will send the message back to RabbitMQ on each retry (but after sleeping, if backoff is configured).\n- 2) What will happen with the other messages depends on the number of concurrent consumers. Each consumer is a separate thread. You set this with container.setConcurrentConsumers(). 3) Custom retry implementation is quite involved to explain in a comment. I'll try to find time to explain later.\n- Another concern related to the stateful retry interceptor is that if you have a clustered application (multiple nodes with consumers on the same queue) you need to find a way to replicate the state across nodes. Otherwise you might get the double number of retries in the worst case.\n- Added a brief description of a backoff solution that doesn't involve Thread.sleep by using RabbitMQ TTL. If you need exponential backoff it gets even more involved. Hope that helps.\n- Thanks a lot. It was very helpful.\n- For implementing this what should be the ack mode manual ? or auto ?","metadata":{"transformedAt":"2026-08-18T18:33:20.137Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":20,"totalLines":147,"estimatedTokens":1116}}208{"id":"stack-25816918","source":"stackoverflow","questionId":25816918,"title":"Not able to Start rabbitmq server in centos 7 using systemctl","tags":["rabbitmq","centos7"],"text":"Title: Not able to Start rabbitmq server in centos 7 using systemctl\nTags: rabbitmq, centos7\nSource: Stack Overflow\n\nQuestion:\nI am trying to start the rabbitmq server in centos 7. I installed erlang as it is a dependency to rabbitmq-server. Package erlang.x86_64 0:R16B-03.7.el7 .I then Installed rabbitmq using package rabbitmq-server-3.2.2-1.noarch.rpm. Installation was successful. I enabled management console uisng rabbitmq-plugins enable rabbitmq_management. But while starting the service rabbitmq-server it fails. \n\n```\n[root@tve-centos ~]# systemctl start rabbitmq-server.service\nJob for rabbitmq-server.service failed. See 'systemctl status rabbitmq-server.service' and 'journalctl -xn' for details.\n[root@tve-centos ~]# systemctl status rabbitmq-server.service\nrabbitmq-server.service - LSB: Enable AMQP service provided by RabbitMQ broker\n Loaded: loaded (/etc/rc.d/init.d/rabbitmq-server)\n Active: failed (Result: exit-code) since Fri 2014-09-12 13:07:05 PDT; 8s ago\n Process: 20235 ExecStart=/etc/rc.d/init.d/rabbitmq-server start (code=exited, status=1/FAILURE)\n\nSep 12 13:07:04 tve-centos su[20245]: (to rabbitmq) root on none\nSep 12 13:07:05 tve-centos su[20296]: (to rabbitmq) root on none\nSep 12 13:07:05 tve-centos su[20299]: (to rabbitmq) root on none\nSep 12 13:07:05 tve-centos rabbitmq-server[20235]: Starting rabbitmq-server: FAILED - check /var/log/rabbitmq/startup_{log, _err}\nSep 12 13:07:05 tve-centos rabbitmq-server[20235]: rabbitmq-server.\nSep 12 13:07:05 tve-centos systemd[1]: rabbitmq-server.service: control process exited, code=exited status=1\nSep 12 13:07:05 tve-centos systemd[1]: Failed to start LSB: Enable AMQP service provided by RabbitMQ broker.\nSep 12 13:07:05 tve-centos systemd[1]: Unit rabbitmq-server.service entered failed state.\n```\n\nand logs shows /var/log/rabbitmq/startup_log\n BOOT FAILED\n ===========\n\n```\nError description:\n {could_not_start,rabbitmq_management,\n {could_not_start_listener,[{port,15672}],eacces}}\n\nLog files (may contain more information):\n /var/log/rabbitmq/rabbit@tve-centos.log\n /var/log/rabbitmq/rabbit@tve-centos-sasl.log\n```\n\nbut no process is using port 15672\n\n**But if I try to start it using /usr/sbin/rabbitmq-server** .I successfully started the service. But my requirements are to start it using the systemctl.\n\n========================================\n\nTop Answer:\nBetter answer would be to actually fix SELinux and the firewall.\n\nOpen the port:\n\n```\nfirewall-cmd --permanent --add-port=5672/tcp\nfirewall-cmd --reload\nsetsebool -P nis_enabled 1\n```\n\nThat works for me.\n\n========================================\n\nCode:\n```text\n[root@tve-centos ~]# systemctl start rabbitmq-server.service\nJob for rabbitmq-server.service failed. See 'systemctl status rabbitmq-server.service' and 'journalctl -xn' for details.\n[root@tve-centos ~]# systemctl status rabbitmq-server.service\nrabbitmq-server.service - LSB: Enable AMQP service provided by RabbitMQ broker\n Loaded: loaded (/etc/rc.d/init.d/rabbitmq-server)\n Active: failed (Result: exit-code) since Fri 2014-09-12 13:07:05 PDT; 8s ago\n Process: 20235 ExecStart=/etc/rc.d/init.d/rabbitmq-server start (code=exited, status=1/FAILURE)\n\nSep 12 13:07:04 tve-centos su[20245]: (to rabbitmq) root on none\nSep 12 13:07:05 tve-centos su[20296]: (to rabbitmq) root on none\nSep 12 13:07:05 tve-centos su[20299]: (to rabbitmq) root on none\nSep 12 13:07:05 tve-centos rabbitmq-server[20235]: Starting rabbitmq-server: FAILED - check /var/log/rabbitmq/startup_{log, _err}\nSep 12 13:07:05 tve-centos rabbitmq-server[20235]: rabbitmq-server.\nSep 12 13:07:05 tve-centos systemd[1]: rabbitmq-server.service: control process exited, code=exited status=1\nSep 12 13:07:05 tve-centos systemd[1]: Failed to start LSB: Enable AMQP service provided by RabbitMQ broker.\nSep 12 13:07:05 tve-centos systemd[1]: Unit rabbitmq-server.service entered failed state.\n```\n\n```text\nError description:\n {could_not_start,rabbitmq_management,\n {could_not_start_listener,[{port,15672}],eacces}}\n\nLog files (may contain more information):\n /var/log/rabbitmq/rabbit@tve-centos.log\n /var/log/rabbitmq/rabbit@tve-centos-sasl.log\n```\n\n```text\nsystemctl stop firewalld\nsystemctl disable firewalld\n```\n\n```text\nSELINUX=disabled\n```\n\n```text\nfirewall-cmd --permanent --add-port=5672/tcp\nfirewall-cmd --reload\nsetsebool -P nis_enabled 1\n```\n\n```text\n[root@gcp-hehe-amqp ~]# /sbin/service rabbitmq-server start\n```\n\n```text\nRedirecting to /bin/systemctl start rabbitmq-server.service\nJob for rabbitmq-server.service failed because the control process exited with error code. See \"systemctl status rabbitmq-server.service\" and \"journalctl -xe\" for details\"\n```\n\n```text\nfirewall-cmd --permanent --add-port=5672/tcp\n```\n\n```text\nfirewall-cmd --reload\n```\n\n```text\nSELINUX=disabled\n```\n\n========================================\n\nComments:\n- As a rule, one should always run a firewall and leave SELINUX enabled; so, once the problem is identified, turning these back on is highly advised. You can run tcpdump to help figure out what firewall ports are blocked (or start by enabling the ones rabbitmq is known to need), and you can use audit2allow to figure out what SELINUX policy/boolean is blocking the service. See @chriscowley's answer.\n- I'm on `CentOS Linux release 7.0.1406 (Core)` and I get an error on the last command `Boolean nisenabled is not defined`\n- @pyCthon try without my typo :-) the boolean is actually `nis_enabled` not `nisenabled`. Sorry\n- Thank you! I finally got it running with this method too. I was missing the setsebool command bit\n- You should probably correct the same typo on your blog. ;)\n- And this doesn't expose the port to the world right? Or where can you configure Rabbit to listen only on the loopback interface?","metadata":{"transformedAt":"2026-08-18T18:33:20.137Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":136,"estimatedTokens":1440}}209{"id":"stack-30616800","source":"stackoverflow","questionId":30616800,"title":"How to change default port(15672) of RabbitMQ Management plugin?","tags":["rabbitmq"],"text":"Title: How to change default port(15672) of RabbitMQ Management plugin?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am running a RabbitMQ Management console on a machine where port above 10000 range are blocked using firewall. Can I change the port so that I can use any one of 9000 range ports ?\n\nPlease help!\n\n========================================\n\nTop Answer:\nNormally, RabbitMQ doesn't comes with config file, so you need to create it:\n\n```\nsudo nano /etc/rabbitmq/rabbitmq.config\n```\n\nAnd you can add this content\n\n```\n%% -*- mode: erlang -*-\n%% ----------------------------------------------------------------------------\n%% RabbitMQ Sample Configuration File.\n%%\n%% Related doc guide: http://www.rabbitmq.com/configure.html. See\n%% http://rabbitmq.com/documentation.html for documentation ToC.\n%% ----------------------------------------------------------------------------\n[\n {rabbit,\n[\n\n]},\n\n{kernel,\n[\n]},\n\n{rabbitmq_management,\n[\n{listener, [{port, 3009}\n ]}\n]},\n\n{rabbitmq_shovel,\n[{shovels,\n[\n]}\n\n]},\n\n{rabbitmq_stomp,\n[\n]},\n\n{rabbitmq_mqtt,\n[\n]},\n\n{rabbitmq_amqp1_0,\n[\n]},\n\n{rabbitmq_auth_backend_ldap,\n[\n]},\n{lager, [\n]}\n].\n```\n\nAs you can see, I changed my rabbitmq_management port to 3009 according to the firewall of my server.\n\nAfter that, you need to modify the /etc/rabbitmq/rabbitmq-env.conf by adding this \n line:\n\n```\nexport RABBITMQ_CONFIG_FILE=\"/etc/rabbitmq/rabbitmq\"\n```\n\nThe .config will be automatically added. \n\nBy the end, just restart the service:\n\n```\nsudo /etc/init.d/rabbitmq-server restart\n```\n\n========================================\n\nCode:\n```text\n{rabbitmq_management,[{listener, [{port, 12345}]}]}\n```\n\n```text\nrabbitmq.config.example\n```\n\n```text\nrabbitmq.config\n```\n\n```text\n/etc/rabbitmq\n```\n\n```text\nrabbitmq_management\n```\n\n```text\n12345\n```\n\n```text\n/etc/rabbitmq/rabbitmq.config\n```\n\n```text\n$ sudo /etc/init.d/rabbitmq-server restart\n```\n\n```text\n#rpm -qa | grep rabbit\nrabbitmq-server-3.6.10-1.el7.noarch\n#rpm -ql rabbitmq-server-3.6.10-1.el7.noarch\n\nsearch file like /usr/sbin/rabbitmq-server\n\ncat /usr/sbin/rabbitmq-server | grep RABBITMQ_ENV\n\nRABBITMQ_ENV=/usr/lib/rabbitmq/bin/rabbitmq-env\n\n\n\nopen file # vi /usr/lib/rabbitmq/bin/rabbitmq-env \n\n*change according to you port \n\n#DEFAULT_NODE_PORT=5672\nDEFAULT_NODE_PORT=2055\n```\n\n```text\nsudo nano /etc/rabbitmq/rabbitmq.config\n```\n\n```text\n%% -*- mode: erlang -*-\n%% ----------------------------------------------------------------------------\n%% RabbitMQ Sample Configuration File.\n%%\n%% Related doc guide: http://www.rabbitmq.com/configure.html. See\n%% http://rabbitmq.com/documentation.html for documentation ToC.\n%% ----------------------------------------------------------------------------\n[\n {rabbit,\n[\n\n]},\n\n{kernel,\n[\n]},\n\n\n{rabbitmq_management,\n[\n{listener, [{port, 3009}\n ]}\n]},\n\n{rabbitmq_shovel,\n[{shovels,\n[\n]}\n\n]},\n\n{rabbitmq_stomp,\n[\n]},\n\n\n{rabbitmq_mqtt,\n[\n]},\n\n{rabbitmq_amqp1_0,\n[\n]},\n\n{rabbitmq_auth_backend_ldap,\n[\n]},\n{lager, [\n]}\n].\n```\n\n```text\nexport RABBITMQ_CONFIG_FILE=\"/etc/rabbitmq/rabbitmq\"\n```\n\n```text\nsudo /etc/init.d/rabbitmq-server restart\n```\n\n```text\nmanagement.tcp.port = 15672\n```\n\n========================================\n\nComments:\n- Check this: rabbitmq.com/management.html#configuration (the first link from google search.)\n- @zaq178miami - I tried to configure /etc/rabbitmq/rabbitmq.config as \"[{rabbit, [{tcp_listeners, [8181]}, {collect_statistics_interval, 10000}]}, {rabbitmq_management, [{listener, [{port, 8282},{ip, \"127.0.0.1\"}, {ssl, true},{ssl_opts, [{cacertfile, \"/path/to/cacert.pem\"},{certfile, \"/path/to/cert.pem\"},{keyfile, \"/path/to/key.pem\"}]}]}]}].\" and restarted rabbitmq server.\n- @Gas - Thanks , I tried as per page. Could see tcp_listener changed from 5672 to 8181, but management console is still blocked.\n- Could you please edit the answer with path of rabbitmq.config ?\n- In my case it was `/etc/rabbitmq/rabbitmq.config`","metadata":{"transformedAt":"2026-08-18T18:33:20.137Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":14,"totalLines":221,"estimatedTokens":985}}210{"id":"stack-22194675","source":"stackoverflow","questionId":22194675,"title":"RabbitMQ - Random queues with name \"amq.gen-*\" getting autogenerated","tags":["android","node.js","rabbitmq"],"text":"Title: RabbitMQ - Random queues with name \"amq.gen-*\" getting autogenerated\nTags: android, node.js, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have a set up to send messages to durable queues from server (NodeJS) and the client (android app) listens to messages on their respective queues (each android device listens to its corresponding queue which is unique).\n\nAs per the RabbitMQ document, when we try to connect to a queue with empty name (i.e \"\") then RabbitMQ generates a random queue with name starting with \"amq.gen-\". But, no where from the client or server code I see that I am trying to connect to a queue with empty name but still see lot of random queues getting generated.\n\nCan anyone help me in understanding what other scenarios might create random queues with name \"amq.gen-*\"?\n\n========================================\n\nTop Answer:\nRabbitMq generated random name queues(amq.gen-* ) if in the application you are passing empty string as a Queue name Plz check RabbitMq configuration .\n\n========================================\n\nCode:\n```text\namq.gen-*\n```\n\n```text\nqueue.declare\n```\n\n```text\ndomain.queue-name\n```\n\n```js\nconst deleteRabbitMQQueues = async (rabbitMQHost, username, password) => {\n try {\n // Encode credentials for Basic Auth\n const auth = Buffer.from(`${username}:${password}`).toString(\"base64\");\n \n // Get the list of all queues\n const response = await axios.get(`https://${rabbitMQHost}/api/queues`, {\n headers: {\n Authorization: `Basic ${auth}`,\n },\n });\n \n const queues = response.data;\n \n console.log(`Found total queues : ${queues.length}`);\n // Filter queues that start with 'amq.gen--'\n const queuesToDelete = queues.filter((queue) =>\n queue.name.startsWith(\"amq.gen-\"),\n );\n \n console.log(`Found queues to delte : ${queuesToDelete.length}`);\n for (const queue of queuesToDelete) {\n try {\n console.log(`Deleting queue: ${queue.name}`);\n \n // Delete the queue\n await axios.delete(\n `https://${rabbitMQHost}/api/queues/%2F/${encodeURIComponent(queue.name)}`,\n {\n headers: {\n Authorization: `Basic ${auth}`,\n },\n },\n );\n } catch (error) {\n console.error(`Failed to delete queue: ${queue.name}`, error);\n }\n }\n } catch (error) {\n console.error(\"Error fetching or deleting queues:\", error);\n }\n };\n```\n\n========================================\n\nComments:\n- The question asker wants to know why these auto-named queues are created when the system is using real queue names. I would also like to know since I have the same scenario.\n- @JamesK as it written in the original answer, when user creates queue with empty name, RabbitMQ generate that name by itself and place `amqp.gen-` as it prefix to denote that queue name is auto-generated. Please, links in the answer above and search there for \"generated\" and for \"amq.\" to get more context of that, hope, it will help.\n- PS: such queues could be exclusive or have auto-delete, queues that supposed to be short-living and about to be deleted right after they did their job. In such cases it doesn't make sense to name them and user may or have to (depends on specific use case) rely on server naming logic.\n- 100% correct - I found that the reply queues in the code were created with no name because they don’t require one. Always wanted to know where these auto-named queues came from, and this answer helped me a lot because it is spot on. Thanks.","metadata":{"transformedAt":"2026-08-18T18:33:20.137Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":83,"estimatedTokens":919}}211{"id":"stack-39122247","source":"stackoverflow","questionId":39122247,"title":"Why do you need a message queue for a chat with web sockets?","tags":["socket.io","rabbitmq","message-queue"],"text":"Title: Why do you need a message queue for a chat with web sockets?\nTags: socket.io, rabbitmq, message-queue\nSource: Stack Overflow\n\nQuestion:\nI have seen a lot of examples on the internet of chats using web sockets and RabbitMQ (https://github.com/videlalvaro/rabbitmq-chat), however I do not understand why it is need it a message queue for a chat application. \n\nWhy it is not ok to send the message from the browser via web sockets to the server and then the server to broadcast that message to the rest of active browsers using again web sockets with broadcast method? (maybe I am missing something)\n\nPseudo code examples (using socket.io):\n\n```\n// client (browser)\nsocket.emit(\"message\",\"my great message that will be received by all\"\n\n// server (any server can be, but let's just say that it is also written in JavaScript\nsocket.on(\"message\", function(msg) {\n socket.broadcast.emit(data);\n});\n\n// the rest of the browsers\nsocket.on(\"message\", function(msg) {\n // display on the screen the message \n});\n```\n\n========================================\n\nTop Answer:\nSimple answer ...\n\nFor a simple chat app you don't need a queue (e.g. signalr would do exactly this without the queue).\n\nTypically though real world applications are not just \"a simple chat app\", the queue might represent the current state of the room for new users joining perhaps, so the server knows what list of messages to serve up when that happens.\n\nAlso it's worth noting that message queues are often implemented when you want reliable messaging (e.g. Service bus) to ensure that all messages definitely get to where they should go even if the first attempt fails. So it's likely that the queue is included in many examples as a default primer in to later problem solving.\n\n========================================\n\nCode:\n```text\n// client (browser)\nsocket.emit(\"message\",\"my great message that will be received by all\"\n\n\n// server (any server can be, but let's just say that it is also written in JavaScript\nsocket.on(\"message\", function(msg) {\n socket.broadcast.emit(data);\n});\n\n// the rest of the browsers\nsocket.on(\"message\", function(msg) {\n // display on the screen the message \n});\n```\n\n```text\nexchange\n```\n\n```text\nqueue\n```\n\n========================================\n\nComments:\n- basically RabbitMQ helps in a real time application due to the fact that the main server which received the request can send it to the RMQ and then RMQ can send it to multiple parties. And the optimization is the fact that the main server is going to do just one request to RMQ and then is free to accept other clients. (in this way he is not responsible with updating all the parties) Is this correct?","metadata":{"transformedAt":"2026-08-18T18:33:20.138Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":68,"estimatedTokens":668}}212{"id":"stack-10939545","source":"stackoverflow","questionId":10939545,"title":"RabbitMQ management web console doesn't show queues or exchanges","tags":["rabbitmq"],"text":"Title: RabbitMQ management web console doesn't show queues or exchanges\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI've got rabbitmq 2.8.2 set up with the web management interface running. The Queues and Exchanges show no data.\n\nrabbitmqctl list_queues works and shows my queues.\n\nI've done rabbitmqctl stop_app, start_app.. and also service rabbitmq-server restart.\n\nAny idea how to get the queue & exchange details to populate?\n\n========================================\n\nTop Answer:\nRabbitmq users only have permission to view the queues that they created by default. Also if you want the user to have access to the management console you need to grant the right privileges.\n\nTo solve this problem I ran:\n\n```\nrabbitmqctl set_user_tags management\n```\n\nThere is more information on setting up the correct permissions for accessing the management console on RabbitMQs website: https://www.rabbitmq.com/management.html\n\n========================================\n\nCode:\n```text\nrabbitmqctl set_user_tags <user> management\n```\n\n========================================\n\nComments:\n- This was a life saver... quick and useful :)\n- Hey This fixed my initial issue, so thank you! but now it doesn't accurately show the Queues I have, for example when in my console it shows 10 Queues but in the RabbitMQ manager it only shows the Queues I hvae manually created","metadata":{"transformedAt":"2026-08-18T18:33:20.138Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":38,"estimatedTokens":340}}213{"id":"stack-5075694","source":"stackoverflow","questionId":5075694,"title":"RabbitMQ - upgraded to a new version and got a lot of \"PRECONDITION_FAILED unknown delivery tag 1\"","tags":["rabbitmq"],"text":"Title: RabbitMQ - upgraded to a new version and got a lot of \"PRECONDITION_FAILED unknown delivery tag 1\"\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nJust upgraded to a new version of RabbitMQ -- 2.3.1 -- and now the following error occurs:\n\n```\nPRECONDITION_FAILED unknown delivery tag 1\n```\n\n...followed by the channel closing. This worked on an older RabbitMQ with no client-side changes.\n\nIn terms of application behavior:\n\nWhen App A wants to send an async message to App b and receive an answer from B, this is the algorithm: \n\n- App A generate a unique ID and puts it in the message object\n\n- Then App A subscribes to a new Queue with both the queue name and routing key equals to the uuid.\n\n- App B open the message, do some calculations and return the result to the channel with the routkey that it recieved.\n\n- App A gets the answer and close the queue.\n\nSo far everything went really well in 1.7.0. what went wrong in 2.3.1? \n\nWhen Application A calls `basicPublish()`, application B immediately throws the following exception:\n\n```\ncom.rabbitmq.client.ShutdownSignalException: channel error; reason: {#method(reply-code=406,reply-text=PRECONDITION_FAILED - unknown delivery tag 1,class-id=60,method-id=80),null,\"\"}\n at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:191)\n at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:159)\n at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:110)\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:438)\nCaused by: com.rabbitmq.client.ShutdownSignalException: channel error; reason: {#method(reply-code=406,reply-text=PRECONDITION_FAILED - unknown delivery tag 1,class-id=60,method-id=80),null,\"\"}\n```\n\n========================================\n\nTop Answer:\nJust set `noAck: false` on `BasicConsume` method\n\n========================================\n\nCode:\n```text\nPRECONDITION_FAILED unknown delivery tag 1\n```\n\n```text\ncom.rabbitmq.client.ShutdownSignalException: channel error; reason: {#method<channel.close>(reply-code=406,reply-text=PRECONDITION_FAILED - unknown delivery tag 1,class-id=60,method-id=80),null,\"\"}\n at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:191)\n at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:159)\n at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:110)\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:438)\nCaused by: com.rabbitmq.client.ShutdownSignalException: channel error; reason: {#method<channel.close>(reply-code=406,reply-text=PRECONDITION_FAILED - unknown delivery tag 1,class-id=60,method-id=80),null,\"\"}\n```\n\n```text\nbasicPublish()\n```\n\n```text\nnoAck: false\n```\n\n```text\nBasicConsume\n```\n\n========================================\n\nComments:\n- Not really. But \"unknown delivery tag\" seems to indicate that you issue a command on the channel that references a delivery tag not generated earlier. Maybe this assertion is new (check the rabbitmq source)? You should probably try to reproduce this issue with the minimal amount of code and it here.\n- I added the following in @Bean SimpleRabbitListenerContainerFactory: factory.setAcknowledgeMode(AcknowledgeMode.MANUAL);\n- I followed your advice and got an answer from Matthias from rabbitMQ - I will publish his answer here : I should have ack'ed messages . therfore subscribe to a channel with ack=true --> channel.basicConsume(queueName, true, queueingConsumer); . Thanks.\n- can you post a a more detailed answer please, from your comment didn't fully understand the answer, thanks.","metadata":{"transformedAt":"2026-08-18T18:33:20.138Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":78,"estimatedTokens":905}}214{"id":"stack-7831407","source":"stackoverflow","questionId":7831407,"title":"how to install php amqp in ubuntu","tags":["php","rabbitmq","ubuntu-10.04"],"text":"Title: how to install php amqp in ubuntu\nTags: php, rabbitmq, ubuntu-10.04\nSource: Stack Overflow\n\nQuestion:\nI am try to install amqp for php (Integrating PHP with RabbitMQ)\nusing this http://code.google.com/p/php-amqp/.\n\nafter run \nphpize && ./configure --with-amqp && make && sudo make install \n\nit give error like this \n\nCannot find config.m4. \nMake sure that you run '/usr/bin/phpize' in the top level source directory of the module\n\nPlease help me, my environment is ubuntu\n\n========================================\n\nTop Answer:\nLet's make life easier, we have tow options:\n\n- If you're using Debian, you can easily install the AMQP extension for PHP with the following command (adjust the PHP version to match your setup):\n\n```\nsudo apt install php7.4-amqp\n```\n\nThis command not only installs the extension but also takes care of enabling it in your php.ini configuration file. \n\n- Another option is to install the extension via PECL using this command:\n\n```\npecl install amqp\n```\n\nAfter a successful installation, make sure to add the following line to your php.ini configuration file (be sure to provide the full path to the extension): `extension = amqp.so`\n\nThis allows PHP to recognize and load the AMQP extension.\n\n========================================\n\nCode:\n```text\nwget http://pecl.php.net/get/amqp -O amqp.tar.gz\ntar -zxvf amqp.tar.gz\ncd amqp-1.0.7 # replace this with the current version\nphpize\n./configure --with-amqp\nmake\nsudo make install\n```\n\n```text\nextension=amqp.so\n```\n\n```text\ncd\n```\n\n```text\nphp.ini\n```\n\n```text\nsudo apt-get install php5-dev\n```\n\n```text\nsudo apt install php7.4-amqp\n```\n\n```text\npecl install amqp\n```\n\n```text\nextension = amqp.so\n```\n\n```text\nsudo apt install php-amqp -y\n```\n\n========================================\n\nComments:\n- Actually I've spent a whole day trying to install the extension in my production machine and I still didn't manage to install it. Why aren't there precompiled downloads of the extension for the most popular distros? It's absurd that I have to install a bunch of development tools in the production server just to be able to install one library. Now I'm stuck.\n- `php5-dev` would install other things which you do not want to have on a production machine.\n- Could you @robbrit Werlich please accept my answer if you think it solved your problem or was the most helpful in finding your solution. Thank you. Cheers!\n- `php7.4-amqp` for relevant versions etc","metadata":{"transformedAt":"2026-08-18T18:33:20.138Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":93,"estimatedTokens":610}}215{"id":"stack-52807913","source":"stackoverflow","questionId":52807913,"title":"What does CTL in rabbitmqctl stand for?","tags":["rabbitmq"],"text":"Title: What does CTL in rabbitmqctl stand for?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nIn the docs it refers to it as the `command line tool` but that's `clt` not `ctl`.\n\n========================================\n\nCode:\n```text\ncommand line tool\n```\n\n```text\nclt\n```\n\n```text\nctl\n```\n\n```text\nRabbitMQCtl\n```\n\n```text\nctl\n```\n\n```text\ncontrol\n```\n\n========================================\n\nComments:\n- Here ctl stands for \"Control\", because you use it to *control* RabbitMQ.\n- Oh Thank you. Why the hell this didn't came to my mind.","metadata":{"transformedAt":"2026-08-18T18:33:20.138Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":39,"estimatedTokens":135}}216{"id":"stack-20184755","source":"stackoverflow","questionId":20184755,"title":"Practical examples of how correlation id is used in messaging?","tags":["rabbitmq","message-queue","nservicebus","amqp","cqrs"],"text":"Title: Practical examples of how correlation id is used in messaging?\nTags: rabbitmq, message-queue, nservicebus, amqp, cqrs\nSource: Stack Overflow\n\nQuestion:\nCan anyone give me examples of how in production a correlation id can be used?\n\nI have read it is used in request/response type messages but I don't understand where I would use it?\n\nOne example (which maybe wrong) I can think off is in a publish subscribe scenario where I could have 5 subscribers and if I get 5 replies with the same correlation id then I could say all my subscribers have received it. Not sure if this would the be correct usage of it.\n\nOr if I send a simple message, the I can use the correlation to guarantee that the client received it.\n\nAny other examples?\n\n========================================\n\nTop Answer:\nIn the context of CQRS and EventSourcing a command message correlation id will most likely get stored togehter with the corresponding events from the domain. This information can later be used to form an audit trail.\n\n========================================\n\nComments:\n- Have you seen rabbitmq.com/tutorials/tutorial-six-java.html? It has pretty nice explanation about `correlation_id`.\n- Here Correlation and Conversations you can see the pattern details. HTH\n- Thanks for the replies. Now I am get the gist of a correlation id, what about real life examples where the correlation id has been used?\n- can you give more concrete example of what to pass on correlationId? Thanks","metadata":{"transformedAt":"2026-08-18T18:33:20.138Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":27,"estimatedTokens":369}}217{"id":"stack-41636566","source":"stackoverflow","questionId":41636566,"title":"Inter-communication microservices - How?","tags":["node.js","web-services","rest","rabbitmq","microservices"],"text":"Title: Inter-communication microservices - How?\nTags: node.js, web-services, rest, rabbitmq, microservices\nSource: Stack Overflow\n\nQuestion:\nI'm working on a personnal project which is to transform a monolithic web application into microservices (each service has its own database).\n\nAt this moment the monolithic backend is made with NodeJS and is able to reply REST request. \nWhen I began to split the application into multiple services I faced the next problem : How to make the communication between them nicely ?\n\nFirst I tried to use **REST call** with the next example : \n\"Register Service\" inserts interesting things into its database, then forward (HTTP POST) the user information to the \"User Service\" in order to persist it into the \"user\" database.\nFrom this example we have 2 services thus 2 databases.\n\nI realized at this moment **it wasn't a good choice**. Because my \"Register Service\" depends on \"User service\". They are kind of coupled and this is an anti-pattern of the microservices conception ( from what I read about ).\n\nThe second idea was to use a **message broker** like RabbitMQ. \"Register Service\" still insert interesting things into its own database and publish a message in a queue with the user information as data. \"User Service\" consumes this message and persists data into its \"user\" database. By using this conception, both of the services are fully isolated and could be a great idea.\n\nBUT, **how about the response to send to the client** ( who made the request to \"Register Service\"). With the first idea we could send \"200, everything's ok !\" or 400. It is not a problem. With the second idea, we don't know if the consumer (\"User Service\") persisted the user data, so what do I need to reply to the client ?\n\nI have the same problem with the shop side of the web application. The client post the product he wants to buy to \"Order Service\". This one needs to check the virtual money he has into \"User Service\" then forward the product detail to \"Deliver Service\" if the user has enough money. How to do that with fully isolated services ? \n\nI don't want to use the http request time from the client to make async request/reply on the message broker. \n\nI hope some of you will enlighten me.\n\n========================================\n\nTop Answer:\nUse cote, it rocks! seriously.\nhttps://github.com/dashersw/cote\n\nin time-service.js...\n\n```\nconst cote = require('cote');\nconst timeService = new cote.Responder({ name: 'Time Service' });\n\ntimeService.on('time', (req, cb) => {\n cb(new Date());\n});\n```\n\nin client.js...\n\n```\nconst cote = require('cote');\nconst client = new cote.Requester({ name: 'Client' });\n\nclient.send({ type: 'time' }, (time) => {\n console.log(time);\n});\n```\n\n========================================\n\nCode:\n```text\nconst cote = require('cote');\nconst timeService = new cote.Responder({ name: 'Time Service' });\n\ntimeService.on('time', (req, cb) => {\n cb(new Date());\n});\n```\n\n```text\nconst cote = require('cote');\nconst client = new cote.Requester({ name: 'Client' });\n\nclient.send({ type: 'time' }, (time) => {\n console.log(time);\n});\n```\n\n========================================\n\nComments:\n- Read this: stackoverflow.com/questions/30213456/…\n- Bring them together? then let's bring everything together into Monolithic again...\n- there could be many apps running on Cote, so how my Requester and Responder will be unique I mean how is it's gonna not be accessible to the outer world? and can I use that between the two backend services?","metadata":{"transformedAt":"2026-08-18T18:33:20.138Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":81,"estimatedTokens":877}}218{"id":"stack-18531308","source":"stackoverflow","questionId":18531308,"title":"RabbitMQ: How to specify the queue to publish to?","tags":["java","rabbitmq","messaging","publish-subscribe","channel"],"text":"Title: RabbitMQ: How to specify the queue to publish to?\nTags: java, rabbitmq, messaging, publish-subscribe, channel\nSource: Stack Overflow\n\nQuestion:\nRabbitMQ's `Channel#basicConsume` method gives us the following arguments:\n\n```\nchannel.basicConsume(queueName, autoAck, consumerTag, noLocal,\n exclusive, arguments, callback);\n```\n\nGiving us the ability to tell RabbitMQ exactly which queue we want to consume from.\n\nBut `Channel#basicPublish` has no such equivalency:\n\n```\nchannel.basicPublish(exchangeName, routingKey, mandatory, immediateFlag,\n basicProperties, messageAsBytes);\n```\n\nWhy can't I specify the queue to publish to here?!? **How do I get a `Channel` publishing to, say, a queue named `logging`?** Thanks in advance!\n\n========================================\n\nTop Answer:\nTo expand on @Tien Nguyen's answer, there is a \"cheat\" in RabbitMQ that effectively lets you publish directly to a queue. Each queue is automatically bound to the AMQP default exchange, with the queue's name as the routing key. The default exchange is also known as the \"nameless exchange\" - ie its name is the empty string. So if you publish to the exchange named `\"\"` with routing key equal to your queue's name, the message will go to just that queue. It is going through an exchange as @John said, it's just not one that you need to declare or bind yourself. \n\nI don't have the Java client handy to try this code, but it should work.\n\n```\nchannel.basicPublish(\"\", myQueueName, false, false, null, myMessageAsBytes);\n```\n\nThat said, this is mostly contrary to the spirit of how RabbitMQ works. For normal application flow you should declare and bind exchanges. But for exceptional cases the \"cheat\" can be useful. For example, I believe this is how the Rabbit Admin Console allows you to manually publish messages to a queue without all the ceremony of creating and binding exchanges.\n\n========================================\n\nCode:\n```text\nchannel.basicConsume(queueName, autoAck, consumerTag, noLocal,\n exclusive, arguments, callback);\n```\n\n```text\nchannel.basicPublish(exchangeName, routingKey, mandatory, immediateFlag,\n basicProperties, messageAsBytes);\n```\n\n```text\nChannel#basicConsume\n```\n\n```text\nChannel#basicPublish\n```\n\n```text\nChannel\n```\n\n```text\nlogging\n```\n\n```text\nchannel.queueBind(queueName, exchangeName, \"events\");\n```\n\n```text\nchannel.basicPublish(\"\", yourQueueName, null,\n message.getBytes((Charset.forName(\"UTF-8\"))));\n```\n\n```text\nchannel.basicPublish(\"\", myQueueName, false, false, null, myMessageAsBytes);\n```\n\n```text\n\"\"\n```\n\n========================================\n\nComments:\n- What you want to do can be done with exclusive queue, with direct exchange and known queue name and somehow with specific route key + topic exchange.\n- Thanks @tien nguyen (+1) - However, it looks like you are using the `basicPublish(java.lang.String exchange, java.lang.String routingKey, AMQP.BasicProperties props, byte[] body)` overload of `basicPublish`. In that overload, the 2nd parameter (which you have as \"yourQueueName\" is called \"routingKey\". So, is \"routingKey\" RabbitMQ lingo for \"queue name\"?\n- @TicketMonster routingKey doesn't mean queue. A queue will be bound to an exchange based on routingKey and only will receive only messages which have that routingKey. see my answer.\n- in a bit more detail the message is sent to the default exchange so the routing key will in effect send to the queue. But no they are not equivalent\n- Awesome @John (+1 and green check) - thanks for the helpful, thorough and informative answer!\n- Will this cheat work even if the queue is also bound to an exchange?\n- Yes, it will, we have code that does this to queues that are bound to other exchanges.\n- Amazing. Exactly what I needed for automated testing. thank you\n- This is also handy in a number of other scenarios outside of testing including local work queues and 'restoration' of messages, etc.","metadata":{"transformedAt":"2026-08-18T18:33:20.138Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":94,"estimatedTokens":978}}219{"id":"stack-13861459","source":"stackoverflow","questionId":13861459,"title":"RabbitMQ wait for multiple queues to finish","tags":["php","symfony","queue","rabbitmq","messaging"],"text":"Title: RabbitMQ wait for multiple queues to finish\nTags: php, symfony, queue, rabbitmq, messaging\nSource: Stack Overflow\n\nQuestion:\nOk here is an overview of what's going on:\n\n```\nM So I have an exchange that pushes to multiple queues, each queue has a task, once all tasks are completed, only then can Queue 4 start.\n\nSo message with unique id of 1234 gets sent to the exchange, the exchange routes it to all the task queues ( Q1, Q2, Q3, etc... ), when all the tasks for message id 1234 have completed, run Q4 for message id 1234.\n\nHow can I implement this?\n\nUsing Symfony2, RabbitMQBundle and RabbitMQ 3.x\n\nResources:\n\n- http://www.rabbitmq.com/tutorials/amqp-concepts.html\n\n- http://www.rabbitmq.com/tutorials/tutorial-six-python.html\n\nUPDATE #1\n\nOk I think this is what I'm looking for:\n\n- https://github.com/videlalvaro/Thumper/tree/master/examples/parallel_processing\n\nRPC with Parallel Processing, but how do I set the Correlation Id to be my unique id to group the messages and also identify what queue?\n\n========================================\n\nTop Answer:\nYou need to implement this: http://www.eaipatterns.com/Aggregator.html but the RabbitMQBundle for Symfony doesn't support that so you would have to use the underlying php-amqplib.\n\nA normal consumer callback from the bundle will get an AMQPMessage. From there you can access the channel and manually publish to whatever exchanges comes next in your \"pipes and filters\" implementation\n\n========================================\n\nCode:\n```text\nM <-- Message with unique id of 1234\n |\n +-Start Queue\n |\n |\n | <-- Exchange\n /|\\\n / | \\\n / | \\ <-- bind to multiple queues\nQ1 Q2 Q3\n\\ | / <-- start of the problem is here\n \\ | / \n \\ | /\n \\|/\n |\n Q4 <-- Queues 1,2 and 3 must finish first before Queue 4 can start\n |\n C <-- Consumer\n```\n\n```text\n// Client\nbyte[] body = new byte[size];\nbody[0] = uniqueUserId;\nbody[1] = howManyWorkItems;\nbody[2] = command;\n\n// Setup your body here\n\nQueue(body)\n```\n\n```text\n// Server\n// Process queue 1, 2, 3\nDequeue(message)\n\nswitch(message.body[2])\n{\n // process however you see fit\n}\n\nprocessedMessages[message.body[0]]++;\n\nif(processedMessages[message.body[0]] == message.body[1])\n{\n // Send to queue 4\n Queue(newMessage)\n}\n```\n\n```text\npublic function call($uniqueUserId, $workItem) {\n $this->response = null;\n $this->corr_id = uniqid();\n\n $msg = new AMQPMessage(\n serialize(array($uniqueUserId, $workItem)),\n array('correlation_id' => $this->corr_id,\n 'reply_to' => $this->callback_queue)\n );\n\n $this->channel->basic_publish($msg, '', 'rpc_queue');\n while(!$this->response) {\n $this->channel->wait();\n }\n\n // We assume that in the response we will get our id back\n return deserialize($this->response);\n }\n\n\n$rpc = new Rpc();\n\n// Get unique user information and work items here\n\n// Pass even more information in here, like what queue to use or you could even loop over this to send all the work items to the queues they need.\n$response = rpc->call($uniqueUserId, $workItem);\n\n$responseBuckets[array[0]]++;\n\n// Just like above code that sees if a bucket is full or not\n```\n\n```text\n// app/config/config.yml\n\nenqueue:\n transport:\n default: 'amnqp://'\n client: ~\n```\n\n```text\n<?php\nuse Enqueue\\Client\\ProducerInterface;\nuse Symfony\\Component\\DependencyInjection\\ContainerInterface;\n\n/** @var ContainerInterface $container */\n\n/** @var ProducerInterface $producer */\n$producer = $container->get('enqueue.client.producer');\n\n$promises = new SplObjectStorage();\n\n$promises->attach($producer->sendCommand('task1', 'the task data', true));\n$promises->attach($producer->sendCommand('task2', 'the task data', true));\n$promises->attach($producer->sendCommand('task3', 'the task data', true));\n\nwhile (count($promises)) {\n foreach ($promises as $promise) {\n if ($replyMessage = $promise->receiveNoWait()) {\n // you may want to check the response here\n $promises->detach($promise);\n }\n }\n}\n\n$producer->sendCommand('task4', 'the task data');\n```\n\n```text\nuse Enqueue\\Client\\CommandSubscriberInterface;\nuse Enqueue\\Consumption\\Result;\nuse Enqueue\\Psr\\PsrContext;\nuse Enqueue\\Psr\\PsrMessage;\nuse Enqueue\\Psr\\PsrProcessor;\n\nclass Task1Processor implements PsrProcessor, CommandSubscriberInterface\n{\n public function process(PsrMessage $message, PsrContext $context)\n {\n // do task job\n\n return Result::reply($context->createMessage('the reply data'));\n }\n\n public static function getSubscribedCommand()\n {\n // you can simply return 'task1'; if you do not need a custom queue, and you are fine to use what enqueue chooses. \n\n return [\n 'processorName' => 'task1',\n 'queueName' => 'Q1',\n 'queueNameHardcoded' => true,\n 'exclusive' => true,\n ];\n }\n}\n```\n\n```text\nenqueue.client.processor\n```\n\n```text\nbin/console enqueue:consume --setup-broker -vvv\n```\n\n```text\n<?php\nuse Enqueue\\Client\\Message;\nuse Enqueue\\Client\\ProducerInterface;\nuse Enqueue\\Util\\UUID;\nuse Symfony\\Component\\DependencyInjection\\ContainerInterface;\n\n/** @var ContainerInterface $container */\n\n/** @var ProducerInterface $producer */\n$producer = $container->get('enqueue.client.producer');\n\n$message = new Message('the task data');\n$message->setCorrelationId(UUID::generate());\n\n$producer->sendCommand('task1', clone $message);\n$producer->sendCommand('task2', clone $message);\n$producer->sendCommand('task3', clone $message);\n```\n\n```text\n<?php\nuse Enqueue\\Client\\CommandSubscriberInterface;\nuse Enqueue\\Client\\Message;\nuse Enqueue\\Client\\ProducerInterface;\nuse Enqueue\\Psr\\PsrContext;\nuse Enqueue\\Psr\\PsrMessage;\nuse Enqueue\\Psr\\PsrProcessor;\n\nclass Task1Processor implements PsrProcessor, CommandSubscriberInterface\n{\n private $producer;\n\n public function __construct(ProducerInterface $producer)\n {\n $this->producer = $producer;\n }\n\n public function process(PsrMessage $message, PsrContext $context)\n {\n // do the job\n\n // same for other\n $eventMessage = new Message('the event data');\n $eventMessage->setCorrelationId($message->getCorrelationId());\n\n $this->producer->sendEvent('task_is_done', $eventMessage);\n\n return self::ACK;\n }\n\n public static function getSubscribedCommand()\n {\n return 'task1';\n }\n}\n```\n\n```text\n<?php\n\nuse Enqueue\\Client\\TopicSubscriberInterface;\nuse Enqueue\\Psr\\PsrContext;\nuse Enqueue\\Psr\\PsrMessage;\nuse Enqueue\\Psr\\PsrProcessor;\nuse Symfony\\Component\\Filesystem\\LockHandler;\n\nclass AggregatorProcessor implements PsrProcessor, TopicSubscriberInterface\n{\n private $producer;\n private $rootDir;\n\n /**\n * @param ProducerInterface $producer\n * @param string $rootDir\n */\n public function __construct(ProducerInterface $producer, $rootDir)\n {\n $this->producer = $producer;\n $this->rootDir = $rootDir;\n }\n\n public function process(PsrMessage $message, PsrContext $context)\n {\n $expectedNumberOfTasks = 3;\n\n if (false == $cId = $message->getCorrelationId()) {\n return self::REJECT;\n }\n\n try {\n $lockHandler = new LockHandler($cId, $this->rootDir.'/var/tasks');\n $lockHandler->lock(true);\n\n $currentNumberOfProcessedTasks = 0;\n if (file_exists($this->rootDir.'/var/tasks/'.$cId)) {\n $currentNumberOfProcessedTasks = file_get_contents($this->rootDir.'/var/tasks/'.$cId);\n\n if ($currentNumberOfProcessedTasks +1 == $expectedNumberOfTasks) {\n unlink($this->rootDir.'/var/tasks/'.$cId);\n\n $this->producer->sendCommand('task4', 'the task data');\n\n return self::ACK;\n }\n }\n\n file_put_contents($this->rootDir.'/var/tasks/'.$cId, ++$currentNumberOfProcessedTasks);\n\n return self::ACK;\n } finally {\n $lockHandler->release();\n }\n }\n\n public static function getSubscribedTopics()\n {\n return 'task_is_done';\n }\n}\n```\n\n========================================\n\nComments:\n- So, if I'm understanding correctly, you have a 4th queue that can only start to be processed when 3 other queues are empty? If you are processing a lot of things in parallel, won't your 3 queues always be passing information?\n- yes as the queues will always have new messages, forgot to mention that all the data in each queue is related by a unique id. so the exchange sends the unique id 1234 to Q1, Q2 and Q3. Each queue performs a different task. In Q4 I need to know when then messages with the unique id of 1234 in Q1, Q2 and Q3 are finished before I can process the message in Q4. Updated my question\n- Sure, could you point me to some documentation on this? How do I know when all the messages ( for a given unique id ) are cleared from all the queues?\n- what do you mean by unique id? topic? you can check if a queue is empty using the channel interface\n- I have updated my question, I think I'm looking for RPC with Parallel Processing, +1 for your efforts. Any chance you could look at my question again?\n- @PhillPafford I don't see your +1 for efforts ;)\n- Could you explain a little more? I understand the RPC part but you're saying add the RPC to Q1, Q2 and Q3?\n- Instead of using the id for an RPC, use it to group messages for the process sitting in front of your 4th queue. You probably don't even need to use that id. You could probably embed a user id into the body of your message.\n- What do you mean by 'Group Messages'? I think I'm getting the concept but need a little more details\n- I tried to write a simple example in my questions. Of course there is a lot to be filled in, but I think it shows the route I would try to take?\n- I have updated my question, I think I'm looking for RPC with Parallel Processing. Would you mind looking at it again? +1 for the efforts","metadata":{"transformedAt":"2026-08-18T18:33:20.138Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":336,"estimatedTokens":2504}}220{"id":"stack-50176793","source":"stackoverflow","questionId":50176793,"title":"Automate RabbitMQ consumer testing","tags":["rabbitmq","integration-testing","microservices"],"text":"Title: Automate RabbitMQ consumer testing\nTags: rabbitmq, integration-testing, microservices\nSource: Stack Overflow\n\nQuestion:\nI have a .net micro-service receiving messages using RabbitMQ client, I need to test the following:\n\n1- consumer is successfully connected to rabbitMq host.\n\n2- consumer is listening to queue.\n\n3- consumer is receiving messages successfully.\n\nTo achieve the above, I have created a sample application that sends messages and I am debugging consumer to be sure that it is receiving messages.\n\nHow can I automate this test? hence include it in my micro-service CI.\n\nI am thinking to include my sample app in my CI so I can fire a message then run a consumer unit test that waits a specific time then passes if the message received, but this seems like a wrong practice to me because the test will not start until a few seconds the message is fired.\n\nAnother way I am thinking of is firing the sample application from the unit test itself, but if the sample app fails to work that would make it the service fault.\n\nIs there any best practices for integration testing of micro-services connecting through RabbitMQ?\n\n========================================\n\nTop Answer:\nI was successfully doing such kind of test. You need test instance of RabbitMQ, test exchange to send messages to and test queue to connect to receive messages.\n\n**Do not mock everything!**\n\nBut, with test consumer, producer and test instance of rabbitMQ there is no actual production code in that test.\n\n**use test rabbitMQ instance and real aplication**\n\nIn order to have meaniningfull test I would use test RabbitMQ instance, exchange and queue, but leave real application (producer and consumer).\n\nI would implement following scenario\n\nwhen test application does something that test message to rabbitMQ\n\nthen number of received messages in rabbitMQ is increased then\n\napplication does something that it should do upon receiving messages\n\nSteps 1 and 3 are application-specific. Your application sends messages to rabbitMQ based on some external event (HTTP message received? timer event?). You could reproduce such condition in your test, so application will send message (to test rabbitMQ instance).\n\nSame story for verifying application action upon receiving message. Application should do something observable upon receiving messages.\nIf application makes HTTP call- then you can mock that HTTP endpoint and verify received messages. If application saves messages to the database- you could pool database to look for your message.\n\n**use rabbitMQ monitoring API**\n\nStep 2 can be implemented using RabbitMQ monitoring API (there are methods to see number of messages received and consumed from queue https://www.rabbitmq.com/monitoring.html#rabbitmq-metrics)\n\n**consider using spring boot to have health checks**\n\nIf you are java-based and then using Spring Boot will significantly simpify your problem. You will automatically get health check for your rabbitMQ connection!\n\nSee https://spring.io/guides/gs/messaging-rabbitmq/ for tutorial how to connect to RabbitMQ using Spring boot.\nSpring boot application exposes health information (using HTTP endpoint /health) for every attached external resource (database, messaging, jms, etc)\nSee https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html#_auto_configured_healthindicators for details.\n\nIf connection to rabbitMQ is down then health check (done by org.springframework.boot.actuate.amqp.RabbitHealthIndicator) will return HTTP code 4xx and meaninfull json message in JSON body.\n\nYou do not have to do anything particular to have that health check- just using org.springframework.boot:spring-boot-starter-amqp as maven/gradle dependency is enough.\n\n**CI test- from src/test directory**\n\nI have written such test (that connect to external test instance of RabbitMQ) using integration tests, in src/test directory. If using Spring Boot it is easiest to do that using test profile, and having details of connection to test RabbitMQ instance in application-test.properties (production could use production profile, and application-production.properties file with production instance of RabbitMQ).\n\nIn simplest case (just verify connection to rabbitMQ) all you need is to start application normally and validate /health endpoint.\n\nIn this case I would do following CI steps\n\n- one that builds (gradle build)\n\n- one that run unit tests (tests without any external dependenices)\n\n- one that run integration tests\n\n**CI test- external**\n\nAbove described approach could also be done for application deployed to test environment (and connected to test rabbitMQ instance). As soon as application starts, you can check /health endpoint to make sure it is connected to rabbitMQ instance.\n\nIf you make your application send message to rabbitMQ, then you could observe rabbbitMQ metrics (using rabbitMQ monitoring API) and observe external effects of message being consumed by application.\n\nFor such test you need to start and deploy your application from CI befor starting tests.\n\nfor that scenario I would do following CI steps\n\n- step that that builds app\n\n- steps that run all tests in src/test directory (unit, integration)\n\n- step that deploys app to test environment, or starts dockerized application\n\n- step that runs external tests\n\n- for dockerized environment, step that stops docker containers\n\n**Consider dockerized enevironment**\n\nFor external test you could run your application along with test RabbitMQ instance in Docker. You will need two docker containers.\n\n- one with application\n\n- one with rabbitMQ . There is official docker image for rabbitmq https://hub.docker.com/_/rabbitmq/ and it is really easy to use\n\nTo run those two images, it is most reasonable to write docker-compose file.\n\n========================================\n\nCode:\n```cs\npublic class QueueDestroyer\n{\n public static void DeleteQueue(string queueName, string virtualHost)\n {\n var connectionFactory = new ConnectionFactory();\n connectionFactory.HostName = \"localhost\";\n connectionFactory.UserName = \"guest\";\n connectionFactory.Password = \"guest\";\n connectionFactory.VirtualHost = virtualHost;\n var connection = connectionFactory.CreateConnection();\n var channel = connection.CreateModel();\n channel.QueueDelete(queueName);\n connection.Close();\n }\n}\n```\n\n```cs\npublic class Consumer\n{\n private IMessageProcessor _messageProcessor;\n private Task _consumerTask;\n\n public Consumer(IMessageProcessor messageProcessor)\n {\n _messageProcessor = messageProcessor;\n }\n\n public void Consume(CancellationToken token, string queueName)\n {\n _consumerTask = Task.Run(() =>\n {\n var factory = new ConnectionFactory() { HostName = \"localhost\" };\n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(queue: queueName,\n durable: false,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n\n var consumer = new EventingBasicConsumer(channel);\n consumer.Received += (model, ea) =>\n {\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n _messageProcessor.ProcessMessage(message);\n };\n channel.BasicConsume(queue: queueName,\n autoAck: false,\n consumer: consumer);\n\n while (!token.IsCancellationRequested)\n Thread.Sleep(1000);\n }\n }\n });\n }\n\n public void WaitForCompletion()\n {\n _consumerTask.Wait();\n }\n}\n```\n\n```cs\npublic class TestPublisher\n{\n public void Publish(string queueName, string message)\n {\n var factory = new ConnectionFactory() { HostName = \"localhost\", UserName=\"guest\", Password=\"guest\" };\n using (var connection = factory.CreateConnection())\n using (var channel = connection.CreateModel())\n {\n var body = Encoding.UTF8.GetBytes(message);\n\n channel.BasicPublish(exchange: \"\",\n routingKey: queueName,\n basicProperties: null,\n body: body);\n }\n }\n}\n```\n\n```cs\n[Fact]\npublic void If_SendMessageToQueue_ThenConsumerReceiv4es()\n{\n // ARRANGE\n QueueDestroyer.DeleteQueue(\"queueX\", \"/\");\n var cts = new CancellationTokenSource();\n var fake = new FakeProcessor();\n var myMicroService = new Consumer(fake);\n\n // ACT\n myMicroService.Consume(cts.Token, \"queueX\");\n\n var producer = new TestPublisher();\n producer.Publish(\"queueX\", \"hello\");\n\n Thread.Sleep(1000); // make sure the consumer will have received the message\n cts.Cancel();\n\n // ASSERT\n Assert.Equal(1, fake.Messages.Count);\n Assert.Equal(\"hello\", fake.Messages[0]);\n}\n```\n\n```cs\npublic class FakeProcessor : IMessageProcessor\n{\n public List<string> Messages { get; set; }\n\n public FakeProcessor()\n {\n Messages = new List<string>();\n }\n\n public void ProcessMessage(string message)\n {\n Messages.Add(message);\n }\n}\n```\n\n========================================\n\nComments:\n- @yahya-hussein please consider accepting the ansfer if you find it valuable. thanks!\n- @Vanlightly I am seeking some help on a similar concept in Java, kindly let me know if you or anyone here is able to help\n- I am seeking some help on a similar concept in Java, kindly let me know if you or anyone here is able to help, I have done some research on this and also visited some existing posts. I am unable to yet find a solution My scenario is App A (Web App with MessageSender), App B (the consumer withing the Java framework). I intend to trigger the script based on the incoming message, my message queue working in isolation as a sender to consumer App, I have now split it into 2 Apps A & B respectively where App is an automation framework containing the consumer code also. @Bartosz Bilicki\n- Thank you for the great answer, my question is: is it a good idea to include the publisher in my under test service? will I be simulating a real integration test?\n- The way I see it is that when building micro-services I really don't want to have to run related services while testing my own. Right now it might be one dependent service but in the future it could be many and be hard to manage. Too many dependencies involved, too many ways for my CI to fail. Also I now have to be able to operate another teams service. I consider the messages as contracts so mocking the other services is fine and usually desired. You can also run all services in end-to-end tests on certain milestones in a test environment but for CI I would consider something more stable.\n- @Vanlightly, could you the connection killer class in .NET Core please if you have?\n- Sure. I just converted it from a full framework version. See the ConnectionKillerExample test for how to use it. ConnectionKiller\n- Note that I have since learned that this method of killing the connection doesn't actually kill the connection but forces and safe closing of the connection. If you want to simulate a more realistic loss of the connection you'll need another way of doing it, such as using something like toxiproxy or tcpkill.","metadata":{"transformedAt":"2026-08-18T18:33:20.138Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":254,"estimatedTokens":2924}}221{"id":"stack-37709896","source":"stackoverflow","questionId":37709896,"title":"Where does a BasicReject with requeue actually go?","tags":["rabbitmq"],"text":"Title: Where does a BasicReject with requeue actually go?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nThis seems like a simple question, but I'm having a hard time finding a definitive answer. If in RabbitMQ 3.6.1 I have a queue that looks like this:\n\n```\n5 4 3 2 1 And I consume message 1, then do:\n\n```\nchannel.BasicReject(ea.DeliveryTag, true);\n```\n\nWill the `1` end up on the end of the queue or at the head of the queue (assuming for the sake of simplicity that nobody else is consuming the queue at the time)? So will I end up with:\n\n```\n1 5 4 3 2 or:\n\n```\n5 4 3 2 1 And is there anyway to control it (one way would be to ack the message and repost it entirely I suppose)? I actually want the first situation because I'm rejecting `1` because a particular resource needed to process that message is currently unavailable. So I'd like to throw it back on the queue to be processed later (when the resource is available) or get picked up by somebody else (who has resources available). But I don't want to throw it back just to keep picking it up again.\n\n========================================\n\nTop Answer:\nExplicitly answering for anyone who, like me, came to this question late and needed a non-\"read the docs\" answer:\n\nWhen a message is requeued, it will be placed to its original position in its queue, if possible. If not (due to concurrent deliveries and acknowledgements from other consumers when multiple consumers a queue), the message will be requeued to a position closer to queue head. - From Rabbitmq's official site - rabbitmq.com/nack.html – smc\n\nTo expand on this comment from the (currently) top answer using your example\n\nI have a queue that looks like this:\n\n`5 4 3 2 1 \nAnd I consume message 1\n\nQueue is now: `5 4 3 2 \nthen do: `channel.BasicReject(ea.DeliveryTag, true);`\n\nYour result will be the same as initial,\n\n`5 4 3 2 1 If you have only one consumer. With multiple consumers it may be possible for the following:\n\nInitial: `5 4 3 2 1 Consumer 1 accepts message: `5 4 3 2 Consumer 2 accepts message while consumer 1 is processing: `5 4 3 Consumer 1 decides to reject and requeue, resulting in: `5 4 3 1 <= head`\n\n========================================\n\nCode:\n```text\n5 4 3 2 1 <= head\n```\n\n```text\nchannel.BasicReject(ea.DeliveryTag, true);\n```\n\n```text\n1 5 4 3 2 <= head\n```\n\n```text\n5 4 3 2 1 <= head\n```\n\n```text\n1\n```\n\n```text\n1\n```\n\n```text\n5 4 3 2 1 <= head\n```\n\n```text\n5 4 3 2 <= head\n```\n\n```text\nchannel.BasicReject(ea.DeliveryTag, true);\n```\n\n```text\n5 4 3 2 1 <= head\n```\n\n```text\n5 4 3 2 1 <= head\n```\n\n```text\n5 4 3 2 <= head\n```\n\n```text\n5 4 3 <= head\n```\n\n```text\n5 4 3 1 <= head\n```\n\n========================================\n\nComments:\n- Thanks. Learned something new about the newer way.\n- So it goes to the end then?\n- `When a message is requeued, it will be placed to its original position in its queue, if possible. If not (due to concurrent deliveries and acknowledgements from other consumers when multiple consumers a queue), the message will be requeued to a position closer to queue head.` - From Rabbitmq's official site - rabbitmq.com/nack.html\n- Can you actually *answer* the question? Where does it go? To the head of to the tail of the queue?\n- I don't know why the downvote.. Also @Maggyero don't know what is not clear. Look at the bold part of my answer, especially the words \"publication order\" That means exactly the same thing as in smc's comment after the fist comma, the part \"original position\". So there, I've quoted what was quoted. As you noticed, there was no mentioned of neither \"head\" nor \"tail\". Disclamer for moderators: I wasn't being sarcastic or anything, the comment required further explanation and this is the best one I can give.\n- As you noticed it was not clear not only for me but also for @simPod whom you ignored. The question was \"Will the 1 end up on the end of the queue or at the head of the queue (assuming for the sake of simplicity that nobody else is consuming the queue at the time)?\" And the answer is: the *head* of the queue.","metadata":{"transformedAt":"2026-08-18T18:33:20.138Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":14,"totalLines":113,"estimatedTokens":1021}}222{"id":"stack-28550140","source":"stackoverflow","questionId":28550140,"title":"Python and RabbitMQ - Best way to listen to consume events from multiple channels?","tags":["python","rabbitmq","pika"],"text":"Title: Python and RabbitMQ - Best way to listen to consume events from multiple channels?\nTags: python, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI have two, separate RabbitMQ instances. I'm trying to find the best way to listen to events from both.\n\nFor example, I can consume events on one with the following:\n\n```\ncredentials = pika.PlainCredentials(user, pass)\nconnection = pika.BlockingConnection(pika.ConnectionParameters(host=\"host1\", credentials=credentials))\nchannel = connection.channel()\nresult = channel.queue_declare(Exclusive=True)\nself.channel.queue_bind(exchange=\"my-exchange\", result.method.queue, routing_key='*.*.*.*.*')\nchannel.basic_consume(callback_func, result.method.queue, no_ack=True)\nself.channel.start_consuming()\n```\n\nI have a second host, \"host2\", that I'd like to listen to as well. I thought about creating two separate threads to do this, but from what I've read, pika isn't thread safe. Is there a better way? Or would creating two separate threads, each listening to a different Rabbit instance (host1, and host2) be sufficient?\n\n========================================\n\nTop Answer:\nBelow is an example of how I use one rabbitmq instance to listen to 2 queues at the same time:\n\n```\nimport pika\nimport threading\n\nthreads=[]\ndef client_info(channel): \n channel.queue_declare(queue='proxy-python')\n print (' [*] Waiting for client messages. To exit press CTRL+C')\n\n def callback(ch, method, properties, body):\n print (\" Received %s\" % (body))\n\n channel.basic_consume(callback, queue='proxy-python', no_ack=True)\n channel.start_consuming()\n\ndef scenario_info(channel): \n channel.queue_declare(queue='savi-virnet-python')\n print (' [*] Waiting for scenrio messages. To exit press CTRL+C')\n\n def callback(ch, method, properties, body):\n print (\" Received %s\" % (body))\n\n channel.basic_consume(callback, queue='savi-virnet-python', no_ack=True)\n channel.start_consuming()\n\ndef manager():\n connection1= pika.BlockingConnection(pika.ConnectionParameters\n (host='localhost'))\n channel1 = connection1.channel()\n connection2= pika.BlockingConnection(pika.ConnectionParameters\n (host='localhost'))\n channel2 = connection2.channel()\n t1 = threading.Thread(target=client_info, args=(channel1,))\n t1.daemon = True\n threads.append(t1)\n t1.start() \n\n t2 = threading.Thread(target=scenario_info, args=(channel2,))\n t2.daemon = True\n threads.append(t2)\n\n t2.start()\n for t in threads:\n t.join()\n\n manager()\n```\n\n========================================\n\nCode:\n```text\ncredentials = pika.PlainCredentials(user, pass)\nconnection = pika.BlockingConnection(pika.ConnectionParameters(host=\"host1\", credentials=credentials))\nchannel = connection.channel()\nresult = channel.queue_declare(Exclusive=True)\nself.channel.queue_bind(exchange=\"my-exchange\", result.method.queue, routing_key='*.*.*.*.*')\nchannel.basic_consume(callback_func, result.method.queue, no_ack=True)\nself.channel.start_consuming()\n```\n\n```text\nimport pika\nimport threading\n\n\nclass ConsumerThread(threading.Thread):\n def __init__(self, host, *args, **kwargs):\n super(ConsumerThread, self).__init__(*args, **kwargs)\n\n self._host = host\n\n # Not necessarily a method.\n def callback_func(self, channel, method, properties, body):\n print(\"{} received '{}'\".format(self.name, body))\n\n def run(self):\n credentials = pika.PlainCredentials(\"guest\", \"guest\")\n\n connection = pika.BlockingConnection(\n pika.ConnectionParameters(host=self._host,\n credentials=credentials))\n\n channel = connection.channel()\n\n result = channel.queue_declare(exclusive=True)\n\n channel.queue_bind(result.method.queue,\n exchange=\"my-exchange\",\n routing_key=\"*.*.*.*.*\")\n\n channel.basic_consume(self.callback_func,\n result.method.queue,\n no_ack=True)\n\n channel.start_consuming()\n\n\nif __name__ == \"__main__\":\n threads = [ConsumerThread(\"host1\"), ConsumerThread(\"host2\")]\n for thread in threads:\n thread.start()\n```\n\n```text\nimport pika\nimport sys\n\n\ndef callback_func(channel, method, properties, body):\n print(body)\n\n\nif __name__ == \"__main__\":\n credentials = pika.PlainCredentials(\"guest\", \"guest\")\n\n connection = pika.BlockingConnection(\n pika.ConnectionParameters(host=sys.argv[1],\n credentials=credentials))\n\n channel = connection.channel()\n\n result = channel.queue_declare(exclusive=True)\n\n channel.queue_bind(result.method.queue,\n exchange=\"my-exchange\",\n routing_key=\"*.*.*.*.*\")\n\n channel.basic_consume(callback_func, result.method.queue, no_ack=True)\n\n channel.start_consuming()\n```\n\n```text\n$ python single_consume.py host1\n$ python single_consume.py host2 # e.g. on another console\n```\n\n```text\nfrom pika.adapters.twisted_connection import TwistedProtocolConnection\nfrom pika.connection import ConnectionParameters\nfrom twisted.internet import protocol, reactor, task\nfrom twisted.python import log\n\n\nclass Consumer(object):\n def on_connected(self, connection):\n d = connection.channel()\n d.addCallback(self.got_channel)\n d.addCallback(self.queue_declared)\n d.addCallback(self.queue_bound)\n d.addCallback(self.handle_deliveries)\n d.addErrback(log.err)\n\n def got_channel(self, channel):\n self.channel = channel\n\n return self.channel.queue_declare(exclusive=True)\n\n def queue_declared(self, queue):\n self._queue_name = queue.method.queue\n\n self.channel.queue_bind(queue=self._queue_name,\n exchange=\"my-exchange\",\n routing_key=\"*.*.*.*.*\")\n\n def queue_bound(self, ignored):\n return self.channel.basic_consume(queue=self._queue_name)\n\n def handle_deliveries(self, queue_and_consumer_tag):\n queue, consumer_tag = queue_and_consumer_tag\n self.looping_call = task.LoopingCall(self.consume_from_queue, queue)\n\n return self.looping_call.start(0)\n\n def consume_from_queue(self, queue):\n d = queue.get()\n\n return d.addCallback(lambda result: self.handle_payload(*result))\n\n def handle_payload(self, channel, method, properties, body):\n print(body)\n\n\nif __name__ == \"__main__\":\n consumer1 = Consumer()\n consumer2 = Consumer()\n\n parameters = ConnectionParameters()\n cc = protocol.ClientCreator(reactor,\n TwistedProtocolConnection,\n parameters)\n d1 = cc.connectTCP(\"host1\", 5672)\n d1.addCallback(lambda protocol: protocol.ready)\n d1.addCallback(consumer1.on_connected)\n d1.addErrback(log.err)\n\n d2 = cc.connectTCP(\"host2\", 5672)\n d2.addCallback(lambda protocol: protocol.ready)\n d2.addCallback(consumer2.on_connected)\n d2.addErrback(log.err)\n\n reactor.run()\n```\n\n```text\npika\n```\n\n```text\npika\n```\n\n```text\nthreading\n```\n\n```text\ncallback_func\n```\n\n```text\nConsumerThread.name\n```\n\n```text\nConsumerThread\n```\n\n```text\nTwisted\n```\n\n```text\nBlockingConnection\n```\n\n```text\npika\n```\n\n```text\nTwisted\n```\n\n```text\npika\n```\n\n```text\npika\n```\n\n```text\nasyncio\n```\n\n```text\nasynqp\n```\n\n```text\naioamqp\n```\n\n```text\nimport pika\nimport threading\n\nthreads=[]\ndef client_info(channel): \n channel.queue_declare(queue='proxy-python')\n print (' [*] Waiting for client messages. To exit press CTRL+C')\n\n\n def callback(ch, method, properties, body):\n print (\" Received %s\" % (body))\n\n channel.basic_consume(callback, queue='proxy-python', no_ack=True)\n channel.start_consuming()\n\ndef scenario_info(channel): \n channel.queue_declare(queue='savi-virnet-python')\n print (' [*] Waiting for scenrio messages. To exit press CTRL+C')\n\n\n def callback(ch, method, properties, body):\n print (\" Received %s\" % (body))\n\n channel.basic_consume(callback, queue='savi-virnet-python', no_ack=True)\n channel.start_consuming()\n\ndef manager():\n connection1= pika.BlockingConnection(pika.ConnectionParameters\n (host='localhost'))\n channel1 = connection1.channel()\n connection2= pika.BlockingConnection(pika.ConnectionParameters\n (host='localhost'))\n channel2 = connection2.channel()\n t1 = threading.Thread(target=client_info, args=(channel1,))\n t1.daemon = True\n threads.append(t1)\n t1.start() \n\n t2 = threading.Thread(target=scenario_info, args=(channel2,))\n t2.daemon = True\n threads.append(t2)\n\n\n t2.start()\n for t in threads:\n t.join()\n\n\n manager()\n```\n\n```text\nimport asyncio\nimport tornado.ioloop\nimport tornado.web\n\nfrom aio_pika import connect_robust, Message\n\ntornado.ioloop.IOLoop.configure(\"tornado.platform.asyncio.AsyncIOLoop\")\nio_loop = tornado.ioloop.IOLoop.current()\nasyncio.set_event_loop(io_loop.asyncio_loop)\n\nQUEUE = asyncio.Queue()\n\n\nclass SubscriberHandler(tornado.web.RequestHandler):\n async def get(self):\n message = await QUEUE.get()\n self.finish(message.body)\n\n\nclass PublisherHandler(tornado.web.RequestHandler):\n async def post(self):\n connection = self.application.settings[\"amqp_connection\"]\n channel = await connection.channel()\n try:\n await channel.default_exchange.publish(\n Message(body=self.request.body), routing_key=\"test\",\n )\n finally:\n await channel.close()\n print('ok')\n self.finish(\"OK\")\n\nasync def make_app():\n amqp_connection = await connect_robust()\n channel = await amqp_connection.channel()\n queue = await channel.declare_queue(\"test\", auto_delete=True)\n await queue.consume(QUEUE.put, no_ack=True)\n return tornado.web.Application(\n [(r\"/publish\", PublisherHandler), (r\"/subscribe\", SubscriberHandler)],\n amqp_connection=amqp_connection,\n )\n\nif __name__ == \"__main__\":\n app = io_loop.asyncio_loop.run_until_complete(make_app())\n app.listen(8888)\n tornado.ioloop.IOLoop.current().start()\n```\n\n```text\ndef on_message(ch, method_frame, _header_frame, body, args):\n (conn, thrds) = args\n delivery_tag = method_frame.delivery_tag\n t = threading.Thread(target=do_work, args=(conn, ch, delivery_tag, body))\n t.start()\n thrds.append(t)\n\nthreads = []\non_message_callback = functools.partial(on_message, args=(connection, threads))\nchannel.basic_consume('standard', on_message_callback)\n```\n\n========================================\n\nComments:\n- Hi @Unit03 I know you have answered in 2015. I am using same twisted adapter and I am getting too many heart beats missing.You can visit my question for code and more description. stackoverflow.com/questions/62024116/…\n- Hi Vaibhav, I have responded under that question.","metadata":{"transformedAt":"2026-08-18T18:33:20.139Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":23,"totalLines":410,"estimatedTokens":2693}}223{"id":"stack-25984602","source":"stackoverflow","questionId":25984602,"title":"What is a reasonable value for heartbeat in RabbitMQ?","tags":["rabbitmq"],"text":"Title: What is a reasonable value for heartbeat in RabbitMQ?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nRabbitMQ allows you to \"heartbeat\" a connection, i.e. from time to time the client and the server check (using empty messages) that the other party is still there and available. So far, so good.\n\nUnfortunately, I was not able to find a place in the documentation where a suggestion is made what a reasonable value for this is. I know that you need to specify the heartbeat in seconds, but what is a real-world best practice value?\n\nObviously, it should not be too often (traffic), but also not too rare (proxies, …). Any suggestions?\n\nIs 15 seconds fine? 30? 60? …?\n\n========================================\n\nTop Answer:\n**This answer if for RabbitMQ It depends on your application needs. Out of the box it is 10 min for RabbitMQ. If you fail to ack heartbeat twice (20min of inactivity), connection will be closed immediately without sending any connection.close method or any error from the broker side.\n\nThe case to use heartbeat is firewalls that closes inactive for a long time connection or some other network settings that doesn't allow you to have waiting connections.\n\nIn fact, hearbeat is not a must, from RabbitMQ config doc\n\n**heartbeat**\n\nValue representing the heartbeat delay, in seconds, that the server sends in the connection.tune frame. If set to 0, heartbeats are disabled. Clients might not the server suggestion, see the AMQP reference for more details. Disabling heartbeats might improve performance in situations with a great number of connections, but might lead to connections dropping in the presence of network devices that close inactive connections.\nDefault: 580\n\nNote, that having hearbeat interval too short may result in significant network overhead. Keep in mind, that hearbeat frames are sent when there are no other activity on the connection for a hearbeat time interval.\n\n========================================\n\nComments:\n- Is it okay to set the heartbeat to be 1 hour? How do I ack heartbeat from client side?\n- IIRC, the RMQ mentions something like \"most clients treat regular traffic as heartbeats, though some don't\"","metadata":{"transformedAt":"2026-08-18T18:33:20.139Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":34,"estimatedTokens":543}}224{"id":"stack-6104418","source":"stackoverflow","questionId":6104418,"title":"Use of messaging like RabbitMQ in web application?","tags":["message-queue","rabbitmq","amqp"],"text":"Title: Use of messaging like RabbitMQ in web application?\nTags: message-queue, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI would like to learn what are the scenarios/usecases/ where messaging like RabbitMQ can help consumer web applications. \n\nAre there any specific resources to learn from? \n\nWhat web applications currently are making use of such messaging schemes and how?\n\n========================================\n\nTop Answer:\nI just did a Google search and came up with the following:\n\n- Reddit.com\n\n- Digg.com\n\n- Poppen.De\n\nThat should get you started, at least.","metadata":{"transformedAt":"2026-08-18T18:33:20.139Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":23,"estimatedTokens":144}}225{"id":"stack-47152466","source":"stackoverflow","questionId":47152466,"title":"Got \"Pipelining of requests forbidden\" in c# rabbitmq client","tags":["c#","rabbitmq"],"text":"Title: Got \"Pipelining of requests forbidden\" in c# rabbitmq client\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have a RabbitMQ C# Client running in a WCF service.\n\nIt catches `System.NotSupportedException: Pipelining of requests forbidden` exception now and then.\n\n========================================\n\nTop Answer:\nif the server doesn't have enough memory where RabbitMQ is installed you can experience this issue as well.\n\n========================================\n\nCode:\n```text\nSystem.NotSupportedException: Pipelining of requests forbidden\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.139Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":20,"estimatedTokens":141}}226{"id":"stack-9151698","source":"stackoverflow","questionId":9151698,"title":"Does RabbitMQ call the callback function for a consumer when it has some message for it?","tags":["php","messaging","rabbitmq","sharding"],"text":"Title: Does RabbitMQ call the callback function for a consumer when it has some message for it?\nTags: php, messaging, rabbitmq, sharding\nSource: Stack Overflow\n\nQuestion:\nDoes RabbitMQ call the callback function for a consumer when it has some message for it, or does the consumer have to poll the RabbitMQ client?\n\nSo on the consumer side, if there is a PHP script, can RabbitMQ call it and pass the message/parameters to it. e.g. if rating is submitted on shard 1 and the aggregateRating table is on shard 2, then would RabbitMQ consumer on shard 2 trigger the script say aggRating.php and pass the parameters that were inserted in shard 1?\n\n========================================\n\nTop Answer:\nThe AMQPQueue::consume method is now a \"proper\" implementation of basic.consume as of version 1.0 of the PHP AMQP library (http://www.php.net/manual/en/amqpqueue.consume.php). Unfortunately, since PHP is a single threaded language, you cant do other things while waiting for a message in the same process space. If you call AMQPQueue::consume and pass it a callback, your entire application will block and wait for the next message to be sent by the broker, at which point it will call the provided callback function. If you want a non blocking method, you will have to use AMQPQueue::get (http://www.php.net/manual/en/amqpqueue.get.php), which will poll the server for a message, and return a boolean FALSE if there is no message.\n\nI disagree with scvatex's suggestion to use a separate language for using a \"push\" approach to this problem though. PHP is not IO driven, and therefore using a separate language to call a PHP script when a message arrives seems like unnecessary complexity: why not just use AMQPQueue::consume and let the process block (wait for a message), and either put all the logic in the callback or make the callback run a separate PHP script.\n\nWe have done the latter at my work as a large scale job processing system so that we can segregate errors and keep the parent job processor running no matter what happens in the children. If you would like a detailed description of how we set this up and some code samples, I would be more than happy to post them.\n\n========================================\n\nCode:\n```text\nbasic.consume\n```\n\n```text\nbasic.consume\n```\n\n```text\nbasic.consume\n```\n\n========================================\n\nComments:\n- The libraries are implemented differently. Most of them have support for basic.consume. If your php library does not, you'll need to write your own. For instance, you could drive your php script by a python script or java program that consumes messages from the broker.\n- The Python/Java clients wouldn't have to poll at all, but they would need a stable connection to the broker. The broker would push messages to the P/J clients. The clients could then call your scripts for each message. See the RabbitMQ tutorials for details: rabbitmq.com/getstarted.html\n- I don't have any experience with PHP and I don't know anything about the PHP AMQP clients. Anything I've said about the PHP library is just an educated guess. I haven't really answered your question here. BTW, in the future, you might want to post questions like this to the RabbitMQ Discuss mailing list. I think I'm the only RabbitMQ developer that checks SO; but we make a point of answering any question posted on the mailing list.","metadata":{"transformedAt":"2026-08-18T18:33:20.139Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":39,"estimatedTokens":841}}227{"id":"stack-39397646","source":"stackoverflow","questionId":39397646,"title":"I cannot start rabbitmq on my mac","tags":["django","rabbitmq","celery"],"text":"Title: I cannot start rabbitmq on my mac\nTags: django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI have brew installed rabbitmq on my mac and have tried the following\n\n```\nrabbitmq-server start\n\nsbin/service rabbitmq-server start\n```\n\nand neither work.How do I start it?\n\n========================================\n\nTop Answer:\nHere are a few commands to get you started. Just open your cli and type from anywhere\n\n```\nbrew services start rabbitmq //start \nbrew services stop rabbitmq //stop\n\nbrew services restart rabbitmq //restart\n```\n\nYou can also list all the running services by \n\n```\nbrew services list\n```\n\n### Alternative way -\n\nGo to the directory where `rabbitMQ` is installed and run following commands\n\n```\ncd rabbitmq_server-3.5.3/ //check you's version \nsbin/rabbitmq-server //start server \n\nsbin/rabbitmqctl shutdown //stop server\n```\n\n========================================\n\nCode:\n```text\nrabbitmq-server start\n\nsbin/service rabbitmq-server start\n```\n\n```text\n/usr/local/sbin/rabbitmq-server\n```\n\n```text\nbrew services start rabbitmq\n```\n\n```text\nbrew services start rabbitmq //start \nbrew services stop rabbitmq //stop\n\nbrew services restart rabbitmq //restart\n```\n\n```text\nbrew services list\n```\n\n```text\ncd rabbitmq_server-3.5.3/ //check you's version \nsbin/rabbitmq-server //start server \n\nsbin/rabbitmqctl shutdown //stop server\n```\n\n```text\nrabbitMQ\n```\n\n```text\nusername-guest \npassword-guest\n```\n\n```text\nbrew services start rabbitmq\n```\n\n```text\nusername: guest\npassword: guest\n```\n\n========================================\n\nComments:\n- That worked. I saw this no where in the docs. How'd you know this?\n- @losee, You can use `brew services start[stop/restart/list]` for run RabbitMQ service in the background (or mysql, redis...). Homebrew installs packages in `/usr/local/Cellar/` and then symlinks their files into `/usr/local/`","metadata":{"transformedAt":"2026-08-18T18:33:20.139Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":102,"estimatedTokens":484}}228{"id":"stack-50454109","source":"stackoverflow","questionId":50454109,"title":"Communication between microservices - request data","tags":["rest","rabbitmq","microservices","rpc"],"text":"Title: Communication between microservices - request data\nTags: rest, rabbitmq, microservices, rpc\nSource: Stack Overflow\n\nQuestion:\nI am dealing with communication between microservices.\n\nFor example (*fictive example, just for the illustration*):\n\n- **Microservice A - Store Users (getUser, etc.)**\n\n- **Microservice B - Store Orders (createOrder, etc.)**\n\nNow if I want to add new Order from the Client app, I need to know user address. So the request would be like this:\n\n**Client -> Microservice B (createOrder for userId 5) -> Microservice A (getUser with id 5)**\n\nThe microservice B will create order with details (address) from the User Microservice.\n\n**PROBLEM TO SOLVE:** How effectively deal with communication between microservice A and microservice B, as we have to wait until the response come back?\n\n**OPTIONS:**\n\n- Use RestAPI,\n\n- Use AMQP, like RabbitMQ and deal with this issue via RPC. (https://www.rabbitmq.com/tutorials/tutorial-six-dotnet.html)\n\nI don't know **what will be better for the performance**. Is call faster via RabbitMQ, or RestAPI? **What is the best solution for microservice architecture**?\n\n========================================\n\nTop Answer:\n**It all depends on your service's communication behaviour to choose between REST APIs and Event-Based design Or Both**.\n\nWhat you do is based on your requirement you can choose **REST APIs** where you see **synchronous behaviour** between services \nand go with **Event based design** where you find services needs **asynchronous behaviour**, there is no harm combining both also. \n\nIdeally for inter-process communication protocol it is better to go with messaging and for client-service REST APIs are best fitted.\nCheck the Communication style in microservices.io\n\n**REST based Architecture**\n\nAdvantage\n\nRequest/Response is easy and best fitted when you need synchronous environments.\n\nSimpler system since there in no intermediate broker\n\nPromotes orchestration i.e Service can take action based on response of other service.\n\nDrawback\n\nServices needs to discover locations of service instances.\n\nOne to one Mapping between services.\n\nRest used HTTP which is general purpose protocol built on top of TCP/IP which adds enormous amount of overhead when using it to pass messages.\n\n**Event Driven Architecture**\n\nAdvantage\n\nEvent-driven architectures are appealing to API developers because they function very well in asynchronous environments.\n\nLoose coupling since it decouples services as on a event of once service multiple services can take action based on application requirement. it is easy to plug-in any new consumer to producer.\n\nImproved availability since the message broker buffers messages until the consumer is able to process them.\n\nDrawback\n\n- Additional complexity of message broker, which must be highly available\n\n- Debugging an event request is not that easy.\n\n========================================\n\nComments:\n- It depends on the requirement for this application. Hard to answer from a fictive example. To me it sounds like add order could be async. It could also be the case that service B already knows about the users in the system - from say reading events, then it is just an in memory lookup.\n- In my opinion, storing users in some memory might be memory consuming. And isn't it anti-pattern to store other microservices data? Do you think, that with this being said, the best option is HTTP?\n- Yes, in that case. HTTP.\n- If you want to do it with API, i strongly recommend you to use gRPC instead of http. It's very faster. But also AMQP is very fast, because of the always-connected nature.\n- Thank you for your submission. RabbitMQ is as standalone microservice in Docker. But you are right, that for the timeouts, and these things, HTTP might be worth using. I like the idea about catching events, but there is problem, that microservice order could shut down, and than he doesn't have that user inside his database. Also it is quite anti-pattern in terms of microservice, which is ment to do only one thing.\n- Well, RabbitMQ is a durable message system. That is one of the points of using it. If one service is down then no problem, you can consume the event when the service comes back up. We get reliable messaging in the face of transient consumers.\n- Also this \"anti-pattern\" is quite a common pattern in microservices. I'm not sure where you got that idea. I would say a larger anti-pattern is to have direct coupling with multiple other services, you're on the road to a distributed monolith. Also think about what happens when the Users service is unavailable, sure you can use your retries and circuit breakers, but that won't help if it is down for a few minutes. When the data is already local to your service, you get better reliability and lower latency. It has trade-offs but I don't think you could call it an anti-pattern.\n- Ok, that sounds reasonable. I am fighting with duplicating databases over the microservices. I don't know if it is the best idea. If you think of what have to be done is, that models from Users must be in the Order and also there have to be event handling. If there is more services like order, that need some data from Users, than this might be a nightmare. Not counting other services that might have data as users. And not counting that Users datacontext might be changed over time.\n- If the service goes down, there is load balancer, that recognize that and redirect communication to the other instance. So, hopefully everything is good to go with synchronous calls. For these calls is better HTTP?\n- Let's come at it from another angle. It's about weighing the trade-offs. So identify what a message broker offers you that HTTP cannot, and vice-versa. With a list of benefits and drawbacks make the decision. So what does a message broker give you in this scenario that HTTP does not?\n- Yes, it does give me everything as HTTP. If I want to call something synchronous, I can do it via RPC (supported by RabbitMQ). What is important for me is speed. I don't know, which one will response faster (HTTP, or RPC). So you would preffer RPC? I need to decide between these two.\n- The last thing I'll say this is. Forgetting all the other trade-offs, if speed is your number one priority then I'd recommend running a benchmark to see which one is faster in your case. Make sure you use non-persistent messages for RabbitMQ. I have used ZeroMQ on a previous project and the performance was phenonmenal at the cost of some extra complexity. Also look at GRPC if your tech stack supports it.","metadata":{"transformedAt":"2026-08-18T18:33:20.139Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":89,"estimatedTokens":1637}}229{"id":"stack-43409988","source":"stackoverflow","questionId":43409988,"title":"How to use Rabbit inside a gitlab-ci.yml file?","tags":["rabbitmq","gitlab-ci"],"text":"Title: How to use Rabbit inside a gitlab-ci.yml file?\nTags: rabbitmq, gitlab-ci\nSource: Stack Overflow\n\nQuestion:\nI want to test with `gitlab-ci.yml` a rpc nameko server.\n\nI can't succeed to make work the Rabitt inside `.gitlab-ci.yml`::\n\n```\nimage: python:latest\n\nbefore_script:\n - apt-get update -yq\n - apt-get install -y python-dev python-pip tree\n - curl -I http://guest:guest@rabbitmq:8080/api/overview\n\nmytest:\n artifacts:\n paths:\n - dist\n script:\n - pip install -r requirements.txt \n - pip install .\n - pytest --amqp-uri=amqp://guest:guest@rabbitmq:5672 --rabbit-ctl-uri=http://guest:guest@rabbitmq:15672 tests\n # - python setup.py test\n - python setup.py bdist_wheel\n\nlook:\n stage: deploy\n script:\n - ls -lah dist\nservices:\n - rabbitmq:3-management\n```\n\nThe Rabbit start correctly::\n\n```\n2017-04-13T18:19:23.436309219Z \n2017-04-13T18:19:23.436409026Z RabbitMQ 3.6.9. Copyright (C) 2007-2016 Pivotal Software, Inc.\n2017-04-13T18:19:23.436432568Z ## ## Licensed under the MPL. See http://www.rabbitmq.com/\n2017-04-13T18:19:23.436451431Z ## ##\n2017-04-13T18:19:23.436468542Z ########## Logs: tty\n2017-04-13T18:19:23.436485607Z ###### ## tty\n2017-04-13T18:19:23.436501886Z ##########\n2017-04-13T18:19:23.436519036Z Starting broker...\n2017-04-13T18:19:23.440790736Z \n2017-04-13T18:19:23.440809836Z =INFO REPORT==== 13-Apr-2017::18:19:23 ===\n2017-04-13T18:19:23.440819014Z Starting RabbitMQ 3.6.9 on Erlang 19.3\n2017-04-13T18:19:23.440827601Z Copyright (C) 2007-2016 Pivotal Software, Inc.\n2017-04-13T18:19:23.440835737Z Licensed under the MPL. See http://www.rabbitmq.com/\n2017-04-13T18:19:23.443408721Z \n2017-04-13T18:19:23.443429311Z =INFO REPORT==== 13-Apr-2017::18:19:23 ===\n2017-04-13T18:19:23.443439837Z node : rabbit@ea1a207b738e\n2017-04-13T18:19:23.443449307Z home dir : /var/lib/rabbitmq\n2017-04-13T18:19:23.443460663Z config file(s) : /etc/rabbitmq/rabbitmq.config\n2017-04-13T18:19:23.443470393Z cookie hash : h6vFB5LezZ4GR1nGuQOVSg==\n2017-04-13T18:19:23.443480053Z log : tty\n2017-04-13T18:19:23.443489256Z sasl log : tty\n2017-04-13T18:19:23.443498676Z database dir : /var/lib/rabbitmq/mnesia/rabbit@ea1a207b738e\n2017-04-13T18:19:27.717290199Z \n2017-04-13T18:19:27.717345348Z =INFO REPORT==== 13-Apr-2017::18:19:27 ===\n2017-04-13T18:19:27.717355143Z Memory limit set to 3202MB of 8005MB total.\n2017-04-13T18:19:27.726821043Z \n2017-04-13T18:19:27.726841925Z =INFO REPORT==== 13-Apr-2017::18:19:27 ===\n2017-04-13T18:19:27.726850927Z Disk free limit set to 50MB\n2017-04-13T18:19:27.732864417Z \n2017-04-13T18:19:27.732882507Z =INFO REPORT==== 13-Apr-2017::18:19:27 ===\n2017-04-13T18:19:27.732891347Z Limiting to approx 1048476 file handles (943626 sockets)\n2017-04-13T18:19:27.733030868Z \n2017-04-13T18:19:27.733041770Z =INFO REPORT==== 13-Apr-2017::18:19:27 ===\n2017-04-13T18:19:27.733049763Z FHC read buffering: OFF\n2017-04-13T18:19:27.733126168Z FHC write buffering: ON\n2017-04-13T18:19:27.793026622Z \n2017-04-13T18:19:27.793043832Z =INFO REPORT==== 13-Apr-2017::18:19:27 ===\n2017-04-13T18:19:27.793052900Z Database directory at /var/lib/rabbitmq/mnesia/rabbit@ea1a207b738e is empty. Initialising from scratch...\n2017-04-13T18:19:27.800414211Z \n2017-04-13T18:19:27.800429311Z =INFO REPORT==== 13-Apr-2017::18:19:27 ===\n2017-04-13T18:19:27.800438013Z application: mnesia\n2017-04-13T18:19:27.800464988Z exited: stopped\n2017-04-13T18:19:27.800473228Z type: temporary\n2017-04-13T18:19:28.129404329Z \n2017-04-13T18:19:28.129482072Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.129491680Z Waiting for Mnesia tables for 30000 ms, 9 retries left\n2017-04-13T18:19:28.153509130Z \n2017-04-13T18:19:28.153526528Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.153535638Z Waiting for Mnesia tables for 30000 ms, 9 retries left\n2017-04-13T18:19:28.193558406Z \n2017-04-13T18:19:28.193600316Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.193611144Z Waiting for Mnesia tables for 30000 ms, 9 retries left\n2017-04-13T18:19:28.194448672Z \n2017-04-13T18:19:28.194464866Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.194475629Z Priority queues enabled, real BQ is rabbit_variable_queue\n2017-04-13T18:19:28.208882072Z \n2017-04-13T18:19:28.208912016Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.208921824Z Starting rabbit_node_monitor\n2017-04-13T18:19:28.211145158Z \n2017-04-13T18:19:28.211169236Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.211182089Z Management plugin: using rates mode 'basic'\n2017-04-13T18:19:28.224499311Z \n2017-04-13T18:19:28.224527962Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.224538810Z msg_store_transient: using rabbit_msg_store_ets_index to provide index\n2017-04-13T18:19:28.226355958Z \n2017-04-13T18:19:28.226376272Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.226385706Z msg_store_persistent: using rabbit_msg_store_ets_index to provide index\n2017-04-13T18:19:28.227832476Z \n2017-04-13T18:19:28.227870221Z =WARNING REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.227891823Z msg_store_persistent: rebuilding indices from scratch\n2017-04-13T18:19:28.230832501Z \n2017-04-13T18:19:28.230872729Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.230893941Z Adding vhost '/'\n2017-04-13T18:19:28.385440862Z \n2017-04-13T18:19:28.385520360Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.385540022Z Creating user 'guest'\n2017-04-13T18:19:28.398092244Z \n2017-04-13T18:19:28.398184254Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.398206496Z Setting user tags for user 'guest' to [administrator]\n2017-04-13T18:19:28.413704571Z \n2017-04-13T18:19:28.413789806Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.413810378Z Setting permissions for 'guest' in '/' to '.*', '.*', '.*'\n2017-04-13T18:19:28.451109821Z \n2017-04-13T18:19:28.451162892Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.451172185Z started TCP Listener on [::]:5672\n2017-04-13T18:19:28.475429729Z \n2017-04-13T18:19:28.475491074Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.475501172Z Management plugin started. Port: 15672\n2017-04-13T18:19:28.475821397Z \n2017-04-13T18:19:28.475835599Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.475844143Z Statistics database started.\n2017-04-13T18:19:28.487572236Z completed with 6 plugins.\n2017-04-13T18:19:28.487797794Z \n2017-04-13T18:19:28.487809763Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.487818426Z Server startup complete; 6 plugins started.\n2017-04-13T18:19:28.487826288Z * rabbitmq_management\n2017-04-13T18:19:28.487833914Z * rabbitmq_web_dispatch\n2017-04-13T18:19:28.487841610Z * rabbitmq_management_agent\n2017-04-13T18:19:28.487861057Z * amqp_client\n2017-04-13T18:19:28.487875546Z * cowboy\n2017-04-13T18:19:28.487883514Z * cowlib\n\n*********\n```\n\nBut I get this error\n\n```\n$ pytest --amqp-uri=amqp://guest:guest@rabbitmq:5672 --rabbit-ctl-uri=http://guest:guest@rabbitmq:15672 tests\n============================= test session starts ==============================\nplatform linux -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0\n...\nE Exception: Connection error for the RabbitMQ management HTTP API at http://guest:guest@rabbitmq:15672/api/overview, is it enabled?\n...\nsource:565: DeprecationWarning: invalid escape sequence \\*\nERROR: Job failed: exit code 1\n```\n\n========================================\n\nCode:\n```text\nimage: python:latest\n\nbefore_script:\n - apt-get update -yq\n - apt-get install -y python-dev python-pip tree\n - curl -I http://guest:guest@rabbitmq:8080/api/overview\n\nmytest:\n artifacts:\n paths:\n - dist\n script:\n - pip install -r requirements.txt \n - pip install .\n - pytest --amqp-uri=amqp://guest:guest@rabbitmq:5672 --rabbit-ctl-uri=http://guest:guest@rabbitmq:15672 tests\n # - python setup.py test\n - python setup.py bdist_wheel\n\nlook:\n stage: deploy\n script:\n - ls -lah dist\nservices:\n - rabbitmq:3-management\n```\n\n```text\n2017-04-13T18:19:23.436309219Z \n2017-04-13T18:19:23.436409026Z RabbitMQ 3.6.9. Copyright (C) 2007-2016 Pivotal Software, Inc.\n2017-04-13T18:19:23.436432568Z ## ## Licensed under the MPL. See http://www.rabbitmq.com/\n2017-04-13T18:19:23.436451431Z ## ##\n2017-04-13T18:19:23.436468542Z ########## Logs: tty\n2017-04-13T18:19:23.436485607Z ###### ## tty\n2017-04-13T18:19:23.436501886Z ##########\n2017-04-13T18:19:23.436519036Z Starting broker...\n2017-04-13T18:19:23.440790736Z \n2017-04-13T18:19:23.440809836Z =INFO REPORT==== 13-Apr-2017::18:19:23 ===\n2017-04-13T18:19:23.440819014Z Starting RabbitMQ 3.6.9 on Erlang 19.3\n2017-04-13T18:19:23.440827601Z Copyright (C) 2007-2016 Pivotal Software, Inc.\n2017-04-13T18:19:23.440835737Z Licensed under the MPL. See http://www.rabbitmq.com/\n2017-04-13T18:19:23.443408721Z \n2017-04-13T18:19:23.443429311Z =INFO REPORT==== 13-Apr-2017::18:19:23 ===\n2017-04-13T18:19:23.443439837Z node : rabbit@ea1a207b738e\n2017-04-13T18:19:23.443449307Z home dir : /var/lib/rabbitmq\n2017-04-13T18:19:23.443460663Z config file(s) : /etc/rabbitmq/rabbitmq.config\n2017-04-13T18:19:23.443470393Z cookie hash : h6vFB5LezZ4GR1nGuQOVSg==\n2017-04-13T18:19:23.443480053Z log : tty\n2017-04-13T18:19:23.443489256Z sasl log : tty\n2017-04-13T18:19:23.443498676Z database dir : /var/lib/rabbitmq/mnesia/rabbit@ea1a207b738e\n2017-04-13T18:19:27.717290199Z \n2017-04-13T18:19:27.717345348Z =INFO REPORT==== 13-Apr-2017::18:19:27 ===\n2017-04-13T18:19:27.717355143Z Memory limit set to 3202MB of 8005MB total.\n2017-04-13T18:19:27.726821043Z \n2017-04-13T18:19:27.726841925Z =INFO REPORT==== 13-Apr-2017::18:19:27 ===\n2017-04-13T18:19:27.726850927Z Disk free limit set to 50MB\n2017-04-13T18:19:27.732864417Z \n2017-04-13T18:19:27.732882507Z =INFO REPORT==== 13-Apr-2017::18:19:27 ===\n2017-04-13T18:19:27.732891347Z Limiting to approx 1048476 file handles (943626 sockets)\n2017-04-13T18:19:27.733030868Z \n2017-04-13T18:19:27.733041770Z =INFO REPORT==== 13-Apr-2017::18:19:27 ===\n2017-04-13T18:19:27.733049763Z FHC read buffering: OFF\n2017-04-13T18:19:27.733126168Z FHC write buffering: ON\n2017-04-13T18:19:27.793026622Z \n2017-04-13T18:19:27.793043832Z =INFO REPORT==== 13-Apr-2017::18:19:27 ===\n2017-04-13T18:19:27.793052900Z Database directory at /var/lib/rabbitmq/mnesia/rabbit@ea1a207b738e is empty. Initialising from scratch...\n2017-04-13T18:19:27.800414211Z \n2017-04-13T18:19:27.800429311Z =INFO REPORT==== 13-Apr-2017::18:19:27 ===\n2017-04-13T18:19:27.800438013Z application: mnesia\n2017-04-13T18:19:27.800464988Z exited: stopped\n2017-04-13T18:19:27.800473228Z type: temporary\n2017-04-13T18:19:28.129404329Z \n2017-04-13T18:19:28.129482072Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.129491680Z Waiting for Mnesia tables for 30000 ms, 9 retries left\n2017-04-13T18:19:28.153509130Z \n2017-04-13T18:19:28.153526528Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.153535638Z Waiting for Mnesia tables for 30000 ms, 9 retries left\n2017-04-13T18:19:28.193558406Z \n2017-04-13T18:19:28.193600316Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.193611144Z Waiting for Mnesia tables for 30000 ms, 9 retries left\n2017-04-13T18:19:28.194448672Z \n2017-04-13T18:19:28.194464866Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.194475629Z Priority queues enabled, real BQ is rabbit_variable_queue\n2017-04-13T18:19:28.208882072Z \n2017-04-13T18:19:28.208912016Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.208921824Z Starting rabbit_node_monitor\n2017-04-13T18:19:28.211145158Z \n2017-04-13T18:19:28.211169236Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.211182089Z Management plugin: using rates mode 'basic'\n2017-04-13T18:19:28.224499311Z \n2017-04-13T18:19:28.224527962Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.224538810Z msg_store_transient: using rabbit_msg_store_ets_index to provide index\n2017-04-13T18:19:28.226355958Z \n2017-04-13T18:19:28.226376272Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.226385706Z msg_store_persistent: using rabbit_msg_store_ets_index to provide index\n2017-04-13T18:19:28.227832476Z \n2017-04-13T18:19:28.227870221Z =WARNING REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.227891823Z msg_store_persistent: rebuilding indices from scratch\n2017-04-13T18:19:28.230832501Z \n2017-04-13T18:19:28.230872729Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.230893941Z Adding vhost '/'\n2017-04-13T18:19:28.385440862Z \n2017-04-13T18:19:28.385520360Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.385540022Z Creating user 'guest'\n2017-04-13T18:19:28.398092244Z \n2017-04-13T18:19:28.398184254Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.398206496Z Setting user tags for user 'guest' to [administrator]\n2017-04-13T18:19:28.413704571Z \n2017-04-13T18:19:28.413789806Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.413810378Z Setting permissions for 'guest' in '/' to '.*', '.*', '.*'\n2017-04-13T18:19:28.451109821Z \n2017-04-13T18:19:28.451162892Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.451172185Z started TCP Listener on [::]:5672\n2017-04-13T18:19:28.475429729Z \n2017-04-13T18:19:28.475491074Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.475501172Z Management plugin started. Port: 15672\n2017-04-13T18:19:28.475821397Z \n2017-04-13T18:19:28.475835599Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.475844143Z Statistics database started.\n2017-04-13T18:19:28.487572236Z completed with 6 plugins.\n2017-04-13T18:19:28.487797794Z \n2017-04-13T18:19:28.487809763Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===\n2017-04-13T18:19:28.487818426Z Server startup complete; 6 plugins started.\n2017-04-13T18:19:28.487826288Z * rabbitmq_management\n2017-04-13T18:19:28.487833914Z * rabbitmq_web_dispatch\n2017-04-13T18:19:28.487841610Z * rabbitmq_management_agent\n2017-04-13T18:19:28.487861057Z * amqp_client\n2017-04-13T18:19:28.487875546Z * cowboy\n2017-04-13T18:19:28.487883514Z * cowlib\n\n*********\n```\n\n```text\n$ pytest --amqp-uri=amqp://guest:guest@rabbitmq:5672 --rabbit-ctl-uri=http://guest:guest@rabbitmq:15672 tests\n============================= test session starts ==============================\nplatform linux -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0\n...\nE Exception: Connection error for the RabbitMQ management HTTP API at http://guest:guest@rabbitmq:15672/api/overview, is it enabled?\n...\nsource:565: DeprecationWarning: invalid escape sequence \\*\nERROR: Job failed: exit code 1\n```\n\n```text\ngitlab-ci.yml\n```\n\n```text\n.gitlab-ci.yml\n```\n\n```text\nimage: \"ruby:2.3.3\" //not required by rabbitmq\n\nservices:\n - rabbitmq:latest\n\nvariables:\n RABBITMQ_DEFAULT_USER: guest\n RABBITMQ_DEFAULT_PASS: guest\n AMQP_URL: 'amqp://guest:guest@rabbitmq:5672'\n```\n\n```text\nenv\n```\n\n```text\nservices\n```\n\n```text\nrabbitmq\n```\n\n========================================\n\nComments:\n- related to stackoverflow.com/questions/43409794/…\n- `AMQP_URL` this `env` variable is not defined in the docker hub documentation. From where did you get this? Thanks.\n- @Vino the `AMQP_URL` is application defined. your application is referencing this variable to access `rabbitmq`\n- Yes. I figured it. Anyway, appreciate you replied mate. Thanks.\n- Following the above information , but I got exception and explained it on the following link : stackoverflow.com/questions/57786388/…\n- @YeasinArRahman I have mention the instruction but I got `org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)`.","metadata":{"transformedAt":"2026-08-18T18:33:20.139Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":9,"totalLines":345,"estimatedTokens":3936}}230{"id":"stack-29513813","source":"stackoverflow","questionId":29513813,"title":"Celery & RabbitMQ running as docker containers: Received unregistered task of type '...'","tags":["python","docker","rabbitmq","celery","amqp"],"text":"Title: Celery & RabbitMQ running as docker containers: Received unregistered task of type '...'\nTags: python, docker, rabbitmq, celery, amqp\nSource: Stack Overflow\n\nQuestion:\nI am relatively new to docker, celery and rabbitMQ.\n\nIn our project we currently have the following setup:\n1 physical host with multiple docker containers running:\n\n**1x rabbitmq:3-management container**\n\n```\n# pull image from docker hub and install\ndocker pull rabbitmq:3-management\n# run docker image\ndocker run -d -e RABBITMQ_NODENAME=my-rabbit --name some-rabbit -p 8080:15672 -p 5672:5672 rabbitmq:3-management\n```\n\n**1x celery container**\n\n```\n# pull docker image from docker hub\ndocker pull celery\n# run celery container\ndocker run --link some-rabbit:rabbit --name some-celery -d celery\n```\n\n(there are some more containers, but they should not have to do anything with the problem)\n\n**Task File**\n\nTo get to know celery and rabbitmq a bit, I created a tasks.py file on the physical host:\n\n```\nfrom celery import Celery\n\napp = Celery('tasks', backend='amqp', broker='amqp://guest:guest@172.17.0.81/')\n\n@app.task(name='tasks.add')\ndef add(x, y):\n return x + y\n```\n\nThe whole setup seems to be working quite fine actually. So when I open a python shell in the directory where tasks.py is located and run\n\n```\n>>> from tasks import add\n>>> add.delay(4,4)\n```\n\nThe task gets queued and directly pulled from the celery worker.\n\nHowever, the celery worker does not know the tasks module regarding to the logs:\n\n```\n$ docker logs some-celery\n\n[2015-04-08 11:25:24,669: ERROR/MainProcess] Received unregistered task of type 'tasks.add'.\nThe message has been ignored and discarded.\n\nDid you remember to import the module containing this task?\nOr maybe you are using relative imports?\nPlease see http://bit.ly/gLye1c for more information.\n\nThe full contents of the message body was:\n{'callbacks': None, 'timelimit': (None, None), 'retries': 0, 'id': '2b5dc209-3c41-4a8d-8efe-ed450d537e56', 'args': (4, 4), 'eta': None, 'utc': True, 'taskset': None, 'task': 'tasks.add', 'errbacks': None, 'kwargs': {}, 'chord': None, 'expires': None} (256b)\nTraceback (most recent call last):\n File \"/usr/local/lib/python3.4/site-packages/celery/worker/consumer.py\", line 455, in on_task_received\nstrategies[name](message, body,\nKeyError: 'tasks.add'\n```\n\nSo the problem obviously seems to be, that the celery workers in the celery container do not know the tasks module.\nNow as I am not a docker specialist, I wanted to ask how I would best import the tasks module into the celery container?\n\nAny help is appreciated :)\n\n**EDIT 4/8/2015, 21:05:**\n\nThanks to Isowen for the answer. Just for completeness here is what I did:\n\nLet's assume my `tasks.py` is located on my local machine in `/home/platzhersh/celerystuff`. Now I created a `celeryconfig.py` in the same directory with the following content:\n\n```\nCELERY_IMPORTS = ('tasks')\nCELERY_IGNORE_RESULT = False\nCELERY_RESULT_BACKEND = 'amqp'\n```\n\nAs mentioned by Isowen, celery searches `/home/user` of the container for tasks and config files. So we mount the `/home/platzhersh/celerystuff` into the container when starting:\n\n```\nrun -v /home/platzhersh/celerystuff:/home/user --link some-rabbit:rabbit --name some-celery -d celery\n```\n\nThis did the trick for me. Hope this helps some other people with similar problems. \nI'll now try to expand that solution by putting the tasks also in a separate docker container.\n\n========================================\n\nCode:\n```text\n# pull image from docker hub and install\ndocker pull rabbitmq:3-management\n# run docker image\ndocker run -d -e RABBITMQ_NODENAME=my-rabbit --name some-rabbit -p 8080:15672 -p 5672:5672 rabbitmq:3-management\n```\n\n```text\n# pull docker image from docker hub\ndocker pull celery\n# run celery container\ndocker run --link some-rabbit:rabbit --name some-celery -d celery\n```\n\n```text\nfrom celery import Celery\n\napp = Celery('tasks', backend='amqp', broker='amqp://guest:guest@172.17.0.81/')\n\n@app.task(name='tasks.add')\ndef add(x, y):\n return x + y\n```\n\n```text\n>>> from tasks import add\n>>> add.delay(4,4)\n```\n\n```text\n$ docker logs some-celery\n\n\n[2015-04-08 11:25:24,669: ERROR/MainProcess] Received unregistered task of type 'tasks.add'.\nThe message has been ignored and discarded.\n\nDid you remember to import the module containing this task?\nOr maybe you are using relative imports?\nPlease see http://bit.ly/gLye1c for more information.\n\nThe full contents of the message body was:\n{'callbacks': None, 'timelimit': (None, None), 'retries': 0, 'id': '2b5dc209-3c41-4a8d-8efe-ed450d537e56', 'args': (4, 4), 'eta': None, 'utc': True, 'taskset': None, 'task': 'tasks.add', 'errbacks': None, 'kwargs': {}, 'chord': None, 'expires': None} (256b)\nTraceback (most recent call last):\n File \"/usr/local/lib/python3.4/site-packages/celery/worker/consumer.py\", line 455, in on_task_received\nstrategies[name](message, body,\nKeyError: 'tasks.add'\n```\n\n```text\nCELERY_IMPORTS = ('tasks')\nCELERY_IGNORE_RESULT = False\nCELERY_RESULT_BACKEND = 'amqp'\n```\n\n```text\nrun -v /home/platzhersh/celerystuff:/home/user --link some-rabbit:rabbit --name some-celery -d celery\n```\n\n```text\ntasks.py\n```\n\n```text\n/home/platzhersh/celerystuff\n```\n\n```text\nceleryconfig.py\n```\n\n```text\n/home/user\n```\n\n```text\n/home/platzhersh/celerystuff\n```\n\n```text\ndocker run --link some-rabbit:rabbit -v /path/to/host/code:/home/user --name some-celery -d celery\n```\n\n```text\n/path/to/host/code\n```\n\n```text\n/home/user\n```\n\n```text\n/home/user\n```\n\n```text\nDockerfile\n```\n\n```text\nWORKDIR\n```\n\n```text\n/home/user\n```\n\n========================================\n\nComments:\n- why are you both using amqp and redis here?\n- @JohnWu sorry for the late reply, but we aren't? :)\n- Hey Isowen, thank you for this fast reply! I already tried mounting the tasks.py file, but did not know I had to mount it into /home/user. Where would I put the celeryconfig? Also /home/user? Actually we want to consume tasks from multiple different hosts in the end, so we would have to find a good solution apart from mounting all the task files. But this is fine for the moment, to see if a basic setup would work.\n- @platzhersh you could actually mount to a different directory, but then it wouldn't be the `PWD` of celery when it runs, so adding the code to the Python search path would take an additional step. In other words, easiest to use `/home/user`. Hope that helps!\n- @platzhersh in the long run you should build a docker image that has your tasks in it.\n- @Isowen: thx! I put the celeryconfig.py also into /user/home and was able to load the tasks.py file with CELERY_IMPORT=(\"tasks\"). I'll see where I can get from there and post my findings later on.\n- From my understanding, you should separate task modules (that workers run) from you app, then build task modules inside the worker container, then distribute them. Linking them sure works, but it does not make any difference since you are running on the same machine, which doesn't scale.\n- @JohnWu: I agree with you. Your approach sounds much more scalable and clean. Can you link to implementation examples / instructions? Thanks","metadata":{"transformedAt":"2026-08-18T18:33:20.139Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":19,"totalLines":219,"estimatedTokens":1780}}231{"id":"stack-10502905","source":"stackoverflow","questionId":10502905,"title":"MassTransit with RabbitMQ: recovering the error queue","tags":["rabbitmq","masstransit"],"text":"Title: MassTransit with RabbitMQ: recovering the error queue\nTags: rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nThis is probably a very simple answer, but I'm not seeing an obvious solution in the MassTransit docs or forums.\n\nWhen you have some messages that have been moved over to the error queue in RabbitMQ, what's the best mechanism for getting them back into the processing queue? Also, is there any built-in logging of why they got moved over there in the first place?\n\n========================================\n\nCode:\n```text\nbusdriver\n```\n\n========================================\n\nComments:\n- I just ran into this and wrote a quick post about using BusDriver to move messages from one queue to another. josephvano.wordpress.com/2012/09/11/…\n- Hi Travis. I've enabled logging with a log level of 'Debug' using NLog and I'm able to log from my application. However, I'm not seeing any log entries from masstransit even though messages are still going to the error queue. Could you pls help with what I could be missing?\n- I'm not actually sure how NLog works. In log4net, I have set to MassTransit filter to Debug or the global one. Hit up the mailing list and ask there, someone will have a better idea than I will. groups.google.com/forum/#!forum/masstransit-discuss\n- Oh, have you included the MassTransit NLog integration nuget package?\n- @Travis: Can you please give me example of command we need to run to copy message from one queue to another\n- groups.google.com/d/msg/masstransit-discuss/sHOCyNdKo1A/… on the mailing list has an example of who they used it.\n- @Travis If you have written business related tools to move messages between queues, could you give a simple example on what that would look like.\n- I've worked with tooling we've built that goes through each item in the queue and allowed the person reviewing to make minor edits or to replay the transaction from an earlier state. It would show the message, the errors related to that transaction, and give them options on how to interact with it.\n- That's pretty nitfy. But, how is the simple BusDriver tool any different than what rabbitmq management tools and UI provide?\n- @Travis, I couldn't find the BusDrive. I have some failed messages which I would like to retry. I'm using masstransit transport Postgres. Please provide the script/tool where I can replay the _error messages.","metadata":{"transformedAt":"2026-08-18T18:33:20.139Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":29,"estimatedTokens":597}}232{"id":"stack-12024241","source":"stackoverflow","questionId":12024241,"title":"C# RabbitMQ Client thread safety","tags":["c#","multithreading","thread-safety","rabbitmq"],"text":"Title: C# RabbitMQ Client thread safety\nTags: c#, multithreading, thread-safety, rabbitmq\nSource: Stack Overflow\n\nQuestion:\n```\nConnectionFactory factory = new ConnectionFactory {HostName = \"localhost\"};\n\nusing (IConnection connection = factory.CreateConnection())\nusing (IModel channel = connection.CreateModel())\n{\n channel.QueueDeclare(\"hello\", false, false, false, null);\n for (int i = 0; i I have the code above, and I'm curious about thread safety.\n\nI am not sure, but I would imagine `ConnectionFactory` is thread safe. But is `IConnection` thread safe? Should I create a connection per request? Or rather a single persistent connection? And what about channel (`IModel`)? \n\nAlso, should I store the connection as ThreadLocal? Or should I create a connection per request?\n\n========================================\n\nCode:\n```text\nConnectionFactory factory = new ConnectionFactory {HostName = \"localhost\"};\n\nusing (IConnection connection = factory.CreateConnection())\nusing (IModel channel = connection.CreateModel())\n{\n channel.QueueDeclare(\"hello\", false, false, false, null);\n for (int i = 0; i < 100000; i++)\n {\n MemoryStream stream = new MemoryStream();\n\n var user = new User \n {\n Id = i\n };\n\n Serializer.Serialize(stream, user);\n\n\n channel.BasicPublish(\"\", \"hello\", null, stream.ToArray());\n\n }\n\n}\n```\n\n```text\nConnectionFactory\n```\n\n```text\nIConnection\n```\n\n```text\nIModel\n```\n\n========================================\n\nComments:\n- see my answer to this question stackoverflow.com/questions/10407760/…\n- \"Extremely careful\"? What kind of vague threat is that? EasyNetQ is a perfectly appropriate suggestion here. If people disagree, that's what the downvote button is for. It's unlikely the suggestion would've been given a second thought had he not also done the courtesy of disclaiming his authorship. I would be extremely careful about riding that high on your horse.\n- Good answer. It aligns with rabbitmq.com/dotnet-api-guide.html\n- EasyNetQ is great! However I have been getting \"Pipelining of requests forbidden\" sometimes.","metadata":{"transformedAt":"2026-08-18T18:33:20.139Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":66,"estimatedTokens":540}}233{"id":"stack-3278590","source":"stackoverflow","questionId":3278590,"title":"Does the content type header in RabbitMQ have any special meaning?","tags":["content-type","rabbitmq","amqp"],"text":"Title: Does the content type header in RabbitMQ have any special meaning?\nTags: content-type, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nDoes the content type header in RabbitMQ have any special meaning, or is it only a standardized way for my producers and consumers to signal what kind of data they are sending? In other words: will messages with certain content types get any special treatment, or is it just bytes, either way?","metadata":{"transformedAt":"2026-08-18T18:33:20.139Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":6,"estimatedTokens":109}}234{"id":"stack-57870894","source":"stackoverflow","questionId":57870894,"title":"How to create dynamic queues in rabbit mq using spring boot?","tags":["java","spring","rabbitmq","queue","amqp"],"text":"Title: How to create dynamic queues in rabbit mq using spring boot?\nTags: java, spring, rabbitmq, queue, amqp\nSource: Stack Overflow\n\nQuestion:\nI need some help.\n\nI'm developing a spring boot application, and I want wo publish messages to a rabbitMQ. I want to send it to a queue, that is named in the message itself. This way i want to create queues dynamicly.\nI only found examples that use a \"static\" queue.\n\nI have reserched some things but didn't find anything.\nI'm new to RabbitMQ and learned the basic concepts.\nI'm also fairly new to spring.\n\nRabbotMQ Config\n\n```\n@Configuration\npublic class RabbitMQConfig {\n\n @Value(\"amq.direct\")\n String exchange;\n\n @Value(\"queue-name\") // Don't want to do this\n String queueName;\n\n @Value(\"routing-key\") // Or this\n String routingkey;\n\n @Bean\n Queue queue() {\n return new Queue(queueName, true);\n }\n\n @Bean\n DirectExchange exchange() {\n return new DirectExchange(exchange);\n }\n\n @Bean\n Binding binding(Queue queue, DirectExchange exchange) {\n return BindingBuilder.bind(queue).to(exchange).with(routingkey);\n }\n\n @Bean\n public MessageConverter jsonMessageConverter() {\n return new Jackson2JsonMessageConverter();\n }\n\n @Bean\n public AmqpTemplate template(ConnectionFactory connectionFactory) {\n final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);\n rabbitTemplate.setMessageConverter(jsonMessageConverter());\n return rabbitTemplate;\n }\n}\n```\n\nMessageSender\n\n```\n@Service\npublic class RabbitMQSender {\n\n @Autowired\n private AmqpTemplate template;\n\n @Value(\"amq.direct\")\n private String exchange;\n\n public void send(MessageDTO message) {\n template.convertAndSend(exchange, message);\n\n }\n}\n```\n\n========================================\n\nCode:\n```java\n@Configuration\npublic class RabbitMQConfig {\n\n @Value(\"amq.direct\")\n String exchange;\n\n @Value(\"queue-name\") // Don't want to do this\n String queueName;\n\n @Value(\"routing-key\") // Or this\n String routingkey;\n\n @Bean\n Queue queue() {\n return new Queue(queueName, true);\n }\n\n @Bean\n DirectExchange exchange() {\n return new DirectExchange(exchange);\n }\n\n @Bean\n Binding binding(Queue queue, DirectExchange exchange) {\n return BindingBuilder.bind(queue).to(exchange).with(routingkey);\n }\n\n @Bean\n public MessageConverter jsonMessageConverter() {\n return new Jackson2JsonMessageConverter();\n }\n\n @Bean\n public AmqpTemplate template(ConnectionFactory connectionFactory) {\n final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);\n rabbitTemplate.setMessageConverter(jsonMessageConverter());\n return rabbitTemplate;\n }\n}\n```\n\n```java\n@Service\npublic class RabbitMQSender {\n\n @Autowired\n private AmqpTemplate template;\n\n @Value(\"amq.direct\")\n private String exchange;\n\n public void send(MessageDTO message) {\n template.convertAndSend(exchange, message);\n\n }\n}\n```\n\n```java\n@Bean\npublic AmqpAdmin amqpAdmin() {\n return new RabbitAdmin(connectionFactory);\n}\n```\n\n```java\n@Autowired\nprivate AmqpAdmin admin;\n```\n\n```java\nQueue queue = new Queue(queueName, durable, false, false);\nBinding binding = new Binding(queueName, Binding.DestinationType.QUEUE, EXCHANGE, routingKey, null);\nadmin.declareQueue(queue);\nadmin.declareBinding(binding);\n```\n\n========================================\n\nComments:\n- have a look here: stackoverflow.com/questions/24241880/…\n- also here: stackoverflow.com/questions/46872274/…\n- Thanks! @BenjaminSlabbert That RabbitAdmin helped a lot\n- How can I tag this as closed?\n- best way would be to post your solution as an answer and then mark it as accepted or give it an upvote","metadata":{"transformedAt":"2026-08-18T18:33:20.139Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":166,"estimatedTokens":920}}235{"id":"stack-36186578","source":"stackoverflow","questionId":36186578,"title":"Dealing with dead letters in RabbitMQ","tags":["rabbitmq","messaging","amqp","dead-letter"],"text":"Title: Dealing with dead letters in RabbitMQ\nTags: rabbitmq, messaging, amqp, dead-letter\nSource: Stack Overflow\n\nQuestion:\nTL;DR: I need to \"replay\" dead letter messages back into their original queues once I've fixed the consumer code that was originally causing the messages to be rejected.\n\nI have configured the Dead Letter Exchange (DLX) for RabbitMQ and am successfully routing rejected messages to a dead letter queue. But now I want to look at the messages in the dead letter queue and try to decide what to do with each of them. Some (many?) of these messages should be replayed (requeued) to their original queues (available in the \"x-death\" headers) once the offending consumer code has been fixed. But how do I actually go about doing this? Should I write a one-off program that reads messages from the dead letter queue and allows me to specify a target queue to send them to? And what about searching the dead letter queue? What if I know that a message (let's say which is encoded in JSON) has a certain attribute that I want to search for and replay? For example, I fix a defect which I know will allow message with PacketId: 1234 to successfully process now. I could also write a one-off program for this I suppose.\n\nI certainly can't be the first one to encounter these problems and I'm wondering if anyone else has already solved them. It seems like there should be some sort of Swiss Army Knife for this sort of thing. I did a pretty extensive search on Google and Stack Overflow but didn't really come up with much. The closest thing I could find were shovels but that doesn't really seem like the right tool for the job.\n\n========================================\n\nComments:\n- I didn't find the links particularly helpful but I otherwise really appreciate your thorough answer. Thanks!\n- yeah, i really didn't read those links. i was just trying to find something quickly that might help. probably should have read them before posting them. :P","metadata":{"transformedAt":"2026-08-18T18:33:20.139Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":16,"estimatedTokens":492}}236{"id":"stack-53525239","source":"stackoverflow","questionId":53525239,"title":"Front-facing REST API with an internal message queue?","tags":["spring","rest","tomcat","kubernetes","rabbitmq"],"text":"Title: Front-facing REST API with an internal message queue?\nTags: spring, rest, tomcat, kubernetes, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have created a REST API - in a few words, my client hits a particular URL and she gets back a JSON response.\n\nInternally, quite a complicated process starts when the URL is hit, and there are various services involved as a microservice architecture is being used.\n\nI was observing some performance bottlenecks and decided to switch to a message queue system. The idea is that now, once the user hits the URL, a request is published on internal message queue waiting for it to be consumed. This consumer will process and publish back on a queue and this will happen quite a few times until finally, the same node servicing the user will receive back the processed response to be delivered to the user.\n\nAn asynchronous \"fire-and-forget\" pattern is now being used. But my question is, how can the node servicing a particular person remember who it was servicing once the processed result arrives back and without blocking (i.e. it can handle several requests until the response is received)? If it makes any difference, my stack looks a little like this: TomCat, Spring, Kubernetes and RabbitMQ.\n\nIn summary, how can the request node (whose job is to push items on the queue) maintain an open connection with the client who requested a JSON response (i.e. client is waiting for JSON response) and receive back the data of the correct client?\n\n========================================\n\nTop Answer:\nOne option would be to use DeferredResult provided by spring but that means you need to maintain some pool of threads in request serving node and max no. of active threads will decide the throughput of your system. For more details on how to implement DeferredResult refer this link https://www.baeldung.com/spring-deferred-result\n\n========================================\n\nCode:\n```text\n{\"status\": \"in_progress\",\n \"retry_after_seconds\": 30,\n \"progress\": \"30%\"}\n```\n\n```text\nTaskId\n```\n\n========================================\n\nComments:\n- Is it and option for you to a) use non-blocking calls so that you can serve another requests as usual while current one is awaiting response from a backend microservice, b) return client task-id token so that she can later query for task result once it wold be ready (and thus maintaining task-id to response-json map?\n- yes both are options for me\n- Thanks for your detailed answer. It covers my problem from almost A to Z. I wish it would have had some more information on libraries e.g. how would Spring / Java / RabbitMQ handle the pool of workers you are referring to? Otherwise, it helped me get a grasp of the concept in great detail, so thanks.\n- Unfortunately I am not familiar with the Java/Spring environment. For the first approach, the keywords to search usually are: `futures`, `deferred`, `asynchronous`, `workers pool`. The second and third approaches are common to REST infrastructures and pretty straightforward to implement. I don't know if Java/Spring provides any abstractions on top of it but it's such a simple concept that you can implement it yourself.","metadata":{"transformedAt":"2026-08-18T18:33:20.140Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":40,"estimatedTokens":790}}237{"id":"stack-43406639","source":"stackoverflow","questionId":43406639,"title":"rabbitmq when to use basic reject over basic nack?","tags":["rabbitmq"],"text":"Title: rabbitmq when to use basic reject over basic nack?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nBasic nack provides facility to return negative acknowledgement for one or multiple messages. \n\nBasic reject has facility to return negative acknowledgement for only one message.\n\nDo we have any use case where we definitely need basic reject?\n\n========================================\n\nTop Answer:\nThe answer by @cantSleepNow is correct, I would also like to add one more difference which is in their default behaviour.\n\nBy default, `nack` will put the message back in the queue for later handling. You can change the setting to not re-queue with `nack`.\n\nWith `reject`, by default, the message is not re-queued by RabbitMQ but will drop the message from the queue entirely.\n\n========================================\n\nCode:\n```text\nnack\n```\n\n```text\nreject\n```\n\n```text\nnack\n```\n\n```text\nreject\n```\n\n```text\nnack\n```\n\n```text\nnack\n```\n\n```text\nnack\n```\n\n```text\nnack\n```\n\n```text\nreject\n```\n\n========================================\n\nComments:\n- *but reject also for multiple. OR nack also for multiple\n- Yeah this answer is a bit more appropriate, there is a good difference between the two (beyond sending it for one vs multiple messages). The documentation calls this out too\n- Your answer doesn't seem to be true when consuming messages from rabbitmq management. Upon retrieving the message **Nack with requeue true** and **reject with requeue true** puts the message back into the queue","metadata":{"transformedAt":"2026-08-18T18:33:20.140Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":65,"estimatedTokens":375}}238{"id":"stack-39853393","source":"stackoverflow","questionId":39853393,"title":"Set message header in rabbitmq while sending","tags":["jackson","rabbitmq","amqp","spring-amqp","spring-rabbit"],"text":"Title: Set message header in rabbitmq while sending\nTags: jackson, rabbitmq, amqp, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI want to set message header while sending a message to rabbit. \nI am using below code, but confused how to set message header in it. \n\n```\npublic static void sendMessage(String routingKey,final Object message,Class type){\n DefaultClassMapper typeMapper = new DefaultClassMapper();\n typeMapper.setDefaultType(type);\n\n Jackson2JsonMessageConverter converter = new Jackson2JsonMessageConverter();\n converter.setClassMapper(typeMapper);\n\n RabbitTemplate template = new RabbitTemplate(getConnectionFactory));\n template.setMessageConverter(converter);\n\n template.convertAndSend(routingKey, message);\n}\n```\n\nIn above method i am simply arguementing java POJO object and its type to send. I want to know where should i set message header here.\n\nHow to listen the message properties at listener end?\n\n========================================\n\nCode:\n```text\npublic static <T> void sendMessage(String routingKey,final Object message,Class<T> type){\n DefaultClassMapper typeMapper = new DefaultClassMapper();\n typeMapper.setDefaultType(type);\n\n Jackson2JsonMessageConverter converter = new Jackson2JsonMessageConverter();\n converter.setClassMapper(typeMapper);\n\n RabbitTemplate template = new RabbitTemplate(getConnectionFactory));\n template.setMessageConverter(converter);\n\n template.convertAndSend(routingKey, message);\n}\n```\n\n```text\ntemplate.convertAndSend(routingKey, message, m -> {\n m.getMessageProperties().getHeaders().put(\"foo\", \"bar\");\n m.getMessageProperties().setPriority(priority); \n return m;\n});\n```\n\n```text\ntemplate.convertAndSend(routingKey, message, new MessagePostProcessor() {\n\n @Override\n public Message postProcessMessage(Message m) throws AmqpException {\n m.getMessageProperties().getHeaders().put(\"foo\", \"bar\");\n m.getMessageProperties().setPriority(priority); \n return m;\n }\n\n});\n```\n\n========================================\n\nComments:\n- Don't put code in comments; as you can see, it's unreadable. Edit your question instead, and show all your configuration. Priority is a message property, not a message header. Use `m.getMessageProperties().setPriority(priority)`.\n- It's not necessary to call `getHeaders()` first. Could simplify to `m.getMessageProperties().setHeader(\"foo\", \"bar\");`","metadata":{"transformedAt":"2026-08-18T18:33:20.140Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":71,"estimatedTokens":606}}239{"id":"stack-3151966","source":"stackoverflow","questionId":3151966,"title":"AMQP vs Websphere MQ","tags":["messaging","rabbitmq","amqp","ibm-mq","celery"],"text":"Title: AMQP vs Websphere MQ\nTags: messaging, rabbitmq, amqp, ibm-mq, celery\nSource: Stack Overflow\n\nQuestion:\nWe're working on an application that supports AMQP for queuing. Some of our clients are using Websphere MQ. I'm just wondering at a high level how interchangeable these two protocols are in terms of functionality. I'm using celery, which should allow me to abstract out the lower-level stuff as long as I can write a Websphere MQ backend. What I'm trying to figure out is how difficult a challenge this will be.\n\nDoes Websphere MQ provide a superset of AMQP's functionality? Does either one have any \"features\" that might make my life difficult?\n\n========================================\n\nTop Answer:\nIBM MQ now supports AMQP 1.0 clients (including the existing IBM MQ Light clients) via the introduction of the AMQP channel in MQ 8.0.0.4.\n\n========================================\n\nComments:\n- Probably should post a question but what is IBM Web MQ's native transport? I thought it was MQTT but apparently that was a recent thing they added.\n- It is a proprietary wire protocol. As a rule I like open standards but one advantage that WMQ has is that IBM can change the wire protocol as needed. So when they wanted to several connections over a single socket and add read-ahead streaming as performance enhancements, they were easily able to do so, even though it meant changing the wire formats. Huge performance impact with these. Had they published the protocol, this would have been MUCH more difficult to do. However with more async on the open net, it may become necessary to support an open protocol or publish MQ's at some point.\n- Can I use AMQP channel feature in 8.0.0.4 to integrate IBM MQ with other AMQP products like RabbitMQ?\n- I suspect probably not. RabbitMQ support AMQP 0.9 protocol whereas IBM MQ support AMQP 1.0. The two protocol versions are different enough to not be interchangeable. Even if they did both use the same protocol level, neither product has the capability to connect as a client to another vendor's server - that I'm aware of. I guess may be possible to write a your own client application that uses AMQP 0.9 to interact with a RabbitMQ server and AMQP 1.0 to interact with an IBM MQ queue manager, using said application to act as a bridge between the two.","metadata":{"transformedAt":"2026-08-18T18:33:20.140Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":21,"estimatedTokens":577}}240{"id":"stack-28414484","source":"stackoverflow","questionId":28414484,"title":"How to limit concurrent message consuming based on a criteria","tags":["rabbitmq","spring-rabbit"],"text":"Title: How to limit concurrent message consuming based on a criteria\nTags: rabbitmq, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\n**The scenario** (I've simplified things):\n\n- Many end users can start jobs (heavy jobs, like rendering a big PDF for example), from a front end web application (producer).\n\n- The jobs are sent to a single durable RabbitMQ queue.\n\n- Many worker applications (consumers) processes those jobs and write the results back in a datastore.\n\nThis fairly standard pattern is working fine.\n\n**The problem**: if a user starts 10 jobs in the same minute, and only 10 worker applications are up at that time of day, this end user is effectively taking over all the compute time for himself.\n\n**The question**: How can I make sure only one job per end user is processed at any time ? (**Bonus**: some end users (admins for example) must not be throttled)\n\nAlso, I do not want the front end application to block end users from starting concurrent jobs. I just want the end users to wait for their concurrent jobs to finish one at a time.\n\n**The solution?**: Should I dynamically create one auto-delete exclusive queue per end users ? If yes, how can I tell the worker applications to start consuming this queue ? How to ensure one (and only one) worker will consume from this queue ?\n\n========================================\n\nTop Answer:\nYou would need to build something yourself to implement this as Dimos says. Here is an alternative implementation which requires an extra queue and some persistent storage.\n\n- As well as the existing queue for jobs, create a \"processable job queue\". Only jobs that satisfy your business rules are added to this queue.\n\n- Create a consumer (named \"Limiter\") for the job queue. The Limiter also needs persistent storage (e.g. Redis or a relational database) to record which jobs are currently processing. The limiter reads from the job queue and writes to the processable job queue.\nWhen a worker application finishes processing a job, it adds a \"job finished\" event to the job queue.\n\n```\n------------ ------------ ----------- \n| Producer | -> () job queue ) -> | Limiter | \n------------ ------------ ----------- \n ^ | \n | V \n | ------------------------ \n | () processable job queue ) \n job finished | ------------------------ \n | |\n | V\n | ------------------------\n \\-----| Job Processors (x10) |\n ------------------------\n```\n\nThe logic for the limiter is as follows:\n\nWhen a job message is received, check the persistent storage to see if a job is already running for the current user: \n\n- If not, record the job in the storage as running and add the job message to the processable job queue.\n\n- If an existing job is running, record the job in the storage as a pending job.\n\n- If the job is for an admin user, always add it to the processable job queue.\n\nWhen a \"job finished\" message is received, remove that job from the \"running jobs\" list in the persistent storage. Then check the storage for a pending job for that user:\n\n- If a job is found, change the status of that job from pending to running and add it to the processable job queue.\n\n- Otherwise, do nothing.\n\n- Only one instance of the limiter process can run at a time. This could be achieved either by only starting a single instance of the limiter process, or by using locking mechanisms in the persistent storage.\n\nIt's fairly heavyweight, but you can always inspect the persistent storage if you need to see what's going on.\n\n========================================\n\nCode:\n```text\n------------ ------------ ----------- \n| Producer | -> () job queue ) -> | Limiter | \n------------ ------------ ----------- \n ^ | \n | V \n | ------------------------ \n | () processable job queue ) \n job finished | ------------------------ \n | |\n | V\n | ------------------------\n \\-----| Job Processors (x10) |\n ------------------------\n```\n\n========================================\n\nComments:\n- Make one queue by one worker. So you can calc somthing like: userid % workercount, add routing like rabbitmq.com/tutorials/tutorial-five-dotnet.html. So in one time only one task from one user can be processed.\n- I see three problems with this approach: 1) the number of worker must be relatively static for this algorithm to work properly, 2) producers needs to know in real time how many consumers are up, 3) work load may not be fairly distributed amongst the workers if some users start more jobs than others. Thank you, but I was hoping someone to helps me understand how I can setup my RabbitMQ queues and exchanges to achieve this (is its possible at all :)).\n- If I understand you correctly, you need something that automatically creates and terminates the workers and evenly distributing tasks. Try to add dispatcher node or nodes depends on how many task you have. Dispatchers will add queue for user and when worker ends all user tasks it send message to dispatcher to remove queue. One worker could process multiple user queues but in your case only one worker can process one user (except admin).\n- Use redis or zookeeper to control the number of concurrent users being processed\n- Robinho, care to expand your comment into an answer?\n- @WW. , this is a little meta, but does the fact that I accepted an answer invalidated your bounty ? I do not know how to behave in this situation. Maybe I can un-accept Dimos 's answer, and wait until YOU are satisfied with an answer ?\n- It's your question, accept the answer you like best.\n- So there is a Zookeeper lock for each end user that might upload a file? If the first message on the low-priority queue is for a user already processing something, then no worker will be able to process any of the messages on that queue? Or am I misunderstanding?\n- My question is a couple months old now. I have now switched to SQS instead of RabbitMQ. But my original question remains, I still have this problem with my SQS based implementation. I will probably try to implement what you are proposing in this answer. Since I already use polling SQS, this part is ok. But I do not want to add an other component to my stack, so I will not use Zookeeper, but Redis (I already use it for caching and counters). Anyways, thank you for this answer. I accept it.\n- @WW. there is a single (global) lock for all the messages of the low-priority queue. Each of the 10 worker processes should first acquire this lock, before reading a message from the queue. Furthermore, every worker must release the lock after having processed the message. Essentially, the read-process-ack processing of a message is being converted into a critical section in this way, so at most one worker can execute it at all times.\n- @Pierre-DavidBelange, as an afterthough, polling is not necessary. You can implement it with pub/sub, but the queue will have to notify all the workers for each new member and only the first to acquire the lock will consume it. Redis can also be an equal alternative to Zookeeper, since you can use optimistic locking & watches, to create a highly scalable solution.\n- Thank you for this answer. This `Limiter` concept with a persistent storage feels indeed heavyweight. Also I do not like the fact that this process will somehow be a single point of failure.\n- You could start multiple instances of the Limiter process across multiple servers and rely on the locking mechanism in the persistent storage to ensure that only one Limiter can process at a time. That way, if one server failed, the other Limiter processes would continue processing.\n- Indeed, sorry, you are right. Only one limiter process can run at a time, but many can be started.","metadata":{"transformedAt":"2026-08-18T18:33:20.140Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":105,"estimatedTokens":1983}}241{"id":"stack-25869858","source":"stackoverflow","questionId":25869858,"title":"Celery: Error in connecting to RabbitMQ Server","tags":["python-2.7","rabbitmq","celery"],"text":"Title: Celery: Error in connecting to RabbitMQ Server\nTags: python-2.7, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI am starting to use celery by following this \"First Steps with Celery\".\nI exactly used the tasks.py indicated on that link.\nHowever when I ran the task using,\n\n```\ncelery -A tasks worker --loglevel=info\n```\n\nI am getting this error:\n\n```\n[2014-09-16 20:52:57,427: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: Socket closed. Trying again in 2.00 seconds...\n```\n\nThe rabbitmq server is for sure running and below is the snippet of the log regarding the error:\n\n```\n=ERROR REPORT==== 16-Sep-2014::20:53:09 ===\nexception on TCP connection from 127.0.0.1:58162\n{channel0_error,starting,\n {amqp_error,access_refused,\n \"AMQPLAIN login refused: user 'guest' - invalid credentials\",\n 'connection.start_ok'}}\n\n=INFO REPORT==== 16-Sep-2014::20:53:09 ===\nclosing TCP connection from 127.0.0.1:58162\n\n=INFO REPORT==== 16-Sep-2014::20:53:15 ===\naccepted TCP connection on [::]:5672 from 127.0.0.1:58163\n\n=INFO REPORT==== 16-Sep-2014::20:53:15 ===\nstarting TCP connection from 127.0.0.1:58163\n\n=ERROR REPORT==== 16-Sep-2014::20:53:18 ===\nexception on TCP connection from 127.0.0.1:58163\n{channel0_error,starting,\n {amqp_error,access_refused,\n \"AMQPLAIN login refused: user 'guest' - invalid credentials\",\n 'connection.start_ok'}}\n\n=INFO REPORT==== 16-Sep-2014::20:53:18 ===\nclosing TCP connection from 127.0.0.1:58163\n```\n\nWith this, I did the following to ensure that the 'guest' user has permissions to / vhost:\n\n```\nsudo rabbitmqctl set_permissions -p / guest \".*\" \".*\" \".*\"\n```\n\nAnd then I reloaded/restarted rabbitmq service to make sure the changes will take effect,\nthen ran the task again. However, the error is still the same.\n\nI even tried creating a different vhost (jm-vhost) and user (jm-user1) and set the permission again to allow all:\n\n```\nsudo rabbitmqctl add_vhost jm-vhost\nsudo rabbitmqctl add_user jm-user1 \"\" --> \"\" to make it passwordless (is this correct?)\nsudo rabbitmqctl set_permissions -p /jm-vhost jm-user1 \".*\" \".*\" \".*\"\n```\n\nAnd then modified tasks.py to this:\n\n```\napp = Celery('tasks', broker='amqp://jm-user1@localhost//jm-vhost')\n```\n\nBut when I started the tasks, still, I get the same error.\nHow should I resolve this? Thanks in advance!\n\n========================================\n\nTop Answer:\nThe `broker_url` has the format:\n\n```\ntransport://userid:password@hostname:port/virtual_host\n```\n\n http://docs.celeryproject.org/en/latest/userguide/configuration.html#broker-url\n\n========================================\n\nCode:\n```text\ncelery -A tasks worker --loglevel=info\n```\n\n```text\n[2014-09-16 20:52:57,427: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: Socket closed. Trying again in 2.00 seconds...\n```\n\n```text\n=ERROR REPORT==== 16-Sep-2014::20:53:09 ===\nexception on TCP connection <0.235.0> from 127.0.0.1:58162\n{channel0_error,starting,\n {amqp_error,access_refused,\n \"AMQPLAIN login refused: user 'guest' - invalid credentials\",\n 'connection.start_ok'}}\n\n=INFO REPORT==== 16-Sep-2014::20:53:09 ===\nclosing TCP connection <0.235.0> from 127.0.0.1:58162\n\n=INFO REPORT==== 16-Sep-2014::20:53:15 ===\naccepted TCP connection on [::]:5672 from 127.0.0.1:58163\n\n=INFO REPORT==== 16-Sep-2014::20:53:15 ===\nstarting TCP connection <0.239.0> from 127.0.0.1:58163\n\n=ERROR REPORT==== 16-Sep-2014::20:53:18 ===\nexception on TCP connection <0.239.0> from 127.0.0.1:58163\n{channel0_error,starting,\n {amqp_error,access_refused,\n \"AMQPLAIN login refused: user 'guest' - invalid credentials\",\n 'connection.start_ok'}}\n\n=INFO REPORT==== 16-Sep-2014::20:53:18 ===\nclosing TCP connection <0.239.0> from 127.0.0.1:58163\n```\n\n```text\nsudo rabbitmqctl set_permissions -p / guest \".*\" \".*\" \".*\"\n```\n\n```text\nsudo rabbitmqctl add_vhost jm-vhost\nsudo rabbitmqctl add_user jm-user1 \"\" --> \"\" to make it passwordless (is this correct?)\nsudo rabbitmqctl set_permissions -p /jm-vhost jm-user1 \".*\" \".*\" \".*\"\n```\n\n```text\napp = Celery('tasks', broker='amqp://jm-user1@localhost//jm-vhost')\n```\n\n```text\nsudo rabbitmqctl add_user jm-user1 sample\n```\n\n```text\nsudo rabbitmqctl set_permissions -p jm-vhost jm-user1 \".*\" \".*\" \".*\"\n```\n\n```text\napp = Celery('tasks', broker='amqp://jm-user1:sample@localhost/jm-vhost')\n```\n\n```text\ncelery -A tasks worker --loglevel=info\n```\n\n```text\ntransport://userid:password@hostname:port/virtual_host\n```\n\n```text\nbroker_url\n```\n\n========================================\n\nComments:\n- Another thing I've found is that if you want to do this programmatically, use this syntax, just like this: subprocess.call(['rabbitmqctl', 'set_permissions', '-p', 'vhost_name', 'joe_user', '.*', '.*', '.*'])\n- My problem was that my password had a bracket and a dollar sign in it. I removed those characters and everything worked.","metadata":{"transformedAt":"2026-08-18T18:33:20.140Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":168,"estimatedTokens":1239}}242{"id":"stack-21453910","source":"stackoverflow","questionId":21453910,"title":"Is it possible to run more than one rabbitmq instance on one machine?","tags":["rabbitmq"],"text":"Title: Is it possible to run more than one rabbitmq instance on one machine?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI want to build a RabbitMQ cluster in my dev machine (windows).\n\nreason is that I would like to test and study it. \n\nIs it possible to run more than one rabbitmq instance on one machine?\n\nI am guessing I need to:\n\n- Change the listening port\n\n- Change the appdata folder (C:\\Users\\MyUser\\AppData\\Roaming)\n\n- Change the ui plugin port so I can view all instances.\n\n- Remove the service and run from cli\n\nHas anyone tried it? \nIs there a known guide?\n\n========================================\n\nTop Answer:\nNow the official RabbitMQ documentation contains a section **\"A Cluster on a Single Machine\"**, which describes how to run multiple Rabbit nodes on a single machine.\n\nSee https://www.rabbitmq.com/clustering.html#single-machine\n\n========================================\n\nComments:\n- Thanks. The following three were enough to do the Job - RABBITMQ_NODENAME, RABBITMQ_BASE, RABBITMQ_NODE_PORT\n- I'm not sure how it fits with rabbitmq clusters, but another option is to use docker. Bring up multiple docker containers and bind them to different ports on the local host.\n- Thanks. I did mean a physical machine. Eventually I did the following 1. I have created three folders 2. edit the run script to update different ports 3. edited the config file to to update different ports for the ui plugin. Did the job.\n- Don't forget, you'll still need some form of load balancer to broker requests between the instances if you want to test out the cluster in action.\n- Is this what HAProxy is for?\n- Yep. HAProxy is a load balancing proxy. If you are going to cluster Rabbit then you need to only expose a single endpoint as you won't know which one might fail. HAProxy takes care of proxying requests to live members of the cluster as it is able to determine whether a node is down or not. See: haproxy.1wt.eu","metadata":{"transformedAt":"2026-08-18T18:33:20.140Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":40,"estimatedTokens":483}}243{"id":"stack-9508246","source":"stackoverflow","questionId":9508246,"title":"RabbitMQ, Pika and reconnection strategy","tags":["python","rabbitmq","pika"],"text":"Title: RabbitMQ, Pika and reconnection strategy\nTags: python, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI'm using Pika to process data from RabbitMQ.\nAs I seemed to run into different kind of problems I decided to write a small test application to see how I can handle disconnects.\n\nI wrote this test app which does following:\n\n- Connect to Broker, retry until successful\n\n- When connected create a queue.\n\n- Consume this queue and put result into a python Queue.Queue(0)\n\n- Get item from Queue.Queue(0) and produce it back into the broker queue.\n\nWhat I noticed were 2 issues:\n\n- When I run my script from one host connecting to rabbitmq on another host (inside a vm) then this scripts exits on random moments without producing an error.\n\n- When I run my script on the same host on which RabbitMQ is installed it runs fine and keeps running.\n\nThis might be explained because of network issues, packets dropped although I find the connection not really robust.\n\nWhen the script runs locally on the RabbitMQ server and I kill the RabbitMQ then the script exits with error: \"ERROR pika SelectConnection: Socket Error on 3: 104\"\n\nSo it looks like I can't get the reconnection strategy working as it should be. Could someone have a look at the code so see what I'm doing wrong?\n\nThanks,\n\nJay\n\n```\n#!/bin/python\nimport logging\nimport threading\nimport Queue\nimport pika\nfrom pika.reconnection_strategies import SimpleReconnectionStrategy\nfrom pika.adapters import SelectConnection\nimport time\nfrom threading import Lock\n\nclass Broker(threading.Thread):\n def __init__(self):\n threading.Thread.__init__(self)\n self.logging = logging.getLogger(__name__)\n self.to_broker = Queue.Queue(0)\n self.from_broker = Queue.Queue(0)\n self.parameters = pika.ConnectionParameters(host='sandbox',heartbeat=True)\n self.srs = SimpleReconnectionStrategy()\n self.properties = pika.BasicProperties(delivery_mode=2)\n\n self.connection = None\n while True:\n try:\n self.connection = SelectConnection(self.parameters, self.on_connected, reconnection_strategy=self.srs)\n break\n except Exception as err:\n self.logging.warning('Cant connect. Reason: %s' % err)\n time.sleep(1)\n\n self.daemon=True\n def run(self):\n while True:\n self.submitData(self.from_broker.get(block=True))\n pass\n def on_connected(self,connection):\n connection.channel(self.on_channel_open)\n def on_channel_open(self,new_channel):\n self.channel = new_channel\n self.channel.queue_declare(queue='sandbox', durable=True)\n self.channel.basic_consume(self.processData, queue='sandbox') \n def processData(self, ch, method, properties, body):\n self.logging.info('Received data from broker')\n self.channel.basic_ack(delivery_tag=method.delivery_tag)\n self.from_broker.put(body)\n def submitData(self,data):\n self.logging.info('Submitting data to broker.')\n self.channel.basic_publish(exchange='',\n routing_key='sandbox',\n body=data,\n properties=self.properties)\nif __name__ == '__main__':\n format=('%(asctime)s %(levelname)s %(name)s %(message)s')\n logging.basicConfig(level=logging.DEBUG, format=format)\n broker=Broker()\n broker.start()\n try:\n broker.connection.ioloop.start()\n except Exception as err:\n print err\n```\n\n========================================\n\nCode:\n```text\n#!/bin/python\nimport logging\nimport threading\nimport Queue\nimport pika\nfrom pika.reconnection_strategies import SimpleReconnectionStrategy\nfrom pika.adapters import SelectConnection\nimport time\nfrom threading import Lock\n\nclass Broker(threading.Thread):\n def __init__(self):\n threading.Thread.__init__(self)\n self.logging = logging.getLogger(__name__)\n self.to_broker = Queue.Queue(0)\n self.from_broker = Queue.Queue(0)\n self.parameters = pika.ConnectionParameters(host='sandbox',heartbeat=True)\n self.srs = SimpleReconnectionStrategy()\n self.properties = pika.BasicProperties(delivery_mode=2)\n\n self.connection = None\n while True:\n try:\n self.connection = SelectConnection(self.parameters, self.on_connected, reconnection_strategy=self.srs)\n break\n except Exception as err:\n self.logging.warning('Cant connect. Reason: %s' % err)\n time.sleep(1)\n\n self.daemon=True\n def run(self):\n while True:\n self.submitData(self.from_broker.get(block=True))\n pass\n def on_connected(self,connection):\n connection.channel(self.on_channel_open)\n def on_channel_open(self,new_channel):\n self.channel = new_channel\n self.channel.queue_declare(queue='sandbox', durable=True)\n self.channel.basic_consume(self.processData, queue='sandbox') \n def processData(self, ch, method, properties, body):\n self.logging.info('Received data from broker')\n self.channel.basic_ack(delivery_tag=method.delivery_tag)\n self.from_broker.put(body)\n def submitData(self,data):\n self.logging.info('Submitting data to broker.')\n self.channel.basic_publish(exchange='',\n routing_key='sandbox',\n body=data,\n properties=self.properties)\nif __name__ == '__main__':\n format=('%(asctime)s %(levelname)s %(name)s %(message)s')\n logging.basicConfig(level=logging.DEBUG, format=format)\n broker=Broker()\n broker.start()\n try:\n broker.connection.ioloop.start()\n except Exception as err:\n print err\n```\n\n```text\nimport logging\nimport pika\nimport Queue\nimport sys\nimport threading\nimport time\nfrom functools import partial\nfrom pika.adapters import SelectConnection, BlockingConnection\nfrom pika.exceptions import AMQPConnectionError\nfrom pika.reconnection_strategies import SimpleReconnectionStrategy\n\nlog = logging.getLogger(__name__)\n\nDEFAULT_PROPERTIES = pika.BasicProperties(delivery_mode=2)\n\n\nclass Broker(object):\n\n def __init__(self, parameters, on_channel_open, name='broker'):\n self.parameters = parameters\n self.on_channel_open = on_channel_open\n self.name = name\n\n def connect(self, forever=False):\n name = self.name\n while True:\n try:\n connection = SelectConnection(\n self.parameters, self.on_connected)\n log.debug('%s connected', name)\n except Exception:\n if not forever:\n raise\n log.warning('%s cannot connect', name, exc_info=True)\n time.sleep(10)\n continue\n\n try:\n connection.ioloop.start()\n finally:\n try:\n connection.close()\n connection.ioloop.start() # allow connection to close\n except Exception:\n pass\n\n if not forever:\n break\n\n def on_connected(self, connection):\n connection.channel(self.on_channel_open)\n\n\ndef setup_submitter(channel, data_queue, properties=DEFAULT_PROPERTIES):\n def on_queue_declared(frame):\n # PROBLEM pika does not appear to have a way to detect delivery\n # failure, which means that data could be lost if the connection\n # drops...\n channel.confirm_delivery(on_delivered)\n submit_data()\n\n def on_delivered(frame):\n if frame.method.NAME in ['Confirm.SelectOk', 'Basic.Ack']:\n log.info('submission confirmed %r', frame)\n # increasing this value seems to cause a higher failure rate\n time.sleep(0)\n submit_data()\n else:\n log.warn('submission failed: %r', frame)\n #data_queue.put(...)\n\n def submit_data():\n log.info('waiting on data queue')\n data = data_queue.get()\n log.info('got data to submit')\n channel.basic_publish(exchange='',\n routing_key='sandbox',\n body=data,\n properties=properties,\n mandatory=True)\n log.info('submitted data to broker')\n\n channel.queue_declare(\n queue='sandbox', durable=True, callback=on_queue_declared)\n\n\ndef blocking_submitter(parameters, data_queue,\n properties=DEFAULT_PROPERTIES):\n while True:\n try:\n connection = BlockingConnection(parameters)\n channel = connection.channel()\n channel.queue_declare(queue='sandbox', durable=True)\n except Exception:\n log.error('connection failure', exc_info=True)\n time.sleep(1)\n continue\n while True:\n log.info('waiting on data queue')\n try:\n data = data_queue.get(timeout=1)\n except Queue.Empty:\n try:\n connection.process_data_events()\n except AMQPConnectionError:\n break\n continue\n log.info('got data to submit')\n try:\n channel.basic_publish(exchange='',\n routing_key='sandbox',\n body=data,\n properties=properties,\n mandatory=True)\n except Exception:\n log.error('submission failed', exc_info=True)\n data_queue.put(data)\n break\n log.info('submitted data to broker')\n\n\ndef setup_receiver(channel, data_queue):\n def process_data(channel, method, properties, body):\n log.info('received data from broker')\n data_queue.put(body)\n channel.basic_ack(delivery_tag=method.delivery_tag)\n\n def on_queue_declared(frame):\n channel.basic_consume(process_data, queue='sandbox')\n\n channel.queue_declare(\n queue='sandbox', durable=True, callback=on_queue_declared)\n\n\nif __name__ == '__main__':\n if len(sys.argv) != 2:\n print 'usage: %s RABBITMQ_HOST' % sys.argv[0]\n sys.exit()\n\n format=('%(asctime)s %(levelname)s %(name)s %(message)s')\n logging.basicConfig(level=logging.DEBUG, format=format)\n\n host = sys.argv[1]\n log.info('connecting to host: %s', host)\n parameters = pika.ConnectionParameters(host=host, heartbeat=True)\n data_queue = Queue.Queue(0)\n data_queue.put('message') # prime the pump\n\n # run submitter in a thread\n\n setup = partial(setup_submitter, data_queue=data_queue)\n broker = Broker(parameters, setup, 'submitter')\n thread = threading.Thread(target=\n partial(broker.connect, forever=True))\n\n # uncomment these lines to use the blocking variant of the submitter\n #thread = threading.Thread(target=\n # partial(blocking_submitter, parameters, data_queue))\n\n thread.daemon = True\n thread.start()\n\n # run receiver in main thread\n setup = partial(setup_receiver, data_queue=data_queue)\n broker = Broker(parameters, setup, 'receiver')\n broker.connect(forever=True)\n```\n\n```text\nsubmitData\n```\n\n```text\nSimpleReconnectionStrategy\n```\n\n```text\nbasic_publish\n```\n\n```text\nadd_on_return_callback\n```\n\n========================================\n\nComments:\n- Thanks for taking the time going through the code and finding all the issues related to it. I'm currently using barryp.org/software/py-amqplib which is imo a more basic/simpler library but suits my needs completely. In combination with gevent I have some really nice results. I don't bother anymore with Pika these days.\n- you can use Channel.confirm_delivery() to wait for ack after published, once the connection closed, it will timeout then you will know the message is not delivered to broker\n- \"Pika does not appear to have a way to detect delivery failure, which means that data may be lost if the connection drops\" - this is **not true**. If you use publisher confirms, you will know when your messages are delivered. At some point I will provide code showing this but you can use the java tutorial as an example of the concept.","metadata":{"transformedAt":"2026-08-18T18:33:20.140Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":352,"estimatedTokens":2966}}244{"id":"stack-36579759","source":"stackoverflow","questionId":36579759,"title":"Golang - RabbitMq : channel/connection is not open","tags":["go","rabbitmq"],"text":"Title: Golang - RabbitMq : channel/connection is not open\nTags: go, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm new to golang, and I would like to refactorate my code so that the rabbitmq initialization is in another function that main. So I use a struct pointer (containing all the rabbitmq infos initilized) and pass it to the send function, but it tells me : Failed to publish a message: Exception (504) Reason: \"channel/connection is not open\"\n\nstruct :\n\n```\ntype RbmqConfig struct {\n q amqp.Queue\n ch *amqp.Channel\n conn *amqp.Connection\n rbmqErr error\n}\n```\n\nthe init function :\n\n```\nfunc initRabbitMq() *RbmqConfig {\n\n config := &RbmqConfig{}\n\n config.conn, config.rbmqErr = amqp.Dial(\"amqp://guest:guest@localhost:5672/\")\n failOnError(config.rbmqErr, \"Failed to connect to RabbitMQ\")\n defer config.conn.Close()\n\n config.ch, config.rbmqErr = config.conn.Channel()\n failOnError(config.rbmqErr, \"Failed to open a channel\")\n defer config.ch.Close()\n\n config.q, config.rbmqErr = config.ch.QueueDeclare(\n \"\",\n true, // durable\n false, // delete when unused\n false, // exclusive\n false, // no-wait\n nil, // arguments\n )\n failOnError(config.rbmqErr, \"Failed to declare a queue\")\n\n return config\n}\n```\n\nmain :\n\n```\nconfig := initRabbitMq()\n\nfmt.Println(\"queue name : \", config.q.Name)\n\nsendMessage(config, )\n```\n\nin send message :\n\n```\nfunc sendMessage(config *RbmqConfig, ) {\n\n config.rbmqErr = config.ch.Publish(\n \"\", // exchange\n config.q.Name, // routing key\n false, // mandatory\n false,\n amqp.Publishing{\n DeliveryMode: amqp.Persistent,\n ContentType: \"text/plain\",\n Body: []byte(),\n })\n failOnError(config.rbmqErr, \"Failed to publish a message\")\n```\n\nIf someone has any idea, that would be very helpful. Thank you in advance\n\n========================================\n\nCode:\n```text\ntype RbmqConfig struct {\n q amqp.Queue\n ch *amqp.Channel\n conn *amqp.Connection\n rbmqErr error\n}\n```\n\n```text\nfunc initRabbitMq() *RbmqConfig {\n\n config := &RbmqConfig{}\n\n config.conn, config.rbmqErr = amqp.Dial(\"amqp://guest:guest@localhost:5672/\")\n failOnError(config.rbmqErr, \"Failed to connect to RabbitMQ\")\n defer config.conn.Close()\n\n config.ch, config.rbmqErr = config.conn.Channel()\n failOnError(config.rbmqErr, \"Failed to open a channel\")\n defer config.ch.Close()\n\n config.q, config.rbmqErr = config.ch.QueueDeclare(\n \"<my_queue_name>\",\n true, // durable\n false, // delete when unused\n false, // exclusive\n false, // no-wait\n nil, // arguments\n )\n failOnError(config.rbmqErr, \"Failed to declare a queue\")\n\n return config\n}\n```\n\n```text\nconfig := initRabbitMq()\n\nfmt.Println(\"queue name : \", config.q.Name)\n\nsendMessage(config, <message_to_send>)\n```\n\n```text\nfunc sendMessage(config *RbmqConfig, <message_to_send>) {\n\n config.rbmqErr = config.ch.Publish(\n \"\", // exchange\n config.q.Name, // routing key\n false, // mandatory\n false,\n amqp.Publishing{\n DeliveryMode: amqp.Persistent,\n ContentType: \"text/plain\",\n Body: []byte(<message_to_send>),\n })\n failOnError(config.rbmqErr, \"Failed to publish a message\")\n```\n\n```text\ninit\n```\n\n```text\ndefer config.conn.Close()\n```\n\n```text\ninit\n```\n\n========================================\n\nComments:\n- I know its good practice to close the connection, but just out of curiosity, what happens if I don't close it\n- I had the same issue, basically the name of the exchange should not be the name of the queue\n- @nixon-kosgei rabbitmq use tcp connection. The tcp connection underneath if not closed will be hang forever until the golang code exit. Which cause the server consume more resources to keep the tcp connection open.","metadata":{"transformedAt":"2026-08-18T18:33:20.140Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":7,"totalLines":158,"estimatedTokens":944}}245{"id":"stack-13037121","source":"stackoverflow","questionId":13037121,"title":"In Pika or RabbitMQ, How do I check if any consumers are currently consuming?","tags":["python","rabbitmq","pika"],"text":"Title: In Pika or RabbitMQ, How do I check if any consumers are currently consuming?\nTags: python, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI would like to check if a *Consumer/Worker* is present to consume a *Message* I am about to send.\n\nIf there isn't any *Worker*, I would start some workers (both consumers and publishers are on a single machine) and then go about publishing *Messages*.\n\nIf there is a function like `connection.check_if_has_consumers`, I would implement it somewhat like this - \n\n```\nimport pika\nimport workers\n\n# code for publishing to worker queue\nconnection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))\nchannel = connection.channel()\n\n# if there are no consumers running (would be nice to have such a function)\nif not connection.check_if_has_consumers(queue=\"worker_queue\", exchange=\"\"):\n # start the workers in other processes, using python's `multiprocessing`\n workers.start_workers()\n\n# now, publish with no fear of your queues getting filled up\nchannel.queue_declare(queue=\"worker_queue\", auto_delete=False, durable=True)\nchannel.basic_publish(exchange=\"\", routing_key=\"worker_queue\", body=\"rockin\",\n properties=pika.BasicProperties(delivery_mode=2))\nconnection.close()\n```\n\nBut I am unable to find any function with `check_if_has_consumers` functionality in *pika*.\n\nIs there some way of accomplishing this, using *pika*? or maybe, by *talking* to ***The Rabbit*** directly?\n\nI am not completely sure, but I really think *RabbitMQ* would be aware of the number of consumers subscribed to different queues, since it does dispatch *messages* to them and accepts *acks*\n\nI just got started with *RabbitMQ* 3 hours ago... any help is welcome...\n\nhere is the **workers.py** code I wrote, if its any help....\n\n```\nimport multiprocessing\nimport pika\n\ndef start_workers(num=3):\n \"\"\"start workers as non-daemon processes\"\"\"\n for i in xrange(num): \n process = WorkerProcess()\n process.start()\n\nclass WorkerProcess(multiprocessing.Process):\n \"\"\"\n worker process that waits infinitly for task msgs and calls\n the `callback` whenever it gets a msg\n \"\"\"\n def __init__(self):\n multiprocessing.Process.__init__(self)\n self.stop_working = multiprocessing.Event()\n\n def run(self):\n \"\"\"\n worker method, open a channel through a pika connection and\n start consuming\n \"\"\"\n connection = pika.BlockingConnection(\n pika.ConnectionParameters(host='localhost')\n )\n channel = connection.channel()\n channel.queue_declare(queue='worker_queue', auto_delete=False,\n durable=True)\n\n # don't give work to one worker guy until he's finished\n channel.basic_qos(prefetch_count=1)\n channel.basic_consume(callback, queue='worker_queue')\n\n # do what `channel.start_consuming()` does but with stopping signal\n while len(channel._consumers) and not self.stop_working.is_set():\n channel.transport.connection.process_data_events()\n\n channel.stop_consuming()\n connection.close()\n return 0\n\n def signal_exit(self):\n \"\"\"exit when finished with current loop\"\"\"\n self.stop_working.set()\n\n def exit(self):\n \"\"\"exit worker, blocks until worker is finished and dead\"\"\"\n self.signal_exit()\n while self.is_alive(): # checking `is_alive()` on zombies kills them\n time.sleep(1)\n\n def kill(self):\n \"\"\"kill now! should not use this, might create problems\"\"\"\n self.terminate()\n self.join()\n\ndef callback(channel, method, properties, body):\n \"\"\"pika basic consume callback\"\"\"\n print 'GOT:', body\n # do some heavy lifting here\n result = save_to_database(body)\n print 'DONE:', result\n channel.basic_ack(delivery_tag=method.delivery_tag)\n```\n\n**EDIT:**\n\nI have to move forward so here is a workaround that I am going to take, unless a better approach comes along,\n\nSo, *RabbitMQ* has these HTTP management apis, they work after you have turned on the management plugin and at middle of HTTP apis page there is \n\n /api/connections - A list of all open connections.\n\n \n /api/connections/name - An individual connection. DELETEing it will close the connection.\n\nSo, if I connect my *Workers* and my *Produces* both by different *Connection* names / users, I'll be able to check if the *Worker Connection* is open... (there might be issues when worker dies...)\n\nwill be waiting for a better solution...\n\n**EDIT:**\n\njust found this in the rabbitmq docs, but this would be hacky to do in python:\n\n```\nshobhit@oracle:~$ sudo rabbitmqctl -p vhostname list_queues name consumers\nListing queues ...\nworker_queue 0\n...done.\n```\n\nso i could do something like, \n\n```\nsubprocess.call(\"echo password|sudo -S rabbitmqctl -p vhostname list_queues name consumers | grep 'worker_queue'\")\n```\n\nhacky... still hope pika has some python function to do this...\n\nThanks,\n\n========================================\n\nTop Answer:\nI actually found this on accident looking for a different issue, but one thing that may help you is on the Basic_Publish function, there is a parameter \"Immediate\" which is defaulted to False.\n\nOne idea you could do is to set the Immediate Flag to True, which will require it to be consumed by a consumer immediately, instead of sitting in a queue. If a worker is not available to consume the message, it will kick back an error, telling you to start another worker.\n\nDepending on the throughput of your system, this would either be spawning a lot of extra workers, or spawning workers to replace dead workers. For the former issue you can write an admin-like system that simply tracks workers via a control queue, where you can tell a \"Runner\" like process to kill processes of workers that are now no longer necessary.\n\n========================================\n\nCode:\n```text\nimport pika\nimport workers\n\n# code for publishing to worker queue\nconnection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))\nchannel = connection.channel()\n\n# if there are no consumers running (would be nice to have such a function)\nif not connection.check_if_has_consumers(queue=\"worker_queue\", exchange=\"\"):\n # start the workers in other processes, using python's `multiprocessing`\n workers.start_workers()\n\n# now, publish with no fear of your queues getting filled up\nchannel.queue_declare(queue=\"worker_queue\", auto_delete=False, durable=True)\nchannel.basic_publish(exchange=\"\", routing_key=\"worker_queue\", body=\"rockin\",\n properties=pika.BasicProperties(delivery_mode=2))\nconnection.close()\n```\n\n```text\nimport multiprocessing\nimport pika\n\n\ndef start_workers(num=3):\n \"\"\"start workers as non-daemon processes\"\"\"\n for i in xrange(num): \n process = WorkerProcess()\n process.start()\n\n\nclass WorkerProcess(multiprocessing.Process):\n \"\"\"\n worker process that waits infinitly for task msgs and calls\n the `callback` whenever it gets a msg\n \"\"\"\n def __init__(self):\n multiprocessing.Process.__init__(self)\n self.stop_working = multiprocessing.Event()\n\n def run(self):\n \"\"\"\n worker method, open a channel through a pika connection and\n start consuming\n \"\"\"\n connection = pika.BlockingConnection(\n pika.ConnectionParameters(host='localhost')\n )\n channel = connection.channel()\n channel.queue_declare(queue='worker_queue', auto_delete=False,\n durable=True)\n\n # don't give work to one worker guy until he's finished\n channel.basic_qos(prefetch_count=1)\n channel.basic_consume(callback, queue='worker_queue')\n\n # do what `channel.start_consuming()` does but with stopping signal\n while len(channel._consumers) and not self.stop_working.is_set():\n channel.transport.connection.process_data_events()\n\n channel.stop_consuming()\n connection.close()\n return 0\n\n def signal_exit(self):\n \"\"\"exit when finished with current loop\"\"\"\n self.stop_working.set()\n\n def exit(self):\n \"\"\"exit worker, blocks until worker is finished and dead\"\"\"\n self.signal_exit()\n while self.is_alive(): # checking `is_alive()` on zombies kills them\n time.sleep(1)\n\n def kill(self):\n \"\"\"kill now! should not use this, might create problems\"\"\"\n self.terminate()\n self.join()\n\n\ndef callback(channel, method, properties, body):\n \"\"\"pika basic consume callback\"\"\"\n print 'GOT:', body\n # do some heavy lifting here\n result = save_to_database(body)\n print 'DONE:', result\n channel.basic_ack(delivery_tag=method.delivery_tag)\n```\n\n```text\nshobhit@oracle:~$ sudo rabbitmqctl -p vhostname list_queues name consumers\nListing queues ...\nworker_queue 0\n...done.\n```\n\n```text\nsubprocess.call(\"echo password|sudo -S rabbitmqctl -p vhostname list_queues name consumers | grep 'worker_queue'\")\n```\n\n```text\nconnection.check_if_has_consumers\n```\n\n```text\ncheck_if_has_consumers\n```\n\n```text\n@property\ndef consumer_tags(self):\n \"\"\"Property method that returns a list of currently active consumers\n\n :rtype: list\n\n \"\"\"\n return self._consumers.keys()\n```\n\n```text\nif len(self._channel.consumer_tags) == 0:\n LOGGER.info(\"Nobody is listening. I'll come back in a couple of minutes.\")\n ...\n```\n\n========================================\n\nComments:\n- Just a note, if you try to do this in Kombu, it will not work because despite being an argument to `Producer.publish`, `immediate` is not supported: docs.celeryq.dev/projects/kombu/en/latest/reference/…","metadata":{"transformedAt":"2026-08-18T18:33:20.140Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":286,"estimatedTokens":2358}}246{"id":"stack-23341811","source":"stackoverflow","questionId":23341811,"title":"How is concurrency in Spring AMQP Listener Container implemented?","tags":["java","spring","rabbitmq","amqp","spring-amqp"],"text":"Title: How is concurrency in Spring AMQP Listener Container implemented?\nTags: java, spring, rabbitmq, amqp, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nMy container XML config:\n\n```\n\n \n\n```\n\nand `myListener` is just a class\n\n```\n@Component(\"myListener\")\npublic class MyListener implements MessageListener {\n @Autowired\n SomeDependency dependency;\n ....\n}\n```\n\nI've specified `concurrency=\"10\"` in my XML. What does this mean **exactly**?\n\nI've found some docs. They are not that helpful stating:\n\n Specify the number of concurrent consumers to create. Default is 1.\n\nWhat I am interested in is whether `MyListener` has to be thread safe i.e.\n\n- are there many instances created or single instance used by many threads?\n\n- can I access instance fields w/o synchronization?\n\n- is `SomeDependency dependency` instantiated once or for each thread/instance?\n\n- does `dependency` need to be thread safe?\n\n========================================\n\nCode:\n```text\n<rabbit:listener-container\n connection-factory=\"myConnectionFactory\"\n acknowledge=\"none\"\n concurrency=\"10\"\n requeue-rejected=\"false\">\n <rabbit:listener ref=\"myListener\" queues=\"myQueue\"/>\n</rabbit:listener-container>\n```\n\n```text\n@Component(\"myListener\")\npublic class MyListener implements MessageListener {\n @Autowired\n SomeDependency dependency;\n ....\n}\n```\n\n```text\nmyListener\n```\n\n```text\nconcurrency=\"10\"\n```\n\n```text\nMyListener\n```\n\n```text\nSomeDependency dependency\n```\n\n```text\ndependency\n```\n\n```text\n<rabbit:listener-container\n connection-factory=\"myConnectionFactory\"\n acknowledge=\"none\"\n requeue-rejected=\"false\">\n <rabbit:listener ref=\"myListener\" queues=\"myQueue\"/>\n <rabbit:listener ref=\"myListener\" queues=\"myQueue\"/>\n <rabbit:listener ref=\"myListener\" queues=\"myQueue\"/>\n <rabbit:listener ref=\"myListener\" queues=\"myQueue\"/>\n ...\n</rabbit:listener-container>\n```\n\n```text\n<rabbit:listener-container/>\n```\n\n```text\n@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)\n```\n\n========================================\n\nComments:\n- I want to be sure I understand correctly: in my example there are 10 `listener-containers`, each holding the one and only `MyListener` instance, correct? In your example there are 10 containers, each with their own listener? Is it somehow possible to keep my approach (using `concurrency`) and make `Dependency` separate for each `listener-container` ?\n- No; in your example there is 1 listener container with 10 consumer threads; in mine there are 10 containers each with one thread. Using prototype scope means each container gets its own instance; so your listener doesn't need to be thread-safe. Without `prototype` scope, each container would get a reference to the same instance - effectively no different (functionally) to your original case. Remember to make all downstream dependencies `prototype` scope too. Like I said, it's generally best to try to make your listener, and its dependencies, stateless to avoid these issues.\n- Thank you, it's clear now. Stateless classes are really pleasure to work with, but I am afraid I'll have a pretty statefull one here :-( Maybe a `ThreadLocal` will be the easiest way out\n- How would you this configuration using annotations in spring-boot?\n- It's better to ask a new question and reference this one rather than using comments. I answered it here.","metadata":{"transformedAt":"2026-08-18T18:33:20.140Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":10,"totalLines":111,"estimatedTokens":840}}247{"id":"stack-36123006","source":"stackoverflow","questionId":36123006,"title":"RabbitMQ closes connection when processing long running tasks and timeout settings produce errors","tags":["python","rabbitmq","amqp","pika","python-pika"],"text":"Title: RabbitMQ closes connection when processing long running tasks and timeout settings produce errors\nTags: python, rabbitmq, amqp, pika, python-pika\nSource: Stack Overflow\n\nQuestion:\nI am using a RabbitMQ producer to send long running tasks (30 mins+) to a consumer. The problem is that the consumer is still working on a task when the connection to the server is closed and the unacknowledged task is requeued. \n\nFrom researching I understand that either a heartbeat or an increased connection timeout can be used to solve this. Both these solutions raise errors when attempting them. In reading answers to similar posts I've also learned that many changes have been implemented to RabbitMQ since the answers were posted (e.g. the default heartbeat timeout has changed to 60 from 580 prior to RabbitMQ 3.5.5).\n\nWhen specifying a heartbeat and blocked connection timeout:\n\n```\ncredentials = pika.PlainCredentials('user', 'password')\nparameters = pika.ConnectionParameters('XXX.XXX.XXX.XXX', port, '/', credentials, blocked_connection_timeout=2000)\nconnection = pika.BlockingConnection(parameters)\n\nchannel = connection.channel()\n```\n\nThe following error is displayed:\n\n```\nTypeError: __init__() got an unexpected keyword argument 'blocked_connection_timeout'\n```\n\nWhen specifying `heartbeat_interval=1000` in the connection parameters a similar error is shown: `TypeError: __init__() got an unexpected keyword argument 'heartbeat_interval'`\n\nAnd similarly for `socket_timeout = 1000` the following error is displayed: `TypeError: __init__() got an unexpected keyword argument 'socket_timeout'`\n\nI am running RabbitMQ 3.6.1, pika 0.10.0 and python 2.7 on Ubuntu 14.04.\n\n- Why are the above approaches producing errors?\n\n- Can a heartbeat approach be used where there is a long running continuous task? For example can heartbeats be used when performing large database joins which take 30+ mins? I am in favour of the heartbeat approach as many times it is difficult to judge how long a task such as database join will take.\n\nI've read through answers to similar questions \n\n**Update**: running code from the pika documentation produces the same error.\n\n========================================\n\nTop Answer:\nI've already see this issue. The reason is you declare to use this queue. but you didn't bind the queue in the exchange.\n\nfor example:\n\n```\n@Bean(name = \"test_queue\")\n public Queue testQueue() {\n return queue(\"test_queue\");\n }\n\n@RabbitListener(queues = \"test_queue_1\")\npublic void listenCreateEvent(){\n}\n```\n\nif you listen a queue didn't bind to the exchange. it will happen.\n\n========================================\n\nCode:\n```text\ncredentials = pika.PlainCredentials('user', 'password')\nparameters = pika.ConnectionParameters('XXX.XXX.XXX.XXX', port, '/', credentials, blocked_connection_timeout=2000)\nconnection = pika.BlockingConnection(parameters)\n\nchannel = connection.channel()\n```\n\n```text\nTypeError: __init__() got an unexpected keyword argument 'blocked_connection_timeout'\n```\n\n```text\nheartbeat_interval=1000\n```\n\n```text\nTypeError: __init__() got an unexpected keyword argument 'heartbeat_interval'\n```\n\n```text\nsocket_timeout = 1000\n```\n\n```text\nTypeError: __init__() got an unexpected keyword argument 'socket_timeout'\n```\n\n```text\n@Bean(name = \"test_queue\")\n public Queue testQueue() {\n return queue(\"test_queue\");\n }\n\n@RabbitListener(queues = \"test_queue_1\")\npublic void listenCreateEvent(){\n}\n```\n\n========================================\n\nComments:\n- Is any kind of load balance sitting in front of the rabbit mq server ? What your environment looks like may be relevant to answering this question.\n- The producer and consumer machines are all on the same private network.\n- The problem is that you need to process data while waiting, even if you are not consuming messages; connection.process_data_events(). Otherwise pika wont respond to heartbeats.\n- What about using another thread to send heartbeat signals asynchronously?\n- If an ack is sent immediately , doesnt that mean that broker will just send another message, and eventually overload the consumer ?\n- @nn0p I'm having a problem with that approach. My tasks are very CPU heavy and even though another thread is sending heartbeats, sometimes it can't find any opportunity to send one during CPU load, which causes connection to terminate.\n- We have a long-running operation performed on the consumer which can take hours to complete. We are getting a timeout exception as we don't acknowledge the message till it is processed completely. If we ack the message, the next message will start getting processed which we don't want. Is there a way to overcome this issue?","metadata":{"transformedAt":"2026-08-18T18:33:20.141Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":111,"estimatedTokens":1166}}248{"id":"stack-27379736","source":"stackoverflow","questionId":27379736,"title":"where is rabbitmq config file?","tags":["rabbitmq"],"text":"Title: where is rabbitmq config file?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nDocumentation says that rabbitmq has config: /etc/rabbitmq/rabbitmq.conf \nbut I have nothing there, but rabbitmq-server is running and consuming messages.\n\nWhere is my config file?\n\n========================================\n\nTop Answer:\n**On Windows:**\n\n### RabbitMQ 3.7.0+\n\n### `%APPDATA%\\RabbitMQ\\rabbitmq.conf`\n\nIn RabbitMQ 3.7.0+, the main configuration file is `rabbitmq.conf`. An additional config file named `advanced.config` is also used for some advanced configuration settings; it uses the classic format.\n\n### Prior to 3.7.0:\n\n### `%APPDATA%\\RabbitMQ\\rabbitmq.config`\n\nThe configuration file is named `rabbitmq.config` and uses the Erlang term format (aka the \"classic format\" for RabbitMQ config files).\n\n### Example files:\n\n- rabbitmq.conf.example\n\n- advanced.config.example\n\n- rabbitmq.config.example\n\n========================================\n\nCode:\n```text\nrabbitmq-server-mac-standalone-3.4.2.tar.gz\n```\n\n```text\netc/rabbitmq/rabbitmq.config.example\n```\n\n```text\nRABBITMQ_CONFIG_FILE\n```\n\n```text\n%APPDATA%\\RabbitMQ\\rabbitmq.conf\n```\n\n```text\nrabbitmq.conf\n```\n\n```text\nadvanced.config\n```\n\n```text\n%APPDATA%\\RabbitMQ\\rabbitmq.config\n```\n\n```text\nrabbitmq.config\n```\n\n```text\n/etc/rabbitmq/rabbitmq.conf\n```\n\n```text\ndocker exec -it container_name bash\n```\n\n```text\nrabbitmq-diagnostics status\n```\n\n```text\nrabbitmq-diagnostics environment\n```\n\n```text\n/etc/rabbitmq/rabbitmq.config\n```\n\n========================================\n\nComments:\n- Which operating system and package manager are you using?\n- It was my fault, cause \"by default /etc/rabbitmq/rabbitmq.config\" is not created and one should create it manualy.\n- Does this answer your question? Why can't I find the 'rabbitmq.config' file while I have already installed RabbitMQ?\n- Run this to see if you have the config file somewhere: `echo $RABBITMQ_CONFIG_FILE`","metadata":{"transformedAt":"2026-08-18T18:33:20.141Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":13,"totalLines":97,"estimatedTokens":481}}249{"id":"stack-20345658","source":"stackoverflow","questionId":20345658,"title":"How to use rabbitmqctl to connect to the rabbitmqserver in the docker container?","tags":["rabbitmq","docker","rabbitmqctl"],"text":"Title: How to use rabbitmqctl to connect to the rabbitmqserver in the docker container?\nTags: rabbitmq, docker, rabbitmqctl\nSource: Stack Overflow\n\nQuestion:\nI've used docker to start my rabbitmqserver. How can I use rabbitmqctl to connect to the rabbitmqserver in the docker container?\n\nPort 5672 has been exposed and map to the 5672 port of my host. But I still get the following error:\n\n```\nStatus of node rabbit@m2 ...\nError: unable to connect to node rabbit@m2: nodedown\n```\n\n========================================\n\nTop Answer:\nAssuming your container is called `rabbitmq` and is running:\n\n```\ndocker exec rabbitmq rabbitmqctl start_app\n```\n\n========================================\n\nCode:\n```text\nStatus of node rabbit@m2 ...\nError: unable to connect to node rabbit@m2: nodedown\n```\n\n```text\n$ netstat -uptan | grep beam\ntcp 0 0 0.0.0.0:55950 0.0.0.0:* LISTEN 31446/beam.smp \ntcp 0 0 0.0.0.0:15672 0.0.0.0:* LISTEN 31446/beam.smp \ntcp 0 0 0.0.0.0:55672 0.0.0.0:* LISTEN 31446/beam.smp \ntcp 0 0 127.0.0.1:55096 127.0.0.1:4369 ESTABLISHED 31446/beam.smp \ntcp6 0 0 :::5672 :::* LISTEN 31446/beam.smp\n```\n\n```text\n[{kernel,[{inet_dist_listen_min, 55950},{inet_dist_listen_min, 55950}]}].\n```\n\n```text\nrabbitmqctl\n```\n\n```text\nrabbitmqctl\n```\n\n```text\nERL_EPMD_PORT\n```\n\n```text\ninet_dist_listen_min\n```\n\n```text\ninet_dist_listen_max\n```\n\n```text\nexport RABBITMQ_CONFIG_FILE=\"/path/to/my_rabbitmq.conf\n```\n\n```text\nel@apollo:/etc/rabbitmq$ sudo rabbitmqctl join_cluster rabbit@192.168.1.8\nClustering node rabbit@apollo with 'rabbit@192.168.1.8' ...\nError: unable to connect to nodes ['rabbit@192.168.1.8']: nodedown\n\nDIAGNOSTICS\n===========\n\nattempted to contact: ['rabbit@192.168.1.8']\n\nrabbit@192.168.1.8:\n * unable to connect to epmd (port 4369) on 192.168.1.8: address \n (cannot connect to host/port)\n\n\ncurrent node details:\n- node name: rabbitmqctl7233@apollo\n- home dir: /var/lib/rabbitmq\n- cookie hash: g0tS9zEdo7OEDSZaDTGirA==\n```\n\n```text\nel@defiant ~ $ su -\nPassword:\n[root@defiant ~]# iptables -I INPUT -p tcp --dport 4369 --syn -j ACCEPT\n[root@defiant ~]# iptables -I INPUT -p tcp --dport 59984 --syn -j ACCEPT\n```\n\n```text\ndocker exec rabbitmq rabbitmqctl start_app\n```\n\n```text\nrabbitmq\n```\n\n```text\ndocker exec -t rabbitmq sh\n```\n\n```text\nrabbitmqctl\n```\n\n========================================\n\nComments:\n- How can \"allow RabbitMQ instance connect to 127.0.0.1:4369\" be achieved with Docker? So far I have the following options: `-p 55950:55950 -p 5672:5672 -p 15672:15672 -e ERL_EPMD_PORT=55950` when running the docker container, and I have `epmd` running on the host. But still, I can't connect with `rabbitmqctl` to the Rabbit instance in the container.\n- Can you explain why opening port 59984 helped?\n- This did not work for me, however `docker exec -ti rabbitmq bash -c \"su -\"` did, although rabbitmqctl was an unknown command once there\n- You may want to use `docker exec -it rabbitmq rabbitmqctl` respectively `docker exec -it rabbitmq sh` instead, note the `-it`. Otherwise, you don't get an interactive shell.","metadata":{"transformedAt":"2026-08-18T18:33:20.141Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":15,"totalLines":119,"estimatedTokens":813}}250{"id":"stack-17778715","source":"stackoverflow","questionId":17778715,"title":"celeryev Queue in RabbitMQ Becomes Very Large","tags":["rabbitmq","celery","django-celery"],"text":"Title: celeryev Queue in RabbitMQ Becomes Very Large\nTags: rabbitmq, celery, django-celery\nSource: Stack Overflow\n\nQuestion:\nI am using celery on rabbitmq. I have been sending thousands of messages to the queue and they are being processed successfully and everything is working just fine. However, the number of messages in several rabbitmq queues are growing quite large (hundreds of thousands of items in the queue). The queues are named `celeryev.[...]` (see screenshot below). Is this appropriate behavior? What is the purpose of these queues and shouldn't they be regularly purged? Is there a way to purge them more regularly, I think they are taking up quite a bit of disk space.\n\n========================================\n\nTop Answer:\nFor anyone else who is running into problems with a `celeryev` queue becoming very large and threatening the disk space on your rabbitmq server, beware the accepted answer! Here's my suggestion. Just issue this command on your rabbitmq instance:\n\n```\nrabbitmqctl set_policy limit_celeryev_queues \"^celeryev\\.\" '{\"max-length\":1000000}' --apply-to queues\n```\n\nThis will limit any queue beginning with \"celeryev\" to 1 Million entries. I did some experimenting with a stuck `flower` instance causing a runaway celeryev queue, and setting CELERY_EVENT_QUEUE_TTL / CELERY_EVENT_QUEUE_EXPIRES did **not** help control the queue size.\n\nIn my testing, I started a `flower` process, then SIGSTOP'ed it, and watched its celeryev queue start running away. Neither of these two settings helped at all. I confirmed SIGCONT'ing the `flower` process would bring the queue back to 0 rapidly. I am not certain why these two knobs didn't help, but it may have something to do with how RabbitMQ implements these two settings. \n\nFirst, the Per-Message TTL corresponding to `CELERY_EVENT_QUEUE_TTL` only establishes an expiration time on each queue entry -- AIUI it will not automatically delete the message out of the queue to save space upon expiration. Second, the Queue TTL corresponding to `CELERY_EVENT_QUEUE_EXPIRES` says that it \"... guarantees that the queue will be deleted, if unused for at least the expiration period\". However, I believe that their definition of \"unused\" may be too strict to kick in for e.g. an overburdened, stuck, or killed flower process.\n\nEDIT: Unfortunately, one problem with this suggestion is that the `set_policy ... apply-to queues` will only impact **existing** queues, and flower can and will create **new** queues which may overflow.\n\n========================================\n\nCode:\n```text\nceleryev.[...]\n```\n\n```text\nCELERY_EVENT_QUEUE_TTL\n```\n\n```text\nceleryev\n```\n\n```text\ncelery control disable_events\n```\n\n```text\nrabbitmqctl set_policy limit_celeryev_queues \"^celeryev\\.\" '{\"max-length\":1000000}' --apply-to queues\n```\n\n```text\nceleryev\n```\n\n```text\nflower\n```\n\n```text\nflower\n```\n\n```text\nflower\n```\n\n```text\nCELERY_EVENT_QUEUE_TTL\n```\n\n```text\nCELERY_EVENT_QUEUE_EXPIRES\n```\n\n```text\nset_policy ... apply-to queues\n```\n\n```text\nCELERY_SEND_EVENTS = False # Will not create celeryev.* queues\n```\n\n```text\nCELERY_EVENT_QUEUE_EXPIRES = 60 # Will delete all celeryev. queues without consumers after 1 minute.\n```\n\n```text\nceleryev.*\n```\n\n========================================\n\nComments:\n- Is there a way to reduce or limit event storage rather than turn it off altogether?\n- Have you tried --maxrate and --frequency arguments (or some other?) which may be placed in CELERYEV_OPTS, I guess\n- Were you able to make use of --maxrate or --frequency options? @pinepain\n- This link is now a dead link. Do you have an updated one? Is it now docs.celeryproject.org/en/latest/userguide/… ?","metadata":{"transformedAt":"2026-08-18T18:33:20.141Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":15,"totalLines":94,"estimatedTokens":915}}251{"id":"stack-25409626","source":"stackoverflow","questionId":25409626,"title":"rabbitmqctl Error: unable to connect to node rabbit@myserver nodedown","tags":["windows","erlang","rabbitmq","rabbitmqctl"],"text":"Title: rabbitmqctl Error: unable to connect to node rabbit@myserver nodedown\nTags: windows, erlang, rabbitmq, rabbitmqctl\nSource: Stack Overflow\n\nQuestion:\nI am running RabbitMQ v3.3.5 with Erlang OTP 17.1 on Windows 2008 R2. My Dev and QA environments are stand-alone. My staging and production environments are clustered.\n\nI am finding this one problem happening often where the RabbitMQ service is running, the RabbitMQ management console is seeing everything, but when I try running rabbitmqctl from the command line it fails with an error saying that the node is down (tried locally and on a remote server).\n\nThis problem is resolved if I restart the Windows service.\n\nI see no error message in the RabbitMQ error log. The last message indicated that the node was up.\n\nBelow is an example output of the issue that I recently experienced on node 2 of our staging windows cluster:\n\n```\nPS C:\\Program Files (x86)\\RabbitMQ Server\\rabbitmq_server-3.3.5\\sbin> .\\rabbitmqctl.bat status\nStatus of node rabbit@MYSERVER2 ...\nError: unable to connect to node rabbit@MYSERVER2: nodedown\n\nDIAGNOSTICS\n===========\n\nattempted to contact: [rabbit@MYSERVER2]\n\nrabbit@MYSERVER2:\n * connected to epmd (port 4369) on MYSERVER2\n * epmd reports: node 'rabbit' not running at all\n no other nodes on MYSERVER2\n * suggestion: start the node\n\ncurrent node details:\n- node name: rabbitmqctl2199771@MYSERVER2\n- home dir: C:\\Users\\RabbitMQ\n- cookie hash: mn6OaTX9mS4DnZaiOzg8pA==\n```\n\nat this point I restart the RabbitMQ service and then try again\n\n```\nPS C:\\Program Files (x86)\\RabbitMQ Server\\rabbitmq_server-3.3.5\\sbin> .\\rabbitmqctl.bat status\nStatus of node rabbit@MYSERVER2...\n[{pid,3784},\n {running_applications,\n [{rabbitmq_management_agent,\"RabbitMQ Management Agent\",\"3.3.5\"},\n {rabbit,\"RabbitMQ\",\"3.3.5\"},\n {os_mon,\"CPO CXC 138 46\",\"2.2.15\"},\n {mnesia,\"MNESIA CXC 138 12\",\"4.12.1\"},\n {xmerl,\"XML parser\",\"1.3.7\"},\n {sasl,\"SASL CXC 138 11\",\"2.4\"},\n {stdlib,\"ERTS CXC 138 10\",\"2.1\"},\n {kernel,\"ERTS CXC 138 10\",\"3.0.1\"}]},\n {os,{win32,nt}},\n {erlang_version,\n \"Erlang/OTP 17 [erts-6.1] [64-bit] [smp:4:4] [async-threads:30]\\n\"},\n {memory,\n [{total,35960208},\n {connection_procs,2704},\n {queue_procs,5408},\n {plugins,111936},\n {other_proc,13695792},\n {mnesia,102296},\n {mgmt_db,0},\n {msg_index,21816},\n {other_ets,884704},\n {binary,25776},\n {code,16672826},\n {atom,602729},\n {other_system,3834221}]},\n {alarms,[]},\n {listeners,[{clustering,25672,\"::\"},{amqp,5672,\"::\"},{amqp,5672,\"0.0.0.0\"}]},\n {vm_memory_high_watermark,0.4},\n {vm_memory_limit,3435787059},\n {disk_free_limit,50000000},\n {disk_free,74911649792},\n {file_descriptors,\n [{total_limit,8092},\n {total_used,4},\n {sockets_limit,7280},\n {sockets_used,2}]},\n {processes,[{limit,1048576},{used,139}]},\n {run_queue,0},\n {uptime,5}]\n...done.\n```\n\nAny idea as to what causes this and how to automatically detect the situation?\n\nIs this specifically a problem with running RabbitMQ on Windows?\n\n========================================\n\nTop Answer:\nTo anyone else getting this error, this was my fix. I installed Erlang, but overlooked the instructions on setting up the Environmental Variable. \n\nI was reading the manual install page: \nhttps://www.rabbitmq.com/install-windows-manual.html \nand found the following: \n\n Set ERLANG_HOME to where you actually put your Erlang installation,\n e.g. C:\\Program Files\\erlx.x.x (full path). The RabbitMQ batch files\n expect to execute %ERLANG_HOME%\\bin\\erl.exe.\n\n \n Go to Start > Settings > Control Panel > System > Advanced >\n Environment Variables. Create the system environment variable\n ERLANG_HOME and set it to the full path of the directory which\n contains bin\\erl.exe.\n\nFor some reason, the auto install assigned the wrong path name to the ERLANG_HOME variable - see image below. I simply added \\bin on the end. \nhttps://i.sstatic.net/w1EYl.jpg\n\n========================================\n\nCode:\n```text\nPS C:\\Program Files (x86)\\RabbitMQ Server\\rabbitmq_server-3.3.5\\sbin> .\\rabbitmqctl.bat status\nStatus of node rabbit@MYSERVER2 ...\nError: unable to connect to node rabbit@MYSERVER2: nodedown\n\nDIAGNOSTICS\n===========\n\nattempted to contact: [rabbit@MYSERVER2]\n\nrabbit@MYSERVER2:\n * connected to epmd (port 4369) on MYSERVER2\n * epmd reports: node 'rabbit' not running at all\n no other nodes on MYSERVER2\n * suggestion: start the node\n\ncurrent node details:\n- node name: rabbitmqctl2199771@MYSERVER2\n- home dir: C:\\Users\\RabbitMQ\n- cookie hash: mn6OaTX9mS4DnZaiOzg8pA==\n```\n\n```text\nPS C:\\Program Files (x86)\\RabbitMQ Server\\rabbitmq_server-3.3.5\\sbin> .\\rabbitmqctl.bat status\nStatus of node rabbit@MYSERVER2...\n[{pid,3784},\n {running_applications,\n [{rabbitmq_management_agent,\"RabbitMQ Management Agent\",\"3.3.5\"},\n {rabbit,\"RabbitMQ\",\"3.3.5\"},\n {os_mon,\"CPO CXC 138 46\",\"2.2.15\"},\n {mnesia,\"MNESIA CXC 138 12\",\"4.12.1\"},\n {xmerl,\"XML parser\",\"1.3.7\"},\n {sasl,\"SASL CXC 138 11\",\"2.4\"},\n {stdlib,\"ERTS CXC 138 10\",\"2.1\"},\n {kernel,\"ERTS CXC 138 10\",\"3.0.1\"}]},\n {os,{win32,nt}},\n {erlang_version,\n \"Erlang/OTP 17 [erts-6.1] [64-bit] [smp:4:4] [async-threads:30]\\n\"},\n {memory,\n [{total,35960208},\n {connection_procs,2704},\n {queue_procs,5408},\n {plugins,111936},\n {other_proc,13695792},\n {mnesia,102296},\n {mgmt_db,0},\n {msg_index,21816},\n {other_ets,884704},\n {binary,25776},\n {code,16672826},\n {atom,602729},\n {other_system,3834221}]},\n {alarms,[]},\n {listeners,[{clustering,25672,\"::\"},{amqp,5672,\"::\"},{amqp,5672,\"0.0.0.0\"}]},\n {vm_memory_high_watermark,0.4},\n {vm_memory_limit,3435787059},\n {disk_free_limit,50000000},\n {disk_free,74911649792},\n {file_descriptors,\n [{total_limit,8092},\n {total_used,4},\n {sockets_limit,7280},\n {sockets_used,2}]},\n {processes,[{limit,1048576},{used,139}]},\n {run_queue,0},\n {uptime,5}]\n...done.\n```\n\n```text\nLOCALHOST\n```\n\n```text\nlocalhost\n```\n\n```text\nrabbit@<hostname>\n```\n\n```text\nrabbit@LOCALHOST\n```\n\n```text\nrabbit@localhost\n```\n\n```text\nrabbit@MYHOST\n```\n\n```text\nrabbitmqctl\n```\n\n```text\nrabbit@myhost\n```\n\n```text\nrabbitmq-env.conf\n```\n\n========================================\n\nComments:\n- I have confirmed that the cookie hash in the error message matches the cookie hash of the last successful service restart in the log file and that that hash also matches the cookie hash of the last successful service restart on the other node.\n- Having the exact same problem. Looks like the discussion is continued on the mailing list groups.google.com/forum/#!topic/rabbitmq-users/Zn8unuF4bTM\n- Yes, I am going to continue to keep this up to date with the latest information as well. So far, the only further solid information I have is that I was able to confirm that when the issue is happening the epmd.exe process is not running on the server. I can see this in the Windows task manager. As soon as I restart the RabbitMQ service, the epmd.exe process spawns and everything is working correctly.\n- I get this issue, and resolved it by this method:stackoverflow.com/questions/38523236/…\n- I found that the epmd process was halting and that was what was ultimately breaking things. When I restarted the service is turned that process back on and everything started working. So I ended up creating a service monitor that not only checks to ensure that the RabbitMQ service is running but also that the epmd process is running. If either of those fail it alerts me and restarts the RabbitMQ service.\n- On WIndows 10 Pro, the rabbitmq installer fails to properly configure RabbitMQ as a service. I had to run `rabbitmq-service remove` and then `rabbitmq-service install` for it to work properly.\n- Hi! Could you please bring this issue to the rabbitmq-users mailing-list? groups.google.com/forum/#!forum/rabbitmq-users\n- looks like the problem still persists. It is trying to reach the node `rabbit@` and my system's hostname is in small characters. Is there a solution to this problem? Or Is there a way I can set hostname in capitals, will this solve my problem?\n- Your quote states \"The RabbitMQ batch files expect to execute `%ERLANG_HOME%\\bin\\erl.exe`\" and therefore `ERLANG_HOME` should be set to the directory *containing* `bin\\erl.exe`. You have concluded `ERLANG_HOME` should be set to `C:\\Program Files (x86)\\erl7.3\\bin`, but that would leave `[...]\\bin\\bin\\erl.exe` after expansion. Is that correct?\n- Sorry, don't remember all the issues.\n- I tried both `\\bin\\erl.exe` and `\\bin` and both return path can't be found or something along these lines, so I guess this is not the solution any more or at least not for RabbitMQ 3.6 and erl 8.1\n- It is `755`, so how to do with it?","metadata":{"transformedAt":"2026-08-18T18:33:20.141Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":11,"totalLines":235,"estimatedTokens":2168}}252{"id":"stack-17684848","source":"stackoverflow","questionId":17684848,"title":"RabbitMQ - Get total count of messages enqueued","tags":["java","rabbitmq"],"text":"Title: RabbitMQ - Get total count of messages enqueued\nTags: java, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have a Java client which monitors RabbitMQ queue. I am able to get the count of messages currently in queue with this code\n\n```\n@Resource\nRabbitAdmin rabbitAdmin;\n..........\n\nDeclareOk declareOk = rabbitAdmin.getRabbitTemplate().execute(new ChannelCallback() {\n public DeclareOk doInRabbit(Channel channel) throws Exception {\n return channel.queueDeclarePassive(\"test.pending\");\n }\n });\n return declareOk.getMessageCount();\n```\n\nI want to get some more additional details like - \n\n- Message body of currently enqueued items.\n\n- Total number of messages that was enqueued in the queue since the queue was created.\n\nIs there any way to retrieve these data in Java client?\n\n========================================\n\nTop Answer:\n```\nAMQP.Queue.DeclareOk dok = channel.queueDeclare(QUEUE_NAME, true, false, false, queueArgs);\ndok.getMessageCount();\n```\n\n========================================\n\nCode:\n```text\n@Resource\nRabbitAdmin rabbitAdmin;\n..........\n\nDeclareOk declareOk = rabbitAdmin.getRabbitTemplate().execute(new ChannelCallback<DeclareOk>() {\n public DeclareOk doInRabbit(Channel channel) throws Exception {\n return channel.queueDeclarePassive(\"test.pending\");\n }\n });\n return declareOk.getMessageCount();\n```\n\n```text\nqueue.declare-ok\n```\n\n```text\nAMQP.Queue.DeclareOk\n```\n\n```text\nqueue.declare-ok\n```\n\n```text\nAMQP.Queue.DeclareOk dok = channel.queueDeclare(QUEUE_NAME, true, false, false, queueArgs);\ndok.getMessageCount();\n```\n\n```text\nhttp://public-domain-name:15672/api/queues/%2f/queue_name\n```\n\n```text\ncurl -i -u guest_uname:guest_password http://localhost:15672/api/queues/%2f/queue_name\n```\n\n```text\n/\n```\n\n```text\n/\n```\n\n========================================\n\nComments:\n- Thanks. Just wanted to confirm if there is any API to support these since I couldn't find it documented anywhere.\n- A small correction to what zaq178miami wrote: 10k messages per second for 2 weeks is a total of 1,463,132,160,000 messages. An unsigned int 64 bit is 2^64 = 18,446,744,073,709,551,615 far more than that.\n- Note If you google for \"RabbitMQ Management HTTP Stats\", you'll see that there is a \"publish\" counter that is the queue's total nb of enqueued messages (since the broker was started as far as I could notice). Also note that setting msg_rates_age and msg_rates_incr querystring parameters will provide historized values of such counter.\n- is there any such code to get all the names of the queues currently in the broker???\n- You'll get an error if queue declaration args are different from those queue was created with. Use queueDeclarePassive instead\n- It should be noted that this solution depends on the Management Plugin. rabbitmq.com/management.html#http-api-endpoints\n- I must be the only one on earth who wonders why the `%2f` is there.\n- Added (%2f URL encoding of / character) to answer. You can check here, urlencoder.org","metadata":{"transformedAt":"2026-08-18T18:33:20.141Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":96,"estimatedTokens":748}}253{"id":"stack-42990585","source":"stackoverflow","questionId":42990585,"title":"Implementation of delayed queue for PHP AMQP","tags":["php","rabbitmq","amqp"],"text":"Title: Implementation of delayed queue for PHP AMQP\nTags: php, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nrecently, I did a quick implementation on producer/ consumer queue system.\n\n```\nconnection = new AMQPStreamConnection($host, $port, $login, $password);\n $this->queueName = $queueName;\n $this->delayedQueueName = null;\n $this->channel = $this->connection->channel();\n // First, we need to make sure that RabbitMQ will never lose our queue.\n // In order to do so, we need to declare it as durable. To do so we pass\n // the third parameter to queue_declare as true.\n $this->channel->queue_declare($queueName, false, true, false, false);\n }\n\n public function __destruct()\n {\n $this->close();\n }\n\n // Just in case : http://stackoverflow.com/questions/151660/can-i-trust-php-destruct-method-to-be-called\n // We should call close explicitly if possible.\n public function close()\n {\n if (!is_null($this->channel)) {\n $this->channel->close();\n $this->channel = null;\n }\n\n if (!is_null($this->connection)) {\n $this->connection->close();\n $this->connection = null;\n }\n }\n\n public function produceWithDelay($data, $delay)\n {\n if (is_null($this->delayedQueueName))\n {\n $delayedQueueName = $this->queueName . '.delayed';\n\n // First, we need to make sure that RabbitMQ will never lose our queue.\n // In order to do so, we need to declare it as durable. To do so we pass\n // the third parameter to queue_declare as true.\n $this->channel->queue_declare($this->delayedQueueName, false, true, false, false, false,\n new AMQPTable(array(\n 'x-dead-letter-exchange' => '',\n 'x-dead-letter-routing-key' => $this->queueName\n ))\n );\n\n $this->delayedQueueName = $delayedQueueName;\n }\n\n $msg = new AMQPMessage(\n $data,\n array(\n 'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT,\n 'expiration' => $delay\n )\n );\n\n $this->channel->basic_publish($msg, '', $this->delayedQueueName);\n }\n\n public function produce($data)\n {\n $msg = new AMQPMessage(\n $data,\n array('delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT)\n );\n\n $this->channel->basic_publish($msg, '', $this->queueName);\n }\n\n public function consume($callback)\n {\n $this->callback = $callback;\n\n // This tells RabbitMQ not to give more than one message to a worker at\n // a time.\n $this->channel->basic_qos(null, 1, null);\n\n // Requires ack.\n $this->channel->basic_consume($this->queueName, '', false, false, false, false, array($this, 'consumeCallback'));\n\n while(count($this->channel->callbacks)) {\n $this->channel->wait();\n }\n }\n\n public function consumeCallback($msg)\n {\n call_user_func_array(\n $this->callback,\n array($msg)\n );\n\n // Very important to ack, in order to remove msg from queue. Ack after\n // callback, as exception might happen in callback.\n $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);\n }\n\n public function getQueueSize()\n {\n // three tuple containing (, , )\n $tuple = $this->channel->queue_declare($this->queueName, false, true, false, false);\n if ($tuple != null && isset($tuple[1])) {\n return $tuple[1];\n }\n return -1;\n }\n}\n```\n\n`public function produce` and `public function consume` pair works as expected.\n\nHowever, when it comes with delayed queue system\n\n`public function produceWithDelay` and `public function consume` pair doesn't work as expected. The consumer which calls `consume`, not able to receive any item, even waiting for some period of time.\n\nI believe something not right with my `produceWithDelay` implementation. May I know what's wrong is that?\n\n========================================\n\nTop Answer:\nFist of all verify that your plugin `rabbitmq_delayed_message_exchange` enabled by running command: `rabbitmq-plugins list`, If not - read more info here.\n\nAnd you have to update your `__construct` method because you need to declare queue in a little bit another way. I do not pretend to update your construct, but would like to provide my simple example:\n\nDeclare queue:\n\n```\nchannel();\n$args = new AMQPTable(['x-delayed-type' => 'fanout']);\n$channel->exchange_declare('delayed_exchange', 'x-delayed-message', false, true, false, false, false, $args);\n$args = new AMQPTable(['x-dead-letter-exchange' => 'delayed']);\n$channel->queue_declare('delayed_queue', false, true, false, false, false, $args);\n$channel->queue_bind('delayed_queue', 'delayed_exchange');\n```\n\nSend message:\n\n```\n$data = 'Hello World at ' . date('Y-m-d H:i:s');\n$delay = 7000;\n$message = new AMQPMessage($data, ['delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT]);\n$headers = new AMQPTable(['x-delay' => $delay]);\n$message->set('application_headers', $headers);\n$channel->basic_publish($message, 'delayed_exchange');\nprintf(' [x] Message sent: %s %s', $data, PHP_EOL);\n$channel->close();\n$connection->close();\n```\n\nReceive message:\n\n```\n$callback = function (AMQPMessage $message) {\n printf(' [x] Message received: %s %s', $message->body, PHP_EOL);\n $message->delivery_info['channel']->basic_ack($message->delivery_info['delivery_tag']);\n};\n$channel->basic_consume('delayed_queue', '', false, false, false, false, $callback);\nwhile(count($channel->callbacks)) {\n $channel->wait();\n}\n$channel->close();\n$connection->close();\n```\n\nAlso you can find source files here.\n\nHope it will help you!\n\n========================================\n\nCode:\n```text\n<?php\nnamespace Queue;\n\nuse PhpAmqpLib\\Connection\\AMQPStreamConnection;\nuse PhpAmqpLib\\Message\\AMQPMessage;\nuse PhpAmqpLib\\Wire\\AMQPTable; \n\nclass Amqp\n{\n private $connection;\n private $queueName;\n private $delayedQueueName;\n private $channel;\n private $callback;\n\n public function __construct($host, $port, $login, $password, $queueName)\n {\n $this->connection = new AMQPStreamConnection($host, $port, $login, $password);\n $this->queueName = $queueName;\n $this->delayedQueueName = null;\n $this->channel = $this->connection->channel();\n // First, we need to make sure that RabbitMQ will never lose our queue.\n // In order to do so, we need to declare it as durable. To do so we pass\n // the third parameter to queue_declare as true.\n $this->channel->queue_declare($queueName, false, true, false, false);\n }\n\n public function __destruct()\n {\n $this->close();\n }\n\n // Just in case : http://stackoverflow.com/questions/151660/can-i-trust-php-destruct-method-to-be-called\n // We should call close explicitly if possible.\n public function close()\n {\n if (!is_null($this->channel)) {\n $this->channel->close();\n $this->channel = null;\n }\n\n if (!is_null($this->connection)) {\n $this->connection->close();\n $this->connection = null;\n }\n }\n\n public function produceWithDelay($data, $delay)\n {\n if (is_null($this->delayedQueueName))\n {\n $delayedQueueName = $this->queueName . '.delayed';\n\n // First, we need to make sure that RabbitMQ will never lose our queue.\n // In order to do so, we need to declare it as durable. To do so we pass\n // the third parameter to queue_declare as true.\n $this->channel->queue_declare($this->delayedQueueName, false, true, false, false, false,\n new AMQPTable(array(\n 'x-dead-letter-exchange' => '',\n 'x-dead-letter-routing-key' => $this->queueName\n ))\n );\n\n $this->delayedQueueName = $delayedQueueName;\n }\n\n $msg = new AMQPMessage(\n $data,\n array(\n 'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT,\n 'expiration' => $delay\n )\n );\n\n $this->channel->basic_publish($msg, '', $this->delayedQueueName);\n }\n\n public function produce($data)\n {\n $msg = new AMQPMessage(\n $data,\n array('delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT)\n );\n\n $this->channel->basic_publish($msg, '', $this->queueName);\n }\n\n public function consume($callback)\n {\n $this->callback = $callback;\n\n // This tells RabbitMQ not to give more than one message to a worker at\n // a time.\n $this->channel->basic_qos(null, 1, null);\n\n // Requires ack.\n $this->channel->basic_consume($this->queueName, '', false, false, false, false, array($this, 'consumeCallback'));\n\n while(count($this->channel->callbacks)) {\n $this->channel->wait();\n }\n }\n\n public function consumeCallback($msg)\n {\n call_user_func_array(\n $this->callback,\n array($msg)\n );\n\n // Very important to ack, in order to remove msg from queue. Ack after\n // callback, as exception might happen in callback.\n $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);\n }\n\n public function getQueueSize()\n {\n // three tuple containing (<queue name>, <message count>, <consumer count>)\n $tuple = $this->channel->queue_declare($this->queueName, false, true, false, false);\n if ($tuple != null && isset($tuple[1])) {\n return $tuple[1];\n }\n return -1;\n }\n}\n```\n\n```text\npublic function produce\n```\n\n```text\npublic function consume\n```\n\n```text\npublic function produceWithDelay\n```\n\n```text\npublic function consume\n```\n\n```text\nconsume\n```\n\n```text\nproduceWithDelay\n```\n\n```text\nif (is_null($this->delayedQueueName))\n {\n $delayedQueueName = $this->queueName . '.delayed';\n\n $this->channel->queue_declare($this->delayedQueueName, false, true, false, false, false,\n ...\n\n $this->delayedQueueName = $delayedQueueName;\n }\n```\n\n```text\nif (is_null($this->delayedQueueName))\n {\n $delayedQueueName = $this->queueName . '.delayed';\n\n $this->channel->queue_declare(delayedQueueName, false, true, false, false, false,\n ...\n\n $this->delayedQueueName = $delayedQueueName;\n }\n```\n\n```text\n<?php\n\nuse PhpAmqpLib\\Connection\\AMQPStreamConnection;\nuse PhpAmqpLib\\Message\\AMQPMessage;\nuse PhpAmqpLib\\Wire\\AMQPTable;\n\nclass Amqp\n{\n private $connection;\n private $queueName;\n private $delayedQueueName;\n private $channel;\n private $callback;\n\n public function __construct($host, $port, $login, $password, $queueName)\n {\n $this->connection = new AMQPStreamConnection($host, $port, $login, $password);\n $this->queueName = $queueName;\n $this->delayedQueueName = null;\n $this->channel = $this->connection->channel();\n $this->channel->queue_declare($queueName, false, true, false, false);\n }\n\n public function __destruct()\n {\n $this->close();\n }\n\n public function close()\n {\n if (!is_null($this->channel)) {\n $this->channel->close();\n $this->channel = null;\n }\n\n if (!is_null($this->connection)) {\n $this->connection->close();\n $this->connection = null;\n }\n }\n\n public function produceWithDelay($data, $delay)\n {\n if (is_null($this->delayedQueueName))\n {\n $delayedQueueName = $this->queueName . '.delayed';\n\n $this->channel->queue_declare($delayedQueueName, false, true, false, false, false,\n new AMQPTable(array(\n 'x-dead-letter-exchange' => '',\n 'x-dead-letter-routing-key' => $this->queueName\n ))\n );\n\n $this->delayedQueueName = $delayedQueueName;\n }\n\n $msg = new AMQPMessage(\n $data,\n array(\n 'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT,\n 'expiration' => $delay\n )\n );\n\n $this->channel->basic_publish($msg, '', $this->delayedQueueName);\n }\n\n public function produce($data)\n {\n $msg = new AMQPMessage(\n $data,\n array('delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT)\n );\n\n $this->channel->basic_publish($msg, '', $this->queueName);\n }\n\n public function consume($callback)\n {\n $this->callback = $callback;\n\n $this->channel->basic_qos(null, 1, null);\n\n $this->channel->basic_consume($this->queueName, '', false, false, false, false, array($this, 'callback'));\n\n while (count($this->channel->callbacks)) {\n $this->channel->wait();\n }\n }\n\n public function callback($msg)\n {\n call_user_func_array(\n $this->callback,\n array($msg)\n );\n\n $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);\n }\n}\n```\n\n```text\n<?php\n\nrequire_once __DIR__ . '/../vendor/autoload.php';\n\nuse PhpAmqpLib\\Connection\\AMQPStreamConnection;\nuse PhpAmqpLib\\Message\\AMQPMessage;\nuse PhpAmqpLib\\Wire\\AMQPTable;\n\n$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');\n$channel = $connection->channel();\n$args = new AMQPTable(['x-delayed-type' => 'fanout']);\n$channel->exchange_declare('delayed_exchange', 'x-delayed-message', false, true, false, false, false, $args);\n$args = new AMQPTable(['x-dead-letter-exchange' => 'delayed']);\n$channel->queue_declare('delayed_queue', false, true, false, false, false, $args);\n$channel->queue_bind('delayed_queue', 'delayed_exchange');\n```\n\n```text\n$data = 'Hello World at ' . date('Y-m-d H:i:s');\n$delay = 7000;\n$message = new AMQPMessage($data, ['delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT]);\n$headers = new AMQPTable(['x-delay' => $delay]);\n$message->set('application_headers', $headers);\n$channel->basic_publish($message, 'delayed_exchange');\nprintf(' [x] Message sent: %s %s', $data, PHP_EOL);\n$channel->close();\n$connection->close();\n```\n\n```text\n$callback = function (AMQPMessage $message) {\n printf(' [x] Message received: %s %s', $message->body, PHP_EOL);\n $message->delivery_info['channel']->basic_ack($message->delivery_info['delivery_tag']);\n};\n$channel->basic_consume('delayed_queue', '', false, false, false, false, $callback);\nwhile(count($channel->callbacks)) {\n $channel->wait();\n}\n$channel->close();\n$connection->close();\n```\n\n```text\nrabbitmq_delayed_message_exchange\n```\n\n```text\nrabbitmq-plugins list\n```\n\n```text\n__construct\n```\n\n========================================\n\nComments:\n- Try to declare your queue as `$channel->queue_declare(\"name\", false, false, false, true, true, array());` and the exchange maybe next following this gist\n- there is no need to implement it from scratch. That's how you should do it stackoverflow.com/a/45549182/579025","metadata":{"transformedAt":"2026-08-18T18:33:20.141Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":16,"totalLines":520,"estimatedTokens":3643}}254{"id":"stack-27805086","source":"stackoverflow","questionId":27805086,"title":"How to connect pika to rabbitMQ remote server? (python, pika)","tags":["python","rabbitmq","pika"],"text":"Title: How to connect pika to rabbitMQ remote server? (python, pika)\nTags: python, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nIn my local machine I can have:\n\n```\nconnection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))\n```\n\nfor both scripts (send.py and recv.py) in order to establish proper communication, but what about to establish communication from 12.23.45.67 to 132.45.23.14 ? I know about all the parameters that ConnectionParameters() take but I am not sure what to pass to the host or what to pass to the client. It would be appreciated if someone could give an example for host scrip and client script.\n\n========================================\n\nTop Answer:\nfirst step is to add another account to your rabbitMQ server. To do this in windows...\n\n- open a command prompt window (windows key->cmd->enter)\n\n- navigate to the \"C:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.6.2\\sbin\" directory ( type \"cd \\Program Files\\RabbitMQ Server\\rabbitmq_server-3.6.2\\sbin\" and press enter )\n\n- enable management plugin (type \"rabbitmq-plugins enable rabbitmq_management\" and press enter)\n\n- open a broswer window to the management console & navigate to the admin section (http://localhost:15672/#/users with credentials \"guest\" - \"guest\")\n\n- add a new user (for example \"the_user\" with password \"the_pass\"\n\n- give that user permission to virtual host \"/\" (click user's name then click \"set permission\")\n\nNow if you modify the connection info as done in the following modification of send.py you should find success:\n\n```\n#!/usr/bin/env python\nimport pika\n\ncredentials = pika.PlainCredentials('the_user', 'the_pass')\nparameters = pika.ConnectionParameters('132.45.23.14',\n 5672,\n '/',\n credentials)\n\nconnection = pika.BlockingConnection(parameters)\n\nchannel = connection.channel()\n\nchannel.queue_declare(queue='hello')\n\nchannel.basic_publish(exchange='',\n routing_key='hello',\n body='Hello W0rld!')\nprint(\" [x] Sent 'Hello World!'\")\nconnection.close()\n```\n\nHope this helps\n\n========================================\n\nCode:\n```text\nconnection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))\n```\n\n```text\n'rabbit-server1'\n```\n\n```text\nguest\n```\n\n```text\n#!/usr/bin/env python\nimport pika\n\ncredentials = pika.PlainCredentials('the_user', 'the_pass')\nparameters = pika.ConnectionParameters('132.45.23.14',\n 5672,\n '/',\n credentials)\n\nconnection = pika.BlockingConnection(parameters)\n\nchannel = connection.channel()\n\nchannel.queue_declare(queue='hello')\n\nchannel.basic_publish(exchange='',\n routing_key='hello',\n body='Hello W0rld!')\nprint(\" [x] Sent 'Hello World!'\")\nconnection.close()\n```\n\n========================================\n\nComments:\n- could you please give an example for the host scrip and another one for the client script, at least the connection part. This helped me understand how it woks but doesn't really explain the specifics of the connection.\n- Problem solved, thanks for your help, it did led me to the solution. As the second link says, the rabbitmq.config file needs to be modified and then restart the server in order to accept remote hosts in the 'guest' user of rabbitmq","metadata":{"transformedAt":"2026-08-18T18:33:20.141Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":100,"estimatedTokens":819}}255{"id":"stack-22464858","source":"stackoverflow","questionId":22464858,"title":"RabbitMQ and Node.js converting message buffer to JSON","tags":["node.js","rabbitmq"],"text":"Title: RabbitMQ and Node.js converting message buffer to JSON\nTags: node.js, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have a node.js app that connects to RabbitMQ to receive messages. When the messages come in and I output them to the console I get:\n**{ data: , contentType: undefined }**\n\nHow do I get a proper JSON or string out of this? Here is my example:\n\n```\nvar amqp = require('amqp');\n\nvar connection = amqp.createConnection({ host: 'localhost' });\n\nprocess.on('uncaughtException', function(err) {\n console.error(err.stack);\n});\n\nconnection.on('ready', function () {\n // Use the default 'amq.topic' exchange\n connection.queue('my-queue', function(q){ \n q.bind('#');\n\n q.subscribe(function (message) { \n console.log(message);\n });\n });\n});\n```\n\nThe messages are being sent using the RabbitMQ management console (for testing purposes currently). In this example I sent a simple message with the topic of \"test\" and the body \"blah\".\n\nI'm new to Node.js but I have tried to do \n\n```\nconsole.log(message.toJSON());\n```\n\nand I get nothing. Not even an error message. (not sure how to catch the issue)\n\n```\nconsole.log(message.toString());\n```\n\nWhen I do this I get [object Object] which doesn't help\n\n```\nconsole.log(JSON.parse(message.toString('utf8')));\n```\n\nAlso does nothing and I get no error message. I assuming it's failing but why I don't get an exception is unknown to me.\n\n========================================\n\nTop Answer:\nIf you are using **amqplib** then the below code solves the issue.\n\nIn the **sender.js** file i convert **data** to JSON string\n\n```\nvar data = [{\n name: '********',\n company: 'JP Morgan',\n designation: 'Senior Application Engineer'\n}];\n\nch.sendToQueue(q, Buffer.from(JSON.stringify(data)));\n```\n\nAnd in the **receiver.js** i use the below code to print the content from the queue. Here i parse the **msg.content** to JSON format.\n\n```\nch.consume(q, function(msg) {\n console.log(\" [x] Received\");\n console.log(JSON.parse(msg.content));\n}, {noAck: true});\n```\n\n========================================\n\nCode:\n```text\nvar amqp = require('amqp');\n\nvar connection = amqp.createConnection({ host: 'localhost' });\n\nprocess.on('uncaughtException', function(err) {\n console.error(err.stack);\n});\n\nconnection.on('ready', function () {\n // Use the default 'amq.topic' exchange\n connection.queue('my-queue', function(q){ \n q.bind('#');\n\n q.subscribe(function (message) { \n console.log(message);\n });\n });\n});\n```\n\n```text\nconsole.log(message.toJSON());\n```\n\n```text\nconsole.log(message.toString());\n```\n\n```text\nconsole.log(JSON.parse(message.toString('utf8')));\n```\n\n```text\nconsole.log(message.data.toString('utf8'));\n```\n\n```text\nvar data = [{\n name: '********',\n company: 'JP Morgan',\n designation: 'Senior Application Engineer'\n}];\n\nch.sendToQueue(q, Buffer.from(JSON.stringify(data)));\n```\n\n```text\nch.consume(q, function(msg) {\n console.log(\" [x] Received\");\n console.log(JSON.parse(msg.content));\n}, {noAck: true});\n```\n\n```text\nvar obj=JSON.parse( msg.content.toString())\nconsole.log(obj.name);\n```\n\n```text\nvar details={'name':'Stack','Age':18}\n```\n\n========================================\n\nComments:\n- Good idea to \"stringify\" and then \"parse\" it by the consumer. Thanks for the tip!\n- you might want to use `Buffer.from()` instead of `new Buffer()` as it is deprecated.","metadata":{"transformedAt":"2026-08-18T18:33:20.141Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":150,"estimatedTokens":846}}256{"id":"stack-34715596","source":"stackoverflow","questionId":34715596,"title":"Is catching an exception and continuing program execution a best practice?","tags":["php","rabbitmq","amqp"],"text":"Title: Is catching an exception and continuing program execution a best practice?\nTags: php, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nMy app connects to rabbitMQ. Sometimes, it's throwing an **AMQPTimeoutException**. More specifically \"*Error sending data. Socket connection timed out.*\"\n\nMy solution:\n\nI'm catching the **AMQPTimeoutException** and calling my reconnect method. After which the program continues it's normal execution. Also I've set a flag so that the exception is handled atmost 3 times.\n\n```\ntry\n{\n sendMethod($message);\n} catch (AMQPTimeoutException $e) {\n echo \"caught socket connection exception\". \"\\n\";\n $this->reconnect($message, $exchangeName, $queue);\n }\n//reconnect internally checks the flag\n```\n\nMy question : Is this a best practice? If not what other solutions are possible?\n\n**Note** : The app is written in PHP.\n\n========================================\n\nCode:\n```text\ntry\n{\n sendMethod($message);\n} catch (AMQPTimeoutException $e) {\n echo \"caught socket connection exception\". \"\\n\";\n $this->reconnect($message, $exchangeName, $queue);\n }\n//reconnect internally checks the flag\n```\n\n========================================\n\nComments:\n- In this situation, seems fine to me. What happens if it fails after 3 attempts?\n- that is really the best practice.. displaying error message on users may not only cause trouble on users but also creates holes for hackers on your system\n- @clayton The program exits","metadata":{"transformedAt":"2026-08-18T18:33:20.142Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":46,"estimatedTokens":364}}257{"id":"stack-50826968","source":"stackoverflow","questionId":50826968,"title":"Apache Pulsar vs. Apache RocketMQ","tags":["apache-kafka","rabbitmq","activemq-classic","rocketmq","apache-pulsar"],"text":"Title: Apache Pulsar vs. Apache RocketMQ\nTags: apache-kafka, rabbitmq, activemq-classic, rocketmq, apache-pulsar\nSource: Stack Overflow\n\nQuestion:\nApache Pulsar (by Yahoo) seems to be the next generation of Apache Kafka.\n\nApache RocketMQ (by Alibaba) seems to be the next generation of Apache ActiveMQ.\n\nBoth are open source distributed messaging and streaming data platforms.\n\nBut how do they compare? When should I prefer one over another in terms of features and performance?\n\nIs Pulsar (like Kafka) strictly better at streaming, and RocketMQ (like ActiveMQ) strictly better at messaging?\n\n========================================\n\nComments:\n- Apache Pulsar now has a RocketMQ on Pulsar. github.com/streamnative/rop","metadata":{"transformedAt":"2026-08-18T18:33:20.142Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":19,"estimatedTokens":180}}258{"id":"stack-4971437","source":"stackoverflow","questionId":4971437,"title":"RabbitMQ reordering messages","tags":["rabbitmq","publish-subscribe","priority-queue","amqp"],"text":"Title: RabbitMQ reordering messages\nTags: rabbitmq, publish-subscribe, priority-queue, amqp\nSource: Stack Overflow\n\nQuestion:\nRabbitMQ ticks all the boxes for the project I am planning, save one. I would have different workers listening on a queue and it is important that they process the newest messages (i.e., latest sequence number) first (LIFO).\n\nMy application is such that newer messages pretty much obsolete older messages. If you have workers to spare you could still process the older messages but it is important the newer ones are done first.\n\nAfter trawling the various forums and such I can only see one solution and that is for a client to process a message it should first:\n\n- consume all messages\n\n- re-order them according to the sequence number\n\n- re-submit to the queue\n\n- consume the first message\n\nUgly and problematic if the client dies halfway. But mabye somebody here has a better solution. \n\nMy research is based (in part) on:\n\n- http://groups.google.com/group/rabbitmq-discuss/browse_thread/thread/e79e77d86bc7a3b8?fwc=1\n\n- http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/2010-July/007934.html\n\n- http://groups.google.com/group/rabbitmq-discuss/browse_thread/thread/e40d1069dcebe2cc\n\n- http://old.nabble.com/Priority-Queue-implementation-and-performance-td29946348.html\n\nNote: the expected traffic of messages will roughly be in the range of 1 msg/hour for some queues and 100/minute for others. So nothing stellar.\n\n========================================\n\nTop Answer:\nOne possibility might be to use `basic.get` in a loop and wait for the response `basic-ok.message-count` to become zero (throwing away all other messages):\n\n```\nwhile ( = ) {\n if (.message-count == 0) {\n // Now is the most recent message on this queue\n break;\n } else if () {\n // Someone else got it\n }\n}\n```\n\nOf course, you'd have to set up the message routing patterns on the broker such that 1 consumer throwing away messages doesn't mess with another. Try to avoid re queueing messages as they will re queue at the top of the stack, making them look like the most recent.\n\n========================================\n\nCode:\n```text\nwhile (<get ok> = <call basic.get>) {\n if (<get ok>.message-count == 0) {\n // Now <get ok> is the most recent message on this queue\n break;\n } else if (<is get-empty>) {\n // Someone else got it\n }\n}\n```\n\n```text\nbasic.get\n```\n\n```text\nbasic-ok.message-count\n```\n\n========================================\n\nComments:\n- Thanks for the reply. However, I wouldn't want one consumer starving the others of work. I'd rather have the other consumers work on slightly less recent messages (which still provide some information) than have them sit around idling because consumer X emptied the queue. Though this also depends on the message rates I guess.","metadata":{"transformedAt":"2026-08-18T18:33:20.142Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":77,"estimatedTokens":698}}259{"id":"stack-36106216","source":"stackoverflow","questionId":36106216,"title":"Optimizing Celery for third party HTTP calls","tags":["python","rabbitmq","celery","scalability"],"text":"Title: Optimizing Celery for third party HTTP calls\nTags: python, rabbitmq, celery, scalability\nSource: Stack Overflow\n\nQuestion:\nWe are using celery to make third party http calls. We have around 100+ of tasks which simply calls the third party HTTP API calls. Some tasks call the API's in bulk, for example half a million requests at 4 AM in morning, while some are continuous stream of API calls receiving requests almost once or twice per second.\n\nMost of API call response time is between 500 - 800 ms.\n\nWe are seeing very slow delivery rates with celery. For most of the above tasks, the max delivery rate is around 100/s (max) to almost 1/s (min). I believe this is very poor and something is definitely wrong, but I am not able to figure out what it is.\n\nWe started with cluster of 3 servers and incrementally made it a cluster of 7 servers, but with no improvement. We have tried with different concurrency settings from autoscale to fixed 10, 20, 50, 100 workers. There is no result backend and our broker is RabbitMQ.\n\nSince our task execution time is very small, less than a second for most, we have also tried making prefetch count unlimited to various values.\n\n`--time-limit=1800 --maxtasksperchild=1000 -Ofair -c 64 --config=celeryconfig_production`\n\nServers are 64 G RAM, Centos 6.6.\n\nCan you give me idea on what could be wrong or pointers on how to solve it? \n\nShould we go with gevents? Though I have little of idea of what it is.\n\n========================================\n\nCode:\n```text\n--time-limit=1800 --maxtasksperchild=1000 -Ofair -c 64 --config=celeryconfig_production\n```\n\n========================================\n\nComments:\n- How filled are your queues in RabbitMQ? RabbitMQ is fastest when the queues are empty. You can monitor RabbitMQ machine's CPU utilization. If you see heavy CPU utilization, probably, it is because RabbitMQ is doing a lot to cope up with huge queue size.\n- Might sound silly and sure you payed attention to this but have you checked if the third party server is behaving well under load? Is it still responding in 500-800ms even when you hit it with many concurrent request?\n- rabbitmq.com/blog/2012/05/11/…\n- What library are you using for the 3rd part api? are you using `requests` module?\n- Yes, we are using requests module @ahmed\n- Are you using `requests.session`? it improve the HTTP speed by keeping the connection alive\n- Your question talks about delivery rate and about gevents, which indicates your doubt on the speed of completing the HTTP requests too. You can divide and rule this issue by first figuring out where the issue exists. Is it with RabbitMQ or with task execution in workers? You can use Celery Flower for monitoring. Also profile, log and monitor the performance from your workers. If HTTP calls are the culprit you can use grequests python module for async calls. Also, consider intelligently not sending concurrent calls to the same 3rd party server.\n- Have you tried to increase the size of the connection pool from requests `requests.adapters.DEFAULT_POOLSIZE` ?\n- Also in some specific cases GIL doesn't release after 100ms","metadata":{"transformedAt":"2026-08-18T18:33:20.142Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":42,"estimatedTokens":779}}260{"id":"stack-40528775","source":"stackoverflow","questionId":40528775,"title":"RabbitMQ node authentification failed after changing cookie file","tags":["windows","cookies","server","rabbitmq","messaging"],"text":"Title: RabbitMQ node authentification failed after changing cookie file\nTags: windows, cookies, server, rabbitmq, messaging\nSource: Stack Overflow\n\nQuestion:\nI have multiple RabbitMQ nodes running on different machines. After installing each node I failed to specify a common cookie for each of them to use so I had to go back and manually change the file .erlang.cookie . My issue is that after doing this I get conflicting error messages. If i do rabbitmqctl status \nI get the following error: \n\n \n\n### DIAGNOSTICS\n\n \n attempted to contact: ['rabbit@nc-mso-test01']\n\n \n rabbit@nc-mso-test01: * connected to epmd (port 4369) on\n nc-mso-test01 * epmd reports node 'rabbit' running on port 25672 *\n TCP connection succeeded but Erlang distribution failed\n\n \n \n Authentication failed (rejected by the remote node), please check\n the Erlang cookie\n \n \n current node details:\n - node name: 'rabbitmq-cli-45@nc-mso-test01'\n - home dir: C:\\Users\\jol\n - cookie hash: 9/Hx6l+wLQv3NkmSDFqBog==\n\nWhatever script I call, I get the same error. I tried restarting the service, removing and installing it through rabbitmq-service. The error persists. From what I can gather from other posts, the reason might be that the node and the erlang broker are running on separate users and each of them have a different version of the cookie, one is stuck with the old one. \n\nHow can I make the server and node restart, so that both of them use the new cookie file?\n\n========================================\n\nTop Answer:\nDocumentation says: \n\n The cookie file used by the Windows service account and the user running CLI tools must be synchronised. RabbitMQ-Clustering Guide\n\nOn Erlang versions starting with 20.2, the cookie file locations are:\n\n- For user running CLI tools - usually `C:\\Users\\%USERNAME%\\.erlang.cookie` for user `%USERNAME%`\nFor the RabbitMQ Windows service - `%USERPROFILE%\\.erlang.cookie`\n(usually `C:\\WINDOWS\\system32\\config\\systemprofile`)\n\nOn Erlang versions prior to 20.2 (e.g. 19.3 or 20.1), the cookie file locations are:\n\n- For user running CLI tools - usually `C:\\Users\\%USERNAME%\\.erlang.cookie` for user `%USERNAME%`\n\n- For the RabbitMQ Windows service - `%WINDIR%\\.erlang.cookie` (usually `C:\\Windows\\.erlang.cookie`)\n\n========================================\n\nCode:\n```text\nC:\\Users\\%USERNAME%\\.erlang.cookie\n```\n\n```text\n%USERNAME%\n```\n\n```text\n%USERPROFILE%\\.erlang.cookie\n```\n\n```text\nC:\\WINDOWS\\system32\\config\\systemprofile\n```\n\n```text\nC:\\Users\\%USERNAME%\\.erlang.cookie\n```\n\n```text\n%USERNAME%\n```\n\n```text\n%WINDIR%\\.erlang.cookie\n```\n\n```text\nC:\\Windows\\.erlang.cookie\n```\n\n========================================\n\nComments:\n- To eliminate the 50/50 chance... To sync: copy the C:\\Windows cookie to overwrite the C:\\Users\\%USER% cookie\n- rabbitmq.com/install-windows-manual.html, the issue is also described here, with the path for the two cookies given .\n- @William Yea, the bottom advice I reached when anyone asks me about rabbitmq is \"Read the documentation at least 3 times\". All the issues I have had with it, I found the solution just by carefully re reading the documentation.\n- Helped me too. RabbitMQ server restart was needed after sync cookies (if it's not obvious).","metadata":{"transformedAt":"2026-08-18T18:33:20.142Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":96,"estimatedTokens":800}}261{"id":"stack-40579804","source":"stackoverflow","questionId":40579804,"title":"Django Celery Beat admin updating Cron Schedule Periodic task not taking effect","tags":["django","centos","rabbitmq","celery","django-celery"],"text":"Title: Django Celery Beat admin updating Cron Schedule Periodic task not taking effect\nTags: django, centos, rabbitmq, celery, django-celery\nSource: Stack Overflow\n\nQuestion:\nI'm running a site using Django 10, RabbitMQ, and Celery 4 on CentOS 7.\n\nMy Celery Beat and Celery Worker instances are controlled by supervisor and I'm using the django celery database scheduler.\n\nI've scheduled a cron style task using the cronsheduler in Django-admin.\n\nWhen I start celery beat and worker instances the job fires as expected.\n\nBut if a change the schedule time in Django-admin then the changes are not picked up unless I restart the celery-beat instance.\n\nIs there something I am missing or do I need to write my own scheduler?\n\nCelery Beat, with the 'django_celery_beat.schedulers.DatabaseScheduler' loads the schedule from the database. According to the following doc https://media.readthedocs.org/pdf/django-celery-beat/latest/django-celery-beat.pdf this should force Celery Beat to reload:\n\nA schedule that runs at a specific interval (e.g. every 5 seconds).\n•\ndjango_celery_beat.models.CrontabSchedule\nA\nschedule\nwith\nfields\nlike\nentries\nin\ncron: minute hour day-of-week day_of_month month_of_year.\n\ndjango_celery_beat.models.PeriodicTasks\nThis model is only used as an index to keep track of when the schedule has changed. Whenever you update a PeriodicTask a counter in this table is also incremented, which tells the celery beat\nservice to reload the schedule from the database.\nIf you update periodic tasks in bulk, you will need to update the counter manually:\n\n```\nfrom django_celery_beat.models import PeriodicTasks\nPeriodicTasks.changed()\n```\n\nFrom the above I would expect the Celery Beat process to check the table regularly for any changes.\n\n========================================\n\nTop Answer:\ni have changed the celery from 4.0 to 3.1.25, django to 1.9.11 and installed djcelery 3.1.17. Then test again, It's OK. So, maybe it's a bug.\n\n========================================\n\nCode:\n```text\nfrom django_celery_beat.models import PeriodicTasks\nPeriodicTasks.changed()\n```\n\n========================================\n\nComments:\n- possible duplicate of: stackoverflow.com/questions/21666229/…\n- Don't think it is a duplicate as I want Celery Beat to detect when the schedule has been updated in the database.\n- Definitely, not a duplicated. The linked question is talking about reload celery worker if Django settings change (a static `.py` file), not about `celery beat` and reload when database tasks change.\n- Looks like this Github issue is a discussion of the same problem: (they reference this post). Some solutions proposed, none simple. Also here. No solution given.\n- You mean, run separate process like: `celery beat ...` and `celery worker ...`? I already doing this and still not working.\n- Yes, using the database scheduler. Whenever the settings (time etc) change in the database you need to restart the Celery Beat process so that it reads the database again.\n- If you have to restart Celery Beat process manually you are not solving the problem, aren't you? \"But if a change the schedule time in Django-admin then the changes are not picked up unless I restart the celery-beat instance.\"\n- You need to add a signal when the record is saved to post a message to restart Celery Beat.\n- Whilst it's not fully solving the problem as such, it's a solution that works for now. I'm not sure how the Celery Beat process could detect changes to the database? FYI the database is Postgresql.\n- Ah OK, I missed the signal part to auto-reload Celery Beat. It is suppose to be auto-reload when something changes on DB reading `PeriodicTasks` but it doesn't work. After debugging the library, I agree with @kenda-zheng, it sames a bug. Finally, I downgrade the project as @kenda-zheng response and it works.","metadata":{"transformedAt":"2026-08-18T18:33:20.142Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":69,"estimatedTokens":957}}262{"id":"stack-20615765","source":"stackoverflow","questionId":20615765,"title":"how to stop rabbitmq servers","tags":["node.js","rabbitmq","pid"],"text":"Title: how to stop rabbitmq servers\nTags: node.js, rabbitmq, pid\nSource: Stack Overflow\n\nQuestion:\nI am trying to start a node app and I think rabbitmq is getting in the way.\n\nSimilar to this thread: \"node with name \"rabbit\" already running\", but also \"unable to connect to node 'rabbit'\"\n\n```\n$ ps aux | grep erl\nrabbitmq 1327 0.0 0.0 2376 300 ? S Dec13 0:00 /usr/lib/erlang/erts-5.8.5/bin/epmd -daemon\nrabbitmq 1344 0.0 0.3 59560 14888 ? Sl Dec13 0:10 /usr/lib/erlang/erts-5.8.5/bin/beam.smp -W w -K true -A30 -P 1048576 -- -root /usr/lib/erlang -progname erl -- -home /var/lib/rabbitmq -- -noshell -noinput -sname rabbit@jasonshark -boot /var/lib/rabbitmq/mnesia/rabbit@jasonshark-plugins-expand/rabbit -kernel inet_default_connect_options [{nodelay,true}] -sasl errlog_type error -sasl sasl_error_logger false -rabbit error_logger {file,\"/var/log/rabbitmq/rabbit@jasonshark.log\"} -rabbit sasl_error_logger {file,\"/var/log/rabbitmq/rabbit@jasonshark-sasl.log\"} -os_mon start_cpu_sup true -os_mon start_disksup false -os_mon start_memsup false -mnesia dir \"/var/lib/rabbitmq/mnesia/rabbit@jasonshark\"\nrabbitmq 1700 0.0 0.0 2136 284 ? Ss Dec13 0:00 /usr/lib/erlang/lib/os_mon-2.2.7/priv/bin/cpu_sup\n1000 15564 0.0 0.0 4392 820 pts/1 S+ 19:23 0:00 grep --color=auto erl\n```\n\nI know I need to run `kill -9 {pid of rabbitmq process}` now, but which number is the pid?\n\nHow do I stop everything to do with rabbitmq, I don't want it interfering with my node js\n\n========================================\n\nTop Answer:\nI just started using RabbitMQ today and learned that you can cleanly shutdown a `rabbitmq-server` process by using the command `rabbitmqctl stop`.\n\nThis may not apply to your situation since you don't seem to be the person who launched rabbitmq on your server in the first place but if you have `rabbitmqctl` in your path, you can try using it to attempt a clean shutdown.\n\n========================================\n\nCode:\n```text\n$ ps aux | grep erl\nrabbitmq 1327 0.0 0.0 2376 300 ? S Dec13 0:00 /usr/lib/erlang/erts-5.8.5/bin/epmd -daemon\nrabbitmq 1344 0.0 0.3 59560 14888 ? Sl Dec13 0:10 /usr/lib/erlang/erts-5.8.5/bin/beam.smp -W w -K true -A30 -P 1048576 -- -root /usr/lib/erlang -progname erl -- -home /var/lib/rabbitmq -- -noshell -noinput -sname rabbit@jasonshark -boot /var/lib/rabbitmq/mnesia/rabbit@jasonshark-plugins-expand/rabbit -kernel inet_default_connect_options [{nodelay,true}] -sasl errlog_type error -sasl sasl_error_logger false -rabbit error_logger {file,\"/var/log/rabbitmq/rabbit@jasonshark.log\"} -rabbit sasl_error_logger {file,\"/var/log/rabbitmq/rabbit@jasonshark-sasl.log\"} -os_mon start_cpu_sup true -os_mon start_disksup false -os_mon start_memsup false -mnesia dir \"/var/lib/rabbitmq/mnesia/rabbit@jasonshark\"\nrabbitmq 1700 0.0 0.0 2136 284 ? Ss Dec13 0:00 /usr/lib/erlang/lib/os_mon-2.2.7/priv/bin/cpu_sup\n1000 15564 0.0 0.0 4392 820 pts/1 S+ 19:23 0:00 grep --color=auto erl\n```\n\n```text\nkill -9 {pid of rabbitmq process}\n```\n\n```text\nsudo /etc/init.d/rabbitmq-server stop\n```\n\n```text\nps -eaf | grep erl\n```\n\n```text\npgrep <proc_name>\n```\n\n```text\npgrep\n```\n\n```text\nrabbitmq-server\n```\n\n```text\nrabbitmqctl stop\n```\n\n```text\nrabbitmqctl\n```\n\n```text\nsudo pkill beam.smp\n```\n\n```text\nbeam.smp\n```\n\n```text\nbrew\n```\n\n```text\nbrew services restart rabbitmq\n```\n\n```text\nbrew services start rabbitmq\n```\n\n```text\nbrew services stop rabbitmq\n```\n\n```text\nservice rabbitmq-server stop\n```\n\n```text\nservice rabbitmq-server start\n```\n\n========================================\n\nComments:\n- **Stop Rabbit** MQ : `sudo -u rabbitmq rabbitmqctl stop`\n- sorry I'm a noob, what's proc_name for this case?\n- The process name: in your case `epmd` or `beam.smp` or `cpu_sup`.\n- this works for a few seconds and it comes right back. rabbitmq is like a freaken virus. it won't go away.","metadata":{"transformedAt":"2026-08-18T18:33:20.142Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":17,"totalLines":110,"estimatedTokens":970}}263{"id":"stack-19240290","source":"stackoverflow","questionId":19240290,"title":"How do i implement Headers Exchange in RabbitMQ using Java?","tags":["java","rabbitmq"],"text":"Title: How do i implement Headers Exchange in RabbitMQ using Java?\nTags: java, rabbitmq\nSource: Stack Overflow\n\nQuestion:\ni am a newbie trying to implement Headers exchange in java client . im aware that This is what the \"x-match\" binding argument is for. When the \"x-match\" argument is set to \"any\", just one matching header value is sufficient. Alternatively, setting \"x-match\" to \"all\" mandates that all the values must match.\nbut can anyone provide me a skeleton code for better understanding.\n\n========================================\n\nCode:\n```text\nchannel.exchangeDeclare(\"myExchange\", \"headers\", true);\n```\n\n```text\nchannel.queueDeclare(\"myQueue\", true, false, false, null);\n```\n\n```text\nMap<String, Object> bindingArgs = new HashMap<String, Object>();\nbindingArgs.put(\"x-match\", \"any\"); //any or all\nbindingArgs.put(\"headerName#1\", \"headerValue#1\");\nbindingArgs.put(\"headerName#2\", \"headerValue#2\");\n\n...\nchannel.queueBind(\"myQueue\", \"myExchange\", \"\", bindingArgs);\n...\n```\n\n========================================\n\nComments:\n- Good explanation of exchange/queue relationship. Thanks!","metadata":{"transformedAt":"2026-08-18T18:33:20.142Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":34,"estimatedTokens":274}}264{"id":"stack-33087332","source":"stackoverflow","questionId":33087332,"title":"How to setup multiple topics in a RabbitMQ Java config class using Spring Framework?","tags":["java","spring","rabbitmq"],"text":"Title: How to setup multiple topics in a RabbitMQ Java config class using Spring Framework?\nTags: java, spring, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm trying to create a RabbitMQ configuration class using Spring Framework. The documentation does not say anything on how to setup multiple topics in a TopicExchange. How do I do that? So far, I have this Java code but I'm not clear on how to setup multiple topics in the binding method below since it only returns one binding. Would I not need multiple bindings if I need multiple topics?\n\n```\n@Configuration\n@EnableRabbit\npublic class MessageReceiverConfiguration {\n\n final static String queueName = \"identity\";\n final static String topic1 = \"NewUserSignedUp\";\n final static String topic2 = \"AccountCreated\";\n\n @Autowired\n RabbitTemplate rabbitTemplate;\n\n @Bean\n Queue queue() {\n return new Queue(queueName, false);\n }\n\n @Bean\n TopicExchange exchange() {\n return new TopicExchange(\"DomainEvents\");\n } \n\n @Bean\n Binding binding(Queue queue, TopicExchange exchange) {\n // How to setup multiple topics?\n return BindingBuilder.bind(queue).to(exchange).with(topic1);\n }\n\n @Bean\n SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {\n\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n\n container.setConnectionFactory(connectionFactory);\n container.setQueueNames(queueName);\n container.setMessageListener(listenerAdapter);\n container.setAcknowledgeMode(AcknowledgeMode.AUTO);\n\n return container;\n }\n\n @Bean\n MessageReceiver receiver() {\n return new MessageReceiver();\n }\n\n @Bean\n MessageListenerAdapter listenerAdapter(MessageReceiver receiver) {\n return new MessageListenerAdapter(receiver, \"receiveMessage\");\n } \n\n}\n```\n\n========================================\n\nTop Answer:\n`List bindings()` not supported by spring boot 2.+ versions.\nThis one works;\n\n```\n@Bean\npublic Declarables bindings() {\n\n return new Declarables(\n BindingBuilder\n .bind(bookingAddQueue())\n .to(bookingExchange())\n .with(\"add\")\n .noargs(),\n BindingBuilder\n .bind(bookingEditQueue())\n .to(bookingExchange())\n .with(\"edit\")\n .noargs());\n}\n```\n\n========================================\n\nCode:\n```text\n@Configuration\n@EnableRabbit\npublic class MessageReceiverConfiguration {\n\n final static String queueName = \"identity\";\n final static String topic1 = \"NewUserSignedUp\";\n final static String topic2 = \"AccountCreated\";\n\n @Autowired\n RabbitTemplate rabbitTemplate;\n\n @Bean\n Queue queue() {\n return new Queue(queueName, false);\n }\n\n @Bean\n TopicExchange exchange() {\n return new TopicExchange(\"DomainEvents\");\n } \n\n @Bean\n Binding binding(Queue queue, TopicExchange exchange) {\n // How to setup multiple topics?\n return BindingBuilder.bind(queue).to(exchange).with(topic1);\n }\n\n @Bean\n SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {\n\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n\n container.setConnectionFactory(connectionFactory);\n container.setQueueNames(queueName);\n container.setMessageListener(listenerAdapter);\n container.setAcknowledgeMode(AcknowledgeMode.AUTO);\n\n return container;\n }\n\n @Bean\n MessageReceiver receiver() {\n return new MessageReceiver();\n }\n\n @Bean\n MessageListenerAdapter listenerAdapter(MessageReceiver receiver) {\n return new MessageListenerAdapter(receiver, \"receiveMessage\");\n } \n\n}\n```\n\n```text\n@Bean\nList<Binding> bindings() {\n\n return Arrays.AsList(BindingBuilder.bind(queue()).to(exchange()).with(topic1), \n BindingBuilder.bind(queue()).to(exchange()).with(topic2));\n}\n```\n\n```text\nBinding\n```\n\n```text\nBinding\n```\n\n```text\n@Bean\npublic Declarables bindings() {\n\n return new Declarables(\n BindingBuilder\n .bind(bookingAddQueue())\n .to(bookingExchange())\n .with(\"add\")\n .noargs(),\n BindingBuilder\n .bind(bookingEditQueue())\n .to(bookingExchange())\n .with(\"edit\")\n .noargs());\n}\n```\n\n```text\nList<Binding> bindings()\n```\n\n========================================\n\nComments:\n- this is not working on my project, however when I create all builders separately it works. do you have any comment on this? I'm using spring boot 2.1.2.RELEASE\n- @MustafaGüven In 2.1.0.RELEASE I achieved to do it with `Declarables` as it is advised here: baeldung.com/rabbitmq-spring-amqp","metadata":{"transformedAt":"2026-08-18T18:33:20.142Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":186,"estimatedTokens":1173}}265{"id":"stack-12748284","source":"stackoverflow","questionId":12748284,"title":"Converting Message from RabbitMQ into string/json","tags":["java","json","spring","rabbitmq","amqp"],"text":"Title: Converting Message from RabbitMQ into string/json\nTags: java, json, spring, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI am currently struggling hard with a fair simple problem. I want to receive a message from RabbitMQ and have that transformed into a string (or later a json object). But all I get is bytes.\n\nThe *Message* object displays itself as a string that way\n\n```\n(Body:'{\"cityId\":644}'; ID:null; Content:application/json; Headers:{}; Exchange:; RoutingKey:pages.type.index; Reply:null; DeliveryMode:NON_PERSISTENT; DeliveryTag:1)\n```\n\nThe configuration class (using spring)\n\n```\n@Configuration\npublic class RabbitConfiguration {\n\n @Bean\n public CachingConnectionFactory connectionFactory() {\n CachingConnectionFactory connectionFactory = new CachingConnectionFactory(\"www.example.com\");\n connectionFactory.setUsername(\"xxxx\");\n connectionFactory.setPassword(\"xxxx\");\n return connectionFactory;\n }\n\n @Bean\n public MessageConverter jsonMessageConverter(){\n JsonMessageConverter jsonMessageConverter = new JsonMessageConverter();\n return jsonMessageConverter;\n }\n\n @Bean\n public SimpleMessageListenerContainer messageListenerContainer(){\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory());\n container.setAutoStartup(false);\n container.setQueues(indexQueue());\n container.setConcurrentConsumers(1);\n container.setAcknowledgeMode(AcknowledgeMode.AUTO);\n container.setMessageListener(new MessageListenerAdapter(pageListener(), jsonMessageConverter()));\n return container;\n }\n\n @Bean\n public Queue indexQueue(){\n return new Queue(\"pages.type.index\");\n }\n\n @Bean\n public MessageListener pageListener(){\n return new PageQueueListener();\n }\n\n}\n```\n\nand the message listener\n\n```\npublic class PageQueueListener implements MessageListener {\n\n public void onMessage(Message message) {\n System.out.println(message);\n System.out.println(message.getBody());\n }\n }\n```\n\nmy problem is, that the *getBody()* method displayes *[B@4dbb73b0* so nothing is ever converted. Neither to a string nor to a json object :(\n\nI feel stupid, but I cannot find a solution here\n\n========================================\n\nTop Answer:\nIf you want to parse to a JSONObject, the best way is add the RabbitMQ message to a StringBuilder in String format. Then parse the StringBuilder into a JSONObject, by using any of the conversion utils.\n\nFor e.g.:\n\n```\nStringBuilder sb = new StringBuilder();\nsb.append(publisher.toString());\npayload = (JSONObject)jsonParser.parse(sb.toString());\n```\n\n========================================\n\nCode:\n```text\n(Body:'{\"cityId\":644}'; ID:null; Content:application/json; Headers:{}; Exchange:; RoutingKey:pages.type.index; Reply:null; DeliveryMode:NON_PERSISTENT; DeliveryTag:1)\n```\n\n```text\n@Configuration\npublic class RabbitConfiguration {\n\n @Bean\n public CachingConnectionFactory connectionFactory() {\n CachingConnectionFactory connectionFactory = new CachingConnectionFactory(\"www.example.com\");\n connectionFactory.setUsername(\"xxxx\");\n connectionFactory.setPassword(\"xxxx\");\n return connectionFactory;\n }\n\n @Bean\n public MessageConverter jsonMessageConverter(){\n JsonMessageConverter jsonMessageConverter = new JsonMessageConverter();\n return jsonMessageConverter;\n }\n\n @Bean\n public SimpleMessageListenerContainer messageListenerContainer(){\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory());\n container.setAutoStartup(false);\n container.setQueues(indexQueue());\n container.setConcurrentConsumers(1);\n container.setAcknowledgeMode(AcknowledgeMode.AUTO);\n container.setMessageListener(new MessageListenerAdapter(pageListener(), jsonMessageConverter()));\n return container;\n }\n\n @Bean\n public Queue indexQueue(){\n return new Queue(\"pages.type.index\");\n }\n\n @Bean\n public MessageListener pageListener(){\n return new PageQueueListener();\n }\n\n}\n```\n\n```text\npublic class PageQueueListener implements MessageListener {\n\n public void onMessage(Message message) {\n System.out.println(message);\n System.out.println(message.getBody());\n }\n }\n```\n\n```text\nbyte[] body = message.getBody();\nSystem.out.println(new String(body));\n```\n\n```text\nmessage.getBody()\n```\n\n```text\nbyte[]\n```\n\n```text\nStringBuilder sb = new StringBuilder();\nsb.append(publisher.toString());\npayload = (JSONObject)jsonParser.parse(sb.toString());\n```\n\n========================================\n\nComments:\n- you are about to be kidding me... that worked, but how about the MessageConverter, doesn't that do anything?\n- Also if you look inside the source code for `org.springframework.amqp.core.Message` you'll find a method with signature `private String getBodyContentAsString()` which does it like this: `return new String(body, ENCODING);` ... therefore this should suffice as well: `System.out.println(new String(message.getBody(), Charset.defaultCharset().name()))`\n- I'm using getBody() method but it results out of memory exception exactly at the line of new String. Actually, after a long time running, it fails but the exception. Do you have any advice to overcome this problem?","metadata":{"transformedAt":"2026-08-18T18:33:20.142Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":170,"estimatedTokens":1310}}266{"id":"stack-26414812","source":"stackoverflow","questionId":26414812,"title":"HelloWorld example for sending an object over RabbitMQ via EasyNetQ between two different applications","tags":["c#","rabbitmq","easynetq"],"text":"Title: HelloWorld example for sending an object over RabbitMQ via EasyNetQ between two different applications\nTags: c#, rabbitmq, easynetq\nSource: Stack Overflow\n\nQuestion:\nHi I am attempting to send a simple object like through RabbitMQ via EasyNetQ. I'm having issues deserializing that object on the subscription side. Anyone able to show me a sample of how this works. Keep in mind the object being sent is defined in it's own project and not shared among the publisher and subscriber. Here is my sample, and perhaps you can tell me what is wrong with it?\n\nProgram A:\n\n```\nclass ProgramA\n{\n static void Main(string[] args)\n {\n using (var bus = RabbitHutch.CreateBus(\"host=localhost\"))\n {\n Console.WriteLine(\"Press any key to send the message\");\n Console.ReadKey();\n bus.Publish(new MessageA { Text = \"Hello World\" });\n Console.WriteLine(\"Press any key to quit\");\n Console.ReadKey();\n }\n }\n\n public class MessageA\n {\n public string Text { get; set; }\n }\n}\n```\n\nProgram B:\n\n```\nclass ProgramB\n{\n static void Main(string[] args)\n {\n using (var bus = RabbitHutch.CreateBus(\"host=localhost\"))\n {\n bus.Subscribe(\"\", HandleClusterNodes);\n Console.WriteLine(\"Press any key to quit\");\n Console.ReadKey();\n }\n }\n\n private static void HandleClusterNodes(MessageB obj)\n {\n Console.WriteLine(obj.Text);\n }\n\n [Queue(\"TestMessagesQueue\", ExchangeName = \"EasyNetQSample.ProgramA+MessageA:EasyNetQSample\")]\n public class MessageB\n {\n public string Text { get; set; }\n }\n}\n```\n\nHere is the error I'm receiving:\n\n```\nDEBUG: HandleBasicDeliver on consumer: f9ded52d-039c-411a-9b9f-5c8ee3301854, deliveryTag: 1\nDEBUG: Received\n RoutingKey: ''\n CorrelationId: 'ec41faea-a0c8-4ffd-8163-2cbf85d45fcd'\n ConsumerTag: 'f9ded52d-039c-411a-9b9f-5c8ee3301854'\n DeliveryTag: 1\n Redelivered: False\nERROR: Exception thrown by subscription callback.\n Exchange: 'EasyNetQSample.ProgramA+MessageA:EasyNetQSample'\n Routing Key: ''\n Redelivered: 'False'\nMessage:\n{\"Text\":\"Hello World\"}\nBasicProperties:\nContentType=NULL, ContentEncoding=NULL, Headers=[], DeliveryMode=2, Priority=0, CorrelationId=ec41faea-a0c8-4ffd-8163-2cbf85d45fcd, ReplyTo=NULL, Expiration=NULL, MessageId=NULL, Timestamp=0, Type=EasyNetQSample.ProgramA+MessageA:EasyNetQSample, UserId=NULL, AppId=NULL, ClusterId=NULL\nException:\nSystem.AggregateException: One or more errors occurred. ---> EasyNetQ.EasyNetQException: Cannot find type EasyNetQSample.ProgramA+MessageA:EasyNetQSample\n at EasyNetQ.TypeNameSerializer.DeSerialize(String typeName)\n at EasyNetQ.DefaultMessageSerializationStrategy.DeserializeMessage(MessageProperties properties, Byte[] body)\n at EasyNetQ.RabbitAdvancedBus.<>c__DisplayClass19.b__18(Byte[] body, MessageProperties properties, MessageReceivedInfo messageReceivedInfo)\n at EasyNetQ.RabbitAdvancedBus.<>c__DisplayClass1e.b__1d(Byte[] body, MessageProperties properties, MessageReceivedInfo receviedInfo)\n at EasyNetQ.Consumer.HandlerRunner.InvokeUserMessageHandler(ConsumerExecutionContext context)\n --- End of inner exception stack trace ---\n---> (Inner Exception #0) EasyNetQ.EasyNetQException: Cannot find type EasyNetQSample.ProgramA+MessageA:EasyNetQSample\n at EasyNetQ.TypeNameSerializer.DeSerialize(String typeName)\n at EasyNetQ.DefaultMessageSerializationStrategy.DeserializeMessage(MessageProperties properties, Byte[] body)\n at EasyNetQ.RabbitAdvancedBus.<>c__DisplayClass19.b__18(Byte[] body, MessageProperties properties, MessageReceivedInfo messageReceivedInfo)\n at EasyNetQ.RabbitAdvancedBus.<>c__DisplayClass1e.b__1d(Byte[] body, MessageProperties properties, MessageReceivedInfo receviedInfo)\n at EasyNetQ.Consumer.HandlerRunner.InvokeUserMessageHandler(ConsumerExecutionContext context)What do I need to do to be able to properly deserialize `MessageA`?\n\n========================================\n\nTop Answer:\nFurkan is correct that your problem is that the subscriber needs access to the `MessageA` type defined by your publisher so that it can deserialize the message to that type. From the EasyNetQ docs\n\n When messages are serialized, EasyNetQ stores the message type name in the Type property of the message properties. This metadata is sent along with your message to any subscribers who can then use it to deserialize the message.\n\nThis amounts to a tight shared contract between publisher and consumer. If you want to loosen that up then there are a couple of things you can do:\n\nYou can publish and subscribe based on an interface (e.g. `IMessage`, from which you can derive `MessageA`). You will still need access to the `MessageA` type in order to cast the received message, but you can publish and subscribe without specifying a specific derived type.\n\nYou can create a single, shared \"container\" type (e.g. `MessageContainer`) and then serialize/deserialize your type into an instance of the container type as XML, JSON, whatever. Your subscriber can pull the data out of the container and parse it however it wants to. You could even include a schema or version info in the container header to give some hints to the subscriber about how to parse the data. The point it that they never have to turn it into a defined type and therefore don't need access to a bunch of types, just to the `MessageContainer` type so they can get at the serialized content.\n\n========================================\n\nCode:\n```text\nclass ProgramA\n{\n static void Main(string[] args)\n {\n using (var bus = RabbitHutch.CreateBus(\"host=localhost\"))\n {\n Console.WriteLine(\"Press any key to send the message\");\n Console.ReadKey();\n bus.Publish(new MessageA { Text = \"Hello World\" });\n Console.WriteLine(\"Press any key to quit\");\n Console.ReadKey();\n }\n }\n\n public class MessageA\n {\n public string Text { get; set; }\n }\n}\n```\n\n```text\nclass ProgramB\n{\n static void Main(string[] args)\n {\n using (var bus = RabbitHutch.CreateBus(\"host=localhost\"))\n {\n bus.Subscribe<MessageB>(\"\", HandleClusterNodes);\n Console.WriteLine(\"Press any key to quit\");\n Console.ReadKey();\n }\n }\n\n private static void HandleClusterNodes(MessageB obj)\n {\n Console.WriteLine(obj.Text);\n }\n\n [Queue(\"TestMessagesQueue\", ExchangeName = \"EasyNetQSample.ProgramA+MessageA:EasyNetQSample\")]\n public class MessageB\n {\n public string Text { get; set; }\n }\n}\n```\n\n```text\nDEBUG: HandleBasicDeliver on consumer: f9ded52d-039c-411a-9b9f-5c8ee3301854, deliveryTag: 1\nDEBUG: Received\n RoutingKey: ''\n CorrelationId: 'ec41faea-a0c8-4ffd-8163-2cbf85d45fcd'\n ConsumerTag: 'f9ded52d-039c-411a-9b9f-5c8ee3301854'\n DeliveryTag: 1\n Redelivered: False\nERROR: Exception thrown by subscription callback.\n Exchange: 'EasyNetQSample.ProgramA+MessageA:EasyNetQSample'\n Routing Key: ''\n Redelivered: 'False'\nMessage:\n{\"Text\":\"Hello World\"}\nBasicProperties:\nContentType=NULL, ContentEncoding=NULL, Headers=[], DeliveryMode=2, Priority=0, CorrelationId=ec41faea-a0c8-4ffd-8163-2cbf85d45fcd, ReplyTo=NULL, Expiration=NULL, MessageId=NULL, Timestamp=0, Type=EasyNetQSample.ProgramA+MessageA:EasyNetQSample, UserId=NULL, AppId=NULL, ClusterId=NULL\nException:\nSystem.AggregateException: One or more errors occurred. ---> EasyNetQ.EasyNetQException: Cannot find type EasyNetQSample.ProgramA+MessageA:EasyNetQSample\n at EasyNetQ.TypeNameSerializer.DeSerialize(String typeName)\n at EasyNetQ.DefaultMessageSerializationStrategy.DeserializeMessage(MessageProperties properties, Byte[] body)\n at EasyNetQ.RabbitAdvancedBus.<>c__DisplayClass19.<Consume>b__18(Byte[] body, MessageProperties properties, MessageReceivedInfo messageReceivedInfo)\n at EasyNetQ.RabbitAdvancedBus.<>c__DisplayClass1e.<Consume>b__1d(Byte[] body, MessageProperties properties, MessageReceivedInfo receviedInfo)\n at EasyNetQ.Consumer.HandlerRunner.InvokeUserMessageHandler(ConsumerExecutionContext context)\n --- End of inner exception stack trace ---\n---> (Inner Exception #0) EasyNetQ.EasyNetQException: Cannot find type EasyNetQSample.ProgramA+MessageA:EasyNetQSample\n at EasyNetQ.TypeNameSerializer.DeSerialize(String typeName)\n at EasyNetQ.DefaultMessageSerializationStrategy.DeserializeMessage(MessageProperties properties, Byte[] body)\n at EasyNetQ.RabbitAdvancedBus.<>c__DisplayClass19.<Consume>b__18(Byte[] body, MessageProperties properties, MessageReceivedInfo messageReceivedInfo)\n at EasyNetQ.RabbitAdvancedBus.<>c__DisplayClass1e.<Consume>b__1d(Byte[] body, MessageProperties properties, MessageReceivedInfo receviedInfo)\n at EasyNetQ.Consumer.HandlerRunner.InvokeUserMessageHandler(ConsumerExecutionContext context)<---\n```\n\n```text\nMessageA\n```\n\n```text\nbus.Publish<String>(\"Excellent.\");\n```\n\n```text\nbus.Publish<string>(JsonConvert.SerializeObject(new MessageA { Text = \"Hello World\" }));\n```\n\n```text\nbus.Subscribe<string>(\"\", HandleClusterNodes);\n\nprivate static void HandleClusterNodes(string obj)\n{\n var myMessage = (MessageB)JsonConvert.DeserializeObject<MessageB>(obj);\n Console.WriteLine(myMessage.Text);\n}\n```\n\n```text\nbus.Publish<string>(JsonConvert.SerializeObject(new MessageA { Text = \"Hello World\" }), \"topic.name\");\n\nbus.Subscribe<string>(\"\", HandleClusterNodes, new Action<EasyNetQ.FluentConfiguration.ISubscriptionConfiguration>( o => o.WithTopic(\"topic.name\")));\n```\n\n```text\nvar yourMessage = new Message<string>(JsonConvert.SerializeObject(new MessageA { Text = \"Hello World\" }));\nbus.Advanced.Publish<string>(new Exchange(\"YourExchangeName\"), \"your.routing.key\", false, false, yourMessage);\n```\n\n```text\nIQueue yourQueue = bus.Advanced.QueueDeclare(\"AnotherTestMessagesQueue\");\nIExchange yourExchange = bus.Advanced.ExchangeDeclare(\"YourExchangeName\", ExchangeType.Topic);\nbus.Advanced.Bind(yourExchange, yourQueue, \"your.routing.key\");\nbus.Advanced.Consume<string>(yourQueue, (msg, info) => HandleClusterNodes(msg.Body));\n```\n\n```text\nvar type = Type.GetType(nameParts[0] + \", \" + nameParts[1]);\n if (type == null)\n {\n throw new EasyNetQException(\n \"Cannot find type {0}\",\n typeName);\n }\n```\n\n```text\nMessageA\n```\n\n```text\nIMessage\n```\n\n```text\nMessageA\n```\n\n```text\nMessageA\n```\n\n```text\nMessageContainer\n```\n\n```text\nMessageContainer\n```\n\n```text\nbus.Publish<MessageA>(\"Excellent.\");\n```\n\n```text\nMessageA\n```\n\n========================================\n\nComments:\n- Excellent response @Furkan. Thank you!\n- Just realized. If I use a primitive type like string, How do I go about naming the exchange and queue, since it defaults to the type name?\n- @Jeremy I have updated my answer. But if you don't want to use the Advanced API, I'd suggest you to create a common class so EasyNetQ can handle serialization itself. Otherwise, it's the same as using the original RabbitMQ Client.","metadata":{"transformedAt":"2026-08-18T18:33:20.142Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":19,"totalLines":276,"estimatedTokens":2716}}267{"id":"stack-37680388","source":"stackoverflow","questionId":37680388,"title":"RabbitMQ Error: unable to connect to nodes : nodedown","tags":["rabbitmq","rabbitmqctl"],"text":"Title: RabbitMQ Error: unable to connect to nodes : nodedown\nTags: rabbitmq, rabbitmqctl\nSource: Stack Overflow\n\nQuestion:\nI am trying to do clustering using two Rhel instances. I am able to ping each other and even when i am trying to use command `empd -names`, i get it is up and running on 4369.When i am use the command as `sudo rabbitmqctl join_cluster rabbit@ip-10-23-20-36` i am getting the below error ensuring as well to i am stop_app first..\n\n```\nsudo rabbitmqctl join_cluster rabbit@ip-10-23-20-36\n```\n\nClustering node 'rabbit@ip-10-23-20-36' with 'rabbit@ip-10-23-209-142' ...\nError: unable to connect to nodes ['rabbit@ip-10-23-209-142']: nodedown\n\n### DIAGNOSTICS\n\nattempted to contact: ['rabbit@ip-10-23-209-142']\n\nrabbit@ip-10-23-209-142:\n * unable to connect to epmd (port 4369) on ip-10-23-209-142: nxdomain (non-existing domain)\n\ncurrent node details:\n- node name: 'rabbitmq-cli-80@ip-10-23-20-36'\n- home dir: /var/lib/rabbitmq\n- cookie hash: u7nRIpJ40Fd356iLbkDO6Q==\n\nThings I already tried: \n\nChecked the cookie name,which is same in both instances using\n\n `sudo cat /var/lib/rabbitmq/.erlang.cookie`. \n\n- Changed the epmd port as well `export ERL_EMPD_PORT=4370`\n\n- `netstat -an |grep 4369 | grep -i listen`\n\n- Changing the hostnames as well in GUI of plugin management.\nChanged owner and permission also using \n\n```\nsudo chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie\nsudo chmod 400 /var/lib/rabbitmq/.erlang.cookie\n```\n\nAdd port \n\n```\nsudo iptables -I INPUT -p tcp --dport 4369 --syn -j ACCEPT\n```\n\nsudo rabbitmqctl status \n\n```\n{listeners,[{clustering,25672,\"::\"},{amqp,5672,\"::\"}]},\n```\n\n*IP-Adresses are sample adrresses.\n\n========================================\n\nTop Answer:\nI got the same error like that today and the suggestion is meaningless. \n\nSo, firstly, you should check its log at /var/log/rabbitmq/rabbitmq@[your hostname].log or you waste your time. Then you can see what's happened there.\n\nIn my case, it reported an error in file /var/db/rabbitmq/mnesia/rabbit@www/cluster_nodes.config\n\n```\nError description:\n\n{error,{cannot_read_file,\"/var/db/rabbitmq/mnesia/rabbit@www/cluster_nodes.config\",\n {1,erl_parse,[\"syntax error before: \",\"'@'\"]}}}\n```\n\nSo, I just remove this folder /var/db/rabbitmq/mnesia/rabbit@www and restart the service and it works like a charm\n\n========================================\n\nCode:\n```text\nsudo rabbitmqctl join_cluster rabbit@ip-10-23-20-36\n```\n\n```text\nsudo chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie\nsudo chmod 400 /var/lib/rabbitmq/.erlang.cookie\n```\n\n```text\nsudo iptables -I INPUT -p tcp --dport 4369 --syn -j ACCEPT\n```\n\n```text\n{listeners,[{clustering,25672,\"::\"},{amqp,5672,\"::\"}]},\n```\n\n```text\nempd -names\n```\n\n```text\nsudo rabbitmqctl join_cluster rabbit@ip-10-23-20-36\n```\n\n```text\nsudo cat /var/lib/rabbitmq/.erlang.cookie\n```\n\n```text\nexport ERL_EMPD_PORT=4370\n```\n\n```text\nnetstat -an |grep 4369 | grep -i listen\n```\n\n```text\nrabbit@ip-10-23-209-142: * unable to connect to epmd (port 4369) on ip-10-23-209-142: nxdomain (non-existing domain)\n```\n\n```text\nping ip-10-23-209-142 # from ip-10-23-20-36\n```\n\n```text\n/etc/hosts\n```\n\n```text\nError description:\n\n\n{error,{cannot_read_file,\"/var/db/rabbitmq/mnesia/rabbit@www/cluster_nodes.config\",\n {1,erl_parse,[\"syntax error before: \",\"'@'\"]}}}\n```\n\n```text\nsudo service rabbitmq-server start\n```\n\n========================================\n\nComments:\n- Thanks Jean.So bad of me.Forgot to check that.\n- \"systemctl restart rabbitmq-server.service\" solved the same issue I had.\n- Can you mark the question as answered since it is the correct solution?\n- Where is this log file? I cannot locate it anywhere.\n- It may be a bit different on your system. Please, check the its docs/configuration file for more deails. rabbitmq.com/logging.html","metadata":{"transformedAt":"2026-08-18T18:33:20.142Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":14,"totalLines":148,"estimatedTokens":955}}268{"id":"stack-40380069","source":"stackoverflow","questionId":40380069,"title":"SimpMessagingTemplate.convertAndSend with RabbitMQ works very slow","tags":["spring","spring-boot","websocket","rabbitmq","stomp"],"text":"Title: SimpMessagingTemplate.convertAndSend with RabbitMQ works very slow\nTags: spring, spring-boot, websocket, rabbitmq, stomp\nSource: Stack Overflow\n\nQuestion:\nI'm using spring STOMP over Websocket with RabbitMQ. All works fine but simpMessagingTemplate.convertAndSend works very slow, call can take 2-10 seconds (synchronously, block thread). What can be a reason??\n\nRabbitTemplate.convertAndSend take **UPDATE**\n\nI try to use ActiveMQ and gets the same result. convertAndSend take 2-10 seconds\n\nActiveMQ have default configuration.\n\nWeb socket config:\n\n```\n@Configuration\n@EnableWebSocket\n@EnableWebSocketMessageBroker\nclass WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {\n\n @Override\n void configureMessageBroker(MessageBrokerRegistry config) {\n config.enableStompBrokerRelay(\"/topic\", \"/queue\", \"/exchange\");\n config.setApplicationDestinationPrefixes(\"/topic\", \"/queue\"); // prefix in client queries\n config.setUserDestinationPrefix(\"/user\");\n }\n\n @Override\n void registerStompEndpoints(StompEndpointRegistry registry) {\n registry.addEndpoint(\"/board\").withSockJS()\n }\n\n @Override\n void configureWebSocketTransport(WebSocketTransportRegistration registration) {\n registration.setMessageSizeLimit(8 * 1024);\n }\n}\n```\n\n========================================\n\nCode:\n```text\n@Configuration\n@EnableWebSocket\n@EnableWebSocketMessageBroker\nclass WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {\n\n @Override\n void configureMessageBroker(MessageBrokerRegistry config) {\n config.enableStompBrokerRelay(\"/topic\", \"/queue\", \"/exchange\");\n config.setApplicationDestinationPrefixes(\"/topic\", \"/queue\"); // prefix in client queries\n config.setUserDestinationPrefix(\"/user\");\n }\n\n @Override\n void registerStompEndpoints(StompEndpointRegistry registry) {\n registry.addEndpoint(\"/board\").withSockJS()\n }\n\n @Override\n void configureWebSocketTransport(WebSocketTransportRegistration registration) {\n registration.setMessageSizeLimit(8 * 1024);\n }\n}\n```\n\n```text\n<dependency>\n <groupId>io.projectreactor</groupId>\n <artifactId>reactor-net</artifactId>\n <version>2.0.8.RELEASE</version>\n </dependency>\n```\n\n========================================\n\nComments:\n- which spring version are you using? could you give an example of a message before/after conversion?\n- Too much to ask but could you attempt this question of mine?","metadata":{"transformedAt":"2026-08-18T18:33:20.142Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":81,"estimatedTokens":608}}269{"id":"stack-20442580","source":"stackoverflow","questionId":20442580,"title":"Unknown queue names show on Rabbitmq mgmt. when using Celery","tags":["python","rabbitmq","celery","amqp"],"text":"Title: Unknown queue names show on Rabbitmq mgmt. when using Celery\nTags: python, rabbitmq, celery, amqp\nSource: Stack Overflow\n\nQuestion:\nI only created the last 2 queue names that show in Rabbitmq management Webui in the below table:\n\nThe rest of the table has hash-like queues, which I don't know:\n\n```\n1- Who created them? (I know it is celery, but which process, task,etc.)\n\n2- Why they are created, and what they are created for?.\n```\n\nI can notice that when the number of pushed messages increase, the number of those hash-like messages increase.\n\n========================================\n\nCode:\n```text\n1- Who created them? (I know it is celery, but which process, task,etc.)\n\n2- Why they are created, and what they are created for?.\n```\n\n```text\nCELERY_AMQP_TASK_RESULT_EXPIRES = Number of seconds\n```\n\n```text\nCELERY_BACKEND = \"amqp\"\n```\n\n```text\nCELERY_IGNORE_RESULT = True.\n```\n\n```text\nCELERY_STORE_ERRORS_EVEN_IF_IGNORED = True.\n```\n\n========================================\n\nComments:\n- `.pidbox` queues are used to control the workers by broadcasting commands to them: docs.celeryproject.org/en/latest/userguide/… Then the `celeryev` queues are used by monitors and other tools that want to subscribe to events. There are two types of events: worker and task. The workers will consume worker related events to synchronize logical clocks. Flower is a web based monitor that also subscribes to task related events: docs.celeryproject.org/en/latest/userguide/…\n- As the answer below said, the hash named queues are task results when you use the amqp result backend. This backend does not perform very well, and it's better to use a database if you want to store results on disk, or if you want RPC calls you should use the new rpc backend.\n- Note that there is also a new RPC backend in Celery 3.1 that creates one queue per client\n- @asksol, Thanks for your comment. Who is calling this RPC? And what queue is created per client?\n- There are two AMQP based result backends: 1) the 'amqp' result backend which stores results on disk and using one queue per task so that the result can be retrieved by any process and 2) the 'rpc' result backend (new in Celery 3.1) which uses one queue per client to send results (not on disk) and only the process that initiated the task can retrieve the result. You have to explicitly enable these result backends, as by default celery does not do anything with the return values.\n- Did you get any more clarity on this? I'm using a db backend to store results and I still see the pidbox queues. My understanding is that the ev queues are for monitoring with a tool like flower like you pointed out.\n- same question here (and not using a result backend)... @asksol can you confirm if pidbox queues are *only* used for remote control of workers as described here docs.celeryproject.org/en/3.1/userguide/… or have other uses?","metadata":{"transformedAt":"2026-08-18T18:33:20.143Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":52,"estimatedTokens":723}}270{"id":"stack-20655367","source":"stackoverflow","questionId":20655367,"title":"How to post a task on a celery-rabbitmq queue in PHP?","tags":["php","python","rabbitmq","celery"],"text":"Title: How to post a task on a celery-rabbitmq queue in PHP?\nTags: php, python, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI have below versions of celery and rabbitmq installed -\n\n celery 3.1.6 \n\n rabbitmq 3.1.1\n\nI can post a task to the default queue from PHP -\n\n```\n//client.php\nPostTask('tasks.add', array(2,2));\n```\n\nMy worker module is in python - \n\n```\n# tasks.py\nfrom celery import Celery\ncelery = Celery('tasks', broker='amqp://guest:guest@localhost:5672//')\n@celery.task(queue='demo', name='add')\ndef add(x, y):\n return x + y\n```\n\nI run the celery worker and client like this -\n\n```\n# terminal window 1\n$ celery -A tasks worker --loglevel=info\n# terminal window 2\n$ php -f client.php\n```\n\nThis works. I see below output in terminal window 1 :\n\n```\nReceived task: tasks.add[php_52b1759141a8b3.43107845]\nTask tasks.add[php_52b1759141a8b3.43107845] succeeded in 0.000701383920386s: 4\n```\n\nBut I want to have different queues. For a demonstration, let's say I only want one queue called **demo**. So I run my celery worker like this -\n\n```\n$ celery -A tasks worker --loglevel=info -Q demo\n```\n\nBut it's not working. The task is not getting executed. I guess it's probably because PHP code is posting the task on default queue : **celery** (apparently not on **demo** queue). \n\nHow do I post my task on a particular queue in PHP? Please help.\n\n========================================\n\nCode:\n```text\n//client.php\n<?php\nrequire 'celery-php/celery.php';\n$c = new Celery('localhost', 'guest', 'guest', '/');\n$result = $c->PostTask('tasks.add', array(2,2));\n```\n\n```text\n# tasks.py\nfrom celery import Celery\ncelery = Celery('tasks', broker='amqp://guest:guest@localhost:5672//')\n@celery.task(queue='demo', name='add')\ndef add(x, y):\n return x + y\n```\n\n```text\n# terminal window 1\n$ celery -A tasks worker --loglevel=info\n# terminal window 2\n$ php -f client.php\n```\n\n```text\nReceived task: tasks.add[php_52b1759141a8b3.43107845]\nTask tasks.add[php_52b1759141a8b3.43107845] succeeded in 0.000701383920386s: 4\n```\n\n```text\n$ celery -A tasks worker --loglevel=info -Q demo\n```\n\n```text\n$exchange = 'demo'; \n$binding = 'demo'; \n$c = new Celery('localhost', 'guest', 'guest', '/', $exchange, $binding);\n```\n\n========================================\n\nComments:\n- I guess I am gonna have go with different tasks instead of different queues if above thing is not possibile.\n- You should check the source code of celery-php to see if there is a way to specify the `exchange` and `routing_key` of the task. In amqp you don't send messages to queues, you send them to exchanges which will then deliver the message to queues by matching the routing_key. There is a trick: you can set `exchange=\"\"` and routing_key to the name of a queue (e.g. `routing_key=\"demo\"` and it will deliver the message directly to the demo queue, bypassing the routing layer.\n- I am not that familiar with amqp. I'll go thorough the source code of celery-php and try above things. I'll let you know about it. Thanks for the reply.","metadata":{"transformedAt":"2026-08-18T18:33:20.143Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":103,"estimatedTokens":752}}271{"id":"stack-45784824","source":"stackoverflow","questionId":45784824,"title":"worker does not consume tasks after celery add_consumer is called","tags":["python","rabbitmq","queue","celery","celery-task"],"text":"Title: worker does not consume tasks after celery add_consumer is called\nTags: python, rabbitmq, queue, celery, celery-task\nSource: Stack Overflow\n\nQuestion:\nI would like to leverage Celery (with RabbitMQ as backend MQ) to execute tasks of varying flavors via different Queues. One requirement is that consumption (by the workers) from a particular Queue should have the capability to be paused and resumed. \n\nCelery, seems to have this capability via calling `add_consumer` and `cancel_consumer`. While I was able to cancel the consumption of tasks from a queue for a particular worker, I cannot get the worker to resume consumption by calling `add_consumer`. The code to reproduce this issue is **provided here**. My guess is likely I'm missing some sort of a parameter to be provided either in the `celeryconfig` or via the arguments when starting the workers? \n\nWould be great to get some fresh pairs of eyes on this. There is not much discussion on Stackoverflow regarding add_consumer nor in Github. So I'm hoping there's some experts here willing to their thoughts/experience.\n\n--\n\nI am running the below:\n\nWindows OS, RabbitMQ 3.5.6, Erlang 18.1, Python 3.3.5, celery 3.1.15\n\n========================================\n\nTop Answer:\nTo resume from queue, you need to specify queue name as well as target workers. Here is how to do it. \n\n```\napp.control.add_consumer(queue='high', destination=['celery@asus'])\n```\n\nHere is add_consumer signature\n\n```\ndef add_consumer(state, queue, exchange=None, exchange_type=None,\n routing_key=None, **options):\n```\n\nIn your case, you are calling with \n\n```\napp.control.add_consumer('high', destination=['celery@high1woka'])\n```\n\nSo `high` is getting passed to state and queue is empty. So it is not able to resume.\n\n========================================\n\nCode:\n```text\nadd_consumer\n```\n\n```text\ncancel_consumer\n```\n\n```text\nadd_consumer\n```\n\n```text\nceleryconfig\n```\n\n```text\ntry: except: pass\n```\n\n```text\n--pool=eventlet\n```\n\n```text\n--pool=solo\n```\n\n```text\napp.control.add_consumer(queue='high', destination=['celery@asus'])\n```\n\n```text\ndef add_consumer(state, queue, exchange=None, exchange_type=None,\n routing_key=None, **options):\n```\n\n```text\napp.control.add_consumer('high', destination=['celery@high1woka'])\n```\n\n```text\nhigh\n```\n\n========================================\n\nComments:\n- Thanks for the attempt. The multi-file gist I have provided for reproducing this behaviour is using add_consumer. While the worker acknowledges execution of add_consumer, it does not resume consumption of tasks in the queue. I'm suspecting my celeryconfig is not properly set or there is a potential bug in celery.\n- @teng Did you try with `queue=high` while adding consumer? I used your gist and reproduced the behavior. After passing proper params, it is working correctly.\n- I have added the `queue=high` as the kwarg to add_consumer, as oppose to just the arg, and after execution of resume.py, the worker is still not consuming tasks. Would you mind letting me know what your OS is, and the rabbitmq and celery versions you are using?\n- Ubuntu 14.04, Celery 4, rabbitmq 3.4\n- I have upgraded to Celery 4.1.0, which doesn't work straight 'out of the box' with Windows, however, I was able to get the worker to resume consuming tasks from the specified queue via add_consumer. Likely there are updates made between Celery v3.1.15 to v4.1 that resolved this issue. Accepting this as the answer. Note to viewers, try upgrading Celery to v4 if you are encounter this issue.","metadata":{"transformedAt":"2026-08-18T18:33:20.143Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":11,"totalLines":97,"estimatedTokens":882}}272{"id":"stack-2936598","source":"stackoverflow","questionId":2936598,"title":"MongoDB Schema Design - Real-time Chat","tags":["mongodb","rabbitmq","activemq-classic","schema-design","nosql"],"text":"Title: MongoDB Schema Design - Real-time Chat\nTags: mongodb, rabbitmq, activemq-classic, schema-design, nosql\nSource: Stack Overflow\n\nQuestion:\nI'm starting a project which I think will be particularly suited to MongoDB due to the speed and scalability it affords.\n\nThe module I'm currently interested in is to do with real-time chat. If I was to do this in a traditional RDBMS I'd split it out into:\n\n- Channel (A channel has many users)\n\n- User (A user has one channel but many messages)\n\n- Message (A message has a user)\n\nThe the purpose of this use case, I'd like to assume that there will be typically 5 channels active at one time, each handling at most 5 messages per second.\n\nSpecific queries that need to be fast:\n\n- Fetch new messages (based on an bookmark, time stamp maybe, or an incrementing counter?)\n\n- Post a message to a channel\n\n- Verify that a user can post in a channel\n\nBearing in mind that the document limit with MongoDB is 4mb, how would you go about designing the schema? What would yours look like? Are there any gotchas I should watch out for?\n\n========================================\n\nTop Answer:\nWhy use mongo for a messaging system? No matter how fast the static store is (and mongo is very fast), whether mongo or db, to mimic a message queue your going to have to use some kind of polling, which is not very scalable or efficient. Granted you're not doing anything terribly intense, but why not just use the right tool for the right job? Use a messaging system like Rabbit or ActiveMQ. \n\nIf you must use mongo (maybe you just want to play around with it and this project is a good chance to do that?) I imagine you'll have a collection for users (where each user object has a list of the queues that user listens to). For messages, you could have a collection for each queue, but then you'd have to poll each queue you're interested in for messages. Better would be to have a single collection as a queue, as it's easy in mongo to do \"in\" queries on a single collection, so it'd be easy to do things like \"get all messages newer than X in any queues where queue.name in list [a,b,c]\".\n\nYou might also consider setting up your collection as a mongo capped collection, which just means that you tell mongo when you set up the collection that your collection should only hold X number of bytes, or X number of items. Adding additional items has First-In, First-Out behavior which is pretty much ideal for a message queue. But again, it's not really a messaging system.\n\n========================================\n\nComments:\n- I would not suggest that the MQ solutions out there are really that much better than some of the NoSQL solutions out there. A lot of MQ tech seems complicated & over-engineered, plus performance isn't always that great, stability & portability may also be sacrificed. See: bhavin.directi.com/rabbitmq-vs-apache-activemq-vs-apache-qpi‌​d\n- There are decent MQ solutions out there, I just find they're the ones without much in the way of features, ZeroMQ and Kestrel are both good for their purposes. ActiveMQ on the other hand is horrific.\n- @Klinky I bet almost any specific MQ solution (especially ActiveMQ) would deal with the messaging (EDA) problem times better, than a custom solution based on a NoSQL of an unspecified type (did you mean a document-oriented DB, or key-value store or what?), because MQ solutions are designed for that problem, and, FTN ActiveMQ uses it's own optimized high-performance data storage for queue persistence.\n- @Steve B. \"...,which is not very scalable or efficient\" -- don't agree on \"scalable\" (though agree on efficiency and performance). Why? Opposed to storing queues in memory (which leads to problems, if you have 1+ node in your cluster -- you either need to setup replication or build a network of brokers), making multiple consumers work on a persisted queue seem to be less problematic (especially, considering failure scenarios).\n- @Vasil. MQ solutions all seem to have their own thought process and methodology w/ large length specs and stuffy documentation. A lot of them seem angled for enterprise situation which may need complex setups. When I was investigating MQs, I found a blog on the complexities of getting one stable for an enterprise SMS based application, read about Twitter developing their own MQ solution because of failure w/ActiveMQ & RabbitMQ. Also the link I posted is offering ActiveMQ w/ 22K msg/sec, which is not a speed demon. Not many details are given about their setup, but it's at least one data point.\n- @Klinky Twitter developers have done a lot of weird stuff, you know :) (if you had a chance to read a book about Scala by one of the Twitter's lead architects, you may guess, how \"good\" is their MQ solution). Regarding ActiveMQ - personally I've had an extremely good experience with it (I was using it to build a merely huge distributed mass mailing system). ~30-60k/sec throughput is a basic setup with one broker - if you build a network of brokers, performance could be times higher.\n- @Vasil, to each his own I guess. I just found NoSQL more straightforward to get started with. I understand what a queue is and that I want to put stuff on it and take stuff off. Something like Redis makes this super easy to do. As far as Redis performance, I can push on to a queue about 35K msgs/sec. Potentially retrieve from the queue at up to 400K msgs/ sec. Tested on my Celeron E3200 1MB L2 @ 3.8Ghz overclock, inside Ubuntu Virtualbox w/ IntelVT enabled. Redis is not multi-threaded so this is only using 1 of 2 cores. I guess it depends on what you need your 'MQ' to do.\n- >>> I can push on to a queue about 35K msgs/sec. Potentially retrieve from the queue at up to 400K msgs/ sec.<<< Hehe) Sounds interesting and promisng. I didn't have much chance to get the hands dirty with Redis, and would be happy to glance over a good architecture that uses it -- is your MQ solution a part of a proprietary system, or it's open?","metadata":{"transformedAt":"2026-08-18T18:33:20.143Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":47,"estimatedTokens":1492}}273{"id":"stack-24284518","source":"stackoverflow","questionId":24284518,"title":"Celery broadcast vs RabbitMQ fanout","tags":["rabbitmq","celery"],"text":"Title: Celery broadcast vs RabbitMQ fanout\nTags: rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI've been working with Celery lately and I don't like it. It's configuration is messy, overcomplicated and poorly documented.\n\nI want to send broadcast messages with Celery from a single producer to multiple consumers. What confuses me is discrepancy between Celery terms and terms of underlying transport RabbitMQ.\n\nIn RabbitMQ you can have a single fanout Exchange and multiple Queues to broadcast messages:\n\nBut in Celery the terms are all messed up: here you can have a broadcast Queue, which sends messages to multiple consumers:\n\nI don't even understand, how Celery broadcast queue is supposed to work at all, cause RabbitMQ queues with multiple consumers are meant for load balancing. So in RabbitMQ if multiple consumers (i.e. a pool of consumers) are connected to the same queue, only one consumer will receive and process message, which is called round robin in RabbitMQ docs.\n\nAlso, Celery documentation on broadcast is really insufficient. What type of RabbitMQ exchange should I specify for Broadcast queue, fanout or not? Could you supply a full example?\n\nSo, what I'm asking for is (1) clarification of concept and implementation of Broadcast queues in Celery and (2) a complete example of Broadcast queues configuration. Thank you.\n\n========================================\n\nTop Answer:\nHaving looked at the code (it's in the `kombu.common` package, not `celery`) and tried it out, it seems to work like this:\n\n- You define a `Broadcast` 'queue' named 'foo' in your celery config.\n\n- This creates an `Exchange` named 'foo', and an `auto_delete` queue with a unique id (via `uuid`), and with the alias 'foo' (I don't think the alias is actually used anywhere, it's just there for reference because the queue's real name is randomly generated)\n\n- The unique queue is bound to the 'foo' exchange\n\nSo, the class is named `Broadcast`, but it's really a uniquely named queue that is bound to a fanout exchange. Therefore when each worker is started, it creates its own unique queue and binds to the fanout exchange.\n\n========================================\n\nCode:\n```text\nExchange('fanout')\n```\n\n```text\nkombu.common\n```\n\n```text\ncelery\n```\n\n```text\nBroadcast\n```\n\n```text\nExchange\n```\n\n```text\nauto_delete\n```\n\n```text\nuuid\n```\n\n```text\nBroadcast\n```\n\n========================================\n\nComments:\n- Does this help? celery.readthedocs.org/en/latest/userguide/… It appears the 'queue' definition in Celery includes the exchange, so possibly you can define a Celery queue on top of a fanout exchange which will have an underlying implementation of multiple RabbitMQ queues. In this case I would guess you don't want a 'broadcast' queue in the Celery config, unless you really want multiple workers processing the same task\n- @Anentropic Thanks for reply, I've been using that page extensively, but as you can see, the definition of Broadcast queue there is `CELERY_QUEUES = (Broadcast('broadcast_tasks'), )` and it doesn't specify the exchange at all, unlike normal `CELERY_QUEUES = (Queue(name, exchange, routing_key), )` in examples, you pointed to. I've been looking for `Broadcast` in API reference, but can't find it.\n- what I was saying is: I don't think you want to use a broadcast queue at all. I think you want to define a normal Celery queue on top of `Exchange('fanout')` exchange type\n- @Anentropic Well, I came to the same conclusion. :) Thanks, Anentropic, let this Broadcast queue be a mistery of Celery, whatever it is.\n- Hi @BorisBurkov, I'm trying to get celery working with rabbitmq fanout queues. This seems to be tricky, celery seems to be having lots of automation done that is not clear to me. Did you manage to get your celery workers consuming tasks from your fanout queue on all hosts?\n- Hi @Greg0ry, I looked up my configs - no, I think, I'm using `direct` queue type everywhere. Cheers!\n- Thanks @BorisBurkov. I found what my issue was, left comment under accepted answer.\n- This is old answer and celery is now at 4.x so I'll leave my observation for others. First - it seems `Broadcast` queue was improved and you can define your queue like this: `Broadcast(name='queue_name', Exchange(name='queue_name', type='fanout')` - at least this made all my hosts within rabbitmq cluster to receive my broadcast task and I could define that queue within worker start arguments (`-Q:1 queue_name -c:1 1`). Also it helps if you remember to erase status of your rabbitmq cluster each time you test new queues configuration. Hope this helps somebody.\n- While this may answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.","metadata":{"transformedAt":"2026-08-18T18:33:20.143Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":79,"estimatedTokens":1185}}274{"id":"stack-36137343","source":"stackoverflow","questionId":36137343,"title":"Is there an equivalent of \"ping\" for RabbitMQ? How can I diagnose whether an exchange or queue is broadcasting?","tags":["node.js","rabbitmq","amqp"],"text":"Title: Is there an equivalent of \"ping\" for RabbitMQ? How can I diagnose whether an exchange or queue is broadcasting?\nTags: node.js, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI'm using `postwait/node-amqp` (link) to connect to a variety of RabbitMQ exchanges and queues in our organization. \n\nAs my project has moved from dev to production I've encountered several issues with queues not being setup correctly or passwords being incorrect etc. In the latter case, it's obvious, I'll get a ECONNREFUSED error. In the first case though, I don't get any errors, just a timeout on the connect. \n\nGiven a URI like `amqp://USER:PASS@messaging.abc.xyz.com` how can I determine if a queue called \"FooWorkItems.Work' is accepting connections for listening? What's the bare minimum code for this, the equivalent of checking if an API is listening or a server is up and listening on the ping port? \n\nCode: \n\n```\nif (this.amqpLib == null) {\n this.amqpLib = require('amqp');\n }\nthis.connection = this.amqpLib.createConnection({\n url: this.endpoint\n });\n\n this.connection.on('ready', (function(_this) {\n return function() {\n var evt, _fn, _fn1, _i, _j, _len, _len1, _ref, _ref1;\n _this.logger.info(\"\" + _this.stepInfo + \" connected to \" + _this.endpoint + \"; connecting to \" + queueName + \" now.\");\n if (_this.fullLogging) {\n _ref = ['connect', 'heartbeat', 'data'];\n _fn = function(evt) {\n return _this.connection.on(evt, function() {\n _this.logger.trace(\"\" + _this.stepInfo + \" AMQP event: \" + evt);\n if (arguments != null) {\n return _this.logger.trace({\n args: arguments\n });\n }\n });\n };\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n evt = _ref[_i];\n _fn(evt);\n }\n _ref1 = ['error', 'close', 'blocked', 'unblocked'];\n _fn1 = function(evt) {\n return _this.connection.on(evt, function() {\n if (evt !== 'close') {\n return _this.logger.error(\"\" + _this.stepInfo + \" AMQP event: \" + evt);\n } else {\n return _this.logger.warn(\"\" + _this.stepInfo + \" AMQP event: \" + evt);\n }\n });\n };\n for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {\n evt = _ref1[_j];\n _fn1(evt);\n }\n }\n return _this.connection.queue(_this.queueName, {\n passive: true\n }, function(q) {\n logger.debug(\"\" + stepInfo + \" connected to queue \" + queueName + \". Init complete.\");\n return q.subscribe(function(message, headers, deliveryInfo, messageObject) {\n logger.trace(\"\" + stepInfo + \" recvd message\");\n return logger.trace({\n headers: headers\n });\n });\n });\n };\n```\n\n========================================\n\nCode:\n```text\nif (this.amqpLib == null) {\n this.amqpLib = require('amqp');\n }\nthis.connection = this.amqpLib.createConnection({\n url: this.endpoint\n });\n\n this.connection.on('ready', (function(_this) {\n return function() {\n var evt, _fn, _fn1, _i, _j, _len, _len1, _ref, _ref1;\n _this.logger.info(\"\" + _this.stepInfo + \" connected to \" + _this.endpoint + \"; connecting to \" + queueName + \" now.\");\n if (_this.fullLogging) {\n _ref = ['connect', 'heartbeat', 'data'];\n _fn = function(evt) {\n return _this.connection.on(evt, function() {\n _this.logger.trace(\"\" + _this.stepInfo + \" AMQP event: \" + evt);\n if (arguments != null) {\n return _this.logger.trace({\n args: arguments\n });\n }\n });\n };\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n evt = _ref[_i];\n _fn(evt);\n }\n _ref1 = ['error', 'close', 'blocked', 'unblocked'];\n _fn1 = function(evt) {\n return _this.connection.on(evt, function() {\n if (evt !== 'close') {\n return _this.logger.error(\"\" + _this.stepInfo + \" AMQP event: \" + evt);\n } else {\n return _this.logger.warn(\"\" + _this.stepInfo + \" AMQP event: \" + evt);\n }\n });\n };\n for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {\n evt = _ref1[_j];\n _fn1(evt);\n }\n }\n return _this.connection.queue(_this.queueName, {\n passive: true\n }, function(q) {\n logger.debug(\"\" + stepInfo + \" connected to queue \" + queueName + \". Init complete.\");\n return q.subscribe(function(message, headers, deliveryInfo, messageObject) {\n logger.trace(\"\" + stepInfo + \" recvd message\");\n return logger.trace({\n headers: headers\n });\n });\n });\n };\n```\n\n```text\npostwait/node-amqp\n```\n\n```text\namqp://USER:PASS@messaging.abc.xyz.com\n```\n\n```text\nheartbeat\n```\n\n```text\nreconnect\n```\n\n========================================\n\nComments:\n- Wow, necromancer right here. I'll mark it as the answer since no one else has answered in 3 years.","metadata":{"transformedAt":"2026-08-18T18:33:20.143Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":150,"estimatedTokens":1175}}275{"id":"stack-51578794","source":"stackoverflow","questionId":51578794,"title":"docker rabbitmq how to expose port and reuse container with a docker file","tags":["docker","rabbitmq"],"text":"Title: docker rabbitmq how to expose port and reuse container with a docker file\nTags: docker, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nHi I am finding it very confusing how I can create a docker file that would run a rabbitmq container, where I can expose the port so I can navigate to the management console via localhost and a port number.\n\nI see someone has provided this dockerfile example, but unsure how to run it?\n\n```\nversion: \"3\"\nservices:\n rabbitmq:\n image: \"rabbitmq:3-management\"\n ports:\n - \"5672:5672\"\n - \"15672:15672\"\n volumes:\n - \"rabbitmq_data:/data\"\n volumes:\n rabbitmq_data:\n```\n\nI have got rabbit working locally fine, but everyone tells me docker is the future, at this rate I dont get it.\n\nDoes the above look like a valid way to run a rabbitmq container? where can I find a full understandable example?\n\n- Do I need a docker file or am I misunderstanding it?\n\n- How can I specify the port? in the example above what are first numbers 5672:5672 and what are the last ones?\n\n- How can I be sure that when I run the container again, say after a machine restart that I get the same container?\n\nMany thanks\n\nAndrew\n\n========================================\n\nCode:\n```text\nversion: \"3\"\nservices:\n rabbitmq:\n image: \"rabbitmq:3-management\"\n ports:\n - \"5672:5672\"\n - \"15672:15672\"\n volumes:\n - \"rabbitmq_data:/data\"\n volumes:\n rabbitmq_data:\n```\n\n```text\nversion: \"3\"\nservices:\n rabbitmq:\n image: \"rabbitmq:3-management\"\n ports:\n - \"5672:5672\"\n - \"15672:15672\"\n volumes:\n - \"rabbitmq_data:/data\"\nvolumes:\n rabbitmq_data:\n```\n\n```text\ncd <location of docker-compose.yml>\ndocker-compose up\n```\n\n```text\nrabbitmq:3-management\n```\n\n```text\ndocker-compose up\n```\n\n```text\n\"5672:5672\"\n```\n\n```text\n\"15672:15672\"\n```\n\n```text\nhttp:\\\\localhost:15672\n```\n\n```text\nhttp:\\\\<host-ip>:<port exposed linked to 15672>\n```\n\n```text\ndocker-compose stop\n```\n\n```text\ndocker-compose start\n```\n\n========================================\n\nComments:\n- Wow that's a good answer on all the levels, thank you very much, amazingly helpful cheers.\n- Glad to be of help :-)","metadata":{"transformedAt":"2026-08-18T18:33:20.143Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":11,"totalLines":110,"estimatedTokens":527}}276{"id":"stack-28041933","source":"stackoverflow","questionId":28041933,"title":"RabbitMQ: throttling fast producer against large queues with slow consumer","tags":["rabbitmq","throttling"],"text":"Title: RabbitMQ: throttling fast producer against large queues with slow consumer\nTags: rabbitmq, throttling\nSource: Stack Overflow\n\nQuestion:\nWe're currently using RabbitMQ, where a continuously super-fast producer is paired with a consumer limited by a limited resource (e.g. slow-ish MySQL inserts).\n\nWe don't like declaring a queue with `x-max-length`, since all messages will be dropped or dead-lettered once the limit is reached, and we don't want to loose messages.\n\nAdding more consumers is easy, but they'll all be limited by the one shared resource, so that won't work. The problem still remains: How to slow down the producer?\n\nSure, we could put a flow control flag in Redis, memcached, MySQL or something else that the producer reads as pointed out in an answer to a similar question, or perhaps better, the producer could periodically test for queue length and throttle itself, but these seem like hacks to me.\n\nI'm mostly questioning whether I have a fundamental misunderstanding. I had expected this to be a common scenario, and so I'm wondering:\n\nWhat is best practice for throttling producers? How is this done with RabbitMQ? Or do you do this in a completely different way?\n\n### Background\n\nAssume the producer actually knows how to slow himself down with the right input. E.g. a hardware sensor or hardware random number generator, that can generate as many events as needed.\n\nIn our particular real case, we have an API that users can use to add messages. Instead of devouring and discarding messages, we'd like to apply back-pressure by having our API return an error if the queue is \"full\", so the caller/user knows to back-off, or have the API block until the consumer catches up. We don't control our user, so regardless of how fast the consumer is, I can create a producer that is faster.\n\nI was hoping for something like the API for a TCP socket, where a `write()` can block and where a `select()` can be used to determine if a handle is writable. So either having the RabbitMQ API block or have it return an error if the queue is full.\n\n========================================\n\nTop Answer:\nI don't think that this is in any way rabbitmq specific. Basically you have a scenario, where there are two systems of different processing capabilities, and this mismatch will either pose a risk of overflowing the queue (whatever it would be), or even in case of a constant mismatch between producer and consumer, simply create more and more time-distance between event creation and its handling.\n\nI used to deal with this kind of scenarios, and unfortunately there is no magic bullet. You either have to speed up even handling (better hardware, more suited software?) or throttle the event creation (which has nothing to do with MQ really).\n\nNow, I would ask you what's the goal and how the events are produced. Are the events are produced constantly, with either unlimitted or just very high rate (for example readings from sensors - the more, the better), or are they created in batches/spikes (for example: user requests in specific time periods, batch loads from CRM system). I assume that the goal is to process everything cause you mention you don't want to loose any queued message.\n\nIf the output is constant, then some limiter (either internal counter, if the producer is the only producer, or external queue length checks if queue can be filled with some other system) is definitely in place.\n\n```\nIF eventsInTimePeriod/timePeriod > estimatedConsumerBandwidth\nTHEN LowerRate()\nELSE RiseRate()\n```\n\nIn real world scenarios we used to simply limit the output manually to the estimated values and there were some alerts set for queue length, time from queue entry to queue leaving etc. Where such limiters were omitted (by mistake mostly) we used to find later some tasks that were supposed to be handled in few hours, that were waiting for three months for their turn.\n\nI'm afraid it's hard to answer to \"How to slow down the producer?\" if we know nothing about it, but some ideas are: aforementioned rate check or maybe a blocking AddMessage method:\n\n```\nAddMessage(message)\n WHILE(getQueueLength() > maxAllowedQueueLength)\n spin(1000); // or sleep or whatever\n mqAdapter.AddMessage(message)\n```\n\nI'd say it all depends on specific of the producer application and in general your architecture.\n\n========================================\n\nCode:\n```text\nx-max-length\n```\n\n```text\nwrite()\n```\n\n```text\nselect()\n```\n\n```text\nIF eventsInTimePeriod/timePeriod > estimatedConsumerBandwidth\nTHEN LowerRate()\nELSE RiseRate()\n```\n\n```text\nAddMessage(message)\n WHILE(getQueueLength() > maxAllowedQueueLength)\n spin(1000); // or sleep or whatever\n mqAdapter.AddMessage(message)\n```\n\n========================================\n\nComments:\n- Just out of curiosity did you ever solved the problem? We want to implement a similar feature where we want Producer to take some action if the Consumer is overloaded.\n- No, I'm sorry. No solution so far.\n- Thanks Peter! I will let you know if we get to any solution.\n- Thanks for your thoughtful reply. Perhaps my question was not clear. I've clarified the question accordingly.\n- Unfortunatelly I won't be able to help with RabbitMQ specifics, never used that particular tech - maybe someone else will have some good insight. I have a feeling, seeing as you have a case where actual source of events are multiple users, that your case is fairly complicated. Simple blocking till queue drops below limit, for example, would be dangerous, as some clients might be unlucky and remain locked forever (because as soon as the length drops, other client pushes it back above the limit). Possibly just returning an error when queue is above certain length could work, but again...\n- ...but again it has some pitfalls to consider (like some clients never hitting the error, and others hitting it constantly, due to sheer chance).","metadata":{"transformedAt":"2026-08-18T18:33:20.143Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":92,"estimatedTokens":1473}}277{"id":"stack-56859006","source":"stackoverflow","questionId":56859006,"title":"Server closes after pika.exceptions.StreamLostError: Stream connection lost","tags":["rabbitmq"],"text":"Title: Server closes after pika.exceptions.StreamLostError: Stream connection lost\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have some images in my queue and I pass each image to my flask server where processing on images is done and a response is received in my rabbitmq server. After receiving response, I get this error \"pika.exceptions.StreamLostError: Stream connection lost(104,'Connection reset by peer')\". This happens when rabbitmq channel again starts consuming the connection. I don't understand why this happens. Also I would like to restart the server again automatically if this error persists. Is there any way to do that?\n\n========================================\n\nTop Answer:\nYou can change stream connection limit if you set heartbeat in ConnectionParameters\n\n```\nconnection_params = pika.ConnectionParameters(heartbeat=10)\n```\n\nwher number in seconds. It say yout TCP connection keepalive to 10 seconds for example.\n\nMore information https://www.rabbitmq.com/heartbeats.html and https://www.rabbitmq.com/heartbeats.html#tcp-keepalives\n\n========================================\n\nCode:\n```text\npika.exceptions.StreamLostError: Stream connection lost(104,'Connection reset by peer')\n```\n\n```text\nmissed heartbeats from client, timeout: 60s\n```\n\n```text\nconnection_params = pika.ConnectionParameters(heartbeat=10)\n```\n\n========================================\n\nComments:\n- Please paste your code here that is generating the exception.\n- hi, do you know why I get this error even if my consume process is not taking too much time stackoverflow.com/questions/76172079/…","metadata":{"transformedAt":"2026-08-18T18:33:20.143Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":40,"estimatedTokens":400}}278{"id":"stack-49909859","source":"stackoverflow","questionId":49909859,"title":"Dynamic Queues on RabbitListener Annotation","tags":["java","spring","rabbitmq"],"text":"Title: Dynamic Queues on RabbitListener Annotation\nTags: java, spring, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'd like to use queue names using a specific pattern, like `project.{queue-name}.queue`. And to keep this pattern solid, I wrote a helper class to generate this name from a simple identifier. So, `foo` would generate a queue called `project.foo.queue`. Simple.\n\nBut, the annotation `RabbitListener` demands a constant string and gives me an error using my helper class. How can I achieve this (or maybe another approach) using `RabbitListener` annotation?\n\n```\n@Component\npublic class FooListener {\n\n // it doesn't work\n @RabbitListener(queues = QueueName.for(\"foo\"))\n // it works\n @RabbitListener(queues = \"project.foo.queue\")\n void receive(final FooMessage message) {\n // ...\n }\n}\n```\n\n========================================\n\nTop Answer:\nTo create and listen to a queue name constructed from a dynamic UUID, you could use random.uuid.\n\nThe problem is that this must be captured to a Java variable in only one place because a new random value would be generated each time the property is referenced.\n\nThe solution is to use Spring Expression Language (SpEL) to call a function that provides the configured value, something like:\n\n```\n@RabbitListener(queues = \"#{configureAMQP.getControlQueueName()}\")\nvoid receive(final FooMessage message) {\n // ...\n}\n```\n\nCreate the queue with something like this:\n\n```\n@Configuration\npublic class ConfigureAMQP {\n\n @Value(\"${controlQueuePrefix}-${random.uuid}\")\n private String controlQueueName;\n\n public String getControlQueueName() {\n return controlQueueName;\n }\n\n @Bean\n public Queue controlQueue() {\n System.out.println(\"controlQueue(): controlQueueName=\" + controlQueueName);\n return new Queue(controlQueueName, true, true, true);\n }\n\n}\n```\n\nNotice that the necessary bean used in the SpEL was created implicitly based on the `@Configuration` class (with a slight alteration of the spelling `ConfigureAMQP` -> `configureAMQP`).\n\n========================================\n\nCode:\n```text\n@Component\npublic class FooListener {\n\n // it doesn't work\n @RabbitListener(queues = QueueName.for(\"foo\"))\n // it works\n @RabbitListener(queues = \"project.foo.queue\")\n void receive(final FooMessage message) {\n // ...\n }\n}\n```\n\n```text\nproject.{queue-name}.queue\n```\n\n```text\nfoo\n```\n\n```text\nproject.foo.queue\n```\n\n```text\nRabbitListener\n```\n\n```text\nRabbitListener\n```\n\n```text\n@Component\npublic class QueueName {\n public String buildFor(String name) {\n return \"project.\"+name+\".queue\";\n }\n}\n```\n\n```text\n@RabbitListener(queues = \"#{queueName.buildFor(\\\"foo\\\")}\")\n```\n\n```text\nqueueName\n```\n\n```text\n@RabbitListener(queues = \"${queue-name}\")\npublic void receiveMessage(FooMessage message) {\n\n}\n```\n\n```text\n{queue-name}\n```\n\n```text\nyml\n```\n\n```text\napplication.yml\n```\n\n```text\n@RabbitListener(queues = \"#{configureAMQP.getControlQueueName()}\")\nvoid receive(final FooMessage message) {\n // ...\n}\n```\n\n```text\n@Configuration\npublic class ConfigureAMQP {\n\n @Value(\"${controlQueuePrefix}-${random.uuid}\")\n private String controlQueueName;\n\n public String getControlQueueName() {\n return controlQueueName;\n }\n\n @Bean\n public Queue controlQueue() {\n System.out.println(\"controlQueue(): controlQueueName=\" + controlQueueName);\n return new Queue(controlQueueName, true, true, true);\n }\n\n}\n```\n\n```text\n@Configuration\n```\n\n```text\nConfigureAMQP\n```\n\n```text\nconfigureAMQP\n```\n\n========================================\n\nComments:\n- Where does the context come from? Environment variable?\n- I've changed \"context\" for \"queue-name\" for clarifying. It's just a name. But I want to reinforce the name pattern.\n- Excellent response, simple solution\n- That seems to work as an annotation, which is great. But I don't see how to connect it to a configuration that creates the queue with the same random name.\n- @nobar assuming you are using spring boot you can easily use same random property in application.yml or properties file - like `queue-name: someprefix-${random-uuid}`. You can use with `value` annotation or SPEL in anywhere in your code.\n- I appreciate the suggestion -- it seems like it should work for my case (although I'm still wresting with Spring trying to make it work). It isn't as general as what the OP was trying to do, but perhaps it suggests that an elaborate general solution is possible with the right magic beans...\n- BTW: I assume you meant to type `${random.uuid}` -- is that correct? I'm having trouble finding documentation for this (using either spelling).\n- You are welcome - Yes, it should be `${random.uuid}`. Documentation and javadoc. I can expand on the solution if you could further explain your problem.\n- You're not going to believe this, but using this in 'application.properties' (`app.id=${random.uuid}` `controlQueueName=${base.name}-${app.id}`, it generates a *different* UUID for the configuration (queue creation) vs. the listener. There must be some magic syntax to lock it down to a single application-wide value.\n- Indeed there are some suggestions here and here. Perhaps will help you or else I will take a deeper look.\n- Based on those two sources, this appears to be a known issue: \"property source should not be stateful\"","metadata":{"transformedAt":"2026-08-18T18:33:20.143Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":18,"totalLines":189,"estimatedTokens":1323}}279{"id":"stack-27991503","source":"stackoverflow","questionId":27991503,"title":"Messages with expiration are not removed from RabbitMQ","tags":["rabbitmq","message","ttl"],"text":"Title: Messages with expiration are not removed from RabbitMQ\nTags: rabbitmq, message, ttl\nSource: Stack Overflow\n\nQuestion:\nI am sending a normal message through a producer to RabbitMQ and then I send a second message with the `expiration` attribute assigned to a value. Then using the `rabbitmqctl list_queues` command I monitor the status of the messages.\n\nI found that if I send a normal message first and then a message with `expiration`, the `rabbitmqctl list_queues` is always showing me 2 messages pending on the queue. When I consume them, I get only one.\n\nOn the other hand if I send just 1 message with `expiration`, in the beginning I see the message and then after the correct expiration time, I find it deleted.\n\nMy question is, on the first situation is actually the message taking space? Or it is an interface bug?\n\nMy rabbitMQ version is:\n`rabbitmq-server.noarch -> 3.1.5-1.el6`\n\n========================================\n\nCode:\n```text\nexpiration\n```\n\n```text\nrabbitmqctl list_queues\n```\n\n```text\nexpiration\n```\n\n```text\nrabbitmqctl list_queues\n```\n\n```text\nexpiration\n```\n\n```text\nrabbitmq-server.noarch -> 3.1.5-1.el6\n```\n\n========================================\n\nComments:\n- Related: stackoverflow.com/questions/26206512/…\n- So the message-ttl or expiration value for a message means \"if it is too late, it won't be delivered but it will remain on the queue\" and \"you have to wait this long without sending any messages to the queue for it to be emptied\" that's a bit complicated.\n- @nurettin - this is a really old answer, and the behavior may have changed since then.\n- I experienced first-hand that message-ttl causes messages to be stuck in a queue if nobody is reading from it. Even though they expired and provide no value.\n- @nurettin that’s fine. A queue that accumulates messages indefinitely with no processor is not an appropriate use case for RMQ anyway.","metadata":{"transformedAt":"2026-08-18T18:33:20.143Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":51,"estimatedTokens":474}}280{"id":"stack-5046944","source":"stackoverflow","questionId":5046944,"title":"Why is RabbitMQ not persisting messages on a durable queue?","tags":["python","django","rabbitmq","celery"],"text":"Title: Why is RabbitMQ not persisting messages on a durable queue?\nTags: python, django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI am using RabbitMQ with Django through Celery. I am using the most basic setup:\n\n```\n# RabbitMQ connection settings\nBROKER_HOST = 'localhost'\nBROKER_PORT = '5672'\nBROKER_USER = 'guest'\nBROKER_PASSWORD = 'guest'\nBROKER_VHOST = '/'\n```\n\nI imported a Celery task and queued it to run one year later. From the iPython shell:\n\n```\nIn [1]: from apps.test_app.tasks import add\n\nIn [2]: dt=datetime.datetime(2012, 2, 18, 10, 00)\n\nIn [3]: add.apply_async((10, 6), eta=dt)\nDEBUG:amqplib:Start from server, version: 8.0, properties: {u'information': 'Licensed under the MPL. See http://www.rabbitmq.com/', u'product': 'RabbitMQ', u'version': '2.2.0', u'copyright': 'Copyright (C) 2007-2010 LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd.', u'platform': 'Erlang/OTP'}, mechanisms: ['PLAIN', 'AMQPLAIN'], locales: ['en_US']\nDEBUG:amqplib:Open OK! known_hosts []\nDEBUG:amqplib:using channel_id: 1\nDEBUG:amqplib:Channel open\nDEBUG:amqplib:Closed channel #1\nOut[3]: \n```\n\nRabbitMQ received this message in the celery queue:\n\n```\n$ rabbitmqctl list_queues name messages durable\nListing queues ...\nKTMacBook.local.celeryd.pidbox 0 false\ncelery 1 true\nceleryctl_KTMacBook.local 0 true\n...done.\n```\n\nI then killed RabbitMQ by hitting control-C followed by 'a' to abort. When I start the server again and check it with rabbitmqctl, it says that there are no messages in the celery queue:\n\n```\n$ rabbitmqctl list_queues name messages durable\nListing queues ...\ncelery 0 true\nceleryctl_KTMacBook.local 0 true\n...done.\n```\n\nThe celery queue was durable. Why were the messages not persisted? What do I need to do to make the messages persistent?\n\n========================================\n\nTop Answer:\nMaking a queue durable is not the same as making the messages on it persistent. Durable queues mean they come up again automatically when the server has restarted - which has obviously happened in your case. But this doesn't affect the messages themselves.\n\nTo make messages persistent, you have to also mark the message's `delivery_mode` property to 2. See the classic write-up Rabbits and Warrens for a full explanation.\n\nEdit: Full link is broken, but as of Dec 2013 you could still find the blog post from the main URL: http://blogs.digitar.com/jjww/\n\n========================================\n\nCode:\n```text\n# RabbitMQ connection settings\nBROKER_HOST = 'localhost'\nBROKER_PORT = '5672'\nBROKER_USER = 'guest'\nBROKER_PASSWORD = 'guest'\nBROKER_VHOST = '/'\n```\n\n```text\nIn [1]: from apps.test_app.tasks import add\n\nIn [2]: dt=datetime.datetime(2012, 2, 18, 10, 00)\n\nIn [3]: add.apply_async((10, 6), eta=dt)\nDEBUG:amqplib:Start from server, version: 8.0, properties: {u'information': 'Licensed under the MPL. See http://www.rabbitmq.com/', u'product': 'RabbitMQ', u'version': '2.2.0', u'copyright': 'Copyright (C) 2007-2010 LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd.', u'platform': 'Erlang/OTP'}, mechanisms: ['PLAIN', 'AMQPLAIN'], locales: ['en_US']\nDEBUG:amqplib:Open OK! known_hosts []\nDEBUG:amqplib:using channel_id: 1\nDEBUG:amqplib:Channel open\nDEBUG:amqplib:Closed channel #1\nOut[3]: <AsyncResult: cfc507a1-175f-438e-acea-8c989a120ab3>\n```\n\n```text\n$ rabbitmqctl list_queues name messages durable\nListing queues ...\nKTMacBook.local.celeryd.pidbox 0 false\ncelery 1 true\nceleryctl_KTMacBook.local 0 true\n...done.\n```\n\n```text\n$ rabbitmqctl list_queues name messages durable\nListing queues ...\ncelery 0 true\nceleryctl_KTMacBook.local 0 true\n...done.\n```\n\n```text\n>>> from tasks import add\n>>> add.delay(2, 2)\n\n>>> from celery import current_app\n>>> conn = current_app.broker_connection()\n>>> consumer = current_app.amqp.get_task_consumer(conn)\n\n>>> messages = []\n>>> def callback(body, message):\n... messages.append(message)\n>>> consumer.register_callback(callback)\n>>> consumer.consume()\n\n>>> conn.drain_events(timeout=1)\n\n>>> messages[0].properties\n>>> messages[0].properties\n{'application_headers': {}, 'delivery_mode': 2, 'content_encoding': u'binary', 'content_type': u'application/x-python-serialize'}\n```\n\n```text\ndelivery_mode\n```\n\n```text\ndelivery_mode\n```\n\n========================================\n\nComments:\n- It looks like the delivery mode is already set to 2: add.delivery_mode == 2. This default cannot be changed in celery as far as I know.\n- Is there a way that I can inspect the message to check its delivery mode?\n- What version of Kombu are you using? (used by Celery) Kombu 1.0.0 had a bug where messages delivery_mode was not correctly set.\n- I'm using kombu-1.0.2, celery-2.2.2, and django_celery-2.2.2.\n- The other thing you'll want to do is use transactions / confirms. That way you know for sure that Rabbit has not only received the message, but it has been sent to disk.\n- I confirmed that the delivery mode was set to 2. I was able to get it to work by upgrading RabbitMQ to 2.3.1. I was getting the persistence problems when using RabbitMQ 2.2.0.","metadata":{"transformedAt":"2026-08-18T18:33:20.144Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":145,"estimatedTokens":1273}}281{"id":"stack-46880229","source":"stackoverflow","questionId":46880229,"title":"Migrate from AMQP to Amazon SNS/SQS - need to understand concepts","tags":["rabbitmq","migration","amqp","amazon-sqs","amazon-sns"],"text":"Title: Migrate from AMQP to Amazon SNS/SQS - need to understand concepts\nTags: rabbitmq, migration, amqp, amazon-sqs, amazon-sns\nSource: Stack Overflow\n\nQuestion:\nI am well experienced with the RabbitMQ and AMQP protocol, and have built a system with patterns for Commands, Requests and Events.\n\nNow I am going to build a system running on AWS Lambda and therefore use SNS, SQS etc. I want to understand the \"mapping\" between these things.\n\nWhat are the equivalent to an exchange in AMQP? What are the equivalent to a routing key?\n\nHow to set up queue bindings for fanout, direct and topic exchanges (or similar) in SNS and SQS?\n\nHow did other people handle this? To me it looks like RabbitMQ is a tool built to fit the usual needs of a message bus, where AWS provides blocks and you have to setup/build the functionality yourself. Am I right?\n\n========================================\n\nTop Answer:\nIt looks like the AWS IoT service with its MQTT provides what I need in order to do routing rules similar to the ones RabbitMQ provides!\n\n========================================\n\nComments:\n- Thanks - your answer matches pretty good with my findings so far. So basically, an SNS topic behaves like a fanout exchange in AMQP, from what I understand. In my particular use case, I'd need this: We have a couple of machines that does a job when they receive a messages (let's just say printers) and send a message when the job is done. In AMQP I just had a Job.Start exchange and a routing key for each machine. Then I could log all Job.Start traffic in one service and let the machines receive messages with their routing key.\n- But in order to do the same here, I guess I will have to send to a SNS topic named job-start, with a subject that is the machine ID, and then have a Lambda that subscribes to that SNS topic, gets the message and dispatches a new message directly to the job-start- - would that be a solution? And what would you do about message-based RPC operations?\n- Its a bit late, but it might still help. I was faced with a similar issue where I needed to move away from rabbitMQ, and I chose to go SNS/SQS with Aws. It wasn't the easiest task, but in the end I put together a Symfony bundle to support my needs. Im not sure what framework you are using, but you are welcome to look at the project and adapt the code to fit your needs. Essentially the code is a big Pu/Sub that allows consumers(sqs) to subscribe to publishers (sns) which is how I manage my routing. packagist.org/packages/beyerz/aws-queue-bundle\n- Just wanted to augment this excellent answer with an update, re: \"the SNS-to-SQS bindings don't allow for any additional filtering/control\" - as of August 2019, you can now attach a \"Filter policy\" to subscriptions which should allow one to approximate routing key behavior. See: docs.aws.amazon.com/sns/latest/dg/sns-message-filtering.html\n- You'll have to implement custom queues though as AWS-IoT doesn't allow holding any data. It's more of a pub/sub system built over a MQTT broker\n- Aah - I can see that IoT does not persist messages... But I guess I can subscribe SQS queues to the IoT broker then? docs.aws.amazon.com/iot/latest/developerguide/sqs-rule.html I guess I can rely on that the lamdas and other AWS subscribers will always receive the messages from the IoT broker, but external actors (like a machine or payment system) will need to create its own SQS queue and subscribe it to my IoT topic and then start to consume it, to avoid data loss?\n- @user2967920 I just made some tests, having a local MQTT client on two computers and connection to my AWS IoT based MQTT broker and subscribing and publishing. Even when I disconnected one of the computers, it would still receive the messages matching its subscription when I took it back online after a few minutes. So I guess there are some kind of buffer/queue present when subscribing to an MQTT topic on AWS. I was not able to see any significant difference in the behavior whether i was using QoS 0 or 1 though.\n- Are you using any SDKs for the Client? In terms of QoS, At most once (0) At least once (1) Exactly once (2). Are you using thing shadow? How many mins apart were your disconnections and reconnections?","metadata":{"transformedAt":"2026-08-18T18:33:20.144Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":31,"estimatedTokens":1053}}282{"id":"stack-65201334","source":"stackoverflow","questionId":65201334,"title":"Rabbit mq prefetch undestanding","tags":["rabbitmq","amqp","spring-amqp","spring-rabbit"],"text":"Title: Rabbit mq prefetch undestanding\nTags: rabbitmq, amqp, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI understand below\n\n*prefetch simply controls how many messsages the broker allows to be outstanding at the consumer at a time. When set to 1, this means the broker will send 1 message, wait for the ack, then send the next.*\n\nbut questions regarding following scenarios:\n\nLets say prefetch is 200, we have 2 consumers idle. Broker got 150 messages, I think broker will pick one random and will send all 150 messages? I think yes it wont do sharing between consumers.\n\nLets say one consumer is having 100 messages in unack and one is idle and prefetch again is 200. Now we got 50 more messages, again I think broker will give those 50 to either one randomly? Or it will not give to consumer who already have 100 messages that not acked yet\n\nIf prefetch is 200, one consumer got 200, will listener block that thread (spring rabbitmq listner method) to send ack until all 200 processed ? I think it will not send ack one by one and will wait until all prefetched messages processed. In other words if prefetch is 200 and if broker delivers 200 messages, when broker will start getting ack?\n\n========================================\n\nTop Answer:\nSetting a right value for prefetch is important and it depends on your RTT for the comume deliver ack cycle, so if you have large processing time its better to have the higher prefetch count otherwise lower prefetchenter link description here\n\n========================================\n\nCode:\n```java\n@SpringBootApplication\npublic class So65201334Application {\n\n public static void main(String[] args) {\n SpringApplication.run(So65201334Application.class, args);\n }\n\n @RabbitListener(id = \"foo\", queues = \"foo\", autoStartup = \"false\")\n @RabbitListener(id = \"bar\", queues = \"foo\", autoStartup = \"false\")\n void listen(String in, @Header(AmqpHeaders.CONSUMER_TAG) String tag) throws InterruptedException {\n System.out.println(tag);\n Thread.sleep(240_000);\n }\n\n @Bean\n public ApplicationRunner runner(RabbitTemplate template, RabbitListenerEndpointRegistry registry) {\n return args -> {\n for (int i = 0; i < 200; i++) {\n template.convertAndSend(\"foo\", \"bar\");\n }\n registry.getListenerContainer(\"foo\").start();\n System.out.println(\"Hit Enter to start the second listener and send more records\");\n System.in.read();\n registry.getListenerContainer(\"bar\").start();\n Thread.sleep(2000);\n for (int i = 0; i < 200; i++) {\n template.convertAndSend(\"foo\", \"bar\");\n }\n };\n }\n\n}\n```\n\n```text\nbatchSize\n```\n\n```text\nbatchSize\n```\n\n```text\ntxSize\n```\n\n========================================\n\nComments:\n- Thanks, so by default, if prefetch size is 100, that consumer gets 100 messages, as it processes it will send ack and at that time if more message comes they may be delivered to that same consumer who already have some messages in unack, or it will send one more consumer if we have is idle, I think you it will send to one who is idle for fair distribution.\n- New messages will go to **both** consumers (unless the prefetch is reached); the broker does not favor the consumer with fewer backlog, until the prefetch is reached on the other consumer. See the example that I added to the answer; you can use that app to see the behavior.","metadata":{"transformedAt":"2026-08-18T18:33:20.144Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":77,"estimatedTokens":870}}283{"id":"stack-54002827","source":"stackoverflow","questionId":54002827,"title":"Configuring ConnectionFactory for RabbitMQ in Spring Boot AMQP","tags":["java","spring-boot","rabbitmq","spring-amqp"],"text":"Title: Configuring ConnectionFactory for RabbitMQ in Spring Boot AMQP\nTags: java, spring-boot, rabbitmq, spring-amqp\nSource: Stack Overflow\n\nQuestion:\n**TL;DR** How to create Spring Boot AMQP connection factory programatically?\n\nHey,\n\nIn order to connect to my RabbitMQ I added these to my `application.properties` file of my Spring Boot app:\n\n```\nspring.rabbitmq.host=host\nspring.rabbitmq.port=5672\nspring.rabbitmq.username=myapp\nspring.rabbitmq.password=mypass\n```\n\nAnd according to my understanding, these values are then used to create Spring Boot's auto configured `ConnectionFactory`, which I then use in:\n\n```\n@Bean\n@Conditional(RabbitCondition.class)\nSimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter completedOrderListenerAdapter) {\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(connectionFactory);\n container.setQueueNames(completedOrderQueueName);\n container.setMessageListener(completedOrderListenerAdapter);\n return container;\n}\n```\n\nI would like to be able to use rabbitMQ credentials from different environment files which are not `application.properties`, so I would like to create `ConnectionFactory` bean programatically.\nHow do I achieve this?\n\nThanks.\n\n========================================\n\nCode:\n```text\nspring.rabbitmq.host=host\nspring.rabbitmq.port=5672\nspring.rabbitmq.username=myapp\nspring.rabbitmq.password=mypass\n```\n\n```text\n@Bean\n@Conditional(RabbitCondition.class)\nSimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter completedOrderListenerAdapter) {\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(connectionFactory);\n container.setQueueNames(completedOrderQueueName);\n container.setMessageListener(completedOrderListenerAdapter);\n return container;\n}\n```\n\n```text\napplication.properties\n```\n\n```text\nConnectionFactory\n```\n\n```text\napplication.properties\n```\n\n```text\nConnectionFactory\n```\n\n```text\n@Bean\npublic ConnectionFactory connectionFactory() {\n CachingConnectionFactory connectionFactory = new CachingConnectionFactory();\n connectionFactory.setAddresses(address);\n connectionFactory.setUsername(username);\n connectionFactory.setPassword(password);\n return connectionFactory;\n}\n```\n\n========================================\n\nComments:\n- what is `address`? In the properties we have host and port.\n- @tostao address = host","metadata":{"transformedAt":"2026-08-18T18:33:20.144Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":7,"totalLines":91,"estimatedTokens":632}}284{"id":"stack-22882318","source":"stackoverflow","questionId":22882318,"title":"EasyNetQ fails to publish to RabbitMQ - PersistentChannel timed out","tags":["rabbitmq","cqrs","easynetq"],"text":"Title: EasyNetQ fails to publish to RabbitMQ - PersistentChannel timed out\nTags: rabbitmq, cqrs, easynetq\nSource: Stack Overflow\n\nQuestion:\nI am trying to connect to RabbitMQ with EasyNetQ.\nRabbitMQ is on remote VM.\n\n```\n_rabbitBus = RabbitHutch.CreateBus(\n string.Format(\"host={0};virtualhost={1}\", \n _hostSettings.Host, _hostSettings.VHost),\n x => x.Register(l => _logger));\n\n_rabbitBus.Subscribe(_topic, ReceiveMessage, m => m.WithTopic(_topic));\n```\n\nI get a TimeoutException `The operation requested on PersistentChannel timed out.`.\nRemote VM is replying to pings, ports 5672 and 15672 are opened (checked with nmap).\nRabbitMQ management can be accessed from my host.\n\nAlso, if RabbitMQ is run on my local machine, it works fine. \nI've tried connecting to RabbitMQ installed on my computer from other pc's in LAN, and it also works.\n\nI've come to an assumption, that it's related to the fact it's on a virtual machine, and maybe there's something wrong in connection. But again, Rabbit's web management works fine.\n\nAlso tested on EasyNetQ Test application - works on localhost, but not on remote.\n\nOutput as following:\n\n```\nDEBUG: Trying to connect\nERROR: Failed to connect to Broker: '192.168.0.13', Port: 5672 VHost: '/'. \n ExceptionMessage: 'None of the specified endpoints were reachable'\nERROR: Failed to connected to any Broker. Retrying in 5000 ms\n```\n\n- EasyNetQ v0.28.4.242\n\n========================================\n\nTop Answer:\nDid you check your credentials. The default username and password is 'guest' and 'guest'. The error message is not very helpful. You get 'None of the specified endpoints were reachable' if there's an authentication error as well\n\n========================================\n\nCode:\n```text\n_rabbitBus = RabbitHutch.CreateBus(\n string.Format(\"host={0};virtualhost={1}\", \n _hostSettings.Host, _hostSettings.VHost),\n x => x.Register<IEasyNetQLogger>(l => _logger));\n\n_rabbitBus.Subscribe<Message>(_topic, ReceiveMessage, m => m.WithTopic(_topic));\n```\n\n```text\nDEBUG: Trying to connect\nERROR: Failed to connect to Broker: '192.168.0.13', Port: 5672 VHost: '/'. \n ExceptionMessage: 'None of the specified endpoints were reachable'\nERROR: Failed to connected to any Broker. Retrying in 5000 ms\n```\n\n```text\nThe operation requested on PersistentChannel timed out.\n```\n\n```text\nvar _bus = RabbitHutch.CreateBus(string.Format(\"host={0};virtualhost={1};username={2};password={3}\", \n_hostSettings.Host, _hostSettings.VHost, _hostSettings.UserName, _hostSettings.Password));\n```\n\n========================================\n\nComments:\n- This saved me, while having spent too much time investigating network issues due to that error messaeg. Thanks.\n- Thanks for this, I had spaces in my connection string causing the same error message!\n- Indeed, that error is totally misleading. The issue is the connection string with spaces.","metadata":{"transformedAt":"2026-08-18T18:33:20.144Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":78,"estimatedTokens":718}}285{"id":"stack-44113578","source":"stackoverflow","questionId":44113578,"title":"Django celery tasks in separate server","tags":["django","rabbitmq","celery"],"text":"Title: Django celery tasks in separate server\nTags: django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nWe have two servers, Server A and Server B. Server A is dedicated for running django web app. Due to large number of data we decided to run the celery tasks in server B. Server A and B uses a common database. Tasks are initiated after post save in models from Server A,webapp. How to implement this idea using rabbitmq in my django project\n\n========================================\n\nCode:\n```text\npython manage.py celery worker -Q queue_name -l info\n```\n\n```text\nrabbit\n```\n\n```text\ncelery\n```\n\n```text\nBROKER_URL = 'amqp://user:password@IP_SERVER_A:5672//'\n```\n\n```text\nrabbit\n```\n\n```text\ncelery\n```\n\n```text\ndjango\n```\n\n```text\nrabbit\n```\n\n```text\ncelery\n```\n\n```text\nrabbitMQ\n```\n\n```text\nBROKER_URL\n```\n\n```text\nBROKER_URL='amqp://user:password@IP_SERVER_C:5672//'\n```\n\n========================================\n\nComments:\n- That is exactly how Celery is supposed to work, and there is nothing unusual here. Where are you having problems?\n- Nothing wrong in your English. Crisp and clear information. Thanks\n- @Diego how would you theoretically point to a second worker D on a different machine and let RabbitMQ (assuming it's the broker) handle the load from Celery? Is it done automatically as long as you list all workers?\n- @tech4242 I don't understand, what do you mean with \"worker D\"? you want many workers by server? can you reformulate? This question does not mention about AMPQ protocol(or how rabbit does put a message on a queue).\n- Yes! Simply meant what happens when you want multiple workers - each one on a different server (doesn’t matter if physical or virtual) How do you tell your broker that you have multiple workers on different servers when you use Celery\n- @tech4242 the broker don't need to know the number of workers. The broker just have to know where put the message(in what queue). If you want more workers, instructions for server B will work for server N. In each settings you set broker url and in the start command you tell from what queue you want to process mesaages.\n- obviously you can add many workers by server with the same command.","metadata":{"transformedAt":"2026-08-18T18:33:20.144Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":12,"totalLines":68,"estimatedTokens":547}}286{"id":"stack-2799731","source":"stackoverflow","questionId":2799731,"title":"Wait for a single RabbitMQ message with a timeout","tags":[".net","python","rabbitmq","amqp","py-amqplib"],"text":"Title: Wait for a single RabbitMQ message with a timeout\nTags: .net, python, rabbitmq, amqp, py-amqplib\nSource: Stack Overflow\n\nQuestion:\nI'd like to send a message to a RabbitMQ server and then wait for a reply message (on a \"reply-to\" queue). Of course, I don't want to wait forever in case the application processing these messages is down - there needs to be a timeout. It sounds like a very basic task, yet I can't find a way to do this. I've now run into this problem with both py-amqplib and the RabbitMQ .NET client.\n\nThe best solution I've got so far is to poll using `basic_get` with `sleep` in-between, but this is pretty ugly:\n\n```\ndef _wait_for_message_with_timeout(channel, queue_name, timeout):\n slept = 0\n sleep_interval = 0.1\n\n while slept Surely there is some better way?\n\n========================================\n\nTop Answer:\nHere's what I ended up doing in the .NET client:\n\n```\nprotected byte[] WaitForMessageWithTimeout(string queueName, int timeoutMs)\n{\n var consumer = new QueueingBasicConsumer(Channel);\n var tag = Channel.BasicConsume(queueName, true, null, consumer);\n try\n {\n object result;\n if (!consumer.Queue.Dequeue(timeoutMs, out result))\n throw new ApplicationException(string.Format(\"Timeout ({0} seconds) expired while waiting for an MQ response.\", timeoutMs / 1000.0));\n\n return ((BasicDeliverEventArgs)result).Body;\n }\n finally\n {\n Channel.BasicCancel(tag);\n }\n}\n```\n\nUnfortunately, I cannot do the same with py-amqplib, because its `basic_consume` method does not call the callback unless you call `channel.wait()` and `channel.wait()` doesn't support timeouts! This silly limitation (which I keep running into) means that if you never receive another message your thread is frozen forever.\n\n========================================\n\nCode:\n```text\ndef _wait_for_message_with_timeout(channel, queue_name, timeout):\n slept = 0\n sleep_interval = 0.1\n\n while slept < timeout:\n reply = channel.basic_get(queue_name)\n if reply is not None:\n return reply\n\n time.sleep(sleep_interval)\n slept += sleep_interval\n\n raise Exception('Timeout (%g seconds) expired while waiting for an MQ response.' % timeout)\n```\n\n```text\nbasic_get\n```\n\n```text\nsleep\n```\n\n```text\namqplib\n```\n\n```text\ncarrot\n```\n\n```text\namqplib.client0_8.Connection\n```\n\n```text\nwait_multi\n```\n\n```text\nchannel.wait\n```\n\n```text\nmsg = q.get(timeout=1)\n```\n\n```text\nprotected byte[] WaitForMessageWithTimeout(string queueName, int timeoutMs)\n{\n var consumer = new QueueingBasicConsumer(Channel);\n var tag = Channel.BasicConsume(queueName, true, null, consumer);\n try\n {\n object result;\n if (!consumer.Queue.Dequeue(timeoutMs, out result))\n throw new ApplicationException(string.Format(\"Timeout ({0} seconds) expired while waiting for an MQ response.\", timeoutMs / 1000.0));\n\n return ((BasicDeliverEventArgs)result).Body;\n }\n finally\n {\n Channel.BasicCancel(tag);\n }\n}\n```\n\n```text\nbasic_consume\n```\n\n```text\nchannel.wait()\n```\n\n```text\nchannel.wait()\n```\n\n```text\ntry{\n using (IModel channel = rabbitConnection.connection.CreateModel())\n {\n client = new SimpleRpcClient(channel, \"\", \"\", queue);\n client.TimeoutMilliseconds = 5000; // 5 sec. defaults to infinity\n client.TimedOut += RpcTimedOutHandler;\n client.Disconnected += RpcDisconnectedHandler;\n byte[] replyMessageBytes = client.Call(message);\n return replyMessageBytes;\n }\n}\ncatch (Exception){\n //Handle timeout and disconnect here\n}\nprivate void RpcDisconnectedHandler(object sender, EventArgs e)\n{\n throw new Exception(\"RPC disconnect exception occured.\");\n}\n\nprivate void RpcTimedOutHandler(object sender, EventArgs e)\n{\n throw new Exception(\"RPC timeout exception occured.\");\n}\n```\n\n========================================\n\nComments:\n- While RpcClient itself is not useful to me, looking at its implementation reveals the approach to use: create a `QueueingBasicConsumer` and wait on its queue, which supports a timeout. This isn't as complex in .NET as I feared.\n- Looking at the source of qpid it seems to use the exact same approach as the .NET client: `basic_consume` with a queue and waiting on the queue with a timeout. Looks like that's what I'll have to do.\n- Now this is what I call a \"great answer\": \"it's fixed\"! Accepting - in the hope that it *is* merged into amqplib.\n- @EMP haha :) funny :)","metadata":{"transformedAt":"2026-08-18T18:33:20.144Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":14,"totalLines":159,"estimatedTokens":1109}}287{"id":"stack-31687652","source":"stackoverflow","questionId":31687652,"title":"Creating a queue per remote method when using RabbitMQ?","tags":["rabbitmq","rpc","mq"],"text":"Title: Creating a queue per remote method when using RabbitMQ?\nTags: rabbitmq, rpc, mq\nSource: Stack Overflow\n\nQuestion:\nLet's just accept for a moment that it is not a horrible idea to implement RPC over message queues (like RabbitMQ) -- sometimes it might be necessary when interfacing with legacy systems.\n\nIn case of RPC over RabbitMQ, clients send a message to the broker, broker routes the message to a worker, worker returns the result through the broker to the client. However, if a worker implements more than one remote method, then somehow the different calls need to be routed to different listeners. \n\nWhat is the general practice in this case? All RPC over MQ examples show only one remote method. It would be nice and easy to just set the method name as the routing rule/queue name, but I don't know whether this is the right way to do it.\n\n========================================\n\nTop Answer:\nI've found that using a new reply-to queue per request can get really inefficient, specially when running RabbitMQ on a cluster.\n\nAs suggested in the comments direct reply-to seems to be the way to go. I've documented here all the options I tried before settling to that one.\n\n========================================\n\nCode:\n```text\ncorrelation-id\n```\n\n```text\nreply-to\n```\n\n```text\ncorrelationId\n```\n\n```text\nreplyTo\n```\n\n```text\ncorrelationId\n```\n\n```text\nreplyTo\n```\n\n```text\nreplyTo\n```\n\n```text\nreplyTo\n```\n\n```text\ncorrelationId\n```\n\n```text\nreplyTo\n```\n\n```text\ncorrelationId\n```\n\n```text\nconst rabbitmqreplyto = require('amq.rabbitmq.reply-to.js');\n\nconst serverCallbackTimesTen = (message, rpcServer) => {\n const n = parseInt(message);\n return Promise.resolve(`${n * 10}`);\n};\n\nlet rpcServer;\nlet rpcClient;\nPromise.resolve().then(() => {\n const serverOptions = new rabbitmqreplyto.RpcServerOptions(\n /* url */ undefined, \n /* serverId */ undefined, \n /* callback */ serverCallbackTimesTen);\n\n return rabbitmqreplyto.RpcServer.Create(serverOptions);\n}).then((rpcServerP) => {\n rpcServer = rpcServerP;\n return rabbitmqreplyto.RpcClient.Create();\n}).then((rpcClientP) => {\n rpcClient = rpcClientP;\n const promises = [];\n for (let i = 1; i <= 20; i++) {\n promises.push(rpcClient.sendRPCMessage(`${i}`));\n }\n return Promise.all(promises);\n}).then((replies) => {\n console.log(replies);\n return Promise.all([rpcServer.Close(), rpcClient.Close()]);\n});\n\n//['10',\n// '20',\n// '30',\n// '40',\n// '50',\n// '60',\n// '70',\n// '80',\n// '90',\n// '100',\n// '110',\n// '120',\n// '130',\n// '140',\n// '150',\n// '160',\n// '170',\n// '180',\n// '190',\n// '200']\n```\n\n========================================\n\nComments:\n- Hi, thanks for the answer. I actually realized that the recent AMQP/RabbitMQ implementations can directly send back a reply to the sender without manually implementing and creating reply queues.\n- where did you read that? i haven't paid attention to recent releases, and was not aware of this\n- i found it: rabbitmq.com/direct-reply-to.html - i'll have to look in to this more. seems interesting\n- Yes, that's exactly it.","metadata":{"transformedAt":"2026-08-18T18:33:20.144Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":126,"estimatedTokens":778}}288{"id":"stack-50909458","source":"stackoverflow","questionId":50909458,"title":"Managing Kafka Topic with spring","tags":["java","spring-boot","apache-kafka","rabbitmq","spring-kafka"],"text":"Title: Managing Kafka Topic with spring\nTags: java, spring-boot, apache-kafka, rabbitmq, spring-kafka\nSource: Stack Overflow\n\nQuestion:\nWe are planning to use Kafka for queueing in our application. I have some bit of experience in RabbitMQ and Spring. \n\nWith RabbitMQ and Spring, we used to manage queue creation while starting up the spring service. \n\nWith Kafka, I'm not sure what could be the best way to create the topics? Is there a way to manage the topics with Spring. \n\nOr, should we write a separate script which helps in creating topics? Maintaining a separate script for creating topics seems a bit weird for me.\n\nAny suggestions will be appreciated.\n\n========================================\n\nTop Answer:\nTo automatically create a Kafka topic in Spring Boot, **only this is required:**\n\n```\n@Bean\npublic NewTopic topic1() {\n return new NewTopic(\"foo\", 10, (short) 2);\n\n //foo: topic name\n //10: number of partitions\n //2: replication factor\n}\n```\n\nThe Kafka Admin is being automatically created and configured by Spring Boot.\n\nVersion 2.3 of Spring Kafka introduced a TopicBuilder class, to make building topics fluent and more intuitive:\n\n```\n@Bean\npublic NewTopic topic(){\n return TopicBuilder.name(\"foo\")\n .partitions(10)\n .replicas(2)\n .build();\n}\n```\n\n========================================\n\nCode:\n```text\n@Bean\npublic KafkaAdmin admin() {\n Map<String, Object> configs = new HashMap<>();\n configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG,\n StringUtils.arrayToCommaDelimitedString(kafkaEmbedded().getBrokerAddresses()));\n return new KafkaAdmin(configs);\n}\n\n@Bean\npublic NewTopic topic1() {\n return new NewTopic(\"foo\", 10, (short) 2);\n}\n```\n\n```text\n@Autowired\nprivate KafkaAdmin admin;\n//...your implementation\n```\n\n```text\nAdminClient\n```\n\n```text\nauto.create.topics.enable\n```\n\n```text\n@Bean\npublic NewTopic topic1() {\n return new NewTopic(\"foo\", 10, (short) 2);\n\n //foo: topic name\n //10: number of partitions\n //2: replication factor\n}\n```\n\n```text\n@Bean\npublic NewTopic topic(){\n return TopicBuilder.name(\"foo\")\n .partitions(10)\n .replicas(2)\n .build();\n}\n```\n\n========================================\n\nComments:\n- kafka 1.1.0 has `auto.create.topics.enable` set to true by default, if it is ok for your production requirements you are already set :D\n- Is it advisable to enable that in production?\n- In general I do not see issues by keeping it enable since 99% of the time kafka is configured to be reachable only by local network and on top of that you can add authentication, so it depends on your architecture and security requirements\n- Yes. Its reachable only by local network\n- I'd prefer disabling it to prevent the app from creating wrong/unnecessary topic accidentally. If it's on local network, a pre-prod app startup might be able to access the cluster? Depends on your NW setting/security, but disabling might be wise choice IMHO.\n- Spring Boot auto configures a `KafkaAdmin` so you only need to add the `NewTopic` `@Bean`s in a boot application.","metadata":{"transformedAt":"2026-08-18T18:33:20.144Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":107,"estimatedTokens":762}}289{"id":"stack-26977708","source":"stackoverflow","questionId":26977708,"title":"How to consume RabbitMQ messages via pika for some limited time?","tags":["python","python-2.7","rabbitmq","pika"],"text":"Title: How to consume RabbitMQ messages via pika for some limited time?\nTags: python, python-2.7, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nAll the examples in pika tutorial end with the client invoking `start_consuming()`, which starts an infinite loop. These examples work for me.\n\nHowever, I do not want my client to run forever. Instead, I need my client to consume messages for some time, such as 15 minutes, then stop.\n\nHow do I accomplish that?\n\n========================================\n\nCode:\n```text\nstart_consuming()\n```\n\n```text\nqueue_state = channel.queue_declare(queue, durable=True, passive=True)\nqueue_empty = queue_state.method.message_count == 0\n```\n\n```text\nif not queue_empty:\n method, properties, body = channel.basic_get(queue, no_ack=True)\n callback_func(channel, method, properties, body)\n```\n\n```text\n# DO NOT\nchannel.basic_consume(callback_func, queue, no_ack=True)\n```\n\n```text\nchannel\n```\n\n```text\nqueue\n```\n\n```text\ncallback_func\n```\n\n========================================\n\nComments:\n- The answer of this question may be useful.\n- Presumably I need invoke channel.close(), so that the exit is clean, right? Is there anything else I need to do on exit?\n- Also I guess I could just invoke this: method, properties, body = channel.basic_get(queue, no_ack=True), followed by if not body is None. Can you explain why do you recommend checking if queue is empty first?\n- Yes, you should close the channel. I check the queue this way because it is more clear what is going on, you could for instance, wait until you have N messages on the queue before processing. The `None` check is fine too though.\n- @Mike I am trying to use RabbitMQ on my localhost, but having hard time with it, can you give me any pointers regarding that","metadata":{"transformedAt":"2026-08-18T18:33:20.144Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":7,"totalLines":54,"estimatedTokens":441}}290{"id":"stack-5951477","source":"stackoverflow","questionId":5951477,"title":"Publish/Subscribe samples with RabbitMQ in .NET","tags":["c#","rabbitmq","publish-subscribe","messagebroker"],"text":"Title: Publish/Subscribe samples with RabbitMQ in .NET\nTags: c#, rabbitmq, publish-subscribe, messagebroker\nSource: Stack Overflow\n\nQuestion:\nI've built this sample: Getting Started With RabbitMQ in .net, but made 2 programs: \n\n- one-publisher\n\n- one-subscriber\n\nI'm using `BasicPublish` to publish and `BasicAck` to listen as in example. If I run one publisher and several subscribers-on every \"send message\" from publisher- only one subscriber gets it. So that there is some order (as subscribers were started) in which publisher sends message to subscribers, and I want to send one message to all subscribers. What is wrong with that sample? May be you can provide working sample of publisher/subscribers message exchange via RabbitMq?\n\n========================================\n\nTop Answer:\nI've added a new tutorial about this Getting Started With RabbitMQ in .net\n\n========================================\n\nCode:\n```text\nBasicPublish\n```\n\n```text\nBasicAck\n```\n\n========================================\n\nComments:\n- Just changed that java code to c# and it worked. Thank you.\n- Thank you - so far your example is the only one I've seen that does asynchronous subscriptions in .NET. Calling Invoke on a delegate seems \"retro\" - is there a better way?","metadata":{"transformedAt":"2026-08-18T18:33:20.144Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":34,"estimatedTokens":314}}291{"id":"stack-27104726","source":"stackoverflow","questionId":27104726,"title":"RabbitMQ clustering and mirror queues behavior behind the scenes","tags":["rabbitmq","haproxy","high-availability"],"text":"Title: RabbitMQ clustering and mirror queues behavior behind the scenes\nTags: rabbitmq, haproxy, high-availability\nSource: Stack Overflow\n\nQuestion:\nCan someone please explain what is going on behind the scenes in a RabbitMQ cluster with multiple nodes and queues in mirrored fashion when publishing to a slave node?\n\nFrom what I read, it seems that all actions other than publishes go only to the master and the master then broadcasts the effect of the actions to the slaves(this is from the documentation). Form my understanding it means a consumer will always consume message from the master queue. Also, if I send a request to a slave for consuming a message, that slave will do an extra hop by getting to the master for fetching that message.\n\nBut what happens when I publish to a slave node? Will this node do the same thing of sending first the message to the master?\n\nIt seems there are so many extra hops when dealing with slaves, so it seems you could have a better performance if you know only the master. But how do you handle master failure? Then one of the slaves will be elected master, so you have to know where to connect to?\n\nAsking all of this because we are using RabbitMQ cluster with HAProxy in front, so we can decouple the cluster structure from our apps. This way, whenever a node goes done, the HAProxy will redirect to living nodes. But we have problems when we kill one of the rabbit nodes. The connection to rabbit is permanent, so if it fails, you have to recreate it. Also, you have to resend the messages in this cases, otherwise you will lose them.\n\nEven with all of this, messages can still be lost, because they may be in transit when I kill a node (in some buffers, somewhere on the network etc). So you have to use transactions or publisher confirms, which guarantee the delivery after all the mirrors have been filled up with the message. But here another issue. You may have duplicate messages, because the broker might have sent a confirmation that never reached the producer (due to network failures, etc). Therefore consumer applications will need to perform deduplication or handle incoming messages in an idempotent manner.\n\nIs there a way of avoiding this? Or I have to decide whether I can lose couple of messages versus duplication of some messages?\n\n========================================\n\nCode:\n```text\nmessage-ttl\n```\n\n========================================\n\nComments:\n- Thank you Paul. You are a god. Just to make sure before I move to implementation can you please confirm this: 1)I can use still use HAProxy and publisher confirms and I won't lose any message. I will have duplicate messages, which I have to remove somehow. I will have performance issues(due to extra hops to the master when first reaching the slaves), but my data will be \"bullet-proof\". 2)In order to increase performance, I will create a monitor service so I will send my requests only to the master every time, but I still need to deal with duplicates. Thanks.\n- You can still use HAProxy, but you'll incur extra network hops with a round-robin configuration. If you want to achieve even load-balancing, please read this: insidethecpu.com/2014/11/17/load-balancing-a-rabbitmq-cluste‌​r It's very unlikely that you will have duplicate messages. I think that setting the message-ttl property is sufficient to remove duplicates, though adding a reference-tag, as I mentioned, will solve the problem. I'll be releasing a RabbitMQ library in C# that achieves all of the above, shortly. Keep monitoring my blog for updates.\n- Actually I did end up having duplicate messages. I ran a test couple of times publishing 10000 messages to a 2 node Rabbit cluster. I killed one node and I got 10011-10012 messages. One of my consuming API is idempotent, so the final result was ok. Thanks a lot.\n- That's very interesting and worth looking into. You're welcome.","metadata":{"transformedAt":"2026-08-18T18:33:20.144Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":33,"estimatedTokens":972}}292{"id":"stack-42593804","source":"stackoverflow","questionId":42593804,"title":"RabbitMQ using custom headers to store message-parameters","tags":["rabbitmq","messaging"],"text":"Title: RabbitMQ using custom headers to store message-parameters\nTags: rabbitmq, messaging\nSource: Stack Overflow\n\nQuestion:\nI'm new to RabbitMQ, and I'm somewhat lost in the documentation.\n\nCurrently, as an example, I'm trying to build a small mailer-service that listens to a queue, but I'm somewhat stuck on where I should put the parameters that my service has (destination, subject, ...)\n\nShould I put them inside some encoded format (json), inside my messages, or should I use the header-construction, like the following example:\n\n```\nstring message = \"Hello World!\";\nvar body = Encoding.UTF8.GetBytes(message);\n\nvar properties = new BasicProperties();\nproperties.Headers = new Dictionary();\nproperties.Headers.Add(\"destination\", \"matthias123@localhost\");\n\nchannel.BasicPublish(exchange: \"\", routingKey: \"sendmail\", basicProperties: properties,body: body);\n```\n\nDoes using the headers offer additional benefits? Like, for example, would it be possible to filter messages that are sent to a specific destination?\n\n========================================\n\nCode:\n```cs\nstring message = \"Hello World!\";\nvar body = Encoding.UTF8.GetBytes(message);\n\nvar properties = new BasicProperties();\nproperties.Headers = new Dictionary<string, object>();\nproperties.Headers.Add(\"destination\", \"matthias123@localhost\");\n\nchannel.BasicPublish(exchange: \"\", routingKey: \"sendmail\", basicProperties: properties,body: body);\n```\n\n```text\n{\n start: 1,\n take: 3\n}\n```\n\n```text\nvar properties = new BasicProperties();\nproperties.Headers = new Dictionary();\nproperties.Headers.Add(\"return-queue\", \"fibreturn\");\n```\n\n```text\n1, 1, 2\n```\n\n```text\nstart\n```\n\n```text\ntake\n```\n\n========================================\n\nComments:\n- I think discouraging use of custom headers altogether is in appropriate. While I do agree that the data mentioned above belongs in the body there is valid case for setting customer message headers. For example specifying the message type with an x-type header so consumer can deserialize the payload.\n- the header content-type is not a custom header.\n- (edit timed out). Plus, in this answer he suggests that you can put anything in the headers that is metadata ABOUT the payload. In fact, that's what headers are FOR. But the data you need to operate on? It should be in the payload. I'd caution against writing your letter on an empty envelope.","metadata":{"transformedAt":"2026-08-18T18:33:20.144Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":69,"estimatedTokens":590}}293{"id":"stack-25489292","source":"stackoverflow","questionId":25489292,"title":"Consuming rabbitmq queue from inside python threads","tags":["python","multithreading","rabbitmq"],"text":"Title: Consuming rabbitmq queue from inside python threads\nTags: python, multithreading, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nThis is a long one.\n\nI have a list of usernames and passwords. For each one I want to login to the accounts and do something things. I want to use several machines to do this faster. The way I was thinking of doing this is have a main machine whose job is just having a cron which from time to time checks if the rabbitmq queue is empty. If it is, read the list of usernames and passwords from a file and send it to the rabbitmq queue. Then have a bunch of machines which are subscribed to that queue whose job is receiving a user/pass, do stuff on it, acknowledge it, and move on to the next one, until the queue is empty and then the main machine fills it up again. So far I think I have everything down.\n\nNow comes my problem. I have checked that the things to be done with each user/passes aren't so intensive and so I could have each machine doing three of them simultaneously using python's threading. In fact for a single machine I have implemented this where I load the user/passes into a python Queue() and then have three threads consume that Queue(). Now I want to do something similar, but instead of consuming from a python Queue(), each thread of each machine should consume from a rabbitmq queue. This is where I'm stuck. To run tests I started by using rabbitmq's tutorial.\n\nsend.py:\n\n```\nimport pika, sys\nconnection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))\nchannel = connection.channel()\nchannel.queue_declare(queue='hello')\n\nmessage = ' '.join(sys.argv[1:])\nchannel.basic_publish(exchange='',\n routing_key='hello',\n body=message)\nconnection.close()\n```\n\nworker.py\n\n```\nimport time, pika\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))\nchannel = connection.channel()\nchannel.queue_declare(queue='hello')\n\ndef callback(ch, method, properties, body):\n print ' [x] received %r' % (body,)\n time.sleep( body.count('.') )\n ch.basic_ack(delivery_tag = method.delivery_tag)\n\nchannel.basic_qos(prefetch_count=1)\nchannel.basic_consume(callback, queue='hello', no_ack=False)\nchannel.start_consuming()\n```\n\nFor the above you can run two worker.py which will subscribe to the rabbitmq queue and consume as expected.\n\nMy threading without rabbitmq is something like this:\n\nrunit.py\n\n```\nclass Threaded_do_stuff(threading.Thread):\n def __init__(self, user_queue):\n threading.Thread.__init__(self)\n self.user_queue = user_queue\n\n def run(self):\n while True:\n login = self.user_queue.get()\n do_stuff(user=login[0], pass=login[1])\n self.user_queue.task_done()\n\nuser_queue = Queue.Queue()\nfor i in range(3):\n td = Threaded_do_stuff(user_queue)\n td.setDaemon(True)\n td.start()\n\n## fill up the queue\nfor user in list_users:\n user_queue.put(user)\n\n## go!\nuser_queue.join()\n```\n\nThis also works as expected: you fill up the queue and have 3 threads subscribe to it. Now what I want to do is something like runit.py but instead of using a python Queue(), using something like worker.py where the queue is actually a rabbitmq queue.\n\nHere's something which I tried and didn't work (and I don't understand why)\n\nrabbitmq_runit.py\n\n```\nimport time, threading, pika\n\nclass Threaded_worker(threading.Thread):\n def callback(self, ch, method, properties, body):\n print ' [x] received %r' % (body,)\n time.sleep( body.count('.') )\n ch.basic_ack(delivery_tag = method.delivery_tag)\n\n def __init__(self):\n threading.Thread.__init__(self)\n self.connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))\n self.channel = self.connection.channel()\n self.channel.queue_declare(queue='hello')\n self.channel.basic_qos(prefetch_count=1)\n self.channel.basic_consume(self.callback, queue='hello')\n\n def run(self):\n print 'start consuming'\n self.channel.start_consuming()\n\nfor _ in range(3):\n print 'launch thread'\n td = Threaded_worker()\n td.setDaemon(True)\n td.start()\n```\n\nI would expect that this launches three threads each of which is blocked by .start_consuming() which just stays there waiting for the rabbitmq queue to send them sometihing. Instead, this program starts, does some prints, and exits. The pattern of the exists is weird too:\n\n```\nlaunch thread\nlaunch thread\nstart consuming\nlaunch thread\nstart consuming\n```\n\nIn particular notice there is one \"start consuming\" missing.\n\nWhat's going on?\n\nEDIT: One answer I found to a similar question is here\nConsuming a rabbitmq message queue with multiple threads (Python Kombu)\nand the answer is to \"use celery\", whatever that means. I don't buy it, I shouldn't need anything remotely as sophisticated as celery. In particular, I'm not trying to set up an RPC and I don't need to read replies from the do_stuff routines.\n\nEDIT 2: The print pattern that I expected would be the following. I do\n\n```\npython send.py first message......\npython send.py second message.\npython send.py third message.\npython send.py fourth message.\n```\n\nand the print pattern would be\n\n```\nlaunch thread\nstart consuming\n [x] received 'first message......'\nlaunch thread\nstart consuming\n [x] received 'second message.'\nlaunch thread\nstart consuming\n [x] received 'third message.'\n [x] received 'fourth message.'\n```\n\n========================================\n\nCode:\n```text\nimport pika, sys\nconnection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))\nchannel = connection.channel()\nchannel.queue_declare(queue='hello')\n\nmessage = ' '.join(sys.argv[1:])\nchannel.basic_publish(exchange='',\n routing_key='hello',\n body=message)\nconnection.close()\n```\n\n```text\nimport time, pika\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))\nchannel = connection.channel()\nchannel.queue_declare(queue='hello')\n\ndef callback(ch, method, properties, body):\n print ' [x] received %r' % (body,)\n time.sleep( body.count('.') )\n ch.basic_ack(delivery_tag = method.delivery_tag)\n\nchannel.basic_qos(prefetch_count=1)\nchannel.basic_consume(callback, queue='hello', no_ack=False)\nchannel.start_consuming()\n```\n\n```text\nclass Threaded_do_stuff(threading.Thread):\n def __init__(self, user_queue):\n threading.Thread.__init__(self)\n self.user_queue = user_queue\n\n def run(self):\n while True:\n login = self.user_queue.get()\n do_stuff(user=login[0], pass=login[1])\n self.user_queue.task_done()\n\nuser_queue = Queue.Queue()\nfor i in range(3):\n td = Threaded_do_stuff(user_queue)\n td.setDaemon(True)\n td.start()\n\n## fill up the queue\nfor user in list_users:\n user_queue.put(user)\n\n## go!\nuser_queue.join()\n```\n\n```text\nimport time, threading, pika\n\nclass Threaded_worker(threading.Thread):\n def callback(self, ch, method, properties, body):\n print ' [x] received %r' % (body,)\n time.sleep( body.count('.') )\n ch.basic_ack(delivery_tag = method.delivery_tag)\n\n def __init__(self):\n threading.Thread.__init__(self)\n self.connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))\n self.channel = self.connection.channel()\n self.channel.queue_declare(queue='hello')\n self.channel.basic_qos(prefetch_count=1)\n self.channel.basic_consume(self.callback, queue='hello')\n\n def run(self):\n print 'start consuming'\n self.channel.start_consuming()\n\nfor _ in range(3):\n print 'launch thread'\n td = Threaded_worker()\n td.setDaemon(True)\n td.start()\n```\n\n```text\nlaunch thread\nlaunch thread\nstart consuming\nlaunch thread\nstart consuming\n```\n\n```text\npython send.py first message......\npython send.py second message.\npython send.py third message.\npython send.py fourth message.\n```\n\n```text\nlaunch thread\nstart consuming\n [x] received 'first message......'\nlaunch thread\nstart consuming\n [x] received 'second message.'\nlaunch thread\nstart consuming\n [x] received 'third message.'\n [x] received 'fourth message.'\n```\n\n```text\ntd = Threaded_worker()\ntd.setDaemon(True) # Shouldn't do that.\ntd.start()\n```\n\n```text\nsetDaemon(True)\n```\n\n```text\n__init__()\n```\n\n```text\nrun()\n```\n\n========================================\n\nComments:\n- That's it! Amazing, I didn't expect anyone would read such a long post, let along be able to answer it. Thank you so much!\n- Also for completeness: rabbitmq.com/tutorials/amqp-concepts.html, chapters \"Channels\" and \"Connections\": it would be better to have one channel per thread and the connection, but pika does not support it.","metadata":{"transformedAt":"2026-08-18T18:33:20.144Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":11,"totalLines":291,"estimatedTokens":2127}}294{"id":"stack-6696694","source":"stackoverflow","questionId":6696694,"title":"Reading from multiple queues, RabbitMQ","tags":["c#",".net","rabbitmq","amqp"],"text":"Title: Reading from multiple queues, RabbitMQ\nTags: c#, .net, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI am new to RabbitMQ. I want to be able to handle reading messages without blocking when there are multiple queues (to read from). Any inputs on how I can do that? \n\n//Edit 1\n\n```\npublic class Rabbit : IMessageBus\n{ \n\n private List publishQ = new List();\n private List subscribeQ = new List();\n\n ConnectionFactory factory = null;\n IConnection connection = null;\n IModel channel = null; \n Subscription sub = null;\n\n public void writeMessage( Measurement m1 ) {\n byte[] body = Measurement.AltSerialize( m1 );\n int msgCount = 1;\n Console.WriteLine(\"Sending message to queue {1} via the amq.direct exchange.\", m1.id);\n\n string finalQueue = publishToQueue( m1.id );\n\n while (msgCount --> 0) {\n channel.BasicPublish(\"amq.direct\", finalQueue, null, body);\n }\n\n Console.WriteLine(\"Done. Wrote the message to queue {0}.\\n\", m1.id);\n }\n\n public string publishToQueue(string firstQueueName) {\n Console.WriteLine(\"Creating a queue and binding it to amq.direct\");\n string queueName = channel.QueueDeclare(firstQueueName, true, false, false, null);\n channel.QueueBind(queueName, \"amq.direct\", queueName, null);\n Console.WriteLine(\"Done. Created queue {0} and bound it to amq.direct.\\n\", queueName);\n return queueName;\n }\n\n public Measurement readMessage() {\n Console.WriteLine(\"Receiving message...\");\n Measurement m = new Measurement();\n\n int i = 0;\n foreach (BasicDeliverEventArgs ev in sub) {\n m = Measurement.AltDeSerialize(ev.Body);\n //m.id = //get the id here, from sub\n if (++i == 1)\n break;\n sub.Ack();\n }\n\n Console.WriteLine(\"Done.\\n\");\n return m;\n }\n\n public void subscribeToQueue(string queueName ) \n {\n sub = new Subscription(channel, queueName);\n }\n\n public static string MsgSysName;\n public string MsgSys\n {\n get \n { \n return MsgSysName;\n }\n set\n {\n MsgSysName = value;\n }\n }\n\n public Rabbit(string _msgSys) //Constructor\n { \n factory = new ConnectionFactory();\n factory.HostName = \"localhost\"; \n connection = factory.CreateConnection();\n channel = connection.CreateModel();\n //consumer = new QueueingBasicConsumer(channel);\n\n System.Console.WriteLine(\"\\nMsgSys: RabbitMQ\");\n MsgSys = _msgSys;\n }\n\n ~Rabbit()\n {\n //observer??\n connection.Dispose();\n //channel.Dispose();\n System.Console.WriteLine(\"\\nDestroying RABBIT\");\n } \n}\n```\n\n//Edit 2\n\n```\nprivate List subscriptions = new List();\n Subscription sub = null;\n\npublic Measurement readMessage()\n {\n Measurement m = new Measurement();\n foreach(Subscription element in subscriptions)\n {\n foreach (BasicDeliverEventArgs ev in element) {\n //ev = element.Next();\n if( ev != null) {\n m = Measurement.AltDeSerialize( ev.Body );\n return m;\n }\n m = null; \n } \n } \n System.Console.WriteLine(\"No message in the queue(s) at this time.\");\n return m;\n }\n\n public void subscribeToQueue(string queueName) \n { \n sub = new Subscription(channel, queueName);\n subscriptions.Add(sub); \n }\n```\n\n//Edit 3\n\n```\n//MessageHandler.cs\n\npublic class MessageHandler\n{ \n // Implementation of methods for Rabbit class go here\n private List publishQ = new List();\n private List subscribeQ = new List();\n\n ConnectionFactory factory = null;\n IConnection connection = null;\n IModel channel = null; \n QueueingBasicConsumer consumer = null; \n\n private List subscriptions = new List();\n Subscription sub = null;\n\n public void writeMessage ( Measurement m1 )\n {\n byte[] body = Measurement.AltSerialize( m1 );\n //declare a queue if it doesn't exist\n publishToQueue(m1.id);\n\n channel.BasicPublish(\"amq.direct\", m1.id, null, body);\n Console.WriteLine(\"\\n [x] Sent to queue {0}.\", m1.id);\n }\n\n public void publishToQueue(string queueName)\n { \n string finalQueueName = channel.QueueDeclare(queueName, true, false, false, null);\n channel.QueueBind(finalQueueName, \"amq.direct\", \"\", null);\n }\n\n public Measurement readMessage()\n {\n Measurement m = new Measurement();\n foreach(Subscription element in subscriptions)\n {\n if( element.QueueName == null)\n {\n m = null;\n }\n else \n {\n BasicDeliverEventArgs ev = element.Next();\n if( ev != null) {\n m = Measurement.AltDeSerialize( ev.Body );\n m.id = element.QueueName;\n element.Ack();\n return m;\n }\n m = null; \n }\n element.Ack();\n } \n System.Console.WriteLine(\"No message in the queue(s) at this time.\");\n return m;\n }\n\n public void subscribeToQueue(string queueName) \n { \n sub = new Subscription(channel, queueName);\n subscriptions.Add(sub); \n }\n\n public static string MsgSysName;\n public string MsgSys\n {\n get \n { \n return MsgSysName;\n }\n set\n {\n MsgSysName = value;\n }\n }\n\n public MessageHandler(string _msgSys) //Constructor\n { \n factory = new ConnectionFactory();\n factory.HostName = \"localhost\"; \n connection = factory.CreateConnection();\n channel = connection.CreateModel();\n consumer = new QueueingBasicConsumer(channel);\n\n System.Console.WriteLine(\"\\nMsgSys: RabbitMQ\");\n MsgSys = _msgSys;\n }\n\n public void disposeAll()\n {\n connection.Dispose();\n channel.Dispose();\n foreach(Subscription element in subscriptions)\n {\n element.Close();\n }\n System.Console.WriteLine(\"\\nDestroying RABBIT\");\n } \n}\n```\n\n//App1.cs\n\n```\nusing System;\nusing System.IO;\n\nusing UtilityMeasurement;\nusing UtilityMessageBus;\n\npublic class MainClass\n{\n public static void Main()\n {\n\n MessageHandler obj1 = MessageHandler(\"Rabbit\");\n\n System.Console.WriteLine(\"\\nA {0} object is now created.\", MsgSysName);\n\n //Create new Measurement messages\n Measurement m1 = new Measurement(\"q1\", 2345, 23.456); \n Measurement m2 = new Measurement(\"q2\", 222, 33.33);\n\n System.Console.WriteLine(\"Test message 1:\\n ID: {0}\", m1.id);\n System.Console.WriteLine(\" Time: {0}\", m1.time);\n System.Console.WriteLine(\" Value: {0}\", m1.value);\n\n System.Console.WriteLine(\"Test message 2:\\n ID: {0}\", m2.id);\n System.Console.WriteLine(\" Time: {0}\", m2.time);\n System.Console.WriteLine(\" Value: {0}\", m2.value); \n\n // Ask queue name and store it\n System.Console.WriteLine(\"\\nName of queue to publish to: \");\n string queueName = (System.Console.ReadLine()).ToString();\n obj1.publishToQueue( queueName );\n\n // Write message to the queue\n obj1.writeMessage( m1 ); \n\n System.Console.WriteLine(\"\\nName of queue to publish to: \");\n string queueName2 = (System.Console.ReadLine()).ToString();\n obj1.publishToQueue( queueName2 );\n\n obj1.writeMessage( m2 );\n\n obj1.disposeAll();\n}\n}\n```\n\n//App2.cs\n\n```\nusing System;\nusing System.IO;\n\nusing UtilityMeasurement;\nusing UtilityMessageBus;\n\npublic class MainClass\n{\n public static void Main()\n {\n //Asks for the message system\n System.Console.WriteLine(\"\\nEnter name of messageing system: \");\n System.Console.WriteLine(\"Usage: [Rabbit] [Zmq]\");\n string MsgSysName = (System.Console.ReadLine()).ToString();\n\n //Declare an IMessageBus instance:\n //Here, an object of the corresponding Message System\n // (ex. Rabbit, Zmq, etc) is instantiated\n IMessageBus obj1 = MessageBusFactory.GetMessageBus(MsgSysName);\n\n System.Console.WriteLine(\"\\nA {0} object is now created.\", MsgSysName);\n\n //Create a new Measurement object m\n Measurement m = new Measurement(); \n\n System.Console.WriteLine(\"Queue name to subscribe to: \");\n string QueueName1 = (System.Console.ReadLine()).ToString();\n obj1.subscribeToQueue( QueueName1 );\n\n //Read message into m\n m = obj1.readMessage();\n\n if (m != null ) {\n System.Console.WriteLine(\"\\nMessage received from queue {0}:\\n ID: {1}\", m.id, m.id);\n System.Console.WriteLine(\" Time: {0}\", m.time);\n System.Console.WriteLine(\" Value: {0}\", m.value);\n }\n\n System.Console.WriteLine(\"Another queue name to subscribe to: \");\n string QueueName2 = (System.Console.ReadLine()).ToString();\n obj1.subscribeToQueue( QueueName2 );\n\n m = obj1.readMessage();\n\n if (m != null ) {\n System.Console.WriteLine(\"\\nMessage received from queue {0}:\\n ID: {1}\", m.id, m.id);\n System.Console.WriteLine(\" Time: {0}\", m.time);\n System.Console.WriteLine(\" Value: {0}\", m.value);\n }\n\n obj1.disposeAll();\n}\n}\n```\n\n========================================\n\nTop Answer:\nThe easiest way is to use the EventingBasicConsumer. I have an example on my site on how to use it. RabbitMQ EventingBasicConsumer\n\nThis Consumer class exposes a Received Event you can use, and therefore does NOT block. The rest of the code basically stays the same.\n\n========================================\n\nCode:\n```text\npublic class Rabbit : IMessageBus\n{ \n\n private List<string> publishQ = new List<string>();\n private List<string> subscribeQ = new List<string>();\n\n ConnectionFactory factory = null;\n IConnection connection = null;\n IModel channel = null; \n Subscription sub = null;\n\n public void writeMessage( Measurement m1 ) {\n byte[] body = Measurement.AltSerialize( m1 );\n int msgCount = 1;\n Console.WriteLine(\"Sending message to queue {1} via the amq.direct exchange.\", m1.id);\n\n string finalQueue = publishToQueue( m1.id );\n\n while (msgCount --> 0) {\n channel.BasicPublish(\"amq.direct\", finalQueue, null, body);\n }\n\n Console.WriteLine(\"Done. Wrote the message to queue {0}.\\n\", m1.id);\n }\n\n public string publishToQueue(string firstQueueName) {\n Console.WriteLine(\"Creating a queue and binding it to amq.direct\");\n string queueName = channel.QueueDeclare(firstQueueName, true, false, false, null);\n channel.QueueBind(queueName, \"amq.direct\", queueName, null);\n Console.WriteLine(\"Done. Created queue {0} and bound it to amq.direct.\\n\", queueName);\n return queueName;\n }\n\n\n public Measurement readMessage() {\n Console.WriteLine(\"Receiving message...\");\n Measurement m = new Measurement();\n\n int i = 0;\n foreach (BasicDeliverEventArgs ev in sub) {\n m = Measurement.AltDeSerialize(ev.Body);\n //m.id = //get the id here, from sub\n if (++i == 1)\n break;\n sub.Ack();\n }\n\n Console.WriteLine(\"Done.\\n\");\n return m;\n }\n\n\n public void subscribeToQueue(string queueName ) \n {\n sub = new Subscription(channel, queueName);\n }\n\n public static string MsgSysName;\n public string MsgSys\n {\n get \n { \n return MsgSysName;\n }\n set\n {\n MsgSysName = value;\n }\n }\n\n public Rabbit(string _msgSys) //Constructor\n { \n factory = new ConnectionFactory();\n factory.HostName = \"localhost\"; \n connection = factory.CreateConnection();\n channel = connection.CreateModel();\n //consumer = new QueueingBasicConsumer(channel);\n\n System.Console.WriteLine(\"\\nMsgSys: RabbitMQ\");\n MsgSys = _msgSys;\n }\n\n ~Rabbit()\n {\n //observer??\n connection.Dispose();\n //channel.Dispose();\n System.Console.WriteLine(\"\\nDestroying RABBIT\");\n } \n}\n```\n\n```text\nprivate List<Subscription> subscriptions = new List<Subscription>();\n Subscription sub = null;\n\npublic Measurement readMessage()\n {\n Measurement m = new Measurement();\n foreach(Subscription element in subscriptions)\n {\n foreach (BasicDeliverEventArgs ev in element) {\n //ev = element.Next();\n if( ev != null) {\n m = Measurement.AltDeSerialize( ev.Body );\n return m;\n }\n m = null; \n } \n } \n System.Console.WriteLine(\"No message in the queue(s) at this time.\");\n return m;\n }\n\n public void subscribeToQueue(string queueName) \n { \n sub = new Subscription(channel, queueName);\n subscriptions.Add(sub); \n }\n```\n\n```text\n//MessageHandler.cs\n\npublic class MessageHandler\n{ \n // Implementation of methods for Rabbit class go here\n private List<string> publishQ = new List<string>();\n private List<string> subscribeQ = new List<string>();\n\n ConnectionFactory factory = null;\n IConnection connection = null;\n IModel channel = null; \n QueueingBasicConsumer consumer = null; \n\n private List<Subscription> subscriptions = new List<Subscription>();\n Subscription sub = null;\n\n public void writeMessage ( Measurement m1 )\n {\n byte[] body = Measurement.AltSerialize( m1 );\n //declare a queue if it doesn't exist\n publishToQueue(m1.id);\n\n channel.BasicPublish(\"amq.direct\", m1.id, null, body);\n Console.WriteLine(\"\\n [x] Sent to queue {0}.\", m1.id);\n }\n\n public void publishToQueue(string queueName)\n { \n string finalQueueName = channel.QueueDeclare(queueName, true, false, false, null);\n channel.QueueBind(finalQueueName, \"amq.direct\", \"\", null);\n }\n\n public Measurement readMessage()\n {\n Measurement m = new Measurement();\n foreach(Subscription element in subscriptions)\n {\n if( element.QueueName == null)\n {\n m = null;\n }\n else \n {\n BasicDeliverEventArgs ev = element.Next();\n if( ev != null) {\n m = Measurement.AltDeSerialize( ev.Body );\n m.id = element.QueueName;\n element.Ack();\n return m;\n }\n m = null; \n }\n element.Ack();\n } \n System.Console.WriteLine(\"No message in the queue(s) at this time.\");\n return m;\n }\n\n public void subscribeToQueue(string queueName) \n { \n sub = new Subscription(channel, queueName);\n subscriptions.Add(sub); \n }\n\n public static string MsgSysName;\n public string MsgSys\n {\n get \n { \n return MsgSysName;\n }\n set\n {\n MsgSysName = value;\n }\n }\n\n public MessageHandler(string _msgSys) //Constructor\n { \n factory = new ConnectionFactory();\n factory.HostName = \"localhost\"; \n connection = factory.CreateConnection();\n channel = connection.CreateModel();\n consumer = new QueueingBasicConsumer(channel);\n\n System.Console.WriteLine(\"\\nMsgSys: RabbitMQ\");\n MsgSys = _msgSys;\n }\n\n public void disposeAll()\n {\n connection.Dispose();\n channel.Dispose();\n foreach(Subscription element in subscriptions)\n {\n element.Close();\n }\n System.Console.WriteLine(\"\\nDestroying RABBIT\");\n } \n}\n```\n\n```text\nusing System;\nusing System.IO;\n\nusing UtilityMeasurement;\nusing UtilityMessageBus;\n\n\npublic class MainClass\n{\n public static void Main()\n {\n\n MessageHandler obj1 = MessageHandler(\"Rabbit\");\n\n System.Console.WriteLine(\"\\nA {0} object is now created.\", MsgSysName);\n\n //Create new Measurement messages\n Measurement m1 = new Measurement(\"q1\", 2345, 23.456); \n Measurement m2 = new Measurement(\"q2\", 222, 33.33);\n\n System.Console.WriteLine(\"Test message 1:\\n ID: {0}\", m1.id);\n System.Console.WriteLine(\" Time: {0}\", m1.time);\n System.Console.WriteLine(\" Value: {0}\", m1.value);\n\n System.Console.WriteLine(\"Test message 2:\\n ID: {0}\", m2.id);\n System.Console.WriteLine(\" Time: {0}\", m2.time);\n System.Console.WriteLine(\" Value: {0}\", m2.value); \n\n // Ask queue name and store it\n System.Console.WriteLine(\"\\nName of queue to publish to: \");\n string queueName = (System.Console.ReadLine()).ToString();\n obj1.publishToQueue( queueName );\n\n // Write message to the queue\n obj1.writeMessage( m1 ); \n\n System.Console.WriteLine(\"\\nName of queue to publish to: \");\n string queueName2 = (System.Console.ReadLine()).ToString();\n obj1.publishToQueue( queueName2 );\n\n obj1.writeMessage( m2 );\n\n obj1.disposeAll();\n}\n}\n```\n\n```text\nusing System;\nusing System.IO;\n\nusing UtilityMeasurement;\nusing UtilityMessageBus;\n\npublic class MainClass\n{\n public static void Main()\n {\n //Asks for the message system\n System.Console.WriteLine(\"\\nEnter name of messageing system: \");\n System.Console.WriteLine(\"Usage: [Rabbit] [Zmq]\");\n string MsgSysName = (System.Console.ReadLine()).ToString();\n\n //Declare an IMessageBus instance:\n //Here, an object of the corresponding Message System\n // (ex. Rabbit, Zmq, etc) is instantiated\n IMessageBus obj1 = MessageBusFactory.GetMessageBus(MsgSysName);\n\n System.Console.WriteLine(\"\\nA {0} object is now created.\", MsgSysName);\n\n //Create a new Measurement object m\n Measurement m = new Measurement(); \n\n System.Console.WriteLine(\"Queue name to subscribe to: \");\n string QueueName1 = (System.Console.ReadLine()).ToString();\n obj1.subscribeToQueue( QueueName1 );\n\n //Read message into m\n m = obj1.readMessage();\n\n if (m != null ) {\n System.Console.WriteLine(\"\\nMessage received from queue {0}:\\n ID: {1}\", m.id, m.id);\n System.Console.WriteLine(\" Time: {0}\", m.time);\n System.Console.WriteLine(\" Value: {0}\", m.value);\n }\n\n System.Console.WriteLine(\"Another queue name to subscribe to: \");\n string QueueName2 = (System.Console.ReadLine()).ToString();\n obj1.subscribeToQueue( QueueName2 );\n\n m = obj1.readMessage();\n\n if (m != null ) {\n System.Console.WriteLine(\"\\nMessage received from queue {0}:\\n ID: {1}\", m.id, m.id);\n System.Console.WriteLine(\" Time: {0}\", m.time);\n System.Console.WriteLine(\" Value: {0}\", m.value);\n }\n\n obj1.disposeAll();\n}\n}\n```\n\n```text\nusing (Subscription sub = new Subscription(ch, QueueNme))\n {\n foreach (BasicDeliverEventArgs ev in sub)\n {\n Process(ev.Body);\n\n ...\n```\n\n```text\nusing (IModel ch = conn.CreateModel()) { // btw: no reason to close the channel afterwards IMO\n conn.AutoClose = true; // no reason to closs the connection either. Here for completeness.\n\n ch.QueueDeclare(queueName);\n BasicGetResult result = ch.BasicGet(queueName, false);\n if (result == null) {\n Console.WriteLine(\"No message available.\");\n } else {\n ch.BasicAck(result.DeliveryTag, false);\n Console.WriteLine(\"Message:\");\n }\n\n return 0;\n }\n```\n\n```text\nIModel channel = ...;\n QueueingBasicConsumer consumer = new QueueingBasicConsumer(channel);\n channel.BasicConsume(queueName, false, null, consumer); //<-----\n channel.BasicConsume(queueName2, false, null, consumer); //<-----\n // etc. channel.BasicConsume(queueNameN, false, null, consumer); //<-----\n\n // At this point, messages will be being asynchronously delivered,\n // and will be queueing up in consumer.Queue.\n\n while (true) {\n try {\n BasicDeliverEventArgs e = (BasicDeliverEventArgs) consumer.Queue.Dequeue();\n // ... handle the delivery ...\n channel.BasicAck(e.DeliveryTag, false);\n } catch (EndOfStreamException ex) {\n // The consumer was cancelled, the model closed, or the\n // connection went away.\n break;\n }\n }\n```\n\n```text\nch.QueueDeclare(queueName);\n BasicGetResult result = ch.BasicGet(queueName, false);\n if (result == null) {\n Console.WriteLine(\"No message available.\");\n } else {\n ch.BasicAck(result.DeliveryTag, false);\n Console.WriteLine(\"Message:\"); \n // deserialize body and display extra info here.\n }\n```\n\n========================================\n\nComments:\n- Thanks a lot for your feedback. I am still learning the messaging system and there are operations I still don't understand. Like listening. I have also seen how rabbitmq subscribe to a queue. Can you subscribe to multiple queues using new Subscription(channel, queueName) ? And if so, how can I go through all the subscribed queues and return a message (null when no messages)? Oh, and mind you that that I have all this operations in different methods. I will edit my post to reflect the code.\n- Thanks again. I edited the code for subscribe and write functions above. However, I have this run time error: if I subscribe to say two queues and try to read messages I can only retrive messages for the first time. I can't see where I messed it up. Can you take a look at if for me?\n- @Demi ... that took some hunting. I think you are missing \"subscriptions.Ack()\" at the end of your reader loop? Which means 'I have successfully processed this message, so give me the next one.' Let me know if that was it. Otherwise you look close.\n- N.B. that should be at the end of your outer loop\n- if you publish a console Main() procedure using your class, I'll have a play with it in the next day or so if you like. Have you successfully read more than one message from a single queue?\n- i.e. just want to have a simple sequence + know we are in sync\n- no. actually that is the problem. reading message doesn't advance to the next once it read for the first time whether from the same queue or from a different one. i will edit the code to reflect the class and the two console procedures that use this class. i'll keep looking into it as well.\n- Thanks for the help. I did some more digging and figured it out.\n- well done. Would you like to what the issue was so that others can benefit too? thanks.\n- well, this is funny. it's still not reading from multiple queues. however, i read messages using Next() and it worked for a while, i guess there were stored messages in the broker from previous iteration of App1.cs. so am back to seeking help. =) edited code above.\n- messages in the queue from last time is normal (there is a setting to autodelete on disconnect). btw: did you know that you've got two \"element.Ack();\" in your reader? There should only be one. Haven't tried your code yet, but I'm using a topic exchange. You are using a direct exchange. A few thoughts. Got to run.\n- how did I miss this? You have two subscriptions (List), whereas I thought you were trying to subscripe to two queues with one subscriber. Now... you are probably getting thread blocking issues with two threads accesses the same connection / channel. I always do one sequential set of work with each thread/channel/connection set. re: subscribing to more than one queue with one subscriber, this is definitely possible with the Java client, and I am currently enquiring about the .net client on your behalf.\n- As you've also outlined it, my application should be able to use the same AMQP connection to receive messages. However, I am dealing with being able to consume from multiple queues. Does this help?\n- you can get messages from more than one queue on one connection. Subscribing once to multiple queues is different to subscribing twice with two different subscribers. The reason is simply that they haven't got around to supporting that with a helper class (i.e. it works in java). However, the raw functionality is still there in the .net client to get what you want.\n- see updates 3 & 4. That should be what you are after. I will add update 5 as a fall back position for you.\n- All the links here are broken","metadata":{"transformedAt":"2026-08-18T18:33:20.145Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":763,"estimatedTokens":5813}}295{"id":"stack-15121519","source":"stackoverflow","questionId":15121519,"title":"Differentiate celery, kombu, PyAMQP and RabbitMQ/ironMQ","tags":["python","heroku","rabbitmq","celery","kombu"],"text":"Title: Differentiate celery, kombu, PyAMQP and RabbitMQ/ironMQ\nTags: python, heroku, rabbitmq, celery, kombu\nSource: Stack Overflow\n\nQuestion:\nI want to upload images to S3 server, but before uploading I want to generate thumbnails of 3 different sizes, and I want it to be done out of request/response cycle hence I am using celery. I have read the docs, here is what I have understood. Please correct me if I am wrong.\n\n- Celery helps you manage your task queues outside the request response cycle.\n\n- Then there is something called carrot/kombu - its a django middleware that packages tasks that get created via celery.\n\n- Then the third layer PyAMQP that facilitates the communication of carrot to a broker. eg. RabbitMQ, AmazonSQS, ironMQ etc.\n\n- Broker sits on a different server and does stuff for you.\n\nNow my understanding is - if multiple users upload image at the same time, celery will queue the resizing, and the resizing will actually happen at the ironMQ server, since it offers a cool addon on heroku.\n\nNow the doubts:\n\nBut what after the image is resized, will ironMQ push it to the S3 server, or will it notify once the process is completed.. i am not clear about it.\n\nWhat is the difference between celery and kombu/carrot, could you explain vividly.\n\n========================================\n\nTop Answer:\n\"One of the biggest differences between IronMQ and RabbitMQ/AMQP is that IronMQ is hosted and managed, so you don't have to host the server yourself and worry about uptime.\" \n\nCurrently there are at least two hosted managed RabbitMQ-as-a-service options: Bigwig and CloudAMQP. Celery should work well with both.\n\n========================================\n\nComments:\n- Kombu is the queue connector. Celery builds *on top of* kombu. It is independent of Django. Kombu superseded carrot quite some time ago.\n- Celery manages tasks; both scheduling them, as well as actually executing the tasks based on message passing.\n- Thanks for the detailed reply. So this is what I have understood. The image processing is done on celery server. Which tasks have been completed etc. is kept track by IronMQ/RabbitMQ. What is this kombu/carrot in the picture?\n- As Martijn explained (stackoverflow.com/questions/15121519/…), Kombu is just a helper underlying Celery. It manages connecting to the queues. Think of it as a high-level messaging wrapper.\n- Thanks Alexis. We'll include those in the future. I think Paddy was referring to native capability - delivered as a service as opposed to a stand up server instance.\n- This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post.","metadata":{"transformedAt":"2026-08-18T18:33:20.145Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":39,"estimatedTokens":666}}296{"id":"stack-10080718","source":"stackoverflow","questionId":10080718,"title":"REST API for rabbitmq","tags":[".net","wcf","rest","rabbitmq","amqp"],"text":"Title: REST API for rabbitmq\nTags: .net, wcf, rest, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nIs there a way how can I send data to RabbitMQ from $.ajax?\n\nMy application is made up of several thousands web-clients (written on js) and WCF REST service and now I am trying to figure out how can I create a scalable point for my application. The idea is to have a rabbitmq instance which receives messages from js clients placed on one side, and instances of WCF Workflow Services which are taking pending messages from the queue.\n\nI understand that AMQP and HTTP is pretty different things.\n\nSo the question is - is there a REST interface for rabbit mq or some sort of gateway for it\n\n========================================\n\nTop Answer:\nThe RabbitMQ REST API documentation for the 3.7.4 release can be found here:\n\nhttps://rawcdn.githack.com/rabbitmq/rabbitmq-management/v3.7.4/priv/www/api/index.html\n\nIt also allows to publish messages besides management tasks.\n\nImportant note from the linked documentation:\n\nPlease note that the publish / get paths in the HTTP API are intended\nfor injecting test messages, diagnostics etc - they do not implement\nreliable delivery and so should be treated as a sysadmin's tool rather\nthan a general API for messaging.\n\n========================================\n\nComments:\n- What you pointed out above is RabbitMQ Management Plugin's bundled HTTP API, which is essentially a RESTful API. However, it doesn't implement reliable messaging delivery so it's probably not a good idea to use it in production systems. Here is the quote: \"Please note that the publish / get paths in the HTTP API are intended for injecting test messages, diagnostics etc - they do not implement reliable delivery and so should be treated as a sysadmin's tool rather than a general API for messaging.\"","metadata":{"transformedAt":"2026-08-18T18:33:20.145Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":33,"estimatedTokens":455}}297{"id":"stack-8985643","source":"stackoverflow","questionId":8985643,"title":"Locks and batch fetch messages with RabbitMq","tags":["message-queue","rabbitmq","amqp"],"text":"Title: Locks and batch fetch messages with RabbitMq\nTags: message-queue, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI'm trying to use RabbitMq in a more unconventional way (though at this point i can pick any other message queue implementation if needed). Instead of leaving Rabbit push messages to my consumers, the consumer connects to a queue and fetches a batch of N messages (during which it consumes some and possible rejects some), after which it jumps to another queue and so on. This is done for redundancy. If some consumers crash all messages are guaranteed to be consumed by some other consumer.\n\nThe problem is that I have multiple consumers and I don't want them to compete over the same queue. Is there a way to guarantee a lock on a queue? If not, can I at least make sure that if 2 consumers are connected to the same queue they don't read the same message? Transactions might help me to some degree but I've heard talk that they'll get removed from RabbitMQ.\n\nOther architectural suggestions are welcomed too.\n\nThanks!\n\n**EDIT:**\nAs pointed in the comment there's an a particularity in how I need to process the messages. They only make sense taken in groups and there's a high probability that related messages are clumped together in a queue. If for example I pull a batch of 100 messages, there's a high probability that I'll be able to do something with messages 1-3, 4-5,6-10 etc. If I fail to find a group for some messages I'll resubmit them to the queue. WorkQueue wouldn't work because it would spread messages from the same group to multiple workers that wouldn't know what to do with them.\n\n========================================\n\nTop Answer:\nHave your consumers pull from just one queue. They will be guaranteed not to messages (Rabbit will round-robin the messages among the currently-connected consumers) and it's heavily optimized for that exact usage pattern.\n\nIt's ready-to-use, out of the box. In the RabbitMQ docs it's called the Work Queue model. One queue, multiple consumers, with none of them sharing anything. It sounds like what you need.\n\n========================================\n\nComments:\n- Obviously the consumers can sync among themselves using something like Gossip in case this is not possible, but I was curious...\n- Unfortunately no because of a particularity in how I need to process the messages. They only make sense taken in groups and there's a high probability that related messages are clumped together in a queue. If for example I pull a batch of 100 messages, there's a high probability that I'll be able to do something with messages 1-3, 4-5,6-10 etc. If I fail to find a group for some messages I'll resubmit them to the queue. WorkQueue wouldn't work because it would spread messages from the same group to multiple workers that wouldn't know what to do with them.\n- That's a pretty important requirement, and you should add it to the question too so that others see it above. Why don't you clump your messages together at the producer side, since it sounds like those groups are logically related and should be taken as an atomic unit rather than split up into lots of disparate messages? That would allow you to move easily between broker technologies, too, as I'm unaware of any broker that will give you what you need out of the box.\n- You're right. I pointed the requirement above. Regarding your question, I would love to be able to clump them at the producer side, but each message in a group might come in via different producers that live on different machines.\n- In the end I do realize that this is better suited for a relational database which would allow me to do the grouping and locking. The reason for which I was exploring the queues is because the messages live for a very short time (usually between the time when the message arrives in the queue and one worker consumes it is less than 1s) and there's a high traffic of messages involved. In a RDB this would work fine in the beginning until fragmentation would take its toll and kill performance.\n- This sound just like what I want. Thans!\n- You should consider using prefetch.count on the channel to pull messages in batches. rabbitmq.com/consumer-prefetch.html","metadata":{"transformedAt":"2026-08-18T18:33:20.145Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":33,"estimatedTokens":1052}}298{"id":"stack-29697703","source":"stackoverflow","questionId":29697703,"title":"RabbitMQ: In pub/sub is the consumer polling the queue for new messages or does the server push messages?","tags":["c#","queue","rabbitmq","message-queue"],"text":"Title: RabbitMQ: In pub/sub is the consumer polling the queue for new messages or does the server push messages?\nTags: c#, queue, rabbitmq, message-queue\nSource: Stack Overflow\n\nQuestion:\nI can't seems to find this information anywhere or maybe I am not understanding it. In the publish/subscribe pattern in RabbitMQ, when a producer produces a message how does the consumer(s) know there is a new message in the queue?\n\nDo the consumers constantly poll the queue to check whether there are any new messages or does the exchange 'push' notification to consumers saying there is a new message?\n\n========================================\n\nComments:\n- See also this answer which explains how *consuming* a message works: server pushes and client gets an async callback.","metadata":{"transformedAt":"2026-08-18T18:33:20.145Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":13,"estimatedTokens":192}}299{"id":"stack-58402670","source":"stackoverflow","questionId":58402670,"title":"TLS-Encrypted Connection with RabbitMQ Using pika","tags":["ssl","rabbitmq","pika"],"text":"Title: TLS-Encrypted Connection with RabbitMQ Using pika\nTags: ssl, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI am finding it impossible to set up an encrypted connection with a RabbitMQ broker using python's pika library on the client side. My starting point was the pika tutorial example here but I cannot make it work. I have proceeded as follows.\n\n(1) The **RabbitMQ configuration file** was:\n\n```\nlisteners.tcp.default = 5672\nlisteners.ssl.default = 5671\n\nssl_options.verify = verify_peer\nssl_options.fail_if_no_peer_cert = false\nssl_options.cacertfile = /etc/cert/tms.crt\nssl_options.certfile = /etc/cert/tms.crt\nssl_options.keyfile = /etc/cert/tmsPrivKey.pem\n\nauth_mechanisms.1 = PLAIN\nauth_mechanisms.2 = AMQPLAIN\nauth_mechanisms.3 = EXTERNAL\n```\n\n(2) The **`rabbitmq-auth-mechanism-ssl` plugin** was enabled with the following command:\n\n```\nrabbitmq-plugins enable rabbitmq_auth_mechanism_ssl\n```\n\nSuccessful enabling was confirmed by checking the enable status through: `rabbitmq-plugins list`.\n\n(3) The correctness of the **TLS certificates** was verified by using openssl tools as described here.\n\n(4) The **client-side program** to set up the connection was:\n\n```\n#!/usr/bin/env python\nimport logging\nimport pika\nimport ssl\nfrom pika.credentials import ExternalCredentials\n\nlogging.basicConfig(level=logging.INFO)\ncontext = ssl.create_default_context(\n cafile=\"/Xyz/sampleNodeCert/tms.crt\")\ncontext.load_cert_chain(\"/Xyz/sampleNodeCert/node.crt\",\n \"/Xyz/sampleNodeCert/nodePrivKey.pem\")\n\nssl_options = pika.SSLOptions(context, '127.0.0.1')\nconn_params = pika.ConnectionParameters(host='127.0.0.1',\n port=5671,\n ssl_options=ssl_options,\n credentials=ExternalCredentials())\n\nwith pika.BlockingConnection(conn_params) as conn:\n ch = conn.channel()\n ch.queue_declare(\"foobar\")\n ch.basic_publish(\"\", \"foobar\", \"Hello, world!\")\n print(ch.basic_get(\"foobar\"))\n```\n\n(5) The client-side program failed with the following **error message**:\n\n```\npika.exceptions.ProbableAuthenticationError: ConnectionClosedByBroker: (403) 'ACCESS_REFUSED - Login was refused using authentication mechanism EXTERNAL. For details see the broker logfile.'\n```\n\n(6) The **log message** in the RabbitMQ broker was:\n\n```\n2019-10-15 20:17:46.028 [info] accepting AMQP connection (127.0.0.1:48252 -> 127.0.0.1:5671)\n2019-10-15 20:17:46.032 [error] Error on AMQP connection (127.0.0.1:48252 -> 127.0.0.1:5671, state: starting):\nEXTERNAL login refused: user 'CN=www.node.com,O=Node GmbH,L=NodeTown,ST=NodeProvince,C=DE' - invalid credentials\n2019-10-15 20:17:46.043 [info] closing AMQP connection (127.0.0.1:48252 -> 127.0.0.1:5671)\n```\n\n(7) The **environment** in which this test was done is Ubuntu 18.04 using RabbitMQ 3.7.17 on Erlang 22.0.7. On the client side, python3 version 3.6.8 was used.\n\n**Questions**: Does anyone have any idea as to why my test fails? Where can I find a complete working example of setting up an encrypted connection to RabbitMQ using pika?\n\nNB: I am familiar with this post but none of the tips in the post helped me.\n\n========================================\n\nTop Answer:\nTo anyone trying to do this with pika the answer is really\n\nset host to the CN name of your client_certificate in the client_certificate.pem file\n\nit will look something like\n\n/CN=..local/O=client\n\nyou only need ..local if it is a self signed certificate\n\n========================================\n\nCode:\n```text\nlisteners.tcp.default = 5672\nlisteners.ssl.default = 5671\n\nssl_options.verify = verify_peer\nssl_options.fail_if_no_peer_cert = false\nssl_options.cacertfile = /etc/cert/tms.crt\nssl_options.certfile = /etc/cert/tms.crt\nssl_options.keyfile = /etc/cert/tmsPrivKey.pem\n\nauth_mechanisms.1 = PLAIN\nauth_mechanisms.2 = AMQPLAIN\nauth_mechanisms.3 = EXTERNAL\n```\n\n```text\nrabbitmq-plugins enable rabbitmq_auth_mechanism_ssl\n```\n\n```text\n#!/usr/bin/env python\nimport logging\nimport pika\nimport ssl\nfrom pika.credentials import ExternalCredentials\n\nlogging.basicConfig(level=logging.INFO)\ncontext = ssl.create_default_context(\n cafile=\"/Xyz/sampleNodeCert/tms.crt\")\ncontext.load_cert_chain(\"/Xyz/sampleNodeCert/node.crt\",\n \"/Xyz/sampleNodeCert/nodePrivKey.pem\")\n\nssl_options = pika.SSLOptions(context, '127.0.0.1')\nconn_params = pika.ConnectionParameters(host='127.0.0.1',\n port=5671,\n ssl_options=ssl_options,\n credentials=ExternalCredentials())\n\nwith pika.BlockingConnection(conn_params) as conn:\n ch = conn.channel()\n ch.queue_declare(\"foobar\")\n ch.basic_publish(\"\", \"foobar\", \"Hello, world!\")\n print(ch.basic_get(\"foobar\"))\n```\n\n```text\npika.exceptions.ProbableAuthenticationError: ConnectionClosedByBroker: (403) 'ACCESS_REFUSED - Login was refused using authentication mechanism EXTERNAL. For details see the broker logfile.'\n```\n\n```text\n2019-10-15 20:17:46.028 [info] <0.642.0> accepting AMQP connection <0.642.0> (127.0.0.1:48252 -> 127.0.0.1:5671)\n2019-10-15 20:17:46.032 [error] <0.642.0> Error on AMQP connection <0.642.0> (127.0.0.1:48252 -> 127.0.0.1:5671, state: starting):\nEXTERNAL login refused: user 'CN=www.node.com,O=Node GmbH,L=NodeTown,ST=NodeProvince,C=DE' - invalid credentials\n2019-10-15 20:17:46.043 [info] <0.642.0> closing AMQP connection <0.642.0> (127.0.0.1:48252 -> 127.0.0.1:5671)\n```\n\n```text\nrabbitmq-auth-mechanism-ssl\n```\n\n```text\nrabbitmq-plugins list\n```\n\n```text\nlisteners.tcp.default = 5672\nlisteners.ssl.default = 5671\n\nssl_cert_login_from = common_name\n\nssl_options.verify = verify_peer\nssl_options.fail_if_no_peer_cert = true\nssl_options.cacertfile = /etc/cert/tms.crt\nssl_options.certfile = /etc/cert/tms.crt\nssl_options.keyfile = /etc/cert/tmsPrivKey.pem\n\nauth_mechanisms.1 = EXTERNAL\nauth_mechanisms.2 = PLAIN\nauth_mechanisms.3 = AMQPLAIN\n```\n\n```text\nrabbitmq-plugins enable rabbitmq_auth_mechanism_ssl\n```\n\n```text\nap@pnp-vm2:openssl x509 -noout -text -in /etc/cert/node.crt | fgrep CN\n Issuer: C = CH, ST = CH, L = Location, O = Organization GmbH, CN = pnp-vm2\n Subject: C = DE, ST = NodeProvince, L = NodeTown, O = Node GmbH, CN = pnp-vm2\n```\n\n```text\n#!/usr/bin/env python\nimport logging\nimport pika\nimport ssl\nfrom pika.credentials import ExternalCredentials\n\nlogging.basicConfig(level=logging.INFO)\ncontext = ssl.create_default_context(cafile=\"/home/ap/RocheTe/cert/sampleNodeCert/tms.crt\")\ncontext.load_cert_chain(\"/home/ap/RocheTe/cert/sampleNodeCert/node.crt\",\n \"/home/ap/RocheTe/cert/sampleNodeCert/nodePrivKey.pem\")\n\nssl_options = pika.SSLOptions(context, 'pnp-vm2')\nconn_params = pika.ConnectionParameters(host='a.b.c.d',\n port=5671,\n ssl_options=ssl_options,\n credentials=ExternalCredentials(),\n heartbeat=0)\n\nwith pika.BlockingConnection(conn_params) as conn:\n ch = conn.channel()\n ch.queue_declare(\"foobar\")\n ch.basic_publish(\"\", \"foobar\", \"Hello, world!\")\n print(ch.basic_get(\"foobar\"))\n input(\"Press Enter to continue...\")\n```\n\n```text\nssl_cert_login_from\n```\n\n```text\nrabbitmq-plugins list\n```\n\n```text\n/var/log/rabbitmq\n```\n\n```text\nrabbit@pnp-vm2\n```\n\n```text\npnp-vm2\n```\n\n```text\nfrom pika.credentials import ExternalCredentials\n# (...)\nconn_params = pika.ConnectionParameters(host='localhost',\n port=5671,\n ssl_options=ssl_options,\n credentials = ExternalCredentials())\n \n# instead of\nconn_params = pika.ConnectionParametersport=5671,\n ssl_options=ssl_options)\n```\n\n```text\n# Enable AMQPS\nlisteners.ssl.default = 5671\nssl_options.cacertfile = PIKA_DIR/testdata/certs/ca_certificate.pem\nssl_options.certfile = PIKA_DIR/testdata/certs/server_certificate.pem\nssl_options.keyfile = PIKA_DIR/testdata/certs/server_key.pem\nssl_options.verify = verify_peer\nssl_options.fail_if_no_peer_cert = true\nssl_cert_login_from = common_name\nauth_mechanisms.1 = EXTERNAL\n\n# instead of\n# Enable AMQPS\nlisteners.ssl.default = 5671\nssl_options.cacertfile = PIKA_DIR/testdata/certs/ca_certificate.pem\nssl_options.certfile = PIKA_DIR/testdata/certs/server_certificate.pem\nssl_options.keyfile = PIKA_DIR/testdata/certs/server_key.pem\nssl_options.verify = verify_peer\nssl_options.fail_if_no_peer_cert = true\n```\n\n========================================\n\nComments:\n- Please ask on the `pika-python` mailing list and we can continue discussion there. I maintain Pika and I have set up client-certificate authentication so I know it works. Most likely the issue is in the order of `auth_mechanisms` (try putting `EXTERNAL` first) or how you created the `CN=www.node.com,O=Node GmbH,L=NodeTown,ST=NodeProvince,C=DE` user in RabbitMQ. I'm assuming you're using Pika `1.1.0`. See this message as well.\n- I think you should try to add something like **management** prefixed config `management.ssl.port = 15671` `management.ssl.cacertfile = /ssl/CA.cer` `management.ssl.certfile = /ssl/cert.cer` `management.ssl.fail_if_no_peer_cert = false` `management.ssl.keyfile = /ssl/cert.key` `management.ssl.verify = verify_none` `management.ssl.versions.1 = tlsv1.2`","metadata":{"transformedAt":"2026-08-18T18:33:20.145Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":18,"totalLines":276,"estimatedTokens":2372}}300{"id":"stack-25855331","source":"stackoverflow","questionId":25855331,"title":"Installing rabbitmq-server on RHEL","tags":["erlang","rabbitmq","redhat","rhel"],"text":"Title: Installing rabbitmq-server on RHEL\nTags: erlang, rabbitmq, redhat, rhel\nSource: Stack Overflow\n\nQuestion:\nWhen trying to install rabbitmq-server on RHEL:\n\n```\n[ec2-user@ip-172-31-34-1XX ~]$ sudo rpm -i rabbitmq-server-3.3.5-1.noarch.rpm \n error: Failed dependencies:\n erlang >= R13B-03 is needed by rabbitmq-server-3.3.5-1.noarch\n\n[ec2-user@ip-172-31-34-1XX ~]$ rpm -i rabbitmq-server-3.3.5-1.noarch.rpm \n error: Failed dependencies:\n erlang >= R13B-03 is needed by rabbitmq-server-3.3.5-1.noarch\n```\n\nI'm unsure why trying to rpm install isn't recognizing my erlang install since running `$ erl`gives:\n\n```\n[ec2-user@ip-172-31-34-1XX ~]$ which erl\n /usr/local/bin/erl\n[ec2-user@ip-172-31-34-1XX ~]$ sudo which erl\n /bin/erl\n```\n\n========================================\n\nTop Answer:\nYou need to install erlang via RPM for it to recognise the dependency.\n\nThe erlang RPMs are available in the EPEL repository:\n\nhttps://www.rabbitmq.com/install-rpm.html\n\n========================================\n\nCode:\n```text\n[ec2-user@ip-172-31-34-1XX ~]$ sudo rpm -i rabbitmq-server-3.3.5-1.noarch.rpm \n error: Failed dependencies:\n erlang >= R13B-03 is needed by rabbitmq-server-3.3.5-1.noarch\n\n[ec2-user@ip-172-31-34-1XX ~]$ rpm -i rabbitmq-server-3.3.5-1.noarch.rpm \n error: Failed dependencies:\n erlang >= R13B-03 is needed by rabbitmq-server-3.3.5-1.noarch\n```\n\n```text\n[ec2-user@ip-172-31-34-1XX ~]$ which erl\n /usr/local/bin/erl\n[ec2-user@ip-172-31-34-1XX ~]$ sudo which erl\n /bin/erl\n```\n\n```text\n$ erl\n```\n\n```text\nrpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc\n yum install rabbitmq-server-3.3.5-1.noarch.rpm\n```\n\n```text\nwget -O /etc/yum.repos.d/epel-erlang.repo http://repos.fedorapeople.org/repos/peter/erlang/epel-erlang.repo\n```\n\n```text\nyum install erlang\n```\n\n========================================\n\nComments:\n- Which version of Erlang do you have installed? You can find out by running: erl --version\n- Similar one.. but I do not have option for yum.. stackoverflow.com/questions/40157859/… help or suggestions much appreciated","metadata":{"transformedAt":"2026-08-18T18:33:20.145Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":77,"estimatedTokens":521}}301{"id":"stack-31038064","source":"stackoverflow","questionId":31038064,"title":"Rabbitmq - queues state shows as 'running' , GUI shows status as IDLE","tags":["python","rabbitmq"],"text":"Title: Rabbitmq - queues state shows as 'running' , GUI shows status as IDLE\nTags: python, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI was playing around the rabbitmq HTTP API and came across a weird scenario. When I look at my queues through the web interface, the status of both of them shows as IDLE. . \n\nHowever when I use the HTTP API, the return for both the queue shows as 'running'. The code im using is below:\n\n```\nimport requests\nimport json\n\nuri = 'http://localhost:15672/api/queues'\n\nr = requests.get(uri, auth=(\"guest\",\"guest\"))\n\nparsed = json.loads(r.content)\n#print json.dumps(parsed, indent=4)\nfor i in parsed:\n print '{:Output:\n\n```\ntest queue : running\ntest2 : running\n```\n\nCan someone explain this behaviour to me?\n\n========================================\n\nCode:\n```text\nimport requests\nimport json\n\nuri = 'http://localhost:15672/api/queues'\n\nr = requests.get(uri, auth=(\"guest\",\"guest\"))\n\nparsed = json.loads(r.content)\n#print json.dumps(parsed, indent=4)\nfor i in parsed:\n print '{:<20} : {}'.format(i.get('name'), i.get('state'))\n```\n\n```text\ntest queue : running\ntest2 : running\n```\n\n```text\nfunction fmt_object_state(obj) {\n if (obj.state == undefined) return '';\n\n var colour = 'green';\n var text = obj.state;\n var explanation;\n\n if (obj.idle_since !== undefined) {\n colour = 'grey';\n explanation = 'Idle since ' + obj.idle_since;\n text = 'idle';\n }\n```\n\n```text\n\"policy\":\"\",\n \"exclusive_consumer_tag\":\"\",\n \"consumers\":0,\n \"consumer_utilisation\":\"\",\n \"memory\":176456,\n \"recoverable_slaves\":\"\",\n \"state\":\"running\",\n```\n\n```text\n\"idle_since\":\"2015-06-25 10:15:07\",\n \"consumer_utilisation\":\"\",\n \"policy\":\"\",\n \"exclusive_consumer_tag\":\"\",\n \"consumers\":0,\n \"recoverable_slaves\":\"\",\n \"state\":\"running\",\n```\n\n```text\nidle_since\n```\n\n```text\n\"idle_since\"\n```\n\n```text\nrunning\n```\n\n========================================\n\nComments:\n- Perhaps poke around at the javascript and see what it is doing with the output from the api?\n- Yes I did the same thing. Just looked at the `json` for `idle_since`. If its there, then the queue is marked as `IDLE` , otherwise its `RUNNING`","metadata":{"transformedAt":"2026-08-18T18:33:20.145Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":103,"estimatedTokens":555}}302{"id":"stack-45803728","source":"stackoverflow","questionId":45803728,"title":"Celery upgrade (3.1->4.1) - Connection reset by peer","tags":["python","rabbitmq","celery","amqp","kombu"],"text":"Title: Celery upgrade (3.1->4.1) - Connection reset by peer\nTags: python, rabbitmq, celery, amqp, kombu\nSource: Stack Overflow\n\nQuestion:\nWe are working with celery at the last year, with ~15 workers, each one defined with concurrency between 1-4.\n\nRecently we upgraded our celery from v3.1 to v4.1\n\nNow we are having the following errors in each one of the workers logs, any ideas what can cause to such error?\n\n```\n2017-08-21 18:33:19,780 94794 ERROR Control command error: error(104, 'Connection reset by peer') [file: pidbox.py, line: 46]\nTraceback (most recent call last):\n File \"/srv/dy/venv/lib/python2.7/site-packages/celery/worker/pidbox.py\", line 42, in on_message\n self.node.handle_message(body, message)\n File \"/srv/dy/venv/lib/python2.7/site-packages/kombu/pidbox.py\", line 129, in handle_message\n return self.dispatch(**body)\n File \"/srv/dy/venv/lib/python2.7/site-packages/kombu/pidbox.py\", line 112, in dispatch\n ticket=ticket)\n File \"/srv/dy/venv/lib/python2.7/site-packages/kombu/pidbox.py\", line 135, in reply\n serializer=self.mailbox.serializer)\n File \"/srv/dy/venv/lib/python2.7/site-packages/kombu/pidbox.py\", line 265, in _publish_reply\n **opts\n File \"/srv/dy/venv/lib/python2.7/site-packages/kombu/messaging.py\", line 181, in publish\n exchange_name, declare,\n File \"/srv/dy/venv/lib/python2.7/site-packages/kombu/messaging.py\", line 203, in _publish\n mandatory=mandatory, immediate=immediate,\n File \"/srv/dy/venv/lib/python2.7/site-packages/amqp/channel.py\", line 1748, in _basic_publish\n (0, exchange, routing_key, mandatory, immediate), msg\n File \"/srv/dy/venv/lib/python2.7/site-packages/amqp/abstract_channel.py\", line 64, in send_method\n conn.frame_writer(1, self.channel_id, sig, args, content)\n File \"/srv/dy/venv/lib/python2.7/site-packages/amqp/method_framing.py\", line 178, in write_frame\n write(view[:offset])\n File \"/srv/dy/venv/lib/python2.7/site-packages/amqp/transport.py\", line 272, in write\n self._write(s)\n File \"/usr/lib64/python2.7/socket.py\", line 224, in meth\n return getattr(self._sock,name)(*args)\nerror: [Errno 104] Connection reset by peer\n```\n\nBTW: our tasks in the form:\n\n```\n@app.task(name='EXAMPLE_TASK'],\n bind=True,\n base=ConnectionHolderTask)\ndef example_task(self, arg1, arg2, **kwargs):\n # task code\n```\n\n========================================\n\nCode:\n```text\n2017-08-21 18:33:19,780 94794 ERROR Control command error: error(104, 'Connection reset by peer') [file: pidbox.py, line: 46]\nTraceback (most recent call last):\n File \"/srv/dy/venv/lib/python2.7/site-packages/celery/worker/pidbox.py\", line 42, in on_message\n self.node.handle_message(body, message)\n File \"/srv/dy/venv/lib/python2.7/site-packages/kombu/pidbox.py\", line 129, in handle_message\n return self.dispatch(**body)\n File \"/srv/dy/venv/lib/python2.7/site-packages/kombu/pidbox.py\", line 112, in dispatch\n ticket=ticket)\n File \"/srv/dy/venv/lib/python2.7/site-packages/kombu/pidbox.py\", line 135, in reply\n serializer=self.mailbox.serializer)\n File \"/srv/dy/venv/lib/python2.7/site-packages/kombu/pidbox.py\", line 265, in _publish_reply\n **opts\n File \"/srv/dy/venv/lib/python2.7/site-packages/kombu/messaging.py\", line 181, in publish\n exchange_name, declare,\n File \"/srv/dy/venv/lib/python2.7/site-packages/kombu/messaging.py\", line 203, in _publish\n mandatory=mandatory, immediate=immediate,\n File \"/srv/dy/venv/lib/python2.7/site-packages/amqp/channel.py\", line 1748, in _basic_publish\n (0, exchange, routing_key, mandatory, immediate), msg\n File \"/srv/dy/venv/lib/python2.7/site-packages/amqp/abstract_channel.py\", line 64, in send_method\n conn.frame_writer(1, self.channel_id, sig, args, content)\n File \"/srv/dy/venv/lib/python2.7/site-packages/amqp/method_framing.py\", line 178, in write_frame\n write(view[:offset])\n File \"/srv/dy/venv/lib/python2.7/site-packages/amqp/transport.py\", line 272, in write\n self._write(s)\n File \"/usr/lib64/python2.7/socket.py\", line 224, in meth\n return getattr(self._sock,name)(*args)\nerror: [Errno 104] Connection reset by peer\n```\n\n```text\n@app.task(name='EXAMPLE_TASK'],\n bind=True,\n base=ConnectionHolderTask)\ndef example_task(self, arg1, arg2, **kwargs):\n # task code\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.145Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":91,"estimatedTokens":1053}}303{"id":"stack-9216712","source":"stackoverflow","questionId":9216712,"title":"Rabbitmq message arrival time stamp","tags":["c#","rabbitmq","amqp"],"text":"Title: Rabbitmq message arrival time stamp\nTags: c#, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nIs there a way to get the timestamp when a message was placed on the queue, from a consumer.\nNot when it was published, but when it actually made it to the queue.\n\n========================================\n\nTop Answer:\nA duplicate question has a good answer https://stackoverflow.com/a/33640262/1689049:\n\n As of 2015, there are new answers for the original question.\n\n \n This plugin will do exactly what you were looking for.\n\n \n Take in mind there will be some minimal overhead since it will hook\n all messages being queued.\n\n========================================\n\nComments:\n- Unless I'm missing something, seems like, short of writing a rabbitmq plugin, there isn't :(\n- Possible duplicate of RabbitMQ 3.1.3 and the missing timestamp header\n- Even as you say that the message might pass through several queues all I want is the timestamp when the message is places on that queue only. so there is an obvious use case and need for the timestamp.\n- @Mani It doesn't seem obvious to me. Which application needs to know? The publisher, the consumer or something else?\n- If you look in the AMQP specification that Daniel has linked and look for \"unix\", you will find a timestamp. But what time for which action that is, that's another question\n- If you think it's a duplicate, vote to close instead of copying the answers (it's with attribution so I have no intention of mod-flagging or calling it plagiarism, but it's not good practice. Close the question if you think it's a dupe)\n- @Zoe you see, this question has been asked before the other one with a newer better answer. So technically the other question with a good answer is a duplicate. Do we still want to mark this one as a dupe?\n- If it's the same question, you could request to have them merged. Otherwise close the bad one as a duplicate","metadata":{"transformedAt":"2026-08-18T18:33:20.145Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":33,"estimatedTokens":476}}304{"id":"stack-8138642","source":"stackoverflow","questionId":8138642,"title":"Notify celery task of worker shutdown","tags":["python","rabbitmq","celery","django-celery"],"text":"Title: Notify celery task of worker shutdown\nTags: python, rabbitmq, celery, django-celery\nSource: Stack Overflow\n\nQuestion:\nI am using celery 2.4.1 with python 2.6, the rabbitmq backend, and django. I would like my task to be able to clean up properly if the worker shuts down. As far as I am aware you cannot supply a task destructor so I tried hooking into the worker_shutdown signal.\n\nNote: AbortableTask only works with the database backend so I cant use that.\n\n```\nfrom celery.signals import worker_shutdown\n\n@task\ndef mytask(*args)\n\n obj = DoStuff()\n\n def shutdown_hook(*args):\n print \"Worker shutting down\"\n # cleanup nicely\n obj.stop()\n\n worker_shutdown.connect(shutdown_hook)\n\n # blocking call that monitors a network connection\n obj.stuff()\n```\n\nHowever, the shutdown hook never gets called. Ctrl-C'ing the worker doesnt kill the task and I have to manually kill it from the shell. \n\nSo if this is not the proper way to go about it, how do I allow tasks to shutdown gracefully?\n\n========================================\n\nTop Answer:\nUse the worker_shutting_down signal.\nSee https://docs.celeryq.dev/en/stable/userguide/signals.html#worker-shutting-down and https://stackoverflow.com/a/55481656/237091 for an example.\n\n========================================\n\nCode:\n```text\nfrom celery.signals import worker_shutdown\n\n@task\ndef mytask(*args)\n\n obj = DoStuff()\n\n def shutdown_hook(*args):\n print \"Worker shutting down\"\n # cleanup nicely\n obj.stop()\n\n worker_shutdown.connect(shutdown_hook)\n\n # blocking call that monitors a network connection\n obj.stuff()\n```\n\n```text\nfrom celery import platforms\nfrom celery.signals import worker_process_init\n\ndef cleanup_after_tasks(signum, frame):\n # reentrant code here (see http://docs.python.org/library/signal.html)\n\ndef install_pool_process_sighandlers(**kwargs):\n platforms.signals[\"TERM\"] = cleanup_after_tasks\n platforms.signals[\"INT\"] = cleanup_after_tasks\n\nworker_process_init.connect(install_pool_process_sighandlers)\n```\n\n```text\nworker_shutdown\n```\n\n```text\nMainProcess\n```\n\n```text\nworker_*\n```\n\n```text\nexcept for worker_process_init\n```\n\n```text\nMainProcess\n```\n\n```text\n--soft-time-limit\n```\n\n```text\n--time-limit\n```\n\n========================================\n\nComments:\n- @RomanPodlinov - look at the Celery docs for `revoke()` - you can optionally send a signal which the worker can catch in order to clean up.\n- I don't get it. Is there any signal being emitted after `--soft-time-limit` is over? If so, which one?\n- Note that this is ancient, and more recent versions of celery can use signals for this. See docs.celeryq.dev/en/stable/userguide/… and stackoverflow.com/a/55481656/237091.","metadata":{"transformedAt":"2026-08-18T18:33:20.145Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":108,"estimatedTokens":673}}305{"id":"stack-7168055","source":"stackoverflow","questionId":7168055,"title":"Binding external IP address to Rabbit MQ server","tags":["ip","rabbitmq"],"text":"Title: Binding external IP address to Rabbit MQ server\nTags: ip, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have box A and it has a consumer on it that listens on a Rabbit MQ server\n\nI have box B that will publish a message to the listener\n\nSo as long as all of this in on box A and I start Rabbit MQ server w/ defaults it works fine.\n\nThe defaults are host=127.0.0.1 on port 5672, but\nwhen I `telnet box.a.ip.addy 5672` from box B I get:\n\n```\nTrying box.a.ip.addy...\ntelnet: connect to address box.a.ip.addy: No route to host\ntelnet: Unable to connect to remote host: No route to host\n```\n\ntelnet on port 22 is fine, I can ssh into Box A from Box B\n\nSo I assume I need to change the ip that the RabbitMQ server uses \nI found this: http://www.rabbitmq.com/configure.html and I now have a config file in the location the documentation said to use, with the name rabbitmq.config and it contains:\n\n```\n[\n {rabbit, [{tcp_listeners, {\"box.a.ip.addy\", 5672}}]}\n].\n```\n\nSo I stopped the server, and started RabbitMQ server again. It failed. Here are the errors from the error logs. It's a little over my head. (in fact most of this is)\n\n```\n=ERROR REPORT==== 23-Aug-2011::14:49:36 ===\nFAILED\nReason: {{case_clause,{{\"box.a.ip.addy\",5672}}},\n [{rabbit_networking,'-boot_tcp/0-lc$^0/1-0-',1},\n {rabbit_networking,boot_tcp,0},\n {rabbit_networking,boot,0},\n {rabbit,'-run_boot_step/1-lc$^1/1-1-',1},\n {rabbit,run_boot_step,1},\n {rabbit,'-start/2-lc$^0/1-0-',1},\n {rabbit,start,2},\n {application_master,start_it_old,4}]}\n\n=INFO REPORT==== 23-Aug-2011::14:49:37 ===\n application: rabbit\n exited: {bad_return,{{rabbit,start,[normal,[]]},\n {'EXIT',{rabbit,failure_during_boot}}}}\n type: permanent\n```\n\nand here is some more from the start up log:\n\n```\nErlang has closed\nError: {node_start_failed,normal}\n^M\nCrash dump was written to: erl_crash.dump^M\nKernel pid terminated (application_controller) ({application_start_failure,rabbit,{bad_return,{{rabbit,start,[normal,[]]},{'EXIT',{rabbit,failure_during_boot}}}}})^M\n```\n\nPlease help\n\n========================================\n\nTop Answer:\n**You need to open up the tcp port on your firewall**\n\nUsing Linux, Find the iptables config file:\n\n```\neric@dev ~$ find / -name \"iptables\" 2>/dev/null\n/etc/sysconfig/iptables\n```\n\nEdit the file:\n\n```\nsudo vi /etc/sysconfig/iptables\n```\n\nFix the file by adding a port:\n\n```\n# Generated by iptables-save v1.4.7 on Thu Jan 16 16:43:13 2014\n*filter\n-A INPUT -p tcp -m tcp --dport 15672 -j ACCEPT\nCOMMIT\n```\n\n========================================\n\nCode:\n```text\nTrying box.a.ip.addy...\ntelnet: connect to address box.a.ip.addy: No route to host\ntelnet: Unable to connect to remote host: No route to host\n```\n\n```text\n[\n {rabbit, [{tcp_listeners, {\"box.a.ip.addy\", 5672}}]}\n].\n```\n\n```text\n=ERROR REPORT==== 23-Aug-2011::14:49:36 ===\nFAILED\nReason: {{case_clause,{{\"box.a.ip.addy\",5672}}},\n [{rabbit_networking,'-boot_tcp/0-lc$^0/1-0-',1},\n {rabbit_networking,boot_tcp,0},\n {rabbit_networking,boot,0},\n {rabbit,'-run_boot_step/1-lc$^1/1-1-',1},\n {rabbit,run_boot_step,1},\n {rabbit,'-start/2-lc$^0/1-0-',1},\n {rabbit,start,2},\n {application_master,start_it_old,4}]}\n\n=INFO REPORT==== 23-Aug-2011::14:49:37 ===\n application: rabbit\n exited: {bad_return,{{rabbit,start,[normal,[]]},\n {'EXIT',{rabbit,failure_during_boot}}}}\n type: permanent\n```\n\n```text\nErlang has closed\nError: {node_start_failed,normal}\n^M\nCrash dump was written to: erl_crash.dump^M\nKernel pid terminated (application_controller) ({application_start_failure,rabbit,{bad_return,{{rabbit,start,[normal,[]]},{'EXIT',{rabbit,failure_during_boot}}}}})^M\n```\n\n```text\ntelnet box.a.ip.addy 5672\n```\n\n```text\neric@dev ~$ find / -name \"iptables\" 2>/dev/null\n/etc/sysconfig/iptables\n```\n\n```text\nsudo vi /etc/sysconfig/iptables\n```\n\n```text\n# Generated by iptables-save v1.4.7 on Thu Jan 16 16:43:13 2014\n*filter\n-A INPUT -p tcp -m tcp --dport 15672 -j ACCEPT\nCOMMIT\n```\n\n========================================\n\nComments:\n- Just to cover the obvious: Do you use `box.a.ip.addy` when you successfully ssh from box B?\n- smh no, I did not want to disclose my ip address\n- It was a firewall related issue, iptables was only letting in port 22, thank you :D\n- or you can change management config [{rabbitmq_management, [{listener, [{port, 15672}, {ip, \"127.0.0.1\"} ]} ]} ].","metadata":{"transformedAt":"2026-08-18T18:33:20.145Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":162,"estimatedTokens":1103}}306{"id":"stack-20530591","source":"stackoverflow","questionId":20530591,"title":"Message Groups in RabbitMQ / AMQP","tags":["rabbitmq","messaging","amqp"],"text":"Title: Message Groups in RabbitMQ / AMQP\nTags: rabbitmq, messaging, amqp\nSource: Stack Overflow\n\nQuestion:\nActiveMQ / JMS has a built in-mechanism for ensuring that messages that a common header (namely, the JMSXGroupID header) are always consumed by the same consumer of a queue when using a competing consumers pattern. The consumers of a queue are completely agnostic of the actual header values, as the guarantee of messages with a common header is performed server-side and not consumer-side. For more details on how this works, see http://activemq.apache.org/message-groups.html . \n\nIs doing such a thing possible with AMQP or with something RabbitMQ specific?\n\n========================================\n\nComments:\n- There is a GitHub issue about this: github.com/rabbitmq/rabbitmq-server/issues/262\n- Edited answer to include that link. Thanks @Merwan !","metadata":{"transformedAt":"2026-08-18T18:33:20.145Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":14,"estimatedTokens":215}}307{"id":"stack-47979831","source":"stackoverflow","questionId":47979831,"title":"How to use priority in celery task.apply_async","tags":["python","rabbitmq","queue","celery","priority-queue"],"text":"Title: How to use priority in celery task.apply_async\nTags: python, rabbitmq, queue, celery, priority-queue\nSource: Stack Overflow\n\nQuestion:\nI have a `test` queue in celery and I have defined a task for it:\n\n```\n@celery_app.task(queue='test', ignore_result=True)\ndef priority_test(priority):\n print(priority)\n```\n\nwhich just print the argument.I want to set the `priority` attribute which is defined here for `appy_async`. So, I wrote a `for loop` like this:\n\n```\nfor i in range(100):\n priority_test.apply_async((i%10,), queue=\"test\", priority=i%10)\n```\n\nI excpected to see some result like this:\n\n```\n[2017-12-26 17:21:37,309: WARNING/ForkPoolWorker-1] 10\n[2017-12-26 17:21:37,311: WARNING/ForkPoolWorker-1] 10\n[2017-12-26 17:21:37,314: WARNING/ForkPoolWorker-1] 10\n[2017-12-26 17:21:37,317: WARNING/ForkPoolWorker-1] 9\n[2017-12-26 17:21:37,319: WARNING/ForkPoolWorker-1] 9\n[2017-12-26 17:21:37,321: WARNING/ForkPoolWorker-1] 9\n[2017-12-26 17:21:37,323: WARNING/ForkPoolWorker-1] 8\n[2017-12-26 17:21:37,326: WARNING/ForkPoolWorker-1] 8\n[2017-12-26 17:21:37,329: WARNING/ForkPoolWorker-1] 8\n[2017-12-26 17:21:37,332: WARNING/ForkPoolWorker-1] 7\n[2017-12-26 17:21:37,334: WARNING/ForkPoolWorker-1] 7\n[2017-12-26 17:21:37,336: WARNING/ForkPoolWorker-1] 7\n[2017-12-26 17:21:37,341: WARNING/ForkPoolWorker-1] 6\n[2017-12-26 17:21:37,344: WARNING/ForkPoolWorker-1] 6\n[2017-12-26 17:21:37,346: WARNING/ForkPoolWorker-1] 6\n[2017-12-26 17:21:37,349: WARNING/ForkPoolWorker-1] 5\n[2017-12-26 17:21:37,351: WARNING/ForkPoolWorker-1] 5\n[2017-12-26 17:21:37,353: WARNING/ForkPoolWorker-1] 5\n[2017-12-26 17:21:37,355: WARNING/ForkPoolWorker-1] 4\n[2017-12-26 17:21:37,358: WARNING/ForkPoolWorker-1] 4\n[2017-12-26 17:21:37,360: WARNING/ForkPoolWorker-1] 4\n```\n\nmeans execute the same priorities after each other but it executed them in the normal way:\n\n```\n[2017-12-26 17:21:37,309: WARNING/ForkPoolWorker-1] 10\n[2017-12-26 17:21:37,311: WARNING/ForkPoolWorker-1] 9\n[2017-12-26 17:21:37,314: WARNING/ForkPoolWorker-1] 8\n[2017-12-26 17:21:37,317: WARNING/ForkPoolWorker-1] 7\n[2017-12-26 17:21:37,319: WARNING/ForkPoolWorker-1] 6\n[2017-12-26 17:21:37,321: WARNING/ForkPoolWorker-1] 5\n[2017-12-26 17:21:37,323: WARNING/ForkPoolWorker-1] 4\n[2017-12-26 17:21:37,326: WARNING/ForkPoolWorker-1] 3\n[2017-12-26 17:21:37,329: WARNING/ForkPoolWorker-1] 2\n[2017-12-26 17:21:37,332: WARNING/ForkPoolWorker-1] 1\n[2017-12-26 17:21:37,334: WARNING/ForkPoolWorker-1] 10\n[2017-12-26 17:21:37,336: WARNING/ForkPoolWorker-1] 9\n[2017-12-26 17:21:37,341: WARNING/ForkPoolWorker-1] 8\n[2017-12-26 17:21:37,344: WARNING/ForkPoolWorker-1] 7\n[2017-12-26 17:21:37,346: WARNING/ForkPoolWorker-1] 6\n[2017-12-26 17:21:37,349: WARNING/ForkPoolWorker-1] 5\n[2017-12-26 17:21:37,351: WARNING/ForkPoolWorker-1] 4\n[2017-12-26 17:21:37,353: WARNING/ForkPoolWorker-1] 3\n[2017-12-26 17:21:37,355: WARNING/ForkPoolWorker-1] 2\n[2017-12-26 17:21:37,358: WARNING/ForkPoolWorker-1] 1\n[2017-12-26 17:21:37,360: WARNING/ForkPoolWorker-1] 10\n[2017-12-26 17:21:37,362: WARNING/ForkPoolWorker-1] 9\n[2017-12-26 17:21:37,364: WARNING/ForkPoolWorker-1] 8\n[2017-12-26 17:21:37,365: WARNING/ForkPoolWorker-1] 7\n[2017-12-26 17:21:37,367: WARNING/ForkPoolWorker-1] 6\n[2017-12-26 17:21:37,369: WARNING/ForkPoolWorker-1] 5\n[2017-12-26 17:21:37,371: WARNING/ForkPoolWorker-1] 4\n[2017-12-26 17:21:37,373: WARNING/ForkPoolWorker-1] 3\n[2017-12-26 17:21:37,374: WARNING/ForkPoolWorker-1] 2\n[2017-12-26 17:21:37,376: WARNING/ForkPoolWorker-1] 1\n```\n\nHow should I apply `priority` in celery with rabbitmq and what is the `priority` attribute in the doc above?\n\n========================================\n\nCode:\n```text\n@celery_app.task(queue='test', ignore_result=True)\ndef priority_test(priority):\n print(priority)\n```\n\n```text\nfor i in range(100):\n priority_test.apply_async((i%10,), queue=\"test\", priority=i%10)\n```\n\n```text\n[2017-12-26 17:21:37,309: WARNING/ForkPoolWorker-1] 10\n[2017-12-26 17:21:37,311: WARNING/ForkPoolWorker-1] 10\n[2017-12-26 17:21:37,314: WARNING/ForkPoolWorker-1] 10\n[2017-12-26 17:21:37,317: WARNING/ForkPoolWorker-1] 9\n[2017-12-26 17:21:37,319: WARNING/ForkPoolWorker-1] 9\n[2017-12-26 17:21:37,321: WARNING/ForkPoolWorker-1] 9\n[2017-12-26 17:21:37,323: WARNING/ForkPoolWorker-1] 8\n[2017-12-26 17:21:37,326: WARNING/ForkPoolWorker-1] 8\n[2017-12-26 17:21:37,329: WARNING/ForkPoolWorker-1] 8\n[2017-12-26 17:21:37,332: WARNING/ForkPoolWorker-1] 7\n[2017-12-26 17:21:37,334: WARNING/ForkPoolWorker-1] 7\n[2017-12-26 17:21:37,336: WARNING/ForkPoolWorker-1] 7\n[2017-12-26 17:21:37,341: WARNING/ForkPoolWorker-1] 6\n[2017-12-26 17:21:37,344: WARNING/ForkPoolWorker-1] 6\n[2017-12-26 17:21:37,346: WARNING/ForkPoolWorker-1] 6\n[2017-12-26 17:21:37,349: WARNING/ForkPoolWorker-1] 5\n[2017-12-26 17:21:37,351: WARNING/ForkPoolWorker-1] 5\n[2017-12-26 17:21:37,353: WARNING/ForkPoolWorker-1] 5\n[2017-12-26 17:21:37,355: WARNING/ForkPoolWorker-1] 4\n[2017-12-26 17:21:37,358: WARNING/ForkPoolWorker-1] 4\n[2017-12-26 17:21:37,360: WARNING/ForkPoolWorker-1] 4\n```\n\n```text\n[2017-12-26 17:21:37,309: WARNING/ForkPoolWorker-1] 10\n[2017-12-26 17:21:37,311: WARNING/ForkPoolWorker-1] 9\n[2017-12-26 17:21:37,314: WARNING/ForkPoolWorker-1] 8\n[2017-12-26 17:21:37,317: WARNING/ForkPoolWorker-1] 7\n[2017-12-26 17:21:37,319: WARNING/ForkPoolWorker-1] 6\n[2017-12-26 17:21:37,321: WARNING/ForkPoolWorker-1] 5\n[2017-12-26 17:21:37,323: WARNING/ForkPoolWorker-1] 4\n[2017-12-26 17:21:37,326: WARNING/ForkPoolWorker-1] 3\n[2017-12-26 17:21:37,329: WARNING/ForkPoolWorker-1] 2\n[2017-12-26 17:21:37,332: WARNING/ForkPoolWorker-1] 1\n[2017-12-26 17:21:37,334: WARNING/ForkPoolWorker-1] 10\n[2017-12-26 17:21:37,336: WARNING/ForkPoolWorker-1] 9\n[2017-12-26 17:21:37,341: WARNING/ForkPoolWorker-1] 8\n[2017-12-26 17:21:37,344: WARNING/ForkPoolWorker-1] 7\n[2017-12-26 17:21:37,346: WARNING/ForkPoolWorker-1] 6\n[2017-12-26 17:21:37,349: WARNING/ForkPoolWorker-1] 5\n[2017-12-26 17:21:37,351: WARNING/ForkPoolWorker-1] 4\n[2017-12-26 17:21:37,353: WARNING/ForkPoolWorker-1] 3\n[2017-12-26 17:21:37,355: WARNING/ForkPoolWorker-1] 2\n[2017-12-26 17:21:37,358: WARNING/ForkPoolWorker-1] 1\n[2017-12-26 17:21:37,360: WARNING/ForkPoolWorker-1] 10\n[2017-12-26 17:21:37,362: WARNING/ForkPoolWorker-1] 9\n[2017-12-26 17:21:37,364: WARNING/ForkPoolWorker-1] 8\n[2017-12-26 17:21:37,365: WARNING/ForkPoolWorker-1] 7\n[2017-12-26 17:21:37,367: WARNING/ForkPoolWorker-1] 6\n[2017-12-26 17:21:37,369: WARNING/ForkPoolWorker-1] 5\n[2017-12-26 17:21:37,371: WARNING/ForkPoolWorker-1] 4\n[2017-12-26 17:21:37,373: WARNING/ForkPoolWorker-1] 3\n[2017-12-26 17:21:37,374: WARNING/ForkPoolWorker-1] 2\n[2017-12-26 17:21:37,376: WARNING/ForkPoolWorker-1] 1\n```\n\n```text\ntest\n```\n\n```text\npriority\n```\n\n```text\nappy_async\n```\n\n```text\nfor loop\n```\n\n```text\npriority\n```\n\n```text\npriority\n```\n\n```text\nfrom kombu import Exchange, Queue\n\napp.conf.task_queues = [\n Queue('tasks', Exchange('tasks'), routing_key='tasks',\n queue_arguments={'x-max-priority': 10},\n]\n```\n\n```text\napp.conf.task_queue_max_priority = 10\n```\n\n```text\nCELERY_ACKS_LATE = True\nCELERYD_PREFETCH_MULTIPLIER = 1\n```\n\n```text\npriority\n```\n\n```text\nx-max-priority\n```\n\n```text\ntask_queue_max_priority\n```\n\n```text\nCELERY_ACKS_LATE\n```\n\n========================================\n\nComments:\n- I rejected the suggested edit that wanted to replace `task_queue_max_priority` with `task_default_priority`. The latter is to configure the default priority for every task, which is not asked in the question nor needed for task priorities to work. It is however a setting that can be used in addition to the other tasks if you do not wish to supply a priority for all tasks.\n- CELERY_ACKS_LATE has many potential (and undesireable) side effects depending on your use case. In the case of Redis (which supports a similar priority approach), late acks are not needed to make priority work properly. The important part of this advice is prefetch_multiplier to prevent prefetching by default, and avoid ETA/countdown to also avoid prefetching behaviour.","metadata":{"transformedAt":"2026-08-18T18:33:20.146Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":17,"totalLines":217,"estimatedTokens":1996}}308{"id":"stack-35795308","source":"stackoverflow","questionId":35795308,"title":"Reproduce RabbitMQ network partition scenario","tags":["rabbitmq","rabbitmqctl"],"text":"Title: Reproduce RabbitMQ network partition scenario\nTags: rabbitmq, rabbitmqctl\nSource: Stack Overflow\n\nQuestion:\nI would like to reproduce the **network partition scenario** with all the three modes - `ignore`, `autoheal` and `pause_minority`. \nHow can I achieve this? I tried stopping(/sbin/service reboot) one of the nodes of the cluster but this didn't cause any network partitioning. I also tried deleting the mnesia on one node to create inconsistent mnesia across the cluster but that also didn't help.\n\n========================================\n\nTop Answer:\nIf you are using a docker, disconnecting the connected network will activate the partitioning.\n\n```\ndocker network disconnect network_name rabbitmq_container_name\n```\n\n========================================\n\nCode:\n```text\nignore\n```\n\n```text\nautoheal\n```\n\n```text\npause_minority\n```\n\n```text\nnode1 - ip : 10.10.0.1\nnode2 - ip : 10.10.0.2\nnode3 - ip : 10.10.0.3\n```\n\n```text\niptables -A OUTPUT -d 10.10.0.1 -j DROP\n```\n\n```text\niptables -F\n```\n\n```text\niptables\n```\n\n```text\nsudo iptables -A INPUT -s 10.10.0.1 -j DROP\n```\n\n```text\nsudo iptables -D INPUT -s 10.10.0.1 -j DROP\n```\n\n```text\niptables --list\n```\n\n```text\nsudo iptables -I INPUT 1 -p tcp --dport 25672 -j DROP\nsudo iptables -I OUTPUT 1 -p tcp --dport 25672 -j DROP\n```\n\n```text\nsudo iptables -D INPUT -p tcp --dport 25672 -j DROP\nsudo iptables -D OUTPUT -p tcp --dport 25672 -j DROP\n```\n\n```text\nsudo rabbitmqctl cluster_status\n```\n\n```text\n{partitions,[{'rabbit@ip-163-10-1-10',['rabbit@ip-163-10-0-15']}]}\n```\n\n```text\n25672\n```\n\n```text\npartitions\n```\n\n```text\ndocker network disconnect network_name rabbitmq_container_name\n```\n\n========================================\n\nComments:\n- How to simulate locally would be helpful too\n- this doesn't work when trying to simulate network partition in rabbitmq cluster of docker swarm service of 3 replicas\n- It doesn't work for me. I have a 7 nodes cluster, if I do this in 3 nodes, the cluster works fine, without any signal of partition detected when I use `rabbitmqctl cluster_status`, but if I disconnect 4 nodes, the entire cluster stop working.","metadata":{"transformedAt":"2026-08-18T18:33:20.146Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":17,"totalLines":98,"estimatedTokens":531}}309{"id":"stack-26990438","source":"stackoverflow","questionId":26990438,"title":"How to set per-message expiration (TTL) in Celery?","tags":["rabbitmq","celery","dead-letter"],"text":"Title: How to set per-message expiration (TTL) in Celery?\nTags: rabbitmq, celery, dead-letter\nSource: Stack Overflow\n\nQuestion:\nIt is possible to publish messages into a RabbitMQ queue with an expiration TTL: such messages will expire once the TTL is done and (if a dead-letter queue is setup,) removed to the dead-letter queue.\n\nBut is it possible to specify such per-message TTL using Celery?\n\nNote that I'm not looking for a way to specify task-expiration but rather message expiration: I want my messages to spend (a configurable) amount of time in the queue before finally getting picked up @ the dead-letter queue.\n\nTIA.\n\n========================================\n\nCode:\n```text\nmy_awesome_task.apply_async(args=(11,), expiration=42)\n```\n\n```text\nexpiration\n```\n\n```text\nexpires\n```\n\n```text\nexpiration != expires\n```\n\n```text\nsend_task\n```\n\n```text\ncelery.app.base.Celery.send_task\n```\n\n```text\napply_async\n```\n\n```text\n**options\n```\n\n```text\n**options\n```\n\n```text\ncelery.app.amqp.Queues->send_task_message( ... )\n```\n\n```text\n**kwargs\n```\n\n========================================\n\nComments:\n- Celery 5.2.0rc1 introduced a new feature that sets the RabbitMQ \"expiration\" property based on the Celery \"expires\" parameter. Snippet: `options[\"expiration\"] = expires_s`","metadata":{"transformedAt":"2026-08-18T18:33:20.146Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":11,"totalLines":64,"estimatedTokens":319}}310{"id":"stack-2596208","source":"stackoverflow","questionId":2596208,"title":"Does RabbitMq do round-robin from the exchange to the queues","tags":["message-queue","messaging","rabbitmq"],"text":"Title: Does RabbitMq do round-robin from the exchange to the queues\nTags: message-queue, messaging, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am currently evaluating message queue systems and RabbitMq seems like a good candidate, so I'm digging a little more into it.\n\nTo give a little context I'm looking to have something like one exchange load balancing the message publishing to multiple queues. I don't want to replicate the messages, so a fanout exchange is not an option. \n\nAlso the reason I'm thinking of having multiple queues vs one queue handling the round-robin w/ the consumers, is that I don't want our single point of failure to be at the queue level. \n\nSounds like I could add some logic on the publisher side to simulate that behavior by editing the routing key and having the appropriate bindings in place. But that's kind of a passive approach that wouldn't take the pace of the message consumption on each queue into account, potentially leading to fill up one queue if the consumer applications for that queue are dead. \n\nI was looking for a more pro-active way from the exchange entity side, that would decide where to send the next message based on each queue size or something of that nature.\n\nI read about Alice and the available RESTful APIs but that seems kind of a heavy duty solution to implement fast routing decisions. \n\nAnyone knows if round-robin between the exchange the queues is feasible w/ RabbitMQ then? Thanks.\n\n========================================\n\nTop Answer:\nOne built in way you can do a form of sharing a form exchange to queues, but not exactly round robin, is Consistent Hashing. `rabbitmq_consistent_hash_exchange`\n\nHow too\nhttps://medium.com/@eranda/rabbitmq-x-consistent-hashing-with-wso2-esb-27479b8d1d21\n\nPaper to explain, it puts queues at a weighted distribution on a circle and then by sending random routing key it will send to the closest queue.\nhttp://www8.org/w8-papers/2a-webserver/caching/paper2.html\n\n========================================\n\nCode:\n```text\nrabbitmq_consistent_hash_exchange\n```\n\n========================================\n\nComments:\n- As soon as we tested a single queue in production we slammed into a scale problem. A single queue is single threaded. It can't keep up with our load. We're looking for best practices to work in a round robin distribution\n- Thanks for the help. That's a good work around for now as I'm only at the evaluating stage.","metadata":{"transformedAt":"2026-08-18T18:33:20.146Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":42,"estimatedTokens":608}}311{"id":"stack-44271613","source":"stackoverflow","questionId":44271613,"title":"RabbitMQ vs Web API + SignalR","tags":["asp.net-web-api","rabbitmq","signalr","easynetq"],"text":"Title: RabbitMQ vs Web API + SignalR\nTags: asp.net-web-api, rabbitmq, signalr, easynetq\nSource: Stack Overflow\n\nQuestion:\nI'm currently using RabbitMQ via EasyNetQ to communicate between a Windows service and numerous clients. The communications are a mix of requests from the clients and push notifications to all of the clients. I'm very happy with the performance, scalability, and security of the current solution, but I want to ensure I'm not missing out on something in the latest technologies. What advantages, if any, does Web API + SignalR have for this scenario?\n\nFrom what I can tell at this point, SignalR has the potential to be much more performant when web sockets are available, but is slightly more complex from the start and will become significantly more complex if we need to scale out because of the need for a backplane.\n\nAny other insights anyone could ?\n\n========================================\n\nComments:\n- not 100% sure what your question is, but I use RabbitMQ+EasyNetQ as a backplane replacement for SignalR (no need for a separate backplane then), and it works fine!\n- Thanks Wiebe. I'm probably missing the obvious, but can you help me understand why you're using SignalR at all? Why not just use RabbitMQ and it's clients for the communications? I'm not dismissing SignalR, but I just haven't been able to find the right info to compare and contrast the technologies yet.\n- To be honest, I haven't tried connecting (different) clients/browsers directly to RabbitMQ (for security reasons). Are you using STOMP now? But for me having Web API and SignalR in between means full control, able to add abstractions and custom security on top of RMQ. This question is a bit too broad for SO, please feel free to continue this discussion in the EasyNetQ group groups.google.com/forum/#!topic/easynetq/\n- The security aspect makes sense. I'm working through a Web API/SignalR prototype now, but will likely take you up on your offer for further discussion after I've educated myself a bit more. Thanks again.\n- As far as I understand it, the biggest advantage of SignalR is that it enables you to call JavaScript functions directly from .NET server side code. RabbitMQ is really good at server to server messaging, but there isn't really a good way for it to directly affect a change in client code, i.e. a Web page for example. For that you would need some type of push server notification solution, such as SignalR. What I do in my application is I use a combination of RabbitMQ and SignalR. I use each one for what it does best, i.e. RabbitMQ for server to server and SignalR for server to client messaging.","metadata":{"transformedAt":"2026-08-18T18:33:20.146Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":19,"estimatedTokens":658}}312{"id":"stack-47308645","source":"stackoverflow","questionId":47308645,"title":"How to send message in rabbitmq on docker?","tags":["c#","docker","rabbitmq"],"text":"Title: How to send message in rabbitmq on docker?\nTags: c#, docker, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nAgain, it supposed to be simple, but wasn't able to find any documentation about it\n\nIn my previous question I had a problems with running rabbitmq container in docker. It has been solved, but now another one appeared\n\nContainer was created with this line\n\n```\ndocker run -d --hostname my-rabbit --name some-rabbit -p 15672:15672 rabbitmq:3-management\n```\n\nI was trying to create a simple console application to check how message sending is working (from base tutorial):\n\n```\nvar factory = new ConnectionFactory()\n{\n HostName = \"localhost\",\n Port = 15672\n};\n\nusing (var connection = factory.CreateConnection())\n{\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(\"Test\", false, false, false, null);\n\n var mess = new RepMessage()\n {\n ConnectionString = \"TestingString\",\n QueueID = 5\n };\n\n var jsonified = JsonConvert.SerializeObject(mess);\n var messBody = Encoding.UTF8.GetBytes(jsonified);\n channel.BasicPublish(\"\", \"Test\", null, messBody);\n\n Console.WriteLine(string.Format(\"Message with ConStr={0}, QueueID={1} has been send\", mess.ConnectionString, mess.QueueID));\n }\n}\n```\n\nAnd result is, its not working.\nI am receiving exception `None of the specified endpoints were reachable` and inner exception as `connection.start was never received, likely due to a network timeout`\n\nIf I remove port, then my inner exception transforms in `No connection could be made because the target machine actively refused it 127.0.0.1:5672`\n\nWhat am I missing, is is this example not supposed to work with docker?\n\n========================================\n\nTop Answer:\nIn your particular case docker command would look like this\n\n docker run -d --hostname my-rabbit --name some-rabbit -p 15672:15672 -p 5672:5672 rabbitmq:3-management\n\n========================================\n\nCode:\n```text\ndocker run -d --hostname my-rabbit --name some-rabbit -p 15672:15672 rabbitmq:3-management\n```\n\n```text\nvar factory = new ConnectionFactory()\n{\n HostName = \"localhost\",\n Port = 15672\n};\n\nusing (var connection = factory.CreateConnection())\n{\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(\"Test\", false, false, false, null);\n\n var mess = new RepMessage()\n {\n ConnectionString = \"TestingString\",\n QueueID = 5\n };\n\n var jsonified = JsonConvert.SerializeObject(mess);\n var messBody = Encoding.UTF8.GetBytes(jsonified);\n channel.BasicPublish(\"\", \"Test\", null, messBody);\n\n Console.WriteLine(string.Format(\"Message with ConStr={0}, QueueID={1} has been send\", mess.ConnectionString, mess.QueueID));\n }\n}\n```\n\n```text\nNone of the specified endpoints were reachable\n```\n\n```text\nconnection.start was never received, likely due to a network timeout\n```\n\n```text\nNo connection could be made because the target machine actively refused it 127.0.0.1:5672\n```\n\n```text\n-p 5672:5672\n```\n\n========================================\n\nComments:\n- Oh... tried... it worked out... jezz. Could you please at this as an answer?","metadata":{"transformedAt":"2026-08-18T18:33:20.146Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":114,"estimatedTokens":771}}313{"id":"stack-4362051","source":"stackoverflow","questionId":4362051,"title":"Swapping out MSMQ for RabbitMQ in NServiceBus","tags":[".net","msmq","nservicebus","rabbitmq","amqp"],"text":"Title: Swapping out MSMQ for RabbitMQ in NServiceBus\nTags: .net, msmq, nservicebus, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nUdi mentions here that \"people have swapped out the MSMQ layer of NServiceBus and plugged in RabbitMQ in its place\".\n\nI'm looking to do the same thing with the end goal of being able to run an app built with NServiceBus on Mono/Linux with AMQP.\n\nBefore diving in though I'd like to get some feedback from people who might have done this already about pitfalls to avoid, red herrings etc.\n\nAlternatively if the approach is a massive undertaking, it might be best to just use RabbitMQ directly, but if possible I'd like to stick with NServiceBus.\n\n========================================\n\nTop Answer:\nMassTransit runs RabbitMQ as a supported transport:\n\n```\nServiceBusFactory.New(sbc =>\n{\n sbc.UseRabbitMq();\n sbc.ReceiveFrom(\"rabbitmq://localhost/app1\")\n});\n```\n\nJust do `install-package masstransit.rabbitmq` and make sure to change your console application framework to '.Net 4.0' instead of '.Net 4.0 Client Profile'.\n\n========================================\n\nCode:\n```text\nServiceBusFactory.New(sbc =>\n{\n sbc.UseRabbitMq();\n sbc.ReceiveFrom(\"rabbitmq://localhost/app1\")\n});\n```\n\n```text\ninstall-package masstransit.rabbitmq\n```\n\n========================================\n\nComments:\n- I think you should do pro/con analysis of why you'd want to use NServiceBus vs. RabbitMQ. Personally having used both, I'm not sure why you'd want to use NServiceBus ontop of Rabbit, as Rabbit is a broker-style setup which removes a lot of the benefits of NServiceBus of being de-centralised.\n- @mrnye - purely because we can't be dependent on MSMQ, as this app needs to run on Mono in a Linux environment as well as Windows.\n- FYI docs.particular.net/nservicebus/bridge is now available, and a great use case is to gradually migrate a system from one transport to another\n- Tried to look this up on the NServiceBus website, but did not find anything. Do you happen to have a reference where I can track future features?\n- The issue tracker is probably the most current list - github.com/NServiceBus/NServiceBus/…","metadata":{"transformedAt":"2026-08-18T18:33:20.146Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":51,"estimatedTokens":537}}314{"id":"stack-28604332","source":"stackoverflow","questionId":28604332,"title":"Rabbitmq Ack or Nack, leaving messages on the queue","tags":["c#",".net","rabbitmq","message-queue"],"text":"Title: Rabbitmq Ack or Nack, leaving messages on the queue\nTags: c#, .net, rabbitmq, message-queue\nSource: Stack Overflow\n\nQuestion:\nI have been playing around with RabbitMq.net and the message acknowledgements. \nIf the consumer is able to process the message you can send back an ack in the form of\n\n```\nchannel.BasicAck(ea.DeliveryTag, false);\n```\n\nwhich will take it off the queue.\n\nBut what about if the message was unable to be processed ? maybe a temporary outage and you don't want the message taken off the queue just put to the back and carry on with the next message?\n\nI have tried using \n\n```\nchannel.BasicNack(ea.DeliveryTag, false, true);\n```\n\nbut the next time round its still getting the same message and not moving to the next message in the queue\n\nmy complete code is\n\n```\nclass Program\n{\n private static IModel channel;\n private static QueueingBasicConsumer consumer;\n private static IConnection Connection;\n\n static void Main(string[] args)\n {\n Connection = GetRabbitMqConnection();\n channel = Connection.CreateModel();\n channel.BasicQos(0, 1, false);\n consumer = new QueueingBasicConsumer(channel);\n channel.BasicConsume(\"SMSQueue\", false, consumer);\n while (true)\n {\n if (!channel.IsOpen)\n {\n throw new Exception(\"Channel is closed\");\n }\n var ea = consumer.Queue.Dequeue();\n string jsonified = Encoding.UTF8.GetString(ea.Body);\n var message = JsonConvert.DeserializeObject(jsonified);\n if (ProcessMessage())\n channel.BasicAck(ea.DeliveryTag, false);\n else\n channel.BasicNack(ea.DeliveryTag, false, true);\n }\n }\n\n private static bool ProcessMessage()\n {\n return false;\n }\n\n public static IConnection GetRabbitMqConnection()\n {\n try\n {\n var connectionFactory = new ConnectionFactory\n {\n UserName = \"guest\",\n Password = \"guest\",\n HostName = \"localhost\"\n };\n return connectionFactory.CreateConnection();\n }\n catch (Exception ex)\n {\n Console.WriteLine(ex.Message);\n return null;\n }\n }\n}\n```\n\n========================================\n\nCode:\n```text\nchannel.BasicAck(ea.DeliveryTag, false);\n```\n\n```text\nchannel.BasicNack(ea.DeliveryTag, false, true);\n```\n\n```text\nclass Program\n{\n private static IModel channel;\n private static QueueingBasicConsumer consumer;\n private static IConnection Connection;\n\n static void Main(string[] args)\n {\n Connection = GetRabbitMqConnection();\n channel = Connection.CreateModel();\n channel.BasicQos(0, 1, false);\n consumer = new QueueingBasicConsumer(channel);\n channel.BasicConsume(\"SMSQueue\", false, consumer);\n while (true)\n {\n if (!channel.IsOpen)\n {\n throw new Exception(\"Channel is closed\");\n }\n var ea = consumer.Queue.Dequeue();\n string jsonified = Encoding.UTF8.GetString(ea.Body);\n var message = JsonConvert.DeserializeObject<SmsRecords>(jsonified);\n if (ProcessMessage())\n channel.BasicAck(ea.DeliveryTag, false);\n else\n channel.BasicNack(ea.DeliveryTag, false, true);\n }\n }\n\n private static bool ProcessMessage()\n {\n return false;\n }\n\n public static IConnection GetRabbitMqConnection()\n {\n try\n {\n var connectionFactory = new ConnectionFactory\n {\n UserName = \"guest\",\n Password = \"guest\",\n HostName = \"localhost\"\n };\n return connectionFactory.CreateConnection();\n }\n catch (Exception ex)\n {\n Console.WriteLine(ex.Message);\n return null;\n }\n }\n}\n```\n\n========================================\n\nComments:\n- I resolved this by using a subscription and then calling BasicDeliverEventArgs basicDeliveryEventArgs = subscription.Next();\n- How did using Subscription 'fix' the issue of keeping on running into the same messages? Either NoAck mode is on (and the server auto-acks) or Ack was sent to acknowledge processing of the message - both are wrong if the message couldn't be processed in some valid fashion but \"shouldn't be lost\". If Acks aren't sent then the messages will 'reappear' once the channel is closed. I suspect that the code with the Subscription simply used a larger Prefetch or something else.. (with RabbitMQ > 2.7 you can Nack-requeue to effectively put messages \"to the back\" of the prefetch buffer).\n- How do you nack message \"into a holding queue\"? doesn't it automatically get re-queued in the original queue?","metadata":{"transformedAt":"2026-08-18T18:33:20.146Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":155,"estimatedTokens":1118}}315{"id":"stack-49728884","source":"stackoverflow","questionId":49728884,"title":"Using DbContext in RabbitMQ Consumer (Singleton Service)","tags":["c#",".net","asp.net-core","rabbitmq"],"text":"Title: Using DbContext in RabbitMQ Consumer (Singleton Service)\nTags: c#, .net, asp.net-core, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have a RabbitMQ Singleton that is working fine, but has a dependency on a scoped service whenever a message arrives: \n\n```\nconsumer.Received += _resourcesHandler.ProcessResourceObject; //Scoped Service\n```\n\nMy services are registered like so: \n\n```\nservices.AddScoped();\nservices.AddSingleton();\n```\n\nThe scoped services constructors uses DI for the Db Context: \n\n```\nprivate readonly ApplicationDbContext _appDbContext;\n\npublic ResourcesHandler(ApplicationDbContext appDbContext)\n{\n _appDbContext = appDbContext;\n}\n```\n\nThis scoped service calls the Db Context in order to insert properties to the database on receipt of a message. \n\nHowever, because the scoped service has a different lifetime, startup is failing. \n\nIs there a better way to do this? I could make the scoped service a singleton, but then I'd have the problem of using DbContext as a dependancy. \n\nWhat's the \"protocol\" in DI for calling the dbContext in singleton services? \n\nI could use a `using` statement to make sure its disposed, but then I'd have to pass the DbContextOptions using DI instead. Is this the only way to achieve this?\n\n========================================\n\nTop Answer:\nI think that if you create a ContextFactory and ask it to for the Context would be a good approach.\n\nYou can just register your new Factory like \n\n```\nservices.AddSingleton();\n```\n\nAnd inject on the constructor of your handler.\n\nAnd then you can `: _yourService.GetContext()`; and use it.\n\nYour factory should has the logic about how to create the context and will be isolated of the rest. Any time you need to use the context, you should call the factory.\n\nRemember as long is a Singleton, you should not use states insides.\n\nAny way if you want to use states just register as Transient for example.\n\n**EDIT : remember to return always NEW instance of the context.\n\n========================================\n\nCode:\n```text\nconsumer.Received += _resourcesHandler.ProcessResourceObject; //Scoped Service\n```\n\n```text\nservices.AddScoped<IHandler, Handler>();\nservices.AddSingleton<RabbitMqListener>();\n```\n\n```text\nprivate readonly ApplicationDbContext _appDbContext;\n\npublic ResourcesHandler(ApplicationDbContext appDbContext)\n{\n _appDbContext = appDbContext;\n}\n```\n\n```text\nusing\n```\n\n```text\nprivate void OnMessageReceived(Message message) {\n using (var scope = _provider.CreateScope()) {\n var handler = scope.ServiceProvider.GetRequiredService<IHandler>();\n handler.ProcessResourceObject(message);\n }\n}\n```\n\n```text\nservices.AddSingleton<Func<ApplicationDbContext>>(() =>\n{\n var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>();\n optionsBuilder.UseSqlServer(Configuration.GetConnectionString(\"DefaultConnection\"));\n return new ApplicationDbContext(optionsBuilder.Options);\n});\n```\n\n```text\nprivate readonly Func<ApplicationDbContext> _appDbContextFactory;\n\npublic ResourcesHandler(Func<ApplicationDbContext> appDbContextFactory)\n{\n _appDbContextFactory = appDbContextFactory;\n}\n```\n\n```text\nusing (var context = _appDbContextFactory()) {\n // do stuff\n}\n```\n\n```text\nIServiceProvider\n```\n\n```text\nRabbitMqListener\n```\n\n```text\n_provider\n```\n\n```text\nApplicationDbContext\n```\n\n```text\nApplicationDbContext\n```\n\n```text\nIHandler\n```\n\n```text\nFunc<ApplicationDbContext>\n```\n\n```text\nservices.AddSingleton<ContextFactory>();\n```\n\n```text\n: _yourService.GetContext()\n```\n\n========================================\n\nComments:\n- The service and DB context must be of the same lifetime if the service references the DB Context.\n- @StanleyOkpalaNwosa Yes. I understand this. My problem is, in my situation, the MQ listener must be a singleton service in order to collect messages. It's the dependancy of the singleton that uses ApplicationDbContext. Is there a way to call DbContext inside of a Singleton safely?\n- Do you mean Scoped or Transient? There is an AddScoped method that I don't see in your code. Scoped only makes sense for requests that come in through the ASP.NET Core pipeline. I'm unsure if RabbitMq messages do that. Edit: I see that you changed AddTransient to AddScoped...\n- @HansKilian Refresh! I was testing with Transient, but changed back to scoped. Apologies. To expand - The RabbitMQ listener in my fetches the registered service on startup, so it has to be singleton to correctly register on startup.\n- This seems like a great way to work around this. I hadn't considered the fact that in this case, I may have picked the wrong framework for this specific service. I hadn't considered this. Thank you! I'll try this out.\n- @Dandy I've added alternative approach if you don't want to bother with scopes, not sure if asker receives notifications of answer edits.\n- For some reason the custom scope wasn't working with the DbContext specifically, always failed because it wasn't instantiated. Rather then figure that out, I used the Factory method for `using` and disposing. This worked like a treat!\n- 'Cannot access a disposed object. Object name: 'IServiceProvider'.'","metadata":{"transformedAt":"2026-08-18T18:33:20.146Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":17,"totalLines":167,"estimatedTokens":1286}}316{"id":"stack-44175968","source":"stackoverflow","questionId":44175968,"title":"Messages lost if queue does not exist","tags":["rabbitmq","spring-rabbit"],"text":"Title: Messages lost if queue does not exist\nTags: rabbitmq, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nWhen we send the messages to RabbitMQ and if queue doesn't exist, messages are lost without throwing any error.\n\nWhere the messages will be posted to? Dead queue?\n\n========================================\n\nTop Answer:\n### Your messages can be returned back to you\n\nIf there are no queues bound to an exchange. To receive them back and not to lose these messages, you must do the following:\n\n### 1. Add these properties to your `application.yml`\n\n```\nspring:\n rabbitmq:\n publisher-confirm-type: correlated\n publisher-returns: true\n template:\n mandatory: true\n```\n\n### 2. Create RabbitConfirmCallback\n\n```\nimport org.slf4j.Logger;\nimport org.slf4j.LoggerFactory;\nimport org.springframework.amqp.rabbit.connection.CorrelationData;\nimport org.springframework.amqp.rabbit.core.RabbitTemplate;\nimport org.springframework.stereotype.Component;\n\n@Component\npublic class RabbitConfirmCallback implements RabbitTemplate.ConfirmCallback {\n private static final Logger logger = LoggerFactory.getLogger(RabbitConfirmCallback.class);\n\n @Override\n public void confirm(CorrelationData correlationData, boolean ack, String cause) {\n if (ack && correlationData != null && correlationData.getId() != null) {\n\n Message returnedMessage = correlationData.getReturnedMessage();\n String dataId = correlationData.getId();\n\n if (returnedMessage != null) {\n logger.error(\"Message wasn't delivered to Consumer; \" + returnedMessage + \"\\nCorrelationData id = \" + dataId);\n } else {\n logger.info(\"CorrelationData with id \" + dataId + \" acknowledged;\");\n }\n\n } else {\n if (ack) {\n logger.warn(\"Unknown message acknowledgement received: \" + correlationData);\n } else {\n logger.info(\"Broker didn't accept message: \" + cause);\n }\n }\n }\n}\n```\n\n**This callback method `confirm(...)` will be triggered, right after trial of sending message in such an exchange without bounded queues**.\nIn `correlationData` object, you will find `returnedMessage` field where will be `messageProperties` and `body` of your message\n\n### 3. Set RabbitConfirmCallback to RabbitTemplate\n\n```\n@Autowired\npublic void post(RabbitTemplate rabbitTemplate, RabbitConfirmCallback rabbitConfirmCallback){\n rabbitTemplate.setConfirmCallback(rabbitConfirmCallback);\n}\n```\n\n### 4. When you are sending your messages, add CorrelationDate object\n\nWith some unique identifier\n\n```\nrabbitTemplate.convertAndSend(exchange, routingKey, wrapMessage(message),\n new CorrelationData(stringId));\n```\n\n========================================\n\nCode:\n```text\nmandatory\n```\n\n```text\nspring:\n rabbitmq:\n publisher-confirm-type: correlated\n publisher-returns: true\n template:\n mandatory: true\n```\n\n```java\nimport org.slf4j.Logger;\nimport org.slf4j.LoggerFactory;\nimport org.springframework.amqp.rabbit.connection.CorrelationData;\nimport org.springframework.amqp.rabbit.core.RabbitTemplate;\nimport org.springframework.stereotype.Component;\n\n@Component\npublic class RabbitConfirmCallback implements RabbitTemplate.ConfirmCallback {\n private static final Logger logger = LoggerFactory.getLogger(RabbitConfirmCallback.class);\n\n @Override\n public void confirm(CorrelationData correlationData, boolean ack, String cause) {\n if (ack && correlationData != null && correlationData.getId() != null) {\n\n Message returnedMessage = correlationData.getReturnedMessage();\n String dataId = correlationData.getId();\n\n if (returnedMessage != null) {\n logger.error(\"Message wasn't delivered to Consumer; \" + returnedMessage + \"\\nCorrelationData id = \" + dataId);\n } else {\n logger.info(\"CorrelationData with id \" + dataId + \" acknowledged;\");\n }\n\n } else {\n if (ack) {\n logger.warn(\"Unknown message acknowledgement received: \" + correlationData);\n } else {\n logger.info(\"Broker didn't accept message: \" + cause);\n }\n }\n }\n}\n```\n\n```java\n@Autowired\npublic void post(RabbitTemplate rabbitTemplate, RabbitConfirmCallback rabbitConfirmCallback){\n rabbitTemplate.setConfirmCallback(rabbitConfirmCallback);\n}\n```\n\n```java\nrabbitTemplate.convertAndSend(exchange, routingKey, wrapMessage(message),\n new CorrelationData(stringId));\n```\n\n```text\napplication.yml\n```\n\n```text\nconfirm(...)\n```\n\n```text\ncorrelationData\n```\n\n```text\nreturnedMessage\n```\n\n```text\nmessageProperties\n```\n\n```text\nbody\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.146Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":11,"totalLines":171,"estimatedTokens":1130}}317{"id":"stack-30780979","source":"stackoverflow","questionId":30780979,"title":"Best way to ensure an event is eventually published to a message queuing sytem","tags":["c#","events","rabbitmq","message-queue","eventual-consistency"],"text":"Title: Best way to ensure an event is eventually published to a message queuing sytem\nTags: c#, events, rabbitmq, message-queue, eventual-consistency\nSource: Stack Overflow\n\nQuestion:\nPlease, imagine you have a method like the following:\n\n```\npublic void PlaceOrder(Order order)\n{\n this.SaveOrderToDataBase(order);\n this.bus.Publish(new OrderPlaced(Order)); \n}\n```\n\nAfter the order is saved to the database, an event is published to the message queuing system, so other subsystems on the same or another machine can process it.\n\nBut, what happens if `this.bus.Publish(new OrderPlaced(Order))` call fails? Or the machine crashes just after saving the order into the database? The event is not published and other subsystems cannot process it. This is unacceptable. If this happens I need to ensure that the event is eventually published.\n\nWhat are the acceptable strategies can I use? Which is the best one?\n\nNOTE: I don't want to use distributed transactions.\n\nEDIT: \n\nPaul Sasik is very close, and I think I can achieve 100%. This is what I thought:\n\nfirst create a table Events in the database like the following:\n\n```\nCREATE TABLE Events (EventId int PRIMARY KEY)\n```\n\nYou may want to use guids instead of int, or you may use sequences or identities.\n\nThen do the following pseudocode:\n\n```\nopen transaction\nsave order and event via A SINGLE transaction\nin case of failure, report error and return\nplace order in message queue\nin case of failure, report error, roll back transaction and return\ncommit transaction\n```\n\nAll events must include EventId. When event subscribers receive an event, they first check EventId existence in database. \n\nThis way you get 100% realiability, not only 99.999%\n\n========================================\n\nTop Answer:\nYou can make the `this.bus.Publish` call part of a database transaction of the `this.SaveOrderToDataBase`. This means that `this.SaveOrderToDataBase` executes in transaction scope and if the db call fails you never call the mq and if the mq call fails then you roll back the db transaction leaving both systems in a consistent state. If both calls succeed you commit the db transaction.\n\nPseudocode:\n\n```\nopen transaction\nsave order via transaction\nin case of failure, report error and return\nplace order in message queue\nin case of failure, report error, roll back transaction and return\ncommit transaction\n```\n\nYou didn't mention any specific db technology so here's a link to a wiki article on transactions. Even if you're new to transactions, it's a good place to start. And a bit of good news: They are not hard to implement.\n\n========================================\n\nCode:\n```text\npublic void PlaceOrder(Order order)\n{\n this.SaveOrderToDataBase(order);\n this.bus.Publish(new OrderPlaced(Order)); \n}\n```\n\n```text\nCREATE TABLE Events (EventId int PRIMARY KEY)\n```\n\n```text\nopen transaction\nsave order and event via A SINGLE transaction\nin case of failure, report error and return\nplace order in message queue\nin case of failure, report error, roll back transaction and return\ncommit transaction\n```\n\n```text\nthis.bus.Publish(new OrderPlaced(Order))\n```\n\n```text\npublic void PlaceOrder(Order order)\n{\n BeginTransaction();\n Try \n {\n SaveOrderToDataBase(order);\n ev = new OrderPlaced(Order);\n SaveEventToDataBase(ev);\n CommitTransaction();\n }\n Catch \n {\n RollbackTransaction();\n return;\n }\n\n PublishEventAsync(ev); \n}\n\nasync Task PublishEventAsync(BussinesEvent ev) \n{\n BegintTransaction();\n try \n {\n await DeleteEventAsync(ev);\n await bus.PublishAsync(ev);\n CommitTransaction();\n }\n catch \n {\n RollbackTransaction();\n }\n\n}\n```\n\n```text\nforeach (ev in eventsThatNeedsToBeSent) {\n await PublishEventAsync(ev);\n}\n```\n\n```text\nopen transaction\nsave order via transaction\nin case of failure, report error and return\nplace order in message queue\nin case of failure, report error, roll back transaction and return\ncommit transaction\n```\n\n```text\nthis.bus.Publish\n```\n\n```text\nthis.SaveOrderToDataBase\n```\n\n```text\nthis.SaveOrderToDataBase\n```\n\n========================================\n\nComments:\n- Ah yes. Your idea is called correlation and the GUID or int ID is called a correlation ID. You might even call it a pattern. It does increase the complexity of your code but not nearly as much as handling distributed transactions. (Also see my edit above. I just specified that there should just be a single transaction managing the table inserts.)\n- @PaulSasik. Yes correlation. I realized there might be a race condition with this approach. In some cases, subscribers might receive the event before transaction is committed, so they cannot see the EventId. To mitigate it, subscribers should retry getting the EventId after a short delay when they detect eventid inexistence. Depending on isolation level subscribers are blocked or not when trying to read an EventId that is on the table but not yet committed.\n- Good attempt!. But this strategy has a problem, the event might be published and the order not saved to the datablase if commit transaction fails or the machine crashes just after placing the order in message queue\n- @JesúsLópez - True, but doing a db transaction gets you darn close, like 99.9999% (probably even better) and I don't think you can do better without distributing the transaction among several machines.\n- Yes you are right. However I think you can do better, please see my edit.\n- This won't really work for databases that don't support atomic transactions. For a document store database I would save the event inside the document, a background process picks up failed events and fires them, and marks the event as complete. In case marking them as complete fails you can keep an idempotency key that is unique enough for the event like orderid for the subscribers can look up the key and do nothing if it exists already. That way there won't be side effects of calling the event twice if the background process tries it twice due to failing to mark it complete.\n- Well, I'm assuming you are working with a system the supports atomic transactions. Incidentally, there are several NoSQL databases that support atomic transactions such as RavenDb\n- @JesúsLópez two questions: 1. what if CommitTransaction() in PublishEventAsync fails? Does this mean eventually in your retry process ev would be retired again, but assuming idempotentcy of the consumer of ev, this would not matter? 2. What if the server crashes in PublishAsyncEvent after bus.publish but before the Commit Transaction? Is the same scenario as 1. above?\n- @GreenieMeanie, 1.- the event would be published twice, the client should implement idempotency based on EventId uniqueness. 2. yes, it's the same scenario as 1.\n- What if we wrap them in just on transaction ? if the PublishEventAsync fails, then whole transaction will be reverted. The client should replace the order. The purpose of saving the message/event is just in case , then we can resend it. If we can replace the order, then we won't have the need to resend the message from the beginning.\n- @ValidfroM what if \"COMMIT\" fails? the event is published but the order is not placed in the database.","metadata":{"transformedAt":"2026-08-18T18:33:20.146Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":174,"estimatedTokens":1819}}318{"id":"stack-36857097","source":"stackoverflow","questionId":36857097,"title":"Changing hostname breaks Rabbitmq when running on Kubernetes","tags":["amazon-ec2","dns","rabbitmq","kubernetes","hostname"],"text":"Title: Changing hostname breaks Rabbitmq when running on Kubernetes\nTags: amazon-ec2, dns, rabbitmq, kubernetes, hostname\nSource: Stack Overflow\n\nQuestion:\nI'm trying to run Rabbitmq using Kubernetes on AWS. I'm using the official Rabbitmq docker container. Each time the pod restarts the rabbitmq container gets a new hostname. I've setup a service (of type LoadBalancer) for the pod with a resolvable DNS name.\n\nBut when I use an EBS to make the rabbit config/messsage/queues persistent between restarts it breaks with:\n\n```\nexception exit: {{failed_to_cluster_with,\n ['rabbitmq@rabbitmq-deployment-2901855891-nord3'],\n \"Mnesia could not connect to any nodes.\"},\n {rabbit,start,[normal,[]]}}\n in function application_master:init/4 (application_master.erl, line 134)\n```\n\n`rabbitmq-deployment-2901855891-nord3` is the previous hostname rabbitmq container. It is almost like Mnesia saved the old hostname :-/\n\nThe container's info looks like this:\n\n```\nStarting broker...\n=INFO REPORT==== 25-Apr-2016::12:42:42 ===\nnode : rabbitmq@rabbitmq-deployment-2770204827-cboj8\nhome dir : /var/lib/rabbitmq\nconfig file(s) : /etc/rabbitmq/rabbitmq.config\ncookie hash : XXXXXXXXXXXXXXXX\nlog : tty\nsasl log : tty\ndatabase dir : /var/lib/rabbitmq/mnesia/rabbitmq\n```\n\nI'm only able to set the first part of the node name to `rabbitmq` using the `RABBITMQ_NODENAME` environment variable.\n\nSetting `RABBITMQ_NODENAME` to a resolvable DNS name breaks with:\n\n`Can't set short node name!\\nPlease check your configuration\\n\"`\n\nSetting `RABBITMQ_USE_LONGNAME` to `true` breaks with:\n\n`Can't set long node name!\\nPlease check your configuration\\n\"`\n\nUpdate: \n\nSetting `RABBITMQ_NODENAME` to rabbitmq@**localhost** works but that negates any possibility to cluster instances. \n\n```\nStarting broker...\n=INFO REPORT==== 26-Apr-2016::11:53:19 ===\nnode : rabbitmq@localhost\nhome dir : /var/lib/rabbitmq\nconfig file(s) : /etc/rabbitmq/rabbitmq.config\ncookie hash : 9WtXr5XgK4KXE/soTc6Lag==\nlog : tty\nsasl log : tty\ndatabase dir : /var/lib/rabbitmq/mnesia/rabbitmq@localhost\n```\n\nSetting `RABBITMQ_NODENAME` to the service name, in this case `rabbitmq-service` like so rabbitmq@**rabbitmq-service** also works since kubernetes service names are internally resolvable via DNS. \n\n```\nStarting broker...\n=INFO REPORT==== 26-Apr-2016::11:53:19 ===\nnode : rabbitmq@rabbitmq-service\nhome dir : /var/lib/rabbitmq\nconfig file(s) : /etc/rabbitmq/rabbitmq.config\ncookie hash : 9WtXr5XgK4KXE/soTc6Lag==\nlog : tty\nsasl log : tty\ndatabase dir : /var/lib/rabbitmq/mnesia/rabbitmq@rabbitmq-service\n```\n\nIs this the right way though? Will I still be able to cluster multiple instances if the node names are the same?\n\n========================================\n\nTop Answer:\nIn addition to the first reply by @ant31:\n\nKubernetes now allows to setup a hostname, e.g. in yaml:\n\n```\ntemplate:\n metadata:\n annotations:\n \"pod.beta.kubernetes.io/hostname\": rabbit-rc1\n```\n\nSee https://github.com/kubernetes/kubernetes/tree/master/cluster/addons/dns # `A Records and hostname Based on Pod Annotations - A Beta Feature in Kubernetes v1.2`\n\nIt seems that the whole configuration alive multiple restarts or re-schedules. I've not setup a cluster however I'm going to the tutorial for mongodb, see https://www.mongodb.com/blog/post/running-mongodb-as-a-microservice-with-docker-and-kubernetes\n\nThe approach will be probably almost same from kubernetes point of view.\n\n========================================\n\nCode:\n```text\nexception exit: {{failed_to_cluster_with,\n ['rabbitmq@rabbitmq-deployment-2901855891-nord3'],\n \"Mnesia could not connect to any nodes.\"},\n {rabbit,start,[normal,[]]}}\n in function application_master:init/4 (application_master.erl, line 134)\n```\n\n```text\nStarting broker...\n=INFO REPORT==== 25-Apr-2016::12:42:42 ===\nnode : rabbitmq@rabbitmq-deployment-2770204827-cboj8\nhome dir : /var/lib/rabbitmq\nconfig file(s) : /etc/rabbitmq/rabbitmq.config\ncookie hash : XXXXXXXXXXXXXXXX\nlog : tty\nsasl log : tty\ndatabase dir : /var/lib/rabbitmq/mnesia/rabbitmq\n```\n\n```text\nStarting broker...\n=INFO REPORT==== 26-Apr-2016::11:53:19 ===\nnode : rabbitmq@localhost\nhome dir : /var/lib/rabbitmq\nconfig file(s) : /etc/rabbitmq/rabbitmq.config\ncookie hash : 9WtXr5XgK4KXE/soTc6Lag==\nlog : tty\nsasl log : tty\ndatabase dir : /var/lib/rabbitmq/mnesia/rabbitmq@localhost\n```\n\n```text\nStarting broker...\n=INFO REPORT==== 26-Apr-2016::11:53:19 ===\nnode : rabbitmq@rabbitmq-service\nhome dir : /var/lib/rabbitmq\nconfig file(s) : /etc/rabbitmq/rabbitmq.config\ncookie hash : 9WtXr5XgK4KXE/soTc6Lag==\nlog : tty\nsasl log : tty\ndatabase dir : /var/lib/rabbitmq/mnesia/rabbitmq@rabbitmq-service\n```\n\n```text\nrabbitmq-deployment-2901855891-nord3\n```\n\n```text\nrabbitmq\n```\n\n```text\nRABBITMQ_NODENAME\n```\n\n```text\nRABBITMQ_NODENAME\n```\n\n```text\nCan't set short node name!\\nPlease check your configuration\\n\"\n```\n\n```text\nRABBITMQ_USE_LONGNAME\n```\n\n```text\ntrue\n```\n\n```text\nCan't set long node name!\\nPlease check your configuration\\n\"\n```\n\n```text\nRABBITMQ_NODENAME\n```\n\n```text\nRABBITMQ_NODENAME\n```\n\n```text\nrabbitmq-service\n```\n\n```text\nRABBITMQ_NODENAME=rabbit@rabbitmq-1\n```\n\n```text\nsearch rmq.svc.cluster.local\n```\n\n```text\n127.0.0.1 rabbitmq-1 # or rabbitmq-2 on node 2...\n```\n\n```text\nrabbitmq-1.svc.cluster.local\nrabbitmq-2.svc.cluster.local\nrabbitmq-3.svc.cluster.local\n```\n\n```text\nrabbitmq-1,rabbitmq-2,rabbitmq-3\n```\n\n```text\n/etc/resolv.conf\n```\n\n```text\n/etc/hosts\n```\n\n```text\ndeployments\n```\n\n```text\ntemplate:\n metadata:\n annotations:\n \"pod.beta.kubernetes.io/hostname\": rabbit-rc1\n```\n\n```text\nA Records and hostname Based on Pod Annotations - A Beta Feature in Kubernetes v1.2\n```\n\n========================================\n\nComments:\n- So OK, dynamic scaling for many applications is severely crippled by this. But at least I have a solution to manually cluster RabbitMQ.\n- I think at this point StatefulSets can do it best, this answer might be outdated.\n- Linking stateful sets here: github.com/rabbitmq/rabbitmq-peer-discovery-k8s/tree/v3.7.x/‌​…","metadata":{"transformedAt":"2026-08-18T18:33:20.146Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":25,"totalLines":237,"estimatedTokens":1551}}319{"id":"stack-7460149","source":"stackoverflow","questionId":7460149,"title":"Lightweight notification technique","tags":["python","django","rabbitmq","celery","greenlets"],"text":"Title: Lightweight notification technique\nTags: python, django, rabbitmq, celery, greenlets\nSource: Stack Overflow\n\nQuestion:\nI need to develop a realtime recent activity feed in django (with AJAX long-polling), and I'm wondering what's the best strategy for the server-side.\n\nPseudocode:\n\n```\ndef recent_activity_post_save():\n notify_view()\n\n[in the view]\nwhile not new_activity():\n sleep(1)\nreturn HttpResponse(new_activity())\n```\n\nThe first thing that comes in mind is querying the DB every second. Not feasible. Other options:\n\n- using the cache as a notification service\n\n- using a specialized tool, like Celery (I'd rather not do it, because it seems like overkill)\n\nWhat's the best way to go here?\n\n========================================\n\nTop Answer:\nHave you considered using Signals? You could send a signal in recent_activity_post_save() and there could be a listener which stores the information in cache. \n\nThe view would just refer to the cache to see if there are new notifications. Of course you don't need Signals, but IMHO it would be a bit cleaner that way, as you could add more \"notification handlers\".\n\nThis seems optimal because you don't need to poll the DB (artificial load), the notifications are \"visible\" almost immediately (only after the time required to process signals and interact with cache).\n\nSo the pseudocode would look like this:\n\n```\n# model\ndef recent_activity_post_save():\n post_save_signal.send()\n\n# listener\ndef my_handler( ... ):\n cache.set( 'notification', .... )\n\npost_save_signal.connect( my_handler )\n\n# view\ndef my_view( request ):\n new_notification = None\n while not new_notification:\n sleep(1)\n new_notification = cache.get( 'notification' )\n return HttpResponse(...)\n```\n\n========================================\n\nCode:\n```text\ndef recent_activity_post_save():\n notify_view()\n\n[in the view]\nwhile not new_activity():\n sleep(1)\nreturn HttpResponse(new_activity())\n```\n\n```text\nfunction simplePoll() {\n $.get(\"your-url\", {query-parameters}, function(data){\n //do stuff with the data, replacing a div or updating json or whatever\n setTimeout(simplePoll, delay);\n });\n}\n```\n\n```text\nRecentActivity\n```\n\n```text\norbited\n```\n\n```text\norbited\n```\n\n```text\n# model\ndef recent_activity_post_save():\n post_save_signal.send()\n\n# listener\ndef my_handler( ... ):\n cache.set( 'notification', .... )\n\npost_save_signal.connect( my_handler )\n\n# view\ndef my_view( request ):\n new_notification = None\n while not new_notification:\n sleep(1)\n new_notification = cache.get( 'notification' )\n return HttpResponse(...)\n```\n\n========================================\n\nComments:\n- This is generally good advice, but the question did specifically say \"in django (with AJAX long-polling)\".\n- this is exactly what I'm using right now; it seems optimal to me too, but I was looking for other opinions on this subject. +1\n- I liked this solution all the way until I saw the `while not new_notification` line... couldn't this theoretically hang indefinitely on a request -- presumably an ajax polling request of some sort -- while it waits for a new notification to come in? Wouldn't it be better to just return an empty data set from the view if the cache was empty?\n- @DMactheDestroyer that was some sort of pseudocode, of course it just returns an empty result after 30 seconds or so if there's no new activity.\n- Can you explain more the advantage of `cache.set( 'notification', .... )` in the signal handler (as you have) vs. directly in `recent_activity_post_save` (without needing signals)?\n- @dkamins The main benefit (IMHO) of having a signal is that the code is decoupled, i.e. the recent_activity_post_save() code doesn't have to (and some might say it shouldn't) \"know\" about notification code. It's task is to just save the post, it may let others know about this even though by sending a signal (not knowing who listens though). So the cleaner, decoupled code would be one thing.\n- @dkamins Another thing is perhaps of less importance, that is if you'd like to add new functionality, you just add another signal listener (handler). This firstly is simpler than tinkering with code in recent_activity_post_save() and secondly each function or method performs a simple task and that task only, which is good from code quality point of view and a lot simpler to maintain once you get lots of code.\n- @DMactheDestroyer - you have a point. It was just a simple code as OP pointed out but I guess optimal would be to either develop a hybrid solution (i.e. check few times and then return empty dataset) or use your approach. The hybrid approach would have the advantage that it could be a bit lighter on the server (i.e. fewer requests) but could result in some requests being returned after the user has already left (e.g. in ajax case you pointed out). So it's matter of a choice of the person who implements, but thanks for pointing out the issue ! :)\n- thanks for the insight; I was looking for a *lightweight* solution though, because there's no point in installing a NoSQL database for a single page in a site, right?","metadata":{"transformedAt":"2026-08-18T18:33:20.146Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":124,"estimatedTokens":1274}}320{"id":"stack-7382655","source":"stackoverflow","questionId":7382655,"title":"Using Redis for Pub Sub . Advantages / Disadvantages over RabbitMQ","tags":["redis","message-queue","rabbitmq"],"text":"Title: Using Redis for Pub Sub . Advantages / Disadvantages over RabbitMQ\nTags: redis, message-queue, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nOur requirement is very simple. Send messages to users subscribed to a topic. We need our messaging system to be able to support millions of topics and maybe millions of subscribers to any given topic in near real time. Our application is built with Java.\n\nWe almost decided on RabbitMQ because of the community support, documentation and features (possibly it will deliver everything we need). But I am very inclined towards using Redis because it looks promising and lightweight. Honestly I have limited understanding about Redis as a messaging system, but looking at a growing number of companies using it as a queuing(with Ruby Resque), I want to know if there is an offering like Resque in Java and what are the advantages or disadvantages of using Redis as a MQ over RabbitMQ.\n\n========================================\n\nComments:\n- Thanks duckworth. My dilemma came from the fact that heello.com is using redis/Resque and probably they are ready for massive message flow. I was wondering if Redis is ready to handle such a scale. I would still be interested in finding the answer, but otherwise I am comfortable with RabbitMQ.\n- Every client library I've used for RMQ has had serious bugs in maintaining a persistent connection. The design/architecture is pretty but please consider real world high-availability situations.","metadata":{"transformedAt":"2026-08-18T18:33:20.146Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":14,"estimatedTokens":369}}321{"id":"stack-2669573","source":"stackoverflow","questionId":2669573,"title":"ZooKeeper and RabbitMQ/Qpid together - overkill or a good combination?","tags":["locking","message-queue","rabbitmq","distributed-system","apache-zookeeper"],"text":"Title: ZooKeeper and RabbitMQ/Qpid together - overkill or a good combination?\nTags: locking, message-queue, rabbitmq, distributed-system, apache-zookeeper\nSource: Stack Overflow\n\nQuestion:\nGreetings,\n\nI'm evaluating some components for a multi-data center distributed system. We're going to be using message queues (via either RabbitMQ or Qpid) so agents can make asynchronous requests to other agents without worrying about addressing, routing, load balancing or retransmission.\n\nIn many cases, the agents will be interacting with components that were not designed for highly concurrent access, so locking and cross-agent coordination will be needed to avoid race conditions. Also, we'd like the system to automatically respond to agent or data center failures.\n\nWith the above use cases in mind, ZooKeeper seemed like it might be a good fit. But I'm wondering if trying to use both ZK and message queuing is overkill. It seems like what Zookeeper does *could* be accomplished by my own cluster manager using AMQP messaging, but that would be hard to get really right. On the other hand, I've seen some examples where ZooKeeper was used to implement message queuing, but I think RabbitMQ/Qpid are a more natural fit for that.\n\nHas anyone out there used a combination like this?\n\nThanks in advance,\n\n-Chris\n\n========================================\n\nTop Answer:\nNot quite sure what ZooKeeper exactly is, but I guess that using a component from Apache (if it does fit your needs well) is preferred before managing such things as distributed synchronization and group services at your own. You could of course hire a team of developers especially for that purpose, but that doesn't guarantee you a better implementation.\n\nI guess, that it would be anyways implemented as a separate component, cuz other way could bring much complexity and decelerate the workflow; so the preference of ZooKeeper or anything similar is kind of obvious (to me).\n\nAnd surely, unless you're in the global optimization phase of your project workflow, I guess it would be better to use RabbitMQ or such (I would even stress that, cuz implementations (especially commercial) of the AMQP would be more reliable than everything that you'd come up with).\n\nSo I would go for both, carefully chosing the appropriate thirdparty products, but using as much of them as it is needed. And that's just my opinion; thanks for reading :)\n\n========================================\n\nComments:\n- Hey Chris, have you figured out the answer to this question? What did you end up going with? Thanks, Ilya\n- These are probably some of the examples you are referring to, adding the links here for other users: cloudera.com/blog/2009/05/… and zookeeper-user.578899.n2.nabble.com/…\n- We ended up going with Qpid for messaging and have put off implementing a distributed coordination service like ZooKeeper. I'm still a big fan of ZK, but our throughput isn't high enough to justify the additional complexity. We are looking at some simple intra-data center distributed locking mechanism, probably backed by MySQL or Redis. Down the road, we may graduate to ZooKeeper.","metadata":{"transformedAt":"2026-08-18T18:33:20.146Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":36,"estimatedTokens":783}}322{"id":"stack-29985065","source":"stackoverflow","questionId":29985065,"title":"RabbitMQ with Unity IOC Container in .NET","tags":[".net","rabbitmq","unity-container"],"text":"Title: RabbitMQ with Unity IOC Container in .NET\nTags: .net, rabbitmq, unity-container\nSource: Stack Overflow\n\nQuestion:\nI am using Unity App Block as my IOC container for my service layer of a WCF project. This works quite well using the Unity.WCF library to plug it into each WCF service.\n\nI recently introduced RabbitMQ into my service layer and I am currently using the \"using\" blocks to connect and add to the queue. I dont like this though and am looking to use the `HierachicalLifetimeManager` to create and destroy my connection to RabbitMQ as I need them? Does this sound correct?\n\nI'm looking for a sample of this, or atleast some guidance on the best approach? (e.g. Should I encapsulate the connection and inject into each service as needed? How would I encapsulate RabbitMQ consumer etc?)\n\n========================================\n\nTop Answer:\nWith RabbitMQ you want your IConnection to be re-used all the time, you don't want it in a \"using\" block. Here is my IOC binding using Ninject, note the InSingletonScope, this is what you want.\n\n```\nBind()\n .ToMethod(ctx =>\n {\n var factory = new ConnectionFactory\n {\n Uri = ConfigurationManager.ConnectionStrings[\"RabbitMQ\"].ConnectionString,\n RequestedHeartbeat = 15\n //every N seconds the server will send a heartbeat. If the connection does not receive a heardbeat within\n //N*2 then the connection is considered dead.\n //suggested from http://public.hudl.com/bits/archives/2013/11/11/c-rabbitmq-happy-servers/\n };\n\n var con = new AutorecoveringConnection(factory);\n con.init();\n return con;\n })\n .InSingletonScope();\n```\n\n========================================\n\nCode:\n```text\nHierachicalLifetimeManager\n```\n\n```text\nvar connectionFactory = new ConnectionFactory\n{\n // Configure the connection factory\n};\nunityContainer.RegisterInstance(connectionFactory);\n\nunityContainer.RegisterType<IConnection, AutorecoveringConnection>(new ContainerControlledLifetimeManager(),\n new InjectionMethod(\"init\"));\n```\n\n```text\nIConnection\n```\n\n```text\nIConnection\n```\n\n```text\nContainerControlledLifetimeManager\n```\n\n```text\nAutorecoveringConnection\n```\n\n```text\nUnityContainer\n```\n\n```text\nConnectionFactory\n```\n\n```text\nUnity\n```\n\n```text\nAutorecoveringConnection\n```\n\n```text\nInjectionMethod\n```\n\n```text\nAutorecoveringConnection\n```\n\n```text\ninit\n```\n\n```text\nIMessageQueue\n```\n\n```text\nIStatusNotifier\n```\n\n```text\nIUpdateSource\n```\n\n```text\nIStatusNotifier\n```\n\n```text\nBind<IConnection>()\n .ToMethod(ctx =>\n {\n var factory = new ConnectionFactory\n {\n Uri = ConfigurationManager.ConnectionStrings[\"RabbitMQ\"].ConnectionString,\n RequestedHeartbeat = 15\n //every N seconds the server will send a heartbeat. If the connection does not receive a heardbeat within\n //N*2 then the connection is considered dead.\n //suggested from http://public.hudl.com/bits/archives/2013/11/11/c-rabbitmq-happy-servers/\n };\n\n var con = new AutorecoveringConnection(factory);\n con.init();\n return con;\n })\n .InSingletonScope();\n```\n\n========================================\n\nComments:\n- thanks for the reply. Do you see any value in abstracting the rabbitmq implementation though? Id imagine it will be very difficult for you to change queue if you really needed ?\n- also could you give me a simple example of it being used then?\n- Yes, we abstract rabbit away. The code only knows about an IMessageBusProducer which it knows pushes messages to a \"message bus\". We can then use Rabbit, MSMQ, whatever we want.\n- There's no reason to create a new factory every time you need a connection\n- @MatteoSp This solution won't because the actual `IConnection` is registered as a singleton, once it's been created it will be reused.\n- You're right, I didn't notice the `InSingletonScope()`. Just curios: a single connection for an entire application, is that enough?\n- @MatteoSp yes, a single connection is rabbits recommended way. The connection will then have many channels on it. We often have 30+ channels on a single connection.","metadata":{"transformedAt":"2026-08-18T18:33:20.147Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":18,"totalLines":144,"estimatedTokens":1065}}323{"id":"stack-37863801","source":"stackoverflow","questionId":37863801,"title":"SparkStreaming, RabbitMQ and MQTT in python using pika","tags":["python","apache-spark","rabbitmq","mqtt","pika"],"text":"Title: SparkStreaming, RabbitMQ and MQTT in python using pika\nTags: python, apache-spark, rabbitmq, mqtt, pika\nSource: Stack Overflow\n\nQuestion:\nJust to make things tricky, I'd like to consume messages from the rabbitMQ queue. Now I know there is a plugin for MQTT on rabbit (https://www.rabbitmq.com/mqtt.html). \n\nHowever I cannot seem to make an example work where Spark consumes a message that has been produced from pika.\n\nFor example I am using the simple wordcount.py program here (https://spark.apache.org/docs/1.2.0/streaming-programming-guide.html) to see if I can I see a message **producer** in the following way:\n\n```\nimport sys\nimport pika\nimport json\nimport future\nimport pprofile\n\ndef sendJson(json):\n\n connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))\n channel = connection.channel()\n\n channel.queue_declare(queue='analytics', durable=True)\n channel.queue_bind(exchange='analytics_exchange',\n queue='analytics')\n\n channel.basic_publish(exchange='analytics_exchange', routing_key='analytics',body=json)\n connection.close()\n\nif __name__ == \"__main__\":\n with open(sys.argv[1],'r') as json_file:\n sendJson(json_file.read())\n```\n\nThe sparkstreaming **consumer** is the following:\n\n```\nimport sys\nimport operator\n\nfrom pyspark import SparkContext\nfrom pyspark.streaming import StreamingContext\nfrom pyspark.streaming.mqtt import MQTTUtils\n\nsc = SparkContext(appName=\"SS\")\nsc.setLogLevel(\"ERROR\")\nssc = StreamingContext(sc, 1)\nssc.checkpoint(\"checkpoint\")\n#ssc.setLogLevel(\"ERROR\")\n\n#RabbitMQ\n\n\"\"\"EXCHANGE = 'analytics_exchange'\nEXCHANGE_TYPE = 'direct'\nQUEUE = 'analytics'\nROUTING_KEY = 'analytics'\nRESPONSE_ROUTING_KEY = 'analytics-response'\n\"\"\"\n\nbrokerUrl = \"localhost:5672\" # \"tcp://iot.eclipse.org:1883\"\ntopic = \"analytics\"\n\nmqttStream = MQTTUtils.createStream(ssc, brokerUrl, topic)\n#dummy functions - nothing interesting...\nwords = mqttStream.flatMap(lambda line: line.split(\" \"))\npairs = words.map(lambda word: (word, 1))\nwordCounts = pairs.reduceByKey(lambda x, y: x + y)\n\nwordCounts.pprint()\nssc.start()\nssc.awaitTermination()\n```\n\nHowever unlike the simple wordcount example, I cannot get this to work and get the following error:\n\n```\n16/06/16 17:41:35 ERROR Executor: Exception in task 0.0 in stage 7.0 (TID 8)\njava.lang.NullPointerException\n at org.eclipse.paho.client.mqttv3.MqttConnectOptions.validateURI(MqttConnectOptions.java:457)\n at org.eclipse.paho.client.mqttv3.MqttAsyncClient.(MqttAsyncClient.java:273)\n```\n\nSo my questions are, what should be the settings in terms of `MQTTUtils.createStream(ssc, brokerUrl, topic)` to listen into the queue and whether there are any more fuller examples and how these map onto those of rabbitMQ.\n\nI am running my consumer code with: `./bin/spark-submit ../../bb/code/skunkworks/sparkMQTTRabbit.py`\n\nI have updated the producer code as follows with TCP parameters as suggested by one comment:\n\n```\nurl_location = 'tcp://localhost'\nurl = os.environ.get('', url_location)\nparams = pika.URLParameters(url)\nconnection = pika.BlockingConnection(params)\n```\n\nand the spark streaming as:\n\n```\nbrokerUrl = \"tcp://127.0.0.1:5672\"\ntopic = \"#\" #all messages\n\nmqttStream = MQTTUtils.createStream(ssc, brokerUrl, topic)\nrecords = mqttStream.flatMap(lambda line: json.loads(line))\ncount = records.map(lambda rec: len(rec))\ntotal = count.reduce(lambda a, b: a + b)\ntotal.pprint()\n```\n\n========================================\n\nTop Answer:\nFrom the `MqttAsyncClient` Javadoc, the server URI must have one of the following schemes: `tcp://`, `ssl://`, or `local://`. You need to change your `brokerUrl` above to have one of these schemes.\n\nFor more information, here's a link to the source for `MqttAsyncClient`:\n\nhttps://github.com/eclipse/paho.mqtt.java/blob/master/org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/MqttAsyncClient.java#L272\n\n========================================\n\nCode:\n```text\nimport sys\nimport pika\nimport json\nimport future\nimport pprofile\n\ndef sendJson(json):\n\n connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))\n channel = connection.channel()\n\n channel.queue_declare(queue='analytics', durable=True)\n channel.queue_bind(exchange='analytics_exchange',\n queue='analytics')\n\n channel.basic_publish(exchange='analytics_exchange', routing_key='analytics',body=json)\n connection.close()\n\nif __name__ == \"__main__\":\n with open(sys.argv[1],'r') as json_file:\n sendJson(json_file.read())\n```\n\n```text\nimport sys\nimport operator\n\nfrom pyspark import SparkContext\nfrom pyspark.streaming import StreamingContext\nfrom pyspark.streaming.mqtt import MQTTUtils\n\nsc = SparkContext(appName=\"SS\")\nsc.setLogLevel(\"ERROR\")\nssc = StreamingContext(sc, 1)\nssc.checkpoint(\"checkpoint\")\n#ssc.setLogLevel(\"ERROR\")\n\n\n#RabbitMQ\n\n\"\"\"EXCHANGE = 'analytics_exchange'\nEXCHANGE_TYPE = 'direct'\nQUEUE = 'analytics'\nROUTING_KEY = 'analytics'\nRESPONSE_ROUTING_KEY = 'analytics-response'\n\"\"\"\n\n\nbrokerUrl = \"localhost:5672\" # \"tcp://iot.eclipse.org:1883\"\ntopic = \"analytics\"\n\nmqttStream = MQTTUtils.createStream(ssc, brokerUrl, topic)\n#dummy functions - nothing interesting...\nwords = mqttStream.flatMap(lambda line: line.split(\" \"))\npairs = words.map(lambda word: (word, 1))\nwordCounts = pairs.reduceByKey(lambda x, y: x + y)\n\nwordCounts.pprint()\nssc.start()\nssc.awaitTermination()\n```\n\n```text\n16/06/16 17:41:35 ERROR Executor: Exception in task 0.0 in stage 7.0 (TID 8)\njava.lang.NullPointerException\n at org.eclipse.paho.client.mqttv3.MqttConnectOptions.validateURI(MqttConnectOptions.java:457)\n at org.eclipse.paho.client.mqttv3.MqttAsyncClient.<init>(MqttAsyncClient.java:273)\n```\n\n```text\nurl_location = 'tcp://localhost'\nurl = os.environ.get('', url_location)\nparams = pika.URLParameters(url)\nconnection = pika.BlockingConnection(params)\n```\n\n```text\nbrokerUrl = \"tcp://127.0.0.1:5672\"\ntopic = \"#\" #all messages\n\nmqttStream = MQTTUtils.createStream(ssc, brokerUrl, topic)\nrecords = mqttStream.flatMap(lambda line: json.loads(line))\ncount = records.map(lambda rec: len(rec))\ntotal = count.reduce(lambda a, b: a + b)\ntotal.pprint()\n```\n\n```text\nMQTTUtils.createStream(ssc, brokerUrl, topic)\n```\n\n```text\n./bin/spark-submit ../../bb/code/skunkworks/sparkMQTTRabbit.py\n```\n\n```text\nFROM rabbitmq:3-management\n\nRUN rabbitmq-plugins enable rabbitmq_mqtt\n```\n\n```text\ndocker build -t rabbit_mqtt .\n```\n\n```text\ndocker run -p 15672:15672 -p 5672:5672 -p 1883:1883 rabbit_mqtt\n```\n\n```text\nimport pika\nimport time \n\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost'))\nchannel = connection.channel()\nchannel.exchange_declare(exchange='amq.topic',\n type='topic', durable=True)\n\nfor i in range(1000):\n channel.basic_publish(\n exchange='amq.topic', # amq.topic as exchange\n routing_key='hello', # Routing key used by producer\n body='Hello World {0}'.format(i)\n )\n time.sleep(3)\n\nconnection.close()\n```\n\n```text\npython producer.py\n```\n\n```text\nfrom pyspark import SparkContext\nfrom pyspark.streaming import StreamingContext\nfrom pyspark.streaming.mqtt import MQTTUtils\n\nsc = SparkContext()\nssc = StreamingContext(sc, 10)\n\nmqttStream = MQTTUtils.createStream(\n ssc, \n \"tcp://localhost:1883\", # Note both port number and protocol\n \"hello\" # The same routing key as used by producer\n)\nmqttStream.count().pprint()\nssc.start()\nssc.awaitTermination()\nssc.stop()\n```\n\n```text\nmvn dependency:get -Dartifact=org.apache.spark:spark-streaming-mqtt_2.11:1.6.1\n```\n\n```text\nspark-submit --packages org.apache.spark:spark-streaming-mqtt_2.11:1.6.1 consumer.py\n```\n\n```text\nrabbitmq-plugins enable rabbitmq_mqtt\n```\n\n```text\nspark-streaming-mqtt\n```\n\n```text\nspark-submit\n```\n\n```text\npyspark\n```\n\n```text\npackages\n```\n\n```text\njars\n```\n\n```text\ndriver-class-path\n```\n\n```text\ntcp://localhost:1883\n```\n\n```text\namq.topic\n```\n\n```text\nDockerfile\n```\n\n```text\nproducer.py\n```\n\n```text\nconsumer.py\n```\n\n```text\nSPARK_HOME\n```\n\n```text\nPYTHONPATH\n```\n\n```text\nconsumer.py\n```\n\n```text\nMqttAsyncClient\n```\n\n```text\ntcp://\n```\n\n```text\nssl://\n```\n\n```text\nlocal://\n```\n\n```text\nbrokerUrl\n```\n\n```text\nMqttAsyncClient\n```\n\n========================================\n\nComments:\n- I attempted to change the producer to use tcp instead of http, however I found that I now get a connection issue of the following: ERROR ReceiverSupervisorImpl: Stopped receiver with error: Connection lost (32109) - java.net.SocketException: Connection reset\n- Thanks. I'll take a look. Can this work with direct and well as topic?\n- MQTT plugin can be configured to use different exchange but as far as I can tell this it. MQTT protocol is not much richer than that anyway.\n- Is there a way to configure this without docker - for example using the .config file. I have tried with the default settings in rabbitmq.com/mqtt.html. But this does not work at all. With no settings, my spark listener can connect with the following: =INFO REPORT==== 5-Jul-2016::11:52:08 === accepting MQTT connection (127.0.0.1:47868 -> 127.0.0.1:1883). But how to make the produced messages map onto this port?\n- Docker is not crucial here but I don't really understand the question. Port is not a property of message. I It is a global property of the server. If topics and exchange match there should be no reason for any issues. What do you mean by \"it doesn't work\"? When you check RabbitMQ UI do you see bindings from producer? How about consumer? Does routing keys match?\n- I had tried using the standard message queue we use. I now tried using the topic without queue and this seems to work right out of the box. However didn't use Docker.\n- This answer is great. Now were are trying a more refined solution. @zero323 however the typical use case we have is a direct exchange with a queue bound to this exchange. I have not seen anyway to make this work sadly. Any suggestions how we might use the direct approach?","metadata":{"transformedAt":"2026-08-18T18:33:20.147Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":36,"totalLines":378,"estimatedTokens":2483}}324{"id":"stack-25619201","source":"stackoverflow","questionId":25619201,"title":"Rabbitmq start fails","tags":["rabbitmq"],"text":"Title: Rabbitmq start fails\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nMy RabbitMQ server went down and it is impossible to restart it. I tried to restart, reinstall it... I still don't understand the error.\nThis is what I get\n\n```\nBOOT FAILED\n\n===========\n\nError description:\n {could_not_start,rabbit,\n {bad_return,\n {{rabbit,start,[normal,[]]},\n {'EXIT',\n {rabbit,failure_during_boot,\n {badmatch,\n {error,\n {{{function_clause,\n [{rabbit_queue_index,journal_minus_segment1,\n [{no_pub,del,no_ack},\n {{>,\n {message_properties,1409712663123302,false},\n true},\n del,ack}],\n [{file,\"src/rabbit_queue_index.erl\"},{line,989}]},\n {rabbit_queue_index,'-journal_minus_segment/2-fun-0-',4,\n [{file,\"src/rabbit_queue_index.erl\"},{line,973}]},\n {array,sparse_foldl_3,7,[{file,\"array.erl\"},{line,1675}]},\n {array,sparse_foldl_2,9,[{file,\"array.erl\"},{line,1669}]},\n {rabbit_queue_index,'-recover_journal/1-fun-0-',1,\n [{file,\"src/rabbit_queue_index.erl\"},{line,701}]},\n {lists,map,2,[{file,\"lists.erl\"},{line,1224}]},\n {rabbit_queue_index,segment_map,2,\n [{file,\"src/rabbit_queue_index.erl\"},{line,819}]},\n {rabbit_queue_index,recover_journal,1,\n [{file,\"src/rabbit_queue_index.erl\"},{line,693}]}]},\n {gen_server2,call,[,out,infinity]}},\n {child,undefined,msg_store_persistent,\n {rabbit_msg_store,start_link,\n [msg_store_persistent,\n \"/var/lib/rabbitmq/mnesia/rabbit@host\",[],\n {#Fun,\n {start,\n [{resource,>,queue,\n >}]}}]},\n transient,4294967295,worker,\n [rabbit_msg_store]}}}}}}}}}\n```\n\nCan anyone help with this?\n\nThanks a lot\n\n========================================\n\nTop Answer:\nI ran into the same issue and this is what helped me. \n\nThe Mnesia files in questions were located in `/var/lib/rabbitmq/`.\n\n========================================\n\nCode:\n```text\nBOOT FAILED\n\n===========\n\nError description:\n {could_not_start,rabbit,\n {bad_return,\n {{rabbit,start,[normal,[]]},\n {'EXIT',\n {rabbit,failure_during_boot,\n {badmatch,\n {error,\n {{{function_clause,\n [{rabbit_queue_index,journal_minus_segment1,\n [{no_pub,del,no_ack},\n {{<<115,254,171,167,171,226,110,171,251,38,217,145,3,12,215,151>>,\n {message_properties,1409712663123302,false},\n true},\n del,ack}],\n [{file,\"src/rabbit_queue_index.erl\"},{line,989}]},\n {rabbit_queue_index,'-journal_minus_segment/2-fun-0-',4,\n [{file,\"src/rabbit_queue_index.erl\"},{line,973}]},\n {array,sparse_foldl_3,7,[{file,\"array.erl\"},{line,1675}]},\n {array,sparse_foldl_2,9,[{file,\"array.erl\"},{line,1669}]},\n {rabbit_queue_index,'-recover_journal/1-fun-0-',1,\n [{file,\"src/rabbit_queue_index.erl\"},{line,701}]},\n {lists,map,2,[{file,\"lists.erl\"},{line,1224}]},\n {rabbit_queue_index,segment_map,2,\n [{file,\"src/rabbit_queue_index.erl\"},{line,819}]},\n {rabbit_queue_index,recover_journal,1,\n [{file,\"src/rabbit_queue_index.erl\"},{line,693}]}]},\n {gen_server2,call,[<0.186.0>,out,infinity]}},\n {child,undefined,msg_store_persistent,\n {rabbit_msg_store,start_link,\n [msg_store_persistent,\n \"/var/lib/rabbitmq/mnesia/rabbit@host\",[],\n {#Fun<rabbit_queue_index.2.132977059>,\n {start,\n [{resource,<<\"/\">>,queue,\n <<\"photos_to_be_tagged_user_36\">>}]}}]},\n transient,4294967295,worker,\n [rabbit_msg_store]}}}}}}}}}\n```\n\n```text\n{badmatch, \n {error, \n {{{function_clause, \n [{rabbit_queue_index,journal_minus_segment1, ...\n```\n\n```text\n/var/lib/rabbitmq/\n```\n\n```text\n...\\AppData\\Roaming\\RabbitMQ\\db\n```\n\n```text\nMnesia\n```\n\n========================================\n\nComments:\n- use sudo to start rabbitmq.\n- I already did. The logs are from the command sudo rabbitmq-server start\n- maybe the problem is mnesia DB, if you can erase your data, try to delete the mnesia DB here /var/lib/rabbitmq/. note : this WILL DELETE all your data stored to the queue.\n- Yes, I did move mnesia and it seems to work now. What was the error? Since I didn't do anything in particular and it has been running fine for the last weeks ...\n- Good question, I don't know exactly, could be an disk error for example. The data-base seems corrupted.\n- Thanks for your help! My whole system seems to be broken though ... This is really obscure, if anybody has an idea, I would appreciate very much an explanation.\n- Please refer my fix in, stackoverflow.com/a/62019910/4817250\n- Thanks. I was worried about doing that, but it recovered nicely. My affected instance is part of a cluster and it synced up with the other one nicely after deleting the queues and msg_store_persistent (in my case) directories.\n- Thanks, after deleting the files, the issue got resolved. And for more info, files will be located under /var/lib/rabbitmq/mnesia/rabbit@/. Here mainly you need to clear the content from these directories msg_store_persistent, msg_store_transient, and queues.","metadata":{"transformedAt":"2026-08-18T18:33:20.147Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":143,"estimatedTokens":1280}}325{"id":"stack-63708061","source":"stackoverflow","questionId":63708061,"title":"How to enable stats in RabbitMQ management UI","tags":["rabbitmq"],"text":"Title: How to enable stats in RabbitMQ management UI\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am running RabbitMQ inside a container on localhost; my /etc/rabbitmq/rabbitmq.conf is pretty straightforward:\n\n```\nloopback_users.guest = false\nlisteners.tcp.default = 5672\nmanagement.tcp.port = 15672\nmanagement.disable_stats = false\n```\n\nI can access management ui with no problem (as a default guest user), but I see no graphs and stats on an Overview tab. And when I enter Channels tab there is only a message:\n\n```\nStats in management UI are disabled on this node\n```\n\nWhat can be the reason of this behaviour?\n\n========================================\n\nTop Answer:\n```\ncd /etc/rabbitmq/conf.d/\necho management_agent.disable_metrics_collector = false > management_agent.disable_metrics_collector.conf\n```\n\nthen restart docker container\nenter image description here\n\n========================================\n\nCode:\n```text\nloopback_users.guest = false\nlisteners.tcp.default = 5672\nmanagement.tcp.port = 15672\nmanagement.disable_stats = false\n```\n\n```text\nStats in management UI are disabled on this node\n```\n\n```text\n# cat /etc/rabbitmq/conf.d/management_agent.disable_metrics_collector.conf \nmanagement_agent.disable_metrics_collector = true\n```\n\n```text\ndocker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management\n```\n\n```text\nrabbitmq_management\n```\n\n```text\ndocker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq\n```\n\n```text\ncd /etc/rabbitmq/conf.d/\necho management_agent.disable_metrics_collector = false > management_agent.disable_metrics_collector.conf\n```\n\n```text\nroot@rabbitmqcontainer:/etc/rabbitmq/conf.d# ls -1\nmanagement_agent.disable_metrics_collector.conf <<<<<<<<<<<<\n\nroot@rabbitmqcontainer:/etc/rabbitmq/conf.d# cat manage*.conf\nmanagement_agent.disable_metrics_collector = true\n```\n\n```text\nCOPY data/etc/rabbitmq/conf.d/zzz_enable_stats.conf /etc/rabbitmq/conf.d/\n```\n\n```text\nmanagement_agent.disable_metrics_collector = false\n```\n\n========================================\n\nComments:\n- Well, adding management_agent.disable_metrics_collector doesn't work for me, but using rabbitmq:3-management does. Thanks a lot!\n- changing the config worked for me, I had to restart my container for the changes to take place\n- This feature is deprecated - rabbitmq.com/release-information/deprecated-features-list One must use Prometheus plugin instead.","metadata":{"transformedAt":"2026-08-18T18:33:20.147Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":91,"estimatedTokens":605}}326{"id":"stack-37625376","source":"stackoverflow","questionId":37625376,"title":"why RabbitMQ shows activity on Message rates but not on Queued messages?","tags":["rabbitmq"],"text":"Title: why RabbitMQ shows activity on Message rates but not on Queued messages?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have this issue, I want to know my rabbit is working great.\n\nI am not gonna send the message, so, Im not 100% sure is being sent correctly. But the problem is this.\n\nAfter all is configured and all....\n\nI see at the RabbitMQ web manager \n\nhttps://i.sstatic.net/qwbsB.png\n\nAnd when I supposedly send a message the I see activity on the \"message rates\" chart but nothing at the \"queued messages\" .\n\nI frankly dont know whats going on, is it too fast that doesnt need to queue the messages? Or something is misconfigured?\n\nAny idea of the difference?\n\nThanks.\n\n========================================\n\nTop Answer:\nIn my case,\n\n### Situation1:\n\nwhen my `Exchange` in `rabbitTemplate.convertAndSend` **was not set properly** -- the message was not sent to the correct queue -- the `Queued messages` was **empty** all time.\n\nhowever, `Message rates` is not zero, it does show there are message get sent.\n\nWhich correspond to what the other answer is saying:\n\nIn case RabbitMQ receive non-routable message it drop it.\n\n### Situation2:\n\nwhen my `Exchange` in `rabbitTemplate.convertAndSend` was **indeed set properly** -- the message was sent to the correct queue -- the `Queued messages` was **queuing up** the message.\n\nEverything seems fine.\n\n### Situation3:\n\n(continue from Situation2)\n\nAnd now, I **turn on** the `receiver service` which has the `@RabbitListener`.\n\nThe `Queued messages` **immediately drops down to 0, and never goes up again**.\n\nBut the transporting of messages is still working fine.\n\n### Situation4:\n\n(continue from Situation2)\n\nAnd now, I change the `receiver service` to use the `rabbitTemplate.receiveAndConvert`.\n\nWhich I **manually** `receive` the message from the `queue` every 2s by using a loop.\n\n- (message is also `sent` from `sender service` every 2s by using a loop, same as the situations before.)\n\nNow, the `Queued messages` **stays at constant** -- a straight line\n\n- (depends on how many message you have queued up, in my case `1`, before the `receiver service` is up, then it stays at `1`).\n\n### Conclusion:\n\n**I suspect that, when the message is consumed too fast, the `Queued messages` will just show 0.**\n\nWhich correspond to what the OP is saying:\n\nis it too fast that doesnt need to queue the messages?\n\n(or, I could screw up some setting in RabbitMQ and led to wrong conclusion. I dont think so, but idk, I am not familiar with RabbitMQ.)\n\n========================================\n\nCode:\n```text\nExchange\n```\n\n```text\nrabbitTemplate.convertAndSend\n```\n\n```text\nQueued messages\n```\n\n```text\nMessage rates\n```\n\n```text\nExchange\n```\n\n```text\nrabbitTemplate.convertAndSend\n```\n\n```text\nQueued messages\n```\n\n```text\nreceiver service\n```\n\n```text\n@RabbitListener\n```\n\n```text\nQueued messages\n```\n\n```text\nreceiver service\n```\n\n```text\nrabbitTemplate.receiveAndConvert\n```\n\n```text\nreceive\n```\n\n```text\nqueue\n```\n\n```text\nsent\n```\n\n```text\nsender service\n```\n\n```text\nQueued messages\n```\n\n```text\n1\n```\n\n```text\nreceiver service\n```\n\n```text\n1\n```\n\n```text\nQueued messages\n```\n\n========================================\n\nComments:\n- I have the same issue. Response below is misleading. Actively messages are sent to my production Q and consumed by consumers properly. But still messages does not show any change where as message rate is showing activity.\n- thanks, and why are they non-routable? is because there is no defined queue for them or because there is no consumer?\n- Non-routable message are messages which are published to exchanges but have no queue to be routed to. To be sure that's your case exactly non-routable message and not something other or even RabbitMQ bug (less likely). You may also have a look at [RabbitMQ official user group ](groups.google.com/forum/#!forum/rabbitmq-users), RabbitMQ staff are active there enough.\n- Ive checked it... any idea how to configure an alternate exchange to catch all non-routable messages?\n- I don't think this is a correct answer. The charts above are from the \"queue\" view, and, besides, TS said: \"I see activity on the \"message rates\"\"; so, if the message cannot be routed, it would not go to this queue at all, right? And it would not show up on \"message rates\". That's something different. I am facing the same problem right now, looks like my message is delivered and acked, but still is not shown on \"queued messages\".\n- If your message goes from exchange to queue and you do ack/nack message or they are timed out by queue length/timeout, Dead Letter Exchanges looks like a solution to catch them and then you can also grasp from message headers why it's get deadlettered.\n- This answer is right. Make sure the routing key exists (I.e. It is the same name as your declared queue)","metadata":{"transformedAt":"2026-08-18T18:33:20.147Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":21,"totalLines":175,"estimatedTokens":1203}}327{"id":"stack-13237628","source":"stackoverflow","questionId":13237628,"title":"RabbitMQ HTTP API call to aliveness-test returns 404 but other calls work","tags":["httprequest","rabbitmq"],"text":"Title: RabbitMQ HTTP API call to aliveness-test returns 404 but other calls work\nTags: httprequest, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nWhen using the HTTP API I am trying to make a call to the aliveness-test for monitoring purposes. At the moment I am testing using curl and the following command:\n\n```\ncurl -i http://guest:guest@localhost:55672/api/aliveness-test/\n```\n\nAnd I get the following response:\n\n```\nHTTP/1.1 404 Object Not Found\nServer: MochiWeb/1.1 WebMachine/1.9.0 (someone had painted it blue)\nDate: Mon, 05 Nov 2012 17:18:58 GMT\nContent-Type: text/html\nContent-Length: 193\n\n404 Not Found\n\n### Not Found\n\nThe requested document was not found on this server.mochiweb+webmachine web server\n```\n\nWhen making a request just to list the users or vhosts, the requests returns successfully:\n\n```\n$ curl -I http://guest:guest@localhost:55672/api/users\n\nHTTP/1.1 200 OK\nServer: MochiWeb/1.1 WebMachine/1.9.0 (someone had painted it blue)\nDate: Mon, 05 Nov 2012 17:51:44 GMT\nContent-Type: application/json\nContent-Length: 11210\nCache-Control: no-cache\n```\n\nI'm using the latest stable version (2.8.7) of RabbitMQ and obviously have the management plugin installed for the API to work with the users call (the response is left out due to it containing company data but is just regular JSON as expected).\n\nThere isn't much on the internet about this call failing so I am wondering if anyone has seen this before?\n\nThanks,\nKristian\n\n========================================\n\nCode:\n```text\ncurl -i http://guest:guest@localhost:55672/api/aliveness-test/\n```\n\n```text\nHTTP/1.1 404 Object Not Found\nServer: MochiWeb/1.1 WebMachine/1.9.0 (someone had painted it blue)\nDate: Mon, 05 Nov 2012 17:18:58 GMT\nContent-Type: text/html\nContent-Length: 193\n\n<HTML><HEAD><TITLE>404 Not Found</TITLE></HEAD><BODY><H1>Not Found</H1>The requested document was not found on this server.<P><HR><ADDRESS>mochiweb+webmachine web server</ADDRESS></BODY></HTML>\n```\n\n```text\n$ curl -I http://guest:guest@localhost:55672/api/users\n\nHTTP/1.1 200 OK\nServer: MochiWeb/1.1 WebMachine/1.9.0 (someone had painted it blue)\nDate: Mon, 05 Nov 2012 17:51:44 GMT\nContent-Type: application/json\nContent-Length: 11210\nCache-Control: no-cache\n```\n\n```text\ncurl -i http://guest:guest@localhost:55672/api/aliveness-test/\n```\n\n```text\ncurl -i http://guest:guest@localhost:55672/api/aliveness-test/%2F\n```\n\n```text\n{\"status\":\"ok\"}\n```\n\n========================================\n\nComments:\n- Port has now changed to 15672 `curl -i http://guest:guest@localhost:15672/api/aliveness-test/%2F`","metadata":{"transformedAt":"2026-08-18T18:33:20.147Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":91,"estimatedTokens":644}}328{"id":"stack-42202437","source":"stackoverflow","questionId":42202437,"title":"RabbitMq: Change x-message-ttl of a queue","tags":["rabbitmq"],"text":"Title: RabbitMq: Change x-message-ttl of a queue\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nHow can I implement a queue with configurable x-message-ttl?\n\nI have a queue with x-message-ttl set to 1 minute and I want to change it to 2 minute at runtime. How can this be achieved?\n\nI already tried declaring queue again with x-message-ttl = 2 minutes but neither ttl is changing by this nor message is being published.\n\n========================================\n\nCode:\n```text\nx-message-ttl\n```\n\n```text\nrabbitmqctl set_policy expiry \".*\" \"{\"\"expires\"\":1800000}\" --apply-to queues\n```\n\n========================================\n\nComments:\n- It will change for all QUEUE ... But is it possible to change in particular queue?\n- @ShiladittyaChakraborty did you manage how to set for a particular queue?\n- @Leonardo I tried curl -i -u guest:guest -H \"content-type:application/json\" -XPUT -d '{\"auto_delete\":false,\"durable\":true,\"arguments\":{\"x-message‌​-ttl\": 3600000}}' localhost:15672/api/queues/vhost/queue_name received the value '3600000' of type 'long' but current is none. Looks like it will not work on existing single queue (unable to change arguments) also noticed if set_policy, then it appears in the policy section of admin console, not on each queue, different from set arguments upon creation of queue.\n- For setting a particular policy for just one queue you can set the regex pattern to your queue name (in @Gabriele example it is the regex string `\".*\"`). So if your queue is named Foo you would just set the regex pattern to be exactly \"Foo\". See this doc for more help on specifics.\n- one important thing to mention. When setting ttl for queue, it won't apply to the messages, that are already landed in queue. It will apply only for new messages added after policy created.","metadata":{"transformedAt":"2026-08-18T18:33:20.147Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":30,"estimatedTokens":451}}329{"id":"stack-46872274","source":"stackoverflow","questionId":46872274,"title":"Spring RabbitTemplate - How to create queues automatically upon send","tags":["java","spring","rabbitmq","spring-amqp","spring-rabbit"],"text":"Title: Spring RabbitTemplate - How to create queues automatically upon send\nTags: java, spring, rabbitmq, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI am using RabbitMQ together with Spring's RabbitTemplate.\n\nWhen sending messages to queues using the template send methods, I want the queue to automatically be created/declared if it is not already exists.\n\nIt is very important since according to our business logic queue names are generated on run-time and I cannot declare them in advance.\n\nPreviously we have used JmsTemplate and any call to send or receive automatically created the queue.\n\n========================================\n\nTop Answer:\nYou can use a RabbitAdmin to automatically declare the exchange, queue, and binding. Check out this thread for more detail. This forum also bit related to your scenario. I have not tried spring with AMQP though, but I believe this would do it.\n\n```\n/**\n * Required for executing adminstration functions against an AMQP Broker\n */\n@Bean\npublic AmqpAdmin amqpAdmin() {\n return new RabbitAdmin(connectionFactory());\n}\n```\n\nKeep coding !\n\n========================================\n\nCode:\n```text\nRabbitAdmin\n```\n\n```text\nadmin.getQueueProperties()\n```\n\n```text\nadmin.declareQueue(new Queue(...))\n```\n\n```text\n/**\n * Required for executing adminstration functions against an AMQP Broker\n */\n@Bean\npublic AmqpAdmin amqpAdmin() {\n return new RabbitAdmin(connectionFactory());\n}\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.147Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":54,"estimatedTokens":361}}330{"id":"stack-40957599","source":"stackoverflow","questionId":40957599,"title":"How to find RabbitMQ URL?","tags":["rabbitmq","celery"],"text":"Title: How to find RabbitMQ URL?\nTags: rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nRabbit MQ URL looks like :\n\n```\nBROKER_URL: \"amqp://user:password@remote.server.com:port//vhost\"\n```\n\nThis is not clear where we can find the URL, login and password of RabbitMQ\nwhen we need to acccess from remote worker (outside of Localhost).\n\nIn other way, how to set RabbitMQ IP adress, login and password from Celery / RabbitMQ\n\n========================================\n\nTop Answer:\nTo add to the accepted answer:\n\n- As of 2022, the default username and password are `guest`\n\n- In my experience, ignoring `vhost` is safe while getting started with RabbitMQ\n\n- If using RabbitMQ as part of a Docker Compose setup (e.g. for testing), other containers in the same application should be able to access RabbitMQ via its service name. For example, if the name of the service in `docker-compose.yml` is `rabbitmq`, passing `amqp://guest:guest@rabbitmq:5672/` should work\n\n========================================\n\nCode:\n```text\nBROKER_URL: \"amqp://user:password@remote.server.com:port//vhost\"\n```\n\n```text\nguest\n```\n\n```text\nvhost\n```\n\n```text\ndocker-compose.yml\n```\n\n```text\nrabbitmq\n```\n\n```text\namqp://guest:guest@rabbitmq:5672/\n```\n\n========================================\n\nComments:\n- Where do you get this information from? You should check your `celeryconfig.py` and also your `app.py`. See stackoverflow.com/q/19938719/6372139 for more information.\n- But, it does not indicate the Ip adress of RabbitMQ server\n- What /dev means ? How/Where can we setup ? What about firewall access ?\n- dev is the virtual host(vhost). It can be used to segregate different application to run on same RabbitMQ server with different access policies. The default vhost is \"/\" (without quotes).\n- Firewall Access, you need to enable access to 5672 port. Setup what? the management plugin?","metadata":{"transformedAt":"2026-08-18T18:33:20.147Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":62,"estimatedTokens":466}}331{"id":"stack-38900125","source":"stackoverflow","questionId":38900125,"title":"Windows could not start the RabbitMQ Service on local Computer","tags":["erlang","rabbitmq","message-queue"],"text":"Title: Windows could not start the RabbitMQ Service on local Computer\nTags: erlang, rabbitmq, message-queue\nSource: Stack Overflow\n\nQuestion:\nI am trying to start RabbitMQ service on my local Windows laptop but I keep getting this error:\n\nhttps://i.sstatic.net/gBu2K.jpg\n\nI first downloaded erlang (OTP 19.0 Windows 64-bit Binary File) from here: http://www.erlang.org/downloads. \nThen I downloaded RabbitMQ from here: https://www.rabbitmq.com/install-windows.html\n\nErlang seems to have installed correctly - I don't see any errors in the logs. RabbitMQ shows this message in the installation logs:\n\n```\nInstalling RabbitMQ service...\nThe filename, directory name, or volume label syntax is incorrect.\nThe filename, directory name, or volume label syntax is incorrect.\nThe filename, directory name, or volume label syntax is incorrect.\nC:\\Program Files\\erl8.0\\erts-8.0\\bin\\erlsrv: Service RabbitMQ added to system.\nError spawning C:\\Program Files\\erl8.0\\erts-8.0\\bin\\epmd -daemon (error 0)\nStarting RabbitMQ service...\nThe filename, directory name, or volume label syntax is incorrect.\nThe filename, directory name, or volume label syntax is incorrect.\nThe filename, directory name, or volume label syntax is incorrect.\nC:\\Program Files\\erl8.0\\erts-8.0\\bin\\erlsrv: Failed to start service RabbitMQ.\nError: The process terminated unexpectedly.\n```\n\nI uninstalled both, restarted my laptop and reinstalled but still doesn't work.\n\nI also added Firewall Rules but still no luck. The 2nd firewall rule is for allowing connection for these ports: 4369, 25672, 5672, 5671, 15672, 61613, 61614, 1883, 8883\n\nhttps://i.sstatic.net/NK473.jpg\n\n========================================\n\nTop Answer:\n```\nOpen the command prompt and run the following commands one by one:\n\nc:\\>cd\\ \nc:\\>cd Program Files \nc:\\Program Files>cd RabbitMQ Server \nc:\\Program Files\\RabbitMQ Server>dir \nc:\\Program Files\\RabbitMQ Server>cd rabbitmq_server-3.8.1 \nc:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.8.1>dir \nc:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.8.1>cd sbin \nc:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.8.1\\sbin>dir \nc:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.8.1\\sbin>SET HOMEDRIVE=C:\n\nc:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.8.1\\sbin>rabbitmq-service enable\n\nc:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.8.1\\sbin>rabbitmq-plugins enable rabbitmq_management\n```\n\nand please make sure that you have copied the .erlang.cookie from c:\\Windows to the root of your user folder ( C:\\Users{user}\\ )\n\n========================================\n\nCode:\n```text\nInstalling RabbitMQ service...\nThe filename, directory name, or volume label syntax is incorrect.\nThe filename, directory name, or volume label syntax is incorrect.\nThe filename, directory name, or volume label syntax is incorrect.\nC:\\Program Files\\erl8.0\\erts-8.0\\bin\\erlsrv: Service RabbitMQ added to system.\nError spawning C:\\Program Files\\erl8.0\\erts-8.0\\bin\\epmd -daemon (error 0)\nStarting RabbitMQ service...\nThe filename, directory name, or volume label syntax is incorrect.\nThe filename, directory name, or volume label syntax is incorrect.\nThe filename, directory name, or volume label syntax is incorrect.\nC:\\Program Files\\erl8.0\\erts-8.0\\bin\\erlsrv: Failed to start service RabbitMQ.\nError: The process terminated unexpectedly.\n```\n\n```text\nSET HOMEDRIVE=C:\n```\n\n```text\nrabbitmq-service stop\nrabbitmq-service remove\nrabbitmq-service install\nrabbitmq-service start\n```\n\n```text\nOpen the command prompt and run the following commands one by one:\n\nc:\\>cd\\ \nc:\\>cd Program Files \nc:\\Program Files>cd RabbitMQ Server \nc:\\Program Files\\RabbitMQ Server>dir \nc:\\Program Files\\RabbitMQ Server>cd rabbitmq_server-3.8.1 \nc:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.8.1>dir \nc:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.8.1>cd sbin \nc:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.8.1\\sbin>dir \nc:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.8.1\\sbin>SET HOMEDRIVE=C:\n\nc:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.8.1\\sbin>rabbitmq-service enable\n\nc:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.8.1\\sbin>rabbitmq-plugins enable rabbitmq_management\n```\n\n```text\nrabbitmq-service start\n```\n\n```text\nrabbitmq-service install\n```\n\n```text\nrabbitmq-service remove\n\nrabbitmq-service install\n\nrabbitmq-service start\n```\n\n========================================\n\nComments:\n- Seems like you are trying to install RabbitMQ in a folder that does not exist.\n- Can you post the directory name when you are trying to install RMQ? does the folder contains spaces or other special characters?\n- @Gabriele By default dir name was \"RabbitMQ Server\" I uninstalled and reinstalled to \"RabbitMQ\" still the same issue. Thanks\n- This will work for the RabbitMQ service start issue\n- Thank you very much! First I installed the wrong version (incompatible with current version of RabbitMQ), and then the registry kept pointing to the wrong one after installing the correct one. Also if somebody else stumbles upon this: make sure to go to Erlang installation directory and delete the offending version.","metadata":{"transformedAt":"2026-08-18T18:33:20.147Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":129,"estimatedTokens":1272}}332{"id":"stack-22103401","source":"stackoverflow","questionId":22103401,"title":"Django, RabbitMQ, & Celery - why does Celery run old versions of my tasks after I update my Django code in development?","tags":["python","django","rabbitmq","celery","django-celery"],"text":"Title: Django, RabbitMQ, & Celery - why does Celery run old versions of my tasks after I update my Django code in development?\nTags: python, django, rabbitmq, celery, django-celery\nSource: Stack Overflow\n\nQuestion:\nSo I have a Django app that occasionally sends a task to Celery for asynchronous execution. I've found that as I work on my code in development, the Django development server knows how to automatically detect when code has changed and then restart the server so I can see my changes. However, the RabbitMQ/Celery section of my app doesn't pick up on these sorts of changes in development. If I change code that will later be run in a Celery task, Celery will still keep running the old version of the code. The only way I can get it to pick up on the change is to:\n\n- stop the Celery worker\n\n- stop RabbitMQ\n\n- reset RabbitMQ\n\n- start RabbitMQ\n\n- add the user to RabbitMQ that my Django app is configured to use\n\n- set appropriate permissions for this user\n\n- restart the Celery worker\n\nThis seems like a far more drastic approach than I should have to take, however. Is there a more lightweight approach I can use?\n\n========================================\n\nComments:\n- Sorry, i have the same issue. I restart the worker by `/etc/init.d/celeryd restart`. Mostly, it works. But sometimes not, even if i restart my server.","metadata":{"transformedAt":"2026-08-18T18:33:20.147Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":27,"estimatedTokens":337}}333{"id":"stack-25701094","source":"stackoverflow","questionId":25701094,"title":"Scaling WebSockets with a Message Queue","tags":["sockets","websocket","rabbitmq","zeromq","publish-subscribe"],"text":"Title: Scaling WebSockets with a Message Queue\nTags: sockets, websocket, rabbitmq, zeromq, publish-subscribe\nSource: Stack Overflow\n\nQuestion:\nI have built a `WebSockets` server that acts as a chat message router (i.e. receiving messages from clients and pushing them to other clients according to a client `ID`). \n\nIt is a requirement that the service be able to scale to handle many millions of concurrent open socket connections, and I wish to be able to horizontally scale the server.\n\nThe architecture I have had in mind is to put the websocket server nodes behind a load balancer, which will create a problem because clients connected to different nodes won't know about each other. While both clients `A` and `B` enter via the `LoadBalancer`, client `A` might have an open connection with node `1` while client `B` is connected to node `2` - each node holds it's own dictionary of open socket connections. \n\nTo solve this problem, I was thinking of using some MQ system like `ZeroMQ` or `RabbitMQ`. All of the websocket server nodes will be subscribers of the MQ server, and when a node gets a request to route a message to a client which is not in the local connections dictionary, it will **`pub`**-lish a message to the MQ server, which will tell all the **`sub`**-scriber nodes to look for this client and issue the message if it's connected to that node. \n\n`Q1:` Does this architecture make sense?\n\n`Q2:` Is the **`pub-sub`** pattern described here really what I am looking for?\n\n========================================\n\nTop Answer:\nTo update this for 2021, we just solved this problem where we needed to design a system that could handle millions of simultaneous WS connections from IoT devices. The WS server just relays messages to our Serverless API backend that handles the actual logic. We chose to use docker and the node `ws` package using an auto-scaling AWS ECS Fargate cluster with an ALB in front of it.\n\nThis solved the main problem of routing messages, but then we had the same issue of how do we route response messages from the server. We initially thought of just keeping a central DB of connections, but routing messages to a specific Fargate instance behind an ALB didn't seem feasible.\n\nInstead, we set up a simple sub/pub pattern using AWS SNS (https://aws.amazon.com/pub-sub-messaging/). Every WS server receives the response and then searches its own WS connections. Since each Fargate instance handles just routing (no logic), they can handle a lot of connections when we vertically scale them.\n\n**Update:** To make this even more performant, you can use a persistent connection like Redis Pub/Sub to allow the response message to only go to one single server instead of every server.\n\n========================================\n\nCode:\n```text\nWebSockets\n```\n\n```text\nID\n```\n\n```text\nA\n```\n\n```text\nB\n```\n\n```text\nLoadBalancer\n```\n\n```text\nA\n```\n\n```text\n1\n```\n\n```text\nB\n```\n\n```text\n2\n```\n\n```text\nZeroMQ\n```\n\n```text\nRabbitMQ\n```\n\n```text\npub\n```\n\n```text\nsub\n```\n\n```text\nQ1:\n```\n\n```text\nQ2:\n```\n\n```text\npub-sub\n```\n\n```text\nPUB\n```\n\n```text\nSUB\n```\n\n```text\nws\n```\n\n========================================\n\nComments:\n- are you building a chat? do you also need to redirect the messages to mobile device?\n- yes (the system is chat like and it should work on Chrome for Android)\n- It is just OT, but have you considered to use XMPP?\n- @Gas I want to be able to connect directly from my html client to the service using WebSockets (clientA -> Load Balancer -> WS_nodeA -> MQ -> WS_nodeB -> clientB) so XMPP is not an option as far as I can gather\n- I have a doubt. In the redis pub/sub mechanism how will you decide which server to send the message to? In the SNS, we were sending the message to all the servers because we didn't know which server the client is connected to...\n- We set it up with each device being a topic, and then the device subscribed to that topic. If I remember correctly, Redis Pub/Sub uses WebSockets behind the scenes, so it has a persistent connection. Since we are using it with IoT devices that can scale quickly, we monitor the maximum connection amount (redis.io/docs/reference/clients). If you were dealing with millions of potential connections, it might be better just to publish a message to every server, but our initial thoughts were to reduce the extra noise by doing that.\n- As another update, we recently migrated to Kafka for this action to push messages to all servers again. It's a little noisier, but it eliminates technical complexity around needing a persistent connection.","metadata":{"transformedAt":"2026-08-18T18:33:20.147Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":19,"totalLines":117,"estimatedTokens":1140}}334{"id":"stack-45327819","source":"stackoverflow","questionId":45327819,"title":"RabbitMQ: dropping messages when no consumers are connected","tags":["rabbitmq","amqp"],"text":"Title: RabbitMQ: dropping messages when no consumers are connected\nTags: rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI'm trying to setup RabbitMQ in a model where there is only one producer and one consumer, and where messages sent by the producer are delivered to the consumer only if the consumer is connected, but dropped if the consumer is not present.\n\nBasically I want the queue to drop all the messages it receives when no consumer is connected to it. \n\nAn additional constraint is that the queue must be declared on the RabbitMQ server side, and must not be explicitly created by the consumer or the producer.\n\nIs that possible?\n\nI've looked at a few things, but I can't seem to make it work:\n\n- durable vs non-durable does not work, because it is only useful when the broker restarts. I need the same effect but on a connection.\n\n- setting `auto_delete` to true on the queue means that my client can never connect to this queue again.\n\n- `x-message-ttl` and `max-length` make it possible to lose message even when there is a consumer connected.\n\n- I've looked at topic exchanges, but as far as I can tell, these only affect the routing of messages between the exchange and the queue based on the message content, and can't take into account whether or not a queue has connected consumers.\n\nThe effect that I'm looking for would be something like `auto_delete` on disconnect, and `auto_create` on connect. Is there a mechanism in rabbitmq that lets me do that?\n\n========================================\n\nTop Answer:\nYou can not doing it directly, but there is a mechanism not dificult to implement.\n\nYou have to enable the Event Exchange Plugin. This is a exchange at which your server app can connect and will receive internal events of RabbitMQ. You would be interested in the consumer.created and consumer.deleted events.\n\nWhen these events are received you can trigger an action (create or delete the queue you need). More information here: https://www.rabbitmq.com/event-exchange.html\n\nHope this helps.\n\n========================================\n\nCode:\n```text\nauto_delete\n```\n\n```text\nx-message-ttl\n```\n\n```text\nmax-length\n```\n\n```text\nauto_delete\n```\n\n```text\nauto_create\n```\n\n```text\nx-message-ttl\n```\n\n```text\nx-message-ttl\n```\n\n```text\n0\n```\n\n========================================\n\nComments:\n- @Jesferman solution is good, based on the constraints indicated in your question. But I'm curious: why can't your consumer create the queue? Would it be ok if the queue was there, but bound (and unbound) by your consumer?\n- My consumer can't create the queue because I'm trying to simulate the behavior of an external broker provided by another company (for automated testing purposes). My consumer is not allowed to create queues on the external broker, so my test environment must reflect that fact.","metadata":{"transformedAt":"2026-08-18T18:33:20.147Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":76,"estimatedTokens":705}}335{"id":"stack-47918407","source":"stackoverflow","questionId":47918407,"title":"Microservice architecture - carry message through services when order doesn't matter","tags":["design-patterns","architecture","rabbitmq","message-queue","microservices"],"text":"Title: Microservice architecture - carry message through services when order doesn't matter\nTags: design-patterns, architecture, rabbitmq, message-queue, microservices\nSource: Stack Overflow\n\nQuestion:\n**Tl;dr**: \"How can I push a message through a bunch of asynchronous, unordered microservices and know when that message has made it through each of them?\"\n\nI'm struggling to find the right messaging system/protocol for a specific microservices architecture. This isn't a \"which is best\" question, but a question about what my options are for a design pattern/protocol.\n\nhttps://i.sstatic.net/MbHRf.png\n\n- I have a *message* on the beginning queue. Let's say a RabbitMQ message with serialized JSON\n\n- I need that message to go through an arbitrary number of microservices\n\n- Each of those microservices are long running, must be independent, and may be implemented in a variety of languages\n\n- The order of services the message goes through does not matter. In fact, it should not be synchronous.\n\n- Each service can *append* data to the original message, but that data is ignored by the other services. There should be *no* merge conflicts (each service writes a unique key). No service will change or destroy data.\n\n- Once *all the services have had their turn*, the message should be published to a second RabbitMQ queue with the original data and the new data.\n\n- The microservices will have no other side-effects. If this were all in one monolithic application (and in the same language), functional programming would be perfect.\n\nSo, the question is, what is an appropriate way to manage that message through the various services? I **don't** want to have to do one at a time, and the order isn't important. But, if that's the case, how can the system know when all the services have had their whack and the final message can be written onto the ending queue (to have the next batch of services have their go).\n\nThe only, semi-elegant solution I could come up with was \n\n- to have the first service that encounters a message write that message to common storage (say mongodb)\n\n- Have each service do its thing, mark that it has completed for that message, and then check to see if all the services have had their turn\n\n- If so, that last service would publish the message\n\nBut that still requires each service to be aware of all the other services *and* requires each service to leave its mark. Neither of those is desired.\n\nI am open to a \"Shepherd\" service of some kind.\n\nI would appreciate any options that I have missed, and am willing to concede that their may be a better, fundamental design.\n\nThank you.\n\n========================================\n\nTop Answer:\nI would go along the common storage idea.\n\nHave each microservice register itself with the common storage. Have each microservice register it has processed the message identifier when it does.\n\nYou can work out which n services should process it and how many of the n service have processed it.\n\nNo services need to be aware of each other.\n\n========================================\n\nComments:\n- Wow, what a wonderfully thorough answer. I'm trying to wrap my head around your anwer and the article. The diagram above is actually only one step in a larger ETL pipeline. I'm thinking that \"reactive between services and orchestration within a service\" may make the most sense here.\n- So, in reading up on orchestration, it seems appropriate and exciting, but I still don't understand how I can write the final \"Ending Queue\" after all the services have had there whack. How can I know that each service has had their shot?\n- @Apollo in this case the Orchestrator writes/updates the status of the overall process after it receives the response from upstream microservice.\n- Ah, so each service notifies the orchestrator when it is done, and the orchestrator knows which services there are and therefore, can publish the final result. That is brilliant. Thank you!","metadata":{"transformedAt":"2026-08-18T18:33:20.148Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":61,"estimatedTokens":984}}336{"id":"stack-40021066","source":"stackoverflow","questionId":40021066,"title":"How can I queue a task to Celery from C#?","tags":["c#","python","rabbitmq","celery","task-queue"],"text":"Title: How can I queue a task to Celery from C#?\nTags: c#, python, rabbitmq, celery, task-queue\nSource: Stack Overflow\n\nQuestion:\nAs I understand message brokers like RabbitMQ facilitates different applications written in different language/platform to communicate with each other. So since celery can use RabbitMQ as message broker, I believe we can queue task from any application to Celery, even though the producer isn't written in Python.\n\nNow I am trying to figure out how I can queue a task to Celery from an application written in C# via RabbitMQ. But I could not find any such example yet.\n\nThe only information close to this I found is this SO question\n\nWhere the accepted answer suggests to use the Celery message format protocol to queue messages to RabbitMQ from Java. However, the link given in the answer does not have any example, only the message format.\n\nAlso, the message format says task id (UUID) is required to communicate in this protocol. How is my C# application supposed to know the task id of the celery task? As I understand it can only know about the task name, but not the task id.\n\n========================================\n\nTop Answer:\nI don't know whether the question is still relevant, but hopefully the answer will help others.\n\nHere is how I succeeded in queening a task to Celery example worker.\n\nYou'll need to establish connection between your producer(client) to RabbitMQ as described here.\n\n```\nConnectionFactory factory = new ConnectionFactory();\n factory.UserName = username;\n factory.Password = password;\n factory.VirtualHost = virtualhost;\n factory.HostName = hostname;\n factory.Port = port;\n\n IConnection connection = factory.CreateConnection();\n IModel channel = connection.CreateModel();\n```\n\nIn default RabbitMQ configuration there is only *Guest* user which can only be used for local connections (from 127.0.0.1). An answer to this question explains how to define users in RabbitMQ.\n\nNext - creating a callback to get results. This example is using Direct reply-to, so an answer listener will look like:\n\n```\nvar consumer = new EventingBasicConsumer(channel);\n consumer.Received += (model, ea) =>\n {\n var ansBody = ea.Body;\n var ansMessage = Encoding.UTF8.GetString(ansBody);\n Console.WriteLine(\" [x] Received {0}\", ansMessage);\n Console.WriteLine(\" [x] Done\");\n };\n channel.BasicConsume(queue: \"amq.rabbitmq.reply-to\", noAck: true, consumer: consumer);\n```\n\nCreating a task message that Celery will consume:\n\n```\nIDictionary headers = new Dictionary();\n headers.Add(\"task\", \"tasks.add\");\n Guid id = Guid.NewGuid();\n headers.Add(\"id\", id.ToString());\n\n IBasicProperties props = channel.CreateBasicProperties();\n props.Headers = headers;\n props.CorrelationId = (string)headers[\"id\"];\n props.ContentEncoding = \"utf-8\";\n props.ContentType = \"application/json\";\n props.ReplyTo = \"amq.rabbitmq.reply-to\";\n\n object[] taskArgs = new object[] { 1, 200 };\n\n object[] arguments = new object[] { taskArgs, new object(), new object()};\n\n MemoryStream stream = new MemoryStream();\n DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(object[]));\n ser.WriteObject(stream, arguments);\n stream.Position = 0;\n StreamReader sr = new StreamReader(stream);\n string message = sr.ReadToEnd();\n\n var body = Encoding.UTF8.GetBytes(message);\n```\n\nAnd finally, publishing the message to RabbitMQ:\n\n```\nchannel.BasicPublish(exchange: \"\",\n routingKey: \"celery\",\n basicProperties: props,\n body: body);\n```\n\n========================================\n\nCode:\n```text\nConnectionFactory factory = new ConnectionFactory();\n factory.UserName = username;\n factory.Password = password;\n factory.VirtualHost = virtualhost;\n factory.HostName = hostname;\n factory.Port = port;\n\n IConnection connection = factory.CreateConnection();\n IModel channel = connection.CreateModel();\n```\n\n```text\nvar consumer = new EventingBasicConsumer(channel);\n consumer.Received += (model, ea) =>\n {\n var ansBody = ea.Body;\n var ansMessage = Encoding.UTF8.GetString(ansBody);\n Console.WriteLine(\" [x] Received {0}\", ansMessage);\n Console.WriteLine(\" [x] Done\");\n };\n channel.BasicConsume(queue: \"amq.rabbitmq.reply-to\", noAck: true, consumer: consumer);\n```\n\n```text\nIDictionary<string, object> headers = new Dictionary<string, object>();\n headers.Add(\"task\", \"tasks.add\");\n Guid id = Guid.NewGuid();\n headers.Add(\"id\", id.ToString());\n\n IBasicProperties props = channel.CreateBasicProperties();\n props.Headers = headers;\n props.CorrelationId = (string)headers[\"id\"];\n props.ContentEncoding = \"utf-8\";\n props.ContentType = \"application/json\";\n props.ReplyTo = \"amq.rabbitmq.reply-to\";\n\n object[] taskArgs = new object[] { 1, 200 };\n\n object[] arguments = new object[] { taskArgs, new object(), new object()};\n\n MemoryStream stream = new MemoryStream();\n DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(object[]));\n ser.WriteObject(stream, arguments);\n stream.Position = 0;\n StreamReader sr = new StreamReader(stream);\n string message = sr.ReadToEnd();\n\n var body = Encoding.UTF8.GetBytes(message);\n```\n\n```text\nchannel.BasicPublish(exchange: \"\",\n routingKey: \"celery\",\n basicProperties: props,\n body: body);\n```\n\n========================================\n\nComments:\n- Looking to implement the same functionality. Were you successful with this ?\n- @Igor..Thanks for the answer, please could you create a github gist showing the celery code that accepts the task.\n- @FrankDupree, It's very simple. Basic example in Celery documentation is what you are looking for. It also includes steps to setup and run a worker.\n- @IgorKleinerman planning to use this to have a C# API pass work to be done to Pandas functions.. Have you had any issues with this approach?","metadata":{"transformedAt":"2026-08-18T18:33:20.148Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":158,"estimatedTokens":1468}}337{"id":"stack-20894771","source":"stackoverflow","questionId":20894771,"title":"Celery Beat: Limit to single task instance at a time","tags":["python","concurrency","rabbitmq","celery","celerybeat"],"text":"Title: Celery Beat: Limit to single task instance at a time\nTags: python, concurrency, rabbitmq, celery, celerybeat\nSource: Stack Overflow\n\nQuestion:\nI have celery beat and celery (four workers) to do some processing steps in bulk. One of those tasks is roughly along the lines of, \"for each X that hasn't had a Y created, create a Y.\"\n\nThe task is run periodically at a semi-rapid rate (10sec). The task completes very quickly. There are other tasks going on as well.\n\nI've run into the issue multiple times in which the beat tasks apparently become backlogged, and so the same task (from different beat times) are executed simultaneously, causing incorrectly duplicated work. It also appears that the tasks are executed out-of-order.\n\nIs it possible to limit celery beat to ensure only one outstanding instance of a task at a time? Is setting something like `rate_limit=5` on the task the \"correct\" way to of doing this?\n\nIs it possible to ensure that beat tasks are executed in-order, e.g. instead of dispatching a task, beat adds it to a task chain?\n\nWhat's the best way of handling this, short of making those tasks themselves execute atomically and are safe to be executed concurrently? That was not a restriction I would have expected of beat tasks…\n\nThe task itself is defined naïvely:\n\n```\n@periodic_task(run_every=timedelta(seconds=10))\ndef add_y_to_xs():\n # Do things in a database\n return\n```\n\nHere's an actual (cleaned) log:\n\n- `[00:00.000]` foocorp.tasks.add_y_to_xs sent. id->#1\n\n- `[00:00.001]` Received task: foocorp.tasks.add_y_to_xs[#1]\n\n- `[00:10.009]` foocorp.tasks.add_y_to_xs sent. id->#2\n\n- `[00:20.024]` foocorp.tasks.add_y_to_xs sent. id->#3\n\n- `[00:26.747]` Received task: foocorp.tasks.add_y_to_xs[#2]\n\n- `[00:26.748]` TaskPool: Apply #2\n\n- `[00:26.752]` Received task: foocorp.tasks.add_y_to_xs[#3]\n\n- `[00:26.769]` Task accepted: foocorp.tasks.add_y_to_xs[#2] pid:26528\n\n- `[00:26.775]` Task foocorp.tasks.add_y_to_xs[#2] succeeded in 0.0197986490093s: None\n\n- `[00:26.806]` TaskPool: Apply #1\n\n- `[00:26.836]` TaskPool: Apply #3\n\n- `[01:30.020]` Task accepted: foocorp.tasks.add_y_to_xs[#1] pid:26526\n\n- `[01:30.053]` Task accepted: foocorp.tasks.add_y_to_xs[#3] pid:26529\n\n- `[01:30.055]` foocorp.tasks.add_y_to_xs[#1]: Adding Y for X id #9725\n\n- `[01:30.070]` foocorp.tasks.add_y_to_xs[#3]: Adding Y for X id #9725\n\n- `[01:30.074]` Task foocorp.tasks.add_y_to_xs[#1] succeeded in 0.0594762689434s: None\n\n- `[01:30.087]` Task foocorp.tasks.add_y_to_xs[#3] succeeded in 0.0352867960464s: None\n\nWe're currently using Celery 3.1.4 with RabbitMQ as the transport.\n\n**EDIT** Dan, here's what I came up with:\n\nDan, here's what I ended up using:\n\n```\nfrom sqlalchemy import func\nfrom sqlalchemy.exc import DBAPIError\nfrom contextlib import contextmanager\n\ndef _psql_advisory_lock_blocking(conn, lock_id, shared, timeout):\n lock_fn = (func.pg_advisory_xact_lock_shared\n if shared else\n func.pg_advisory_xact_lock)\n if timeout:\n conn.execute(text('SET statement_timeout TO :timeout'),\n timeout=timeout)\n try:\n conn.execute(select([lock_fn(lock_id)]))\n except DBAPIError:\n return False\n return True\n\ndef _psql_advisory_lock_nonblocking(conn, lock_id, shared):\n lock_fn = (func.pg_try_advisory_xact_lock_shared\n if shared else\n func.pg_try_advisory_xact_lock)\n return conn.execute(select([lock_fn(lock_id)])).scalar()\n\nclass DatabaseLockFailed(Exception):\n pass\n\n@contextmanager\ndef db_lock(engine, name, shared=False, block=True, timeout=None):\n \"\"\"\n Context manager which acquires a PSQL advisory transaction lock with a\n specified name.\n \"\"\"\n lock_id = hash(name)\n\n with engine.begin() as conn, conn.begin():\n if block:\n locked = _psql_advisory_lock_blocking(conn, lock_id, shared,\n timeout)\n else:\n locked = _psql_advisory_lock_nonblocking(conn, lock_id, shared)\n if not locked:\n raise DatabaseLockFailed()\n yield\n```\n\nAnd the celery task decorator (used only for periodic tasks):\n\n```\nfrom functools import wraps\nfrom preo.extensions import db\n\ndef locked(name=None, block=True, timeout='1s'):\n \"\"\"\n Using a PostgreSQL advisory transaction lock, only runs this task if the\n lock is available. Otherwise logs a message and returns `None`.\n \"\"\"\n def with_task(fn):\n lock_id = name or 'celery:{}.{}'.format(fn.__module__, fn.__name__)\n\n @wraps(fn)\n def f(*args, **kwargs):\n try:\n with db_lock(db.engine, name=lock_id, block=block,\n timeout=timeout):\n return fn(*args, **kwargs)\n except DatabaseLockFailed:\n logger.error('Failed to get lock.')\n return None\n return f\n return with_task\n```\n\n========================================\n\nTop Answer:\n```\nfrom functools import wraps\nfrom celery import shared_task\n\ndef skip_if_running(f):\n task_name = f'{f.__module__}.{f.__name__}'\n\n @wraps(f)\n def wrapped(self, *args, **kwargs):\n workers = self.app.control.inspect().active()\n\n for worker, tasks in workers.items():\n for task in tasks:\n if (task_name == task['name'] and\n tuple(args) == tuple(task['args']) and\n kwargs == task['kwargs'] and\n self.request.id != task['id']):\n print(f'task {task_name} ({args}, {kwargs}) is running on {worker}, skipping')\n\n return None\n\n return f(self, *args, **kwargs)\n\n return wrapped\n\n@shared_task(bind=True)\n@skip_if_running\ndef test_single_task(self):\n pass\n\ntest_single_task.delay()\n```\n\n========================================\n\nCode:\n```text\n@periodic_task(run_every=timedelta(seconds=10))\ndef add_y_to_xs():\n # Do things in a database\n return\n```\n\n```py\nfrom sqlalchemy import func\nfrom sqlalchemy.exc import DBAPIError\nfrom contextlib import contextmanager\n\n\ndef _psql_advisory_lock_blocking(conn, lock_id, shared, timeout):\n lock_fn = (func.pg_advisory_xact_lock_shared\n if shared else\n func.pg_advisory_xact_lock)\n if timeout:\n conn.execute(text('SET statement_timeout TO :timeout'),\n timeout=timeout)\n try:\n conn.execute(select([lock_fn(lock_id)]))\n except DBAPIError:\n return False\n return True\n\n\ndef _psql_advisory_lock_nonblocking(conn, lock_id, shared):\n lock_fn = (func.pg_try_advisory_xact_lock_shared\n if shared else\n func.pg_try_advisory_xact_lock)\n return conn.execute(select([lock_fn(lock_id)])).scalar()\n\n\nclass DatabaseLockFailed(Exception):\n pass\n\n\n@contextmanager\ndef db_lock(engine, name, shared=False, block=True, timeout=None):\n \"\"\"\n Context manager which acquires a PSQL advisory transaction lock with a\n specified name.\n \"\"\"\n lock_id = hash(name)\n\n with engine.begin() as conn, conn.begin():\n if block:\n locked = _psql_advisory_lock_blocking(conn, lock_id, shared,\n timeout)\n else:\n locked = _psql_advisory_lock_nonblocking(conn, lock_id, shared)\n if not locked:\n raise DatabaseLockFailed()\n yield\n```\n\n```text\nfrom functools import wraps\nfrom preo.extensions import db\n\n\ndef locked(name=None, block=True, timeout='1s'):\n \"\"\"\n Using a PostgreSQL advisory transaction lock, only runs this task if the\n lock is available. Otherwise logs a message and returns `None`.\n \"\"\"\n def with_task(fn):\n lock_id = name or 'celery:{}.{}'.format(fn.__module__, fn.__name__)\n\n @wraps(fn)\n def f(*args, **kwargs):\n try:\n with db_lock(db.engine, name=lock_id, block=block,\n timeout=timeout):\n return fn(*args, **kwargs)\n except DatabaseLockFailed:\n logger.error('Failed to get lock.')\n return None\n return f\n return with_task\n```\n\n```text\nrate_limit=5\n```\n\n```text\n[00:00.000]\n```\n\n```text\n[00:00.001]\n```\n\n```text\n[00:10.009]\n```\n\n```text\n[00:20.024]\n```\n\n```text\n[00:26.747]\n```\n\n```text\n[00:26.748]\n```\n\n```text\n[00:26.752]\n```\n\n```text\n[00:26.769]\n```\n\n```text\n[00:26.775]\n```\n\n```text\n[00:26.806]\n```\n\n```text\n[00:26.836]\n```\n\n```text\n[01:30.020]\n```\n\n```text\n[01:30.053]\n```\n\n```text\n[01:30.055]\n```\n\n```text\n[01:30.070]\n```\n\n```text\n[01:30.074]\n```\n\n```text\n[01:30.087]\n```\n\n```text\nfrom functools import wraps\nfrom sqlalchemy import select, func\n\nfrom my_db_module import Session # SQLAlchemy ORM scoped_session\n\ndef pg_locked(key):\n def decorator(f):\n @wraps(f)\n def wrapped(*args, **kw):\n session = db.Session()\n try:\n acquired, = session.execute(select([func.pg_try_advisory_lock(key)])).fetchone()\n if acquired:\n return f(*args, **kw)\n finally:\n if acquired:\n session.execute(select([func.pg_advisory_unlock(key)]))\n return wrapped\n return decorator\n\n@app.task\n@pg_locked(0xdeadbeef)\ndef singleton_task():\n # only 1x this task can run at a time\n pass\n```\n\n```text\ncelery = Celery('test')\ncelery.conf.ONE_REDIS_URL = REDIS_URL\ncelery.conf.ONE_DEFAULT_TIMEOUT = 60 * 60\ncelery.conf.BROKER_URL = REDIS_URL\ncelery.conf.CELERY_RESULT_BACKEND = REDIS_URL\n\nfrom datetime import timedelta\n\ncelery.conf.CELERYBEAT_SCHEDULE = {\n 'add-every-30-seconds': {\n 'task': 'tasks.slow_task',\n 'schedule': timedelta(seconds=1),\n 'args': (1,)\n },\n}\n\ncelery.conf.CELERY_TIMEZONE = 'UTC'\n\n\n@celery.task(base=QueueOne, one_options={'fail': False})\ndef slow_task(a):\n print(\"Running\")\n sleep(5)\n return \"Done \" + str(a)\n```\n\n```text\ncelery-one\n```\n\n```text\nslow_task\n```\n\n```text\ncelery-one\n```\n\n```text\nfrom functools import wraps\nfrom celery import shared_task\n\n\ndef skip_if_running(f):\n task_name = f'{f.__module__}.{f.__name__}'\n\n @wraps(f)\n def wrapped(self, *args, **kwargs):\n workers = self.app.control.inspect().active()\n\n for worker, tasks in workers.items():\n for task in tasks:\n if (task_name == task['name'] and\n tuple(args) == tuple(task['args']) and\n kwargs == task['kwargs'] and\n self.request.id != task['id']):\n print(f'task {task_name} ({args}, {kwargs}) is running on {worker}, skipping')\n\n return None\n\n return f(self, *args, **kwargs)\n\n return wrapped\n\n\n@shared_task(bind=True)\n@skip_if_running\ndef test_single_task(self):\n pass\n\n\ntest_single_task.delay()\n```\n\n========================================\n\nComments:\n- Thank you, that's a very thorough solution with advisory locks, and much cleaner than mine with `@contextmanager`. I was puzzled by the lack of unlock until I realized you were using transaction-level locking... was that simply for convenience or is there another reason to choose it?\n- I changed `SET statement_timeout TO :timeout` to `SET LOCAL lock_timeout TO :timeout` (postgresql.org/docs/9.3/static/runtime-config-client.html). This way you won't affect any long-running non-locking statements in the session. (Probably not an issue since you said yours run quickly!)\n- @DanLenski That seems like a good change, thank you. Most of our helper functions are wrapped in sub-transactions and so I'm using transaction-level locking to ensure global locks aren't held needlessly long when there is other work being one in the same session.\n- But I just realized that by creating a new connection (`conn.begin()`), there's no reason to use a transaction lock rather than session lock. Likewise, there's no reason to differentiate `lock_timeout` and `statement_timeout` in this case either as far as I understand.\n- @erydo just my week got better... )\n- Thanks. I ended up creating a task decorator that guards the task with a PostgreSQL advisory lock. I went this route so that workers on separate machines can maintain a single synchronized lock point. (We're not currently using memcached as in the example).\n- @erydo, would you be willing to that decorator? I'm trying to do nearly the same thing and running into some odd synchronization issues.\n- i think you'll still have backlogged tasks if you say, had only one worker for this one task. Would need that extra worker to prevent the backlogging\n- Dan, yep, that's essentially equivalent to what I came up with—I've added my solution as an edit. It includes support for non-blocking lock attempts and configurable timeouts, since I ended up using the locking code in another place as well.\n- Please a) include the relevant parts of the answer here and b) declare your interest in the site. This was being flagged as spam so I deleted it for you.\n- I've undeleted your answer and invalidated the spam flag. Thanks for following up.\n- The celery-one link is broken.\n- Distributed locking is a great suggestion, but not strictly required. Centralized locking is fine as long as everything is referring to the same center. In our case, these celery workers all interact with the same master Postgres database anyway.etcd, ZooKeeper, or consul are great suggestions here though.\n- what in the world is \"clr_app\" and how do I import it? Wow. I'm a dummy. It's just @app.task...\n- For Django users with `shared_task` decorator: Use the above code with `@shared_task(bind=true)` and the function with `self` as first parameter `def your_task(self, *args, **kwargs)`","metadata":{"transformedAt":"2026-08-18T18:33:20.148Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":27,"totalLines":456,"estimatedTokens":3292}}338{"id":"stack-68600215","source":"stackoverflow","questionId":68600215,"title":"Dropping container with RabbitMQ in Docker","tags":["docker","rabbitmq"],"text":"Title: Dropping container with RabbitMQ in Docker\nTags: docker, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI try to start a Docker container with RabbitMQ, as a result, the image is downloaded, but the container does not start. I get the following message in the logs:\n\n```\nerror: RABBITMQ_DEFAULT_PASS is set but deprecated\nerror: RABBITMQ_DEFAULT_USER is set but deprecated\nerror: RABBITMQ_DEFAULT_VHOST is set but deprecated\nerror: RABBITMQ_ERLANG_COOKIE is set but deprecated\nerror: deprecated environment variables detected\n```\n\nThis problem appeared recently, before that everything worked fine and started.\n\nThis is my docker-compose rabbit:\n\n```\nrabbit:\n image: \"rabbitmq:3-management\"\n hostname: \"rabbit\"\n environment:\n RABBITMQ_ERLANG_COOKIE: 'SWQOKODSQALRPCLNMEQGW'\n RABBITMQ_DEFAULT_USER: 'user'\n RABBITMQ_DEFAULT_PASS: 'bitnami'\n RABBITMQ_DEFAULT_VHOST: '/'\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n labels:\n NAME: \"rabbitmq\" \n networks:\n - postgres\n```\n\n========================================\n\nTop Answer:\nYou should use the following environment varibles:\n\n```\nDEFAULT_VHOST=/\nDEFAULT_USER=user1\nDEFAULT_PASS=pass1\n```\n\nsee https://www.rabbitmq.com/configure.html for more information.\n\nOr use other versions of rabbitMQ like 3.8:\n\n```\nrabbitmq:3.8-management\n```\n\n========================================\n\nCode:\n```text\nerror: RABBITMQ_DEFAULT_PASS is set but deprecated\nerror: RABBITMQ_DEFAULT_USER is set but deprecated\nerror: RABBITMQ_DEFAULT_VHOST is set but deprecated\nerror: RABBITMQ_ERLANG_COOKIE is set but deprecated\nerror: deprecated environment variables detected\n```\n\n```text\nrabbit:\n image: \"rabbitmq:3-management\"\n hostname: \"rabbit\"\n environment:\n RABBITMQ_ERLANG_COOKIE: 'SWQOKODSQALRPCLNMEQGW'\n RABBITMQ_DEFAULT_USER: 'user'\n RABBITMQ_DEFAULT_PASS: 'bitnami'\n RABBITMQ_DEFAULT_VHOST: '/'\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n labels:\n NAME: \"rabbitmq\" \n networks:\n - postgres\n```\n\n```text\nAs of RabbitMQ 3.9, all of the docker-specific variables listed below are deprecated and no longer used.\n```\n\n```text\ndefault_vhost = /\ndefault_user = user\ndefault_pass = bitnami\n```\n\n```text\nrabbit:\n image: \"rabbitmq:3-management\"\n hostname: \"rabbit\"\n volumes:\n - \"./rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf\"\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n labels:\n NAME: \"rabbitmq\" \n networks:\n - postgres\n```\n\n```text\nDEFAULT_VHOST=/\nDEFAULT_USER=user1\nDEFAULT_PASS=pass1\n```\n\n```text\nrabbitmq:3.8-management\n```\n\n```text\nimage: \"rabbitmq:3-management\"\n```\n\n```text\nimage: \"rabbitmq:3.8-management\"\n```\n\n```text\nDockerfile\n```\n\n```text\nDockerfile\n```\n\n```text\nCOPY ./rabbitmq.conf /etc/rabbitmq/rabbitmq.conf\n```\n\n========================================\n\nComments:\n- From the official rabbitmq dockerhub page: \"***Environment Variables** ... **WARNING:** As of RabbitMQ 3.9, all of the docker-specific variables listed below are deprecated and no longer used. Please use a configuration file instead; visit rabbitmq.com/configure to learn more about the configuration file. For a starting point, the 3.8 images will print out the config file it generated from supplied environment variables. ... - `RABBITMQ_DEFAULT_PASS` ... - `RABBITMQ_DEFAULT_USER`*\"\n- This is probably better than my answer, since it addresses the actual error instead of reverting back to the version when it worked. However, the whole reason it came up is because we were using 3-management, which is simply bad practice for an evolving project. So I guess I would add to yours that it'd be worth doing 3.9-management once the problem is resolved to avoid future breaking changes being added from the outside. No idea if they plan a 3.10 before moving on to 4.0, and they certainly could change the way this is done again.\n- this would expose credentials into docker layers - bad idea","metadata":{"transformedAt":"2026-08-18T18:33:20.148Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":146,"estimatedTokens":976}}339{"id":"stack-37457140","source":"stackoverflow","questionId":37457140,"title":"Distributed architecture with MassTransit, RabbitMQ and SignalR","tags":["c#","asp.net-mvc","rabbitmq","signalr","masstransit"],"text":"Title: Distributed architecture with MassTransit, RabbitMQ and SignalR\nTags: c#, asp.net-mvc, rabbitmq, signalr, masstransit\nSource: Stack Overflow\n\nQuestion:\nI'm developing distributed application with help of MassTransit and rabbitmq\n\nI have to provide ability to generate report on a web page without page reloading by click on a button, also I should call a windows service for data preparation (The service handles each request for 30sek - 1min). \n\nMy first try based on this sample: https://github.com/MassTransit/Sample-RequestResponse \n\n```\n[HttpPost]\n public async Task GenerateReport(string someJsonData)\n { \n var serviceAddress = new Uri(ConfigurationManager.AppSettings[\"BaseLineRecordService\"]);\n var client = this.Bus.CreateRequestClient(serviceAddress, TimeSpan.FromHours(1));\n ICreateReportResponse response = await client.Request(new CreateReportRequest());\n reportHub.ShowRepordData(response); // Update data by SingleR\n return new HttpStatusCodeResult(200);\n }\n```\n\nBut as I understand it' not a better approach, because I'm keeping connection during all data preparation.\n\nI've read many articles and I have found three ways. Which way is preferred?\n\n1) Like on this article http://www.maldworth.com/2015/07/19/signalrchat-with-masstransit-v3/ \n\nhttps://i.sstatic.net/lqgt7.png\n\n2) As first but with Rest API calling instead of Consumers from IIS side\n\nhttps://i.sstatic.net/EGE5s.png\n\n3) Idea from this article http://weblog.west-wind.com/posts/2013/Sep/04/SelfHosting-SignalR-in-a-Windows-Service\n\nhttps://i.sstatic.net/z6IGW.png\n\n========================================\n\nCode:\n```text\n[HttpPost]\n public async Task<HttpStatusCodeResult> GenerateReport(string someJsonData)\n { \n var serviceAddress = new Uri(ConfigurationManager.AppSettings[\"BaseLineRecordService\"]);\n var client = this.Bus.CreateRequestClient<ICreateReportRequest, ICreateReportResponse>(serviceAddress, TimeSpan.FromHours(1));\n ICreateReportResponse response = await client.Request(new CreateReportRequest());\n reportHub.ShowRepordData(response); // Update data by SingleR\n return new HttpStatusCodeResult(200);\n }\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.148Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":53,"estimatedTokens":540}}340{"id":"stack-6351698","source":"stackoverflow","questionId":6351698,"title":"What does nowait mean in RabbitMQ's exchange.declare()?","tags":["rabbitmq","amqp"],"text":"Title: What does nowait mean in RabbitMQ's exchange.declare()?\nTags: rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nPretty straightforward question. I can't find it in the docs or the spec.","metadata":{"transformedAt":"2026-08-18T18:33:20.148Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":6,"estimatedTokens":48}}341{"id":"stack-19695897","source":"stackoverflow","questionId":19695897,"title":"How do you handle recovering from a faulty connection using RabbitMQ java client library?","tags":["java","rabbitmq","amqp"],"text":"Title: How do you handle recovering from a faulty connection using RabbitMQ java client library?\nTags: java, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI'm interested in knowing how other people handle recovering from a faulty connection using the official RabbitMQ java client library. We are using it to connect our application servers to our RabbitMQ cluster and we have implemented a few different ways to recover from a connection failure, but non of them feel quite right. \n\nImagine this pseudo application:\n\n```\npublic class OurClassThatStartsConsumers {\n Connection conn;\n\n public void start() {\n ConnectionFactory factory = new ConnectionFactory();\n factory.setUsername(\"someusername\");\n factory.setPassword(\"somepassword\");\n factory.setHost(\"somehost\");\n conn = factory.newConnection();\n\n new Thread(new Consumer(conn.createChannel())).start();\n }\n }\n\nclass Consumer1 implements Runnable {\n public Consumer1(Channel channel) {\n this.channel = channel;\n }\n\n @Override\n public void run() {\n while (true) {\n ... consume incoming messages on the channel...\n // How do we handle that the connection dies?\n }\n }\n}\n```\n\nIn the real world we have several hundreds of consumers. So what happens if the connection dies? In the above example Consumer1 can not recover, when the connection closes, the Channel also closes, a state from which we can not recover. So lets look at some ways to solve this:\n\nSolution A) \n\nLet every consumer have their own connection and register the events that trigger when the connection dies and then handle reconnecting. \n\nPros: It works\n\nCons: \n\nSince we have a lot of consumers, we probably do not want that many\nconnections. \nWe might possibly have a lot of duplicated code for\nreconnecting to rabbit and handle reconnecting\n\nSolution B)\n\nHave each consumer use the same connection and subscribe to it's connection failure events. \n\nPros: Less connections than in Solution A\n\nCons: Since the connection is closed we need to reopen/replace it. The java client library doesn't seem to provide a way to reopen the connection, so we would have to replace it with a new connection and then somehow notify all the consumers about this new connection and they would have to recreate the channels and the consumers. Once again, a lot of logic that I don't want to see in the consumer ends up there. \n\nSolution C)\n\nWrap `Connection` and `Channel` classes is classes that handle the re-connection logic, the consumer only needs to know about the `WrappedChannel` class. On a connection failure the `WrappedConnection` will deal with re-establishing the connection and once connected the `WrappedConnection` will automatically create new Channels and register consumers.\n\nPros: It works - this is actually the solution we are using today.\n\nCons: It feels like a hack, I think this is something that should be handled more elegantly by the underlying library. \n\nMaybe there is a much better way? The API documentation does not talk that much about recovering from a faulty connection. Any input is appreciated :)\n\n========================================\n\nTop Answer:\nSince version 3.3.0 you can use automatic recovery, which is a new feature of the Java client. From the Java API guide (http://www.rabbitmq.com/api-guide.html#recovery)\n\n To enable automatic connection recovery, use\n factory.setAutomaticRecovery(true):\n\n========================================\n\nCode:\n```text\npublic class OurClassThatStartsConsumers {\n Connection conn;\n\n public void start() {\n ConnectionFactory factory = new ConnectionFactory();\n factory.setUsername(\"someusername\");\n factory.setPassword(\"somepassword\");\n factory.setHost(\"somehost\");\n conn = factory.newConnection();\n\n new Thread(new Consumer(conn.createChannel())).start();\n }\n }\n\nclass Consumer1 implements Runnable {\n public Consumer1(Channel channel) {\n this.channel = channel;\n }\n\n @Override\n public void run() {\n while (true) {\n ... consume incoming messages on the channel...\n // How do we handle that the connection dies?\n }\n }\n}\n```\n\n```text\nConnection\n```\n\n```text\nChannel\n```\n\n```text\nWrappedChannel\n```\n\n```text\nWrappedConnection\n```\n\n```text\nWrappedConnection\n```\n\n========================================\n\nComments:\n- Can you give hint on how exactly to code it. As there seem to be no callback called on which we can recover all the channels, queues and bindings. Can you tell me how exactly i should wrap the connection??\n- You will have to wrap the Connection and the Channel, there is no way to recover a channel once it has disconnected so you will have to create a new one.","metadata":{"transformedAt":"2026-08-18T18:33:20.148Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":138,"estimatedTokens":1169}}342{"id":"stack-16308849","source":"stackoverflow","questionId":16308849,"title":"Running a task after all tasks have been completed","tags":["python","rabbitmq","celery"],"text":"Title: Running a task after all tasks have been completed\nTags: python, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI'm writing an application which needs to run a series of tasks in parallel and then a single task with the results of all the tasks run:\n\n```\n@celery.task\ndef power(value, expo):\n return value ** expo\n\n@celery.task\ndef amass(values):\n print str(values)\n```\n\nIt's a very contrived and oversimplified example, but hopefully the point comes across well. Basically, I have *many* items which need to run through `power`, but I only want to run `amass` on the results from all of the tasks. All of this should happen asynchronously, and I don't need anything back from the `amass` method.\n\nDoes anyone know how to set this up in celery so that everything is executed asynchronously and a single callback with a list of the results is called after all is said and done?\n\nI've setup this example to run with a `chord` as Alexander Afanasiev recommended:\n\n```\nfrom time import sleep\n\nimport random\n\ntasks = []\n\nfor i in xrange(10):\n tasks.append(power.s((i, 2)))\n sleep(random.randint(10, 1000) / 1000.0) # sleep for 10-1000ms\n\ncallback = amass.s()\n\nr = chord(tasks)(callback)\n```\n\nUnfortunately, in the above example, all tasks in `tasks` are started only when the `chord` method is called. Is there a way that each task can start separately and then I could add a callback to the group to run when everything has finished?\n\n========================================\n\nTop Answer:\nCelery has plenty of tools for most of workflows you can imagine.\n\nIt seems you need to get use of chord. Here's a quote from docs:\n\n A chord is just like a group but with a callback. A chord consists of\n a header group and a body, where the body is a task that should\n execute after all of the tasks in the header are complete.\n\n========================================\n\nCode:\n```text\n@celery.task\ndef power(value, expo):\n return value ** expo\n\n@celery.task\ndef amass(values):\n print str(values)\n```\n\n```text\nfrom time import sleep\n\nimport random\n\ntasks = []\n\nfor i in xrange(10):\n tasks.append(power.s((i, 2)))\n sleep(random.randint(10, 1000) / 1000.0) # sleep for 10-1000ms\n\ncallback = amass.s()\n\nr = chord(tasks)(callback)\n```\n\n```text\npower\n```\n\n```text\namass\n```\n\n```text\namass\n```\n\n```text\nchord\n```\n\n```text\ntasks\n```\n\n```text\nchord\n```\n\n```text\nfrom time import sleep\n\nimport random\n\n@celery.task\ndef power(value, expo):\n sleep(random.randint(10, 1000) / 1000.0) # sleep for 10-1000ms\n return value ** expo\n\n@celery.task\ndef amass(results, tasks):\n completed_tasks = []\n for task in tasks:\n if task.ready():\n completed_tasks.append(task)\n results.append(task.get())\n\n # remove completed tasks\n tasks = list(set(tasks) - set(completed_tasks))\n\n if len(tasks) > 0:\n # resend the task to execute at least 1 second from now\n amass.delay(results, tasks, countdown=1)\n else:\n # we done\n print results\n```\n\n```text\ntasks = []\n\nfor i in xrange(10):\n tasks.append(power.delay(i, 2))\n\namass.delay([], tasks)\n```\n\n```text\namass\n```\n\n```text\ntasks.append(power.s((i, 2)))\n```\n\n```text\nchord(...)(...)\n```\n\n```text\ntasks\n```\n\n```text\nchord\n```\n\n```text\nr.ready()\n```\n\n```text\nfrom time import sleep\nimport random\n\ntasks = []\n\nfor i in xrange(10):\n tasks.append(power.s((i, 2)))\n sleep(random.randint(10, 1000) / 1000.0) # sleep for 10-1000ms\n\ncallback = amass.s()\n\nr = chord(tasks)(callback)\n```\n\n```text\n...\n\ncallback = amass.s()\n\ntasks = group(tasks)\n\nr = chord(tasks)(callback)\n```\n\n```text\nlist\n```\n\n```text\ngroup\n```\n\n```text\nlist\n```\n\n```text\ngroup\n```\n\n========================================\n\nComments:\n- This is definitely right, however, there's a problem with it. I've updated my answer with the details.\n- I want each subtask to execute as soon as it's posted, not when the chord is posted. Is that possible?\n- Well, just do a `power.delay(i, 2)` in the loop and poll all the intermediate results for completion before calling `amass(results)`. But I don't really see the point. Using the chord will execute the `power.s` subtasks as soon as they are available as messages in the broker and `amass` after they finish. I think you should clarify what you want to achieve, because it seems your desire to execute the tasks asynchronously contradicts the usage you are proposing.\n- I came up with a solution above which demonstrates what I wanted to do.\n- I think you just have reimplemented the `chord` function.\n- Not at all: I think you don't understand what I'm asking. The chord function does not start executing tasks until it is called. However, in my code, tasks start executing immediately, and then a completion handler is also posted to the queue. In my use case, I'm not calling the actual chord function until some point in the future when I've started all necessary tasks for the job. Essentially, the chord function is lazy, only starting tasks when they've all been posted and the chord function is called. My implementation is eager, in that it starts all tasks as soon as possible.\n- Hi, looks like the above is a good approach, at least conceptually. However, when I tried it out, the exact same code as above, it throws the below error: `EncodeError: is not JSON serializable` Would really appreciate some help here .\n- Ok, I solved the above error by passing the final_task() a list of taskIds itself directly instead of passing it the list of task objects as is being done in the above code sample. Thanks anyway for the answer. It helped a lot.\n- upvoted! any ideas how this works if each group starts a new task and you want the chord to say wait for the subtasks of each group to complete\n- Sorry it's been a while since I looked into Celery in detail so I don't know the specifics of how 4.x works","metadata":{"transformedAt":"2026-08-18T18:33:20.148Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":22,"totalLines":221,"estimatedTokens":1457}}343{"id":"stack-6362829","source":"stackoverflow","questionId":6362829,"title":"RabbitMQ on EC2 Consuming Tons of CPU","tags":["django","rabbitmq","celery"],"text":"Title: RabbitMQ on EC2 Consuming Tons of CPU\nTags: django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI am trying to get RabbitMQ with Celery and Django going on an EC2 instance to do some pretty basic background processing. I'm running rabbitmq-server 2.5.0 on a large EC2 instance.\n\nI downloaded and installed the test client per the instructions here (at the very bottom of the page). I have been just letting the test script go and am getting the expected output:\n\n```\nrecving rate: 2350 msg/s, min/avg/max latency: 588078478/588352905/588588968 microseconds\nrecving rate: 1844 msg/s, min/avg/max latency: 588589350/588845737/589195341 microseconds\nrecving rate: 1562 msg/s, min/avg/max latency: 589182735/589571192/589959071 microseconds\nrecving rate: 2080 msg/s, min/avg/max latency: 589959557/590284302/590679611 microseconds\n```\n\nThe problem is that it is consuming an incredible amount of CPU:\n\n PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND\n\n 668 rabbitmq 20 0 618m 506m 2340 S 166 6.8 2:31.53 beam.smp\n\n 1301 ubuntu 20 0 2142m 90m 9128 S 17 1.2 0:24.75 java \n\nI was testing on a micro instance earlier and it was completely consuming all resources on the instance. \n\nIs this to be expected? Am I doing something wrong?\n\nThanks.\n\n**Edit:**\n\nThe real reason for this post was that celerybeat seemed to run okay for awhile and then suddenly consume all resources on the system. I installed the rabbitmq management tools and have been investigating how the queues are created from celery and from the rabbitmq test suite. It seems to me that celery is orphaning these queues and they are not going away.\n\nHere is the queue as generated by the test suite. One queue is created and all the messages go into it and come out:\n\nCelerybeat creates a new queue for every time it runs the task:\n\nIt sets the auto-delete parameter to true, but I'm not entirely sure when these queues will get deleted. They seem to just slowly build up and eat resources.\n\nDoes anyone have an idea?\n\nThanks.\n\n========================================\n\nTop Answer:\nTo add to Eric Conner's solution to his own problem, http://docs.celeryproject.org/en/latest/userguide/tasks.html#tips-and-best-practices states:\n\n **Ignore results you don’t want**\n\n \n If you don’t care about the results of a task, be sure to set the ignore_result option, as storing results wastes time and resources.\n\n```\n@app.task(ignore_result=True)\ndef mytask(…):\n something()\n```\n\n \n Results can even be disabled globally using the CELERY_IGNORE_RESULT setting.\n\nThat along with Eric's answer is probably a bare minimum best practices for managing your results backend.\n\nIf you don't need a results backend, set CELERY_IGNORE_RESULT or don't set a results backend at all. If you do need a results backend, set CELERY_AMQP_TASK_RESULT_EXPIRES to be safeguarded against unused results building up. If you don't need it for a specific app, set the local ignore as above.\n\n========================================\n\nCode:\n```text\nrecving rate: 2350 msg/s, min/avg/max latency: 588078478/588352905/588588968 microseconds\nrecving rate: 1844 msg/s, min/avg/max latency: 588589350/588845737/589195341 microseconds\nrecving rate: 1562 msg/s, min/avg/max latency: 589182735/589571192/589959071 microseconds\nrecving rate: 2080 msg/s, min/avg/max latency: 589959557/590284302/590679611 microseconds\n```\n\n```text\n@app.task(ignore_result=True)\ndef mytask(…):\n something()\n```\n\n========================================\n\nComments:\n- The next Celery version (2.3.0) will not have a result backend by default. Making it a more conscious choice, so pitfalls like these can be avoided.","metadata":{"transformedAt":"2026-08-18T18:33:20.148Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":87,"estimatedTokens":909}}344{"id":"stack-13087058","source":"stackoverflow","questionId":13087058,"title":"Consuming SQL Server data events for messaging purposes","tags":["c#","sql-server-2005","rabbitmq"],"text":"Title: Consuming SQL Server data events for messaging purposes\nTags: c#, sql-server-2005, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nAt our organization we have a SQL Server 2005 database and a fair number of database clients: web sites (php, zope, asp.net), rich clients (legacy fox pro). Now we need to pass certain events from the core database with other systems (MongoDb, LDAP and others). Messaging paradigm seems pretty capable of solving this kind of problem. So we decided to use RabbitMQ broker as a middleware.\n\nThe problem of consuming events from the database at first seemed to have only two possible solutions:\n\n- Poll the database for outgoing messages and pass them to a message broker.\n\n- Use triggers on certain tables to pass messages to a broker on the same machine.\n\nI disliked the first idea due to latency issues which arise when periodical execution of sql is involved. \n\nBut event-based trigger approach has a problem which seems unsolvable to me at the moment. Consider this scenario:\n\n- A row is inserted into a table.\n\n- Trigger fires and sends a message (using a CLR Stored Procedure written in C#)\n\nEverything is ok unless transaction which writes data is rolled back. In this case data will be consistent, but the message has already been sent and cannot be rolled back because trigger fires at the moment of writing to the database log, not at the time of transaction commit (which is a correct behaviour of a RDBMS).\n\nI realize now that I'm asking too much of triggers and they are not suitable for tasks other than working with data.\n\nSo my questions are:\n\n- Has anyone managed to extract data events using triggers?\n\n- What other methods of consuming data events can you advise?\n\n- Is Query Notification (built on top of Service Broker) suitable in my situation?\n\nThanks in advance!\n\n========================================\n\nTop Answer:\nRemus's answer lays out some sound principals for generating and handling events. You can initiate the pushing of events from a trigger to achieve low latency.\n\nYou can achieve everything necessary from a trigger. We will still **decouple** this into two components: a trigger that generates the events and a local reader that reads the events.\n\nThe first component is the trigger.\n\n- Make a CLR trigger that prepares what needs to be done when the transaction commits.\n\n- Create a `System.Transactions.IEnlistmentNotification` that always agrees to be prepared, and whose `void Commit(System.Transactions.Enlistment)` method executes the prepared action.\n\n- In the trigger, call `System.Transactions.Transaction.Current.EnlistVolatile(enlistmentNotification, System.Transactions.EnlistmentOptions.None)`\n\nYou'll want your action to be short and sweet, like appending the data to a lockless queue in memory or updating some other state in memory. Don't try to communicate with other machines or processes. Don't write to a disk (if you wanted to write to a disk, just make an ordinary trigger that inserts into a queue table). You'll need to be careful to make sure your assembly is loaded only once so that any shared static state will be unique; this is easiest to do if your static state is in a top level assembly that isn't referenced by other assemblies, so no other assemblies will try to load it. \n\nYou will also need to either\n\n- initialize your state in such a way that it will be correct even if the system was restarted without sending all the previously queued messages (since a short, in memory queue will not be durable). This means you might be resending messages, so they will need to be **idempotent**. or\n\n- rely on the **tolerance** of another component to pick up on missed messages\n\nThe second component reads the state that is update by the trigger. Make a separate CLR component that reads from your queue or state, and does whatever you need done (like send an idempotent message to a messaging system, record that it was sent, whatever). If this component can fail (hint: it can), you will need some form of **tolerance**, which may belong in another system. You can achieve low latency by having the trigger signal the second component when new state is available.\n\nOne architectural possibility is to have the trigger put the event in memory on commit for another low-latency component to pick up and have the second component send a low-latency, low-reliability copy of an idempotent message. You can pair that with a more reliably or durable messaging system, such as SSB, that will reliably and durably, but with grater latency, send the same idempotent message later.\n\n========================================\n\nCode:\n```text\nSEND\n```\n\n```text\nSystem.Transactions.IEnlistmentNotification\n```\n\n```text\nvoid Commit(System.Transactions.Enlistment)\n```\n\n```text\nSystem.Transactions.Transaction.Current.EnlistVolatile(enlistmentNotification, System.Transactions.EnlistmentOptions.None)\n```\n\n========================================\n\nComments:\n- You're already kind of using SQL Server as a queuing system so maybe some middleware to make that easier: docs.particular.net/transports/sql. There's also a bridge if you want to communicate between SQL Server and RabbitMQ: docs.particular.net/nservicebus/bridge\n- Thank you very much for such a thorough answer! I came across BizTalk in the first place, but was intimidated by the complexity and price. Now I'm going to try tables as queues approach for simple things, and discuss a possible purchase of BizTalk in the future with my bosses. SSB also needs a deeper understanding.","metadata":{"transformedAt":"2026-08-18T18:33:20.148Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":86,"estimatedTokens":1382}}345{"id":"stack-52487851","source":"stackoverflow","questionId":52487851,"title":"RabbitMQ on Android and Java","tags":["java","android","rabbitmq"],"text":"Title: RabbitMQ on Android and Java\nTags: java, android, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am trying to reproduce the first example of a Java publisher that can be found in RabbitMQ's main page.\n\nFirst, I did it in Java and it worked fine. Then, I tried it on Android and here is where the weird part comes.\n\nI have added manually the same jar libraries that I used in my Java program and that are suggested in RabbitMQ's tutorial. That is to say, `amqp-client-5.4.1`, `slf4j-api-1.7.21` and `slf4j-simple-1.7.22` are added in `/libs` directory and then referenced in the `buid.gradle (module:app)` with the commands `implementation files('libs/amqp-client-5.4.1.jar')` and so on.\n\nThen, I have added the required package dependencies in my `MainActivity.java` file without encountering any error. But when adding the piece of code that should publish the data, the different methods of the imported libraries are not found, for instance, `factory` appears as it did not have the method `setHost`.\n\nI attach the code bellow I am currently using.\n\n```\nimport android.support.v7.app.AppCompatActivity;\nimport android.os.Bundle;\nimport java.io.IOException;\nimport java.util.concurrent.TimeoutException;\n\nimport com.rabbitmq.client.ConnectionFactory;\nimport com.rabbitmq.client.Connection;\nimport com.rabbitmq.client.Channel;\n\npublic class MainActivity extends AppCompatActivity {\n\n String QUEUE_NAME = \"hello\";\n ConnectionFactory factory = new ConnectionFactory();\n\n factory.setHost(\"192.0.0.0\"); //Marked as error\n factory.setUsername(\"test\");\n factory.setPassword(\"test\");\n Connection connection;\n Channel channel;\n connection = factory.newConnection();\n channel = connection.createChannel();\n\n channel.queueDeclare(QUEUE_NAME, false, false, false, null);\n String message = \"Example3\";\n channel.basicPublish(\"\", QUEUE_NAME, null, message.getBytes());\n System.out.println(\" [x] Sent '\" + message + \"'\");\n channel.close();\n connection.close();\n\n @Override\n protected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n setContentView(R.layout.activity_main);\n }\n}\n```\n\nAny ideas of why this code is working fine on Java but these libraries fails to be correctly imported in Android?\n\n========================================\n\nCode:\n```text\nimport android.support.v7.app.AppCompatActivity;\nimport android.os.Bundle;\nimport java.io.IOException;\nimport java.util.concurrent.TimeoutException;\n\nimport com.rabbitmq.client.ConnectionFactory;\nimport com.rabbitmq.client.Connection;\nimport com.rabbitmq.client.Channel;\n\npublic class MainActivity extends AppCompatActivity {\n\n String QUEUE_NAME = \"hello\";\n ConnectionFactory factory = new ConnectionFactory();\n\n factory.setHost(\"192.0.0.0\"); //Marked as error\n factory.setUsername(\"test\");\n factory.setPassword(\"test\");\n Connection connection;\n Channel channel;\n connection = factory.newConnection();\n channel = connection.createChannel();\n\n channel.queueDeclare(QUEUE_NAME, false, false, false, null);\n String message = \"Example3\";\n channel.basicPublish(\"\", QUEUE_NAME, null, message.getBytes());\n System.out.println(\" [x] Sent '\" + message + \"'\");\n channel.close();\n connection.close();\n\n @Override\n protected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n setContentView(R.layout.activity_main);\n }\n}\n```\n\n```text\namqp-client-5.4.1\n```\n\n```text\nslf4j-api-1.7.21\n```\n\n```text\nslf4j-simple-1.7.22\n```\n\n```text\n/libs\n```\n\n```text\nbuid.gradle (module:app)\n```\n\n```text\nimplementation files('libs/amqp-client-5.4.1.jar')\n```\n\n```text\nMainActivity.java\n```\n\n```text\nfactory\n```\n\n```text\nsetHost\n```\n\n```text\nimport android.support.v7.app.AppCompatActivity;\nimport android.os.Bundle;\nimport java.io.IOException;\nimport java.util.concurrent.TimeoutException;\n\nimport com.rabbitmq.client.ConnectionFactory;\nimport com.rabbitmq.client.Connection;\nimport com.rabbitmq.client.Channel;\n\npublic class MainActivity extends AppCompatActivity {\n\n String QUEUE_NAME = \"hello\";\n ConnectionFactory factory = new ConnectionFactory();\n\n @Override\n protected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n setContentView(R.layout.activity_main);\n init();\n }\n\n private void init() {\n try {\n factory.setHost(\"192.0.0.0\");\n factory.setUsername(\"test\");\n factory.setPassword(\"test\");\n Connection connection;\n Channel channel;\n connection = factory.newConnection();\n channel = connection.createChannel();\n\n channel.queueDeclare(QUEUE_NAME, false, false, false, null);\n String message = \"Example3\";\n channel.basicPublish(\"\", QUEUE_NAME, null, message.getBytes());\n System.out.println(\" [x] Sent '\" + message + \"'\");\n channel.close();\n connection.close();\n } catch (IOException | TimeoutException e) {\n throw new RuntimeException(\"Rabbitmq problem\", e);\n }\n }\n}\n```\n\n```text\ndependencies {\n compile group: 'com.rabbitmq', name: 'amqp-client', version: '5.4.1'\n compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.21'\n compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.21'\n}\n```\n\n```text\nbuild.gradle\n```\n\n========================================\n\nComments:\n- You don't normally run code outside of lifecycle methods, try to do that in onCreate and perhaps as an async task.\n- those libraries are also available on `mavenCentral()` eg.: mvnrepository.com/artifact/com.rabbitmq/amqp-client/5.4.2","metadata":{"transformedAt":"2026-08-18T18:33:20.148Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":13,"totalLines":194,"estimatedTokens":1408}}346{"id":"stack-23333863","source":"stackoverflow","questionId":23333863,"title":"How to stop consuming message from selective queue - RabbitMQ","tags":["queue","rabbitmq","consumer"],"text":"Title: How to stop consuming message from selective queue - RabbitMQ\nTags: queue, rabbitmq, consumer\nSource: Stack Overflow\n\nQuestion:\n```\nQueueingConsumer consumer = new QueueingConsumer(channel);\nSystem.out.println(consumer.getConsumerTag());\nchannel.basicConsume(\"queue1\", consumer);\nchannel.basicConsume(\"queue3\", consumer);\n```\n\nIs it possible to stop consuming the messages from the queue \"queue3\" alone dynamically?\n\n========================================\n\nCode:\n```text\nQueueingConsumer consumer = new QueueingConsumer(channel);\nSystem.out.println(consumer.getConsumerTag());\nchannel.basicConsume(\"queue1\", consumer);\nchannel.basicConsume(\"queue3\", consumer);\n```\n\n```text\nString tag3 = channel.basicConsume(\"queue3\", consumer);\nchannel.basicCancel(tag3)\n```\n\n```text\nString tag1 = channel.basicConsume(myQueue, autoAck, consumer);\nString tag2 = channel.basicConsume(myQueue2, autoAck, consumer);\n executorService.execute(new Runnable() {\n @Override\n public void run() {\n while (true) {\n Delivery delivery;\n try {\n delivery = consumer.nextDelivery();\n String message = new String(delivery.getBody());\n System.out.println(\"Received: \" + message);\n } catch (Exception ex) {\n Logger.getLogger(TestMng.class.getName()).log(Level.SEVERE, null, ex);\n }\n }\n }\n });\n System.out.println(\"Consumers Ready\");\n try {\n Thread.sleep(5000);\n } catch (InterruptedException ex) {\n Logger.getLogger(TestMng.class.getName()).log(Level.SEVERE, null, ex);\n }\n\n channel.basicCancel(tag2); /// here you remove only the Myqueue2\n```\n\n```text\nchannel.basicCancel(consumerTag);\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.148Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":60,"estimatedTokens":445}}347{"id":"stack-21098502","source":"stackoverflow","questionId":21098502,"title":"Pitfalls with local in memory cache invalidated using RabbitMQ","tags":["web-services","memcached","rabbitmq","guava","memorycache"],"text":"Title: Pitfalls with local in memory cache invalidated using RabbitMQ\nTags: web-services, memcached, rabbitmq, guava, memorycache\nSource: Stack Overflow\n\nQuestion:\nI have a java web server and am currently using the Guava library to handle my in-memory caching, which I use heavily. I now need to expand to multiple servers (2+) for failover and load balancing. In the process, I switched from a in-process cache to Memcache (external service) instead. However, I'm not terribly impressed with the results, as now for nearly every call, I have to make an external call to another server, which is significantly slower than the in-memory cache.\n\nI'm thinking instead of getting the data from Memcache, I could keep using a local cache on each server, and use RabbitMQ to notify the other servers when their caches need to be updated. So if one server makes a change to the underlying data, it would also broadcast a message to all other servers telling them their cache is now invalid. Every server is both broadcasting and listening for cache invalidation messages.\n\nDoes anyone know any potential pitfalls of this approach? I'm a little nervous because I can't find anyone else that is doing this in production. The only problems I see would be that each server needs more memory (in-memory cache), and it might take a little longer for any given server to get the updated data. Anything else?\n\n========================================\n\nTop Answer:\nWe're using something similar for data which is read-only and doesn't require updated every time. I'm in doubt, that this is good plan for you. Just imagine you should have one more additional service on each instance, which will monitor queue, and process change to in-memory storage. This is very hard to test. \n\nAre you sure that most of the time is spent on communication between your servers? Maybe you run multiple calls?\n\n========================================\n\nComments:\n- I found this article on DZone helpful, but it did not address messaging other systems to keep caches consistent.\n- Please elaborate on your setup. There is an issue with your cache/server configuration if you are seeing response times 250-350ms.\n- We have similar setup in our system, and it works. Only difference is, we use notifications to notify that entry needs to be evicted (for simplicity). In this case notified instance needs to re-query again persistent storage to get most recent value and then update local in-memory cache. But it all depends how frequently erased item is accessed.\n- Makes sense, but it's not exactly my problem. My original cache is **local to the process** (think of Guava cache as a map or a dictionary). It does not have any built-in mechanism to expand to multiple nodes. Memcache does have this feature, which is why I switched to it, but now the cache is not local to my web server, it's on a different machine which slows things down.\n- Is there some reason you can't run memcached on the web server box?\n- Some memcached clients keep connections to the servers open to optimize response time; I'm struggling with your use case that a few tenths of a millisecond are enough to cause a noticeable degradation in performance. Could you please elaborate on that?\n- @ChrisJohnson I really like your suggestion to run memcached on the same server, I will try that.\n- @rmayer06 It's about 150 to 200 ms for each call to memcache (nearly all that time is spent on the network request). Since I'm only storing the models in the cache right now, some requests require 2 calls (serialized) because I need the first model to figure out what model to get for the second call.\n- 150 to 200ms is several orders of magnitude greater than what it should be. Something is off with your setup. You aren't trying to access it over a WAN, by chance? Also, I would use Couchbase as your memcached server, it is proven and commercially-supported. Just my 2 cents there.\n- +1 For some great points. Theoretically, an advantage of this approach would be to avoid serialization of objects, assuming the caches are going to live on the same machines as the application. There is an overwhelming list of disadvantages though, some of which you address here. I posted the bounty out of curiosity to see if the idea had ever been tried in some shape or form, but I guess it's untenable.\n- Thanks Paul! I actually do use some local data caching in my application, but it re-syncs itself every 5 minutes and I wouldn't consider it in a multi-user scenario such as a web app.","metadata":{"transformedAt":"2026-08-18T18:33:20.148Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":32,"estimatedTokens":1129}}348{"id":"stack-28520784","source":"stackoverflow","questionId":28520784,"title":"RabbitMQ RPC across multiple rabbitMQ instances","tags":["rabbitmq","spring-amqp","federation","rabbitmq-shovel"],"text":"Title: RabbitMQ RPC across multiple rabbitMQ instances\nTags: rabbitmq, spring-amqp, federation, rabbitmq-shovel\nSource: Stack Overflow\n\nQuestion:\nI have three clients each with their own RabbitMQ instances and I have an application (let's call it appA) that has its own RabbitMQ instance, the three client applications (app1, app2, app3) wants to make use of a service on appA.\n\nThe service on appA requires RPC communication, app1, app2 and app3 each has a booking.request queue and a booking.response queue.\n\nWith the shovel plugin, I can forward all booking.request messages from app1-3 to appA:\n\n```\nShovel1 \nvirtualHost=appA, \nname=booking-request-shovel, \nsourceURI=amqp://userForApp1:password@app1-server/vhostForApp1\nqueue=booking.request\ndestinationURI=amqp://userForAppA:password@appA-server/vhostForAppA\nqueue=booking.request\n\nsetup another shovel to get booking requests from app2 and app3 to appA in the same way as above.\n```\n\nNow appA will respond to the request on the booking.response queue, I need the booking response message on rabbitMQ-appA to go back to the correct booking.response queue either on app1, app2 or app3, but not to all of them - how do I setup a shovel / federated queue on rabbitMQ-appA that will forward the response back to the correct rabbitMQ (app1, app2, app3) that is expecting a response in their own booking.response queue?\n\nAll these apps are using spring-amqp (in case that's relevant)\nAlternatively, I could setup a rabbitMQ template in Spring that listens to multiple rabbitMQ queues and consumes from each of them.\n\nFrom the docs, this what a typical consumer looks like:\n\n```\n\n \n\n```\n\nIs it possible to specify multiple connection factories in order to do this even if the connection factories are to the same instance of RabbitMQ, but just different vhosts:\n\n**Update**:\n\nBased on Josh's answer, I'd have multiple connection factories:\n\n```\n\n \n```\n\nThen I would use the SimpleRoutingConnectionFactory to wrap both connection-factories:\n\n```\n\n \n \n \n \n \n \n\n```\n\nNow when I declare my rabbitMQ template, I would point it to the SimpleRoutingConnectionFactory instead of the individual connection factories:\n\n```\n\n```\n\n... and then use the template as I would normally use it ...\n\n```\n\n \n\n```\n\n// and messages are consumed from both rabbitMQ instances\n\n... and ...\n\n```\n@Autowired\n private AmqpTemplate template;\n\n template.send(getExchange(), getQueue(), new Message(gson.toJson(message).getBytes(), properties));\n```\n\n// and message publishes to both queues\n\nAm I correct?\n\n========================================\n\nTop Answer:\nIt's been awhile, but if you're using Spring you can create as many connection factories as you want, with their own configurations (host, user/pass, vhost, etc.), just like you did:\n\n```\n@Bean\n@Primary\npublic ConnectionFactory amqpConnectionFactory1() {\n final CachingConnectionFactory connectionFactory = new CachingConnectionFactory();\n \n connectionFactory.setAddresses(\"...\");\n connectionFactory.setUsername(\"...\");\n connectionFactory.setPassword(\"...\");\n connectionFactory.setVirtualHost(\"...\");\n\n return connectionFactory;\n}\n\n@Bean\npublic ConnectionFactory amqpConnectionFactory2() {\n final CachingConnectionFactory connectionFactory = new CachingConnectionFactory();\n \n // ...\n\n return connectionFactory;\n}\n```\n\nAnd your rabbit admin/template's as you go:\n\n```\n@Bean\n@Primary\npublic RabbitAdmin rabbitAdmin1() {\n return new RabbitAdmin(amqpConnectionFactory1());\n}\n\n@Bean\npublic RabbitAdmin rabbitAdmin2() {\n return new RabbitAdmin(amqpConnectionFactory2());\n}\n\n// ...\n\n@Bean\n@Primary\npublic RabbitTemplate rabbitTemplate1() {\n RabbitTemplate rabbitTemplate = new RabbitTemplate(amqpConnectionFactory1());\n\n // ...\n\n return rabbitTemplate;\n}\n\n@Bean\npublic RabbitTemplate rabbitTemplate2() {\n RabbitTemplate rabbitTemplate = new RabbitTemplate(amqpConnectionFactory2());\n\n // ...\n\n return rabbitTemplate;\n}\n```\n\nNote that you have to provide the `@Primary` tag to enable one main bean, once Spring doesn't know which one to choose when you don't inform the `name` explicitly.\n\nWith this in hands, just inject them normally along your components:\n\n```\n@Autowired\nprivate RabbitTemplate template;\n\n// ...\n\n@Autowired\n@Qualifier(\"rabbitTemplate2\") // Needed when want to use the non-primary bean\nprivate RabbitTemplate template;\n```\n\nHope it helps! :)\n\n========================================\n\nCode:\n```text\nShovel1 \nvirtualHost=appA, \nname=booking-request-shovel, \nsourceURI=amqp://userForApp1:password@app1-server/vhostForApp1\nqueue=booking.request\ndestinationURI=amqp://userForAppA:password@appA-server/vhostForAppA\nqueue=booking.request\n\nsetup another shovel to get booking requests from app2 and app3 to appA in the same way as above.\n```\n\n```text\n<rabbit:listener-container connection-factory=\"rabbitConnectionFactory\">\n <rabbit:listener queues=\"some.queue\" ref=\"somePojo\" method=\"handle\"/>\n</rabbit:listener-container>\n```\n\n```text\n<rabbit:connection-factory\n id=\"connectionFactory1\"\n port=\"${rabbit.port1}\"\n virtual-host=\"${rabbit.virtual1}\"\n host=\"${rabbit.host1}\"\n username=\"${rabbit.username1}\"\n password=\"${rabbit.password1}\"\n connection-factory=\"nativeConnectionFactory\" />\n\n <rabbit:connection-factory\n id=\"connectionFactory2\"\n port=\"${rabbit.port2}\"\n virtual-host=\"${rabbit.virtual2}\"\n host=\"${rabbit.host2}\"\n username=\"${rabbit.username2}\"\n password=\"${rabbit.password2}\"\n connection-factory=\"nativeConnectionFactory\" />\n```\n\n```text\n<bean id=\"connectionFactory\" class=\"org.springframework.amqp.rabbit.connection.SimpleRoutingConnectionFactory\">\n <property name=\"targetConnectionFactories\">\n <map>\n <entry key=\"#{connectionFactory1.virtualHost}\" ref=\"connectionFactory1\"/>\n <entry key=\"#{connectionFactory2.virtualHost}\" ref=\"connectionFactory2\"/>\n </map>\n </property>\n</bean>\n```\n\n```text\n<rabbit:template id=\"template\" connection-factory=\"connectionFactory\" />\n```\n\n```text\n<rabbit:listener-container\n connection-factory=\"connectionFactory\"\n channel-transacted=\"true\"\n requeue-rejected=\"true\"\n concurrency=\"${rabbit.consumers}\">\n <rabbit:listener queues=\"${queue.booking}\" ref=\"TransactionMessageListener\" method=\"handle\" />\n</rabbit:listener-container>\n```\n\n```text\n@Autowired\n private AmqpTemplate template;\n\n template.send(getExchange(), getQueue(), new Message(gson.toJson(message).getBytes(), properties));\n```\n\n```java\n@Bean\n@Primary\npublic ConnectionFactory amqpConnectionFactory1() {\n final CachingConnectionFactory connectionFactory = new CachingConnectionFactory();\n \n connectionFactory.setAddresses(\"...\");\n connectionFactory.setUsername(\"...\");\n connectionFactory.setPassword(\"...\");\n connectionFactory.setVirtualHost(\"...\");\n\n return connectionFactory;\n}\n\n@Bean\npublic ConnectionFactory amqpConnectionFactory2() {\n final CachingConnectionFactory connectionFactory = new CachingConnectionFactory();\n \n // ...\n\n return connectionFactory;\n}\n```\n\n```java\n@Bean\n@Primary\npublic RabbitAdmin rabbitAdmin1() {\n return new RabbitAdmin(amqpConnectionFactory1());\n}\n\n@Bean\npublic RabbitAdmin rabbitAdmin2() {\n return new RabbitAdmin(amqpConnectionFactory2());\n}\n\n// ...\n\n@Bean\n@Primary\npublic RabbitTemplate rabbitTemplate1() {\n RabbitTemplate rabbitTemplate = new RabbitTemplate(amqpConnectionFactory1());\n\n // ...\n\n return rabbitTemplate;\n}\n\n@Bean\npublic RabbitTemplate rabbitTemplate2() {\n RabbitTemplate rabbitTemplate = new RabbitTemplate(amqpConnectionFactory2());\n\n // ...\n\n return rabbitTemplate;\n}\n```\n\n```java\n@Autowired\nprivate RabbitTemplate template;\n\n// ...\n\n@Autowired\n@Qualifier(\"rabbitTemplate2\") // Needed when want to use the non-primary bean\nprivate RabbitTemplate template;\n```\n\n```text\n@Primary\n```\n\n```text\nname\n```\n\n========================================\n\nComments:\n- please check this out github.com/janitham/rabbitmq-spring-boot-rpc-worker\n- AbstractRoutingConnectionFactory looks promising, do you have an example of how you use it? What is determineCurrentLookupKey being used for?\n- Here is the spring doc on it. http://docs.spring.io/spring-amqp/docs/1.3.0.M1/reference/ht‌​ml/amqp.html#routing‌​-connection-factory. Let me know if you have any questions after reading that doc.\n- Based on the doc, I have updated my question ... in short, the SimpleRoutingConnectionFactory wraps multiple connection factories and can then be used in the same way as a single connection factory, is that correct?\n- If I can have multiple listener-containers and multiple amqp templates (I'm assuming spring allows that?) and use them either directly or via the SimpleRoutingConnectionFactory which combines them, then that solves my problem since that will allow me to operate on one vHost and selectively operate on other queues / exchanges on other vHosts at the same time (will only be able to test next week, knee deep in a dart project at the moment hence all the questions)\n- Yea you can have multiple instances of SimpleMessageListenerContainer and multiple AmqpTemplate instances. But each is configured with one ConnectionFactory. If you have a fixed number of vhosts known at development time you should be able to write simple logic to determine which AmqpTemplate to use when sending a message. Then just have separate SimpleMessageListenerContainers for each vhost that you need. If you want one AmqpTemplate to work across multiple vhosts then you need AbstractRoutingConnectionFactory.\n- I've got 5 foreseeable external projects that will integrate into the service and if it does get to a point where it becomes an unlimited number of projects, I'll probably avoid the XML configuration and do it with Java as that will give me more control. AbstractRoutingConnectionFactory thus solves my problem, thanks Josh!\n- How to implement org.springframework.amqp.rabbit.core.RabbitTemplate.ConfirmC‌​allback for different template\n- @diogo how can i set this with ssl enabled?","metadata":{"transformedAt":"2026-08-18T18:33:20.149Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":333,"estimatedTokens":2547}}349{"id":"stack-41160585","source":"stackoverflow","questionId":41160585,"title":"RabbitMQ same message to each consumer","tags":["rabbitmq"],"text":"Title: RabbitMQ same message to each consumer\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have implemented the example from the RabbitMQ website:\nRabbitMQ Example\n\nI have expanded it to have an application with a button to send a message.\nNow I started two consumer on two different computers.\nWhen I send the message the first message is sent to computer1, then the second message is sent to computer2, the thrid to computer1 and so on.\n\nWhy is this, and how can I change the behavior to send each message to each consumer?\n\n========================================\n\nTop Answer:\nyou can't it's controlled by the server check **Round-robin dispatching** section\n\nIt decides which consumer turn is. i'm not sure if there is a set of algorithms you can pick from, but at the end server will control this (i think round robin algorithm is default)\n\nunless you want to use routing keys and exchanges\n\n========================================\n\nCode:\n```text\nfanout\n```\n\n```text\ntopic\n```\n\n```text\ndirect\n```\n\n========================================\n\nComments:\n- You implemented producer-consumer model. If you want all consumers to receive the message you should implement publish-subscribe model rabbitmq.com/tutorials/tutorial-three-java.html\n- So it isn't possible to use RabbitMQ as some sort of global notification sender, to send the same message to all clients?\n- Oh, sorry at this moment I see your hint about routing - so it should be possible to do that.\n- @GreenEyedAndy it depends on your requirements you can read about that and see if it fits your need","metadata":{"transformedAt":"2026-08-18T18:33:20.149Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":45,"estimatedTokens":393}}350{"id":"stack-37682184","source":"stackoverflow","questionId":37682184,"title":"How to add a header key:value pair when publishing a message with pika","tags":["python","rabbitmq","amqp","pika"],"text":"Title: How to add a header key:value pair when publishing a message with pika\nTags: python, rabbitmq, amqp, pika\nSource: Stack Overflow\n\nQuestion:\nI am writing an automated test to test a consumer. So far I did not need to include a header when publishing messages but now I do. And it seems like its lacking documentation.\n\nThis is my publisher:\n\n```\nclass RMQProducer(object):\n\n def __init__(self, host, exchange, routing_key):\n self.host = host\n self.exchange = exchange\n self.routing_key = routing_key\n\n def publish_message(self, message):\n connection = pika.BlockingConnection(pika.ConnectionParameters(self.host))\n channel = connection.channel()\n message = json.dumps(message)\n channel.basic_publish(exchange=self.exchange,\n routing_key=self.routing_key,\n body=message)\n```\n\nI want to do smtn like:\n\n```\nchannel.basic_publish(exchange=self.exchange,\n routing_key=self.routing_key,\n body=message,\n headers={\"key\": \"value\"})\n```\n\nWhats the correct way to add headers to this message?\n\n========================================\n\nTop Answer:\ncant say where i get this, but i do it like:\n\n```\nprops = pika.BasicProperties({'headers': {'key': 'value'}})\nchannel.basic_publish(exchange=self.exchange,\n routing_key=self.routing_key,\n body=message, properties = props)\n```\n\n========================================\n\nCode:\n```text\nclass RMQProducer(object):\n\n def __init__(self, host, exchange, routing_key):\n self.host = host\n self.exchange = exchange\n self.routing_key = routing_key\n\n def publish_message(self, message):\n connection = pika.BlockingConnection(pika.ConnectionParameters(self.host))\n channel = connection.channel()\n message = json.dumps(message)\n channel.basic_publish(exchange=self.exchange,\n routing_key=self.routing_key,\n body=message)\n```\n\n```text\nchannel.basic_publish(exchange=self.exchange,\n routing_key=self.routing_key,\n body=message,\n headers={\"key\": \"value\"})\n```\n\n```text\nchannel.basic_publish(exchange=self.exchange,\n routing_key=self.routing_key,\n properties=pika.BasicProperties(\n headers={'key': 'value'} # Add a key/value header\n ),\n body=message)\n```\n\n```text\nprops = pika.BasicProperties({'headers': {'key': 'value'}})\nchannel.basic_publish(exchange=self.exchange,\n routing_key=self.routing_key,\n body=message, properties = props)\n```\n\n```text\nhdrs = {u'': u' ',\n u'': u'',\n u'': u''}\nproperties = pika.BasicProperties(app_id='example-publisher',\n content_type='application/json', \n headers=hdrs)\n```\n\n========================================\n\nComments:\n- You can take a look at an example I have for pika here, on how to add headers. github.com/eandersson/python-rabbitmq-examples/blob/master/…\n- You have another example with my own amqp library here as well github.com/eandersson/amqpstorm/blob/stable/examples/…\n- hdrs dictionary has duplicate keys ;)","metadata":{"transformedAt":"2026-08-18T18:33:20.149Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":107,"estimatedTokens":787}}351{"id":"stack-63607314","source":"stackoverflow","questionId":63607314,"title":"Getting \"PreconditionFailed - inequivalent arg 'x-max-priority' for queue\" error when trying to set up priority queues with Celery+RabbitMQ","tags":["python-3.x","rabbitmq","celery","amqp","priority-queue"],"text":"Title: Getting \"PreconditionFailed - inequivalent arg 'x-max-priority' for queue\" error when trying to set up priority queues with Celery+RabbitMQ\nTags: python-3.x, rabbitmq, celery, amqp, priority-queue\nSource: Stack Overflow\n\nQuestion:\nI have RabbitMQ setup with two queues called: `low` and `high`. I want my celery workers to consume from the high priority queue before consuming tasks for the low priority queue. I get this following error when trying to push a message into RabbitMQ\n\n```\n>>> import tasks\n>>> tasks.high.apply_async()\nTraceback (most recent call last):\n File \"\", line 1, in \n File \"/home/vagrant/.local/lib/python3.6/site-packages/celery/app/task.py\", line 570, in apply_async\n **options\n File \"/home/vagrant/.local/lib/python3.6/site-packages/celery/app/base.py\", line 756, in send_task\n amqp.send_task_message(P, name, message, **options)\n File \"/home/vagrant/.local/lib/python3.6/site-packages/celery/app/amqp.py\", line 552, in send_task_message\n **properties\n File \"/home/vagrant/.local/lib/python3.6/site-packages/kombu/messaging.py\", line 181, in publish\n exchange_name, declare,\n File \"/home/vagrant/.local/lib/python3.6/site-packages/kombu/connection.py\", line 510, in _ensured\n return fun(*args, **kwargs)\n File \"/home/vagrant/.local/lib/python3.6/site-packages/kombu/messaging.py\", line 194, in _publish\n [maybe_declare(entity) for entity in declare]\n File \"/home/vagrant/.local/lib/python3.6/site-packages/kombu/messaging.py\", line 194, in \n [maybe_declare(entity) for entity in declare]\n File \"/home/vagrant/.local/lib/python3.6/site-packages/kombu/messaging.py\", line 102, in maybe_declare\n return maybe_declare(entity, self.channel, retry, **retry_policy)\n File \"/home/vagrant/.local/lib/python3.6/site-packages/kombu/common.py\", line 121, in maybe_declare\n return _maybe_declare(entity, channel)\n File \"/home/vagrant/.local/lib/python3.6/site-packages/kombu/common.py\", line 145, in _maybe_declare\n entity.declare(channel=channel)\n File \"/home/vagrant/.local/lib/python3.6/site-packages/kombu/entity.py\", line 609, in declare\n self._create_queue(nowait=nowait, channel=channel)\n File \"/home/vagrant/.local/lib/python3.6/site-packages/kombu/entity.py\", line 618, in _create_queue\n self.queue_declare(nowait=nowait, passive=False, channel=channel)\n File \"/home/vagrant/.local/lib/python3.6/site-packages/kombu/entity.py\", line 653, in queue_declare\n nowait=nowait,\n File \"/home/vagrant/.local/lib/python3.6/site-packages/amqp/channel.py\", line 1154, in queue_declare\n spec.Queue.DeclareOk, returns_tuple=True,\n File \"/home/vagrant/.local/lib/python3.6/site-packages/amqp/abstract_channel.py\", line 80, in wait\n self.connection.drain_events(timeout=timeout)\n File \"/home/vagrant/.local/lib/python3.6/site-packages/amqp/connection.py\", line 500, in drain_events\n while not self.blocking_read(timeout):\n File \"/home/vagrant/.local/lib/python3.6/site-packages/amqp/connection.py\", line 506, in blocking_read\n return self.on_inbound_frame(frame)\n File \"/home/vagrant/.local/lib/python3.6/site-packages/amqp/method_framing.py\", line 55, in on_frame\n callback(channel, method_sig, buf, None)\n File \"/home/vagrant/.local/lib/python3.6/site-packages/amqp/connection.py\", line 510, in on_inbound_method\n method_sig, payload, content,\n File \"/home/vagrant/.local/lib/python3.6/site-packages/amqp/abstract_channel.py\", line 126, in dispatch_method\n listener(*args)\n File \"/home/vagrant/.local/lib/python3.6/site-packages/amqp/channel.py\", line 282, in _on_close\n reply_code, reply_text, (class_id, method_id), ChannelError,\namqp.exceptions.PreconditionFailed: Queue.declare: (406) PRECONDITION_FAILED - inequivalent arg 'x-max-priority' for queue 'high' in vhost '/': received none but current is the value '10' of type 'signedint'\n```\n\nHere is my celery configuration\n\n```\nimport ssl\nbroker_url=\"amqps://\"\nresult_backend=\"amqp://\"\ninclude=[\"tasks\"]\ntask_acks_late=True\ntask_default_rate_limit=\"150/m\"\ntask_time_limit=300\nworker_prefetch_multiplier=1\nworker_max_tasks_per_child=2\ntimezone=\"UTC\"\nbroker_use_ssl = {'keyfile': '/usr/local//private/my_key.key', 'certfile': '/usr/local//ca-certificates/my_cert.crt', 'ca_certs': '/usr/local//ca-certificates/rootca.crt', 'cert_reqs': ssl.CERT_REQUIRED, 'ssl_version': ssl.PROTOCOL_TLSv1_2}\nfrom kombu import Exchange, Queue\ntask_default_priority=5\ntask_queue_max_priority = 10\ntask_queues = [Queue('high', Exchange('high'), routing_key='high', queue_arguments={'x-max-priority': 10}),]\ntask_routes = {'tasks.high': {'queue': 'high'}}\n```\n\nI have a `tasks.py` script with the following tasks defined\n\n```\nfrom __future__ import absolute_import, unicode_literals\nfrom celery_app import celery_app\n\n@celery_app.task\ndef low(queue='low'):\n print(\"Low Priority\")\n\n@celery_app.task(queue='high')\ndef high():\n print(\"HIGH PRIORITY\")\n```\n\nAnd my `celery_app.py` script:\n\n```\nfrom __future__ import absolute_import, unicode_literals\nfrom celery import Celery\nfrom celery_once import QueueOnce\nimport celeryconfig\n\ncelery_app = Celery(\"test\")\nif __name__ == '__main__':\n celery_app.start()\n```\n\nI am starting the celery workers with this command\n\n```\ncelery -A celery_app worker -l info --config celeryconfig --concurrency=16 -n \"%h:celery\" -O fair -Q high,low\n```\n\nI'm using:\n\n- RabbitMQ: 3.7.17\n\n- Celery: 4.3.0\n\n- Python: 3.6.7\n\n- OS: Ubuntu 18.04.3 LTS bionic\n\n========================================\n\nCode:\n```text\n>>> import tasks\n>>> tasks.high.apply_async()\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\n File \"/home/vagrant/.local/lib/python3.6/site-packages/celery/app/task.py\", line 570, in apply_async\n **options\n File \"/home/vagrant/.local/lib/python3.6/site-packages/celery/app/base.py\", line 756, in send_task\n amqp.send_task_message(P, name, message, **options)\n File \"/home/vagrant/.local/lib/python3.6/site-packages/celery/app/amqp.py\", line 552, in send_task_message\n **properties\n File \"/home/vagrant/.local/lib/python3.6/site-packages/kombu/messaging.py\", line 181, in publish\n exchange_name, declare,\n File \"/home/vagrant/.local/lib/python3.6/site-packages/kombu/connection.py\", line 510, in _ensured\n return fun(*args, **kwargs)\n File \"/home/vagrant/.local/lib/python3.6/site-packages/kombu/messaging.py\", line 194, in _publish\n [maybe_declare(entity) for entity in declare]\n File \"/home/vagrant/.local/lib/python3.6/site-packages/kombu/messaging.py\", line 194, in <listcomp>\n [maybe_declare(entity) for entity in declare]\n File \"/home/vagrant/.local/lib/python3.6/site-packages/kombu/messaging.py\", line 102, in maybe_declare\n return maybe_declare(entity, self.channel, retry, **retry_policy)\n File \"/home/vagrant/.local/lib/python3.6/site-packages/kombu/common.py\", line 121, in maybe_declare\n return _maybe_declare(entity, channel)\n File \"/home/vagrant/.local/lib/python3.6/site-packages/kombu/common.py\", line 145, in _maybe_declare\n entity.declare(channel=channel)\n File \"/home/vagrant/.local/lib/python3.6/site-packages/kombu/entity.py\", line 609, in declare\n self._create_queue(nowait=nowait, channel=channel)\n File \"/home/vagrant/.local/lib/python3.6/site-packages/kombu/entity.py\", line 618, in _create_queue\n self.queue_declare(nowait=nowait, passive=False, channel=channel)\n File \"/home/vagrant/.local/lib/python3.6/site-packages/kombu/entity.py\", line 653, in queue_declare\n nowait=nowait,\n File \"/home/vagrant/.local/lib/python3.6/site-packages/amqp/channel.py\", line 1154, in queue_declare\n spec.Queue.DeclareOk, returns_tuple=True,\n File \"/home/vagrant/.local/lib/python3.6/site-packages/amqp/abstract_channel.py\", line 80, in wait\n self.connection.drain_events(timeout=timeout)\n File \"/home/vagrant/.local/lib/python3.6/site-packages/amqp/connection.py\", line 500, in drain_events\n while not self.blocking_read(timeout):\n File \"/home/vagrant/.local/lib/python3.6/site-packages/amqp/connection.py\", line 506, in blocking_read\n return self.on_inbound_frame(frame)\n File \"/home/vagrant/.local/lib/python3.6/site-packages/amqp/method_framing.py\", line 55, in on_frame\n callback(channel, method_sig, buf, None)\n File \"/home/vagrant/.local/lib/python3.6/site-packages/amqp/connection.py\", line 510, in on_inbound_method\n method_sig, payload, content,\n File \"/home/vagrant/.local/lib/python3.6/site-packages/amqp/abstract_channel.py\", line 126, in dispatch_method\n listener(*args)\n File \"/home/vagrant/.local/lib/python3.6/site-packages/amqp/channel.py\", line 282, in _on_close\n reply_code, reply_text, (class_id, method_id), ChannelError,\namqp.exceptions.PreconditionFailed: Queue.declare: (406) PRECONDITION_FAILED - inequivalent arg 'x-max-priority' for queue 'high' in vhost '/': received none but current is the value '10' of type 'signedint'\n```\n\n```text\nimport ssl\nbroker_url=\"amqps://\"\nresult_backend=\"amqp://\"\ninclude=[\"tasks\"]\ntask_acks_late=True\ntask_default_rate_limit=\"150/m\"\ntask_time_limit=300\nworker_prefetch_multiplier=1\nworker_max_tasks_per_child=2\ntimezone=\"UTC\"\nbroker_use_ssl = {'keyfile': '/usr/local/share/private/my_key.key', 'certfile': '/usr/local/share/ca-certificates/my_cert.crt', 'ca_certs': '/usr/local/share/ca-certificates/rootca.crt', 'cert_reqs': ssl.CERT_REQUIRED, 'ssl_version': ssl.PROTOCOL_TLSv1_2}\nfrom kombu import Exchange, Queue\ntask_default_priority=5\ntask_queue_max_priority = 10\ntask_queues = [Queue('high', Exchange('high'), routing_key='high', queue_arguments={'x-max-priority': 10}),]\ntask_routes = {'tasks.high': {'queue': 'high'}}\n```\n\n```text\nfrom __future__ import absolute_import, unicode_literals\nfrom celery_app import celery_app\n\n@celery_app.task\ndef low(queue='low'):\n print(\"Low Priority\")\n\n@celery_app.task(queue='high')\ndef high():\n print(\"HIGH PRIORITY\")\n```\n\n```text\nfrom __future__ import absolute_import, unicode_literals\nfrom celery import Celery\nfrom celery_once import QueueOnce\nimport celeryconfig\n\ncelery_app = Celery(\"test\")\nif __name__ == '__main__':\n celery_app.start()\n```\n\n```text\ncelery -A celery_app worker -l info --config celeryconfig --concurrency=16 -n \"%h:celery\" -O fair -Q high,low\n```\n\n```text\nlow\n```\n\n```text\nhigh\n```\n\n```text\ntasks.py\n```\n\n```text\ncelery_app.py\n```\n\n```text\nnone\n```\n\n```text\nx-expires\n```\n\n```text\ntask_queue_max_priority\n```\n\n```text\nx-max-priority\n```\n\n```text\nlow\n```\n\n```text\nqueue_arguments={'x-max-priority': 10}\n```\n\n```text\nhigh\n```\n\n========================================\n\nComments:\n- thanks @zok, i think i solved the issue by re-creating the queues\n- re-creating the queues helps. If you're using rabbitmq in docker, you may want to: `docker exec rabbitmq rabbitmqctl stop_app && docker exec rabbitmq rabbitmqctl reset && docker exec rabbitmq rabbitmqctl start_app;` because the current docker rabbitmq container stores queue information on a mounted volume","metadata":{"transformedAt":"2026-08-18T18:33:20.149Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":16,"totalLines":271,"estimatedTokens":2697}}352{"id":"stack-49742269","source":"stackoverflow","questionId":49742269,"title":"RabbitMQ Management Over HTTPS and Nginx","tags":["nginx","https","rabbitmq"],"text":"Title: RabbitMQ Management Over HTTPS and Nginx\nTags: nginx, https, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm trying to access the RabbitMQ interface over HTTPS/SSL with nginx, and I can't figure out what I'm missing.\n\nHere's my rabbitmq.conf file:\n\n```\n[\n {ssl, [{versions, ['tlsv1.2', 'tlsv1.1']}]},\n {rabbit, [\n {reverse_dns_lookups, true},\n {hipe_compile, true},\n {tcp_listeners, [5672]},\n {ssl_listeners, [5671]},\n {ssl_options, [\n {cacertfile, \"/etc/ssl/certs/CA.pem\"},\n {certfile, \"/etc/nginx/ssl/my_domain.crt\"},\n {keyfile, \"/etc/nginx/ssl/my_domain.key\"},\n {versions, ['tlsv1.2', 'tlsv1.1']}\n ]}\n ]\n },\n {rabbitmq_management, [\n {listener, [\n {port, 15671},\n {ssl, true},\n {ssl_opts, [\n {cacertfile, \"/etc/ssl/certs/CA.pem\"},\n {certfile, \"/etc/nginx/ssl/my_domain.crt\"},\n {keyfile, \"/etc/nginx/ssl/my_domain.key\"},\n {versions, ['tlsv1.2', 'tlsv1.1']}\n ]}\n ]}\n ]}\n].\n```\n\nAll works ok when I restart rabbitmq-server\n\nMy nginx file looks like this:\n\n```\nlocation /rabbitmq/ {\n if ($request_uri ~* \"/rabbitmq/(.*)\") {\n proxy_pass https://example.com:15671/$1;\n }\n}\n```\n\nNow, I'm guessing there's something with the ngnix config not being able to resolve the HTTPS URL, as I'm getting 504 timeout errors when trying to browse:\n\n```\nhttps://example.com/rabbitmq/\n```\n\n**Obviously, this is not the correct FQDN, but the SSL cert works fine without the /rabbitmq/**\n\nHas anyone been able to use the RabbitMQ Management web interface on an external connection over a FQDN and HTTPS?\n\nDo I need to create a new \"server\" block in nginx config dedicated to the 15671 port?\n\nAny help would be much appreciated!\n\n========================================\n\nTop Answer:\nI tried the following nginx.conf\n\n```\nlocation /rabbitmq/ {\n proxy_pass http://rabbitmq/;\n proxy_buffering off;\n proxy_set_header Host $http_host;\n proxy_set_header X-Real-IP $remote_addr;\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n proxy_set_header X-Forwarded-Proto $scheme;\n }\n```\n\nHowever I couldn't get the details for a `queue` or `exchange`. I got 404 errors for api calls.\nAnd there was a `%2F` in the url, it's url encoded `/`.\n\nWe need to keep the `%2F` in the API url and pass it to rabbitmq.\n\nThe following link describes how to keep the encoded url part and rewrite it.\nNginx pass_proxy subdirectory without url decoding\n\nSo my solution is:\n\n```\nlocation /rabbitmq/api/ {\n rewrite ^ $request_uri;\n rewrite ^/rabbitmq/api/(.*) /api/$1 break;\n return 400;\n proxy_pass http://rabbitmq$uri;\n proxy_buffering off;\n proxy_set_header Host $http_host;\n proxy_set_header X-Real-IP $remote_addr;\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n proxy_set_header X-Forwarded-Proto $scheme;\n }\n\n location /rabbitmq/ {\n proxy_pass http://rabbitmq/;\n proxy_buffering off;\n proxy_set_header Host $http_host;\n proxy_set_header X-Real-IP $remote_addr;\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n proxy_set_header X-Forwarded-Proto $scheme;\n }\n```\n\n========================================\n\nCode:\n```text\n[\n {ssl, [{versions, ['tlsv1.2', 'tlsv1.1']}]},\n {rabbit, [\n {reverse_dns_lookups, true},\n {hipe_compile, true},\n {tcp_listeners, [5672]},\n {ssl_listeners, [5671]},\n {ssl_options, [\n {cacertfile, \"/etc/ssl/certs/CA.pem\"},\n {certfile, \"/etc/nginx/ssl/my_domain.crt\"},\n {keyfile, \"/etc/nginx/ssl/my_domain.key\"},\n {versions, ['tlsv1.2', 'tlsv1.1']}\n ]}\n ]\n },\n {rabbitmq_management, [\n {listener, [\n {port, 15671},\n {ssl, true},\n {ssl_opts, [\n {cacertfile, \"/etc/ssl/certs/CA.pem\"},\n {certfile, \"/etc/nginx/ssl/my_domain.crt\"},\n {keyfile, \"/etc/nginx/ssl/my_domain.key\"},\n {versions, ['tlsv1.2', 'tlsv1.1']}\n ]}\n ]}\n ]}\n].\n```\n\n```text\nlocation /rabbitmq/ {\n if ($request_uri ~* \"/rabbitmq/(.*)\") {\n proxy_pass https://example.com:15671/$1;\n }\n}\n```\n\n```text\nhttps://example.com/rabbitmq/\n```\n\n```text\nlocation ~* /rabbitmq/api/(.*?)/(.*) {\n proxy_pass http://127.0.0.1:15672/api/$1/%2F/$2?$query_string;\n proxy_buffering off;\n proxy_set_header Host $http_host;\n proxy_set_header X-Real-IP $remote_addr;\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n proxy_set_header X-Forwarded-Proto $scheme;\n }\n\n location ~* /rabbitmq/(.*) {\n rewrite ^/rabbitmq/(.*)$ /$1 break;\n proxy_pass http://127.0.0.1:15672;\n proxy_buffering off;\n proxy_set_header Host $http_host;\n proxy_set_header X-Real-IP $remote_addr;\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n proxy_set_header X-Forwarded-Proto $scheme;\n }\n```\n\n```text\nhttps://example.com/rabbitmq/\n```\n\n```text\nlocation /rabbitmq/ {\n proxy_pass http://rabbitmq/;\n proxy_buffering off;\n proxy_set_header Host $http_host;\n proxy_set_header X-Real-IP $remote_addr;\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n proxy_set_header X-Forwarded-Proto $scheme;\n }\n```\n\n```text\nlocation /rabbitmq/api/ {\n rewrite ^ $request_uri;\n rewrite ^/rabbitmq/api/(.*) /api/$1 break;\n return 400;\n proxy_pass http://rabbitmq$uri;\n proxy_buffering off;\n proxy_set_header Host $http_host;\n proxy_set_header X-Real-IP $remote_addr;\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n proxy_set_header X-Forwarded-Proto $scheme;\n }\n\n location /rabbitmq/ {\n proxy_pass http://rabbitmq/;\n proxy_buffering off;\n proxy_set_header Host $http_host;\n proxy_set_header X-Real-IP $remote_addr;\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n proxy_set_header X-Forwarded-Proto $scheme;\n }\n```\n\n```text\nqueue\n```\n\n```text\nexchange\n```\n\n```text\n%2F\n```\n\n```text\n/\n```\n\n```text\n%2F\n```\n\n```text\nlocation /rabbitmq {\n proxy_pass http://localhost:15672/;\n rewrite ^/rabbitmq/(.*)$ /$1 break;\n}\n```\n\n```text\n<VirtualHost *:443>\n ServerName rabbitmq.your-domain.com\n AllowEncodedSlashes NoDecode \n ... // rest of the settings\n\n <Location \"/\">\n Require all granted\n \n ProxyPass http://localhost:15672/\n ProxyPassReverse http://localhost:15672/\n </Location>\n <Location \"/api\">\n Require all granted\n\n ProxyPass http://localhost:15672/api nocanon\n </Location>\n</VirtualHost>\n```\n\n```text\nlocation /rabbitmq/ {\n # Strip off the \"/rabbitmq\" prefix\n rewrite ^/rabbitmq/(.*) /$1 break;\n\n # Do NOT suffix proxy_pass path with a trailing \"/\". This allows NGINX to pass the client request completely unchanged.\n # - see http://mailman.nginx.org/pipermail/nginx/2009-November/016577.html\n proxy_pass $scheme://localhost:15672;\n}\n```\n\n```yaml\nversion: \"3\"\nservices:\n rabbitmq:\n hostname: 'rmq'\n image: rabbitmq:management\n container_name: 'rmq'\n restart: always\n environment:\n - RABBITMQ_DEFAULT_USER=rmq-usr\n - RABBITMQ_DEFAULT_PASS=burFPso0ULwPMp_w3lkg4QT6-a2H6\n ports:\n - \"5672:5672\"\n - \"127.0.0.1:15672:15672\"\n volumes:\n - ./data:/var/lib/rabbitmq/\n - ./rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf\n```\n\n```text\nmanagement.path_prefix = /rmq\n```\n\n```text\nupstream rmq {\n server 127.0.0.1:15672 fail_timeout=0;\n}\nserver {\n listen 443 ssl http2;\n server_name example.com;\n error_page 497 https://example.com$request_uri;\n ssl_certificate /etc/ssl/certs/example.pem;\n ssl_certificate_key /etc/ssl/private/example.key;\n location /rmq {\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n proxy_set_header X-Forwarded-Proto $scheme;\n proxy_set_header Host $http_host;\n proxy_intercept_errors on;\n proxy_buffering off;\n proxy_redirect off;\n proxy_pass http://rmq;\n allow my.trusted.ip.addresses1;\n allow my.trusted.ip.addresses2;\n deny all;\n }\n}\n```\n\n========================================\n\nComments:\n- This got me most of the way, but I'm getting a bunch of `Cannot read property 'length' of undefined` errors from js files, and I've tried both disabling and clearing my cache... did you ever find the core issue with the JS files and how to fix it?\n- I removed the .js extension from nginx caching.\n- You saved me tons of time here. I only modified the target to another server behind a firewall and it worked perfectly. Just remember to add the \"/\" at the end of the URL in your browser.\n- Awesome David, glad it helped!\n- Thank you Dario. It works for some of the APIs like `queue` or `exchange`. But not with `user` API which doesn't need `%2F` as a vhost\n- I got also the users API part working by removing the first location configuration. It only matched the users API management like `rabbitmq/api/users/my-username` and broke it. All other API calls were already going through the second location configuration. Tested with github.com/nginxinc/NGINX-Demos/tree/master/nginx-regex-test‌​er .\n- Thanks, this rule `proxy_pass http://127.0.0.1:15672/api/$1/%2F/$2?$query_string;` worked for me, but seems like a hack. Should be easier.\n- Bingo, I tried 5 variants of this but this one did it.\n- This was the best solution.\n- An other solution to prevent url decoding is to use $request_uri: `location ^~ /rabbitmq/ { if ($request_uri ~* \"/rabbitmq/(.*)\") { proxy_pass http://rabbitmq_server/$1; }}`\n- Thank you very much for your solution, i was trying to fix it in the wrong way (single rewrite!), this trick made it work!\n- This answer again proves that copying lots of configuration is dangerous sometimes. This answer ended my 2 days debugging and searching for answer. Thanks.\n- Did not work for me. I can access the managment but when I navigate to a queue \"Object not found\". The solution of @leoleozhu worked for me.","metadata":{"transformedAt":"2026-08-18T18:33:20.149Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":18,"totalLines":342,"estimatedTokens":2543}}353{"id":"stack-35117752","source":"stackoverflow","questionId":35117752,"title":"Where should you update Celery settings? On the remote worker or sender?","tags":["python","django","rabbitmq","celery"],"text":"Title: Where should you update Celery settings? On the remote worker or sender?\nTags: python, django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\n**Where should you update celery settings**? On the remote worker or the sender?\n\nFor example, I have an API using Django and Celery. The API sends remote jobs to my remote workers via a broker (RabbitMQ). The workers are running a python script (not using Django) sometimes these works spawn sub tasks. \n\nI've created celery settings on both sides (sender and worker) i.e. they both need the setting `BROKER_URL`. However, say I want to add the setting `CELERY_ACKS_LATE = True`, **which end do I add this setting to?** Each of the remote workers or the sender (API)? \n\nBoth the API and the remote workers connect to the same Broker, each start celery differently. The API creates a celery instance via Django `__init__.py` and the workers start celery via supervisor i.e. `celery -A tasks worker -l info`\n\n========================================\n\nTop Answer:\n`CELERY_ACKS_LATE = True` belongs to worker. It describes if worker should mark the task 'acknowledged' immediately after consuming (before completion) or after completing (late). Both methods have their drawbacks and I think you know what you're doing.\n\nOf course it would be better to have single configuration file for both parties and use it. For example have the common codebase for entire project and after updating the file in VCS and deploy - restart all parties.\n\nBut in this case with this particular flag you can restart only workers.\n\n========================================\n\nCode:\n```text\nBROKER_URL\n```\n\n```text\nCELERY_ACKS_LATE = True\n```\n\n```text\n__init__.py\n```\n\n```text\ncelery -A tasks worker -l info\n```\n\n```text\n@app.task(name='report_task')\ndef reportTask(self, link):\n pass\n```\n\n```text\nCELERY_ACKS_LATE = True\n```\n\n========================================\n\nComments:\n- That makes sense until I look at things like route and queue settings these settings surely have to be set on the sender? I would be nice if the celery does labeled what settings are sender and what are client.\n- Yes, the route and queue settings should be set on the sender , then you Start your remote workers to listen on that queue.\n- also, we do not need to even have the task signature on the sender side if we use the method `send_task()` instead of `apply_async()`. The first param of `send_task` is the name string of the task.","metadata":{"transformedAt":"2026-08-18T18:33:20.149Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":57,"estimatedTokens":612}}354{"id":"stack-30770725","source":"stackoverflow","questionId":30770725,"title":"spring boot rabbitmq MappingJackson2MessageConverter custom object conversion","tags":["java","json","rabbitmq","spring-boot","spring-amqp"],"text":"Title: spring boot rabbitmq MappingJackson2MessageConverter custom object conversion\nTags: java, json, rabbitmq, spring-boot, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI'm trying to create a simple spring boot app with spring boot that \"produce\" messages to a rabbitmq exchange/queue and another sample spring boot app that \"consume\" these messages.\nSo I have two apps (or microservices if you wish).\n1) \"producer\" microservice\n2) \"consumer\" microservice\n\nThe \"producer\" has 2 domain objects. Foo and Bar which should be converted to json and send to rabbitmq.\nThe \"consumer\" should receive and convert the json message into a domain Foo and Bar respectively.\nFor some reason I can not make this simple task. There are not much examples about this.\nFor the message converter I want to use org.springframework.messaging.converter.MappingJackson2MessageConverter\n\nHere is what I have so far:\n\nPRODUCER MICROSERVICE\n\n```\npackage demo.producer;\n\nimport org.springframework.amqp.core.Binding;\nimport org.springframework.amqp.core.BindingBuilder;\nimport org.springframework.amqp.core.Queue;\nimport org.springframework.amqp.core.TopicExchange;\nimport org.springframework.amqp.rabbit.core.RabbitMessagingTemplate;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.boot.CommandLineRunner;\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.messaging.converter.MappingJackson2MessageConverter;\nimport org.springframework.stereotype.Service;\n\n@SpringBootApplication\npublic class ProducerApplication implements CommandLineRunner {\n\n public static void main(String[] args) {\n SpringApplication.run(ProducerApplication.class, args);\n }\n\n @Bean\n Queue queue() {\n return new Queue(\"queue\", false);\n }\n\n @Bean\n TopicExchange exchange() {\n return new TopicExchange(\"exchange\");\n }\n\n @Bean\n Binding binding(Queue queue, TopicExchange exchange) {\n return BindingBuilder.bind(queue).to(exchange).with(\"queue\");\n }\n\n @Bean\n public MappingJackson2MessageConverter jackson2Converter() {\n MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();\n return converter;\n }\n\n @Autowired\n private Sender sender;\n\n @Override\n public void run(String... args) throws Exception {\n sender.sendToRabbitmq(new Foo(), new Bar());\n }\n}\n\n@Service\nclass Sender {\n\n @Autowired\n private RabbitMessagingTemplate rabbitMessagingTemplate;\n @Autowired\n private MappingJackson2MessageConverter mappingJackson2MessageConverter;\n\n public void sendToRabbitmq(final Foo foo, final Bar bar) {\n\n this.rabbitMessagingTemplate.setMessageConverter(this.mappingJackson2MessageConverter);\n\n this.rabbitMessagingTemplate.convertAndSend(\"exchange\", \"queue\", foo);\n this.rabbitMessagingTemplate.convertAndSend(\"exchange\", \"queue\", bar);\n\n }\n}\n\nclass Bar {\n public int age = 33;\n}\n\nclass Foo {\n public String name = \"gustavo\";\n}\n```\n\nCONSUMER MICROSERVICE\n\n```\npackage demo.consumer;\n\nimport org.springframework.amqp.rabbit.annotation.EnableRabbit;\nimport org.springframework.amqp.rabbit.annotation.RabbitListener;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.boot.CommandLineRunner;\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\nimport org.springframework.stereotype.Service;\n\n@SpringBootApplication\n@EnableRabbit\npublic class ConsumerApplication implements CommandLineRunner {\n\n public static void main(String[] args) {\n SpringApplication.run(ConsumerApplication.class, args);\n }\n\n @Autowired\n private Receiver receiver;\n\n @Override\n public void run(String... args) throws Exception {\n\n }\n\n}\n\n@Service\nclass Receiver {\n @RabbitListener(queues = \"queue\")\n public void receiveMessage(Foo foo) {\n System.out.println(\"Received \");\n }\n\n @RabbitListener(queues = \"queue\")\n public void receiveMessage(Bar bar) {\n System.out.println(\"Received \");\n }\n}\n\nclass Foo {\n public String name;\n}\n\nclass Bar {\n public int age;\n}\n```\n\nAnd here is the exception I'm getting:\n\n```\norg.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Listener method could not be invoked with the incoming message\nEndpoint handler details:\nMethod [public void demo.consumer.Receiver.receiveMessage(demo.consumer.Bar)]\nBean [demo.consumer.Receiver@1672fe87]\n at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:116)\n at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.onMessage(MessagingMessageListenerAdapter.java:93)\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:756)\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:679)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$001(SimpleMessageListenerContainer.java:83)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$1.invokeListener(SimpleMessageListenerContainer.java:170)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.invokeListener(SimpleMessageListenerContainer.java:1257)\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:660)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:1021)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:1005)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$700(SimpleMessageListenerContainer.java:83)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1119)\n at java.lang.Thread.run(Thread.java:745)\nCaused by: org.springframework.amqp.support.converter.MessageConversionException: Cannot handle message\n ... 13 common frames omitted\nCaused by: org.springframework.messaging.converter.MessageConversionException: No converter found to convert to class demo.consumer.Bar, message=GenericMessage [payload=byte[10], headers={amqp_receivedRoutingKey=queue, amqp_receivedExchange=exchange, amqp_deliveryTag=1, amqp_deliveryMode=PERSISTENT, amqp_consumerQueue=queue, amqp_redelivered=false, id=87cf7e06-a78a-ddc1-71f5-c55066b46b11, amqp_consumerTag=amq.ctag-msWSwB4bYGWVO2diWSAHlw, contentType=application/json;charset=UTF-8, timestamp=1433989934574}]\n at org.springframework.messaging.handler.annotation.support.PayloadArgumentResolver.resolveArgument(PayloadArgumentResolver.java:115)\n at org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77)\n at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:127)\n at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:100)\n at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:113)\n ... 12 common frames omitted\n```\n\nThe exception says there is no converter, and that is true, my problem is that I have no idea how to set the **MappingJackson2MessageConverter** converter in the consumer side (please note that I want to use **org.springframework.messaging.converter.MappingJackson2MessageConverter** and not **org.springframework.amqp.support.converter.JsonMessageConverter**)\n\nAny thoughts ?\n\nJust in case, you can fork this sample project at: \nhttps://github.com/gustavoorsi/rabbitmq-consumer-receiver\n\n========================================\n\nTop Answer:\nHave not done this myself but it seems like you need to register the appropriate conversions by setting up a RabbitTemplate. Take a look at section 3.1.8 in this Spring documentation. I know it is configured using the AMQP classes but if the messaging class you are mentioning is compatible there is no reason you can't substitute it. Looks like this reference explains how you might do it using Java configuration rather than XML. I have not really used Rabbit so I don't have any personal experience but I would love to hear what you find out.\n\n========================================\n\nCode:\n```text\npackage demo.producer;\n\nimport org.springframework.amqp.core.Binding;\nimport org.springframework.amqp.core.BindingBuilder;\nimport org.springframework.amqp.core.Queue;\nimport org.springframework.amqp.core.TopicExchange;\nimport org.springframework.amqp.rabbit.core.RabbitMessagingTemplate;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.boot.CommandLineRunner;\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.messaging.converter.MappingJackson2MessageConverter;\nimport org.springframework.stereotype.Service;\n\n@SpringBootApplication\npublic class ProducerApplication implements CommandLineRunner {\n\n public static void main(String[] args) {\n SpringApplication.run(ProducerApplication.class, args);\n }\n\n @Bean\n Queue queue() {\n return new Queue(\"queue\", false);\n }\n\n @Bean\n TopicExchange exchange() {\n return new TopicExchange(\"exchange\");\n }\n\n @Bean\n Binding binding(Queue queue, TopicExchange exchange) {\n return BindingBuilder.bind(queue).to(exchange).with(\"queue\");\n }\n\n @Bean\n public MappingJackson2MessageConverter jackson2Converter() {\n MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();\n return converter;\n }\n\n @Autowired\n private Sender sender;\n\n @Override\n public void run(String... args) throws Exception {\n sender.sendToRabbitmq(new Foo(), new Bar());\n }\n}\n\n@Service\nclass Sender {\n\n @Autowired\n private RabbitMessagingTemplate rabbitMessagingTemplate;\n @Autowired\n private MappingJackson2MessageConverter mappingJackson2MessageConverter;\n\n public void sendToRabbitmq(final Foo foo, final Bar bar) {\n\n this.rabbitMessagingTemplate.setMessageConverter(this.mappingJackson2MessageConverter);\n\n this.rabbitMessagingTemplate.convertAndSend(\"exchange\", \"queue\", foo);\n this.rabbitMessagingTemplate.convertAndSend(\"exchange\", \"queue\", bar);\n\n }\n}\n\nclass Bar {\n public int age = 33;\n}\n\nclass Foo {\n public String name = \"gustavo\";\n}\n```\n\n```text\npackage demo.consumer;\n\nimport org.springframework.amqp.rabbit.annotation.EnableRabbit;\nimport org.springframework.amqp.rabbit.annotation.RabbitListener;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.boot.CommandLineRunner;\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\nimport org.springframework.stereotype.Service;\n\n@SpringBootApplication\n@EnableRabbit\npublic class ConsumerApplication implements CommandLineRunner {\n\n public static void main(String[] args) {\n SpringApplication.run(ConsumerApplication.class, args);\n }\n\n @Autowired\n private Receiver receiver;\n\n @Override\n public void run(String... args) throws Exception {\n\n }\n\n}\n\n@Service\nclass Receiver {\n @RabbitListener(queues = \"queue\")\n public void receiveMessage(Foo foo) {\n System.out.println(\"Received <\" + foo.name + \">\");\n }\n\n @RabbitListener(queues = \"queue\")\n public void receiveMessage(Bar bar) {\n System.out.println(\"Received <\" + bar.age + \">\");\n }\n}\n\nclass Foo {\n public String name;\n}\n\nclass Bar {\n public int age;\n}\n```\n\n```text\norg.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Listener method could not be invoked with the incoming message\nEndpoint handler details:\nMethod [public void demo.consumer.Receiver.receiveMessage(demo.consumer.Bar)]\nBean [demo.consumer.Receiver@1672fe87]\n at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:116)\n at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.onMessage(MessagingMessageListenerAdapter.java:93)\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:756)\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:679)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$001(SimpleMessageListenerContainer.java:83)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$1.invokeListener(SimpleMessageListenerContainer.java:170)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.invokeListener(SimpleMessageListenerContainer.java:1257)\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:660)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:1021)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:1005)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$700(SimpleMessageListenerContainer.java:83)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1119)\n at java.lang.Thread.run(Thread.java:745)\nCaused by: org.springframework.amqp.support.converter.MessageConversionException: Cannot handle message\n ... 13 common frames omitted\nCaused by: org.springframework.messaging.converter.MessageConversionException: No converter found to convert to class demo.consumer.Bar, message=GenericMessage [payload=byte[10], headers={amqp_receivedRoutingKey=queue, amqp_receivedExchange=exchange, amqp_deliveryTag=1, amqp_deliveryMode=PERSISTENT, amqp_consumerQueue=queue, amqp_redelivered=false, id=87cf7e06-a78a-ddc1-71f5-c55066b46b11, amqp_consumerTag=amq.ctag-msWSwB4bYGWVO2diWSAHlw, contentType=application/json;charset=UTF-8, timestamp=1433989934574}]\n at org.springframework.messaging.handler.annotation.support.PayloadArgumentResolver.resolveArgument(PayloadArgumentResolver.java:115)\n at org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77)\n at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:127)\n at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:100)\n at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:113)\n ... 12 common frames omitted\n```\n\n```text\npackage demo.consumer;\n\nimport org.springframework.amqp.rabbit.annotation.EnableRabbit;\nimport org.springframework.amqp.rabbit.annotation.RabbitListener;\nimport org.springframework.amqp.rabbit.annotation.RabbitListenerConfigurer;\nimport org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistrar;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.messaging.converter.MappingJackson2MessageConverter;\nimport org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory;\nimport org.springframework.stereotype.Service;\n\n@SpringBootApplication\n@EnableRabbit\npublic class ConsumerApplication implements RabbitListenerConfigurer {\n\n public static void main(String[] args) {\n SpringApplication.run(ConsumerApplication.class, args);\n }\n\n @Bean\n public MappingJackson2MessageConverter jackson2Converter() {\n MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();\n return converter;\n }\n\n @Bean\n public DefaultMessageHandlerMethodFactory myHandlerMethodFactory() {\n DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();\n factory.setMessageConverter(jackson2Converter());\n return factory;\n }\n\n @Override\n public void configureRabbitListeners(RabbitListenerEndpointRegistrar registrar) {\n registrar.setMessageHandlerMethodFactory(myHandlerMethodFactory());\n }\n\n @Autowired\n private Receiver receiver;\n\n}\n\n@Service\nclass Receiver {\n @RabbitListener(queues = \"queue\")\n public void receiveMessage(Foo foo) {\n System.out.println(\"Received <\" + foo.name + \">\");\n }\n\n @RabbitListener(queues = \"queue\")\n public void receiveMessage(Bar bar) {\n System.out.println(\"Received <\" + bar.age + \">\");\n }\n}\n\nclass Foo {\n public String name;\n}\n\nclass Bar {\n public int age;\n}\n```\n\n========================================\n\nComments:\n- Take a look here: stackoverflow.com/questions/29337550/…\n- In that example it uses **org.springframework.amqp.support.converter.Jackson2JsonMessa‌​geConverter** (which belongs to dependency spring-amqp), in my case I want to use **org.springframework.messaging.converter.MappingJackson2Messa‌​geConverter** (which belongs to spring-messaging).\n- 1.5.0 (currently at milestone 1) supports class-level `@RabbitListener` along with `@RabbitHandler` on individual methods to support this use case.\n- If I use request/reply, will get another exeception: `Caused by: org.springframework.amqp.rabbit.listener.adapter.ReplyFailur‌​eException: Failed to send reply with payload 'InvocationResult`, I'm confused.","metadata":{"transformedAt":"2026-08-18T18:33:20.149Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":433,"estimatedTokens":4578}}355{"id":"stack-9576160","source":"stackoverflow","questionId":9576160,"title":"celery - call function on task done","tags":["python","django","rabbitmq","celery"],"text":"Title: celery - call function on task done\nTags: python, django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI'm using celery with django and rabbitmq to create a message queue. I also have a worker, which is originating from a different machine. In a django view I'm starting a process like this:\n\n```\ndef processtask(request, name):\n args = [\"ls\", \"-l\"]\n MyTask.delay(args)\n return HttpResponse(\"Task set to execute.\")\n```\n\nMy task is configured like this:\n\n```\nclass MyTask(Task):\n def run(self, args):\n p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n (out, err) = p.communicate()\n return out\n```\n\nMy question now is how can a broker (my django project) now receive the output from the \"ls -l\" command that the worker executed on his computer. I guess the best thing would be for worker to call a function in broker whenever it's ready to send the output from the executed command. \n\nI would like to receive the output from worker asynchronously, then update the webpage with the output, but that's for another time. For now I would only like to receive the output from worker. \n\n**Update**\n\nRight now I've added a HTTP GET request that is triggered at the end of task notifying the web application that the task is done - I'm also sending the task_id in the http GET. The http GET method calls django view, which creates AsyncResult and gets the result, but the problem is that when calling **result.get()** I get the following error:\n\n```\n/usr/lib64/python2.6/site-packages/django_celery-2.5.1-py2.6.egg/djcelery/managers.py:178: TxIsolationWarning: Polling results with transaction isolation level repeatable-read within the same transaction may give outdated results. Be sure to commit the transaction for each poll iteration.\n \"Polling results with transaction isolation level\"\n```\n\nAny ideas why? I'm not using database, because I'm using rabbitmq with AMQP.\n\nUpdate.\n\nI would very much like to use third option, which seems like the best option - for small and big return values. My whole task looks like this:\n\n```\nclass MyTask(Task):\n def __call__(self, *args, **kwargs):\n return self.run(*args, **kwargs)\n\n def after_return(self, status, retval, task_id, args, kwargs, einfo):\n if self.webhost is not None:\n conn = httplib.HTTPConnection(self.webhost, self.webport)\n conn.request(\"HEAD\", \"/vuln/task/output/\"+task_id)\n\n def run(self, args, webhost=None, webport=None):\n self.webhost = webhost\n self.webport = webport\n r = \"This is a basic result string used for code clarity\"\n return r\n```\n\nSo I've overridden the after_return function, which should also release the lock on my task, since the task's run() function already returned a value. In the HEAD request I'm basically calling a django function, which calls AsyncResult on task_id, which should provide with the result of the task. I've used arbitrary result for testing purposes in my case, since it's only for testing.\n\nI would like to know why the above code doesn't work. I can use on_success, but I don't think it will make a difference - or will it?\n\n========================================\n\nCode:\n```text\ndef processtask(request, name):\n args = [\"ls\", \"-l\"]\n MyTask.delay(args)\n return HttpResponse(\"Task set to execute.\")\n```\n\n```text\nclass MyTask(Task):\n def run(self, args):\n p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n (out, err) = p.communicate()\n return out\n```\n\n```text\n/usr/lib64/python2.6/site-packages/django_celery-2.5.1-py2.6.egg/djcelery/managers.py:178: TxIsolationWarning: Polling results with transaction isolation level repeatable-read within the same transaction may give outdated results. Be sure to commit the transaction for each poll iteration.\n \"Polling results with transaction isolation level\"\n```\n\n```text\nclass MyTask(Task):\n def __call__(self, *args, **kwargs):\n return self.run(*args, **kwargs)\n\n def after_return(self, status, retval, task_id, args, kwargs, einfo):\n if self.webhost is not None:\n conn = httplib.HTTPConnection(self.webhost, self.webport)\n conn.request(\"HEAD\", \"/vuln/task/output/\"+task_id)\n\n def run(self, args, webhost=None, webport=None):\n self.webhost = webhost\n self.webport = webport\n r = \"This is a basic result string used for code clarity\"\n return r\n```\n\n```text\nASyncResult\n```\n\n========================================\n\nComments:\n- Could you save the output of the command in the database ?\n- Hi, no, because the workers don't have access to the broker's database and nor do I want them to have access. I definitely need to send back a result and then process it in the broker.\n- Maybe you could make an HTTP API to send back the result ? There are some pretty easy ways to do that in Django.\n- Yes, I made a HTTP GET call which sends back an ID. Then the web application should just read the output of the task, but it doesn't work - I've updated my question with the results of a failure.\n- I don't understand what you're doing - you didn't post your code. But if a URL is going to be used to store a result, then it should definitely **not** be on GET, that would be against RFC2616. Consider POST.\n- Can you elaborate more on how it doesn't work?\n- Sorry. The problem is the same as it was before, so it can't get the result of the task getting \"Polling results with transaction isolation level\" error.\n- I have a very similar problem, why could this not be done with the Celery Signal `task_postrun(task_id, task, args, kwargs, retval)`? What am I missing about signals (please)? Are the receivers also on an unknown process rather than Django?\n- Thank you for your comment. I've updated my answer to ask additional question, which I need to be answered before accepting your answer, which is really good btw.","metadata":{"transformedAt":"2026-08-18T18:33:20.149Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":120,"estimatedTokens":1441}}356{"id":"stack-44927085","source":"stackoverflow","questionId":44927085,"title":"Prevent @RabbitListener in spring-rabbit from trying to connect to server during integration test","tags":["java","spring","rabbitmq","spring-rabbit"],"text":"Title: Prevent @RabbitListener in spring-rabbit from trying to connect to server during integration test\nTags: java, spring, rabbitmq, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI want to run some acceptance tests for my services that are using rabbitMq but I want to ignore all that require inter-service communication (amqp). \n\nThe problem however is that Spring tries to connect to the (non-exisiting) rabbit host on startup so it can register its consumers. It does that for each method that is annotated with `@RabbitListener` which can get quite annoying with the long timeout this has if I have more than one listener in my service.\n\nHow can I reduce this timeout or even prevent @RabbitListener connection all together?\n\nOur (simplified) Rabbit Config:\n\n```\n@Configuration\n@EnableRabbit\npublic class RabbitMqConfig {\n\n public RabbitMqConfig(\n @Value(\"${rabbitmq.host}\") String rabbitHost,\n @Value(\"${rabbitmq.port}\") int rabbitPort,\n @Value(\"${exchange.name}\") String exchange) {\n this.rabbitHost = rabbitHost;\n this.rabbitPort = rabbitPort;\n this.exchange= exchange;\n }\n\n @Bean\n DirectExchange directExchangeBean() {\n return new DirectExchange(this.exchange, true, false);\n }\n\n @Bean\n public ConnectionFactory connectionFactory() {\n CachingConnectionFactory connectionFactory = new CachingConnectionFactory(rabbitHost);\n connectionFactory.setPort(rabbitPort);\n return connectionFactory;\n }\n\n @Bean\n public RabbitTemplate rabbitTemplate() {\n return new RabbitTemplate(connectionFactory());\n }\n\n @Bean\n public Queue itemDoneQueue() {\n return new Queue(ITEM_DONE_QUEUENAME, true);\n }\n\n @Bean\n Binding itemDoneBinding() {\n return BindingBuilder.bind(itemDoneQueue()).to(directExchangeBean()).with(ITEM_DONE_KEY);\n }\n\n}\n```\n\nProperties\n\n```\nrabbitmq.host=192.168.42.100\nrabbitmq.port=5672\nexchange.name=myExchange\n```\n\nThe Listener:\n\n```\n@RabbitListener(queues = ITEM_DONE_QUEUENAME)\n public void receiveMessageFromItemDoneQueue(String message) {\n // do the work\n }\n```\n\nThe Test:\n\n```\n@RunWith(SpringRunner.class)\n@SpringBootTest(classes = {Application.class}) \npublic abstract class RabbitTest {\n```\n\nReally nothing special here. Obviously during testing the rabbit host is unavailable. That is fine. I want to ignore the fact. And quickly. \n\nI've tried \n\n```\nspring.rabbitmq.connection-timeout=1\n```\n\nBut that didn't change anything.\n\nUsing \n\n```\nspring.rabbitmq.listener.simple.auto-startup=false\n```\n\nneither does anything.\n\nUsing \n\n```\nspring.autoconfigure.exclude:org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration\n```\n\njust kills my application context loading with spring complaining about a `NoSuchBeanDefinitionException: No bean named 'rabbitListenerContainerFactory' available`\n\nAny ideas?\nThanks!\n\n========================================\n\nTop Answer:\nI've had a similar problem, but solved it with\n\n`spring.rabbitmq.listener.direct.auto-startup=false`\n\nSpringBoot version 2.2.4.RELEASE\n\nSpring framework version 5.2.3.RELEASE\n\n========================================\n\nCode:\n```text\n@Configuration\n@EnableRabbit\npublic class RabbitMqConfig {\n\n public RabbitMqConfig(\n @Value(\"${rabbitmq.host}\") String rabbitHost,\n @Value(\"${rabbitmq.port}\") int rabbitPort,\n @Value(\"${exchange.name}\") String exchange) {\n this.rabbitHost = rabbitHost;\n this.rabbitPort = rabbitPort;\n this.exchange= exchange;\n }\n\n @Bean\n DirectExchange directExchangeBean() {\n return new DirectExchange(this.exchange, true, false);\n }\n\n @Bean\n public ConnectionFactory connectionFactory() {\n CachingConnectionFactory connectionFactory = new CachingConnectionFactory(rabbitHost);\n connectionFactory.setPort(rabbitPort);\n return connectionFactory;\n }\n\n @Bean\n public RabbitTemplate rabbitTemplate() {\n return new RabbitTemplate(connectionFactory());\n }\n\n\n @Bean\n public Queue itemDoneQueue() {\n return new Queue(ITEM_DONE_QUEUENAME, true);\n }\n\n @Bean\n Binding itemDoneBinding() {\n return BindingBuilder.bind(itemDoneQueue()).to(directExchangeBean()).with(ITEM_DONE_KEY);\n }\n\n}\n```\n\n```text\nrabbitmq.host=192.168.42.100\nrabbitmq.port=5672\nexchange.name=myExchange\n```\n\n```text\n@RabbitListener(queues = ITEM_DONE_QUEUENAME)\n public void receiveMessageFromItemDoneQueue(String message) {\n // do the work\n }\n```\n\n```text\n@RunWith(SpringRunner.class)\n@SpringBootTest(classes = {Application.class}) \npublic abstract class RabbitTest {\n```\n\n```text\nspring.rabbitmq.connection-timeout=1\n```\n\n```text\nspring.rabbitmq.listener.simple.auto-startup=false\n```\n\n```text\nspring.autoconfigure.exclude:org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration\n```\n\n```text\n@RabbitListener\n```\n\n```text\nNoSuchBeanDefinitionException: No bean named 'rabbitListenerContainerFactory' available\n```\n\n```text\n@Bean\n public ConnectionFactory connectionFactory() {\n com.rabbitmq.client.ConnectionFactory connectionFactory = new com.rabbitmq.client.ConnectionFactory();\n connectionFactory.setConnectionTimeout(this.connectionTimeout);\n connectionFactory.setHost(this.rabbitHost);\n connectionFactory.setPort(this.rabbitPort);\n CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(\n connectionFactory);\n return cachingConnectionFactory;\n }\n```\n\n```text\nCachingConnectionFactory\n```\n\n```text\nspring.rabbitmq.connection-timeout\n```\n\n```text\nspring.rabbitmq.listener.simple.auto-startup=false\n```\n\n```text\nBrokerRunning\n```\n\n```text\n@Bean\n ConnectionFactory connectionFactory() {\n ConnectionFactory factory = mock(ConnectionFactory.class);\n Connection connection = mock(Connection.class);\n Channel channel = mock(Channel.class);\n willReturn(connection).given(factory).createConnection();\n willReturn(channel).given(connection).createChannel(anyBoolean());\n given(channel.isOpen()).willReturn(true);\n return factory;\n }\n```\n\n```text\n@Rule\npublic BrokerRunning brokerRunning = BrokerRunning.isNotRunning();\n```\n\n```text\nBrokerRunning.isNotRunning()\n```\n\n```text\n@Bean\nSimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(\n SimpleRabbitListenerContainerFactoryConfigurer containerFactoryConfigurer, \n ConnectionFactory connectionFactory) {\n\n SimpleRabbitListenerContainerFactory listenerContainerFactory =\n new SimpleRabbitListenerContainerFactory();\n containerFactoryConfigurer.configure(listenerContainerFactory, connectionFactory);\n\n return listenerContainerFactory;\n}\n```\n\n```text\nspring.rabbitmq.listener.simple.auto-startup=false\n```\n\n```text\nSimpleRabbitListenerContainerFactory\n```\n\n```text\nRabbitAnnotationDrivenConfiguration.rabbitListenerContainerFactory()\n```\n\n```text\nSimpleRabbitListenerContainerFactoryConfigurer\n```\n\n```text\nSimpleRabbitListenerContainerFactory\n```\n\n```text\napplication.properties\n```\n\n```text\n@Bean\n public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {\n SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();\n factory.setConnectionFactory(connectionFactory);\n\n factory.setAutoStartup(autoStartup); //autoStartup = false, in your case\n\n factory.setMessageConverter(jsonMessageConverter())\n return factory;\n }\n```\n\n```text\nspring.rabbitmq.listener.direct.auto-startup=false\n```\n\n```text\nspring.rabbitmq.listener.direct.auto-startup=false\n```\n\n```text\nlistener.direct.auto-startup\nor\nlistener.simple.auto-startup\n```\n\n```text\nmanagement.health.rabbit.enabled=false\n```\n\n```text\nspring.rabbitmq.listener.simple.auto-startup: false\n```\n\n```text\n@EnableAutoConfiguration(exclude = RabbitAutoConfiguration.class)\n```\n\n========================================\n\nComments:\n- auto-startup=false perfect to stop listners at startup\n- How to do this with Rabbitmq 3.8.9 and Spring Boot 2.2.6.RELEASE? setConnectionTimeout method is not there in SimpleMessageListenerContainer class?\n- I have a custom SimpleRabbitListenerContainerFactory bean in my RabbitConfig configuration class and this worked as expected after I added the SimpleRabbitListenerContainerFactoryConfigurer and ConnectionFactory beans to the parameters to be passed in. I submitted an edit to your post to correct that. Thank you!\n- @LethalLima, accepted your edit as it clarifies usage of the provided code example for those who are not familiar with framework classes. I personally didn't go that way due to some peculiarities in my config\n- That was it.. simple and direct. Or should I say simple and not direct! Thank you!","metadata":{"transformedAt":"2026-08-18T18:33:20.149Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":31,"totalLines":345,"estimatedTokens":2147}}357{"id":"stack-37067467","source":"stackoverflow","questionId":37067467,"title":"Sending a persistent message in RabbitMQ via HTTP API","tags":["http","rabbitmq","persistent"],"text":"Title: Sending a persistent message in RabbitMQ via HTTP API\nTags: http, rabbitmq, persistent\nSource: Stack Overflow\n\nQuestion:\nI want to send a persistent mesaage via HTTP API. Im using this command:\n\n```\ncurl -u UN:PWD -H \"content-type:application/json\" -X POST -d'{\"properties\":{},\"routing_key\":\"QueueName\",\"payload\":\"HI\",\"payload_encoding\":\"string\", \"deliverymode\": 2}' http://url:8080/api/exchanges/%2f/amq.default/publish\n```\n\nMy queue is durable and deliverymode is also set to 2(Persistent), but the messages published are not durable. What change needs to be done?\nWhen I send the same via Management Console, the message is persistent but not via HTTP API.\n\n========================================\n\nCode:\n```text\ncurl -u UN:PWD -H \"content-type:application/json\" -X POST -d'{\"properties\":{},\"routing_key\":\"QueueName\",\"payload\":\"HI\",\"payload_encoding\":\"string\", \"deliverymode\": 2}' http://url:8080/api/exchanges/%2f/amq.default/publish\n```\n\n```text\ncurl -u guest:guest -H \"content-type:application/json\" -X POST -d'{\"properties\":{\"delivery_mode\":2},\"routing_key\":\"QueueName\",\"payload\":\"HI\",\"payload_encoding\":\"string\"}' http://localhost:15672/api/exchanges/%2f/amq.default/publish\n```\n\n```text\ndelivery_mode\n```\n\n```text\n\"properties\"\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.150Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":32,"estimatedTokens":312}}358{"id":"stack-43895737","source":"stackoverflow","questionId":43895737,"title":"High thread count stuck in GCFrame causes high CPU usage","tags":["c#","multithreading","rabbitmq","quartz.net","kestrel"],"text":"Title: High thread count stuck in GCFrame causes high CPU usage\nTags: c#, multithreading, rabbitmq, quartz.net, kestrel\nSource: Stack Overflow\n\nQuestion:\nWe have an application that uses Kestrel to serve HTTP requests. We've had some problems in the past where high load caused the thread pool to spawn thousands of threads, at which point we would get lock convoy symptoms. Most of the time, the threads would start blocking each other at `Monitor.Enter()` somewhere in our code, causing delays and more contentions until the application became unresponsive with a 100% CPU usage due to context switching. The problem would not go away until we restarted the application.\n\nHowever, we've eliminated most locks and implemented a throttling mechanism so that we don't allow more than 1000 threads to enter the application. We're using the `System.Threading.Semaphore` class to allow only a set number of threads to continue. This has solved our lock contention problems, but possible introduced a new problem:\n\nWe still get cases of 100% CPU usage and high thread count (500-1000 threads), although this time the threads are not blocked on `Monitor.Enter()`. Instead, when we do thread dump (using `Microsoft.Diagnostics.Runtime.ClrRuntime`), we see the following call stack (for hundreds of threads):\n\n```\nthread id = 892\n GCFrame\n GCFrame\n HelperMethodFrame\n System.Threading.TimerQueueTimer.Fire()\n System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()\n System.Threading.ThreadPoolWorkQueue.Dispatch()\n DebuggerU2MCatchHandlerFrame\n```\n\nIn this case, the problem would case the application to become unresponsive, but in most cases it solves itself after a few minutes. Sometimes it takes hours.\n\nWhat does a call stack like this mean? Is this a known problem with Kestrel or is it some kind of combination of Kestrel and `Semaphore` that is causing this?\n\nUPDATE: A memory dump reveals that the `HelperMethodFrame` in the call stack is probably a call to `Monitor.Enter()` after all. However we still cannot pinpoint whether this is in our code or in Kestrel or some other library. When we had our lock convoy problems before, we would see our code in the call stack. Now it seems to be a `Monitor.Enter()` call inside `TimerQueueTimer` instead, which we are not using in our code. The memory dump looks like this:\n\n.NET stack trace:\n\n```\nChild SP IP Call Site\n0000005a92b5e438 00007ff8a11c0c6a [GCFrame: 0000005a92b5e438] \n0000005a92b5e660 00007ff8a11c0c6a [GCFrame: 0000005a92b5e660] \n0000005a92b5e698 00007ff8a11c0c6a [HelperMethodFrame: 0000005a92b5e698] System.Threading.Monitor.Enter(System.Object)\n0000005a92b5e790 00007ff88f30096b System.Threading.TimerQueueTimer.Fire()\n0000005a92b5e7e0 00007ff88f2e1a1d System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()\n0000005a92b5e820 00007ff88f2e1f70 System.Threading.ThreadPoolWorkQueue.Dispatch()\n0000005a92b5ed48 00007ff890413753 [DebuggerU2MCatchHandlerFrame: 0000005a92b5ed48]\n```\n\nFull stack trace:\n\n```\n# Child-SP RetAddr : Args to Child : Call Site\n00 0000005a`9cf5e9a8 00007ff8`9e6513ed : 00000000`00000000 00000000`00000001 00000000`00000001 00000000`00000000 : ntdll!ZwWaitForMultipleObjects+0xa\n01 0000005a`9cf5e9b0 00007ff8`904e92aa : 0000005a`9cf5ef48 00007ff5`fffce000 0000005a`00000000 00000000`00000000 : KERNELBASE!WaitForMultipleObjectsEx+0xe1\n02 0000005a`9cf5ec90 00007ff8`904e91bf : 00000000`00000001 00000000`00000000 0000005a`66b48e20 00000000`ffffffff : clr!WaitForMultipleObjectsEx_SO_TOLERANT+0x62\n03 0000005a`9cf5ecf0 00007ff8`904e8fb1 : 0000005a`66b48e20 00000000`00000001 00000000`00000018 00007ff8`00000000 : clr!Thread::DoAppropriateWaitWorker+0x243\n04 0000005a`9cf5edf0 00007ff8`90731267 : 00000000`00000000 00007ff8`00000001 0000004f`a419c548 0000004f`a419c548 : clr!Thread::DoAppropriateWait+0x7d\n05 0000005a`9cf5ee70 00007ff8`90834a56 : 0000005a`5aec0308 0000005a`9cf5f0d0 00000000`00000000 0000005a`66b48e20 : clr!CLREventBase::WaitEx+0x28e6b7\n06 0000005a`9cf5ef00 00007ff8`9083495a : 0000005a`5aec0308 0000005a`66b48e20 00000000`00000000 00000050`22945ab8 : clr!AwareLock::EnterEpilogHelper+0xca\n07 0000005a`9cf5efc0 00007ff8`90763c8c : 0000005a`66b48e20 0000005a`5aec0308 0000005a`5aec0308 00000000`002d0d01 : clr!AwareLock::EnterEpilog+0x62\n08 0000005a`9cf5f020 00007ff8`908347ed : 00000000`00000000 0000005a`9cf5f0d0 0000005a`5aec0308 0000005a`5aec0301 : clr!AwareLock::Enter+0x24390c\n09 0000005a`9cf5f050 00007ff8`908338a5 : 00000050`22945ab8 0000005a`9cf5f201 0000005a`66b48e20 00007ff8`90419050 : clr!AwareLock::Contention+0x2fd\n0a 0000005a`9cf5f110 00007ff8`8f30096b : 0000005a`5aec0308 0000005a`9cf5f2d0 0000005a`9cf5f560 00000000`00000000 : clr!JITutil_MonContention+0xc5\n0b 0000005a`9cf5f2a0 00007ff8`8f2e1a1d : 00000051`a2bb6bb0 00007ff8`90417d0e 00000050`229491d8 0000005a`9cf5f330 : mscorlib_ni+0x49096b\n0c 0000005a`9cf5f2f0 00007ff8`8f2e1f70 : 00000000`00000000 0000005a`9cf5f3a8 00000000`00000001 0000005a`9cf5f370 : mscorlib_ni+0x471a1d\n0d 0000005a`9cf5f330 00007ff8`90413753 : 00000000`00000004 00000000`00000000 0000005a`9cf5f600 0000005a`9cf5f688 : mscorlib_ni+0x471f70\n0e 0000005a`9cf5f3d0 00007ff8`9041361c : 00000050`22945ab8 00000000`00000000 0000005a`9cf5f640 0000005a`9cf5f6c8 : clr!CallDescrWorkerInternal+0x83\n0f 0000005a`9cf5f410 00007ff8`904144d3 : 00000000`00000000 00000000`00000004 0000005a`9cf5f858 0000005a`9cf5f688 : clr!CallDescrWorkerWithHandler+0x4e\n10 0000005a`9cf5f450 00007ff8`9041b73d : 0000005a`9cf5fb70 0000005a`9cf5fb20 0000005a`9cf5fb70 00000000`00000001 : clr!MethodDescCallSite::CallTargetWorker+0x2af\n11 0000005a`9cf5f5e0 00007ff8`90416810 : 00000000`00000007 00007ff8`00000000 ffffffff`fffffffe 0000005a`66b48e20 : clr!QueueUserWorkItemManagedCallback+0x2a\n12 0000005a`9cf5f6d0 00007ff8`904167c0 : 00670061`00500064 00000000`00730065 ffffffff`fffffffe 0000005a`66b48e20 : clr!ManagedThreadBase_DispatchInner+0x29\n13 0000005a`9cf5f710 00007ff8`90416705 : ffffffff`ffffffff 00007ff8`90414051 0000005a`9cf5f7b8 00000000`ffffffff : clr!ManagedThreadBase_DispatchMiddle+0x6c\n14 0000005a`9cf5f810 00007ff8`90416947 : ffffffff`ffffffff 0000005a`66b48e20 0000005a`66b48e20 00000000`00000001 : clr!ManagedThreadBase_DispatchOuter+0x75\n15 0000005a`9cf5f8a0 00007ff8`9041b6a2 : 0000005a`9cf5f988 00000000`00000000 00000000`00000001 00007ff8`9e651118 : clr!ManagedThreadBase_FullTransitionWithAD+0x2f\n16 0000005a`9cf5f900 00007ff8`904158ba : 0000005a`9cf5fb70 0000005a`9cf5fb68 00000000`00000000 00000000`00000200 : clr!ManagedPerAppDomainTPCount::DispatchWorkItem+0x11c\n17 0000005a`9cf5fa90 00007ff8`904157da : 0000010b`010b010b 0000005a`9cf5fb20 00000000`00000000 0000005a`66b48e20 : clr!ThreadpoolMgr::ExecuteWorkRequest+0x64\n18 0000005a`9cf5fac0 00007ff8`90433e1e : 00000000`00000000 00000000`00000000 00000000`00000001 00000000`0000041d : clr!ThreadpoolMgr::WorkerThreadStart+0x3b5\n19 0000005a`9cf5fb60 00007ff8`9e7c13d2 : 00007ff8`90433da8 0000005a`5add4db0 00000000`00000000 00000000`00000000 : clr!Thread::intermediateThreadProc+0x7d\n1a 0000005a`9cf5fca0 00007ff8`a11454e4 : 00007ff8`9e7c13b0 00000000`00000000 00000000`00000000 00000000`00000000 : kernel32!BaseThreadInitThunk+0x22\n1b 0000005a`9cf5fcd0 00000000`00000000 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x34\n```\n\nUPDATE 2: WinDbg `syncblock` command gives us this:\n\n```\nThe version of SOS does not match the version of CLR you are debugging. Please\nload the matching version of SOS for the version of CLR you are debugging.\nCLR Version: 4.6.1055.0\nSOS Version: 4.6.1637.0\nIndex SyncBlock MonitorHeld Recursion Owning Thread Info SyncBlock Owner\n 148 0000005a5aec0308 426 0 0000000000000000 none 0000005022945ab8 System.Threading.TimerQueue\n-----------------------------\nTotal 152\nCCW 1\nRCW 1\nComClassFactory 0\nFree 66\n```\n\nUPDATE 3: More digging shows that we have about 42000 Timer objects:\n\n```\n00007ff8871bedd0 41728 1001472 System.Runtime.Caching.MemoryCacheEqualityComparer\n00007ff88f4a0998 42394 1017456 System.Threading.TimerHolder\n00007ff8871bbed0 41728 1335296 System.Runtime.Caching.UsageBucket[]\n00007ff88f51ab30 41749 1335968 Microsoft.Win32.SafeHandles.SafeWaitHandle\n00007ff88f519de0 42394 1356608 System.Threading.Timer\n00007ff8871be870 41728 1669120 System.Runtime.Caching.CacheUsage\n00007ff88f50ea80 41734 2003232 System.Threading.ManualResetEvent\n00007ff8871be810 41728 2336768 System.Runtime.Caching.CacheExpires\n00007ff88f519f08 42390 2712960 System.Threading.TimerCallback\n00007ff8871be558 41728 3338240 System.Runtime.Caching.MemoryCacheStore\n00007ff88f4a0938 42394 3730672 System.Threading.TimerQueueTimer\n00007ff8871be8d0 41728 4005888 System.Runtime.Caching.UsageBucket\n00007ff8871bb9c8 41728 11016192 System.Runtime.Caching.ExpiresBucket[]\n```\n\nChecking a few of the _methodPtr references, they all point to:\n\n```\n00007ff8`871b22c0 0f1f440000 nop dword ptr [rax+rax]\n00007ff8`871b22c5 33d2 xor edx,edx\n00007ff8`871b22c7 4533c0 xor r8d,r8d\n00007ff8`871b22ca 488d055ffeffff lea rax,[System_Runtime_Caching_ni+0x32130 (00007ff8`871b2130)]\n00007ff8`871b22d1 48ffe0 jmp rax\n```\n\nAnd with GC Traces looking similar to this:\n\n```\n0:000> !gcroot 00000055629e5ca0\nThe version of SOS does not match the version of CLR you are debugging. Please\nload the matching version of SOS for the version of CLR you are debugging.\nCLR Version: 4.6.1055.0\nSOS Version: 4.6.1637.0\nThread 27a368:\n 0000005a61c4ed10 00007ff88f2d2490 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)\n r14: \n -> 0000004b6296f840 System.Threading.ThreadHelper\n -> 0000004b6296f7a0 System.Threading.ThreadStart\n -> 0000004b6296f750 Quartz.Simpl.SimpleThreadPool+WorkerThread\n -> 0000004b6296f7e0 System.Threading.Thread\n -> 0000004b62959710 System.Runtime.Remoting.Contexts.Context\n -> 0000004aa29315a8 System.AppDomain\n -> 0000004c22c4b368 System.EventHandler\n -> 00000051e2eb5f48 System.Object[]\n -> 00000050629e6180 System.EventHandler\n -> 000000506298b268 System.Runtime.Caching.MemoryCache\n -> 000000506298b348 System.Runtime.Caching.MemoryCacheStore[]\n -> 000000506298d470 System.Runtime.Caching.MemoryCacheStore\n -> 000000506298d5a0 System.Runtime.Caching.CacheExpires\n -> 000000506298e868 System.Threading.Timer\n -> 000000506298eaa8 System.Threading.TimerHolder\n -> 000000506298e888 System.Threading.TimerQueueTimer\n -> 000000506298fe78 System.Threading.TimerQueueTimer\n```\n\n========================================\n\nCode:\n```text\nthread id = 892\n GCFrame\n GCFrame\n HelperMethodFrame\n System.Threading.TimerQueueTimer.Fire()\n System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()\n System.Threading.ThreadPoolWorkQueue.Dispatch()\n DebuggerU2MCatchHandlerFrame\n```\n\n```text\nChild SP IP Call Site\n0000005a92b5e438 00007ff8a11c0c6a [GCFrame: 0000005a92b5e438] \n0000005a92b5e660 00007ff8a11c0c6a [GCFrame: 0000005a92b5e660] \n0000005a92b5e698 00007ff8a11c0c6a [HelperMethodFrame: 0000005a92b5e698] System.Threading.Monitor.Enter(System.Object)\n0000005a92b5e790 00007ff88f30096b System.Threading.TimerQueueTimer.Fire()\n0000005a92b5e7e0 00007ff88f2e1a1d System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()\n0000005a92b5e820 00007ff88f2e1f70 System.Threading.ThreadPoolWorkQueue.Dispatch()\n0000005a92b5ed48 00007ff890413753 [DebuggerU2MCatchHandlerFrame: 0000005a92b5ed48]\n```\n\n```text\n# Child-SP RetAddr : Args to Child : Call Site\n00 0000005a`9cf5e9a8 00007ff8`9e6513ed : 00000000`00000000 00000000`00000001 00000000`00000001 00000000`00000000 : ntdll!ZwWaitForMultipleObjects+0xa\n01 0000005a`9cf5e9b0 00007ff8`904e92aa : 0000005a`9cf5ef48 00007ff5`fffce000 0000005a`00000000 00000000`00000000 : KERNELBASE!WaitForMultipleObjectsEx+0xe1\n02 0000005a`9cf5ec90 00007ff8`904e91bf : 00000000`00000001 00000000`00000000 0000005a`66b48e20 00000000`ffffffff : clr!WaitForMultipleObjectsEx_SO_TOLERANT+0x62\n03 0000005a`9cf5ecf0 00007ff8`904e8fb1 : 0000005a`66b48e20 00000000`00000001 00000000`00000018 00007ff8`00000000 : clr!Thread::DoAppropriateWaitWorker+0x243\n04 0000005a`9cf5edf0 00007ff8`90731267 : 00000000`00000000 00007ff8`00000001 0000004f`a419c548 0000004f`a419c548 : clr!Thread::DoAppropriateWait+0x7d\n05 0000005a`9cf5ee70 00007ff8`90834a56 : 0000005a`5aec0308 0000005a`9cf5f0d0 00000000`00000000 0000005a`66b48e20 : clr!CLREventBase::WaitEx+0x28e6b7\n06 0000005a`9cf5ef00 00007ff8`9083495a : 0000005a`5aec0308 0000005a`66b48e20 00000000`00000000 00000050`22945ab8 : clr!AwareLock::EnterEpilogHelper+0xca\n07 0000005a`9cf5efc0 00007ff8`90763c8c : 0000005a`66b48e20 0000005a`5aec0308 0000005a`5aec0308 00000000`002d0d01 : clr!AwareLock::EnterEpilog+0x62\n08 0000005a`9cf5f020 00007ff8`908347ed : 00000000`00000000 0000005a`9cf5f0d0 0000005a`5aec0308 0000005a`5aec0301 : clr!AwareLock::Enter+0x24390c\n09 0000005a`9cf5f050 00007ff8`908338a5 : 00000050`22945ab8 0000005a`9cf5f201 0000005a`66b48e20 00007ff8`90419050 : clr!AwareLock::Contention+0x2fd\n0a 0000005a`9cf5f110 00007ff8`8f30096b : 0000005a`5aec0308 0000005a`9cf5f2d0 0000005a`9cf5f560 00000000`00000000 : clr!JITutil_MonContention+0xc5\n0b 0000005a`9cf5f2a0 00007ff8`8f2e1a1d : 00000051`a2bb6bb0 00007ff8`90417d0e 00000050`229491d8 0000005a`9cf5f330 : mscorlib_ni+0x49096b\n0c 0000005a`9cf5f2f0 00007ff8`8f2e1f70 : 00000000`00000000 0000005a`9cf5f3a8 00000000`00000001 0000005a`9cf5f370 : mscorlib_ni+0x471a1d\n0d 0000005a`9cf5f330 00007ff8`90413753 : 00000000`00000004 00000000`00000000 0000005a`9cf5f600 0000005a`9cf5f688 : mscorlib_ni+0x471f70\n0e 0000005a`9cf5f3d0 00007ff8`9041361c : 00000050`22945ab8 00000000`00000000 0000005a`9cf5f640 0000005a`9cf5f6c8 : clr!CallDescrWorkerInternal+0x83\n0f 0000005a`9cf5f410 00007ff8`904144d3 : 00000000`00000000 00000000`00000004 0000005a`9cf5f858 0000005a`9cf5f688 : clr!CallDescrWorkerWithHandler+0x4e\n10 0000005a`9cf5f450 00007ff8`9041b73d : 0000005a`9cf5fb70 0000005a`9cf5fb20 0000005a`9cf5fb70 00000000`00000001 : clr!MethodDescCallSite::CallTargetWorker+0x2af\n11 0000005a`9cf5f5e0 00007ff8`90416810 : 00000000`00000007 00007ff8`00000000 ffffffff`fffffffe 0000005a`66b48e20 : clr!QueueUserWorkItemManagedCallback+0x2a\n12 0000005a`9cf5f6d0 00007ff8`904167c0 : 00670061`00500064 00000000`00730065 ffffffff`fffffffe 0000005a`66b48e20 : clr!ManagedThreadBase_DispatchInner+0x29\n13 0000005a`9cf5f710 00007ff8`90416705 : ffffffff`ffffffff 00007ff8`90414051 0000005a`9cf5f7b8 00000000`ffffffff : clr!ManagedThreadBase_DispatchMiddle+0x6c\n14 0000005a`9cf5f810 00007ff8`90416947 : ffffffff`ffffffff 0000005a`66b48e20 0000005a`66b48e20 00000000`00000001 : clr!ManagedThreadBase_DispatchOuter+0x75\n15 0000005a`9cf5f8a0 00007ff8`9041b6a2 : 0000005a`9cf5f988 00000000`00000000 00000000`00000001 00007ff8`9e651118 : clr!ManagedThreadBase_FullTransitionWithAD+0x2f\n16 0000005a`9cf5f900 00007ff8`904158ba : 0000005a`9cf5fb70 0000005a`9cf5fb68 00000000`00000000 00000000`00000200 : clr!ManagedPerAppDomainTPCount::DispatchWorkItem+0x11c\n17 0000005a`9cf5fa90 00007ff8`904157da : 0000010b`010b010b 0000005a`9cf5fb20 00000000`00000000 0000005a`66b48e20 : clr!ThreadpoolMgr::ExecuteWorkRequest+0x64\n18 0000005a`9cf5fac0 00007ff8`90433e1e : 00000000`00000000 00000000`00000000 00000000`00000001 00000000`0000041d : clr!ThreadpoolMgr::WorkerThreadStart+0x3b5\n19 0000005a`9cf5fb60 00007ff8`9e7c13d2 : 00007ff8`90433da8 0000005a`5add4db0 00000000`00000000 00000000`00000000 : clr!Thread::intermediateThreadProc+0x7d\n1a 0000005a`9cf5fca0 00007ff8`a11454e4 : 00007ff8`9e7c13b0 00000000`00000000 00000000`00000000 00000000`00000000 : kernel32!BaseThreadInitThunk+0x22\n1b 0000005a`9cf5fcd0 00000000`00000000 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x34\n```\n\n```text\nThe version of SOS does not match the version of CLR you are debugging. Please\nload the matching version of SOS for the version of CLR you are debugging.\nCLR Version: 4.6.1055.0\nSOS Version: 4.6.1637.0\nIndex SyncBlock MonitorHeld Recursion Owning Thread Info SyncBlock Owner\n 148 0000005a5aec0308 426 0 0000000000000000 none 0000005022945ab8 System.Threading.TimerQueue\n-----------------------------\nTotal 152\nCCW 1\nRCW 1\nComClassFactory 0\nFree 66\n```\n\n```text\n00007ff8871bedd0 41728 1001472 System.Runtime.Caching.MemoryCacheEqualityComparer\n00007ff88f4a0998 42394 1017456 System.Threading.TimerHolder\n00007ff8871bbed0 41728 1335296 System.Runtime.Caching.UsageBucket[]\n00007ff88f51ab30 41749 1335968 Microsoft.Win32.SafeHandles.SafeWaitHandle\n00007ff88f519de0 42394 1356608 System.Threading.Timer\n00007ff8871be870 41728 1669120 System.Runtime.Caching.CacheUsage\n00007ff88f50ea80 41734 2003232 System.Threading.ManualResetEvent\n00007ff8871be810 41728 2336768 System.Runtime.Caching.CacheExpires\n00007ff88f519f08 42390 2712960 System.Threading.TimerCallback\n00007ff8871be558 41728 3338240 System.Runtime.Caching.MemoryCacheStore\n00007ff88f4a0938 42394 3730672 System.Threading.TimerQueueTimer\n00007ff8871be8d0 41728 4005888 System.Runtime.Caching.UsageBucket\n00007ff8871bb9c8 41728 11016192 System.Runtime.Caching.ExpiresBucket[]\n```\n\n```text\n00007ff8`871b22c0 0f1f440000 nop dword ptr [rax+rax]\n00007ff8`871b22c5 33d2 xor edx,edx\n00007ff8`871b22c7 4533c0 xor r8d,r8d\n00007ff8`871b22ca 488d055ffeffff lea rax,[System_Runtime_Caching_ni+0x32130 (00007ff8`871b2130)]\n00007ff8`871b22d1 48ffe0 jmp rax\n```\n\n```text\n0:000> !gcroot 00000055629e5ca0\nThe version of SOS does not match the version of CLR you are debugging. Please\nload the matching version of SOS for the version of CLR you are debugging.\nCLR Version: 4.6.1055.0\nSOS Version: 4.6.1637.0\nThread 27a368:\n 0000005a61c4ed10 00007ff88f2d2490 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)\n r14: \n -> 0000004b6296f840 System.Threading.ThreadHelper\n -> 0000004b6296f7a0 System.Threading.ThreadStart\n -> 0000004b6296f750 Quartz.Simpl.SimpleThreadPool+WorkerThread\n -> 0000004b6296f7e0 System.Threading.Thread\n -> 0000004b62959710 System.Runtime.Remoting.Contexts.Context\n -> 0000004aa29315a8 System.AppDomain\n -> 0000004c22c4b368 System.EventHandler\n -> 00000051e2eb5f48 System.Object[]\n -> 00000050629e6180 System.EventHandler\n -> 000000506298b268 System.Runtime.Caching.MemoryCache\n -> 000000506298b348 System.Runtime.Caching.MemoryCacheStore[]\n -> 000000506298d470 System.Runtime.Caching.MemoryCacheStore\n -> 000000506298d5a0 System.Runtime.Caching.CacheExpires\n -> 000000506298e868 System.Threading.Timer\n -> 000000506298eaa8 System.Threading.TimerHolder\n -> 000000506298e888 System.Threading.TimerQueueTimer\n -> 000000506298fe78 System.Threading.TimerQueueTimer\n```\n\n```text\nMonitor.Enter()\n```\n\n```text\nSystem.Threading.Semaphore\n```\n\n```text\nMonitor.Enter()\n```\n\n```text\nMicrosoft.Diagnostics.Runtime.ClrRuntime\n```\n\n```text\nSemaphore\n```\n\n```text\nHelperMethodFrame\n```\n\n```text\nMonitor.Enter()\n```\n\n```text\nMonitor.Enter()\n```\n\n```text\nTimerQueueTimer\n```\n\n```text\nsyncblock\n```\n\n```text\nSystem.Runtime.Caching.MemoryCache\n```\n\n```text\nMemoryCache\n```\n\n```text\nMemoryCache\n```\n\n```text\nSystem.Runtime.Caching\n```\n\n========================================\n\nComments:\n- Jeez Marie, if a thousand threads can't drive cpu usage up to 100% then all hope is lost. If you got that many timers ticking then something went seriously wrong a while ago. Not terribly obvious how it went from TimerQueueTimer.Fire() straight into Monitor.Enter(), perhaps you need to look for [MethodImpl(MethodImplOptions.Synchronized)]. Always a good way to cause unintended deadlock.\n- Thanks for the tip, will look for that attribute. Some more digging suggests that this might not be related to Kestrel, but rather to Quartz.net, which our application is also using. Added the tag.\n- That seems very likely. Quartz is a Java library. MethodImplOptions.Synchronized is a curse inherited from Java.\n- Digging into the source (v 2.3.3 that we are using) for Quartz.net, I find that there are explicit Monitor.Enter calls inside the Run() method of Quartz.Simpl.SimpleThreadPool+WorkerThread. No MethodImplOptions.Synchronized attribute what I can see. We'll try to configure Quartz to not use its' own SimpleThreadPool and use something else instead.\n- We've seen the same thing happening inside RabbitMQ client library as well. It seems as though a lot of Timer objects are created, which causes the thread pool in Quartz or RabbitMQ (both use their own thread pools) to stall and create a lot of new threads. Could this be related to using GCLatencyMode.SustainedLowLatency? It's one of the changes we've done in the version exhibiting this behaviour.\n- I really, really appreciate you adding how things worked out. Not sure it's the answer I need yet, but it has given me reason to dig deeper in a direction.","metadata":{"transformedAt":"2026-08-18T18:33:20.150Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":21,"totalLines":339,"estimatedTokens":5345}}359{"id":"stack-53102929","source":"stackoverflow","questionId":53102929,"title":"RabbitMQ Error 530 vhost not found with pika","tags":["python","rabbitmq","pika"],"text":"Title: RabbitMQ Error 530 vhost not found with pika\nTags: python, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI am trying to connect to a remote rabbitmq server. I have the correct credentials and vhost exists on the remove server, but I cannot connect.\nI get the error \n\n pika.exceptions.ProbableAccessDeniedError: (530, 'NOT_ALLOWED - vhost\n test_vhost not found')\n\nI have struggled with this for a while but I can't seem to get what the problem is.\n\n========================================\n\nTop Answer:\nFor me,\nbefore:\n\n```\nAMQP_URL = 'amqp://guest:guest@localhost:5672/hostname'\n```\n\nafter:\n\n```\nAMQP_URL = 'amqp://guest:guest@localhost:5672'\n```\n\nit works.\n\n========================================\n\nCode:\n```text\n/test_vhost\n```\n\n```text\ntest_vhost\n```\n\n```text\nAMQP_URL = 'amqp://guest:guest@localhost:5672/hostname'\n```\n\n```text\nAMQP_URL = 'amqp://guest:guest@localhost:5672'\n```\n\n========================================\n\nComments:\n- Have you set permissions for the user you're trying to use?\n- Yes, the permissions have been set correctly for the user I'm trying to connect with\n- removing slash at the end in rmq connection string worked for me.\n- added a '/' and it worked :)\n- This is what worked for me too. Thanks. `f\"pyamqp://{RABBITMQ_USER}:{RABBITMQ_PASS}@localhost/{RABBIT‌​MQ_VHOST}\"`\n- Added // after the hostname. So from CELERY_BROKER_URL = 'amqp://usrename:pass@rabbitmq:5672/vhost' to CELERY_BROKER_URL = 'amqp://usrename:pass@rabbitmq:5672//vhost'\n- when you create the vhost you need to add a slash? I'm confused.\n- @chovy you don't add the slash when creating it, you add it in the connection url\n- how to add url parameters like `heartbeat` if slash is removed at the end\n- @Perry you can keep the slash, just try 'amqp://guest:guest@localhost:5672/?heartbeat=30'","metadata":{"transformedAt":"2026-08-18T18:33:20.150Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":63,"estimatedTokens":456}}360{"id":"stack-38275479","source":"stackoverflow","questionId":38275479,"title":"RabbitMQ management returns 500 when trying to list queues","tags":["rabbitmq"],"text":"Title: RabbitMQ management returns 500 when trying to list queues\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI've just installed Erlang 19.0, then Rabbitmq Server 3.6.3. OS - Windows 10. Then I installed rabbitmq_management plugin, then I started rabbitmq-server. I can successfully login into management console. The problem is when I go to Queues I get as error:\n\n Got response code 500 with body {\"error\":\"JSON encode error:\n {bad_term,#{error_logger => true,kill => true,size =>\n 0}}\",\"reason\":\"While encoding: \\n[{total_count,1},\\n {item_count,1},\\n\n {filtered_count,1},\\n {page,1},\\n {page_size,100},\\n {page_count,1},\\n\n {items,\\n [[{memory,22048},\\n {reductions,6633},\\n\n {reductions_details,[{rate,0.0}]},\\n {messages,0},\\n\n {messages_details,[{rate,0.0}]},\\n {messages_ready,0},\\n\n {messages_ready_details,[{rate,0.0}]},\\n\n {messages_unacknowledged,0},\\n\n {messages_unacknowledged_details,[{rate,0.0}]},\\n\n {idle_since,>},\\n\n {consumer_utilisation,''},\\n {policy,''},\\n\n {exclusive_consumer_tag,''},\\n {consumers,1},\\n\n {recoverable_slaves,''},\\n {state,running},\\n {reductions,6633},\\n\n {garbage_collection,\\n [{max_heap_size,#{error_logger => true,kill =>\n true,size => 0}},\\n {min_bin_vheap_size,46422},\\n\n {min_heap_size,233},\\n {fullsweep_after,65535},\\n {minor_gcs,3}]},\\n\n {messages_ram,0},\\n {messages_ready_ram,0},\\n\n {messages_unacknowledged_ram,0},\\n {messages_persistent,0},\\n\n {message_bytes,0},\\n {message_bytes_ready,0},\\n\n {message_bytes_unacknowledged,0},\\n {message_bytes_ram,0},\\n\n {message_bytes_persistent,0},\\n {head_message_timestamp,''},\\n\n {disk_reads,0},\\n {disk_writes,0},\\n {backing_queue_status,\\n\n {struct,\\n [{mode,default},\\n {q1,0},\\n {q2,0},\\n\n {delta,[delta,undefined,0,undefined]},\\n {q3,0},\\n {q4,0},\\n\n {len,0},\\n {target_ram_count,infinity},\\n {next_seq_id,0},\\n\n {avg_ingress_rate,0.0},\\n {avg_egress_rate,0.0},\\n\n {avg_ack_ingress_rate,0.0},\\n {avg_ack_egress_rate,0.0}]}},\\n\n {node,'rabbit@DESKTOP-330SD1I'},\\n {arguments,{struct,[]}},\\n\n {exclusive,false},\\n {auto_delete,false},\\n {durable,true},\\n\n {vhost,>},\\n {name,>}]]}]\"}\n\nIf I remove from myself a privilegy to access \"/\" virtual host error disappears, but no queues are shown, which I suppose is wrong, because I have a running application which sends and reveives messages.\n\nHere is the closest question to my, but those solution doesn't help.\n\nP.S. I don't even hope somebody help me, I just wanted to post this question so at least this error can be googled.\n\n========================================\n\nTop Answer:\nI've installed Erlang OTP 18.0 and RabbitMq 3.6.3 management console started to work fine. Before I tried to use OTP 19.0 and I got errors during browsing web-console.\n\n========================================\n\nComments:\n- This works! Can't believe there is no information about that on the rabbitmq website.\n- erlang 19 has only been out for a few weeks. sometimes it takes a while for information to move from testing to the site.\n- For those of you who are using Archlinux I recommend: wget archive.archlinux.org/repos/2015/11/01/community/os/x86_64/… and pacman -U erlang-18.1-1-x86_64.pkg.tar.xz . This package works great :)","metadata":{"transformedAt":"2026-08-18T18:33:20.150Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":56,"estimatedTokens":793}}361{"id":"stack-12153451","source":"stackoverflow","questionId":12153451,"title":"Celery - Can a message in RabbitMQ be consumed by two or more workers at the same time?","tags":["python","rabbitmq","celery","django-celery"],"text":"Title: Celery - Can a message in RabbitMQ be consumed by two or more workers at the same time?\nTags: python, rabbitmq, celery, django-celery\nSource: Stack Overflow\n\nQuestion:\nPerhaps I'm being silly asking the question but I need to wrap my head around the basic concepts before I do further work.\n\nI am processing a few thousand RSS feeds, using multiple Celery worker nodes and a RabbitMQ node as the broker. The URL of each feed is being written as a message in the queue. A worker just reads the URL from the queue and starts processing it. **I have to ensure that a single RSS feed does not get processed by two workers at the same time.**\n\nThe article Ensuring a task is only executed one at a time suggests a Memcahced-based solution for locking the feed when it's being processed. \n\nBut what I'm trying to understand is that why do I need to use Memcached (or something else) to ensure that a message on a RabbitMQ queue not be consumed by multiple workers at the same time. Is there some configuration change in RabbitMQ (or Celery) that I can do to achieve this goal?\n\n========================================\n\nTop Answer:\nA single MQ message will certainly not be seen by multiple consumers in a normal working setup. You'll have to do some work for the cases involving failing/crashing workers, read up on auto-acks and message rejections, but the basic case is sound.\n\nI don't see a synchronized queue (read: MQ) in the article you've linked, so (as far as I can tell) they're using the lock mechanism (read: memcache) to synchronize, as an alternative. And I can think of a few problems which wouldn't be there in a proper MQ setup.\n\n========================================\n\nCode:\n```text\n@task(...)\ndef my_task(\n\nmy_task.apply(1)\n```\n\n```text\nRedis\n```\n\n```text\nsetnx\n```\n\n========================================\n\nComments:\n- There's a difference between needing to lock on the messages and locking on the feeds. Which do you need to do?\n- @PlatinumAzure - care to explain a bit? I need locking on the message (if that means ensuring it won't consumed by multiple workers).","metadata":{"transformedAt":"2026-08-18T18:33:20.150Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":43,"estimatedTokens":523}}362{"id":"stack-37867486","source":"stackoverflow","questionId":37867486,"title":"How can I delete a RabbitMq exchange?","tags":["rabbitmq"],"text":"Title: How can I delete a RabbitMq exchange?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI can easily delete queues, like this:\n\n`rabbitmqadmin delete queue name='MyQ'`\n\nHowever, I cannot find a way to delete exchanges. What am I missing?\n\n========================================\n\nTop Answer:\nyou can also get the same functionality with the `rabbitmq management` web interface,\nusually accessible via `localhost:15672`\n\n(the rabbitmq management plugin need to be installed, usually the case)\n\n========================================\n\nCode:\n```text\nrabbitmqadmin delete queue name='MyQ'\n```\n\n```text\n./rabbitmqadmin delete exchange name='myexchange'\nexchange deleted\n```\n\n```text\nrabbitmq management\n```\n\n```text\nlocalhost:15672\n```\n\n========================================\n\nComments:\n- How do you delete an exchange that isn't on the default vhost?\n- very old but had the same problem: /rabbitmqadmin -V vhost delete exchange name='myexchange'\n- Is there a way to delete all/multiple exchanges???\n- here you can find some useful command line github.com/Gsantomaggio/rabbitmq-utils/blob/master/…\n- My web interface throws a 500 error when clicking on exchanges, does this happen to anyone else?","metadata":{"transformedAt":"2026-08-18T18:33:20.150Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":47,"estimatedTokens":303}}363{"id":"stack-39642777","source":"stackoverflow","questionId":39642777,"title":"RabbitMQ + C# + SSL","tags":["c#","ssl","rabbitmq"],"text":"Title: RabbitMQ + C# + SSL\nTags: c#, ssl, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm trying to use C# to get RabbitMQ 3.6.2 to use SSL/TLS on Windows 7 against Erlang 18.0. I'm running into errors when I'm enabling SSL in my C# code. I have gone through the steps to set up SSL/TLS here. I've also gone through the [troubleshooting steps][2] which show turn up successful (except I couldn't do the stunnel step due to lack of knowledge of stunnel). Here's my C# code trying to connect to RabbitMQ:\n\n```\nvar factory = new ConnectionFactory()\n{\n // NOTE: guest username ONLY works with HostName \"localhost\"!\n //HostName = Environment.MachineName,\n HostName = \"localhost\",\n UserName = \"guest\",\n Password = \"guest\",\n};\n\n// Without this line, RabbitMQ.log shows error: \"SSL: hello: tls_handshake.erl:174:Fatal error: protocol version\"\n// When I add this line to go to TLS 1.2, .NET throws an exception: The remote certificate is invalid according to the validation procedure.\n// https://stackoverflow.com/questions/9983265/the-remote-certificate-is-invalid-according-to-the-validation-procedure:\n// Walked through this tutorial to add the client certificate as a Windows Trusted Root Certificate: http://www.sqlservermart.com/HowTo/Windows_Import_Certificate.aspx\nfactory.Ssl.Version = SslProtocols.Tls12;\n\nfactory.Ssl.ServerName = \"localhost\"; //System.Net.Dns.GetHostName();\nfactory.Ssl.CertPath = @\"C:\\OpenSSL-Win64\\client\\keycert.p12\";\nfactory.Ssl.CertPassphrase = \"Re$sp3cMyS3curi1ae!\";\nfactory.Ssl.Enabled = true;\nfactory.Port = 5671;\n\n// Error: \"The remote certificate is invalid according to the validation procedure.\"\nusing (var connection = factory.CreateConnection())\n{\n}\n```\n\nThere's a StackOverflow post regarding the \"The remote certificate is invalid according to the validation procedure.\" exception, but the hack fix doesn't seem to take effect as the callback method suggested is never called. I *think* that I've added my certificate generated via OpenSSL to the Windows Trusted Root Certification Authorities certificates list for local computer. So I'm at a loss here. Any ideas on how to proceed?\n\n**Edit:** Here's the final working code for anyone struggling to implement SSL on Rabbit:\n\n```\nvar factory = new ConnectionFactory();\nfactory.HostName = ConfigurationManager.AppSettings[\"rabbitmqHostName\"];\n\nfactory.AuthMechanisms = new AuthMechanismFactory[] { new ExternalMechanismFactory() };\n// Note: This should NEVER be \"localhost\"\nfactory.Ssl.ServerName = ConfigurationManager.AppSettings[\"rabbitmqServerName\"];\n// Path to my .p12 file.\nfactory.Ssl.CertPath = ConfigurationManager.AppSettings[\"certificateFilePath\"];\n// Passphrase for the certificate file - set through OpenSSL\nfactory.Ssl.CertPassphrase = ConfigurationManager.AppSettings[\"certificatePassphrase\"];\nfactory.Ssl.Enabled = true;\n// Make sure TLS 1.2 is supported & enabled by your operating system\nfactory.Ssl.Version = SslProtocols.Tls12;\n// This is the default RabbitMQ secure port\nfactory.Port = 5671;\nfactory.VirtualHost = \"/\";\n// Standard RabbitMQ authentication (if not using ExternalAuthenticationFactory)\n//factory.UserName = ConfigurationManager.AppSettings[\"rabbitmqUsername\"];\n//factory.Password = ConfigurationManager.AppSettings[\"rabbitmqPassword\"];\n\nusing (var connection = factory.CreateConnection())\n{\n using (var channel = connection.CreateModel())\n {\n // publish some messages...\n }\n}\n```\n\nThanks,\n\nAndy\n\n========================================\n\nTop Answer:\nMy problem was related to using self signed certificates. I had to add the SslOption AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateNameMismatch |\nSslPolicyErrors.RemoteCertificateChainErrors\n\nIn the example connection factory creation code sslEnabled is true.\n\n```\nnew ConnectionFactory()\n {\n Uri = uri,\n ClientProvidedName = clientProvidedName,\n AutomaticRecoveryEnabled = true,\n Ssl = new SslOption(){\n Enabled = sslEnabled,\n AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateNameMismatch |\n SslPolicyErrors.RemoteCertificateChainErrors} ,\n\n NetworkRecoveryInterval = TimeSpan.FromSeconds(networkRecoveryIntervalSecs)\n }\n```\n\n========================================\n\nCode:\n```text\nvar factory = new ConnectionFactory()\n{\n // NOTE: guest username ONLY works with HostName \"localhost\"!\n //HostName = Environment.MachineName,\n HostName = \"localhost\",\n UserName = \"guest\",\n Password = \"guest\",\n};\n\n// Without this line, RabbitMQ.log shows error: \"SSL: hello: tls_handshake.erl:174:Fatal error: protocol version\"\n// When I add this line to go to TLS 1.2, .NET throws an exception: The remote certificate is invalid according to the validation procedure.\n// https://stackoverflow.com/questions/9983265/the-remote-certificate-is-invalid-according-to-the-validation-procedure:\n// Walked through this tutorial to add the client certificate as a Windows Trusted Root Certificate: http://www.sqlservermart.com/HowTo/Windows_Import_Certificate.aspx\nfactory.Ssl.Version = SslProtocols.Tls12;\n\nfactory.Ssl.ServerName = \"localhost\"; //System.Net.Dns.GetHostName();\nfactory.Ssl.CertPath = @\"C:\\OpenSSL-Win64\\client\\keycert.p12\";\nfactory.Ssl.CertPassphrase = \"Re$sp3cMyS3curi1ae!\";\nfactory.Ssl.Enabled = true;\nfactory.Port = 5671;\n\n// Error: \"The remote certificate is invalid according to the validation procedure.\"\nusing (var connection = factory.CreateConnection())\n{\n}\n```\n\n```text\nvar factory = new ConnectionFactory();\nfactory.HostName = ConfigurationManager.AppSettings[\"rabbitmqHostName\"];\n\nfactory.AuthMechanisms = new AuthMechanismFactory[] { new ExternalMechanismFactory() };\n// Note: This should NEVER be \"localhost\"\nfactory.Ssl.ServerName = ConfigurationManager.AppSettings[\"rabbitmqServerName\"];\n// Path to my .p12 file.\nfactory.Ssl.CertPath = ConfigurationManager.AppSettings[\"certificateFilePath\"];\n// Passphrase for the certificate file - set through OpenSSL\nfactory.Ssl.CertPassphrase = ConfigurationManager.AppSettings[\"certificatePassphrase\"];\nfactory.Ssl.Enabled = true;\n// Make sure TLS 1.2 is supported & enabled by your operating system\nfactory.Ssl.Version = SslProtocols.Tls12;\n// This is the default RabbitMQ secure port\nfactory.Port = 5671;\nfactory.VirtualHost = \"/\";\n// Standard RabbitMQ authentication (if not using ExternalAuthenticationFactory)\n//factory.UserName = ConfigurationManager.AppSettings[\"rabbitmqUsername\"];\n//factory.Password = ConfigurationManager.AppSettings[\"rabbitmqPassword\"];\n\nusing (var connection = factory.CreateConnection())\n{\n using (var channel = connection.CreateModel())\n {\n // publish some messages...\n }\n}\n```\n\n```text\nSsl.ServerName\n```\n\n```text\nSsl.CertPath\n```\n\n```text\nfactory.Ssl.ServerName = \"[certificate cn]\";\n```\n\n```cs\nnew ConnectionFactory()\n {\n Uri = uri,\n ClientProvidedName = clientProvidedName,\n AutomaticRecoveryEnabled = true,\n Ssl = new SslOption(){\n Enabled = sslEnabled,\n AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateNameMismatch |\n SslPolicyErrors.RemoteCertificateChainErrors} ,\n\n NetworkRecoveryInterval = TimeSpan.FromSeconds(networkRecoveryIntervalSecs)\n }\n```\n\n```text\nconst string RabbitMqServerHostname = \"myserver.northeurope.cloudapp.azure.com\";\n\n var factory = new ConnectionFactory()\n {\n HostName = RabbitMqServerHostname,\n UserName = \"myuser\",\n Password = \"mypassword\",\n\n // The settings below turn on SSL\n Port = 5671,\n Ssl = new SslOption\n {\n Enabled = true,\n ServerName = RabbitMqServerHostname\n }\n };\n```\n\n========================================\n\nComments:\n- So your certificate is issued for \"localhost\"? Because Ssl.ServerName mush match. Also, why you provide CertPath and especially CertPassphrase? This is for client authentication, and I suppose you are trying to setup server-side ssl (or not?)\n- The issue was the servername not matching... By default \"localhost\" is used, but my certificate was created for my machine name (Environment.MachineName in C#). I'm using the client cert because that's what's in the example C# at rabbitmq.com/ssl.html. Thanks very much for your help!\n- Does the ssl plugin need to be installed for this?\n- @TophatGordon yes, SSL auth requires the aptly-named plugin: rabbitmq_auth_mechanism_ssl\n- Thanks for the reply - I got it sorted out. I completely agree that the setup/configuration is not intuitive. There's definitely an opportunity for someone to write a wizard to wrap the RabbitMQ installer that optionally includes OpenSSL and configures security since it's such a pain.\n- @Andy : I know this is a fairly old thread. I am facing the same problem with a x509 certificate I generated using openssl. If you can post your code for the SslOption object (the required properties and its values) I can probably stop pulling my hair. Also, I did not add my certificate (.p12) to any certificate store. It is simply sitting in the folder where I created it. Does it make any difference? Any help would be highly appreciated. Thanks.\n- @Babu - sorry it's so late, but I've updated with my final code that should work. I'm using MassTransit to abstract away a lot of the RabbitMQ specifics and would highly recommend if you're not already using it. SSL+RabbitMQ is tricky to implement though regardless of whether you use MassTransit.\n- I can't speak to python, but when I tried this approach in C# I got the same behavior as when the hostname and common name didn't match.","metadata":{"transformedAt":"2026-08-18T18:33:20.150Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":214,"estimatedTokens":2414}}364{"id":"stack-12681802","source":"stackoverflow","questionId":12681802,"title":"Using Celery with existing RabbitMQ messages","tags":["python","rabbitmq","celery"],"text":"Title: Using Celery with existing RabbitMQ messages\nTags: python, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI have an existing RabbitMQ deployment that that a few Java applications are using the send out log messages as string JSON objects on various channels. I would like to use Celery to consume these messages and write them to various places (e.g. DB, Hadoop, etc.).\n\nI can see that Celery is design to be both the producer and consumer of RabbitMQ messages, since it tries to hide the mechanism by which those messages are delivered. Is there anyway to get Celery to consume messages created by another app and run jobs when they arrive?\n\n========================================\n\nCode:\n```text\nfrom celery import Celery\nfrom celery.bin import Option\nfrom celery.bootsteps import ConsumerStep\nfrom kombu import Consumer, Exchange, Queue\n\nclass CustomConsumer(ConsumerStep):\n queue = Queue('custom', Exchange('custom'), routing_key='custom')\n\n def __init__(self, c, enable_custom_consumer=False, **kwargs):\n self.enable = self.enable_custom_consumer\n\n def get_consumers(self, connection):\n return [\n Consumer(connection.channel(),\n queues=[self.queue],\n callbacks=[self.on_message]),\n ]\n\n def on_message(self, body, message):\n print('GOT MESSAGE: %r' % (body, ))\n message.ack()\n\n\ncelery = Celery(broker='amqp://localhost//')\ncelery.steps['consumer'].add(CustomConsumer)\ncelery.user_options['worker'].add(\n Option('--enable-custom-consumer', action='store_true',\n help='Enable our custom consumer.'),\n)\n```\n\n```text\nget_consumer(connection)\n```\n\n========================================\n\nComments:\n- The documentation can now be found at celery.readthedocs.org/en/latest/userguide/extending.html","metadata":{"transformedAt":"2026-08-18T18:33:20.150Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":52,"estimatedTokens":450}}365{"id":"stack-10155114","source":"stackoverflow","questionId":10155114,"title":"Is it possible to ensure unique messages are in a rabbitmq queue?","tags":["queue","rabbitmq"],"text":"Title: Is it possible to ensure unique messages are in a rabbitmq queue?\nTags: queue, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nBasically my consumers are producers as well. We get an initial dataset and it gets sent to the queue. A consumer takes an item and processes it, from that point there's 3 possibilities:\n\n- Data is good and gets putting a 'good' queue for storage\n\n- Data is bad and discarded\n\n- Data is not good(yet) or bad(yet) so data is broken down into smaller parts and sent back to the queue for further processing.\n\nMy problem is with step 3, because the queue grows very quickly at first its possible that a piece of data is broken down into a part thats duplicated in the queue and the consumers continue to process it and end up in a infinite loop. \n\nI think the way to prevent against this is to prevent duplicates from going into the queue. I can't do this on the client side because over the course of an hour I may have many cores dealing with billions of data points(to have each client scan it before submitting would slow me down too much). I think this needs to be done on the server side but, like I mentioned, the data is quite large and I don't know how to efficiently ensure no duplicates.\n\nI might be asking the impossible but thought I'd give it a shot. Any ideas would be greatly appreciated.\n\n========================================\n\nTop Answer:\nI think even if you could fix the issue of not sending duplicates to the queue, you will sooner or later hit this issue:\n\n From RabbitMQ Documentation: \"Recovery from failure: in the event that a client is disconnected from the broker owing to failure of the node to which the client was connected, if the client was a publishing client, it's possible for the broker to have accepted and passed on messages from the client without the client having received confirmation for them; and likewise on the consuming side it's possible for the client to have issued acknowledgements for messages and have no idea whether or not those acknowledgements made it to the broker and were processed before the failure occurred. In short, you still need to make sure your consuming clients can identify and deal with duplicate messages.\"\n\nBasically, it looks like this, you send a request to rabbitmq, rabbitmq replies with an ACK but for 1 reason or another, your consumer or producer does not receive this ACK. Rabbitmq has no way of knowing the ack was not received and your producer will end up re-sending the message, having never received an ack.\n\nIt is a pain to handle duplicate messages especially in apps where messaging is used as a kind of RPC, but it looks like this is unavoidable when using this kind of messaging architecture.\n\n========================================\n\nCode:\n```text\n\"...its possible that a piece of data is broken down into a part that's \nduplicated in the queue and the consumers continue to process it and \nend up in a infinite loop.\"\n```\n\n```text\nx-deduplication-header\n```\n\n========================================\n\nComments:\n- I'm happy to see that such \"soft\" questions aren't getting downvoted on StackOverflow. Gives me hope for the future! :D\n- I am trying to do exactly that(I think). By ensuring there are no duplicates of past items I'm ensuring that the same data is not processed more than once. I'm just sure of the implemention in rabbitmq, is there a way to simply send message id's and have rabbitmq discard duplicates or do I need to set a filter or something(if I do how does it work with rabbitmq).\n- There's no way to do that, AFAIK. Rabbit doesn't care about the contents of your messages or what's already in your queues, so it would be up to your application to take care of this.\n- So, if my message ID's are unique(hashcode of my actual data), I would need to store them in a DB or something and query against that(to see if msg ID has been sent before) before sending to rabbit? I've been thinking of that but it would require the client to do a few queries while my message server waits(I was trying to see if I could push this work to the message server itself)\n- Another question, related to mine above, with rabbitmq can I trigger a process when something is sent to the queue so I can filter it or do I need to send it to another program to filter before its sent to the queue at all?\n- You can do anything you want when a message arrives at the front of a queue - that's the very definition of a \"message consumer\" :) Also, I'd avoid adding a DB to the equation. Why not track the fact that the message has already been processed *within the message itself*? That avoids duplication, another system dependency and the creation of a single-point-of-failure.\n- The problem is if I do this on the consumer side than the consumers need to be aware of everything thats gone into the queue. That means for my job I can't use high cpu instances but instead need to provision memory as well(also I'm not sure how to sync between multiple servers sending jobs as well). My rabbitmq server is dedicated to this task and has a ton of memory I could allocate to filtering, but your right I'm want to avoid DB, but not sure how(maybe java server socket that consumers send to, stores ID and if unique passes to rabbitmq? this is where I'm lost.)\n- Why not just have an always-incrementing number added to each message? Before it gets re-queued the consumer dealing with it could just read and then increment the number in the payload as it pushes it back in the queue. Then, any consumers reading a message could reject any of them that have a number higher than a specific threshold (say, 10). It solves the infinite loop issue, requires no tracking of uniqueness and doesn't need any extra DB.\n- If I'm interacting with an external API as part of the business logic, then this strategy isn't very appealing. I mean, suppose I have ten instances in a distributed setting, and each issues a series of messages in a cron-like fashion to check, say, the status of some e-commerce orders, then we'll get 10 GET messages in the queue per order, overloading the external API. I think this is where having the queue reject messages with duplicate content/id will help greatly.","metadata":{"transformedAt":"2026-08-18T18:33:20.150Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":55,"estimatedTokens":1550}}366{"id":"stack-19410762","source":"stackoverflow","questionId":19410762,"title":"RabbitMQ Visibility Timeout","tags":["amazon-web-services","queue","rabbitmq","amazon-sqs"],"text":"Title: RabbitMQ Visibility Timeout\nTags: amazon-web-services, queue, rabbitmq, amazon-sqs\nSource: Stack Overflow\n\nQuestion:\nDo RabbitMQ queues have a AWS SQS-like - \"message visibility timeout\" ?\n\nFrom the AWS SQS documentation :\n\n\"The visibility timeout clock starts ticking once Amazon SQS returns the message. During that time, the component processes and deletes the message. But what happens if the component fails before deleting the message? If your system doesn't call DeleteMessage for that message before the visibility timeout expires, the message again becomes visible to the ReceiveMessage calls placed by the components in your system and it will be received again\"\n\n========================================\n\nTop Answer:\nThere aren't any message timeouts; RabbitMQ will redeliver the message only when the worker connection dies. It's fine even if processing a message takes a very, very long time.There aren't any message timeouts; RabbitMQ will redeliver the message only when the worker connection dies. It's fine even if processing a message takes a very, very long time.\n\n========================================\n\nComments:\n- yes, but how can you control the ammount of time. I need to make a message invisible for at most 12h.\n- I'm interested in this as well. I'd like to change the visibility time to something greater than the default (which i think is 3 mins?)\n- rabbitmq.com/consumers.html#acknowledgement-timeout is somewhat close, but does not work for my use case\n- That's superior to SQS in my opinion.","metadata":{"transformedAt":"2026-08-18T18:33:20.150Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":23,"estimatedTokens":383}}367{"id":"stack-6933833","source":"stackoverflow","questionId":6933833,"title":"Interoperating with Django/Celery From Java","tags":["java","python","django","rabbitmq","celery"],"text":"Title: Interoperating with Django/Celery From Java\nTags: java, python, django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nOur company has a Python based web site and some Python based worker nodes which communicate via Django/Celery and RabbitMQ. I have a Java based application which needs to submit tasks to the Celery based workers. I can send jobs to RabbitMQ from Java just fine, but the Celery based workers are never picking up the jobs. From looking at the packet captures of both types of job submissions, there are differences, but I cannot fathom how to account for them because a lot of it is binary that I cannot find documentation about decoding. Does anyone here have any reference or experience with having Java/RabbitMQ and Celery working together?\n\n========================================\n\nCode:\n```text\nCELERY_ROUTES = {\n 'mypackage.myclass.runworker' : {'queue':'myqueue'},\n}\n```\n\n```text\nConnectionFactory factory = new ConnectionFactory();\n Connection connection = null ;\n try {\n connection = factory.newConnection(mqHost, mqPort);\n } catch (IOException ioe) {\n log.error(\"Unable to create new MQ connection from factory.\", ioe) ;\n }\n\n Channel channel = null ;\n try {\n channel = connection.createChannel();\n } catch (IOException ioe) {\n log.error(\"Unable to create new channel for MQ connection.\", ioe) ;\n }\n\n try {\n channel.queueDeclare(\"celery\", false, false, false, true, null);\n } catch (IOException ioe) {\n log.error(\"Unable to declare queue for MQ channel.\", ioe) ;\n }\n\n try {\n channel.exchangeDeclare(\"myqueue\", \"direct\") ;\n } catch (IOException ioe) {\n log.error(\"Unable to declare exchange for MQ channel.\", ioe) ;\n }\n\n try {\n channel.queueBind(\"celery\", \"myqueue\", \"myqueue\") ;\n } catch (IOException ioe) {\n log.error(\"Unable to bind queue for channel.\", ioe) ;\n }\n\n // Generate the message body as a string here.\n\n try {\n channel.basicPublish(mqExchange, mqRouteKey, \n new AMQP.BasicProperties(\"application/json\", \"ASCII\", null, null, null, null, null, null, null, null, null, \"guest\", null, null),\n messageBody.getBytes(\"ASCII\"));\n } catch (IOException ioe) {\n log.error(\"IOException encountered while trying to publish task via MQ.\", ioe) ;\n }\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.150Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":60,"estimatedTokens":628}}368{"id":"stack-17005515","source":"stackoverflow","questionId":17005515,"title":"Rabbitmq retrieve multiple messages using single synchronous call","tags":["rabbitmq","synchronous"],"text":"Title: Rabbitmq retrieve multiple messages using single synchronous call\nTags: rabbitmq, synchronous\nSource: Stack Overflow\n\nQuestion:\nIs there a way to receive multiple message using a single synchronous call ? \n\nWhen I know that there are N messages( N could be a small value less than 10) in the queue, then I should be able to do something like channel.basic_get(String queue, boolean autoAck , int numberofMsg ). I don't want to make multiple requests to the server .\n\n========================================\n\nTop Answer:\nYou can use a `QueueingConsumer` implementation of `Consumer` interface which allows you to retrieve several messages in a single request. \n\n```\nQueueingConsumer queueingConsumer = new QueueingConsumer(channel);\n channel.basicConsume(plugin.getQueueName(), false, queueingConsumer);\n\n for(int i = 0; i < 10; i++){\n QueueingConsumer.Delivery delivery = queueingConsumer.nextDelivery(100);//read timeout in ms\n if(delivery == null){\n break;\n }\n }\n```\n\n========================================\n\nCode:\n```text\nbasic.get\n```\n\n```text\nacks\n```\n\n```text\nbasic.consume\n```\n\n```text\nbasic.get\n```\n\n```text\nno-ack\n```\n\n```text\ntrue\n```\n\n```text\nbasic.qos\n```\n\n```text\nprefetch-count\n```\n\n```text\nQueueingConsumer queueingConsumer = new QueueingConsumer(channel);\n channel.basicConsume(plugin.getQueueName(), false, queueingConsumer);\n\n for(int i = 0; i < 10; i++){\n QueueingConsumer.Delivery delivery = queueingConsumer.nextDelivery(100);//read timeout in ms\n if(delivery == null){\n break;\n }\n }\n```\n\n```text\nQueueingConsumer\n```\n\n```text\nConsumer\n```\n\n```text\npublic string GetMessagesByQueue(string QueueName)\n {\n var consumer = new QueueingBasicConsumer(_model);\n _model.BasicConsume(QueueName, false, consumer);\n\n string message = string.Empty;\n\n while (Enabled)\n {\n //Get next message\n var deliveryArgs = (BasicDeliverEventArgs)consumer.Queue.Dequeue();\n\n //Serialize message\n message = Encoding.Default.GetString(deliveryArgs.Body);\n _model.BasicAck(deliveryArgs.DeliveryTag, false);\n }\n return message;\n }\n```\n\n```text\nbool noAck = false;\n var messageCount = channel.MessageCount(\"hello\");\n BasicGetResult result = null;\n if (messageCount == 0)\n {\n // No messages available\n }\n else\n {\n while (messageCount > 0)\n {\n result = channel.BasicGet(\"hello\", noAck);\n var message = Encoding.UTF8.GetString(result.Body);\n //process message .....\n messageCount = channel.MessageCount(\"hello\");\n }\n```\n\n========================================\n\nComments:\n- This is not an answer to what was asked. There are scenarios (for example due to security concerns) where connections cannot be triggered from the message broker but only from the secure zone to the less secure zone. Being so, this is still missing an answer to what was asked.\n- There may have been changes to AMQP or RabbitMQ that allow a synchronous call to get multiple messages in the intervening years. Connections for RabbitMQ are from client -> Rabbit. The publishing of messages happens over this existing connection. Usage of `basic.get` or `basic.consume` doesn't change how the connection is established.\n- This is about consuming messages not publishing. Does that means that a connection is established by the consumer and then stays open in order for RabbitMQ callbacks work? This may not be a possibility in some scenarios as well with limiting firewall rules.. In that sense the usage of age of basic.get or basic.consume indeed change how the connection is handled.\n- The client makes the connection whether consuming or publishing, regardless of the commands that are used over the connection. The callbacks are handled by client libraries as a result of AMQP messages over that connection.\n- Links are indeed redirecting to RabbitMQ official site but with 'Page not found'.\n- Nowadays it is a deprecated solution. rabbitmq.com/releases/rabbitmq-java-client/v3.4.1/…","metadata":{"transformedAt":"2026-08-18T18:33:20.150Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":13,"totalLines":130,"estimatedTokens":1014}}369{"id":"stack-7952000","source":"stackoverflow","questionId":7952000,"title":"RabbitMQ Queue with no subscribers","tags":["c#","rabbitmq"],"text":"Title: RabbitMQ Queue with no subscribers\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\n\"Durable\" and \"persistent mode\" appear to relate to reboots rather than relating to there being no subscribers to receive the message.\n\nI'd like RabbitMQ to keep messages on the queue when there are no subscribers. When a subscriber does come online, the message should be recieved by that subscriber. Is this possible with RabbitMQ?\n\nCode sample:\n\n**Server:**\n\n```\nnamespace RabbitEg\n{\n class Program\n {\n private const string EXCHANGE_NAME = \"helloworld\";\n\n static void Main(string[] args)\n {\n ConnectionFactory cnFactory = new RabbitMQ.Client.ConnectionFactory() { HostName = \"localhost\" };\n\n using (IConnection cn = cnFactory.CreateConnection())\n {\n using (IModel channel = cn.CreateModel())\n {\n //channel.ExchangeDelete(EXCHANGE_NAME);\n channel.ExchangeDeclare(EXCHANGE_NAME, \"direct\", true);\n //channel.BasicReturn += new BasicReturnEventHandler(channel_BasicReturn);\n\n for (int i = 0; i **Client:**\n\n```\nnamespace RabbitListener\n{\n class Program\n {\n private const string EXCHANGE_NAME = \"helloworld\";\n\n static void Main(string[] args)\n {\n ConnectionFactory cnFactory = new ConnectionFactory() { HostName = \"localhost\" };\n\n using (IConnection cn = cnFactory.CreateConnection())\n {\n using (IModel channel = cn.CreateModel())\n {\n channel.ExchangeDeclare(EXCHANGE_NAME, \"direct\", true);\n\n string queueName = channel.QueueDeclare(\"myQueue\", true, false, false, null);\n channel.QueueBind(queueName, EXCHANGE_NAME, \"routekey_helloworld\");\n\n Console.WriteLine(\"Waiting for messages\");\n\n QueueingBasicConsumer consumer = new QueueingBasicConsumer(channel);\n channel.BasicConsume(queueName, true, consumer);\n\n while (true)\n {\n BasicDeliverEventArgs e = (BasicDeliverEventArgs)consumer.Queue.Dequeue();\n Console.WriteLine(Encoding.ASCII.GetString(e.Body));\n }\n }\n }\n }\n }\n}\n```\n\n========================================\n\nCode:\n```text\nnamespace RabbitEg\n{\n class Program\n {\n private const string EXCHANGE_NAME = \"helloworld\";\n\n static void Main(string[] args)\n {\n ConnectionFactory cnFactory = new RabbitMQ.Client.ConnectionFactory() { HostName = \"localhost\" };\n\n using (IConnection cn = cnFactory.CreateConnection())\n {\n using (IModel channel = cn.CreateModel())\n {\n //channel.ExchangeDelete(EXCHANGE_NAME);\n channel.ExchangeDeclare(EXCHANGE_NAME, \"direct\", true);\n //channel.BasicReturn += new BasicReturnEventHandler(channel_BasicReturn);\n\n for (int i = 0; i < 100; i++)\n {\n byte[] payLoad = Encoding.ASCII.GetBytes(\"hello world _ \" + i);\n IBasicProperties channelProps = channel.CreateBasicProperties();\n channelProps.SetPersistent(true);\n\n channel.BasicPublish(EXCHANGE_NAME, \"routekey_helloworld\", false, false, channelProps, payLoad);\n\n Console.WriteLine(\"Sent Message \" + i);\n System.Threading.Thread.Sleep(25);\n }\n\n Console.ReadLine();\n }\n }\n }\n }\n}\n```\n\n```text\nnamespace RabbitListener\n{\n class Program\n {\n private const string EXCHANGE_NAME = \"helloworld\";\n\n static void Main(string[] args)\n {\n ConnectionFactory cnFactory = new ConnectionFactory() { HostName = \"localhost\" };\n\n using (IConnection cn = cnFactory.CreateConnection())\n {\n using (IModel channel = cn.CreateModel())\n {\n channel.ExchangeDeclare(EXCHANGE_NAME, \"direct\", true);\n\n string queueName = channel.QueueDeclare(\"myQueue\", true, false, false, null);\n channel.QueueBind(queueName, EXCHANGE_NAME, \"routekey_helloworld\");\n\n Console.WriteLine(\"Waiting for messages\");\n\n QueueingBasicConsumer consumer = new QueueingBasicConsumer(channel);\n channel.BasicConsume(queueName, true, consumer);\n\n while (true)\n {\n BasicDeliverEventArgs e = (BasicDeliverEventArgs)consumer.Queue.Dequeue();\n Console.WriteLine(Encoding.ASCII.GetString(e.Body));\n }\n }\n }\n }\n }\n}\n```\n\n```text\ndurable\n```\n\n```text\npersistent\n```\n\n```text\ndurable\n```\n\n```text\nnon-durable\n```\n\n```text\ntransient\n```\n\n```text\npersistent\n```\n\n```text\npersistent\n```\n\n```text\ndurable\n```\n\n```text\ndurable\n```\n\n```text\npersistent\n```\n\n========================================\n\nComments:\n- Thanks, I've tried this but it still doesn't persist messages if there is no client listening. Code sample attached to question.\n- Good code. Two problems: 1) the server should *also* declare the queue; declaring it twice isn't a problem and it's good practice and 2) queueDeclare() gives you an anonymous non-durable queue; you want queueDeclare(\"myQueue\", true, false, false, null).\n- Also, the way you edited the question makes it hard to understand what you're trying to achieve.\n- Point taken regarding the edit (updated accordingly). I've tried specifying the queue as you indicated (code sample updated to prove it). Still the same result for me though.\n- Ah got it... declaring the queue on the client clearly is too late because the messages are already on the queue. Adding the same bit of QueueDeclare & QueueBind code to the Server code makes it work. Thanks for your insight (much appreciated).\n- What about uniqueness of the consumers? Do we have here the same limitation as in JMS where you can't subscribe two durable subscribers with the same id? This is very useful if you have an active/active model.","metadata":{"transformedAt":"2026-08-18T18:33:20.151Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":12,"totalLines":199,"estimatedTokens":1467}}370{"id":"stack-10365867","source":"stackoverflow","questionId":10365867,"title":"How can I pool channels in rabbitmq?","tags":["java","multithreading","rabbitmq"],"text":"Title: How can I pool channels in rabbitmq?\nTags: java, multithreading, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have been trying to connection between threads and have channels open only on thread creation but after researching a bit more, I think I want to also try to `connection pooling`. How can I do this on rabbitmq? or is this a general idea I can apply generally? My goal is to spawn X threads and then have them not have to open new channels(which requires round robin establishment between client and server).\n\nSince the threads are their own class, I'm not sure if I need to put the pool in the class itself that spawns the threads or where they go?I also have multiple types of threads I would want to these connections between(not just a single one). Is that possible?\n\nJust to give you a general idea, here's how connections/channels are estblished in rabbitmq:\n\n```\nConnectionFactory factory = new ConnectionFactory();\n factory.setHost(\"localhost\");\n Connection connection = factory.newConnection();\n Channel channel = connection.createChannel(); //I want to several of these between threads\n```\n\n========================================\n\nTop Answer:\nYou can also use ThreadLocal object, in case you use the channels. \n\nRabbitMQ advises you to use channels per thread, so that would be a perfect match.\n\nSample code:\n\n```\nprivate final ThreadLocal channels = new ThreadLocal<>();\n...\nChannel channel = channels.get();\n if (channel == null){\n channel = connection.createChannel();\n channels.set(channel);\n }\n```\n\nno need to close the channels, as they will be closed by your application when the connection is closed.\n\nHowever, this solution might not suit you well if you're heavily creating new threads since that will allocate a lot of new channels that will never be closed. But if you do something like that, you are probably doing something wrong.\n\n========================================\n\nCode:\n```text\nConnectionFactory factory = new ConnectionFactory();\n factory.setHost(\"localhost\");\n Connection connection = factory.newConnection();\n Channel channel = connection.createChannel(); //I want to share several of these between threads\n```\n\n```text\nconnection pooling\n```\n\n```text\nChannel\n```\n\n```text\nObjectPool\n```\n\n```text\nChannel\n```\n\n```text\nChannel\n```\n\n```text\nprivate final ThreadLocal<Channel> channels = new ThreadLocal<>();\n...\nChannel channel = channels.get();\n if (channel == null){\n channel = connection.createChannel();\n channels.set(channel);\n }\n```\n\n========================================\n\nComments:\n- Thanks, I'll study it to learn more but is the objectpool shareable between other classes? Say I have a class that uploads and another that downloads, can both use Channels from the same objectpool?\n- @Lostsoul - it's been a while since I've mucked with rabbit, but if the `Channel` class is used for both producing as well as consuming, then yes.\n- I understood that, what I meant was would multiple classes have access to the same object pool or do I need to create object pools for each class that is going to use it?\n- Sorry, misunderstood - the point of the pool is for all your classes to use the same instance of it, yes. The general way to accomplish this is through dependency injection; have the pool be one of the things you pass to the constructors of your other objects. If that's not possible you could make the pool be a singleton, but preferably you want the former.\n- cool thanks alot Brian. I'll play around with it. Btw, say your a developer at Riak. I was playing around with Riak last week and its great. You guys are doing an amazing job! Thanks again for your help.\n- I think you need to be careful about reusing channels. If there's an error (say, you publish to a non-existent exchange) then the channel is useless beyond that point. It should not be returned to the pool as it cannot be used for further operations and can even block your threads indefinitely.","metadata":{"transformedAt":"2026-08-18T18:33:20.151Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":90,"estimatedTokens":990}}371{"id":"stack-44905126","source":"stackoverflow","questionId":44905126,"title":"RabbitMQ REST HTTP JSON payload","tags":["json","rest","rabbitmq"],"text":"Title: RabbitMQ REST HTTP JSON payload\nTags: json, rest, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am trying to use RabbitMQ HTTP REST client to publish messages into the queue. I am using the following url and request\n\nhttp://xxxx/api/exchanges/xxxx/exc.notif/publish\n\n```\n{\n \"routing_key\":\"routing.key\",\n \"payload\":{\n\n },\n \"payload_encoding\":\"string\",\n \"properties\":{\n \"headers\":{\n \"notif_d\":\"TEST\",\n \"notif_k\": [\"example1\", \"example2\"],\n \"userModTime\":\"timestamp\"\n }\n }\n}\n```\n\nAnd getting back from the rabbit the following response:\n\n```\n{\"error\":\"bad_request\",\"reason\":\"payload_not_string\"}\n```\n\nI have just one header set:\n\n```\nContent-Type:application/json\n```\n\nI was trying to set the\n\n```\n\"payload_encoding\":\"base64\",\n```\n\nbut it didn't help. I am new to rabbit any response is welcome.\n\n========================================\n\nTop Answer:\nWorking example. We need simple to escape doublequotes.\nIt is important that the colon is outside of the quotes, as this causes inexplicable errors.\n\n```\n{\n \"properties\": {},\n \"routing_key\": \"q_testing\",\n \"payload\": \"{\n \\\"message\\\": \\\"message from terminal\\\"\n }\",\n \"payload_encoding\": \"string\"\n}\n```\n\n========================================\n\nCode:\n```text\n{\n \"routing_key\":\"routing.key\",\n \"payload\":{\n\n },\n \"payload_encoding\":\"string\",\n \"properties\":{\n \"headers\":{\n \"notif_d\":\"TEST\",\n \"notif_k\": [\"example1\", \"example2\"],\n \"userModTime\":\"timestamp\"\n }\n }\n}\n```\n\n```text\n{\"error\":\"bad_request\",\"reason\":\"payload_not_string\"}\n```\n\n```text\nContent-Type:application/json\n```\n\n```text\n\"payload_encoding\":\"base64\",\n```\n\n```text\n{\n\"properties\": {\n\"content-type\": \"application/json\"\n},\n\"routing_key\": \"testKey\",\n\"payload\": \"1234\",\n\"payload_encoding\": \"string\"\n}\n```\n\n```text\n{\n \"properties\": {},\n \"routing_key\": \"q_testing\",\n \"payload\": \"{\n \\\"message\\\": \\\"message from terminal\\\"\n }\",\n \"payload_encoding\": \"string\"\n}\n```\n\n```sh\ncurl -i -u guest:guest -XPOST --data '{\"properties\":\\\n{\"content_type\":\"application/json\"}, \\\n\"routing_key\":\"\", \\\n\"payload\":\"{\\\"foo\\\":\\\"bar\\\"}\",\\\n\"payload_encoding\":\"string\"}' \\\n\"http://localhost:15672/api/exchanges/%2f/exchange_name/publish\"\n```\n\n```text\n\"payload_encoding\": \"base64\"\n```\n\n```bash\njson='{\"type\": \"earl-grey\", \"strength\": 7, \"milk\": true}'\namqp_host=amqp.improbability.cloud\namqp_username=slarti\namqp_password=bartfast\namqp_vhost=heart-of-gold\namqp_exchange=food.dispenser\namqp_queue=tea-requests\namqp_message_id=$(uuid)\namqp_delivery_mode=2\npayload=$(echo -n $json | base64 -w0)\nauthorization=$(echo -n \"${amqp_username}:${amqp_password}\" | base64 -w0)\n\ncurl https://${amqp_host}/api/exchanges/${amqp_vhost}/${amqp_exchange}/publish \\\n -H \"authorization: Basic ${authorization}\" \\\n -H 'Content-Type: application/json;charset=UTF-8' \\\n --data @- <<EOF\n{\n \"properties\": {\n \"message_id\":\"${amqp_message_id}\",\n \"delivery_mode\": ${amqp_delivery_mode}\n },\n \"routing_key\": \"${amqp_queue}\",\n \"payload_encoding\":\"base64\",\n \"payload\": \"${payload}\"\n}\nEOF\n```\n\n```bash\ncurl https://amqp.improbability.cloud/api/exchanges/heart-of-gold/food.dispenser/publish \n -H \"authorization: Basic c2xhcnRpOmJhcnRmYXN0\" \\\n -H \"Content-Type: application/json;charset=UTF-8\" \\\n --data @- <<EOF\n{\n \"properties\": {\n \"message_id\":\"eb28ad00-f86f-11ed-9e7f-00155d591867\",\n \"delivery_mode\": 2\n },\n \"routing_key\": \"tea-requests\",\n \"payload_encoding\":\"base64\",\n \"payload\": \"eyJ0eXBlIjogImVhcmwtZ3JleSIsICJzdHJlbmd0aCI6IDcsICJtaWxrIjogdHJ1ZX0=\"\n}\nEOF\n```\n\n```text\n=> {\"routed\":true}\n```\n\n```text\npayload_encoding\n```\n\n```text\nbase64\n```\n\n```text\ncurl\n```\n\n========================================\n\nComments:\n- Thanks for the quick reply. My challenge is that I would like to have JSON in the payload. Something similar \"payload\" : { \"nos\":[\"test\"], \"parameters\":{\"var2\":\"val2\",\"var1\":\"val1\"}, \"exception\":\"test-excpetion\" } I tried String and escapes but still no joy.\n- You helped me a lot. just escaped the json properly and its working fine. Cheers","metadata":{"transformedAt":"2026-08-18T18:33:20.151Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":14,"totalLines":197,"estimatedTokens":994}}372{"id":"stack-52271432","source":"stackoverflow","questionId":52271432,"title":"RabbitMQ virtual host error when starting service","tags":["rabbitmq"],"text":"Title: RabbitMQ virtual host error when starting service\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI've had a RabbitMQ server running for months. This morning I was unable to connect to it, my applications was timing out and the Management client was unresponsive. Rebooted the machine. Applications are still timing out. I'm able to login to the Management client but I see this message:\n\n Virtual host / experienced an error on node rabbit@MQT01 and may be inaccessible\n\nAll my queues are there but can't see any exchanges.\n\nI hope someone can help me figure out what going on. I've looked at the logs but can't find any good hint.\n\nHere a part of the log:\n\n\r\n\r\n\n```\n2018-09-11 09:39:42 =ERROR REPORT====\r\n** Generic server terminating\r\n** Last message in was {'$gen_cast',{submit_async,#Fun}}\r\n** When Server state == undefined\r\n** Reason for termination == \r\n** {function_clause,[{rabbit_queue_index,journal_minus_segment1,[{{true,>,>},no_del,no_ack},{{true,>,>},no_del,no_ack}],[{file,\"src/rabbit_queue_index.erl\"},{line,1231}]},{rabbit_queue_index,'-journal_minus_segment/3-fun-0-',4,[{file,\"src/rabbit_queue_index.erl\"},{line,1208}]},{array,sparse_foldl_3,7,[{file,\"array.erl\"},{line,1684}]},{array,sparse_foldl_2,9,[{file,\"array.erl\"},{line,1678}]},{rabbit_queue_index,'-recover_journal/1-fun-0-',1,[{file,\"src/rabbit_queue_index.erl\"},{line,915}]},{lists,map,2,[{file,\"lists.erl\"},{line,1239}]},{rabbit_queue_index,segment_map,2,[{file,\"src/rabbit_queue_index.erl\"},{line,1039}]},{rabbit_queue_index,recover_journal,1,[{file,\"src/rabbit_queue_index.erl\"},{line,906}]}]}\r\n2018-09-11 09:39:42 =CRASH REPORT====\r\n crasher:\r\n initial call: worker_pool_worker:init/1\r\n pid: \r\n registered_name: []\r\n exception exit: {{function_clause,[{rabbit_queue_index,journal_minus_segment1,[{{true,>,>},no_del,no_ack},{{true,>,>},no_del,no_ack}],[{file,\"src/rabbit_queue_index.erl\"},{line,1231}]},{rabbit_queue_index,'-journal_minus_segment/3-fun-0-',4,[{file,\"src/rabbit_queue_index.erl\"},{line,1208}]},{array,sparse_foldl_3,7,[{file,\"array.erl\"},{line,1684}]},{array,sparse_foldl_2,9,[{file,\"array.erl\"},{line,1678}]},{rabbit_queue_index,'-recover_journal/1-fun-0-',1,[{file,\"src/rabbit_queue_index.erl\"},{line,915}]},{lists,map,2,[{file,\"lists.erl\"},{line,1239}]},{rabbit_queue_index,segment_map,2,[{file,\"src/rabbit_queue_index.erl\"},{line,1039}]},{rabbit_queue_index,recover_journal,1,[{file,\"src/rabbit_queue_index.erl\"},{line,906}]}]},[{gen_server2,terminate,3,[{file,\"src/gen_server2.erl\"},{line,1161}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,247}]}]}\r\n ancestors: [worker_pool_sup,rabbit_sup,]\r\n message_queue_len: 0\r\n messages: []\r\n links: [,,#Port]\r\n dictionary: [{fhc_age_tree,{1,{{10352640,#Ref},true,nil,nil}}},{worker_pool_worker,true},{rand_seed,{#{jump => #Fun,max => 288230376151711743,next => #Fun,type => exsplus},[257570830250844431|246837015578235662]}},{worker_pool_name,worker_pool},{{\"c:/Users/dfpsb/AppData/Roaming/RabbitMQ/db/RABBIT~1/msg_stores/vhosts/628WB79CIFDYO9LJI6DKMI09L/queues/9GD33C2I2PKZ7A8QHZ4MWWCKE/journal.jif\",fhc_file},{file,1,true}},{{#Ref,fhc_handle},{handle,{file_descriptor,prim_file,{#Port,1808}},#Ref,240,false,0,infinity,[],>,0,0,0,0,0,false,\"c:/Users/dfpsb/AppData/Roaming/RabbitMQ/db/RABBIT~1/msg_stores/vhosts/628WB79CIFDYO9LJI6DKMI09L/queues/9GD33C2I2PKZ7A8QHZ4MWWCKE/journal.jif\",[write,binary,raw,read],[{write_buffer,infinity}],true,true,10352640}}]\r\n trap_exit: false\r\n status: running\r\n heap_size: 10958\r\n stack_size: 27\r\n reductions: 104391\r\n neighbours:\r\n neighbour: [{pid,},{registered_name,[]},{initial_call,{worker_pool_worker,init,['Argument__1']}},{current_function,{gen,do_call,4}},{ancestors,[worker_pool_sup,rabbit_sup,]},{message_queue_len,0},{links,[,]},{trap_exit,false},{status,waiting},{heap_size,4185},{stack_size,42},{reductions,21548},{current_stacktrace,[{gen,do_call,4,[{file,\"gen.erl\"},{line,169}]},{gen_server,call,3,[{file,\"gen_server.erl\"},{line,210}]},{file,call,2,[{file,\"file.erl\"},{line,1499}]},{rabbit_queue_index,get_journal_handle,1,[{file,\"src/rabbit_queue_index.erl\"},{line,881}]},{rabbit_queue_index,load_journal,1,[{file,\"src/rabbit_queue_index.erl\"},{line,894}]},{rabbit_queue_index,recover_journal,1,[{file,\"src/rabbit_queue_index.erl\"},{line,904}]},{rabbit_queue_index,scan_queue_segments,3,[{file,\"src/rabbit_queue_index.erl\"},{line,724}]},{rabbit_queue_index,queue_index_walker_reader,2,[{file,\"src/rabbit_queue_index.erl\"},{line,712}]}]}]\r\n neighbour: [{pid,},{registered_name,[]},{initial_call,{worker_pool_worker,init,['Argument__1']}},{current_function,{gen,do_call,4}},{ancestors,[worker_pool_sup,rabbit_sup,]},{message_queue_len,0},{links,[,,#Port]},{trap_exit,false},{status,waiting},{heap_size,6772},{stack_size,102},{reductions,129623},{current_stacktrace,[{gen,do_call,4,[{file,\"gen.erl\"},{line,169}]},{gen_server2,call,3,[{file,\"src/gen_server2.erl\"},{line,323}]},{array,sparse_foldr_3,6,[{file,\"array.erl\"},{line,1848}]},{array,sparse_foldr_2,8,[{file,\"array.erl\"},{line,1837}]},{lists,foldr,3,[{file,\"lists.erl\"},{line,1276}]},{rabbit_queue_index,scan_queue_segments,3,[{file,\"src/rabbit_queue_index.erl\"},{line,725}]},{rabbit_queue_index,queue_index_walker_reader,2,[{file,\"src/rabbit_queue_index.erl\"},{line,712}]},{rabbit_queue_index,'-queue_index_walker/1-fun-0-',2,[{file,\"src/rabbit_queue_index.erl\"},{line,694}]}]}]\r\n neighbour: [{pid,},{registered_name,[]},{initial_call,{worker_pool_worker,init,['Argument__1']}},{current_function,{array,set_1,4}},{ancestors,[worker_pool_sup,rabbit_sup,]},{message_queue_len,0},{links,[,,#Port]},{trap_exit,false},{status,runnable},{heap_size,121536},{stack_size,44},{reductions,122988},{current_stacktrace,[{array,set_1,4,[{file,\"array.erl\"},{line,590}]},{array,set_1,4,[{file,\"array.erl\"},{line,592}]},{array,set_1,4,[{file,\"array.erl\"},{line,592}]},{array,set,3,[{file,\"array.erl\"},{line,574}]},{rabbit_queue_index,parse_segment_publish_entry,5,[{file,\"src/rabbit_queue_index.erl\"},{line,1135}]},{rabbit_queue_index,segment_entries_foldr,3,[{file,\"src/rabbit_queue_index.erl\"},{line,1091}]},{lists,foldr,3,[{file,\"lists.erl\"},{line,1276}]},{rabbit_queue_index,scan_queue_segments,3,[{file,\"src/rabbit_queue_index.erl\"},{line,725}]}]}]\r\n neighbour: [{pid,},{registered_name,[]},{initial_call,{gatherer,init,['Argument__1']}},{current_function,{gen_server2,process_next_msg,1}},{ancestors,[,,,rabbit_vhost_sup_sup,rabbit_sup,]},{message_queue_len,2},{links,[,,,,]},{trap_exit,false},{status,runnable},{heap_size,987},{stack_size,8},{reductions,73223},{current_stacktrace,[{gen_server2,process_next_msg,1,[{file,\"src/gen_server2.erl\"},{line,666}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,247}]}]}]\r\n2018-09-11 09:39:42 =CRASH REPORT====\r\n crasher:\r\n initial call: rabbit_msg_store:init/1\r\n pid: \r\n registered_name: []\r\n exception exit: {{{function_clause,[{rabbit_queue_index,journal_minus_segment1,[{{true,>,>},no_del,no_ack},{{true,>,>},no_del,no_ack}],[{file,\"src/rabbit_queue_index.erl\"},{line,1231}]},{rabbit_queue_index,'-journal_minus_segment/3-fun-0-',4,[{file,\"src/rabbit_queue_index.erl\"},{line,1208}]},{array,sparse_foldl_3,7,[{file,\"array.erl\"},{line,1684}]},{array,sparse_foldl_2,9,[{file,\"array.erl\"},{line,1678}]},{rabbit_queue_index,'-recover_journal/1-fun-0-',1,[{file,\"src/rabbit_queue_index.erl\"},{line,915}]},{lists,map,2,[{file,\"lists.erl\"},{line,1239}]},{rabbit_queue_index,segment_map,2,[{file,\"src/rabbit_queue_index.erl\"},{line,1039}]},{rabbit_queue_index,recover_journal,1,[{file,\"src/rabbit_queue_index.erl\"},{line,906}]}]},{gen_server2,call,[,out,infinity]}},[{gen_server2,init_it,6,[{file,\"src/gen_server2.erl\"},{line,589}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,247}]}]}\r\n ancestors: [,,rabbit_vhost_sup_sup,rabbit_sup,]\r\n message_queue_len: 1\r\n messages: [{'EXIT',,{function_clause,[{rabbit_queue_index,journal_minus_segment1,[{{true,>,>},no_del,no_ack},{{true,>,>},no_del,no_ack}],[{file,\"src/rabbit_queue_index.erl\"},{line,1231}]},{rabbit_queue_index,'-journal_minus_segment/3-fun-0-',4,[{file,\"src/rabbit_queue_index.erl\"},{line,1208}]},{array,sparse_foldl_3,7,[{file,\"array.erl\"},{line,1684}]},{array,sparse_foldl_2,9,[{file,\"array.erl\"},{line,1678}]},{rabbit_queue_index,'-recover_journal/1-fun-0-',1,[{file,\"src/rabbit_queue_index.erl\"},{line,915}]},{lists,map,2,[{file,\"lists.erl\"},{line,1239}]},{rabbit_queue_index,segment_map,2,[{file,\"src/rabbit_queue_index.erl\"},{line,1039}]},{rabbit_queue_index,recover_journal,1,[{file,\"src/rabbit_queue_index.erl\"},{line,906}]}]}}]\r\n links: [,]\r\n dictionary: []\r\n trap_exit: true\r\n status: running\r\n heap_size: 2586\r\n stack_size: 27\r\n reductions: 57377\r\n neighbours:\r\n neighbour: [{pid,},{registered_name,[]},{initial_call,{rabbit_msg_store_gc,init,['Argument__1']}},{current_function,{gen_server2,process_next_msg,1}},{ancestors,[,,,rabbit_vhost_sup_sup,rabbit_sup,]},{message_queue_len,0},{links,[]},{trap_exit,false},{status,waiting},{heap_size,987},{stack_size,8},{reductions,174},{current_stacktrace,[{gen_server2,process_next_msg,1,[{file,\"src/gen_server2.erl\"},{line,666}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,247}]}]}]\r\n2018-09-11 09:39:42 =SUPERVISOR REPORT====\r\n Supervisor: {local,worker_pool_sup}\r\n Context: child_terminated\r\n Reason: {function_clause,[{rabbit_queue_index,journal_minus_segment1,[{{true,>,>},no_del,no_ack},{{true,>,>},no_del,no_ack}],[{file,\"src/rabbit_queue_index.erl\"},{line,1231}]},{rabbit_queue_index,'-journal_minus_segment/3-fun-0-',4,[{file,\"src/rabbit_queue_index.erl\"},{line,1208}]},{array,sparse_foldl_3,7,[{file,\"array.erl\"},{line,1684}]},{array,sparse_foldl_2,9,[{file,\"array.erl\"},{line,1678}]},{rabbit_queue_index,'-recover_journal/1-fun-0-',1,[{file,\"src/rabbit_queue_index.erl\"},{line,915}]},{lists,map,2,[{file,\"lists.erl\"},{line,1239}]},{rabbit_queue_index,segment_map,2,[{file,\"src/rabbit_queue_index.erl\"},{line,1039}]},{rabbit_queue_index,recover_journal,1,[{file,\"src/rabbit_queue_index.erl\"},{line,906}]}]}\r\n Offender: [{pid,},{id,4},{mfargs,{worker_pool_worker,start_link,[worker_pool]}},{restart_type,transient},{shutdown,4294967295},{child_type,worker}]\r\n\r\n2018-09-11 09:39:42 =CRASH REPORT====\r\n crasher:\r\ninitial call: rabbit_vhost_process:init/1\r\npid: \r\nregistered_name: []\r\nexception exit: {{error,{{{function_clause,[{rabbit_queue_index,journal_minus_segment1,[{{true,>,>},no_del,no_ack},{{true,>,>},no_del,no_ack}],[{file,\"src/rabbit_queue_index.erl\"},{line,1231}]},{rabbit_queue_index,'-journal_minus_segment/3-fun-0-',4,[{file,\"src/rabbit_queue_index.erl\"},{line,1208}]},{array,sparse_foldl_3,7,[{file,\"array.erl\"},{line,1684}]},{array,sparse_foldl_2,9,[{file,\"array.erl\"},{line,1678}]},{rabbit_queue_index,'-recover_journal/1-fun-0-',1,[{file,\"src/rabbit_queue_index.erl\"},{line,915}]},{lists,map,2,[{file,\"lists.erl\"},{line,1239}]},{rabbit_queue_index,segment_map,2,[{file,\"src/rabbit_queue_index.erl\"},{line,1039}]},{rabbit_queue_index,recover_journal,1,[{file,\"src/rabbit_queue_index.erl\"},{line,906}]}]},{gen_server2,call,[,out,infinity]}},{child,undefined,msg_store_persistent,{rabbit_msg_store,start_link,[msg_store_persistent,\"c:/Users/dfpsb/AppData/Roaming/RabbitMQ/db/RABBIT~1/msg_stores/vhosts/628WB79CIFDYO9LJI6DKMI09L\",[],{#Fun,{start,[{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>}]}}]},transient,30000,worker,[rabbit_msg_store]}}},[{gen_server2,init_it,6,[{file,\"src/gen_server2.erl\"},{line,581}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,247}]}]}\r\nancestors: [,rabbit_vhost_sup_sup,rabbit_sup,]\r\nmessage_queue_len: 0\r\nmessages: []\r\nlinks: []\r\ndictionary: []\r\ntrap_exit: true\r\nstatus: running\r\nheap_size: 10958\r\nstack_size: 27\r\nreductions: 63314\r\n neighbours:\r\n2018-09-11 09:39:42 =SUPERVISOR REPORT====\r\n Supervisor: {,rabbit_vhost_sup_wrapper}\r\n Context: start_error\r\n Reason: {error,{{{function_clause,[{rabbit_queue_index,journal_minus_segment1,[{{true,>,>},no_del,no_ack},{{true,>,>},no_del,no_ack}],[{file,\"src/rabbit_queue_index.erl\"},{line,1231}]},{rabbit_queue_index,'-journal_minus_segment/3-fun-0-',4,[{file,\"src/rabbit_queue_index.erl\"},{line,1208}]},{array,sparse_foldl_3,7,[{file,\"array.erl\"},{line,1684}]},{array,sparse_foldl_2,9,[{file,\"array.erl\"},{line,1678}]},{rabbit_queue_index,'-recover_journal/1-fun-0-',1,[{file,\"src/rabbit_queue_index.erl\"},{line,915}]},{lists,map,2,[{file,\"lists.erl\"},{line,1239}]},{rabbit_queue_index,segment_map,2,[{file,\"src/rabbit_queue_index.erl\"},{line,1039}]},{rabbit_queue_index,recover_journal,1,[{file,\"src/rabbit_queue_index.erl\"},{line,906}]}]},{gen_server2,call,[,out,infinity]}},{child,undefined,msg_store_persistent,{rabbit_msg_store,start_link,[msg_store_persistent,\"c:/Users/dfpsb/AppData/Roaming/RabbitMQ/db/RABBIT~1/msg_stores/vhosts/628WB79CIFDYO9LJI6DKMI09L\",[],{#Fun,{start,[{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>},{resource,>,queue,>}]}}]},transient,30000,worker,[rabbit_msg_store]}}}\r\n Offender: [{pid,undefined},{id,rabbit_vhost_process},{mfargs,{rabbit_vhost_process,start_link,[>]}},{restart_type,permanent},{shutdown,30000},{child_type,worker}]\n```\n\n========================================\n\nTop Answer:\nFor me, I was trying to install management plugin (rabbitmqadmin) and it failed in \nrabbitmq-delayed-message-exchange. So I downloaded rabbitmq-delayed-message-exchange from JFrog Bintray and updated my plugins folder, stopped and started rabbitmq service. This action, courrupted the database. \n\nTo fix it, \n\nStop Rabbitmq service\n\nI went to %APPDATA%\\RabbitMQ\\db and cleared the data in transient msg_stores & queues folders. e.g. C:\\Users\\bharath\\AppData\\Roaming\\RabbitMQ\\db\\rabbit@js-mnesia\\msg_stores\\vhosts\\6ZOILVXV632BBEWZY4TBABTPP\\msg_store_transient\n\nRemoved the rabbitmq-delayed-message-exchange from rabbit@js-plugins-expand folder\n\nRemoved the data in transient msg_store & queues from RABBIT~1-upgrade-backup folder\n\nWent one folder back and removed the plugin name rabbitmq-delayed-message-exchange, from enabled_plugins file\n\nStart the rabbitmq service\n\nIt worked!!!\n\nNote: Only try this if data is not important, as it will get cleared or you can restore it from backup.\n\n========================================\n\nCode:\n```html\n2018-09-11 09:39:42 =ERROR REPORT====\n** Generic server <0.281.0> terminating\n** Last message in was {'$gen_cast',{submit_async,#Fun<rabbit_queue_index.36.122888644>}}\n** When Server state == undefined\n** Reason for termination == \n** {function_clause,[{rabbit_queue_index,journal_minus_segment1,[{{true,<<172,190,166,92,192,205,125,125,36,223,114,188,53,139,128,108,0,0,0,0,0,0,0,0,0,0,26,151>>,<<>>},no_del,no_ack},{{true,<<89,173,78,227,188,37,119,171,231,189,220,236,244,79,138,177,0,0,0,0,0,0,0,0,0,0,23,40>>,<<>>},no_del,no_ack}],[{file,\"src/rabbit_queue_index.erl\"},{line,1231}]},{rabbit_queue_index,'-journal_minus_segment/3-fun-0-',4,[{file,\"src/rabbit_queue_index.erl\"},{line,1208}]},{array,sparse_foldl_3,7,[{file,\"array.erl\"},{line,1684}]},{array,sparse_foldl_2,9,[{file,\"array.erl\"},{line,1678}]},{rabbit_queue_index,'-recover_journal/1-fun-0-',1,[{file,\"src/rabbit_queue_index.erl\"},{line,915}]},{lists,map,2,[{file,\"lists.erl\"},{line,1239}]},{rabbit_queue_index,segment_map,2,[{file,\"src/rabbit_queue_index.erl\"},{line,1039}]},{rabbit_queue_index,recover_journal,1,[{file,\"src/rabbit_queue_index.erl\"},{line,906}]}]}\n2018-09-11 09:39:42 =CRASH REPORT====\n crasher:\n initial call: worker_pool_worker:init/1\n pid: <0.281.0>\n registered_name: []\n exception exit: {{function_clause,[{rabbit_queue_index,journal_minus_segment1,[{{true,<<172,190,166,92,192,205,125,125,36,223,114,188,53,139,128,108,0,0,0,0,0,0,0,0,0,0,26,151>>,<<>>},no_del,no_ack},{{true,<<89,173,78,227,188,37,119,171,231,189,220,236,244,79,138,177,0,0,0,0,0,0,0,0,0,0,23,40>>,<<>>},no_del,no_ack}],[{file,\"src/rabbit_queue_index.erl\"},{line,1231}]},{rabbit_queue_index,'-journal_minus_segment/3-fun-0-',4,[{file,\"src/rabbit_queue_index.erl\"},{line,1208}]},{array,sparse_foldl_3,7,[{file,\"array.erl\"},{line,1684}]},{array,sparse_foldl_2,9,[{file,\"array.erl\"},{line,1678}]},{rabbit_queue_index,'-recover_journal/1-fun-0-',1,[{file,\"src/rabbit_queue_index.erl\"},{line,915}]},{lists,map,2,[{file,\"lists.erl\"},{line,1239}]},{rabbit_queue_index,segment_map,2,[{file,\"src/rabbit_queue_index.erl\"},{line,1039}]},{rabbit_queue_index,recover_journal,1,[{file,\"src/rabbit_queue_index.erl\"},{line,906}]}]},[{gen_server2,terminate,3,[{file,\"src/gen_server2.erl\"},{line,1161}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,247}]}]}\n ancestors: [worker_pool_sup,rabbit_sup,<0.262.0>]\n message_queue_len: 0\n messages: []\n links: [<0.276.0>,<0.336.0>,#Port<0.31196>]\n dictionary: [{fhc_age_tree,{1,{{10352640,#Ref<0.1077581647.1695285251.67028>},true,nil,nil}}},{worker_pool_worker,true},{rand_seed,{#{jump => #Fun<rand.16.15449617>,max => 288230376151711743,next => #Fun<rand.15.15449617>,type => exsplus},[257570830250844431|246837015578235662]}},{worker_pool_name,worker_pool},{{\"c:/Users/dfpsb/AppData/Roaming/RabbitMQ/db/RABBIT~1/msg_stores/vhosts/628WB79CIFDYO9LJI6DKMI09L/queues/9GD33C2I2PKZ7A8QHZ4MWWCKE/journal.jif\",fhc_file},{file,1,true}},{{#Ref<0.1077581647.1695285251.67028>,fhc_handle},{handle,{file_descriptor,prim_file,{#Port<0.31196>,1808}},#Ref<0.1077581647.1695285251.67028>,240,false,0,infinity,[],<<>>,0,0,0,0,0,false,\"c:/Users/dfpsb/AppData/Roaming/RabbitMQ/db/RABBIT~1/msg_stores/vhosts/628WB79CIFDYO9LJI6DKMI09L/queues/9GD33C2I2PKZ7A8QHZ4MWWCKE/journal.jif\",[write,binary,raw,read],[{write_buffer,infinity}],true,true,10352640}}]\n trap_exit: false\n status: running\n heap_size: 10958\n stack_size: 27\n reductions: 104391\n neighbours:\n neighbour: [{pid,<0.279.0>},{registered_name,[]},{initial_call,{worker_pool_worker,init,['Argument__1']}},{current_function,{gen,do_call,4}},{ancestors,[worker_pool_sup,rabbit_sup,<0.262.0>]},{message_queue_len,0},{links,[<0.276.0>,<0.336.0>]},{trap_exit,false},{status,waiting},{heap_size,4185},{stack_size,42},{reductions,21548},{current_stacktrace,[{gen,do_call,4,[{file,\"gen.erl\"},{line,169}]},{gen_server,call,3,[{file,\"gen_server.erl\"},{line,210}]},{file,call,2,[{file,\"file.erl\"},{line,1499}]},{rabbit_queue_index,get_journal_handle,1,[{file,\"src/rabbit_queue_index.erl\"},{line,881}]},{rabbit_queue_index,load_journal,1,[{file,\"src/rabbit_queue_index.erl\"},{line,894}]},{rabbit_queue_index,recover_journal,1,[{file,\"src/rabbit_queue_index.erl\"},{line,904}]},{rabbit_queue_index,scan_queue_segments,3,[{file,\"src/rabbit_queue_index.erl\"},{line,724}]},{rabbit_queue_index,queue_index_walker_reader,2,[{file,\"src/rabbit_queue_index.erl\"},{line,712}]}]}]\n neighbour: [{pid,<0.278.0>},{registered_name,[]},{initial_call,{worker_pool_worker,init,['Argument__1']}},{current_function,{gen,do_call,4}},{ancestors,[worker_pool_sup,rabbit_sup,<0.262.0>]},{message_queue_len,0},{links,[<0.276.0>,<0.336.0>,#Port<0.31157>]},{trap_exit,false},{status,waiting},{heap_size,6772},{stack_size,102},{reductions,129623},{current_stacktrace,[{gen,do_call,4,[{file,\"gen.erl\"},{line,169}]},{gen_server2,call,3,[{file,\"src/gen_server2.erl\"},{line,323}]},{array,sparse_foldr_3,6,[{file,\"array.erl\"},{line,1848}]},{array,sparse_foldr_2,8,[{file,\"array.erl\"},{line,1837}]},{lists,foldr,3,[{file,\"lists.erl\"},{line,1276}]},{rabbit_queue_index,scan_queue_segments,3,[{file,\"src/rabbit_queue_index.erl\"},{line,725}]},{rabbit_queue_index,queue_index_walker_reader,2,[{file,\"src/rabbit_queue_index.erl\"},{line,712}]},{rabbit_queue_index,'-queue_index_walker/1-fun-0-',2,[{file,\"src/rabbit_queue_index.erl\"},{line,694}]}]}]\n neighbour: [{pid,<0.280.0>},{registered_name,[]},{initial_call,{worker_pool_worker,init,['Argument__1']}},{current_function,{array,set_1,4}},{ancestors,[worker_pool_sup,rabbit_sup,<0.262.0>]},{message_queue_len,0},{links,[<0.276.0>,<0.336.0>,#Port<0.31170>]},{trap_exit,false},{status,runnable},{heap_size,121536},{stack_size,44},{reductions,122988},{current_stacktrace,[{array,set_1,4,[{file,\"array.erl\"},{line,590}]},{array,set_1,4,[{file,\"array.erl\"},{line,592}]},{array,set_1,4,[{file,\"array.erl\"},{line,592}]},{array,set,3,[{file,\"array.erl\"},{line,574}]},{rabbit_queue_index,parse_segment_publish_entry,5,[{file,\"src/rabbit_queue_index.erl\"},{line,1135}]},{rabbit_queue_index,segment_entries_foldr,3,[{file,\"src/rabbit_queue_index.erl\"},{line,1091}]},{lists,foldr,3,[{file,\"lists.erl\"},{line,1276}]},{rabbit_queue_index,scan_queue_segments,3,[{file,\"src/rabbit_queue_index.erl\"},{line,725}]}]}]\n neighbour: [{pid,<0.336.0>},{registered_name,[]},{initial_call,{gatherer,init,['Argument__1']}},{current_function,{gen_server2,process_next_msg,1}},{ancestors,[<0.332.0>,<0.324.0>,<0.323.0>,rabbit_vhost_sup_sup,rabbit_sup,<0.262.0>]},{message_queue_len,2},{links,[<0.280.0>,<0.332.0>,<0.281.0>,<0.278.0>,<0.279.0>]},{trap_exit,false},{status,runnable},{heap_size,987},{stack_size,8},{reductions,73223},{current_stacktrace,[{gen_server2,process_next_msg,1,[{file,\"src/gen_server2.erl\"},{line,666}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,247}]}]}]\n2018-09-11 09:39:42 =CRASH REPORT====\n crasher:\n initial call: rabbit_msg_store:init/1\n pid: <0.332.0>\n registered_name: []\n exception exit: {{{function_clause,[{rabbit_queue_index,journal_minus_segment1,[{{true,<<172,190,166,92,192,205,125,125,36,223,114,188,53,139,128,108,0,0,0,0,0,0,0,0,0,0,26,151>>,<<>>},no_del,no_ack},{{true,<<89,173,78,227,188,37,119,171,231,189,220,236,244,79,138,177,0,0,0,0,0,0,0,0,0,0,23,40>>,<<>>},no_del,no_ack}],[{file,\"src/rabbit_queue_index.erl\"},{line,1231}]},{rabbit_queue_index,'-journal_minus_segment/3-fun-0-',4,[{file,\"src/rabbit_queue_index.erl\"},{line,1208}]},{array,sparse_foldl_3,7,[{file,\"array.erl\"},{line,1684}]},{array,sparse_foldl_2,9,[{file,\"array.erl\"},{line,1678}]},{rabbit_queue_index,'-recover_journal/1-fun-0-',1,[{file,\"src/rabbit_queue_index.erl\"},{line,915}]},{lists,map,2,[{file,\"lists.erl\"},{line,1239}]},{rabbit_queue_index,segment_map,2,[{file,\"src/rabbit_queue_index.erl\"},{line,1039}]},{rabbit_queue_index,recover_journal,1,[{file,\"src/rabbit_queue_index.erl\"},{line,906}]}]},{gen_server2,call,[<0.336.0>,out,infinity]}},[{gen_server2,init_it,6,[{file,\"src/gen_server2.erl\"},{line,589}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,247}]}]}\n ancestors: [<0.324.0>,<0.323.0>,rabbit_vhost_sup_sup,rabbit_sup,<0.262.0>]\n message_queue_len: 1\n messages: [{'EXIT',<0.336.0>,{function_clause,[{rabbit_queue_index,journal_minus_segment1,[{{true,<<172,190,166,92,192,205,125,125,36,223,114,188,53,139,128,108,0,0,0,0,0,0,0,0,0,0,26,151>>,<<>>},no_del,no_ack},{{true,<<89,173,78,227,188,37,119,171,231,189,220,236,244,79,138,177,0,0,0,0,0,0,0,0,0,0,23,40>>,<<>>},no_del,no_ack}],[{file,\"src/rabbit_queue_index.erl\"},{line,1231}]},{rabbit_queue_index,'-journal_minus_segment/3-fun-0-',4,[{file,\"src/rabbit_queue_index.erl\"},{line,1208}]},{array,sparse_foldl_3,7,[{file,\"array.erl\"},{line,1684}]},{array,sparse_foldl_2,9,[{file,\"array.erl\"},{line,1678}]},{rabbit_queue_index,'-recover_journal/1-fun-0-',1,[{file,\"src/rabbit_queue_index.erl\"},{line,915}]},{lists,map,2,[{file,\"lists.erl\"},{line,1239}]},{rabbit_queue_index,segment_map,2,[{file,\"src/rabbit_queue_index.erl\"},{line,1039}]},{rabbit_queue_index,recover_journal,1,[{file,\"src/rabbit_queue_index.erl\"},{line,906}]}]}}]\n links: [<0.335.0>,<0.324.0>]\n dictionary: []\n trap_exit: true\n status: running\n heap_size: 2586\n stack_size: 27\n reductions: 57377\n neighbours:\n neighbour: [{pid,<0.335.0>},{registered_name,[]},{initial_call,{rabbit_msg_store_gc,init,['Argument__1']}},{current_function,{gen_server2,process_next_msg,1}},{ancestors,[<0.332.0>,<0.324.0>,<0.323.0>,rabbit_vhost_sup_sup,rabbit_sup,<0.262.0>]},{message_queue_len,0},{links,[<0.332.0>]},{trap_exit,false},{status,waiting},{heap_size,987},{stack_size,8},{reductions,174},{current_stacktrace,[{gen_server2,process_next_msg,1,[{file,\"src/gen_server2.erl\"},{line,666}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,247}]}]}]\n2018-09-11 09:39:42 =SUPERVISOR REPORT====\n Supervisor: {local,worker_pool_sup}\n Context: child_terminated\n Reason: {function_clause,[{rabbit_queue_index,journal_minus_segment1,[{{true,<<172,190,166,92,192,205,125,125,36,223,114,188,53,139,128,108,0,0,0,0,0,0,0,0,0,0,26,151>>,<<>>},no_del,no_ack},{{true,<<89,173,78,227,188,37,119,171,231,189,220,236,244,79,138,177,0,0,0,0,0,0,0,0,0,0,23,40>>,<<>>},no_del,no_ack}],[{file,\"src/rabbit_queue_index.erl\"},{line,1231}]},{rabbit_queue_index,'-journal_minus_segment/3-fun-0-',4,[{file,\"src/rabbit_queue_index.erl\"},{line,1208}]},{array,sparse_foldl_3,7,[{file,\"array.erl\"},{line,1684}]},{array,sparse_foldl_2,9,[{file,\"array.erl\"},{line,1678}]},{rabbit_queue_index,'-recover_journal/1-fun-0-',1,[{file,\"src/rabbit_queue_index.erl\"},{line,915}]},{lists,map,2,[{file,\"lists.erl\"},{line,1239}]},{rabbit_queue_index,segment_map,2,[{file,\"src/rabbit_queue_index.erl\"},{line,1039}]},{rabbit_queue_index,recover_journal,1,[{file,\"src/rabbit_queue_index.erl\"},{line,906}]}]}\n Offender: [{pid,<0.281.0>},{id,4},{mfargs,{worker_pool_worker,start_link,[worker_pool]}},{restart_type,transient},{shutdown,4294967295},{child_type,worker}]\n\n2018-09-11 09:39:42 =CRASH REPORT====\n crasher:\ninitial call: rabbit_vhost_process:init/1\npid: <0.325.0>\nregistered_name: []\nexception exit: {{error,{{{function_clause,[{rabbit_queue_index,journal_minus_segment1,[{{true,<<172,190,166,92,192,205,125,125,36,223,114,188,53,139,128,108,0,0,0,0,0,0,0,0,0,0,26,151>>,<<>>},no_del,no_ack},{{true,<<89,173,78,227,188,37,119,171,231,189,220,236,244,79,138,177,0,0,0,0,0,0,0,0,0,0,23,40>>,<<>>},no_del,no_ack}],[{file,\"src/rabbit_queue_index.erl\"},{line,1231}]},{rabbit_queue_index,'-journal_minus_segment/3-fun-0-',4,[{file,\"src/rabbit_queue_index.erl\"},{line,1208}]},{array,sparse_foldl_3,7,[{file,\"array.erl\"},{line,1684}]},{array,sparse_foldl_2,9,[{file,\"array.erl\"},{line,1678}]},{rabbit_queue_index,'-recover_journal/1-fun-0-',1,[{file,\"src/rabbit_queue_index.erl\"},{line,915}]},{lists,map,2,[{file,\"lists.erl\"},{line,1239}]},{rabbit_queue_index,segment_map,2,[{file,\"src/rabbit_queue_index.erl\"},{line,1039}]},{rabbit_queue_index,recover_journal,1,[{file,\"src/rabbit_queue_index.erl\"},{line,906}]}]},{gen_server2,call,[<0.336.0>,out,infinity]}},{child,undefined,msg_store_persistent,{rabbit_msg_store,start_link,[msg_store_persistent,\"c:/Users/dfpsb/AppData/Roaming/RabbitMQ/db/RABBIT~1/msg_stores/vhosts/628WB79CIFDYO9LJI6DKMI09L\",[],{#Fun<rabbit_queue_index.2.122888644>,{start,[{resource,<<\"/\">>,queue,<<\"DF-9ID59RK-WS.InterchangeFragtbrevEnvelope.TurPlan\">>},{resource,<<\"/\">>,queue,<<\"Test1.InterchangeFragtbrevEnvelope.RET\">>},{resource,<<\"/\">>,queue,<<\"Test2.DfLoggingEvent.Debug\">>},{resource,<<\"/\">>,queue,<<\"DF-9ID59RK-WS.InterchangeTurEnvelope.DFMobil\">>},{resource,<<\"/\">>,queue,<<\"Paw.DfLoggingEvent.Debug\">>},{resource,<<\"/\">>,queue,<<\"DevUnitTest.TruckLoadingEnvelope.UnitTest\">>},{resource,<<\"/\">>,queue,<<\"Test1.InterchangeFragtbrevEnvelope.RET_error\">>},{resource,<<\"/\">>,queue,<<\"Paw.InterchangeFragtbrevEnvelope.TurPlan\">>},{resource,<<\"/\">>,queue,<<\"DevUnitTest.TestMsg.UnitTest_error\">>},{resource,<<\"/\">>,queue,<<\"DevUnitTest.TestMsg.UnitTest\">>},{resource,<<\"/\">>,queue,<<\"Paw.InterchangeTurEnvelope.DFMobil\">>},{resource,<<\"/\">>,queue,<<\"Test2.InterchangeFragtbrevEnvelope.TurPlan\">>},{resource,<<\"/\">>,queue,<<\"Paw.InterchangeFragtbrevEnvelope.TurPlan_error\">>},{resource,<<\"/\">>,queue,<<\"Paw.TruckLoadingEnvelope.TurPlan\">>},{resource,<<\"/\">>,queue,<<\"Test2.InterchangeFragtbrevEnvelope.TurPlan_error\">>},{resource,<<\"/\">>,queue,<<\"Test2.TruckLoadingEnvelope.TurPlan\">>},{resource,<<\"/\">>,queue,<<\"Paw.DfLoggingEvent.Warning\">>},{resource,<<\"/\">>,queue,<<\"DF-9ID59RK-WS.InterchangeFragtbrevEnvelope.RET\">>},{resource,<<\"/\">>,queue,<<\"Test2.InterchangeTurEnvelope.DFMobil\">>},{resource,<<\"/\">>,queue,<<\"Test2.DfLoggingEvent.Warning\">>}]}}]},transient,30000,worker,[rabbit_msg_store]}}},[{gen_server2,init_it,6,[{file,\"src/gen_server2.erl\"},{line,581}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,247}]}]}\nancestors: [<0.323.0>,rabbit_vhost_sup_sup,rabbit_sup,<0.262.0>]\nmessage_queue_len: 0\nmessages: []\nlinks: [<0.323.0>]\ndictionary: []\ntrap_exit: true\nstatus: running\nheap_size: 10958\nstack_size: 27\nreductions: 63314\n neighbours:\n2018-09-11 09:39:42 =SUPERVISOR REPORT====\n Supervisor: {<0.323.0>,rabbit_vhost_sup_wrapper}\n Context: start_error\n Reason: {error,{{{function_clause,[{rabbit_queue_index,journal_minus_segment1,[{{true,<<172,190,166,92,192,205,125,125,36,223,114,188,53,139,128,108,0,0,0,0,0,0,0,0,0,0,26,151>>,<<>>},no_del,no_ack},{{true,<<89,173,78,227,188,37,119,171,231,189,220,236,244,79,138,177,0,0,0,0,0,0,0,0,0,0,23,40>>,<<>>},no_del,no_ack}],[{file,\"src/rabbit_queue_index.erl\"},{line,1231}]},{rabbit_queue_index,'-journal_minus_segment/3-fun-0-',4,[{file,\"src/rabbit_queue_index.erl\"},{line,1208}]},{array,sparse_foldl_3,7,[{file,\"array.erl\"},{line,1684}]},{array,sparse_foldl_2,9,[{file,\"array.erl\"},{line,1678}]},{rabbit_queue_index,'-recover_journal/1-fun-0-',1,[{file,\"src/rabbit_queue_index.erl\"},{line,915}]},{lists,map,2,[{file,\"lists.erl\"},{line,1239}]},{rabbit_queue_index,segment_map,2,[{file,\"src/rabbit_queue_index.erl\"},{line,1039}]},{rabbit_queue_index,recover_journal,1,[{file,\"src/rabbit_queue_index.erl\"},{line,906}]}]},{gen_server2,call,[<0.336.0>,out,infinity]}},{child,undefined,msg_store_persistent,{rabbit_msg_store,start_link,[msg_store_persistent,\"c:/Users/dfpsb/AppData/Roaming/RabbitMQ/db/RABBIT~1/msg_stores/vhosts/628WB79CIFDYO9LJI6DKMI09L\",[],{#Fun<rabbit_queue_index.2.122888644>,{start,[{resource,<<\"/\">>,queue,<<\"DF-9ID59RK-WS.InterchangeFragtbrevEnvelope.TurPlan\">>},{resource,<<\"/\">>,queue,<<\"Test1.InterchangeFragtbrevEnvelope.RET\">>},{resource,<<\"/\">>,queue,<<\"Test2.DfLoggingEvent.Debug\">>},{resource,<<\"/\">>,queue,<<\"DF-9ID59RK-WS.InterchangeTurEnvelope.DFMobil\">>},{resource,<<\"/\">>,queue,<<\"Paw.DfLoggingEvent.Debug\">>},{resource,<<\"/\">>,queue,<<\"DevUnitTest.TruckLoadingEnvelope.UnitTest\">>},{resource,<<\"/\">>,queue,<<\"Test1.InterchangeFragtbrevEnvelope.RET_error\">>},{resource,<<\"/\">>,queue,<<\"Paw.InterchangeFragtbrevEnvelope.TurPlan\">>},{resource,<<\"/\">>,queue,<<\"DevUnitTest.TestMsg.UnitTest_error\">>},{resource,<<\"/\">>,queue,<<\"DevUnitTest.TestMsg.UnitTest\">>},{resource,<<\"/\">>,queue,<<\"Paw.InterchangeTurEnvelope.DFMobil\">>},{resource,<<\"/\">>,queue,<<\"Test2.InterchangeFragtbrevEnvelope.TurPlan\">>},{resource,<<\"/\">>,queue,<<\"Paw.InterchangeFragtbrevEnvelope.TurPlan_error\">>},{resource,<<\"/\">>,queue,<<\"Paw.TruckLoadingEnvelope.TurPlan\">>},{resource,<<\"/\">>,queue,<<\"Test2.InterchangeFragtbrevEnvelope.TurPlan_error\">>},{resource,<<\"/\">>,queue,<<\"Test2.TruckLoadingEnvelope.TurPlan\">>},{resource,<<\"/\">>,queue,<<\"Paw.DfLoggingEvent.Warning\">>},{resource,<<\"/\">>,queue,<<\"DF-9ID59RK-WS.InterchangeFragtbrevEnvelope.RET\">>},{resource,<<\"/\">>,queue,<<\"Test2.InterchangeTurEnvelope.DFMobil\">>},{resource,<<\"/\">>,queue,<<\"Test2.DfLoggingEvent.Warning\">>}]}}]},transient,30000,worker,[rabbit_msg_store]}}}\n Offender: [{pid,undefined},{id,rabbit_vhost_process},{mfargs,{rabbit_vhost_process,start_link,[<<\"/\">>]}},{restart_type,permanent},{shutdown,30000},{child_type,worker}]\n```\n\n```text\nsudo rabbitmqctl stop\n\nsudo rabbitmq-server -detached\n```\n\n```text\nsudo\n```\n\n```text\nsudo rabbitmqctl start_app\nsudo rabbitmqctl reset\n```\n\n```text\nsudo rabbitmqctl forget_cluster_node {vhost_name}@{faulty_node_name}\n```\n\n```text\nsudo rabbitmqctl join_cluster {vhost_name}@{any_working_cluster_node}\n```\n\n```text\nsudo rabbitmqctl start_app\n```\n\n```text\n/var/lib/rabbitmq/mnesia/{vhost_name}\n```\n\n========================================\n\nComments:\n- I suggest doing a search on the keyword `journal_minus_segment1` - you'll find relevant information. In addition, providing information like RabbitMQ and Erlang version is required to narrow issues down. This document has suggestions for what information should be provided. Finally, the `rabbitmq-users` mailing list is the best place to get help as the core team members monitor it.\n- you can delete contains of /var/lib/rabbitmq/.mnesia and restart rabbit.\n- Thanks @JamesM this solved my problem, however it also deleted my users, so I had to re-create them, and also re-created guest (which is a vulnerability)!\n- Variant of this worked for me - I purged `rabbit@-mnesia` from the `db` folder. Possibly was caused by a full disk and it didn't recover after purging. I didn't care about data loss on my dev machine","metadata":{"transformedAt":"2026-08-18T18:33:20.151Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":235,"estimatedTokens":8300}}373{"id":"stack-34202345","source":"stackoverflow","questionId":34202345,"title":"RabbitMQ def callback(ch, method, properties, body)","tags":["rabbitmq","pika","python-pika"],"text":"Title: RabbitMQ def callback(ch, method, properties, body)\nTags: rabbitmq, pika, python-pika\nSource: Stack Overflow\n\nQuestion:\nJust want to know the meaning of the parameters in `worker.py` file:\n\n```\ndef callback(ch, method, properties, body):\n print \" [x] Received %r\" % (body,)\n```\n\nWhat do ch, method, and properties mean?\n\n========================================\n\nCode:\n```text\ndef callback(ch, method, properties, body):\n print \" [x] Received %r\" % (body,)\n```\n\n```text\nworker.py\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.151Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":25,"estimatedTokens":124}}374{"id":"stack-57262128","source":"stackoverflow","questionId":57262128,"title":"Using rabbitmq with docker in production","tags":["docker","docker-compose","rabbitmq"],"text":"Title: Using rabbitmq with docker in production\nTags: docker, docker-compose, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI currently have a small server running in a docker container, the server uses RabbitMQ which is being run by docker-compose using the DockerHub image.\n\nIt is running nicely, but I'm worried that it may not be properly configured for production (production being a simple server, without clustering or anything fancy). In particular, I'm worried about the disk space limit described at RabbitMQ production checklist.\n\nI'm not sure how to configure these things through docker-compose, as the env variables defined by the image seem to be quite limited.\n\nMy docker-compose file:\n\n```\nversion: '3.4'\nservices:\n rabbitmq:\n image: rabbitmq:3-management-alpine\n ports:\n - \"5672:5672\"\n - \"15672:15672\"\n volumes:\n - rabbitmq:/var/lib/rabbitmq\n restart: always\n environment:\n - RABBITMQ_DEFAULT_USER=user\n - RABBITMQ_DEFAULT_PASS=secretpassword\n\n my-server:\n # server config here\n\nvolumes:\n rabbitmq:\n\nnetworks:\n server-network:\n driver: bridge\n```\n\n========================================\n\nCode:\n```text\nversion: '3.4'\nservices:\n rabbitmq:\n image: rabbitmq:3-management-alpine\n ports:\n - \"5672:5672\"\n - \"15672:15672\"\n volumes:\n - rabbitmq:/var/lib/rabbitmq\n restart: always\n environment:\n - RABBITMQ_DEFAULT_USER=user\n - RABBITMQ_DEFAULT_PASS=secretpassword\n\n my-server:\n # server config here\n\nvolumes:\n rabbitmq:\n\nnetworks:\n server-network:\n driver: bridge\n```\n\n```text\nshubuntu1@shubuntu1:~$ docker exec some-rabbit cat /etc/rabbitmq/rabbitmq.conf\nloopback_users.guest = false\nlisteners.tcp.default = 5672\n```\n\n```text\nloopback_users.guest = false\nlisteners.tcp.default = 5672\ndisk_free_limit.absolute = 1GB\n```\n\n```text\nversion: '3.4'\nservices:\n rabbitmq:\n image: rabbitmq:3-management-alpine\n ports:\n - \"5672:5672\"\n - \"15672:15672\"\n volumes:\n - rabbitmq:/var/lib/rabbitmq\n - ./rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf\n\nvolumes:\n rabbitmq:\n\nnetworks:\n server-network:\n driver: bridge\n```\n\n```text\n$ docker-compose up -d\n$ docker-compose logs rabbitmq | grep \"Disk free limit\"\nrabbitmq_1 | 2019-07-30 04:51:40.609 [info] <0.241.0> Disk free limit set to 1000MB\n```\n\n```text\ndisk_free_limit\n```\n\n```text\n/etc/rabbitmq/rabbitmq.conf\n```\n\n```text\nrabbitmq.conf\n```\n\n```text\ndisk_free_limit.absolute = 1GB\n```\n\n```text\nrabbitmq.conf\n```\n\n```text\ndisk free limit\n```\n\n========================================\n\nComments:\n- It depends on what OS you’re using as host for docker daemon. If it’s windows then the hyperV machine’s disk is the size limit for all your docker containers, in the case of Linux its the actual system If I’m not mistaken\n- I'm more worried about the disk_size_limit imposed by rabbitmq itself (~50MB according to docs) rather than docker disk size (I'm using Linux btw)\n- After adding `- ./rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf`, creating that file and executing docker-compose up -d, logs only show `rabbitmq_1 | sed: can't move '/etc/rabbitmq/rabbitmq.confLNOkjP' to '/etc/rabbitmq/rabbitmq.conf': Resource busy`\n- @angrykoala Sorry, I did not notice there is a rabbitmq docker official issue there, see this, so the solution is remove your environment in docker-compose.yaml. In my example I also did not set it. To set the environment, set `default_user = admin` & `default_pass = YourStrongPasswort` in your `rabbitmq.conf` also.\n- And, another solution is not use volume, use you own dockerfile, in this dockerfile, use `COPY ./rabbitmq.conf /etc/rabbitmq/rabbitmq.conf`, then in compose.yaml, use your own docker image which base from the official rabbitmq docker image. In this way, you can still use `environment` in your docker-compose.yaml","metadata":{"transformedAt":"2026-08-18T18:33:20.151Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":11,"totalLines":138,"estimatedTokens":958}}375{"id":"stack-31938638","source":"stackoverflow","questionId":31938638,"title":"Spring with AMQP and RabbitMQ, queue with optional x-dead-letter-exchange","tags":["java","spring","rabbitmq","amqp","spring-amqp"],"text":"Title: Spring with AMQP and RabbitMQ, queue with optional x-dead-letter-exchange\nTags: java, spring, rabbitmq, amqp, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI have an existing queue created in RabbitMQ. It can be created with or without `x-dead-letter-exchange` parameter. I am creating a consumer of this queue in Spring using the RabbitTemplate. When I declare the queue, I don't want to specify the `x-dead-letter-exchange` parameter. I would like the template to somehow figure it itself or not care. I am throwing `AmqpRejectAndDontRequeueException` from my consumer to indicate bad messages, but I want the creator of the queue to be responsible for the decision whether or not to create an exchange and queue for the rejected messages.\n\nHere is my bean that declares the queue in Spring:\n\n```\n@Bean\nQueue queue() {\n Map args = new HashMap<>();\n // set the queue with a dead letter feature\n args.put(\"x-dead-letter-exchange\", REJECTED_EXCHANGE);\n args.put(\"x-dead-letter-routing-key\", REJECTED_ROUTING_KEY);\n Queue queue = new Queue(Constants.QUEUE_NAME, false, false, false, args);\n return queue;\n}\n```\n\nThis works fine, but when the creator of the queue decides not to use the dead letter feature, I see the following error:\n\n```\nChannel shutdown: channel error; protocol method: #method\n(reply-code=406, reply-text=PRECONDITION_FAILED - \ninequivalent arg 'x-dead-letter-exchange' for queue 'queueName'\n```\n\nThe message is a bit longer, it continues telling me which side has which `x-dead-letter-exchange` (none or a name of the exchange). I've tried different combinations (e.g. creating the queue with exchange and not specifying it in the Spring or creating the queue without the exchange and specifying it in the Spring), only to see different variants of this message.\n\nHow do I declare the queue so it simply accepts whatever parameters are already set in the queue?\n\n========================================\n\nTop Answer:\nYes, The possible cause is - if you declare some queues manually and later your program (client in code) tries to create one (based on the settings you had in code) then you get this error. The reason behind it is when your code (client application) tries to access one queue. It gets a signal from the server that the connection is not available for this.\n\nTo solve this problem\n\n- Delete all the queues that you have created manually, and let the client program create them by itself.\n\n- If you got problems in deleting the queues, because of some data is there in it, or for some reason, you want to maintain it, create one queue manually, and move all the queue data to be deleted in it through \"Move\" tab of the queue.\n\n========================================\n\nCode:\n```text\n@Bean\nQueue queue() {\n Map<String, Object> args = new HashMap<>();\n // set the queue with a dead letter feature\n args.put(\"x-dead-letter-exchange\", REJECTED_EXCHANGE);\n args.put(\"x-dead-letter-routing-key\", REJECTED_ROUTING_KEY);\n Queue queue = new Queue(Constants.QUEUE_NAME, false, false, false, args);\n return queue;\n}\n```\n\n```text\nChannel shutdown: channel error; protocol method: #method<channel.close>\n(reply-code=406, reply-text=PRECONDITION_FAILED - \ninequivalent arg 'x-dead-letter-exchange' for queue 'queueName'\n```\n\n```text\nx-dead-letter-exchange\n```\n\n```text\nx-dead-letter-exchange\n```\n\n```text\nAmqpRejectAndDontRequeueException\n```\n\n```text\nx-dead-letter-exchange\n```\n\n```text\nThe RabbitMQ broker will not allow declaration of a queue with mismatched arguments.\n```\n\n```text\nqueueDeclarePassive\n```\n\n========================================\n\nComments:\n- When declaring RabbitMQ objects, like queues and exchanges you have to specify the exact same parameters, RabbitMQ won't do any kind of parameter merging for you. How do you do that with spring, I don't know.\n- Deleting queues and let them being created on application startup solved for me","metadata":{"transformedAt":"2026-08-18T18:33:20.151Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":94,"estimatedTokens":975}}376{"id":"stack-44196151","source":"stackoverflow","questionId":44196151,"title":"Running RabbitMQ+Celery in the same server as production environment","tags":["amazon-web-services","amazon-ec2","rabbitmq","celery","django-celery"],"text":"Title: Running RabbitMQ+Celery in the same server as production environment\nTags: amazon-web-services, amazon-ec2, rabbitmq, celery, django-celery\nSource: Stack Overflow\n\nQuestion:\nI'm running a Django app in an EC2 instance, which uses RabbitMQ + Celery for task queuing. Are there any drawbacks to running my RabbitMQ node from the same EC2 instance as my production app?\n\n========================================\n\nTop Answer:\nTLDR; If you can run on one EC2 you should but make it easy to scale today.\n\nBoth Joshnidhin and Giannis covered the RAM, IO and CPU aspects.\n\nI have run production apps in single instances with containerization and slept with peace of mind that if tomorrow suddenly lots of people want what I have built, I can scale pretty quickly by deploying those containers on different instances instead of one single instance.\n\nDocker allows you to put a limit on CPU consumption and memory usage for each container hence you can also be sure that they will not step into each other.","metadata":{"transformedAt":"2026-08-18T18:33:20.151Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":17,"estimatedTokens":251}}377{"id":"stack-19481470","source":"stackoverflow","questionId":19481470,"title":"Measuring Celery task execution time","tags":["python","rabbitmq","celery"],"text":"Title: Measuring Celery task execution time\nTags: python, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI have converted a standalone batch job to use celery for dispatching the work to be done. I'm using RabbitMQ. Everything is running on a single machine and no other processes are using the RabbitMQ instance. My script just creates a bunch of tasks which are processed by workers.\n\nIs there a simple way to measure the time from the start of my script until all tasks are finished? I know that this a bit complicated by design when using message queues. But I don't want to do it in production, just for testing and getting a performance estimation.\n\n========================================\n\nTop Answer:\nYou could use celery signals, functions registered will be called before and after a task is executed, it is trivial to measure elapsed time:\n\n```\nfrom time import time\nfrom celery.signals import task_prerun, task_postrun\n\nd = {}\n\n@task_prerun.connect\ndef task_prerun_handler(signal, sender, task_id, task, args, kwargs, **extras):\n d[task_id] = time()\n\n@task_postrun.connect\ndef task_postrun_handler(signal, sender, task_id, task, args, kwargs, retval, state, **extras):\n try:\n cost = time() - d.pop(task_id)\n except KeyError:\n cost = -1\n print task.__name__, cost\n```\n\n========================================\n\nCode:\n```text\nimport celery\nimport datetime\nfrom celery import chord\n\n@celery.task\ndef dummy_task(res=None, start_time=None):\n print datetime.datetime.now() - start_time\n\ndef send_my_task():\n chord(my_task.s(), dummy_task.s(start_time=datetime.datetime.now()).delay()\n```\n\n```text\nsend_my_task\n```\n\n```text\ndummy_task\n```\n\n```text\nfrom time import time\nfrom celery.signals import task_prerun, task_postrun\n\n\nd = {}\n\n@task_prerun.connect\ndef task_prerun_handler(signal, sender, task_id, task, args, kwargs, **extras):\n d[task_id] = time()\n\n\n@task_postrun.connect\ndef task_postrun_handler(signal, sender, task_id, task, args, kwargs, retval, state, **extras):\n try:\n cost = time() - d.pop(task_id)\n except KeyError:\n cost = -1\n print task.__name__, cost\n```\n\n========================================\n\nComments:\n- But dummy_task will be another task and can be executed on different worker or significant later, than original task.\n- @homm, yes, but the OP explicitly stated that there is a single worker node, and no other processes are using the RabbitMQ node, thus only tasks that we are measuring are calculated. The only delay comes from receiving the time measuring tasks for the last time, but the chord is on a 1-second periodic timer.\n- No other processes, but not \"no other tasks\", right? If there is no free worker processes, dummy_task will wait.\n- @homm, yes, but the OP said that no other process than his script uses the queue, and the OP wants to measure time from start of the script up to when *all* tasks have finished.\n- @vikas-prasad `kwargs` is for receiving \"task keyword arguments\", added `**extras` for celery 4 compatiability.","metadata":{"transformedAt":"2026-08-18T18:33:20.151Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":86,"estimatedTokens":752}}378{"id":"stack-31340413","source":"stackoverflow","questionId":31340413,"title":"How to set up autoscaling RabbitMQ Cluster AWS","tags":["amazon-web-services","amazon-ec2","docker","rabbitmq","cluster-computing"],"text":"Title: How to set up autoscaling RabbitMQ Cluster AWS\nTags: amazon-web-services, amazon-ec2, docker, rabbitmq, cluster-computing\nSource: Stack Overflow\n\nQuestion:\nI'm trying to move away from SQS to RabbitMQ for messaging service. I'm looking to build a stable high availability queuing service. For now I'm going with cluster. \n\n**Current Implementation** , \n I have three EC2 machines with RabbitMQ with management plugin installed in a AMI , and then I explicitly go to each of the machine and add \n\n```\nsudo rabbitmqctl join_cluster rabbit@\n```\n\nWith HA property set to all and the synchronization works. And a load balancer on top it with a DNS assigned. So far this thing works. \n\n**Expected Implementation**: Create an autoscaling clustered environment where the machines that go Up/Down has to join/Remove the cluster dynamically. What is the best way to achieve this? Please help.\n\n========================================\n\nTop Answer:\nWe recently had similar problem.\n\nWe tried to use https://github.com/rabbitmq/rabbitmq-autocluster but found it overcomplicated for our use case. \n\nI created terraform configuration to spin X RabbitMQ nodes on Y subnets (availability zones) using Autoscaling Group.\n\nTL;DR https://github.com/ulamlabs/rabbitmq-aws-cluster\n\nThe configuration creates IAM role to allow nodes to autodiscover all other nodes in the Autoscaling Group.\n\n========================================\n\nCode:\n```text\nsudo rabbitmqctl join_cluster rabbit@<hostnameOfParentMachine>\n```\n\n```py\n#!/usr/bin/env python\nimport json\nimport urllib2,base64\n\nif __name__ == '__main__':\n prefix =''\n from subprocess import call\n call([\"rabbitmqctl\", \"stop_app\"])\n call([\"rabbitmqctl\", \"reset\"])\n try:\n _url = 'http://internal-myloadbalamcer-xxx.com:15672/api/nodes'\n print prefix + 'Get json info from ..' + _url\n request = urllib2.Request(_url)\n\n base64string = base64.encodestring('%s:%s' % ('guest', 'guest')).replace('\\n', '')\n request.add_header(\"Authorization\", \"Basic %s\" % base64string)\n data = json.load(urllib2.urlopen(request))\n ##if the script got an error here you can assume that it's the first machine and then \n ## exit without controll the error. Remember to add the new machine to the balancer\n print prefix + 'request ok... finding for running node'\n\n\n for r in data:\n if r.get('running'):\n print prefix + 'found running node to bind..'\n print prefix + 'node name: '+ r.get('name') +'- running:' + str(r.get('running'))\n from subprocess import call\n call([\"rabbitmqctl\", \"join_cluster\",r.get('name')])\n break;\n pass\n except Exception, e:\n print prefix + 'error during add node'\n finally:\n from subprocess import call\n call([\"rabbitmqctl\", \"start_app\"])\n\n\n pass\n```\n\n```text\nrabbitmqctl set_policy ha-two \"^two\\.\" ^\n \"{\"\"ha-mode\"\":\"\"exactly\"\",\"\"ha-params\"\":2,\"ha-sync-mode\":\"automatic\"}\"\n```\n\n========================================\n\nComments:\n- autoscaling based on? cloudwatch?\n- Yes . But then the scaled instance has to join the cluster automatically.\n- Be careful - Erlang in clustered mode is not tolerant to network partitions (including micro-partitions), and may cause some problems; I had regular micro-partitions on AWS which would bring my cluster down. I would recommend running a staging cluster for a while before committing to it for production.\n- Your script works like a charm! thanks a ton . Regarding taking the node away fro mthe load balancer im using the autoscaling policy based on the memory utilization i.e <40% .\n- I was able to do that via custom metric for memory as per aws documentation on custom metric . Thanks for the code .\n- Isn't the point of the clustering such that you *can* remove a node because the data are replicated between the nodes?\n- @K-Iyer can you please how did you handle with removing nodes from the cluster automatically?\n- @Berlin Yes that is something I put it on pending while running against time and havent found time to look at it yet. Currently those stay as the inactive nodes in the rabbitmq admin page. :P sorry about that\n- @Karthik you can clean dead nodes with autocluster plugin, it work very well\n- Hi all, this post is bit old, we are working on: github.com/rabbitmq/rabbitmq-autocluster so I suggest to use it to scale on AWS\n- Nice to see it as a plugin @Gabriele. Will definitely be useful.","metadata":{"transformedAt":"2026-08-18T18:33:20.151Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":98,"estimatedTokens":1124}}379{"id":"stack-43001689","source":"stackoverflow","questionId":43001689,"title":"Can I dispatch messages with a custom algorithm instead of round robin using RabbitMQ?","tags":["java","algorithm","rabbitmq"],"text":"Title: Can I dispatch messages with a custom algorithm instead of round robin using RabbitMQ?\nTags: java, algorithm, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm using RabbitMQ's round robin feature to dispatch messages between multiple consumers but having only one of them receive the actual message at a time.\n\nMy problem is that my messages represent tasks and I would like to have local sessions (state) on my consumers. I know beforehand which messages belong to which session but I don't know what is the best way (or is there a way?) to make RabbitMQ dispatch to consumers using an algorithm I specify.\n\nI don't want to write my own orchestration service because it will become a bottleneck and I don't want my producers to know which consumer will take their messages because I'll lose the decoupling I get using Rabbit.\n\nIs there a way to make RabbitMQ dispatch my messages to consumers based on a pre-defined algorithm/rule instead of round robin?\n\n**Clarification:** I use several microservices written in different languages and each service has its own job. I communicate between them using protobuf messages. I give each new message a `UUID`. If a consumer receives a message it can create a response message from it *(this might not be the correct terminology since the producers and consumers are decoupled and they don't know about each other)* and this `UUID` is copied to the new message. This forms a data transformation pipeline and this **\"process\"** is identified by the `UUID` (the *processId*). My problem is that it is possible that I have multiple worker consumers and I need a worker to **stick** to an `UUID` if it has seen it before. I have this need because \n\n- there might be local state for each *process*\n\n- After the *process* is finished I want to clean up the local state\n\n- A microservice might receive multiple messages for the same *process* and I need to differentiate which message belongs to which *process*\n\nSince RabbitMQ distributes tasks between workers using round robin I can't force my processes to stick to a worker. I have several caveats:\n\n- The producers are decoupled from the consumers so direct messaging is not an option\n\n- The number of workers is not constant (there is a load balancer which might start new instances of a worker)\n\n**If there is a workaround which does not involve changing the round robin algorithm and does not break my constraints it is also OK!**\n\n========================================\n\nCode:\n```text\nUUID\n```\n\n```text\nUUID\n```\n\n```text\nUUID\n```\n\n```text\nUUID\n```\n\n```text\nprocessId\n```\n\n```text\nheader\n```\n\n```text\nalternative-exchange\n```\n\n```text\nNo Session Exchange\n```\n\n```text\nor else\n```\n\n```text\nprocessId(s)\n```\n\n```text\nprocessId\n```\n\n```text\nprocessId\n```\n\n========================================\n\nComments:\n- Could you elaborate on what exactly makes a message belong to a specific consumer?\n- See my edit which clarifies this.\n- Simply Genius! I was aware of the alternate exchange but I was not aware of this clever trick which it can be used for!","metadata":{"transformedAt":"2026-08-18T18:33:20.152Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":12,"totalLines":86,"estimatedTokens":763}}380{"id":"stack-14821675","source":"stackoverflow","questionId":14821675,"title":"unable to start rabbitmq-server","tags":["erlang","rabbitmq"],"text":"Title: unable to start rabbitmq-server\nTags: erlang, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI installed rabbitmq using homebrew. I am trying to start rabbitmq server but I always get this error which I am unable to figure out why!\n\nI have erlang installed and there is no other application running on the same port.\n\n$ rabbitmq-server \n{error_logger,{{2013,2,11},{22,37,49}},\"Can't set short node name!\\nPlease check your configuration\\n\",[]}\n{error_logger,{{2013,2,11},{22,37,49}},crash_report,[[{initial_call,{net_kernel,init,['Argument__1']}},{pid,},{registered_name,[]},{error_info,{exit,{error,badarg},[{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,320}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,227}]}]}},{ancestors,[net_sup,kernel_sup,]},{messages,[]},{links,[]},{dictionary,[{longnames,false}]},{trap_exit,true},{status,running},{heap_size,610},{stack_size,24},{reductions,249}],[]]}\n{error_logger,{{2013,2,11},{22,37,49}},supervisor_report,[{supervisor,{local,net_sup}},{errorContext,start_error},{reason,{'EXIT',nodistribution}},{offender,[{pid,undefined},{name,net_kernel},{mfargs,{net_kernel,start_link,[[rabbitmqprelaunch1593,shortnames]]}},{restart_type,permanent},{shutdown,2000},{child_type,worker}]}]}\n{error_logger,{{2013,2,11},{22,37,49}},supervisor_report,[{supervisor,{local,kernel_sup}},{errorContext,start_error},{reason,shutdown},{offender,[{pid,undefined},{name,net_sup},{mfargs,{erl_distribution,start_link,[]}},{restart_type,permanent},{shutdown,infinity},{child_type,supervisor}]}]}\n{error_logger,{{2013,2,11},{22,37,49}},std_info,[{application,kernel},{exited,{shutdown,{kernel,start,[normal,[]]}}},{type,permanent}]}\n{\"Kernel pid terminated\",application_controller,\"{application_start_failure,kernel,{shutdown,{kernel,start,[normal,[]]}}}\"}\n\nCrash dump was written to: erl_crash.dump\nKernel pid terminated (application_controller) ({application_start_failure,kernel,{shutdown,{kernel,start,[normal,[]]}}})\n\nbtw, `erl -sname abc` gives the same output\n\n**Update**:\n\nThis is what I have in `/etc/hosts`\n\n127.0.0.1 localhost\n255.255.255.255 broadcasthost\n\n========================================\n\nTop Answer:\ncheck your computer name and your short host name or alias name in /etc/hosts, match this\n\nCheck your computer name `[wendy@nyc123]$`\n\nnyc123 is your computer name\nCheck your short hostname \n\n[wendy@nyc123]$ hostname -s\n\n[wendy@nyc123]$ nyc456\n\nThis error could happen because your computer name and short host name didn't match. To match this, you can change the computer hostname or alias name.\n\nChange computer host name\n\n[wendy@nyc123]$ hostname nyc456\n\nclose your terminal and open again\n\n[wendy@nyc456]$ \n\nthe computer name has changed\n\nor\n\nChange alias name in /etc/hosts\n\n127.0.0.1 nyc123.com nyc123\n\nsave and check again\n\n[wendy@nyc123]$ hostname -s\n\n[wendy@nyc123]$ nyc123\n\nRestart your rabbitmq!\n\n```\n[root@nyc123]$ rabbitmq-server start\n\n RabbitMQ 3.6.0. Copyright (C) 2007-2015 Pivotal Software, Inc.\n\n## ## Licensed under the MPL. See http://www.rabbitmq.com/\n\n## ##\n\n########## Logs: /var/log/rabbitmq/rabbitmq@nyc123.com.log\n\n###### ## /var/log/rabbitmq/rabbitmq@nyc123.com-sasl.log\n\n##########\n\n Starting broker... completed with 6 plugins.\n\n```\n\n========================================\n\nCode:\n```text\n$ rabbitmq-server \n{error_logger,{{2013,2,11},{22,37,49}},\"Can't set short node name!\\nPlease check your configuration\\n\",[]}\n{error_logger,{{2013,2,11},{22,37,49}},crash_report,[[{initial_call,{net_kernel,init,['Argument__1']}},{pid,},{registered_name,[]},{error_info,{exit,{error,badarg},[{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,320}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,227}]}]}},{ancestors,[net_sup,kernel_sup,]},{messages,[]},{links,[]},{dictionary,[{longnames,false}]},{trap_exit,true},{status,running},{heap_size,610},{stack_size,24},{reductions,249}],[]]}\n{error_logger,{{2013,2,11},{22,37,49}},supervisor_report,[{supervisor,{local,net_sup}},{errorContext,start_error},{reason,{'EXIT',nodistribution}},{offender,[{pid,undefined},{name,net_kernel},{mfargs,{net_kernel,start_link,[[rabbitmqprelaunch1593,shortnames]]}},{restart_type,permanent},{shutdown,2000},{child_type,worker}]}]}\n{error_logger,{{2013,2,11},{22,37,49}},supervisor_report,[{supervisor,{local,kernel_sup}},{errorContext,start_error},{reason,shutdown},{offender,[{pid,undefined},{name,net_sup},{mfargs,{erl_distribution,start_link,[]}},{restart_type,permanent},{shutdown,infinity},{child_type,supervisor}]}]}\n{error_logger,{{2013,2,11},{22,37,49}},std_info,[{application,kernel},{exited,{shutdown,{kernel,start,[normal,[]]}}},{type,permanent}]}\n{\"Kernel pid terminated\",application_controller,\"{application_start_failure,kernel,{shutdown,{kernel,start,[normal,[]]}}}\"}\n\nCrash dump was written to: erl_crash.dump\nKernel pid terminated (application_controller) ({application_start_failure,kernel,{shutdown,{kernel,start,[normal,[]]}}})\n```\n\n```text\n127.0.0.1 localhost\n255.255.255.255 broadcasthost\n```\n\n```text\nerl -sname abc\n```\n\n```text\n/etc/hosts\n```\n\n```text\n/etc/hosts\n```\n\n```text\nabc@abc\n```\n\n```text\n[root@nyc123]$ rabbitmq-server start</p>\n\n\n RabbitMQ 3.6.0. Copyright (C) 2007-2015 Pivotal Software, Inc.</p>\n## ## Licensed under the MPL. See http://www.rabbitmq.com/</p>\n## ##</p>\n########## Logs: /var/log/rabbitmq/rabbitmq@nyc123.com.log</p>\n###### ## /var/log/rabbitmq/rabbitmq@nyc123.com-sasl.log</p>\n##########</p>\n Starting broker... completed with 6 plugins.</p>\n```\n\n```text\n[wendy@nyc123]$\n```\n\n```text\nlisteners.tcp.default = 5672\n```\n\n========================================\n\nComments:\n- Does using a long name work?\n- you mean instead of `localhost`? nope!\n- How about `erl -name abc@abc`?\n- did u eventually get this working? running into the exact same issue and spent the past hour looking for it. no one else seems to have the same issues.\n- all i have in /etc/hosts is 127.0.0.1\tlocalhost 255.255.255.255\tbroadcasthost\n- This is the correct answer. Since the original poster is on OS X, there needs to be an entry in `/etc/hosts` for `127.0.0.1` that matches the output of `hostname -s`","metadata":{"transformedAt":"2026-08-18T18:33:20.152Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":155,"estimatedTokens":1537}}381{"id":"stack-8902986","source":"stackoverflow","questionId":8902986,"title":"Django Celery: Execute only one instance of a long-running process","tags":["django","concurrency","multiprocessing","rabbitmq","celery"],"text":"Title: Django Celery: Execute only one instance of a long-running process\nTags: django, concurrency, multiprocessing, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI have a long-running process that must run every five minutes, but more than one instance of the processes should never run at the same time. The process should not normally run past five min, but I want to be sure that a second instance does not start up if it runs over. \n\nPer a previous recommendation, I'm using Django Celery to schedule this long-running task. \n\nI don't think a periodic task will work, because if I have a five minute period, I don't want a second task to execute if another instance of the task is running already. \n\nMy current experiment is as follows: at 8:55, an instance of the task starts to run. When the task is finishing up, it will trigger another instance of itself to run at the next five min mark. So if the first task finished at 8:57, the second task would run at 9:00. If the first task happens to run long and finish at 9:01, it would schedule the next instance to run at 9:05. \n\nI've been struggling with a variety of cryptic errors when doing anything more than the simple example below and I haven't found any other examples of people scheduling tasks from a previous instance of itself. I'm wondering if there is maybe a better approach to doing what I am trying to do. I know there's a way to name one's tasks; perhaps there's a way to search for running or scheduled instances with the same name? Does anyone have any advice to offer regarding running a task every five min, but ensuring that only one task runs at a time? \n\nThank you,\nJoe\n\n**In mymodule/tasks.py:**\n\n```\nimport datetime\nfrom celery.decorators import task \n\n@task \ndef test(run_periodically, frequency):\n\n run_long_process()\n now = datetime.datetime.now()\n # Run this task every x minutes, where x is an integer specified by frequency\n eta = (\n now - datetime.timedelta(\n minutes = now.minute % frequency , seconds = now.second, \n microseconds = now.microsecond ) ) + datetime.timedelta(minutes=frequency) \n task = test.apply_async(args=[run_periodically, frequency,], eta=eta)\n```\n\n**From a ./manage.py shell:**\n\n```\nfrom mymodule import tasks\nresult = tasks.test.apply_async(args=[True, 5])\n```\n\n========================================\n\nTop Answer:\nI personally solve this issue by caching a flag by a key like `task.name + args`\n\n```\ndef perevent_run_duplicate(func):\n \"\"\"\n this decorator set a flag to cache for a task with specifig args\n and wait to completion, if during this task received another call\n with same cache key will ignore to avoid of conflicts.\n and then after task finished will delete the key from cache\n\n - cache keys with a day of timeout\n\n \"\"\"\n\n @wraps(func)\n def outer(self, *args, **kwargs):\n if cache.get(f\"running_task_{self.name}_{args}\", False):\n return\n else:\n cache.set(f\"running_task_{self.name}_{args}\", True, 24 * 60 * 60)\n try:\n func(self, *args, **kwargs)\n finally:\n cache.delete(f\"running_task_{self.name}_{args}\")\n\n return outer\n```\n\nthis decorator will manage task calls to prevent duplicate calls for a task by same args.\n\n========================================\n\nCode:\n```text\nimport datetime\nfrom celery.decorators import task \n\n@task \ndef test(run_periodically, frequency):\n\n run_long_process()\n now = datetime.datetime.now()\n # Run this task every x minutes, where x is an integer specified by frequency\n eta = (\n now - datetime.timedelta(\n minutes = now.minute % frequency , seconds = now.second, \n microseconds = now.microsecond ) ) + datetime.timedelta(minutes=frequency) \n task = test.apply_async(args=[run_periodically, frequency,], eta=eta)\n```\n\n```text\nfrom mymodule import tasks\nresult = tasks.test.apply_async(args=[True, 5])\n```\n\n```text\ndef perevent_run_duplicate(func):\n \"\"\"\n this decorator set a flag to cache for a task with specifig args\n and wait to completion, if during this task received another call\n with same cache key will ignore to avoid of conflicts.\n and then after task finished will delete the key from cache\n\n - cache keys with a day of timeout\n\n \"\"\"\n\n @wraps(func)\n def outer(self, *args, **kwargs):\n if cache.get(f\"running_task_{self.name}_{args}\", False):\n return\n else:\n cache.set(f\"running_task_{self.name}_{args}\", True, 24 * 60 * 60)\n try:\n func(self, *args, **kwargs)\n finally:\n cache.delete(f\"running_task_{self.name}_{args}\")\n\n return outer\n```\n\n```text\ntask.name + args\n```\n\n========================================\n\nComments:\n- Thanks 0x00mh. That's a neat link. I'm giving it a try.","metadata":{"transformedAt":"2026-08-18T18:33:20.152Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":136,"estimatedTokens":1179}}382{"id":"stack-15342340","source":"stackoverflow","questionId":15342340,"title":"Trouble with RabbitMQ fanout exchange","tags":["rabbitmq","messaging","amqp","rabbitmq-exchange"],"text":"Title: Trouble with RabbitMQ fanout exchange\nTags: rabbitmq, messaging, amqp, rabbitmq-exchange\nSource: Stack Overflow\n\nQuestion:\nI am able to create a fanout exchange using the Publish/Subscribe RabbitMQ Java tutorial, and any connected consumer will receive a copy of a message. Instead of declaring an exchange and binding dynamically/programmatically, I would like to create the exchange and the binding prior to connecting any consumers. I have done this through the RabbitMQ Management Console. For some reason, however, my consumers are receiving messages in a round-robin fashion, rather than all receiving copies of the message. What am I missing? Here are some code snippets:\n\nPublisher:\n\n```\nchannel.basicPublish(\"public\", \"\", null, rowId.getBytes(\"UTF-8\"));\n```\n\nConsumer:\n\n```\nQueueingConsumer consumer = new QueueingConsumer(channel);\n channel.basicConsume(\"myqueue\", false, consumer);\n```\n\n...And in the RabbitMQ Management console, I created an exchange \"public\" of type \"fanout\", and I set a binding from that exchange to \"myqueue\".\n\nI'd appreciate any help!\n\n========================================\n\nTop Answer:\nYou should Create new Queue for Each of Consumers manually or Create Randomly\nnon durable Queue with this command.\n\nvar queueName = channel.QueueDeclare().QueueName;\n\neach consumer consumes from related Queue name and Receives all of The messages\n\n========================================\n\nCode:\n```text\nchannel.basicPublish(\"public\", \"\", null, rowId.getBytes(\"UTF-8\"));\n```\n\n```text\nQueueingConsumer consumer = new QueueingConsumer(channel);\n channel.basicConsume(\"myqueue\", false, consumer);\n```\n\n========================================\n\nComments:\n- This answer was very helpful to me, thank you! I kept thinking that each bound consumer will receive a copy of the message, rather than each bound queue. This fixed my problem. Thanks again!\n- I failed to find this explanation in the documentation. They told me to use a temporary queue name but not why. I thought I'd just use a named \"global_messages\" queue for everyone, why not? And then it didn't work. Setting the exchange to fanout was just half the piece of the pussle. This was the key information that was missing. Thank you!","metadata":{"transformedAt":"2026-08-18T18:33:20.152Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":51,"estimatedTokens":558}}383{"id":"stack-22797961","source":"stackoverflow","questionId":22797961,"title":"Is it appropriate to use message queues for synchronous rpc calls via ajax","tags":["rabbitmq","soa","rpc"],"text":"Title: Is it appropriate to use message queues for synchronous rpc calls via ajax\nTags: rabbitmq, soa, rpc\nSource: Stack Overflow\n\nQuestion:\nI have a web application that uses the jquery autocomplete plugin, which essentially sends via ajax a request containing text that has been typed into a textbox to our web server, once the web server receives this request, it is then handed off to rabbitmq. \n\nI know that we do get benefits from using messaging, but it seems like using it for blocking rpc calls is a misuse and that something like WCF is far more appropriate in this instance, is this the case or is it considered acceptable architecture?\n\n========================================\n\nTop Answer:\nWhat benefit would you get from it? And in fairness if you put the message in the queue how is is synchronous? unless the same process that placed the message in the queue is the one removing it, but that is pretty much useless no?\n\nNow, if all you want to do is place the message in the queue and process it later on is grand.\nAlso the fact that you had WCF to the mixture is IMHO a symptom that something is perhaps not clear enough. You could use WCF as an API gateway and use it to write the message to the queue so this is not really about WCF or Queues, but more like sync vs async.\n\nThe way you are putting your ideas, does not look alright to me.\n\n========================================\n\nComments:\n- Obviously it depends from your application, You can use the queue for the RPC calls,but I think it’s not its natural uses. In order to help you I have two questions: 1.Why do you use synchronous calls? 2.Do you have some problem with your current application? Anyway,I don’t know in which language you are developing the application but I think you could use the async-calls with RabbitMQ and use some technologies like Spring DeferredResult to get the results from your queue. I don’t like so much the synchronous calls, because you block the thread (for example during your DB search) uselessly.\n- 1. we have synchronous calls for the autocomplete plugin, you have to have to have a response for the request 2. no issue other than I think it's a misuse of messaging in this instance and I want to change it, and I am looking for evidence to support this change.\n- sometimes you have have to have to get a response from a message, for the autocomplete, if you didn't get a response it would be useless. I would prefer to remove synchronous calls from messaging and am looking for evidence to support/contradict this\n- In asycn calls you get a response, but not the way you think. As an example, if you use CQRS with REST, when you submit an instruction such as: AddUserCommand, you only get HTTP codes such as 200, 401, 406.. nothing else, even if the message is processed sync. You need to use another API layer to retrieve the command status. That same layers (read models) is the same proving the data for your drop downs. One thing is for sure, if you want sync processing, remove the queues from your architecture.\n- yeah it's the latency that to me that is the deal breaker, you can't really have an autocomplete that is slow\n- o well... latency here is measured in terms of millis. Faster is better, but that's not the only parameter to keep into account. The only thing that let me think, is that autocomplete should be implemented async. Interestingly, I have come across this so post - maybe it can be useful: I have never used autocomplete at now, I leave it to you.","metadata":{"transformedAt":"2026-08-18T18:33:20.152Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":28,"estimatedTokens":873}}384{"id":"stack-53995130","source":"stackoverflow","questionId":53995130,"title":"NestJS - Combine HTTP with RabbitMQ in microservices","tags":["node.js","events","rabbitmq","microservices","nestjs"],"text":"Title: NestJS - Combine HTTP with RabbitMQ in microservices\nTags: node.js, events, rabbitmq, microservices, nestjs\nSource: Stack Overflow\n\nQuestion:\nI have a few microservices, which are exposed through an API-Gateway. The gateway takes care of handling authentication and routing into the system. The services behind the gateway are mostly simple CRUD-Services. Each service exposes its own API and they communicate synchronously via HTTP. All of these services, including the API-Gateway, are \"default\" NestJS applications.\n\nLet's stick with the Cats example. Whenever the `Cat-Service` updates or creates a new `Cat`, I want an `CatCreatedEvent` or `CatUpdatedEvent` to be emmited. The event should be pushed into some message broker like RabbitMQ and another service should listen to this event and process the event asynchronously.\n\nI am not sure how to achive this, in terms of how to \"inject\" RabbitMQ the right way and I am wondering if this approach makes sense in generel. I have seen the CQRS Module for NestJS, but i think CQRS is a bit too much for this domain. Especially because there is no benefit in this domain to split read- and write-models. Maybe I am totally on the wrong track, so I hope you can give me some advises.\n\n========================================\n\nTop Answer:\nNote startAllMicroservicesAsync is depricated****\n\n```\nimport { Transport, MicroserviceOptions } from '@nestjs/microservices';\n const app = await NestFactory.create(AppModule);\n app.connectMicroservice({\n transport: Transport.TCP,\n options: { retryAttempts: 5, retryDelay: 3000 },\n });\n \n await app.startAllMicroservices();\n await app.listen(3001);\n console.log(`Application is running on: ${await app.getUrl()}`);\n```\n\n========================================\n\nCode:\n```text\nCat-Service\n```\n\n```text\nCat\n```\n\n```text\nCatCreatedEvent\n```\n\n```text\nCatUpdatedEvent\n```\n\n```text\n// Create your regular nest application.\nconst app = await NestFactory.create(ApplicationModule);\n\n// Then combine it with a RabbitMQ microservice\nconst microservice = app.connectMicroservice({\n transport: Transport.RMQ,\n options: {\n urls: [`amqp://localhost:5672`],\n queue: 'my_queue',\n queueOptions: { durable: false },\n },\n});\n\nawait app.startAllMicroservices();\nawait app.listen(3001);\n```\n\n```text\nimport { Transport, MicroserviceOptions } from '@nestjs/microservices';\n const app = await NestFactory.create(AppModule);\n app.connectMicroservice<MicroserviceOptions>({\n transport: Transport.TCP,\n options: { retryAttempts: 5, retryDelay: 3000 },\n });\n \n await app.startAllMicroservices();\n await app.listen(3001);\n console.log(`Application is running on: ${await app.getUrl()}`);\n```\n\n========================================\n\nComments:\n- Thank you! After a bit of trying, I got this working. In the `CatService` I added this, which is called by the `CatController` after a POST request to `/cats` `emitCatCreatedEvent() { return this.client.send({ name: 'catCreatedEvent'}, 'something happend').toPromise(); }` Would you say this approch goes in the right direction?\n- Yes, looks good. :-) It's a bit tricky to understand how to use `this.client`.\n- @user2534584 can you please your example?\n- Yes, and obiviously the emitCatCreatedEvent() call should always be the last thing done on the happy path, since signals that the \"cat creation\" is actually happened. Maybe it could be better if the event signalling is done on a controller level, since it looks like more application logic than business logic. Am I wrong?\n- @user2534584 in your post above, where does `this.client` come from? Is that a standard NestJS service? A node driver for RabbitMQ?\n- nvm; I think it is a `ClientProxy` from docs.nestjs.com/microservices/basics#client","metadata":{"transformedAt":"2026-08-18T18:33:20.152Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":88,"estimatedTokens":961}}385{"id":"stack-40807355","source":"stackoverflow","questionId":40807355,"title":"Scheduled messages with RabbitMQ","tags":["rabbitmq","message-queue","microservices"],"text":"Title: Scheduled messages with RabbitMQ\nTags: rabbitmq, message-queue, microservices\nSource: Stack Overflow\n\nQuestion:\nI'm looking for a solution to have scheduled messages with RabbitMQ, so not only delaying the messages as described in several sources but schedule it to have a message e.g. every day.\n\nIf not RabbitMQ, any other solutions out there you can think of and you'd suggest for a microservices environment using a message-bus?\nSo it's really about combining the concept of a task-scheduler and a message bus ...\n\nOr is it better to use a job scheduler just to push messages to the message queue, e.g. using rundeck in combination with RabbitMQ?\n\n========================================\n\nTop Answer:\nYou may try ActiveMQ, It supports crontab schedule, and it provides a web console to setup the schedule too. If you want to schedule from code, it may looks like:\n\n```\nMessageProducer producer = session.createProducer(destination);\nTextMessage message = session.createTextMessage(\"test msg\");\nmessage.setStringProperty(ScheduledMessage.AMQ_SCHEDULED_CRON, \"0 * * * *\");\nproducer.send(message);\n```\n\n========================================\n\nCode:\n```text\nMessageProducer producer = session.createProducer(destination);\nTextMessage message = session.createTextMessage(\"test msg\");\nmessage.setStringProperty(ScheduledMessage.AMQ_SCHEDULED_CRON, \"0 * * * *\");\nproducer.send(message);\n```\n\n========================================\n\nComments:\n- How about a simple cron ? Maybe you could have a microservices that is used as a message scheduler, and would simply interact with cron?\n- Did you look at using NServiceBus?\n- BTW, I ended up using a combination of a cron based scheduler and also having github.com/rabbitmq/rabbitmq-delayed-message-exchange in place ...\n- I found this link interesting. The solution is to create a delayed exchange in RabbitMQ and after the delay the message is send to the queue. It's not native in RabbitMQ though but it's a plugin.\n- if you googled here you are probably searching for this: `rabbitmqadmin -u $user -p $password publish routing_key=$queue_name payload=$payload`.\n- Thx, I went with this approach so far; it's a bit more setup work, but so far I am pretty happy about having a scheduler and RabbitMQ separated in two different services. Seems definitely to pay off.","metadata":{"transformedAt":"2026-08-18T18:33:20.152Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":43,"estimatedTokens":580}}386{"id":"stack-43799932","source":"stackoverflow","questionId":43799932,"title":"rabbitmq list queues on all vhosts","tags":["rabbitmq","rabbitmqctl"],"text":"Title: rabbitmq list queues on all vhosts\nTags: rabbitmq, rabbitmqctl\nSource: Stack Overflow\n\nQuestion:\nI've got rabbitmq with couple virtual hosts, there is few queues on each.\nHow can I list all queues from all vhosts using rabbitmqctl?\nI've tried:\n\n```\nrabbitmqctl list_queues -p /*\nrabbitmqctl list_queues -p *\nrabbitmqctl list_queues -p /\nrabbitmqctl list_queues -p ./*\n```\n\nAny ideas?\n\n========================================\n\nTop Answer:\nYou can use `for i in $(rabbitmqctl list_vhosts); do echo vhost: $i && rabbitmqctl list_queues -p $i; done` to just run from the command line\n\n========================================\n\nCode:\n```text\nrabbitmqctl list_queues -p /*\nrabbitmqctl list_queues -p *\nrabbitmqctl list_queues -p /\nrabbitmqctl list_queues -p ./*\n```\n\n```text\n#!/bin/bash\nIFS=$'\\n'\nordered_vhosts=$(./rabbitmqctl list_vhosts -q | xargs -n1 | sort -u)\n\nfor V in $ordered_vhosts; do\n echo \"*****Vhost $V Total queues \" $(./rabbitmqctl list_queues -q -p $V | wc -l)\n for Q in $(./rabbitmqctl list_queues -q name messages -p $V | xargs -n2 | sort -u); do\n echo \"Vhost $V queue-name total-messages $Q\"\n done\ndone\n```\n\n```text\nfor i in $(rabbitmqctl list_vhosts); do echo vhost: $i && rabbitmqctl list_queues -p $i; done\n```\n\n```text\nrabbitmqctl list_vhosts | xargs -n1 rabbitmqctl list_queues -p\n```\n\n========================================\n\nComments:\n- With a few modifications this works beautifully! Thank you!\n- I would suggest an option with few modifications, since the code above doesn't work as is: ``` #!/bin/bash IFS=$'\\n' ordered_vhosts=$(rabbitmqctl list_vhosts -q | xargs -n1 | sort -u) for V in $ordered_vhosts; do echo \"*****Vhost $V Total queues \" $(rabbitmqctl list_queues -q -p $V | wc -l) for Q in $(rabbitmqctl list_queues -q name messages -p $V | xargs -n2 | sort -u); do echo \"Vhost $V queue-name total-messages $Q\" done done ```\n- You need to add the `--quiet` option otherwise you will run the function on non-existing vhosts for each word in the verbose output in the command.","metadata":{"transformedAt":"2026-08-18T18:33:20.152Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":60,"estimatedTokens":508}}387{"id":"stack-13049829","source":"stackoverflow","questionId":13049829,"title":"How can I view the enqueued tasks in RabbitMQ?","tags":["python","rabbitmq","celery"],"text":"Title: How can I view the enqueued tasks in RabbitMQ?\nTags: python, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI'm using RabbitMQ as my message broker and my workers are Celery tasks. I'm trying to diagnose an issue where I'm enqueue tasks to RabbitMQ but Celery doesn't pick then up.\n\nIs there a way I can check what tasks are enqueued in RabbitMQ? I'd like to see the date and time when they are enqueued, any ETA is specified, the arguments and the task name.\n\nI haven't been able to find this information in the docs — maybe I've overlooked it — and was hoping that some of you might know an easy way to inspect the task queue. Thanks.\n\n========================================\n\nTop Answer:\nAlso some celery tasks to monitor the queue: \n\nhttp://docs.celeryproject.org/en/latest/userguide/monitoring.html\n\nCheck out these commands:\n\n```\n#shows status of all worker nodes\ncelery status\n#List active tasks\ncelery inspect active\n#Show worker statistics (call counts etc.)\ncelery inspect stats\n```\n\n========================================\n\nCode:\n```text\nrabbitmqctl list_queues\n```\n\n```text\n#shows status of all worker nodes\ncelery status\n#List active tasks\ncelery inspect active\n#Show worker statistics (call counts etc.)\ncelery inspect stats\n```\n\n```text\nrabbitmqadmin get queue=queue_name requeue=true count=100\n```\n\n```text\ncelery inspect reserved\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.152Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":52,"estimatedTokens":341}}388{"id":"stack-39443850","source":"stackoverflow","questionId":39443850,"title":"Spring AMQP - Sender and Receiving Messages","tags":["rabbitmq","spring-amqp","spring-rabbit"],"text":"Title: Spring AMQP - Sender and Receiving Messages\nTags: rabbitmq, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI am facing an issue in receiving a message from RabbitMQ.\nI am sending a message like below\n\n```\nHashMap senderMap=new HashMap<>();\n senderMap.put(\"STATUS\", \"SUCCESS\");\n senderMap.put(\"EXECUTION_START_TIME\", new Date());\n\n rabbitTemplate.convertAndSend(Constants.ADAPTOR_OP_QUEUE,senderMap);\n```\n\nIf we see in RabbitMQ, we will get a fully qualified type.\n\nIn the current scenario, we have n number of producer for the same consumer. If i use any mapper, it leads to an exception.\nHow will i send a message so that it doesn't contain any type_id and i can receive the message as Message object and later i can bind it to my custom object in the receiver.\n\nI am receiving message like below.\nCould you please let me know how to use **Jackson2MessageConverter** so that message will get directly binds to my Object/HashMap from Receiver end. Also i have removed the Type_ID now from the sender.\n\nHow Message looks in RabbitMQ\n\n priority: 0 delivery_mode: 2 headers:\n\n **ContentTypeId**: java.lang.Object\n **KeyTypeId**: java.lang.Object content_encoding: UTF-8 content_type: application/json\n {\"Execution_start_time\":1473747183636,\"status\":\"SUCCESS\"}\n\n```\n@Component\npublic class AdapterOutputHandler {\n\n private static Logger logger = Logger.getLogger(AdapterOutputHandler.class);\n\n @RabbitListener(containerFactory=\"adapterOPListenerContainerFactory\",queues=Constants.ADAPTOR_OP_QUEUE)\n public void handleAdapterQueueMessage(HashMap message){\n\n System.out.println(\"Receiver:::::::::::\"+message.toString());\n\n }\n\n}\n```\n\nConnection \n\n```\n@Bean(name=\"adapterOPListenerContainerFactory\")\n public SimpleRabbitListenerContainerFactory adapterOPListenerContainerFactory() {\n SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();\n factory.setConnectionFactory(connectionFactory());\n Jackson2JsonMessageConverter messageConverter = new Jackson2JsonMessageConverter();\n DefaultClassMapper classMapper = new DefaultClassMapper();\n messageConverter.setClassMapper(classMapper);\n factory.setMessageConverter(messageConverter);\n\n }\n```\n\nException\n\n```\nCaused by: org.springframework.amqp.support.converter.MessageConversionException: failed to convert Message content. Could not resolve __TypeId__ in header and no defaultType provided\n at org.springframework.amqp.support.converter.DefaultClassMapper.toClass(DefaultClassMapper.java:139)\n```\n\n**I don't want to use __TYPE__ID from sender because they are multiple senders for the same queue and only one consumer.**\n\n========================================\n\nTop Answer:\nWant to use \"a\" different Java calss when receive message?\n\nConfig @Bean Jackson2JsonMessageConverter with a custom ClassMapper\n\nWant to use \"many\" different Java calss when receive message? such as :\n\n```\n@MyAmqpMsgListener\nvoid handlerMsg(\n // Main message class, by MessageConverter\n @Payload MyMsg myMsg, \n\n // Secondary message class - by MessageConverter->ConversionService\n @Payload Map map,\n\n org.springframework.messaging.Message msg,\n org.springframework.amqp.core.Message amqpMsg\n) {\n // ...\n}\n```\n\nProvide a custom @Bean `Converter`, `ConversionService`, `RabbitListenerAnnotationBeanPostProcessor` :\n\n```\n@Bean\nFormattingConversionServiceFactoryBean rabbitMqCs(\n Set converters\n) {\n FormattingConversionServiceFactoryBean fac = new FormattingConversionServiceFactoryBean();\n fac.setConverters(converters);\n return fac;\n}\n@Bean\nDefaultMessageHandlerMethodFactory messageHandlerMethodFactory(\n @Qualifier(\"rabbitMqCs\")\n FormattingConversionService rabbitMqCs\n) {\n DefaultMessageHandlerMethodFactory defaultFactory = new DefaultMessageHandlerMethodFactory();\n defaultFactory.setConversionService(rabbitMqCs);\n return defaultFactory;\n}\n\n// copied from RabbitBootstrapConfiguration\n@Bean(name = RabbitListenerConfigUtils.RABBIT_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)\n@Role(BeanDefinition.ROLE_INFRASTRUCTURE)\npublic RabbitListenerAnnotationBeanPostProcessor rabbitListenerAnnotationProcessor(\n MessageHandlerMethodFactory handlerFac\n) {\n RabbitListenerAnnotationBeanPostProcessor bpp = new RabbitListenerAnnotationBeanPostProcessor();\n bpp.setMessageHandlerMethodFactory(handlerFac);\n return bpp;\n}\n\n@Bean(name = RabbitListenerConfigUtils.RABBIT_LISTENER_ENDPOINT_REGISTRY_BEAN_NAME)\npublic RabbitListenerEndpointRegistry defaultRabbitListenerEndpointRegistry() {\n return new RabbitListenerEndpointRegistry();\n}\n```\n\nReferences:\n\n- Jackson2JsonMessageConverter\n\n- AMQP-461\n\n- Debugging source code PayloadArgumentResolver\n\n========================================\n\nCode:\n```text\nHashMap<Object, Object> senderMap=new HashMap<>();\n senderMap.put(\"STATUS\", \"SUCCESS\");\n senderMap.put(\"EXECUTION_START_TIME\", new Date());\n\n rabbitTemplate.convertAndSend(Constants.ADAPTOR_OP_QUEUE,senderMap);\n```\n\n```text\n@Component\npublic class AdapterOutputHandler {\n\n private static Logger logger = Logger.getLogger(AdapterOutputHandler.class);\n\n @RabbitListener(containerFactory=\"adapterOPListenerContainerFactory\",queues=Constants.ADAPTOR_OP_QUEUE)\n public void handleAdapterQueueMessage(HashMap<String,Object> message){\n\n System.out.println(\"Receiver:::::::::::\"+message.toString());\n\n }\n\n}\n```\n\n```text\n@Bean(name=\"adapterOPListenerContainerFactory\")\n public SimpleRabbitListenerContainerFactory adapterOPListenerContainerFactory() {\n SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();\n factory.setConnectionFactory(connectionFactory());\n Jackson2JsonMessageConverter messageConverter = new Jackson2JsonMessageConverter();\n DefaultClassMapper classMapper = new DefaultClassMapper();\n messageConverter.setClassMapper(classMapper);\n factory.setMessageConverter(messageConverter);\n\n }\n```\n\n```text\nCaused by: org.springframework.amqp.support.converter.MessageConversionException: failed to convert Message content. Could not resolve __TypeId__ in header and no defaultType provided\n at org.springframework.amqp.support.converter.DefaultClassMapper.toClass(DefaultClassMapper.java:139)\n```\n\n```text\nrabbitTemplate.convertAndSend(Constants.INPUT_QUEUE, dto, m -> {\n m.getMessageProperties.getHeaders().remove(\"__TypeId__\");\n return m;\n});\n```\n\n```text\npackage com.example;\n\nimport java.util.HashMap;\nimport java.util.concurrent.CountDownLatch;\nimport java.util.concurrent.TimeUnit;\n\nimport org.springframework.amqp.core.Queue;\nimport org.springframework.amqp.rabbit.annotation.RabbitListener;\nimport org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;\nimport org.springframework.amqp.rabbit.connection.ConnectionFactory;\nimport org.springframework.amqp.rabbit.core.RabbitAdmin;\nimport org.springframework.amqp.rabbit.core.RabbitTemplate;\nimport org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\nimport org.springframework.context.ConfigurableApplicationContext;\nimport org.springframework.context.annotation.Bean;\n\n@SpringBootApplication\npublic class So39443850Application {\n\n private static final String QUEUE = \"so39443850\";\n\n public static void main(String[] args) throws Exception {\n ConfigurableApplicationContext context = SpringApplication.run(So39443850Application.class, args);\n context.getBean(RabbitTemplate.class).convertAndSend(QUEUE, new DTO(\"baz\", \"qux\"));\n context.getBean(So39443850Application.class).latch.await(10, TimeUnit.SECONDS);\n context.getBean(RabbitAdmin.class).deleteQueue(QUEUE);\n context.close();\n }\n\n private final CountDownLatch latch = new CountDownLatch(1);\n\n @RabbitListener(queues = QUEUE, containerFactory = \"adapterOPListenerContainerFactory\")\n public void listen(HashMap<String, Object> message) {\n System.out.println(message.getClass() + \":\" + message);\n latch.countDown();\n }\n\n @Bean\n public Queue queue() {\n return new Queue(QUEUE);\n }\n\n @Bean\n public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {\n RabbitTemplate template = new RabbitTemplate(connectionFactory);\n template.setMessageConverter(new Jackson2JsonMessageConverter());\n return template;\n }\n\n @Bean\n public SimpleRabbitListenerContainerFactory adapterOPListenerContainerFactory(ConnectionFactory connectionFactory) {\n SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();\n factory.setConnectionFactory(connectionFactory);\n factory.setMessageConverter(new Jackson2JsonMessageConverter());\n return factory;\n }\n\n public static class DTO {\n\n private String foo;\n\n private String baz;\n\n public DTO(String foo, String baz) {\n this.foo = foo;\n this.baz = baz;\n }\n\n public String getFoo() {\n return this.foo;\n }\n\n public void setFoo(String foo) {\n this.foo = foo;\n }\n\n public String getBaz() {\n return this.baz;\n }\n\n public void setBaz(String baz) {\n this.baz = baz;\n }\n\n }\n\n}\n```\n\n```text\nclass java.util.HashMap:{foo=baz, baz=qux}\n```\n\n```text\n, new MessagePostProcessor() {...}\n```\n\n```text\n__TypeId__\n```\n\n```text\nClassMapper\n```\n\n```text\nHashMap\n```\n\n```text\n@MyAmqpMsgListener\nvoid handlerMsg(\n // Main message class, by MessageConverter\n @Payload MyMsg myMsg, \n\n // Secondary message class - by MessageConverter->ConversionService\n @Payload Map<String, String> map,\n\n org.springframework.messaging.Message<MyMsg> msg,\n org.springframework.amqp.core.Message amqpMsg\n) {\n // ...\n}\n```\n\n```text\n@Bean\nFormattingConversionServiceFactoryBean rabbitMqCs(\n Set<Converter> converters\n) {\n FormattingConversionServiceFactoryBean fac = new FormattingConversionServiceFactoryBean();\n fac.setConverters(converters);\n return fac;\n}\n@Bean\nDefaultMessageHandlerMethodFactory messageHandlerMethodFactory(\n @Qualifier(\"rabbitMqCs\")\n FormattingConversionService rabbitMqCs\n) {\n DefaultMessageHandlerMethodFactory defaultFactory = new DefaultMessageHandlerMethodFactory();\n defaultFactory.setConversionService(rabbitMqCs);\n return defaultFactory;\n}\n\n// copied from RabbitBootstrapConfiguration\n@Bean(name = RabbitListenerConfigUtils.RABBIT_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)\n@Role(BeanDefinition.ROLE_INFRASTRUCTURE)\npublic RabbitListenerAnnotationBeanPostProcessor rabbitListenerAnnotationProcessor(\n MessageHandlerMethodFactory handlerFac\n) {\n RabbitListenerAnnotationBeanPostProcessor bpp = new RabbitListenerAnnotationBeanPostProcessor();\n bpp.setMessageHandlerMethodFactory(handlerFac);\n return bpp;\n}\n\n@Bean(name = RabbitListenerConfigUtils.RABBIT_LISTENER_ENDPOINT_REGISTRY_BEAN_NAME)\npublic RabbitListenerEndpointRegistry defaultRabbitListenerEndpointRegistry() {\n return new RabbitListenerEndpointRegistry();\n}\n```\n\n```text\nConverter\n```\n\n```text\nConversionService\n```\n\n```text\nRabbitListenerAnnotationBeanPostProcessor\n```\n\n========================================\n\nComments:\n- *it leads to an exception* is not enough Informations. Add the stacktrace please\n- Actually headers in rabbitmq contains a property called type_id_. This shouldn't be. **How to send a message in which type_id_ property is not present** `priority:\t0 delivery_mode:\t2 __TypeId__:\tcom.diff.approach.JobListenerDTO** content_encoding:\tUTF-8 content_type:\tapplication/json`\n- Thanks Gary, One more question, How to receive this message ? `headers: __ContentTypeId__:\tjava.lang.Object __KeyTypeId__:\tjava.lang.Object content_encoding:\tUTF-8 content_type:\tapplication/json`\n- I am receiving the message like below `@RabbitListener(containerFactory=\"adapterOPListenerContainer‌​Factory\",queues=Cons‌​tants.ADAPTOR_OP_QUE‌​UE) public void handleAdapterQueueMessage(Message message){ byte[] body = message.getBody(); }` How to convert from byte[] to hashmap back ??\n- Don't put code in comments - it's unreadable - edit your question instead. You need a `Jackson2JsonMessageConverter` in the listener container factory.\n- Hello Gary, I have added my receiver code, could you please suggest how to use `Jackson2JsonMessageConverter`\n- Version of Spring AMQP - `1.6.1.RELEASE` Version of Spring RabbitMQ - `1.5.6.RELEASE`\n- Why are you using mismatched versions? That won't work; they need to be the same version. If you are using maven or gradle, you only need to declare `spring-rabbit` and the corresponding version of `spring-amqp` will be pulled in automatically (transitively). Regardless, you should always use the same versions for both jars; the current version is 1.6.2.RELEASE - see the project page.\n- Yes Gary. I used the same versions for both now. It worked. Thanks!","metadata":{"transformedAt":"2026-08-18T18:33:20.152Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":16,"totalLines":383,"estimatedTokens":3258}}389{"id":"stack-43513681","source":"stackoverflow","questionId":43513681,"title":"RabbitMQ - Get messages from a queue using curl","tags":["linux","curl","rabbitmq"],"text":"Title: RabbitMQ - Get messages from a queue using curl\nTags: linux, curl, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am trying to get a few messages from a queue using the HTTP API of rabbitmq.\n\nI am following the documentation in here\nI have no `vhost` configured.\n\nI tried the following curl command:\n\n```\ncurl -i -u guest:guest -H \"content-type:application/json\" -X POST http://127.0.0.1:15672/api/queues/foo/get -d'{\"count\":5,\"requeue\":true,\"encoding\":\"auto\",\"truncate\":50000}'\n```\n\nRabbitMQ then answers:\n\n```\nHTTP/1.1 405 Method Not Allowed\nvary: origin\nServer: MochiWeb/1.1 WebMachine/1.10.0 (never breaks eye contact)\nDate: Thu, 20 Apr 2017 08:03:28 GMT\nContent-Length: 66\nAllow: HEAD, GET, PUT, DELETE, OPTIONS\n\n{\"error\":\"Method Not Allowed\",\"reason\":\"\\\"Method Not Allowed\\\"\\n\"}\n```\n\nCan you point out my mistake? How can I get these messages?\n\n========================================\n\nTop Answer:\nyou are missing the queue name:\n\n```\ncurl -i -u guest:guest -H \"content-type:application/json\" -X POST http://127.0.0.1:15672/api/queues/foo/my_queue/get -d'{\"count\":5,\"requeue\":true,\"encoding\":\"auto\",\"truncate\":50000}'\n```\n\nwhere `foo` is the virtual host, and `my_queue` is the queue name.\n\nas result:\n\n```\n[\n {\n \"payload_bytes\":4,\n \"redelivered\":true,\n \"exchange\":\"\",\n \"routing_key\":\"my_queue\",\n \"message_count\":5,\n \"properties\":{\n \"delivery_mode\":1,\n \"headers\":{\n\n }\n },\n \"payload\":\"test\",\n \"payload_encoding\":\"string\"\n },\n {\n \"payload_bytes\":4,\n \"redelivered\":true,\n \"exchange\":\"\",\n \"routing_key\":\"my_queue\",\n \"message_count\":4,\n \"properties\":{\n \"delivery_mode\":1,\n \"headers\":{\n\n }\n },\n \"payload\":\"test\",\n \"payload_encoding\":\"string\"\n },\n {\n \"payload_bytes\":4,\n \"redelivered\":true,\n \"exchange\":\"\",\n \"routing_key\":\"my_queue\",\n \"message_count\":3,\n \"properties\":{\n \"delivery_mode\":1,\n \"headers\":{\n\n }\n },\n \"payload\":\"test\",\n \"payload_encoding\":\"string\"\n },\n {\n \"payload_bytes\":4,\n \"redelivered\":true,\n \"exchange\":\"\",\n \"routing_key\":\"my_queue\",\n \"message_count\":2,\n \"properties\":{\n \"delivery_mode\":1,\n \"headers\":{\n\n }\n },\n \"payload\":\"test\",\n \"payload_encoding\":\"string\"\n },\n {\n \"payload_bytes\":4,\n \"redelivered\":true,\n \"exchange\":\"\",\n \"routing_key\":\"my_queue\",\n \"message_count\":1,\n \"properties\":{\n \"delivery_mode\":1,\n \"headers\":{\n\n }\n },\n \"payload\":\"test\",\n \"payload_encoding\":\"string\"\n }\n]\n```\n\n**EDIT**\n\nIn case you are using the default vhost:\n\n```\ncurl -i -u guest:guest -H \"content-type:application/json\" -X POST http://127.0.0.1:15672/api/queues/%2f/my_queue/get -d'{\"count\":5,\"requeue\":true,\"encoding\":\"auto\",\"truncate\":50000}'\n```\n\n========================================\n\nCode:\n```text\ncurl -i -u guest:guest -H \"content-type:application/json\" -X POST http://127.0.0.1:15672/api/queues/foo/get -d'{\"count\":5,\"requeue\":true,\"encoding\":\"auto\",\"truncate\":50000}'\n```\n\n```text\nHTTP/1.1 405 Method Not Allowed\nvary: origin\nServer: MochiWeb/1.1 WebMachine/1.10.0 (never breaks eye contact)\nDate: Thu, 20 Apr 2017 08:03:28 GMT\nContent-Length: 66\nAllow: HEAD, GET, PUT, DELETE, OPTIONS\n\n{\"error\":\"Method Not Allowed\",\"reason\":\"\\\"Method Not Allowed\\\"\\n\"}\n```\n\n```text\nvhost\n```\n\n```text\ncurl -u guest:guest -i -H \"content-type:application/json\" -X POST http://127.0.0.1:15672/api/queues/%2F/foo/get -d'{\"count\":5,\"requeue\":true,\"encoding\":\"auto\",\"truncate\":50000}'\n```\n\n```text\n%2F\n```\n\n```text\ncurl -i -u guest:guest -H \"content-type:application/json\" -X POST http://127.0.0.1:15672/api/queues/foo/my_queue/get -d'{\"count\":5,\"requeue\":true,\"encoding\":\"auto\",\"truncate\":50000}'\n```\n\n```text\n[\n {\n \"payload_bytes\":4,\n \"redelivered\":true,\n \"exchange\":\"\",\n \"routing_key\":\"my_queue\",\n \"message_count\":5,\n \"properties\":{\n \"delivery_mode\":1,\n \"headers\":{\n\n }\n },\n \"payload\":\"test\",\n \"payload_encoding\":\"string\"\n },\n {\n \"payload_bytes\":4,\n \"redelivered\":true,\n \"exchange\":\"\",\n \"routing_key\":\"my_queue\",\n \"message_count\":4,\n \"properties\":{\n \"delivery_mode\":1,\n \"headers\":{\n\n }\n },\n \"payload\":\"test\",\n \"payload_encoding\":\"string\"\n },\n {\n \"payload_bytes\":4,\n \"redelivered\":true,\n \"exchange\":\"\",\n \"routing_key\":\"my_queue\",\n \"message_count\":3,\n \"properties\":{\n \"delivery_mode\":1,\n \"headers\":{\n\n }\n },\n \"payload\":\"test\",\n \"payload_encoding\":\"string\"\n },\n {\n \"payload_bytes\":4,\n \"redelivered\":true,\n \"exchange\":\"\",\n \"routing_key\":\"my_queue\",\n \"message_count\":2,\n \"properties\":{\n \"delivery_mode\":1,\n \"headers\":{\n\n }\n },\n \"payload\":\"test\",\n \"payload_encoding\":\"string\"\n },\n {\n \"payload_bytes\":4,\n \"redelivered\":true,\n \"exchange\":\"\",\n \"routing_key\":\"my_queue\",\n \"message_count\":1,\n \"properties\":{\n \"delivery_mode\":1,\n \"headers\":{\n\n }\n },\n \"payload\":\"test\",\n \"payload_encoding\":\"string\"\n }\n]\n```\n\n```text\ncurl -i -u guest:guest -H \"content-type:application/json\" -X POST http://127.0.0.1:15672/api/queues/%2f/my_queue/get -d'{\"count\":5,\"requeue\":true,\"encoding\":\"auto\",\"truncate\":50000}'\n```\n\n```text\nfoo\n```\n\n```text\nmy_queue\n```\n\n```text\ncurl -u guest:guest -i -H \"content-type:application/json\" -X POST http://127.0.0.1:15672/api/queues/%2F/foo/get -d'{\"count\":5,\"ack_mode\":\"ack_requeue_true\",\"encoding\":\"auto\",\"truncate\":50000}'\n```\n\n```text\nrequeue\n```\n\n```text\nack_mode\n```\n\n```text\n\"ack_mode\":\"ack_requeue_true\"\n```\n\n```text\npip install rabbitgetapi\n```\n\n```text\n$ rabbitgetapi getqueue -f <path/fileconf.yaml> -o <outputfile> -c 1000 -s =\n\nWhere (get dlq messages):\n path/fileconf.yaml = Configuration file (In this example, the server credentials)\n outputfile = File where the message will be saved \n c = Counter\n s = Seperator\n```\n\n```text\nurl: \n https://f-9e14acc7-ef3c-4a2f-a829-c96a7c8c691f.mq.us-east-1.amazonaws.com \n \nuser: \n login-user\n \npassword: \n the-secret-password\n \nqueue: \n DLQ_QUEUE\n \ncount: \n 100\n```\n\n========================================\n\nComments:\n- Can I somehow add the filter ? for example get messages filtering by headers or properties ?\n- Again, No it is not possible, as I said: `you can consume one message at a time in FIFO way` :)!\n- It need to be {\"ackmode\":\"ack_requeue_true\"} not {\"ack_mode\"=\"ack_requeue_true\"}, otherwise you'll get not json error.\n- Little detail: But I'd like to point out that the answer of Akos it says \"ack_mode\" and in Semooze reply it's \"ackmode\" without the underscore, for those that are blind like me. I was getting {\"error\":\"bad_request\",\"reason\":\"[{key_missing,ackmode}]\"} and didn't realize for a while that there's no underscore.\n- provided json has a error, so this is you use -d'{\"count\":5,\"ackmode\":\"ack_requeue_true\",\"requeue\": true,\"encoding\":\"auto\",\"truncate\":50000}'\n- Thanks all, I fixed the JSON (hopefully).","metadata":{"transformedAt":"2026-08-18T18:33:20.152Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":17,"totalLines":314,"estimatedTokens":1715}}390{"id":"stack-9250364","source":"stackoverflow","questionId":9250364,"title":"rabbitmqctl.bat on Windows XP: unable to connect to node rabbit@MYPCNAME: nodedown","tags":["windows","erlang","rabbitmq"],"text":"Title: rabbitmqctl.bat on Windows XP: unable to connect to node rabbit@MYPCNAME: nodedown\nTags: windows, erlang, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have just installed RabbitMQ on my WindowsXP PC. I have fulfilled the Erlang OPC15 prereq as well.\n\nMy rabitmq seems to be working. I did a simple test using pika in python and it seems to work. The service is urnning.\n\nThe problem is that I cannot do anything with rabbitmqctl.bat. I always get the response:\n\n```\nStatus of node rabbit@MYPCNAME ...\nError: unable to connect to node rabbit@MYPCNAME: nodedown\ndiagnostics:\n- nodes and their ports on MYPCNAME: [{rabbit,3097},{rabbitmqctl17251,1132}]\n- current node: rabbitmqctl17251@mypcname\n- current node home dir: C:\\Documents and Settings\\Myuser\n- current node cookie hash: NOTSUREIFTHISISSENSITIVESOREMOVED==\n```\n\nIn my rabbitmq log file I get:\n\n```\n=ERROR REPORT==== 12-Feb-2012::17:01:22 ===\n** Connection attempt from disallowed node rabbitmqctl17251@mypcname **\n```\n\nFrom various forums I deduce this has something to do with cookies. What cookies are we talking about? What do I need to do to be able to manage my RabbitMQ instance using rabbitmqctl.bat? Please word your answer in a way that a non-erlang non-functional programmer would understand.\n\n========================================\n\nTop Answer:\nShortcut command for @Lining answer:\n\n```\ncopy C:\\Windows\\.erlang.cookie %HOMEDRIVE%%HOMEPATH%\\.erlang.cookie\n```\n\n========================================\n\nCode:\n```text\nStatus of node rabbit@MYPCNAME ...\nError: unable to connect to node rabbit@MYPCNAME: nodedown\ndiagnostics:\n- nodes and their ports on MYPCNAME: [{rabbit,3097},{rabbitmqctl17251,1132}]\n- current node: rabbitmqctl17251@mypcname\n- current node home dir: C:\\Documents and Settings\\Myuser\n- current node cookie hash: NOTSUREIFTHISISSENSITIVESOREMOVED==\n```\n\n```text\n=ERROR REPORT==== 12-Feb-2012::17:01:22 ===\n** Connection attempt from disallowed node rabbitmqctl17251@mypcname **\n```\n\n```text\nrabbitmqctl.bat\n```\n\n```text\nrabbitmqctl.bat\n```\n\n```text\n.erlang.cookie\n```\n\n```text\nC:\\WINDOWS\\.erlang.cookie\n```\n\n```text\n.erlang.cookie.\n```\n\n```text\n%HOMEDRIVE%%HOMEPATH%\n```\n\n```text\nC:\\Documents and Settings\\%USERNAME%\\.erlang.cookie\n```\n\n```text\nC:\\Users\\%USERNAME%\\.erlang.cookie\n```\n\n```text\ncopy C:\\Windows\\.erlang.cookie %HOMEDRIVE%%HOMEPATH%\\.erlang.cookie\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.152Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":11,"totalLines":92,"estimatedTokens":589}}391{"id":"stack-11446443","source":"stackoverflow","questionId":11446443,"title":"Queue Size in Spring AMQP Java client","tags":["spring","rabbitmq","spring-amqp"],"text":"Title: Queue Size in Spring AMQP Java client\nTags: spring, rabbitmq, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI am using Spring amqp 1.1 version as my java client. \nI have a queue which has around 2000 messages. I want to have a service which checks this queue size and and if it is empty it will send out a message saying \" All items processed\".\n\nI dont know how to get current queue size ? Please help\n\nI googled and found a class \"RabbitBrokerAdmin\" that was present in earlier version 1.0.\nI think it is not present in 1.1 now. \n\nAny pointers in getting current queue size?\n\n========================================\n\nTop Answer:\nYou can use the RabbitAdmin instance to get the details from the queue, as follows:\n\n```\n@Resource RabbitAdmin admin;\n...\nprotected int getQueueCount(final String name) {\n DeclareOk declareOk = admin.getRabbitTemplate().execute(new ChannelCallback() {\n public DeclareOk doInRabbit(Channel channel) throws Exception {\n return channel.queueDeclarePassive(name);\n }\n });\n return declareOk.getMessageCount();\n}\n```\n\n========================================\n\nCode:\n```text\n<rabbit:queue>\n<rabbit:admin>\n```\n\n```text\npublic class QueueStatsProcessor {\n @Autowired\n private RabbitAdmin admin;\n @Autowired\n private List<Queue> rabbitQueues;\n\n public void getCounts(){\n Properties props;\n Integer messageCount;\n for(Queue queue : rabbitQueues){\n props = admin.getQueueProperties(queue.getName());\n messageCount = Integer.parseInt(props.get(\"QUEUE_MESSAGE_COUNT\").toString());\n System.out.println(queue.getName() + \" has \" + messageCount + \" messages\");\n }\n }\n}\n```\n\n```text\n@Resource RabbitAdmin admin;\n...\nprotected int getQueueCount(final String name) {\n DeclareOk declareOk = admin.getRabbitTemplate().execute(new ChannelCallback<DeclareOk>() {\n public DeclareOk doInRabbit(Channel channel) throws Exception {\n return channel.queueDeclarePassive(name);\n }\n });\n return declareOk.getMessageCount();\n}\n```\n\n========================================\n\nComments:\n- This is the much better answer. Far less hacky.","metadata":{"transformedAt":"2026-08-18T18:33:20.152Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":77,"estimatedTokens":538}}392{"id":"stack-3280676","source":"stackoverflow","questionId":3280676,"title":"Content-based routing with RabbitMQ and Python","tags":["python","routes","rabbitmq","amqp"],"text":"Title: Content-based routing with RabbitMQ and Python\nTags: python, routes, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nIs it possible with RabbitMQ and Python to do content-based routing?\n\nThe AMQP standard and RabbitMQ claims to support content-based routing, but are there any libraries for Python which support specifying content-based bindings etc.?\n\nThe library I am currently using (py-amqplib http://barryp.org/software/py-amqplib/) seems to only support topic-based routing with simple pattern-matching (#, *).\n\n========================================\n\nTop Answer:\nIn RabbitMQ, routing is the process by which an exchange decides which queues to place your message on. You publish all messages to an exchange, but you only receive messages from a queue. This means that the exchange is an active part of the process that makes some decisions about message forwarding or copying.\n\nThe topic exchange included with RabbitMQ looks at a string on the incoming messages (the routing_key) and matches that with the patterns (the binding_keys) supplied by all queues which declare their desire to receive messages from the exchange.\n\nRabbitMQ source code is on the web so you can have a look at the topic exchange code here:\nhttp://hg.rabbitmq.com/rabbitmq-server/file/9b22dde04c9f/src/rabbit_exchange_type_topic.erl\nA lot of the complexity there is to handle a data structure called a trie which allows for very fast lookups. In fact the same data structure is used inside Internet routers.\n\nThe headers exchange found here http://hg.rabbitmq.com/rabbitmq-server/file/9b22dde04c9f/src/rabbit_exchange_type_headers.erl\nis probably easier to understand. As you can see there is not a lot of code required to make a different type of exchange. If you wanted to examine the content (or maybe just peek at the first few bytes of messages, you should be able to quickly identify XML versus JSON versus something else. And if your JSON objects and XML documents maintain a specific sequence of elements then you should be able to distinguish between different JSON objects (or XML doc types) without parsing the entire message body.\n\n========================================\n\nCode:\n```text\nwidth=1024\nheight=768\nmode=bw\nphotographer=John Doe\n```\n\n```text\nmode=bw\n```\n\n```text\nmode=colour\n```\n\n========================================\n\nComments:\n- New links to the source files: github.com/rabbitmq/rabbitmq-server/blob/… and github.com/rabbitmq/rabbitmq-server/blob/…","metadata":{"transformedAt":"2026-08-18T18:33:20.152Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":47,"estimatedTokens":621}}393{"id":"stack-26471231","source":"stackoverflow","questionId":26471231,"title":"Access refused for user rabbitmq & celery","tags":["python","rabbitmq","celery"],"text":"Title: Access refused for user rabbitmq & celery\nTags: python, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI create vhost:\n\n```\nrabbitmqctl add_vhost test\n```\n\nThen user:\n\n```\nrabbitmqctl add_user user 123456\n```\n\nThen I take permissions to that user:\n\n```\nrabbitmqctl set_permissions -p test user \"test\" \"test\" \"test\"\n```\n\nI use Celery, in tasks.py:\n\n```\napp = Celery('tasks', broker='amqp://user:123456@localhost/test', backend='amqp://user:123456@localhost/test')\n```\n\nThen I run:\n\n```\ncelery -A tasks worker --loglevel=info\n```\n\nI have error:\n\n```\namqp.exceptions.AccessRefused: Exchange.declare: (403) ACCESS_REFUSED - access to exchange 'celeryev' in vhost 'test' refused for user 'user'\n```\n\nHow to fix that?\n\n========================================\n\nTop Answer:\nIf you still have error please check that you have correct double quotes (happened to me)\n\n```\n\".*\"\n```\n\ninstead of \n\n```\n“.*”\n```\n\nTo be sure, list permissions from users in your vhostpath (by default /)\n\n```\nrabbitmqctl list_permissions -p /\n```\n\n========================================\n\nCode:\n```text\nrabbitmqctl add_vhost test\n```\n\n```text\nrabbitmqctl add_user user 123456\n```\n\n```text\nrabbitmqctl set_permissions -p test user \"test\" \"test\" \"test\"\n```\n\n```text\napp = Celery('tasks', broker='amqp://user:123456@localhost/test', backend='amqp://user:123456@localhost/test')\n```\n\n```text\ncelery -A tasks worker --loglevel=info\n```\n\n```text\namqp.exceptions.AccessRefused: Exchange.declare: (403) ACCESS_REFUSED - access to exchange 'celeryev' in vhost 'test' refused for user 'user'\n```\n\n```text\n\".*\"\n```\n\n```text\n“.*”\n```\n\n```text\nrabbitmqctl list_permissions -p /\n```\n\n```text\nsudo rabbitmqctl list_permissions -p EDO_DEVELOPING\n*Listing permissions in vhost \"EDO_DEVELOPING\" ...\nbilling “.*” “.*” “.*”\n```\n\n```text\nsudo rabbitmqctl clear_permissions -p EDO_DEVELOPING billing\nClearing permissions for user \"billing\" in vhost \"EDO_DEVELOPING\" ...\n\nsudo rabbitmqctl set_permissions -p EDO_DEVELOPING billing \".*\" \".*\" \".*\"\nSetting permissions for user \"billing\" in vhost \"EDO_DEVELOPING\" ...\n```\n\n```text\nsudo rabbitmqctl list_permissions -p EDO_DEVELOPING \nListing permissions in vhost \"EDO_DEVELOPING\" ...\nbilling .* .* .*\n```\n\n========================================\n\nComments:\n- Thanks. I try with `celeryev` in set_permissions and I have error with exchange `reply.celery.pidbox`, so now I use '.*' and it works. Does it save or I need to use regular expression 'celery'?\n- the regular expression needs to match the name of the queue/exchanges that you plan to create.","metadata":{"transformedAt":"2026-08-18T18:33:20.153Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":128,"estimatedTokens":641}}394{"id":"stack-54094994","source":"stackoverflow","questionId":54094994,"title":"Dynamic addition of queues to a rabbit listener at runtime","tags":["java","rabbitmq","spring-amqp"],"text":"Title: Dynamic addition of queues to a rabbit listener at runtime\nTags: java, rabbitmq, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI've got a project where we are going to have hundreds (potentially thousands) of queues in rabbit and each of these queues will need to be consumed by a pool of consumers.\n\nIn rabbit (using spring-amqp), you have the rabbitlistener annotation which allows me to statically assign the queues this particular consumer(s) will handle.\n\nMy question is - with rabbit and spring, is there a clean way for me to grab a section of queues (lets say queues that start with a-c) and then also listen for any queues that are created while the consumer is running.\n\nExample (at start):\n\n- ant-queue\n\n- apple-queue\n\n- cat-queue\n\nWhile consumer is running:\n\n- Add bat-queue\n\nHere is the (very simple) code I currently have:\n\n```\n@Component\n public class MessageConsumer {\n\n public MessageConsumer() {\n // ideally grab a section of queues here, initialize a parameter and give to the rabbitlistener annotation\n }\n\n @RabbitListener(queues= {\"ant-queue\", \"apple-queue\", \"cat-queue\"})\n public void processQueues(String messageAsJson) {\n \n }\n }\n```\n\nEdit:\n\nI should add - I've gone through the spring amqp documentation I found online and I haven't found anything outside of statically (either hardcoded or via properties) declaring the queues\n\n========================================\n\nCode:\n```text\n@Component\n public class MessageConsumer {\n\n public MessageConsumer() {\n // ideally grab a section of queues here, initialize a parameter and give to the rabbitlistener annotation\n }\n\n @RabbitListener(queues= {\"ant-queue\", \"apple-queue\", \"cat-queue\"})\n public void processQueues(String messageAsJson) {\n < how do I update the queues declared in rabbit listener above ? >\n }\n }\n```\n\n```text\n@Autowired\n```\n\n```text\nRabbitListenerEndpointRegistry\n```\n\n```text\nid\n```\n\n```text\nregistry.getListenerContainer(id)\n```\n\n```text\nAbstractMessageListenerContainer\n```\n\n```text\naddQueues()\n```\n\n```text\naddQueueNames()\n```\n\n```text\nDirectMessageListenerContainer\n```\n\n```text\nSimpleMessageListenerContainer\n```\n\n========================================\n\nComments:\n- \"With the direct container, each queue gets its own consumer(s)\" - music to my ears. Thank you for the info!\n- Gary - my mistake. Is it possible to asynchronously determine queues that exist within a rabbitmq server based on a certain naming convention? In theory, we would need to poll every second to determine which queues exist and create a consumer for it.\n- Don't ask new questions in comments to old answers, it won't help other people when searching for answers; ask a new question instead. There is nothing in the AMQP protocol to do that; RabbitMQ does provide a REST API (and a java binding for it), but I would suggest that polling (especially at that rate) would not be a good idea. Consider adding a consumer for a queue bound to the event exchange instead; you can get `queue.created` events.\n- Thanks Gary - apologies for the question in comment\n- @GaryRussell could you please any example of this. It is exactly what we are looking for, however we want a hybrid approach where some queue names are known in advance and some new queues will be discovered at runtime.\n- It is better to ask a new question showing your config so I can understand how you are using the framework to give you the best answer.\n- Thank you for your quick response @GaryRussell. I have created a new question here: stackoverflow.com/questions/63162812/…\n- @GaryRussell registry.getListenerContainer(id) and adding a queue name to it takes a long time, and I'm adding queue names in the container from another rabbitlistener. Isn't there a faster approach or any other way to make it faster?\n- It's best to ask a new question, with much more information, rather than commenting on a 3 year old answer. That said, using a `DirectMessageListenerContainer` will probably be quite a bit faster; aside from that, I am not aware of any issues.\n- Is there an example of an implementation of this reply?\n- Which reply? Why don't you ask a new question with more clarity; I can then add an answer with an example if needed. The admins here don't like prolonged discussions in comments on old answers.","metadata":{"transformedAt":"2026-08-18T18:33:20.153Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":10,"totalLines":112,"estimatedTokens":1081}}395{"id":"stack-23399604","source":"stackoverflow","questionId":23399604,"title":"RabbitMQ connection through Nginx","tags":["nginx","rabbitmq","amqp"],"text":"Title: RabbitMQ connection through Nginx\nTags: nginx, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI am trying to setup rabbitmq it can be accessed externally (from non-localhost) through nginx.\n\nnginx-rabbitmq.conf:\n\n```\nserver {\n listen 5672;\n server_name x.x.x.x;\n location / {\n proxy_pass http://localhost:55672/;\n }\n}\n```\n\nrabbitmq.conf:\n\n```\n[\n {rabbit,\n [\n {tcp_listeners, [{\"127.0.0.1\", 55672}]}\n ]\n }\n]\n```\n\nBy default guest user can only interact from localhost, so we need to create another user with required permissions, like so:\n\n```\nsudo rabbitmqctl add_user my_user my_password\nsudo rabbitmqctl set_permissions my_user \".*\" \".*\" \".*\"\n```\n\nHowever, when I attempt a connection to rabbitmq through pika I get ConnectionClosed exception\n\n```\nimport pika\ncredentials = pika.credentials.PlainCredentials('my_username', 'my_password')\npika.BlockingConnection(\n pika.ConnectionParameters(host=ip_address, port=55672, credentials=credentials)\n)\n```\n\n--[raises ConnectionClosed exception]--\n\nIf I use the same parameters but change host to localhost and port to 5672 then I connect ok:\n`pika.ConnectionParameters(host=ip_address, port=55672, credentials=credentials)`\n\nI have opened port 5672 on the GCE web console, and communication through nginx is happening: nginx access.log file shows\n\n[30/Apr/2014:22:59:41 +0000] \"AMQP\\x00\\x00\\x09\\x01\" 400 172 \"-\" \"-\" \"-\"\n\nWhich shows a 400 status code response (bad request).\n\nSo by the looks the request fails when going through nginx, but works when we request rabbitmq directly.\n\nHas anyone else had similar problems/got rabbitmq working for external users through nginx? Is there a rabbitmq log file where I can see each request and help further troubleshooting?\n\n========================================\n\nTop Answer:\nSince nginx 1.9 there is stream module for the tcp or udp (not compiled with by default).\n\nI configured my nginx (1.13.3) with ssl stream\n\n```\nstream {\n upstream rabbitmq_backend {\n server rabbitmq.server:5672\n }\n\n server {\n listen 5671 ssl;\n\n ssl_protocols TLSv1.2 TLSv1.1 TLSv1;\n ssl_ciphers RC4:HIGH:!aNULL:!MD5;\n ssl_handshake_timeout 30s;\n\n ssl_certificate /path/to.crt;\n ssl_certificate_key /path/to.key;\n\n proxy_connect_timeout 1s;\n proxy_pass rabbitmq_backend;\n }\n}\n```\n\nhttps://docs.nginx.com/nginx/admin-guide/security-controls/terminating-ssl-tcp/\n\n========================================\n\nCode:\n```text\nserver {\n listen 5672;\n server_name x.x.x.x;\n location / {\n proxy_pass http://localhost:55672/;\n }\n}\n```\n\n```text\n[\n {rabbit,\n [\n {tcp_listeners, [{\"127.0.0.1\", 55672}]}\n ]\n }\n]\n```\n\n```text\nsudo rabbitmqctl add_user my_user my_password\nsudo rabbitmqctl set_permissions my_user \".*\" \".*\" \".*\"\n```\n\n```text\nimport pika\ncredentials = pika.credentials.PlainCredentials('my_username', 'my_password')\npika.BlockingConnection(\n pika.ConnectionParameters(host=ip_address, port=55672, credentials=credentials)\n)\n```\n\n```text\npika.ConnectionParameters(host=ip_address, port=55672, credentials=credentials)\n```\n\n```text\nstream {\n upstream rabbitmq_backend {\n server rabbitmq.server:5672\n }\n\n server {\n listen 5671 ssl;\n\n ssl_protocols TLSv1.2 TLSv1.1 TLSv1;\n ssl_ciphers RC4:HIGH:!aNULL:!MD5;\n ssl_handshake_timeout 30s;\n\n ssl_certificate /path/to.crt;\n ssl_certificate_key /path/to.key;\n\n proxy_connect_timeout 1s;\n proxy_pass rabbitmq_backend;\n }\n}\n```\n\n========================================\n\nComments:\n- thanks. is it possible to configure nginx to use ampq protocol? I tried using proxy_pass ampq://localhost:55672/, but nging complained that url was invalid.\n- See nginx.com. It supports HTTP, POP and IMAP by default. There is a list of 3rd party modules but I do not see any for rabbitmq/amqp.\n- STOMP it is then, thanks. seems like quite an oversight not being able to do AMQP stuff from an external domain via nginx. someone with C skills should make a module :).\n- dont use HTTP with rabbitmq. its limited on message size\n- This is really nice and was able to help me! However, is there a way to include this inside your `sites-enabled` section? (Since normally these files are included in the `http {...}` block of the config, that does not allow `stream {...}`?\n- Works perfectly. I also make some tunning of your configuration gist.github.com/mPanasiewicz/e7ae1c60d13ab34fe57d78f26747f6e‌​6\n- Has anyone tried this with letsencrypt ? I am using my certificates from letsencrypt and getting an UNABLE_TO_VERIFY_LEAF_SIGNATURE error. I can confirm that it is proxying correctly, just not with actual ssl.","metadata":{"transformedAt":"2026-08-18T18:33:20.153Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":166,"estimatedTokens":1164}}396{"id":"stack-13460352","source":"stackoverflow","questionId":13460352,"title":"how to get basicproperties header field in pika python from rabbitmq messages?","tags":["python","rabbitmq","amqp","pika"],"text":"Title: how to get basicproperties header field in pika python from rabbitmq messages?\nTags: python, rabbitmq, amqp, pika\nSource: Stack Overflow\n\nQuestion:\n```\ndef callback(ch, method, properties, body):\n prop = properties\n print prop\n #print prop[1]\n #print prop[“headers”]\n #print prop.headers()\n print body\n```\n\nThis is the list from prop:\n\n```\n\n```\n\nI'm able to print body and the list of basic properties. But how can I just get headers?\n\nAll the #print statements in the function error-ed.\n\n========================================\n\nCode:\n```text\ndef callback(ch, method, properties, body):\n prop = properties\n print prop\n #print prop[1]\n #print prop[“headers”]\n #print prop.headers()\n print body\n```\n\n```text\n<BasicProperties(['delivery_mode=2', \"headers={'BIProto.ClickEvent': 'BIProto.ClickEvent'}\", 'content_type=application/x-protobuf'])>\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.153Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":41,"estimatedTokens":224}}397{"id":"stack-15655189","source":"stackoverflow","questionId":15655189,"title":"I am using Python3 and I want to use RabbitMQ","tags":["python","python-3.x","rabbitmq"],"text":"Title: I am using Python3 and I want to use RabbitMQ\nTags: python, python-3.x, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am using Python3 and I want to use RabbitMQ. I already tried to use Pika, and txAMQP but they do not support Python 3. Have anybody an idea how I can use RabbitMQ.\n\n========================================\n\nTop Answer:\nCheck this page https://github.com/hollobon/pika-python3\nMay be it can help you.\n\n========================================\n\nCode:\n```text\npip install rabbitmq\n```\n\n========================================\n\nComments:\n- This is incorrect, `py-amqplib` *does* support Python 3 according to their Google Code page: *\"Also features [...] Python 3.x compatibility (via 2to3 being invoked automatically by setup.py) [...]\"*\n- For those looking now, pika just got python 3 support: pika.readthedocs.org/en/latest/…\n- Celery is indeed very good, but you will still need to choose an AMQP library.\n- This is now updated to version 0.9.13. It works well for us with Python 3.2.\n- pip install python3-pika works like a charm under Python 3.3.5.","metadata":{"transformedAt":"2026-08-18T18:33:20.153Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":28,"estimatedTokens":271}}398{"id":"stack-24103758","source":"stackoverflow","questionId":24103758,"title":"Why can't I establish connection to rabbitMQ using python?","tags":["python","rabbitmq"],"text":"Title: Why can't I establish connection to rabbitMQ using python?\nTags: python, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm learning how to use rabbitMQ. I'm running the rabbit-MQ server on my MacBook and trying to connect with a python client. I followed the installation instructions **here**. And now I'm performing the tutorial shown **here**.\n\nThe tutorial says to run this client:\n\n```\n#!/usr/bin/env python\nimport pika\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))\nchannel = connection.channel()\n```\n\nHowever, when I do, I get the following error while trying to establish the connection:\n\n```\nWARNING:pika.adapters.base_connection:Connection to ::1:5672 failed: [Errno 61] Connection refused\n```\n\nAs you can see rabbitmq-server seems to be running fine in a different window:\n\n```\n% rabbitmq-server\n\n RabbitMQ 3.3.1. Copyright (C) 2007-2014 GoPivotal, Inc.\n ## ## Licensed under the MPL. See http://www.rabbitmq.com/\n ## ##\n ########## Logs: /usr/local/var/log/rabbitmq/rabbit@localhost.log\n ###### ## /usr/local/var/log/rabbitmq/rabbit@localhost-sasl.log\n ##########\n Starting broker... completed with 10 plugins.\n\n % ps -ef | grep -i rabbit\n 973025343 37253 1 0 2:47AM ?? 0:00.00 /usr/local/Cellar/rabbitmq/3.3.1/erts-5.10.3/bin/../../erts-5.10.3/bin/epmd -daemon\n 973025343 37347 262 0 2:49AM ttys001 0:02.66 /usr/local/Cellar/rabbitmq/3.3.1/erts-5.10.3/bin/../../erts-5.10.3/bin/beam.smp -W w -K true -A30 -P 1048576 -- -root /usr/local/Cellar/rabbitmq/3.3.1/erts-5.10.3/bin/../.. -progname erl -- -home /Users/myUser -- -pa /usr/local/Cellar/rabbitmq/3.3.1/ebin -noshell -noinput -s rabbit boot -sname rabbit@localhost -boot /usr/local/Cellar/rabbitmq/3.3.1/releases/3.3.1/start_sasl -kernel inet_default_connect_options [{nodelay,true}] -rabbit tcp_listeners [{\"127.0.0.1\",5672}] -sasl errlog_type error -sasl sasl_error_logger false -rabbit error_logger {file,\"/usr/local/var/log/rabbitmq/rabbit@localhost.log\"} -rabbit sasl_error_logger {file,\"/usr/local/var/log/rabbitmq/rabbit@localhost-sasl.log\"} -rabbit enabled_plugins_file \"/usr/local/etc/rabbitmq/enabled_plugins\" -rabbit plugins_dir \"/usr/local/Cellar/rabbitmq/3.3.1/plugins\" -rabbit plugins_expand_dir \"/usr/local/var/lib/rabbitmq/mnesia/rabbit@localhost-plugins-expand\" -os_mon start_cpu_sup false -os_mon start_disksup false -os_mon start_memsup false -mnesia dir \"/usr/local/var/lib/rabbitmq/mnesia/rabbit@localhost\" -kernel inet_dist_listen_min 25672 -kernel inet_dist_listen_max 25672\n```\n\nHow can I establish this connection? What is the problem?\n\n========================================\n\nCode:\n```text\n#!/usr/bin/env python\nimport pika\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))\nchannel = connection.channel()\n```\n\n```text\nWARNING:pika.adapters.base_connection:Connection to ::1:5672 failed: [Errno 61] Connection refused\n```\n\n```text\n% rabbitmq-server\n\n RabbitMQ 3.3.1. Copyright (C) 2007-2014 GoPivotal, Inc.\n ## ## Licensed under the MPL. See http://www.rabbitmq.com/\n ## ##\n ########## Logs: /usr/local/var/log/rabbitmq/rabbit@localhost.log\n ###### ## /usr/local/var/log/rabbitmq/rabbit@localhost-sasl.log\n ##########\n Starting broker... completed with 10 plugins.\n\n\n\n % ps -ef | grep -i rabbit\n 973025343 37253 1 0 2:47AM ?? 0:00.00 /usr/local/Cellar/rabbitmq/3.3.1/erts-5.10.3/bin/../../erts-5.10.3/bin/epmd -daemon\n 973025343 37347 262 0 2:49AM ttys001 0:02.66 /usr/local/Cellar/rabbitmq/3.3.1/erts-5.10.3/bin/../../erts-5.10.3/bin/beam.smp -W w -K true -A30 -P 1048576 -- -root /usr/local/Cellar/rabbitmq/3.3.1/erts-5.10.3/bin/../.. -progname erl -- -home /Users/myUser -- -pa /usr/local/Cellar/rabbitmq/3.3.1/ebin -noshell -noinput -s rabbit boot -sname rabbit@localhost -boot /usr/local/Cellar/rabbitmq/3.3.1/releases/3.3.1/start_sasl -kernel inet_default_connect_options [{nodelay,true}] -rabbit tcp_listeners [{\"127.0.0.1\",5672}] -sasl errlog_type error -sasl sasl_error_logger false -rabbit error_logger {file,\"/usr/local/var/log/rabbitmq/rabbit@localhost.log\"} -rabbit sasl_error_logger {file,\"/usr/local/var/log/rabbitmq/rabbit@localhost-sasl.log\"} -rabbit enabled_plugins_file \"/usr/local/etc/rabbitmq/enabled_plugins\" -rabbit plugins_dir \"/usr/local/Cellar/rabbitmq/3.3.1/plugins\" -rabbit plugins_expand_dir \"/usr/local/var/lib/rabbitmq/mnesia/rabbit@localhost-plugins-expand\" -os_mon start_cpu_sup false -os_mon start_disksup false -os_mon start_memsup false -mnesia dir \"/usr/local/var/lib/rabbitmq/mnesia/rabbit@localhost\" -kernel inet_dist_listen_min 25672 -kernel inet_dist_listen_max 25672\n```\n\n```text\nconnection = pika.BlockingConnection(pika.ConnectionParameters('127.0.0.1'))\n```\n\n```text\n::1:5672\n```\n\n```text\n{\"127.0.0.1\",5672}\n```\n\n========================================\n\nComments:\n- Ah! Worked. Thanks! Stupid tutorial leading me wrong!","metadata":{"transformedAt":"2026-08-18T18:33:20.153Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":92,"estimatedTokens":1224}}399{"id":"stack-33930923","source":"stackoverflow","questionId":33930923,"title":"PHP RabbitMQ setTimeout or other option to stop waiting for queue","tags":["php","rabbitmq","wait","amqp","php-amqplib"],"text":"Title: PHP RabbitMQ setTimeout or other option to stop waiting for queue\nTags: php, rabbitmq, wait, amqp, php-amqplib\nSource: Stack Overflow\n\nQuestion:\nI'm required to create a simple queue manager to pass a number from a sender to a consumer. Hello World tutorial provided by RabbitMQ covers almost 70% of it.\n\nBut I need to change the queue to not to forever waiting for incoming messages. Or stop waiting after certain amount of messages. I read and tried few solutions from other post, but it doesn't work.\n\nrabbitmq AMQP::consume() - undefined method. there's another method, wait_frame but it is protected.\n\nand other post is in python which I dont understand.\n\n```\nwait_frame(10);\n // }catch(AMQPConnectionException $e){\n // echo \"asdasd\";\n // }\n\n $channel = $connection->channel();\n\n $channel->queue_declare($queueName, false, false, false, false);\n\n echo ' [*] Waiting for messages. To exit press CTRL+C', \"\\n\";\n\n $callback = function($msg) {\n echo \" [x] Received \", $msg->body, \"\\n\";\n\n };\n\n // $tag = uniqid() . microtime(true);\n // $queue->consume($callback, $flags, $tag);\n\n $channel->basic_consume($queueName, '', false, true, false, false, $callback);\n\n // $channel->cancel($tag);\n\n while(count($channel->callbacks)) {\n $channel->wait();\n }\n\n echo \"\\nfinish\";\n}\n\nrecieveQueue('vtiger');\n\n?>\n```\n\n========================================\n\nTop Answer:\n**wait function** works only with sockets, we have to catch the exception:\n\n```\n$timeout = 5;\n while (count($channel->callbacks)) {\n try{\n $channel->wait(null, false , $timeout);\n }catch(\\PhpAmqpLib\\Exception\\AMQPTimeoutException $e){\n $channel->close();\n $connection->close();\n exit;\n }\n }\n```\n\n========================================\n\nCode:\n```text\n<?php\n\nrequire_once __DIR__ . '/vendor/autoload.php';\nrequire 'config.php';\nuse PhpAmqpLib\\Connection\\AMQPStreamConnection;\n\nfunction recieveQueue($queueName){\n $connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');\n\n // try{\n // $connection->wait_frame(10);\n // }catch(AMQPConnectionException $e){\n // echo \"asdasd\";\n // }\n\n $channel = $connection->channel();\n\n $channel->queue_declare($queueName, false, false, false, false);\n\n echo ' [*] Waiting for messages. To exit press CTRL+C', \"\\n\";\n\n $callback = function($msg) {\n echo \" [x] Received \", $msg->body, \"\\n\";\n\n };\n\n // $tag = uniqid() . microtime(true);\n // $queue->consume($callback, $flags, $tag);\n\n $channel->basic_consume($queueName, '', false, true, false, false, $callback);\n\n // $channel->cancel($tag);\n\n while(count($channel->callbacks)) {\n $channel->wait();\n }\n\n echo \"\\nfinish\";\n}\n\nrecieveQueue('vtiger');\n\n?>\n```\n\n```text\n$timeout = 55;\nwhile(count($channel->callbacks)) {\n $channel->wait(null, false, $timeout);\n}\n```\n\n```text\n$callback = function($msg) {\n echo \" [x] Received \", $msg->body, \"\\n\";\n\n // if queue recieve 'stop', stop consume anymore messages\n if ($msg->body == 'stop'){\n $channel->basic_cancel($queueName);\n }\n };\n\n $channel->basic_consume($queueName, '', false, true, false, false, $callback);\n\n $timeout = 10;\n while(count($channel->callbacks)) {\n // $channel->wait(null, false, $timeout);\n $channel->wait();\n }\n```\n\n```text\n$timeout = 5;\n while (count($channel->callbacks)) {\n try{\n $channel->wait(null, false , $timeout);\n }catch(\\PhpAmqpLib\\Exception\\AMQPTimeoutException $e){\n $channel->close();\n $connection->close();\n exit;\n }\n }\n```\n\n========================================\n\nComments:\n- what does 'null' and 'false' stand for? and may I know if there's a way to stop wait after receive something like 'stop' signal from producer?\n- `public function wait($allowed_methods=null, $non_blocking = false, $timeout = 0)`\n- Is this a common practice if you run your workers as a cronjob?\n- it would be great if one could just use `channel->wait(null, $nonBlockinge=true);` without having to specify a timeout, but it looks like a non blocking consume on its own never arrived after being requested. github.com/pdezwart/php-amqp/issues/55\n- @mnv Is there a manual page for `wait()` somewhere? You probably just pulled that line from the source code, but an explanation of the function and parameters would help.\n- I found this example in Internet many time ago and as I see it is not documented","metadata":{"transformedAt":"2026-08-18T18:33:20.153Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":164,"estimatedTokens":1108}}400{"id":"stack-62084208","source":"stackoverflow","questionId":62084208,"title":"Can we use RabbitMQ and Mediatr together using masstransit?","tags":["rabbitmq","microservices","masstransit","mediatr"],"text":"Title: Can we use RabbitMQ and Mediatr together using masstransit?\nTags: rabbitmq, microservices, masstransit, mediatr\nSource: Stack Overflow\n\nQuestion:\nI created a microservice application that microservices using **MassTransit** and **RabbitMQ** for communication.\n\nEach microservice developed using clean architecture, so we have **MediatR** inside each microservice.\n\nIs it possible to use MassTransit for inside communication as well? so I can use the same signature for all services and when I want to expose a service to be used inter-microservice, it will be doable with ease.\nSo MediatR used for intra-communication and RabbitMQ used for inter-communication, and whole universe is on MassTransit system.\n\n**[Update]** My question is how we can configure consumers so some can be used for inside communication (via MediatR) and some can be used for external communication (via RabbitMQ) and easily change them from inside to outside.\n\n**[Update2]** for example here is my MassTransit registration:\n\n```\nservices.AddMassTransit(x =>\n {\n x.AddConsumers(Assembly.GetExecutingAssembly());\n\n x.AddBus(provider =>\n Bus.Factory.CreateUsingRabbitMq(cfg =>\n {\n cfg.Host(new Uri(config.RabbitMQ.Address), h =>\n {\n h.Username(config.RabbitMQ.Username);\n h.Password(config.RabbitMQ.Password);\n });\n\n cfg.ReceiveEndpoint(\"my-queue\", ep => { ep.ConfigureConsumers(provider); });\n }));\n\n x.AddMediator((provider, cfg) => { cfg.ConfigureConsumers(provider); });\n });\n```\n\nHow can I differ in internal communication and external communication? in other words, how can I register some consumers to MediatR and some to RabbitMQ?\n\n========================================\n\nTop Answer:\nThey can be used together, and MassTransit has its own Mediator implementation as well so you can write your handlers once and use them either via the mediator or via a durable transport such as RabbitMQ.\n\nThere are videos available that take you through the capabilities, starting with mediator and moving to RabbitMQ.\n\n========================================\n\nCode:\n```text\nservices.AddMassTransit(x =>\n {\n x.AddConsumers(Assembly.GetExecutingAssembly());\n\n x.AddBus(provider =>\n Bus.Factory.CreateUsingRabbitMq(cfg =>\n {\n cfg.Host(new Uri(config.RabbitMQ.Address), h =>\n {\n h.Username(config.RabbitMQ.Username);\n h.Password(config.RabbitMQ.Password);\n });\n\n cfg.ReceiveEndpoint(\"my-queue\", ep => { ep.ConfigureConsumers(provider); });\n }));\n\n\n x.AddMediator((provider, cfg) => { cfg.ConfigureConsumers(provider); });\n });\n```\n\n```text\n// find consumers\n var types = AssemblyTypeCache.FindTypes(new[]{Assembly.GetExecutingAssembly()},TypeMetadataCache.IsConsumerOrDefinition).GetAwaiter().GetResult();\n var consumers = types.FindTypes(TypeClassification.Concrete | TypeClassification.Closed).ToArray();\n var internals = new List<Type>();\n var externals = new List<Type>();\n foreach (Type type in consumers)\n {\n if (type.HasInterface<IExternalConsumer>())\n externals.Add(type);\n else\n internals.Add(type);\n }\n\n services.AddMediator(x =>\n {\n x.AddConsumers(internals.ToArray());\n x.ConfigureMediator((provider, cfg) => cfg.UseFluentValidation());\n });\n services.AddMassTransit<IExternalBus>(x =>\n {\n x.AddConsumers(externals.ToArray());\n x.AddBus(provider =>\n Bus.Factory.CreateUsingRabbitMq(cfg =>\n {\n cfg.Host(new Uri(config.RabbitMQ.Address), h =>\n {\n h.Username(config.RabbitMQ.Username);\n h.Password(config.RabbitMQ.Password);\n });\n\n cfg.ReceiveEndpoint(apiProviderName, ep => { ep.ConfigureConsumers(provider); });\n\n }));\n });\n\n services.AddMassTransitHostedService();\n```\n\n========================================\n\nComments:\n- Based upon your update, you would need to use the MassTransit mediator to have a single interface for consumers that you could move to either mediator or RabbitMQ endpoints.\n- Thanks for your comment. Actually I know it's possible to use both. I want to know how we can configure consumers that some used for inside communication (via MediatR) and some used for external communication (via RabbitMQ)\n- can we use main mediatR library with mass transit ? @Chris\n- Sure? I haven't used MediatR, so I have no idea how it works but I imagine the two can be used in the same project. They are not, however, *integrated* to work together.\n- Just to update, with v7, the .AddMediator() and .AddMassTransit() can be configured in the same container without using a separate bus.\n- I've been trying with MassTransit.AspNetCore 7.0.3 but cannot do .AddMediator(). services.AddMassTransit(cfg => { cfg.AddConsumer(); cfg.AddMediator(); // <- this line doesn't work. no definition found. });\n- With that approach should I use MassTransit interfaces in my controllers or MediatR ones? Can you any sample solution?\n- Currently migrating to V8 and had a hard Time with TypeMetadataCache.IsConsumerOrDefinition. For everyone running into the same problem, it is now RegistrationMetadata.IsConsumerOrDefinition","metadata":{"transformedAt":"2026-08-18T18:33:20.153Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":121,"estimatedTokens":1369}}401{"id":"stack-28747192","source":"stackoverflow","questionId":28747192,"title":"How to consume just one message from rabbit mq on nodejs","tags":["node.js","rabbitmq"],"text":"Title: How to consume just one message from rabbit mq on nodejs\nTags: node.js, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nIm using amqp.node library to integrate rabbitmq into my system.\n\nBut in consumer i want to process just one message at the time, then acknowledge the message then consume the next message from the queue.\n\nThe current code is:\n\n```\n// Consumer\nopen.then(function(conn) {\n var ok = conn.createChannel();\n ok = ok.then(function(ch) {\n ch.assertQueue(q);\n ch.consume(q, function(msg) {\n if (msg !== null) {\n othermodule.processMessage(msg, function(error, response){\n console.log(msg.content.toString());\n ch.ack(msg);\n });\n }\n });\n });\n return ok;\n}).then(null, console.warn);\n```\n\nThe ch.consume will process all messages in the channel at one time and the function of the module call it here othermodule will not be executed in the same time line. \n\nI want to wait for the othermodule function to finish before consume the next message in the queue.\n\n========================================\n\nTop Answer:\nAt this moment (2018), I think RabbitMQ team has an option to do that:\n\nhttps://www.rabbitmq.com/tutorials/tutorial-two-javascript.html\n\n```\nch.prefetch(1);\n```\n\n In order to defeat that we can use the prefetch method with the value\n of 1. This tells RabbitMQ not to give more than one message to a\n worker at a time. Or, in other words, don't dispatch a new message to\n a worker until it has processed and acknowledged the previous one.\n Instead, it will dispatch it to the next worker that is not still\n busy.\n\n========================================\n\nCode:\n```text\n// Consumer\nopen.then(function(conn) {\n var ok = conn.createChannel();\n ok = ok.then(function(ch) {\n ch.assertQueue(q);\n ch.consume(q, function(msg) {\n if (msg !== null) {\n othermodule.processMessage(msg, function(error, response){\n console.log(msg.content.toString());\n ch.ack(msg);\n });\n }\n });\n });\n return ok;\n}).then(null, console.warn);\n```\n\n```text\nvar _model = rabbitConnection.CreateModel();\n // Configure the Quality of service for the model. Below is how what each setting means.\n // BasicQos(0=\"Dont send me a new message untill I’ve finshed\", _fetchSize = \"Send me N messages at a time\", false =\"Apply to this Model only\")\n _model.BasicQos(0, _fetchSize, false);\n var consumerTag = _model.BasicConsume(rabbitQueue.QueueName, false, _consumerName, queueingConsumer);\n```\n\n```text\nch = ...\nch.qos(1);\nch.consume(q, msg => { ... });\n```\n\n```text\nch.prefetch(1);\n```\n\n```text\n// Consumer\nfunction consumer(conn) {\n var ok = conn.createChannel(on_open);\n function on_open(err, ch) {\n if (err != null) bail(err);\n ch.assertQueue(q);\n \n // IMPORTANT\n ch.prefetch(1);\n\n ch.consume(q, function(msg) {\n if (msg !== null) {\n console.log(msg.content.toString());\n ch.ack(msg);\n }\n });\n }\n}\n```\n\n========================================\n\nComments:\n- this is not even in nodejs. how is this the accepted answer?\n- There is anyway to tell RabbitMQ not to give more than one message to a any worker at a time, so, for exmaple i have 10 subscribers that connect to the same queue, only 1 will get message at the time? –","metadata":{"transformedAt":"2026-08-18T18:33:20.153Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":118,"estimatedTokens":807}}402{"id":"stack-19643774","source":"stackoverflow","questionId":19643774,"title":"Separating celery consumer and producer","tags":["python","flask","rabbitmq","celery"],"text":"Title: Separating celery consumer and producer\nTags: python, flask, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI want my email service that I wrote to be completely decoupled from my flask application. I am using celery with rabbitmq. So I am wondering is there a way I can configure celery so that in one project I have the Flask application that sends the message to the queue (producer). And in another project I have the celery instance running that listens to the message and execute the task(consumer). I am still confused by how the communication will exactly work? Do I put the API (that sends the email) in my flask application OR the celery project? Ultimately I would like to have the Flask application and the Celery instance in different EC2 instances - with rabbitmq acting as the message broker. \n\nThanks for your help!\n\n========================================\n\nCode:\n```text\nfrom yourmodule.yourapp import celery\ncelery.send_task(\"yourtasksmodule.yourtask\", args=[\"Hello World\"])\n```\n\n========================================\n\nComments:\n- I was wondering if it is possible to do it without importing my module (as I am planning on putting it in a different server instance). As celery needs to be on both side of the pipe (rabbitmq), my question is - can I subclass from celery.Task - so that in one side I'll have methods that define what happens when a task is called (sends a message) and on the other do the actual tasks?\n- @user2216194 can you explain how did you got it working? I am stuck with the same problem as you\n- Tutorial can help","metadata":{"transformedAt":"2026-08-18T18:33:20.153Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":23,"estimatedTokens":393}}403{"id":"stack-34525941","source":"stackoverflow","questionId":34525941,"title":"Sidekiq VS RabbitMQ","tags":["ruby-on-rails","rabbitmq","sidekiq"],"text":"Title: Sidekiq VS RabbitMQ\nTags: ruby-on-rails, rabbitmq, sidekiq\nSource: Stack Overflow\n\nQuestion:\nWe are in need of a queuing system in our **Ruby On Rails 4** web application\n\nwhat are the differences and why would/wouldn't you pick\n\nSidekiq over RabbitMQ?\n\n========================================\n\nComments:\n- It's a lot more than that if you use the right gems and plugins, I don't really want to reproduce the whole article in a comment so here it is blog.stanko.io/…","metadata":{"transformedAt":"2026-08-18T18:33:20.153Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":15,"estimatedTokens":121}}404{"id":"stack-56438819","source":"stackoverflow","questionId":56438819,"title":"What's the difference between SimpleMessageListenerContainer and DirectMessageListenerContainer in Spring AMQP?","tags":["java","rabbitmq","spring-amqp","spring-rabbit"],"text":"Title: What's the difference between SimpleMessageListenerContainer and DirectMessageListenerContainer in Spring AMQP?\nTags: java, rabbitmq, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nWhat's the difference between `SimpleMessageListenerContainer` and `DirectMessageListenerContainer` in Spring AMQP? I checked both of their documentation pages, `SimpleMessageListenerContainer` has almost no explanation on inner workings, and `DirectMessageListenerContainer` has the following explanation:\n\n**The SimpleMessageListenerContainer** is not so simple. Recent changes to the rabbitmq java client has facilitated a much simpler listener container that invokes the listener directly on the rabbit client consumer thread. There is no txSize property - each message is acked (or nacked) individually.\n\nI don't really understand what these mean. It says `listener container that invokes the listener directly on the rabbit client consumer thread`. If so, then how does `SimpleMessageListenerContainer` do the invocation?\n\nI wrote a small application and used `DirectMessageListenerContainer` and just to see the difference, I switched to `SimpleMessageListenerContainer`, but as far as I can see there was no difference on RabbitMQ side. From Java side the difference was in methods (`SimpleMessageListenerContainer` provides more) and logs (`DirectMessageListenerContainer` logged more stuff)\n\nI would like to know the scenarios to use each one of those.\n\n========================================\n\nTop Answer:\nIn the DirectMessageListenerContainer some of the logic is moved into the AMQP implementation as opposed to ListenerContainer as is SimpleMessageListenerContainer\n\nThis is what the Javadocs in SimpleMessageListenerContainer say for setTxSize() - \n\n```\n/**\n * Tells the container how many messages to process in a single transaction (if the channel is transactional). For\n * best results it should be less than or equal to {@link #setPrefetchCount(int) the prefetch count}. Also affects\n * how often acks are sent when using {@link AcknowledgeMode#AUTO} - one ack per txSize. Default is 1.\n * @param txSize the transaction size\n */\n```\n\nThe client sends an ack every time txSize number of messages are processed. This is controlled in the method \n\n```\nprivate boolean doReceiveAndExecute(BlockingQueueConsumer consumer) throws Throwable { //NOSONAR\n\n Channel channel = consumer.getChannel();\n\n for (int i = 0; i In the newer implementations, each message is acked on the thread directly and based on the transactional model (Single or publisher confirms) the consumer sends Acknowledgments to Rabbit MQ\n\n========================================\n\nCode:\n```text\nSimpleMessageListenerContainer\n```\n\n```text\nDirectMessageListenerContainer\n```\n\n```text\nSimpleMessageListenerContainer\n```\n\n```text\nDirectMessageListenerContainer\n```\n\n```text\nlistener container that invokes the listener directly on the rabbit client consumer thread\n```\n\n```text\nSimpleMessageListenerContainer\n```\n\n```text\nDirectMessageListenerContainer\n```\n\n```text\nSimpleMessageListenerContainer\n```\n\n```text\nSimpleMessageListenerContainer\n```\n\n```text\nDirectMessageListenerContainer\n```\n\n```text\ntxSize\n```\n\n```text\n/**\n * Tells the container how many messages to process in a single transaction (if the channel is transactional). For\n * best results it should be less than or equal to {@link #setPrefetchCount(int) the prefetch count}. Also affects\n * how often acks are sent when using {@link AcknowledgeMode#AUTO} - one ack per txSize. Default is 1.\n * @param txSize the transaction size\n */\n```\n\n```text\nprivate boolean doReceiveAndExecute(BlockingQueueConsumer consumer) throws Throwable { //NOSONAR\n\n Channel channel = consumer.getChannel();\n\n for (int i = 0; i < this.txSize; i++) {\n\n logger.trace(\"Waiting for message from consumer.\");\n Message message = consumer.nextMessage(this.receiveTimeout);\n .\n .\n```\n\n========================================\n\nComments:\n- The provided link doesn't work anymore. Here is a new link Choosing a Container","metadata":{"transformedAt":"2026-08-18T18:33:20.153Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":13,"totalLines":113,"estimatedTokens":1017}}405{"id":"stack-6854133","source":"stackoverflow","questionId":6854133,"title":"Django Celery tutorial not returning results","tags":["python","django","rabbitmq","celery"],"text":"Title: Django Celery tutorial not returning results\nTags: python, django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\n**UDATE3:** found the issue. See the answer below.\n\n**UPDATE2:** It seems I might have been dealing with an automatic naming and relative imports problem by running the djcelery tutorial through the manage.py shell, see below. It is still not working for me, but now I get new log error messages. See below.\n\n**UPDATE:** I added the log at the bottom of the post. It seems the example task is not registered?\n\n**Original Post:**\n\nI am trying to get django-celery up and running. I was not able to get through the example.\n\nI installed rabbitmq succesfully and went through the tutorials without trouble: http://www.rabbitmq.com/getstarted.html\n\nI then tried to go through the djcelery tutorial.\n\nWhen I run `python manage.py celeryd -l info` I get the message:\n [Tasks]\n - app.module.add\n [2011-07-27 21:17:19, 990: WARNING/MainProcess] celery@sequoia has started.\n\nSo that looks good. I put this at the top of my settings file:\n\n```\nimport djcelery\ndjcelery.setup_loader()\n\nBROKER_HOST = \"localhost\"\nBROKER_PORT = 5672\nBROKER_USER = \"guest\"\nBROKER_PASSWORD = \"guest\"\nBROKER_VHOST = \"/\"\n```\n\nadded these to my installed apps:\n\n```\n'djcelery',\n```\n\nhere is my tasks.py file in the tasks folder of my app:\n\n```\nfrom celery.task import task\n\n@task()\ndef add(x, y):\n return x + y\n```\n\nI added this to my django.wsgi file:\n\n```\nos.environ[\"CELERY_LOADER\"] = \"django\"\n```\n\nThen I entered this at the command line:\n\n```\n>>> from app.module.tasks import add\n>>> result = add.delay(4,4)\n>>> result\n(AsyncResult: 7auathu945gry48- a bunch of stuff)\n>>> result.ready()\nFalse\n```\n\nSo it looks like it worked, but here is the problem:\n\n```\n>>> result.result\n>>> (nothing is returned)\n>>> result.get()\n```\n\nWhen I put in result.get() it just hangs. What am I doing wrong?\n\n**UPDATE:** This is what running the logger in the foreground says when I start up the worker server:\n\n```\nNo handlers could be found for logger “multiprocessing”\n\n[Configuration]\n- broker: amqplib://guest@localhost:5672/\n- loader: djcelery.loaders.DjangoLoader\n- logfile: [stderr]@INFO\n- concurrency: 4\n- events: OFF\n- beat: OFF\n\n[Queues]\n- celery: exchange: celery (direct) binding: celery\n\n[Tasks]\n - app.module.add\n[2011-07-27 21:17:19, 990: WARNING/MainProcess] celery@sequoia has started.\n\n C:\\Python27\\lib\\site-packages\\django-celery-2.2.4-py2.7.egg\\djcelery\\loaders.py:80: UserWarning: Using settings.DEBUG leads to a memory leak, neveruse this setting in production environments!\n warnings.warn(“Using settings.DEBUG leads to a memory leak, never”\n```\n\nthen when I put in the command:\n\n```\n>>> result = add(4,4)\n```\n\nThis appears in the error log:\n\n```\n[2011-07-28 11:00:39, 352: ERROR/MainProcess] Unknown task ignored: Task of kind ‘task.add’ is not registered, please make sure it’s imported. Body->”{‘retries’: 0, ‘task’: ‘tasks.add’, ‘args’: (4,4), ‘expires’: None, ‘ta’: None\n ‘kwargs’: {}, ‘id’: ‘225ec0ad-195e-438b-8905-ce28e7b6ad9’}”\nTraceback (most recent call last):\n File “C:\\Python27\\..\\celery\\worker\\consumer.py”,line 368, in receive_message\n Eventer=self.event_dispatcher)\n File “C:\\Python27\\..\\celery\\worker\\job.py”,line 306, in from_message \n **kw)\n File “C:\\Python27\\..\\celery\\worker\\job.py”,line 275, in __init__\n self.task = tasks[self.task_name]\n File “C:\\Python27\\...\\celery\\registry.py”, line 59, in __getitem__\n Raise self.NotRegistered(key)\nNotRegistered: ‘tasks.add’\n```\n\nHow do I get this task to be registered and handled properly? thanks.\n\n**UPDATE 2:**\n\nThis link suggested that the not registered error can be due to task name mismatches between client and worker - http://celeryproject.org/docs/userguide/tasks.html#automatic-naming-and-relative-imports\n\nexited the manage.py shell and entered a python shell and entered the following:\n\n```\n>>> from app.module.tasks import add\n>>> result = add.delay(4,4)\n>>> result.ready()\nFalse\n>>> result.result\n>>> (nothing returned)\n>>> result.get()\n (it just hangs there)\n```\n\nso I am getting the same behavior, but new log message. From the log, it appears the server is working but it won't feed the result back out:\n\n```\n[2011-07-28 11:39:21, 706: INFO/MainProcess] Got task from broker: app.module.tasks.add[7e794740-63c4-42fb-acd5-b9c6fcd545c3]\n[2011-07-28 11:39:21, 706: INFO/MainProcess] Task app.module.tasks.add[7e794740-63c4-42fb-acd5-b9c6fcd545c3] succeed in 0.04600000038147s: 8\n```\n\nSo the server got the task and it computed the correct answer, but it won't send it back? why not?\n\n========================================\n\nTop Answer:\nif you run celery in debug mode is more easy understand the problem\n\n```\npython manage.py celeryd\n```\n\nWhat the celery logs says, celery is receiving the task ? \nIf not probably there is a problem with broker (wrong queue ?)\n\nGive us more detail, in this way we can help you\n\n========================================\n\nCode:\n```text\nimport djcelery\ndjcelery.setup_loader()\n\nBROKER_HOST = \"localhost\"\nBROKER_PORT = 5672\nBROKER_USER = \"guest\"\nBROKER_PASSWORD = \"guest\"\nBROKER_VHOST = \"/\"\n```\n\n```text\n'djcelery',\n```\n\n```text\nfrom celery.task import task\n\n@task()\ndef add(x, y):\n return x + y\n```\n\n```text\nos.environ[\"CELERY_LOADER\"] = \"django\"\n```\n\n```text\n>>> from app.module.tasks import add\n>>> result = add.delay(4,4)\n>>> result\n(AsyncResult: 7auathu945gry48- a bunch of stuff)\n>>> result.ready()\nFalse\n```\n\n```text\n>>> result.result\n>>> (nothing is returned)\n>>> result.get()\n```\n\n```text\nNo handlers could be found for logger “multiprocessing”\n\n[Configuration]\n- broker: amqplib://guest@localhost:5672/\n- loader: djcelery.loaders.DjangoLoader\n- logfile: [stderr]@INFO\n- concurrency: 4\n- events: OFF\n- beat: OFF\n\n[Queues]\n- celery: exchange: celery (direct) binding: celery\n\n[Tasks]\n - app.module.add\n[2011-07-27 21:17:19, 990: WARNING/MainProcess] celery@sequoia has started.\n\n C:\\Python27\\lib\\site-packages\\django-celery-2.2.4-py2.7.egg\\djcelery\\loaders.py:80: UserWarning: Using settings.DEBUG leads to a memory leak, neveruse this setting in production environments!\n warnings.warn(“Using settings.DEBUG leads to a memory leak, never”\n```\n\n```text\n>>> result = add(4,4)\n```\n\n```text\n[2011-07-28 11:00:39, 352: ERROR/MainProcess] Unknown task ignored: Task of kind ‘task.add’ is not registered, please make sure it’s imported. Body->”{‘retries’: 0, ‘task’: ‘tasks.add’, ‘args’: (4,4), ‘expires’: None, ‘ta’: None\n ‘kwargs’: {}, ‘id’: ‘225ec0ad-195e-438b-8905-ce28e7b6ad9’}”\nTraceback (most recent call last):\n File “C:\\Python27\\..\\celery\\worker\\consumer.py”,line 368, in receive_message\n Eventer=self.event_dispatcher)\n File “C:\\Python27\\..\\celery\\worker\\job.py”,line 306, in from_message \n **kw)\n File “C:\\Python27\\..\\celery\\worker\\job.py”,line 275, in __init__\n self.task = tasks[self.task_name]\n File “C:\\Python27\\...\\celery\\registry.py”, line 59, in __getitem__\n Raise self.NotRegistered(key)\nNotRegistered: ‘tasks.add’\n```\n\n```text\n>>> from app.module.tasks import add\n>>> result = add.delay(4,4)\n>>> result.ready()\nFalse\n>>> result.result\n>>> (nothing returned)\n>>> result.get()\n (it just hangs there)\n```\n\n```text\n[2011-07-28 11:39:21, 706: INFO/MainProcess] Got task from broker: app.module.tasks.add[7e794740-63c4-42fb-acd5-b9c6fcd545c3]\n[2011-07-28 11:39:21, 706: INFO/MainProcess] Task app.module.tasks.add[7e794740-63c4-42fb-acd5-b9c6fcd545c3] succeed in 0.04600000038147s: 8\n```\n\n```text\npython manage.py celeryd -l info\n```\n\n```text\nCELERY_RESULT_BACKEND = \"amqp\"\nCELERY_IMPORTS = (\"app.module.tasks\", )\n```\n\n```text\n@task(name=\"module.tasks.add\")\n```\n\n```text\npython manage.py celeryd\n```\n\n========================================\n\nComments:\n- Are you using Windows? There have been reports about results not working in Windows for Celery 3\n- Yes I am using windows. I am about to revisit the project which utilizes rabbitmq and celery. I'll keep your comments in mind then. In general I have been very happy with the two though.\n- where is the log file stored? I cannot find it. Would it be the rabbitmq log? or another? I added the text from running the logger in the fore ground to my post above. Thanks.\n- I can't believe they omitted these crucial crucial lines in django celery docs.....\n- @Tony see the note about Relative Imports below at docs.celeryproject.org/en/latest/django/… It's not a problem unless you use relative imports, and relative imports are discouraged in Python\n- I had a similar problem and whether or not relative imports has anything to do with it, the CELERY_RESULT_BACKEND = 'amqp' bit is necessary.","metadata":{"transformedAt":"2026-08-18T18:33:20.153Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":15,"totalLines":297,"estimatedTokens":2174}}406{"id":"stack-45107418","source":"stackoverflow","questionId":45107418,"title":"Is it possible to skip delegating a celery task if the params and the task name is already queued in the server?","tags":["python","django","rabbitmq","celery"],"text":"Title: Is it possible to skip delegating a celery task if the params and the task name is already queued in the server?\nTags: python, django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nSay that I have this task:\n\n```\ndef do_stuff_for_some_time(some_id):\n e = Model.objects.get(id=some_id)\n e.domanystuff()\n```\n\nand I'm using it like so:\n\n```\ndo_stuff_for_some_time.apply_async(args=[some_id], queue='some_queue')\n```\n\nThe problem I'm facing is that there are a lot of repetitive tasks with the same arg param and it's boggling down the queue.\n\nIs it possible to apply async only if the same args and the same task is not in the queue?\n\n========================================\n\nTop Answer:\nI would try a mix of a `cache lock` and a `task result backend` which stores each task's results:\n\nThe cache lock will prevent tasks with the same arguments to get added to the queue multiple times. Celery documentation contains a nice example of cache lock implementation here, but if you don't want to create it yourself, you can use the celery-once module.\n\nFor a task result backend, we will use the recommended django-celery-results, which creates a `TaskResult` table that we will query for task results.\n\n**Example:**\n\nInstall and configure `django-celery-results`:\n\n`settings.py`:\n\n```\nINSTALLED_APPS = (\n ...,\n 'django_celery_results',\n)\nCELERY_RESULT_BACKEND = 'django-db' # You can also use 'django-cache'\n```\n\n`./manage.py migrate django_celery_results`\n\nInstall and configure the `celery-once` module:\n\n`tasks.py`:\n\n```\nfrom celery import Celery\nfrom celery_once import QueueOnce\nfrom time import sleep\n\ncelery = Celery('tasks', broker='amqp://guest@localhost//')\ncelery.conf.ONCE = {\n 'backend': 'celery_once.backends.Redis',\n 'settings': {\n 'url': 'redis://localhost:6379/0',\n 'default_timeout': 60 * 60\n }\n}\n\n@celery.task(base=QueueOnce)\ndef do_stuff_for_some_time(some_id):\n e = Model.objects.get(id=some_id)\n e.domanystuff()\n```\n\nAt this point, if a task with the same arguments is going to be executed,\n\nan `AlreadyQueued` exception will be raised. \n\nLet's use the above:\n\n```\nfrom django_celery_results.models import TaskResult\n\ntry:\n result = do_stuff_for_some_time(some_id)\nexcept AlreadyQueued:\n result = TaskResult.objects.get(task_args=some_id)\n```\n\n**Caveats:**\n\nMind that at the time an `AlreadyQueued` exception arises, the initial task with argument=`some_id` may not be executed and therefore it will not have results in `TaskResult` table.\n\nMind everything in your code that can go wrong and hang any of the above processes (because it will do that!).\n\n**Extra Reading:**\n\n- Another Task with Lock DIY implementation\n\n- django-celery-result's `TaskResult` model.\n\n========================================\n\nCode:\n```text\ndef do_stuff_for_some_time(some_id):\n e = Model.objects.get(id=some_id)\n e.domanystuff()\n```\n\n```text\ndo_stuff_for_some_time.apply_async(args=[some_id], queue='some_queue')\n```\n\n```text\nfrom celery_singleton import Singleton\n\n@celery_app.task(base=Singleton)\ndef do_stuff_for_some_time(some_id):\n e = Model.objects.get(id=some_id)\n e.domanystuff()\n```\n\n```text\npip install celery-singleton\n```\n\n```text\nSingleton\n```\n\n```text\nINSTALLED_APPS = (\n ...,\n 'django_celery_results',\n)\nCELERY_RESULT_BACKEND = 'django-db' # You can also use 'django-cache'\n```\n\n```text\nfrom celery import Celery\nfrom celery_once import QueueOnce\nfrom time import sleep\n\ncelery = Celery('tasks', broker='amqp://guest@localhost//')\ncelery.conf.ONCE = {\n 'backend': 'celery_once.backends.Redis',\n 'settings': {\n 'url': 'redis://localhost:6379/0',\n 'default_timeout': 60 * 60\n }\n}\n\n@celery.task(base=QueueOnce)\ndef do_stuff_for_some_time(some_id):\n e = Model.objects.get(id=some_id)\n e.domanystuff()\n```\n\n```text\nfrom django_celery_results.models import TaskResult\n\ntry:\n result = do_stuff_for_some_time(some_id)\nexcept AlreadyQueued:\n result = TaskResult.objects.get(task_args=some_id)\n```\n\n```text\ncache lock\n```\n\n```text\ntask result backend\n```\n\n```text\nTaskResult\n```\n\n```text\ndjango-celery-results\n```\n\n```text\nsettings.py\n```\n\n```text\n./manage.py migrate django_celery_results\n```\n\n```text\ncelery-once\n```\n\n```text\ntasks.py\n```\n\n```text\nAlreadyQueued\n```\n\n```text\nAlreadyQueued\n```\n\n```text\nsome_id\n```\n\n```text\nTaskResult\n```\n\n```text\nTaskResult\n```\n\n========================================\n\nComments:\n- take a look at github.com/sgrepo/celery-unique\n- docs.celeryproject.org/en/latest/tutorials/…\n- @trinchet that wouldn't quite solve the issue of repeated tasks in the queue. You could still submit 100 of the same task with the same parameter but only one worker would ever be able to work on it, which still doesn't solve the problem.","metadata":{"transformedAt":"2026-08-18T18:33:20.153Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":21,"totalLines":224,"estimatedTokens":1183}}407{"id":"stack-21385143","source":"stackoverflow","questionId":21385143,"title":"Comsuming MassTransit from Python or other languages","tags":["c#","python",".net","rabbitmq","masstransit"],"text":"Title: Comsuming MassTransit from Python or other languages\nTags: c#, python, .net, rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nI have a simple publisher done in MassTransit. I’m sending the message in an interval and am able to receive it from .NET client using MassTransit. But when I try to observe something from Python, it is silent. Is there a way to consume MassTransit from Python or other languages? Examples appreciated.\n\nPublisher:\n\n```\nbuilder.Register(c => ServiceBusFactory.New(sbc => {\n sbc.UseRabbitMq();\n sbc.UseBsonSerializer();\n sbc.UseLog4Net();\n\n sbc.ReceiveFrom(\"rabbitmq://localhost/masstransit\");\n});\n```\n\n.NET client:\n\n```\npublic void Execute(IJobExecutionContext context) {\n using (var scope = ServiceLocator.Current.GetInstance().BeginLifetimeScope()) {\n var log = scope.Resolve();\n log.Debug(\"Sending queue message\");\n\n var bus = scope.Resolve();\n bus.Publish(new SimpleTextMessage{Text = \"some text\"});\n }\n}\n```\n\nPython client:\n\n```\nimport pika\nprint('Stating consumer')\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost'))\nchannel = connection.channel()\n\nchannel.queue_declare(queue='python_consumer_1')\n\nprint ' [*] Waiting for messages. To exit press CTRL+C'\n\ndef callback(ch, method, properties, body):\n print \" [x] Received %r\" % (body,)\n\nchannel.basic_consume(callback, queue='python_consumer_1')\nchannel.start_consuming()\n```\n\nThe trace from C# app:\n\n```\nConfiguration Result:\n[Success] Name MyApp\n[Success] ServiceName MyApp\nTopshelf v3.1.122.0, .NET Framework v4.0.30319.34003\nINFO (MassTransit.BusConfigurators.ServiceBusConfiguratorImpl) 209 - MassTransit v2.9.2/v2.9.0.0, .NET Framework v4.0.30319.34003\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 245 - CreatingRabbitMQ connection: rabbitmq://localhost/groups_error\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 246 - Using default configurator for connection: rabbitmq://localhost/groups_error\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 251 - RabbitMQconnection created: localhost:5672//\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 921 - Creating RabbitMQ connection: rabbitmq://localhost/groups\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 922 - Using default configurator for connection: rabbitmq://localhost/groups\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 924 - RabbitMQconnection created: localhost:5672//\nDEBUG(MassTransit.ServiceContainer) 1056 - Starting bus service: MassTransit.Subscriptions.Coordinator.SubscriptionRouterService\nDEBUG(MassTransit.ServiceContainer) 1062 - Starting bus service: MassTransit.Subscriptions.SubscriptionBusService\nDEBUG(MassTransit.Threading.ThreadPoolConsumerPool) 1080 - Starting Consumer Pool for rabbitmq://localhost/groups\n[Topshelf.Quartz] Scheduled Job: DEFAULT.ea637337-950a-4281-99c0-f10b842814c9\n[Topshelf.Quartz] Job Schedule: Trigger 'DEFAULT.8a1d0b7c-d670-440b-974f-31ec8be6f294': triggerClass: 'Quartz.Impl.Triggers.SimpleTriggerImpl calendar: '' misfireInstruction: 0 nextFireTime: 01/28/2014 07:12:35 +00:00 - Next Fire Time (local): 28.01.2014 9:12:35 +02:00\n[Topshelf.Quartz] Scheduler started...\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 1248 - CreatingRabbitMQ connection: rabbitmq://localhost/MyApp.Transit:SimpleTextMessage_error\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 1250 - Using default configurator for connection: rabbitmq://localhost/MyApp.Transit:SimpleTextMessage_error\nDEBUG(Global) 1254 - Sending queue message\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 1254 - RabbitMQconnection created: localhost:5672//\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 1272 - CreatingRabbitMQ connection: rabbitmq://localhost/MyApp.Transit:SimpleTextMessage\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 1273 - Using default configurator for connection: rabbitmq://localhost/MyApp.Transit:SimpleTextMessage\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 1277 - RabbitMQconnection created: localhost:5672//\nDEBUG(MassTransit.Messages) 1439 - SEND:rabbitmq://localhost/MyApp.Transit:SimpleTextMessage:935a0000-5d93-0015-961c-08d0ea0f744a:MyApp.Transit.SimpleTextMessage, MyApp\nDEBUG(MassTransit.Messages) 1441 - SEND:rabbitmq://localhost/MyApp.Transit:SimpleTextMessage:935a0000-5d93-0015-8965-08d0ea0f744b:MyApp.Transit.SimpleTextMessage, MyApp\nThe MyApp service is now running, press Control+C to exit.\n\nDEBUG(Global) 21212 - Sending queue message\nDEBUG(MassTransit.Messages) 21214 - SEND:rabbitmq://localhost/MyApp.Transit:SimpleTextMessage:935a0000-5d93-0015-d4fb-08d0ea0f77c4:MyApp.Transit.SimpleTextMessage, MyApp\nDEBUG(Global) 41213 - Sending queue message\nDEBUG(MassTransit.Messages) 41214 - SEND:rabbitmq://localhost/MyApp.Transit:SimpleTextMessage:935a0000-5d93-0015-077b-08d0ea0f7b40:MyApp.Transit.SimpleTextMessage, MyApp\nDEBUG(Global) 61212 - Sending queue message\nDEBUG(MassTransit.Messages) 61214 - SEND:rabbitmq://localhost/MyApp.Transit:SimpleTextMessage:935a0000-5d93-0015-2bed-08d0ea0f7ebb:MyApp.Transit.SimpleTextMessage, MyApp\nDEBUG(Global) 81213 - Sending queue message\nDEBUG(MassTransit.Messages) 81215 - SEND:rabbitmq://localhost/MyApp.Transit:SimpleTextMessage:935a0000-5d93-0015-5f44-08d0ea0f8236:MyApp.Transit.SimpleTextMessage, MyApp\nDEBUG(Global) 101212 - Sending queue message\nDEBUG(MassTransit.Messages) 101214 - SEND:rabbitmq://localhost/MyApp.Transit:SimpleTextMessage:935a0000-5d93-0015-80f8-08d0ea0f85b1:MyApp.Transit.SimpleTextMessage, MyApp\nDEBUG(Global) 121212 - Sending queue message\nDEBUG(MassTransit.Messages) 121213 - SEND:rabbitmq://localhost/MyApp.Transit:SimpleTextMessage:935a0000-5d93-0015-a971-08d0ea0f892c:MyApp.Transit.SimpleTextMessage, MyApp\nDEBUG(Global) 141212 - Sending queue message\nDEBUG(MassTransit.Messages) 141214 - SEND:rabbitmq://localhost/MyApp.Transit:SimpleTextMessage:935a0000-5d93-0015-d53e-08d0ea0f8ca7:MyApp.Transit.SimpleTextMessage, MyApp\nDEBUG(Global) 161212 - Sending queue message\nDEBUG(MassTransit.Messages) 172109 - SEND:rabbitmq://localhost/MyApp.Transit:SimpleTextMessage:935a0000-5d93-0015-7504-08d0ea0f9208:MyApp.Transit.SimpleTextMessage, MyApp\nDEBUG(Global) 181212 - Sending queue message\nDEBUG(MassTransit.Messages) 193461 - SEND:rabbitmq://localhost/MyApp.Transit:SimpleTextMessage:935a0000-5d93-0015-dd26-08d0ea0f95bf:MyApp.Transit.SimpleTextMessage, MyApp\n```\n\n========================================\n\nTop Answer:\nIf you're going to consume messages from another language, you need to look at how the exchanges are created when MassTransit publishes a message. Then, you will need to bind those exchanges to your queues so that messages are delivered to your subscribers.\n\nFor your Python code, you need to \n\n```\nexchange_bind(\".....:SimpleTextMessage\", \"phython_consumer_1\")\n```\n\nOnce you've done that, the messages will be delivered to your queue. You're using BSON, why not use JSON or something that python works with easily? Honestly I'm not sure if Python supports BSON or not, just trying to offer other suggestions.\n\n========================================\n\nCode:\n```text\nbuilder.Register(c => ServiceBusFactory.New(sbc => {\n sbc.UseRabbitMq();\n sbc.UseBsonSerializer();\n sbc.UseLog4Net();\n\n sbc.ReceiveFrom(\"rabbitmq://localhost/masstransit\");\n});\n```\n\n```text\npublic void Execute(IJobExecutionContext context) {\n using (var scope = ServiceLocator.Current.GetInstance<ILifetimeScope>().BeginLifetimeScope()) {\n var log = scope.Resolve<ILog>();\n log.Debug(\"Sending queue message\");\n\n var bus = scope.Resolve<IServiceBus>();\n bus.Publish(new SimpleTextMessage{Text = \"some text\"});\n }\n}\n```\n\n```text\nimport pika\nprint('Stating consumer')\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost'))\nchannel = connection.channel()\n\nchannel.queue_declare(queue='python_consumer_1')\n\nprint ' [*] Waiting for messages. To exit press CTRL+C'\n\ndef callback(ch, method, properties, body):\n print \" [x] Received %r\" % (body,)\n\nchannel.basic_consume(callback, queue='python_consumer_1')\nchannel.start_consuming()\n```\n\n```none\nConfiguration Result:\n[Success] Name MyApp\n[Success] ServiceName MyApp\nTopshelf v3.1.122.0, .NET Framework v4.0.30319.34003\nINFO (MassTransit.BusConfigurators.ServiceBusConfiguratorImpl) 209 - MassTransit v2.9.2/v2.9.0.0, .NET Framework v4.0.30319.34003\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 245 - CreatingRabbitMQ connection: rabbitmq://localhost/groups_error\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 246 - Using default configurator for connection: rabbitmq://localhost/groups_error\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 251 - RabbitMQconnection created: localhost:5672//\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 921 - Creating RabbitMQ connection: rabbitmq://localhost/groups\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 922 - Using default configurator for connection: rabbitmq://localhost/groups\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 924 - RabbitMQconnection created: localhost:5672//\nDEBUG(MassTransit.ServiceContainer) 1056 - Starting bus service: MassTransit.Subscriptions.Coordinator.SubscriptionRouterService\nDEBUG(MassTransit.ServiceContainer) 1062 - Starting bus service: MassTransit.Subscriptions.SubscriptionBusService\nDEBUG(MassTransit.Threading.ThreadPoolConsumerPool) 1080 - Starting Consumer Pool for rabbitmq://localhost/groups\n[Topshelf.Quartz] Scheduled Job: DEFAULT.ea637337-950a-4281-99c0-f10b842814c9\n[Topshelf.Quartz] Job Schedule: Trigger 'DEFAULT.8a1d0b7c-d670-440b-974f-31ec8be6f294': triggerClass: 'Quartz.Impl.Triggers.SimpleTriggerImpl calendar: '' misfireInstruction: 0 nextFireTime: 01/28/2014 07:12:35 +00:00 - Next Fire Time (local): 28.01.2014 9:12:35 +02:00\n[Topshelf.Quartz] Scheduler started...\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 1248 - CreatingRabbitMQ connection: rabbitmq://localhost/MyApp.Transit:SimpleTextMessage_error\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 1250 - Using default configurator for connection: rabbitmq://localhost/MyApp.Transit:SimpleTextMessage_error\nDEBUG(Global) 1254 - Sending queue message\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 1254 - RabbitMQconnection created: localhost:5672//\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 1272 - CreatingRabbitMQ connection: rabbitmq://localhost/MyApp.Transit:SimpleTextMessage\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 1273 - Using default configurator for connection: rabbitmq://localhost/MyApp.Transit:SimpleTextMessage\nDEBUG(MassTransit.Transports.RabbitMq.RabbitMqTransportFactory) 1277 - RabbitMQconnection created: localhost:5672//\nDEBUG(MassTransit.Messages) 1439 - SEND:rabbitmq://localhost/MyApp.Transit:SimpleTextMessage:935a0000-5d93-0015-961c-08d0ea0f744a:MyApp.Transit.SimpleTextMessage, MyApp\nDEBUG(MassTransit.Messages) 1441 - SEND:rabbitmq://localhost/MyApp.Transit:SimpleTextMessage:935a0000-5d93-0015-8965-08d0ea0f744b:MyApp.Transit.SimpleTextMessage, MyApp\nThe MyApp service is now running, press Control+C to exit.\n\nDEBUG(Global) 21212 - Sending queue message\nDEBUG(MassTransit.Messages) 21214 - SEND:rabbitmq://localhost/MyApp.Transit:SimpleTextMessage:935a0000-5d93-0015-d4fb-08d0ea0f77c4:MyApp.Transit.SimpleTextMessage, MyApp\nDEBUG(Global) 41213 - Sending queue message\nDEBUG(MassTransit.Messages) 41214 - SEND:rabbitmq://localhost/MyApp.Transit:SimpleTextMessage:935a0000-5d93-0015-077b-08d0ea0f7b40:MyApp.Transit.SimpleTextMessage, MyApp\nDEBUG(Global) 61212 - Sending queue message\nDEBUG(MassTransit.Messages) 61214 - SEND:rabbitmq://localhost/MyApp.Transit:SimpleTextMessage:935a0000-5d93-0015-2bed-08d0ea0f7ebb:MyApp.Transit.SimpleTextMessage, MyApp\nDEBUG(Global) 81213 - Sending queue message\nDEBUG(MassTransit.Messages) 81215 - SEND:rabbitmq://localhost/MyApp.Transit:SimpleTextMessage:935a0000-5d93-0015-5f44-08d0ea0f8236:MyApp.Transit.SimpleTextMessage, MyApp\nDEBUG(Global) 101212 - Sending queue message\nDEBUG(MassTransit.Messages) 101214 - SEND:rabbitmq://localhost/MyApp.Transit:SimpleTextMessage:935a0000-5d93-0015-80f8-08d0ea0f85b1:MyApp.Transit.SimpleTextMessage, MyApp\nDEBUG(Global) 121212 - Sending queue message\nDEBUG(MassTransit.Messages) 121213 - SEND:rabbitmq://localhost/MyApp.Transit:SimpleTextMessage:935a0000-5d93-0015-a971-08d0ea0f892c:MyApp.Transit.SimpleTextMessage, MyApp\nDEBUG(Global) 141212 - Sending queue message\nDEBUG(MassTransit.Messages) 141214 - SEND:rabbitmq://localhost/MyApp.Transit:SimpleTextMessage:935a0000-5d93-0015-d53e-08d0ea0f8ca7:MyApp.Transit.SimpleTextMessage, MyApp\nDEBUG(Global) 161212 - Sending queue message\nDEBUG(MassTransit.Messages) 172109 - SEND:rabbitmq://localhost/MyApp.Transit:SimpleTextMessage:935a0000-5d93-0015-7504-08d0ea0f9208:MyApp.Transit.SimpleTextMessage, MyApp\nDEBUG(Global) 181212 - Sending queue message\nDEBUG(MassTransit.Messages) 193461 - SEND:rabbitmq://localhost/MyApp.Transit:SimpleTextMessage:935a0000-5d93-0015-dd26-08d0ea0f95bf:MyApp.Transit.SimpleTextMessage, MyApp\n```\n\n```text\nimport pika\n\nprint('Stating consumer')\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))\nchannel = connection.channel()\n\nchannel.queue_declare('python_consumer_1')\n\nprint ' [*] Waiting for messages. To exit press CTRL+C'\n\ndef callback(ch, method, properties, body):\n print \" [x] Received %r\" % (body,)\n ch.basic_ack(delivery_tag = method.delivery_tag)\n\nchannel.queue_bind(queue='python_consumer_1', exchange='MyApp.Transit:SimpleTextMessage')\nchannel.basic_consume(callback, queue='python_consumer_1')\nchannel.start_consuming()\n```\n\n```text\nexchange_bind(\".....:SimpleTextMessage\", \"phython_consumer_1\")\n```\n\n========================================\n\nComments:\n- I get an error: ChannelClosed: (404, \"NOT_FOUND - no exchange 'python_consumer_1' in vhost '/'\") when try to call: channel.exchange_bind('MyApp.Transit:SimpleTextMessage', 'python_consumer_1') before nor after basic_consume.. Will update the question with trace from masstrasit.\n- I've also removed BSON serializer and tried to replace it with JSON, but python part still silent and unable to get the message.\n- Yes, I've managed to provide a PoC. Thank you for giving an idea.","metadata":{"transformedAt":"2026-08-18T18:33:20.154Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":240,"estimatedTokens":3613}}408{"id":"stack-21007096","source":"stackoverflow","questionId":21007096,"title":"Django, Celery, Redis, RabbitMQ: Chained Tasks for Fanout-On-Writes","tags":["python","django","redis","rabbitmq","celery"],"text":"Title: Django, Celery, Redis, RabbitMQ: Chained Tasks for Fanout-On-Writes\nTags: python, django, redis, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI've been watching Rick Branson's PyCon video: Messaging at Scale at Instagram. You might want to watch the video in order to answer this question. Rick Branson uses Celery, Redis and RabbitMQ. To get you up to speed, each user has a redis list for their homefeed. Each list contains media ID's of photos posted by the people they . \n\nJustin Bieber for example has 1.5 million followers. When he posts a photo, the ID of that photo needs to be inserted into each individual redis list for each of his followers. This is called the Fanout-On-Write approach. However, there are a few reliability problems with this approach. It can work, but for someone like Justin Bieber or Lady Gaga who have millions of followers, doing this in the web request (where you have 0-500ms to complete the request) can be problem. By then, the request will timeout.\n\nSo Rick Branson decided to use Celery, an asynchronous task queue/job queue based on distributed message passing. Any heavy lifting such as inserting media IDs into follower's lists can be done asynchronously, outside of the web request. The request will complete and celery will continue to insert the IDs into all of the lists. \n\nThis approach works wonders. But again, you don't want to deliver all of Justin's followers to Celery in one huge chunk because it would tie up a celery worker. Why not have multiple workers work on it at the same time so it finishes faster? Brilliant idea! you'd want to break up this chunk into smaller chunks and have different workers working on each batch. Rick Branson does a batch of 10,000 followers, and he uses something called a cursor to keep inserting media IDs for all of Justin Bieber's followers until it is completed. In the video, he talks about this in 3:56\n\nI was wondering if anyone could explain this more and show examples of how it can be done. I'm currently trying to attempt the same setup. I use Andy McCurdy's redis-py python client library to communicate with my redis server. For every user on my service, I create a redis followers list. \n\nSo a user with an ID of 343 would have a list at the following key: \n\n```\nfollowers:343\n```\n\nI also create a homefeed list for each user. Every user has their own list.\nSo a user with an ID of 1990 would have a list at the following key:\n\n```\nhomefeed:1990\n```\n\nIn the \"followers:343\" redis list, it contains all the IDs of the people who user 343. user 343 has 20,007 followers. Below, I am retrieving all the IDs in the list starting from index 0 all the way to the end -1 just to show you what it looks like.\n\n```\n>>> r_server.lrange(\"followers:343\", 0, -1)\n['8', '7', '5', '3', '65', '342', '42', etc...] ---> for the sake of example, assume this list has another 20,000 IDs.\n```\n\nWhat you see is a list of all the ID's of users who user 343.\n\nHere is my *proj/mydjangoapp/tasks.py* which contains my insert_into_homefeed function:\n\n```\nfrom __future__ import absolute_import\nfrom celery import shared_task\nimport redis\npool = redis.ConnectionPool(host='XX.XXX.XXX.X', port=6379, db=0, password='XXXXX')\n\n@shared_task\ndef insert_into_homefeed(photo_id, user_id):\n # Grab the list of all follower IDs from Redis for user_id.\n r_server = redis.Redis(connection_pool=pool)\n\n followers_list = r_server.lrange(\"followers:%s\" % (user_id), 0, -1)\n\n # Now for each follower_id in followers_list, find their homefeed key \n # in Redis and insert the photo_id into that homefeed list.\n\n for follower_id in followers_list:\n homefeed_list = r_server.lpush(\"homefeed:%s\" % (follower_id), photo_id)\n return \"Fan Out Completed for %s\" % (user_id)\n```\n\nIn this task, when called from the Django view, it will grab all the IDs of the people who user 343 and then insert the photo ID into all of their homefeed lists.\n\nHere is my upload view in my proj/mydjangoapp/views.py. I basically call celery's delay method and pass on the neccessary variables so that the request ends quickly:\n\n```\n# Import the Celery Task Here\nfrom mydjangoapp.tasks import insert_into_homefeed\n\n@csrf_exempt\ndef Upload(request):\n if request.method == 'POST':\n data = json.loads(request.body)\n newPhoto = Photo.objects.create(user_id = data['user_id'], description= data['description'], photo_url = data['photo_url'])\n newPhoto_ID = newPhoto.pk\n insert_into_homefeed.delay(newPhoto_ID, data['user_id'])\n return HttpResponse(\"Request Completed\")\n```\n\nHow can I do this in such a way that it will be batched by 10,000?\n\n========================================\n\nCode:\n```text\nfollowers:343\n```\n\n```text\nhomefeed:1990\n```\n\n```text\n>>> r_server.lrange(\"followers:343\", 0, -1)\n['8', '7', '5', '3', '65', '342', '42', etc...] ---> for the sake of example, assume this list has another 20,000 IDs.\n```\n\n```text\nfrom __future__ import absolute_import\nfrom celery import shared_task\nimport redis\npool = redis.ConnectionPool(host='XX.XXX.XXX.X', port=6379, db=0, password='XXXXX')\n\n@shared_task\ndef insert_into_homefeed(photo_id, user_id):\n # Grab the list of all follower IDs from Redis for user_id.\n r_server = redis.Redis(connection_pool=pool)\n\n followers_list = r_server.lrange(\"followers:%s\" % (user_id), 0, -1)\n\n # Now for each follower_id in followers_list, find their homefeed key \n # in Redis and insert the photo_id into that homefeed list.\n\n for follower_id in followers_list:\n homefeed_list = r_server.lpush(\"homefeed:%s\" % (follower_id), photo_id)\n return \"Fan Out Completed for %s\" % (user_id)\n```\n\n```text\n# Import the Celery Task Here\nfrom mydjangoapp.tasks import insert_into_homefeed\n\n\n@csrf_exempt\ndef Upload(request):\n if request.method == 'POST':\n data = json.loads(request.body)\n newPhoto = Photo.objects.create(user_id = data['user_id'], description= data['description'], photo_url = data['photo_url'])\n newPhoto_ID = newPhoto.pk\n insert_into_homefeed.delay(newPhoto_ID, data['user_id'])\n return HttpResponse(\"Request Completed\")\n```\n\n```text\nINSERT_INTO_HOMEFEED_BATCH = 10000\n\n@shared_task\ndef insert_into_homefeed(photo_id, user_id, index=0):\n # Grab the list of all follower IDs from Redis for user_id.\n r_server = redis.Redis(connection_pool=pool)\n\n range_limit = index + INSERT_INTO_HOMEFEED_BATCH - 1 # adjust for zero-index\n\n followers_list_batch = r_server.lrange(\"followers:%s\" % (user_id), index, range_limit)\n\n if not followers_list_batch:\n return # zero followers or no more batches\n\n # Now for each follower_id in followers_list_batch, find their homefeed key \n # in Redis and insert the photo_id into that homefeed list.\n for follower_id in followers_list:\n homefeed_list = r_server.lpush(\"homefeed:%s\" % (follower_id), photo_id)\n\n insert_into_homefeed.delay(photo_id, user_id, range_limit + 1)\n```\n\n========================================\n\nComments:\n- Thanks for the quick reply! :) nice approach! But wouldn't this be an infinite loop? Won't the task keep getting called over and over again even after I have run through the entire list?\n- Ahh! I just saw the if followers_list_batch:\n- You got it. That's probably a good indication I should have used explicit return statements.","metadata":{"transformedAt":"2026-08-18T18:33:20.154Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":161,"estimatedTokens":1821}}409{"id":"stack-17841843","source":"stackoverflow","questionId":17841843,"title":"RabbitMQ - Does one consumer block the other consumers of the same queue?","tags":["rabbitmq","amqp"],"text":"Title: RabbitMQ - Does one consumer block the other consumers of the same queue?\nTags: rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI'm in a phase of learning RabbitMQ/AMQP from the RabbitMQ documentation. Something that is not clear to me that I wanted to ask those who have hands-on experience.\nI want to have multiple consumers listening to the same queue in order to balance the work load. What I need is pretty much close to the \"Work Queues\" example in the RabbitMQ tutorial.\nI want the consumer to acknowledge message explicitly after it finishes handling it to preserve the message and delegate it to another consumer in case of crash. Handling a message may take a while.\nMy question is whether AMQP postpones next message processing until the previous message is ack'ed? If so how do I achieve load balancing between multiple workers and guarantee no messages get lost?\n\n========================================\n\nComments:\n- Thanks. Actually I couldn't find the answer to the first part (\"No, the other consumers don't get blocked.\") anywhere in the docs. It is exactly the behavior I'm looking for. On the other hand it breaks the queue semantics, doesn't it? The messages may be processed out of order.\n- Edited the answer. Yes, the messages may be processed by the consumers out of order.\n- Thanks for adding the clarification about FIFO. Thorough and clear answer.\n- @flup If an unacknowledged message gets nack or reject, where does it go? At the top or bottom of the queue ?\n- @guiomie That is implementation-specific. the docs say: [...] Any of these scenarios caused messages to be requeued at the back of the queue for RabbitMQ releases earlier than 2.7.0. From RabbitMQ release 2.7.0, messages are always held in the queue in publication order, even in the presence of requeueing or channel closure.\n- Are you aware if theres a way to apply pre-2.7.0 behavior to a post 2.7.0 rabbitmq ?\n- If there is exactly one consumer and only message gets delivered to consumer at a time, why there remains more than one message unacknowledged ?","metadata":{"transformedAt":"2026-08-18T18:33:20.154Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":20,"estimatedTokens":515}}410{"id":"stack-22862970","source":"stackoverflow","questionId":22862970,"title":"Sending RabbitMQ messages via websockets","tags":["node.js","websocket","rabbitmq","node-amqp","python-pika"],"text":"Title: Sending RabbitMQ messages via websockets\nTags: node.js, websocket, rabbitmq, node-amqp, python-pika\nSource: Stack Overflow\n\nQuestion:\nLooking for some code samples to solve this problem :-\n\nWould like to write some code (Python or Javascript) that would act as a subscriber to a RabbitMQ queue so that on receiving a message it would broadcast the message via websockets to any connected client. \n\nI've looked at Autobahn and node.js (using \"amqp\" and \"ws\" ) but cannot get things to work as needed. Here's the server code in javascript using node.js:-\n\n```\nvar amqp = require('amqp');\nvar WebSocketServer = require('ws').Server\n\nvar connection = amqp.createConnection({host: 'localhost'});\nvar wss = new WebSocketServer({port:8000});\n\nwss.on('connection',function(ws){\n\n ws.on('open', function() {\n console.log('connected');\n ws.send(Date.now().toString());\n });\n\n ws.on('message',function(message){\n console.log('Received: %s',message);\n ws.send(Date.now().toString());\n });\n});\n\nconnection.on('ready', function(){\n connection.queue('MYQUEUE', {durable:true,autoDelete:false},function(queue){\n console.log(' [*] Waiting for messages. To exit press CTRL+C')\n queue.subscribe(function(msg){\n console.log(\" [x] Received from MYQUEUE %s\",msg.data.toString('utf-8'));\n payload = msg.data.toString('utf-8');\n // HOW DOES THIS NOW GET SENT VIA WEBSOCKETS ??\n });\n });\n});\n```\n\nUsing this code, I can successfully subscribe to a queue in Rabbit and receive any messages that are sent to the queue. Similarly, I can connect a websocket client (e.g. a browser) to the server and send/receive messages. BUT ... how can I send the payload of the Rabbit queue message as a websocket message at the point indicated (\"HOW DOES THIS NOW GET SENT VIA WEBSOCKETS\") ? I think it's something to do with being stuck in the wrong callback or they need to be nested somehow ...?\n\nAlternatively, if this can be done easier in Python (via Autobahn and pika) that would be great.\n\nThanks !\n\n========================================\n\nCode:\n```text\nvar amqp = require('amqp');\nvar WebSocketServer = require('ws').Server\n\nvar connection = amqp.createConnection({host: 'localhost'});\nvar wss = new WebSocketServer({port:8000});\n\nwss.on('connection',function(ws){\n\n ws.on('open', function() {\n console.log('connected');\n ws.send(Date.now().toString());\n });\n\n ws.on('message',function(message){\n console.log('Received: %s',message);\n ws.send(Date.now().toString());\n });\n});\n\nconnection.on('ready', function(){\n connection.queue('MYQUEUE', {durable:true,autoDelete:false},function(queue){\n console.log(' [*] Waiting for messages. To exit press CTRL+C')\n queue.subscribe(function(msg){\n console.log(\" [x] Received from MYQUEUE %s\",msg.data.toString('utf-8'));\n payload = msg.data.toString('utf-8');\n // HOW DOES THIS NOW GET SENT VIA WEBSOCKETS ??\n });\n });\n});\n```\n\n```text\nimport tornado.ioloop\n import tornado.web\n import tornado.websocket\n import os\n import pika\n from threading import Thread\n\n\n clients = []\n\n def threaded_rmq():\n connection = pika.BlockingConnection(pika.ConnectionParameters(\"localhost\"));\n print 'Connected:localhost'\n channel = connection.channel()\n channel.queue_declare(queue=\"my_queue\")\n print 'Consumer ready, on my_queue'\n channel.basic_consume(consumer_callback, queue=\"my_queue\", no_ack=True) \n channel.start_consuming()\n\n\n def consumer_callback(ch, method, properties, body):\n print \" [x] Received %r\" % (body,)\n for itm in clients:\n itm.write_message(body)\n\n class SocketHandler(tornado.websocket.WebSocketHandler):\n def open(self):\n print \"WebSocket opened\"\n clients.append(self)\n def on_message(self, message):\n self.write_message(u\"You said: \" + message)\n\n def on_close(self):\n print \"WebSocket closed\"\n clients.remove(self)\n\n\n class MainHandler(tornado.web.RequestHandler):\n def get(self):\n print \"get page\"\n self.render(\"websocket.html\")\n\n\napplication = tornado.web.Application([\n (r'/ws', SocketHandler),\n (r\"/\", MainHandler),\n])\n\nif __name__ == \"__main__\":\n thread = Thread(target = threaded_rmq)\n thread.start()\n\n application.listen(8889)\n tornado.ioloop.IOLoop.instance().start()\n```\n\n```text\n<html>\n<head>\n <script src=\"//code.jquery.com/jquery-1.11.0.min.js\"></script>\n <script>\n\n $(document).ready(function() {\n var ws;\n if ('WebSocket' in window) {\n ws = new WebSocket('ws://localhost:8889/ws');\n }\n else if ('MozWebSocket' in window) {\n ws = new MozWebSocket('ws://localhost:8889/ws');\n }\n else {\n\n alert(\"<tr><td> your browser doesn't support web socket </td></tr>\");\n\n return;\n }\n\n ws.onopen = function(evt) { alert(\"Connection open ...\")};\n\n ws.onmessage = function(evt){\n alert(evt.data);\n };\n\n function closeConnect(){\n ws.close();\n }\n\n\n });\n </script>\n\n</head>\n\n<html>\n```\n\n========================================\n\nComments:\n- Is it a problem if the web-pages access directly to RabbitMQ.? because a faster way is: rabbitmq.com/web-stomp.html\n- Thanks for the suggestion. I had seen this plug-in, but I don't want the web pages to access the MQ messages directly, because they need to be processed before being available to the web page.\n- You are welcome. This is just a skeleton you have to handle the close application, now it doesn't close the connection with rabbitmq!","metadata":{"transformedAt":"2026-08-18T18:33:20.154Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":187,"estimatedTokens":1434}}411{"id":"stack-63971973","source":"stackoverflow","questionId":63971973,"title":"Celery in Docker container: ERROR/MainProcess consumer: Cannot connect to redis","tags":["python","docker","redis","rabbitmq","celery"],"text":"Title: Celery in Docker container: ERROR/MainProcess consumer: Cannot connect to redis\nTags: python, docker, redis, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nA lot of frustration on this, been trying to make it work for days. I beg for help.\n\nIt's a Django project with Postgres, Celery and Docker.\nFirst I tried with RabbitMQ, and I had the same error than now with Redis, then I changed to redis after multiple tries and the error is still the same, so I think the problem is around Celery, not RabbitMQ/Redis.\n\n**Dockerfile:**\n\n```\nFROM python:3.8.5-alpine\n\nENV PYTHONUNBUFFERED 1\n\nRUN apk update \\\n # psycopg2 dependencies\n && apk add --virtual build-deps gcc python3-dev musl-dev \\\n && apk add postgresql-dev \\\n # Pillow dependencies\n && apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev \\\n # Translation dependencies\n && apk add gettext \\\n # CFFI dependencies\n && apk add libffi-dev py-cffi \\\n && apk add --no-cache openssl-dev libffi-dev \\\n && apk add --no-cache --virtual .pynacl_deps build-base python3-dev libffi-dev\n\nRUN mkdir /app\nWORKDIR /app\nCOPY requirements.txt /app/\nRUN pip install -r requirements.txt\nCOPY . /app/\n```\n\n**docker-compose.yml:**\n\n```\nversion: '3'\n\nvolumes:\n local_postgres_data: {}\n\nservices:\n postgres:\n image: postgres\n environment:\n - POSTGRES_DB=postgres\n - POSTGRES_USER=postgres\n - POSTGRES_PASSWORD=postgres\n volumes:\n - local_postgres_data:/var/lib/postgresql/data\n env_file:\n - ./.envs/.postgres\n\n django: &django\n build: .\n command: python manage.py runserver 0.0.0.0:8000\n volumes:\n - .:/app/\n ports:\n - \"8000:8000\"\n depends_on:\n - postgres\n\n redis:\n image: redis:6.0.8\n\n celeryworker:\n **pyrty/pyrty/celery.py:**\n\n```\nfrom __future__ import absolute_import, unicode_literals\n\nimport os\n\nfrom celery import Celery\n\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pyrty.settings')\n\napp = Celery('pyrty')\n\napp.config_from_object('django.conf:settings', namespace='CELERY')\n\napp.autodiscover_tasks()\n\n@app.task(bind=True)\ndef debug_task(self):\n print('Request: {0!r}'.format(self.request))\n```\n\n**pyrty/pyrty/settings.py:**\n\n```\n# Celery conf\nCELERY_BROKER_URL = 'redis://127.0.0.1:6379/0' #also tried localhost and\nCELERY_RESULT_BACKEND = 'redis://127.0.0.1:6379/0' #also tried without the '/0'\nCELERY_ACCEPT_CONTENT = ['json']\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_TIMEZONE = 'America/Argentina/Buenos_Aires'\n```\n\n**pyrty/pyrty/init**.py:\n\n```\nfrom __future__ import absolute_import, unicode_literals\n\nfrom .celery import app as celery_app\n\n__all__ = ('celery_app',)\n```\n\n**requirements.txt:**\n\n```\nDjango==3.1\npsycopg2==2.8.3\ndjangorestframework==3.11.0\ncelery==4.4.7\nredis==3.5.3\nPillow==7.1.2\ndjango-extensions==2.2.9\namqp==2.6.1\nbilliard==3.6.3\nkombu==4.6.11\nvine==1.3.0\npytz==2020.1\n```\n\nThat's all the configuration, then when I do `docker-compose up` I get the following (regarding Celery and Redis) in the terminal:\n\n```\nredis_1 | 1:M 19 Sep 2020 18:09:08.117 # Server initialized\nredis_1 | 1:M 19 Sep 2020 18:09:08.117 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.\nredis_1 | 1:M 19 Sep 2020 18:09:08.118 * Loading RDB produced by version 6.0.8\nredis_1 | 1:M 19 Sep 2020 18:09:08.118 * RDB age 16 seconds\nredis_1 | 1:M 19 Sep 2020 18:09:08.118 * RDB memory usage when created 0.77 Mb\nredis_1 | 1:M 19 Sep 2020 18:09:08.118 * DB loaded from disk: 0.000 seconds\nredis_1 | 1:M 19 Sep 2020 18:09:08.118 * Ready to accept connections\n\nceleryworker_1 | \nceleryworker_1 | -------------- celery@f334b468b079 v4.4.7 (cliffs)\nceleryworker_1 | --- ***** ----- \nceleryworker_1 | -- ******* ---- Linux-5.4.0-47-generic-x86_64-with 2020-09-19 18:09:16\nceleryworker_1 | - *** --- * --- \nceleryworker_1 | - ** ---------- [config]\nceleryworker_1 | - ** ---------- .> app: pyrty:0x7fd280ac7640\nceleryworker_1 | - ** ---------- .> transport: redis://127.0.0.1:6379/0\nceleryworker_1 | - ** ---------- .> results: redis://127.0.0.1:6379/0\nceleryworker_1 | - *** --- * --- .> concurrency: 6 (prefork)\nceleryworker_1 | -- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)\nceleryworker_1 | --- ***** ----- \nceleryworker_1 | -------------- [queues]\nceleryworker_1 | .> celery exchange=celery(direct) key=celery\nceleryworker_1 | \nceleryworker_1 | \nceleryworker_1 | [tasks]\nceleryworker_1 | . pyrty.celery.debug_task\nceleryworker_1 | \nceleryworker_1 | [2020-09-19 18:09:16,865: ERROR/MainProcess] consumer: Cannot connect to redis://127.0.0.1:6379/0: Error 111 connecting to 127.0.0.1:6379. Connection refused..\nceleryworker_1 | Trying again in 2.00 seconds... (1/100)\nceleryworker_1 | \nceleryworker_1 | [2020-09-19 18:09:18,871: ERROR/MainProcess] consumer: Cannot connect to redis://127.0.0.1:6379/0: Error 111 connecting to 127.0.0.1:6379. Connection refused..\nceleryworker_1 | Trying again in 4.00 seconds... (2/100)\n```\n\nI really don't get what I am missing, I've been reading documentation but I cannot solve this. Please help!\n\n========================================\n\nCode:\n```text\nFROM python:3.8.5-alpine\n\nENV PYTHONUNBUFFERED 1\n\nRUN apk update \\\n # psycopg2 dependencies\n && apk add --virtual build-deps gcc python3-dev musl-dev \\\n && apk add postgresql-dev \\\n # Pillow dependencies\n && apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev \\\n # Translation dependencies\n && apk add gettext \\\n # CFFI dependencies\n && apk add libffi-dev py-cffi \\\n && apk add --no-cache openssl-dev libffi-dev \\\n && apk add --no-cache --virtual .pynacl_deps build-base python3-dev libffi-dev\n\nRUN mkdir /app\nWORKDIR /app\nCOPY requirements.txt /app/\nRUN pip install -r requirements.txt\nCOPY . /app/\n```\n\n```text\nversion: '3'\n\nvolumes:\n local_postgres_data: {}\n\nservices:\n postgres:\n image: postgres\n environment:\n - POSTGRES_DB=postgres\n - POSTGRES_USER=postgres\n - POSTGRES_PASSWORD=postgres\n volumes:\n - local_postgres_data:/var/lib/postgresql/data\n env_file:\n - ./.envs/.postgres\n\n django: &django\n build: .\n command: python manage.py runserver 0.0.0.0:8000\n volumes:\n - .:/app/\n ports:\n - \"8000:8000\"\n depends_on:\n - postgres\n\n redis:\n image: redis:6.0.8\n\n celeryworker:\n <<: *django\n image: pyrty_celeryworker\n depends_on:\n - redis\n - postgres\n ports: []\n command: celery -A pyrty worker -l INFO\n\n celerybeat:\n <<: *django\n image: pyrty_celerybeat\n depends_on:\n - redis\n - postgres\n ports: []\n command: celery -A pyrty beat -l INFO\n```\n\n```text\nfrom __future__ import absolute_import, unicode_literals\n\nimport os\n\nfrom celery import Celery\n\n\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pyrty.settings')\n\napp = Celery('pyrty')\n\napp.config_from_object('django.conf:settings', namespace='CELERY')\n\napp.autodiscover_tasks()\n\n\n@app.task(bind=True)\ndef debug_task(self):\n print('Request: {0!r}'.format(self.request))\n```\n\n```text\n# Celery conf\nCELERY_BROKER_URL = 'redis://127.0.0.1:6379/0' #also tried localhost and\nCELERY_RESULT_BACKEND = 'redis://127.0.0.1:6379/0' #also tried without the '/0'\nCELERY_ACCEPT_CONTENT = ['json']\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_TIMEZONE = 'America/Argentina/Buenos_Aires'\n```\n\n```text\nfrom __future__ import absolute_import, unicode_literals\n\nfrom .celery import app as celery_app\n\n\n__all__ = ('celery_app',)\n```\n\n```text\nDjango==3.1\npsycopg2==2.8.3\ndjangorestframework==3.11.0\ncelery==4.4.7\nredis==3.5.3\nPillow==7.1.2\ndjango-extensions==2.2.9\namqp==2.6.1\nbilliard==3.6.3\nkombu==4.6.11\nvine==1.3.0\npytz==2020.1\n```\n\n```text\nredis_1 | 1:M 19 Sep 2020 18:09:08.117 # Server initialized\nredis_1 | 1:M 19 Sep 2020 18:09:08.117 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.\nredis_1 | 1:M 19 Sep 2020 18:09:08.118 * Loading RDB produced by version 6.0.8\nredis_1 | 1:M 19 Sep 2020 18:09:08.118 * RDB age 16 seconds\nredis_1 | 1:M 19 Sep 2020 18:09:08.118 * RDB memory usage when created 0.77 Mb\nredis_1 | 1:M 19 Sep 2020 18:09:08.118 * DB loaded from disk: 0.000 seconds\nredis_1 | 1:M 19 Sep 2020 18:09:08.118 * Ready to accept connections\n\nceleryworker_1 | \nceleryworker_1 | -------------- celery@f334b468b079 v4.4.7 (cliffs)\nceleryworker_1 | --- ***** ----- \nceleryworker_1 | -- ******* ---- Linux-5.4.0-47-generic-x86_64-with 2020-09-19 18:09:16\nceleryworker_1 | - *** --- * --- \nceleryworker_1 | - ** ---------- [config]\nceleryworker_1 | - ** ---------- .> app: pyrty:0x7fd280ac7640\nceleryworker_1 | - ** ---------- .> transport: redis://127.0.0.1:6379/0\nceleryworker_1 | - ** ---------- .> results: redis://127.0.0.1:6379/0\nceleryworker_1 | - *** --- * --- .> concurrency: 6 (prefork)\nceleryworker_1 | -- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)\nceleryworker_1 | --- ***** ----- \nceleryworker_1 | -------------- [queues]\nceleryworker_1 | .> celery exchange=celery(direct) key=celery\nceleryworker_1 | \nceleryworker_1 | \nceleryworker_1 | [tasks]\nceleryworker_1 | . pyrty.celery.debug_task\nceleryworker_1 | \nceleryworker_1 | [2020-09-19 18:09:16,865: ERROR/MainProcess] consumer: Cannot connect to redis://127.0.0.1:6379/0: Error 111 connecting to 127.0.0.1:6379. Connection refused..\nceleryworker_1 | Trying again in 2.00 seconds... (1/100)\nceleryworker_1 | \nceleryworker_1 | [2020-09-19 18:09:18,871: ERROR/MainProcess] consumer: Cannot connect to redis://127.0.0.1:6379/0: Error 111 connecting to 127.0.0.1:6379. Connection refused..\nceleryworker_1 | Trying again in 4.00 seconds... (2/100)\n```\n\n```text\ndocker-compose up\n```\n\n```text\n# Celery conf\nCELERY_BROKER_URL = 'redis://redis:6379/0'\nCELERY_RESULT_BACKEND = 'redis://redis:6379/0'\n```\n\n```text\nredis\n```\n\n```text\n127.0.0.1\n```\n\n========================================\n\nComments:\n- Can you verify whether Redis server is running or not. You can use command line to determine if redis is running: `redis-cli ping` you should get back `PONG`\n- Abosolute hero!!!!!!! This also worked doing it back with rabbitmq (CELERY_BROKER_URL = 'amqp://rabbitmq:5672'), therefore I didn't have to change rabbit for redis.\n- Frustration is on my side as well, as I have tried to fiddle around with correct URLs, but always get an ERROR/MainProcess] consumer: Cannot connect to redis://redis:6379//: Error -3 connecting to redis:6379. What does ERROR -3 mean?","metadata":{"transformedAt":"2026-08-18T18:33:20.154Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":11,"totalLines":364,"estimatedTokens":2723}}412{"id":"stack-5361521","source":"stackoverflow","questionId":5361521,"title":"Celery task schedule (Celery, Django and RabbitMQ)","tags":["rabbitmq","celery","django-celery"],"text":"Title: Celery task schedule (Celery, Django and RabbitMQ)\nTags: rabbitmq, celery, django-celery\nSource: Stack Overflow\n\nQuestion:\nI want to have a task that will execute every 5 minutes, but it will wait for last execution to finish and then start to count this 5 minutes. (This way I can also be sure that there is only one task running) The easiest way I found is to run django application manage.py shell and run this:\n\n```\nwhile True:\n result = task.delay()\n result.wait()\n sleep(5)\n```\n\nbut for each task that I want to execute this way I have to run it's own shell, is there an easy way to do it? May be some king custom ot django celery scheduler?\n\n========================================\n\nTop Answer:\nWow it's amazing how no one understands this person's question. They are asking not about running tasks periodically, but how to ensure that Celery does not run two instances of the same task simultaneously. I don't think there's a way to do this with Celery directly, but what you can do is have one of the tasks acquire a lock right when it begins, and if it fails, to try again in a few seconds (using retry). The task would release the lock right before it returns; you can make the lock auto-expire after a few minutes if it ever crashes or times out. \n\nFor the lock you can probably just use your database or something like Redis.\n\n========================================\n\nCode:\n```text\nwhile True:\n result = task.delay()\n result.wait()\n sleep(5)\n```\n\n```text\nfrom datetime import timedelta\n\nCELERYBEAT_SCHEDULE = {\n \"runs-every-30-seconds\": {\n \"task\": \"tasks.add\",\n \"schedule\": timedelta(seconds=30),\n \"args\": (16, 16)\n },\n}\n```\n\n```text\nmanage celeryd -B\n```\n\n```text\nCELERYBEAT_SCHEDULER = \"djcelery.schedulers.DatabaseScheduler\"\n```\n\n```text\n@celery.decorators.periodic_task(run_every=datetime.timedelta(minutes=5))\ndef my_task():\n # Insert fun-stuff here\n```\n\n```text\nfrom celery.task.base import periodic_task\nfrom django.utils.timezone import timedelta\n\n@periodic_task(run_every=timedelta(seconds=5))\ndef my_background_process():\n # insert code\n```\n\n========================================\n\nComments:\n- The problem with this is that it will not wait for task to finish, but will just send another task when it's time (every 30 seconds). Or may be I'm wrong?\n- Thank you for advice, but I think I want something else - I want to create a job, send it for execution, and create another job ONLY when the EXECUTION of previous one is finished. I don't want to create jobs until I know that the previous one is finished. I want the task to have synchronous (not asynchronous) behavior\n- The global objective is to run a task for which I can't tell how much time it will take and when it's finished wait for some time and start it again. Also I have to be sure that it will not be executed 2 or more times simultaneously by different worker threads, and also that I don't have to write my own program code to do this.\n- If you want to make sure a task only starts after the last one finished, use memcached (or django cache) to create a lock on the task type or resource in said task. Its easy and scalable to do.\n- @MauroRocco This is not true, at least as of 3.0.12, `celery beat` will most certainly create overlapping tasks.\n- Sorry, about the question, but what if task takes 20 seconds to complete, will it run in 0:30 (1-st), finish in 0:50 and then start in 1:20 (this is what I really want)\n- If you want that the task run every 30 seconds independently from the duration than you have to use a crontab schedule, but remember that this task are added to the celery queue and if there is other tasks in execution/in queue your are not sure that you task start at the given time.\n- I got an error 'Celery' object has no attribute 'decorators'. Any idea about this? I wrote @celery.decorators.periodic_task(run_every=datetime.timedelt‌​a(minutes=5)) above my task.\n- The newest version of celery doesn't have this decorator. You'll have to just use the instructions here: docs.celeryproject.org/en/latest/userguide/periodic-tasks.ht‌​ml\n- +1. The only person to address the unique instance issue! Details on how to implement a lock if you are using a django database can be found here: stackoverflow.com/questions/4095940/…","metadata":{"transformedAt":"2026-08-18T18:33:20.154Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":81,"estimatedTokens":1081}}413{"id":"stack-31369854","source":"stackoverflow","questionId":31369854,"title":"RabbitMQ durable queue does not work (RPC-Server, RPC-Client)","tags":["c#","rabbitmq"],"text":"Title: RabbitMQ durable queue does not work (RPC-Server, RPC-Client)\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI wondering why my RabbitMQ RPC-Client always processed the dead messages after restart. `_channel.QueueDeclare(queue, false, false, false, null);` should disable buffers. If I overload the `QueueDeclare` inside the RPC-Client I can't connect to the server. Is something wrong here? Any idea how to fix this problem?\n\n**RPC-Server**\n\n```\nnew Thread(() =>\n{\n var factory = new ConnectionFactory { HostName = _hostname };\n if (_port > 0)\n factory.Port = _port;\n _connection = factory.CreateConnection();\n _channel = _connection.CreateModel();\n\n _channel.QueueDeclare(queue, false, false, false, null);\n _channel.BasicQos(0, 1, false);\n var consumer = new QueueingBasicConsumer(_channel);\n _channel.BasicConsume(queue, false, consumer);\n IsRunning = true;\n while (IsRunning)\n {\n BasicDeliverEventArgs ea;\n try {\n ea = consumer.Queue.Dequeue();\n }\n catch (Exception ex) {\n IsRunning = false;\n }\n var body = ea.Body;\n var props = ea.BasicProperties;\n var replyProps = _channel.CreateBasicProperties();\n replyProps.CorrelationId = props.CorrelationId;\n\n var xmlRequest = Encoding.UTF8.GetString(body);\n\n var messageRequest = XmlSerializer.DeserializeObject(xmlRequest, typeof(Message)) as Message;\n var messageResponse = handler(messageRequest);\n\n _channel.BasicPublish(\"\", props.ReplyTo, replyProps,\n messageResponse);\n _channel.BasicAck(ea.DeliveryTag, false);\n }\n}).Start();\n```\n\n**RPC-Client**\n\n```\npublic void Start()\n{\n if (IsRunning)\n return;\n var factory = new ConnectionFactory { \n HostName = _hostname,\n Endpoint = _port <= 0 ? new AmqpTcpEndpoint(_endpoint) \n : new AmqpTcpEndpoint(_endpoint, _port)\n };\n _connection = factory.CreateConnection();\n _channel = _connection.CreateModel();\n _replyQueueName = _channel.QueueDeclare(); // Do not connect any more\n _consumer = new QueueingBasicConsumer(_channel);\n _channel.BasicConsume(_replyQueueName, true, _consumer);\n IsRunning = true;\n}\n\npublic Message Call(Message message)\n{\n if (!IsRunning)\n throw new Exception(\"Connection is not open.\");\n var corrId = Guid.NewGuid().ToString().Replace(\"-\", \"\");\n var props = _channel.CreateBasicProperties();\n props.ReplyTo = _replyQueueName;\n props.CorrelationId = corrId;\n\n if (!String.IsNullOrEmpty(_application))\n props.AppId = _application;\n\n message.InitializeProperties(_hostname, _nodeId, _uniqueId, props);\n\n var messageBytes = Encoding.UTF8.GetBytes(XmlSerializer.ConvertToString(message));\n _channel.BasicPublish(\"\", _queue, props, messageBytes);\n\n try \n {\n while (IsRunning)\n {\n var ea = _consumer.Queue.Dequeue();\n if (ea.BasicProperties.CorrelationId == corrId)\n {\n var xmlResponse = Encoding.UTF8.GetString(ea.Body);\n try\n {\n return XmlSerializer.DeserializeObject(xmlResponse, typeof(Message)) as Message;\n }\n catch(Exception ex)\n {\n IsRunning = false;\n return null;\n }\n }\n }\n }\n catch (EndOfStreamException ex)\n {\n IsRunning = false;\n return null;\n }\n return null;\n}\n```\n\n========================================\n\nCode:\n```text\nnew Thread(() =>\n{\n var factory = new ConnectionFactory { HostName = _hostname };\n if (_port > 0)\n factory.Port = _port;\n _connection = factory.CreateConnection();\n _channel = _connection.CreateModel();\n\n _channel.QueueDeclare(queue, false, false, false, null);\n _channel.BasicQos(0, 1, false);\n var consumer = new QueueingBasicConsumer(_channel);\n _channel.BasicConsume(queue, false, consumer);\n IsRunning = true;\n while (IsRunning)\n {\n BasicDeliverEventArgs ea;\n try {\n ea = consumer.Queue.Dequeue();\n }\n catch (Exception ex) {\n IsRunning = false;\n }\n var body = ea.Body;\n var props = ea.BasicProperties;\n var replyProps = _channel.CreateBasicProperties();\n replyProps.CorrelationId = props.CorrelationId;\n\n var xmlRequest = Encoding.UTF8.GetString(body);\n\n var messageRequest = XmlSerializer.DeserializeObject(xmlRequest, typeof(Message)) as Message;\n var messageResponse = handler(messageRequest);\n\n _channel.BasicPublish(\"\", props.ReplyTo, replyProps,\n messageResponse);\n _channel.BasicAck(ea.DeliveryTag, false);\n }\n}).Start();\n```\n\n```text\npublic void Start()\n{\n if (IsRunning)\n return;\n var factory = new ConnectionFactory { \n HostName = _hostname,\n Endpoint = _port <= 0 ? new AmqpTcpEndpoint(_endpoint) \n : new AmqpTcpEndpoint(_endpoint, _port)\n };\n _connection = factory.CreateConnection();\n _channel = _connection.CreateModel();\n _replyQueueName = _channel.QueueDeclare(); // Do not connect any more\n _consumer = new QueueingBasicConsumer(_channel);\n _channel.BasicConsume(_replyQueueName, true, _consumer);\n IsRunning = true;\n}\n\npublic Message Call(Message message)\n{\n if (!IsRunning)\n throw new Exception(\"Connection is not open.\");\n var corrId = Guid.NewGuid().ToString().Replace(\"-\", \"\");\n var props = _channel.CreateBasicProperties();\n props.ReplyTo = _replyQueueName;\n props.CorrelationId = corrId;\n\n if (!String.IsNullOrEmpty(_application))\n props.AppId = _application;\n\n message.InitializeProperties(_hostname, _nodeId, _uniqueId, props);\n\n var messageBytes = Encoding.UTF8.GetBytes(XmlSerializer.ConvertToString(message));\n _channel.BasicPublish(\"\", _queue, props, messageBytes);\n\n try \n {\n while (IsRunning)\n {\n var ea = _consumer.Queue.Dequeue();\n if (ea.BasicProperties.CorrelationId == corrId)\n {\n var xmlResponse = Encoding.UTF8.GetString(ea.Body);\n try\n {\n return XmlSerializer.DeserializeObject(xmlResponse, typeof(Message)) as Message;\n }\n catch(Exception ex)\n {\n IsRunning = false;\n return null;\n }\n }\n }\n }\n catch (EndOfStreamException ex)\n {\n IsRunning = false;\n return null;\n }\n return null;\n}\n```\n\n```text\n_channel.QueueDeclare(queue, false, false, false, null);\n```\n\n```text\nQueueDeclare\n```\n\n```text\npublic Message Call(Message message)\n{\n ...\n var props = _channel.CreateBasicProperties();\n props.DeliveryMode = 1; //you might want to do this in your RPC-Server as well\n ...\n}\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.154Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":239,"estimatedTokens":1615}}414{"id":"stack-45031418","source":"stackoverflow","questionId":45031418,"title":"Where to set up of the binding of exchange and queue (producer vs. consumer)?","tags":["rabbitmq","amqp"],"text":"Title: Where to set up of the binding of exchange and queue (producer vs. consumer)?\nTags: rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nAll of the official RabbitMQ examples set up the queues and bindings in the **consumer**. The Publish/Subscribe tutorial states that\n\n The messages will be lost if no queue is bound to the exchange yet, but that's \n okay for us; if no consumer is listening yet we can safely discard the message.\n\nThis is absolutely not okay for me, because I'm implementing a job worker queue on top of RabbitMQ, and it is important to not lose any messages when the consumer hasn't run yet. Therefore, I'm thinking of establishing the exchange queue routing in the **producer**. Is there a reason why the examples do it the other way around?\n\nAs an aside, is it considered best practice to do the basic exchange/queue/routing setup every time I connect to the RabbitMQ server or just once (ever) to basically configure the RabbitMQ instance? My current approach to publish a message currently looks a bit like this:\n\n```\nconst getChannel = () => \n ampq.connect() // The real implementation caches the connection\n .then(conn => conn.createChannel())\n .then(channel => channel.assertExchange(...)\n .then(() => channel.assertQueue(...)) // Assert and bind for all queues\n .then(() => channel.bindQueue(...)) // Assert and bind for all queues\n );\n\nconst publish = (task, payload) => \n getChannel().then(channel => \n channel.publish(exchange, task, payload)\n );\n```\n\n========================================\n\nCode:\n```js\nconst getChannel = () => \n ampq.connect() // The real implementation caches the connection\n .then(conn => conn.createChannel())\n .then(channel => channel.assertExchange(...)\n .then(() => channel.assertQueue(...)) // Assert and bind for all queues\n .then(() => channel.bindQueue(...)) // Assert and bind for all queues\n );\n\nconst publish = (task, payload) => \n getChannel().then(channel => \n channel.publish(exchange, task, payload)\n );\n```\n\n========================================\n\nComments:\n- Thanks! I'm currently setting up two different queues for unrelated jobs (say `media` and `bookings`), both linked to one (direct routed) exchange and binding all possible job tasks via dedicated routing keys to either of the two queues. Does that make sense? Or is there a better approach to map tasks to specific queues (perhaps using Topics)?\n- Yes, it makes sense as long as you want your message routed to just one single queue. Topic exchanges could be good if you would like your message to be sent to many different queues, where a lot of services can subscribe to one job. E.g when you have multiple services/workers that needs to take different actions on one single message.\n- would it not make sense to do all common exchange/queue declarations in both consumers and producers?","metadata":{"transformedAt":"2026-08-18T18:33:20.154Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":53,"estimatedTokens":714}}415{"id":"stack-31360918","source":"stackoverflow","questionId":31360918,"title":"Celery chain not working with batches","tags":["python","rabbitmq","celery","celery-task"],"text":"Title: Celery chain not working with batches\nTags: python, rabbitmq, celery, celery-task\nSource: Stack Overflow\n\nQuestion:\nAt first glance I liked very much the \"Batches\" feature in Celery because I need to group an amount of IDs before calling an API (otherwise I may be kicked out).\n\nUnfortunately, when testing a little bit, batch tasks don't seem to play well with the rest of the Canvas primitives, in this case, chains. For example:\n\n```\n@a.task(base=Batches, flush_every=10, flush_interval=5)\ndef get_price(requests):\n for request in requests:\n a.backend.mark_as_done(request.id, 42, request=request)\n print \"filter_by_price \" + str([r.args[0] for r in requests])\n\n@a.task\ndef completed():\n print(\"complete\")\n```\n\nSo, with this simple workflow:\n\n```\nchain(get_price.s(\"ID_1\"), completed.si()).delay()\n```\n\nI see this output:\n\n```\n[2015-07-11 16:16:20,348: INFO/MainProcess] Connected to redis://localhost:6379/0\n[2015-07-11 16:16:20,376: INFO/MainProcess] mingle: searching for neighbors\n[2015-07-11 16:16:21,406: INFO/MainProcess] mingle: all alone\n[2015-07-11 16:16:21,449: WARNING/MainProcess] celery@ultra ready.\n[2015-07-11 16:16:34,093: WARNING/Worker-4] filter_by_price ['ID_1']\n```\n\nAfter 5 seconds, filter_by_price() gets triggered just like expected. The problem is that completed() never gets invoked.\n\nAny ideas of what could be going on here? \nIf not using batches, what could be a decent approach to solve this problem?\n\n**PS:** I have set `CELERYD_PREFETCH_MULTIPLIER=0` like the docs say.\n\n========================================\n\nCode:\n```text\n@a.task(base=Batches, flush_every=10, flush_interval=5)\ndef get_price(requests):\n for request in requests:\n a.backend.mark_as_done(request.id, 42, request=request)\n print \"filter_by_price \" + str([r.args[0] for r in requests])\n\n@a.task\ndef completed():\n print(\"complete\")\n```\n\n```text\nchain(get_price.s(\"ID_1\"), completed.si()).delay()\n```\n\n```text\n[2015-07-11 16:16:20,348: INFO/MainProcess] Connected to redis://localhost:6379/0\n[2015-07-11 16:16:20,376: INFO/MainProcess] mingle: searching for neighbors\n[2015-07-11 16:16:21,406: INFO/MainProcess] mingle: all alone\n[2015-07-11 16:16:21,449: WARNING/MainProcess] celery@ultra ready.\n[2015-07-11 16:16:34,093: WARNING/Worker-4] filter_by_price ['ID_1']\n```\n\n```text\nCELERYD_PREFETCH_MULTIPLIER=0\n```\n\n```text\n@a.task(base=Batches, flush_every=10, flush_interval=5)\ndef get_price(requests):\n for request in requests:\n # do something\n completed.delay()\n```\n\n```text\ncompleted\n```\n\n```text\nget_price\n```\n\n```text\nget_price\n```\n\n========================================\n\nComments:\n- Just for the record, I needed so bad the batching thing that I ended up using RabbitMQ + Pika alone with a very simple worker template that buffers messages. If anyone interested, I have the source code available, cheers.","metadata":{"transformedAt":"2026-08-18T18:33:20.159Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":99,"estimatedTokens":714}}416{"id":"stack-55189827","source":"stackoverflow","questionId":55189827,"title":"java.lang.IllegalArgumentException when publishing a message with RabbitTemplate","tags":["java","spring-boot","rabbitmq","amqp"],"text":"Title: java.lang.IllegalArgumentException when publishing a message with RabbitTemplate\nTags: java, spring-boot, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI try to publish a message on a Queue with RabbitTemplate (using Spring Boot) and I got this message. I already tried to search for a solution.\n\n```\nCaused by: java.lang.IllegalArgumentException: SimpleMessageConverter only supports String, byte[] and Serializable payloads, received: com.example.demo.SimpleMessage\n```\n\nMaybe this part of code can help\n\n```\n@Override\n public void run(String...strings) throws Exception {\n\n SimpleMessage simpleMessage = new SimpleMessage();\n simpleMessage.setName(\"FirstMessage\");\n simpleMessage.setDescription(\"simpleDescription\");\n\n rabbitTemplate.convertAndSend(\"TestExchange\", \"testRouting\", simpleMessage);\n }\n```\n\nI appreciate any collaboration.\n\n========================================\n\nTop Answer:\nThere is another solution: use a different implementation of the MessageConverter instead of default SimpleMessageConverter.\n\nFor example, Jackson2JsonMessageConverter:\n\n```\npublic RabbitTemplate jsonRabbitTemplate(ConnectionFactory connectionFactory, ObjectMapper mapper) {\n final var jsonRabbitTemplate = new RabbitTemplate(connectionFactory);\n jsonRabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter(mapper));\n return jsonRabbitTemplate;\n}\n```\n\n========================================\n\nCode:\n```text\nCaused by: java.lang.IllegalArgumentException: SimpleMessageConverter only supports String, byte[] and Serializable payloads, received: com.example.demo.SimpleMessage\n```\n\n```text\n@Override\n public void run(String...strings) throws Exception {\n\n SimpleMessage simpleMessage = new SimpleMessage();\n simpleMessage.setName(\"FirstMessage\");\n simpleMessage.setDescription(\"simpleDescription\");\n\n rabbitTemplate.convertAndSend(\"TestExchange\", \"testRouting\", simpleMessage);\n }\n```\n\n```text\npublic class SimpleMessage implements Serializable {\n ... your code here\n}\n```\n\n```text\nSimpleMessage\n```\n\n```text\nSerializable\n```\n\n```text\nRabbitTemplate.convertAndSend\n```\n\n```text\nSimpleMessageConveter\n```\n\n```text\nSimpleMessageConverter\n```\n\n```text\nSerializable\n```\n\n```text\nSimpleMessage\n```\n\n```text\npublic RabbitTemplate jsonRabbitTemplate(ConnectionFactory connectionFactory, ObjectMapper mapper) {\n final var jsonRabbitTemplate = new RabbitTemplate(connectionFactory);\n jsonRabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter(mapper));\n return jsonRabbitTemplate;\n}\n```\n\n```text\n@Bean\npublic RabbitTemplate rabbitTemplate() {\n return new RabbitTemplate(connectionFactory());\n}\n```\n\n```text\n@Bean\npublic RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory, MessageConverter messageConverter) {\n RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);\n rabbitTemplate.setMessageConverter(messageConverter);\n return rabbitTemplate;\n}\n\n@Bean\npublic MessageConverter messageConverter(ObjectMapper jsonMapper) {\n return new Jackson2JsonMessageConverter(jsonMapper);\n}\n```\n\n```text\n\"rabbitTemplate.convertAndSend(\"\", \"user-registration\", userRegistrationRequest);\"\n```\n\n```text\nconvertAndSend()\n```\n\n```text\nUserRegistrationRequest\n```\n\n```text\nUserRegistrationRequest\n```\n\n========================================\n\nComments:\n- somewhere `SimpleMessageConverter.createMessage` is being called. I can't remember if convertAndSend calls that for you or not.\n- Looking at the source for spring, convertAndSend, calls `MessageConverter.toMessage` which calls `MessageConverter.createMessage` and since this is an instance of `SimpleMessage` we get `SimpleMessageConverter.createMessage`.\n- Agree with what Dylan has mentioned below. You need to make your object as Serializable. Take a look at some samples on sending message similar to your use case here. thepracticaldeveloper.com/2016/10/23/…\n- Thanks a lot for your suggestion @Yunnosch, of course i will check out this and i will try to make my answers more clear in the future.\n- just did it, so let me know if something still missing. Thanks a lot!","metadata":{"transformedAt":"2026-08-18T18:33:20.160Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":17,"totalLines":148,"estimatedTokens":1032}}417{"id":"stack-52159857","source":"stackoverflow","questionId":52159857,"title":"Consumer \"received\" event not firing","tags":["c#","rabbitmq"],"text":"Title: Consumer \"received\" event not firing\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm trying to set up a subscription to a RabbitMQ queue and pass it a custom event handler.\nSo I have a class called `RabbitMQClient` which contains the following method:\n\n```\npublic void Subscribe(string queueName, EventHandler receivedHandler)\n{\n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(\n queue: queueName,\n durable: false,\n exclusive: false,\n autoDelete: false,\n arguments: null\n );\n\n var consumer = new EventingBasicConsumer(channel);\n\n consumer.Received += receivedHandler;\n\n channel.BasicConsume(\n queue: queueName,\n autoAck: false,\n consumer: consumer\n );\n }\n }\n}\n```\n\nI'm using dependency injection, so I have a `RabbitMQClient` (singleton) interface for it.\n\nIn my consuming class, I have this method which I want to act as the `EventHandler`\n\n```\npublic void Consumer_Received(object sender, BasicDeliverEventArgs e)\n{\n var message = e.Body.FromByteArray();\n}\n```\n\nAnd I'm trying to subscribe to the queue like this:\n\n```\nrabbitMQClient.Subscribe(Consts.RabbitMQ.ProgressQueue, Consumer_Received);\n```\n\nI can see that the queue starts to get messages, but the `Consumer_Received` method is not firing.\n\nWhat am I missing here?\n\n========================================\n\nCode:\n```text\npublic void Subscribe(string queueName, EventHandler<BasicDeliverEventArgs> receivedHandler)\n{\n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(\n queue: queueName,\n durable: false,\n exclusive: false,\n autoDelete: false,\n arguments: null\n );\n\n var consumer = new EventingBasicConsumer(channel);\n\n consumer.Received += receivedHandler;\n\n channel.BasicConsume(\n queue: queueName,\n autoAck: false,\n consumer: consumer\n );\n }\n }\n}\n```\n\n```text\npublic void Consumer_Received(object sender, BasicDeliverEventArgs e)\n{\n var message = e.Body.FromByteArray<ProgressQueueMessage>();\n}\n```\n\n```text\nrabbitMQClient.Subscribe(Consts.RabbitMQ.ProgressQueue, Consumer_Received);\n```\n\n```text\nRabbitMQClient\n```\n\n```text\nRabbitMQClient\n```\n\n```text\nEventHandler\n```\n\n```text\nConsumer_Received\n```\n\n```text\nvar connection = factory.CreateConnection();\n\nvar channel = connection.CreateModel();\n\nchannel.QueueDeclare(\n queue: queueName,\n durable: false,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n\nvar consumer = new EventingBasicConsumer(channel);\n\nconsumer.Received += receivedHandler;\n\nchannel.BasicConsume(\n queue: queueName,\n autoAck: false,\n consumer: consumer);\n```\n\n========================================\n\nComments:\n- OP said the class is a singleton. I guess it would be a good idea to keep a static List of channels, then.\n- I can't believe I didn't see that... This is such a beginners mistake. I think I'll delete this question because it is so obvious...\n- @vhr, Still, It's embarrassing :-)\n- @LiranFriedman Not really. That's exactly why we have \"review\", too. If you write something, you can read it 1000 times and you don't see an obvious mistake. Have someone else read it and he will catch it ... We are all human after all.\n- @Fildor Well said\n- perfect! i had the same problem\n- Fun part, their official documentation / tutorial shows putting both inside a using block.\n- @LiranFriedman I am new to C#, but I am confused that if the function already return, why the connection or the channel or the consumer.Receive event still there! Or actually they all be register into the another thread hold by Rabbitmq client library. I can't find the answer in the document. Can you help it? Thanks very much.\n- save my day ! @user1689716 official document put \"using \" in the top block of the application, not in a \"scope\"(in a method) block, so , the rabbitmq instances(factory,model,...) will not disposed.","metadata":{"transformedAt":"2026-08-18T18:33:20.160Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":151,"estimatedTokens":1030}}418{"id":"stack-22882108","source":"stackoverflow","questionId":22882108,"title":"What's the point of AMQP?","tags":["rabbitmq","standards","messaging","amqp"],"text":"Title: What's the point of AMQP?\nTags: rabbitmq, standards, messaging, amqp\nSource: Stack Overflow\n\nQuestion:\nAs I understood AMQP 0.9.1, the main benefit was that you could send and receive messages and configure your exchanges / bindings / queues in a broker-independent way, thus you were able to switch your broker implementation without too much headache.\n\nNow, AMQP 1.0 only defines a wire-level protocol, so you actually have to know your broker specifics in order to implement most messaging patterns.\n\nThen why would I favour a message broker that is AMQP compliant over one that is not?\n\nIf the broker implements AMQP 1.0, I'm still locked in with broker specific client code. With AMQP 0.9.1, I am theoretically broker independent but would most likely end up with RabbitMQ, since they seem to be the only ones to sincerely maintain the full support for AMQP 0.9.1.\n\n========================================\n\nComments:\n- Whereas JMS provides a standard messaging API for the Java Platform, AMQP provides a standard messaging protocol across all platforms. AMQP does not provide a specification for an industry standard API. Rather, it provides a specification for an industry standard wire-level binary protocol to describe how the message should be structured and sent across the network. With AMQP, we can use whatever AMQP-compliant client library we want and any AMQP-compliant broker. As a result, messaging clients using AMQP are completely agnostic to which AMQP client API or AMQP message broker we are using.\n- @java_geek While your comment sounds close to original intention, it does not seem to be correct in few places. AMQP 0.9.1 allowed what you describe (exchanging client and broker implementation and keep interoperability), but with 1.0 this is not always true, as broker can implement only part of what can be expected, so the option of replacing one broker by another is not always true.","metadata":{"transformedAt":"2026-08-18T18:33:20.160Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":18,"estimatedTokens":480}}419{"id":"stack-41441545","source":"stackoverflow","questionId":41441545,"title":"RabbitMQ CreateConnection issues - works in one app but not in another","tags":["c#","wpf","rabbitmq"],"text":"Title: RabbitMQ CreateConnection issues - works in one app but not in another\nTags: c#, wpf, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nSo here is the connection code.\n\n```\nvar factory = new ConnectionFactory\n{\n HostName = \"myserver\",\n UserName = \"testuser\",\n Password = \"testuserpassword\"\n};\n\nusing (var connection = factory.CreateConnection())\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(queue: \"LOG\",\n durable: false,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n\n string message = \"Hello World!\";\n var body = Encoding.UTF8.GetBytes(message);\n\n channel.BasicPublish(exchange: \"\",\n routingKey: \"LOG\",\n basicProperties: null,\n body: body);\n Console.WriteLine(\" [x] Sent {0}\", message);\n }\n```\n\nI test this in a console app and everything works fine and I could send and receive messages.\n\nIf i then copy and paste the same code from above into my WPF app, I get an exception here\n\n```\nconnection = factory.CreateConnection()\n```\n\nException\n\nException thrown: 'System.ArgumentException' in RabbitMQ.Client.dll\n\nAdditional information: No ip address could be resolved for myserver\n\nIf I change \"myserver\" to the server ip I get the same error.\nDon't understand why the code works in one app and not the other.\n\n========================================\n\nTop Answer:\nIt did because the exception setting, if you look into the RMQ .net client source code, at the beginning it will try to connect your ip address with IPv6 Protocol, if your are connecting an IPv4 address this step will fail and throw System.ArgumentException: No ip address could be resolved for 'your ip address', but the RMQ .net client will catch this exception and move forward to try connect your ip address with IPv4 Protocol. \n\n```\nif (ShouldTryIPv6(endpoint))\n {\n try {\n m_socket = ConnectUsingIPv6(endpoint, socketFactory, connectionTimeout);\n } catch (ConnectFailureException)\n {\n m_socket = null;\n }\n }\n\n if (m_socket == null && endpoint.AddressFamily != AddressFamily.InterNetworkV6)\n {\n m_socket = ConnectUsingIPv4(endpoint, socketFactory, connectionTimeout);\n }\n```\n\nif yous set to break on the connection exceptions, your force the ArgumentException to throw.\n\n```\npublic virtual async Task ConnectAsync(string host, int port)\n {\n AssertSocket();\n var adds = await Dns.GetHostAddressesAsync(host).ConfigureAwait(false);\n var ep = TcpClientAdapterHelper.GetMatchingHost(adds, sock.AddressFamily);\n if (ep == default(IPAddress))\n {\n throw new ArgumentException(\"No ip address could be resolved for \" + host);\n }\n```\n\n========================================\n\nCode:\n```text\nvar factory = new ConnectionFactory\n{\n HostName = \"myserver\",\n UserName = \"testuser\",\n Password = \"testuserpassword\"\n};\n\nusing (var connection = factory.CreateConnection())\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(queue: \"LOG\",\n durable: false,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n\n string message = \"Hello World!\";\n var body = Encoding.UTF8.GetBytes(message);\n\n channel.BasicPublish(exchange: \"\",\n routingKey: \"LOG\",\n basicProperties: null,\n body: body);\n Console.WriteLine(\" [x] Sent {0}\", message);\n }\n```\n\n```text\nconnection = factory.CreateConnection()\n```\n\n```text\nif (ShouldTryIPv6(endpoint))\n {\n try {\n m_socket = ConnectUsingIPv6(endpoint, socketFactory, connectionTimeout);\n } catch (ConnectFailureException)\n {\n m_socket = null;\n }\n }\n\n if (m_socket == null && endpoint.AddressFamily != AddressFamily.InterNetworkV6)\n {\n m_socket = ConnectUsingIPv4(endpoint, socketFactory, connectionTimeout);\n }\n```\n\n```text\npublic virtual async Task ConnectAsync(string host, int port)\n {\n AssertSocket();\n var adds = await Dns.GetHostAddressesAsync(host).ConfigureAwait(false);\n var ep = TcpClientAdapterHelper.GetMatchingHost(adds, sock.AddressFamily);\n if (ep == default(IPAddress))\n {\n throw new ArgumentException(\"No ip address could be resolved for \" + host);\n }\n```\n\n```text\n<dependentAssembly>\n <assemblyIdentity name=\"System.Threading.Tasks.Extensions\" publicKeyToken=\"cc7b13ffcd2ddd51\" culture=\"neutral\"/>\n <bindingRedirect oldVersion=\"0.0.0.0-4.2.0.1\" newVersion=\"4.2.0.1\"/>\n</dependentAssembly>\n```\n\n========================================\n\nComments:\n- What is the API URL you are trying to access? Also show the code inside CreateConnection() function.\n- I haven't shown the code because I didn't think it was relevant, the code does not get that far. API url? I haven't a clue. I am using a tutorial like this and it doesn't mention API url. rabbitmq.com/tutorials/tutorial-four-dotnet.html\n- API URL is where we post messages to the MQ. I can show you a sample code to make a connection and POST a message, but not sure if that will be helpful. So I wanted to see how exactly how you are creating the connection.\n- oh right, I don't know the URL. I imagine the RabbitMQ .net client creates. As you can see from my code, I don't enter a url anywhere and it works fine in the console app.\n- Is your MQ running on a different machine? If yes, check if you are able to ping that machine using it's IP. And the URL is something like this- http://:/rpa/api/message\n- Yes it is running fine. I think you are missing the point that this code works in my console application so pinging is irrelevant. I believe it is related to the WPF application.\n- I see. Seems like some configuration is missed. Check the ConnectionFactory details and compare it with the one in your Console app.\n- Glad you found it.\n- What was the exception setting that you changed? I've run into the same issue\n- @Gaz83 what changes did you make to fix this? I'm facing a similar trouble but for the console app instead.\n- @ValerianPereira Sorry this was a long time ago. The only advice I can give, based on my answer, is to run the console app and watch the output window in visual studio. The exceptions will show there. Then change the settings to break on that type.\n- Thanks for posting the offending code and for a clear explanation. Your answer is the only place online that I have found that actually explains this.\n- Using exceptions as normal control flow is just annoying.. Thanks for your answer.","metadata":{"transformedAt":"2026-08-18T18:33:20.160Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":175,"estimatedTokens":1654}}420{"id":"stack-9824952","source":"stackoverflow","questionId":9824952,"title":"Socket.IO with RabbitMQ?","tags":["socket.io","rabbitmq"],"text":"Title: Socket.IO with RabbitMQ?\nTags: socket.io, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm currently using Socket.IO with redis store.\n\nAnd I'm using Room feature with it.\n\nSo I'm totally okay with Room join (subscribe)\n\nand Leave (unsubscribe) with Socket.IO.\n\nI just see this page\n\nhttp://www.rabbitmq.com/blog/2010/11/12/rabbitmq-nodejs-rabbitjs/\n\nAnd I have found that some people are using Socket.IO with rabbitMQ.\n\nWhy using Socket.IO alone is not good enough?\n\nIs there any good reason to use Socket.IO with rabbitMQ?\n\n========================================\n\nTop Answer:\nI just used rabbitMQ with socket.io for a different reason than in the accepted answer. It wasn't that relevant in 2012, that's why I'm updating it here.\n\nI'm using a docker swarm deployment of a chat application with scalability and high availability. I have three replicas of the chat application (which uses socket.io) running in the cluster. The swarm cluster automatically load-balances the incoming requests and at any given time a client might get connected to any of the three replicas of the application.\n\nWith this scenario, it gets really necessary to sync the WebSocket responses in the replicas of the application because two clients connected to two different instances of the application wouldn't get each other's messages because they've been connected to different WebSockets.\n\nThis is where rabbitMQ comes into the picture. It syncs all the instances of the application and whenever a message is pushed from a WebSocket on a replica, it gets pushed by all replicas.\n\nhttps://i.sstatic.net/NaVUR.png\n\nComplete details of the project have been given here. This is a potential use case of socket.io and rabbitMQ use in conjunction. This goes for any application using socket.io in a distributed environment with high availability and scalability.\n\n========================================\n\nComments:\n- So the RabbitMQ can relieve some heavy loads from persisting messages. Do you recommend using RabbitMQ in front of Socket.IO? In that way Socket.IO can be highly scalable with smaller Socket.IO server clusters but with RabbitMQ server clusters. Am I on right track?\n- If what you mean by \"RabbitMQ in front of Socket.IO\" is having a web farm which uses SocketIO to broker requests from the client and then use a RabbitMQ cluster to drop messages intended for persistence on to and then have a separate set of services which consume from RabbitMQ and persist the messages appropriately, then yes ;-)\n- would be quite interested in finding out more about that experimental project.\n- Here are the official release notes: rabbitmq.com/blog/2012/05/14/introducing-rabbitmq-web-stomp","metadata":{"transformedAt":"2026-08-18T18:33:20.160Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":45,"estimatedTokens":670}}421{"id":"stack-58689551","source":"stackoverflow","questionId":58689551,"title":"RabbitMQ - vhost '/' is down for user 'XYZ'. even after user has all access","tags":["rabbitmq"],"text":"Title: RabbitMQ - vhost '/' is down for user 'XYZ'. even after user has all access\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am using RabbitMQ version 3.7.17 \n\nAs my AWS hard disk was completely occupied(100% full). Due to which all the services stopped working\n\nSolution to this: I extended AWS server memory and than tried to start all the API services after that it started throwing error. (Post this it started giving error)\n\n Connection.open: (541) INTERNAL_ERROR - access to vhost '/' refused for user 'XYZ': vhost '/' is down \n\nRestarted RabbitmMQ server using the below code still it was giving error:\n\n`sudo service rabbitmq-server restart` \n\nIf I checked the permission for my user using:\n\n`sudo rabbitmqctl list_permissions --vhost /`\n\nResponse shows that user has all the access.\n\n```\nListing permissions for vhost \"/\" ...\nuser configure write read\nXYZ .* .* .*\n```\n\nThank You.\n\n========================================\n\nCode:\n```text\nListing permissions for vhost \"/\" ...\nuser configure write read\nXYZ .* .* .*\n```\n\n```text\nsudo service rabbitmq-server restart\n```\n\n```text\nsudo rabbitmqctl list_permissions --vhost /\n```\n\n```text\nsudo rabbitmqctl stop_app\n```\n\n```text\nsudo rabbitmqctl reset\n```\n\n```text\nsudo rabbitmqctl start_app\n```\n\n```text\nsudo rabbitmqctl restart_vhost\n```\n\n```text\nsudo rabbitmqctl restart_vhost\n```\n\n```text\ncelery\n```\n\n========================================\n\nComments:\n- @cabreracanal the server memory was expanded it was resolved but rabbitmq stopped working after that which was working fine before that. It started throwing above mention error.\n- I don't know if you are talking about server's memory (RAM) or server's volume capacity (disk). In your description, you said that expanding the memory did not solve the problem, so this is why I'm asking if you are talking about RAM or disk.\n- @cabreracanal I have updated the question. Initially it was working fine after aws hard disk was full and memory and it was expanded than rabbitmq started throwing error. There no problem with server it RabbitMQ that is giving error.\n- @cabreracanal your are telling me solution of aws memory which is been resolved and all other application are working fine such as `apache2, celery` etc only `rabbitmq` is throwing error.\n- Please refer my fix in stackoverflow.com/a/62019910/4817250\n- it works perfect for docker's container as well. Thank you very much\n- If you don't want to remove all data (e.g. only one vhost is corrupted), use `rabbitmqctl delete_vhost badvhost` and then recreate it. If like me you have your rabbitmq definitions in a json file, that would be `rabbitmqadmin import /path/to/definitions.json`\n- That helped me too. But is there a way to save the message queue so I can resume where it left off?\n- Hi @ruslaniv good question, I have added a link to backup your data before reset in my answer. Hope that is helpful.","metadata":{"transformedAt":"2026-08-18T18:33:20.160Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":9,"totalLines":84,"estimatedTokens":727}}422{"id":"stack-76712557","source":"stackoverflow","questionId":76712557,"title":"RabbitMQ enagle feature flags before run server","tags":["rabbitmq"],"text":"Title: RabbitMQ enagle feature flags before run server\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have tried to start rabbitmq-server after update and got this error.\n\n```\n2023-07-18 14:47:49.621801+03:00 [error] Feature flags: `classic_mirrored_queue_version`: required feature flag not enabled! It must be enabled before upgrading RabbitMQ.\n2023-07-18 14:47:49.627876+03:00 [error] Failed to initialize feature flags registry: {disabled_required_feature_flag,\n2023-07-18 14:47:49.627876+03:00 [error] classic_mirrored_queue_version}\n\nBOOT FAILED\n===========\nError during startup: {error,failed_to_initialize_feature_flags_registry}\n2023-07-18 14:47:49.633989+03:00 [error] \n2023-07-18 14:47:49.633989+03:00 [error] BOOT FAILED\n2023-07-18 14:47:49.633989+03:00 [error] ===========\n2023-07-18 14:47:49.633989+03:00 [error] Error during startup: {error,failed_to_initialize_feature_flags_registry}\n2023-07-18 14:47:49.633989+03:00 [error] \n\n2023-07-18 14:47:50.635088+03:00 [error] crasher:\n2023-07-18 14:47:50.635088+03:00 [error] initial call: application_master:init/4\n2023-07-18 14:47:50.635088+03:00 [error] pid: \nCONFIG_FILE=/opt/homebrew/etc/rabbitmq/rabbitmq\n2023-07-18 14:47:50.635088+03:00 [error] registered_name: []\n2023-07-18 14:47:50.635088+03:00 [error] exception exit: {failed_to_initialize_feature_flags_registry,\n2023-07-18 14:47:50.635088+03:00 [error] {rabbit,start,[normal,[]]}}\n2023-07-18 14:47:50.635088+03:00 [error] in function application_master:init/4 (application_master.erl, line 142)\n2023-07-18 14:47:50.635088+03:00 [error] ancestors: []\n2023-07-18 14:47:50.635088+03:00 [error] message_queue_len: 1\n2023-07-18 14:47:50.635088+03:00 [error] messages: [{'EXIT',,normal}]\n2023-07-18 14:47:50.635088+03:00 [error] links: [,]\n2023-07-18 14:47:50.635088+03:00 [error] dictionary: []\n2023-07-18 14:47:50.635088+03:00 [error] trap_exit: true\n2023-07-18 14:47:50.635088+03:00 [error] status: running\n2023-07-18 14:47:50.635088+03:00 [error] heap_size: 376\n2023-07-18 14:47:50.635088+03:00 [error] stack_size: 28\n2023-07-18 14:47:50.635088+03:00 [error] reductions: 173\n2023-07-18 14:47:50.635088+03:00 [error] neighbours:\n2023-07-18 14:47:50.635088+03:00 [error] \n2023-07-18 14:47:50.646529+03:00 [notice] Application rabbit exited with reason: {failed_to_initialize_feature_flags_registry,{rabbit,start,[normal,[]]}}\nKernel pid terminated (application_controller) ({application_start_failure,rabbit,{failed_to_initialize_feature_flags_registry,{rabbit,start,[normal,[]]}}})\n```\n\nSolutions what I have found in official doc are to use rabbitmqctl or web plugin.\n\nI'm getting an error while I try to work with rabbitmqctl. As I understand, it can't connect to the server and server I can't start until I find a way to add the necessary function flags\n\n```\n$ rabbitmqctl list_feature_flags\nError: {:badrpc, :nodedown}\n```\n\n========================================\n\nTop Answer:\nIf you had already installed rabbitMQ on your MAC please these instructions to resolve error\n\nFirst Stop rabbitmq and uninstall\n\n```\nbrew services stop rabbitmq\nbrew uninstall rabbitmq\n```\n\nRemove all references of rabbitMQ\n\n```\nrm -rf /opt/homebrew/etc/rabbitmq\nrm -rf /opt/homebrew/etc/rabbitmq/enabled_plugins\nrm -rf /opt/homebrew/etc/rabbitmq/enabled_plugins.default\nrm -rf /opt/homebrew/etc/rabbitmq/rabbitmq-env.conf\nrm -rf /opt/homebrew/etc/rabbitmq \nrm -rf /opt/homebrew/var/lib/rabbitmq\nrm -rf /opt/homebrew/var/log/rabbitmq\n```\n\nInstall fresh copy of rabbitMQ\n\n```\nbrew update\nbrew install rabbitmq\nbrew services start rabbitmq\n```\n\nRef: https://medium.com/@anjantalatatam/how-to-clean-install-rabbitmq-1ae214436b7d\n\n========================================\n\nCode:\n```text\n2023-07-18 14:47:49.621801+03:00 [error] <0.234.0> Feature flags: `classic_mirrored_queue_version`: required feature flag not enabled! It must be enabled before upgrading RabbitMQ.\n2023-07-18 14:47:49.627876+03:00 [error] <0.234.0> Failed to initialize feature flags registry: {disabled_required_feature_flag,\n2023-07-18 14:47:49.627876+03:00 [error] <0.234.0> classic_mirrored_queue_version}\n\nBOOT FAILED\n===========\nError during startup: {error,failed_to_initialize_feature_flags_registry}\n2023-07-18 14:47:49.633989+03:00 [error] <0.234.0>\n2023-07-18 14:47:49.633989+03:00 [error] <0.234.0> BOOT FAILED\n2023-07-18 14:47:49.633989+03:00 [error] <0.234.0> ===========\n2023-07-18 14:47:49.633989+03:00 [error] <0.234.0> Error during startup: {error,failed_to_initialize_feature_flags_registry}\n2023-07-18 14:47:49.633989+03:00 [error] <0.234.0>\n\n2023-07-18 14:47:50.635088+03:00 [error] <0.233.0> crasher:\n2023-07-18 14:47:50.635088+03:00 [error] <0.233.0> initial call: application_master:init/4\n2023-07-18 14:47:50.635088+03:00 [error] <0.233.0> pid: <0.233.0>\nCONFIG_FILE=/opt/homebrew/etc/rabbitmq/rabbitmq\n2023-07-18 14:47:50.635088+03:00 [error] <0.233.0> registered_name: []\n2023-07-18 14:47:50.635088+03:00 [error] <0.233.0> exception exit: {failed_to_initialize_feature_flags_registry,\n2023-07-18 14:47:50.635088+03:00 [error] <0.233.0> {rabbit,start,[normal,[]]}}\n2023-07-18 14:47:50.635088+03:00 [error] <0.233.0> in function application_master:init/4 (application_master.erl, line 142)\n2023-07-18 14:47:50.635088+03:00 [error] <0.233.0> ancestors: [<0.232.0>]\n2023-07-18 14:47:50.635088+03:00 [error] <0.233.0> message_queue_len: 1\n2023-07-18 14:47:50.635088+03:00 [error] <0.233.0> messages: [{'EXIT',<0.234.0>,normal}]\n2023-07-18 14:47:50.635088+03:00 [error] <0.233.0> links: [<0.232.0>,<0.44.0>]\n2023-07-18 14:47:50.635088+03:00 [error] <0.233.0> dictionary: []\n2023-07-18 14:47:50.635088+03:00 [error] <0.233.0> trap_exit: true\n2023-07-18 14:47:50.635088+03:00 [error] <0.233.0> status: running\n2023-07-18 14:47:50.635088+03:00 [error] <0.233.0> heap_size: 376\n2023-07-18 14:47:50.635088+03:00 [error] <0.233.0> stack_size: 28\n2023-07-18 14:47:50.635088+03:00 [error] <0.233.0> reductions: 173\n2023-07-18 14:47:50.635088+03:00 [error] <0.233.0> neighbours:\n2023-07-18 14:47:50.635088+03:00 [error] <0.233.0>\n2023-07-18 14:47:50.646529+03:00 [notice] <0.44.0> Application rabbit exited with reason: {failed_to_initialize_feature_flags_registry,{rabbit,start,[normal,[]]}}\nKernel pid terminated (application_controller) ({application_start_failure,rabbit,{failed_to_initialize_feature_flags_registry,{rabbit,start,[normal,[]]}}})\n```\n\n```bash\n$ rabbitmqctl list_feature_flags\nError: {:badrpc, :nodedown}\n```\n\n```text\nbrew services stop rabbitmq\nbrew uninstall rabbitmq\n```\n\n```text\nrm -rf /opt/homebrew/etc/rabbitmq\nrm -rf /opt/homebrew/etc/rabbitmq/enabled_plugins\nrm -rf /opt/homebrew/etc/rabbitmq/enabled_plugins.default\nrm -rf /opt/homebrew/etc/rabbitmq/rabbitmq-env.conf\nrm -rf /opt/homebrew/etc/rabbitmq \nrm -rf /opt/homebrew/var/lib/rabbitmq\nrm -rf /opt/homebrew/var/log/rabbitmq\n```\n\n```text\nbrew update\nbrew install rabbitmq\nbrew services start rabbitmq\n```\n\n```text\nbrew services stop rabbitmq\nbrew uninstall rabbitmq\nrm -rf /usr/local/var/lib/rabbitmq\nrm -rf /usr/local/var/log/rabbitmq\nbrew install rabbitmq\nbrew services start rabbitmq\n```\n\n```text\nfind / -type d -name \"rabbitmq\" -print 2>/dev/null\n```\n\n```text\nrm -rf\n```\n\n```text\nrm -rf /usr/local/var/lib/rabbitmq/mnesia\n```\n\n========================================\n\nComments:\n- This is a quickest solution\n- I recently updated my MAC OS version and rabbitmq started disconnecting afterwards following these steps and everything fine now :+1\n- For some reason this worked. In my case it seems like not all of my rabbitmq references have been deleted.\n- Now can't install back rabbitmq lol Please always consult current RabbitMQ installation instructions as they seem to change repos from time to time.\n- same issue on MBP 2019; had to delete etc/rabbitmq as well: `rm -rf /usr/local/etc/rabbitmq`","metadata":{"transformedAt":"2026-08-18T18:33:20.160Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":184,"estimatedTokens":1984}}423{"id":"stack-8230833","source":"stackoverflow","questionId":8230833,"title":"Stopping/Purging Periodic Tasks in Django-Celery","tags":["django","rabbitmq","celery","django-celery"],"text":"Title: Stopping/Purging Periodic Tasks in Django-Celery\nTags: django, rabbitmq, celery, django-celery\nSource: Stack Overflow\n\nQuestion:\nI have managed to get periodic tasks working in django-celery by subclassing PeriodicTask. I tried to create a test task and set it running doing something useless. It works. \n\nNow I can't stop it. I've read the documentation and I cannot find out how to remove the task from the execution queue. I have tried using celeryctl and using the shell, but registry.tasks() is empty, so I can't see how to remove it.\n\nI have seen suggestions that I should \"revoke\" it, but for this I appear to need a task id, and I can't see how I would find the task id. \n\nThanks.\n\n========================================\n\nTop Answer:\nJust in case this may help someone ... We had the same problem at work, and despites some efforts to find some kind of management command to remove the periodic task, we could not. So here are some pointers.\n\nYou should probably first double-check which scheduler class you're using.\n\n The default scheduler is `celery.beat.PersistentScheduler`, which is simply keeping track of the last run times in a local database file (a shelve).\n\nIn our case, we were using the `djcelery.schedulers.DatabaseScheduler` class.\n\n `django-celery` also ships with a scheduler that stores the schedule in the Django database\n\nAlthough the documentation does mention a way to remove the periodic tasks:\n\n Using `django-celery`‘s scheduler you can add, modify and remove periodic tasks from the Django Admin.\n\nWe wanted to perform the removal programmatically, or via a (celery/management) command in a shell.\n\nSince we could not find a command line, we used the django/python shell:\n\n```\n$ python manage.py shell\n>>> from djcelery.models import PeriodicTask\n>>> pt = PeriodicTask.objects.get(name='the_task_name')\n>>> pt.delete()\n```\n\nI hope this helps!\n\n========================================\n\nCode:\n```text\n@periodic_task(options={\"task_id\": \"my_periodic_task\"})\ndef my_periodic_task():\n pass\n```\n\n```text\nCELERYBEAT_SCHEDULE = {name: {\"task\": task_name,\n \"options\": {\"task_id\": name}}}\n```\n\n```text\nfrom celery.task import Task\n\nclass RevokeableTask(Task):\n \"\"\"Task that can be revoked.\n\n Example usage:\n\n @task(base=RevokeableTask)\n def mytask():\n pass\n \"\"\"\n\n def __call__(self, *args, **kwargs):\n if revoke_flag_set_in_db_for(self.request.id):\n return\n super(RevokeableTask, self).__call__(*args, **kwargs)\n```\n\n```text\nrevoke\n```\n\n```text\n@periodic_task\n```\n\n```text\nCELERYBEAT_SCHEDULE\n```\n\n```text\n@periodic_task\n```\n\n```text\nCELERYBEAT_SCHEDULE\n```\n\n```text\nrevoke\n```\n\n```text\nrevoke(task_id, terminate=True)\n```\n\n```text\nTERM\n```\n\n```text\nrevoke(task_id, terminate=True, signal=\"KILL\")\n```\n\n```text\ncancelled\n```\n\n```text\n$ python manage.py shell\n>>> from djcelery.models import PeriodicTask\n>>> pt = PeriodicTask.objects.get(name='the_task_name')\n>>> pt.delete()\n```\n\n```text\ncelery.beat.PersistentScheduler\n```\n\n```text\ndjcelery.schedulers.DatabaseScheduler\n```\n\n```text\ndjango-celery\n```\n\n```text\ndjango-celery\n```\n\n========================================\n\nComments:\n- Thank you for this extremely thorough answer.","metadata":{"transformedAt":"2026-08-18T18:33:20.160Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":18,"totalLines":143,"estimatedTokens":815}}424{"id":"stack-38206347","source":"stackoverflow","questionId":38206347,"title":"how to mark a message as persistent using spring-rabbitmq?","tags":["rabbitmq","spring-amqp","spring-rabbit"],"text":"Title: how to mark a message as persistent using spring-rabbitmq?\nTags: rabbitmq, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nThis is how I'm creating an exchange and binding a queue to it \n\n```\n\n \n \n \n\n```\n\nI have read a lot of posts on the Internet where it is written that a message is also needed to be marked persistent if it is to be secured in case rabbitmq or the queue crashes. But I couldn't figure out how to mark my messages persistent.\n\nThis is how I'm publishing the messages to the queue\n\n```\n@Autowired\n private RabbitTemplate template;\n\n @Override\n public void produceMessage(Object message, String routingKey) {\n template.convertAndSend(routingKey, message); \n }\n```\n\nI looked for different API methods to know this and also tried to look for any specific property that I could configure in the XML but couldn't find a way. Any guidance ?\n\n========================================\n\nCode:\n```text\n<rabbit:topic-exchange id=\"dataExchange\" name=\"MQ-EXCHANGE\" durable=\"true\">\n <rabbit:bindings>\n <rabbit:binding queue=\"COMM_QUEUE\" pattern=\"queue.*\" />\n </rabbit:bindings>\n</rabbit:topic-exchange>\n```\n\n```text\n@Autowired\n private RabbitTemplate template;\n\n @Override\n public void produceMessage(Object message, String routingKey) {\n template.convertAndSend(routingKey, message); \n }\n```\n\n```text\nMessageProperties\n```\n\n```text\nPERSISTENT\n```\n\n```text\nconvertAndSend(...)\n```\n\n```text\nMessagePostProcessor\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.160Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":67,"estimatedTokens":371}}425{"id":"stack-56886770","source":"stackoverflow","questionId":56886770,"title":"How to change RabbitMQ Heartbeat without restart","tags":["rabbitmq","consumer","heartbeat","rabbitmqctl"],"text":"Title: How to change RabbitMQ Heartbeat without restart\nTags: rabbitmq, consumer, heartbeat, rabbitmqctl\nSource: Stack Overflow\n\nQuestion:\nThere are several questions here in SO about RabbitMQ heartbeat but I haven't found one addressing how to actually change the default heartbeat value of `60 seconds` (`580 seconds` in previous versions).\n\nIn the case when a consumer is running for longer than `60 seconds` and is incapable of producing any traffic that would count as heartbeat (for example PHP consumers), RabbitMQ will close the connection considering the consumer is dead, but the consumer might continue to run, and when it tries to produce the ACK the connection is closed and you get an error message like: \n\n Broken pipe or closed connection\n\nOne can set the heartbeat at the consumer side to a higher value, for example `1800 seconds`, but if the broker configuration is not changed, then the lower value will be use, in case of the default value then `60 seconds`. From RabbitMQ docs:\n\n The broker and client will attempt to negotiate heartbeats by default.\n When both values are non-0, the lower of the requested values will be\n used. If one side uses a zero value (attempts to disable heartbeats)\n but the other does not, the non-zero value will be used.\n\nTo change the Heartbeat value one can add the following line in `/etc/rabbitmq/rabbitmq.conf` (using the new configuration format)\n\n```\nheartbeat = 1800\n```\n\nThis requires a restart, so the question is: **How to change the rabbitmq heartbeat value without a restart?**\n\n========================================\n\nCode:\n```text\nheartbeat = 1800\n```\n\n```text\n60 seconds\n```\n\n```text\n580 seconds\n```\n\n```text\n60 seconds\n```\n\n```text\n1800 seconds\n```\n\n```text\n60 seconds\n```\n\n```text\n/etc/rabbitmq/rabbitmq.conf\n```\n\n```text\n# Set\nrabbitmqctl eval 'application:set_env(rabbit, heartbeat, 1800).'\n\n# Get \nrabbitmqctl eval 'application:get_env(rabbit, heartbeat).'\n```\n\n```text\neval\n```\n\n```text\nrabbitmqctl eval\n```\n\n========================================\n\nComments:\n- This will only affect new connections.\n- @LukeBakken Indeed is not possible to change the heartbeat for already established connections. I just tested it to be sure. Thanks\n- Thank you for both the Q and the A. I didn't know that the problems I was seeing (RabbitMQ management UI showing 0s heartbeat for PHP connection) was endemic to PHP, and was trying to find a way to verify RabbitMQ's actual default heartbeat... and trying to isolate the problem as due to the client or the server.","metadata":{"transformedAt":"2026-08-18T18:33:20.160Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":10,"totalLines":79,"estimatedTokens":632}}426{"id":"stack-33239347","source":"stackoverflow","questionId":33239347,"title":"how to use @queuebinding with @rabbitlistener?","tags":["rabbitmq","spring-amqp","spring-rabbit"],"text":"Title: how to use @queuebinding with @rabbitlistener?\nTags: rabbitmq, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nSeems since spring-amqp version 1.5, there is a new annotation @queuebinding。But how to use it, i don't know if it can be used on a class or a method? Does it exist any example?\n\n========================================\n\nCode:\n```text\n@Component\npublic class MyService {\n\n @RabbitListener(bindings = @QueueBinding(\n value = @Queue(value = \"myQueue\", durable = \"true\"),\n exchange = @Exchange(value = \"auto.exch\"),\n key = \"orderRoutingKey\")\n )\n public void processOrder(String data) {\n ...\n }\n```\n\n========================================\n\nComments:\n- I am seeking help on a similar concept, but not sure If i am allowed to post my question here? @Artem Bilan, based on your response may I ask a question\n- Just raise a new SO thread and we will try to help you\n- Thanks @Artem Bilan, this is the link to my actual thread so I just expanded on my question, stackoverflow.com/questions/63484183/…","metadata":{"transformedAt":"2026-08-18T18:33:20.160Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":30,"estimatedTokens":265}}427{"id":"stack-8107085","source":"stackoverflow","questionId":8107085,"title":"Django - Executing a task through celery from a model","tags":["django","rabbitmq","celery"],"text":"Title: Django - Executing a task through celery from a model\nTags: django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nIn my models.py:\n\n```\nfrom django.db import models\nfrom core import tasks\n\nclass Image(models.Model):\n image = models.ImageField(upload_to='images/orig')\n thumbnail = models.ImageField(upload_to='images/thumbnails', editable=False)\n\n def save(self, *args, **kwargs):\n super(Image, self).save(*args, **kwargs)\n tasks.create_thumbnail.delay(self.id)\n```\n\nIn my tasks.py:\n\n```\nfrom celery.decorators import task\nfrom core.models import Image\n\n@task()\ndef create_thumbnail(image_id):\n ImageObj = Image.objects.get(id=image_id)\n # other stuff here\n```\n\nThis is returning the following:\n\n- **Exception Type:** ImportError\n\n- **Exception Value:** cannot import name tasks\n\nThe error disappears if I comment out `from core.models import Image` in `tasks.py`, however this obviously will cause a problem since `Image` has no meaning in here. I have tried to import it inside `create_thumbnail` however it still won't recognize `Image`.\n\nI have read somewhere that usually the object itself can be passed as an argument to a task and that would solve my problem. However, a friend once told me that it is considered best practice to send as little data as possible in a RabbitMQ message, so to achieve that I'm trying to only pass the image ID and then retrieve it again in the task.\n\n1) Is what I'm trying to do considered a best practice? If yes, how do I work it out?\n\n2) I have noticed in all the examples I found around the web, they execute the task from a view and never from a model. I'm trying to create a thumbnail whenever a new image is uploaded, I don't want to call create_thumbnail in every form/view I have. Any idea about that? Is executing a task from a model not recommended or a common practice?\n\n========================================\n\nTop Answer:\nYou don't need to import the task itself. Try using the following\n\n```\nfrom django.db import models\nfrom celery.execute import send_task, delay_task\n\nclass Image(models.Model):\n image = models.ImageField(upload_to='images/orig')\n thumbnail = models.ImageField(upload_to='images/thumbnails', editable=False)\n\n def save(self, *args, **kwargs):\n super(Image, self).save(*args, **kwargs)\n result = delay_task(\"task_prefix.create_thumbnail\", post.id)\n```\n\n========================================\n\nCode:\n```text\nfrom django.db import models\nfrom core import tasks\n\nclass Image(models.Model):\n image = models.ImageField(upload_to='images/orig')\n thumbnail = models.ImageField(upload_to='images/thumbnails', editable=False)\n\n def save(self, *args, **kwargs):\n super(Image, self).save(*args, **kwargs)\n tasks.create_thumbnail.delay(self.id)\n```\n\n```text\nfrom celery.decorators import task\nfrom core.models import Image\n\n@task()\ndef create_thumbnail(image_id):\n ImageObj = Image.objects.get(id=image_id)\n # other stuff here\n```\n\n```text\nfrom core.models import Image\n```\n\n```text\ntasks.py\n```\n\n```text\nImage\n```\n\n```text\ncreate_thumbnail\n```\n\n```text\nImage\n```\n\n```text\nfrom django.db import models\n\nclass Image(models.Model):\n image = models.ImageField(upload_to='images/orig')\n thumbnail = models.ImageField(upload_to='images/thumbnails', editable=False)\n\n def save(self, *args, **kwargs):\n super(Image, self).save(*args, **kwargs)\n from core.tasks import create_thumbnail\n create_thumbnail.delay(self.id)\n```\n\n```text\nfrom celery.decorators import task\n\n@task()\ndef create_thumbnail(image_id):\n from core.models import Image\n ImageObj = Image.objects.get(id=image_id)\n # other stuff here\n```\n\n```text\nmodels\n```\n\n```text\ntasks\n```\n\n```text\nfrom core.models import Image\n```\n\n```text\ncreate_thumbnail\n```\n\n```text\ntasks\n```\n\n```text\nfrom django.db import models\nfrom celery.execute import send_task, delay_task\n\nclass Image(models.Model):\n image = models.ImageField(upload_to='images/orig')\n thumbnail = models.ImageField(upload_to='images/thumbnails', editable=False)\n\n def save(self, *args, **kwargs):\n super(Image, self).save(*args, **kwargs)\n result = delay_task(\"task_prefix.create_thumbnail\", post.id)\n```\n\n========================================\n\nComments:\n- I have already tried that, in this case the message is sent correctly however create_thumbnail generates an error: `File \"/home/ubuntu/project/core/tasks.py\", line 5, in create_thumbnail` `from core.models import Image` `NameError: global name 'Image' is not defined`\n- i presume `core` is the name of your app. have you tried prepending the project name (ie `from project.app.models import Model`)? django does some path magic which is sometimes less than helpful\n- Just did, same error returned: `NameError: global name 'Image' is not defined`. I have already appended my project path in `django.wsgi`.\n- The only settings I have for celery are the following in `settings.py`: `# Celery Settings` `import djcelery` `djcelery.setup_loader()` `BROKER_HOST = \"localhost\"` `BROKER_PORT = 5672` `BROKER_USER = \"guest\"` `BROKER_PASSWORD = \"guest\"` `BROKER_VHOST = \"/\"` **Update**: Also the following in `django.wsgi`: `os.environ['CELERY_LOADER'] = 'django'`\n- Ok I have just checked out the admin interface, and I have 0 workers apparently! Not sure if this is relevant though, as I'm already running celeryd in a terminal and can see the messages getting through.\n- are you definitely running celeryd from django?\n- Yea: `python manage.py celeryd --verbosity=2 --loglevel=DEBUG`\n- I really apprecieated the paragraph \"To eliminate circular imports, you should think about which way the imports should happen...\". Thank you.\n- celery.execute does not seem to exist any more in celery 3.x","metadata":{"transformedAt":"2026-08-18T18:33:20.160Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":15,"totalLines":178,"estimatedTokens":1438}}428{"id":"stack-22840247","source":"stackoverflow","questionId":22840247,"title":"RabbitMQ Java Client Using DefaultConsumer vs QueueingConsumer","tags":["multithreading","rabbitmq","messaging"],"text":"Title: RabbitMQ Java Client Using DefaultConsumer vs QueueingConsumer\nTags: multithreading, rabbitmq, messaging\nSource: Stack Overflow\n\nQuestion:\nDefaultConsumer\n\nMy DemoConsumer inherits from DefaultConsumer.\n\nI have noticed that working this way handleDelivery() is invoked from ThreadPool.\n\n(printing Thread.currentThread().getName() I see pool-1-thread-1/2/3/4 eachtime.\n\nI have also tested it several times and saw that the order is saved.\n\nJust to make sure - since different threads call handle delivery - will it mess my order? \n\nQueueingConsumer\n\nAll of the java tutorial use QueueingConsumer to consume messages.\n\nIn the API Docs it is mentioned as a deprecated class.\n\nShould I change my code to inherit from DefaultConsumer use it? Is the tutorial outdated? \n\nThanks.\n\n========================================\n\nCode:\n```text\nExecutorService es = Executors.newFixedThreadPool(20);\nConnection conn = factory.newConnection(es);\n```\n\n```text\nQueueingConsumer consumer = new QueueingConsumer(channel);\nchannel.basicConsume(QUEUE_NAME, true, consumer);\nwhile (true) {\n QueueingConsumer.Delivery delivery = consumer.nextDelivery(); \n /// here you are blocked, waiting the next message.\n String message = new String(delivery.getBody());\n}\n```\n\n```text\npublic class MyConsumer extends DefaultConsumer {...}\n```\n\n```text\npublic static void main(String[] args) {\nMyConsumer consumer = new MyConsumer (channel);\nString consumerTag = channel.basicConsume(Constants.queue, false, consumer);\nSystem.out.println(\"press any key to terminate\");\nSystem.in.read();\nchannel.basicCancel(consumerTag);\nchannel.close();\n....\n```\n\n```text\nDefaultConsumer\n```\n\n```text\nExecutorService\n```\n\n```text\nDefaultConsumer\n```\n\n========================================\n\nComments:\n- What do you mean with \"will it mess my order?\" ? Threads order or Messages order?\n- Hi, how to do a rateLimiter when extends DefaultConsumer, Since i can't control whether to receive a message or not when extends DefaultConsumer, but when using QueueingConsumer, i can refuse consume before consumer.nextDelivery()\n- What happens if we set the thread pool to 1? `ExecutorService es = Executors.newFixedThreadPool(1); Connection conn = factory.newConnection(es);`","metadata":{"transformedAt":"2026-08-18T18:33:20.160Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":7,"totalLines":78,"estimatedTokens":558}}429{"id":"stack-6333691","source":"stackoverflow","questionId":6333691,"title":"best way to rotate rabbitmq log files","tags":["logging","rabbitmq"],"text":"Title: best way to rotate rabbitmq log files\nTags: logging, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nMy rabbit logs are getting very large and I am wondering if there is a better way to control the rotation. I'd like the logs to rotate based on size, and to keep at most ten logs at a time. The best I've found so far is that you can turn off logging by putting `SERVER_START_ARGS=\"-kernel error_logger silent\"` into the rabbitmq.conf file. Is there a better way? I'd like to avoid using a crontab for this.\n\n========================================\n\nTop Answer:\nThe best choice is put the log rotate logical inside your rabbitmq.conf file like below:\n\n```\n{log, [\n {file, [{file, \"/var/log/rabbitmq/rabbitmq.log\"}, %% log.file\n {level, info}, %% log.file.info\n {date, \"$D0\"}, %% log.file.rotation.date\n {size, 1024}, %% log.file.rotation.size\n {count, 15} %% log.file.rotation.count\n ]}\n ]},\n```\n\n========================================\n\nCode:\n```text\nSERVER_START_ARGS=\"-kernel error_logger silent\"\n```\n\n```text\nrabbitmqctl rotate_logs\n```\n\n```text\n{log, [\n {file, [{file, \"/var/log/rabbitmq/rabbitmq.log\"}, %% log.file\n {level, info}, %% log.file.info\n {date, \"$D0\"}, %% log.file.rotation.date\n {size, 1024}, %% log.file.rotation.size\n {count, 15} %% log.file.rotation.count\n ]}\n ]},\n```\n\n```text\n{lager, [\n\n {handlers, [\n {lager_file_backend, [{file, \"rabbit.log\"},\n {level, info},\n {date, \"$D0\"},\n {size, 10},\n {count, 2}\n ]}]}\n ]},\n```\n\n========================================\n\nComments:\n- \"handle this much better\" is not a good answer, as it indicates that there is no need for rotating in newer versions. Please read rabbitmq.com/logging.html as \"Log file rotation is not performed by default\"\n- Just noting that this needs RabbitMq 3.7 > version.","metadata":{"transformedAt":"2026-08-18T18:33:20.161Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":63,"estimatedTokens":502}}430{"id":"stack-17075116","source":"stackoverflow","questionId":17075116,"title":"Is it possible to move / merge messages between RabbitMQ queues?","tags":["python","queue","rabbitmq","amqp","pika"],"text":"Title: Is it possible to move / merge messages between RabbitMQ queues?\nTags: python, queue, rabbitmq, amqp, pika\nSource: Stack Overflow\n\nQuestion:\nI'm looking to know is it possible to move / merge messages from one queue to another.\nFor example:\n\n`main-queue` contains messages `['cat-1','cat-2','cat-3','cat-4','dog-1','dog-2','cat-5']`\n\n`dog-queue` contains messages `['dog-1, dog-2, dog-3, dog-4]`\n\nSo the question is, (assuming both queues are on the same cluster, vhost) it possible to move messages from `dog-queue` to `main-queue` using `rabbitmqctl` ?\n\nSo at the end I'm looking to get something like:\n\n### Ideally:\n\n`main-queue` : `['cat-1','cat-2','cat-3','cat-4','dog-1','dog-2','cat-5', dog-3, dog-4]`\n\n### But this is ok too:\n\n`main-queue` : `['cat-1','cat-2','cat-3','cat-4','dog-1','dog-2','cat-5', 'dog-1, dog-2, dog-3, dog-4]`\n\n========================================\n\nCode:\n```text\nmain-queue\n```\n\n```text\n['cat-1','cat-2','cat-3','cat-4','dog-1','dog-2','cat-5']\n```\n\n```text\ndog-queue\n```\n\n```text\n['dog-1, dog-2, dog-3, dog-4]\n```\n\n```text\ndog-queue\n```\n\n```text\nmain-queue\n```\n\n```text\nrabbitmqctl\n```\n\n```text\nmain-queue\n```\n\n```text\n['cat-1','cat-2','cat-3','cat-4','dog-1','dog-2','cat-5', dog-3, dog-4]\n```\n\n```text\nmain-queue\n```\n\n```text\n['cat-1','cat-2','cat-3','cat-4','dog-1','dog-2','cat-5', 'dog-1, dog-2, dog-3, dog-4]\n```\n\n```text\nsudo rabbitmq-plugins enable rabbitmq_shovel\n```\n\n```text\nsudo rabbitmq-plugins enable rabbitmq_shovel_management\n```\n\n```text\nsudo rabbitmqctl set_parameter shovel cats-and-dogs \\\n'{\"src-uri\": \"amqp://user:pass@host/vhost\", \"src-queue\": \"dog-queue\", \\\n\"dest-uri\": \"amqp://user:pass@host/vhost\", \"dest-queue\": \"main-queue\"}'\n```\n\n========================================\n\nComments:\n- I think you might need to look in to topic exchanges\n- That's right. I didn't noted that it possible via shovels. Thanks for providing correct answer and sorry for incorrect answer.\n- Note, you don't have to enable shovel plugin on every machine, while you can set it up even on some remote machine and have both source and destination also remote servers.\n- @rocksfrow, installed `rabbitmq_management` on all nodes is not a must.\n- @zaq178miami I updated my answer and removed the note about installing the management plugin on every node, although I still personally think you should the plugin on all of your nodes -- otherwise you'll potentially run into management issues after a node failure.\n- @rocksfrow, or any one here, what will be the output of this??\n- I tried this, but it is not showing any success/failure message\n- For future reference. I am using the plugin described by @rocksfrow I had a issue where my \"Move\" function with the admin GUI didn't work then I deleted the temporary shovel that was created and tried again then on the second attempt it moved the items.","metadata":{"transformedAt":"2026-08-18T18:33:20.161Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":14,"totalLines":96,"estimatedTokens":710}}431{"id":"stack-28253641","source":"stackoverflow","questionId":28253641,"title":"Is VirtualHost a good pattern in RabbitMQ?","tags":["rabbitmq","virtualhost"],"text":"Title: Is VirtualHost a good pattern in RabbitMQ?\nTags: rabbitmq, virtualhost\nSource: Stack Overflow\n\nQuestion:\nI have 100 clients. Each client has unique username, password and two channels (users can't connect to different channels apart from their own). Should I create VirtualHost for each user?\n\nHow to write proper user permission to the below situation?:\n\n- `my_user` can connect only to vahost called `user_vhost` using `username` and `password`\n\n- `my_user` can consume only from the `user_channel` channel\n\n- `my_user` can publish only to the `user_channel` channel\n\n- `my_user` can connect remotely\n\nThank You!\n\n========================================\n\nCode:\n```text\nmy_user\n```\n\n```text\nuser_vhost\n```\n\n```text\nusername\n```\n\n```text\npassword\n```\n\n```text\nmy_user\n```\n\n```text\nuser_channel\n```\n\n```text\nmy_user\n```\n\n```text\nuser_channel\n```\n\n```text\nmy_user\n```\n\n========================================\n\nComments:\n- How about creating, deleting, declaring queues, exchanges etc? Consumer should not have access to this action. Can I achieve this using only granting permission per vhost?\n- Yes, it is possible to set that kind of permissions using, for example, `rabbitmqctl`\n- How to do it? :-) I'm searching examples several hours :-)\n- Well, you can use something like this `rabbitmqctl set_permissions your_user \"^$\" \"^$\" \"your_user_.*\"` . If I am not wrong, this will grant permission to your_user for reading resources that start with the name \"your_user_\". The regexp `^$` is for denying.\n- To give read access to the queue `myqueue` I used: `rabbitmqctl set_permissions my_user \"myqueue.*\" \"^$\" \"myqueue.*\"` .. it works, but user can delete the queue, purge the queue etc. How to prevent it? I found default perms on rabbitmq.com/access-control.html, but I doesn't work, eg. `rabbitmqctl set_permissions my_user \"myqueue.*\" \"^$\" \"$(myqueue.queue.declare|myqueue.basic.consume)$\"`. I've got \"403, ACCESS_REFUSED - access to queue 'myqueue' in vhost '.' refused for user 'my_user'\". :-(\n- Here's the documentation for permissions rabbitmq.com/access-control.html","metadata":{"transformedAt":"2026-08-18T18:33:20.161Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":9,"totalLines":67,"estimatedTokens":521}}432{"id":"stack-2155759","source":"stackoverflow","questionId":2155759,"title":"Is AMQP production ready?","tags":[".net","python","rabbitmq","amqp"],"text":"Title: Is AMQP production ready?\nTags: .net, python, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI'd like to use AMQP to join two services one written in C# and other written in python.\nI'm expecting quite large volume of messages per second. \n\n- Is there any AMQP Broker that is production ready?\n\n- Are the python & .net bindings good enough?\n\n========================================\n\nTop Answer:\nYes: RabbitMQ\n\n========================================\n\nComments:\n- It depends on what do you mean by production ready ? and what kind of work you are doing. Definitely none of the open source broker can be used for financial domain where losing one message means losing millions.","metadata":{"transformedAt":"2026-08-18T18:33:20.161Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":21,"estimatedTokens":172}}433{"id":"stack-29221020","source":"stackoverflow","questionId":29221020,"title":"RabbitMQ 3.5 and Message Priority","tags":["c#","rabbitmq"],"text":"Title: RabbitMQ 3.5 and Message Priority\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nRabbitMQ 3.5 now supports message priority; \nHowever, I am unable to build a working example. I've placed my code below. It includes the output that I expect and the output I actually. I'd be interested in more documentation, and/or a working example.\n\nSo my question in short: How do I get message priority to work in Rabbit 3.5.0.0?\n\nPublisher:\n\n```\nusing System;\nusing RabbitMQ.Client;\nusing System.Text;\nusing System.Collections.Generic;\n\nclass Publisher\n{\n\n public static void Main()\n {\n var factory = new ConnectionFactory() { HostName = \"localhost\" };\n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n IDictionary args = new Dictionary() ;\n args.Add(\" x-max-priority \", 10);\n channel.QueueDeclare(\"task_queue1\", true, false, true, args);\n\n for (int i = 1 ; iConsumer:\n\n```\nusing System;\nusing RabbitMQ.Client;\nusing RabbitMQ.Client.Events;\nusing System.Text;\nusing System.Threading;\nusing System.Collections.Generic;\n\nnamespace Consumer\n{ \n class Worker\n {\n public static void Main()\n {\n var factory = new ConnectionFactory() { HostName = \"localhost\" };\n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n IDictionary args = new Dictionary(); \n channel.BasicQos(0, 1, false);\n var consumer = new QueueingBasicConsumer(channel);\n IDictionary consumerArgs = new Dictionary();\n channel.BasicConsume( \"task_queue1\", false, \"\", args, consumer);\n Console.WriteLine(\" [*] Waiting for messages. \" +\n \"To exit press CTRL+C\");\n while (true)\n {\n var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n Console.WriteLine(\" [x] Received {0}\", message);\n channel.BasicAck(ea.DeliveryTag, false);\n }\n }\n }\n }\n }\n}\n```\n\nActual output:\n\n```\n[*] Waiting for messages. To exit press CTRL+C\n[x] Received Message 1\n[x] Received Message 2\n[x] Received Message 3\n[x] Received Message 4\n[x] Received Message 5\n[x] Received Message 6\n[x] Received Message 7\n[x] Received Message 8\n[x] Received Message 9\n[x] Received Message 10\n```\n\nExpected output:\n\n```\n[*] Waiting for messages. To exit press CTRL+C\n[x] Received Message 10\n[x] Received Message 9\n[x] Received Message 8\n[x] Received Message 7\n[x] Received Message 6\n[x] Received Message 5\n[x] Received Message 4\n[x] Received Message 3\n[x] Received Message 2\n[x] Received Message 1\n```\n\nUPDATE #1.\nI found an example in Java here. However it's the Rabbit 3.4.x.x. addin that was incorporated into 3.5. \nThe only difference I can see is that they express the priority as an int and mine is a byte. But I feel like that's a red herring. I'm at a bit of a loss here.\n\n========================================\n\nTop Answer:\nA similar RabbitMq Priority Queue Implementation in Node JS\n\n**Install amqplib**\n\n*In order to test, we are required to have amqplib installed*\n\n```\nnpm install amqplib\n```\n\nPublisher (send.js)\n\n```\n#!/usr/bin/env node\n\nvar amqp = require('amqplib/callback_api');\n\nfunction bail(err, conn) {\n console.error(err);\n if (conn) conn.close(function() { process.exit(1); });\n}\n\nfunction on_connect(err, conn) {\n if (err !== null) return bail(err);\n\n // name of queue\n var q = 'hello';\n var msg = 'Hello World!';\n var priorityValue = 0;\n\n function on_channel_open(err, ch) {\n if (err !== null) return bail(err, conn);\n // maxPriority : max priority value supported by queue\n ch.assertQueue(q, {durable: false, maxPriority: 10}, function(err, ok) {\n if (err !== null) return bail(err, conn);\n\n for(var index=1; indexSubscriber (receive.js)\n\n```\n#!/usr/bin/env node\n\nvar amqp = require('amqplib/callback_api');\n\nfunction bail(err, conn) {\n console.error(err);\n if (conn) conn.close(function() { process.exit(1); });\n}\n\nfunction on_connect(err, conn) {\n if (err !== null) return bail(err);\n process.once('SIGINT', function() { conn.close(); });\n\n var q = 'hello';\n\n function on_channel_open(err, ch) {\n ch.assertQueue(q, {durable: false, maxPriority: 10}, function(err, ok) {\n if (err !== null) return bail(err, conn);\n ch.consume(q, function(msg) { // message callback\n console.log(\" [x] Received '%s'\", msg.content.toString());\n }, {noAck: true}, function(_consumeOk) { // consume callback\n console.log(' [*] Waiting for messages. To exit press CTRL+C');\n });\n });\n }\n\n conn.createChannel(on_channel_open);\n}\n\namqp.connect(on_connect);\n```\n\nRun:\n\n```\nnode send.js\n```\n\nIt will create a queue named 'hello' and will flood it with '1000' sample messages using default AMQP exchange. \n\n```\nnode receive.js\n```\n\nIt will act as a consumer to subscribe to messages waiting in the queue.\n\n========================================\n\nCode:\n```text\nusing System;\nusing RabbitMQ.Client;\nusing System.Text;\nusing System.Collections.Generic;\n\nclass Publisher\n{\n\n public static void Main()\n {\n var factory = new ConnectionFactory() { HostName = \"localhost\" };\n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n IDictionary <String , Object> args = new Dictionary<String,Object>() ;\n args.Add(\" x-max-priority \", 10);\n channel.QueueDeclare(\"task_queue1\", true, false, true, args);\n\n for (int i = 1 ; i<=10; i++ )\n {\n var message = \"Message\";\n var body = Encoding.UTF8.GetBytes(message + \" \" + i);\n var properties = channel.CreateBasicProperties();\n properties.SetPersistent(true);\n properties.Priority = Convert.ToByte(i);\n channel.BasicPublish(\"\", \"task_queue1\", properties, body);\n }\n }\n }\n }\n}\n```\n\n```text\nusing System;\nusing RabbitMQ.Client;\nusing RabbitMQ.Client.Events;\nusing System.Text;\nusing System.Threading;\nusing System.Collections.Generic;\n\nnamespace Consumer\n{ \n class Worker\n {\n public static void Main()\n {\n var factory = new ConnectionFactory() { HostName = \"localhost\" };\n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n IDictionary<String, Object> args = new Dictionary<String, Object>(); \n channel.BasicQos(0, 1, false);\n var consumer = new QueueingBasicConsumer(channel);\n IDictionary<string, object> consumerArgs = new Dictionary<string, object>();\n channel.BasicConsume( \"task_queue1\", false, \"\", args, consumer);\n Console.WriteLine(\" [*] Waiting for messages. \" +\n \"To exit press CTRL+C\");\n while (true)\n {\n var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n Console.WriteLine(\" [x] Received {0}\", message);\n channel.BasicAck(ea.DeliveryTag, false);\n }\n }\n }\n }\n }\n}\n```\n\n```text\n[*] Waiting for messages. To exit press CTRL+C\n[x] Received Message 1\n[x] Received Message 2\n[x] Received Message 3\n[x] Received Message 4\n[x] Received Message 5\n[x] Received Message 6\n[x] Received Message 7\n[x] Received Message 8\n[x] Received Message 9\n[x] Received Message 10\n```\n\n```text\n[*] Waiting for messages. To exit press CTRL+C\n[x] Received Message 10\n[x] Received Message 9\n[x] Received Message 8\n[x] Received Message 7\n[x] Received Message 6\n[x] Received Message 5\n[x] Received Message 4\n[x] Received Message 3\n[x] Received Message 2\n[x] Received Message 1\n```\n\n```text\nargs.Add(\" x-max-priority \", 10);\n```\n\n```text\nargs.Add(\"x-max-priority\", 10);\n```\n\n```text\nnpm install amqplib\n```\n\n```text\n#!/usr/bin/env node\n\nvar amqp = require('amqplib/callback_api');\n\nfunction bail(err, conn) {\n console.error(err);\n if (conn) conn.close(function() { process.exit(1); });\n}\n\nfunction on_connect(err, conn) {\n if (err !== null) return bail(err);\n\n // name of queue\n var q = 'hello';\n var msg = 'Hello World!';\n var priorityValue = 0;\n\n function on_channel_open(err, ch) {\n if (err !== null) return bail(err, conn);\n // maxPriority : max priority value supported by queue\n ch.assertQueue(q, {durable: false, maxPriority: 10}, function(err, ok) {\n if (err !== null) return bail(err, conn);\n\n for(var index=1; index<=100; index++) {\n priorityValue = Math.floor((Math.random() * 10));\n msg = 'Hello World!' + ' ' + index + ' ' + priorityValue;\n ch.publish('', q, new Buffer(msg), {priority: priorityValue});\n console.log(\" [x] Sent '%s'\", msg);\n }\n\n ch.close(function() { conn.close(); });\n });\n }\n\n conn.createChannel(on_channel_open);\n}\n\namqp.connect(on_connect);\n```\n\n```text\n#!/usr/bin/env node\n\nvar amqp = require('amqplib/callback_api');\n\nfunction bail(err, conn) {\n console.error(err);\n if (conn) conn.close(function() { process.exit(1); });\n}\n\nfunction on_connect(err, conn) {\n if (err !== null) return bail(err);\n process.once('SIGINT', function() { conn.close(); });\n\n var q = 'hello';\n\n function on_channel_open(err, ch) {\n ch.assertQueue(q, {durable: false, maxPriority: 10}, function(err, ok) {\n if (err !== null) return bail(err, conn);\n ch.consume(q, function(msg) { // message callback\n console.log(\" [x] Received '%s'\", msg.content.toString());\n }, {noAck: true}, function(_consumeOk) { // consume callback\n console.log(' [*] Waiting for messages. To exit press CTRL+C');\n });\n });\n }\n\n conn.createChannel(on_channel_open);\n}\n\namqp.connect(on_connect);\n```\n\n```text\nnode send.js\n```\n\n```text\nnode receive.js\n```\n\n```text\nvar consumer = new EventingBasicConsumer(channel);\nconsumer.Received += (ch, ea) =>\n {\n var body = ea.Body;\n // ... process the message\n ch.BasicAck(ea.DeliveryTag, false);\n }; \nString consumerTag = channel.BasicConsume(queueName, false, consumer);\n```\n\n```text\nbool noAck = false;\nBasicGetResult result = channel.BasicGet(queueName, noAck);\nif (result == null) {\n // No message available at this time.\n} else {\n IBasicProperties props = result.BasicProperties;\n byte[] body = result.Body;\n ...\n```\n\n```text\n...\n // acknowledge receipt of the message\n channel.BasicAck(result.DeliveryTag, false);\n}\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.161Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":14,"totalLines":428,"estimatedTokens":2681}}434{"id":"stack-11478002","source":"stackoverflow","questionId":11478002,"title":"Url Encode Forward Slash (/) in .NET","tags":["c#","url","rabbitmq"],"text":"Title: Url Encode Forward Slash (/) in .NET\nTags: c#, url, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nHow can I force either `Uri` or `HttpWebRequest` to allow a uri containing both `/` and `%2f` like the following?\n\n```\nhttp://localhost:55672/api/exchanges/%2f/MyExchange\n```\n\nI tried this...\n\n```\nWebRequest request = \n HttpWebRequest.Create(\"http://localhost:55672/api/exchanges/%2f/MyExchange\");\n```\n\n...and this...\n\n```\nUri uri = new Uri(\"http://localhost:55672/api/exchanges/%2f/MyExchange\", true);\nWebRequest request = HttpWebRequest.Create(uri);\n```\n\n...and this...\n\n```\nUriBuilder builder = new UriBuilder();\nbuilder.Port = 55672;\nbuilder.Path = \"api/exchanges/%2f/MyExchange\";\nWebRequest request = HttpWebRequest.Create(builder.Uri);\n```\n\nHowever with all of these, `request.RequestUri` ends up `http://localhost:55672/api/exchanges///MyExchange` and `request.GetResponse()` produces a 404 response.\n\nFYI I'm trying to use RabbitMQ's HTTP API and typing the Url in Chrome produces the expected JSON result.\n\n========================================\n\nTop Answer:\nI had this exact same problem when communicating with the RabbitMQ management API a while back. I wrote a blog post about it, including a couple of solutions:\n\nhttp://mikehadlow.blogspot.co.uk/2011/08/how-to-stop-systemuri-un-escaping.html\n\nYou can turn the behavior off either with some nasty reflection into the System.Uri code, or by a setting in App.config (or Web.config):\n\n```\n \n \n \n \n\n```\n\n========================================\n\nCode:\n```text\nhttp://localhost:55672/api/exchanges/%2f/MyExchange\n```\n\n```text\nWebRequest request = \n HttpWebRequest.Create(\"http://localhost:55672/api/exchanges/%2f/MyExchange\");\n```\n\n```text\nUri uri = new Uri(\"http://localhost:55672/api/exchanges/%2f/MyExchange\", true);\nWebRequest request = HttpWebRequest.Create(uri);\n```\n\n```text\nUriBuilder builder = new UriBuilder();\nbuilder.Port = 55672;\nbuilder.Path = \"api/exchanges/%2f/MyExchange\";\nWebRequest request = HttpWebRequest.Create(builder.Uri);\n```\n\n```text\nUri\n```\n\n```text\nHttpWebRequest\n```\n\n```text\n/\n```\n\n```text\n%2f\n```\n\n```text\nrequest.RequestUri\n```\n\n```text\nhttp://localhost:55672/api/exchanges///MyExchange\n```\n\n```text\nrequest.GetResponse()\n```\n\n```text\n<uri> \n <schemeSettings>\n <add name=\"http\" genericUriParserOptions=\"DontUnescapePathDotsAndSlashes\" />\n </schemeSettings>\n</uri>\n```\n\n========================================\n\nComments:\n- I also tried `HttpWebRequest.Create(\"http://localhost:55672/api/exchanges/‌​%252f/PrintConnector‌​\");` What is interesting is that this produces the same `request.RequestUri` as above, but `request.RequestUri.LocalPath` is correctly encoded to `/api/exchanges/%2f/MyConnector`\n- FWIW I've built a .NET client for the RabbitMQ management API that might save you some work: nuget.org/packages/EasyNetQ.Management.Client\n- Unfortunately Uri.EscapeDataString produces the same result: `request = HttpWebRequest.Create(\"http://localhost:55672/api/exchanges/‌​\" + Uri.EscapeDataString(\"/\") + \"/MyExchange\");`\n- Targeting .NET 4.5 fixed it, even without the uri config setting. Perhaps it was a bug in the .NET framework.\n- Seems to be back in .NET Core 2.0.\n- Thanks for this, we managed to easily reproduce this in .NET (we switched between 4.0 and 4.6.1). The problem we're having is when calling the same code from COM interop. The COM DLL is targeting .NET Framework 4.6.1 but we're still getting the 4.0 behaviour (ie the forward slash is un-encoded). We're running out of ideas and getting desperate. When running, Environment.Version is 4.0.30319.42000.\n- Perhaps I'm doing something wrong, but neither solution seems to work from VS 2010 or 2012 (using console application). `Uri uri = new Uri(\"http://localhost:55672/api/exchanges/%2f/MyExchange\"); Console.WriteLine(uri);`\n- I use exactly that method in my RabbitMQ.Management.Client library. Have a look here: github.com/mikehadlow/EasyNetQ/tree/master/Source/…","metadata":{"transformedAt":"2026-08-18T18:33:20.161Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":126,"estimatedTokens":1021}}435{"id":"stack-53351186","source":"stackoverflow","questionId":53351186,"title":"Publish to RabbitMQ queue with HTTP API","tags":["rabbitmq"],"text":"Title: Publish to RabbitMQ queue with HTTP API\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nBeen going through the documentation (https://cdn.rawgit.com/rabbitmq/rabbitmq-management/v3.7.9/priv/www/api/index.html)\n\nAnd did not find a way to publish a message to a *queue* (not an exchange, a queue) with the HTTP API?\n\nIs that possible?\n\nAs much as it might make little sens in a production mindset, it still can be useful for testing purposes.\n\nI basically want to mimic the “Publish message” interface available in the RabbitMQ administration console.\n\nIs this possible somehow?\n\n========================================\n\nTop Answer:\nFor those interested in Intellij IDEA HTTP Client syntax with an array of ids\n\n```\n[\n {\"id\": \"83d6e4dc-0478-42da-8da0-65b508530a43\"},\n {\"id\": \"08d3e147-79c4-4b91-be7c-b1cc86e21278\"}\n]\n\nPOST http://localhost:15672/api/exchanges/%2F/amqp.myexchange/publish\nAuthorization: Basic guest guest\nContent-Type: application/json\n\n{\n \"vhost\": \"/\",\n \"name\": \"amqp.myexchange\",\n \"properties\": {\n \"delivery_mode\": 2,\n \"headers\": {},\n \"content_type\": \"application/json\"\n },\n \"routing_key\": \"\",\n \"delivery_mode\": \"2\",\n \"payload\": \"[{\\\"id\\\":\\\"83d6e4dc-0478-42da-8da0-65b508530a43\\\"},{\\\"id\\\":\\\"08d3e147-79c4-4b91-be7c-b1cc86e21278\\\"}]\",\n \"headers\": {},\n \"props\": {\n \"content_type\": \"application/json\"\n },\n \"payload_encoding\": \"string\"\n}\n```\n\n========================================\n\nCode:\n```text\nchannel.basic_publish(exchange='',\n routing_key='hello',\n body=message)\n```\n\n```text\ncurl -4vvv -u guest:guest \\\n 'localhost:15672/api/exchanges/%2F/amq.default/publish' \\\n -H 'Content-Type: text/plain;charset=UTF-8' \\\n --data-binary '{\"vhost\":\"/\",\"name\":\"amq.default\",\"properties\":{\"delivery_mode\":1,\"headers\":{}},\"routing_key\":\"MY-QUEUE-NAME\",\"delivery_mode\":\"1\",\"payload\":\"TEST\",\"headers\":{},\"props\":{},\"payload_encoding\":\"string\"}'\n```\n\n```text\namq.default\n```\n\n```text\n\"\"\n```\n\n```text\n/api/exchanges/vhost/name/publish\n```\n\n```text\npublish\n```\n\n```text\nC:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.7.18\\sbin>\nC:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.7.18\\sbin>curl -i -u guest:guest localhost:15672/api/exchanges/%2F/amq.default/publish -H 'content-type:application/json\" -d '{\"vhost\":\"/\",\"name\":\"amq.default\",\"properties\":{\"delivery_mode\":1,\"headers\":{}},\"routing_key\":\"TEST,\"delivery_mode\":\"1\",\"payload\":\"TEST\",\"headers\":{},\"props\":{},\"payload_encoding\":\"string\"}'\nHTTP/1.1 405 Method Not Allowed\nallow: POST, OPTIONS\ncontent-length: 0\ncontent-security-policy: default-src 'self'\ndate: Fri, 06 Dec 2019 14:03:08 GMT\nserver: Cowboy\nvary: origin\n```\n\n```text\n[\n {\"id\": \"83d6e4dc-0478-42da-8da0-65b508530a43\"},\n {\"id\": \"08d3e147-79c4-4b91-be7c-b1cc86e21278\"}\n]\n\nPOST http://localhost:15672/api/exchanges/%2F/amqp.myexchange/publish\nAuthorization: Basic guest guest\nContent-Type: application/json\n\n{\n \"vhost\": \"/\",\n \"name\": \"amqp.myexchange\",\n \"properties\": {\n \"delivery_mode\": 2,\n \"headers\": {},\n \"content_type\": \"application/json\"\n },\n \"routing_key\": \"\",\n \"delivery_mode\": \"2\",\n \"payload\": \"[{\\\"id\\\":\\\"83d6e4dc-0478-42da-8da0-65b508530a43\\\"},{\\\"id\\\":\\\"08d3e147-79c4-4b91-be7c-b1cc86e21278\\\"}]\",\n \"headers\": {},\n \"props\": {\n \"content_type\": \"application/json\"\n },\n \"payload_encoding\": \"string\"\n}\n```\n\n========================================\n\nComments:\n- You can obtain the actual API for your version of RabbitMQ by pointing your browser to localhost:15672/api.\n- FYI, this curl call does work as well against AWS AmazonMQ RabbitMQ, through the console https port 443. Thanks!\n- corrected json: curl -i -u guest:guest localhost:32936/api/exchanges/%2F/amq.default/publish -H \"content-type:application/json\" -d '{\"vhost\":\"/platform\",\"name\":\"innovasea\",\"properties\":{\"deli‌​very_mode\":1,\"header‌​s\":{}},\"routing_key\"‌​:\"TEST\",\"delivery_mo‌​de\":\"1\",\"payload\":\"T‌​ESTadf\",\"headers\":{}‌​,\"props\":{},\"payload‌​_encoding\":\"string\"}‌​'","metadata":{"transformedAt":"2026-08-18T18:33:20.161Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":130,"estimatedTokens":1008}}436{"id":"stack-35773789","source":"stackoverflow","questionId":35773789,"title":"IncompatibleProtocolError while trying to connect to RabbitMQ","tags":["python","rabbitmq","pika"],"text":"Title: IncompatibleProtocolError while trying to connect to RabbitMQ\nTags: python, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI've got a problem with connecting from Python code using pika to dockerized RabbitMQ.\nI'm using this code to connect to the queue:\n\n```\n@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, stop_max_attempt_number=2)\ndef rabbit_connect():\n connection_uri = cfg.get(\"System\", \"rabbit_uri\", raw=True)\n queue = cfg.get(\"System\", \"queue\")\n username = cfg.get(\"System\", \"username\")\n password = cfg.get(\"System\", \"password\")\n host = cfg.get(\"System\", \"rabbit_host\")\n port = cfg.get(\"System\", \"rabbit_port\")\n credentials = pika.PlainCredentials(username, password)\n log.info(\"Connecting queue %s at %s:%s\", queue, host, port)\n connection = None\n try:\n connection = pika.BlockingConnection(pika.ConnectionParameters(credentials=credentials, host=host, port=int(port)))\n except Exception, e:\n log.error(\"Can't connect to RabbitMQ\")\n log.error(e.message)\n raise\n```\n\nAnd these are my docker containers:\n\n```\nroot@pc:~# docker ps\nCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES\n2063ad939823 rabbitmq:3-management \"/docker-entrypoint.s\" About an hour ago Up About an hour 4369/tcp, 5671-5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:8080->15672/tcp new-rabbitmg\n94628f1fb33f rabbitmq \"/docker-entrypoint.s\" About an hour ago Up About an hour 4369/tcp, 5671-5672/tcp, 25672/tcp new-rabbit\n```\n\nWhen I try to connect to localhost:8080 with any available credentials, pika retries connection until the error comes:\n\n```\nTraceback (most recent call last):\n File \"script.py\", line 146, in worker\n connection = rabbit_connect()\n File \"build/bdist.linux-x86_64/egg/retrying.py\", line 49, in wrapped_f\n return Retrying(*dargs, **dkw).call(f, *args, **kw)\n File \"build/bdist.linux-x86_64/egg/retrying.py\", line 212, in call\n raise attempt.get()\n File \"build/bdist.linux-x86_64/egg/retrying.py\", line 247, in get\n six.reraise(self.value[0], self.value[1], self.value[2])\n File \"build/bdist.linux-x86_64/egg/retrying.py\", line 200, in call\n attempt = Attempt(fn(*args, **kwargs), attempt_number, False)\n File \"script.py\", line 175, in rabbit_connect\n connection = pika.BlockingConnection(pika.ConnectionParameters(credentials=credentials, host=host, port=int(port)))\n File \"build/bdist.linux-x86_64/egg/pika/adapters/blocking_connection.py\", line 339, in __init__\n self._process_io_for_connection_setup()\n File \"build/bdist.linux-x86_64/egg/pika/adapters/blocking_connection.py\", line 374, in _process_io_for_connection_setup\n self._open_error_result.is_ready)\n File \"build/bdist.linux-x86_64/egg/pika/adapters/blocking_connection.py\", line 410, in _flush_output\n self._impl.ioloop.poll()\n File \"build/bdist.linux-x86_64/egg/pika/adapters/select_connection.py\", line 602, in poll\n self._process_fd_events(fd_event_map, write_only)\n File \"build/bdist.linux-x86_64/egg/pika/adapters/select_connection.py\", line 443, in _process_fd_events\n handler(fileno, events, write_only=write_only)\n File \"build/bdist.linux-x86_64/egg/pika/adapters/base_connection.py\", line 364, in _handle_events\n self._handle_read()\n File \"build/bdist.linux-x86_64/egg/pika/adapters/base_connection.py\", line 412, in _handle_read\n return self._handle_disconnect()\n File \"build/bdist.linux-x86_64/egg/pika/adapters/base_connection.py\", line 288, in _handle_disconnect\n self._adapter_disconnect()\n File \"build/bdist.linux-x86_64/egg/pika/adapters/select_connection.py\", line 95, in _adapter_disconnect\n super(SelectConnection, self)._adapter_disconnect()\n File \"build/bdist.linux-x86_64/egg/pika/adapters/base_connection.py\", line 154, in _adapter_disconnect\n self._check_state_on_disconnect()\n File \"build/bdist.linux-x86_64/egg/pika/adapters/base_connection.py\", line 169, in _check_state_on_disconnect\n raise exceptions.IncompatibleProtocolError\nIncompatibleProtocolError\n```\n\nIs it some kind of bug? Or am I doing something not right?\n\n========================================\n\nCode:\n```text\n@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, stop_max_attempt_number=2)\ndef rabbit_connect():\n connection_uri = cfg.get(\"System\", \"rabbit_uri\", raw=True)\n queue = cfg.get(\"System\", \"queue\")\n username = cfg.get(\"System\", \"username\")\n password = cfg.get(\"System\", \"password\")\n host = cfg.get(\"System\", \"rabbit_host\")\n port = cfg.get(\"System\", \"rabbit_port\")\n credentials = pika.PlainCredentials(username, password)\n log.info(\"Connecting queue %s at %s:%s\", queue, host, port)\n connection = None\n try:\n connection = pika.BlockingConnection(pika.ConnectionParameters(credentials=credentials, host=host, port=int(port)))\n except Exception, e:\n log.error(\"Can't connect to RabbitMQ\")\n log.error(e.message)\n raise\n```\n\n```text\nroot@pc:~# docker ps\nCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES\n2063ad939823 rabbitmq:3-management \"/docker-entrypoint.s\" About an hour ago Up About an hour 4369/tcp, 5671-5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:8080->15672/tcp new-rabbitmg\n94628f1fb33f rabbitmq \"/docker-entrypoint.s\" About an hour ago Up About an hour 4369/tcp, 5671-5672/tcp, 25672/tcp new-rabbit\n```\n\n```text\nTraceback (most recent call last):\n File \"script.py\", line 146, in worker\n connection = rabbit_connect()\n File \"build/bdist.linux-x86_64/egg/retrying.py\", line 49, in wrapped_f\n return Retrying(*dargs, **dkw).call(f, *args, **kw)\n File \"build/bdist.linux-x86_64/egg/retrying.py\", line 212, in call\n raise attempt.get()\n File \"build/bdist.linux-x86_64/egg/retrying.py\", line 247, in get\n six.reraise(self.value[0], self.value[1], self.value[2])\n File \"build/bdist.linux-x86_64/egg/retrying.py\", line 200, in call\n attempt = Attempt(fn(*args, **kwargs), attempt_number, False)\n File \"script.py\", line 175, in rabbit_connect\n connection = pika.BlockingConnection(pika.ConnectionParameters(credentials=credentials, host=host, port=int(port)))\n File \"build/bdist.linux-x86_64/egg/pika/adapters/blocking_connection.py\", line 339, in __init__\n self._process_io_for_connection_setup()\n File \"build/bdist.linux-x86_64/egg/pika/adapters/blocking_connection.py\", line 374, in _process_io_for_connection_setup\n self._open_error_result.is_ready)\n File \"build/bdist.linux-x86_64/egg/pika/adapters/blocking_connection.py\", line 410, in _flush_output\n self._impl.ioloop.poll()\n File \"build/bdist.linux-x86_64/egg/pika/adapters/select_connection.py\", line 602, in poll\n self._process_fd_events(fd_event_map, write_only)\n File \"build/bdist.linux-x86_64/egg/pika/adapters/select_connection.py\", line 443, in _process_fd_events\n handler(fileno, events, write_only=write_only)\n File \"build/bdist.linux-x86_64/egg/pika/adapters/base_connection.py\", line 364, in _handle_events\n self._handle_read()\n File \"build/bdist.linux-x86_64/egg/pika/adapters/base_connection.py\", line 412, in _handle_read\n return self._handle_disconnect()\n File \"build/bdist.linux-x86_64/egg/pika/adapters/base_connection.py\", line 288, in _handle_disconnect\n self._adapter_disconnect()\n File \"build/bdist.linux-x86_64/egg/pika/adapters/select_connection.py\", line 95, in _adapter_disconnect\n super(SelectConnection, self)._adapter_disconnect()\n File \"build/bdist.linux-x86_64/egg/pika/adapters/base_connection.py\", line 154, in _adapter_disconnect\n self._check_state_on_disconnect()\n File \"build/bdist.linux-x86_64/egg/pika/adapters/base_connection.py\", line 169, in _check_state_on_disconnect\n raise exceptions.IncompatibleProtocolError\nIncompatibleProtocolError\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.161Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":148,"estimatedTokens":1949}}437{"id":"stack-24803021","source":"stackoverflow","questionId":24803021,"title":"Celery First Steps - timeout error on result.get()","tags":["python","rabbitmq","celery","django-celery"],"text":"Title: Celery First Steps - timeout error on result.get()\nTags: python, rabbitmq, celery, django-celery\nSource: Stack Overflow\n\nQuestion:\nI am following the Celery First Steps tutorial here : http://celery.readthedocs.org/en/latest/getting-started/first-steps-with-celery.html#keeping-results\n\nI am following with the tutorial as is, with RabbitMQ.\n\nWhen I am doing result.get(timeout=1), it is showing a timeout error, even though it is a simple add operation, and I can see the worker running and producing correct result (of 8) in the other window\n\n```\n(venv) C:\\Volt\\celerytest>ipython\nPython 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]\nType \"copyright\", \"credits\" or \"license\" for more information.\n\nIPython 2.1.0 -- An enhanced Interactive Python.\n? -> Introduction and overview of IPython's features.\n%quickref -> Quick reference.\nhelp -> Python's own help system.\nobject? -> Details about 'object', use 'object??' for extra details.\n\nIn [1]: from tasks import add\n\nIn [2]: a = add(1,3)\n\nIn [3]: a\nOut[3]: 4\n\nIn [4]: a = add.delay(1,3)\n\nIn [5]: a.ready()\nOut[5]: False\n\nIn [6]: a = add.delay(4,4)\n\nIn [7]: a.get(timeout=0.5)\n---------------------------------------------------------------------------\nTimeoutError Traceback (most recent call last)\n in ()\n----> 1 a.get(timeout=0.5)\n\nC:\\Users\\Som\\Envs\\venv\\lib\\site-packages\\celery\\result.pyc in get(self, timeout,\n propagate, interval, no_ack, follow_parents)\n 167 interval=interval,\n 168 on_interval=on_interval,\n--> 169 no_ack=no_ack,\n 170 )\n 171 finally:\n\nC:\\Users\\Som\\Envs\\venv\\lib\\site-packages\\celery\\backends\\amqp.pyc in wait_for(se\nlf, task_id, timeout, cache, propagate, no_ack, on_interval, READY_STATES, PROPA\nGATE_STATES, **kwargs)\n 155 on_interval=on_interval)\n 156 except socket.timeout:\n--> 157 raise TimeoutError('The operation timed out.')\n 158\n 159 if meta['status'] in PROPAGATE_STATES and propagate:\n\nTimeoutError: The operation timed out.\n\nIn [8]:\n```\n\n**tasks.py file**\n\n```\nfrom celery import Celery\n\napp = Celery('tasks', backend='amqp', broker='amqp://')\n\n@app.task\ndef add(x, y):\n return x + y\n```\n\n**worker log**\n\n```\n[tasks]\n . tasks.add\n\n[2014-07-17 13:00:33,196: INFO/MainProcess] Connected to amqp://guest:**@127.0.0\n.1:5672//\n[2014-07-17 13:00:33,211: INFO/MainProcess] mingle: searching for neighbors\n[2014-07-17 13:00:34,220: INFO/MainProcess] mingle: all alone\n[2014-07-17 13:00:34,240: WARNING/MainProcess] celery@SomsPC ready.\n[2014-07-17 13:00:34,242: INFO/MainProcess] Received task: tasks.add[85ff75d8-38\nb5-442a-a574-c8b976a33739]\n[2014-07-17 13:00:34,243: INFO/MainProcess] Task tasks.add[85ff75d8-38b5-442a-a5\n74-c8b976a33739] succeeded in 0.000999927520752s: 4\n[2014-07-17 13:00:46,582: INFO/MainProcess] Received task: tasks.add[49de7c6b-96\n72-485d-926e-a4e564ccc89a]\n[2014-07-17 13:00:46,588: INFO/MainProcess] Task tasks.add[49de7c6b-9672-485d-92\n6e-a4e564ccc89a] succeeded in 0.00600004196167s: 8\n```\n\n========================================\n\nTop Answer:\nIf you look at this thread it appears that setting `--pool=solo` also solves the issue. This works for me.\n\n========================================\n\nCode:\n```text\n(venv) C:\\Volt\\celerytest>ipython\nPython 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]\nType \"copyright\", \"credits\" or \"license\" for more information.\n\nIPython 2.1.0 -- An enhanced Interactive Python.\n? -> Introduction and overview of IPython's features.\n%quickref -> Quick reference.\nhelp -> Python's own help system.\nobject? -> Details about 'object', use 'object??' for extra details.\n\nIn [1]: from tasks import add\n\nIn [2]: a = add(1,3)\n\nIn [3]: a\nOut[3]: 4\n\nIn [4]: a = add.delay(1,3)\n\nIn [5]: a.ready()\nOut[5]: False\n\nIn [6]: a = add.delay(4,4)\n\nIn [7]: a.get(timeout=0.5)\n---------------------------------------------------------------------------\nTimeoutError Traceback (most recent call last)\n<ipython-input-7-2c407a92720e> in <module>()\n----> 1 a.get(timeout=0.5)\n\nC:\\Users\\Som\\Envs\\venv\\lib\\site-packages\\celery\\result.pyc in get(self, timeout,\n propagate, interval, no_ack, follow_parents)\n 167 interval=interval,\n 168 on_interval=on_interval,\n--> 169 no_ack=no_ack,\n 170 )\n 171 finally:\n\nC:\\Users\\Som\\Envs\\venv\\lib\\site-packages\\celery\\backends\\amqp.pyc in wait_for(se\nlf, task_id, timeout, cache, propagate, no_ack, on_interval, READY_STATES, PROPA\nGATE_STATES, **kwargs)\n 155 on_interval=on_interval)\n 156 except socket.timeout:\n--> 157 raise TimeoutError('The operation timed out.')\n 158\n 159 if meta['status'] in PROPAGATE_STATES and propagate:\n\nTimeoutError: The operation timed out.\n\nIn [8]:\n```\n\n```text\nfrom celery import Celery\n\napp = Celery('tasks', backend='amqp', broker='amqp://')\n\n\n@app.task\ndef add(x, y):\n return x + y\n```\n\n```text\n[tasks]\n . tasks.add\n\n[2014-07-17 13:00:33,196: INFO/MainProcess] Connected to amqp://guest:**@127.0.0\n.1:5672//\n[2014-07-17 13:00:33,211: INFO/MainProcess] mingle: searching for neighbors\n[2014-07-17 13:00:34,220: INFO/MainProcess] mingle: all alone\n[2014-07-17 13:00:34,240: WARNING/MainProcess] celery@SomsPC ready.\n[2014-07-17 13:00:34,242: INFO/MainProcess] Received task: tasks.add[85ff75d8-38\nb5-442a-a574-c8b976a33739]\n[2014-07-17 13:00:34,243: INFO/MainProcess] Task tasks.add[85ff75d8-38b5-442a-a5\n74-c8b976a33739] succeeded in 0.000999927520752s: 4\n[2014-07-17 13:00:46,582: INFO/MainProcess] Received task: tasks.add[49de7c6b-96\n72-485d-926e-a4e564ccc89a]\n[2014-07-17 13:00:46,588: INFO/MainProcess] Task tasks.add[49de7c6b-9672-485d-92\n6e-a4e564ccc89a] succeeded in 0.00600004196167s: 8\n```\n\n```text\napp = Celery('tasks', broker='amqp://guest@localhost//')\napp.conf.CELERY_RESULT_BACKEND = 'db+sqlite:///results.sqlite'\n```\n\n```text\nbackend='amqp'\n```\n\n```text\nTask tasks.add[49de7c6b-9672-485d-926e-a4e564ccc89a] succeeded in 0.00600004196167s: 8\n```\n\n```text\n--pool=solo\n```\n\n```text\ncelery_app.update(\n redis_socket_timeout=5,\n redis_socket_connect_timeout=5,\n)\n\n\ndef run_task(task, *args, **kwargs):\n timeout = 2 * 60\n future = task.apply_async(args, kwargs)\n time_end = time.time() + timeout\n\n while True:\n try:\n return future.get(timeout=timeout)\n except redis.TimeoutError:\n if time.time() < time_end:\n continue\n raise\n```\n\n```text\nTimeoutError\n```\n\n========================================\n\nComments:\n- Thanks for that. Its a really simple hack yet it tripped me for two days straight... Thanks. But wonder why they won't point out that in the docs plus also I wonder if it will affect the rest of the guide since the guide is based on an `amqp` broker\n- This error is still in the documentation without any suggested fix. I'm going to make a request to fix this.\n- +1 for showing how to use a different result backend! Note that sqlalchemy is required to use sqlite backend which can be easily installed via `pip install sqlalchemy`.\n- Probably the quickest solution to the problem. But bare in mind that calling celery with the `--pool=solo` flag makes celery use a single-threaded implementation of the worker pool which stops you from potentially taking advantage of parallel processing. Thus I guess the Strikki's accepted solution should be preferred.","metadata":{"transformedAt":"2026-08-18T18:33:20.161Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":237,"estimatedTokens":1850}}438{"id":"stack-5363401","source":"stackoverflow","questionId":5363401,"title":"What language was RabbitMQ written in?","tags":["rabbitmq"],"text":"Title: What language was RabbitMQ written in?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm looking at the repos and there are so many projects, not sure which are wrappers/clients and which is the actual project.\n\nIs it Erlang?\n\n========================================\n\nTop Answer:\nSee Wikipedia: RabbitMQ\n\n \n **The RabbitMQ server is written in Erlang** and is built on the Open Telecom Platform framework for clustering and failover.\n\n \n\nThe actual documentation/promo on http://rabbitmq.com is rather fluffy ;-)","metadata":{"transformedAt":"2026-08-18T18:33:20.161Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":20,"estimatedTokens":131}}439{"id":"stack-8981422","source":"stackoverflow","questionId":8981422,"title":"Rabbit MQ fails to start","tags":["erlang","rabbitmq"],"text":"Title: Rabbit MQ fails to start\nTags: erlang, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have finished installing RabbitMQ using the following RPM\n\nhttp://www.rabbitmq.com/releases/rabbitmq-server/v2.7.1/rabbitmq-server-2.7.1-1.noarch.rpm\n\ni installed it like so :\n\n```\n$ wget \\ http://www.rabbitmq.com/releases/rabbitmq-server/v2.7.1/rabbitmq-server-2.7.1-1.noarch.rpm\n$ rpm --nodeps -Uvh rabbitmq-server-2.7.1-1.noarch.rpm\n```\n\nthe reason i used --nodeps was because i installed erlang from source and the rpm will try looking for an erlang.rpm dependency ignoring the one on the system.\n\nWhen i try to start the Rabbit MQ server i get this error :\n\n```\n/usr/lib/rabbitmq/bin/rabbitmq-server: line 73: /var/lib/rabbitmq/mnesia/rabbit@\nvz129.pid: Permission denied\n{\"init terminating in do_boot\",{undef,[{rabbit_prelaunch,start,[]},{init,start_i\nt,1},{init,start_em,1}]}}\n```\n\nIm using CentOS release 4.9 (Final).\n\nAny help is appreciated.\n\n========================================\n\nCode:\n```text\n$ wget \\ http://www.rabbitmq.com/releases/rabbitmq-server/v2.7.1/rabbitmq-server-2.7.1-1.noarch.rpm\n$ rpm --nodeps -Uvh rabbitmq-server-2.7.1-1.noarch.rpm\n```\n\n```text\n/usr/lib/rabbitmq/bin/rabbitmq-server: line 73: /var/lib/rabbitmq/mnesia/rabbit@\nvz129.pid: Permission denied\n{\"init terminating in do_boot\",{undef,[{rabbit_prelaunch,start,[]},{init,start_i\nt,1},{init,start_em,1}]}}\n```\n\n```text\nchown -R rabbitmq:rabbitmq /var/lib/rabbitmq/\n```\n\n========================================\n\nComments:\n- Who is the owner of this directory /var/lib/rabbitmq/mnesia and what user are you running rabbitmq as?\n- thanks for replying, root is the owner and i was running as rabbitmq user, it was a simple permission error.","metadata":{"transformedAt":"2026-08-18T18:33:20.161Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":55,"estimatedTokens":429}}440{"id":"stack-12277067","source":"stackoverflow","questionId":12277067,"title":"Java & RabbitMQ - Queueing & Multithreading - Or Couchbase as Job-Queue","tags":["java","multithreading","mongodb","rabbitmq","couchbase"],"text":"Title: Java & RabbitMQ - Queueing & Multithreading - Or Couchbase as Job-Queue\nTags: java, multithreading, mongodb, rabbitmq, couchbase\nSource: Stack Overflow\n\nQuestion:\ni have one `Job Distributor` who publishes messages on different `Channels`.\n\nFurther, i want to have two (and more in the future) `Consumers` who work on different tasks and run on different machines. (Currently i have only one and need to scale it)\n\nLet's name these tasks (just examples):\n\n- `FIBONACCI` (generates fibonacci numbers)\n\n- `RANDOMBOOKS` (generates random sentences to write a book)\n\nThose tasks run up to 2-3 hours and **should be divided equally to each `Consumer`**.\n\nEvery Consumer can have `x` **parallel** threads for working on these tasks.\nSo i say: (those numbers are just examples and will be replaced by variables)\n\n- Machine 1 can consume 3 **parallel** jobs for `FIBONACCI` and 5 **parallel** jobs for `RANDOMBOOKS`\n\n- Machine 2 can consume 7 **parallel** jobs for `FIBONACCI` and 3 **parallel** jobs for `RANDOMBOOKS`\n\nHow can i achieve this?\n\nDo i have to start `x` Threads for each `Channel` to listen on on each `Consumer` ?\n\nWhen do i have to ack that? \n\nMy current approach for only one `Consumer` is: Start `x` Threads for each Task - each Thread is a Defaultconsumer implementing `Runnable`. In the `handleDelivery` method, i call `basicAck(deliveryTag,false)` and then do the work.\n\nFurther: I want to send some tasks to a special consumer. How can i achieve that in combination with the fair distribution as mentioned above?\n\nThis is my Code for `publishing`\n\n```\nString QUEUE_NAME = \"FIBONACCI\";\n\nChannel channel = this.clientManager.getRabbitMQConnection().createChannel();\n\nchannel.queueDeclare(QUEUE_NAME, true, false, false, null);\n\nchannel.basicPublish(\"\", QUEUE_NAME,\n MessageProperties.BASIC,\n Control.getBytes(this.getArgument()));\n\nchannel.close();\n```\n\nThis is my code for the `Consumer`\n\n```\npublic final class Worker extends DefaultConsumer implements Runnable {\n @Override\n public void run() {\n\n try {\n this.getChannel().queueDeclare(this.jobType.toString(), true, false, false, null);\n this.getChannel().basicConsume(this.jobType.toString(), this);\n\n this.getChannel().basicQos(1);\n } catch (IOException e) {\n // catch something\n }\n while (true) {\n try {\n Thread.sleep(1000);\n } catch (InterruptedException e) {\n Control.getLogger().error(\"Exception!\", e);\n }\n\n }\n }\n\n @Override\n public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] bytes) throws IOException {\n String routingKey = envelope.getRoutingKey();\n String contentType = properties.getContentType();\n this.getChannel().basicAck(deliveryTag, false); // Is this right?\n // Start new Thread for this task with my own ExecutorService\n\n }\n}\n```\n\nThe class `Worker` is started twice in this case: Once for `FIBUNACCI` and once for `RANDOMBOOKS`\n\n**UPDATE**\n\nAs the answers stated, RabbitMQ would not be the best solution for this, but a Couchbase or MongoDB pull approach would be best. I'm new to those systems, is there anybody that could explain to me, how this would be achieved?\n\n========================================\n\nTop Answer:\nFirst let me say that I haven't used Java for communicating with RabbitMQ so I wont be able to provide code-examples. That shouldn't be a problem however since that's not what you're asking about. This question is more about the general design of your application.\n\nLets break it down a bit, because there's a lot of questions going on here.\n\n### Dividing the tasks on different consumers\n\nWell one way to do this is to use round-robin, but that is rather crude and doesn't take into account that different tasks may take a different amount of time to finish. So what to do. Well one way to do this is to set the `prefetch` to `1`. Prefetching means that the consumer caches the messages locally (**note:** the message is not consumed yet). By setting this value to 1 no prefetching will occur. This means that your consumer will only know about and only have the message which it is currently working on in memory. This makes it possible to only receive messages, when the worker is idle.\n\n### When to acknowledge\n\nWith the setup described above it is possible to read a message from the queue, pass it on to one of your threads, and then acknowledge the message. Do this for all the available threads -1. You don't want to acknowledge the last message, because that means that you'll open up for receiving another message which you won't be able to pass to one of your workers yet. When one of the threads finishes, that's when you acknowledge that message, this way you'll always have your threads working with something. \n\n### passing on special messages\n\nThis depends on what you wan't to do, but in general I'd say that your producers should know what they are passing on. This means that you'd be able to send it to a certain exchange or rather with a certain routing-key that would pass on this message to a proper queue which will have a consumer listening to it that knows what to do with that message. \n\nI'd recommend you read up on AMQP and RabbitMQ, this might be a good startingpoint.\n\n### caveats\n\nThere is one major flaw in my proposal and in your design, and that is that we `ACK` the message before we're actually done with processing it. This means that when(not if) our application craches, we have no way of recreating the `ACKed` messages. This could be solved if you know how many threads you're going to start beforehand. I don't know if you can change the prefetch count dynamically, but somehow I doubt that.\n\n### Some thoughts\n\nFrom my, albeit limited, experience with RabbitMQ you shouldn't be scared of creating exchanges and queues, these can greatly improve and simplify your application design if done correctly. Maybe you shouldn't have an application that starts a bunch of consumer-threads. Instead you might want to have some kind of wrapper that starts consumers based on available memory in your system or something similar. If you do that you could make sure that no messages are lost, should your application crash, since if you do it like that, you'll, of course, acknowledge the message when you're done with it. \n\n### Recommended reading\n\n- RabbitMQ tutorials\n\n- Understanding AMQP\n\nLet me know if something is unclear or if I'm missing your point and I'll try to expand upon my answer or improve it if I can.\n\n========================================\n\nCode:\n```text\nString QUEUE_NAME = \"FIBONACCI\";\n\nChannel channel = this.clientManager.getRabbitMQConnection().createChannel();\n\nchannel.queueDeclare(QUEUE_NAME, true, false, false, null);\n\nchannel.basicPublish(\"\", QUEUE_NAME,\n MessageProperties.BASIC,\n Control.getBytes(this.getArgument()));\n\nchannel.close();\n```\n\n```text\npublic final class Worker extends DefaultConsumer implements Runnable {\n @Override\n public void run() {\n\n try {\n this.getChannel().queueDeclare(this.jobType.toString(), true, false, false, null);\n this.getChannel().basicConsume(this.jobType.toString(), this);\n\n this.getChannel().basicQos(1);\n } catch (IOException e) {\n // catch something\n }\n while (true) {\n try {\n Thread.sleep(1000);\n } catch (InterruptedException e) {\n Control.getLogger().error(\"Exception!\", e);\n }\n\n }\n }\n\n @Override\n public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] bytes) throws IOException {\n String routingKey = envelope.getRoutingKey();\n String contentType = properties.getContentType();\n this.getChannel().basicAck(deliveryTag, false); // Is this right?\n // Start new Thread for this task with my own ExecutorService\n\n }\n}\n```\n\n```text\nJob Distributor\n```\n\n```text\nChannels\n```\n\n```text\nConsumers\n```\n\n```text\nFIBONACCI\n```\n\n```text\nRANDOMBOOKS\n```\n\n```text\nConsumer\n```\n\n```text\nx\n```\n\n```text\nFIBONACCI\n```\n\n```text\nRANDOMBOOKS\n```\n\n```text\nFIBONACCI\n```\n\n```text\nRANDOMBOOKS\n```\n\n```text\nx\n```\n\n```text\nChannel\n```\n\n```text\nConsumer\n```\n\n```text\nConsumer\n```\n\n```text\nx\n```\n\n```text\nRunnable\n```\n\n```text\nhandleDelivery\n```\n\n```text\nbasicAck(deliveryTag,false)\n```\n\n```text\npublishing\n```\n\n```text\nConsumer\n```\n\n```text\nWorker\n```\n\n```text\nFIBUNACCI\n```\n\n```text\nRANDOMBOOKS\n```\n\n```text\n@Configuration\npublic class ExampleAmqpConfiguration {\n\n @Bean\n public MessageListenerContainer messageListenerContainer() {\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(rabbitConnectionFactory());\n container.setQueueName(\"some.queue\");\n container.setMessageListener(exampleListener());\n return container;\n }\n\n @Bean\n public ConnectionFactory rabbitConnectionFactory() {\n CachingConnectionFactory connectionFactory = new CachingConnectionFactory(\"localhost\");\n connectionFactory.setUsername(\"guest\");\n connectionFactory.setPassword(\"guest\");\n return connectionFactory;\n }\n\n @Bean\n public MessageListener exampleListener() {\n return new MessageListener() {\n public void onMessage(Message message) {\n System.out.println(\"received: \" + message);\n }\n };\n }\n}\n```\n\n```text\nprefetch\n```\n\n```text\n1\n```\n\n```text\nACK\n```\n\n```text\nACKed\n```\n\n```text\nfibonacci\n```\n\n```text\nfibonacci\n```\n\n```text\nCAS\n```\n\n========================================\n\nComments:\n- I made a few bullet points regarding Couchbase in my answer; however, I would say to start thinking about it, and then ping me/StackOverflow with specific questions :-)\n- Thanks rmayer06, those points are definitely a good start. I'll read into Couchbase and i will bother you with further questions if i have any ;P\n- I don't use spring and i don't want to switch just because of this issue.\n- Hi :) Yes, i have multiple Consumers (running applications on different machines) and each `Consumer` can consume a different number of **parallel** jobs for each jobtype. Say Machine 1 can handle 3 parallel `fibonacci` tasks and 5 parallel `randombooks` tasks, Machine 2 can have other settings.\n- How would i achieve this with Couchbase or MongoDB? Can you give me an Example or a link to this topic?\n- Hi @Steve, I would recommend creating an additional question for that - there are others out there who have expertise, and we should involve them.\n- Hi Bill, thanks for your input so far, i'm developing a solution for my needs based on this. What do you mean with CRDT? Could you explain this a bit?\n- When you have distributed systems you can have the situation where the same piece of data is being written by two different clients. CRDT is a method for deterministically resolving these kinds of conflicts, and is a subject of its own. An example is, if you have a list of items in a document, instead of just changing the list and writing the document out, you could make it a list of changes to the list \"add this, subtract that\", then you can always play back that log to get the correct final list. Couchbase has a clever method to lessen the need for CRDT, but I'm out of space.\n- Two possible technologies are CRDT and event sourcing. I don't know much about the latter. If you go here: ricon.io/archive/ricon2012.html There are two videos that I think will set off lightbulbs in your head. The first is \"immutability changes everything\" and the second one is \"bringing consistency to Riak.\" This second one is about a form of CRDT, and mostly is about the technology (and less about Riak).\n- Also, to give you an idea of the state of things. in Riak, you could be writing document A to node B, while someone else is writing the same document to node C, and at some future point when you request document A, you could get two documents back. In couchbase, it's better, because both clients would be writing document A to node C, and whichever client is slower, will get back an error saying it needs to reconcile with the changed document. (This is optional, you can have it be \"last write wins\" which is essentially how SQL deals with it.) I like the CB solution better since a node is auth.\n- Thanks Bill, i get the idea now. Still building that system. Thanks so far for your great ideas for that topic, it really, REALLY helped me.\n- Bill, thanks for your help. One last question: Do i have to poll all the time from each worker or should i wait a second between each poll from couchbase?\n- oh and how much delay is there between adding a document to couchbase and seeing it in a view? is it about one second or one minute (give me a range)\n- I think the answers to both questions are going to vary depending on your configuration of hardware, complexity of the views, etc. I was assuming you'd poll every minute or two. I figure if you've got a worker controller getting a list of jobs, it could poll every minute, and then spawn off a series of jobs at a time until it's full of work. At any rate, when you put data into CB it will show up immediately, and in the view, it should show up on the order of less than a second, generally.\n- Hi Bill, just want to point out that Couchbase buckets are memory-resident (they are based on memcached). So items #9 and 10 can be accomplished using either the lock method or using the Check-And-Set mechanism on the same bucket.\n- Another comment, before coming up with a scheduling algorithm (i.e. what job gets processed next on what computer), it would be helpful to know what the objective is (high utilization vs. minimize lateness, etc.).\n- Couchbase 2.0 supports persistent buckets (eg: \"Couchbase Buckets\") and memory-only buckets (\"memcache buckets\")... with the couchbase buckets being cached in memory as well as persisted to disk. You're right that each document has a CAS value, and you can know by checking the current value against a previous one whether the document has been changed (presumably to put a lock on it.) So, while I was assuming a memcache bucket in step 9, you could use either. You still have to allow for the possibility of a lock where the worker dies before completion, however.\n- Here's a slide deck on a distributed lock solution relevant to this problem. slideshare.net/knutnesheim/…","metadata":{"transformedAt":"2026-08-18T18:33:20.162Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":34,"totalLines":357,"estimatedTokens":3594}}441{"id":"stack-28696339","source":"stackoverflow","questionId":28696339,"title":"Custom Error Queue Name when using EasyNetQ for RabbitMQ?","tags":["c#",".net","rabbitmq","message-queue","easynetq"],"text":"Title: Custom Error Queue Name when using EasyNetQ for RabbitMQ?\nTags: c#, .net, rabbitmq, message-queue, easynetq\nSource: Stack Overflow\n\nQuestion:\nRather than having my unhandled exceptions go into **EasyNetQ_Default_Error_Queue** I wondered if there is a way that I can explicitly state the name of an Error Queue that should be used for a given application, so errors don't ALL end up in this one **EasyNetQ_Default_Error_Queue**?\n\nI can see how to specify regular message queue names but haven't managed to find anything about Error Queue names.\n\n========================================\n\nCode:\n```text\nvar bus = RabbitHutch.CreateBus(\"host=localhost\");\nbus.Advanced.Container.Resolve<IConventions>().ErrorExchangeNamingConvention = info => \"MyExchangeNaming\";\nbus.Advanced.Container.Resolve<IConventions>().ErrorQueueNamingConvention = () => \"MyErrorQueueNaming\";\n```\n\n========================================\n\nComments:\n- Thanks Zidad. Works great. My only issue after doing this is now: stackoverflow.com/questions/28738683/…","metadata":{"transformedAt":"2026-08-18T18:33:20.162Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":22,"estimatedTokens":260}}442{"id":"stack-26480081","source":"stackoverflow","questionId":26480081,"title":"Synchronous and blocking consumption in RabbitMQ using pika","tags":["python","python-2.7","rabbitmq","pika"],"text":"Title: Synchronous and blocking consumption in RabbitMQ using pika\nTags: python, python-2.7, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI want to consume a queue (RabbitMQ) synchronously with blocking.\n\n**Note: below is full code ready to be run.**\n\nThe system set up is using RabbitMQ as it's queuing system, but asynchronous consumption is not needed in one of our modules.\n\nI've tried using basic_get on top of a BlockingConnection, which doesn't block (returns `(None, None, None)` immediately):\n\n```\n# declare queue\nget_connection().channel().queue_declare(TEST_QUEUE)\ndef blocking_get_1():\n\n channel = get_connection().channel()\n\n # get from an empty queue (prints immediately)\n print channel.basic_get(TEST_QUEUE)\n```\n\nI've also tried to use the consume generator, fails with \"Connection Closed\" after a long time of not consuming.\n\n```\ndef blocking_get_2():\n channel = get_connection().channel()\n # put messages in TEST_QUEUE\n for i in range(4):\n channel.basic_publish(\n '',\n TEST_QUEUE,\n 'body %d' % i\n )\n consume_generator = channel.consume(TEST_QUEUE)\n print next(consume_generator)\n time.sleep(14400)\n print next(consume_generator)\n```\n\nIs there a way to use RabbitMQ using the pika client as I would a `Queue.Queue` in python? or anything similar?\n\nMy option at the moment is busy-wait (using basic_get) - but I rather use the existing system to not busy-wait, if possible.\n\nFull code:\n\n```\n#!/usr/bin/env python\nimport pika\nimport time\n\nTEST_QUEUE = 'test'\ndef get_connection():\n # define connection\n connection = pika.BlockingConnection(\n pika.ConnectionParameters(\n host=YOUR_IP,\n port=YOUR_PORT,\n credentials=pika.PlainCredentials(\n username=YOUR_USER,\n password=YOUR_PASSWORD,\n )\n )\n )\n return connection\n\n# declare queue\nget_connection().channel().queue_declare(TEST_QUEUE)\ndef blocking_get_1():\n\n channel = get_connection().channel()\n\n # get from an empty queue (prints immediately)\n print channel.basic_get(TEST_QUEUE)\n\ndef blocking_get_2():\n channel = get_connection().channel()\n # put messages in TEST_QUEUE\n for i in range(4):\n channel.basic_publish(\n '',\n TEST_QUEUE,\n 'body %d' % i\n )\n consume_generator = channel.consume(TEST_QUEUE)\n print next(consume_generator)\n time.sleep(14400)\n print next(consume_generator)\n\nprint \"blocking_get_1\"\nblocking_get_1()\n\nprint \"blocking_get_2\"\nblocking_get_2()\n\nget_connection().channel().queue_delete(TEST_QUEUE)\n```\n\n========================================\n\nCode:\n```text\n# declare queue\nget_connection().channel().queue_declare(TEST_QUEUE)\ndef blocking_get_1():\n\n channel = get_connection().channel()\n\n # get from an empty queue (prints immediately)\n print channel.basic_get(TEST_QUEUE)\n```\n\n```text\ndef blocking_get_2():\n channel = get_connection().channel()\n # put messages in TEST_QUEUE\n for i in range(4):\n channel.basic_publish(\n '',\n TEST_QUEUE,\n 'body %d' % i\n )\n consume_generator = channel.consume(TEST_QUEUE)\n print next(consume_generator)\n time.sleep(14400)\n print next(consume_generator)\n```\n\n```text\n#!/usr/bin/env python\nimport pika\nimport time\n\nTEST_QUEUE = 'test'\ndef get_connection():\n # define connection\n connection = pika.BlockingConnection(\n pika.ConnectionParameters(\n host=YOUR_IP,\n port=YOUR_PORT,\n credentials=pika.PlainCredentials(\n username=YOUR_USER,\n password=YOUR_PASSWORD,\n )\n )\n )\n return connection\n\n# declare queue\nget_connection().channel().queue_declare(TEST_QUEUE)\ndef blocking_get_1():\n\n channel = get_connection().channel()\n\n # get from an empty queue (prints immediately)\n print channel.basic_get(TEST_QUEUE)\n\ndef blocking_get_2():\n channel = get_connection().channel()\n # put messages in TEST_QUEUE\n for i in range(4):\n channel.basic_publish(\n '',\n TEST_QUEUE,\n 'body %d' % i\n )\n consume_generator = channel.consume(TEST_QUEUE)\n print next(consume_generator)\n time.sleep(14400)\n print next(consume_generator)\n\n\nprint \"blocking_get_1\"\nblocking_get_1()\n\nprint \"blocking_get_2\"\nblocking_get_2()\n\nget_connection().channel().queue_delete(TEST_QUEUE)\n```\n\n```text\n(None, None, None)\n```\n\n```text\nQueue.Queue\n```\n\n```text\nwhile True:\n result = channel.basic.get(queue='simple_queue', no_ack=False)\n if result:\n print(\"Message:\", message.body)\n message.ack()\n else:\n print(\"Channel Empty.\")\n sleep(1)\n```\n\n```text\nconnection.process_data_events()\n```\n\n========================================\n\nComments:\n- I think it also has to do with not sending the heartbeat (`consume` possibly blocks them?) as seen here: stackoverflow.com/questions/14572020/…\n- I posted my take on this, but let me know if I misunderstood your question. :)\n- I remember having trouble when accessing the connection from two threads. Inter-thread communication adds overhead so I'm going to wait for a way to do it without it. I'll give it another go later on and update here.\n- Yea if you are using pika it can be difficult. It is not designed for threading, but the example I linked can handle quite a lot of simultaneous messages. My library amqp-storm on the other hand should make it easier, as it is thread safe.\n- the links provided are outdated...","metadata":{"transformedAt":"2026-08-18T18:33:20.162Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":7,"totalLines":214,"estimatedTokens":1407}}443{"id":"stack-60581782","source":"stackoverflow","questionId":60581782,"title":"How do I set RabbitMQ logging level to debug, really?","tags":["logging","configuration","rabbitmq"],"text":"Title: How do I set RabbitMQ logging level to debug, really?\nTags: logging, configuration, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm trying to figure out how to solve a specific problem with RabbitMQ 3.6.6. In order to gather some more information, I wanted to switch logs to debug level. However, it doesn't seem to work.\n\nHere's the relevant part of `/etc/rabbitmq/rabbitmq.config`, inspired by the official documentation:\n\n```\n[\n {rabbit,\n [\n {log_levels, [{connection, debug}, {queue, debug}]},\n {log,\n [{file, [{level, debug}]},\n {categories,\n [{connection,\n [{level, debug}]\n },\n {queue,\n [{level, debug}]\n }\n ]\n }]\n },\n ]\n }\n]\n```\n\nHowever, what I see in the actual logs (after restarting the server) looks nothing like verbose logs. Not only all messages I see are marked only `INFO REPORT` or `ERROR REPORT`, but also when I create a queue, I see only two messages:\n\n accepting AMQP connection [...]\n\n \n Mirrored queue [...] in vhost [...]: Adding mirror on node [...]\n\nwhich doesn't look particularly verbose.\n\nSo, how do I set log level to debug in RabbitMQ?\n\n========================================\n\nTop Answer:\nAre you trying to look into the console logs , if yes , t , you need to configure the console log level as well by adding the additional node as \n\n```\n[\n{rabbit,\n [\n {log_levels, [{connection, debug}, {queue, debug}]},\n {log,\n [{file, [{level, debug}]},\n {categories,\n [{connection,\n [{level, debug}]\n },\n {queue,\n [{level, debug}]\n },\n {console, \n [{enabled, true},\n {level, debug}]\n }\n ]\n }]\n },\n ]\n}\n```\n\n]\n\nin the config file\n\n========================================\n\nCode:\n```text\n[\n {rabbit,\n [\n {log_levels, [{connection, debug}, {queue, debug}]},\n {log,\n [{file, [{level, debug}]},\n {categories,\n [{connection,\n [{level, debug}]\n },\n {queue,\n [{level, debug}]\n }\n ]\n }]\n },\n ]\n }\n]\n```\n\n```text\n/etc/rabbitmq/rabbitmq.config\n```\n\n```text\nINFO REPORT\n```\n\n```text\nERROR REPORT\n```\n\n```text\nlog.file.level = debug\n```\n\n```text\n[\n{rabbit,\n [\n {log_levels, [{connection, debug}, {queue, debug}]},\n {log,\n [{file, [{level, debug}]},\n {categories,\n [{connection,\n [{level, debug}]\n },\n {queue,\n [{level, debug}]\n },\n {console, \n [{enabled, true},\n {level, debug}]\n }\n ]\n }]\n },\n ]\n}\n```\n\n========================================\n\nComments:\n- I was looking at the logs in `/var/log/rabbitmq`, not the console logs.","metadata":{"transformedAt":"2026-08-18T18:33:20.162Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":146,"estimatedTokens":710}}444{"id":"stack-60488824","source":"stackoverflow","questionId":60488824,"title":"Having a hard time getting Rabbitmq Server started and wonder why keep getting this Error init:do_boot/3 line 817","tags":["python","django-models","rabbitmq"],"text":"Title: Having a hard time getting Rabbitmq Server started and wonder why keep getting this Error init:do_boot/3 line 817\nTags: python, django-models, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI keep getting this error when I start Rabbitmq and wonder what's wrong? \n\n```\nBOOT FAILED\n===========\n\nError description:\n init:do_boot/3 line 817\n init:start_em/1 line 1109\n rabbit:start_it/1 line 474\n rabbit:broker_start/1 line 350\n rabbit:start_loaded_apps/2 line 600\n app_utils:manage_applications/6 line 126\n lists:foldl/3 line 1263\n rabbit:'-handle_app_error/1-fun-0-'/3 line 723\nthrow:{could_not_start,ra,\n {ra,\n {{shutdown,\n {failed_to_start_child,ra_system_sup,\n {shutdown,\n {failed_to_start_child,ra_log_sup,\n {shutdown,\n {failed_to_start_child,ra_log_wal_sup,\n {shutdown,\n {failed_to_start_child,ra_log_wal,\n {{case_clause,{ok,>}},\n [{ra_log_wal,open_existing,1,\n [{file,\"src/ra_log_wal.erl\"},{line,646}]},\n {ra_log_wal,'-recover_wal/2-lc$^0/1-0-',1,\n [{file,\"src/ra_log_wal.erl\"},{line,265}]},\n {ra_log_wal,recover_wal,2,\n [{file,\"src/ra_log_wal.erl\"},{line,268}]},\n {ra_log_wal,init,1,\n [{file,\"src/ra_log_wal.erl\"},{line,214}]},\n {gen_batch_server,init_it,6,\n [{file,\"src/gen_batch_server.erl\"},{line,133}]},\n {proc_lib,init_p_do_apply,3,\n [{file,\"proc_lib.erl\"},{line,249}]}]}}}}}}}}},\n {ra_app,start,[normal,[]]}}}}\nLog file(s) (may contain more information):\n C:/Users/AIMLExpert/AppData/Roaming/RabbitMQ/log/rabbit@DESKTOP-N0Q3S7C.log\n C:/Users/AIMLExpert/AppData/Roaming/RabbitMQ/log/rabbit@DESKTOP-N0Q3S7C_upgrade.log\n\n{\"init terminating in do_boot\",{could_not_start,ra,{ra,{{shutdown,{failed_to_start_child,ra_system_sup,{shutdown,{failed_to_start_child,ra_log_sup,{shutdown,{failed_to_start_child,ra_log_wal_sup,{shutdown,{failed_to_start_child,ra_log_wal,{{case_clause,{ok,>}},[{ra_log_wal,open_existing,1,[{file,\"src/ra_log_wal.erl\"},{line,646}]},{ra_log_wal,'-recover_wal/2-lc$^0/1-0-',1,[{file,\"src/ra_log_wal.erl\"},{line,265}]},{ra_log_wal,recover_wal,2,[{file,\"src/ra_log_wal.erl\"},{line,268}]},{ra_log_wal,init,1,[{file,\"src/ra_log_wal.erl\"},{line,214}]},{gen_batch_server,init_it,6,[{file,\"src/gen_batch_server.erl\"},{line,133}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,249}]}]}}}}}}}}},{ra_app,start,[normal,[]]}}}}}\ninit terminating in do_boot ({could_not_start,ra,{ra,{{shutdown,{_}},{ra_app,start,[_]}}}})\n\nCrash dump is being written to: C:\\Users\\AIMLExpert\\AppData\\Roaming\\RabbitMQ\\log\\erl_crash.dump...done\n```\n\nwhats causing this Error? I have tried restarting the command line but am still getting the error.\n\n========================================\n\nTop Answer:\nI was able to get the problem solved by running the command Rabbitmq-server restart and I also got celery to connect to the server by running the command Celery -A app_name worker --loglevel=info. so everything is working well.\n\n========================================\n\nCode:\n```text\nBOOT FAILED\n===========\n\nError description:\n init:do_boot/3 line 817\n init:start_em/1 line 1109\n rabbit:start_it/1 line 474\n rabbit:broker_start/1 line 350\n rabbit:start_loaded_apps/2 line 600\n app_utils:manage_applications/6 line 126\n lists:foldl/3 line 1263\n rabbit:'-handle_app_error/1-fun-0-'/3 line 723\nthrow:{could_not_start,ra,\n {ra,\n {{shutdown,\n {failed_to_start_child,ra_system_sup,\n {shutdown,\n {failed_to_start_child,ra_log_sup,\n {shutdown,\n {failed_to_start_child,ra_log_wal_sup,\n {shutdown,\n {failed_to_start_child,ra_log_wal,\n {{case_clause,{ok,<<0,0,0,0,0>>}},\n [{ra_log_wal,open_existing,1,\n [{file,\"src/ra_log_wal.erl\"},{line,646}]},\n {ra_log_wal,'-recover_wal/2-lc$^0/1-0-',1,\n [{file,\"src/ra_log_wal.erl\"},{line,265}]},\n {ra_log_wal,recover_wal,2,\n [{file,\"src/ra_log_wal.erl\"},{line,268}]},\n {ra_log_wal,init,1,\n [{file,\"src/ra_log_wal.erl\"},{line,214}]},\n {gen_batch_server,init_it,6,\n [{file,\"src/gen_batch_server.erl\"},{line,133}]},\n {proc_lib,init_p_do_apply,3,\n [{file,\"proc_lib.erl\"},{line,249}]}]}}}}}}}}},\n {ra_app,start,[normal,[]]}}}}\nLog file(s) (may contain more information):\n C:/Users/AIMLExpert/AppData/Roaming/RabbitMQ/log/rabbit@DESKTOP-N0Q3S7C.log\n C:/Users/AIMLExpert/AppData/Roaming/RabbitMQ/log/rabbit@DESKTOP-N0Q3S7C_upgrade.log\n\n{\"init terminating in do_boot\",{could_not_start,ra,{ra,{{shutdown,{failed_to_start_child,ra_system_sup,{shutdown,{failed_to_start_child,ra_log_sup,{shutdown,{failed_to_start_child,ra_log_wal_sup,{shutdown,{failed_to_start_child,ra_log_wal,{{case_clause,{ok,<<0,0,0,0,0>>}},[{ra_log_wal,open_existing,1,[{file,\"src/ra_log_wal.erl\"},{line,646}]},{ra_log_wal,'-recover_wal/2-lc$^0/1-0-',1,[{file,\"src/ra_log_wal.erl\"},{line,265}]},{ra_log_wal,recover_wal,2,[{file,\"src/ra_log_wal.erl\"},{line,268}]},{ra_log_wal,init,1,[{file,\"src/ra_log_wal.erl\"},{line,214}]},{gen_batch_server,init_it,6,[{file,\"src/gen_batch_server.erl\"},{line,133}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,249}]}]}}}}}}}}},{ra_app,start,[normal,[]]}}}}}\ninit terminating in do_boot ({could_not_start,ra,{ra,{{shutdown,{_}},{ra_app,start,[_]}}}})\n\nCrash dump is being written to: C:\\Users\\AIMLExpert\\AppData\\Roaming\\RabbitMQ\\log\\erl_crash.dump...done\n```\n\n```text\nfind /var/lib/rabbitmq/ -name \"*.wal\"\n```\n\n```text\nC:\\Users\\username\\AppData\\Roaming\\RabbitMQ\\db\\rabbit@computername-mnesia\\quorum\\rabbit@computername\n```\n\n========================================\n\nComments:\n- I was able to get the problem solved by running the command Rabbitmq-server restart and I also got celery to connect to the server by running the command Celery -A app_name worker --loglevel=info. so everything is working well.\n- I was strugging with this issue for 3 days. It worked for MAC OS as well.","metadata":{"transformedAt":"2026-08-18T18:33:20.162Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":124,"estimatedTokens":1501}}445{"id":"stack-39317437","source":"stackoverflow","questionId":39317437,"title":"set 'x-message-ttl' in pika python","tags":["python-2.7","rabbitmq","pika"],"text":"Title: set 'x-message-ttl' in pika python\nTags: python-2.7, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI want to set the TTL to 1 sec for a Rabbitmq queue using pika.\nI tried the following code\n\n```\nimport ctypes\nint32=ctypes.c_int\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost'))\nchannel = connection.channel()\nthis=channel.queue_declare(queue='hello',\n arguments={'x-message-ttl' : int32(1000)}\n )\n\nchannel.basic_publish(exchange='',\n routing_key='hello',\n body=message)\n\nprint this.method.consumer_count\n```\n\nI am getting the following error\n\n```\nTraceback (most recent call last):\n File \"rabt.py\", line 8, in \n arguments={'x-message-ttl' : int32(1000)}\n File \"build\\bdist.win32\\egg\\pika\\adapters\\blocking_connection.py\", line 2397, in queue_declare\n File \"build\\bdist.win32\\egg\\pika\\channel.py\", line 815, in queue_declare\n File \"build\\bdist.win32\\egg\\pika\\channel.py\", line 1312, in _rpc\n File \"build\\bdist.win32\\egg\\pika\\channel.py\", line 1324, in _send_method\n File \"build\\bdist.win32\\egg\\pika\\connection.py\", line 2139, in _send_method\n File \"build\\bdist.win32\\egg\\pika\\connection.py\", line 2119, in _send_frame\n File \"build\\bdist.win32\\egg\\pika\\frame.py\", line 74, in marshal\n File \"build\\bdist.win32\\egg\\pika\\spec.py\", line 1015, in encode\n File \"build\\bdist.win32\\egg\\pika\\data.py\", line 85, in encode_table\n File \"build\\bdist.win32\\egg\\pika\\data.py\", line 153, in encode_value\npika.exceptions.UnsupportedAMQPFieldException: (['\\x00\\x00', '\\x05', 'hello', '\\x00', None, '\\r', 'x-message-ttl'], c_long(1000))\n```\n\nI am trying to dead-letter all the messages in this particular queue after 1 sec. Can I know how to set the TTL using Pika? Thanks!\n\n========================================\n\nCode:\n```text\nimport ctypes\nint32=ctypes.c_int\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost'))\nchannel = connection.channel()\nthis=channel.queue_declare(queue='hello',\n arguments={'x-message-ttl' : int32(1000)}\n )\n\nchannel.basic_publish(exchange='',\n routing_key='hello',\n body=message)\n\nprint this.method.consumer_count\n```\n\n```text\nTraceback (most recent call last):\n File \"rabt.py\", line 8, in <module>\n arguments={'x-message-ttl' : int32(1000)}\n File \"build\\bdist.win32\\egg\\pika\\adapters\\blocking_connection.py\", line 2397, in queue_declare\n File \"build\\bdist.win32\\egg\\pika\\channel.py\", line 815, in queue_declare\n File \"build\\bdist.win32\\egg\\pika\\channel.py\", line 1312, in _rpc\n File \"build\\bdist.win32\\egg\\pika\\channel.py\", line 1324, in _send_method\n File \"build\\bdist.win32\\egg\\pika\\connection.py\", line 2139, in _send_method\n File \"build\\bdist.win32\\egg\\pika\\connection.py\", line 2119, in _send_frame\n File \"build\\bdist.win32\\egg\\pika\\frame.py\", line 74, in marshal\n File \"build\\bdist.win32\\egg\\pika\\spec.py\", line 1015, in encode\n File \"build\\bdist.win32\\egg\\pika\\data.py\", line 85, in encode_table\n File \"build\\bdist.win32\\egg\\pika\\data.py\", line 153, in encode_value\npika.exceptions.UnsupportedAMQPFieldException: (['\\x00\\x00', '\\x05', 'hello', '\\x00', None, '\\r', 'x-message-ttl'], c_long(1000))\n```\n\n```text\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost'))\nchannel = connection.channel()\nthis=channel.queue_declare(queue='hello',\n arguments={'x-message-ttl' : 1000}\n )\n```\n\n========================================\n\nComments:\n- ,Could you please let me know how we do it in scala. channel.queueDeclare(\"test\",true,false,false,{\"x-message-ttl‌​\" : 30000}). This is throwing me the below error. error: identifier expected but integer literal found.","metadata":{"transformedAt":"2026-08-18T18:33:20.162Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":96,"estimatedTokens":937}}446{"id":"stack-4857464","source":"stackoverflow","questionId":4857464,"title":"Celery (Django) Rate limiting","tags":["rabbitmq","amqp","celery","carrot"],"text":"Title: Celery (Django) Rate limiting\nTags: rabbitmq, amqp, celery, carrot\nSource: Stack Overflow\n\nQuestion:\nI'm using Celery to process multiple data-mining tasks. One of these tasks connects to a remote service which allows a maximum of 10 simultaneous connections **per user** (or in other words, it **CAN** exceed 10 connections globally but it **CANNOT** exceed 10 connections per individual job). \n\nI **THINK** Token Bucket (rate limiting) is what I'm looking for, but I can't seem to find any implementation of it.\n\n========================================\n\nTop Answer:\nCelery features rate limiting, and contains a generic token bucket implementation.\n\nSet rate limits for tasks:\nhttp://docs.celeryproject.org/en/latest/userguide/tasks.html#Task.rate_limit\n\nOr at runtime:\n\nhttp://docs.celeryproject.org/en/latest/userguide/workers.html#rate-limits\n\nThe token bucket implementation is in Kombu\n\n========================================\n\nCode:\n```text\n# ./manage.py celery worker -Q another_queue -c 10\n```\n\n========================================\n\nComments:\n- Alas, this doesn't work properly because it's per queue. I came up with a better solution here: stackoverflow.com/a/66161773/64911\n- I don't think is bad practice. It's a queue with a different usage and consuming pattern so... to me it makes sense if it's a different queue.","metadata":{"transformedAt":"2026-08-18T18:33:20.162Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":35,"estimatedTokens":336}}447{"id":"stack-36080524","source":"stackoverflow","questionId":36080524,"title":"Rails: How to listen to / pull from service or queue?","tags":["ruby-on-rails","rabbitmq","apache-kafka","microservices"],"text":"Title: Rails: How to listen to / pull from service or queue?\nTags: ruby-on-rails, rabbitmq, apache-kafka, microservices\nSource: Stack Overflow\n\nQuestion:\nMost Rails applications work in a way that they are waiting for requests comming from a client and then do their magic.\nBut if I want to use a Rails application as part of a microservice architecture (for example) with some asychonious communication (Serivce A sends an event into a Kafka or RabbitMQ queue and Service B - my Rails app - is supposed to listen to this queue), how can I tune/start the Rails app to immediately listen to a queue and being triggered by event from there? (Meaning the initial trigger is not comming from a client, but from the App itself.)\n\nThanks for your advice!\n\n========================================\n\nTop Answer:\nI'm afraid that for RabbitMQ at least you will need a client. RabbitMQ implements the AMQP protocol, as opposed to the HTTP protocol used by web servers. As Sergio mentioned above, Rails is a web framework, so it doesn't have AMQP support built into it. You'll have to use an AMQP client such as Bunny in order to subscribe to a Rabbit queue from within a Rails app.\n\n========================================\n\nCode:\n```text\n#Gemfile\n gem 'bunny'\n gem 'sneakers'\n```\n\n```text\n# app/agents/messaging/publisher.rb\n module Messaging\n class Publisher\n class << self\n\n def publish(args)\n connection = Bunny.new\n connection.start\n channel = connection.create_channel\n queue_name = \"#{args.keys.first.to_s.pluralize}_queue\"\n queue = channel.queue(queue_name, durable: true)\n channel.default_exchange.publish(args[args.keys.first].to_json, :routing_key => queue.name)\n puts \"in #{self}.#{__method__}, [x] Sent #{args}!\"\n connection.close\n end\n\n end\n end\n end\n```\n\n```text\nMessaging::Publisher.publish(event: {... event details...})\n```\n\n```text\n# app/agents/messaging/events_queue_receiver.rb\n require_dependency \"#{Rails.root.join('app','agents','messaging','events_agent')}\"\n\n module Messaging\n class EventsQueueReceiver\n include Sneakers::Worker\n from_queue :events_queue, env: nil\n\n def work(msg)\n logger.info msg\n response = Messaging::EventsAgent.distribute(JSON.parse(msg).with_indifferent_access)\n ack! if response[:success]\n end\n\n end\n end\n```\n\n```text\n# app/agents/messaging/events_agent.rb\n require_dependency #{Rails.root.join('app','agents','fsm','state_assignment_agent')}\"\n\n module Messaging\n class EventsAgent\n EVENT_HANDLERS = {\n enroll_in_program: [\"FSM::StateAssignmentAgent\"]\n }\n class << self\n\n def publish(event)\n Messaging::Publisher.publish(event: event)\n end\n\n def distribute(event)\n puts \"in #{self}.#{__method__}, message\"\n if event[:handler]\n puts \"in #{self}.#{__method__}, event[:handler: #{event[:handler}\"\n event[:handler].constantize.handle_event(event)\n else\n event_name = event[:event_name].to_sym\n EVENT_HANDLERS[event_name].each do |handler|\n event[:handler] = handler\n publish(event)\n end\n end\n return {success: true}\n end\n\n end\n end\n end\n```\n\n```text\n# Rakefile\n # Add your own tasks in files placed in lib/tasks ending in .rake,\n # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.\n\n require File.expand_path('../config/application', __FILE__)\n\n require 'sneakers/tasks'\n Rails.application.load_tasks\n```\n\n```text\n# app/config/sneakers.rb\n Sneakers.configure({})\n Sneakers.logger.level = Logger::INFO # the default DEBUG is too noisy\n```\n\n```text\n$ WORKERS=Messaging::EventsQueueReceiver rake sneakers:run\n ... a bunch of start up info\n 2016-03-18T14:16:42Z p-5877 t-14d03e INFO: Heartbeat interval used (in seconds): 2\n 2016-03-18T14:16:42Z p-5899 t-14d03e INFO: Heartbeat interval used (in seconds): 2\n 2016-03-18T14:16:42Z p-5922 t-14d03e INFO: Heartbeat interval used (in seconds): 2\n 2016-03-18T14:16:42Z p-5944 t-14d03e INFO: Heartbeat interval used (in seconds): 2\n```\n\n```text\n$ rails s --sandbox\n 2.1.2 :001 > Messaging::Publisher.publish({:event=>{:event_name=>\"enroll_in_program\", :program_system_name=>\"aha_chh\", :person_id=>1}})\n in Messaging::Publisher.publish, [x] Sent {:event=>{:event_name=>\"enroll_in_program\", :program_system_name=>\"aha_chh\", :person_id=>1}}!\n => :closed\n```\n\n```text\n2016-03-18T14:17:44Z p-5877 t-19nfxy INFO: {\"event_name\":\"enroll_in_program\",\"program_system_name\":\"aha_chh\",\"person_id\":1}\n in Messaging::EventsAgent.distribute, message\n in Messaging::EventsAgent.distribute, event[:handler]: FSM::StateAssignmentAgent\n```\n\n```text\nPublisher\n```\n\n```text\nMessaging::EventsAgent.distribute\n```\n\n```text\nthin\n```\n\n```text\nwash_out\n```\n\n========================================\n\nComments:\n- rails is a web framework. That's what it does, handle web requests. If you need to monitor job/event queue (kafka or whatever), you'll need to use something else.\n- @Sergio Tulentsev what would you recommend - just a manual Ruby script, or some other Ruby framework, which is useful for this case or maybe other language altogether?\n- awesome reply @SergioTulentsev way to add absolutely no value.\n- Sure - I was aware that there needs to be some piece of software between RabbitMQ and Rails. But my understanding/hope is that this client can be called / can life within the Rails app!? If so, how would I \"trigger\" the subscribe process? (And then also: how to process the events so that I can process them in the rails context of my app?)\n- A RabbitMQ client can be used within a Rails app. You can have Rails run a background task that will maintain the queue subscription and process incoming messages. Based on what you've told me, it sounds like the sneakers library is probably a better option for you than Bunny. It's meant for situations where queue processing happens in the background.","metadata":{"transformedAt":"2026-08-18T18:33:20.162Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":14,"totalLines":167,"estimatedTokens":1517}}448{"id":"stack-2557424","source":"stackoverflow","questionId":2557424,"title":"delete Task / PeriodicTask in celery","tags":["python","rabbitmq","celery"],"text":"Title: delete Task / PeriodicTask in celery\nTags: python, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nHow can I delete a regular Task or PeriodicTask in celery?\n\n========================================\n\nCode:\n```text\nControl.revoke(task_id, destination=None, terminate=False, signal='SIGTERM', **kwargs)\n Tell all (or specific) workers to revoke a task by id.\n\n If a task is revoked, the workers will ignore the task and not execute it after all.\n\n Parameters: \n task_id – Id of the task to revoke.\n terminate – Also terminate the process currently working on the task (if any).\n signal – Name of signal to send to process if terminate. Default is TERM.\n```\n\n```text\nrevoke\n```\n\n========================================\n\nComments:\n- and how can i get all task list?","metadata":{"transformedAt":"2026-08-18T18:33:20.162Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":30,"estimatedTokens":201}}449{"id":"stack-53261142","source":"stackoverflow","questionId":53261142,"title":"econnrefused 127.0.0.1:5672 Rabbit-mq with docker compose","tags":["docker","rabbitmq","docker-compose"],"text":"Title: econnrefused 127.0.0.1:5672 Rabbit-mq with docker compose\nTags: docker, rabbitmq, docker-compose\nSource: Stack Overflow\n\nQuestion:\nI am not able to connect a node.js app with rabbit-mq server. Postgres is correctly connected. I don't know why I have a connection refused.\n\n```\nversion: \"3\"\nnetworks:\napp-tier:\n driver: bridge\n\nservices:\ndb:\n image: postgres\n environment:\n - POSTGRES_USER=dockerDBuser\n - POSTGRES_PASSWORD=dockerDBpass\n - POSTGRES_DB=performance\n ports:\n - \"5433:5432\"\n volumes:\n - ./pgdata:/var/lib/postgresql/data\n networks:\n - app-tier\n\nrabbitmq:\n image: rabbitmq:3.6.14-management\n healthcheck:\n test: [\"CMD\", \"curl\", \"-f\", \"http://127.0.0.1:5672\"]\n interval: 30s\n timeout: 10s\n retries: 5\n ports:\n - \"0.0.0.0:5672:5672\"\n - \"0.0.0.0:15672:15672\"\n networks:\n - app-tier\napp:\n build: .\n depends_on:\n - rabbitmq\n - db\n links:\n - rabbitmq\n - db\n command: npm run startOrc\n environment:\n DATABASE_URL: postgres://dockerDBuser:dockerDBpass@db:5432/asdf\n restart: on-failure\n networks:\n - app-tier\n```\n\nIt seems it's trying to connect to the host rabbitmq instead of the container rabbitmq\n\n========================================\n\nTop Answer:\nThis error also comes up if you haven't started docker and run rabbitmq server. So if in case if someone who's reading this post gets the same error, please check whether your rabbitmq server is running.\n\nYou can use below command to run the rabbitmq server. (5672 is the port of that server)\n\n`docker run -p 5672:5672 rabbitmq`\n\n========================================\n\nCode:\n```text\nversion: \"3\"\nnetworks:\napp-tier:\n driver: bridge\n\nservices:\ndb:\n image: postgres\n environment:\n - POSTGRES_USER=dockerDBuser\n - POSTGRES_PASSWORD=dockerDBpass\n - POSTGRES_DB=performance\n ports:\n - \"5433:5432\"\n volumes:\n - ./pgdata:/var/lib/postgresql/data\n networks:\n - app-tier\n\nrabbitmq:\n image: rabbitmq:3.6.14-management\n healthcheck:\n test: [\"CMD\", \"curl\", \"-f\", \"http://127.0.0.1:5672\"]\n interval: 30s\n timeout: 10s\n retries: 5\n ports:\n - \"0.0.0.0:5672:5672\"\n - \"0.0.0.0:15672:15672\"\n networks:\n - app-tier\napp:\n build: .\n depends_on:\n - rabbitmq\n - db\n links:\n - rabbitmq\n - db\n command: npm run startOrc\n environment:\n DATABASE_URL: postgres://dockerDBuser:dockerDBpass@db:5432/asdf\n restart: on-failure\n networks:\n - app-tier\n```\n\n```text\nCLOUDAMQP_URL\n```\n\n```text\namqp://rabbitmq:5672\n```\n\n```text\nrabbitmq\n```\n\n```text\ndocker run -p 5672:5672 rabbitmq\n```\n\n```text\ndocker-compose\n```\n\n========================================\n\nComments:\n- You have a DATABASE_URL for postgres but you don't have a QUEUE_URL (or something like this) for RabbitMq. What url are you using to connect to RabbitMQ.\n- @Sodala that would be really helpful, but until the moment I didn't find it\n- You didn't find the url of rabbitmq that your application is using ?\n- I have found it's connecting to \"amqp://0.0.0.0:5672\" which is the env variable CLOUDAMQP_URL. The thing is that it's not connecting from the container to the host. Do you know how to do it?\n- That was it..!!\n- Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.","metadata":{"transformedAt":"2026-08-18T18:33:20.162Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":146,"estimatedTokens":845}}450{"id":"stack-52351459","source":"stackoverflow","questionId":52351459,"title":"multiple queues consuming in one channel","tags":["node.js","rabbitmq"],"text":"Title: multiple queues consuming in one channel\nTags: node.js, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI use rabbitMq for manage and work with queues. I have multiple queues. the count of them is n't specific. I use direct exchange for publishing messages.\nhow can I consume all messages of each queues (based on routing_key) using only one\nchannel?\nat this time I assume i have 5 queues. I've used for loop and create a channel per queue. like this: \n\n```\nstuff=[\"shoes\",\"pants\",\"hats\",\"jewels\",\"glasses\"];\n\n stuff.forEach(cnt => \n {\n var ex = 'stuff';\n var cq=cnt;\n\n amqp\n .connect('amqp://localhost')\n .then(conn => conn.createChannel())\n .then(ch => {\n\n ch.assertExchange(ex, 'x-delayed-message', { durable: true, \n arguments: { 'x-delayed-type': 'direct' } })\n return ch\n .assertQueue(cq, { durable: true })\n .then(() => { ch.bindQueue(cq, ex, cq) /*second cq is routing*/ \n })\n .then(() => {\n ch.consume(cq, (msg) =>\n {\n\n console.log(\"['%s'] '%s'\",cq, msg.content.toString()); \n if( msg.content.toString()!=null)\n console.log(cq);\n\n reciveMSG=JSON.parse(msg.content.toString());\n\n }, { noAck: true });\n }); \n }) \n\n });\n```\n\nbut I wanna do it only with one channel. because its more optimistic and use less memory(i do n't know it is true or not!).is there a way for handle unspecific count of queues?\n\n========================================\n\nCode:\n```text\nstuff=[\"shoes\",\"pants\",\"hats\",\"jewels\",\"glasses\"];\n\n stuff.forEach(cnt => \n {\n var ex = 'stuff';\n var cq=cnt;\n\n amqp\n .connect('amqp://localhost')\n .then(conn => conn.createChannel())\n .then(ch => {\n\n ch.assertExchange(ex, 'x-delayed-message', { durable: true, \n arguments: { 'x-delayed-type': 'direct' } })\n return ch\n .assertQueue(cq, { durable: true })\n .then(() => { ch.bindQueue(cq, ex, cq) /*second cq is routing*/ \n })\n .then(() => {\n ch.consume(cq, (msg) =>\n {\n\n console.log(\"['%s'] '%s'\",cq, msg.content.toString()); \n if( msg.content.toString()!=null)\n console.log(cq);\n\n reciveMSG=JSON.parse(msg.content.toString());\n\n }, { noAck: true });\n }); \n }) \n\n\n });\n```\n\n========================================\n\nComments:\n- node sample code rabbitmq , multi-Queues , single channel github.com/heroku-examples/node-articles-nlp/blob/master/lib‌​/…\n- Note that that code is not using a single channel, because you *must* use at least one channel per-queue to consume messages.\n- You mean I ask my question there again?\n- No, that is a footer I include to tell people that the best place to ask RabbitMQ questions is the mailing list, not stack overflow.\n- @LukeBakken I'm using the node client and currently using the same channel to consume on multiple queues, everything is running fine as well. I'm sure you're more experienced than me in rabbit, should I move to a multi-channel setup?\n- @LukeBakken - Luke, the official docs state \"...limiting the number of channels used per connection is highly recommended\", recommend pooling channels (so it seems re-using with various queues) and don't mention the one channel per queue rule at all (rabbitmq.com/channels.html). Can you please clarify and give more context to your answer? Thanks in advance.","metadata":{"transformedAt":"2026-08-18T18:33:20.162Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":97,"estimatedTokens":856}}451{"id":"stack-8532295","source":"stackoverflow","questionId":8532295,"title":"RabbitMQ and authorization","tags":["authentication","rabbitmq","amqp"],"text":"Title: RabbitMQ and authorization\nTags: authentication, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nOne of my projects requires authentication for using RabbitMQ. Only authenticated users can connect to the rabbitmq server and subscribe to queues etc. For example, when a user connects to the server for the first time and sends some auth data (like login, password) - server should check it and, if the user passed authentication, he will be able to subscribe to queues etc. Otherwise, the server would disconnect the user. Is there a solution for this?\n\nPlease don't judge too harshly, I'm not really familiar with RabbitMQ and stuff like this.\n\n========================================\n\nTop Answer:\nThis amqplib documentation gives a straightforward answer.\n\n```\nConnecting with an object instead of a URL\nThe URL can also be supplied as an object of the form:\n\n{\n protocol: 'amqp',\n hostname: 'localhost',\n port: 5672,\n username: 'guest',\n password: 'guest',\n locale: 'en_US',\n frameMax: 0,\n heartbeat: 0,\n vhost: '/',\n}\n```\n\n========================================\n\nCode:\n```text\nConnecting with an object instead of a URL\nThe URL can also be supplied as an object of the form:\n\n{\n protocol: 'amqp',\n hostname: 'localhost',\n port: 5672,\n username: 'guest',\n password: 'guest',\n locale: 'en_US',\n frameMax: 0,\n heartbeat: 0,\n vhost: '/',\n}\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.162Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":50,"estimatedTokens":341}}452{"id":"stack-38140849","source":"stackoverflow","questionId":38140849,"title":"STOMP over websockets vs plain STOMP. Which one is better?","tags":["spring","websocket","rabbitmq","stomp","spring-websocket"],"text":"Title: STOMP over websockets vs plain STOMP. Which one is better?\nTags: spring, websocket, rabbitmq, stomp, spring-websocket\nSource: Stack Overflow\n\nQuestion:\nAs from spring 4, we have support of `STOMP` (sub)protocol over `WebSocket`. I do understand the benefits of `WebSocket` as compared to HTTP and the use & benefits of using `STOMP` over the `WebSocket` but I would like to understand the following: \n\nAre there any Performance benefits of directly using the stomp protocol to talk with the MB (like RabbitMQ or Kafka - probably in future) \n\nIs there any benefit of using `STOMP` as a sub-protocol over web-sockets other than to take care of the handshake required by the client to connect to the server/MB\n\n========================================\n\nCode:\n```text\nSTOMP\n```\n\n```text\nWebSocket\n```\n\n```text\nWebSocket\n```\n\n```text\nSTOMP\n```\n\n```text\nWebSocket\n```\n\n```text\nSTOMP\n```\n\n========================================\n\nComments:\n- Regarding your point 1) As per the link rabbitmq.com/protocols.html it seems that we can use web-stomp (over http) but the default STOMP/MQTT/AMQP mentioned doesn't use the HTTP. I am not sure how the handshake happens without the underlying HTTP but would have to investigate\n- But in the spring documentation at \"26.4.14 STOMP Client\" it is written that there's a STOMP over WebSocket and a STOMP over TCP client. So in my understanding WebSocket already builds on TCP so STOMP over TCP leaves the WebSocket layer in between out? So where would be the benifit in not leaving the WebSocket layer out? Edit: I want to communicate from server to server (so no browser involved)","metadata":{"transformedAt":"2026-08-18T18:33:20.162Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":43,"estimatedTokens":405}}453{"id":"stack-26838803","source":"stackoverflow","questionId":26838803,"title":"Spring AMQP RabbitMQ implementing priority queue","tags":["java","apache-camel","rabbitmq","spring-amqp","spring-rabbit"],"text":"Title: Spring AMQP RabbitMQ implementing priority queue\nTags: java, apache-camel, rabbitmq, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nAfter Google for a few days, and i believe i am totally lost. I would like to implement a kind of priority queue that has about 3 queues:\n\n- high priority queue (daily), that needs to be process first.\n\n- mid priority queue (weekly), that will process if no items in queue #1. (it is ok message in this queue it never process at all)\n\n- low priority queue (monthly), that will process if no items in queue #1 & #2. (it is ok message in this queue it never process at all)\n\nInitially I have the following flow, to have a consumer to consume messages from all three queues and checks whether there is any items in queue #1, #2 and #3. and then I realize that this is wrong because: \n\n- I am totally lost with a question: \"How do I know which queue it is coming from?\".\n\n- I'm already consuming a message regardless from any queue, So if I get an object from lower priority queue, am I gonna put it back to the queue if I discover there is a message at the higher priority queue?\n\nFollowing is my current configurations, which shows what an idiot I am.\n\n```\n\n \n\n \n \n\n \n \n\n```\n\nAny idea how should I tackle this with priority queue? \n\nps: I also wonder, if Apache Camel has something I can depend on? \n\nUPDATE 1: I just saw this from Apache Camel: \"https://issues.apache.org/jira/browse/CAMEL-2537\" the sequencer on JMSPriority seems to be what im looking for, anyone has tried this before?\n\nUPDATE 2: assuming i am to use RabbitMQ's plugin base on @Gary Russell recommendation, I have the following spring-rabbitmq context XML configuration, which seems to make sense (by guest..): \n \n \n\n```\n\n \n \n \n\n \n\n```\n\nThe above xml configuration has successfully create a Queue, with name: \"ad_google_dfa_reporting_queue\", and with Parameter arguments: x-max-priority: 10 & durable: true\n\nBut not when comes to the code that send the message with *priority*, I totally lost it. How to define the priority as mention in the Sample URL: https://github.com/rabbitmq/rabbitmq-priority-queue/blob/master/examples/java/src/com/rabbitmq/examples/PriorityQueue.java\n\n```\nAmqpTemplate amqpTemplateGoogleDfaReporting = (AmqpTemplate) applicationContext.getBean(\"amqpTemplateadGoogleDfaReporting\");\namqpTemplateGoogleDfaReporting.convertAndSend(\"message\"); // how to define message priority?\n```\n\nUPDATE 3: Based on the @Gary's answer, i manage to sent message with priority set in the message, as per image below:\n\n However, when i sent in 1000 messages with random priority between 1-10, the consumer is consuming message with all kinds of priority. (I was expecting only the high priority message to be consume first). following is the code for Message producer:\n\n```\nRandom random = new Random();\n for (int i=0; iAnd following is the code for Message consumer:\n\n```\npublic void consume(DfaReportingModel message) {\n System.out.println(message.getUserProfileId());\n\n Thread.sleep(500);\n }\n```\n\nThe result im getting: \n\n```\n9, 10, 7, 9, 6, 4, 10, 10, 3, 10, 6, 1, 5, 6, 6, 3, 4, 7, 6, 8, 3, 1, 4, 5, 5, 3, 10, 9, 5, 1, 8, 9, 6, 9, 3, 10, 7, 4, 8, 7, 3, 4, 8, 2, 6, 9, 6, 4, 7, 7, 2, 8, 4, 4, 1,\n```\n\nUPDATE 4: Problem solved! Knowing the sample code from https://github.com/rabbitmq/rabbitmq-priority-queue is working in my environment, I presume that the problem is around the spring context. Hence, after countless time on try and error with different type of configurations, and I pin point the exact combination that will make this works! and is as per following:\n\n```\n\n \n \n 10 \n \n \n\n```\n\nWithout specifically define the value is Integer type, the priority queue does not work. Finally, it is solved. Yay!\n\n========================================\n\nTop Answer:\nRabbitMQ has priority queue implementation in the core as of version 3.5.0.\n\nYou can declare priority queues using the `x-max-priority` argument. This argument should be an integer indicating the maximum priority the queue should support. For example, using the Java client:\n\n```\nChannel ch = ...;\nMap args = new HashMap();\nargs.put(\"x-max-priority\", 10);\nch.queueDeclare(\"my-priority-queue\", true, false, false, args);\n```\n\nYou can then publish prioritised messages using the priority field of `basic.properties`. Larger numbers indicate higher priority.\n\n========================================\n\nCode:\n```text\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<beans xmlns=\"http://www.springframework.org/schema/beans\"\nxmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:rabbit=\"http://www.springframework.org/schema/rabbit\"\nxsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd\nhttp://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd\">\n\n<rabbit:connection-factory id=\"connectionFactory\" host=\"localhost\" />\n\n<rabbit:template id=\"amqpTemplatead_daily\" connection-factory=\"connectionFactory\"\n exchange=\"\" routing-key=\"daily_queue\"/>\n\n<rabbit:template id=\"amqpTemplatead_weekly\" connection-factory=\"connectionFactory\"\n exchange=\"\" routing-key=\"weekly_queue\"/>\n\n<rabbit:template id=\"amqpTemplatead_monthly\" connection-factory=\"connectionFactory\"\n exchange=\"\" routing-key=\"monthly_queue\"/>\n\n<rabbit:admin connection-factory=\"connectionFactory\" />\n\n<rabbit:listener-container connection-factory=\"connectionFactory\">\n <rabbit:listener ref=\"Consumer\" method=\"consume\" queue-names=\"daily_queue\" />\n</rabbit:listener-container>\n\n<rabbit:listener-container connection-factory=\"connectionFactory\">\n <rabbit:listener ref=\"Consumer\" method=\"consume\" queue-names=\"weekly_queue\" />\n</rabbit:listener-container> \n\n<rabbit:listener-container connection-factory=\"connectionFactory\">\n <rabbit:listener ref=\"Consumer\" method=\"consume\" queue-names=\"monthly_queue\" />\n</rabbit:listener-container> \n\n<bean id=\"Consumer\" class=\"com.test.Consumer\" />\n\n</beans>\n```\n\n```text\n<rabbit:queue name=\"ad_google_dfa_reporting_queue\">\n <rabbit:queue-arguments>\n <entry key=\"x-max-priority\" value=\"10\"/>\n </rabbit:queue-arguments>\n</rabbit:queue>\n\n<rabbit:listener-container connection-factory=\"connectionFactory\">\n <rabbit:listener ref=\"adGoogleDfaReporting\" method=\"consume\" queue-names=\"ad_google_dfa_reporting_queue\" />\n</rabbit:listener-container>\n\n<bean id=\"Consumer\" class=\"com.test.Consumer\" />\n```\n\n```text\nAmqpTemplate amqpTemplateGoogleDfaReporting = (AmqpTemplate) applicationContext.getBean(\"amqpTemplateadGoogleDfaReporting\");\namqpTemplateGoogleDfaReporting.convertAndSend(\"message\"); // how to define message priority?\n```\n\n```text\nRandom random = new Random();\n for (int i=0; i< 1000; i++){\n final int priority = random.nextInt(10 - 1 + 1) + 1;\n\n DfaReportingModel model = new DfaReportingModel();\n model.setReportType(DfaReportingModel.ReportType.FACT);\n model.setUserProfileId(0l + priority);\n amqpTemplateGoogleDfaReporting.convertAndSend(model, new MessagePostProcessor() {\n @Override\n public Message postProcessMessage(Message message) throws AmqpException {\n message.getMessageProperties().setPriority(priority);\n return message;\n }\n });\n }\n```\n\n```text\npublic void consume(DfaReportingModel message) {\n System.out.println(message.getUserProfileId());\n\n Thread.sleep(500);\n }\n```\n\n```text\n9, 10, 7, 9, 6, 4, 10, 10, 3, 10, 6, 1, 5, 6, 6, 3, 4, 7, 6, 8, 3, 1, 4, 5, 5, 3, 10, 9, 5, 1, 8, 9, 6, 9, 3, 10, 7, 4, 8, 7, 3, 4, 8, 2, 6, 9, 6, 4, 7, 7, 2, 8, 4, 4, 1,\n```\n\n```text\n<rabbit:queue name=\"ad_google_dfa_reporting_queue\">\n <rabbit:queue-arguments>\n <entry key=\"x-max-priority\">\n <value type=\"java.lang.Integer\">10</value> <!-- MUST specifically define java.lang.Integer to get it to work -->\n </entry>\n </rabbit:queue-arguments>\n</rabbit:queue>\n```\n\n```text\ntemplate.convertAndSend(\"exchange\", \"routingKey\", \"message\", new MessagePostProcessor() {\n\n @Override\n public Message postProcessMessage(Message message) throws AmqpException {\n message.getMessageProperties().setPriority(5);\n return message;\n }\n});\n```\n\n```text\nrabbitTemplate.convertAndSend(...)\n```\n\n```text\nMessagePropertiesConverter\n```\n\n```text\nDefaultMessagePropertiesConverter\n```\n\n```text\nconvertAnSend\n```\n\n```text\nChannel ch = ...;\nMap<String, Object> args = new HashMap<String, Object>();\nargs.put(\"x-max-priority\", 10);\nch.queueDeclare(\"my-priority-queue\", true, false, false, args);\n```\n\n```text\nx-max-priority\n```\n\n```text\nbasic.properties\n```\n\n========================================\n\nComments:\n- For the p.s. I suggest to add a Apache Camel tag\n- @mjn done. apache-camel added.\n- @ben75 thank you!! i was wonder how to itemize the facts :)\n- WOW your post was very helpful and saved me A LOT of time! thank you\n- I saw this plugin and was confused on how to implement the plugin with the Spring-rabbitmq. Is there any xml context example that utilizing this plugin?\n- Russel i manage to \"guess\" the most likely xml context configuration, but when comes to java code that does the template.convertandsend(); the document does not have any reference on how to send in the priority. clue?\n- Able to sent in messages with Priority! But strangely, the consumer is consuming messages with all sorts of priority. Its like the priority was never being enforce. I have double check the rabbitMQ plugin Status, and priority queue shows as enabled: [E] rabbitmq_priority_queue 3.3.x-72d20292\n- @Gray I am trying to use RabbitMQ on my localhost, but having hard time with it, can you give me any pointers regarding that\n- Please don't pile onto an existing question/answer - open a new question; tag it with `spring-amqp` and I'll get an email. Please provide **much more information** than 'having hard time'.\n- But it does not work with Quorum queues. rabbitmq.com/quorum-queues.html","metadata":{"transformedAt":"2026-08-18T18:33:20.163Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":15,"totalLines":268,"estimatedTokens":2498}}454{"id":"stack-46240032","source":"stackoverflow","questionId":46240032,"title":"Rabbitmq File Descriptor Limit","tags":["rabbitmq","rabbitmq-exchange","rabbitmqctl"],"text":"Title: Rabbitmq File Descriptor Limit\nTags: rabbitmq, rabbitmq-exchange, rabbitmqctl\nSource: Stack Overflow\n\nQuestion:\nRabbitmq documentation says that we need to do some configuration before we use it on production. One of the configuration is about maximum open file number (which is an OS parameter).\n\nRabbitmq server we use is running on Ubuntu 16.04 and according to resources I found on web, I updated the number of open files as 500k. When I check it from command line, I get the following output:\n\n```\nroot@madeleine:~# ulimit -n\n500000\n```\n\nHowever when I look at the rabbitmq server status, I see another number.\n\n```\nroot@madeleine:~# rabbitmqctl status | grep 'file_descriptors' -A 4\n {file_descriptors,\n [{total_limit,924},\n {total_used,19},\n {sockets_limit,829},\n {sockets_used,10}]},\n```\n\nIt seems like, I managed to increase the limit on OS side, but rabbitmq still thinks that total limit of file descriptors is 924.\n\nWhat might be causing this problem?\n\n========================================\n\nTop Answer:\nIncrease / Set maximum number of open files\n\n***sudo sysctl -w fs.file-max=65536***\n\nThese limits are defined in /etc/security/limits.conf\n\n***sudo nano /etc/security/limits.conf***\n\nand set\n\nsoft nofile 65536\n\nhard nofile 65536\n\nPer user settings for rabbitmq process can also be set in \n/etc/default/rabbitmq-server\n\n***sudo nano /etc/default/rabbitmq-server***\n\nand set\n\nulimit -n 65536\n\nThen reboot the server for changes to take effect.\n\n========================================\n\nCode:\n```text\nroot@madeleine:~# ulimit -n\n500000\n```\n\n```text\nroot@madeleine:~# rabbitmqctl status | grep 'file_descriptors' -A 4\n {file_descriptors,\n [{total_limit,924},\n {total_used,19},\n {sockets_limit,829},\n {sockets_used,10}]},\n```\n\n```text\nfind / -name \"*rabbitmq-server.service*\"\n```\n\n```text\nsystemctl edit rabbitmq-server.service\n```\n\n```text\nvi /etc/systemd/system/rabbitmq-server.service.d/limits.conf\n\n[Service]\nLimitNOFILE=64000\n```\n\n========================================\n\nComments:\n- That depends entirely on how you're running RabbitMQ, and how you configured the open file limit.\n- @RogerLipscombe I am using a config file to run Rabbitmq. Its content is here, can you take a look at it? [{rabbit, [{vm_memory_high_watermark, 0.4},{disk_free_limit, {mem_relative, 2.0}}]}].\n- Which OS are you using? do you use systemd?\n- Ubuntu 16.04.2 LTS and yes I am using systemd\n- These steps seems like working. ulimit -n now returns 65536 but still, in rabbitmqctl status command's output, file_descriptors values are not increased.\n- ubuntu 16.04 **/lib/systemd/system/rabbitmq-server.service** add **LimitNOFILE** under [Service] block works\n- @cwhsu, this is really bad advice as that file can be overwritten by package updates.\n- The proper way to edit systemd service is `sudo systemctl edit rabbitmq-server.service` - this will figure out what is the correct location for your override file and open it in your preferred editor. Then you can just add the `[Service]` block as suggested, save and quit. systemctl will then also reload the configuration for you.\n- Another way (ubuntu 16.04). After installation there is no folder `/etc/systemd/system/rabbitmq-server.service.d`. Just create it and put file `limits.conf`in that folder. In file add the `[Service]` block as in answer. Then in console `sudo service rabbitmq-server restart` for restart and `sudo rabbitmqctl status` for check.","metadata":{"transformedAt":"2026-08-18T18:33:20.163Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":101,"estimatedTokens":863}}455{"id":"stack-40857070","source":"stackoverflow","questionId":40857070,"title":"Why does celery.control.inspect report fewer queued tasks than rabbitmqctl?","tags":["python","rabbitmq","celery","rabbitmqctl"],"text":"Title: Why does celery.control.inspect report fewer queued tasks than rabbitmqctl?\nTags: python, rabbitmq, celery, rabbitmqctl\nSource: Stack Overflow\n\nQuestion:\n`rabbitmqctl` correctly reports thousands of queued tasks:\n\n```\n$ sudo rabbitmqctl -q list_queues name messages messages_ready messages_unacknowledged\ndefault 13142 13126 16\n```\n\nYet celery reports:\n\n```\n>>> len(app.control.inspect().active()['celery@default'])\n4\n>>> len(app.control.inspect().scheduled()['celery@default'])\n1\n>>> len(app.control.inspect().reserved()['celery@default'])\n16\n>>> len(app.control.inspect().revoked()['celery@default'])\n0\n```\n\nThe correct number (thousands) of tasks seem to show up in `app.control.inspect().stats()['celery@default']['total']`, but I really want to know the correct number of *outstanding* queued tasks from within python, and `active()` et al seem to only ever report up to 16 or so -- perhaps there is a limit?\n\nShort of using privileged subprocess calls to `rabbitmqctl`, how can I get the full queued task count from within python, preferably via `celery` (btw this server is using Celery 3.1.8 currently)\n\n========================================\n\nCode:\n```text\n$ sudo rabbitmqctl -q list_queues name messages messages_ready messages_unacknowledged\ndefault 13142 13126 16\n```\n\n```text\n>>> len(app.control.inspect().active()['celery@default'])\n4\n>>> len(app.control.inspect().scheduled()['celery@default'])\n1\n>>> len(app.control.inspect().reserved()['celery@default'])\n16\n>>> len(app.control.inspect().revoked()['celery@default'])\n0\n```\n\n```text\nrabbitmqctl\n```\n\n```text\napp.control.inspect().stats()['celery@default']['total']\n```\n\n```text\nactive()\n```\n\n```text\nrabbitmqctl\n```\n\n```text\ncelery\n```\n\n```text\nactive\n```\n\n```text\nreserved\n```\n\n```text\nscheduled\n```\n\n```text\npika\n```\n\n========================================\n\nComments:\n- Thank you! Can I also get details of what each message on the queue is using `pika` etc, or just the total number of messages in the queue?\n- Thanks @ChillarAnand; does \"consuming\" messages via `pika` leave them safely on the queue for celery to process? If so, this is a good solution\n- @DrMeers I don't think there is a way for that. However you can consume and requeue messages rabbitmq.1065348.n5.nabble.com/…","metadata":{"transformedAt":"2026-08-18T18:33:20.163Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":11,"totalLines":90,"estimatedTokens":569}}456{"id":"stack-45875167","source":"stackoverflow","questionId":45875167,"title":"Which one to use RabbitTemplate or AmqpTemplate?","tags":["spring","spring-boot","rabbitmq","amqp","spring-amqp"],"text":"Title: Which one to use RabbitTemplate or AmqpTemplate?\nTags: spring, spring-boot, rabbitmq, amqp, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI have the following program written in `Spring Boot` which is working fine. However, the problem is that the I am not sure whether I should be using `RabbitTemplate` or `AmqpTemplate`. Some of the online examples/tutorials use `RabbitTemplate` while others use `AmqpTemplate`. \n\nPlease guide as to what is the best practice and which one should be used.\n\n```\n@SpringBootApplication\npublic class BasicApplication {\n\n private static RabbitTemplate rabbitTemplate;\n private static final String QUEUE_NAME = \"helloworld.q\";\n\n //this definition of Queue is required in RabbitMQ. Not required in ActiveMQ\n @Bean\n public Queue queue() {\n return new Queue(QUEUE_NAME, false);\n }\n\n public static void main(String[] args) {\n try (ConfigurableApplicationContext ctx = SpringApplication.run(BasicApplication.class, args)) {\n rabbitTemplate = ctx.getBean(RabbitTemplate.class);\n rabbitTemplate.convertAndSend(QUEUE_NAME, \"Hello World !\");\n }\n }\n\n}\n```\n\n========================================\n\nTop Answer:\nAmqpTemplate is an interface. RabbitTemplate is an implementation of the AmqpTemplate interface. You should use RabbitTemplate.\n\n========================================\n\nCode:\n```text\n@SpringBootApplication\npublic class BasicApplication {\n\n private static RabbitTemplate rabbitTemplate;\n private static final String QUEUE_NAME = \"helloworld.q\";\n\n //this definition of Queue is required in RabbitMQ. Not required in ActiveMQ\n @Bean\n public Queue queue() {\n return new Queue(QUEUE_NAME, false);\n }\n\n public static void main(String[] args) {\n try (ConfigurableApplicationContext ctx = SpringApplication.run(BasicApplication.class, args)) {\n rabbitTemplate = ctx.getBean(RabbitTemplate.class);\n rabbitTemplate.convertAndSend(QUEUE_NAME, \"Hello World !\");\n }\n }\n\n}\n```\n\n```text\nSpring Boot\n```\n\n```text\nRabbitTemplate\n```\n\n```text\nAmqpTemplate\n```\n\n```text\nRabbitTemplate\n```\n\n```text\nAmqpTemplate\n```\n\n```text\nRabbitTemplate\n```\n\n```text\nRabbitTemplate\n```\n\n========================================\n\nComments:\n- You should state why coding to an implementation is desirable here, q.v. the accepted answer.","metadata":{"transformedAt":"2026-08-18T18:33:20.163Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":95,"estimatedTokens":578}}457{"id":"stack-55285341","source":"stackoverflow","questionId":55285341,"title":"RabbitMq - ConversationId vs CorrelationId - Which is the more appropriate for tracking a specific request?","tags":["c#","rabbitmq","masstransit"],"text":"Title: RabbitMq - ConversationId vs CorrelationId - Which is the more appropriate for tracking a specific request?\nTags: c#, rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nRabbitMQ seems to have two properties that are very similar, and I don't entirely understand the difference. `ConversationId` and `CorrelationId`.\n\nMy use case is as follows. I have a website that generates a `Guid`. The website calls an API, adding that unique identifier to the `HttpRequest` headers. This in turn publishes a message to RabbitMQ. That message is processed by the first consumer and passed off elsewhere to another consumer, and so on.\n\nFor logging purposes I want to log an identifier that ties the initial request together with all of the subsequent actions. This should be unique for that journey throughout the different parts of the application. Hence. When logged to something like Serilog/ElasticSearch, this then becomes easy to see which request triggered the initial request, and all of the log entries for that request throughout the application can be correlated together.\n\nI have created a provider that looks at the incoming `HttpRequest` for an identifier. I've called this a \"CorrelationId\", but I'm starting to wonder if this should really be named a \"ConversationId\". In terms of RabbitMQ, does the idea of a \"ConversationId\" fit better to this model, or is \"CorrelationId\" better?\n\nWhat is the difference between the two concepts?\n\nIn terms of code, I've looked to do the following. Firstly register the bus in my API and configure the `SendPublish` to use the `CorrelationId` from the provider.\n\n```\n// bus registration in the API\nvar busSettings = context.Resolve();\n// using AspNetCoreCorrelationIdProvider\nvar correlationIdProvider = context.Resolve();\n\nvar busControl = Bus.Factory.CreateUsingRabbitMq(cfg =>\n{\n cfg.Host(\n new Uri(busSettings.HostAddress),\n h =>\n {\n h.Username(busSettings.Username);\n h.Password(busSettings.Password);\n });\n cfg.ConfigurePublish(x => x.UseSendExecute(sendContext =>\n {\n // which one is more appropriate\n //sendContext.ConversationId = correlationIdProvider.GetCorrelationId();\n sendContext.CorrelationId = correlationIdProvider.GetCorrelationId();\n }));\n});\n```\n\nFor reference, this is my simple provider interface\n\n```\n// define the interface\npublic interface ICorrelationIdProvider\n{\n Guid GetCorrelationId();\n}\n```\n\nAnd the AspNetCore implementation, which extracts the unique ID set by the calling client (i.e. a website).\n\n```\npublic class AspNetCoreCorrelationIdProvider : ICorrelationIdProvider\n{\n private IHttpContextAccessor _httpContextAccessor;\n\n public AspNetCoreCorrelationIdProvider(IHttpContextAccessor httpContextAccessor)\n {\n _httpContextAccessor = httpContextAccessor;\n }\n\n public Guid GetCorrelationId()\n {\n if (_httpContextAccessor.HttpContext.Request.Headers.TryGetValue(\"correlation-Id\", out StringValues headers))\n {\n var header = headers.FirstOrDefault();\n if (Guid.TryParse(header, out Guid headerCorrelationId))\n {\n return headerCorrelationId;\n }\n }\n\n return Guid.NewGuid();\n }\n}\n```\n\nFinally, my Service hosts are simple windows service applications that sit and consume published messages. They use the following to grab the CorrelationId and might well publish to other consumers as well in other service hosts.\n\n```\npublic class MessageContextCorrelationIdProvider : ICorrelationIdProvider\n{\n /// \n /// The consume context\n /// \n private readonly ConsumeContext _consumeContext;\n\n /// \n /// Initializes a new instance of the class.\n /// \n /// The consume context.\n public MessageContextCorrelationIdProvider(ConsumeContext consumeContext)\n {\n _consumeContext = consumeContext;\n }\n\n /// \n /// Gets the correlation identifier.\n /// \n /// \n public Guid GetCorrelationId()\n {\n // correlationid or conversationIs?\n if (_consumeContext.CorrelationId.HasValue && _consumeContext.CorrelationId != Guid.Empty)\n {\n return _consumeContext.CorrelationId.Value;\n }\n\n return Guid.NewGuid();\n }\n}\n```\n\nI then have a logger in my consumer that uses that provider to extract the `CorrelationId`:\n\n```\npublic async Task Consume(ConsumeContext context)\n{\n var correlationId = _correlationProvider.GetCorrelationId();\n _logger.Info(correlationId, $\"#### IMyEvent received for customer:{context.Message.CustomerId}\");\n\n try\n {\n await _mediator.Send(new SomeOtherRequest(correlationId) { SomeObject: context.Message.SomeObject });\n }\n catch (Exception e)\n {\n _logger.Exception(e, correlationId, $\"Exception:{e}\");\n throw;\n }\n\n _logger.Info(correlationId, $\"Finished processing: {DateTime.Now}\");\n}\n```\n\nReading the docs, it says the following about a \"ConversationId\":\n\n The conversation is created by the first message that is sent or\n published, in which no existing context is available (such as when a\n message is sent or published by using IBus.Send or IBus.Publish). If\n an existing context is used to send or publish a message, the\n ConversationId is copied to the new message, ensuring that a set of\n messages within the same conversation have the same identifier.\n\nNow I'm starting to think that I've got my terminology mixed up, and technically this is a conversation (although the 'conversation' is like 'the telephone game').\n\nSo, `CorrelationId` in this use case, or `ConversationId`? Please help me get my terminology right!!\n\n========================================\n\nCode:\n```text\n// bus registration in the API\nvar busSettings = context.Resolve<BusSettings>();\n// using AspNetCoreCorrelationIdProvider\nvar correlationIdProvider = context.Resolve<ICorrelationIdProvider>();\n\nvar busControl = Bus.Factory.CreateUsingRabbitMq(cfg =>\n{\n cfg.Host(\n new Uri(busSettings.HostAddress),\n h =>\n {\n h.Username(busSettings.Username);\n h.Password(busSettings.Password);\n });\n cfg.ConfigurePublish(x => x.UseSendExecute(sendContext =>\n {\n // which one is more appropriate\n //sendContext.ConversationId = correlationIdProvider.GetCorrelationId();\n sendContext.CorrelationId = correlationIdProvider.GetCorrelationId();\n }));\n});\n```\n\n```text\n// define the interface\npublic interface ICorrelationIdProvider\n{\n Guid GetCorrelationId();\n}\n```\n\n```text\npublic class AspNetCoreCorrelationIdProvider : ICorrelationIdProvider\n{\n private IHttpContextAccessor _httpContextAccessor;\n\n public AspNetCoreCorrelationIdProvider(IHttpContextAccessor httpContextAccessor)\n {\n _httpContextAccessor = httpContextAccessor;\n }\n\n public Guid GetCorrelationId()\n {\n if (_httpContextAccessor.HttpContext.Request.Headers.TryGetValue(\"correlation-Id\", out StringValues headers))\n {\n var header = headers.FirstOrDefault();\n if (Guid.TryParse(header, out Guid headerCorrelationId))\n {\n return headerCorrelationId;\n }\n }\n\n return Guid.NewGuid();\n }\n}\n```\n\n```text\npublic class MessageContextCorrelationIdProvider : ICorrelationIdProvider\n{\n /// <summary>\n /// The consume context\n /// </summary>\n private readonly ConsumeContext _consumeContext;\n\n /// <summary>\n /// Initializes a new instance of the <see cref=\"MessageContextCorrelationIdProvider\"/> class.\n /// </summary>\n /// <param name=\"consumeContext\">The consume context.</param>\n public MessageContextCorrelationIdProvider(ConsumeContext consumeContext)\n {\n _consumeContext = consumeContext;\n }\n\n /// <summary>\n /// Gets the correlation identifier.\n /// </summary>\n /// <returns></returns>\n public Guid GetCorrelationId()\n {\n // correlationid or conversationIs?\n if (_consumeContext.CorrelationId.HasValue && _consumeContext.CorrelationId != Guid.Empty)\n {\n return _consumeContext.CorrelationId.Value;\n }\n\n return Guid.NewGuid();\n }\n}\n```\n\n```text\npublic async Task Consume(ConsumeContext<IMyEvent> context)\n{\n var correlationId = _correlationProvider.GetCorrelationId();\n _logger.Info(correlationId, $\"#### IMyEvent received for customer:{context.Message.CustomerId}\");\n\n try\n {\n await _mediator.Send(new SomeOtherRequest(correlationId) { SomeObject: context.Message.SomeObject });\n }\n catch (Exception e)\n {\n _logger.Exception(e, correlationId, $\"Exception:{e}\");\n throw;\n }\n\n _logger.Info(correlationId, $\"Finished processing: {DateTime.Now}\");\n}\n```\n\n```text\nConversationId\n```\n\n```text\nCorrelationId\n```\n\n```text\nGuid\n```\n\n```text\nHttpRequest\n```\n\n```text\nHttpRequest\n```\n\n```text\nSendPublish\n```\n\n```text\nCorrelationId\n```\n\n```text\nCorrelationId\n```\n\n```text\nCorrelationId\n```\n\n```text\nConversationId\n```\n\n```text\nConversationId\n```\n\n```text\nConsumeContext\n```\n\n========================================\n\nComments:\n- It seems ConversationId is a MassTransit/NServiceBus thing? I don't find any mention in the RabbitMQ or AMQP docs. CorrelationId *is* a specific AMQP thing. The spec says \"no formal behaviour but may hold the name of a private response queue, when used in request messages\", and it's commonly used for the response queue name when doing an RPC request. So I think your use-case is ConversationId, not CorrelationId.\n- `ConversationId` is limited to a single message sequence, where you get one message and it goes through several consumers. `CorrelationId` is more long-living, you can have multiple conversations with one correlation id.\n- In addition to that, the conversation id is auto-generated and the correlation id is something arbitrary, which you can take from your domain. For example, in our ShoppingCart saga we use order id as the correlation id.\n- I stand corrected on ConversationId. Of course you can add your own header, if you want to keep CorrelationId for its normal purpose of doing RPC.\n- When I ran into this I just decided to use a term from my business domain. It ended up just being called lineId and I didn't use the header. I just used my own custom correlationId which helped because different rabbitmq clients can decide do different things with those headers. I also could include multiple lineids per message if I wanted to be less chatty.\n- Suggest reading the docs: masstransit-project.com/MassTransit/usage/…\n- @ChrisPatterson I literally quoted the docs and the difference between the two aren't clear! That's why I'm asking the question!!","metadata":{"transformedAt":"2026-08-18T18:33:20.163Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":17,"totalLines":323,"estimatedTokens":2590}}458{"id":"stack-17224331","source":"stackoverflow","questionId":17224331,"title":"How to ensure that messages get delivered?","tags":["python","rabbitmq","message","pika"],"text":"Title: How to ensure that messages get delivered?\nTags: python, rabbitmq, message, pika\nSource: Stack Overflow\n\nQuestion:\nHow do you ensure that messages get delivered with Pika? By default it will not provide you with an error if the message was not delivered succesfully.\n\nIn this example several messages can be sent before pika acknowledges that the connection was down.\n\n```\nimport pika\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost'))\nchannel = connection.channel()\nchannel.queue_declare(queue='hello')\nfor index in xrange(10):\n channel.basic_publish(exchange='', routing_key='hello', \n body='Hello World #%s!' % index)\n print('Total Messages Sent: %s' % x)\nconnection.close()\n```\n\n========================================\n\nTop Answer:\nafter trying myself and failing to receive other than ack,\ni decided to implement a direct reply to the sender.\n\ni followed the example given here\n\n========================================\n\nCode:\n```text\nimport pika\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost'))\nchannel = connection.channel()\nchannel.queue_declare(queue='hello')\nfor index in xrange(10):\n channel.basic_publish(exchange='', routing_key='hello', \n body='Hello World #%s!' % index)\n print('Total Messages Sent: %s' % x)\nconnection.close()\n```\n\n```text\nchannel.confirm_delivery()\n\ntry:\n for index in xrange(10):\n channel.basic_publish(exchange='', routing_key='hello', \n body='Hello World #%s!' % index)\n print('Total Messages Sent: %s' % x)\nexcept pika.exceptions.ConnectionClosed as exc:\n print('Error. Connection closed, and the message was never delivered.')\n```\n\n```text\nchannel.confirm_delivery()\n```\n\n```text\nbasic_publish\n```\n\n```text\nBoolean\n```\n\n========================================\n\nComments:\n- just out of curiousity, is BlockingConnection() needed in order to call channel.confirm_delivery() ?\n- @Jeffrey04: It should be supported in all connection types, as it is defined in the base channel object. github.com/pika/pika/blob/…","metadata":{"transformedAt":"2026-08-18T18:33:20.163Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":77,"estimatedTokens":530}}459{"id":"stack-19783529","source":"stackoverflow","questionId":19783529,"title":"RabbitMQ portable on Windows?","tags":["python","windows","erlang","rabbitmq","admin"],"text":"Title: RabbitMQ portable on Windows?\nTags: python, windows, erlang, rabbitmq, admin\nSource: Stack Overflow\n\nQuestion:\nI do not have access to the admin account in Windows 7. Is there a way to install *RabbitMQ* and its required *Erlang* without admin privileges? In some portable way?\n\nI need to use it in my Python Celery project.\n\nThanks!\n\n========================================\n\nTop Answer:\nI know this is an old question but I was facing the same issue recently and unfortunately I still haven't found an official portable version.\n\nFollowing @Furkan's answer, I created an automated workflow to create portable releases for RabbitMQ. You can find it here:\nhttps://github.com/sb-ghvcs/rabbitmq-portable\n\nIt does the same steps as @Furkan's answer temperorily within a contained shell without affecting rest of the system.\n\n========================================\n\nCode:\n```text\n[erlang]\nBindir=C:\\\\Users\\\\Limited_Account\\\\AppData\\\\erl5.10.4\\\\erts-5.10.4\\\\bin\nProgname=erl\nRootdir=C:\\\\Users\\\\Limited_Account\\\\AppData\\\\erl5.10.4\\\\erl5.10.4\n```\n\n```text\nC:\\Users\\Limited_Account\\AppData\\erl5.10.4\n```\n\n```text\nset ERLANG_HOME=\"C:\\\\Users\\\\Limited_Account\\\\AppData\\\\erl5.10.4\\\"\n```\n\n========================================\n\nComments:\n- I know this is an almost year old question that is possibly not relevant to you but I encountered the same thing 6 months ago and I posted an answer. It would be great if you can check that or at least accept it, it's a working solution :)\n- If you use a directory with spaces in the folder name (ex. 'Program Files), use MS-DOS path in .bat files like this: `set ERLANG_HOME=\"C:\\\\PROGRA~1\\\\MY~1\\\\resources\\\\assets\\\\erlang\\\\‌​erts-10.5\"` which corresponds to: `set ERLANG_HOME=\"C:\\\\Program Files\\\\My Folder\\\\resources\\\\assets\\\\erlang\\\\erts-10.5\"`","metadata":{"transformedAt":"2026-08-18T18:33:20.163Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":44,"estimatedTokens":449}}460{"id":"stack-38746900","source":"stackoverflow","questionId":38746900,"title":"QueueingBasicConsumer is deprecated. Which consumer is better to implement RabbitMq .net client","tags":["c#","rabbitmq"],"text":"Title: QueueingBasicConsumer is deprecated. Which consumer is better to implement RabbitMq .net client\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nIn the RabbitMQ .NET client, `QueueingBasicConsumer` is deprecated. \n\nThey recommend to use `EventingBasicConsumer` instead. I implemented the `IQueueingBasicConsumer` interface for the same way they did and it works well. \n\nHowever, I am curious to why it is deprecated and why I should use `EventingBasicConsumer`?\n\n========================================\n\nTop Answer:\nRead this discussion. Michael Klishin is the maintainer of .NET RabbitMQ client on GitHub.\n\nBut if you don't feel like going to different links and reading there I'll summarize...\n\nQueingBasicConsumer does not autorecover in current version, and it was a work around for a message dispatcher issue which no longer exists. But also I think Alexey is right, the performance was probably an issue too with the locking and busy waiting (in most implementations) the queue was introducing.\n\n========================================\n\nCode:\n```text\nQueueingBasicConsumer\n```\n\n```text\nEventingBasicConsumer\n```\n\n```text\nIQueueingBasicConsumer\n```\n\n```text\nEventingBasicConsumer\n```\n\n```text\nQueueingBasicConsumer\n```\n\n```text\nSharedQueue<T>\n```\n\n```text\nQueue\n```\n\n```text\nEventingBasicConsumer\n```\n\n```text\nEventingBasicConsumer\n```\n\n========================================\n\nComments:\n- Thank you for explanation. I simply used `QueueingBasicConsumer` for messaging module in my application. I need to update client and re implement with `EventingBasicConsumer`.","metadata":{"transformedAt":"2026-08-18T18:33:20.163Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":63,"estimatedTokens":396}}461{"id":"stack-41819447","source":"stackoverflow","questionId":41819447,"title":"Using publisher confirms with RabbitMQ, in which cases publisher will be notified about success/failure?","tags":["node.js","rabbitmq","amqp"],"text":"Title: Using publisher confirms with RabbitMQ, in which cases publisher will be notified about success/failure?\nTags: node.js, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nQuoting the book, RabbitMQ in Depth:\n\n A Basic.Ack request is sent to a publisher when a message that it has\n published has been directly consumed by consumer applications on all\n queues it was routed to or that the message was enqueued and persisted\n if requested.\n\nConfused with `Has been directly consumed`, does it mean when consumer send `ack` to broker publisher will be informed that consumer process message successfully? or it means that publisher will be notified when consumer just receive message from the queue?\n\n`or that the message was enqueued and persisted if requested`. Is this like conjuction or publisher will be informed when either of those happens? (In that case publisher would be notified twice)\n\nUsing `node.js` and `amqplib` wanted to check what is happening actually:\n\n```\n// consumer.js\namqp.connect(...)\n.then(connection => connection.createChannel())\n.then(() => { assert exchange here })\n.then(() => { assert queue here })\n.then(() => { bind queue and exchange here })\n.then(() => {\n channel.consume(QUEUE, (message) => {\n console.log('Raw RabbitMQ message received', message)\n\n // Simulate some job to do\n setTimeout(() => {\n channel.ack(message, false)\n }, 5000})\n\n }, { noAck: false })\n})\n\n// publisher.js\namqp.connect(...)\n.then(connection => connection.createConfirmChannel())\n.then(() => { assert exchange here })\n.then(() => {\n channel.publish(exchange, routingKey, new Buffer(...),{}, (err, ok) => {\n if (err) {\n console.log('Error from handling confirmation on publisher side', err)\n } else {\n console.log('From handling confirmation on publisher side', ok)\n }\n })\n})\n```\n\nRunning the example, i can see following logs:\n\n```\nFrom handling confirmation on publisher side undefined\nRaw RabbitMQ message received\nTime to ack the message\n```\n\n**As far as i see, at least by this log, publisher will be notified only when message was enqueued?** (So having consumer `ack`ing the message will not influence publisher in any way)\n\nQuoting further:\n\n If a message cannot be routed, the broker will send a Basic.Nack RPC\n request indicating the failure. It is then up to the publisher to\n decide what to do with the message.\n\nChanging the above example, where i only changed the routing key of the message to something that should not be routed anywhere (there are no bindings that would match routing key), from logs i can see **only** following.\n\n```\nFrom handling confirmation on publisher side undefined\n```\n\nNow i'm more confused, about what publisher is notified exactly here? I would understand that it receive an error, like `Can't route anywhere`, that would be aligned with quote above. But as you can see `err` is not defined and as side question even if `amqplib` in their official docs are using `(err, ok)`, in no single case i see those defined. So here output is same like in above example, how one can differ between above example and un-routable message. \n\nSo what im up to here, when exactly publisher will be notified about what is happening with the message? Any concrete example in which one would use PublisherConfirms? From logging above, i would conclude that is nice to have it in cases where you want to be 100% sure that message was enqueued.\n\n========================================\n\nTop Answer:\nby default publishers don't know anything about consumers.\n\n`PublisherConfirms` is used to check if the message reached the broker, but not if the message has been enqueued.\n\nyou can use `mandatory` flag to be sure the message has been routed\nsee this https://www.rabbitmq.com/reliability.html \n\n To ensure messages are routed to a single known queue, the producer\n can just declare a destination queue and publish directly to it. If\n messages may be routed in more complex ways but the producer still\n needs to know if they reached at least one queue, it can set the\n mandatory flag on a basic.publish, ensuring that a basic.return\n (containing a reply code and some textual explanation) will be sent\n back to the client if no queues were appropriately bound.\n\n========================================\n\nCode:\n```text\n// consumer.js\namqp.connect(...)\n.then(connection => connection.createChannel())\n.then(() => { assert exchange here })\n.then(() => { assert queue here })\n.then(() => { bind queue and exchange here })\n.then(() => {\n channel.consume(QUEUE, (message) => {\n console.log('Raw RabbitMQ message received', message)\n\n // Simulate some job to do\n setTimeout(() => {\n channel.ack(message, false)\n }, 5000})\n\n }, { noAck: false })\n})\n\n// publisher.js\namqp.connect(...)\n.then(connection => connection.createConfirmChannel())\n.then(() => { assert exchange here })\n.then(() => {\n channel.publish(exchange, routingKey, new Buffer(...),{}, (err, ok) => {\n if (err) {\n console.log('Error from handling confirmation on publisher side', err)\n } else {\n console.log('From handling confirmation on publisher side', ok)\n }\n })\n})\n```\n\n```text\nFrom handling confirmation on publisher side undefined\nRaw RabbitMQ message received\nTime to ack the message\n```\n\n```text\nFrom handling confirmation on publisher side undefined\n```\n\n```text\nHas been directly consumed\n```\n\n```text\nack\n```\n\n```text\nor that the message was enqueued and persisted if requested\n```\n\n```text\nnode.js\n```\n\n```text\namqplib\n```\n\n```text\nack\n```\n\n```text\nCan't route anywhere\n```\n\n```text\nerr\n```\n\n```text\namqplib\n```\n\n```text\n(err, ok)\n```\n\n```text\nPublisherConfirms\n```\n\n```text\nmandatory\n```\n\n```text\nconst BunnyBus = require('bunnybus');\nconst bunnyBus = new BunnyBus({\n user: 'your-user',\n vhost: 'your-vhost', // cloudamqp defaults vhost to the username\n password: 'your-password',\n server: 'your.server.com'\n});\n\nconst handler = {\n 'test.event': (message, ack) => {\n\n // Do your work here.\n\n // acknowledge the message off of the bus.\n return ack();\n }\n};\n\n// Create exchange and queue if they do not already exist and then auto connect.\nreturn bunnyBus.subscribe('test', handler)\n .then(() => {\n\n return bunnyBus.publish({event: 'test.event', body: 'here\\'s the thing.'});\n })\n .catch(console.log);\n```\n\n========================================\n\nComments:\n- please check my answer, as it seems your answer is not correct\n- Actually, my understanding is that publisher confirms tell you that Rabbit has it and will not lose it ... the accepted answer above is straight from the official blog ...\n- I upvoted this answer because it is accurate, but I think the question was asking how you can get those events from that article in javascript. The most popular library does not make that obvious at all ...","metadata":{"transformedAt":"2026-08-18T18:33:20.163Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":16,"totalLines":225,"estimatedTokens":1701}}462{"id":"stack-35748700","source":"stackoverflow","questionId":35748700,"title":"How to post messages to RabbitMQ from SQL Server?","tags":["sql-server","rabbitmq","message-queue","easynetq"],"text":"Title: How to post messages to RabbitMQ from SQL Server?\nTags: sql-server, rabbitmq, message-queue, easynetq\nSource: Stack Overflow\n\nQuestion:\nI am creating an application for testing performance between different RabbitMQ clients.\n\nOne of them should be SQL Server.\n\nI found out that there exists RabbitMQ component for SQL Server Integration Services (SSIS).\n\nBut seems like destination component which can send messages to an exchange is not written yet.\n\nAny ideas how to perform that?\n\nShould it be similar with posting messages to MSMQ?\n\n========================================\n\nTop Answer:\nYou can create a SQLClr to comunicate with a RabbitMQ, like in this post.\n\nI don't believe it's a nice solution, but it seems to work.\n\n========================================\n\nCode:\n```text\n--help\n```\n\n```text\nDECLARE @Cmd VARCHAR(2000)\nSET @Cmd = 'rabbitmqadmin publish exchange=amq.default routing_key=test payload=\"hello, world\"'\nEXEC [sys].[xp_cmdshell] @Cmd\n```\n\n========================================\n\nComments:\n- What are you trying to do? A database stores data and responds to queries, it doesn't try to talk to integrate with other systems. While you *can* eg call external commands, the delay is attrocious, it involves relaxing security and it's simply a misuse of the *database*. SSIS is a different sevice, one made explicitly to ease *integration* between different systems, not just SQL Server.\n- I'm trying to compare sending and receiving capabillity of clients including sql server (messages per second).\n- A database isn't a messaging client. A web application on the other hand, is. What is the actual problem you are trying to solve? How to integrate different systems? Services? Web applications?\n- Note that SQL Server has its own messaging system, the Message Broker. Which wasn't very well received because well, as it's heavier than what most people want from messaging systems. It also requires configuration. While you *could* integrate Message Broker with RabbitMQ, it would be like shooting a fly with a howitzer\n- I just got a task to create different RabbitMQ clients that would send many messages to RabbitMQ. So after that we would be able to test their sending and receiving performance. I was thinking that I can send a messages to RabbitMQ for example from within a SQL Server stored procedure.\n- Note that NServiceBus supports queueing using both SQL Server (docs.particular.net/transports/sql) and RabbitMQ (docs.particular.net/transports/rabbitmq) and running a bridge between the two – docs.particular.net/nservicebus/bridge\n- Sorry, downvoting because the OP wants to connect directly from SQL Server/SSIS. Java is not mentioned.\n- @KeesdeKooter do as you must. I'm not going to quote the disclaimer I wrote at the beginning of the answer. I do appreciate the explanation for the -1\n- Please include the neccessary steps inside your answer body. While the post behind the link may solve the question, the link can go down and your answer becomes pretty much useless.\n- this link not working\n- Morten makes a great point, because in 2024, that link still does not work and as someone looking for a solution it is frustrating. Sadly I see this more and more and it is a lazy way to put up an answer.","metadata":{"transformedAt":"2026-08-18T18:33:20.163Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":51,"estimatedTokens":811}}463{"id":"stack-42813355","source":"stackoverflow","questionId":42813355,"title":"Does pika confirm_delivery mean confirm when broker got the message or when consumer acknowledged?","tags":["rabbitmq","amqp","pika"],"text":"Title: Does pika confirm_delivery mean confirm when broker got the message or when consumer acknowledged?\nTags: rabbitmq, amqp, pika\nSource: Stack Overflow\n\nQuestion:\nFrom my producer code I want to know when the consumer has `basic.ack`ed a message.\n\nUsing `channel.confirm_delivery()` and a `BlockingConnection` it is not clear from the documentation if this should confirm 1) the broker having received the message, or, 2) a consumer having acknowledge receiving it.\n\nRunning this code (with no consumer):\n\n```\nimport pika\nimport uuid\n\n# Open a connection to RabbitMQ on localhost using all default parameters\nconnection = pika.BlockingConnection()\n# Open the channel\nchannel = connection.channel()\nqueue = str(uuid.uuid4())\n\n# Declare the queue\nchannel.queue_declare(queue=queue)\n\n# Turn on delivery confirmations\nchannel.confirm_delivery()\n\n# Send a message\nif channel.basic_publish(exchange='',\n routing_key=queue,\n body='Hello World!',\n properties=pika.BasicProperties(\n content_type='text/plain',\n delivery_mode=1)):\n print('Message publish was confirmed')\nelse:\n print('Message could not be confirmed')\n```\n\nshows the message to be confirmed. This is not what I expect or want.\n\nThis may be a duplicate of\nBehavior of channels in \"confirm\" mode with RabbitMQ however the documentation for basic_publish says\n\n :returns: True if delivery confirmation is not enabled (NEW in pika\n 0.10.0); otherwise returns False if the message could not be\n deliveved (Basic.nack and/or Basic.Return) and True if the message\n was delivered (Basic.ack and no Basic.Return)\n\nwhich makes me think it should have the I wanted in the first place.\n\n========================================\n\nCode:\n```text\nimport pika\nimport uuid\n\n# Open a connection to RabbitMQ on localhost using all default parameters\nconnection = pika.BlockingConnection()\n# Open the channel\nchannel = connection.channel()\nqueue = str(uuid.uuid4())\n\n# Declare the queue\nchannel.queue_declare(queue=queue)\n\n# Turn on delivery confirmations\nchannel.confirm_delivery()\n\n# Send a message\nif channel.basic_publish(exchange='',\n routing_key=queue,\n body='Hello World!',\n properties=pika.BasicProperties(\n content_type='text/plain',\n delivery_mode=1)):\n print('Message publish was confirmed')\nelse:\n print('Message could not be confirmed')\n```\n\n```text\nbasic.ack\n```\n\n```text\nchannel.confirm_delivery()\n```\n\n```text\nBlockingConnection\n```\n\n```text\nconfirm_deliveries\n```\n\n========================================\n\nComments:\n- Thanks a lot for clearing this up - indeed this is what I found out after some testing.","metadata":{"transformedAt":"2026-08-18T18:33:20.163Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":102,"estimatedTokens":674}}464{"id":"stack-36719960","source":"stackoverflow","questionId":36719960,"title":"“init terminating in do_boot” Windows 8.1 Rabbit MQ fails to start","tags":["windows","rabbitmq"],"text":"Title: “init terminating in do_boot” Windows 8.1 Rabbit MQ fails to start\nTags: windows, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI install `erl7.3` and `rabbitmq_server-3.6.1`,but I get the error when I run `rabbitmq-plugins enable rabbitmq_stomp`.\n\n```\n{ \"init terminating in do_boot\", { undef, [{ rabbit_nodes, ensure_epmd, [], [] }, { rabbit_ cli, start_distribution, 0, [{ file, \"src/rabbit_cli.erl\" }, { line, 152 }] }, { rabbit_cli, e nsure_cli_distribution, 0, [{ file, \"src/rabbit_cli.erl\" }, { line, 49 }] }, { rabbit_cli, ma in , 3, [{ file, \"src/rabbit_cli.erl\" }, { line, 62 }] }, { init, start_it, 1, [{ file, \"init.erl\" }, { line, 1054 }] }, { init, start_em, 1, [{ file, \"init.erl\" }, { line, 1035 }] }] } }\n\ninit terminating in do_boot ()\n```\n\nIs there anything I'm missing?How can I fix the `init terminating in do_boot` error.\n\n========================================\n\nTop Answer:\nOn the same error, on Windows 7 :\n\n- If I use in the installation path of the RabbitMQ Server space characters (i.e. D:\\soft\\RabbitMQ Server), the same error occured ({ \"init terminating in do_boot\", { undef, [{ rabbit_nodes,...) .\n\n- If the installation path doesn't contain space char (i.e. D:\\soft\\RabbitMQServer), then no error and RabbitMQ works fine.\n\nSo the problem is due for many people to the space in paths of default settings of the RabbitMQ installation program on Windows.\n\n========================================\n\nCode:\n```text\n{ \"init terminating in do_boot\", { undef, [{ rabbit_nodes, ensure_epmd, [], [] }, { rabbit_ cli, start_distribution, 0, [{ file, \"src/rabbit_cli.erl\" }, { line, 152 }] }, { rabbit_cli, e nsure_cli_distribution, 0, [{ file, \"src/rabbit_cli.erl\" }, { line, 49 }] }, { rabbit_cli, ma in , 3, [{ file, \"src/rabbit_cli.erl\" }, { line, 62 }] }, { init, start_it, 1, [{ file, \"init.erl\" }, { line, 1054 }] }, { init, start_em, 1, [{ file, \"init.erl\" }, { line, 1035 }] }] } }\n\ninit terminating in do_boot ()\n```\n\n```text\nerl7.3\n```\n\n```text\nrabbitmq_server-3.6.1\n```\n\n```text\nrabbitmq-plugins enable rabbitmq_stomp\n```\n\n```text\ninit terminating in do_boot\n```\n\n```text\nC:\\Program Files\\RabbitMQ Server\n```\n\n========================================\n\nComments:\n- Thx, I change the path `D:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.6.1` to `D:\\RbbbitMQ\\rabbitmq_server-3.6.1` and now it's work well.\n- @qqxufo, so you left the Erlang install as is?\n- I have installed erl7.3.And I find the Official Guide `This is because we need to pass the location of the compiled Erlang files to the Erlang VM. It expects input in UTF-8, but the console will typically use some other encoding.`\n- Installed on Windows 7, no problems... mine was on windows 10, must be an 8+ issue!?\n- I am not sure.May be is 8+ issuel.\n- Thank you! I tried several other fixes and removing the space in the installation path is the only thing that worked. RabbitMQ is great but it's insane that this is still a problem in 2017.","metadata":{"transformedAt":"2026-08-18T18:33:20.163Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":64,"estimatedTokens":736}}465{"id":"stack-38844610","source":"stackoverflow","questionId":38844610,"title":"Consume messages in batches - RabbitMQ","tags":["c#","rabbitmq","message-queue"],"text":"Title: Consume messages in batches - RabbitMQ\nTags: c#, rabbitmq, message-queue\nSource: Stack Overflow\n\nQuestion:\nI was able to consume multiple messages that are sent by multiple producers to the same exchange with different routing key using the above code and was able to insert each message to database.\n\nBut this will consume too much of resources as messages will be inserted into DB one after the other. So I decided to go for batch insert and I found I can set `BasicQos`\n\nAfter setting the message limit to 10 in BasicQos, my expectation is the `Console.WriteLine` must write 10 messages, but it is not as expected.\n\nMy expectation is to consume N number messages from the queue and do bulk insert and on successful send ACK else No ACK\n\nHere is the piece of code I use.\n\n```\nusing (var connection = factory.CreateConnection())\n{\n using (var channel = connection.CreateModel())\n {\n channel.QueueBind(queue: \"queueName\", exchange: \"exchangeName\", routingKey: \"Producer_A\");\n channel.QueueBind(queue: \"queueName\", exchange: \"exchangeName\", routingKey: \"Producer_B\");\n\n channel.BasicQos(0, 10, false);\n\n var consumer = new EventingBasicConsumer(channel);\n channel.BasicConsume(queue: \"queueName\", noAck: false, consumer: consumer);\n\n consumer.Received += (model, ea) =>\n {\n try\n {\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n\n // Insert into Database\n\n channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);\n Console.WriteLine(\" Recevier Ack \" + ea.DeliveryTag);\n }\n catch (Exception e)\n {\n channel.BasicNack(deliveryTag: ea.DeliveryTag, multiple: false, requeue: true);\n Console.WriteLine(\" Recevier No Ack \" + ea.DeliveryTag);\n }\n };\n\n Console.ReadLine();\n }\n}\n```\n\n========================================\n\nTop Answer:\nBatch size based consumption can be done using the channel.basicQos().\n\n```\nChannel channel = connection.createChannel();\nchannel.basicQos(10);\n```\n\nIt specifies the maximum no of messages to be fetched without sending ACK for each.\n\nUse the DefaultConsumer class and override its methods.\n\n```\nConsumer batchConsumer = new DefaultConsumer(channel) {\n\n @Override\n public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {\n \n }\n\n @Override\n public void handleCancelOk(String consumerTag) {\n \n }\n};\n```\n\nConsume 10 messages using channel.basicConsume()\n\n```\nchannel.basicConsume(QUEUE_NAME, false, batchConsumer);\n```\n\nWhen channel.basicConsume() is called it will fetch a batch of 10 messages. 'false' is set to disable auto ack, and ACK to be sent only once after consuming entire batch.\n\n```\nchannel.basicAck(getLastMessageEnvelope().getDeliveryTag(), true);\n```\n\nHere 'true' means we are sending ACK for multiple messages.\n\nDetailed explanation can be found in\n\nRabbitMQ Batch Consumption\n\n========================================\n\nCode:\n```text\nusing (var connection = factory.CreateConnection())\n{\n using (var channel = connection.CreateModel())\n {\n channel.QueueBind(queue: \"queueName\", exchange: \"exchangeName\", routingKey: \"Producer_A\");\n channel.QueueBind(queue: \"queueName\", exchange: \"exchangeName\", routingKey: \"Producer_B\");\n\n channel.BasicQos(0, 10, false);\n\n var consumer = new EventingBasicConsumer(channel);\n channel.BasicConsume(queue: \"queueName\", noAck: false, consumer: consumer);\n\n consumer.Received += (model, ea) =>\n {\n try\n {\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n\n // Insert into Database\n\n channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);\n Console.WriteLine(\" Recevier Ack \" + ea.DeliveryTag);\n }\n catch (Exception e)\n {\n channel.BasicNack(deliveryTag: ea.DeliveryTag, multiple: false, requeue: true);\n Console.WriteLine(\" Recevier No Ack \" + ea.DeliveryTag);\n }\n };\n\n Console.ReadLine();\n }\n}\n```\n\n```text\nBasicQos\n```\n\n```text\nConsole.WriteLine\n```\n\n```text\nchannel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: true);\n```\n\n```text\nfinal List<String> myMessagges = new ArrayList<String>();\n channel.basicConsume(\"my_queue\", false, new DefaultConsumer(channel) {\n\n @Override\n public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {\n myMessagges.add(new String(body));\n System.out.println(\"Received...\");\n\n if (myMessagges.size() >= 10) {\n System.out.println(\"insert into DB...\");\n channel.basicAck(envelope.getDeliveryTag(), true);\n myMessagges.clear();\n }\n\n\n }\n });\n```\n\n```text\nBasicQos = 10\n```\n\n```text\nChannel channel = connection.createChannel();\nchannel.basicQos(10);\n```\n\n```text\nConsumer batchConsumer = new DefaultConsumer(channel) {\n\n @Override\n public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {\n \n }\n\n @Override\n public void handleCancelOk(String consumerTag) {\n \n }\n};\n```\n\n```text\nchannel.basicConsume(QUEUE_NAME, false, batchConsumer);\n```\n\n```text\nchannel.basicAck(getLastMessageEnvelope().getDeliveryTag(), true);\n```\n\n========================================\n\nComments:\n- Thanks. here the scope of \"ea\" is with in the event consumer.Received, so how can I do ACK after inserting all the messages to DB?\n- Well, just don't execute `basicAck` for each message and execute it each x messages using the flag `multiple = true`\n- if I understand it correctly, within the scope of consumer.Received, if I set 'multiple = true', then the ACK will be sent only after consuming all the 10 messages set in BasicQos. Sorry to bother again. It will be helpful if you can give me some code sample. Thanks in advance!\n- @Gabriele What will happen if any of the 10 messages gives error while inserting into DB? How will you handle that?\n- How would you handle errors with this model? Ack where multiple = true is nice if there is no errors. But I don't see how I'd synchronize this if I couldnt just do an ack for some and a nack for others.\n- What happens when there are fewer than 10 messages to be consumed? Won't these messages be left unacknowledged? How would this be handled? Is there a way to check / prevent this given the above solution?","metadata":{"transformedAt":"2026-08-18T18:33:20.164Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":212,"estimatedTokens":1633}}466{"id":"stack-2835143","source":"stackoverflow","questionId":2835143,"title":"AMQP subscriber inside Rails app","tags":["ruby-on-rails","rabbitmq","amqp"],"text":"Title: AMQP subscriber inside Rails app\nTags: ruby-on-rails, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nIs it possible to start an AMQP subscriber with my Rails app? Possibly through an initializer or something. \n\nI'd like to have it running at the same time that can also interact with Rails models. Below is a pseudo-code example of what I mean.\n\n```\nqueue.subscribe do |msg,body|\n Foo.create(....)\nend\n```\n\n========================================\n\nCode:\n```text\nqueue.subscribe do |msg,body|\n Foo.create(....)\nend\n```\n\n```text\n#!/usr/bin/env ruby\n require 'rubygems'\n require 'amqp'\n require 'daemons'\n\n ENV[\"RAILS_ENV\"] ||= \"development\"\n require File.dirname(__FILE__) + \"/../config/environment\"\n\n options = { :backtrace => true, :dir => '.', :log_output => true}\n\n Daemons.run_proc('myapp_daemon', options) do\n EventMachine.run do\n connection = AMQP.connect(:host => \"127.0.0.1\")\n\n channel = AMQP::Channel.new(connection)\n queue = channel.queue(\"/myapp_daemon\", :durable => true)\n exchange = channel.direct(\"\")\n\n queue.subscribe do |payload|\n obj = JSON.parse(payload)\n #... handle messages here, utilize your rails models\n Foo.create(...)\n end\n end\n end\n```\n\n```text\nRAILS_ENV=development script/myapp_daemon.rb run\n```\n\n```text\nsystem('script/myapp_daemon.rb start')\n```\n\n========================================\n\nComments:\n- i wonder where you have decided to get subscribe, initializer or somewhere else?\n- Looking at your implementation, does it recursively launch daemons?\n- Just notice that starting that from an initializer will start that on rails console and generally everything that starts the app.","metadata":{"transformedAt":"2026-08-18T18:33:20.164Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":66,"estimatedTokens":433}}467{"id":"stack-1139203","source":"stackoverflow","questionId":1139203,"title":"In a FIFO Qeueing system, what's the best way the to implement priority messaging","tags":["message-queue","messaging","priority-queue","rabbitmq","amqp"],"text":"Title: In a FIFO Qeueing system, what's the best way the to implement priority messaging\nTags: message-queue, messaging, priority-queue, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nFor message-oriented middleware that does not consistently support priority messages (such as AMQP) what is the best way to implement priority consumption when queues have only FIFO semantics? The general use case would be a system in which consumers receive messages of a higher priority before messages of a lower priority when a large backlog of messages exists in Queue(s).\n\n========================================\n\nComments:\n- Can you have multiple queues? If so I would suggest having a seperate queue for high priority messages which is queried first before the standard queue, which is only used if the priority queue is empty. I don't know if that fits with your scenario but that was my first idea.\n- I agree with CSharpWithJava. I'm doing a big messaging app at the moment, and I think from your questions, you need multiple queues, so you can offload lower pri messages to a lower pri queue, and read the high pri immediately.\n- Notice AMQP does have priority messages starting from 0-9-1 spec (rabbitmq.com/amqp-0-9-1-reference.html)\n- This is more or less exactly who we've implemented this strategy for a project at work. Multiple queues for a graded priority system. We don't worry much about starvation because we can just republish important lower priority messages with a higher priority in such instances; redundantly work is handled, for the most part, idempotently to allow this.","metadata":{"transformedAt":"2026-08-18T18:33:20.164Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":14,"estimatedTokens":397}}468{"id":"stack-33416511","source":"stackoverflow","questionId":33416511,"title":"Is There a way to debug RabbitMQ Consumer (php-ampqlib) using PhpStorm and Xdebug?","tags":["php","cakephp","rabbitmq","phpstorm","xdebug"],"text":"Title: Is There a way to debug RabbitMQ Consumer (php-ampqlib) using PhpStorm and Xdebug?\nTags: php, cakephp, rabbitmq, phpstorm, xdebug\nSource: Stack Overflow\n\nQuestion:\nHere is my dev setup:\n\n**IDE:** PhpStorm 9.0.2\n\n**Debugger:** Xdebug 2.3.3\n\n**Message Queue Server:** RabbitMQ 3.5.6\n\n**PHP Lib to connect to RabbitMQ Server:** php-ampqlib\n\nTo start my consumer I'm using a CakePHP Task and run like this:\n\n ../lib/Cake/Console/cake cron message_trigger_consumer\n\nWhen I run this command, my consumer is UP and waiting for a message, that will comes from a **Producer** (for example: Save Form Button that send a confirmation email). Until here, everything is OK, but my two questions are: \n\n1) Is There a way to debug the **Consumer**? In my point of view, **Consumer** is in a different process, that's why Xdebug cannot debug it\n\n2) Have some way to attach my **Consumer** process to my current debug in PhpStorm + Xdebug? \n\nIf you not understand my question, please, show me your doubts.\n\n========================================\n\nTop Answer:\n### Xdebug and RabbitMQ consumer commands\n\nRunning `cake cron message_trigger_consumer` doesn't trigger xdebug in the IDE. To make PhpStorm aware of the connection you need to prefix the command with the environment variable: \n\n`PHP_IDE_CONFIG=\"serverName=example.com\" cake cron message_trigger_consumer`\n\nReplace `example.com` with appropriate server name.\n\n========================================\n\nCode:\n```text\nexport PHP_IDE_CONFIG=\"serverName=your-server-name-configured-in-php-storm\"\nexport XDEBUG_CONFIG=\"remote_host=ip_of_php_storm_pc idekey=PHPSTORM\"\n```\n\n```text\nXDEBUG_SESSION\n```\n\n```text\ncake cron message_trigger_consumer\n```\n\n```text\nPHP_IDE_CONFIG=\"serverName=example.com\" cake cron message_trigger_consumer\n```\n\n```text\nexample.com\n```\n\n========================================\n\nComments:\n- Debug it as any other PHP script.\n- Could you explain how?\n- Could you your PHP xdebug.ini settings ?\n- Your solution works when I using php script without CakePHP framework. I tried a plugin called FIREHOSE from RabbitMQ and works more or less. I think CLI using CakePHP is my problem.\n- Please your xdebug.* settings values from `php -i`\n- zend_extension=xdebug.so xdebug.remote_enable=1 xdebug.remote_host=localhost xdebug.remote_port= 9000 xdebug.profiler_enable=1 xdebug.profiler_output_dir=\"/tmp\" xdebug.idekey=PHPSTORM","metadata":{"transformedAt":"2026-08-18T18:33:20.164Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":71,"estimatedTokens":597}}469{"id":"stack-22354668","source":"stackoverflow","questionId":22354668,"title":"Celery tasks disappear","tags":["python","django","rabbitmq","task","celery"],"text":"Title: Celery tasks disappear\nTags: python, django, rabbitmq, task, celery\nSource: Stack Overflow\n\nQuestion:\nI have a django project running with cron script, executing a management command. This command creates in for cycle tasks for celery:\n\n```\nfor r in pr:\n log_task(tasks_logger.info, \"to_queue\", r)\n remind.delay(r, now, send_all)\n```\n\nAnd the task looks like this:\n\n```\nclass RTask(Task):\n abstract = True\n def on_failure(self, exc, task_id, args, kwargs, einfo):\n r = args[0]\n log_task(logger.error, exc, r)\n log_task(logger_tb.error, einfo, r)\n\n@task(base=RTask)\ndef remind(r, now, send_all):\n log_task(logger.info, \"from_queue\", r)\n ....\n```\n\nAs u can see, I have a logger before task execution and on first line inside it. The problem is - after the update of the project code (another programmer added other tasks and celery version update) majority of my tasks start vanishing. My log file looks like this (only 1 of 8-10 tasks executed):\n\n```\n[2014-03-12 12:45:08,806] 106152122 INFO to_queue\n[2014-03-12 12:45:08,819] 106138932 INFO to_queue\n[2014-03-12 12:45:08,915] 106121944 INFO to_queue\n[2014-03-12 12:45:08,916] 110418819 INFO from_queue\n[2014-03-12 12:45:08,922] 106075777 INFO to_queue\n```\n\nThe celery log file don't contains any helpful info. So does rabbit.\nIt has lots of this stuff, but its not connected with my tasks, or does it?\n\n```\n[2014-03-12 12:58:43,091: INFO/MainProcess] Got task from broker: celery.chord_unlock[7fe8f29f-69e1-456c-8a14-7fae0cfacc33] eta:[2014-03-12 12:58:44.089401+00:00]\n[2014-03-12 12:58:43,092: INFO/MainProcess] Task celery.chord_unlock[7fe8f29f-69e1-456c-8a14-7fae0cfacc33] retry: Retry in 1s\n[2014-03-12 12:58:43,092: INFO/MainProcess] Task celery.chord_unlock[7b1d4a6b-9a34-43e9-98c9-851c93ace5ce] retry: Retry in 1s\n```\n\nWhat could be possibly the problem?\nHow can I trace task to understand when it disappears?\n\nPlease help =)\n\n========================================\n\nTop Answer:\nIt's possible that you have celery processes running in the background, relics of previous launches that weren't shut down properly, that might be consuming the messages. try to see if you have such workers by running\n\n`ps aux | grep celery` \n\nin the command line. The following command will automatically kill all such orphan celery workers for you:\n\n`ps aux | grep celery | awk '{system(\"kill -9 \" $2)}'`\n\nI execute it before launching my app\n\n========================================\n\nCode:\n```text\nfor r in pr:\n log_task(tasks_logger.info, \"to_queue\", r)\n remind.delay(r, now, send_all)\n```\n\n```text\nclass RTask(Task):\n abstract = True\n def on_failure(self, exc, task_id, args, kwargs, einfo):\n r = args[0]\n log_task(logger.error, exc, r)\n log_task(logger_tb.error, einfo, r)\n\n\n@task(base=RTask)\ndef remind(r, now, send_all):\n log_task(logger.info, \"from_queue\", r)\n ....\n```\n\n```text\n[2014-03-12 12:45:08,806] 106152122 INFO to_queue\n[2014-03-12 12:45:08,819] 106138932 INFO to_queue\n[2014-03-12 12:45:08,915] 106121944 INFO to_queue\n[2014-03-12 12:45:08,916] 110418819 INFO from_queue\n[2014-03-12 12:45:08,922] 106075777 INFO to_queue\n```\n\n```text\n[2014-03-12 12:58:43,091: INFO/MainProcess] Got task from broker: celery.chord_unlock[7fe8f29f-69e1-456c-8a14-7fae0cfacc33] eta:[2014-03-12 12:58:44.089401+00:00]\n[2014-03-12 12:58:43,092: INFO/MainProcess] Task celery.chord_unlock[7fe8f29f-69e1-456c-8a14-7fae0cfacc33] retry: Retry in 1s\n[2014-03-12 12:58:43,092: INFO/MainProcess] Task celery.chord_unlock[7b1d4a6b-9a34-43e9-98c9-851c93ace5ce] retry: Retry in 1s\n```\n\n```text\nps aux | grep celery\n```\n\n```text\nps aux | grep celery | awk '{system(\"kill -9 \" $2)}'\n```\n\n========================================\n\nComments:\n- Have you tried setting the loglevel to DEBUG instead of INFO?\n- >> Have you tried setting the loglevel to DEBUG instead of INFO? No additional info =(\n- It's hard to tell what your problem is without detailed info. Try first `rabbitmqctl list_queues` or if you use vhost: `rabbitmqctl list_queues -p ` and see that these tasks really do get stored in RabbitMQ. If not then double-check your config file. Note that if you're using django_celery, you need to add this to settings: `import djcelery; djcelery.setup_loader()`. BTW: if you have multiple workers and are logging to the same file, you might have file lock problems with some workers overwriting others' lines.","metadata":{"transformedAt":"2026-08-18T18:33:20.164Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":118,"estimatedTokens":1103}}470{"id":"stack-15204051","source":"stackoverflow","questionId":15204051,"title":"Integration tests of a polyglot stack (Java/MongoDB/RabbitMQ...)","tags":["java","mongodb","jvm","rabbitmq","amqp"],"text":"Title: Integration tests of a polyglot stack (Java/MongoDB/RabbitMQ...)\nTags: java, mongodb, jvm, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI am aware RabbitMQ is written in Erlang and thus can't be embedded in a JVM like we would do with the ActiveMQ JMS broker for exemple.\n\nBut actually there are some projects that are done in another language and that can easily be embedded for integration tests.\n\nFor exemple, MongoDB, written in C++, can be easily started/stopped in the context of a JVM integration test with: \nhttps://github.com/flapdoodle-oss/embedmongo.flapdoodle.de\n\nThere is also someone porting it to Java:\nhttps://github.com/thiloplanz/jmockmongo/\n\nSo I just wonder how can we do integration tests when my application is written in Java, and the other technology is in another langage (like Erlang for RabbitMQ)? \n\nIn general what are the good practices? \n\nI see 3 main solutions:\n\n- Starting a real RabbitMQ\n\n- Embedding a JVM port of the technology in the currently used Langage\n\n- Use standard technologies so that a technology in Erlang may have the same behavior and communication layer that another one in Java (RabbitMQ / Qpid / StormMQ implementing AMQP)\n\nIs there a Maven/Sbt/Ant plugin to startup a temporary RabbitMQ broker? \nAny project to support Junit/TestNG RabbitMQ before a test class?\n\nI have seen that there is an opensource implementation of AMQP in Java: Apache Qpid\nHas someone any experience using this implementation for integration testing while in production there is RabbitMQ? Is it even possible?\nI am using Spring Integration.\n\nBy the way, I just noticed that the Spring-AMQP project mention on its github readme:\n\n Many of the \"integration\" tests here require a running RabbitMQ server\n - they will be skipped if the broker is not detected.\n\n========================================\n\nTop Answer:\nIf it were me, I would look at mocking the stack component in question. What's the best mock framework for Java? (although not a great Stack Overflow question) and Mock Object might help get you going.\n\nMocking the components makes testing much easier (IMHO) than trying to \"live test\" everything.\n\n========================================\n\nCode:\n```text\nEmbeddedRabbitMqConfig config = new EmbeddedRabbitMqConfig.Builder()\n .version(PredefinedVersion.V3_5_7)\n // ...\n .build();\nEmbeddedRabbitMq rabbitMq = new EmbeddedRabbitMq(config);\nrabbitMq.start();\n...\nrabbitMq.stop();\n```\n\n========================================\n\nComments:\n- My experience using Apache Qpid from within another JVM project was certainly disappointing. While it IS possible to start Apache Qpid this way, it was NOT designed to work like this. QPid, at runtime, reconfigured the whole application Logging framework (SLF4J + Logback) to suit its own needs and wasn't easy to revert this change. In our case, we were heavily relying on RabbitMQ's extensions so it didn't make sense pursuing this avenue anymore.\n- We already use mocking (btw I work with a Mockito commiter). This integration test is aimed to check that the integration works. So if I use mocks, this part is not tested anymore. I'd like to check my broken configuration works fine with my application too, and not just the application behavior.\n- Nice idea. How much time does it take to spawn that VM with a RabbitMQ?\n- With Vagrant and the basebox cached it takes under 5 minutes, it was a bit of a problem on the CI machine so it is rebuilt after the tests run to be left waiting for the next code push. With proper management of vhosts it should be possible to leave it running for the CI server and just rebuild it overnight.\n- I saw there is a maven vagrant plugin. Need to try it. nicoulaj.github.io/vagrant-maven-plugin/examples/… Thanks this seems to be the best way to use\n- I've accepted my own answer here: stackoverflow.com/a/24919210/82609 because using Docker seems to me more appropriate than using VMs finally\n- Yeas that's right. Btw it seems RabbitMQ an AMQP 0.9.1 broker but Qpid is 1.0...\n- I would also start an instance of RabbitMQ, but for automated/CI tests how do you start it? I would like to have some maven plugin for the pre-integration-test phase which spawns a fresh new RabbitMQ server and shuts it down after the tests","metadata":{"transformedAt":"2026-08-18T18:33:20.164Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":71,"estimatedTokens":1065}}471{"id":"stack-12687368","source":"stackoverflow","questionId":12687368,"title":"RabbitMQ QueueingConsumer possible memory leak","tags":["java","memory-leaks","jms","rabbitmq"],"text":"Title: RabbitMQ QueueingConsumer possible memory leak\nTags: java, memory-leaks, jms, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have the following code to declare a queue:\n\n```\nConnection connection = RabbitConnection.getConnection();\nChannel channel = connection.createChannel();\nchannel.queueDeclare(getQueueName(), false, false, false, null);\nconsumer = new QueueingConsumer(channel);\nchannel.basicConsume(getQueueName(), true,consumer);\n```\n\nand the following to get the next Delivery object and process it:\n\n```\nDelivery delivery = null;\n T queue = null;\n\n //loop over, continuously retrieving messages\n while(true) {\n\n try {\n delivery = consumer.nextDelivery();\n queue = deserialise(delivery.getBody());\n\n process(queue);\n\n } catch (ShutdownSignalException e) {\n logger.warn(\"Shutodwon signal received.\");\n break;\n } catch (ConsumerCancelledException e) {\n logger.warn(\"Consumer cancelled exception: {}\",e.getMessage());\n break;\n } catch (InterruptedException e) {\n logger.warn(\"Interuption exception: {}\", e);\n break;\n }\n }\n```\n\nThe deserialise code. As you can see I'm using Kryo:\n\n```\npublic T deserialise(byte[] body) {\n Kryo kryo= new Kryo();\n Input input = new Input(body);\n T deserialised = kryo.readObject(input, getQueueClass());\n input.close();\n\n return deserialised;\n}\n```\n\nIf I run this with a queue containing a large number of objects, after approximatelly 2.7 million objects I get an out of memory exception. I found this originally by running it over night with data going in from JMeter at a rate ~90/s which at first it is consuming without any trouble, but in the morning I noticed a large number in RabbitMQ and an out of memory exception on the consumer. I ran it up again and used the Eclipse Memory Analyzer to determine where this memory was being used. From this I can see that the java.util.concurrent.LinkedBlockingQueue that is referenced by com.rabbitmq.client.QueueingConsumer is growing and growing until it runs out of memory.\n\nDo I need to do anything to tell Rabbit to release resources?\n\nI could increase the heap size but I'm concerned that this is just a short term fix and there might be something in my code that could bite me with a memory leak a few months into production deployment.\n\n========================================\n\nTop Answer:\nThe solution is to set the basicQos - `channel.basicQos(2);`. My channel declaration now looks like this:\n\n```\nConnection connection = RabbitConnection.getConnection();\n Channel channel = connection.createChannel();\n channel.queueDeclare(getQueueName(), false, false, false, null);\n consumer = new QueueingConsumer(channel);\n channel.basicConsume(getQueueName(), true,consumer);\n channel.basicQos(2);\n```\n\nSetting basicQos to 2 means only keep 2 messages in the internal memory. For more information and an interesting discussion on using the CoDel algorithm see http://www.rabbitmq.com/blog/2012/05/11/some-queuing-theory-throughput-latency-and-bandwidth/\n\n========================================\n\nCode:\n```text\nConnection connection = RabbitConnection.getConnection();\nChannel channel = connection.createChannel();\nchannel.queueDeclare(getQueueName(), false, false, false, null);\nconsumer = new QueueingConsumer(channel);\nchannel.basicConsume(getQueueName(), true,consumer);\n```\n\n```text\nDelivery delivery = null;\n T queue = null;\n\n //loop over, continuously retrieving messages\n while(true) {\n\n try {\n delivery = consumer.nextDelivery();\n queue = deserialise(delivery.getBody());\n\n process(queue);\n\n } catch (ShutdownSignalException e) {\n logger.warn(\"Shutodwon signal received.\");\n break;\n } catch (ConsumerCancelledException e) {\n logger.warn(\"Consumer cancelled exception: {}\",e.getMessage());\n break;\n } catch (InterruptedException e) {\n logger.warn(\"Interuption exception: {}\", e);\n break;\n }\n }\n```\n\n```text\npublic T deserialise(byte[] body) {\n Kryo kryo= new Kryo();\n Input input = new Input(body);\n T deserialised = kryo.readObject(input, getQueueClass());\n input.close();\n\n return deserialised;\n}\n```\n\n```text\nConnection connection = RabbitConnection.getConnection();\n Channel channel = connection.createChannel();\n channel.queueDeclare(getQueueName(), false, false, false, null);\n consumer = new QueueingConsumer(channel);\n channel.basicConsume(getQueueName(), false,consumer);\n```\n\n```text\nDelivery delivery = null;\n T queue = null;\n\n //loop over, continuously retrieving messages\n while(true) {\n\n try {\n delivery = consumer.nextDelivery();\n queue = deserialise(delivery.getBody());\n process(queue);\n consumer.getChannel().basicAck(delivery.getEnvelope().getDeliveryTag(), false);\n\n } catch (ShutdownSignalException e) {\n logger.warn(\"Shutodwon signal received.\");\n break;\n } catch (ConsumerCancelledException e) {\n logger.warn(\"Consumer cancelled exception: {}\",e.getMessage());\n break;\n } catch (InterruptedException e) {\n logger.warn(\"Interuption exception: {}\", e);\n break;\n } catch (IOException e) {\n logger.error(\"Could not ack message: {}\",e);\n break;\n }\n }\n```\n\n```text\nchannel.basicConsume(getQueueName(), false,consumer);\n```\n\n```text\nconsumer.getChannel().basicAck(delivery.getEnvelope().getDeliveryTag(), false);\n```\n\n```text\nchannel.basicQos(10);\n```\n\n```text\nConnection connection = RabbitConnection.getConnection();\n Channel channel = connection.createChannel();\n channel.queueDeclare(getQueueName(), false, false, false, null);\n consumer = new QueueingConsumer(channel);\n channel.basicConsume(getQueueName(), true,consumer);\n channel.basicQos(2);\n```\n\n```text\nchannel.basicQos(2);\n```\n\n========================================\n\nComments:\n- It keeps up just fine for a while; at least the first hour I've watched it and the messages are arriving at ~120/s and being consumed straight away. As I ran this overnight, in the morning I had 4.34 million messages unconsumed in Rabbit. So, I re-started my consumer and it consumed at a rate of over 5000/s before running out of memory after consuming approximately 2.7 million messages. It would seem that the consumer can keep up just fine but it is running out of memory because the LinkedBlockingQueue inside the QueueingConsumer is growing too fast.\n- If the queue is growing then the consumer cannot possibly be keeping up with the producer. It is possible the consumer is fast enough to start with but slows down over time.\n- Ah, now I'm wondering if when I see it is consuming it is actually just placing the messages into memory on the LinkedBlockingQueue and that does not mean it is being properly consumed. That might make sense.\n- The only natural way to get a task added to a queue is to remove or take it off that queue.\n- By the way, this is just from me testing out extreme circumstances that should never happen in production. It's unlikely we'd ever get data at the rate I've been testing and certainly not for any length of time.\n- Normally, I would agree that this should be a problem, unless it is the case that the consumer slows over time. i.e. it will just be a matter of time as to when you have a problem. After you restart the consumer appears to be *much* faster which is suspicious.\n- I've added the deserialise code to my question. The deserialise code use Kryo. I've been using the Eclipse Memory Analyzer and 99% of the memory is being consumed by LinkedBlockingQueue which is growing all the time. This is referenced by QueueingConsumer.\n- According to what I just read then if this solves the problem you were not consuming fast enough in your original code and your buffer was growing very large with messages read of the queue but not yet processed. Changing the QOS to 2 means that only 2 messages will be buffered and the queue will buffer the rest. Does your queue not get very large in this case instead of your memory usage?\n- Just been testing this out and the memory is still growing and the queue is not getting larger. It's seems that this isn't doing anything. I don't mind the queue getting large because I can add more consumer and the rate that I'm putting messages on the queue is about 30 times the expected rate. I'm just concerned that if there is a memory leak on the Consumer then I will find out a month into production; probably when I'm on holiday :/\n- I am pretty sure this is a GC problem. Some reference to the data is being held and the memory usage is growing with each incoming message.\n- @robthewolf If I'm remembering this correctly, this solves the memory leak problem by not having all of the messages sent to the consumer where they are stored up in a memory map consuming more and more memory. By setting the channel to auto-ack, only one message at a time is held in the JVM memory, the rest being stored in the Rabbit Queue. As well as resolving the memory leak, this also makes it possible to add more consumers to handle the load and they will pull messages as and when they have finished processing the previous one.\n- you said \"By setting the channel to auto-ack\" did you mean that you set it to not auto-ack","metadata":{"transformedAt":"2026-08-18T18:33:20.164Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":203,"estimatedTokens":2340}}472{"id":"stack-10461808","source":"stackoverflow","questionId":10461808,"title":"How To Load-Distribution in RabbitMQ cluster?","tags":["amazon-ec2","amazon-web-services","rabbitmq","cluster-computing","autoscaling"],"text":"Title: How To Load-Distribution in RabbitMQ cluster?\nTags: amazon-ec2, amazon-web-services, rabbitmq, cluster-computing, autoscaling\nSource: Stack Overflow\n\nQuestion:\nHi I create three RabbitMQ servers running in cluster on EC2\n\nI want to scale out RabbitMQ cluster base on CPU utilization but when I publish message only one server utilizes CPU and other RabbitMQ-server not utilize CPU \n\nso how can i distribute the load across the RabbitMQ cluster\n\n========================================\n\nTop Answer:\nThat is not really true. Check out the documentation on that subject.\n\n Messages published to the queue are replicated to all mirrors. Consumers are connected to the master regardless of which node they connect to, with mirrors dropping messages that have been acknowledged at the master. Queue mirroring therefore enhances availability, but does not distribute load across nodes (all participating nodes each do all the work).\n\n========================================\n\nComments:\n- Hello, scvalex. for \"have multiple queues distributed across the nodes, such that work is distributed somewhat evenly\", does it necessary to add a linux server to run load balancer program for solving the program? Or have to change the application's source code to add \"rabbitmq\" all nodes name information to program for load balance?\n- I'd say \"change the application's source code to add 'rabbitmq' all nodes name information to program for load balance\", but there are some people who have used load balancers with success.\n- Before finding your post, I think rabbitmq is very powerful. But after that, I think it is not automatic as you said. It is not easy to use.","metadata":{"transformedAt":"2026-08-18T18:33:20.164Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":24,"estimatedTokens":415}}473{"id":"stack-47949370","source":"stackoverflow","questionId":47949370,"title":"Is it a good way to run Kafka on Kubernetes?","tags":["redis","rabbitmq","apache-kafka","kubernetes","apache-zookeeper"],"text":"Title: Is it a good way to run Kafka on Kubernetes?\nTags: redis, rabbitmq, apache-kafka, kubernetes, apache-zookeeper\nSource: Stack Overflow\n\nQuestion:\nFor a large online application, use k8s to run it. The scale maybe daily activity user 500,000.\n\nThe application inside k8s need messaging feature - Pub/Sub, there are these options:\n\n- Kafka\n\n- RabbitMQ\n\n- Redis\n\n### Kafka\n\nIt needs zookeeper and good to run on os depends on disk I/O. So if install it into k8s cluster, how? The performance will be worse?\n\nAnd, if keep Kafka outside of the k8s cluster, connect Kafka from application inside the k8s cluster, how about that performance? They are in the different layer, won't be slow?\n\n### RabbitMQ\n\nIt's slow than Kafka, but for a daily activity user 500,000 application, is it good enough? If so, maybe it's a good choice.\n\n### Redis\n\nIt's another option. Maybe the most simple one. But from the internet I got that it will lose message sometimes. If true, that's terrible.\n\nSo, the most important thing is, use Kafka(also with zookeeper) on k8s, good or not in this use case?\n\n========================================\n\nTop Answer:\nFor Kafka, you can find some suggestion here. Kubernetes 1.7+ supports local persistent volume, which may be good for Kafka deployment.\n\n========================================\n\nCode:\n```text\nStatefulSet\n```\n\n========================================\n\nComments:\n- Thank you very much for your answer. As I asked and worried, it the performance the same as use pure OS and on k8s with docker?\n- I think there’s always overhead with kubernetes. I’ve not benchmarked it but I read kubernetes does come with overhead. I would google it. Personally, though, I find it the overhead can’t detract given the convenience.\n- Please don't add the same answer - 1, 2, 3, 4, - to multiple questions. Answer the best one and flag the rest as duplicates. See Is it acceptable to add a duplicate answer to several questions?","metadata":{"transformedAt":"2026-08-18T18:33:20.164Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":49,"estimatedTokens":487}}474{"id":"stack-17163252","source":"stackoverflow","questionId":17163252,"title":"Are there disadvantages of using channel.Get() over channel.Consume()?","tags":["go","rabbitmq","amqp"],"text":"Title: Are there disadvantages of using channel.Get() over channel.Consume()?\nTags: go, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI'm using streadway's amqp library to connect with a rabbitmq server. \nThe library provides a channel.Consume() function which returns a \"**I've to implement a **pop()** functionality, and I'm using **channel.Get()**. However, the documentation says:\n\n```\n\"In almost all cases, using Channel.Consume will be preferred.\"\n```\n\nDoes the *preferred* here means *recommended*? Are there any disadvantages of using channel.Get() over channel.Consume()? If yes, how do I use channel.Consume() to implement a Pop() function?\n\n========================================\n\nTop Answer:\nIt really depend of what are you trying to do. If you want to get only one message from queue (first one) you probably should use `basic.get`, if you are planning to process all incoming messages from queue - `basic.consume` is what you want.\n\nProbably, it is not platform or library specific question but rather protocol understanding question. \n\n**UPD**\n\nI'm not familiar with it go language well, so I will try to give you some brief on AMQP details and describe use cases.\n\nYou may get in troubles and have an overhead with `basic.consume` sometimes:\n\n**With `basic.consume` you have such workflow:**\n\nSend `basic.consume` method to notify broker that you want to receive messages\n\n- while this is a synchronous method, wait for `basic.consume-ok` message from broker\n\nStart listening to `basic.deliver` message from server\n\n- this is an asynchronous method and you should take care by yourself situations where no messages on server available, e.g. limit reading time\n\n**With `basic.get` you have such workflow:**\n\nsend synchronous method `basic.get` to broker\n\n- wait for `basic.get-ok` method, which hold message(s) or `basic.empty` method, which denote situation no message available on server\n\n*Note about synchronous and asynchronous methods:* synchronous is expected to have some response, whether asynchronous doesn't\n\n*Note on `basic.qos` method `prefetch-count` property:* it is ignored when `no-ack` property is set on `basic.consume` or `basic.get`.\n\nSpec has a note on `basic.get`: \"this method provides a direct access to the messages in a queue using a synchronous dialogue that is designed for specific types of application where synchronous functionality is more important than performance\" which applies for continuous messages consumption.\n\nMy personal tests show that getting in row 1000 messages with `basic.get` (0.38659715652466) is faster than getting 1000 messages with `basic.consume` one by one (0.47398710250854) on RabbitMQ 3.0.1, Erlang R14B04 in average more than 15%.\n\nIf consume only one message in main thread is your case - probably you have to use `basic.get`. \n\nYou still can consume only one message asynchronously, for example in separate thread or use some event mechanism. It would be better solution for you machine resource sometimes, but you have to take care about situation where no message available in queue.\n\nIf you have to process message one by one it is obvious that `basic.consume` should be used, I think\n\n========================================\n\nCode:\n```text\n\"In almost all cases, using Channel.Consume will be preferred.\"\n```\n\n```text\nfunc handle(deliveries <-chan amqp.Delivery, done chan error) {\n select {\n case d = <-deliveries:\n // Do stuff with the delivery\n // Send any errors down the done chan. for example:\n // done <- err\n default:\n done <- nil\n }\n}\n```\n\n```text\nchannel.Get()\n```\n\n```text\nchannel.Consume()\n```\n\n```text\nchan\n```\n\n```text\nDelivery\n```\n\n```text\nDelivery\n```\n\n```text\nexclusive\n```\n\n```text\nnoLocal\n```\n\n```text\nnoWait\n```\n\n```text\nTable\n```\n\n```text\nPop()\n```\n\n```text\nchannel.Consume()\n```\n\n```text\nConsume()\n```\n\n```text\nchan\n```\n\n```text\nDelivery\n```\n\n```text\nPop()\n```\n\n```text\nhandle()\n```\n\n```text\ngoroutine\n```\n\n```text\nhandle()\n```\n\n```text\nrange\n```\n\n```text\nPop()\n```\n\n```text\nchan\n```\n\n```text\nDelivery\n```\n\n```text\nDelivery\n```\n\n```text\nchan\n```\n\n```text\nbasic.get\n```\n\n```text\nbasic.consume\n```\n\n```text\nbasic.consume\n```\n\n```text\nbasic.consume\n```\n\n```text\nbasic.consume\n```\n\n```text\nbasic.consume-ok\n```\n\n```text\nbasic.deliver\n```\n\n```text\nbasic.get\n```\n\n```text\nbasic.get\n```\n\n```text\nbasic.get-ok\n```\n\n```text\nbasic.empty\n```\n\n```text\nbasic.qos\n```\n\n```text\nprefetch-count\n```\n\n```text\nno-ack\n```\n\n```text\nbasic.consume\n```\n\n```text\nbasic.get\n```\n\n```text\nbasic.get\n```\n\n```text\nbasic.get\n```\n\n```text\nbasic.consume\n```\n\n```text\nbasic.get\n```\n\n```text\nbasic.consume\n```\n\n========================================\n\nComments:\n- thanks a lot for your reply! however, your last line is the exact problem I'm facing. I tried to make a Pop() by using range over the Delivery channel, but returning as soon as a value is found. Of-course that returned the most recent value but also popped out all the other values from the queue in background, and so I moved to channel.Get(). I'm new to channels and goroutines. How can I implement this function to receive the latest value from the chan?\n- does Rabbitmq .get works in round-robin manner in case we have multiple consumers or does it atleast guarantee that message is received by only one consumer\n- What I'm trying to do is exactly what basic.Get() does, but my question was whether the \"preferred\" in docs mean \"recommended\", i.e., even if I'm well off using Get(), do the docs still recommend that I should use Consume() and not Get() (as there might be some disadvantages in the way Get itself is implemented etc.)?","metadata":{"transformedAt":"2026-08-18T18:33:20.164Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":47,"totalLines":263,"estimatedTokens":1405}}475{"id":"stack-8296201","source":"stackoverflow","questionId":8296201,"title":"when does an AMQP/RabbitMQ channel with no connections die?","tags":["java","message-queue","rabbitmq","amqp","spring-amqp"],"text":"Title: when does an AMQP/RabbitMQ channel with no connections die?\nTags: java, message-queue, rabbitmq, amqp, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI have a simple RabbitMQ test program randomly enqueuing messages, and another reading them, all using Spring-AMQP. If the consumer dies (for example killing a process without having a chance to close its connection or channel), any messages that it had not acknowledged appear to remain unacknowledged forever.\n\nI have seen a number of references (for example this question) that say that the channel dies when it has no connections, and that remaining unack'd messages will be redelivered. That's not the behaviour I see - instead I get a growing list of channels marked IDLE and a growing list of connections marked running but with no activity.\n\nIs there some configuration required to notice that connections are dead once the process has been killed?\n\n**EDIT:**\nI was running the rabbitmq server inside a VirtualBox VM, which apparently doesn't manage dead inbound connections correctly over NAT. This works just fine with the mq server running directly on the physical host.\n\n========================================\n\nTop Answer:\nAMQP uses Queues and Exchanges. You publish on an exchange and you bind queues to get messages from exchanges (you can see a short explanation on my blog. When you create a queue you can set it to auto-delete as well as how much time will it stay unused before it auto deletes.\nHere's a quote from the RabbitMQ quickref:\n\n queue.declare(short reserved-1, queue-name queue, bit passive, bit\n durable, bit exclusive, **bit auto-delete**, no-wait no-wait, table\n arguments) ➔ declare-ok\n\n \n Support: full Declare queue, create if needed.\n\n \n This method creates or checks a queue. When creating a new queue the\n client can specify various properties that control the durability of\n the queue and its contents, and the level of sharing for the queue.\n\n \n RabbitMQ implements extensions to the AMQP specification that permits\n the creator of a queue to control various aspects of its behaviour.\n\n \n Per-Queue Message TTL This extension determines for how long a message\n published to a queue can live before it is discarded by the server.\n The time-to-live is configured with the x-message-ttl argument to the\n arguments parameter of this method.\n\n \n **Queue Expiry** Queues can be declared with an optional lease time. The\n lease time determines how long a queue can remain unused before it is\n automatically deleted by the server. The lease time is provided as an\n x-expires argument in the arguments parameter to this method.\n\n \n Mirrored Queues We have developed active/active high availability for\n queues. This works by allowing queues to be mirrored on other nodes\n within a RabbitMQ cluster. The result is that should one node of a\n cluster fail, the queue can automatically switch to one of the mirrors\n and continue to operate, with no unavailability of service. To create\n a mirrored queue, you provide an x-ha-policy argument in the arguments\n parameter to this method.\n\n========================================\n\nComments:\n- FYI: I was having a similar problem where exclusive queues were not being cleaned up on the broker in a timely manner after the exclusive consumer dies. This prevented these components with deterministic names from starting. It was solved by setting `ConnectionFactory.RequestedHeartbeat` to a small value (seconds)\n- I don't want the queue to be deleted, I want it to be persistent. But I also want the unacknowledged messages (consumed by processes that died before acknowledging) to be redelivered. It's the dead connections/channels that need deleting, not messages.\n- ok now I got you - you need to create ConnectionParameters instance and set a heartbeat (setRequestedHeardbeat) to a reasonable value (1 heartbeat miss will close the channel) Then pass that to the ConnectionFactory constructor\n- @Arnon Rotem-Gal-Oz, setting `RequestedHeartbeat` solved my similar problem which was manifesting by exclusive queues not being cleaned up on the broker in a timely manner. This prevented components which declare exclusive queues with deterministic names from starting.\n- @drstevens right- that's pretty much the same issue. The broker needs to know that clients are gone to release resources","metadata":{"transformedAt":"2026-08-18T18:33:20.164Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":65,"estimatedTokens":1080}}476{"id":"stack-3379332","source":"stackoverflow","questionId":3379332,"title":"Workaround for celery task priority on RabbitMQ?","tags":["rabbitmq","celery"],"text":"Title: Workaround for celery task priority on RabbitMQ?\nTags: rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI am running Django with Celery on top of RabbitMQ as a queue to handle some data processing tasks. I am kicking off celery tasks when a user first signs up, as well as periodically to update their data. However, I'd like to of course give priority to the tasks running users who are currently online. I noticed there was a priority setting for tasks in celery, but it seems that rabbitmq does not support this. This thread http://groups.google.com/group/celery-users/browse_thread/thread/ac3b6123d63421e5/b7740def1389e87e?lnk=gst&q=priority#b7740def1389e87e suggests have two different queues, a high priority one and a low priority one, or setting a rate limit for lower priority tasks. \n\nDoes anyone have a good workaround to implement priority? Thanks in advance!\n\n========================================\n\nTop Answer:\nApart from this, you can push urgent tasks to some queue (let's say urgent-queue) and set consumer priorities, i.e, let all consumers pick up task from urgent-queue with high priority.\n\nhttps://github.com/celery/celery/issues/3098\n\nAt consumer end, you can define x-priority argument in queues to consume from. In the below example, consumer picks up tasks from celery queue with priority 0 and from hipri with priority 10.\n\nExample:\n\n```\nCELERY_QUEUES = (\n Queue('celery', Exchange('celery', type='direct'), routing_key='celery',\n consumer_arguments={'x-priority': 0}),\n Queue('hipri', Exchange('hipri', type='direct'), routing_key='hipri',\n consumer_arguments={'x-priority': 10}),\n)\n```\n\n========================================\n\nCode:\n```text\nCELERY_QUEUES = (\n Queue('celery', Exchange('celery', type='direct'), routing_key='celery',\n consumer_arguments={'x-priority': 0}),\n Queue('hipri', Exchange('hipri', type='direct'), routing_key='hipri',\n consumer_arguments={'x-priority': 10}),\n)\n```\n\n========================================\n\nComments:\n- Check this question & answers.","metadata":{"transformedAt":"2026-08-18T18:33:20.164Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":45,"estimatedTokens":511}}477{"id":"stack-43009597","source":"stackoverflow","questionId":43009597,"title":"Spring AMQP (Rabbit) Listener goes in a loop in case of exception","tags":["java","spring","rabbitmq","spring-amqp"],"text":"Title: Spring AMQP (Rabbit) Listener goes in a loop in case of exception\nTags: java, spring, rabbitmq, spring-amqp\nSource: Stack Overflow\n\nQuestion:\n```\n@Bean\nRabbitTemplate rabbitTemplate() {\n RabbitTemplate template = new RabbitTemplate(rabbitConnectionFactory());\n template.setMessageConverter(messageConverter);\n template.setExchange(amqpProperties.getRabbitMqTopicExchangeName());\n return template;\n}\n\n@Bean\n@Conditional (OperationsCondition.class)\n SimpleMessageListenerContainer opsMessageListenerContainer() {\n return listenerContainer(amqpProperties.getRabbitMqOperationsQueue(), \n amqpProperties.getInitialRabbitOperationsConsumerCount(), \n amqpProperties.getMaximumRabbitOperationsConsumerCount(),\n opsReceiver());\n}\n\n@Bean\n@Conditional (OperationsCondition.class)\nOperationsListener opsReceiver() {\n return new OperationsListener();\n}\n\nprivate SimpleMessageListenerContainer listenerContainer(String queue,\n int initConsumers,int maxConsumers, MessageListener listener)\n{\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(rabbitConnectionFactory());\n container.setQueueNames(queue);\n container.setMessageListener(listener);\n container.setConcurrentConsumers(initConsumers);\n container.setMaxConcurrentConsumers(maxConsumers);\n container.setMessageConverter(messageConverter);\n return container;\n}\n```\n\nMessage listener is:\n\n```\npublic class OperationsListener implements MessageListener\n{\n public static final Logger logger = Logger.getInstance(OperationsListener.class);\n\n @Autowired (required=true)\n private OperationsProcessor processor;\n @Autowired (required=true)\n private ObjectMapper objectMapper;\n\n public void onMessage(Message message)\n {\n Jackson2JsonMessageConverter converter = new Jackson2JsonMessageConverter(); \n converter.setJsonObjectMapper(objectMapper);\n OperationsMessage request = (OperationsMessage)converter.fromMessage(message);\n processor.createMessage(request);\n //This is throwing a JPA database exception\n processor.createOperation(request);\n }\n}\n```\n\nprocessor.createOperation() is throwing an exception due to database issue. Problem is that message listener is going in a loop and message keeps coming back. \n\nMy processor class:\n\n```\n@Component\n@Transactional (propagation = Propagation.REQUIRES_NEW) \npublic class OperationsProcessor\n{\n...............\n\n public void createOperation(OperationsMessage message)\n {\n try\n {\n .............\n .............\n //this call throws exception.\n opsRepo.create(operation,null);\n }\n catch (Exception e)\n {\n logger.error(e);\n }\n\n }\n}\n```\n\nopsRepo.create throws an exception. Even though i am catching error, i was hoping that message doesn't gets sent again by spring amqp. Not sure why same message keeps coming back. \n\nEDIT:\n\nI think i found some pointers on how to deal with this. The cause is that spring is requeing events upon failure and this is the default nature. \nFound an helpful thread here and here.\n\n========================================\n\nCode:\n```text\n@Bean\nRabbitTemplate rabbitTemplate() {\n RabbitTemplate template = new RabbitTemplate(rabbitConnectionFactory());\n template.setMessageConverter(messageConverter);\n template.setExchange(amqpProperties.getRabbitMqTopicExchangeName());\n return template;\n}\n\n@Bean\n@Conditional (OperationsCondition.class)\n SimpleMessageListenerContainer opsMessageListenerContainer() {\n return listenerContainer(amqpProperties.getRabbitMqOperationsQueue(), \n amqpProperties.getInitialRabbitOperationsConsumerCount(), \n amqpProperties.getMaximumRabbitOperationsConsumerCount(),\n opsReceiver());\n}\n\n@Bean\n@Conditional (OperationsCondition.class)\nOperationsListener opsReceiver() {\n return new OperationsListener();\n}\n\nprivate SimpleMessageListenerContainer listenerContainer(String queue,\n int initConsumers,int maxConsumers, MessageListener listener)\n{\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(rabbitConnectionFactory());\n container.setQueueNames(queue);\n container.setMessageListener(listener);\n container.setConcurrentConsumers(initConsumers);\n container.setMaxConcurrentConsumers(maxConsumers);\n container.setMessageConverter(messageConverter);\n return container;\n}\n```\n\n```text\npublic class OperationsListener implements MessageListener\n{\n public static final Logger logger = Logger.getInstance(OperationsListener.class);\n\n @Autowired (required=true)\n private OperationsProcessor processor;\n @Autowired (required=true)\n private ObjectMapper objectMapper;\n\n public void onMessage(Message message)\n {\n Jackson2JsonMessageConverter converter = new Jackson2JsonMessageConverter(); \n converter.setJsonObjectMapper(objectMapper);\n OperationsMessage request = (OperationsMessage)converter.fromMessage(message);\n processor.createMessage(request);\n //This is throwing a JPA database exception\n processor.createOperation(request);\n }\n}\n```\n\n```text\n@Component\n@Transactional (propagation = Propagation.REQUIRES_NEW) \npublic class OperationsProcessor\n{\n...............\n\n public void createOperation(OperationsMessage message)\n {\n try\n {\n .............\n .............\n //this call throws exception.\n opsRepo.create(operation,null);\n }\n catch (Exception e)\n {\n logger.error(e);\n }\n\n }\n}\n```\n\n========================================\n\nComments:\n- True. I thought i read entire document few months back. I guess i missed important sections. Thank you for the link. I am throwing AmqpRejectAndDontRequeueException in case of any exceptions in the listener. This way error is logged as well as message is not retried. Works for now.","metadata":{"transformedAt":"2026-08-18T18:33:20.164Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":195,"estimatedTokens":1473}}478{"id":"stack-27778156","source":"stackoverflow","questionId":27778156,"title":"amqp.node won't detect a connection drop","tags":["node.js","amazon-web-services","socket.io","rabbitmq","node-amqp"],"text":"Title: amqp.node won't detect a connection drop\nTags: node.js, amazon-web-services, socket.io, rabbitmq, node-amqp\nSource: Stack Overflow\n\nQuestion:\nWe have a node.js script running a socket.io server whose clients consume messages from a RabbitMQ queue. We've recently migrated to Amazon AWS and RabbitMQ is now a cluster of two machines (redundant instances). The AMQP connection is lost from time to time (it is a limitation that arrives from a high availability environment with redundant VMs and we have to cope with it) and if an attempt to reconnect is made, the DNS chooses which instance to connect to (it is a cluster with data replication so it doesn't matter which instance to connect to).\n\nThe problem is that the attempt to reconnect is never made; after a while, when the connection is lost, amqp.node apparently fails to notice that the connection has been lost. Also, the consumers stop receiving messages and the socket.io server simply stops accepting new connections.\n\nWe have a 55 seconds heartbeat timeout (not to be confused with the socket.io heartbeat timeout) set at the RabbitMQ URL and are checking for 'error' and 'close' events with amqp.node's callback API but they are apparently never issued. The queues expect the consumed messages to be ack'ed. We want the node script to detect a lost connection and finish itself, so the environment will automatically start a new process and establish a connection again.\n\nHere is the code, maybe we are doing something wrong with the amqp.node callback API or something else.\n\n```\nvar express = require('express');\napp = express();\nvar http = require('http');\nvar serverio = http.createServer(app);\nvar io = require('socket.io').listen(serverio, { log: false });\nvar socket;\nvar allcli = [];\nvar red, blue, green, magenta, reset;\nred = '\\033[31m';\nblue = '\\033[34m';\ngreen = '\\033[32m';\nmagenta = '\\033[35m';\norange = '\\033[43m';\nreset = '\\033[0m';\n\nvar queue = 'ha.atualizacao_mobile';\nvar urlRabbit = 'amqp://login:password@host?heartbeat=55' // Amazon\nvar amqp = require('amqplib/callback_api');\nvar debug = true;\n\nconsole.log(\"Original Socket.IO heartbeat interval: \" + io.get('heartbeat interval') + \" seconds.\");\nio.set('heartbeat interval', 10 * 60);\nconsole.log(\"Hearbeat interval changed to \" + io.get('heartbeat interval') + \" seconds to reduce battery consumption in the mobile clients.\");\n\nconsole.log(\"Original Socket.IO heartbeat timeout: \" + io.get('heartbeat timeout') + \" seconds.\");\nio.set('heartbeat timeout', 11 * 60);\nconsole.log(\"Heartbeat timeout set to \" + io.get('heartbeat timeout') + \" seconds.\");\n\nio.sockets.on('connection', function(socket){\n\n socket.on('error', function (exc) {\n console.log(orange+\"Ignoring exception: \" + exc + reset);\n });\n\n socket.on('send-indice', function (data) {\n // Some business logic\n });\n\n socket.on('disconnect', function () {\n // Some business logic\n });\n\n}); \n\nfunction updatecli(data){\n // Some business logic\n}\n\namqp.connect(urlRabbit, null, function(err, conn) {\n if (err !== null) {\n return console.log(\"Error creating connection: \" + err);\n }\n\n conn.on('error', function(err) {\n console.log(\"Generated event 'error': \" + err);\n });\n\n conn.on('close', function() {\n console.log(\"Connection closed.\");\n process.exit();\n });\n\n processRabbitConnection(conn, function() {\n conn.close();\n });\n});\n\nfunction processRabbitConnection(conn, finalize) {\n conn.createChannel(function(err, channel) {\n\n if (err != null) {\n console.log(\"Error creating channel: \" + err);\n return finalize();\n }\n\n channel.assertQueue(queue, null, function(err, ok) {\n if (err !== null) {\n console.log(\"Error asserting queue \" + queue + \": \" + err);\n return finalize();\n }\n\n channel.consume(queue, function (msg) {\n if (msg !== null) {\n try {\n var dataObj = JSON.parse(msg.content);\n if (debug == true) {\n //console.log(dataObj);\n }\n updatecli(dataObj);\n } catch(err) {\n console.log(\"Error in JSON: \" + err);\n }\n channel.ack(msg);\n }\n }, null, function(err, ok) {\n if (err !== null) {\n console.log(\"Error consuming message: \" + err);\n return finalize();\n }\n });\n });\n });\n}\n\nserverio.listen(9128, function () {\n console.log('Server: Socket IO Online - Port: 9128 - ' + new Date());\n});\n```\n\n========================================\n\nCode:\n```text\nvar express = require('express');\napp = express();\nvar http = require('http');\nvar serverio = http.createServer(app);\nvar io = require('socket.io').listen(serverio, { log: false });\nvar socket;\nvar allcli = [];\nvar red, blue, green, magenta, reset;\nred = '\\033[31m';\nblue = '\\033[34m';\ngreen = '\\033[32m';\nmagenta = '\\033[35m';\norange = '\\033[43m';\nreset = '\\033[0m';\n\nvar queue = 'ha.atualizacao_mobile';\nvar urlRabbit = 'amqp://login:password@host?heartbeat=55' // Amazon\nvar amqp = require('amqplib/callback_api');\nvar debug = true;\n\nconsole.log(\"Original Socket.IO heartbeat interval: \" + io.get('heartbeat interval') + \" seconds.\");\nio.set('heartbeat interval', 10 * 60);\nconsole.log(\"Hearbeat interval changed to \" + io.get('heartbeat interval') + \" seconds to reduce battery consumption in the mobile clients.\");\n\nconsole.log(\"Original Socket.IO heartbeat timeout: \" + io.get('heartbeat timeout') + \" seconds.\");\nio.set('heartbeat timeout', 11 * 60);\nconsole.log(\"Heartbeat timeout set to \" + io.get('heartbeat timeout') + \" seconds.\");\n\n\nio.sockets.on('connection', function(socket){\n\n socket.on('error', function (exc) {\n console.log(orange+\"Ignoring exception: \" + exc + reset);\n });\n\n socket.on('send-indice', function (data) {\n // Some business logic\n });\n\n socket.on('disconnect', function () {\n // Some business logic\n });\n\n}); \n\nfunction updatecli(data){\n // Some business logic\n}\n\namqp.connect(urlRabbit, null, function(err, conn) {\n if (err !== null) {\n return console.log(\"Error creating connection: \" + err);\n }\n\n conn.on('error', function(err) {\n console.log(\"Generated event 'error': \" + err);\n });\n\n conn.on('close', function() {\n console.log(\"Connection closed.\");\n process.exit();\n });\n\n processRabbitConnection(conn, function() {\n conn.close();\n });\n});\n\nfunction processRabbitConnection(conn, finalize) {\n conn.createChannel(function(err, channel) {\n\n if (err != null) {\n console.log(\"Error creating channel: \" + err);\n return finalize();\n }\n\n channel.assertQueue(queue, null, function(err, ok) {\n if (err !== null) {\n console.log(\"Error asserting queue \" + queue + \": \" + err);\n return finalize();\n }\n\n channel.consume(queue, function (msg) {\n if (msg !== null) {\n try {\n var dataObj = JSON.parse(msg.content);\n if (debug == true) {\n //console.log(dataObj);\n }\n updatecli(dataObj);\n } catch(err) {\n console.log(\"Error in JSON: \" + err);\n }\n channel.ack(msg);\n }\n }, null, function(err, ok) {\n if (err !== null) {\n console.log(\"Error consuming message: \" + err);\n return finalize();\n }\n });\n });\n });\n}\n\nserverio.listen(9128, function () {\n console.log('Server: Socket IO Online - Port: 9128 - ' + new Date());\n});\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.165Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":236,"estimatedTokens":1868}}479{"id":"stack-40404642","source":"stackoverflow","questionId":40404642,"title":"Unable to connect to local RabbitMQ on Windows 10","tags":["rabbitmq"],"text":"Title: Unable to connect to local RabbitMQ on Windows 10\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI've installed RabbitMQ (latest version downloadable from RabbitMQ website) on my Windows 10 machine. It installed with ERlang 19.1.\n\nI'm trying to install RabbitMQ Web UI Management Tools using the following command (using RabbitMQ Command Prompt):\n\n```\nrabbitmq-plugins enable rabbitmq_management\n```\n\nI'm getting the following error:\n\n```\nThe directory name is invalid.\nThe filename, directory name, or volume label syntax is incorrect.\nThe filename, directory name, or volume label syntax is incorrect. \nPlugin configuration unchanged.\n\nApplying plugin configuration to rabbit@[0x7FF9A8527044]... failed.\n * Could not contact node rabbit@[0x7FF9A8527044].\n Changes will take effect at broker restart.\n * Options: --online - fail if broker cannot be contacted.\n --offline - do not try to contact broker.\n```\n\nI've looked up on SO and tried stopping and restarting, overriding erlang cookie, but nothing helps.\n\nI think there's a problem with RabbitMQ itself. The service itself is marked as started, but if I try to telnet the default port (5672) then it fails (it's not a firewall issue - I've disabled it).\n\nAlso I don't see an log files created for RabbitMQ or any related Event Logs messages. So it's hard to diagnose exactly the problem.\n\nI also tried uninstalling and re-install both erlang and RabbitMQ. Still didn't help.\n\nHow do I further diagnose the problem?\n\n========================================\n\nTop Answer:\nyou may be running into issues with Erlang 19 incompatibility. there has been some history of Erlang 19 support problems with RMQ. Try installing Erlang 18 instead.\n\nIf that fails, I would recommend using Docker for Windows and installing / running RabbitMQ in that. I've moved all my services like RabbitMQ, MongoDB, etc. into Docker containers and it's made my life as a dev so much simpler.\n\n========================================\n\nCode:\n```text\nrabbitmq-plugins enable rabbitmq_management\n```\n\n```text\nThe directory name is invalid.\nThe filename, directory name, or volume label syntax is incorrect.\nThe filename, directory name, or volume label syntax is incorrect. \nPlugin configuration unchanged.\n\nApplying plugin configuration to rabbit@[0x7FF9A8527044]... failed.\n * Could not contact node rabbit@[0x7FF9A8527044].\n Changes will take effect at broker restart.\n * Options: --online - fail if broker cannot be contacted.\n --offline - do not try to contact broker.\n```\n\n```text\nApplying plugin configuration to rabbit@[0x7FF9A8527044]... failed.\n```\n\n```text\nrabbitmqctl.bat status\n```\n\n```text\n[0x7FF9A8527044]\n```\n\n```text\nrabbit@my-mchine-name\n```\n\n```text\nRABBITMQ_NODENAME\n```\n\n```text\nrabbit@localhost\n```\n\n```text\n%APPDATA%\\RabbitMQ\\\n```\n\n========================================\n\nComments:\n- exactly what I wanted to write +1\n- I've installed `Erlang/OTP 18 [erts-7.3] [64-bit] [smp:4:4] [async-threads:10]` but still the exactly same results as I encountered in above question.","metadata":{"transformedAt":"2026-08-18T18:33:20.165Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":98,"estimatedTokens":763}}480{"id":"stack-50098316","source":"stackoverflow","questionId":50098316,"title":"How to check whether the connection is alive or not in RabbitMq node-amqplib library?","tags":["javascript","node.js","rabbitmq","node-amqplib"],"text":"Title: How to check whether the connection is alive or not in RabbitMq node-amqplib library?\nTags: javascript, node.js, rabbitmq, node-amqplib\nSource: Stack Overflow\n\nQuestion:\nI am writing producer & consumer using rabbitMq node-amqplib library, I am afraid about suddenly to lost connection of server , How could I check whether the connection is alive or not ?\n\n========================================\n\nTop Answer:\nThere are some options in doing this:\n\nOne way is using the heartbeat and an event listener, something like\n`conn.on('close', (err) => { this.connected = false; } )`\n\nOr you can get into the connection object. There is a risk here as upgrades to amqplib may break this, as it's not part of the official interface:\n`const connClosed = conn.connection['expectSocketClose']`\n\nThere are other properties inside the connection object that also can tell you if it's closed, like stream writeable state (could be a false flag) or the heartbeater object.\n\n========================================\n\nCode:\n```text\nconnect([url, [socketOptions]])\n```\n\n```text\nconn.on('close', (err) => { this.connected = false; } )\n```\n\n```text\nconst connClosed = conn.connection['expectSocketClose']\n```\n\n========================================\n\nComments:\n- Connect with RabbitMQ Web UI Server. You can achieve this with the plugin. This might help: rabbitmq.com/management.html There you can see bindings between producer & consumer.\n- Thank you so much for your prompt reply ,,kindly mention one more thing , could I keep connection alive with server by using heartbeat or by any other exclusive way that I can implement?\n- You can only keep the connection alive using heartbeats (it is the way RabbitMQ works). Note that every message you send or receive also count as a heartbeat. So if you send arbitrary messages, the connection will be kept alive.","metadata":{"transformedAt":"2026-08-18T18:33:20.165Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":41,"estimatedTokens":462}}481{"id":"stack-44464884","source":"stackoverflow","questionId":44464884,"title":"RabbitMQ how to split jobs to tasks and handle results","tags":["java","spring","rabbitmq","spring-rabbit"],"text":"Title: RabbitMQ how to split jobs to tasks and handle results\nTags: java, spring, rabbitmq, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI have the following use case on a Spring-based Web application:\n\n- I need to apply the Competing Consumers EIP with the following twists: the messages in the queue are actually split tasks belonging to the same job. Therefore, I need to properly track when all tasks of a job get completed and their completion status in order to save the scenario either as COMPLETED or FAILED, log the outcome and notify by e.g. e-mail the users accordingly\n\nSo, given the requirements I described above, my question is:\n\n- Can this be done with RabbitMQ and if yes how?\n\n========================================\n\nTop Answer:\nWhat you are trying to do is beyond the scope of RabbitMQ. RabbitMQ is for sending and receiving messages with ability to queue them.\nIt can't track your job tasks for you. \n\nYou will need to have a \"Job Storage\" service. Whenever your consumer finishes the task, its updates the Job Storage service, marking task as done. Job storage service knows about how many tasks are in the job, and when last task is done, completes jobs as succeeded. There in this service, you will also implement all your other business logic, such as when to treat job as failed.\n\n========================================\n\nComments:\n- In that case I would simply put a unique ID per job, attach this ID to every message in the queue related to the job, put a status flag on each task as \"In Progress\", and on the last one \"Completed\". You just have to define what \"Fail\" means and implement the rules accordingly\n- @asettouf - if I the \"Competing Consumers\" pattern a.k.a \" Work Queues\" rabbitmq.com/tutorials/tutorial-two-java.html, the tasks of the job will be executed in parallel and this it what I need. So, taking this into consideration I don't see how your proposal can work\n- By the way, if someone's answer solved your problem, you might want to accept it as the answer using the big checkbox. It helps keep the focus on unanswered questions on Stackoverflow.\n- Of course there will be need for implementing services. However after further research, I see that by combining \"Work Queue\" with \"Request-Reply\" patter and of course with some services I can approach a solution. See for example: blog.zenika.com/2012/03/15/pdf-workers-with-rabbitmq\n- If something needs to happen on publisher side after consumer processed the message, yes consumer can send response back to publisher.\n- thanks for the feedback. I will try to evaluate as soon as possible, seems like a useful answer that can be accepted.\n- @kmandalas No problem, let me know if you want the full project, though the pom.xml is pretty straightforward. Also keep in mind that I did not try to improve or make it as efficient as possible, please take it more as a proof of concept\n- I think your idea is a logical PoC. Now, I try to link it with what I had discovered on this site: blog.zenika.com/2012/03/15/pdf-workers-with-rabbitmq since I am using Spring and associated frameworks.","metadata":{"transformedAt":"2026-08-18T18:33:20.165Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":32,"estimatedTokens":772}}482{"id":"stack-26229031","source":"stackoverflow","questionId":26229031,"title":"AMQP Connection Closed certain time interval with node js","tags":["node.js","rabbitmq","amqp"],"text":"Title: AMQP Connection Closed certain time interval with node js\nTags: node.js, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI tried out last 3 days with the below issue. Kindly help me to resolve the issue,\n\n```\n>Error: Unexpected close\nat succeed (/usr/local/lib/node_modules/amqplib/lib/connection.js:259:13)\nat onOpenOk (/usr/local/lib/node_modules/amqplib/lib/connection.js:241:5)\nat /usr/local/lib/node_modules/amqplib/lib/connection.js:160:32\nat /usr/local/lib/node_modules/amqplib/lib/connection.js:154:12\nat Socket.recv (/usr/local/lib/node_modules/amqplib/lib/connection.js:480:12)\nat Socket.g (events.js:180:16)\nat Socket.EventEmitter.emit (events.js:92:17)\nat emitReadable_ (_stream_readable.js:407:10)\nat emitReadable (_stream_readable.js:403:5)\nat readableAddChunk (_stream_readable.js:165:9)\n```\n\nI am using amqplib + node js. Whenever i started the server i got the above error with a time interval. Maximum it will occurs at 5 mins interval.\n\n```\namqplib = amqplib.connect('amqp://'+rabit_host).then(function(conn)\n{\n amqpconnection = conn;\n});\n\nio.sockets.on('connection', function(client)\n{ \n client.on('receivemsg', function(arg)\n {\n amqpconnection.createConfirmChannel().then(function(channelObjSuccess)\n {\n channelObjSuccess.assertQueue(queue_name,{durable:false,autoDelete:true});\n client.assignObj = channelObjSuccess;\n channelObjSuccess.consume(queue_name, function(msg)\n {\n var encodemsg = msg.content.toString();\n var json_msg = JSON.parse(encodemsg); \n client.emit('chatrecive',json_msg);\n }).then(function(){\n console.log(\"Receive Consiuume Close\");\n }); \n });\n });\n\nclient.on('loginentry', function(arg)\n{\n amqpconnection.createConfirmChannel().then(function(channelObjSuccess) {\n channelObjSuccess.assertQueue(queue_name,{durable:false,autoDelete:true});\n }); \n});\n\nclient.on('sendmsg', function(arg)\n{ \n var payload_stringify = JSON.stringify(arg); \n amqpconnection.createConfirmChannel().then(function(channelObjSuccess) {\n channelObjSuccess.assertQueue(queue_name,{durable:false,autoDelete:true});\n channelObjSuccess.sendToQueue(queue_name, new Buffer(payload_stringify), {},\n function(err, ok) \n {\n if (err !== null)\n console.log('Message Send Failure! ');\n else\n {\n channelObjSuccess.close();\n }\n });\n });\n}); \n\nclient.on('disconnect', function()\n{ \n try {\n console.log(\"AMPQ Connection Closed - Disconnect\");\n if(typeof(client.assignObj)!=undefined)\n {\n client.assignObj.close();\n } \n }\n catch (alreadyClosed) {\n console.log(\"RabbitMQ Connection Already Closed \" + alreadyClosed.stackAtStateChange);\n }\n }); \n});\n\nserver.listen(port);\n```\n\n========================================\n\nTop Answer:\nI'm also touched by this error.\n\nDigging a bit, i have set `?heartbeat=0` in the client url and set `heartbeat=0` in the server configuration.\n\nwhen `console.log(connection)` i can see the heartbeat value to `0`, yet the thread hangs exactly 30s from the moment i call `await channel.close()` to termination of the thread.\n\ni've still no clue why but i'd like to remove this overhead.\n\n========================================\n\nCode:\n```text\n>Error: Unexpected close\nat succeed (/usr/local/lib/node_modules/amqplib/lib/connection.js:259:13)\nat onOpenOk (/usr/local/lib/node_modules/amqplib/lib/connection.js:241:5)\nat /usr/local/lib/node_modules/amqplib/lib/connection.js:160:32\nat /usr/local/lib/node_modules/amqplib/lib/connection.js:154:12\nat Socket.recv (/usr/local/lib/node_modules/amqplib/lib/connection.js:480:12)\nat Socket.g (events.js:180:16)\nat Socket.EventEmitter.emit (events.js:92:17)\nat emitReadable_ (_stream_readable.js:407:10)\nat emitReadable (_stream_readable.js:403:5)\nat readableAddChunk (_stream_readable.js:165:9)\n```\n\n```text\namqplib = amqplib.connect('amqp://'+rabit_host).then(function(conn)\n{\n amqpconnection = conn;\n});\n\nio.sockets.on('connection', function(client)\n{ \n client.on('receivemsg', function(arg)\n {\n amqpconnection.createConfirmChannel().then(function(channelObjSuccess)\n {\n channelObjSuccess.assertQueue(queue_name,{durable:false,autoDelete:true});\n client.assignObj = channelObjSuccess;\n channelObjSuccess.consume(queue_name, function(msg)\n {\n var encodemsg = msg.content.toString();\n var json_msg = JSON.parse(encodemsg); \n client.emit('chatrecive',json_msg);\n }).then(function(){\n console.log(\"Receive Consiuume Close\");\n }); \n });\n });\n\nclient.on('loginentry', function(arg)\n{\n amqpconnection.createConfirmChannel().then(function(channelObjSuccess) {\n channelObjSuccess.assertQueue(queue_name,{durable:false,autoDelete:true});\n }); \n});\n\nclient.on('sendmsg', function(arg)\n{ \n var payload_stringify = JSON.stringify(arg); \n amqpconnection.createConfirmChannel().then(function(channelObjSuccess) {\n channelObjSuccess.assertQueue(queue_name,{durable:false,autoDelete:true});\n channelObjSuccess.sendToQueue(queue_name, new Buffer(payload_stringify), {},\n function(err, ok) \n {\n if (err !== null)\n console.log('Message Send Failure! ');\n else\n {\n channelObjSuccess.close();\n }\n });\n });\n}); \n\nclient.on('disconnect', function()\n{ \n try {\n console.log(\"AMPQ Connection Closed - Disconnect\");\n if(typeof(client.assignObj)!=undefined)\n {\n client.assignObj.close();\n } \n }\n catch (alreadyClosed) {\n console.log(\"RabbitMQ Connection Already Closed \" + alreadyClosed.stackAtStateChange);\n }\n }); \n});\n\nserver.listen(port);\n```\n\n```text\nurl = \"amqp://turtle.rmq.cloudamqp.com/bqftjxzn?heartbeat=45\";\n```\n\n```text\n?heartbeat=0\n```\n\n```text\nheartbeat=0\n```\n\n```text\nconsole.log(connection)\n```\n\n```text\n0\n```\n\n```text\nawait channel.close()\n```\n\n========================================\n\nComments:\n- the error comes from your socket, please post related code. `self.stream.on('end', self.onSocketError.bind(self, new Error('Unexpected close')));`\n- Thanks for the quick response. When it will be call? Which part of the code you want?\n- that says that the error is a socket error, so show us some socket code\n- I have added the code above. Kindly check.\n- ouch, please, indent your code and I'll have a look at it.\n- Can you help me to resolve this now?\n- The same happens in localhost also how do you resolve it?\n- Hi i doesnt' use heartbeat from the url but the issue is happening on my local, how you resolved it","metadata":{"transformedAt":"2026-08-18T18:33:20.165Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":222,"estimatedTokens":1641}}483{"id":"stack-16144665","source":"stackoverflow","questionId":16144665,"title":"node-amqp cannot send message to RabbitMQ","tags":["node.js","rabbitmq","amqp","node-amqp"],"text":"Title: node-amqp cannot send message to RabbitMQ\nTags: node.js, rabbitmq, amqp, node-amqp\nSource: Stack Overflow\n\nQuestion:\nI'm tring rabbitmq-tutorials, ruby version works fine, but node.js version cannot send message. I do not know what is wrong.\n\n```\nvar amqp = require('amqp');\nvar amqp_hacks = require('./amqp-hacks');\n\nvar connection = amqp.createConnection({host: 'localhost'});\n\nconnection.on('ready', function(){\n connection.publish('hello_node', 'Hello World!');\n console.log(\" [x] Sent 'Hello World!'\");\n\n amqp_hacks.safeEndConnection(connection);\n});\n```\n\nafter I run `node send.js`, runing process `node recv.js` cannot recv anything. and `rabbitmqctl list_queues` does not show `hello_node` queues.\n\n========================================\n\nCode:\n```text\nvar amqp = require('amqp');\nvar amqp_hacks = require('./amqp-hacks');\n\nvar connection = amqp.createConnection({host: 'localhost'});\n\nconnection.on('ready', function(){\n connection.publish('hello_node', 'Hello World!');\n console.log(\" [x] Sent 'Hello World!'\");\n\n amqp_hacks.safeEndConnection(connection);\n});\n```\n\n```text\nnode send.js\n```\n\n```text\nnode recv.js\n```\n\n```text\nrabbitmqctl list_queues\n```\n\n```text\nhello_node\n```\n\n```text\nvar amqp = require('amqp');\n var amqp_hacks = require('./amqp-hacks');\n\n var connection = amqp.createConnection({host: 'localhost'});\n\n connection.on('ready', function(){\n connection.queue('hello_node', {'durable': false}, function(q){\n connection.publish('hello_node', 'Hello World!');\n console.log(\" [x] Sent 'Hello World!' to 'hello_node'\");\n\n amqp_hacks.safeEndConnection(connection);\n });\n });\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.165Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":71,"estimatedTokens":427}}484{"id":"stack-29584618","source":"stackoverflow","questionId":29584618,"title":"Sending information to a ngnix from php on the same server without http","tags":["php","nginx","connection","rabbitmq","real-time"],"text":"Title: Sending information to a ngnix from php on the same server without http\nTags: php, nginx, connection, rabbitmq, real-time\nSource: Stack Overflow\n\nQuestion:\nWe are developing a realtime app and we are using nginx push stream module for a websockets part. Firstly, data is send from a client to a php script that does some authentication and stores needed information in database and then pushes information to nginx that later sends it to a subscribed users on a specific sockets. Quite often there will be situations when there are more that 30 http requests made from this script to local nginx (*which I am not exactly sure is a bad thing?*). \n\n**Question**\n\nIs it possible to send information from php to nginx without http requests? Is there any way that my php script can communicate with nginx? What is a best practise to handle this kind of communications? Is sending 30+ http requests per php script a good practise? \n\nI have read towards some AMQP solutions but haven't found information where nginx is a consumer of messages from rabbitmq. \n\nI will gladly provide any additional information if something is not clear.\n\n========================================\n\nTop Answer:\nWhy don't you consider using socket.io and Amazon SNS?\n\nIn our infrastructure when we want to send a notification to a specific client subscribed on a socket.io channel, we send a payload to an Amazon SNS topic. This payload has \"channel\" attribute and the \"message\" to send to the client. I give just a snippet from our code that's easy to understand\n\n```\n$msg = array(\n 'channel' => $receiver->getCometChannel(), //Channel id of the client to send the message \n 'data' => json_encode($payload) //The message to send to the client\n );\n$client = $this->getSNSObject();\n$client->publish(array(\n 'TopicArn' => $topicArn,\n 'Message' => json_encode($msg)\n ));\n```\n\nWe have a node.js script that creates and endpoint on the port 8002 (http://your_ip:8002/receive) When Amazon SNS receives a payload from PHP backends, it forwards this payload to this endpoint and then the only thing to do is processing the payload and send the message to the corresponding client via socket.js. Here goes the node.js script:\n\n```\nvar fs = require('fs');\n\nvar options = {\n pfx:fs.readFileSync('/etc/ssl/certificate.pfx') //optional, for SSL support for socket.js\n};\n\nvar io = require('socket.io')(8001);\n\n// open the socket connection\nio.sockets.on('connection', function(socket) {\n socket.on('subscribe', function(data) { socket.join(data.channel); });\n socket.on('unsubscribe', function(data) { socket.leave(data.channel); });\n socket.on('message', function (data) {\n io.sockets.in(data.channel).emit('message', data.message);\n });\n})\n\nvar http=require('http');\nhttp.createServer(function(req, res) {\n if(req.method === 'POST' && req.url === '/receive') {\n return client(req, res);\n }\n res.writeHead(404);\n res.end('Not found.');\n}).listen(8002);\n\nvar SNSClient = require('aws-snsclient');\nvar client = SNSClient(function(err, message) {\n try{\n var body=JSON.parse(message.Message)\n var channel=body.channel,data=(body.data);\n console.log(channel);\n io.sockets.in(channel).emit('message', {channel: channel, data: data});\n } catch(e) {\n console.log(e);\n }\n});\n```\n\nMaybe it seems complicated but i the idea is clear.\n\n========================================\n\nCode:\n```text\n$msg = array(\n 'channel' => $receiver->getCometChannel(), //Channel id of the client to send the message \n 'data' => json_encode($payload) //The message to send to the client\n );\n$client = $this->getSNSObject();\n$client->publish(array(\n 'TopicArn' => $topicArn,\n 'Message' => json_encode($msg)\n ));\n```\n\n```text\nvar fs = require('fs');\n\nvar options = {\n pfx:fs.readFileSync('/etc/ssl/certificate.pfx') //optional, for SSL support for socket.js\n};\n\n\nvar io = require('socket.io')(8001);\n\n\n// open the socket connection\nio.sockets.on('connection', function(socket) {\n socket.on('subscribe', function(data) { socket.join(data.channel); });\n socket.on('unsubscribe', function(data) { socket.leave(data.channel); });\n socket.on('message', function (data) {\n io.sockets.in(data.channel).emit('message', data.message);\n });\n})\n\nvar http=require('http');\nhttp.createServer(function(req, res) {\n if(req.method === 'POST' && req.url === '/receive') {\n return client(req, res);\n }\n res.writeHead(404);\n res.end('Not found.');\n}).listen(8002);\n\nvar SNSClient = require('aws-snsclient');\nvar client = SNSClient(function(err, message) {\n try{\n var body=JSON.parse(message.Message)\n var channel=body.channel,data=(body.data);\n console.log(channel);\n io.sockets.in(channel).emit('message', {channel: channel, data: data});\n } catch(e) {\n console.log(e);\n }\n});\n```\n\n```text\na. high timing to reestablish http connection each request; \nb. when concurrent requests reach its maximum nginx can skip some of your requests;\n```\n\n========================================\n\nComments:\n- I dont know what you are trying to do here, NGINX works on http protocol and you need some protocol to send the request from php script to nginx. Apart from that NGINX is a reverse proxy so you cant use it for RabbitMQ\n- @Pulkit Thanks for your comment. I need some balancing like solution for ngnix web socket module. Because as John Siu mentioned it seems like overkill to send 20+ http requests from php script to ngnix on my own server.\n- RusIanN: in case of loadbalancing have a look at this answer may be this can help you. stackoverflow.com/a/29718992/2219920\n- Why doesn't the PHP simply send the information directly to the sockets?\n- If each in-bound request creates 30 out-bound requests you will run out of file descriptors on your server a lot quicker than you think during periods of high traffic.\n- @chugadie can you elaborate more on topic of file descriptors and how they will affect me? I have very basic knowledge of them.\n- Thanks for idea, but reading from file(s) seems like really slow for chat like app\n- @RuslanN If it is a chatting apps, maybe you can consider using unix socket instead of file\n- I am using websocket module for nginx. The problem is as you mentioned overkill as the communication happens with the same server. This happens because I need to do some processing on server side before sending data to receivers so overkill happens.\n- @RuslanN I have been thinking about your question and come up with one more proposal.\n- I am happy to hear it\n- So what you are telling is to put all work done in php (db communication, parsing json result) to a nginx side? I thought about this idea, but amount of work done in php script is quite big and this will slow workflow. My current workflow: client (ios based or android) sends message using http request to api written in php. Php processes message, stores it does some additional work with it (authentication, notification and statistic related stuff) and then makes http request to nginx with parsed-json message which then is retrieved by client.\n- Base on your comment so far, seems your current flow from is as (1) Mobile client request is sent to php script over tcp (2) Standalone php script will authenticate, process data, update db, etc (3) Standalone php script communicate with nginx, (4) Naginx script send information to mobile client through websocket connection.\n- @RuslanN If my above assumption is true, then in the current flow, on top of a active websocket connection between mobile client and nginx, each time mobile client send a request, there is a additional tcp connection to the standalone php script, which is expensive and excessive.\n- If there is a active websocket connection, that means the mobile client already authenticate. Client request should definitely use the websocket connection to send request, this remove the authentication requirement for each request. This also remove the TCP connection setup and tear down for each request, which is expensive in terms of network communication.\n- Regarding db connection, you chould research database connection pool.\n- So to sum up what you are suggesting: transfer all message managing (parsing, validation and storing to database) to nginx side?\n- @RuslanN That is correct. It should one web application on the Nginx side.\n- Thanks you for bringing AmazonSNS up. We are using similar model but instead of socket.io we are using ngnix_stream_push_module and we needed something to balance load and AmazonSNS seems like great solution so far. What do you think about sending from PHP backends to Amazon SNS which forwards to ngnix websocket module? And what speed does this Amazov service provide? Is it good for real time chats?\n- Also, is it possible to send messages to amazon sns in batch?\n- Here you can nginx_stream_push_module instead of socket.io. I tried both solutions and socket.io is far better because it also has its client api etc. As you see the implementation is pretty short. For realtime chat, there's some delay in SNS. It can be used but you should implement and test before. There's no batch api for SNS but for SQS yes.\n- I am using websockets from nginx push_stream module if this helps.\n- By doing this php script will send data to nginx inside server? Can you provide some sources where I can learn more about this\n- Both the Nginx and the PHP processes have to run on the same machine. Google for PHP-FPM and Nginx, and you'll see lots of tutorials.\n- See for instance this one. The Unix socket in Nginx configuration file looks like `fastcgi_pass unix:/var/run/php5-fpm.sock;`\n- Can you tell what solution you've chosen? Just curious.\n- We have chosen to optimize current workflow and while we are going to monitor load on a current system we will try two ideas for out sockets: nodejs one and ratchet based with queue system for load balancing.","metadata":{"transformedAt":"2026-08-18T18:33:20.165Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":170,"estimatedTokens":2496}}485{"id":"stack-49334193","source":"stackoverflow","questionId":49334193,"title":"RabbitMQ Failed to declare queue and Listener is not able to get queue on server","tags":["spring-boot","rabbitmq","message-queue","spring-amqp","spring-rabbit"],"text":"Title: RabbitMQ Failed to declare queue and Listener is not able to get queue on server\nTags: spring-boot, rabbitmq, message-queue, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI have **spring boot** **rabbitmq** application where i have to send an Employee object to queue. Then i have set up a listener application. Do some processing on employee object and put this object in call back queue.\n\nFor this, i have created below objects in my appication.\n\n- Created *ConnectionFactory*.\n\n- Created *RabbitAdmin* object using *ConnectionFactory*..\n\n- Request Queue.\n\n- Callback Queue.\n\n- Direct Exchange.\n\n- Request Queue Binding.\n\n- Callback Queue Binding.\n\n- MessageConverter.\n\n- RabbitTemplate object.\n\n- And finally object of *SimpleMessageListenerContainer*.\n\nMy Application files looks like below.\n\napplication.properties\n\n```\nspring.rabbitmq.host=localhost\nspring.rabbitmq.port=5672\nspring.rabbitmq.username=guest\nspring.rabbitmq.password=guest\nspring.rabbitmq.virtual-host=foo\nemp.rabbitmq.directexchange=EMP_EXCHANGE1\nemp.rabbitmq.requestqueue=EMP_QUEUE1\nemp.rabbitmq.routingkey=EMP_ROUTING_KEY1\n```\n\nMainClass.java\n\n```\npackage com.employee;\n\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\n\n@SpringBootApplication\npublic class MainClass {\n\n public static void main(String[] args) {\n SpringApplication.run(\n MainClass.class, args);\n }\n}\n```\n\nApplicationContextProvider.java\n\n```\npackage com.employee.config;\n\nimport org.springframework.beans.BeansException;\nimport org.springframework.beans.factory.config.ConfigurableListableBeanFactory;\nimport org.springframework.beans.factory.support.BeanDefinitionRegistry;\nimport org.springframework.context.ApplicationContext;\nimport org.springframework.context.ApplicationContextAware;\nimport org.springframework.context.ConfigurableApplicationContext;\n\npublic class ApplicationContextProvider implements ApplicationContextAware {\n private static ApplicationContext context;\n\n public ApplicationContext getApplicationContext(){\n return context;\n }\n\n @Override\n public void setApplicationContext(ApplicationContext arg0) throws BeansException {\n context = arg0;\n\n }\n\n public Object getBean(String name){\n return context.getBean(name, Object.class);\n }\n\n public void addBean(String beanName, Object beanObject){\n ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext)context).getBeanFactory();\n beanFactory.registerSingleton(beanName, beanObject);\n }\n\n public void removeBean(String beanName){\n BeanDefinitionRegistry reg = (BeanDefinitionRegistry) context.getAutowireCapableBeanFactory();\n reg.removeBeanDefinition(beanName);\n }\n}\n```\n\nConstants.java\n\n```\npackage com.employee.constant;\n\npublic class Constants {\n\n public static final String CALLBACKQUEUE = \"_CBQ\";\n\n}\n```\n\nEmployee.java\n\n```\npackage com.employee.model;\n\nimport com.fasterxml.jackson.annotation.JsonIdentityInfo;\nimport com.fasterxml.jackson.annotation.ObjectIdGenerators;\n\n@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = \"@id\", scope = Employee.class)\npublic class Employee {\n\n private String empName;\n private String empId;\n private String changedValue;\n public String getEmpName() {\n return empName;\n }\n public void setEmpName(String empName) {\n this.empName = empName;\n }\n public String getEmpId() {\n return empId;\n }\n public void setEmpId(String empId) {\n this.empId = empId;\n }\n public String getChangedValue() {\n return changedValue;\n }\n public void setChangedValue(String changedValue) {\n this.changedValue = changedValue;\n }\n\n}\n```\n\nEmployeeProducerInitializer.java\n\n```\npackage com.employee.config;\n\nimport org.springframework.amqp.core.Binding;\nimport org.springframework.amqp.core.BindingBuilder;\nimport org.springframework.amqp.core.DirectExchange;\nimport org.springframework.amqp.core.Queue;\nimport org.springframework.amqp.rabbit.connection.ConnectionFactory;\nimport org.springframework.amqp.rabbit.core.RabbitAdmin;\nimport org.springframework.amqp.rabbit.core.RabbitTemplate;\nimport org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;\nimport org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;\nimport org.springframework.amqp.support.converter.MessageConverter;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.beans.factory.annotation.Qualifier;\nimport org.springframework.beans.factory.annotation.Value;\nimport org.springframework.boot.autoconfigure.EnableAutoConfiguration;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.ComponentScan;\nimport org.springframework.context.annotation.Configuration;\n\nimport com.employee.constant.Constants;\nimport com.employee.service.EmployeeResponseReceiver;\n\n@Configuration\n@EnableAutoConfiguration\n@ComponentScan(value=\"com.en.*\")\npublic class EmployeeProducerInitializer {\n\n @Value(\"${emp.rabbitmq.requestqueue}\")\n String requestQueueName;\n\n @Value(\"${emp.rabbitmq.directexchange}\")\n String directExchange;\n\n @Value(\"${emp.rabbitmq.routingkey}\")\n private String requestRoutingKey;\n\n @Autowired\n private ConnectionFactory rabbitConnectionFactory;\n\n @Bean\n ApplicationContextProvider applicationContextProvider(){\n System.out.println(\"inside app ctx provider\");\n return new ApplicationContextProvider();\n };\n\n @Bean\n RabbitAdmin rabbitAdmin(){\n System.out.println(\"inside rabbit admin\");\n return new RabbitAdmin(rabbitConnectionFactory);\n };\n\n @Bean\n Queue empRequestQueue() {\n System.out.println(\"inside request queue\");\n return new Queue(requestQueueName, true);\n }\n\n @Bean\n Queue empCallBackQueue() {\n System.out.println(\"inside call back queue\");\n return new Queue(requestQueueName + Constants.CALLBACKQUEUE, true);\n }\n\n @Bean\n DirectExchange empDirectExchange() {\n System.out.println(\"inside exchange\");\n return new DirectExchange(directExchange);\n }\n\n @Bean\n Binding empRequestBinding() {\n System.out.println(\"inside request binding\");\n return BindingBuilder.bind(empRequestQueue()).to(empDirectExchange()).with(requestRoutingKey);\n }\n\n @Bean\n Binding empCallBackBinding() {\n return BindingBuilder.bind(empCallBackQueue()).to(empDirectExchange()).with(requestRoutingKey + Constants.CALLBACKQUEUE);\n }\n\n @Bean\n public MessageConverter jsonMessageConverter(){\n System.out.println(\"inside json msg converter\");\n return new Jackson2JsonMessageConverter();\n }\n\n @Bean\n public RabbitTemplate empFixedReplyQRabbitTemplate() {\n System.out.println(\"inside rabbit template\");\n RabbitTemplate template = new RabbitTemplate(this.rabbitConnectionFactory);\n template.setExchange(empDirectExchange().getName());\n template.setRoutingKey(requestRoutingKey);\n template.setMessageConverter(jsonMessageConverter());\n template.setReceiveTimeout(100000);\n template.setReplyTimeout(100000);\n\n return template;\n }\n\n @Bean\n public SimpleMessageListenerContainer empReplyListenerContainer() {\n System.out.println(\"inside listener\");\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n try{\n container.setConnectionFactory(this.rabbitConnectionFactory);\n container.setQueues(empCallBackQueue());\n container.setMessageListener(new EmployeeResponseReceiver());\n container.setMessageConverter(jsonMessageConverter());\n container.setConcurrentConsumers(10);\n container.setMaxConcurrentConsumers(20);\n container.start();\n }catch(Exception e){\n e.printStackTrace();\n }finally{\n System.out.println(\"inside listener finally\");\n }\n\n return container;\n }\n\n @Autowired\n @Qualifier(\"empReplyListenerContainer\")\n private SimpleMessageListenerContainer empReplyListenerContainer;\n}\n```\n\nEmployeeResponseReceiver.java\n\n```\npackage com.employee.service;\n\nimport org.springframework.amqp.core.Message;\nimport org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;\nimport org.springframework.boot.autoconfigure.EnableAutoConfiguration;\nimport org.springframework.stereotype.Component;\n\nimport com.employee.config.ApplicationContextProvider;\nimport com.employee.model.Employee;\nimport com.fasterxml.jackson.databind.ObjectMapper;\nimport com.rabbitmq.client.Channel;\n\n@Component\n@EnableAutoConfiguration\npublic class EmployeeResponseReceiver implements ChannelAwareMessageListener {\n\n ApplicationContextProvider applicationContextProvider = new ApplicationContextProvider();\n\n String msg = null;\n ObjectMapper mapper = new ObjectMapper();\n Employee employee = null;\n\n @Override\n public void onMessage(Message message, Channel arg1) throws Exception {\n try {\n msg = new String(message.getBody());\n System.out.println(\"Received Message : \" + msg);\n\n employee = mapper.readValue(msg, Employee.class);\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n}\n```\n\nThe problem is whenever i start my application, i get below exceptions.\n\n```\n2018-03-17 14:18:36.695 INFO 12472 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext\n2018-03-17 14:18:36.696 INFO 12472 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 5060 ms\n2018-03-17 14:18:37.004 INFO 12472 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]\n2018-03-17 14:18:37.010 INFO 12472 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]\n2018-03-17 14:18:37.010 INFO 12472 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]\n2018-03-17 14:18:37.011 INFO 12472 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]\n2018-03-17 14:18:37.011 INFO 12472 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]\ninside listener\ninside call back queue\ninside json msg converter\n2018-03-17 14:18:37.576 INFO 12472 --- [cTaskExecutor-8] o.s.a.r.c.CachingConnectionFactory : Created new connection: SimpleConnection@3d31af39 [delegate=amqp://guest@127.0.0.1:5672/foo, localPort= 50624]\n2018-03-17 14:18:37.654 WARN 12472 --- [cTaskExecutor-7] o.s.a.r.listener.BlockingQueueConsumer : Failed to declare queue:EMP_QUEUE1_CBQ\n2018-03-17 14:18:37.655 WARN 12472 --- [cTaskExecutor-6] o.s.a.r.listener.BlockingQueueConsumer : Failed to declare queue:EMP_QUEUE1_CBQ\n2018-03-17 14:18:37.655 WARN 12472 --- [cTaskExecutor-5] o.s.a.r.listener.BlockingQueueConsumer : Failed to declare queue:EMP_QUEUE1_CBQ\n2018-03-17 14:18:37.655 WARN 12472 --- [cTaskExecutor-3] o.s.a.r.listener.BlockingQueueConsumer : Failed to declare queue:EMP_QUEUE1_CBQ\n2018-03-17 14:18:37.657 WARN 12472 --- [cTaskExecutor-1] o.s.a.r.listener.BlockingQueueConsumer : Failed to declare queue:EMP_QUEUE1_CBQ\n2018-03-17 14:18:37.658 WARN 12472 --- [cTaskExecutor-8] o.s.a.r.listener.BlockingQueueConsumer : Failed to declare queue:EMP_QUEUE1_CBQ\n2018-03-17 14:18:37.661 WARN 12472 --- [cTaskExecutor-2] o.s.a.r.listener.BlockingQueueConsumer : Failed to declare queue:EMP_QUEUE1_CBQ\n2018-03-17 14:18:37.660 WARN 12472 --- [cTaskExecutor-4] o.s.a.r.listener.BlockingQueueConsumer : Failed to declare queue:EMP_QUEUE1_CBQ\n2018-03-17 14:18:37.661 WARN 12472 --- [cTaskExecutor-9] o.s.a.r.listener.BlockingQueueConsumer : Failed to declare queue:EMP_QUEUE1_CBQ\n2018-03-17 14:18:37.666 WARN 12472 --- [TaskExecutor-10] o.s.a.r.listener.BlockingQueueConsumer : Failed to declare queue:EMP_QUEUE1_CBQ\n2018-03-17 14:18:37.667 WARN 12472 --- [cTaskExecutor-2] o.s.a.r.listener.BlockingQueueConsumer : Queue declaration failed; retries left=3\n\norg.springframework.amqp.rabbit.listener.BlockingQueueConsumer$DeclarationException: Failed to declare queue(s):[EMP_QUEUE1_CBQ]\n at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:636) ~[spring-rabbit-1.7.2.RELEASE.jar:na]\n at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:535) ~[spring-rabbit-1.7.2.RELEASE.jar:na]\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1389) [spring-rabbit-1.7.2.RELEASE.jar:na]\n at java.lang.Thread.run(Unknown Source) [na:1.8.0_151]\nCaused by: java.io.IOException: null\n at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:105) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:101) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:123) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:992) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:50) ~[amqp-client-4.0.2.jar:4.0.2]\n at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_151]\n at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_151]\n at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_151]\n at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_151]\n at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$CachedChannelInvocationHandler.invoke(CachingConnectionFactory.java:955) ~[spring-rabbit-1.7.2.RELEASE.jar:na]\n at com.sun.proxy.$Proxy58.queueDeclarePassive(Unknown Source) ~[na:na]\n at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:615) ~[spring-rabbit-1.7.2.RELEASE.jar:na]\n ... 3 common frames omitted\nCaused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method(reply-code=404, reply-text=NOT_FOUND - no queue 'EMP_QUEUE1_CBQ' in vhost 'foo', class-id=50, method-id=10)\n at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:32) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:366) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:229) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:117) ~[amqp-client-4.0.2.jar:4.0.2]\n ... 12 common frames omitted\nCaused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method(reply-code=404, reply-text=NOT_FOUND - no queue 'EMP_QUEUE1_CBQ' in vhost 'foo', class-id=50, method-id=10)\n at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:505) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:336) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:143) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:90) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQConnection.readFrame(AMQConnection.java:634) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQConnection.access$300(AMQConnection.java:47) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:572) ~[amqp-client-4.0.2.jar:4.0.2]\n ... 1 common frames omitted\n\n2018-03-17 14:08:36.689 WARN 11076 --- [cTaskExecutor-4] o.s.a.r.listener.BlockingQueueConsumer : Failed to declare queue:EMP_QUEUE1_CBQ\n2018-03-17 14:08:36.695 ERROR 11076 --- [cTaskExecutor-4] o.s.a.r.l.SimpleMessageListenerContainer : Consumer received fatal exception on startup\n\norg.springframework.amqp.rabbit.listener.QueuesNotAvailableException: Cannot prepare queue for listener. Either the queue doesn't exist or the broker will not allow us to use it.\n at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:563) ~[spring-rabbit-1.7.2.RELEASE.jar:na]\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1389) ~[spring-rabbit-1.7.2.RELEASE.jar:na]\n at java.lang.Thread.run(Unknown Source) [na:1.8.0_151]\nCaused by: org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$DeclarationException: Failed to declare queue(s):[EMP_QUEUE1_CBQ]\n at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:636) ~[spring-rabbit-1.7.2.RELEASE.jar:na]\n at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:535) ~[spring-rabbit-1.7.2.RELEASE.jar:na]\n ... 2 common frames omitted\nCaused by: java.io.IOException: null\n at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:105) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:101) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:123) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:992) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:50) ~[amqp-client-4.0.2.jar:4.0.2]\n at sun.reflect.GeneratedMethodAccessor27.invoke(Unknown Source) ~[na:na]\n at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_151]\n at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_151]\n at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$CachedChannelInvocationHandler.invoke(CachingConnectionFactory.java:955) ~[spring-rabbit-1.7.2.RELEASE.jar:na]\n at com.sun.proxy.$Proxy58.queueDeclarePassive(Unknown Source) ~[na:na]\n at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:615) ~[spring-rabbit-1.7.2.RELEASE.jar:na]\n ... 3 common frames omitted\nCaused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method(reply-code=404, reply-text=NOT_FOUND - no queue 'EMP_QUEUE1_CBQ' in vhost 'foo', class-id=50, method-id=10)\n at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:32) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:366) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:229) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:117) ~[amqp-client-4.0.2.jar:4.0.2]\n ... 11 common frames omitted\nCaused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method(reply-code=404, reply-text=NOT_FOUND - no queue 'EMP_QUEUE1_CBQ' in vhost 'foo', class-id=50, method-id=10)\n at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:505) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:336) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:143) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:90) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQConnection.readFrame(AMQConnection.java:634) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQConnection.access$300(AMQConnection.java:47) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:572) ~[amqp-client-4.0.2.jar:4.0.2]\n ... 1 common frames omitted\n\n2018-03-17 14:08:36.697 INFO 11076 --- [TaskExecutor-10] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.\n2018-03-17 14:08:36.699 INFO 11076 --- [cTaskExecutor-5] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.\n2018-03-17 14:08:36.700 INFO 11076 --- [cTaskExecutor-1] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.\n2018-03-17 14:08:36.701 INFO 11076 --- [cTaskExecutor-3] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.\n2018-03-17 14:08:36.700 INFO 11076 --- [cTaskExecutor-2] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.\n2018-03-17 14:08:36.702 INFO 11076 --- [cTaskExecutor-7] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.\n2018-03-17 14:08:36.765 ERROR 11076 --- [cTaskExecutor-8] o.s.a.r.l.SimpleMessageListenerContainer : Stopping container from aborted consumer\n2018-03-17 14:08:36.766 ERROR 11076 --- [cTaskExecutor-6] o.s.a.r.l.SimpleMessageListenerContainer : Stopping container from aborted consumer\n2018-03-17 14:08:36.779 ERROR 11076 --- [cTaskExecutor-9] o.s.a.r.l.SimpleMessageListenerContainer : Stopping container from aborted consumer\n2018-03-17 14:08:36.791 ERROR 11076 --- [cTaskExecutor-4] o.s.a.r.l.SimpleMessageListenerContainer : Stopping container from aborted consumer\ninside app ctx provider\ninside rabbit admin\ninside exchange\ninside request queue\ninside request binding\ninside rabbit template\n2018-03-17 14:08:38.978 INFO 11076 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@33b37288: startup date [Sat Mar 17 14:08:16 IST 2018]; root of context hierarchy\n2018-03-17 14:08:39.395 INFO 11076 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped \"{[/error]}\" onto public org.springframework.http.ResponseEntity> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)\n2018-03-17 14:08:39.398 INFO 11076 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped \"{[/error],produces=[text/html]}\" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)\n2018-03-17 14:08:39.663 INFO 11076 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]\n2018-03-17 14:08:39.663 INFO 11076 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]\n2018-03-17 14:08:39.826 INFO 11076 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]\n2018-03-17 14:08:40.648 INFO 11076 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup\n2018-03-17 14:08:40.677 INFO 11076 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'rabbitConnectionFactory' has been autodetected for JMX exposure\n2018-03-17 14:08:40.685 INFO 11076 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'rabbitConnectionFactory': registering with JMX server as MBean [org.springframework.amqp.rabbit.connection:name=rabbitConnectionFactory,type=CachingConnectionFactory]\n2018-03-17 14:08:40.746 INFO 11076 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase -2147482648\n2018-03-17 14:08:40.747 INFO 11076 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483647\n2018-03-17 14:08:41.258 INFO 11076 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)\n2018-03-17 14:08:41.270 INFO 11076 --- [ main] com.employee.MainClass : Started MainClass in 26.141 seconds (JVM running for 28.02)\n```\n\nCan anybody help me resolving my issue? As per my understanding, when object of **SimpleMessageListenerContainer** is being created, callback queue is not created on rabbitmq server. I tried declaring queue using **RabbitAdmin** object, but then execution stops and nothing goes ahead. This problem was not there when i was declaring queue in default virtual host. But when i added virtual host **foo** all of it sudden stopped working. You can replicate this issue using above code. I have pasted all my code. Kindly let me know if anything else is to be posted.\n\nInteresting point is even if i am getting this exceptions, my application is up and running. That means somehow my callback queue is created and object of **SimpleMessageListenerContainer** gets the queue. I read somewhere that, when queue is created, my **SimpleMessageListenerContainer** object will listen to it.\n\nPlease help me resolving this issue.\n\n========================================\n\nCode:\n```text\nspring.rabbitmq.host=localhost\nspring.rabbitmq.port=5672\nspring.rabbitmq.username=guest\nspring.rabbitmq.password=guest\nspring.rabbitmq.virtual-host=foo\nemp.rabbitmq.directexchange=EMP_EXCHANGE1\nemp.rabbitmq.requestqueue=EMP_QUEUE1\nemp.rabbitmq.routingkey=EMP_ROUTING_KEY1\n```\n\n```text\npackage com.employee;\n\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\n\n@SpringBootApplication\npublic class MainClass {\n\n public static void main(String[] args) {\n SpringApplication.run(\n MainClass.class, args);\n }\n}\n```\n\n```text\npackage com.employee.config;\n\nimport org.springframework.beans.BeansException;\nimport org.springframework.beans.factory.config.ConfigurableListableBeanFactory;\nimport org.springframework.beans.factory.support.BeanDefinitionRegistry;\nimport org.springframework.context.ApplicationContext;\nimport org.springframework.context.ApplicationContextAware;\nimport org.springframework.context.ConfigurableApplicationContext;\n\npublic class ApplicationContextProvider implements ApplicationContextAware {\n private static ApplicationContext context;\n\n public ApplicationContext getApplicationContext(){\n return context;\n }\n\n @Override\n public void setApplicationContext(ApplicationContext arg0) throws BeansException {\n context = arg0;\n\n }\n\n public Object getBean(String name){\n return context.getBean(name, Object.class);\n }\n\n public void addBean(String beanName, Object beanObject){\n ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext)context).getBeanFactory();\n beanFactory.registerSingleton(beanName, beanObject);\n }\n\n public void removeBean(String beanName){\n BeanDefinitionRegistry reg = (BeanDefinitionRegistry) context.getAutowireCapableBeanFactory();\n reg.removeBeanDefinition(beanName);\n }\n}\n```\n\n```text\npackage com.employee.constant;\n\npublic class Constants {\n\n public static final String CALLBACKQUEUE = \"_CBQ\";\n\n}\n```\n\n```text\npackage com.employee.model;\n\nimport com.fasterxml.jackson.annotation.JsonIdentityInfo;\nimport com.fasterxml.jackson.annotation.ObjectIdGenerators;\n\n@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = \"@id\", scope = Employee.class)\npublic class Employee {\n\n private String empName;\n private String empId;\n private String changedValue;\n public String getEmpName() {\n return empName;\n }\n public void setEmpName(String empName) {\n this.empName = empName;\n }\n public String getEmpId() {\n return empId;\n }\n public void setEmpId(String empId) {\n this.empId = empId;\n }\n public String getChangedValue() {\n return changedValue;\n }\n public void setChangedValue(String changedValue) {\n this.changedValue = changedValue;\n }\n\n\n}\n```\n\n```text\npackage com.employee.config;\n\nimport org.springframework.amqp.core.Binding;\nimport org.springframework.amqp.core.BindingBuilder;\nimport org.springframework.amqp.core.DirectExchange;\nimport org.springframework.amqp.core.Queue;\nimport org.springframework.amqp.rabbit.connection.ConnectionFactory;\nimport org.springframework.amqp.rabbit.core.RabbitAdmin;\nimport org.springframework.amqp.rabbit.core.RabbitTemplate;\nimport org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;\nimport org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;\nimport org.springframework.amqp.support.converter.MessageConverter;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.beans.factory.annotation.Qualifier;\nimport org.springframework.beans.factory.annotation.Value;\nimport org.springframework.boot.autoconfigure.EnableAutoConfiguration;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.ComponentScan;\nimport org.springframework.context.annotation.Configuration;\n\nimport com.employee.constant.Constants;\nimport com.employee.service.EmployeeResponseReceiver;\n\n@Configuration\n@EnableAutoConfiguration\n@ComponentScan(value=\"com.en.*\")\npublic class EmployeeProducerInitializer {\n\n @Value(\"${emp.rabbitmq.requestqueue}\")\n String requestQueueName;\n\n @Value(\"${emp.rabbitmq.directexchange}\")\n String directExchange;\n\n @Value(\"${emp.rabbitmq.routingkey}\")\n private String requestRoutingKey;\n\n @Autowired\n private ConnectionFactory rabbitConnectionFactory;\n\n @Bean\n ApplicationContextProvider applicationContextProvider(){\n System.out.println(\"inside app ctx provider\");\n return new ApplicationContextProvider();\n };\n\n @Bean\n RabbitAdmin rabbitAdmin(){\n System.out.println(\"inside rabbit admin\");\n return new RabbitAdmin(rabbitConnectionFactory);\n };\n\n @Bean\n Queue empRequestQueue() {\n System.out.println(\"inside request queue\");\n return new Queue(requestQueueName, true);\n }\n\n @Bean\n Queue empCallBackQueue() {\n System.out.println(\"inside call back queue\");\n return new Queue(requestQueueName + Constants.CALLBACKQUEUE, true);\n }\n\n @Bean\n DirectExchange empDirectExchange() {\n System.out.println(\"inside exchange\");\n return new DirectExchange(directExchange);\n }\n\n @Bean\n Binding empRequestBinding() {\n System.out.println(\"inside request binding\");\n return BindingBuilder.bind(empRequestQueue()).to(empDirectExchange()).with(requestRoutingKey);\n }\n\n @Bean\n Binding empCallBackBinding() {\n return BindingBuilder.bind(empCallBackQueue()).to(empDirectExchange()).with(requestRoutingKey + Constants.CALLBACKQUEUE);\n }\n\n @Bean\n public MessageConverter jsonMessageConverter(){\n System.out.println(\"inside json msg converter\");\n return new Jackson2JsonMessageConverter();\n }\n\n @Bean\n public RabbitTemplate empFixedReplyQRabbitTemplate() {\n System.out.println(\"inside rabbit template\");\n RabbitTemplate template = new RabbitTemplate(this.rabbitConnectionFactory);\n template.setExchange(empDirectExchange().getName());\n template.setRoutingKey(requestRoutingKey);\n template.setMessageConverter(jsonMessageConverter());\n template.setReceiveTimeout(100000);\n template.setReplyTimeout(100000);\n\n return template;\n }\n\n @Bean\n public SimpleMessageListenerContainer empReplyListenerContainer() {\n System.out.println(\"inside listener\");\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n try{\n container.setConnectionFactory(this.rabbitConnectionFactory);\n container.setQueues(empCallBackQueue());\n container.setMessageListener(new EmployeeResponseReceiver());\n container.setMessageConverter(jsonMessageConverter());\n container.setConcurrentConsumers(10);\n container.setMaxConcurrentConsumers(20);\n container.start();\n }catch(Exception e){\n e.printStackTrace();\n }finally{\n System.out.println(\"inside listener finally\");\n }\n\n return container;\n }\n\n @Autowired\n @Qualifier(\"empReplyListenerContainer\")\n private SimpleMessageListenerContainer empReplyListenerContainer;\n}\n```\n\n```text\npackage com.employee.service;\n\nimport org.springframework.amqp.core.Message;\nimport org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;\nimport org.springframework.boot.autoconfigure.EnableAutoConfiguration;\nimport org.springframework.stereotype.Component;\n\nimport com.employee.config.ApplicationContextProvider;\nimport com.employee.model.Employee;\nimport com.fasterxml.jackson.databind.ObjectMapper;\nimport com.rabbitmq.client.Channel;\n\n@Component\n@EnableAutoConfiguration\npublic class EmployeeResponseReceiver implements ChannelAwareMessageListener {\n\n ApplicationContextProvider applicationContextProvider = new ApplicationContextProvider();\n\n String msg = null;\n ObjectMapper mapper = new ObjectMapper();\n Employee employee = null;\n\n @Override\n public void onMessage(Message message, Channel arg1) throws Exception {\n try {\n msg = new String(message.getBody());\n System.out.println(\"Received Message : \" + msg);\n\n employee = mapper.readValue(msg, Employee.class);\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n}\n```\n\n```text\n2018-03-17 14:18:36.695 INFO 12472 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext\n2018-03-17 14:18:36.696 INFO 12472 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 5060 ms\n2018-03-17 14:18:37.004 INFO 12472 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]\n2018-03-17 14:18:37.010 INFO 12472 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]\n2018-03-17 14:18:37.010 INFO 12472 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]\n2018-03-17 14:18:37.011 INFO 12472 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]\n2018-03-17 14:18:37.011 INFO 12472 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]\ninside listener\ninside call back queue\ninside json msg converter\n2018-03-17 14:18:37.576 INFO 12472 --- [cTaskExecutor-8] o.s.a.r.c.CachingConnectionFactory : Created new connection: SimpleConnection@3d31af39 [delegate=amqp://guest@127.0.0.1:5672/foo, localPort= 50624]\n2018-03-17 14:18:37.654 WARN 12472 --- [cTaskExecutor-7] o.s.a.r.listener.BlockingQueueConsumer : Failed to declare queue:EMP_QUEUE1_CBQ\n2018-03-17 14:18:37.655 WARN 12472 --- [cTaskExecutor-6] o.s.a.r.listener.BlockingQueueConsumer : Failed to declare queue:EMP_QUEUE1_CBQ\n2018-03-17 14:18:37.655 WARN 12472 --- [cTaskExecutor-5] o.s.a.r.listener.BlockingQueueConsumer : Failed to declare queue:EMP_QUEUE1_CBQ\n2018-03-17 14:18:37.655 WARN 12472 --- [cTaskExecutor-3] o.s.a.r.listener.BlockingQueueConsumer : Failed to declare queue:EMP_QUEUE1_CBQ\n2018-03-17 14:18:37.657 WARN 12472 --- [cTaskExecutor-1] o.s.a.r.listener.BlockingQueueConsumer : Failed to declare queue:EMP_QUEUE1_CBQ\n2018-03-17 14:18:37.658 WARN 12472 --- [cTaskExecutor-8] o.s.a.r.listener.BlockingQueueConsumer : Failed to declare queue:EMP_QUEUE1_CBQ\n2018-03-17 14:18:37.661 WARN 12472 --- [cTaskExecutor-2] o.s.a.r.listener.BlockingQueueConsumer : Failed to declare queue:EMP_QUEUE1_CBQ\n2018-03-17 14:18:37.660 WARN 12472 --- [cTaskExecutor-4] o.s.a.r.listener.BlockingQueueConsumer : Failed to declare queue:EMP_QUEUE1_CBQ\n2018-03-17 14:18:37.661 WARN 12472 --- [cTaskExecutor-9] o.s.a.r.listener.BlockingQueueConsumer : Failed to declare queue:EMP_QUEUE1_CBQ\n2018-03-17 14:18:37.666 WARN 12472 --- [TaskExecutor-10] o.s.a.r.listener.BlockingQueueConsumer : Failed to declare queue:EMP_QUEUE1_CBQ\n2018-03-17 14:18:37.667 WARN 12472 --- [cTaskExecutor-2] o.s.a.r.listener.BlockingQueueConsumer : Queue declaration failed; retries left=3\n\norg.springframework.amqp.rabbit.listener.BlockingQueueConsumer$DeclarationException: Failed to declare queue(s):[EMP_QUEUE1_CBQ]\n at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:636) ~[spring-rabbit-1.7.2.RELEASE.jar:na]\n at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:535) ~[spring-rabbit-1.7.2.RELEASE.jar:na]\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1389) [spring-rabbit-1.7.2.RELEASE.jar:na]\n at java.lang.Thread.run(Unknown Source) [na:1.8.0_151]\nCaused by: java.io.IOException: null\n at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:105) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:101) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:123) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:992) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:50) ~[amqp-client-4.0.2.jar:4.0.2]\n at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_151]\n at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_151]\n at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_151]\n at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_151]\n at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$CachedChannelInvocationHandler.invoke(CachingConnectionFactory.java:955) ~[spring-rabbit-1.7.2.RELEASE.jar:na]\n at com.sun.proxy.$Proxy58.queueDeclarePassive(Unknown Source) ~[na:na]\n at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:615) ~[spring-rabbit-1.7.2.RELEASE.jar:na]\n ... 3 common frames omitted\nCaused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'EMP_QUEUE1_CBQ' in vhost 'foo', class-id=50, method-id=10)\n at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:32) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:366) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:229) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:117) ~[amqp-client-4.0.2.jar:4.0.2]\n ... 12 common frames omitted\nCaused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'EMP_QUEUE1_CBQ' in vhost 'foo', class-id=50, method-id=10)\n at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:505) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:336) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:143) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:90) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQConnection.readFrame(AMQConnection.java:634) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQConnection.access$300(AMQConnection.java:47) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:572) ~[amqp-client-4.0.2.jar:4.0.2]\n ... 1 common frames omitted\n\n2018-03-17 14:08:36.689 WARN 11076 --- [cTaskExecutor-4] o.s.a.r.listener.BlockingQueueConsumer : Failed to declare queue:EMP_QUEUE1_CBQ\n2018-03-17 14:08:36.695 ERROR 11076 --- [cTaskExecutor-4] o.s.a.r.l.SimpleMessageListenerContainer : Consumer received fatal exception on startup\n\norg.springframework.amqp.rabbit.listener.QueuesNotAvailableException: Cannot prepare queue for listener. Either the queue doesn't exist or the broker will not allow us to use it.\n at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:563) ~[spring-rabbit-1.7.2.RELEASE.jar:na]\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1389) ~[spring-rabbit-1.7.2.RELEASE.jar:na]\n at java.lang.Thread.run(Unknown Source) [na:1.8.0_151]\nCaused by: org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$DeclarationException: Failed to declare queue(s):[EMP_QUEUE1_CBQ]\n at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:636) ~[spring-rabbit-1.7.2.RELEASE.jar:na]\n at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:535) ~[spring-rabbit-1.7.2.RELEASE.jar:na]\n ... 2 common frames omitted\nCaused by: java.io.IOException: null\n at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:105) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:101) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:123) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:992) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:50) ~[amqp-client-4.0.2.jar:4.0.2]\n at sun.reflect.GeneratedMethodAccessor27.invoke(Unknown Source) ~[na:na]\n at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_151]\n at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_151]\n at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$CachedChannelInvocationHandler.invoke(CachingConnectionFactory.java:955) ~[spring-rabbit-1.7.2.RELEASE.jar:na]\n at com.sun.proxy.$Proxy58.queueDeclarePassive(Unknown Source) ~[na:na]\n at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:615) ~[spring-rabbit-1.7.2.RELEASE.jar:na]\n ... 3 common frames omitted\nCaused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'EMP_QUEUE1_CBQ' in vhost 'foo', class-id=50, method-id=10)\n at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:32) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:366) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:229) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:117) ~[amqp-client-4.0.2.jar:4.0.2]\n ... 11 common frames omitted\nCaused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'EMP_QUEUE1_CBQ' in vhost 'foo', class-id=50, method-id=10)\n at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:505) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:336) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:143) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:90) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQConnection.readFrame(AMQConnection.java:634) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQConnection.access$300(AMQConnection.java:47) ~[amqp-client-4.0.2.jar:4.0.2]\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:572) ~[amqp-client-4.0.2.jar:4.0.2]\n ... 1 common frames omitted\n\n2018-03-17 14:08:36.697 INFO 11076 --- [TaskExecutor-10] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.\n2018-03-17 14:08:36.699 INFO 11076 --- [cTaskExecutor-5] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.\n2018-03-17 14:08:36.700 INFO 11076 --- [cTaskExecutor-1] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.\n2018-03-17 14:08:36.701 INFO 11076 --- [cTaskExecutor-3] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.\n2018-03-17 14:08:36.700 INFO 11076 --- [cTaskExecutor-2] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.\n2018-03-17 14:08:36.702 INFO 11076 --- [cTaskExecutor-7] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.\n2018-03-17 14:08:36.765 ERROR 11076 --- [cTaskExecutor-8] o.s.a.r.l.SimpleMessageListenerContainer : Stopping container from aborted consumer\n2018-03-17 14:08:36.766 ERROR 11076 --- [cTaskExecutor-6] o.s.a.r.l.SimpleMessageListenerContainer : Stopping container from aborted consumer\n2018-03-17 14:08:36.779 ERROR 11076 --- [cTaskExecutor-9] o.s.a.r.l.SimpleMessageListenerContainer : Stopping container from aborted consumer\n2018-03-17 14:08:36.791 ERROR 11076 --- [cTaskExecutor-4] o.s.a.r.l.SimpleMessageListenerContainer : Stopping container from aborted consumer\ninside app ctx provider\ninside rabbit admin\ninside exchange\ninside request queue\ninside request binding\ninside rabbit template\n2018-03-17 14:08:38.978 INFO 11076 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@33b37288: startup date [Sat Mar 17 14:08:16 IST 2018]; root of context hierarchy\n2018-03-17 14:08:39.395 INFO 11076 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped \"{[/error]}\" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)\n2018-03-17 14:08:39.398 INFO 11076 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped \"{[/error],produces=[text/html]}\" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)\n2018-03-17 14:08:39.663 INFO 11076 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]\n2018-03-17 14:08:39.663 INFO 11076 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]\n2018-03-17 14:08:39.826 INFO 11076 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]\n2018-03-17 14:08:40.648 INFO 11076 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup\n2018-03-17 14:08:40.677 INFO 11076 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'rabbitConnectionFactory' has been autodetected for JMX exposure\n2018-03-17 14:08:40.685 INFO 11076 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'rabbitConnectionFactory': registering with JMX server as MBean [org.springframework.amqp.rabbit.connection:name=rabbitConnectionFactory,type=CachingConnectionFactory]\n2018-03-17 14:08:40.746 INFO 11076 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase -2147482648\n2018-03-17 14:08:40.747 INFO 11076 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483647\n2018-03-17 14:08:41.258 INFO 11076 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)\n2018-03-17 14:08:41.270 INFO 11076 --- [ main] com.employee.MainClass : Started MainClass in 26.141 seconds (JVM running for 28.02)\n```\n\n```text\ncontainer.start();\n```\n\n```text\nconfigure\n```\n\n```text\nstart()\n```\n\n```text\nautoStartUp\n```\n\n```text\ntrue\n```\n\n========================================\n\nComments:\n- Yes sir. the user have permissions to declare the queue with admin privilege. Let me know if you can replicate the issue with provided code.\n- The problem is you are starting the container too early - see my edit.\n- Hi Garry. Thanks. I got it. I removed start method call and its working now. I searched more on that, when bean is declared, queue is getting created passively. And it will get active when my app ctx is loaded properly.","metadata":{"transformedAt":"2026-08-18T18:33:20.165Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":13,"totalLines":899,"estimatedTokens":12431}}486{"id":"stack-38530948","source":"stackoverflow","questionId":38530948,"title":"zsh: command not found: rabbitmq-server","tags":["rabbitmq","zsh"],"text":"Title: zsh: command not found: rabbitmq-server\nTags: rabbitmq, zsh\nSource: Stack Overflow\n\nQuestion:\nI've been following the RabbitMQ installation guide via homebrew.\n\nIt says to add a line to my `.bash_profile`, but since I'm using ohmyzsh for my terminal I'm guessing I have to edit my `.zshrc` file.\n\nI've tried adding the following possibilities:\n\n- `PATH=$PATH:/usr/local/sbin`\n\n- `export PATH=$PATH:/usr/local/sbin`\n\n- `export PATH=/usr/local/sbin:$PATH`\n\nUnfortunately none of them worked.\n\nElsewhere in the `.zshrc` file I see this line: `export ZSH=/Users/robinkim/.oh-my-zsh`. This may give a clue as to what needs to be added.\n\n**EDIT: I simply forgot to `brew link rabbitmq`**\n\n========================================\n\nTop Answer:\nFor me the solution was to run\n\n`brew services start rabbitmq`\n\n========================================\n\nCode:\n```text\n.bash_profile\n```\n\n```text\n.zshrc\n```\n\n```text\nPATH=$PATH:/usr/local/sbin\n```\n\n```text\nexport PATH=$PATH:/usr/local/sbin\n```\n\n```text\nexport PATH=/usr/local/sbin:$PATH\n```\n\n```text\n.zshrc\n```\n\n```text\nexport ZSH=/Users/robinkim/.oh-my-zsh\n```\n\n```text\nbrew link rabbitmq\n```\n\n```text\nbrew link rabbitmq\n```\n\n```text\nbrew services start rabbitmq\n```\n\n========================================\n\nComments:\n- After editing `.zshrc`, did you start a new shell or re-`source` the file?\n- doh.. apparently I forgot to run `brew link rabbitmq` after installation. sorry.","metadata":{"transformedAt":"2026-08-18T18:33:20.166Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":78,"estimatedTokens":357}}487{"id":"stack-43332913","source":"stackoverflow","questionId":43332913,"title":"Can I iterate through queues using the RabbitMQ .NET Client?","tags":["c#","rabbitmq"],"text":"Title: Can I iterate through queues using the RabbitMQ .NET Client?\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'd like a way to iterate through existing queues on a rabbit server's virtual host, and output the number of messages in the queues, without hardcoding the queue names into my C# code.\n\nHere's an example of getting the number of messages in a queue by hardcoding the queue value, using the RabbitMQ .NET Client:\n\n```\nusing System;\nusing RabbitMQ.Client;\n\nnamespace RabbitMonitor\n{\n class Program\n {\n static void Main(string[] args)\n {\n var factory = new ConnectionFactory()\n {\n HostName = \"\",\n UserName = \"\",\n Password = \"\",\n VirtualHost = \"\",\n Port = 5672\n };\n\n var queueNameMessageCount = 0;\n\n using (var connection = factory.CreateConnection())\n using (var channel = connection.CreateModel())\n {\n queueNameMessageCount = channel.MessageCount(\"\");\n }\n }\n }\n}\n```\n\nIs there a way I can get a collection of queues / queue names that are on a given virtual host, using the RabbitMQ .NET Client?\n\nRelated: is there a way for be to get a collection of virtual hosts/virtual host names on a server, using the RabbitMQ .NET Client?\n\n========================================\n\nCode:\n```text\nusing System;\nusing RabbitMQ.Client;\n\nnamespace RabbitMonitor\n{\n class Program\n {\n static void Main(string[] args)\n {\n var factory = new ConnectionFactory()\n {\n HostName = \"<HostName>\",\n UserName = \"<UserName>\",\n Password = \"<Password>\",\n VirtualHost = \"<VirtualHost>\",\n Port = 5672\n };\n\n var queueNameMessageCount = 0;\n\n using (var connection = factory.CreateConnection())\n using (var channel = connection.CreateModel())\n {\n queueNameMessageCount = channel.MessageCount(\"<QueueName>\");\n }\n }\n }\n}\n```\n\n========================================\n\nComments:\n- While I haven't found a way to do it through the .NET client, I have found what I was looking for by looking at the rest api directly: cdn.rawgit.com/rabbitmq/rabbitmq-management/rabbitmq_v3_6_9/‌​…","metadata":{"transformedAt":"2026-08-18T18:33:20.166Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":82,"estimatedTokens":547}}488{"id":"stack-49226659","source":"stackoverflow","questionId":49226659,"title":"Swoole with RabbitMQ","tags":["php","sockets","websocket","rabbitmq","swoole"],"text":"Title: Swoole with RabbitMQ\nTags: php, sockets, websocket, rabbitmq, swoole\nSource: Stack Overflow\n\nQuestion:\nI'm trying to send some data from php application to the user's browser using websockets. Therefore I've decided to use Swoole in combination with RabbitMQ.\n\nIt's the first time I'm working with websockets and after reading some posts about Socket.IO, Ratchet, etc. I've decided to halt on Swoole because it's written in C and handy to use with php.\n\nThis is how I understood the idea of enabling data transfer using websockets: \n1) Start RabbitMQ worker and Swoole server in CLI\n2) php application sends data to RabbitMQ\n3) RabbitMQ sends message with data to worker\n4) Worker receives message with data + establishes socket connection with Swoole socket server.\n5) Swoole server broadcasts data to all connections\n\nThe question is how to bind Swoole socket server with RabbitMQ? Or how to make RabbitMQ to establish connection with Swoole and send data to it?\n\nHere is the code:\n\nSwoole server (swoole_sever.php)\n\n```\n$server = new \\swoole_websocket_server(\"0.0.0.0\", 2345, SWOOLE_BASE);\n\n$server->on('open', function(\\Swoole\\Websocket\\Server $server, $req)\n{\n echo \"connection open: {$req->fd}\\n\";\n});\n\n$server->on('message', function($server, \\Swoole\\Websocket\\Frame $frame)\n{\n echo \"received message: {$frame->data}\\n\";\n $server->push($frame->fd, json_encode([\"hello\", \"world\"]));\n});\n\n$server->on('close', function($server, $fd)\n{\n echo \"connection close: {$fd}\\n\";\n});\n\n$server->start();\n```\n\nWorker which receives message from RabbitMQ, then makes connection to Swoole and broadcasts the message via socket connection (worker.php)\n\n```\n$connection = new AMQPStreamConnection('0.0.0.0', 5672, 'guest', 'guest');\n$channel = $connection->channel();\n\n$channel->queue_declare('task_queue', false, true, false, false);\n\necho ' [*] Waiting for messages. To exit press CTRL+C', \"\\n\";\n\n$callback = function($msg){\n echo \" [x] Received \", $msg->body, \"\\n\";\n sleep(substr_count($msg->body, '.'));\n echo \" [x] Done\", \"\\n\";\n $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);\n\n // Here I'm trying to make connection to Swoole server and sernd data\n $cli = new \\swoole_http_client('0.0.0.0', 2345);\n\n $cli->on('message', function ($_cli, $frame) {\n var_dump($frame);\n });\n\n $cli->upgrade('/', function($cli)\n {\n $cli->push('This is the message to send to Swoole server');\n $cli->close();\n });\n};\n\n$channel->basic_qos(null, 1, null);\n$channel->basic_consume('task_queue', '', false, false, false, false, $callback);\n\nwhile(count($channel->callbacks)) {\n $channel->wait();\n}\n\n$channel->close();\n$connection->close();\n```\n\nNew task where the message will be send to RabbitMQ (new_task.php):\n\n```\n$connection = new AMQPStreamConnection('0.0.0.0', 5672, 'guest', 'guest');\n$channel = $connection->channel();\n\n$channel->queue_declare('task_queue', false, true, false, false);\n\n$data = implode(' ', array_slice($argv, 1));\nif(empty($data)) $data = \"Hello World!\";\n$msg = new AMQPMessage($data,\n array('delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT)\n);\n\n$channel->basic_publish($msg, '', 'task_queue');\n\necho \" [x] Sent \", $data, \"\\n\";\n\n$channel->close();\n$connection->close();\n```\n\nAfter starting both swoole server and worker I'm triggering new_task.php from command line:\n\n```\nphp new_task.php\n```\n\nIn command line prompt where a RabbitMQ Worker is running (worker.php) I can see that a message is delivered to the worker (\"[x] Received Hello World!\" message is appearing). \n\nHowever in command line prompt where Swoole server is running happens nothing.\n\nSo the questions are:\n1) Is the idea of this approach right?\n2) What am I doing wrong?\n\n========================================\n\nCode:\n```text\n$server = new \\swoole_websocket_server(\"0.0.0.0\", 2345, SWOOLE_BASE);\n\n$server->on('open', function(\\Swoole\\Websocket\\Server $server, $req)\n{\n echo \"connection open: {$req->fd}\\n\";\n});\n\n$server->on('message', function($server, \\Swoole\\Websocket\\Frame $frame)\n{\n echo \"received message: {$frame->data}\\n\";\n $server->push($frame->fd, json_encode([\"hello\", \"world\"]));\n});\n\n$server->on('close', function($server, $fd)\n{\n echo \"connection close: {$fd}\\n\";\n});\n\n$server->start();\n```\n\n```text\n$connection = new AMQPStreamConnection('0.0.0.0', 5672, 'guest', 'guest');\n$channel = $connection->channel();\n\n$channel->queue_declare('task_queue', false, true, false, false);\n\necho ' [*] Waiting for messages. To exit press CTRL+C', \"\\n\";\n\n$callback = function($msg){\n echo \" [x] Received \", $msg->body, \"\\n\";\n sleep(substr_count($msg->body, '.'));\n echo \" [x] Done\", \"\\n\";\n $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);\n\n\n // Here I'm trying to make connection to Swoole server and sernd data\n $cli = new \\swoole_http_client('0.0.0.0', 2345);\n\n $cli->on('message', function ($_cli, $frame) {\n var_dump($frame);\n });\n\n $cli->upgrade('/', function($cli)\n {\n $cli->push('This is the message to send to Swoole server');\n $cli->close();\n });\n};\n\n$channel->basic_qos(null, 1, null);\n$channel->basic_consume('task_queue', '', false, false, false, false, $callback);\n\nwhile(count($channel->callbacks)) {\n $channel->wait();\n}\n\n$channel->close();\n$connection->close();\n```\n\n```text\n$connection = new AMQPStreamConnection('0.0.0.0', 5672, 'guest', 'guest');\n$channel = $connection->channel();\n\n$channel->queue_declare('task_queue', false, true, false, false);\n\n$data = implode(' ', array_slice($argv, 1));\nif(empty($data)) $data = \"Hello World!\";\n$msg = new AMQPMessage($data,\n array('delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT)\n);\n\n$channel->basic_publish($msg, '', 'task_queue');\n\necho \" [x] Sent \", $data, \"\\n\";\n\n$channel->close();\n$connection->close();\n```\n\n```text\nphp new_task.php\n```\n\n```text\n$client = new WebSocketClient('0.0.0.0', 2345);\n$client->connect();\n$client->send('This is the message to send to Swoole server');\n$recv = $client->recv();\nprint_r($recv);\n$client->close();\n```\n\n```text\ngo(function () {\n $client = new WebSocketClient('0.0.0.0', 2345);\n $client->connect();\n $client->send('This is the message to send to Swoole server');\n $recv = $client->recv();\n print_r($recv);\n $client->close();\n});\n```\n\n```text\nworker.php\n```\n\n```text\nswoole_http_client\n```\n\n```text\nWebSocketClient\n```\n\n========================================\n\nComments:\n- I never used this `swoole` but I have used rabbit, just a cursory look a their documentation and it seems like you are missing a few things github.com/swoole/swoole-src/blob/master/examples/… such as `$cli->setData(...)` and `$cli->execute(...)`\n- I would suggest breaking things down, for example write a command line php script to test sending a simple message to this `swoole` then once you get that working integrate the RabbitMq stuff, that way you can isolate the issues.\n- I've already done that. I can have a socket connection using Swoole and send data in two ways. I can also send message to Worker using RabbitMQ. So, the only problem I have is using RabbitMQ with Swoole together.\n- Make sure you worker has the proper permissions then, that's the only thing I can think of. Perhaps as root you can connect to `swoole` but the worker cannot. There should be no difference if the code works separate so it must be environment.\n- Strange thing I've noticed. The steps I'm doing: 1) Start Swoole server 2) Start Worker 3) execute new_task.php 4) Got message in worker.php 5) Nothing to see in swoole_server.php 6) Manually stop worker.php running in terminal 7) in terminal window of swoole_server.php I get message: \"connection close: 1\".\n- So it seems like connection is being established but no 'message' event is triggered in $cli->on('message', function ($_cli, $frame)\n- @ArtisticPhoenix, the worker is connected with username \"guest\". I've checked the permissions by command \"sudo rabbitmqctl list_user_permissions guest\". And the result is: / .* .* .*","metadata":{"transformedAt":"2026-08-18T18:33:20.166Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":9,"totalLines":252,"estimatedTokens":1999}}489{"id":"stack-19690849","source":"stackoverflow","questionId":19690849,"title":"Preventing task from running on certain thread","tags":["c#","multithreading","asynchronous","task-parallel-library","rabbitmq"],"text":"Title: Preventing task from running on certain thread\nTags: c#, multithreading, asynchronous, task-parallel-library, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have been struggling a bit with some async await stuff. I am using RabbitMQ for sending/receiving messages between some programs.\n\nAs a bit of background, the RabbitMQ client uses 3 or so threads that I can see: A connection thread and two heartbeat threads. Whenever a message is received via TCP, the connection thread handles it and calls a callback which I have supplied via an interface. The documentation says that it is best to avoid doing lots of work during this call since its done on the same thread as the connection and things need to continue on. They supply a `QueueingBasicConsumer` which has a blocking 'Dequeue' method which is used to wait for a message to be received.\n\nI wanted my consumers to be able to actually release their thread context during this waiting time so somebody else could do some work, so I decided to use async/await tasks. I wrote an `AwaitableBasicConsumer` class which uses `TaskCompletionSource`s in the following fashion:\n\n**I have an awaitable Dequeue method:**\n\n```\npublic Task DequeueAsync(CancellationToken cancellationToken)\n{\n //we are enqueueing a TCS. This is a \"read\"\n rwLock.EnterReadLock();\n\n try\n {\n TaskCompletionSource tcs = new TaskCompletionSource();\n\n //if we are cancelled before we finish, this will cause the tcs to become cancelled\n cancellationToken.Register(() =>\n {\n tcs.TrySetCanceled();\n });\n\n //if there is something in the undelivered queue, the task will be immediately completed\n //otherwise, we queue the task into deliveryTCS\n if (!TryDeliverUndelivered(tcs))\n deliveryTCS.Enqueue(tcs);\n }\n\n return tcs.Task;\n }\n finally\n {\n rwLock.ExitReadLock();\n }\n}\n```\n\n**The callback which the rabbitmq client calls fulfills the tasks:** This is called from the context of the AMQP Connection thread\n\n```\npublic void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, RabbitMQ.Client.IBasicProperties properties, byte[] body)\n{\n //we want nothing added while we remove. We also block until everybody is done.\n rwLock.EnterWriteLock();\n try\n {\n RabbitMQ.Client.Events.BasicDeliverEventArgs e = new RabbitMQ.Client.Events.BasicDeliverEventArgs(consumerTag, deliveryTag, redelivered, exchange, routingKey, properties, body);\n\n bool sent = false;\n TaskCompletionSource tcs;\n while (deliveryTCS.TryDequeue(out tcs))\n {\n //once we manage to actually set somebody's result, we are done with handling this\n if (tcs.TrySetResult(e))\n {\n sent = true;\n break;\n }\n }\n\n //if nothing was sent, we queue up what we got so that somebody can get it later.\n /**\n * Without the rwlock, this logic would cause concurrency problems in the case where after the while block completes without sending, somebody enqueues themselves. They would get the\n * next message and the person who enqueues after them would get the message received now. Locking prevents that from happening since nobody can add to the queue while we are\n * doing our thing here.\n */\n if (!sent)\n {\n undelivered.Enqueue(e);\n }\n }\n finally\n {\n rwLock.ExitWriteLock();\n }\n}\n```\n\n`rwLock` is a `ReaderWriterLockSlim`. The two queues (`deliveryTCS` and `undelivered`) are ConcurrentQueues.\n\n**The problem:**\n\nEvery once in a while, the method that awaits the dequeue method throws an exception. This would not normally be an issue since that method is also `async` and so it enters the \"Exception\" completion state that tasks enter. The problem comes in the situation where the task that calls `DequeueAsync` is resumed after the await on the AMQP Connection thread that the RabbitMQ client creates. Normally I have seen tasks resume onto the main thread or one of the worker threads floating around. However, when it resumes onto the AMQP thread and an exception is thrown, everything stalls. The task *does not* enter its \"Exception state\" and the AMQP Connection thread is left saying that it is executing the method that had the exception occur.\n\nMy main confusion here is why this doesn't work:\n\n```\nvar task = c.RunAsync(); //Here is the `RunAsync` method, set up for the test:\n\n```\npublic async Task RunAsync()\n{\n using (var channel = this.Connection.CreateModel())\n {\n ...\n AwaitableBasicConsumer consumer = new AwaitableBasicConsumer(channel);\n var result = consumer.DequeueAsync(this.CancellationToken);\n\n //wait until we find something to eat\n await result;\n\n throw new NotImplementeException(); //Reading what I have written, I see that I may not have explained my problem very well. If clarification is needed, just ask.\n\nMy solutions that I have come up with are as follows:\n\n- Remove all Async/Await code and just use straight up threads and block. Performance will be decreased, but at least it won't stall sometimes\n\n- Somehow exempt the AMQP threads from being used for resuming tasks. I assume that they were sleeping or something and then the default `TaskScheduler` decided to use them. If I could find a way to tell the task scheduler that those threads are off limits, that would be great.\n\n**Does anyone have an explanation for why this is happening or any suggestions to solving this?** Right now I am removing the async code just so that the program is reliable, but I really want to understand what is going on here.\n\n========================================\n\nCode:\n```text\npublic Task<RabbitMQ.Client.Events.BasicDeliverEventArgs> DequeueAsync(CancellationToken cancellationToken)\n{\n //we are enqueueing a TCS. This is a \"read\"\n rwLock.EnterReadLock();\n\n try\n {\n TaskCompletionSource<RabbitMQ.Client.Events.BasicDeliverEventArgs> tcs = new TaskCompletionSource<RabbitMQ.Client.Events.BasicDeliverEventArgs>();\n\n //if we are cancelled before we finish, this will cause the tcs to become cancelled\n cancellationToken.Register(() =>\n {\n tcs.TrySetCanceled();\n });\n\n //if there is something in the undelivered queue, the task will be immediately completed\n //otherwise, we queue the task into deliveryTCS\n if (!TryDeliverUndelivered(tcs))\n deliveryTCS.Enqueue(tcs);\n }\n\n return tcs.Task;\n }\n finally\n {\n rwLock.ExitReadLock();\n }\n}\n```\n\n```text\npublic void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, RabbitMQ.Client.IBasicProperties properties, byte[] body)\n{\n //we want nothing added while we remove. We also block until everybody is done.\n rwLock.EnterWriteLock();\n try\n {\n RabbitMQ.Client.Events.BasicDeliverEventArgs e = new RabbitMQ.Client.Events.BasicDeliverEventArgs(consumerTag, deliveryTag, redelivered, exchange, routingKey, properties, body);\n\n bool sent = false;\n TaskCompletionSource<RabbitMQ.Client.Events.BasicDeliverEventArgs> tcs;\n while (deliveryTCS.TryDequeue(out tcs))\n {\n //once we manage to actually set somebody's result, we are done with handling this\n if (tcs.TrySetResult(e))\n {\n sent = true;\n break;\n }\n }\n\n //if nothing was sent, we queue up what we got so that somebody can get it later.\n /**\n * Without the rwlock, this logic would cause concurrency problems in the case where after the while block completes without sending, somebody enqueues themselves. They would get the\n * next message and the person who enqueues after them would get the message received now. Locking prevents that from happening since nobody can add to the queue while we are\n * doing our thing here.\n */\n if (!sent)\n {\n undelivered.Enqueue(e);\n }\n }\n finally\n {\n rwLock.ExitWriteLock();\n }\n}\n```\n\n```text\nvar task = c.RunAsync(); //<-- This method awaits the DequeueAsync and throws an exception afterwards\n\nConsumerTaskState state = new ConsumerTaskState()\n{\n Connection = connection,\n CancellationToken = cancellationToken\n};\n\n//if there is a problem, we execute our faulted method\n//PROBLEM: If task fails when its resumed onto the AMQP thread, this method is never called\ntask.ContinueWith(this.OnFaulted, state, TaskContinuationOptions.OnlyOnFaulted);\n```\n\n```text\npublic async Task RunAsync()\n{\n using (var channel = this.Connection.CreateModel())\n {\n ...\n AwaitableBasicConsumer consumer = new AwaitableBasicConsumer(channel);\n var result = consumer.DequeueAsync(this.CancellationToken);\n\n //wait until we find something to eat\n await result;\n\n throw new NotImplementeException(); //<-- the test exception. Normally this causes OnFaulted to be called, but sometimes, it stalls\n ...\n } //<-- This is where the debugger says the thread is sitting at when I find it in the stalled state\n}\n```\n\n```text\nQueueingBasicConsumer\n```\n\n```text\nAwaitableBasicConsumer\n```\n\n```text\nTaskCompletionSource\n```\n\n```text\nrwLock\n```\n\n```text\nReaderWriterLockSlim\n```\n\n```text\ndeliveryTCS\n```\n\n```text\nundelivered\n```\n\n```text\nasync\n```\n\n```text\nDequeueAsync\n```\n\n```text\nRunAsync\n```\n\n```text\nTaskScheduler\n```\n\n```text\nprivate readonly BufferBlock<RabbitMQ.Client.Events.BasicDeliverEventArgs> _queue = new BufferBlock<RabbitMQ.Client.Events.BasicDeliverEventArgs>();\n\npublic void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, RabbitMQ.Client.IBasicProperties properties, byte[] body)\n{\n RabbitMQ.Client.Events.BasicDeliverEventArgs e = new RabbitMQ.Client.Events.BasicDeliverEventArgs(consumerTag, deliveryTag, redelivered, exchange, routingKey, properties, body);\n _queue.Post(e);\n}\n\npublic Task<RabbitMQ.Client.Events.BasicDeliverEventArgs> DequeueAsync(CancellationToken cancellationToken)\n{\n return _queue.ReceiveAsync(cancellationToken);\n}\n```\n\n```text\nasync\n```\n\n```text\nawait\n```\n\n```text\nSynchronizationContext\n```\n\n```text\nTaskScheduler\n```\n\n```text\nSynchronizationContext.Current\n```\n\n```text\nnull\n```\n\n```text\nasync\n```\n\n```text\nTaskContinuationOptions.ExecuteSynchronously\n```\n\n```text\nasync\n```\n\n```text\nawait\n```\n\n```text\nSynchronizationContext\n```\n\n```text\nTaskScheduler\n```\n\n```text\nTrySetResult\n```\n\n```text\nasync\n```\n\n```text\nBufferBlock<T>\n```\n\n```text\nasync\n```\n\n```text\nAsyncProducerConsumerQueue\n```\n\n```text\nBufferBlock<T>\n```\n\n```text\nDequeueAsync\n```\n\n```text\nDequeueAsync\n```\n\n```text\nBufferBlock\n```\n\n```text\nActionBlock\n```\n\n========================================\n\nComments:\n- *I wanted my consumers to be able to actually release their thread context during this waiting time*. Are you saying that the waiting threads blocked other threads from executing? That seems . . . odd.\n- The RabbitMQ client provides a \"QueuingBasicConsumer\" which blocks the caller until it receives something. If I were to be using raw threads instead of tasks, that thread would be sleeping and not doing anything. I wanted to avoid this blocking so that the underlying thread could do another task during that time (increase throughput), so I wrote my awaitable consumer which uses tasks instead of actually blocking the calling thread.\n- I understood that part. What I don't understand is the problem that you're trying to solve. If the `QueuingBasicConsumer` is competently written, it's a non-busy wait and the blocked thread won't consume CPU cycles while waiting and therefore won't affect any other work that's being done. Just dedicate those threads to RabbitMQ and use other threads for the other jobs.\n- I wanted to be able have 1000 listeners while not spawning 1000 listening threads. Their thread blocking method would make me need to spawn just as many threads as I had receivers. I thought it would be nice if I could have my number of receiving channels greater than the number of threads I was running. Instead of spawning 1000 threads, I would spawn 1000 tasks instead which could possibly be running on less than 1000 threads since many of them could be awaiting a message delivery. I am under the (possibly mistaken) impression that tasks are cheaper than threads in terms of system resources.\n- The real issue here is that an exception thrown by a task which ended up being resumed onto the AMQP Connection thread caused the task to never be completed in any way (excepted, complete, cancelled, etc) and caused the AMQP Connection thread to hang in general. So, basically it looks like I am unable to mix the RabbitMQ client with the Task Parallel Library.\n- I could have a dedicated thread just picking up things from rabbitmq and throwing them into some processor, but I needed a way to either Ack or Nack the message *after* it had been processed and that operation has to happen on the same receiving channel. These channels aren't thread safe either, so I can't just pass them along with the messages unless I used `lock` or something and that could lead to a race if I did things wrong and also gives a slight bottleneck (not much of a bottleneck, however).\n- I understand now the problem you're trying to solve. I have no experience orchestrating workflows that way. Sounds like a rather difficult way to do things, trying to persist the state *in code* while waiting for the next message. That's not the typical way I've seen things done, but perhaps somebody else has more experience with that kind of thing.\n- `TaskCompletionSource.TrySetResult()` usually also executes any code that was `await`ing the `Task`. Could this be causing the problem you're observing?\n- Wait...so TaskCompletionSource.TrySetResult will execute the awaiting code synchronously on the thread setting the result without switching back to the original context?\n- I did use the ReaderWriterLockSlim in a way that probably wasn't intended. I used to it say that multiple people could DequeueAsync, but while an event is being handled, nobody should touch either queue except the handler. It wasn't necessary until I added the 'undelivered' queue so I wouldn't miss messages that were received before a call to DequeueAsync. Am I using it wrong? Here is the full AwaitableBasicConsumer code: gist.github.com/kcuzner/7242836\n- OK, it looks like it would work. But it doesn't get you much over a simple `lock`. I do see another problem: `cancellationToken.Register` can execute its delegate inline, which would cause `SetResult` to fail. Yet another obscure corner condition that I'd rather leave to Stephen Toub. :)\n- One more followup question: RabbitMQ creates its threads in the standard fashion with just a `new Thread(new ThreadStart(...`. Are these threads eligible to have tasks run on them or are they going to be left alone when sleeping? If I can know that tasks won't be run on those threads (unless called synchronously, like mine were), then I can probably just use the `BufferBlock` (which I didn't know about before now) and not have to worry about using TPL and RabbitMQ in the same application.\n- Tasks will only be scheduled to thread pool threads by default. What you were seeing before was `SetResult` deciding to execute the continuation inline instead of scheduling it. This will not happen with `BufferBlock`.","metadata":{"transformedAt":"2026-08-18T18:33:20.166Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":38,"totalLines":386,"estimatedTokens":3813}}490{"id":"stack-21759847","source":"stackoverflow","questionId":21759847,"title":"Node-amqp - rejecting message after X attempts","tags":["node.js","rabbitmq","node-amqp"],"text":"Title: Node-amqp - rejecting message after X attempts\nTags: node.js, rabbitmq, node-amqp\nSource: Stack Overflow\n\nQuestion:\nHow do I implement mechanism which reject message after few configurable requeue attempts?\n\nIn other words, if I'm subscribing to a queue I want to guaranty that same message does not redelivered more then X times.\n\nMy code sample:\n\n```\nq.subscribe({ack: true}, function(data,headers,deliveryInfo,message) {\n try{\n doSomething(data);\n } catch(e) {\n message.reject(true);\n }\n}\n```\n\n========================================\n\nTop Answer:\nOne possible solution is to hash the message using some sort of hash function you define, then check a cache object for that hash. If it is there, add one to the cache up to the configurable max, and if it's not there, set it to 1. Here's a quick and dirty prototype for you (note that the `mcache` object should be in scope for all subscribers):\n\n```\nvar mcache = {}, maxRetries = 3;\n\nq.subscribe({ack: true}, function(data,headers,deliveryInfo,message) {\n var messagehash = hash(message);\n if(mcache[messagehash] === undefined){\n mcache[messagehash] = 0;\n }\n if(mcache[messagehash] > maxRetries) {\n q.shift(true,false); //reject true, requeue false (discard message)\n delete mcache[messagehash]; //don't leak memory\n } else {\n try{\n doSomething(data);\n q.shift(false); //reject false\n delete mcache[messagehash]; //don't leak memory\n } catch(e) {\n mcache[messagehash]++;\n q.shift(true,true); //reject true, requeue true\n }\n }\n}\n```\n\nif the message has a GUID, you can simply return that in the hash function.\n\n========================================\n\nCode:\n```text\nq.subscribe({ack: true}, function(data,headers,deliveryInfo,message) {\n try{\n doSomething(data);\n } catch(e) {\n message.reject(true);\n }\n}\n```\n\n```text\nq.subscribe({ack: true}, function () {\n var numOfRetries = 0;\n var args = arguments;\n var self = this;\n var promise = doWork.apply(self, args);\n for (var numOfRetries = 0; numOfRetries < MAX_RETRIES; numOfRetries++) {\n promise = promise.fail(function () { return doWork.apply(self, args); });\n }\n\n promise.fail(function () {\n sendMessageToErrorQueue.apply(self, args);\n rejectMessage.apply(self, args);\n })\n})\n```\n\n```text\nvar mcache = {}, maxRetries = 3;\n\nq.subscribe({ack: true}, function(data,headers,deliveryInfo,message) {\n var messagehash = hash(message);\n if(mcache[messagehash] === undefined){\n mcache[messagehash] = 0;\n }\n if(mcache[messagehash] > maxRetries) {\n q.shift(true,false); //reject true, requeue false (discard message)\n delete mcache[messagehash]; //don't leak memory\n } else {\n try{\n doSomething(data);\n q.shift(false); //reject false\n delete mcache[messagehash]; //don't leak memory\n } catch(e) {\n mcache[messagehash]++;\n q.shift(true,true); //reject true, requeue true\n }\n }\n}\n```\n\n```text\nmcache\n```\n\n========================================\n\nComments:\n- Possible duplicate stackoverflow.com/q/17654475\n- How are you identifying messages uniquely? Do you have your own ID in the message payload?\n- In my case (but I'm not the OP) - yes, messages can be identified by their UUID. Alas, it's not enough to have a simple counter in the subscriber, as I have multiple subscribers to the same queue to balance work, and number of retries should be global, not local to each worker.\n- This introduces the cache as single point of failure. I'd like to have a solution completely using RabbitMQ techniques.\n- In what scenario do you envision the cache failing?\n- The cache (physically) needs to run on any server. What if this server goes down? So you need the cache to be highly available and fail-safe, and this increases the required effort. If there was any possibility to use RabbitMQ itself for it, I'd highly favor such a solution.\n- Definitely something that causes concern, but if your receiver goes down, do you really want the messages to be dropped completely? Setting `ack` to true implies the messages need to be received.","metadata":{"transformedAt":"2026-08-18T18:33:20.166Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":120,"estimatedTokens":1002}}491{"id":"stack-20857712","source":"stackoverflow","questionId":20857712,"title":"Django-celery and RabbitMQ not executing tasks","tags":["django","rabbitmq","celery","message-queue","django-celery"],"text":"Title: Django-celery and RabbitMQ not executing tasks\nTags: django, rabbitmq, celery, message-queue, django-celery\nSource: Stack Overflow\n\nQuestion:\nWe've got a **Django 1.3** application with **django-celery 2.5.5** that's been running fine in production for month, but all of the sudden one of the celery tasks are failing to execute now.\n\nThe RabbitMQ broker and Celery workers are running on a separate machine and celeryconfig.py is configured to use that particular RabbitMQ instance as the backend.\n\nOn the application server I tried to manually fire off the celery task via `python manage.py shell`.\n\nThe actual task is called like so: \n\n```\n>>> result = tasks.runCodeGeneration.delay(code_generation, None)\n>>> result\n\n>>> result.state\n'PENDING'\n```\n\nIt returns an `AsyncResult` as expected but its status is forever `'PENDING'`.\n\nTo see if the RabbitMQ broker received the message I ran the following:\n\n```\n$ rabbitmqctl list_queues name messages messages_ready messages_unacknowledged | grep 853daa\n853daa7b8be54a25a1d01552b38a0d21 0 0 0\n```\n\nI'm not sure what this means, RabbitMQ certainly seems to receive some sort of request, otherwise how else could a queue have been created for the task with id: 853daa7b8be54a25a1d01552b38a0d21. It just doesn't seem to hold any messages?\n\nI've tried restarting both Celery and RabbitMQ and the problem persists. \n\nCelery is run like so: `$ python /home/[project]/console/manage.py celeryd -B -c2 --loglevel=INFO`\n\nNote that the celerybeat/scheduled tasks seem to be running just fine.\n\n[EDIT]:\nThere is no RabbitMQ configuration as it is being inlined by the init.d script:\n`/usr/lib/erlang/erts-5.8.5/bin/beam.smp -W w -K true -A30 -P 1048576 -- -root /usr/lib/erlang -progname erl -- -home /var/lib/rabbitmq -- -noshell -noinput -sname rabbit@hostname -boot /var/lib/rabbitmq/mnesia/rabbit@hostname-plugins-expand/rabbit -kernel inet_default_connect_options [{nodelay,true}] -sasl errlog_type error -sasl sasl_error_logger false -rabbit error_logger {file,\"/var/log/rabbitmq/rabbit@hostname.log\"} -rabbit sasl_error_logger {file,\"/var/log/rabbitmq/rabbit@hostname-sasl.log\"} -os_mon start_cpu_sup true -os_mon start_disksup false -os_mon start_memsup false -mnesia dir \"/var/lib/rabbitmq/mnesia/rabbit@hostname\"`\n\n[EDIT2]:\nHere's the celeryconfig we're using for the workers. The same config is used for the producer except of course localhost is changed to the box with RabbitMQ broker on it.\n\n```\nfrom datetime import timedelta\n\nBROKER_HOST = \"localhost\"\n\nBROKER_PORT = 5672\nBROKER_USER = \"console\"\nBROKER_PASSWORD = \"console\"\n\nBROKER_VHOST = \"console\"\nBROKER_URL = \"amqp://guest:guest@localhost:5672//\"\n\nCELERY_RESULT_BACKEND = \"amqp\"\n\nCELERY_IMPORTS = (\"tasks\", )\n\nCELERYD_HIJACK_ROOT_LOGGER = True\nCELERYD_LOG_FORMAT = \"[%(asctime)s: %(levelname)s/%(processName)s/%(name)s] %(message)s\"\n\nCELERYBEAT_SCHEDULE = {\n \"runs-every-60-seconds\": {\n \"task\": \"tasks.runMapReduceQueries\",\n \"schedule\": timedelta(seconds=60),\n \"args\": ()\n },\n}\n```\n\n[EDIT3]:\nOur infrastructure is set up like number 2 below:\n\n========================================\n\nCode:\n```text\n>>> result = tasks.runCodeGeneration.delay(code_generation, None)\n>>> result\n<AsyncResult: 853daa7b-8be5-4a25-a1d0-1552b38a0d21>\n>>> result.state\n'PENDING'\n```\n\n```text\n$ rabbitmqctl list_queues name messages messages_ready messages_unacknowledged | grep 853daa\n853daa7b8be54a25a1d01552b38a0d21 0 0 0\n```\n\n```text\nfrom datetime import timedelta\n\nBROKER_HOST = \"localhost\"\n\nBROKER_PORT = 5672\nBROKER_USER = \"console\"\nBROKER_PASSWORD = \"console\"\n\nBROKER_VHOST = \"console\"\nBROKER_URL = \"amqp://guest:guest@localhost:5672//\"\n\nCELERY_RESULT_BACKEND = \"amqp\"\n\nCELERY_IMPORTS = (\"tasks\", )\n\nCELERYD_HIJACK_ROOT_LOGGER = True\nCELERYD_LOG_FORMAT = \"[%(asctime)s: %(levelname)s/%(processName)s/%(name)s] %(message)s\"\n\n\nCELERYBEAT_SCHEDULE = {\n \"runs-every-60-seconds\": {\n \"task\": \"tasks.runMapReduceQueries\",\n \"schedule\": timedelta(seconds=60),\n \"args\": ()\n },\n}\n```\n\n```text\npython manage.py shell\n```\n\n```text\nAsyncResult\n```\n\n```text\n'PENDING'\n```\n\n```text\n$ python /home/[project]/console/manage.py celeryd -B -c2 --loglevel=INFO\n```\n\n```text\n/usr/lib/erlang/erts-5.8.5/bin/beam.smp -W w -K true -A30 -P 1048576 -- -root /usr/lib/erlang -progname erl -- -home /var/lib/rabbitmq -- -noshell -noinput -sname rabbit@hostname -boot /var/lib/rabbitmq/mnesia/rabbit@hostname-plugins-expand/rabbit -kernel inet_default_connect_options [{nodelay,true}] -sasl errlog_type error -sasl sasl_error_logger false -rabbit error_logger {file,\"/var/log/rabbitmq/rabbit@hostname.log\"} -rabbit sasl_error_logger {file,\"/var/log/rabbitmq/rabbit@hostname-sasl.log\"} -os_mon start_cpu_sup true -os_mon start_disksup false -os_mon start_memsup false -mnesia dir \"/var/lib/rabbitmq/mnesia/rabbit@hostname\"\n```\n\n========================================\n\nComments:\n- If I understand you correctly, you have only one task that is not executing while all the rest works fine ? If this is the case could be that the task is scheduled on a queue that is never consumed ?\n- That is correct. Is there a way I can verify that what you say is happening? And what can I do to fix it?\n- If should check and maybe here the 2 celeryconfig, the one on the servers where the worker are running and the one that you are using from console when scheduling the task. As you are using django-celery than the celeryconfig is the Django settings itself. Another thing you can do is to check rabbitmq management web console for queues that are always growing and never consumed, you can even check all the consumers subscribed to a queue. rabbitmq.com/management.html\n- Thanks for the help. However, using management web console we can see that a queue is created and is in \"Active\" state but there are no messages in it...\n- Could be that messages are consumed immediately but this should be evident from other statistics. If you really want some help I suggest you to paste the settings, off course not with real IP and password :-)\n- Please see updated question. Any more insights you have will be greatly appreciated.\n- Honestly it's hard to figure out. From the management console of RabbitMQ you should see what happen when scheduling the message from console. Shut down all consumers and just try to produce some messages manually from python console and see on which queue they fall on rabbitMQ. When you can prove that the message is in fact scheduled on the right queue than you can move to understand why is not being consumed.\n- Just did as you suggested and a queue is indeed created, but no messages are published to it ever. The queue is bound to the \"celeryresults\" exchange.\n- Well, as far as I can see from your configuration file you don't specify a different queue this means that the producer will use the default celery exchange and queue that is \"celery\", you have this queue and exchange ? (docs.celeryproject.org/en/latest/…) The exchange celeryresults is the one used to store back the results of the task not for the task itself.\n- maybe try --loglevel=DEBUG to get a little more output from celery.","metadata":{"transformedAt":"2026-08-18T18:33:20.166Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":154,"estimatedTokens":1785}}492{"id":"stack-32055259","source":"stackoverflow","questionId":32055259,"title":"Ensure that AMQP exchange exists before publishing a message to it","tags":["java","rabbitmq","amqp"],"text":"Title: Ensure that AMQP exchange exists before publishing a message to it\nTags: java, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\n### Problem\n\nA Java application uses RabbitMQ and client library `com.rabbitmq:amqp-client` to connect to it. The application declares an AMQP exchange during initialization and periodically publishes messages to it. \n\n**If that exchange gets removed for some reason the application cannot publish messages to it and the AMQP channel gets automatically closed by the library**. So any subsequent publishes (even after the exchange is re-created) fail with such exception:\n\n```\nException in thread \"main\" com.rabbitmq.client.AlreadyClosedException: channel is already closed due to channel error; protocol method: #method(reply-code=404, reply-text=NOT_FOUND - no exchange 'logs' in vhost '/', class-id=60, method-id=40)\nat com.rabbitmq.client.impl.AMQChannel.ensureIsOpen(AMQChannel.java:195)\nat com.rabbitmq.client.impl.AMQChannel.transmit(AMQChannel.java:296)\nat com.rabbitmq.client.impl.ChannelN.basicPublish(ChannelN.java:648)\nat com.rabbitmq.client.impl.ChannelN.basicPublish(ChannelN.java:631)\nat com.rabbitmq.client.impl.ChannelN.basicPublish(ChannelN.java:622)\n```\n\nHow can I guarantee that the exchange does exist before publish? I see the following options.\n\n### Possible solutions\n\n### 1. Try to re-declare exchange before each publish explicitly\n\nThanks to the fact that `exchangeDeclare` is idempotent and has no effect if the exchange is already in place I could explicitly declare the exchange before any publish:\n\n```\nchannel.exchangeDeclare(EXCHANGE_NAME, \"fanout\", false, true, null);\nchannel.basicPublish(EXCHANGE_NAME, \"\", MessageProperties.PERSISTENT_TEXT_PLAIN, message);\n```\n\nThe issue with this code is that it looks stupid because most of the time the exchange is in place and the declaration is just redundant. \n\nAlso I'm still be in trouble if the exchange is deleted exactly between declaration and publish.\n\n### 2. Verify that exchange does exist via `exchangeDeclarePassive`\n\nI could use `exchangeDeclarePassive` to check that the exchange exists before publish but the following obvious method doesn't work:\n\n```\nprivate static void ensureExchangeExists(Channel channel) throws IOException {\n try {\n channel.exchangeDeclarePassive(EXCHANGE_NAME);\n } catch (Exception e) {\n channel.exchangeDeclare(EXCHANGE_NAME, \"fanout\", false, true, null);\n }\n}\n```\n\nThe problem is that if the exchange is missing, `exchangeDeclarePassive` throws the exception and the channel is closed automatically by the library. So the code in catch block cannot declare the exchange (because it tries to perform an operation on the closed channel).\n\nSo I can no longer use single AMQP channel and have to manage them in some way.\n\nAlso I'm still in trouble if the exchange is removed between declaration and publish.\n\n### 3. Catch exception upon publish\n\nYou cannot just wrap call channel.basicPublish with a try/catch block because if the exchange is missing then no exception is thrown. This answer explains what actually happens in this situation.\n\nBut you can register a `ShutdownListener` that is able to detect when a channel is closed, investigate the reason (via `cause.isInitiatedByApplication()`/`cause.getReason()`) and do the necessary action.\n\n### Question\n\nThe question is what is the best way to ensure that AMQP exchange exists before publishing a message to it and why?\n\n========================================\n\nTop Answer:\nIME, option #1 is the close to the better option.\n\nWhat I've found works best, is to have the code for a given publisher encapsulated in a way that lets me declare / re-declare the queue the first time I create the object instance. Then I can re-use the same object instance to publish messages without having to re-declare the exchange again.\n\nIf I create a new instance of the object, it will re-declare the exchange. But re-using the same instance prevents that from happening.\n\nThis strategy has worked well for me.\n\nthe other option is to pre-define and pre-declare your exchanges, queues and bindings at the app startup. that way you don't have to worry about it anymore. the downside here, is you have pre-determine all exchanges, queues and bindings... which works in some apps but not in others.\n\n========================================\n\nCode:\n```text\nException in thread \"main\" com.rabbitmq.client.AlreadyClosedException: channel is already closed due to channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'logs' in vhost '/', class-id=60, method-id=40)\nat com.rabbitmq.client.impl.AMQChannel.ensureIsOpen(AMQChannel.java:195)\nat com.rabbitmq.client.impl.AMQChannel.transmit(AMQChannel.java:296)\nat com.rabbitmq.client.impl.ChannelN.basicPublish(ChannelN.java:648)\nat com.rabbitmq.client.impl.ChannelN.basicPublish(ChannelN.java:631)\nat com.rabbitmq.client.impl.ChannelN.basicPublish(ChannelN.java:622)\n```\n\n```text\nchannel.exchangeDeclare(EXCHANGE_NAME, \"fanout\", false, true, null);\nchannel.basicPublish(EXCHANGE_NAME, \"\", MessageProperties.PERSISTENT_TEXT_PLAIN, message);\n```\n\n```text\nprivate static void ensureExchangeExists(Channel channel) throws IOException {\n try {\n channel.exchangeDeclarePassive(EXCHANGE_NAME);\n } catch (Exception e) {\n channel.exchangeDeclare(EXCHANGE_NAME, \"fanout\", false, true, null);\n }\n}\n```\n\n```text\ncom.rabbitmq:amqp-client\n```\n\n```text\nexchangeDeclare\n```\n\n```text\nexchangeDeclarePassive\n```\n\n```text\nexchangeDeclarePassive\n```\n\n```text\nexchangeDeclarePassive\n```\n\n```text\nShutdownListener\n```\n\n```text\ncause.isInitiatedByApplication()\n```\n\n```text\ncause.getReason()\n```\n\n========================================\n\nComments:\n- Thanks for your answer Derrick. The problem however is that the exchange is removed by some external party when application is running. So it may disappear at any time from the application perspective. And hence neither eager nor lazy initialization works.\n- in that case, you should go with option #1 and re-declare the exchange before sending any message. note that this will incur massive performance penalties... you should work with the team that runs the other system to fix the root of the problem, but re-declare before send should be sufficient for now\n- well, no. i take that back. you should probably use a combination of option #1 and option #3, because of the possibility of the exchange being deleted before the publish, as you noted in the original post. you should treat the missing exchange as a known failure condition, and provide a backup solution to re-try the message later, after the exchange has been recreated. this is often done with a log file or even in-memory list of messages to retry, from the publisher side of things","metadata":{"transformedAt":"2026-08-18T18:33:20.166Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":11,"totalLines":145,"estimatedTokens":1696}}493{"id":"stack-7742426","source":"stackoverflow","questionId":7742426,"title":"How to Implement Priority Queues in RabbitMQ/pika","tags":["python","rabbitmq","priority-queue","amqp","pika"],"text":"Title: How to Implement Priority Queues in RabbitMQ/pika\nTags: python, rabbitmq, priority-queue, amqp, pika\nSource: Stack Overflow\n\nQuestion:\nI am looking to implement a priority queue with RabbitMQ. The mailing list recommends to use multiple queues, each queue representing a different priority level.\n\nMy question is, how do you poll multiple queues in some prioritized order using pika (or possibly some other python library)?\n\n========================================\n\nTop Answer:\nThe accepted answer is outdated.\nFrom `rabbitmq 3.5.0` there's native support for priority queues:\n\n RabbitMQ has priority queue\n implementation in the core as of version 3.5.0. Any queue can be\n turned into a priority one using client-provided optional arguments\n\nIt's also available as of `pika 1.1.0`\n\n class pika.spec.BasicProperties(content_type=None,\n content_encoding=None, headers=None, delivery_mode=None,\n priority=None, correlation_id=None, reply_to=None, expiration=None,\n message_id=None, timestamp=None, type=None, user_id=None, app_id=None,\n cluster_id=None)\n\nThe code using this feature might look as follows:\n\n```\nchannel.basic_publish(properties=pika.BasicProperties(priority=your_priority),\n exchange=...,\n routing_key=...,\n body=...)\n```\n\n========================================\n\nCode:\n```text\nchannel.basic_publish(properties=pika.BasicProperties(priority=your_priority),\n exchange=...,\n routing_key=...,\n body=...)\n```\n\n```text\nrabbitmq 3.5.0\n```\n\n```text\npika 1.1.0\n```\n\n========================================\n\nComments:\n- as of RabbitMQ 3.5.0, the queue priority is a native feature, so the plugin is not needed anymore. see github.com/rabbitmq/rabbitmq-priority-queue .","metadata":{"transformedAt":"2026-08-18T18:33:20.166Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":58,"estimatedTokens":437}}494{"id":"stack-42372747","source":"stackoverflow","questionId":42372747,"title":"RabbitMQ and Delivery Guarantees in Distributed Database Transaction","tags":["rabbitmq","amqp","spring-amqp","spring-rabbit"],"text":"Title: RabbitMQ and Delivery Guarantees in Distributed Database Transaction\nTags: rabbitmq, amqp, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI am trying to understand what is the right pattern to deal with RabbitMQ deliveries in the context of distributed database transaction.\n\nTo make this simple, I will illustrate my ideas in pseudocode, but I'm in fact using Spring AMQP to implement these ideas.\n\nAnything like\n\n```\nvoid foo(message) {\n processMessageInDatabaseTransaction(message);\n sendMessageToRabbitMQ(message);\n}\n```\n\nWhere by the time we reach `sendMessageToRabbitMQ()` the `processMessageInDatabaseTransaction()` has successfully committed its changes to the database, or an exception has been thrown before reaching the message sending code.\n\nI know that for the `sendMessageToRabbitMQ()` I can use Rabbit transactions or publisher confirms to guarantee that Rabbit got my message.\n\nMy interest is understanding what should happen when things go south, i.e. when the database transaction succeeded, but the confirmation does not arrive after certain amount of time (with publisher confirms) or the Rabbit transaction fails to commit (with Rabbit transaction).\n\nOnce that happens, what is the right pattern to guarantee delivery of my message?\n\nOf course, having developed idempotent consumers, I have considered that I could retry the sending of the messages until Rabbit confirms success:\n\n```\nvoid foo(message) {\n processMessageInDatabaseTransaction(message);\n retryUntilSuccessFull {\n sendMessagesToRabbitMQ(message);\n }\n}\n```\n\nBut this pattern has a couple of drawbacks I dislike, first, if the failure is prolonged, my threads will start to block here and my system will eventually become unresponsive. Second, what happens if my system crashes or shuts down? I will never deliver these messages then since they will be lost.\n\nSo, I thought, well, I will have to write my messages to the database first, in pending status, and then publish my pending messages from there:\n\n```\nvoid foo(message) {\n //transaction commits leaving message in pending status\n processMessageInDatabaseTransaction(message);\n}\n\n@Poller(every=\"10 seconds\")\nvoid bar() {\n for(message in readPendingMessagesFromDbStore()) {\n sendPendingMessageToRabbitMQ(message);\n if(confirmed) {\n acknowledgeMessageInDatabase(message); \n }\n }\n}\n```\n\nPossibly sending the messages multiple times if I fail to acknowledge the message in my database.\n\nBut now I have introduced other problems:\n\n- The need to do I/O from the database to publish a message that 99% time would have successfully being published immediately without having to check the database.\n\n- The difficulty of making the poller closer to real time delivery since now I have added latency to the publication of the messages.\n\n- And perhaps other complications like guarantee delivery of events in order, poller executions stepping into one another, multiple pollers, etc.\n\nAnd then I thought well, I could make this a bit more complicated like, I can publish from the database until I catch up with the live stream of events and then publish real time, i.e. maintain a buffer of size b (circular buffer) as I read based on pages check if that message is in buffer. If so then switch to live subscription.\n\nTo this point I realized that how to do this right is not exactly evident and so I concluded that I need to learn what are the right patterns to solve this problem.\n\nSo, does anyone has suggestions on what is the right ways to do this correctly?\n\n========================================\n\nTop Answer:\nWhen Rabbit fails to receive a message (for whatever reason, but in my experience only because the service is down or unavailable) you should be in a position to catch an error. At this point, you can make a record of that - and any subsequent - failed attempt in order to retry when Rabbit becomes available again. The quickest way of doing this is just logging the message details to file, and iterating over to re-send **when appropriate**.\n\nAs long as you have that file, you've not lost your messages.\n\nOnce messages are inside Rabbit, *and you have faith in the rest of the architecture*, it should be safe to assume that messages will end up where they are supposed to be, and that no further persistence work needs doing at your end.\n\n========================================\n\nCode:\n```text\nvoid foo(message) {\n processMessageInDatabaseTransaction(message);\n sendMessageToRabbitMQ(message);\n}\n```\n\n```text\nvoid foo(message) {\n processMessageInDatabaseTransaction(message);\n retryUntilSuccessFull {\n sendMessagesToRabbitMQ(message);\n }\n}\n```\n\n```text\nvoid foo(message) {\n //transaction commits leaving message in pending status\n processMessageInDatabaseTransaction(message);\n}\n\n@Poller(every=\"10 seconds\")\nvoid bar() {\n for(message in readPendingMessagesFromDbStore()) {\n sendPendingMessageToRabbitMQ(message);\n if(confirmed) {\n acknowledgeMessageInDatabase(message); \n }\n }\n}\n```\n\n```text\nsendMessageToRabbitMQ()\n```\n\n```text\nprocessMessageInDatabaseTransaction()\n```\n\n```text\nsendMessageToRabbitMQ()\n```\n\n========================================\n\nComments:\n- I can see you point, @HomerPlata. One question though, now you have pending message to be sent from your file (due to previous failure) and also new events arriving from the runtime stream of events. So you need first to process the pending messages from your file before you deal with the live stream of events, how do you deal with that? Are you suggesting these file processing feature is entirely separate from the current stream of events?\n- If you just keep appending the failed messages to a log file until the next message eventually gets accepted by Rabbit (indicating you're good to go again), you can then iterate through the log lines and re-add to the message queue, deleting the log file once it's been used. You might run into a bit of a concurrency issue if Rabbit goes down again while you're iterating through the log file and you need to add more failures to it, but it's not impossible to solve.\n- Actually, let me improve on that: If you use a single file per failed message (just serialise them individually) in a specific folder, you can iterate through all the files in that folder without any concurrency issues, adding new \"failure\" files even if you're in the process of resending.\n- Thanks for the link, @Gary. Precisely \"dealing with that possibility\" is what I'm most interested in discovering with my question here. I have indeed played with Spring AMPQ and I have seen how the post database commit code deals with committing the Rabbit transaction, but the race condition there is what worries. For example in implementing CQRS/ES I must be completely sure I will never lose an event. How do you think one should deal with that possibility you mentioned in your answer?\n- You will never lose an event if the DB commits before the rabbit send commits. If the server crashes between the two commits, the rabbit message will be redelivered (while the DB has already committed). You just need to be sure the transaction managers are configured to commit in that order. See `ChainedTransactionManager` in spring-data-commons.\n- That discussion is if you are using rabbit as the event source. If the database is the event source, you would need them to commit the other way around.\n- If the event comes from a listener container, you don't need a chained TxManager. Just make the container transactional, and the rabbit TX will commit last. Make sure you start the DB transaction at `foo()` so the sends will be done within the scope of both transactions. Make sure the rabbit template is also marked `channelTransacted` so its sends operate within the same Rabbit transaction.\n- I think I am starting to understand it, in the ChainedtransactionManager messages won't be delivered until the database transaction commits, and it if it rolls back the entire transaction is retried and messages are possibly republished, which is acceptable give the constraints of delivery at least once that Rabbit presupposes.\n- OK, I gave it a shot to the `ChainedTransaction` manager and it worked like charm. I can clearly see that I will need to make my database transaction idempotent, because if the Rabbit transaction fails I will have to repeat the entire thing. I think it still stands that using Rabbit transactions will be less efficient than publishing returns and that retrying transactions if not done efficiently might make my application irresponsive, but I think this works pretty well. That link you shared is pretty good, Gary. Thanks!\n- Yes, transactions are considered to be slow but publisher confirms only really help if you send a bunch of messages and **then** wait for the confirms. I haven't done any testing, but I suspect that sending a single message and waiting for its confirm will not be a lot different than blocking on the commit (and you lose the transaction semantics).","metadata":{"transformedAt":"2026-08-18T18:33:20.166Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":144,"estimatedTokens":2250}}495{"id":"stack-30987941","source":"stackoverflow","questionId":30987941,"title":"When to create RabbitMQ channels in node.js","tags":["node.js","rabbitmq"],"text":"Title: When to create RabbitMQ channels in node.js\nTags: node.js, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nThe common advice I've read for creating channels for RabbitMQ recommends using a single channel per thread. But in node.js, we don't manage threads at all. **So when do we create channels**?\n\nMy use case is that of a node web server, using AMQPLib, that needs to use a request/response pattern to communicate with a single RabbitMQ server. Each HTTP request may require multiple RabbitMQ requests in order to generate the HTTP response. I plan to use a single Rabbit connection per node process, but as far as how much to reuse channels for various requests or response queues, I'm not certain.\n\nAn add-on question: If the answer is to use a channel for each separate request, then will there be much of a latency penalty for having to create a channel before each message sent?\n\n========================================\n\nComments:\n- Create a channel for every units of work.\n- Your first intuition is correct, you should use one connection per node process. The amqblib module is heavily based on streams, and therefore will not selfishly tie up your event loop. Additionally, there is a heavy cost to creating and tearing down channels relative to the cost of publishing data on a channel, so you should avoid unnecessary channel creation. If you're using multiple queues you should create one channel per queue per node process.\n- I meant there was a high cost of creating a channel *relative* to just publishing or consuming data on an existing channel. Consider the case of using a task queue, in this case with the node.js client amqplib library OP references. Here \"creating\" a channel would necessitate creating an amqp connection, creating a channel, asserting the queue, setting configuration on the queue, then creating a consumer. That's four asynchronous function calls compared to just one if you reuse a channel. Given your answer you clearly understand AMQP better than I do, so this comment is more to clarify for OP.\n- The real cost is in the programmer's time to keep all of this straight. I don't worry as much about the computer's effort when I think about cost, but if it helps to think through to the right solution, then it is good.","metadata":{"transformedAt":"2026-08-18T18:33:20.167Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":18,"estimatedTokens":567}}496{"id":"stack-7115410","source":"stackoverflow","questionId":7115410,"title":"Way to break a connection from rabbitmq","tags":["rabbitmq","consumer"],"text":"Title: Way to break a connection from rabbitmq\nTags: rabbitmq, consumer\nSource: Stack Overflow\n\nQuestion:\nI've got an application which has some bugs. For some reason 2 consumers are created when only one should be there - and one of them is not checked for messages anymore.\n\nI can detect that situation by listing queues and the number of consumers on the server. Is there some way to destroy that consumer from the server side?\n\n========================================\n\nTop Answer:\nconsumer can be kill by `rabbitmqctl` using close_connection input `connectionpid`\n\nexample\n\n```\n> rabbitmqctl close_connection \"\" \"reason here\"\n```\n\nconnectionpid can get by\n\n```\n> rabbitmqctl list_consumers\n\nListing consumers ...\nsend_email_1 amq.ctag-oim8CCP2hsioWc-3WwS-qQ true 1 []\nsend_email_2 amq.ctag-WxpxDglqZQN2FNShN4g7QA true 1 []\n```\n\nRabbitMQ 3.5.4\n\n========================================\n\nCode:\n```text\nrabbitmqctl\n```\n\n```text\n> rabbitmqctl close_connection \"<rabbit@hardys-Mac-mini.1.4195.0>\" \"reason here\"\n```\n\n```text\n> rabbitmqctl list_consumers\n\nListing consumers ...\nsend_email_1 <rabbit@hardys-Mac-mini.1.4185.0> amq.ctag-oim8CCP2hsioWc-3WwS-qQ true 1 []\nsend_email_2 <rabbit@hardys-Mac-mini.1.4195.0> amq.ctag-WxpxDglqZQN2FNShN4g7QA true 1 []\n```\n\n```text\nrabbitmqctl\n```\n\n```text\nconnectionpid\n```\n\n========================================\n\nComments:\n- if you want to remove the consumer programmatically, calling the cancel method on the RabbitMQ channel should do.\n- That did work, almost. For some reason there are two consumers, but there's only one connection assigned to one of them. The other consumer just... exists. Looking for an explanation of that situation now.\n- No idea...if you restart your broker, does the problem remain?","metadata":{"transformedAt":"2026-08-18T18:33:20.167Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":65,"estimatedTokens":443}}497{"id":"stack-43677390","source":"stackoverflow","questionId":43677390,"title":"How to use the rabbitmq docker compose yml file to build docker image?","tags":["docker","rabbitmq","installation","docker-compose"],"text":"Title: How to use the rabbitmq docker compose yml file to build docker image?\nTags: docker, rabbitmq, installation, docker-compose\nSource: Stack Overflow\n\nQuestion:\nI'm new to docker and I know how to pull images of Ubuntu Linux and run it. I just wish to try out rabbitmq, and the site says we can use a `docker-composer.yml` file like this:\n\n```\nrabbitmq:\n image: rabbitmq:management\n ports:\n - \"5672:5672\"\n - \"15672:15672\"\n```\n\nI googled for a while but only find YAML related sites talks about how to write a complex YAML file. But my question is, how to use this YAML file to build/compose any docker image with rabbitmq so that I can start to use it?\n\n========================================\n\nTop Answer:\nHere is simple docker compose\n\n```\nversion: \"3\"\n\nservices:\n\n rabbitmq:\n image: rabbitmq\n command: rabbitmq-server\n expose:\n - 5672\n - 15672\n```\n\n========================================\n\nCode:\n```text\nrabbitmq:\n image: rabbitmq:management\n ports:\n - \"5672:5672\"\n - \"15672:15672\"\n```\n\n```text\ndocker-composer.yml\n```\n\n```text\nversion: \"2\"\nservices:\n rabbit_node_1:\n environment:\n - RABBITMQ_ERLANG_COOKIE='secret_cookie'\n networks:\n - back\n hostname: rabbit_node_1\n image: \"rabbitmq:3-management\"\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n tty: true\n volumes:\n - rabbit1:/var/lib/rabbitmq\n - ./conf/:/etc/rabbitmq/\n command: bash -c \"sleep 10; rabbitmq-server;\"\n rabbit_node_2:\n environment:\n - RABBITMQ_ERLANG_COOKIE='secret_cookie'\n networks:\n - back\n hostname: rabbit_node_2\n depends_on:\n - rabbit_node_1\n image: \"rabbitmq:3-management\"\n ports:\n - \"15673:15672\"\n - \"5673:5672\"\n tty: true\n volumes:\n - rabbit2:/var/lib/rabbitmq\n - ./conf/:/etc/rabbitmq/\n command: bash -c \"sleep 10; rabbitmq-server; \"\nvolumes:\n rabbit1:\n driver: local\n rabbit2:\n driver: local\n\nnetworks:\n back:\n```\n\n```text\nversion: \"3\"\n\nservices:\n\n rabbitmq:\n image: rabbitmq\n command: rabbitmq-server\n expose:\n - 5672\n - 15672\n```\n\n========================================\n\nComments:\n- @ gabriele Do we need to create host entries also in etc/hosts file i have similar config but it gives me error process_not_running","metadata":{"transformedAt":"2026-08-18T18:33:20.167Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":112,"estimatedTokens":564}}498{"id":"stack-21652517","source":"stackoverflow","questionId":21652517,"title":"AMQP: acknowledgement and prefetching","tags":["python","rabbitmq","amqp","pika"],"text":"Title: AMQP: acknowledgement and prefetching\nTags: python, rabbitmq, amqp, pika\nSource: Stack Overflow\n\nQuestion:\nI try to understand some aspects of AMQP protocol. Currently I have project with RabbitMQ and use python pika library. So question is about acknowledgement and message prefetching.\n\nConsider we have a queue with only consumer (for sure this queue was declared as exclusive). So do I understand correctly: no matter if I consume with or with no ack flag? Anyway I should not be able to process several messages simultaneously and there are no another consumers that could take some of other still queued messages. Even better not to turn acknowledgement on, because possibly this may reduce AMQP server load.\n\nPrefetch count doesn't mean anything if there is no acknowledgement. Correct?\n\nI am not sure how prefetching works. I have a callback on new message and in its **finally** statement I acknowledge or reject the message. This is the only function and no matter how big prefetch count would be - anyway another message would not be processed until the current one is completed. So why should I need change prefetch_count value?\n\nthanks in advance.\n\n========================================\n\nCode:\n```text\nautoack\n```\n\n```text\nautoack\n```\n\n```text\nprefetch count\n```\n\n```text\nprefetch size\n```\n\n```text\nprefetch size\n```\n\n```text\nprefetch count\n```\n\n```text\nprefetch size\n```\n\n```text\nprefetch-size=5kb, prefetch-count=4\n```\n\n```text\noff\n```\n\n```text\nprefetch-count=4\n```\n\n```text\nprefetch-size=5kb, prefetch-count=2\n```\n\n```text\noff\n```\n\n```text\nprefetch-size=5kb\n```\n\n```text\nprefetch-count=2\n```\n\n```text\nprefetch-size=5kb, prefetch-count=10\n```\n\n```text\non\n```\n\n```text\nprefetch-size\n```\n\n```text\nprefetch-count\n```\n\n```text\nno-ack\n```\n\n```text\nprefetch-size\n```\n\n```text\nprefetch-count\n```\n\n```text\nautoack\n```\n\n```text\nno-ack\n```\n\n```text\ntrue\n```\n\n========================================\n\nComments:\n- Great answer, thanks for the examples! So have I understood correctly: though client cannot process more than 1 message from queue simultaneously it can *prefetch* some messages (limited by number and / or by size) in some kind of cache to have quick access for them (not to wait them from the server)? Seems it is implemented internally by AMQP library and is transparent for user so I work with prefetching in the same way like without it.\n- In case of \"No autoack\", how does broker come to know how much consumer has processed? In your example, you mentioned 3 messages are processed and then broker sends two more. Can you please explain this again?\n- @AkashJain, I had multiple errors in my answer, stackoverflow.com/posts/21662129/revisions, should be fixed now. Sorry for any inconvenience.\n- @Serge A client can process many message 'simultaneously' - ie. with threads. This requires more coordination and individual message tracking but is entirely possible. The only restriction is that it client read the messages from the front of the queue.. from there until the client ACKs/NACKs/DCs, is the client's responsibility.","metadata":{"transformedAt":"2026-08-18T18:33:20.167Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":24,"totalLines":121,"estimatedTokens":765}}499{"id":"stack-42577262","source":"stackoverflow","questionId":42577262,"title":"Unable to increase file descriptors for rabbitmq","tags":["rabbitmq"],"text":"Title: Unable to increase file descriptors for rabbitmq\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI want to increase file descriptors for Rabbitmq server.\n\nMachine details:\n\n```\nroot@rabbitmq-stats-node:/home/# uname -a\nLinux rabbitmq-stats-node 3.16.0-4-amd64 #1 SMP Debian 3.16.39-1+deb8u1 (2017-02-22) x86_64 GNU/Linux\n```\n\nHere are the details of configuration parameters changed:\n\n```\nroot@rabbitmq-stats-node:/home/# cat /proc/sys/fs/file-max\n500000\n\nroot@rabbitmq-stats-node:/home/# tail -n1 /etc/pam.d/common-session\nsession required pam_limits.so\n\nroot@rabbitmq-stats-node:/home/# tail -n1 /etc/pam.d/common-session-noninteractive\nsession required pam_limits.so\n\nroot@rabbitmq-stats-node:/home/# tail -n4 /etc/security/limits.conf \n* soft nofile 65536\n* hard nofile 500000\nroot soft nofile 65536\nroot hard nofile 500000\n\nroot@rabbitmq-stats-node:/home/# sysctl -p \nfs.file-max = 500000\n\nroot@rabbitmq-stats-node:/home/# sudo service rabbitmq-server restart\n\nroot@rabbitmq-stats-node:/home/# sudo reboot\n```\n\nAfter all configuration changes, I am unable to change file desciptors limit.\n\n```\nroot@rabbitmq-stats-node:/home/# rabbitmqctl status | grep -A1 descriptors\n {file_descriptors,\n [{total_limit,924},{total_used,13},{sockets_limit,829},{sockets_used,3}]},\n```\n\nI can see changed limit when I enter,\n\n```\nroot@rabbitmq-stats-node:/home/# ulimit -n\n65536\n```\n\nThough the changes are not reflected in rabbitmq installation.\n\nI also tried adding ulimit line to `/usr/lib/rabbitmq/bin/rabbitmq-env` file. Though rabbitmq server doesnot start after adding this change. Error thrown: \n\n```\nulimit: error setting limit (Operation not permitted)\n```\n\n========================================\n\nTop Answer:\nActually making a quick test, adding my user **running** (let's call him my_user) rabbitmq to */etc/security/limits.conf* the following:\n\n```\nmy_user soft nofile 65000\nmy_user hard nofile 65000\n```\n\nThen login out and back again, starting rabbitmq, and checking the number of file descriptors as you did, I obtain:\n\n```\n{file_descriptors,\n [{total_limit,64900},...\n```\n\nSo I can conclude that it works. Now I highly suspect from what you are writing that the user running rabbitmq is not the root user, but a different one. However the increase of max file descriptors seems only applied to the root user, consequently no differences is seen running rabbitmq.\n\nTo check it in more detail, it would be good that you post the \"service\" script ran when you enter:\n\n```\nsudo service rabbitmq-server restart\n```\n\nNow if you want to make sure your modifications worked, you could start directly rabbitmq as *root* (which I don't recommend for production)\n\n========================================\n\nCode:\n```text\nroot@rabbitmq-stats-node:/home/# uname -a\nLinux rabbitmq-stats-node 3.16.0-4-amd64 #1 SMP Debian 3.16.39-1+deb8u1 (2017-02-22) x86_64 GNU/Linux\n```\n\n```text\nroot@rabbitmq-stats-node:/home/# cat /proc/sys/fs/file-max\n500000\n\nroot@rabbitmq-stats-node:/home/# tail -n1 /etc/pam.d/common-session\nsession required pam_limits.so\n\nroot@rabbitmq-stats-node:/home/# tail -n1 /etc/pam.d/common-session-noninteractive\nsession required pam_limits.so\n\nroot@rabbitmq-stats-node:/home/# tail -n4 /etc/security/limits.conf \n* soft nofile 65536\n* hard nofile 500000\nroot soft nofile 65536\nroot hard nofile 500000\n\nroot@rabbitmq-stats-node:/home/# sysctl -p \nfs.file-max = 500000\n\nroot@rabbitmq-stats-node:/home/# sudo service rabbitmq-server restart\n\nroot@rabbitmq-stats-node:/home/# sudo reboot\n```\n\n```text\nroot@rabbitmq-stats-node:/home/# rabbitmqctl status | grep -A1 descriptors\n {file_descriptors,\n [{total_limit,924},{total_used,13},{sockets_limit,829},{sockets_used,3}]},\n```\n\n```text\nroot@rabbitmq-stats-node:/home/# ulimit -n\n65536\n```\n\n```text\nulimit: error setting limit (Operation not permitted)\n```\n\n```text\n/usr/lib/rabbitmq/bin/rabbitmq-env\n```\n\n```text\n[Service]\nLimitNOFILE=300000\n```\n\n```text\nmy_user soft nofile 65000\nmy_user hard nofile 65000\n```\n\n```text\n{file_descriptors,\n [{total_limit,64900},...\n```\n\n```text\nsudo service rabbitmq-server restart\n```\n\n```text\nDefaultLimitNOFILE=1048576\n```\n\n```text\n/etc/systemd/system.conf\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.167Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":167,"estimatedTokens":1077}}500{"id":"stack-38988356","source":"stackoverflow","questionId":38988356,"title":"Why can't I find the 'rabbitmq.config' file while I have already installed RabbitMQ?","tags":["rabbitmq"],"text":"Title: Why can't I find the 'rabbitmq.config' file while I have already installed RabbitMQ?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm running Red Hat Enterprise Linux 7.2, I have installed RabbitMQ and `systemctl status rabbitmq-server` shows\n\n ● rabbitmq-server.service - LSB: Enable AMQP service provided by\n RabbitMQ broker Loaded: loaded (/etc/rc.d/init.d/rabbitmq-server)\n\n Active: active (running) since Wed 2016-08-17 11:25:56 JST; 1h 14min\n ago\n Docs: man:systemd-sysv-generator(8)\n\nBut when I want to configure it I cannot find the file: `find / -iname \"rabbitmq.config\"` shows nothing.\n\nI have an application which connects to `127.0.0.1:3000`, but the default port listened by RabbitMQ is 5672, so I want to add the port 3000 (hope it will fix the problem)\n\n========================================\n\nCode:\n```text\nsystemctl status rabbitmq-server\n```\n\n```text\nfind / -iname \"rabbitmq.config\"\n```\n\n```text\n127.0.0.1:3000\n```\n\n```text\n/etc/rabbitmq/rabbitmq.config\n```\n\n```text\nrabbitmq.conf\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.167Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":40,"estimatedTokens":254}}501{"id":"stack-8633882","source":"stackoverflow","questionId":8633882,"title":"RabbitMQ on Ubuntu 10.04 Server","tags":["ubuntu","rabbitmq","ubuntu-10.04"],"text":"Title: RabbitMQ on Ubuntu 10.04 Server\nTags: ubuntu, rabbitmq, ubuntu-10.04\nSource: Stack Overflow\n\nQuestion:\nTrying to run RabbitMQ on VPS with Ubuntu 10.04. Doing everything like usual:\n\n- added RabbitMQ deb repo\n\n- updated with apt-get update\n\n- installed with apt-get install rabbitmq-server\n\nOn my local machine with Ubuntu 11.10 and another VPS with same 10.04 everything works just fine. But on this one i getting error like this (from /var/log/rabbitmq/startup_log):\n\n```\nActivating RabbitMQ plugins ...\n\n********************************************************************************\n********************************************************************************\n\n0 plugins activated:\n\nERROR: epmd error for host \"67714\": badarg (unknown POSIX error)\n```\n\nWhat i'm doing wrong and wtf is this?\n\n========================================\n\nTop Answer:\nThis worked for me on CentOS 5.8 when I was unable to use the /etc/hosts file to fix it:\n\n- Create a rabbitmq environment variables config file at /etc/rabbitmq/rabbitmq-env.conf\n\n- Add NODENAME=rabbit@localhost to it (note that just localhost didn't work)\n\n- sudo service rabbitmq-server start\n\nTo see more about config options, check this out: http://www.rabbitmq.com/configure.html#customise-general-unix-environment.\n\n========================================\n\nCode:\n```text\nActivating RabbitMQ plugins ...\n\n********************************************************************************\n********************************************************************************\n\n0 plugins activated:\n\nERROR: epmd error for host \"67714\": badarg (unknown POSIX error)\n```\n\n```text\nsu\n vim /etc/hosts\n 127.0.0.1 localhost.localdomain localhost YOUR-HOSTNAME\n ::1 localhost6.localdomain6 localhost6\n service rabbitmq-server start\n```\n\n```text\nsu\n vim /etc/hosts\n 127.0.0.1 localhost.localdomain localhost 67714\n ::1 localhost6.localdomain6 localhost6\n service rabbitmq-server start\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.167Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":70,"estimatedTokens":499}}502{"id":"stack-56601031","source":"stackoverflow","questionId":56601031,"title":"\"Directory name is invalid.\" etc. with rabbitmq-plugins on Windows","tags":["rabbitmq","windows-10"],"text":"Title: \"Directory name is invalid.\" etc. with rabbitmq-plugins on Windows\nTags: rabbitmq, windows-10\nSource: Stack Overflow\n\nQuestion:\nI'm trying to get RabbitMQ going on Windows 10 by following these instructions.\n\nHowever, when trying to enable the management plugin via powershell command:\n\n```\n./rabbitmq-plugins enable rabbitmq_management\n```\n\nI get the following:\n\n```\nThe directory name is invalid.\nThe filename, directory name, or volume label syntax is incorrect.\nUnsupported node name: hostname is invalid (possibly contains unsupported characters).\nIf using FQDN node names, use the -l / --longnames argument.\n```\n\nI've tried setting `HOMEDRIVE=C:` as the blog suggested.\n\nWhat am I doing wrong?\n\n**EDIT**\n\nPer the comment below I did the following:\n\n```\nPS C:\\program files\\rabbitmq server\\rabbitmq_server-3.7.15\\sbin> ./rabbitmq-service.bat stop\nThe directory name is invalid.\nThe filename, directory name, or volume label syntax is incorrect.\nThe RabbitMQ service is stopping.\nThe RabbitMQ service was stopped successfully.\n\nPS C:\\program files\\rabbitmq server\\rabbitmq_server-3.7.15\\sbin> ./rabbitmq-service.bat uninstall\nThe directory name is invalid.\nThe filename, directory name, or volume label syntax is incorrect.\n\n*********************\nService control usage\n*********************\n\nrabbitmq-service help - Display this help\nrabbitmq-service install - Install the RabbitMQ service\nrabbitmq-service remove - Remove the RabbitMQ service\n\nThe following actions can also be accomplished by using\nWindows Services Management Console (services.msc):\n\nrabbitmq-service start - Start the RabbitMQ service\nrabbitmq-service stop - Stop the RabbitMQ service\nrabbitmq-service disable - Disable the RabbitMQ service\nrabbitmq-service enable - Enable the RabbitMQ service\n\nPS C:\\program files\\rabbitmq server\\rabbitmq_server-3.7.15\\sbin> set HOMEDRIVE=C:\nPS C:\\program files\\rabbitmq server\\rabbitmq_server-3.7.15\\sbin> ./rabbitmq-service.bat install\nThe directory name is invalid.\nThe filename, directory name, or volume label syntax is incorrect.\nRabbitMQ service is already present - only updating service parameters\n\"WARNING: Using RABBITMQ_ADVANCED_CONFIG_FILE: C:\\Users\\Mj\\AppData\\Roaming\\RabbitMQ\\advanced.config\"\n2019-06-14 10:55:09.630000\n args: []\n format: \"Failed to create cookie file 'l:/.erlang.cookie': enoent\"\n label: {error_logger,error_msg}\n2019-06-14 10:55:09.630000 crash_report #{label=>{proc_lib,crash},report=>[[{initial_call,{auth,init,['Argument__1']}},{pid,},{registered_name,[]},{error_info,{error,\"Failed to create cookie file 'l:/.erlang.cookie': enoent\",[{auth,init_cookie,0,[{file,\"auth.erl\"},{line,286}]},{auth,init,1,[{file,\"auth.erl\"},{line,140}]},{gen_server,init_it,2,[{file,\"gen_server.erl\"},{line,374}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,249}]}]}},{ancestors,[net_sup,kernel_sup,]},{message_queue_len,0},{messages,[]},{links,[]},{dictionary,[]},{trap_exit,true},{status,running},{heap_size,610},{stack_size,27},{reductions,1456}],[]]}\n2019-06-14 10:55:09.635000 supervisor_report #{label=>{supervisor,start_error},report=>[{supervisor,{local,net_sup}},{errorContext,start_error},{reason,{\"Failed to create cookie file 'l:/.erlang.cookie': enoent\",[{auth,init_cookie,0,[{file,\"auth.erl\"},{line,286}]},{auth,init,1,[{file,\"auth.erl\"},{line,140}]},{gen_server,init_it,2,[{file,\"gen_server.erl\"},{line,374}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,249}]}]}},{offender,[{pid,undefined},{id,auth},{mfargs,{auth,start_link,[]}},{restart_type,permanent},{shutdown,2000},{child_type,worker}]}]}\n2019-06-14 10:55:09.704000 supervisor_report #{label=>{supervisor,start_error},report=>[{supervisor,{local,kernel_sup}},{errorContext,start_error},{reason,{shutdown,{failed_to_start_child,auth,{\"Failed to create cookie file 'l:/.erlang.cookie': enoent\",[{auth,init_cookie,0,[{file,\"auth.erl\"},{line,286}]},{auth,init,1,[{file,\"auth.erl\"},{line,140}]},{gen_server,init_it,2,[{file,\"gen_server.erl\"},{line,374}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,249}]}]}}}},{offender,[{pid,undefined},{id,net_sup},{mfargs,{erl_distribution,start_link,[]}},{restart_type,permanent},{shutdown,infinity},{child_type,supervisor}]}]}\n2019-06-14 10:55:09.742000 crash_report #{label=>{proc_lib,crash},report=>[[{initial_call,{application_master,init,['Argument__1','Argument__2','Argument__3','Argument__4']}},{pid,},{registered_name,[]},{error_info,{exit,{{shutdown,{failed_to_start_child,net_sup,{shutdown,{failed_to_start_child,auth,{\"Failed to create cookie file 'l:/.erlang.cookie': enoent\",[{auth,init_cookie,0,[{file,\"auth.erl\"},{line,286}]},{auth,init,1,[{file,\"auth.erl\"},{line,140}]},{gen_server,init_it,2,[{file,\"gen_server.erl\"},{line,374}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,249}]}]}}}}},{kernel,start,[normal,[]]}},[{application_master,init,4,[{file,\"application_master.erl\"},{line,138}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,249}]}]}},{ancestors,[]},{message_queue_len,1},{messages,[{'EXIT',,normal}]},{links,[,]},{dictionary,[]},{trap_exit,true},{status,running},{heap_size,987},{stack_size,27},{reductions,184}],[]]}\n2019-06-14 10:55:09.789000 std_info #{label=>{application_controller,exit},report=>[{application,kernel},{exited,{{shutdown,{failed_to_start_child,net_sup,{shutdown,{failed_to_start_child,auth,{\"Failed to create cookie file 'l:/.erlang.cookie': enoent\",[{auth,init_cookie,0,[{file,\"auth.erl\"},{line,286}]},{auth,init,1,[{file,\"auth.erl\"},{line,140}]},{gen_server,init_it,2,[{file,\"gen_server.erl\"},{line,374}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,249}]}]}}}}},{kernel,start,[normal,[]]}}},{type,permanent}]}\n{\"Kernel pid terminated\",application_controller,\"{application_start_failure,kernel,{{shutdown,{failed_to_start_child,net_sup,{shutdown,{failed_to_start_child,auth,{\\\"Failed to create cookie file 'l:/.erlang.cookie': enoent\\\",[{auth,init_cookie,0,[{file,\\\"auth.erl\\\"},{line,286}]},{auth,init,1,[{file,\\\"auth.erl\\\"},{line,140}]},{gen_server,init_it,2,[{file,\\\"gen_server.erl\\\"},{line,374}]},{gen_server,init_it,6,[{file,\\\"gen_server.erl\\\"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,\\\"proc_lib.erl\\\"},{line,249}]}]}}}}},{kernel,start,[normal,[]]}}}\"}\nKernel pid terminated (application_controller) ({application_start_failure,kernel,{{shutdown,{failed_to_start_child,net_sup,{shutdown,{failed_to_start_child,auth,{\"Failed to create cookie file 'l:/.er\n\nCrash dump is being written to: C:\\Users\\Mj\\AppData\\Roaming\\RabbitMQ\\log\\erl_crash.dump...done\n```\n\n========================================\n\nTop Answer:\nSeems that the Order at which the commands are ran Matters, this worked for me, shuffle them around\n\n```\nSET HOMEDRIVE=C:\nrabbitmq-plugins.bat enable rabbitmq_management\nrabbitmq-service.bat stop\nrabbitmq-service.bat install\nrabbitmq-service.bat start\n```\n\n========================================\n\nCode:\n```text\n./rabbitmq-plugins enable rabbitmq_management\n```\n\n```text\nThe directory name is invalid.\nThe filename, directory name, or volume label syntax is incorrect.\nUnsupported node name: hostname is invalid (possibly contains unsupported characters).\nIf using FQDN node names, use the -l / --longnames argument.\n```\n\n```text\nPS C:\\program files\\rabbitmq server\\rabbitmq_server-3.7.15\\sbin> ./rabbitmq-service.bat stop\nThe directory name is invalid.\nThe filename, directory name, or volume label syntax is incorrect.\nThe RabbitMQ service is stopping.\nThe RabbitMQ service was stopped successfully.\n\nPS C:\\program files\\rabbitmq server\\rabbitmq_server-3.7.15\\sbin> ./rabbitmq-service.bat uninstall\nThe directory name is invalid.\nThe filename, directory name, or volume label syntax is incorrect.\n\n*********************\nService control usage\n*********************\n\nrabbitmq-service help - Display this help\nrabbitmq-service install - Install the RabbitMQ service\nrabbitmq-service remove - Remove the RabbitMQ service\n\nThe following actions can also be accomplished by using\nWindows Services Management Console (services.msc):\n\nrabbitmq-service start - Start the RabbitMQ service\nrabbitmq-service stop - Stop the RabbitMQ service\nrabbitmq-service disable - Disable the RabbitMQ service\nrabbitmq-service enable - Enable the RabbitMQ service\n\nPS C:\\program files\\rabbitmq server\\rabbitmq_server-3.7.15\\sbin> set HOMEDRIVE=C:\nPS C:\\program files\\rabbitmq server\\rabbitmq_server-3.7.15\\sbin> ./rabbitmq-service.bat install\nThe directory name is invalid.\nThe filename, directory name, or volume label syntax is incorrect.\nRabbitMQ service is already present - only updating service parameters\n\"WARNING: Using RABBITMQ_ADVANCED_CONFIG_FILE: C:\\Users\\Mj\\AppData\\Roaming\\RabbitMQ\\advanced.config\"\n2019-06-14 10:55:09.630000\n args: []\n format: \"Failed to create cookie file 'l:/.erlang.cookie': enoent\"\n label: {error_logger,error_msg}\n2019-06-14 10:55:09.630000 crash_report #{label=>{proc_lib,crash},report=>[[{initial_call,{auth,init,['Argument__1']}},{pid,<0.57.0>},{registered_name,[]},{error_info,{error,\"Failed to create cookie file 'l:/.erlang.cookie': enoent\",[{auth,init_cookie,0,[{file,\"auth.erl\"},{line,286}]},{auth,init,1,[{file,\"auth.erl\"},{line,140}]},{gen_server,init_it,2,[{file,\"gen_server.erl\"},{line,374}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,249}]}]}},{ancestors,[net_sup,kernel_sup,<0.46.0>]},{message_queue_len,0},{messages,[]},{links,[<0.55.0>]},{dictionary,[]},{trap_exit,true},{status,running},{heap_size,610},{stack_size,27},{reductions,1456}],[]]}\n2019-06-14 10:55:09.635000 supervisor_report #{label=>{supervisor,start_error},report=>[{supervisor,{local,net_sup}},{errorContext,start_error},{reason,{\"Failed to create cookie file 'l:/.erlang.cookie': enoent\",[{auth,init_cookie,0,[{file,\"auth.erl\"},{line,286}]},{auth,init,1,[{file,\"auth.erl\"},{line,140}]},{gen_server,init_it,2,[{file,\"gen_server.erl\"},{line,374}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,249}]}]}},{offender,[{pid,undefined},{id,auth},{mfargs,{auth,start_link,[]}},{restart_type,permanent},{shutdown,2000},{child_type,worker}]}]}\n2019-06-14 10:55:09.704000 supervisor_report #{label=>{supervisor,start_error},report=>[{supervisor,{local,kernel_sup}},{errorContext,start_error},{reason,{shutdown,{failed_to_start_child,auth,{\"Failed to create cookie file 'l:/.erlang.cookie': enoent\",[{auth,init_cookie,0,[{file,\"auth.erl\"},{line,286}]},{auth,init,1,[{file,\"auth.erl\"},{line,140}]},{gen_server,init_it,2,[{file,\"gen_server.erl\"},{line,374}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,249}]}]}}}},{offender,[{pid,undefined},{id,net_sup},{mfargs,{erl_distribution,start_link,[]}},{restart_type,permanent},{shutdown,infinity},{child_type,supervisor}]}]}\n2019-06-14 10:55:09.742000 crash_report #{label=>{proc_lib,crash},report=>[[{initial_call,{application_master,init,['Argument__1','Argument__2','Argument__3','Argument__4']}},{pid,<0.45.0>},{registered_name,[]},{error_info,{exit,{{shutdown,{failed_to_start_child,net_sup,{shutdown,{failed_to_start_child,auth,{\"Failed to create cookie file 'l:/.erlang.cookie': enoent\",[{auth,init_cookie,0,[{file,\"auth.erl\"},{line,286}]},{auth,init,1,[{file,\"auth.erl\"},{line,140}]},{gen_server,init_it,2,[{file,\"gen_server.erl\"},{line,374}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,249}]}]}}}}},{kernel,start,[normal,[]]}},[{application_master,init,4,[{file,\"application_master.erl\"},{line,138}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,249}]}]}},{ancestors,[<0.44.0>]},{message_queue_len,1},{messages,[{'EXIT',<0.46.0>,normal}]},{links,[<0.44.0>,<0.43.0>]},{dictionary,[]},{trap_exit,true},{status,running},{heap_size,987},{stack_size,27},{reductions,184}],[]]}\n2019-06-14 10:55:09.789000 std_info #{label=>{application_controller,exit},report=>[{application,kernel},{exited,{{shutdown,{failed_to_start_child,net_sup,{shutdown,{failed_to_start_child,auth,{\"Failed to create cookie file 'l:/.erlang.cookie': enoent\",[{auth,init_cookie,0,[{file,\"auth.erl\"},{line,286}]},{auth,init,1,[{file,\"auth.erl\"},{line,140}]},{gen_server,init_it,2,[{file,\"gen_server.erl\"},{line,374}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,249}]}]}}}}},{kernel,start,[normal,[]]}}},{type,permanent}]}\n{\"Kernel pid terminated\",application_controller,\"{application_start_failure,kernel,{{shutdown,{failed_to_start_child,net_sup,{shutdown,{failed_to_start_child,auth,{\\\"Failed to create cookie file 'l:/.erlang.cookie': enoent\\\",[{auth,init_cookie,0,[{file,\\\"auth.erl\\\"},{line,286}]},{auth,init,1,[{file,\\\"auth.erl\\\"},{line,140}]},{gen_server,init_it,2,[{file,\\\"gen_server.erl\\\"},{line,374}]},{gen_server,init_it,6,[{file,\\\"gen_server.erl\\\"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,\\\"proc_lib.erl\\\"},{line,249}]}]}}}}},{kernel,start,[normal,[]]}}}\"}\nKernel pid terminated (application_controller) ({application_start_failure,kernel,{{shutdown,{failed_to_start_child,net_sup,{shutdown,{failed_to_start_child,auth,{\"Failed to create cookie file 'l:/.er\n\nCrash dump is being written to: C:\\Users\\Mj\\AppData\\Roaming\\RabbitMQ\\log\\erl_crash.dump...done\n```\n\n```text\nHOMEDRIVE=C:\n```\n\n```text\n.\\rabbitmq-service.bat stop\n.\\rabbitmq-service.bat remove\nset HOMEDRIVE=C: \n.\\rabbitmq-service.bat install\n.\\rabbitmq-plugins.bat enable rabbitmq_management\n.\\rabbitmq-service.bat start\n```\n\n```text\nuninstall\n```\n\n```text\nremove\n```\n\n```text\nuninstall\n```\n\n```text\nSET HOMEDRIVE=C:\nrabbitmq-plugins.bat enable rabbitmq_management\nrabbitmq-service.bat stop\nrabbitmq-service.bat install\nrabbitmq-service.bat start\n```\n\n========================================\n\nComments:\n- Try this: log in as the admin user you installed RMQ with, open the \"RabbitMQ Command Prompt (sbin dir)\" terminal, run `.\\rabbitmq-service.bat stop`, `.\\rabbitmq-service.bat uninstall`, `set HOMEDRIVE=C:`, `.\\rabbitmq-service.bat install`, `.\\rabbitmq-service.bat start`, `.\\rabbitmq-plugins.bat enable rabbitmq_management`. Also see - stackoverflow.com/q/56364372/1466825\n- Oddly, when stopping the service, I get: `The directory name is invalid. The filename, directory name, or volume label syntax is incorrect. The RabbitMQ service is stopping. The RabbitMQ service was stopped successfully.`. I uninstalled, set the HOMEDRIVE, and installed. Got a massive error listing.\n- Updated post with attempt per comment above.\n- `format: \"Failed to create cookie file 'l:/.erlang.cookie': enoent\"` - ensure that `HOMEDRIVE` and `HOMEPATH` both use `C:`. Or, create a local admin user. Domain users seem to have problems like these.\n- Thanks, @LukeBakken. I think I'll punt and just move to linux. That seems to be the more-traveled path.\n- It works for me :) 1 uninstall rebbitmq 2 login using local admin \"Administrator\" account 3 insall rabbitmq 4 enable rebbitmq_management","metadata":{"transformedAt":"2026-08-18T18:33:20.167Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":195,"estimatedTokens":3844}}503{"id":"stack-49071667","source":"stackoverflow","questionId":49071667,"title":"Can't enable plugin in rabbitmq 3.7.3","tags":["rabbitmq"],"text":"Title: Can't enable plugin in rabbitmq 3.7.3\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have a web application that receives location data via web sockets. I have installed rabbitmq on my mac via homebrew to run the web sockets locally. I am trying to enable rabbitmq_web_stomp but I get this error :\n` \n\n```\nrabbitmq-plugins enable rabbitmq_web_stomp\nError:\n{:plugins_not_found, [:rabbitmq_management_visualiser]\n```\n\nAnd when I run `rabbitmq-plugins list`\n\n```\nWARNING - plugins currently enabled but missing: rabbitmq_management_visualiser\n\n Configured: E = explicitly enabled; e = implicitly enabled\n | Status: * = running on rabbit@localhost\n |/\n[E*] rabbitmq_amqp1_0 3.7.3\n[ ] rabbitmq_auth_backend_cache 3.7.3\n[ ] rabbitmq_auth_backend_http 3.7.3\n[ ] rabbitmq_auth_backend_ldap 3.7.3\n[ ] rabbitmq_auth_mechanism_ssl 3.7.3\n[ ] rabbitmq_consistent_hash_exchange 3.7.3\n[ ] rabbitmq_event_exchange 3.7.3\n[ ] rabbitmq_federation 3.7.3\n[ ] rabbitmq_federation_management 3.7.3\n[ ] rabbitmq_jms_topic_exchange 3.7.3\n[E*] rabbitmq_management 3.7.3\n[e*] rabbitmq_management_agent 3.7.3\n[E*] rabbitmq_mqtt 3.7.3\n[ ] rabbitmq_peer_discovery_aws 3.7.3\n[ ] rabbitmq_peer_discovery_common 3.7.3\n[ ] rabbitmq_peer_discovery_consul 3.7.3\n[ ] rabbitmq_peer_discovery_etcd 3.7.3\n[ ] rabbitmq_peer_discovery_k8s 3.7.3\n[ ] rabbitmq_random_exchange 3.7.3\n[ ] rabbitmq_recent_history_exchange 3.7.3\n[ ] rabbitmq_sharding 3.7.3\n[ ] rabbitmq_shovel 3.7.3\n[ ] rabbitmq_shovel_management 3.7.3\n[E*] rabbitmq_stomp 3.7.3\n[ ] rabbitmq_top 3.7.3\n[ ] rabbitmq_tracing 3.7.3\n[ ] rabbitmq_trust_store 3.7.3\n[e*] rabbitmq_web_dispatch 3.7.3\n[ ] rabbitmq_web_mqtt 3.7.3\n[ ] rabbitmq_web_mqtt_examples 3.7.3\n[ ] rabbitmq_web_stomp 3.7.3\n[ ] rabbitmq_web_stomp_examples 3.7.3\n```\n\nBut when look at docs https://www.rabbitmq.com/plugins.html\nIt says rabbitmq_management_visualiser is discontinued and no longer maintained.\n\nHow do I fix this?\n\n========================================\n\nTop Answer:\nIm my case i had an azure container and i discovered plugins were installed under /opt/rabbitmq/plugins instead of /usr/lib/rabbitmq/plugins according with the official guide:\n\nhttps://www.rabbitmq.com/prometheus.html\n\nI changed the plugins path in the script and i installed the plugin.\n\n========================================\n\nCode:\n```text\nrabbitmq-plugins enable rabbitmq_web_stomp\nError:\n{:plugins_not_found, [:rabbitmq_management_visualiser]\n```\n\n```text\nWARNING - plugins currently enabled but missing: rabbitmq_management_visualiser\n\n Configured: E = explicitly enabled; e = implicitly enabled\n | Status: * = running on rabbit@localhost\n |/\n[E*] rabbitmq_amqp1_0 3.7.3\n[ ] rabbitmq_auth_backend_cache 3.7.3\n[ ] rabbitmq_auth_backend_http 3.7.3\n[ ] rabbitmq_auth_backend_ldap 3.7.3\n[ ] rabbitmq_auth_mechanism_ssl 3.7.3\n[ ] rabbitmq_consistent_hash_exchange 3.7.3\n[ ] rabbitmq_event_exchange 3.7.3\n[ ] rabbitmq_federation 3.7.3\n[ ] rabbitmq_federation_management 3.7.3\n[ ] rabbitmq_jms_topic_exchange 3.7.3\n[E*] rabbitmq_management 3.7.3\n[e*] rabbitmq_management_agent 3.7.3\n[E*] rabbitmq_mqtt 3.7.3\n[ ] rabbitmq_peer_discovery_aws 3.7.3\n[ ] rabbitmq_peer_discovery_common 3.7.3\n[ ] rabbitmq_peer_discovery_consul 3.7.3\n[ ] rabbitmq_peer_discovery_etcd 3.7.3\n[ ] rabbitmq_peer_discovery_k8s 3.7.3\n[ ] rabbitmq_random_exchange 3.7.3\n[ ] rabbitmq_recent_history_exchange 3.7.3\n[ ] rabbitmq_sharding 3.7.3\n[ ] rabbitmq_shovel 3.7.3\n[ ] rabbitmq_shovel_management 3.7.3\n[E*] rabbitmq_stomp 3.7.3\n[ ] rabbitmq_top 3.7.3\n[ ] rabbitmq_tracing 3.7.3\n[ ] rabbitmq_trust_store 3.7.3\n[e*] rabbitmq_web_dispatch 3.7.3\n[ ] rabbitmq_web_mqtt 3.7.3\n[ ] rabbitmq_web_mqtt_examples 3.7.3\n[ ] rabbitmq_web_stomp 3.7.3\n[ ] rabbitmq_web_stomp_examples 3.7.3\n```\n\n```text\nrabbitmq-plugins list\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.167Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":122,"estimatedTokens":1027}}504{"id":"stack-2124221","source":"stackoverflow","questionId":2124221,"title":"RabbitMQ High-speed Transient Messaging Performance","tags":["msmq","rabbitmq","tibco"],"text":"Title: RabbitMQ High-speed Transient Messaging Performance\nTags: msmq, rabbitmq, tibco\nSource: Stack Overflow\n\nQuestion:\nThe system we are building is receiving data through the external feed. Our job is to distribute this data to multiple services, run the calculations and forward the results elsewhere - typical publisher-subscriber situation. What we need is a very low latency messaging. We don't need to persist the messages like MSMQ.\n\nIs RabbitMq fast enough for a soft realtime message delivery? Are there any benchmarks? \nIs it a good idea to use it instead of TIBCO Rendezvous? \nAre there any other open-source soft real time messaging alternatives?\n\nThanks.\n\n========================================\n\nTop Answer:\nYou should be able to achieve many tens of thousands of messages per second per CPU. For example one of our standard tests pushes 25k messages per second from a Java client to the server running on a quad core COTS debian box, and back to the client. The client and server are running on the same box, so that's 50k messages processed per second on the server plus 50k messages processed per second on the client. You can get higher rates by running the server on a dedicated box with more cores. For rates based on bytes/second please ask on the rabbitmq-discuss mailing list.\n\nalexis\n\n========================================\n\nComments:\n- Thank you for the answer. Do you know what are the numbers considered to be high for messages-per-second, bytes-per-second?","metadata":{"transformedAt":"2026-08-18T18:33:20.167Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":24,"estimatedTokens":373}}505{"id":"stack-9486047","source":"stackoverflow","questionId":9486047,"title":"Using EasyNetQ with RabbitMQ to publish and receive messages","tags":["rabbitmq","message-queue","easynetq"],"text":"Title: Using EasyNetQ with RabbitMQ to publish and receive messages\nTags: rabbitmq, message-queue, easynetq\nSource: Stack Overflow\n\nQuestion:\nI'm new to messaging, and currently investigating using RabbitMQ as part of our system architecture to provide messaging between different services. I've got a basic RabbitMQ example working and it can transmit a basic text message over the bus. It looks like EasyNetQ could simply some of the complexity of using RabbitMQ, though I'm having a little trouble getting it working.\n\nInstead of just a string, I'd like to send a more advanced message represented by the following class:\n\n```\npublic class Message\n{\n public string Text { get; set; }\n public int RandomNumber { get; set; }\n public DateTime Date { get; set; }\n}\n```\n\nI'm trying to send this by publishing it to the queue, and then have the subscriber pick it up off the queue. My code is as follows:\n\n**Publisher**\n\n```\nusing (var bus = RabbitHutch.CreateBus(\"host=localhost\"))\n{\n var message = new Message() { Text = \"Hello World\", RandomNumber = new Random().Next(1,100), Date = DateTime.Now };\n bus.Publish(message);\n}\n```\n\n**Receiver**\n\n```\nusing (var bus = RabbitHutch.CreateBus(\"host=localhost\"))\n{\n bus.Subscribe(\"test\", m => Console.WriteLine(string.Format(\"Text: {0}, RandomNumber: {1}, Date: {2}\", m.Text, m.RandomNumber, m.Date)));\n}\n```\n\nBoth sides seem to connect, and the publisher reports that the message was published:\n\n```\nDEBUG: Trying to connect\nINFO: Connected to RabbitMQ. Broker: 'localhost', VHost: '/'\nDEBUG: Published UserQuery+Message:query_lzzfst, CorrelationId ec81fc89-4d60-4a8b-8ba2-7a6d0818d2ed\n```\n\nThe subscriber logs the following:\n\n```\nDEBUG: Trying to connect\nINFO: Connected to RabbitMQ. Broker: 'localhost', VHost: '/'\n```\n\nIt looks like the subscriber is either not connecting to a queue (or the correct queue), or there is something else I need to do to actually receive the message?\n\n========================================\n\nTop Answer:\nRabbitMQ has a management add-on (http://www.rabbitmq.com/management.html ) which is essential when working with rabbit: it will show you the exchanges and queues and the client which are connected. So you should be able to see if the receiver is connected to the queue.\n\nBe careful about the order as an Exchange will not hold a copy of a message sent to it; merely pass it to the queues bound to it (or other exchanges in later versions) so if you send a message to an exchange and the create a receiver - which creates a temp queue and binds this queue to the exchange - its possible the message has already been processed - RabbitMQ is very fast (just thinking out loud)\n\nEasyNetQ is a look piece of work butthe not dealing with ACK messages might be an issue for some type of app. RabbitMQ, unlike others, supports more models than pub/sub so using EasyNetQ will limit you - which might be an issue depends on your app etc.\n\nThanks\n\nSimon\n\n========================================\n\nCode:\n```text\npublic class Message\n{\n public string Text { get; set; }\n public int RandomNumber { get; set; }\n public DateTime Date { get; set; }\n}\n```\n\n```text\nusing (var bus = RabbitHutch.CreateBus(\"host=localhost\"))\n{\n var message = new Message() { Text = \"Hello World\", RandomNumber = new Random().Next(1,100), Date = DateTime.Now };\n bus.Publish<Message>(message);\n}\n```\n\n```text\nusing (var bus = RabbitHutch.CreateBus(\"host=localhost\"))\n{\n bus.Subscribe<Message>(\"test\", m => Console.WriteLine(string.Format(\"Text: {0}, RandomNumber: {1}, Date: {2}\", m.Text, m.RandomNumber, m.Date)));\n}\n```\n\n```text\nDEBUG: Trying to connect\nINFO: Connected to RabbitMQ. Broker: 'localhost', VHost: '/'\nDEBUG: Published UserQuery+Message:query_lzzfst, CorrelationId ec81fc89-4d60-4a8b-8ba2-7a6d0818d2ed\n```\n\n```text\nDEBUG: Trying to connect\nINFO: Connected to RabbitMQ. Broker: 'localhost', VHost: '/'\n```\n\n========================================\n\nComments:\n- Yep, the management add on is very useful and definitely essential when doing anything with RabbitMQ.\n- Thanks Mike. Ended up creating a custom wrapper to serve the needs of our project, but will keep an eye on EasyNetQ for any updates.","metadata":{"transformedAt":"2026-08-18T18:33:20.167Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":112,"estimatedTokens":1044}}506{"id":"stack-44880870","source":"stackoverflow","questionId":44880870,"title":"RabbitMQ EventBasicConsumer not working","tags":["c#",".net","rabbitmq","topshelf"],"text":"Title: RabbitMQ EventBasicConsumer not working\nTags: c#, .net, rabbitmq, topshelf\nSource: Stack Overflow\n\nQuestion:\n**BACKGROUND INFO**\n\nI have a queue (**for emails**) in RabbitMQ, and want to build a consumer for it. The queue is used by another .NET app for sending emails to customers. I wanted the emailing logic to sit outside of the .NET app, and also have the benefits of durability ...etc that RabbitMQ offers.\n\n**ISSUE**\n\nThe .NET app is able to publish/push emails onto the queue, but I have difficulty building the consumer! Here's my code for the consumer:\n\n```\n// A console app that would be turned into a service via TopShelf\npublic void Start()\n{\n using (_connection = _connectionFactory.CreateConnection())\n {\n using (var model = _connection.CreateModel())\n {\n model.QueueDeclare(_queueName, true, false, false, null);\n model.BasicQos(0, 1, false);\n\n var consumer = new EventingBasicConsumer(model);\n consumer.Received += (channelModel, ea) =>\n {\n var message = (Email) ea.Body.DeSerialize(typeof(Email));\n Console.WriteLine(\"----- Email Processed {0} : {1}\", message.To, message.Subject);\n model.BasicAck(ea.DeliveryTag, false);\n };\n var consumerTag = model.BasicConsume(_queueName, false, consumer);\n }\n }\n}\n```\n\nThe code above should be able to grab messages off the queue and process them (according to this official guide), but this isn't happening.\n\n========================================\n\nTop Answer:\nYou said queue is used by another .Net app, is that another consumer? If that is another consumer then can you please confirm which exchange you are using? If you want multiple consumers to pick up the message then please go ahead with \"FanOut\" exchange\n\n========================================\n\nCode:\n```text\n// A console app that would be turned into a service via TopShelf\npublic void Start()\n{\n using (_connection = _connectionFactory.CreateConnection())\n {\n using (var model = _connection.CreateModel())\n {\n model.QueueDeclare(_queueName, true, false, false, null);\n model.BasicQos(0, 1, false);\n\n var consumer = new EventingBasicConsumer(model);\n consumer.Received += (channelModel, ea) =>\n {\n var message = (Email) ea.Body.DeSerialize(typeof(Email));\n Console.WriteLine(\"----- Email Processed {0} : {1}\", message.To, message.Subject);\n model.BasicAck(ea.DeliveryTag, false);\n };\n var consumerTag = model.BasicConsume(_queueName, false, consumer);\n }\n }\n}\n```\n\n```text\nBasicConsume\n```\n\n========================================\n\nComments:\n- Many things can go wrong. How do you publish messages (to which exchange)? Also in your current code - connection will be closed immediately after you create your consumer (after `BasicConsume`) so you won't be able to get any messages anyway. Do not dispose your connection right after starting consumption.\n- @Evk both the publisher and consumer are targeting the same exchange and queue, of that I am certain. But I think you are right about the connection disposal, I'll fix that, and see if that does anything.\n- @Evk you were right, the disposing of the connection was the issue, please reply and I'll mark as answer :)\n- It turned out to be what @Evk suggested.","metadata":{"transformedAt":"2026-08-18T18:33:20.167Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":82,"estimatedTokens":803}}507{"id":"stack-22636439","source":"stackoverflow","questionId":22636439,"title":"Architecture for distributed workers","tags":["node.js","redis","rabbitmq"],"text":"Title: Architecture for distributed workers\nTags: node.js, redis, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nWe are creating a website able to distribute tasks across multiple geographical sites.\nThe website should be able to:\n\n- create a task,\n\n- put it in a queue,\n\n- assign it to a worker depending on a geographical criteria,\n\n- update the web interface according to the working status (step 1, 2 3 etc.),\n\n- save the final result in mongodb and notice the web interface.\n\nWe can have parallel jobs working as long as they are not in the same geographical criteria. \n\nWe can delete a job as long as it is not in processing state.\n\nOur current stack is: Angulajs - nodejs - mongodb.\n\nOur first idea was to make an HTTP pooling from the distant workers to the mongodb task. The point is that we will have more than 20 distant workers and we would like a high frequency refresh (After some researchs on the web, we found documentation on rabbitMQ and message system. This seems to fit most of our requirements but I don’t see how we can delete a specific job in a queue in pending state and how we can easily handle the update of the task status.\n\nWe found also documentation about redis, a KV system in RAM. This solves the issue to be able to delete a specific task in a queue and reduce mongodb load but we don’t see how we will be able to notice distant worker on the job to do. If it is HTTP pooling, we lost all the benefits.\n\nOur situation seems to be a usual problem I and would like to know what the best solution is?\n\n========================================\n\nTop Answer:\n### Redis\n\nRedis is great because you can use it for other features besides Job Queuing, like caching. I personally use Kue. Kueing jobs across datacenters might not be the best decision. Though I don't understand your circumstance, it's generally accepted that your data model be centralized where as your content be distributed. I run a service that hosts an API in San Fransisco, and has CDN nodes in San Fran and NYC. My content is server side templates, images, scripts, css, etc. Which can be completely populated by my API.\n\n### Outsource\n\nIf you absolutely need this functionality I would personally recommend iron.io. They offer 2 services that may be able to solve your problem. Firstly they offer an MQ system through a RESTful API, which is very easy to use and works perfectly with node. The also offer a Worker service, which allows you to queue, schedule, and run tasks on their stack. This would be limiting if you needed to access resources from your own cloud, in which case I would recommend ironMQ.\n\n### Insource\n\nIf you don't want to outsource your service, and you want to host an MQ I would not recommend rabbitMQ for job queuing. I'd recommend something like beanstalkd which is more geared towards *job queuing*, where as RabbitMQ is more geared towards **message queuing**(who'd thunk?).\n\n### Additionally:\n\nHaving read some of the comments to some of the other answers it seems to me that beanstalkd might be your best approach. It's more specific to job queuing, whereas many other MQ systems are to message about updates and push new data across your cloud in realtime and you'll have to implement your own Job Queuing system on top of that.\n\n========================================\n\nCode:\n```text\naws-sdk\n```\n\n```text\nvar internalQueue = async.queue(function (doc, callback) {\n doc.status = 2; \n doc.save(function(e){ // We update the status of the task\n // And we follow from here, doing whatever we want to do\n })\n}, 1);\n\n\n\nmongoose\n.TaskModel\n.find({\n status: 1,\n region: \"KH\" // Unstarted stuff from Camboya\n})\n.stream()\n.on('data', function (doc){\n internalQueue.push(doc, function(e){\n console.log('We have finished our task, alert the web interface or save me or something');\n });\n});\n```\n\n```text\ndb.createCollection('test', {capped: true, size: 100*1000, max: 100} )\n```\n\n========================================\n\nComments:\n- Redis has pub/sub where you can subscribe your workers and they will be notified when there is work there. But any pub/sub solution would only scale and perform well in LANs... if you need a WAN solution you could look into Shovel or something like that to replicate your brokers.\n- Thank you for your help. So if my understanding is good redis pub/sub is not adapted for WAN. I will have to use RabbitMQ with shovel. Regarding the deletion of a specific task in a queue, I had the suggestion to add an admin queue per worker in which I can send message like 'IGNORE TASK #111'. This solution seems to work but is-it a relevant solution?\n- You cant guarantee that the admin message will reach consumers before the task is actually executed. RabbitMQ won't help you on this case. You are better off replicating the KV store (like Redis) across WAN if you want to control your queues.\n- Thank you but we can't depend on Amazon and we need to be able to run it on private global network\n- Ok, I understand. I've also have positive experience with Kafka. kafka.apache.org\n- Thank you, but how will I be able to display the working status on the web page as I don't have access to the queue content? Should I write a special consumer that consume and reinject all the content in the queue or should I have a special collection in mongodb that will be updated ?\n- The second one. I never use it, but you could considerer also www.celeryproject.org\n- After a long reflection on this topic, we will use the RabbitMQ solution\n- Thank you, I need to study beanstalkd closely. Seems interesting.\n- As someone else had mentioned SQS is a good option, but it's ultimately an outsourced solution.\n- To be quite honest, all these queuing services are really meant to be `inbound`. Redis might actually be one of the better outbound solutions simple because it offers more security features. I still wouldn't deem this good practice. You should really consider *not distributing your cluster geographically*. Can you explain why this must be done? You should really keep your API in *one* location, and distribute your content through a CDN.\n- Maybe the approch is not good. We are working on a central web server that is able to distribute tests accross multiple geographical sites. We have some probes that need to do this work asynchronously. The probe must launch a job maximum 1 second after the action request from the webserver. We need to communicate between the webserver and the probe over the net. Our first prototype is using HTTP pooling from the probe to the web central server but I was wondering if a queue message system can improve the architecture and ease the maintenance.\n- @Julio I think you're looking for something that's much more specific to your needs than a Job Queue or a Message Queue. It would be very difficult and sloppy to discuss this through comments. If you could create a new question and perhaps comment a link to this question. I would be more than happy to give you a more extensive answer specific to the technology you're trying to implement.\n- @tsturzl I found many people reported issues on Kue, you can refer here github.com/Automattic/kue/issues/130 did you use it in production? if so, what is your experience? Thanks.\n- Thank you. For your solution, the worker will have to be on a the same LAN as the DB. We will have to pull on the `TaskModel` capped collection, isn't it?\n- I think you don't need to be in the same LAN as the DB. I have done it with mongolab for example. If the worker can connect with mongoDB it can stream from the capped collection.\n- Yes, the `TaskModel` is supposed to be the model from where you pull the information.","metadata":{"transformedAt":"2026-08-18T18:33:20.167Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":104,"estimatedTokens":1915}}508{"id":"stack-39214569","source":"stackoverflow","questionId":39214569,"title":"Spring amqp: How can I read MessageProperties in MessageListenerAdapter","tags":["rabbitmq","spring-amqp","spring-rabbit"],"text":"Title: Spring amqp: How can I read MessageProperties in MessageListenerAdapter\nTags: rabbitmq, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nhandleMessage method does not get the message from queue if I add MessageProperties in its signature. It works fine if there is no MessageProperties. \n\nHow can I get MessageProperties in handleMessage of MessageListenerAdapter? \n\n```\npublic class EventMessageAdapter {\n\n public void handleMessage(MessageProperties messageProperties, Event event) {\n ...\n String id = messageProperties.getHeaders().get(\"key\");\n}\n```\n\n========================================\n\nCode:\n```text\npublic class EventMessageAdapter {\n\n public void handleMessage(MessageProperties messageProperties, Event event) {\n ...\n String id = messageProperties.getHeaders().get(\"key\");\n}\n```\n\n```text\n@RabbitListener(queues = \"foo\")\npublic void foo(Event event, @Header(\"foo\") String fooHeader, \n @Header(\"bar\") Integer barHeader) {...}\n```\n\n```text\n@RabbitListener(queues = \"bar\")\npublic void bar(Event event, Message message) {...}\n```\n\n```text\n@RabbitListener\n```\n\n```text\nmessage.getMessageProperties()\n```\n\n========================================\n\nComments:\n- The second option is exactly what I needed. Thank you, sir.\n- How to get the headers from the message (not the properties, but the actual headers)? `message.getMessageProperties()` returns the properties.\n- When I publish a message from the RabbitMQ Management UI, I put in the \"Headers\" a simple header, but can't get it in my listener.\n- You shouldn't ask new questions in comments; it doesn't help others find questions and answers. `message.getMessageProperties().getHeaders()`.\n- just in case someone stumbles on this answer, the link to the documentation is broken and one should use this instead: docs.spring.io/spring-amqp/reference/html/…\n- Alternate link is also broken.\n- I fixed the links in the answer docs.spring.io/spring-amqp/reference/amqp/receiving-messages‌​/…","metadata":{"transformedAt":"2026-08-18T18:33:20.167Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":59,"estimatedTokens":502}}509{"id":"stack-46125675","source":"stackoverflow","questionId":46125675,"title":"Rabbit listener annotation get queue name from yaml","tags":["spring-boot","rabbitmq","spring-rabbit"],"text":"Title: Rabbit listener annotation get queue name from yaml\nTags: spring-boot, rabbitmq, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI currently have my rabbit listener annotation set as:\n\n@RabbitListener(queues = \"my-queue\")\n\nIs it not possible to pull in the queue name from my yaml file. The reason I want to do this, is so that I can change my queue to a test queue for my integration test, simply by changing the queue name in the yaml file. It appears the annotation must accept a constant string, is there a way round this? Thanks,\n\n========================================\n\nCode:\n```text\n@RabbitListener(queues = \"${myQueue.property}\")\n```\n\n```text\nproperties place holder\n```\n\n```text\nmyQueue.property\n```\n\n========================================\n\nComments:\n- what if i have to configure listener for multiple queues?\n- The `queues` is multi-value option, so you just can do this `queues = {\"queue1\", \"queue2\"}`\n- That's not what I want I should be able to to configure multiple queues without doing code change\n- Well, that's not clear from your plain comment. So, you need to specify those queues in the properties file for your application, and use the same properties placeholder mechanism, but wrapped into this SpEL expression: `\"#{'${myQueue.property}'.split(',')}`","metadata":{"transformedAt":"2026-08-18T18:33:20.167Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":33,"estimatedTokens":322}}510{"id":"stack-41085116","source":"stackoverflow","questionId":41085116,"title":"Docker container not started because rabbit is out of disc space","tags":["docker","rabbitmq","docker-compose"],"text":"Title: Docker container not started because rabbit is out of disc space\nTags: docker, rabbitmq, docker-compose\nSource: Stack Overflow\n\nQuestion:\nRabbitMQ seems to have taken too much diskspace and doesn't start. How can I delete it on my Mac? I cannot seem to find it. I already tried deleting all images and containers and then rebuild from scratch hoping it would solve the problem. \n\n```\n$docker logs rabbitmq\n\n RabbitMQ 3.6.6. Copyright (C) 2007-2016 Pivotal Software, Inc.\n ## ## Licensed under the MPL. See http://www.rabbitmq.com/\n ## ##\n ########## Logs: tty\n ###### ## tty\n ##########\n Starting broker...\n\n=INFO REPORT==== 11-Dec-2016::10:06:13 ===\nStarting RabbitMQ 3.6.6 on Erlang 19.0.7\nCopyright (C) 2007-2016 Pivotal Software, Inc.\nLicensed under the MPL. See http://www.rabbitmq.com/\n\n=INFO REPORT==== 11-Dec-2016::10:06:13 ===\nnode : rabbit@538f7beedbe3\nhome dir : /var/lib/rabbitmq\nconfig file(s) : /etc/rabbitmq/rabbitmq.config\ncookie hash : kOyaDgypIBcP8tZ01/3Fdg==\nlog : tty\nsasl log : tty\ndatabase dir : /var/lib/rabbitmq/mnesia/rabbit@538f7beedbe3\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\nMemory limit set to 799MB of 1997MB total.\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\nDisk free limit set to 50MB\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\nDisk free space insufficient. Free bytes:0 Limit:50000000\n\n=WARNING REPORT==== 11-Dec-2016::10:06:18 ===\ndisk resource limit alarm set on node rabbit@538f7beedbe3.\n\n**********************************************************\n*** Publishers will be blocked until this alarm clears ***\n**********************************************************\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\nLimiting to approx 1048476 file handles (943626 sockets)\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\nFHC read buffering: OFF\nFHC write buffering: ON\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\nDatabase directory at /var/lib/rabbitmq/mnesia/rabbit@538f7beedbe3 is empty. Initialising from scratch...\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\n application: mnesia\n exited: stopped\n type: temporary\n\n=CRASH REPORT==== 11-Dec-2016::10:06:18 ===\n crasher:\n initial call: application_master:init/4\n pid: \n registered_name: []\n exception exit: {{cannot_create_schema,\n {file_error,\n \"/var/lib/rabbitmq/mnesia/rabbit@538f7beedbe3/rabbit@538f7beedbe3514846847780.BUPTMP\",\n enospc}},\n {rabbit,start,[normal,[]]}}\n in function application_master:init/4 (application_master.erl, line 134)\n ancestors: []\n messages: [{'EXIT',,normal}]\n links: [,]\n dictionary: []\n trap_exit: true\n status: running\n heap_size: 1598\n stack_size: 27\n reductions: 98\n neighbours:\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\n application: rabbit\n exited: {{cannot_create_schema,\n {file_error,\n \"/var/lib/rabbitmq/mnesia/rabbit@538f7beedbe3/rabbit@538f7beedbe3514846847780.BUPTMP\",\n enospc}},\n {rabbit,start,[normal,[]]}}\n type: temporary\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\n application: ranch\n exited: stopped\n type: temporary\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\n application: os_mon\n exited: stopped\n type: temporary\n\nBOOT FAILED\n===========\n\nError description:\n {could_not_start,rabbit,\n {{cannot_create_schema,\n {file_error,\n \"/var/lib/rabbitmq/mnesia/rabbit@538f7beedbe3/rabbit@538f7beedbe3514846847780.BUPTMP\",\n enospc}},\n {rabbit,start,[normal,[]]}}}\n\nLog files (may contain more information):\n tty\n tty\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\n application: amqp_client\n exited: stopped\n type: temporary\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\n application: syntax_tools\n exited: stopped\n type: temporary\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\n application: rabbit_common\n exited: stopped\n type: temporary\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\n application: xmerl\n exited: stopped\n type: temporary\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\n application: asn1\n exited: stopped\n type: temporary\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\n application: inets\n exited: stopped\n type: temporary\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\nError description:\n {could_not_start,rabbit,\n {{cannot_create_schema,\n {file_error,\n \"/var/lib/rabbitmq/mnesia/rabbit@538f7beedbe3/rabbit@538f7beedbe3514846847780.BUPTMP\",\n enospc}},\n {rabbit,start,[normal,[]]}}}\n\nLog files (may contain more information):\n tty\n tty\n\n{\"init terminating in do_boot\",{could_not_start,rabbit,{{cannot_create_schema,{file_error,\"/var/lib/rabbitmq/mnesia/rabbit@538f7beedbe3/rabbit@538f7beedbe3514846847780.BUPTMP\",enospc}},{rabbit,start,[normal,[]]}}}}\ninit terminating in do_boot ()\n\nCrash dump is being written to: erl_crash.dump...\n```\n\nCould I definde a physical volume for Rabbit in my docker-compose.yml?\n\n========================================\n\nTop Answer:\nYou can get rid of your dangling volumes also by running this command:\n\n```\ndocker system prune -a\n```\n\n========================================\n\nCode:\n```text\n$docker logs rabbitmq\n\n RabbitMQ 3.6.6. Copyright (C) 2007-2016 Pivotal Software, Inc.\n ## ## Licensed under the MPL. See http://www.rabbitmq.com/\n ## ##\n ########## Logs: tty\n ###### ## tty\n ##########\n Starting broker...\n\n=INFO REPORT==== 11-Dec-2016::10:06:13 ===\nStarting RabbitMQ 3.6.6 on Erlang 19.0.7\nCopyright (C) 2007-2016 Pivotal Software, Inc.\nLicensed under the MPL. See http://www.rabbitmq.com/\n\n=INFO REPORT==== 11-Dec-2016::10:06:13 ===\nnode : rabbit@538f7beedbe3\nhome dir : /var/lib/rabbitmq\nconfig file(s) : /etc/rabbitmq/rabbitmq.config\ncookie hash : kOyaDgypIBcP8tZ01/3Fdg==\nlog : tty\nsasl log : tty\ndatabase dir : /var/lib/rabbitmq/mnesia/rabbit@538f7beedbe3\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\nMemory limit set to 799MB of 1997MB total.\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\nDisk free limit set to 50MB\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\nDisk free space insufficient. Free bytes:0 Limit:50000000\n\n=WARNING REPORT==== 11-Dec-2016::10:06:18 ===\ndisk resource limit alarm set on node rabbit@538f7beedbe3.\n\n**********************************************************\n*** Publishers will be blocked until this alarm clears ***\n**********************************************************\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\nLimiting to approx 1048476 file handles (943626 sockets)\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\nFHC read buffering: OFF\nFHC write buffering: ON\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\nDatabase directory at /var/lib/rabbitmq/mnesia/rabbit@538f7beedbe3 is empty. Initialising from scratch...\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\n application: mnesia\n exited: stopped\n type: temporary\n\n=CRASH REPORT==== 11-Dec-2016::10:06:18 ===\n crasher:\n initial call: application_master:init/4\n pid: <0.116.0>\n registered_name: []\n exception exit: {{cannot_create_schema,\n {file_error,\n \"/var/lib/rabbitmq/mnesia/rabbit@538f7beedbe3/rabbit@538f7beedbe3514846847780.BUPTMP\",\n enospc}},\n {rabbit,start,[normal,[]]}}\n in function application_master:init/4 (application_master.erl, line 134)\n ancestors: [<0.115.0>]\n messages: [{'EXIT',<0.117.0>,normal}]\n links: [<0.115.0>,<0.31.0>]\n dictionary: []\n trap_exit: true\n status: running\n heap_size: 1598\n stack_size: 27\n reductions: 98\n neighbours:\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\n application: rabbit\n exited: {{cannot_create_schema,\n {file_error,\n \"/var/lib/rabbitmq/mnesia/rabbit@538f7beedbe3/rabbit@538f7beedbe3514846847780.BUPTMP\",\n enospc}},\n {rabbit,start,[normal,[]]}}\n type: temporary\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\n application: ranch\n exited: stopped\n type: temporary\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\n application: os_mon\n exited: stopped\n type: temporary\n\n\nBOOT FAILED\n===========\n\nError description:\n {could_not_start,rabbit,\n {{cannot_create_schema,\n {file_error,\n \"/var/lib/rabbitmq/mnesia/rabbit@538f7beedbe3/rabbit@538f7beedbe3514846847780.BUPTMP\",\n enospc}},\n {rabbit,start,[normal,[]]}}}\n\nLog files (may contain more information):\n tty\n tty\n\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\n application: amqp_client\n exited: stopped\n type: temporary\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\n application: syntax_tools\n exited: stopped\n type: temporary\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\n application: rabbit_common\n exited: stopped\n type: temporary\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\n application: xmerl\n exited: stopped\n type: temporary\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\n application: asn1\n exited: stopped\n type: temporary\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\n application: inets\n exited: stopped\n type: temporary\n\n=INFO REPORT==== 11-Dec-2016::10:06:18 ===\nError description:\n {could_not_start,rabbit,\n {{cannot_create_schema,\n {file_error,\n \"/var/lib/rabbitmq/mnesia/rabbit@538f7beedbe3/rabbit@538f7beedbe3514846847780.BUPTMP\",\n enospc}},\n {rabbit,start,[normal,[]]}}}\n\nLog files (may contain more information):\n tty\n tty\n\n{\"init terminating in do_boot\",{could_not_start,rabbit,{{cannot_create_schema,{file_error,\"/var/lib/rabbitmq/mnesia/rabbit@538f7beedbe3/rabbit@538f7beedbe3514846847780.BUPTMP\",enospc}},{rabbit,start,[normal,[]]}}}}\ninit terminating in do_boot ()\n\nCrash dump is being written to: erl_crash.dump...\n```\n\n```text\ndocker rmi $(docker images -q) //removes all images\n docker volume rm $(docker volume ls -f dangling=true -q) // removes all volumes\n```\n\n```text\ndocker system prune -a\n```\n\n========================================\n\nComments:\n- u got only 50mb of space. U can change that in rabbit conf\n- Thx. For production yes, but when I run it locally for development. Can I pass a command to compose to clean it up everytime it starts?\n- Future people: just removing the dangling volumes (the second command) resolved this for me. No need to blow away all your images.","metadata":{"transformedAt":"2026-08-18T18:33:20.168Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":360,"estimatedTokens":2542}}511{"id":"stack-56791857","source":"stackoverflow","questionId":56791857,"title":"ASP.NET Core service not creating RabbitMQ queue","tags":["c#","asp.net","rabbitmq","masstransit"],"text":"Title: ASP.NET Core service not creating RabbitMQ queue\nTags: c#, asp.net, rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nBeing a new user of MassTransit and RabbitMQ I'm currently trying to make my ASP.NET core service to work with MassTransit.\n\nTaking this documentation section to configure MassTransit and ASP.NET Core I'm unable to get it working. \n\nCurrently (part of) the Startup.cs looks like \n\n```\nservices.AddMassTransit(x =>\n {\n x.AddConsumer();\n x.AddConsumer();\n\n x.AddBus(provider => ConfigureBus(provider, rabbitMqConfigurations));\n });\n\nprivate IBusControl ConfigureBus(\n IServiceProvider provider,\n RabbitMqConfigSection rabbitMqConfigurations) => Bus.Factory.CreateUsingRabbitMq(\n cfg =>\n {\n var host = cfg.Host(\n rabbitMqConfigurations.Host,\n \"/\",\n hst =>\n {\n hst.Username(rabbitMqConfigurations.Username);\n hst.Password(rabbitMqConfigurations.Password);\n });\n\n cfg.ReceiveEndpoint(host, $\"{typeof(MailSent).Namespace}.{typeof(MailSent).Name}\", endpoint =>\n {\n endpoint.Consumer(provider);\n });\n\n cfg.ReceiveEndpoint(host, $\"{typeof(MailSentFailed).Namespace}.{typeof(MailSentFailed).Name}\", endpoint =>\n {\n endpoint.Consumer(provider);\n });\n });\n```\n\nThe exchange is created automatically in RabbitMQ on startup, but no queue is bind to the exchange which I would expect. \n\nAfter invoking my API endpoint I can see activity on the exchange, but of course the consumers doing nothing as there is no queue. \n\nWhat (obvious) part am I missing?\n\n========================================\n\nTop Answer:\nAccording to the latest MT version, `services.AddMassTransitHostedService();` was deprecated.\n\n**This is related to the RabbitMQ.**\n\nLet's say you have a program which publish the messages to the queue and configured the exchanges for them and you have another program to consume messages from the queue.\n\nIf you run only the publisher program, it will not create a defined queue. When you run the consumer program, it will check the queue existence and if it is not there it will create a queue and bind with the defined exchanges.\n**As a advice, Make sure to run the consumer program before publishing any messages to the queue.** Otherwise you can see RabbitMQ UI that showing message has arrived to the exchange but not in the queue.\n\nI am sharing my thoughts regarding on this since I currently have been working on the .NET core web API project which publish the messages to the queue and have another worker project to consume messages from the queue.\n\nI think this will help you to resolve your matter. Thanks.\n\n========================================\n\nCode:\n```text\nservices.AddMassTransit(x =>\n {\n x.AddConsumer<MailConsumer>();\n x.AddConsumer<MailFailedConsumer>();\n\n x.AddBus(provider => ConfigureBus(provider, rabbitMqConfigurations));\n });\n\n\nprivate IBusControl ConfigureBus(\n IServiceProvider provider,\n RabbitMqConfigSection rabbitMqConfigurations) => Bus.Factory.CreateUsingRabbitMq(\n cfg =>\n {\n var host = cfg.Host(\n rabbitMqConfigurations.Host,\n \"/\",\n hst =>\n {\n hst.Username(rabbitMqConfigurations.Username);\n hst.Password(rabbitMqConfigurations.Password);\n });\n\n cfg.ReceiveEndpoint(host, $\"{typeof(MailSent).Namespace}.{typeof(MailSent).Name}\", endpoint =>\n {\n endpoint.Consumer<MailConsumer>(provider);\n });\n\n cfg.ReceiveEndpoint(host, $\"{typeof(MailSentFailed).Namespace}.{typeof(MailSentFailed).Name}\", endpoint =>\n {\n endpoint.Consumer<MailFailedConsumer>(provider);\n });\n });\n```\n\n```text\nservices.AddMassTransitHostedService();\n```\n\n```text\nAddMassTransit\n```\n\n```text\nIServiceCollection\n```\n\n```text\nAddMassTransit\n```\n\n```text\nAddMassTransit\n```\n\n```text\nAction<IServiceCollectionConfigurator>\n```\n\n```text\nservices.AddMassTransitHostedService();\n```\n\n========================================\n\nComments:\n- Yeah, the MT hosted service doesn't get registered. Can you put your repo on GitHub? I can have a quick look.\n- Thank you! This helps a lot :-) Although now I'm getting `MassTransit bus is not ready` in the health checks. Queues and exchanges are created though!\n- Fixed the `MassTransit bus is not ready` by adding : `cfg.UseHealthCheck(provider);`\n- Yeah, I believe that was in the docs :) Still need to clarify this, thanks for pointing it out :)\n- Do you have an alternative to services.AddMassTransitHostedService() ?","metadata":{"transformedAt":"2026-08-18T18:33:20.168Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":143,"estimatedTokens":1257}}512{"id":"stack-41294754","source":"stackoverflow","questionId":41294754,"title":"Rabbitmq server start failed with file locked","tags":["java","server","rabbitmq"],"text":"Title: Rabbitmq server start failed with file locked\nTags: java, server, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nRabbitmq 3.6.5 start failed with this. How to fix it? \n\n```\nBOOT FAILED\n ===========\n\n Error description: \"Found lock file at ~s.\\n Either previous upgrade is in progress or has failed.\\n Database\n backup path: ~s\"\n\n Log files (may contain more information): \n /var/log/rabbitmq/rabbit@vm-10-111-29-211.log \n /var/log/rabbitmq/rabbit@vm-10-111-29-211-sasl.log\n\n Stack trace: [{rabbit_upgrade,ensure_backup_taken,\n [\"/var/lib/rabbitmq/mnesia/rabbit@vm-10-111-29-211/schema_upgrade_lock\", \"/var/lib/rabbitmq/mnesia/rabbit@vm-10-111-29-211-upgrade-backup\"],\n [{file,\"src/rabbit_upgrade.erl\"},{line,101}]},\n {rabbit_upgrade,maybe_upgrade_mnesia,0,\n [{file,\"src/rabbit_upgrade.erl\"},{line,144}]},\n {rabbit,'-boot/0-fun-0-',0,[{file,\"src/rabbit.erl\"},{line,271}]},\n {rabbit,start_it,1,[{file,\"src/rabbit.erl\"},{line,403}]},\n {init,start_it,1,[]},\n {init,start_em,1,[]}]\n\n {\"init terminating in do_boot\",\"Found lock file at ~s.\\n \n Either previous upgrade is in progress or has failed.\\n \n Database backup path: ~s\"}\n\n Crash dump was written to: erl_crash.dump init terminating in do_boot\n (Found lock file at ~s.\n Either previous upgrade is in progress or has failed.\n Database backup path: ~s)\n```\n\n========================================\n\nCode:\n```text\nBOOT FAILED\n ===========\n\n Error description: \"Found lock file at ~s.\\n Either previous upgrade is in progress or has failed.\\n Database\n backup path: ~s\"\n\n Log files (may contain more information): \n /var/log/rabbitmq/rabbit@vm-10-111-29-211.log \n /var/log/rabbitmq/rabbit@vm-10-111-29-211-sasl.log\n\n Stack trace: [{rabbit_upgrade,ensure_backup_taken,\n [\"/var/lib/rabbitmq/mnesia/rabbit@vm-10-111-29-211/schema_upgrade_lock\", \"/var/lib/rabbitmq/mnesia/rabbit@vm-10-111-29-211-upgrade-backup\"],\n [{file,\"src/rabbit_upgrade.erl\"},{line,101}]},\n {rabbit_upgrade,maybe_upgrade_mnesia,0,\n [{file,\"src/rabbit_upgrade.erl\"},{line,144}]},\n {rabbit,'-boot/0-fun-0-',0,[{file,\"src/rabbit.erl\"},{line,271}]},\n {rabbit,start_it,1,[{file,\"src/rabbit.erl\"},{line,403}]},\n {init,start_it,1,[]},\n {init,start_em,1,[]}]\n\n {\"init terminating in do_boot\",\"Found lock file at ~s.\\n \n Either previous upgrade is in progress or has failed.\\n \n Database backup path: ~s\"}\n\n Crash dump was written to: erl_crash.dump init terminating in do_boot\n (Found lock file at ~s.\n Either previous upgrade is in progress or has failed.\n Database backup path: ~s)\n```\n\n```text\nmnesia\n```\n\n```text\n/var/lib/rabbitmq/mnesia\n```\n\n```text\nmnesia\n```\n\n========================================\n\nComments:\n- Not a question for SO. Please refer to: How to Ask. This belongs on serverfault.com. You also didn't even bother to complete the 2-minute site tour before asking.\n- Thank you, but after delete the directory, it reports another error below Error description: {aborted,undef} Stack trace: [{mnesia,abort,1,[{file,\"mnesia.erl\"},{line,318}]}, {rabbit_node_monitor,legacy_cluster_nodes,1, [{file,\"src/rabbit_node_monitor.erl\"},{line,789}]}, {rabbit_node_monitor,prepare_cluster_status_files,0, [{file,\"src/rabbit_node_monitor.erl\"},{line,121}]}, {rabbit,'-boot/0-fun-0-',0,[{file,\"src/rabbit.erl\"},{line,27‌​0}]}...\n- Add 'sudo' before works, I don't know why, I'm login with root already. Thank u again.","metadata":{"transformedAt":"2026-08-18T18:33:20.168Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":90,"estimatedTokens":878}}513{"id":"stack-38087136","source":"stackoverflow","questionId":38087136,"title":"RabbitMQ: direct reply-to?","tags":["c#",".net","rabbitmq"],"text":"Title: RabbitMQ: direct reply-to?\nTags: c#, .net, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nIs there a good example (C#) of how to do the direct reply-to in RabbitMQ? What I want to do is for X Producers to post a message (\"I've got some work for somebody\") and I want one of X Consumers to pick it up, do the work and send the response back. Not a basic Ack, but some data, the result of the calculation. Of course, the response has to go back to the right producer.\n\nProducer:\n\n```\nusing (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(queue: \"hello\",\n durable: true,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n\n string message = \"Hello World!\";\n var body = Encoding.UTF8.GetBytes(message);\n\n var properties = channel.CreateBasicProperties();\n properties.Persistent = true;\n\n channel.BasicPublish(exchange: \"\",\n routingKey: \"hello\",\n basicProperties: properties,\n body: body);\n\n Console.WriteLine(\" [x] Sent {0}\", message);\n }\n }\n```\n\nConsumer:\n\n```\nusing (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(queue: \"hello\",\n durable: true,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n\n channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false);\n\n var consumer = new EventingBasicConsumer(channel);\n\n consumer.Received += (model, ea) =>\n {\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n Console.WriteLine(\" [x] Received {0}\", message);\n channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);\n };\n\n channel.BasicConsume(queue: \"hello\",\n noAck: false,\n consumer: consumer);\n\n Console.WriteLine(\" Press [enter] to exit.\");\n Console.ReadLine();\n }\n```\n\nIt's not very clear from the minimal docs on how to set up both sides. I know somebody has to do something with the \"amq.rabbitmq.reply-to\" queue, but its not clear which side and what they have to do with it.\n\n========================================\n\nCode:\n```text\nusing (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(queue: \"hello\",\n durable: true,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n\n string message = \"Hello World!\";\n var body = Encoding.UTF8.GetBytes(message);\n\n var properties = channel.CreateBasicProperties();\n properties.Persistent = true;\n\n channel.BasicPublish(exchange: \"\",\n routingKey: \"hello\",\n basicProperties: properties,\n body: body);\n\n Console.WriteLine(\" [x] Sent {0}\", message);\n }\n }\n```\n\n```text\nusing (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(queue: \"hello\",\n durable: true,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n\n channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false);\n\n var consumer = new EventingBasicConsumer(channel);\n\n consumer.Received += (model, ea) =>\n {\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n Console.WriteLine(\" [x] Received {0}\", message);\n channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);\n };\n\n channel.BasicConsume(queue: \"hello\",\n noAck: false,\n consumer: consumer);\n\n Console.WriteLine(\" Press [enter] to exit.\");\n Console.ReadLine();\n }\n```\n\n```text\namq.rabbitmq.reply-to\n```\n\n```text\namq.rabbitmq.reply-to\n```\n\n```text\namq.rabbitmq.reply-to\n```\n\n```text\namq.rabbitmq.reply-to\n```\n\n```text\namq.rabbitmq.reply-to\n```\n\n```text\nreplyTo\n```\n\n```text\namq.rabbitmq.reply-to\n```\n\n========================================\n\nComments:\n- Is there a reasons you aren't using a service for this? When a message is published to a queue and an ack is received, the responsibility for the poster is effectively relinquished. A REST service would be more logical for your case.\n- @Tim, that is just what I have now with no response implemented. Are you talking about HTTP POSTs back and forth? As I said, I might have 5 producers, but maybe 5,000 consumers. The whole point of the message queue is to do all the coordination back and forth and \"load balance\" the requests.\n- I'm just a bit confused regarding the use case. This situation is inversed in the sense that there are usually far more consumers (application servers in your case) than \"producers\" . Why would you have 5000 consumers (that do work) all waiting for a calculation request, with only 5 \"work producers\"? Why not just use haproxy or something similar in front of a REST service to load balance?\n- @Tim, not sure what the confusion is. Think of a producer as a \"job submitter\". A \"job\" is to load / process a batch (of files). A batch might contain 10,000 files. Processing a file is computationally expensive, so that work is distributed across 5,000 worker nodes. You wouldn't do it the way I describe? Consumers = worker nodes in this case, not submitters.\n- FYI: This isn't *really* an answer, but my Shuttle.Esb open-source service bus that has a RabbitMQ transport with a request-response sample. Of course, other service bus implementations would provide the same functionality.\n- Ok, this might get me started.. Thanks!\n- Even though this answer is 4yr old I'd like to point out for future reference that on the third bullet point instead of using \"amq.rabbitmq.reply-to\" as the routing_key, you should use whatever was received on ea.BasicProperties.ReplyTo field. If you print it you'll notice it's not the same.\n- Any chance you know whether this will work with multiple services consuming from `amq.rabbitmq.reply-to`? Will the reply message go to the correct consumer or one of them at random? There is no mention about this in the docs. While, I guess this should go to the right consumer (because if it didn't, I am not sure how valuable this feature would be), I am not sure how RabbitMQ figures out on which consumer it should forward the reply message.\n- I guess the comment from `Cyber Oliveira` above, sheds some light into how RabbitMQ deals with the message, in order to forward it to the correct consumer.","metadata":{"transformedAt":"2026-08-18T18:33:20.168Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":9,"totalLines":174,"estimatedTokens":1686}}514{"id":"stack-30716002","source":"stackoverflow","questionId":30716002,"title":"Is there a size limit on a RabbitMQ message header?","tags":["rabbitmq","spring-amqp"],"text":"Title: Is there a size limit on a RabbitMQ message header?\nTags: rabbitmq, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI plan on storing stacktraces in the RabbitMQ message header. Do message headers have a size limit?\n\n========================================\n\nTop Answer:\nThe answers so far seem to indicate that it would be no problem to cram a stacktrace in a header.\n\nAs John insinuates in his answer previously, some changes were made a couple of years a go that will cause an `IllegalArgumentException` to be thrown when the header size exceeds `frame_max` (by default this is indeed 128kB).\n\n(The source code I'm referring to can be found here!)\n\nAs a (fun) side note, this was done to prevent an issue whereby messages that had single huge header that exceeded max frame size would result in the client creating and transmitting the huge header frame to server and, as a result, the server shuts the connection down with `frame_too_large` error and that breaks all open channels!\n\nIn order to include a stacktrace in a header, you *could* increase the header size, or set it to `0` for 'unlimited', but you should be aware that this isn't particularly advisable in most situations (larger values may improve throughput while smaller values may improve latency).\n\n========================================\n\nCode:\n```text\nfield-table\n```\n\n```text\nlong-string\n```\n\n```text\nstandard delivery details\n```\n\n```text\nCaused by: java.lang.IllegalArgumentException: Content headers exceeded max frame size: 163475 > 131072\n at com.rabbitmq.client.impl.AMQCommand.transmit(AMQCommand.java:115) ~[amqp-client-5.7.3.jar:5.7.3]\n```\n\n```text\nIllegalArgumentException\n```\n\n```text\nframe_max\n```\n\n```text\nframe_too_large\n```\n\n```text\n0\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.168Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":55,"estimatedTokens":434}}515{"id":"stack-29415098","source":"stackoverflow","questionId":29415098,"title":"MonologBundle memory leak (?)","tags":["symfony","memory-leaks","rabbitmq","monolog"],"text":"Title: MonologBundle memory leak (?)\nTags: symfony, memory-leaks, rabbitmq, monolog\nSource: Stack Overflow\n\nQuestion:\nI have a long running process in Symfony2 (rabbit consumer) and I am using the **MonologBundle** for logging. The lines are logged immediately but I have noticed that the memory consumption of the process is increasing with every iteration, reaching over 1GB after a fiew minutes.\n\nThe script runs with: --env=prod\n\nSo i made a smaller test:\n\n```\n// taken from my symfony test command\n $logger = $this->getContainer()->get('logger');\n\n while (true){\n $logger->debug(\"line one\");\n $logger->debug(\"line two\");\n $logger->debug(\"line three\");\n var_dump($logger);\n }\n```\n\nThis is the var_dump content after ~10k iterations:\n\n```\nclass Symfony\\Bridge\\Monolog\\Logger#3 (3) {\n protected $name =>\n string(3) \"app\"\n protected $handlers =>\n array(1) {\n [0] =>\n class Monolog\\Handler\\FingersCrossedHandler#132 (11) {\n protected $handler =>\n class Monolog\\Handler\\StreamHandler#133 (9) {\n ...\n }\n protected $activationStrategy =>\n class Monolog\\Handler\\FingersCrossed\\ErrorLevelActivationStrategy#134 (1) {\n ...\n }\n protected $buffering =>\n bool(true)\n protected $bufferSize =>\n int(0)\n protected $buffer =>\n array(100) {\n ...\n }\n protected $stopBuffering =>\n bool(true)\n protected $passthruLevel =>\n NULL\n protected $level =>\n int(100)\n protected $bubble =>\n bool(true)\n protected $formatter =>\n NULL\n protected $processors =>\n array(0) {\n ...\n }\n }\n }\n protected $processors =>\n array(0) {\n }\n}\n```\n\nMonolog bundle settings:\n\n```\nmonolog:\n handlers:\n main:\n type: fingers_crossed\n action_level: error\n handler: nested\n buffer_size: 100\n nested:\n type: stream\n path: \"%kernel.logs_dir%/%kernel.environment%.log\"\n level: debug\n buffer_size: 100\n\nframework:\n profiler:\n only_exceptions: false\n enabled: false\n collect: false\n```\n\nThe log entries in the buffer do not exceed the buffer_limit but the memory usage of the script still increases.\n\nAny ideas?\nThanks\n\nPS: I repeated the test with plain monolog and there was no memory issue.\n\n========================================\n\nTop Answer:\nYou can also limit the amount of logs stored with \"buffer_size\". See:\n\nhttp://symfony.com/doc/current/reference/configuration/monolog.html\n\n========================================\n\nCode:\n```text\n// taken from my symfony test command\n $logger = $this->getContainer()->get('logger');\n\n while (true){\n $logger->debug(\"line one\");\n $logger->debug(\"line two\");\n $logger->debug(\"line three\");\n var_dump($logger);\n }\n```\n\n```text\nclass Symfony\\Bridge\\Monolog\\Logger#3 (3) {\n protected $name =>\n string(3) \"app\"\n protected $handlers =>\n array(1) {\n [0] =>\n class Monolog\\Handler\\FingersCrossedHandler#132 (11) {\n protected $handler =>\n class Monolog\\Handler\\StreamHandler#133 (9) {\n ...\n }\n protected $activationStrategy =>\n class Monolog\\Handler\\FingersCrossed\\ErrorLevelActivationStrategy#134 (1) {\n ...\n }\n protected $buffering =>\n bool(true)\n protected $bufferSize =>\n int(0)\n protected $buffer =>\n array(100) {\n ...\n }\n protected $stopBuffering =>\n bool(true)\n protected $passthruLevel =>\n NULL\n protected $level =>\n int(100)\n protected $bubble =>\n bool(true)\n protected $formatter =>\n NULL\n protected $processors =>\n array(0) {\n ...\n }\n }\n }\n protected $processors =>\n array(0) {\n }\n}\n```\n\n```text\nmonolog:\n handlers:\n main:\n type: fingers_crossed\n action_level: error\n handler: nested\n buffer_size: 100\n nested:\n type: stream\n path: \"%kernel.logs_dir%/%kernel.environment%.log\"\n level: debug\n buffer_size: 100\n\n\nframework:\n profiler:\n only_exceptions: false\n enabled: false\n collect: false\n```\n\n```text\nfingers_crossed\n```\n\n```text\naction_level\n```\n\n```text\nstream\n```\n\n========================================\n\nComments:\n- I have a question about the buffer_size, what does the number mean? does it mean the size of buffered log or the number of rows? Thanks\n- I think yes, comment in code says `How many entries should be buffered at most, beyond that the oldest items are removed from the buffer.`\n- Note that you need to `bin/console cache:clear` after changing this configuration - I didn't realize this initially.","metadata":{"transformedAt":"2026-08-18T18:33:20.168Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":209,"estimatedTokens":1127}}516{"id":"stack-37870763","source":"stackoverflow","questionId":37870763,"title":"Docker config : Celery + RabbitMQ","tags":["docker","rabbitmq","celery","docker-compose","dockerfile"],"text":"Title: Docker config : Celery + RabbitMQ\nTags: docker, rabbitmq, celery, docker-compose, dockerfile\nSource: Stack Overflow\n\nQuestion:\nHow do I run Celery and RabbitMQ in a docker container? Can you point me to sample dockerfile or compose files?\n\nThis is what I have:\n\nDockerfile:\n\n```\nFROM python:3.4\nENV PYTHONBUFFERED 1\nWORKDIR /tasker\nADD requirements.txt /tasker/\nRUN pip install -r requirements.txt\nADD . /tasker/\n```\n\ndocker-compose.yml\n\n```\nrabbitmq:\n image: tutum/rabbitmq\n environment:\n - RABBITMQ_PASS=mypass\n ports:\n - \"5672:5672\" \n - \"15672:15672\"\ncelery:\n build: .\n command: celery worker --app=tasker.tasks\n volumes:\n - .:/tasker\n links:\n - rabbitmq:rabbit\n```\n\nThe issue I'm having is I cant get Celery to stay alive or running. It keeps exiting.\n\n========================================\n\nTop Answer:\nI have similar Celery exiting problem while dockerizing the application. You should use rabbit service name ( in your case it's `rabbitmq`) as host name in your celery configuration.That is, \nuse `broker_url = 'amqp://guest:guest@rabbitmq:5672//'` instead of `broker_url = 'amqp://guest:guest@localhost:5672//'` . \n\nIn my case, major components are Flask, Celery and Redis.My problem is HERE please check the link, you may find it useful.\n\n========================================\n\nCode:\n```text\nFROM python:3.4\nENV PYTHONBUFFERED 1\nWORKDIR /tasker\nADD requirements.txt /tasker/\nRUN pip install -r requirements.txt\nADD . /tasker/\n```\n\n```text\nrabbitmq:\n image: tutum/rabbitmq\n environment:\n - RABBITMQ_PASS=mypass\n ports:\n - \"5672:5672\" \n - \"15672:15672\"\ncelery:\n build: .\n command: celery worker --app=tasker.tasks\n volumes:\n - .:/tasker\n links:\n - rabbitmq:rabbit\n```\n\n```text\n$ docker run --link some-rabbit:rabbit --name some-celery -d celery\n```\n\n```text\n$ docker run --link some-rabbit:rabbit --rm celery celery status\n```\n\n```text\ntasks.py\n```\n\n```text\ncelery ... worker\n```\n\n```text\ndocker-compose\n```\n\n```text\ndocker-compose.yml\n```\n\n```text\nlocal.yml\n```\n\n```text\nstart.sh\n```\n\n```text\nCMD [\"celery\", \"worker\"]\n```\n\n```text\nFROM celery\n```\n\n```text\nFROM python\n```\n\n```text\nversion: '2'\nservices:\nrabbit:\n hostname: rabbit\n image: rabbitmq:latest\n environment:\n - RABBITMQ_DEFAULT_USER=admin\n - RABBITMQ_DEFAULT_PASS=mypass\n ports:\n - \"5672:5672\"\n\nworker:\n build:\n context: .\n dockerfile: dockerfile\n volumes:\n - .:/app\n links:\n - rabbit\n depends_on:\n - rabbit\n```\n\n```text\nrabbitmq\n```\n\n```text\nbroker_url = 'amqp://guest:guest@rabbitmq:5672//'\n```\n\n```text\nbroker_url = 'amqp://guest:guest@localhost:5672//'\n```\n\n========================================\n\nComments:\n- Can't you use the docker images of celery? I am not sure what you are trying to do with your Dockerfile either. One thing for suer is, it is missing ENTRYPOINT.\n- The celery image is now officially deprecated in favor of the official python image : hub.docker.com/r/library/celery\n- @FloranGmehlin Thank you. I have included your comment in the answer for more visibility.","metadata":{"transformedAt":"2026-08-18T18:33:20.168Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":17,"totalLines":164,"estimatedTokens":769}}517{"id":"stack-33384341","source":"stackoverflow","questionId":33384341,"title":"How to connect to RabbitMQ using RabbitMQ JMS client from an existing JMS application?","tags":["java","jms","rabbitmq"],"text":"Title: How to connect to RabbitMQ using RabbitMQ JMS client from an existing JMS application?\nTags: java, jms, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have a generic standalone JMS application which works with following JMS providers WebSphere, HornetQ and ActiveMq. I pass Context.INITIAL_CONTEXT_FACTORY and Context.PROVIDER_URL as parameters to my application and create a naming context out of them by doing something like this \n\n```\nProperties environmentParameters = new Properties();\nenvironmentParameters.put(Context.INITIAL_CONTEXT_FACTORY, property.context);\nenvironmentParameters.put(Context.PROVIDER_URL, property.provider);\nnamingContext = new InitialContext(environmentParameters);\n```\n\nAnd use this context for object lookup. \n\nI understand RabbitMQ isn't a JMS provider so it doesn't have an InitialContext class or a Provider URL but it provides a JMS Client which is an abstraction of its Java client conforming to JMS specification. RabbitMQ's JMS client documentation has an example of defining objects in JNDI as a resource configuration as part of a web application but I quite couldn't figure out how to do something similar for my standalone application which creates a naming context based on JNDI provider using JMS client's dependencies or to create an InitialContext out of the available dependencies. \n\nSo can someone throw some light on how this can be done? Hope my question is clear.\n\n========================================\n\nTop Answer:\nIn order to get **JMS** working with **RabbitMQ**, you have to **enable** the **plugin rabbitmq_jms_topic_exchange**. \n\nYou can download it following the directions in this site (You'll need to login):\n \nhttps://my.vmware.com/web/vmware/details?downloadGroup=VFRMQ_JMS_105&productId=349\n\n- After extraction, put the file rjms-topic-selector-1.0.5.ez inside the Folder $RABBITMQ_SERVER\\plugins.\n\n- Enable the plugin with the command: `rabbitmq-plugins enable rabbitmq_jms_topic_exchange`\nCheck if the plugin it's running ok with the command: `rabbitmq-plugins list`\n\nhttps://i.sstatic.net/jgQ7b.png\n\n- Restart the RabbitMQ - I'm not sure if it's really necessary, but just in case ;-)\nAt your RabbitMQ web management (http://localhost:15672/#/exchanges) you can check the new Exchange you have available:\nhttps://i.sstatic.net/F1P1q.png\n\n- Now, in theory :-), you're already able to connect to your RabbiMQ server using the standard Java JMS API.\n\nBear in mind that you'll have to create a .bindings file in order to JNDI found your registered objects. This is an example of the content of it:\n\n`ConnectionFactory/ClassName=com.rabbitmq.jms.admin.RMQConnectionFactory\n ConnectionFactory/FactoryName=com.rabbitmq.jms.admin.RMQObjectFactory\n ConnectionFactory/RefAddr/0/Content=jms/ConnectionFactory\n ConnectionFactory/RefAddr/0/Type=name\n ConnectionFactory/RefAddr/0/Encoding=String\n ConnectionFactory/RefAddr/1/Content=javax.jms.ConnectionFactory\n ConnectionFactory/RefAddr/1/Type=type\n ConnectionFactory/RefAddr/1/Encoding=String\n ConnectionFactory/RefAddr/2/Content=com.rabbitmq.jms.admin.RMQObjectFactory\n ConnectionFactory/RefAddr/2/Type=factory\n ConnectionFactory/RefAddr/2/Encoding=String\n # Change this line accordingly if the broker is not at localhost\n ConnectionFactory/RefAddr/3/Content=localhost\n ConnectionFactory/RefAddr/3/Type=host\n ConnectionFactory/RefAddr/3/Encoding=String\n # HELLO Queue \n HELLO/ClassName=com.rabbitmq.jms.admin.RMQDestination\n HELLO/FactoryName=com.rabbitmq.jms.admin.RMQObjectFactory\n HELLO/RefAddr/0/Content=jms/Queue\n HELLO/RefAddr/0/Type=name\n HELLO/RefAddr/0/Encoding=String\n HELLO/RefAddr/1/Content=javax.jms.Queue\n HELLO/RefAddr/1/Type=type\n HELLO/RefAddr/1/Encoding=String\n HELLO/RefAddr/2/Content=com.rabbitmq.jms.admin.RMQObjectFactory\n HELLO/RefAddr/2/Type=factory\n HELLO/RefAddr/2/Encoding=String\n HELLO/RefAddr/3/Content=HELLO\n HELLO/RefAddr/3/Type=destinationName\n HELLO/RefAddr/3/Encoding=String`\n\nAnd then... finally... the code: \n\n Properties environmentParameters = new Properties();\n environmentParameters.put(Context.INITIAL_CONTEXT_FACTORY, \"com.sun.jndi.fscontext.RefFSContextFactory\");\n environmentParameters.put(Context.PROVIDER_URL, \"file:/C:/rabbitmq-bindings\");\n namingContext = new InitialContext(environmentParameters);\n\n ConnectionFactory connFactory = (ConnectionFactory) ctx.lookup(\"ConnectionFactory\");\n\n========================================\n\nCode:\n```text\nProperties environmentParameters = new Properties();\nenvironmentParameters.put(Context.INITIAL_CONTEXT_FACTORY, property.context);\nenvironmentParameters.put(Context.PROVIDER_URL, property.provider);\nnamingContext = new InitialContext(environmentParameters);\n```\n\n```text\nCaused by: javax.naming.NamingException: Unknown class [com.rabbitmq.jms.admin.RMQConnectionFactory]\n```\n\n```text\nConnectionFactory/ClassName=com.rabbitmq.jms.admin.RMQConnectionFactory --->\nConnectionFactory/ClassName=javax.jms.ConnectionFactory\n```\n\n```text\nYourQueueName/ClassName=com.rabbitmq.jms.admin.RMQDestination --->\nStriimQueue/ClassName=javax.jms.Queue\n```\n\n```text\n/*\n * Valid class names are:\n * javax.jms.ConnectionFactory\n * javax.jms.QueueConnectionFactory\n * javax.jms.TopicConnectionFactory\n * javax.jms.Topic\n * javax.jms.Queue\n *\n */\n```\n\n```text\nConnectionFactory/ClassName=com.rabbitmq.jms.admin.RMQConnectionFactory\n ConnectionFactory/FactoryName=com.rabbitmq.jms.admin.RMQObjectFactory\n ConnectionFactory/RefAddr/0/Content=jms/ConnectionFactory\n ConnectionFactory/RefAddr/0/Type=name\n ConnectionFactory/RefAddr/0/Encoding=String\n ConnectionFactory/RefAddr/1/Content=javax.jms.ConnectionFactory\n ConnectionFactory/RefAddr/1/Type=type\n ConnectionFactory/RefAddr/1/Encoding=String\n ConnectionFactory/RefAddr/2/Content=com.rabbitmq.jms.admin.RMQObjectFactory\n ConnectionFactory/RefAddr/2/Type=factory\n ConnectionFactory/RefAddr/2/Encoding=String\n # Change this line accordingly if the broker is not at localhost\n ConnectionFactory/RefAddr/3/Content=localhost\n ConnectionFactory/RefAddr/3/Type=host\n ConnectionFactory/RefAddr/3/Encoding=String\n # HELLO Queue \n HELLO/ClassName=com.rabbitmq.jms.admin.RMQDestination\n HELLO/FactoryName=com.rabbitmq.jms.admin.RMQObjectFactory\n HELLO/RefAddr/0/Content=jms/Queue\n HELLO/RefAddr/0/Type=name\n HELLO/RefAddr/0/Encoding=String\n HELLO/RefAddr/1/Content=javax.jms.Queue\n HELLO/RefAddr/1/Type=type\n HELLO/RefAddr/1/Encoding=String\n HELLO/RefAddr/2/Content=com.rabbitmq.jms.admin.RMQObjectFactory\n HELLO/RefAddr/2/Type=factory\n HELLO/RefAddr/2/Encoding=String\n HELLO/RefAddr/3/Content=HELLO\n HELLO/RefAddr/3/Type=destinationName\n HELLO/RefAddr/3/Encoding=String\n```\n\n```text\nProperties environmentParameters = new Properties();\n environmentParameters.put(Context.INITIAL_CONTEXT_FACTORY, \"com.sun.jndi.fscontext.RefFSContextFactory\");\n environmentParameters.put(Context.PROVIDER_URL, \"file:/C:/rabbitmq-bindings\");\n namingContext = new InitialContext(environmentParameters);\n\n ConnectionFactory connFactory = (ConnectionFactory) ctx.lookup(\"ConnectionFactory\");\n```\n\n```text\nrabbitmq-plugins enable rabbitmq_jms_topic_exchange\n```\n\n```text\nrabbitmq-plugins list\n```\n\n```text\nimport java.util.Properties;\nimport javax.jms.ConnectionFactory;\nimport javax.jms.Queue;\nimport javax.jms.Topic;\nimport javax.naming.Context;\nimport javax.naming.InitialContext;\nimport javax.naming.Reference;\nimport javax.naming.StringRefAddr;\n\nProperties env = new Properties();\n env.put(Context.INITIAL_CONTEXT_FACTORY, \"com.sun.jndi.fscontext.RefFSContextFactory\");\n env.put(Context.PROVIDER_URL, \"file:bindings\");\n Context ctx = new InitialContext(env);\n\n Reference connectionFactoryRef = new Reference(ConnectionFactory.class.getName(), RMQObjectFactory.class.getName(), null);\n connectionFactoryRef.add(new StringRefAddr(\"name\", \"jms/ConnectionFactory\"));\n connectionFactoryRef.add(new StringRefAddr(\"type\", ConnectionFactory.class.getName()));\n connectionFactoryRef.add(new StringRefAddr(\"factory\", RMQObjectFactory.class.getName()));\n connectionFactoryRef.add(new StringRefAddr(\"host\", \"$JMS_RABBITMQ_HOST$\"));\n connectionFactoryRef.add(new StringRefAddr(\"port\", \"$JMS_RABBITMQ_PORT$\"));\n ctx.rebind(\"ConnectionFactory\", connectionFactoryRef);\n\n String jndiAppend = \"jndi\";\n for (int i = 1; i <= 10; i++) {\n String name = String.format(\"queue%02d\", i);\n Reference ref = new Reference(Queue.class.getName(), com.rabbitmq.jms.admin.RMQObjectFactory.class.getName(), null);\n ref.add(new StringRefAddr(\"name\", \"jms/Queue\"));\n ref.add(new StringRefAddr(\"type\", Queue.class.getName()));\n ref.add(new StringRefAddr(\"factory\", RMQObjectFactory.class.getName()));\n ref.add(new StringRefAddr(\"destinationName\", name));\n ctx.rebind(name+jndiAppend, ref);\n\n name = String.format(\"topic%02d\", i);\n ref = new Reference(Topic.class.getName(), com.rabbitmq.jms.admin.RMQObjectFactory.class.getName(), null);\n ref.add(new StringRefAddr(\"name\", \"jms/Topic\"));\n ref.add(new StringRefAddr(\"type\", Topic.class.getName()));\n ref.add(new StringRefAddr(\"factory\", RMQObjectFactory.class.getName()));\n ref.add(new StringRefAddr(\"destinationName\", name));\n ctx.rebind(name+jndiAppend, ref);\n }\n```\n\n========================================\n\nComments:\n- Thanks yes with respect to configuration I've got it right but I didn't figure out how to create this .bindings file. I did come across a couple of examples but is there a way to create this file? Certain systems like IBM WMQ takes care of creating this file for the users.\n- I have created this file without the help of a tool. For the RabbitMQ I don't know if there's way that it creates automatically, I don't think so. I followed the syntax according to some readings I found on internet and comparing of a .bindings file automatically created by the IBM MQ Explorer.\n- Okay, I understand. Even what is surprising is I didn't find any official documentation on this .bindings file except few posts on internet. Anyway I'll try your answer and see.\n- Do we need to explicitly add an exchange which is of type x-jms-topic? By default I don't see any exchange named jms.durable.queues? And in your screenshot why is the type direct? Shouldn't it be something like JMS queue or something?\n- @NiranjanSubramanian Actually all this is set for you automatically when you install the plugin, then you shouldn't need to do anything else besides the installation.\n- well that wasn't the case for me. I didn't have the additional exchange which is highlighted in your screenshot. Anyway while running did you encounter this exception? Caused by: javax.naming.NamingException: Unknown class [com.rabbitmq.jms.admin.RMQConnectionFactory]\n- Check if you have on your classpath all this dependencies: amqp-client-3.1.5.jar, fscontext.jar, geronimo-jms_1.1_spec-1.1.1.jar, providerutil.jar, rabbitmq-jms-1.0.5.jar.\n- Yup I've all these in my classpath.\n- Be careful with the provider_url as specified and used here; it is not a compliant file:// URI. Use `file:.` to look for your `.bindings` file in your working directory, `file:/` presumably looks from the root of your file-system. `file:/C:/rabbitmq-bindings` is not a URI, but `/C:/rabbitmq-bindings` is just the Unix way to express a Windows path rooted in the C drive.","metadata":{"transformedAt":"2026-08-18T18:33:20.168Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":225,"estimatedTokens":2862}}518{"id":"stack-12307173","source":"stackoverflow","questionId":12307173,"title":"Celery: long dedicated monolithic task vs short multiple tasks","tags":["python","rabbitmq","celery","distributed-computing","django-celery"],"text":"Title: Celery: long dedicated monolithic task vs short multiple tasks\nTags: python, rabbitmq, celery, distributed-computing, django-celery\nSource: Stack Overflow\n\nQuestion:\nIn my solution I use distributed tasks to monitor hardware instances for a period of time (say, 10 minutes). I have to do some stuff when:\n\n- I start this monitoring session\n\n- I finish this monitoring session\n\n- (Potentially) during the monitoring session\n\nIs it safe to have a single task run for the whole session (10 minutes) and perform all these, or should I split these actions into their own tasks? \n\nThe advantages of a single task, as I see it, are that it would be easier to manage and enforce timing constraints. But:\n\nIs it a good idea to run a large pool of (mostly) asleep workers? For example, if I know that at most I will have 200 sessions open, I have a pool of 500 workers to ensure there are always available \"session\" seats?\n\n========================================\n\nComments:\n- Thanks for the in-depth answer. I was expecting that I would end up with a multiple queue solution.","metadata":{"transformedAt":"2026-08-18T18:33:20.168Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":23,"estimatedTokens":269}}519{"id":"stack-39462885","source":"stackoverflow","questionId":39462885,"title":"RabbitMQ - Regex Implementation Topic Exchange","tags":["rabbitmq","amqp","spring-amqp"],"text":"Title: RabbitMQ - Regex Implementation Topic Exchange\nTags: rabbitmq, amqp, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nSuppose, If I have a binding key as \"a.b.*\" then I can use the routing keys as a.b.1, a.b.2, a.b.3 , a.b.4 and so on. \n\nI want the queue to accept messages from the all these routing keys **except** the routing key **\"a.b.3\"**. How can that be implemented?\n\nOr is there any way I can use **regex** for my binding key instead of just the wildcard characters \"*\" and \"#\".\n\n========================================\n\nComments:\n- in addition to what Gary said, there is not \"except\" or \"not\" or \"exclude\" in routing / binding with rabbitmq. a match is a match and will always route the message.","metadata":{"transformedAt":"2026-08-18T18:33:20.168Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":15,"estimatedTokens":178}}520{"id":"stack-36179111","source":"stackoverflow","questionId":36179111,"title":"Whether to create connection every time when amqp.Dial is threadsafe or not in go lang","tags":["go","rabbitmq","rabbitmqctl"],"text":"Title: Whether to create connection every time when amqp.Dial is threadsafe or not in go lang\nTags: go, rabbitmq, rabbitmqctl\nSource: Stack Overflow\n\nQuestion:\nAs it is mentioned in the RabbitMQ docs that tcp connections are expensive to make. So, for that concept of channel was introduced. Now i came across this example. In the `main()` it creates the connection everytime a message is publised. \n`conn, err := amqp.Dial(\"amqp://guest:guest@localhost:5672/\")`. \nShouldn't it be declared globally once and there should be failover mechanism in case connection get closed like singleton object. If amqp.Dial is thread-safe, which i suppose it should be \n\n**Edited question :**\n\nI am handling the connection error in the following manner. In which i listen on a channel and create a new connection on error. But when i kill the existing connection and try to publish message. I get the following error.\n\n**error :**\n\n```\n2016/03/30 19:20:08 Failed to open a channel: write tcp 172.16.5.48:51085->172.16.0.20:5672: use of closed network connection\nexit status 1\n7:25 PM\n```\n\n**Code :**\n\n```\nfunc main() {\n\n Conn, err := amqp.Dial(\"amqp://guest:guest@172.16.0.20:5672/\")\n failOnError(err, \"Failed to connect to RabbitMQ\")\n context := &appContext{queueName: \"QUEUENAME\",exchangeName: \"ExchangeName\",exchangeType: \"direct\",routingKey: \"RoutingKey\",conn: Conn}\n c := make(chan *amqp.Error)\n\n go func() {\n error := <-c\n if(error != nil){ \n Conn, err = amqp.Dial(\"amqp://guest:guest@172.16.0.20:5672/\") \n failOnError(err, \"Failed to connect to RabbitMQ\") \n Conn.NotifyClose(c) \n } \n }()\n\n Conn.NotifyClose(c)\n r := web.New()\n // We pass an instance to our context pointer, and our handler.\n r.Get(\"/\", appHandler{context, IndexHandler})\n graceful.ListenAndServe(\":8086\", r) \n\n }\n```\n\n========================================\n\nCode:\n```text\n2016/03/30 19:20:08 Failed to open a channel: write tcp 172.16.5.48:51085->172.16.0.20:5672: use of closed network connection\nexit status 1\n7:25 PM\n```\n\n```text\nfunc main() {\n\n Conn, err := amqp.Dial(\"amqp://guest:guest@172.16.0.20:5672/\")\n failOnError(err, \"Failed to connect to RabbitMQ\")\n context := &appContext{queueName: \"QUEUENAME\",exchangeName: \"ExchangeName\",exchangeType: \"direct\",routingKey: \"RoutingKey\",conn: Conn}\n c := make(chan *amqp.Error)\n\n go func() {\n error := <-c\n if(error != nil){ \n Conn, err = amqp.Dial(\"amqp://guest:guest@172.16.0.20:5672/\") \n failOnError(err, \"Failed to connect to RabbitMQ\") \n Conn.NotifyClose(c) \n } \n }()\n\n Conn.NotifyClose(c)\n r := web.New()\n // We pass an instance to our context pointer, and our handler.\n r.Get(\"/\", appHandler{context, IndexHandler})\n graceful.ListenAndServe(\":8086\", r) \n\n }\n```\n\n```text\nmain()\n```\n\n```text\nconn, err := amqp.Dial(\"amqp://guest:guest@localhost:5672/\")\n```\n\n```text\nfunc initialize() {\n c := make(chan *amqp.Error)\n go func() {\n err := <-c\n log.Println(\"reconnect: \" + err.Error())\n initialize()\n }()\n\n conn, err := amqp.Dial(\"amqp://guest:guest@localhost:5672/\")\n if err != nil {\n panic(\"cannot connect\")\n }\n conn.NotifyClose(c)\n\n // create topology\n}\n```\n\n```text\nConnection.NotifyClose\n```\n\n========================================\n\nComments:\n- As far as I can see the connection is only create one time in the linked samples. You should include the respective code in your question.\n- No, but let's say i have a http handler which gets called every time you need to push an object in the queue. So, should we create connection on every request to rabbitmq or use only one connection.\n- Could you please elaborate in more detail. I am new to go. So, don't have much idea. I have edited the question. Could you please point out the error where i am wrong.\n- Are you re-declaring your topology (create channels, etc.) on reconnect?\n- No, I am only re-creating the connection. As you can see in the code. I have pasted in my question\n- You need to re-declare the topology after you have established the connection. You can place this in some function which you can call on startup and after reconnects.\n- But i create RabbitMQ channel (not to be confused with go channel) for every request to publish the message. Now how can i re-declare it. Could you please give me the suggestion using code.\n- I updated my answer. BTW: Your code isn't working for more than one reconnect because nothing is listening on the channel `c` after you have called `Conn.NotifyClose(c)` within the goroutine.","metadata":{"transformedAt":"2026-08-18T18:33:20.168Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":126,"estimatedTokens":1169}}521{"id":"stack-35227845","source":"stackoverflow","questionId":35227845,"title":"Scheduled/Delay messaging in Spring AMQP RabbitMq","tags":["rabbitmq","spring-amqp"],"text":"Title: Scheduled/Delay messaging in Spring AMQP RabbitMq\nTags: rabbitmq, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI am struggling hard to find out the way for scheduled/Delaying messages in Spring AMQP/Rabbit MQ.\nAfter hell lot of searching still I am not able to do that in Spring AMQP. Can someone please tell me how to do **x-delay** in Spring AMQP.\nI want to Delay a message if some exception occurs in the consumer side. RabbitMQ says to add x-delay and install the plugin which I have already done, but still messages is comming immediately without any delay\n\nI am getting this in message\n\nReceived Consumer---\n\n @Override\n\n```\npublic void onMessage(Message message, Channel channel) throws Exception {\n\n System.out.println(\"Received \" +rabbitTemplate);\n\n if(i==1){\n AMQP.BasicProperties.Builder props = new AMQP.BasicProperties.Builder();\n Map headers = message.getMessageProperties().getHeaders();\n headers.put(\"x-delay\", 15000);\n props.headers(headers);\n i++;\n channel.basicPublish(message.getMessageProperties().getReceivedExchange(), message.getMessageProperties().getReceivedRoutingKey(),\n props.build(), message.getBody());\n }\n }\n```\n\n========================================\n\nCode:\n```text\n@Bean\nConnectionFactory connectionFactory(){\n\n CachingConnectionFactory connectionFactory=new CachingConnectionFactory(\"127.0.0.1\");\n connectionFactory.setUsername(\"guest\");\n connectionFactory.setPassword(\"guest\");\n connectionFactory.setPort(1500);\n connectionFactory.setPublisherReturns(true);\n return connectionFactory;\n\n}\n\n@Bean\nBinding binding(@Qualifier(\"queue\")Queue queue, DirectExchange exchange) {\n return new Binding(queue.getName(), Binding.DestinationType.QUEUE, exchange.getName(), queue.getName(), null);\n //return BindingBuilder.bind(queue).to(exchange).with(queueName); \n}\n\n@Bean\nDirectExchange exchange() {\n DirectExchange exchange=new DirectExchange(\"delay-exchange\");\n return exchange;\n}\n```\n\n```text\npublic void onMessage(Message message, Channel channel) throws Exception {\n\n System.out.println(\"Received <\" + message+ \">\" +rabbitTemplate);\n\n if(i==1){\n AMQP.BasicProperties.Builder props = new AMQP.BasicProperties.Builder();\n Map<String,Object> headers = message.getMessageProperties().getHeaders();\n headers.put(\"x-delay\", 15000);\n props.headers(headers);\n i++;\n channel.basicPublish(message.getMessageProperties().getReceivedExchange(), message.getMessageProperties().getReceivedRoutingKey(),\n props.build(), message.getBody());\n }\n }\n```\n\n```text\nMap<String, Object> args = new HashMap<String, Object>();\nargs.put(\"x-delayed-type\", \"direct\");\nchannel.exchangeDeclare(\"my-exchange\", \"x-delayed-message\", true, false, args);\n```\n\n```text\n@Bean\nCustomExchange delayExchange() {\n Map<String, Object> args = new HashMap<String, Object>();\n args.put(\"x-delayed-type\", \"direct\");\n return new CustomExchange(\"my-exchange\", \"x-delayed-message\", true, false, args);\n}\n```\n\n```text\ndelay-exchange\n```\n\n========================================\n\nComments:\n- Not sure who recommended you to mark this question with `jms` tag, but that isn't correct. That is only about RabbitMQ. And yes, `spring-amqp`. Fixing...\n- Yes, I was not getting this x-delayed-message type in Exchange as it was not in the Spring AMQP. I went through that many times but not able to figure out that it is a Exchange type. Anyways, I am able to do it now.\n- @Artem where should I look for spring-rabbit-1.6.xsd\n- Not sure what is your question, but `spring-rabbit-1.6.xsd` is fully a part of `spring-rabbit-1.6.0.RELEASE.jar`: `org/springframework/amqp/rabbit/config/spring-rabbit-1.6.xsd`‌​. If you use versionless XSD declaration in your configs, you already can declare `delayed` attribute on exchanges definitions.\n- @ArtemBilan I have this in my config xml \"springframework.org/schema/rabbit/spring-rabbit.xsd\" but it doesn't work !!\n- @ArtemBilan though \"springframework.org/schema/rabbit/spring-rabbit-1.5.xsd\" this url works but it doesn't allow to use delayed attribute.\n- @ArtemBilan did this \"classpath:org/springframework/amqp/rabbit/config/spring-rab‌​bit-1.6.xsd\" and it seems to be working. Is it the right way to pick xsd from within a jar ?\n- @lalit : please use like this springframework.org/schema/rabbit classpath:org/springframework/amqp/rabbit/config/spring-rabb‌​it-1.6.xsd","metadata":{"transformedAt":"2026-08-18T18:33:20.168Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":108,"estimatedTokens":1114}}522{"id":"stack-24236131","source":"stackoverflow","questionId":24236131,"title":"Celery scheduled list returns None","tags":["python","rabbitmq","celery"],"text":"Title: Celery scheduled list returns None\nTags: python, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI'm fairly new to Celery and I've been attempting setup a simple script to schedule and unschedule tasks. However I feel like I'm running into a weird issue. I have the following setup\n\n```\nfrom celery import Celery\napp = Celery('celery_test',\n broker='amqp://',\n backend='amqp')\n\n@app.task\ndef add(x, y):\n return x + y\n```\n\nI start up my celery server just fine and can add tasks. Now when I want to get a list of active tasks things seem to get weird. When I goto use inspect to get a list of scheduled tasks it works exactly once then returns None every time afterwards.\n\n```\n>>> i = app.control.inspect()\n>>> print i.scheduled()\n{u'celery@mymachine': []}\n>>> print i.scheduled()\nNone\n>>>\n```\n\nThis happens whether I add tasks or not. I want to find a way to consistently return a list of tasks from my celery queue. I want to do this so I can find a previously queued task, revoke it, and reschedule it. I feel like I'm missing something basic here.\n\n========================================\n\nTop Answer:\nThanks to daniula, \n\nI'm using this code in django-celery-rabbitmq and i need to close app instance aftert inspect... like this:\n\n```\nfrom celery import Celery\n\ndef inspect(method):\n app = Celery('app', broker='amqp://')\n inspect_result = getattr(app.control.inspect(), method)()\n app.close()\n return inspect_result\n\nprint inspect('scheduled')\nprint inspect('active')\n```\n\nIn my case if i don't call app.close() socket connection to rabbitmq still alive (active), in this way all socket descriptors will be consumed and after that, new socket connection cannot be available, so everything stop to work.\n\n========================================\n\nCode:\n```text\nfrom celery import Celery\napp = Celery('celery_test',\n broker='amqp://',\n backend='amqp')\n\n@app.task\ndef add(x, y):\n return x + y\n```\n\n```text\n>>> i = app.control.inspect()\n>>> print i.scheduled()\n{u'celery@mymachine': []}\n>>> print i.scheduled()\nNone\n>>>\n```\n\n```text\nfrom celery import Celery\n\ndef inspect(method):\n app = Celery('app', broker='amqp://')\n return getattr(app.control.inspect(), method)()\n\nprint inspect('scheduled')\nprint inspect('active')\n```\n\n```text\n./manage.py celery inspect scheduled\n```\n\n```text\nfrom celery import Celery\n\ndef inspect(method):\n app = Celery('app', broker='amqp://')\n inspect_result = getattr(app.control.inspect(), method)()\n app.close()\n return inspect_result\n\nprint inspect('scheduled')\nprint inspect('active')\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.168Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":103,"estimatedTokens":645}}523{"id":"stack-32330909","source":"stackoverflow","questionId":32330909,"title":"rabbitmq consume json message and convert into Java object","tags":["java","rabbitmq","spring-amqp","spring-rabbit"],"text":"Title: rabbitmq consume json message and convert into Java object\nTags: java, rabbitmq, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI have put together a java test. It puts a message on a queue and returns it as a string. What Im trying to achieve is for it to it convert into the java object SignUpDto. I have stripped down the code as much as possible for the question.\n\n**The question:**\n\nHow do I modify the test below to convert into a object? \n\n**SignUpClass**\n\n```\npublic class SignUpDto {\n private String customerName;\n private String isoCountryCode;\n ... etc\n}\n```\n\n**Application - Config class**\n\n```\n@Configuration\npublic class Application {\n\n @Bean\n public ConnectionFactory connectionFactory() {\n return new CachingConnectionFactory(\"localhost\");\n }\n\n @Bean\n public AmqpAdmin amqpAdmin() {\n return new RabbitAdmin(connectionFactory());\n }\n\n @Bean\n public RabbitTemplate rabbitTemplate() {\n\n // updated with @GaryRussels feedback\n RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory());\n rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());\n return rabbitTemplate;\n }\n\n @Bean\n public Queue myQueue() {\n return new Queue(\"myqueue\");\n }\n}\n```\n\n**The Test** \n\n```\n@RunWith(SpringJUnit4ClassRunner.class)\n@ContextConfiguration(classes = {Application.class})\npublic class TestQueue {\n\n @Test\n public void convertMessageIntoObject(){\n\n ApplicationContext context = new AnnotationConfigApplicationContext(Application.class);\n AmqpTemplate template = context.getBean(AmqpTemplate.class);\n\n String jsonString = \"{ \\\"customerName\\\": \\\"TestName\\\", \\\"isoCountryCode\\\": \\\"UK\\\" }\";\n\n template.convertAndSend(\"myqueue\", jsonString);\n\n String foo = (String) template.receiveAndConvert(\"myqueue\");\n\n // this works ok \n System.out.println(foo);\n\n // How do I make this convert\n //SignUpDto objFoo = (SignUpDto) template.receiveAndConvert(\"myqueue\");\n // objFoo.toString() \n\n }\n}\n```\n\n========================================\n\nCode:\n```text\npublic class SignUpDto {\n private String customerName;\n private String isoCountryCode;\n ... etc\n}\n```\n\n```text\n@Configuration\npublic class Application {\n\n @Bean\n public ConnectionFactory connectionFactory() {\n return new CachingConnectionFactory(\"localhost\");\n }\n\n @Bean\n public AmqpAdmin amqpAdmin() {\n return new RabbitAdmin(connectionFactory());\n }\n\n @Bean\n public RabbitTemplate rabbitTemplate() {\n\n // updated with @GaryRussels feedback\n RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory());\n rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());\n return rabbitTemplate;\n }\n\n @Bean\n public Queue myQueue() {\n return new Queue(\"myqueue\");\n }\n}\n```\n\n```text\n@RunWith(SpringJUnit4ClassRunner.class)\n@ContextConfiguration(classes = {Application.class})\npublic class TestQueue {\n\n @Test\n public void convertMessageIntoObject(){\n\n ApplicationContext context = new AnnotationConfigApplicationContext(Application.class);\n AmqpTemplate template = context.getBean(AmqpTemplate.class);\n\n String jsonString = \"{ \\\"customerName\\\": \\\"TestName\\\", \\\"isoCountryCode\\\": \\\"UK\\\" }\";\n\n template.convertAndSend(\"myqueue\", jsonString);\n\n String foo = (String) template.receiveAndConvert(\"myqueue\");\n\n // this works ok \n System.out.println(foo);\n\n // How do I make this convert\n //SignUpDto objFoo = (SignUpDto) template.receiveAndConvert(\"myqueue\");\n // objFoo.toString() \n\n }\n}\n```\n\n```text\ntemplate.convertAndSend(\"myqueue\", myDto);\n\n...\n\nSignUpDto out = (SignUpDto) template.receiveAndConvert(\"myQueue\");\n```\n\n```text\n<rabbit:template id=\"amqpTemplate\" connection-factory=\"connectionFactory\"\n message-converter=\"json\" />\n\n<bean id=\"json\"\n class=\"org.springframework.amqp.support.converter.Jackson2JsonMessageConverter\" />\n```\n\n```text\ntemplate.convertAndSend(\"\", \"myQueue\", jsonString, new MessagePostProcessor() {\n\n @Override\n public Message postProcessMessage(Message message) throws AmqpException {\n message.getMessageProperties().setContentType(\"application/json\");\n message.getMessageProperties().getHeaders()\n .put(AbstractJavaTypeMapper.DEFAULT_CLASSID_FIELD_NAME, \"foo.SignUpDto\");\n return message;\n }\n});\n```\n\n```text\nRabbitTemplate\n```\n\n```text\nJackson2JsonMessageConverter\n```\n\n```text\napplication/json\n```\n\n```text\nClassMapper\n```\n\n```text\nSimpleMessageConverter\n```\n\n========================================\n\nComments:\n- how do I configure the RabbitTemplate with a Jackson2JsonMessageConverter?\n- im not sure how that xml maps into java config?\n- Within your `RabbitTemplate` `@Bean` definition: `template.setMessageConverter(new Jackson2JsonMessageConverter());`.\n- it now works thanks for your help :-) I have updated my config settings above so its more readable. One last question how would I set the type headers.\n- See the second edit - beware of the caveat at the end, though.","metadata":{"transformedAt":"2026-08-18T18:33:20.168Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":11,"totalLines":209,"estimatedTokens":1259}}524{"id":"stack-23158842","source":"stackoverflow","questionId":23158842,"title":"using rabbitmq in android for chat","tags":["android","rabbitmq","amqp"],"text":"Title: using rabbitmq in android for chat\nTags: android, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nWe have implemented rabbitmq chat in android. but java client of rabbitmq is power hungry.is rabbitmq good for android chat?. we have used direct exchange individual queue for persons and individual routing keys. what is the best design pattern for one to one chat in rabbitmq.\nand also ways to reduce battery usage\n\n========================================\n\nTop Answer:\nMaybe you could combine RabbitMQ with GCM to save power as GCM gets triggered by the system and doesn´t need to keep any extra connection alive.\n\nFor example:\n\nThe app gets notified via GCM when any new event comes in.\nThen a new Rabbit connection gets established, retrieving the data and timeouting after a short while again, if no messages are coming in again.\n\nSo the actual \"hungryness\" exists only for a short moment and only when neccessary.\n\nYou can also analyze which users are tending to always write multiple messages close behind one other and vary the timeout based on that value\n\n========================================\n\nComments:\n- But mqtt doesn't retain the offline messages, is not that the main reason people seek solutions with built-in queues?","metadata":{"transformedAt":"2026-08-18T18:33:20.168Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":26,"estimatedTokens":311}}525{"id":"stack-56663985","source":"stackoverflow","questionId":56663985,"title":"What is Z offset in OffsetDateTime?","tags":["java","rabbitmq","java-time"],"text":"Title: What is Z offset in OffsetDateTime?\nTags: java, rabbitmq, java-time\nSource: Stack Overflow\n\nQuestion:\nThese two OffsetDateTime are returning a different String representation and different offsets. \n\nThe trigger time was created in a different service, but also through `OffsetDateTime.now()` and then send over RabbitMQ.\n\nAre these just a different representations of the `ISO-8601` format? Or am I missing a valid offset value ?\n\nI checked the `OffsetDateTime.toString()` docu, but not sure if that is really where I should be looking...\n\nThanks everyone!\n\n```\nOffsetDateTime offsetDateTime = event.getTriggerTime();\n\nSystem.out.println(offsetDateTime); //2019-06-19T08:56:19.152564Z\nSystem.out.println(OffsetDateTime.now()); //2019-06-19T10:56:19.293893+02:00\n```\n\n========================================\n\nCode:\n```text\nOffsetDateTime offsetDateTime = event.getTriggerTime();\n\nSystem.out.println(offsetDateTime); //2019-06-19T08:56:19.152564Z\nSystem.out.println(OffsetDateTime.now()); //2019-06-19T10:56:19.293893+02:00\n```\n\n```text\nOffsetDateTime.now()\n```\n\n```text\nISO-8601\n```\n\n```text\nOffsetDateTime.toString()\n```\n\n========================================\n\nComments:\n- Though the linked question is not identical to yours, I believe the answers there answer your question too. You may search for more questions and answers and web sites that treat `Z` as offset.","metadata":{"transformedAt":"2026-08-18T18:33:20.169Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":48,"estimatedTokens":345}}526{"id":"stack-51195026","source":"stackoverflow","questionId":51195026,"title":"RabbitMQ - access to vhost 'XXX' refused for user 'guest'","tags":[".net","rabbitmq","masstransit","rabbitmq-exchange","rabbitmqctl"],"text":"Title: RabbitMQ - access to vhost 'XXX' refused for user 'guest'\nTags: .net, rabbitmq, masstransit, rabbitmq-exchange, rabbitmqctl\nSource: Stack Overflow\n\nQuestion:\nI am using RabbitMQ 3.0.3 version. The service was working fine for last 4-5 years. Recently some updates patches were installed on the server and the Service stopped responding. This is what is happening:\n\n- The RabbitMQ service (windows service) is running but not responding.\n\n- In the log file I see error `access to vhost 'XXX' refused for user 'guest'`\n\n- The management console is throwing site cannot be reached error\n\nWhat options do I have here? I cannot update RabbitMQ version as my code starts to fail. I have not tried reinstalling the service. \n\n**I am using RabbitMQ 3.0.3 - How can I request `guest` account to be accessible even from remote machine. `rabbitmq.conf` file only appeared after version 3.7.0**\n\n========================================\n\nCode:\n```text\naccess to vhost 'XXX' refused for user 'guest'\n```\n\n```text\nguest\n```\n\n```text\nrabbitmq.conf\n```\n\n```text\nGuest\n```\n\n```text\nGuest\n```\n\n```text\nThe name of Virtual host was same as the one I saw in error message \"access to vhost 'XXX' refused for user 'guest'\"\n```\n\n========================================\n\nComments:\n- Do you know if you rely on RabbitMQ to store your queue and consumer config? Or could the app recreate that in a blank MQ? The error suggests that the guest account isn't allowed into your porn vhost, or perhaps that it doesn't exist.\n- I've got this before when the vhost didn't exist.\n- Sounds like your vhost either doesn't exist, or the user guest doesn't have access to it. Usually guest is limited to localhost only by RMQ. Use a real user acct.\n- @Davesoft: App creates the queue. Like i said, this setup was working for very long time and its not been touched. The issue appeared on two machines. Even if the guest account is blocked or got deleted on this machine, the management console should continue to work. How can i recreate the user account?\n- @KevinSmith How can I create the Vhost? How did you resolved this issue?\n- @ChrisPatterson : How can I create vhost? I am also not able to launch management console\n- Read the docs: rabbitmq.com/rabbitmqctl.8.html\n- @ChrisPatterson I am using RabbitMQ 3.0.3 - How can i request `guest` account to be accessible even from remote machine. `rabbitmq.conf` file only appeared after version 3.7.0\n- @Davesoft I am using RabbitMQ 3.0.3 - How can i request `guest` account to be accessible even from remote machine. `rabbitmq.conf` file only appeared after version 3.7.0\n- Why use guest? Make a real account :)\n- @Davesoft: That is how my app was configured. Obviously creating a user id and using it is not a big change but i was wondering why the guest account is suddenly being disabled.\n- This is correct. In a future release, `guest` was limited to `localhost`-only connections. Please see the `loopback_users` setting in the RabbitMQ documentation.","metadata":{"transformedAt":"2026-08-18T18:33:20.169Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":59,"estimatedTokens":744}}527{"id":"stack-10502818","source":"stackoverflow","questionId":10502818,"title":"Competing Consumers in Mass Transit with RabbitMQ","tags":["rabbitmq","masstransit"],"text":"Title: Competing Consumers in Mass Transit with RabbitMQ\nTags: rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nI've implemented a simple publisher/consumer set with MassTransit, and I want to have the consumers read the messages from the same queue. However, when I run it, I see a large portion of the messages sent to the error queue instead of being consumed. From the discussions I've seen (SO, Forum), this should be really really simple with RabbitMQ (just point to the same queue), but it's not working. Is there an additional configuration that should be set?\n\nHere's My Publisher\n\n```\npublic class YourMessage { public string Text { get; set; } }\npublic class Program\n{\n public static void Main()\n {\n Console.WriteLine(\"Publisher\");\n Bus.Initialize(sbc =>\n {\n sbc.UseRabbitMqRouting();\n sbc.ReceiveFrom(\"rabbitmq://localhost/test_queue\");\n });\n var x = Console.Read();\n for (var i = 0; i And My Consumer\n\n```\npublic class YourMessage { public string Text { get; set; } }\npublic class Program\n{\n public static void Main()\n {\n Console.WriteLine(\"Consumer\");\n Bus.Initialize(sbc =>\n {\n sbc.UseRabbitMqRouting();\n sbc.ReceiveFrom(\"rabbitmq://localhost/test_queue\");\n sbc.Subscribe(subs =>\n {\n var del = new Action,YourMessage>((context, msg) =>\n {\n Console.WriteLine(msg.Text);\n });\n subs.Handler(del);\n });\n });\n while (true) { }\n }\n}\n```\n\n========================================\n\nTop Answer:\nSo, it looks like the solution was to change the line in the publisher: \n\n```\nsbc.ReceiveFrom(\"rabbitmq://localhost/test_queue\");\n```\n\nTo something like: \n\n```\nsbc.ReceiveFrom(\"rabbitmq://localhost/test_queue_publisher\");\n```\n\nThis prevented the publishers from competing for messages they weren't configured to consume.\n\n========================================\n\nCode:\n```text\npublic class YourMessage { public string Text { get; set; } }\npublic class Program\n{\n public static void Main()\n {\n Console.WriteLine(\"Publisher\");\n Bus.Initialize(sbc =>\n {\n sbc.UseRabbitMqRouting();\n sbc.ReceiveFrom(\"rabbitmq://localhost/test_queue\");\n });\n var x = Console.Read();\n for (var i = 0; i <= 1000; i++)\n {\n Console.WriteLine(\"Message Number \" + i);\n Bus.Instance.Publish(new YourMessage { \"Message Number \" + i });\n }\n }\n}\n```\n\n```text\npublic class YourMessage { public string Text { get; set; } }\npublic class Program\n{\n public static void Main()\n {\n Console.WriteLine(\"Consumer\");\n Bus.Initialize(sbc =>\n {\n sbc.UseRabbitMqRouting();\n sbc.ReceiveFrom(\"rabbitmq://localhost/test_queue\");\n sbc.Subscribe(subs =>\n {\n var del = new Action<IConsumeContext<YourMessage>,YourMessage>((context, msg) =>\n {\n Console.WriteLine(msg.Text);\n });\n subs.Handler<YourMessage>(del);\n });\n });\n while (true) { }\n }\n}\n```\n\n```text\nsbc.ReceiveFrom(\"rabbitmq://localhost/test_queue\");\n```\n\n```text\nsbc.ReceiveFrom(\"rabbitmq://localhost/test_queue_publisher\");\n```\n\n========================================\n\nComments:\n- the link to documentation is broken\n- Does anyone have a new link for how to setup competing consumers for publish?","metadata":{"transformedAt":"2026-08-18T18:33:20.169Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":129,"estimatedTokens":826}}528{"id":"stack-54563783","source":"stackoverflow","questionId":54563783,"title":"Failing K8s rabbitmq-peer-discovery-k8s clustering","tags":["kubernetes","rabbitmq","cluster-computing"],"text":"Title: Failing K8s rabbitmq-peer-discovery-k8s clustering\nTags: kubernetes, rabbitmq, cluster-computing\nSource: Stack Overflow\n\nQuestion:\nI'm trying to bring up a RabbitMQ cluster on Kubernetes using Rabbitmq-peer-discovery-k8s plugin and I always have only on pod running and ready but the next one always fails.\n\nI tried multiple changes to my configuration and this is what got at least one pod running\n\n```\n---\napiVersion: v1\nkind: ServiceAccount\nmetadata:\n name: rabbitmq \n namespace: namespace-dev\n---\nkind: Role\napiVersion: rbac.authorization.k8s.io/v1beta1\nmetadata:\n name: endpoint-reader\n namespace: namespace-dev\nrules:\n- apiGroups: [\"\"]\n resources: [\"endpoints\"]\n verbs: [\"get\"]\n---\nkind: RoleBinding\napiVersion: rbac.authorization.k8s.io/v1beta1\nmetadata:\n name: endpoint-reader\n namespace: namespace-dev\nsubjects:\n- kind: ServiceAccount\n name: rabbitmq\nroleRef:\n apiGroup: rbac.authorization.k8s.io\n kind: Role\n name: endpoint-reader\n---\napiVersion: v1\nkind: PersistentVolume\nmetadata:\n name: \"rabbitmq-data\"\n labels:\n name: \"rabbitmq-data\"\n release: \"rabbitmq-data\"\n namespace: \"namespace-dev\"\nspec:\n capacity:\n storage: 5Gi\n accessModes:\n - \"ReadWriteMany\"\n nfs:\n path: \"/path/to/nfs\"\n server: \"xx.xx.xx.xx\"\n persistentVolumeReclaimPolicy: Retain\n\n--- \napiVersion: v1\nkind: PersistentVolumeClaim\nmetadata:\n name: \"rabbitmq-data-claim\"\n namespace: \"namespace-dev\"\nspec:\n accessModes:\n - ReadWriteMany\n resources: \n requests:\n storage: 5Gi\n selector:\n matchLabels:\n release: rabbitmq-data\n---\n# headless service Used to access pods using hostname\nkind: Service\napiVersion: v1\nmetadata:\n name: rabbitmq-headless\n namespace: namespace-dev\nspec:\n clusterIP: None\n # publishNotReadyAddresses, when set to true, indicates that DNS implementations must publish the notReadyAddresses of subsets for the Endpoints associated with the Service. The default value is false. The primary use case for setting this field is to use a StatefulSet's Headless Service to propagate SRV records for its Pods without respect to their readiness for purpose of peer discovery. This field will replace the service.alpha.kubernetes.io/tolerate-unready-endpoints when that annotation is deprecated and all clients have been converted to use this field.\n # Since access to the Pod using DNS requires Pod and Headless service to be started before launch, publishNotReadyAddresses is set to true to prevent readinessProbe from finding DNS when the service is not started.\n publishNotReadyAddresses: true \n ports: \n - name: amqp\n port: 5672\n - name: http\n port: 15672\n selector:\n app: rabbitmq\n---\n# Used to expose the dashboard to the external network\nkind: Service\napiVersion: v1\nmetadata:\n namespace: namespace-dev\n name: rabbitmq-service\nspec:\n type: NodePort\n ports:\n - name: http\n protocol: TCP\n port: 15672\n targetPort: 15672\n nodePort: 31672\n - name: amqp\n protocol: TCP\n port: 5672\n targetPort: 5672\n nodePort: 30672\n selector:\n app: rabbitmq\n---\napiVersion: v1\nkind: ConfigMap\nmetadata:\n name: rabbitmq-config\n namespace: namespace-dev\ndata:\n enabled_plugins: |\n [rabbitmq_management,rabbitmq_peer_discovery_k8s].\n rabbitmq.conf: |\n cluster_formation.peer_discovery_backend = rabbit_peer_discovery_k8s\n cluster_formation.k8s.host = kubernetes.default.svc.cluster.local\n cluster_formation.k8s.address_type = hostname\n cluster_formation.node_cleanup.interval = 10\n cluster_formation.node_cleanup.only_log_warning = true\n cluster_partition_handling = autoheal\n queue_master_locator=min-masters\n loopback_users.guest = false\n\n cluster_formation.randomized_startup_delay_range.min = 0\n cluster_formation.randomized_startup_delay_range.max = 2\n cluster_formation.k8s.service_name = rabbitmq-headless\n cluster_formation.k8s.hostname_suffix = .rabbitmq-headless.namespace-dev.svc.cluster.local\n vm_memory_high_watermark.absolute = 1.6GB\n disk_free_limit.absolute = 2GB\n\n---\napiVersion: apps/v1\nkind: StatefulSet\nmetadata:\n name: rabbitmq\n namespace: rabbitmq\nspec:\n serviceName: rabbitmq-headless # Must be the same as the name of the headless service, used for hostname propagation access pod\n selector:\n matchLabels:\n app: rabbitmq # In apps/v1, it needs to be the same as .spec.template.metadata.label for hostname propagation access pods, but not in apps/v1beta\n replicas: 3\n template:\n metadata:\n labels:\n app: rabbitmq # In apps/v1, the same as .spec.selector.matchLabels\n # setting podAntiAffinity\n annotations:\n scheduler.alpha.kubernetes.io/affinity: >\n {\n \"podAntiAffinity\": {\n \"requiredDuringSchedulingIgnoredDuringExecution\": [{\n \"labelSelector\": {\n \"matchExpressions\": [{\n \"key\": \"app\",\n \"operator\": \"In\",\n \"values\": [\"rabbitmq\"]\n }]\n },\n \"topologyKey\": \"kubernetes.io/hostname\"\n }]\n }\n }\n spec:\n serviceAccountName: rabbitmq\n terminationGracePeriodSeconds: 10\n containers: \n - name: rabbitmq\n image: rabbitmq:3.7.10\n resources:\n limits:\n cpu: \"0.5\"\n memory: 2Gi\n requests:\n cpu: \"0.3\"\n memory: 2Gi\n volumeMounts:\n - name: config-volume\n mountPath: /etc/rabbitmq\n - name: rabbitmq-data\n mountPath: /var/lib/rabbitmq/mnesia\n ports:\n - name: http\n protocol: TCP\n containerPort: 15672\n - name: amqp\n protocol: TCP\n containerPort: 5672\n livenessProbe:\n exec:\n command: [\"rabbitmqctl\", \"status\"]\n initialDelaySeconds: 60\n periodSeconds: 60\n timeoutSeconds: 5\n readinessProbe:\n exec:\n command: [\"rabbitmqctl\", \"status\"]\n initialDelaySeconds: 20\n periodSeconds: 60\n timeoutSeconds: 5\n imagePullPolicy: IfNotPresent\n env:\n - name: HOSTNAME\n valueFrom:\n fieldRef:\n fieldPath: metadata.name\n - name: RABBITMQ_USE_LONGNAME\n value: \"true\"\n - name: RABBITMQ_NODENAME\n value: \"rabbit@$(HOSTNAME).rabbitmq-headless.namespace-dev.svc.cluster.local\"\n # If service_name is set in ConfigMap, there is no need to set it again here.\n # - name: K8S_SERVICE_NAME\n # value: \"rabbitmq-headless\"\n - name: RABBITMQ_ERLANG_COOKIE\n value: \"mycookie\" \n volumes:\n - name: config-volume\n configMap:\n name: rabbitmq-config\n items:\n - key: rabbitmq.conf\n path: rabbitmq.conf\n - key: enabled_plugins\n path: enabled_plugins\n - name: rabbitmq-data\n persistentVolumeClaim:\n claimName: rabbitmq-data-claim\n```\n\nI only get one pod running and ready instead of the 3 replicas\n\n```\n[admin@devsvr3 yaml]$ kubectl get pods\nNAME READY STATUS RESTARTS AGE\nrabbitmq-0 1/1 Running 0 2m2s\nrabbitmq-1 0/1 Running 1 43s\n```\n\nInspecting the failing pod I got this.\n\n```\n[admin@devsvr3 yaml]$ kubectl logs rabbitmq-1\n\n ## ##\n ## ## RabbitMQ 3.7.10. Copyright (C) 2007-2018 Pivotal Software, Inc.\n ########## Licensed under the MPL. See http://www.rabbitmq.com/\n ###### ##\n ########## Logs: \n\n Starting broker...\n2019-02-06 21:09:03.303 [info] \n Starting RabbitMQ 3.7.10 on Erlang 21.2.3\n Copyright (C) 2007-2018 Pivotal Software, Inc.\n Licensed under the MPL. See http://www.rabbitmq.com/\n2019-02-06 21:09:03.315 [info] \n node : rabbit@rabbitmq-1.rabbitmq-headless.namespace-dev.svc.cluster.local\n home dir : /var/lib/rabbitmq\n config file(s) : /etc/rabbitmq/rabbitmq.conf\n cookie hash : XhdCf8zpVJeJ0EHyaxszPg==\n log(s) : \n database dir : /var/lib/rabbitmq/mnesia/rabbit@rabbitmq-1.rabbitmq-headless.namespace-dev.svc.cluster.local\n2019-02-06 21:09:10.617 [error] Unable to parse vm_memory_high_watermark value \"1.6GB\"\n2019-02-06 21:09:10.617 [info] Memory high watermark set to 103098 MiB (108106919116 bytes) of 257746 MiB (270267297792 bytes) total\n2019-02-06 21:09:10.690 [info] Enabling free disk space monitoring\n2019-02-06 21:09:10.690 [info] Disk free limit set to 2000MB\n2019-02-06 21:09:10.698 [info] Limiting to approx 1048476 file handles (943626 sockets)\n2019-02-06 21:09:10.698 [info] FHC read buffering: OFF\n2019-02-06 21:09:10.699 [info] FHC write buffering: ON\n2019-02-06 21:09:10.702 [info] Node database directory at /var/lib/rabbitmq/mnesia/rabbit@rabbitmq-1.rabbitmq-headless.namespace-dev.svc.cluster.local is empty. Assuming we need to join an existing cluster or initialise from scratch...\n2019-02-06 21:09:10.702 [info] Configured peer discovery backend: rabbit_peer_discovery_k8s\n2019-02-06 21:09:10.702 [info] Will try to lock with peer discovery backend rabbit_peer_discovery_k8s\n2019-02-06 21:09:10.702 [info] Peer discovery backend does not support locking, falling back to randomized delay\n2019-02-06 21:09:10.702 [info] Peer discovery backend rabbit_peer_discovery_k8s does not support registration, skipping randomized startup delay.\n2019-02-06 21:09:10.710 [info] Failed to get nodes from k8s - {failed_connect,[{to_address,{\"kubernetes.default.svc.cluster.local\",443}},\n {inet,[inet],nxdomain}]}\n2019-02-06 21:09:10.711 [error] CRASH REPORT Process with 0 neighbours exited with reason: no case clause matching {error,\"{failed_connect,[{to_address,{\\\"kubernetes.default.svc.cluster.local\\\",443}},\\n {inet,[inet],nxdomain}]}\"} in rabbit_mnesia:init_from_config/0 line 164 in application_master:init/4 line 138\n2019-02-06 21:09:10.711 [info] Application rabbit exited with reason: no case clause matching {error,\"{failed_connect,[{to_address,{\\\"kubernetes.default.svc.cluster.local\\\",443}},\\n {inet,[inet],nxdomain}]}\"} in rabbit_mnesia:init_from_config/0 line 164\n{\"Kernel pid terminated\",application_controller,\"{application_start_failure,rabbit,{bad_return,{{rabbit,start,[normal,[]]},{'EXIT',{{case_clause,{error,\\\"{failed_connect,[{to_address,{\\\\\"kubernetes.default.svc.cluster.local\\\\\",443}},\\n {inet,[inet],nxdomain}]}\\\"}},[{rabbit_mnesia,init_from_config,0,[{file,\\\"src/rabbit_mnesia.erl\\\"},{line,164}]},{rabbit_mnesia,init_with_lock,3,[{file,\\\"src/rabbit_mnesia.erl\\\"},{line,144}]},{rabbit_mnesia,init,0,[{file,\\\"src/rabbit_mnesia.erl\\\"},{line,111}]},{rabbit_boot_steps,'-run_step/2-lc$^1/1-1-',1,[{file,\\\"src/rabbit_boot_steps.erl\\\"},{line,49}]},{rabbit_boot_steps,run_step,2,[{file,\\\"src/rabbit_boot_steps.erl\\\"},{line,49}]},{rabbit_boot_steps,'-run_boot_steps/1-lc$^0/1-0-',1,[{file,\\\"src/rabbit_boot_steps.erl\\\"},{line,26}]},{rabbit_boot_steps,run_boot_steps,1,[{file,\\\"src/rabbit_boot_steps.erl\\\"},{line,26}]},{rabbit,start,2,[{file,\\\"src/rabbit.erl\\\"},{line,815}]}]}}}}}\"}\nKernel pid terminated (application_controller) ({application_start_failure,rabbit,{bad_return,{{rabbit,start,[normal,[]]},{'EXIT',{{case_clause,{error,\"{failed_connect,[{to_address,{\\\"kubernetes.defau\n\nCrash dump is being written to: /var/log/rabbitmq/erl_crash.dump...done\n[admin@devsvr3 yaml]$\n```\n\nWhat did I do wrong here?\n\n========================================\n\nTop Answer:\nTry to set:\n\n```\ncluster_formation.k8s.host = [your kubernetes endpoint ip addres]\ncluster_formation.k8s.port = [your kubernetes endpoint port]\n```\n\nbecause it seems that your pod cannot solve this name:\n\n```\nkubernetes.default.svc.cluster.local\n```\n\n========================================\n\nCode:\n```text\n---\napiVersion: v1\nkind: ServiceAccount\nmetadata:\n name: rabbitmq \n namespace: namespace-dev\n---\nkind: Role\napiVersion: rbac.authorization.k8s.io/v1beta1\nmetadata:\n name: endpoint-reader\n namespace: namespace-dev\nrules:\n- apiGroups: [\"\"]\n resources: [\"endpoints\"]\n verbs: [\"get\"]\n---\nkind: RoleBinding\napiVersion: rbac.authorization.k8s.io/v1beta1\nmetadata:\n name: endpoint-reader\n namespace: namespace-dev\nsubjects:\n- kind: ServiceAccount\n name: rabbitmq\nroleRef:\n apiGroup: rbac.authorization.k8s.io\n kind: Role\n name: endpoint-reader\n---\napiVersion: v1\nkind: PersistentVolume\nmetadata:\n name: \"rabbitmq-data\"\n labels:\n name: \"rabbitmq-data\"\n release: \"rabbitmq-data\"\n namespace: \"namespace-dev\"\nspec:\n capacity:\n storage: 5Gi\n accessModes:\n - \"ReadWriteMany\"\n nfs:\n path: \"/path/to/nfs\"\n server: \"xx.xx.xx.xx\"\n persistentVolumeReclaimPolicy: Retain\n\n--- \napiVersion: v1\nkind: PersistentVolumeClaim\nmetadata:\n name: \"rabbitmq-data-claim\"\n namespace: \"namespace-dev\"\nspec:\n accessModes:\n - ReadWriteMany\n resources: \n requests:\n storage: 5Gi\n selector:\n matchLabels:\n release: rabbitmq-data\n---\n# headless service Used to access pods using hostname\nkind: Service\napiVersion: v1\nmetadata:\n name: rabbitmq-headless\n namespace: namespace-dev\nspec:\n clusterIP: None\n # publishNotReadyAddresses, when set to true, indicates that DNS implementations must publish the notReadyAddresses of subsets for the Endpoints associated with the Service. The default value is false. The primary use case for setting this field is to use a StatefulSet's Headless Service to propagate SRV records for its Pods without respect to their readiness for purpose of peer discovery. This field will replace the service.alpha.kubernetes.io/tolerate-unready-endpoints when that annotation is deprecated and all clients have been converted to use this field.\n # Since access to the Pod using DNS requires Pod and Headless service to be started before launch, publishNotReadyAddresses is set to true to prevent readinessProbe from finding DNS when the service is not started.\n publishNotReadyAddresses: true \n ports: \n - name: amqp\n port: 5672\n - name: http\n port: 15672\n selector:\n app: rabbitmq\n---\n# Used to expose the dashboard to the external network\nkind: Service\napiVersion: v1\nmetadata:\n namespace: namespace-dev\n name: rabbitmq-service\nspec:\n type: NodePort\n ports:\n - name: http\n protocol: TCP\n port: 15672\n targetPort: 15672\n nodePort: 31672\n - name: amqp\n protocol: TCP\n port: 5672\n targetPort: 5672\n nodePort: 30672\n selector:\n app: rabbitmq\n---\napiVersion: v1\nkind: ConfigMap\nmetadata:\n name: rabbitmq-config\n namespace: namespace-dev\ndata:\n enabled_plugins: |\n [rabbitmq_management,rabbitmq_peer_discovery_k8s].\n rabbitmq.conf: |\n cluster_formation.peer_discovery_backend = rabbit_peer_discovery_k8s\n cluster_formation.k8s.host = kubernetes.default.svc.cluster.local\n cluster_formation.k8s.address_type = hostname\n cluster_formation.node_cleanup.interval = 10\n cluster_formation.node_cleanup.only_log_warning = true\n cluster_partition_handling = autoheal\n queue_master_locator=min-masters\n loopback_users.guest = false\n\n cluster_formation.randomized_startup_delay_range.min = 0\n cluster_formation.randomized_startup_delay_range.max = 2\n cluster_formation.k8s.service_name = rabbitmq-headless\n cluster_formation.k8s.hostname_suffix = .rabbitmq-headless.namespace-dev.svc.cluster.local\n vm_memory_high_watermark.absolute = 1.6GB\n disk_free_limit.absolute = 2GB\n\n---\napiVersion: apps/v1\nkind: StatefulSet\nmetadata:\n name: rabbitmq\n namespace: rabbitmq\nspec:\n serviceName: rabbitmq-headless # Must be the same as the name of the headless service, used for hostname propagation access pod\n selector:\n matchLabels:\n app: rabbitmq # In apps/v1, it needs to be the same as .spec.template.metadata.label for hostname propagation access pods, but not in apps/v1beta\n replicas: 3\n template:\n metadata:\n labels:\n app: rabbitmq # In apps/v1, the same as .spec.selector.matchLabels\n # setting podAntiAffinity\n annotations:\n scheduler.alpha.kubernetes.io/affinity: >\n {\n \"podAntiAffinity\": {\n \"requiredDuringSchedulingIgnoredDuringExecution\": [{\n \"labelSelector\": {\n \"matchExpressions\": [{\n \"key\": \"app\",\n \"operator\": \"In\",\n \"values\": [\"rabbitmq\"]\n }]\n },\n \"topologyKey\": \"kubernetes.io/hostname\"\n }]\n }\n }\n spec:\n serviceAccountName: rabbitmq\n terminationGracePeriodSeconds: 10\n containers: \n - name: rabbitmq\n image: rabbitmq:3.7.10\n resources:\n limits:\n cpu: \"0.5\"\n memory: 2Gi\n requests:\n cpu: \"0.3\"\n memory: 2Gi\n volumeMounts:\n - name: config-volume\n mountPath: /etc/rabbitmq\n - name: rabbitmq-data\n mountPath: /var/lib/rabbitmq/mnesia\n ports:\n - name: http\n protocol: TCP\n containerPort: 15672\n - name: amqp\n protocol: TCP\n containerPort: 5672\n livenessProbe:\n exec:\n command: [\"rabbitmqctl\", \"status\"]\n initialDelaySeconds: 60\n periodSeconds: 60\n timeoutSeconds: 5\n readinessProbe:\n exec:\n command: [\"rabbitmqctl\", \"status\"]\n initialDelaySeconds: 20\n periodSeconds: 60\n timeoutSeconds: 5\n imagePullPolicy: IfNotPresent\n env:\n - name: HOSTNAME\n valueFrom:\n fieldRef:\n fieldPath: metadata.name\n - name: RABBITMQ_USE_LONGNAME\n value: \"true\"\n - name: RABBITMQ_NODENAME\n value: \"rabbit@$(HOSTNAME).rabbitmq-headless.namespace-dev.svc.cluster.local\"\n # If service_name is set in ConfigMap, there is no need to set it again here.\n # - name: K8S_SERVICE_NAME\n # value: \"rabbitmq-headless\"\n - name: RABBITMQ_ERLANG_COOKIE\n value: \"mycookie\" \n volumes:\n - name: config-volume\n configMap:\n name: rabbitmq-config\n items:\n - key: rabbitmq.conf\n path: rabbitmq.conf\n - key: enabled_plugins\n path: enabled_plugins\n - name: rabbitmq-data\n persistentVolumeClaim:\n claimName: rabbitmq-data-claim\n```\n\n```text\n[admin@devsvr3 yaml]$ kubectl get pods\nNAME READY STATUS RESTARTS AGE\nrabbitmq-0 1/1 Running 0 2m2s\nrabbitmq-1 0/1 Running 1 43s\n```\n\n```text\n[admin@devsvr3 yaml]$ kubectl logs rabbitmq-1\n\n ## ##\n ## ## RabbitMQ 3.7.10. Copyright (C) 2007-2018 Pivotal Software, Inc.\n ########## Licensed under the MPL. See http://www.rabbitmq.com/\n ###### ##\n ########## Logs: <stdout>\n\n Starting broker...\n2019-02-06 21:09:03.303 [info] <0.211.0> \n Starting RabbitMQ 3.7.10 on Erlang 21.2.3\n Copyright (C) 2007-2018 Pivotal Software, Inc.\n Licensed under the MPL. See http://www.rabbitmq.com/\n2019-02-06 21:09:03.315 [info] <0.211.0> \n node : rabbit@rabbitmq-1.rabbitmq-headless.namespace-dev.svc.cluster.local\n home dir : /var/lib/rabbitmq\n config file(s) : /etc/rabbitmq/rabbitmq.conf\n cookie hash : XhdCf8zpVJeJ0EHyaxszPg==\n log(s) : <stdout>\n database dir : /var/lib/rabbitmq/mnesia/rabbit@rabbitmq-1.rabbitmq-headless.namespace-dev.svc.cluster.local\n2019-02-06 21:09:10.617 [error] <0.219.0> Unable to parse vm_memory_high_watermark value \"1.6GB\"\n2019-02-06 21:09:10.617 [info] <0.219.0> Memory high watermark set to 103098 MiB (108106919116 bytes) of 257746 MiB (270267297792 bytes) total\n2019-02-06 21:09:10.690 [info] <0.221.0> Enabling free disk space monitoring\n2019-02-06 21:09:10.690 [info] <0.221.0> Disk free limit set to 2000MB\n2019-02-06 21:09:10.698 [info] <0.224.0> Limiting to approx 1048476 file handles (943626 sockets)\n2019-02-06 21:09:10.698 [info] <0.225.0> FHC read buffering: OFF\n2019-02-06 21:09:10.699 [info] <0.225.0> FHC write buffering: ON\n2019-02-06 21:09:10.702 [info] <0.211.0> Node database directory at /var/lib/rabbitmq/mnesia/rabbit@rabbitmq-1.rabbitmq-headless.namespace-dev.svc.cluster.local is empty. Assuming we need to join an existing cluster or initialise from scratch...\n2019-02-06 21:09:10.702 [info] <0.211.0> Configured peer discovery backend: rabbit_peer_discovery_k8s\n2019-02-06 21:09:10.702 [info] <0.211.0> Will try to lock with peer discovery backend rabbit_peer_discovery_k8s\n2019-02-06 21:09:10.702 [info] <0.211.0> Peer discovery backend does not support locking, falling back to randomized delay\n2019-02-06 21:09:10.702 [info] <0.211.0> Peer discovery backend rabbit_peer_discovery_k8s does not support registration, skipping randomized startup delay.\n2019-02-06 21:09:10.710 [info] <0.211.0> Failed to get nodes from k8s - {failed_connect,[{to_address,{\"kubernetes.default.svc.cluster.local\",443}},\n {inet,[inet],nxdomain}]}\n2019-02-06 21:09:10.711 [error] <0.210.0> CRASH REPORT Process <0.210.0> with 0 neighbours exited with reason: no case clause matching {error,\"{failed_connect,[{to_address,{\\\"kubernetes.default.svc.cluster.local\\\",443}},\\n {inet,[inet],nxdomain}]}\"} in rabbit_mnesia:init_from_config/0 line 164 in application_master:init/4 line 138\n2019-02-06 21:09:10.711 [info] <0.43.0> Application rabbit exited with reason: no case clause matching {error,\"{failed_connect,[{to_address,{\\\"kubernetes.default.svc.cluster.local\\\",443}},\\n {inet,[inet],nxdomain}]}\"} in rabbit_mnesia:init_from_config/0 line 164\n{\"Kernel pid terminated\",application_controller,\"{application_start_failure,rabbit,{bad_return,{{rabbit,start,[normal,[]]},{'EXIT',{{case_clause,{error,\\\"{failed_connect,[{to_address,{\\\\\"kubernetes.default.svc.cluster.local\\\\\",443}},\\n {inet,[inet],nxdomain}]}\\\"}},[{rabbit_mnesia,init_from_config,0,[{file,\\\"src/rabbit_mnesia.erl\\\"},{line,164}]},{rabbit_mnesia,init_with_lock,3,[{file,\\\"src/rabbit_mnesia.erl\\\"},{line,144}]},{rabbit_mnesia,init,0,[{file,\\\"src/rabbit_mnesia.erl\\\"},{line,111}]},{rabbit_boot_steps,'-run_step/2-lc$^1/1-1-',1,[{file,\\\"src/rabbit_boot_steps.erl\\\"},{line,49}]},{rabbit_boot_steps,run_step,2,[{file,\\\"src/rabbit_boot_steps.erl\\\"},{line,49}]},{rabbit_boot_steps,'-run_boot_steps/1-lc$^0/1-0-',1,[{file,\\\"src/rabbit_boot_steps.erl\\\"},{line,26}]},{rabbit_boot_steps,run_boot_steps,1,[{file,\\\"src/rabbit_boot_steps.erl\\\"},{line,26}]},{rabbit,start,2,[{file,\\\"src/rabbit.erl\\\"},{line,815}]}]}}}}}\"}\nKernel pid terminated (application_controller) ({application_start_failure,rabbit,{bad_return,{{rabbit,start,[normal,[]]},{'EXIT',{{case_clause,{error,\"{failed_connect,[{to_address,{\\\"kubernetes.defau\n\nCrash dump is being written to: /var/log/rabbitmq/erl_crash.dump...done\n[admin@devsvr3 yaml]$\n```\n\n```text\n[my-rabbit-svc].[my-rabbitmq-namespace].svc.[cluster-name]\n```\n\n```text\ndnsConfig:\n searches:\n - [my-rabbit-svc].[my-rabbitmq-namespace].svc.[cluster-name]\n```\n\n```text\ncluster_formation.k8s.host = [your kubernetes endpoint ip addres]\ncluster_formation.k8s.port = [your kubernetes endpoint port]\n```\n\n```text\nkubernetes.default.svc.cluster.local\n```\n\n```text\nkubernetes.default.svc.cluster.local\n```\n\n```text\n- name: \"k8s-api-sidecar\"\n image: \"tommyvn/kubectl-proxy:latest\"\n```\n\n```text\ncluster_formation.peer_discovery_backend = rabbit_peer_discovery_k8s\ncluster_formation.k8s.host = localhost\ncluster_formation.k8s.port = 8001\ncluster_formation.k8s.scheme = http\n```\n\n========================================\n\nComments:\n- Probably late to answer, but for other struck at this, try adding service account and token value as per the doc rabbitmq.com/cluster-formation.html#peer-discovery-k8s\n- it seems more like a DNS problem as pointed out in the logs '{failed_connect,[{to_address,{\\\"kubernetes.default.svc.clus‌​ter.local\\\",443}}'\n- That is one solution to the dns problem except it will still rely on IP address while the need for statefulset is to use hostnames\n- are you shure that your kubernetes cluster name is cluster.local?","metadata":{"transformedAt":"2026-08-18T18:33:20.169Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":638,"estimatedTokens":5800}}529{"id":"stack-56074676","source":"stackoverflow","questionId":56074676,"title":"How to override MassTransit default exchange and queue topology convention?","tags":["c#",".net-core","rabbitmq","masstransit"],"text":"Title: How to override MassTransit default exchange and queue topology convention?\nTags: c#, .net-core, rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nAs pointed out [in one of my questions on SO] (Why a simple configuration in MassTransit creates 2 queues and 3 exchanges?), MassTransit for RabbitMQ creates automatically a certain number of queues and exchange for a given simple configuration:\n\n Exchanges, all fanouts:\n\n \n \n \n- `ConsoleApp1:Program-YourMessage`: Durable\n \n- `VP0003748_dotnet_bus_6n9oyyfzxhyx9ybobdmpj8qeyt`: Auto-delete and Durable?\n \n- `test_queue`: Durable\n \n \n Queues:\n\n \n \n \n- `VP0003748_dotnet_bus_6n9oyyfzxhyx9ybobdmpj8qeyt`: x-expire 60000\n \n- `test_queue`: Durable\n \n\nHowever, I found it a bit frustration to not be able to override the naming of those exchanges and queues. Is there anything I can do to change that?\n\nFor example, if you refactor some type or a namespace you may endup polluting your RabbitMQ instance with tons of exchanges that are no longer used =/\n\nI understand `test_queue` cause this is something I decided so fair enough.\nTypes are easily subject to changes / refactoring.\n\n========================================\n\nTop Answer:\nName of the queue can be changed by using OverrideDefaultBusEndpointQueueName method of IRabbitMqBusFactoryConfigurator in the following way\n\n```\nvar bus = Bus.Factory.CreateUsingRabbitMq(sbc =>\n{\n sbc.Host(\"rabbitmq://localhost/\");\n\n sbc.OverrideDefaultBusEndpointQueueName(\"endpoint\");\n});\n```\n\n========================================\n\nCode:\n```text\nConsoleApp1:Program-YourMessage\n```\n\n```text\nVP0003748_dotnet_bus_6n9oyyfzxhyx9ybobdmpj8qeyt\n```\n\n```text\ntest_queue\n```\n\n```text\nVP0003748_dotnet_bus_6n9oyyfzxhyx9ybobdmpj8qeyt\n```\n\n```text\ntest_queue\n```\n\n```text\ntest_queue\n```\n\n```text\npublic class BusEnvironmentNameFormatter : IEntityNameFormatter\n{\n private readonly IEntityNameFormatter _original;\n private readonly string _prefix;\n\n public BusEnvironmentNameFormatter(IEntityNameFormatter original, SomeAppSettingsSection busSettings)\n {\n _original = original;\n _prefix = string.IsNullOrWhiteSpace(busSettings.Environment)\n ? string.Empty // no prefix\n : $\"{busSettings.Environment}:\"; // custom prefix\n }\n\n // Used to rename the exchanges\n public string FormatEntityName<T>()\n {\n var original = _original.FormatEntityName<T>();\n return Format(original);\n }\n\n // Use this one to rename the queue\n public string Format(string original)\n {\n return string.IsNullOrWhiteSpace(_prefix)\n ? original\n : $\"{_prefix}{original}\";\n }\n}\n```\n\n```text\nvar busSettings = busConfigSection.Get<SomeAppSettingsSection>();\nvar rabbitMqSettings = rabbitMqConfigSection.Get<SomeOtherAppSettingsSection>();\n\nservices.AddMassTransit(scConfig =>\n{\n scConfig.AddConsumers(consumerAssemblies);\n\n scConfig.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(rmqConfig =>\n {\n rmqConfig.UseExtensionsLogging(provider.GetRequiredService<ILoggerFactory>());\n\n // Force serialization of default values: null, false, etc\n rmqConfig.ConfigureJsonSerializer(jsonSettings =>\n {\n jsonSettings.DefaultValueHandling = DefaultValueHandling.Include;\n return jsonSettings;\n });\n\n var nameFormatter = new BusEnvironmentNameFormatter(rmqConfig.MessageTopology.EntityNameFormatter, busSettings);\n var host = rmqConfig.Host(new Uri(rabbitMqSettings.ConnectionString), hostConfig =>\n {\n hostConfig.Username(rabbitMqSettings.Username);\n hostConfig.Password(rabbitMqSettings.Password);\n });\n\n // Endpoint with custom naming\n rmqConfig.ReceiveEndpoint(host, nameFormatter.Format(busSettings.Endpoint), epConfig =>\n {\n epConfig.PrefetchCount = busSettings.MessagePrefetchCount;\n epConfig.UseMessageRetry(x => x.Interval(busSettings.MessageRetryCount, busSettings.MessageRetryInterval));\n epConfig.UseInMemoryOutbox();\n\n //TODO: Bind messages to this queue/endpoint\n epConfig.MapMessagesToConsumers(provider, busSettings);\n });\n\n // Custom naming for exchanges\n rmqConfig.MessageTopology.SetEntityNameFormatter(nameFormatter);\n }));\n});\n```\n\n```text\nvar bus = Bus.Factory.CreateUsingRabbitMq(sbc =>\n{\n sbc.Host(\"rabbitmq://localhost/\");\n\n sbc.OverrideDefaultBusEndpointQueueName(\"endpoint\");\n});\n```\n\n========================================\n\nComments:\n- You might read the documentation: masstransit-project.com/MassTransit/advanced/topology/… and masstransit-project.com/MassTransit/advanced/topology/… and masstransit-project.com/MassTransit/advanced/topology/rabbit‌​mq\n- @Chris Patterson the documentation does not say how to change the temporary exchanges / queues e.g. `VP0003748_dotnet_bus_7qyyyyrfxhbykj9dbdmpks5xd5` `VP0003748_dotnet_bus_7qyyyyrfxhbykj9dbdmpks5xd5`\n- github.com/MassTransit/MassTransit/blob/develop/src/…\n- github.com/MassTransit/MassTransit/blob/develop/src/Transpor‌​ts/… Updated link to method.","metadata":{"transformedAt":"2026-08-18T18:33:20.169Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":167,"estimatedTokens":1291}}530{"id":"stack-8015840","source":"stackoverflow","questionId":8015840,"title":"RabbitMQ with WCF and a persistent queue","tags":["wcf","message-queue","rabbitmq"],"text":"Title: RabbitMQ with WCF and a persistent queue\nTags: wcf, message-queue, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am trying to write a wcf service that works over the rabbitMQ binding. I was able to successfully create a server and a client and have the client send messages to the server via the queue. I am confused about 2 issues.\n\nAs soon as the service is shutdown the queue is deleted. Is there a way to configure wcf and rabbitMQ so that the queue is persistent? This way I dont have to worry about losing data if my server crashes.\n\nI can't seem to control the name of the queue. When I run `rabbitmqctl.bat list_queues` I see that the queue is called `amq.gen-3IgZD30XvTEQWNRsezSUUA==`. Is there a way to control the name of the queue?\n\n========================================\n\nTop Answer:\nI had the same problem as you did and what I did was to edit the source code of the rabbitMQDotNetClient.\n\nFile: RabbitMQInputChannel.cs\n\n```\npublic override void Open(TimeSpan timeout)\n { \n if (State != CommunicationState.Created && State != CommunicationState.Closed)\n throw new InvalidOperationException(string.Format(\"Cannot open the channel from the {0} state.\", base.State));\n\n OnOpening();\n#if VERBOSE\n DebugHelper.Start();\n#endif\n //Create a queue for messages destined to this service, bind it to the service URI routing key\n#if USE_DEFINED_QUEUE_NAMES\n //here we create a queue that uses the name given in the service address in the wcf binding.\n //if the address in the web.config is: soap.amq:///QueueName\n //the name of the queue will be: QueueName\n //LVV\n string queue = m_model.QueueDeclare(base.LocalAddress.Uri.PathAndQuery, true, false, false, null);\n#else\n string queue = m_model.QueueDeclare();\n#endif\n m_model.QueueBind(queue, Exchange, base.LocalAddress.Uri.PathAndQuery, null);\n\n //Listen to the queue\n m_messageQueue = new QueueingBasicConsumer(m_model);\n m_model.BasicConsume(queue, false, m_messageQueue);\n\n#if VERBOSE\n DebugHelper.Stop(\" ## In.Channel.Open {{\\n\\tAddress={1}, \\n\\tTime={0}ms}}.\", LocalAddress.Uri.PathAndQuery);\n#endif\n OnOpened();\n }\n```\n\nCompile with the flag USE_DEFINED_QUEUE_NAMES. This will create a queue name with the name you have given in your app.config or web.config file. You can always change the queues options on the QueueDeclare(...) if you want your queues to behave differently than the ones I'm creating.\nCheers!\n\n========================================\n\nCode:\n```text\nrabbitmqctl.bat list_queues\n```\n\n```text\namq.gen-3IgZD30XvTEQWNRsezSUUA==\n```\n\n```text\npublic override void Open(TimeSpan timeout)\n { \n if (State != CommunicationState.Created && State != CommunicationState.Closed)\n throw new InvalidOperationException(string.Format(\"Cannot open the channel from the {0} state.\", base.State));\n\n OnOpening();\n#if VERBOSE\n DebugHelper.Start();\n#endif\n //Create a queue for messages destined to this service, bind it to the service URI routing key\n#if USE_DEFINED_QUEUE_NAMES\n //here we create a queue that uses the name given in the service address in the wcf binding.\n //if the address in the web.config is: soap.amq:///QueueName\n //the name of the queue will be: QueueName\n //LVV\n string queue = m_model.QueueDeclare(base.LocalAddress.Uri.PathAndQuery, true, false, false, null);\n#else\n string queue = m_model.QueueDeclare();\n#endif\n m_model.QueueBind(queue, Exchange, base.LocalAddress.Uri.PathAndQuery, null);\n\n //Listen to the queue\n m_messageQueue = new QueueingBasicConsumer(m_model);\n m_model.BasicConsume(queue, false, m_messageQueue);\n\n#if VERBOSE\n DebugHelper.Stop(\" ## In.Channel.Open {{\\n\\tAddress={1}, \\n\\tTime={0}ms}}.\", LocalAddress.Uri.PathAndQuery);\n#endif\n OnOpened();\n }\n```\n\n========================================\n\nComments:\n- Thanks. That's the answer that I was looking for. It basically makes it pointless to even have a WCF binding for rabbitMQ if it can't give you this control.","metadata":{"transformedAt":"2026-08-18T18:33:20.169Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":102,"estimatedTokens":1004}}531{"id":"stack-5683217","source":"stackoverflow","questionId":5683217,"title":"Subscribe to a queue, receive 1 message, and then unsubscribe","tags":["ruby","rabbitmq","amqp"],"text":"Title: Subscribe to a queue, receive 1 message, and then unsubscribe\nTags: ruby, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI have a scenario where I need to distribute and process jobs extremely quickly. I'll have about 45 jobs populated in the queue quickly and I can process about 20 simultaneously (5 machines, 4 cores each). Each job takes a variable amount of time, and to complicate matters garbage collection is an issue so I need to be able to take a consumer offline for garbage collection.\n\nCurrently, I have everything working with pop (every consumer pops every 5ms). This seems undesirable because it translates to 600 pop requests per second to rabbitmq.\n\nI would love if it there were a pop command that would act like subscribe, but for only one message. (the process would block, waiting for input from the rabbitMQ connection, via something akin to Kernel.select)\n\nI have tried to trick the AMQP gem to doing something like this, but it's not working: I can't seem to unsubscribe until the queue is empty and no more messages are being sent to the consumer. Other methods of unsubscribing I fear will lose messages.\n\nconsume_1.rb :\n\n```\nrequire \"amqp\"\n\nEventMachine.run do\n puts \"connecting...\"\n connection = AMQP.connect(:host => \"localhost\", :user => \"guest\", :pass => \"guest\", :vhost => \"/\")\n puts \"Connected to AMQP broker\"\n\n channel = AMQP::Channel.new(connection)\n queue = channel.queue(\"tasks\", :auto_delete => true)\n exchange = AMQP::Exchange.default(channel)\n\n queue.subscribe do |payload|\n puts \"Received a message: #{payload}.\"\n queue.unsubscribe { puts \"unbound\" }\n sleep 3\n end\nend\n```\n\nconsumer_many.rb:\n\n```\nrequire \"amqp\"\n\n# Imagine the command is something CPU - intensive like image processing.\ncommand = \"sleep 0.1\"\n\nEventMachine.run do\n puts \"connecting...\"\n connection = AMQP.connect(:host => \"localhost\", :user => \"guest\", :pass => \"guest\", :vhost => \"/\")\n puts \"Connected to AMQP broker\"\n\n channel = AMQP::Channel.new(connection)\n queue = channel.queue(\"tasks\", :auto_delete => true)\n exchange = AMQP::Exchange.default(channel)\n\n queue.subscribe do |payload|\n puts \"Received a message: #{payload}.\"\n end\nend\n```\n\nproducer.rb:\n\n```\nrequire \"amqp\"\n\ni = 0\nEventMachine.run do\n connection = AMQP.connect(:host => \"localhost\", :user => \"guest\", :pass => \"guest\", :vhost => \"/\")\n puts \"Connected to AMQP broker\"\n\n channel = AMQP::Channel.new(connection)\n queue = channel.queue(\"tasks\", :auto_delete => true)\n exchange = AMQP::Exchange.default(channel)\n\n EM.add_periodic_timer(1) do\n msg = \"Message #{i}\"\n i+=1\n puts \"~ publishing #{msg}\"\n end\nend\n```\n\nI'll launch consume_many.rb and producer.rb. Messages will flow as expected.\n\nWhen I launch consume_1.rb, it gets every other message (as expected). But it NEVER unsubscribes because it never finishes processing all of its messages... so on it goes.\n\nHow do I get consume_1.rb to subscribe to the queue, get a single message, and then take itself out of the load-balancer ring so it can do it's work, without losing any additional pending jobs that might be in the queue and would otherwise be scheduled to be sent to the process?\n\nTim\n\n========================================\n\nTop Answer:\nWith the environment that I have,\n\nRabbitMQ version: 3.3.3\n\namqp gem version: 1.5.0\n\nThe solution from Ivan still resulted in all the messages being fetched from the queue.\n\nInstead, the number of unacknowledged messages by subscribing to a queue can be limited by setting the QoS of a channel.\n\nAs per the API document of AMQP::Channel,\n\n```\n#qos(prefetch_size = 0, prefetch_count = 32, global = false, &block) ⇒ Object\n```\n\nOne note for the method in that, if you are running RabbitMQ servers after version 2.3.6, *prefetch_size* is deprecated.\n\n```\nchannel = AMQP::Channel.new(connection, :prefetch => 1)\nchannel.qos(0, 1)\n\nqueue = channel.queue(queue_name, :auto_delete => false)\nqueue.subscribe(:ack => true) do |metadata, payload|\n puts \"Received a message: #{payload}.\"\n\n # Do long running work here\n\n # Acknowledge message\n metadata.ack\nend\n```\n\nHope the solution helps someone out.\n\nCheers.\n\n========================================\n\nCode:\n```text\nrequire \"amqp\"\n\nEventMachine.run do\n puts \"connecting...\"\n connection = AMQP.connect(:host => \"localhost\", :user => \"guest\", :pass => \"guest\", :vhost => \"/\")\n puts \"Connected to AMQP broker\"\n\n channel = AMQP::Channel.new(connection)\n queue = channel.queue(\"tasks\", :auto_delete => true)\n exchange = AMQP::Exchange.default(channel)\n\n queue.subscribe do |payload|\n puts \"Received a message: #{payload}.\"\n queue.unsubscribe { puts \"unbound\" }\n sleep 3\n end\nend\n```\n\n```text\nrequire \"amqp\"\n\n# Imagine the command is something CPU - intensive like image processing.\ncommand = \"sleep 0.1\"\n\nEventMachine.run do\n puts \"connecting...\"\n connection = AMQP.connect(:host => \"localhost\", :user => \"guest\", :pass => \"guest\", :vhost => \"/\")\n puts \"Connected to AMQP broker\"\n\n channel = AMQP::Channel.new(connection)\n queue = channel.queue(\"tasks\", :auto_delete => true)\n exchange = AMQP::Exchange.default(channel)\n\n queue.subscribe do |payload|\n puts \"Received a message: #{payload}.\"\n end\nend\n```\n\n```text\nrequire \"amqp\"\n\ni = 0\nEventMachine.run do\n connection = AMQP.connect(:host => \"localhost\", :user => \"guest\", :pass => \"guest\", :vhost => \"/\")\n puts \"Connected to AMQP broker\"\n\n channel = AMQP::Channel.new(connection)\n queue = channel.queue(\"tasks\", :auto_delete => true)\n exchange = AMQP::Exchange.default(channel)\n\n EM.add_periodic_timer(1) do\n msg = \"Message #{i}\"\n i+=1\n puts \"~ publishing #{msg}\"\n end\nend\n```\n\n```text\nchannel = AMQP::Channel.new(connection, :prefetch => 1)\n```\n\n```text\nqueue.subscribe(:ack => true) do |queue_header, payload|\n puts \"Received a message: #{payload}.\"\n # Do long running work here\n\n # Acknowledge message\n queue_header.ack\nend\n```\n\n```text\nack\n```\n\n```text\ndirect\n```\n\n```text\n#qos(prefetch_size = 0, prefetch_count = 32, global = false, &block) ⇒ Object\n```\n\n```text\nchannel = AMQP::Channel.new(connection, :prefetch => 1)\nchannel.qos(0, 1)\n\nqueue = channel.queue(queue_name, :auto_delete => false)\nqueue.subscribe(:ack => true) do |metadata, payload|\n puts \"Received a message: #{payload}.\"\n\n # Do long running work here\n\n # Acknowledge message\n metadata.ack\nend\n```\n\n========================================\n\nComments:\n- Writing a server that behaves this way would be stupid-easy in ruby... maybe using zero-mq to implement my own broker is the solution?\n- Ivan, you're a genius. I have been searching for this for several months now. THANK YOU!\n- I'm not half surprised, I was banging my head against the desk for months before figuring that out from reading the source code.\n- Ivan - I don't think the type of exchange would really matter here. His issue is at the queue level because it sounds like he wants multiple consumers working from the same queue, each taking turns to pull a single work item and process it. Therefore, the type of exchange in use doesn't matter because the exchange is essentially out of the picture once the message is inserted into the queue.","metadata":{"transformedAt":"2026-08-18T18:33:20.169Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":240,"estimatedTokens":1775}}532{"id":"stack-67907336","source":"stackoverflow","questionId":67907336,"title":"Celery task with a long ETA and RabbitMQ","tags":["rabbitmq","celery"],"text":"Title: Celery task with a long ETA and RabbitMQ\nTags: rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nRabbitMQ may enforce ack timeouts for consumers: https://www.rabbitmq.com/consumers.html#acknowledgement-modes\nBy default if a task has not been acked within 15 min entire node will go down with a `PreconditionFailed` error.\nI need to schedule a celery task (using RabbitMQ as a broker) with an ETA quite far in the future (1-3 h) and as of now (with celery 4 and rabbitmq 3.8) when I try that... I get `PreconditionFailed` after the consumer ack timeout configured for my RMQ.\nI expected that the task would be acknolwedged before its ETA ...\n\n**Is there a way to configure an ETA celery task to be acknowledged within the consumer ack timeout?**\n\nright now I am increasing the `consumer_timeout` to above my ETA time delta, but there must be a better solution ...\n\n========================================\n\nTop Answer:\nThere's a way to change this `consumer_timeout` for a running instance by running the following command on the RabbitMQ server:\n\n`rabbitmqctl eval 'application:set_env(rabbit, consumer_timeout, 36000000).'`\n\nThis will set the new timeout to 10 hrs (36000000ms). For this to take effect, you need to restart your workers though. Existing worker connections will continue to use the old timeout.\n\nYou can check the current configured timeout value as well:\n\n`rabbitmqctl eval 'application:get_env(rabbit, consumer_timeout).'`\n\nIf you are running RabbitMQ via Docker image, here's how to set the value: Simply add `-e RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS=\"-rabbit consumer_timeout 36000000\"` to your `docker run` OR set the environment `RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS` to `\"-rabbit consumer_timeout 36000000\"`.\n\nHope this helps!\n\n========================================\n\nCode:\n```text\nPreconditionFailed\n```\n\n```text\nPreconditionFailed\n```\n\n```text\nconsumer_timeout\n```\n\n```text\nconsumer_timeout\n```\n\n```text\nrabbitmqctl eval 'application:set_env(rabbit, consumer_timeout, 36000000).'\n```\n\n```text\nrabbitmqctl eval 'application:get_env(rabbit, consumer_timeout).'\n```\n\n```text\n-e RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS=\"-rabbit consumer_timeout 36000000\"\n```\n\n```text\ndocker run\n```\n\n```text\nRABBITMQ_SERVER_ADDITIONAL_ERL_ARGS\n```\n\n```text\n\"-rabbit consumer_timeout 36000000\"\n```\n\n========================================\n\nComments:\n- Set `{consumer_timeout, false}` in `rabbitmq.config`.\n- sadly, that does not seem to work for me: github.com/rabbitmq/rabbitmq-server/issues/3096\n- It does if you use `rabbitmq.config` and classic formatting. `Config files * /etc/rabbitmq/rabbitmq.config`\n- Hi, I also wanted to do something similar and have tried something with the \"rabbitmq-delayed-exchange-plugin\" and \"dead-letter-queue\". I wrote an article about both and mentioned the links below. I hope it will be helpful to someone. using dlx: medium.com/@anandhu.gopi97/… using RabbitMQ Delayed Message Plugin: medium.com/@anandhu.gopi97/…\n- I do not think this solves the problem that is discussed. `time_limit` and `soft_time_limit` are for running tasks where as the issue under discussion is for tasks that are using `ETA` or `Countdown` feature of celery. The tasks are taken up by workers but not acknowledged (since they are yet to be run at the given `ETA`) and hence the problem (newer RabbitMQ doesn't like that!)","metadata":{"transformedAt":"2026-08-18T18:33:20.169Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":82,"estimatedTokens":843}}533{"id":"stack-60607001","source":"stackoverflow","questionId":60607001,"title":"Can I wait for a process to complete when consuming RabbitMQ messages with Node.js?","tags":["javascript","node.js","rabbitmq","es6-promise"],"text":"Title: Can I wait for a process to complete when consuming RabbitMQ messages with Node.js?\nTags: javascript, node.js, rabbitmq, es6-promise\nSource: Stack Overflow\n\nQuestion:\nI'm pretty new to Node.js and ES6, and this is just confusing me a little bit. I am trying to leave a process running, consuming messages from a RabbitMQ queue. It needs to be able to process the message (which takes about 30-60 seconds) before it grabs the next message. Currently, the code I have, it grabs all messages it can and then tries to fork the processes. When there are 3-5 messages in the queue, this is fine, but for 20, 50 or 100 messages, this causes the server to run out of memory.\n\nI have tried making the `.consume()` callback function async and adding `await` to the message processing function. I have tried wrapping an `await new Promise` within the `.consume()` callback around `processMessage`. I have tried adding `await` to the line that calls `channel.consume`. Nothing changes the behavior.\n\n```\n#!/usr/bin/env node\n\nconst amqp = require('amqplib');\n\nconst consumeFromQueue = async (queue, isNoAck = false, durable = false, prefetch = null) => {\n const conn_str = \"amqp://\" + process.env.RABBITMQ_USERNAME + \":\" + process.env.RABBITMQ_PASSWORD + \"@\" + process.env.RABBITMQ_HOST + \"/development?heartbeat=60\"\n const cluster = await amqp.connect(conn_str);\n const channel = await cluster.createChannel();\n await channel.assertQueue(queue, { durable: durable, autoDelete: true });\n if (prefetch) {\n channel.prefetch(prefetch);\n }\n console.log(` [x] Waiting for messages in ${queue}. To exit press CTRL+C`)\n\n try {\n channel.consume(queue, message => {\n if (message !== null) {\n console.log(' [x] Received', message.content.toString());\n processMessage(message.content.toString());\n channel.ack(message);\n return null;\n } else {\n console.log(error, 'Queue is empty!')\n channel.reject(message);\n }\n }, {noAck: isNoAck});\n } catch (error) {\n console.log(error, 'Failed to consume messages from Queue!')\n cluster.close(); \n }\n}\n\nexports.consumeFromQueue = consumeFromQueue;\n```\n\nAs a sidenote, if I create an array of strings and loop through the strings, when I add await to the `processMessage` line, it waits to execute process (30-60 seconds) before processing the next string.\n\n```\n(async () => {\n for (let i=0; iSo I basically need something that functions like this, but with listening to the queue in RabbitMQ.\n\n========================================\n\nTop Answer:\nIf someone needs a complete answer:\n\nYou need to mix channel.prefetch(1), and { noAck: false } to consume one to one messages:\n\nSimple Example:\n\n```\nconst connection = await amqp.connect('amqp://localhost') \nconst channel = await connection.createChannel()\n\nawait channel.assertQueue(queue, { durable: false })\n\n// Set the number of messages to consume:\nchannel.prefetch(1)\n\nawait channel.consume(\n 'QUEUE_NAME',\n async message => {\n if (message) {\n // YOUR ASYNC/AWAIT CODE\n\n // And then, ack the message manually:\n channel.ack(message)\n }\n },\n\n { noAck: false } // Set noAck to false to manually acknowledge messages\n)\n```\n\nThis is the way to consume a message at a time.\n\n========================================\n\nCode:\n```text\n#!/usr/bin/env node\n\nconst amqp = require('amqplib');\n\nconst consumeFromQueue = async (queue, isNoAck = false, durable = false, prefetch = null) => {\n const conn_str = \"amqp://\" + process.env.RABBITMQ_USERNAME + \":\" + process.env.RABBITMQ_PASSWORD + \"@\" + process.env.RABBITMQ_HOST + \"/development?heartbeat=60\"\n const cluster = await amqp.connect(conn_str);\n const channel = await cluster.createChannel();\n await channel.assertQueue(queue, { durable: durable, autoDelete: true });\n if (prefetch) {\n channel.prefetch(prefetch);\n }\n console.log(` [x] Waiting for messages in ${queue}. To exit press CTRL+C`)\n\n try {\n channel.consume(queue, message => {\n if (message !== null) {\n console.log(' [x] Received', message.content.toString());\n processMessage(message.content.toString());\n channel.ack(message);\n return null;\n } else {\n console.log(error, 'Queue is empty!')\n channel.reject(message);\n }\n }, {noAck: isNoAck});\n } catch (error) {\n console.log(error, 'Failed to consume messages from Queue!')\n cluster.close(); \n }\n}\n\nexports.consumeFromQueue = consumeFromQueue;\n```\n\n```text\n(async () => {\n for (let i=0; i<urls.length; i++) {\n await processMessage(urls[i]);\n }\n})();\n```\n\n```text\n.consume()\n```\n\n```text\nawait\n```\n\n```text\nawait new Promise\n```\n\n```text\n.consume()\n```\n\n```text\nprocessMessage\n```\n\n```text\nawait\n```\n\n```text\nchannel.consume\n```\n\n```text\nprocessMessage\n```\n\n```text\nchannel.prefetch(1)\n```\n\n```text\nchannel.prefetch(1)\n```\n\n```text\nconst connection = await amqp.connect('amqp://localhost') \nconst channel = await connection.createChannel()\n\nawait channel.assertQueue(queue, { durable: false })\n\n// Set the number of messages to consume:\nchannel.prefetch(1)\n\nawait channel.consume(\n 'QUEUE_NAME',\n async message => {\n if (message) {\n // YOUR ASYNC/AWAIT CODE\n\n // And then, ack the message manually:\n channel.ack(message)\n }\n },\n\n { noAck: false } // Set noAck to false to manually acknowledge messages\n)\n```\n\n========================================\n\nComments:\n- What value of `prefetch` do you pass into your `consumeFromQueue` function?\n- @shkaper Just null for now.\n- Prefetch count is what limits the number of messages that can be processed at a time by a consumer. Try limiting it to 3-5.\n- If I set prefetch, it doesn't seem that I can get any more messages until I restart my node script. Also, if I process 5 messages at once, I am unable to verify whether any are duplicates, and so could run into issues there. I am just wondering if there is anyway to wait for the process to finish before it gets a new message.\n- Hmm, this is definitely what I want. I just tested it now. It seems to still just be getting any new messages right away. I start the node script, and I send it 3 messages, and it processes all 3 instantly, without waiting for the message to finish processing, even though `channel.prefetch(1)` is now explicitly called.\n- @KenyonRosewall What's the `processMessage`? Could it be an asynchronous function by any chance?\n- If it is, and you don't wait for its execution, the message gets acked right away and the broker sends another immediately.\n- It uses pupeteer, which is asynchronous with a bunch of awaits and callbacks in there. I'm trying to figure out how to setup the rabbitmq layer to `await` the asynchronous process.\n- Yeah, how do I wait for the async process before acking the message?\n- You can make the consumer async, i.e. `channel.consume(queue, async (message) => { ...`, then `await processMessage(...); channel.ack(message)`. Or simply use the promise chain: `processMessage(...).then(() => { channel.ack(message) })`\n- Great, that was it. I just hadn't done the async callback AND prefetch(1) together. Now it is working as I want it, thank you very much.\n- `And then, ack the message manually` that was what I was missing, thanks!","metadata":{"transformedAt":"2026-08-18T18:33:20.169Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":13,"totalLines":212,"estimatedTokens":1820}}534{"id":"stack-72564558","source":"stackoverflow","questionId":72564558,"title":"Django celery error while adding tasks to RabbitMQ message queue : AttributeError: 'ChannelPromise' object has no attribute '__value__'","tags":["python","django","rabbitmq","celery","system-design"],"text":"Title: Django celery error while adding tasks to RabbitMQ message queue : AttributeError: 'ChannelPromise' object has no attribute '__value__'\nTags: python, django, rabbitmq, celery, system-design\nSource: Stack Overflow\n\nQuestion:\nI have setup celery, rabbitmq and django web server on digitalocean. RabbitMQ runs on another server where my Django app is not running.\nWhen I am trying to add the tasks to the queue using delay I am getting an error\n\nAttributeError: 'ChannelPromise' object has no attribute '**value**'\n\nFrom django shell I am adding the task to my message queue.\n\n**python3 manage.py shell**\n\n```\nPython 3.8.10 (default, Mar 15 2022, 12:22:08)\n[GCC 9.4.0] on linux\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n(InteractiveConsole)\n>>> from app1.tasks import add\n>>> add.delay(5, 6)\n```\n\nBut getting error\n\n```\nTraceback (most recent call last):\n File \"/etc/myprojectenv/lib/python3.8/site-packages/kombu/utils/functional.py\", line 30, in __call__\n return self.__value__\nAttributeError: 'ChannelPromise' object has no attribute '__value__'\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/etc/myprojectenv/lib/python3.8/site-packages/kombu/connection.py\", line 446, in _reraise_as_library_errors\n yield\n File \"/etc/myprojectenv/lib/python3.8/site-packages/kombu/connection.py\", line 433, in _ensure_connection\n return retry_over_time(\n File \"/etc/myprojectenv/lib/python3.8/site-packages/kombu/utils/functional.py\", line 312, in retry_over_time\n return fun(*args, **kwargs)\n File \"/etc/myprojectenv/lib/python3.8/site-packages/kombu/connection.py\", line 877, in _connection_factory\n self._connection = self._establish_connection()\n File \"/etc/myprojectenv/lib/python3.8/site-packages/kombu/connection.py\", line 812, in _establish_connection\n conn = self.transport.establish_connection()\n File \"/etc/myprojectenv/lib/python3.8/site-packages/kombu/transport/pyamqp.py\", line 201, in establish_connection\n conn.connect()\n File \"/etc/myprojectenv/lib/python3.8/site-packages/amqp/connection.py\", line 323, in connect\n self.transport.connect()\n File \"/etc/myprojectenv/lib/python3.8/site-packages/amqp/transport.py\", line 129, in connect\n self._connect(self.host, self.port, self.connect_timeout)\n File \"/etc/myprojectenv/lib/python3.8/site-packages/amqp/transport.py\", line 184, in _connect\n self.sock.connect(sa)\nConnectionRefusedError: [Errno 111] Connection refused\n```\n\nStarted celery as :\n\n```\ncelery -A myproject worker -l info\n```\n\nwhich gives me\n\n```\nUser information: uid=0 euid=0 gid=0 egid=0\n\n warnings.warn(SecurityWarning(ROOT_DISCOURAGED.format(\n\n -------------- celery@ubuntu-s-1vcpu-1gb-blr1-01 v5.2.7 (dawn-chorus)\n--- ***** -----\n-- ******* ---- Linux-5.4.0-107-generic-x86_64-with-glibc2.29 2022-06-09 17:24:14\n- *** --- * ---\n- ** ---------- [config]\n- ** ---------- .> app: myproject:0x7fd64fa5d970\n- ** ---------- .> transport: amqp://himanshu:**@IPADDRESS2:5672/vhostcheck\n- ** ---------- .> results:\n- *** --- * --- .> concurrency: 1 (prefork)\n-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)\n--- ***** -----\n -------------- [queues]\n .> celery exchange=celery(direct) key=celery\n\n[tasks]\n . app1.tasks.add\n\n[2022-06-09 17:24:14,309: INFO/MainProcess] Connected to amqp://himanshu:**@IPADDRESS:5672/vhostcheck\n[2022-06-09 17:24:14,313: INFO/MainProcess] mingle: searching for neighbors\n[2022-06-09 17:24:15,333: INFO/MainProcess] mingle: all alone\n[2022-06-09 17:24:15,349: WARNING/MainProcess] /etc/myprojectenv/lib/python3.8/site-packages/kombu/pidbox.py:70: UserWarning: A node named celery@ubuntu-s-1vcpu-1gb-blr1-01 is already using this process mailbox!\n\n[2022-06-09 17:24:15,352: WARNING/MainProcess] /etc/myprojectenv/lib/python3.8/site-packages/celery/fixups/django.py:203: UserWarning: Using settings.DEBUG leads to a memory\n leak, never use this setting in production environments!\n warnings.warn('''Using settings.DEBUG leads to a memory\n\n[2022-06-09 17:24:15,352: INFO/MainProcess] celery@ubuntu-s-1vcpu-1gb-blr1-01 ready.\n```\n\nInside app1 project :\n\n**tasks.py**\n\n```\nfrom __future__ import absolute_import, unicode_literals\nfrom celery import shared_task\n\n@shared_task\ndef add(x, y):\n return x + y\n```\n\n**settings.py**\n\n```\nINSTALLED_APPS = [\n ...\n 'app1',\n 'django_celery_results',\n]\n\nCELERY_RESULT_BACKEND = 'django-db'\nCELERY_CACHE_BACKEND = 'django-cache'\nCELERY_BROKER_URL = 'amqp://himanshu:password@IPADDRESS:5672/vhostcheck'\n\nCELERY_ACCEPT_CONTENT = ['application/json']\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_TIMEZONE = 'Europe/Amsterdam'\n```\n\n========================================\n\nTop Answer:\nIn my case, I had to add `broker_url` to my Django app settings. One way to do this is to create an environment variable named `CELERY_BROKER_URL`.\n\n========================================\n\nCode:\n```text\nPython 3.8.10 (default, Mar 15 2022, 12:22:08)\n[GCC 9.4.0] on linux\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n(InteractiveConsole)\n>>> from app1.tasks import add\n>>> add.delay(5, 6)\n```\n\n```text\nTraceback (most recent call last):\n File \"/etc/myprojectenv/lib/python3.8/site-packages/kombu/utils/functional.py\", line 30, in __call__\n return self.__value__\nAttributeError: 'ChannelPromise' object has no attribute '__value__'\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/etc/myprojectenv/lib/python3.8/site-packages/kombu/connection.py\", line 446, in _reraise_as_library_errors\n yield\n File \"/etc/myprojectenv/lib/python3.8/site-packages/kombu/connection.py\", line 433, in _ensure_connection\n return retry_over_time(\n File \"/etc/myprojectenv/lib/python3.8/site-packages/kombu/utils/functional.py\", line 312, in retry_over_time\n return fun(*args, **kwargs)\n File \"/etc/myprojectenv/lib/python3.8/site-packages/kombu/connection.py\", line 877, in _connection_factory\n self._connection = self._establish_connection()\n File \"/etc/myprojectenv/lib/python3.8/site-packages/kombu/connection.py\", line 812, in _establish_connection\n conn = self.transport.establish_connection()\n File \"/etc/myprojectenv/lib/python3.8/site-packages/kombu/transport/pyamqp.py\", line 201, in establish_connection\n conn.connect()\n File \"/etc/myprojectenv/lib/python3.8/site-packages/amqp/connection.py\", line 323, in connect\n self.transport.connect()\n File \"/etc/myprojectenv/lib/python3.8/site-packages/amqp/transport.py\", line 129, in connect\n self._connect(self.host, self.port, self.connect_timeout)\n File \"/etc/myprojectenv/lib/python3.8/site-packages/amqp/transport.py\", line 184, in _connect\n self.sock.connect(sa)\nConnectionRefusedError: [Errno 111] Connection refused\n```\n\n```text\ncelery -A myproject worker -l info\n```\n\n```text\nUser information: uid=0 euid=0 gid=0 egid=0\n\n warnings.warn(SecurityWarning(ROOT_DISCOURAGED.format(\n\n -------------- celery@ubuntu-s-1vcpu-1gb-blr1-01 v5.2.7 (dawn-chorus)\n--- ***** -----\n-- ******* ---- Linux-5.4.0-107-generic-x86_64-with-glibc2.29 2022-06-09 17:24:14\n- *** --- * ---\n- ** ---------- [config]\n- ** ---------- .> app: myproject:0x7fd64fa5d970\n- ** ---------- .> transport: amqp://himanshu:**@IPADDRESS2:5672/vhostcheck\n- ** ---------- .> results:\n- *** --- * --- .> concurrency: 1 (prefork)\n-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)\n--- ***** -----\n -------------- [queues]\n .> celery exchange=celery(direct) key=celery\n\n\n[tasks]\n . app1.tasks.add\n\n[2022-06-09 17:24:14,309: INFO/MainProcess] Connected to amqp://himanshu:**@IPADDRESS:5672/vhostcheck\n[2022-06-09 17:24:14,313: INFO/MainProcess] mingle: searching for neighbors\n[2022-06-09 17:24:15,333: INFO/MainProcess] mingle: all alone\n[2022-06-09 17:24:15,349: WARNING/MainProcess] /etc/myprojectenv/lib/python3.8/site-packages/kombu/pidbox.py:70: UserWarning: A node named celery@ubuntu-s-1vcpu-1gb-blr1-01 is already using this process mailbox!\n\n\n[2022-06-09 17:24:15,352: WARNING/MainProcess] /etc/myprojectenv/lib/python3.8/site-packages/celery/fixups/django.py:203: UserWarning: Using settings.DEBUG leads to a memory\n leak, never use this setting in production environments!\n warnings.warn('''Using settings.DEBUG leads to a memory\n\n[2022-06-09 17:24:15,352: INFO/MainProcess] celery@ubuntu-s-1vcpu-1gb-blr1-01 ready.\n```\n\n```text\nfrom __future__ import absolute_import, unicode_literals\nfrom celery import shared_task\n\n@shared_task\ndef add(x, y):\n return x + y\n```\n\n```text\nINSTALLED_APPS = [\n ...\n 'app1',\n 'django_celery_results',\n]\n\nCELERY_RESULT_BACKEND = 'django-db'\nCELERY_CACHE_BACKEND = 'django-cache'\nCELERY_BROKER_URL = 'amqp://himanshu:password@IPADDRESS:5672/vhostcheck'\n\nCELERY_ACCEPT_CONTENT = ['application/json']\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_TIMEZONE = 'Europe/Amsterdam'\n```\n\n```text\nsudo nano myproject/__init__.py\n```\n\n```text\n# This will make sure the app is always imported when\n# Django starts so that shared_task will use this app.\nfrom .celery import app as celery_app\n__all__ = ['celery_app']\n```\n\n```text\nmyproject/__init__.py\n```\n\n```text\nbroker_url\n```\n\n```text\nCELERY_BROKER_URL\n```\n\n========================================\n\nComments:\n- I assume that it should have been \"we defined in myproject/__init.py__\" instead of \"we defined in myproject/init.py\". Furthermore, according to your initial question and example, it should have been `__all__ = ['myproject']` instead of `__all__ = ['celery_app']`. Just my 2 cents.\n- @Kay I edited the answer with formatting so the dunders render correctly However, I'm not sure about the second part of your suggest since it is more substantive. I'm not taking the time right now to evaluate what the correct thing should be.\n- this helped to figure my issue to find the solution: stackoverflow.com/a/77735731/5305401 thanks Code-Apprentice","metadata":{"transformedAt":"2026-08-18T18:33:20.169Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":11,"totalLines":271,"estimatedTokens":2498}}535{"id":"stack-43229943","source":"stackoverflow","questionId":43229943,"title":"Can I bind a queue from a different vhost?","tags":["rabbitmq","vhosts","rabbitmq-exchange"],"text":"Title: Can I bind a queue from a different vhost?\nTags: rabbitmq, vhosts, rabbitmq-exchange\nSource: Stack Overflow\n\nQuestion:\nI have an exchange with a vhost, user, etc from that exchange I bind different queues. The exchange and the queues are in the same vhost.\nNow I want to create a different vhost for a different queue but I cannot bind this new queue from the previous exchange as It is in different vhost.\n\nWhat is the best solution for that?\nThanks\n\n========================================\n\nComments:\n- Thanks, This was my first option, to create a federation. Just wondering, do we have other options? As for example in my architecture we have already more than 10 federation just for this purpose..\n- No as far as I know, vhosts are isolated namespaces. By curiosity, what is your use case?\n- I have Internal rabbit with an exchange. then I have 10 federation each one for a different client and a different queue. I was wondering if It was possible to do in another way rather than all the time to federate.\n- What is the purpose of having a vhost per client ? (if I understand correctly)\n- so every client cannot see the queue of the others. different vhost/user for each client. Then every client has access to just one exchange and one queue\n- I conceive permission are not suitable for your use case. Thanks for this answer\n- so what do you think is the best solution? Thank you for all your answers and comments\n- I will look first at permissions, like they control access to queues, a client can have permission to access to only its queues.","metadata":{"transformedAt":"2026-08-18T18:33:20.169Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":22,"estimatedTokens":390}}536{"id":"stack-33977844","source":"stackoverflow","questionId":33977844,"title":"Spring: send message to websocket clients","tags":["java","spring","spring-boot","rabbitmq","spring-websocket"],"text":"Title: Spring: send message to websocket clients\nTags: java, spring, spring-boot, rabbitmq, spring-websocket\nSource: Stack Overflow\n\nQuestion:\nI'm building a webchat with Spring Boot, RabbitMQ and WebSocket as POC, but I'm stucked a the last point: WebSockets\n\nI want my ws clients to connect to a specific endpoint, like `/room/{id}` and when a new message arrives, I want the server to send the response to clients, but I searched for something similar and didn't found.\n\nCurrently, when the message arrives, I process it with RabbitMQ, like \n\n```\ncontainer.setMessageListener(new MessageListenerAdapter(){\n @Override\n public void onMessage(org.springframework.amqp.core.Message message, Channel channel) throws Exception {\n log.info(message);\n log.info(\"Got: \"+ new String(message.getBody()));\n }\n });\n```\n\nwhat I would like is, instead log it , I want to send it to the client, for example: `websocketManager.sendMessage(new String(message.getBody()))`\n\n========================================\n\nCode:\n```text\ncontainer.setMessageListener(new MessageListenerAdapter(){\n @Override\n public void onMessage(org.springframework.amqp.core.Message message, Channel channel) throws Exception {\n log.info(message);\n log.info(\"Got: \"+ new String(message.getBody()));\n }\n });\n```\n\n```text\n/room/{id}\n```\n\n```text\nwebsocketManager.sendMessage(new String(message.getBody()))\n```\n\n```text\n<dependency>\n <groupId>org.springframework.boot</groupId>\n <artifactId>spring-boot-starter-websocket</artifactId>\n</dependency>\n<dependency>\n <groupId>org.springframework</groupId>\n <artifactId>spring-messaging</artifactId>\n</dependency>\n```\n\n```text\n@Configuration\n@EnableWebSocketMessageBroker\npublic class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {\n\n @Override\n public void registerStompEndpoints(StompEndpointRegistry registry) {\n // the endpoint for websocket connections\n registry.addEndpoint(\"/stomp\").withSockJS();\n }\n\n @Override\n public void configureMessageBroker(MessageBrokerRegistry config) {\n config.enableSimpleBroker(\"/\");\n\n // use the /app prefix for others\n config.setApplicationDestinationPrefixes(\"/app\");\n }\n\n}\n```\n\n```text\n<script type=\"text/javascript\">\n $(document).ready(function() {\n var messageList = $(\"#messages\");\n // defined a connection to a new socket endpoint\n var socket = new SockJS('/stomp');\n var stompClient = Stomp.over(socket);\n stompClient.connect({ }, function(frame) {\n // subscribe to the /topic/message endpoint\n stompClient.subscribe(\"/room.2\", function(data) {\n var message = data.body;\n messageList.append(\"<li>\" + message + \"</li>\");\n });\n\n });\n });\n</script>\n```\n\n```text\n@Autowired\nprivate SimpMessagingTemplate webSocket;\n```\n\n```text\nwebSocket.convertAndSend(channel, new String(message.getBody()));\n```\n\n========================================\n\nComments:\n- where did \"channel\" come from as your destination argument to convertAndSend?\n- channel is a string. it is the \"room\" I'm sending the message, something like `\"/room.\".concat(message.getRoom().getUid().toString())`","metadata":{"transformedAt":"2026-08-18T18:33:20.170Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":110,"estimatedTokens":820}}537{"id":"stack-57578645","source":"stackoverflow","questionId":57578645,"title":"Python Flask Pika Consumer (RabbitMQ)","tags":["python","flask","rabbitmq","pika"],"text":"Title: Python Flask Pika Consumer (RabbitMQ)\nTags: python, flask, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI have two little \n\n Python Flask\n\napps\n\n- Appone --> Producer\n\n- Apptwo --> Consumer\n\nBoth are in different `docker-container` and orchestrated by `docker-compose`\n\nI dont get the Data from the Producer to the Consumer...Even when I start in apptwo the `start.consuming()` the Producer cant send any Data to the RabbitMQ Broker\nMaybe someone can help me. Thank you very much\n\n**docker-compose:**\n\n```\nversion: '3'\nservices:\n\n appone:\n container_name: appone\n restart: always\n build:\n context: ./appone\n dockerfile: Dockerfile\n environment:\n FLASK_APP: ./app.py \n volumes:\n - './appone:/code/:cached'\n ports:\n - \"5001:5001\"\n\n apptwo:\n container_name: apptwo\n restart: always\n build:\n context: ./apptwo\n dockerfile: Dockerfile\n environment:\n FLASK_DEBUG: 1\n FLASK_APP: ./app.py \n volumes:\n - ./apptwo:/code:cached \n ports:\n - \"5002:5002\" \n\n rabbitmq:\n image: \"rabbitmq:3-management\"\n hostname: \"rabbit\"\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n labels:\n NAME: \"rabbitmq\"\n volumes:\n - ./rabbitmq/rabbitmq-isolated.conf:/etc/rabbitmq/rabbitmq.config\n```\n\n**appone (Producer)**\n\n```\nfrom flask import Flask\nfrom flask_restful import Resource, Api\nimport pika\n\napp = Flask(__name__)\napi = Api(app)\n\napp.config['DEBUG'] = True\n\nmessage = \"Hello World, its me appone\"\n\nclass HelloWorld(Resource):\n def get(self):\n connection = pika.BlockingConnection(\n pika.ConnectionParameters(host='rabbitmq'))\n channel = connection.channel()\n\n channel.queue_declare(queue='hello', durable=True)\n\n channel.basic_publish(exchange='', routing_key='hello', body='Hello World!', properties=pika.BasicProperties(delivery_mode=2))\n\n connection.close()\n\n return {'message': message}\n\napi.add_resource(HelloWorld, '/api/appone/post')\n\nif __name__ == '__main__':\n # Development\n app.run(host=\"0.0.0.0\", port=5001)\n```\n\n**apptwo (Consumer)**\n\n```\nfrom flask import Flask\nfrom flask_restful import Resource, Api\nimport pika\nfrom threading import Thread\n\napp = Flask(__name__)\napi = Api(app)\n\napp.config['DEBUG'] = True\n\ndata = []\n\nconnection = pika.BlockingConnection(\n pika.ConnectionParameters(host='rabbitmq'))\n\nchannel = connection.channel()\n\nchannel.queue_declare(queue='hello', durable=True)\n\ndef callback(ch, method, properties, body):\n data.append(body)\n ch.basic_ack(delivery_tag = method.delivery_tag)\n\nchannel.basic_consume(queue='hello', on_message_callback=callback)\n\nthread = Thread(channel.start_consuming())\nthread.start()\n\nclass HelloWorld(Resource):\n def get(self):\n return {'message': data}\n\napi.add_resource(HelloWorld, '/api/apptwo/get')\n\nif __name__ == '__main__':\n app.run(debug=True, host=\"0.0.0.0\", port=5002)\n```\n\n**Goal**\nIn this easy example I just want to receice the data in apptwo and store it in the data list...\n\nThanks again!!\n\n========================================\n\nCode:\n```text\nversion: '3'\nservices:\n\n appone:\n container_name: appone\n restart: always\n build:\n context: ./appone\n dockerfile: Dockerfile\n environment:\n FLASK_APP: ./app.py \n volumes:\n - './appone:/code/:cached'\n ports:\n - \"5001:5001\"\n\n apptwo:\n container_name: apptwo\n restart: always\n build:\n context: ./apptwo\n dockerfile: Dockerfile\n environment:\n FLASK_DEBUG: 1\n FLASK_APP: ./app.py \n volumes:\n - ./apptwo:/code:cached \n ports:\n - \"5002:5002\" \n\n rabbitmq:\n image: \"rabbitmq:3-management\"\n hostname: \"rabbit\"\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n labels:\n NAME: \"rabbitmq\"\n volumes:\n - ./rabbitmq/rabbitmq-isolated.conf:/etc/rabbitmq/rabbitmq.config\n```\n\n```text\nfrom flask import Flask\nfrom flask_restful import Resource, Api\nimport pika\n\napp = Flask(__name__)\napi = Api(app)\n\napp.config['DEBUG'] = True\n\nmessage = \"Hello World, its me appone\"\n\n\nclass HelloWorld(Resource):\n def get(self):\n connection = pika.BlockingConnection(\n pika.ConnectionParameters(host='rabbitmq'))\n channel = connection.channel()\n\n channel.queue_declare(queue='hello', durable=True)\n\n channel.basic_publish(exchange='', routing_key='hello', body='Hello World!', properties=pika.BasicProperties(delivery_mode=2))\n\n connection.close()\n\n return {'message': message}\n\n\napi.add_resource(HelloWorld, '/api/appone/post')\n\nif __name__ == '__main__':\n # Development\n app.run(host=\"0.0.0.0\", port=5001)\n```\n\n```text\nfrom flask import Flask\nfrom flask_restful import Resource, Api\nimport pika\nfrom threading import Thread\n\napp = Flask(__name__)\napi = Api(app)\n\napp.config['DEBUG'] = True\n\ndata = []\n\nconnection = pika.BlockingConnection(\n pika.ConnectionParameters(host='rabbitmq'))\n\nchannel = connection.channel()\n\nchannel.queue_declare(queue='hello', durable=True)\n\ndef callback(ch, method, properties, body):\n data.append(body)\n ch.basic_ack(delivery_tag = method.delivery_tag)\n\nchannel.basic_consume(queue='hello', on_message_callback=callback)\n\nthread = Thread(channel.start_consuming())\nthread.start()\n\nclass HelloWorld(Resource):\n def get(self):\n return {'message': data}\n\napi.add_resource(HelloWorld, '/api/apptwo/get')\n\nif __name__ == '__main__':\n app.run(debug=True, host=\"0.0.0.0\", port=5002)\n```\n\n```text\ndocker-container\n```\n\n```text\ndocker-compose\n```\n\n```text\nstart.consuming()\n```\n\n```text\nthread = Thread(channel.start_consuming())\nthread.start()\n```\n\n```text\nthread = Thread(target = channel.start_consuming)\nthread.start()\n```\n\n========================================\n\nComments:\n- Did you provide the hostname, port, virtual host and user credentials while making the connection? Also, did you check if the message is getting published in the queue using the management plugin?\n- hi @bumblebee, the connection is up. I can use the container_name to \"talk\" to the rabbit mq container. The producer can send data to the broker. But the example for the consumer didnt get the data. Both consumer/producer are from the getting started tutorial for rabbitmq but are implemented in Flask.\n- Why do you want your consumer to be a flask app? Is there any specific need for that?\n- i just need to say how simple this application of threading rabbitmq consumers is, thank you for your post! there is no need for a cron job or scheduled task with this approach; it all runs within the Flask framework without any extra steps\n- hi @beep_check How do you capture the exception thrown by pika? I am not able to capture it when using Threads. Can you post the example code of your wsgi.py where you use RabbitMQ?","metadata":{"transformedAt":"2026-08-18T18:33:20.170Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":296,"estimatedTokens":1653}}538{"id":"stack-13181328","source":"stackoverflow","questionId":13181328,"title":"RabbitMQ: Injecting the connection factory","tags":["c#",".net","dependency-injection","rabbitmq"],"text":"Title: RabbitMQ: Injecting the connection factory\nTags: c#, .net, dependency-injection, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am attempting to set up RabbitMQ for a pair of Windows Services I am writing, to facilitate communication between them in a quick and reliable way. However, I'm running into a problem when trying to set up the main windows service engines, which need to establish connections to the RabbitMQ server to do their thing.\n\nBasically, the `ConnectionFactory` object in RabbitMQ's .NET client is not abstract and implements no interfaces. I can't see an obvious way to inject this class using an IoC container like StructureMap. Even the code examples in the documentation show just blatantly `new`ing it up, like so:\n\n```\nConnectionFactory factory = new ConnectionFactory();\n factory.Uri = \"amqp://user:pass@hostName:port/vhost\";\n IConnection conn = factory.CreateConnection();\n```\n\nThe solution that presents itself to me is to push up the entire factory into the service's main `OnStart` and `OnStop` functions, which are really difficult to test and not of huge interest anyway. However, that leaves me with a single `IConnection` for the service, so if that connection is broken in any way, the service has no way to recover and must simply exit. If the main engine had visibility to the factory, it could simply produce a new connection and continue. But unless I inject that, there is no way to test the main engine without connecting to an existing server!\n\nIs there anything I am missing here? Any other option I'm not considering? How can I go about injecting this factory, and if I can't, how can I limit the damage?\n\nEDIT: Also, as an afterthought, I'm perfectly happy to make a change to RabbitMQ's .NET client to implement an interface on this if someone has a good idea of how receptive the main dev team would be to a change like this. I'd be delighted to contribute, but the last thing I want to do is have my programs working on some custom version of RabbitMQ, thereby eliminating the main benefit of using a third party library in the first place.\n\n========================================\n\nTop Answer:\nThe RabbitMQ C# client is a low-level pureish AMQP implementation, you'd probably want to wrap it in some higher level abstraction and then register that with your IoC container. \n\nEasyNetQ, a higher level abstraction over the basic client, implements a persistent AMQP connection that reconnects after a connection is lost (either through network problems, or a server bounce), and rebuilds all the current subscriptions. You're welcome to take any of that code that you find useful.\n\nIn short, it's a question of wrapping connection management in some kind of PersistentConnection class, and then registering each subscription with some code to rebuild them after a successful reconnect.\n\nI've written a blog post on wiring up EasyNetQ, the Windsor IoC container and TopShelf. I've used this technique successfully for building RabbitMQ based windows services.\n\n========================================\n\nCode:\n```text\nConnectionFactory factory = new ConnectionFactory();\n factory.Uri = \"amqp://user:pass@hostName:port/vhost\";\n IConnection conn = factory.CreateConnection();\n```\n\n```text\nConnectionFactory\n```\n\n```text\nnew\n```\n\n```text\nOnStart\n```\n\n```text\nOnStop\n```\n\n```text\nIConnection\n```\n\n```text\npublic interface IConnectionFactory\n{\n ConnectionFactory Get();\n ConnectionFactory Get(string uri);\n}\n\npublic class ConnectionFactoryCreator : IConnectionFactory\n{\n public ConnectionFactory Get(\n string uri = \"amqp://user:pass@hostName:port/vhost\")\n {\n return new ConnectionFactory\n {\n Uri = uri\n };\n }\n}\n```\n\n```text\npublic class RabbitMQUserClass\n{\n public ConnectionFactory ConnectionFactory {get; private set;}\n public RabbitMQUserClass(IConnectionFactory connectionFactory)\n {\n ConnectionFactory = connectionFactory.Get();\n }\n}\n```\n\n```text\nConnectionFactory\n```\n\n========================================\n\nComments:\n- I want it on record that I dislike this solution intensely, but you are absolutely correct that it's the only recourse I have with the situation as it is. I appreciate your time and thanks for your help.\n- I will be eagerly investigating this. If it's as good as I hope I will be changing the accepted answer over here, with apologies to M Afifi, of course.\n- When attempting to install via the NuGet package, EasyNetQ is insisting I am already referencing a newer version of RabbitMQ.Client even though I axed the old reference completely. Any idea why?\n- \"EasyNetQ is insisting I am already referencing a newer version.\" Can you be a bit more specific? Is it a runtime assembly binding problem, or is NuGet complaining?\n- Sorry - NuGet is complaining. The specific output I am seeing is: `Successfully installed 'RabbitMQ.Client 2.8.6'. Successfully installed 'Newtonsoft.Json 4.5.10'. Successfully installed 'EasyNetQ 0.8.1.37'. Install failed. Rolling back... Already referencing a newer version of 'RabbitMQ.Client'.`\n- It's worth noting (afterthought that just hit me) that there are a few comparable assemblies that NuGet is installing without complaint. It installed Burrow just fine, for example. I have Burrow in my project as a stop-gap, but it looks like EasyNetQ has more stuff that I'd like to use.\n- I would try removing all the NuGet stuff, the packages.config file from each of your projects and the Packages folder from your solution root. Then fire up NuGet and add everything again.\n- Bingo, that sorted it out. Time to start tinkering. Thanks!","metadata":{"transformedAt":"2026-08-18T18:33:20.170Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":107,"estimatedTokens":1404}}539{"id":"stack-40813706","source":"stackoverflow","questionId":40813706,"title":"RabbitMQ - Topic Exchange - Same topics two or more consumers","tags":["rabbitmq"],"text":"Title: RabbitMQ - Topic Exchange - Same topics two or more consumers\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm nmew to AMQP and trying to work out a notification architecture for a RabbitMQ system.\n\nI want a Topic exchange (NotificationsExchange, let's say), specifically because I want to flexibility with routing keys and queues that comes with the topic exchange as well as more options for future expansion on the topic. I might be wrong though, because...\n\nI also want to have each notification consumed by two or more consumers. As a baseline, I want each notification published to wind up in a database. Additionally, I want each notification to be eligible for consumption by a client application (e.g., web app to consume and further push through sockets for immediate user notification without db polling).\n\nThis really sounds like a fanout exhange situation, except I didn't want to do that because I'd need a whole lot more queues to handle the various notifications (I think - still new to AMQP and trying to wrap my head around it).\n\nIs it possible to have two consumers get notified (consistently) from the same queue?\n\nFor example:\n\n- Push `Notif.NotifGroup.User.ThisUser` through the NotificationExchange\n\n- Have `dbListener` bind to `Notif.#`\n\n- Have `mvcClientListener` also bind to `Notif.#` (and further determine if the user is online and push downstream via socket)\n\nI'm not sure if I'm on the right track here. I'm reading that \"multiple consumers to the same queue are load balanced in a round robin fashion\", and quite frankly, I don't know what that means.\n\nIs it possible to have a Topic Exchange where two consumers can consistently read the same messages from the same queue (e.g., same routing key), or must I go with a Fanout Exchange for this?\n\nThanks.\n\n========================================\n\nCode:\n```text\nNotif.NotifGroup.User.ThisUser\n```\n\n```text\ndbListener\n```\n\n```text\nNotif.#\n```\n\n```text\nmvcClientListener\n```\n\n```text\nNotif.#\n```\n\n```text\nNotificationEx\n```\n\n```text\nNotif.#\n```\n\n```text\ndbQueue\n```\n\n```text\nNotif.#\n```\n\n```text\nmvcQueue\n```\n\n```text\ndbQueue\n```\n\n```text\nmvcQueue\n```\n\n========================================\n\nComments:\n- Thanks - I hadn't known if I could create two entirely separate queues based on the same \"push criteria\" (for lack of the correct term - I'll have to look at those details a bit more closely). As a side note, I just this morning started digging into RabbitMQ and thus AMQP in general, and this is the fourth post of yours I've seen on the topic at SO (and one or two blog posts also maybe?) I purchased one of the ebooks a few hours ago. Helpful.\n- BTW, if by chance to could throw a quick example as to how to create those separate queues, that'd be great. If not I'll find it eventually, but I don't think I've come across it quite yet and the tuts at RabbitMQ don't seem to cover that scenario. Thanks again\n- glad my work is being helpful! :) for multiple queues, it works the same way as creating a single queue and binding it to an exchange. there are 2 things you need to do, though: 1) make sure you only have 1 RMQ connection per application instance, and 2) use a new Channel for each consumer. 1 connection, many channels within that connection. Connections are expensive and limited. Channels are cheap, and nearly unlimited. All the real work is done on channels, and it's easiest to have 1 channel dedicated to 1 thing. hope that helps!\n- @DerickBailey please help me on this question - stackoverflow.com/questions/59213798/…","metadata":{"transformedAt":"2026-08-18T18:33:20.170Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":12,"totalLines":87,"estimatedTokens":886}}540{"id":"stack-45795996","source":"stackoverflow","questionId":45795996,"title":"RabbitMQ tools: rabbitmqctl vs rabbitmqadmin","tags":["rabbitmq","rabbitmqctl"],"text":"Title: RabbitMQ tools: rabbitmqctl vs rabbitmqadmin\nTags: rabbitmq, rabbitmqctl\nSource: Stack Overflow\n\nQuestion:\nI'm new to RabbitMQ and I decided to start with console tools for better management understanding. Then I'm going to use web console and then Java client.\n\nI faced some operations can be executed both with `rabbitmqctl`:\n\n```\nrabbitmqctl add_vhost test_vhost\n```\n\nand with `rabbitmqadmin`:\n\n```\nrabbitmqadmin declare vhost name=\"test_vhost\"\n```\n\nBut I did not succeed in, for instance, creating new exchange with rabbitmqctl. What's the difference between these two tools?\n\n========================================\n\nCode:\n```text\nrabbitmqctl add_vhost test_vhost\n```\n\n```text\nrabbitmqadmin declare vhost name=\"test_vhost\"\n```\n\n```text\nrabbitmqctl\n```\n\n```text\nrabbitmqadmin\n```\n\n```text\nrabbitmqctl\n```\n\n```text\nrabbitmqadmin\n```\n\n```text\nrabbitmqctl\n```\n\n```text\nrabbitmqadmin\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.170Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":55,"estimatedTokens":224}}541{"id":"stack-29575789","source":"stackoverflow","questionId":29575789,"title":"RabbitMQ queue messages before writing to MongoDb","tags":["mongodb","rabbitmq","message-queue","messaging"],"text":"Title: RabbitMQ queue messages before writing to MongoDb\nTags: mongodb, rabbitmq, message-queue, messaging\nSource: Stack Overflow\n\nQuestion:\nApplication is sending logs from many machines to Amazon Cloud and store them in some database.\n\n```\n> Lets assume: one machine log size: 1kB every 10 seconds, num of machines from\n1000 to 5000\n```\n\nMy first approach was to queue logs in rabbitmq and then rabbitmq consumer would store them in sql database.\n\n- Do I really need rabbitmq when consumer only do some basic storage operation?\n\nSecond approach was to queue logs in rabbitmq but store them in mongodb\n\n- Is this make sense to queue messages before write to mongodb?\n\n========================================\n\nTop Answer:\nAs stated by StuartLC, you need buffering and you need to `decouples the availability of the producing system from the logging service`.\n\nHere is the cons against RabbitMQ:\n\n- RabbitMQ will be another point of failure to manage. If your logs are significant and/or have a high throughput you will have to make a cluster of RabbitMQ.\n\n- You will have to manage local buffering because RabbitMQ can be unavailable or because your producers are under flow control.\n\n- RabbitMQ does buffering but an healthy RabbitMQ is an empty one.\n\nYou do not define what you put under \"log\". As you state `1kB every 10 seconds`, it seems to be metrics. Please correct me if I'm wrong.\n\nRegarding logs handling, I tend to favor local buffering with a stack dedicated to logs handling: syslog, flume, logstash... Backed by a datastore with a high throughput. MongoDB should fit the need, I'm a bit skeptical about a RDBMS. \n\nWhatever you may be able to implement local buffering with local RabbitMQ and federated queues.\n\n========================================\n\nCode:\n```text\n> Lets assume: one machine log size: 1kB every 10 seconds, num of machines from\n1000 to 5000\n```\n\n```text\ndecouples the availability of the producing system from the logging service\n```\n\n```text\n1kB every 10 seconds\n```\n\n========================================\n\nComments:\n- That said, many loggers allow for multiple `sinks` at the producer system. Logging to the file system in addition to, or prior to, sending logs to a centralized database is a good idea, just in case something goes wrong when sending log data across the network - i.e. like the black box in an airline industry, if the file system survives a traumatic hardware failure or such, you still have some data to assist with post mortems.","metadata":{"transformedAt":"2026-08-18T18:33:20.170Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":59,"estimatedTokens":622}}542{"id":"stack-61092733","source":"stackoverflow","questionId":61092733,"title":"Docker - RabbitMQ.Client.Exceptions.BrokerUnreachableException: 'None of the specified endpoints were reachable'","tags":["docker",".net-core","rabbitmq","rabbitmq-exchange"],"text":"Title: Docker - RabbitMQ.Client.Exceptions.BrokerUnreachableException: 'None of the specified endpoints were reachable'\nTags: docker, .net-core, rabbitmq, rabbitmq-exchange\nSource: Stack Overflow\n\nQuestion:\nI have set up RabbitMQ server on my dev machine using this docker image. \n\nI have used below command to setup my container\n\n`docker run -d --name my-rabbit -p 5672:15672 rabbitmq:3-management`\n\nBelow is docker ps command output\n\n`CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES\na40704b7f3a4 rabbitmq:3-management \"docker-entrypoint.s…\" 13 minutes ago Up 12 minutes 4369/tcp, 5671-5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:5672->15672/tcp my-rabbit`\n\nManagement console is accessible at http://localhost:5672 and I can login using default username and password ( guest/guest )\n\nBelow is my .Net Core code\n\n```\npublic RabbitMQMnager()\n {\n var factory = new ConnectionFactory();\n factory.Port = 5672;\n Uri uri = new Uri(\"amqp://guest:guest@localhost:5672/\");\n\n var connection = factory.CreateConnection();\n\n //Below are values of different connection string parameters\n factory.HostName = \"localhost\";\n factory.UserName = \"guest\";\n factory.Password = \"guest\";\n factory.VirtualHost = \"/\";\n factory.Port = 5672;\n\n var channel = connection.CreateModel(); //Upon executing above code, I am getting below exception.\n\n```\nRabbitMQ.Client.Exceptions.BrokerUnreachableException: 'None of the specified endpoints were reachable'\n```\n\nStack Trace\n\n`This exception was originally thrown at this call stack:\n RabbitMQ.Client.Framing.Impl.Connection.StartAndTune()\n RabbitMQ.Client.Framing.Impl.Connection.Open(bool)\n RabbitMQ.Client.Framing.Impl.Connection.Connection(RabbitMQ.Client.IConnectionFactory, bool, \n RabbitMQ.Client.Impl.IFrameHandler, string)\n RabbitMQ.Client.Framing.Impl.AutorecoveringConnection.Init(RabbitMQ.Client.Impl.IFrameHandler)\n RabbitMQ.Client.Framing.Impl.AutorecoveringConnection.Init(RabbitMQ.Client.IEndpointResolver)\n RabbitMQ.Client.ConnectionFactory.CreateConnection(RabbitMQ.Client.IEndpointResolver, string)`\n\nI found similar questions but solution mentioned there is not enough for me. It looks like it has something to do with docker and the network created by docker.\n\nRefused connection to RabbitMQ when using docker link\n\nOther details\n\n- .Net Core 3.1 app\nRabbitMQ.Client -> 5.1.2\n\n**UPDATE 1**\n\nAs per @ThisIsNoZaku answer exposing additional port solved my issue.\n\n```\ndocker run -d --hostname my-rabbit --name my-rabbit -p 15672:15672 -p 5672:5672 rabbitmq:3-management\n```\n\n========================================\n\nCode:\n```text\npublic RabbitMQMnager()\n {\n var factory = new ConnectionFactory();\n factory.Port = 5672;\n Uri uri = new Uri(\"amqp://guest:guest@localhost:5672/\");\n\n var connection = factory.CreateConnection();\n\n //Below are values of different connection string parameters\n factory.HostName = \"localhost\";\n factory.UserName = \"guest\";\n factory.Password = \"guest\";\n factory.VirtualHost = \"/\";\n factory.Port = 5672;\n\n var channel = connection.CreateModel(); //<- Exception here\n }\n```\n\n```text\nRabbitMQ.Client.Exceptions.BrokerUnreachableException: 'None of the specified endpoints were reachable'\n```\n\n```text\ndocker run -d --hostname my-rabbit --name my-rabbit -p 15672:15672 -p 5672:5672 rabbitmq:3-management\n```\n\n```text\ndocker run -d --name my-rabbit -p 5672:15672 rabbitmq:3-management\n```\n\n```text\nCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES\na40704b7f3a4 rabbitmq:3-management \"docker-entrypoint.s…\" 13 minutes ago Up 12 minutes 4369/tcp, 5671-5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:5672->15672/tcp my-rabbit\n```\n\n```text\nThis exception was originally thrown at this call stack:\n RabbitMQ.Client.Framing.Impl.Connection.StartAndTune()\n RabbitMQ.Client.Framing.Impl.Connection.Open(bool)\n RabbitMQ.Client.Framing.Impl.Connection.Connection(RabbitMQ.Client.IConnectionFactory, bool, \n RabbitMQ.Client.Impl.IFrameHandler, string)\n RabbitMQ.Client.Framing.Impl.AutorecoveringConnection.Init(RabbitMQ.Client.Impl.IFrameHandler)\n RabbitMQ.Client.Framing.Impl.AutorecoveringConnection.Init(RabbitMQ.Client.IEndpointResolver)\n RabbitMQ.Client.ConnectionFactory.CreateConnection(RabbitMQ.Client.IEndpointResolver, string)\n```\n\n```text\n15762\n```\n\n```text\n5762\n```\n\n========================================\n\nComments:\n- Thanks @ThisIsNoZaku , I have updated my question with your answer.","metadata":{"transformedAt":"2026-08-18T18:33:20.170Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":133,"estimatedTokens":1164}}543{"id":"stack-57869937","source":"stackoverflow","questionId":57869937,"title":"Horizontal pod Autoscaler scales custom metric too aggressively on GKE","tags":["kubernetes","rabbitmq","google-kubernetes-engine","kubernetes-hpa"],"text":"Title: Horizontal pod Autoscaler scales custom metric too aggressively on GKE\nTags: kubernetes, rabbitmq, google-kubernetes-engine, kubernetes-hpa\nSource: Stack Overflow\n\nQuestion:\nI have the below Horizontal Pod Autoscaller configuration on Google Kubernetes Engine to scale a deployment by a custom metric - `RabbitMQ messages ready count` for a specific queue: `foo-queue`.\n\nIt picks up the metric value correctly.\n\nWhen inserting 2 messages it scales the deployment to the maximum 10 replicas.\nI expect it to scale to 2 replicas since the targetValue is 1 and there are 2 messages ready.\n\nWhy does it scale so aggressively?\n\nHPA configuration:\n\n```\napiVersion: autoscaling/v2beta1\nkind: HorizontalPodAutoscaler\nmetadata:\n name: foo-hpa\n namespace: development\nspec:\n scaleTargetRef:\n apiVersion: apps/v1\n kind: Deployment\n name: foo\n minReplicas: 1\n maxReplicas: 10\n metrics:\n - type: External\n external:\n metricName: \"custom.googleapis.com|rabbitmq_queue_messages_ready\"\n metricSelector:\n matchLabels:\n metric.labels.queue: foo-queue\n targetValue: 1\n```\n\n========================================\n\nTop Answer:\nAccording to https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/\n\nFrom the most basic perspective, the Horizontal Pod Autoscaler controller operates on the ratio between desired metric value and current metric value:\n\n```\ndesiredReplicas = ceil[currentReplicas * ( currentMetricValue / desiredMetricValue )]\n```\n\nFrom the above I understand that as long as the queue has messages the k8 HPA will continue to scale up since `currentReplicas` is part of the `desiredReplicas` calculation.\n\nFor example if:\n\n`currentReplicas` = 1\n\n`currentMetricValue` / `desiredMetricValue` = 2/1\n\nthen:\n\n`desiredReplicas` = 2\n\nIf the metric stay the same in the next hpa cycle `currentReplicas` will become 2 and `desiredReplicas` will be raised to 4\n\n========================================\n\nCode:\n```text\napiVersion: autoscaling/v2beta1\nkind: HorizontalPodAutoscaler\nmetadata:\n name: foo-hpa\n namespace: development\nspec:\n scaleTargetRef:\n apiVersion: apps/v1\n kind: Deployment\n name: foo\n minReplicas: 1\n maxReplicas: 10\n metrics:\n - type: External\n external:\n metricName: \"custom.googleapis.com|rabbitmq_queue_messages_ready\"\n metricSelector:\n matchLabels:\n metric.labels.queue: foo-queue\n targetValue: 1\n```\n\n```text\nRabbitMQ messages ready count\n```\n\n```text\nfoo-queue\n```\n\n```text\napiVersion: autoscaling/v2beta1\nkind: HorizontalPodAutoscaler\nmetadata:\n name: foo-hpa\n namespace: development\nspec:\n scaleTargetRef:\n apiVersion: apps/v1\n kind: Deployment\n name: foo\n minReplicas: 1\n maxReplicas: 10\n metrics:\n - type: External\n external:\n metricName: \"custom.googleapis.com|rabbitmq_queue_messages_ready\"\n metricSelector:\n matchLabels:\n metric.labels.queue: foo-queue\n # Aim for one Pod per message in the queue\n targetAverageValue: 1\n```\n\n```text\ntargetValue\n```\n\n```text\ntargetAverageValue\n```\n\n```text\ntargetValue\n```\n\n```text\ntargetAverageValue\n```\n\n```text\ntargetAverageValue\n```\n\n```text\ntargetAverageValue\n```\n\n```text\napiVersion: autoscaling/v2beta1\nkind: HorizontalPodAutoscaler\nmetadata:\n name: workers-hpa\nspec:\n scaleTargetRef:\n apiVersion: apps/v1beta1\n kind: Deployment\n name: my-workers\n minReplicas: 1\n maxReplicas: 10\n metrics:\n - type: External\n external:\n metricName: \"custom.googleapis.com|rabbitmq_queue_messages_ready\"\n metricSelector:\n matchLabels:\n metric.labels.queue: myqueue\n **targetValue: 20\n```\n\n```text\nRabbitMQ\n```\n\n```text\nk8s\n```\n\n```text\ntargetValue: 20\n```\n\n```text\nrabbitmq_queue_messages_ready\n```\n\n```text\ntargetValue: 1\n```\n\n```text\ndesiredReplicas = ceil[currentReplicas * ( currentMetricValue / desiredMetricValue )]\n```\n\n```text\ncurrentReplicas\n```\n\n```text\ndesiredReplicas\n```\n\n```text\ncurrentReplicas\n```\n\n```text\ncurrentMetricValue\n```\n\n```text\ndesiredMetricValue\n```\n\n```text\ndesiredReplicas\n```\n\n```text\ncurrentReplicas\n```\n\n```text\ndesiredReplicas\n```\n\n```text\nrabbitmq_queue_messages_unacked\n```\n\n```text\nrabbitmq_queue_messages_ready\n```\n\n```text\nrabbitmq_queue_messages_ready\n```\n\n```text\nrabbitmq_queue_messages_unacked\n```\n\n```text\nrabbitmq_queue_messages_ready\n```\n\n```text\nrabbitmq_queue_messages\n```\n\n========================================\n\nComments:\n- Are you sure about `targetValue: 1`? Why this value is so small? I saw samples with recommended value above than 100\n- @Yasen When setting `targetValue: 100` and having 2 messages in the queue the HPA scales to 2 pods, it seems to be very aggressive, I expect it to be 1 replica\n- Would you please read this guide by former Docker developer Jérôme Petazzoni: Kubernetes Deployments: The Ultimate Guide - Semaphore. It explains why in `k8s` there are two replicas and not one as in `docker`\n- The problem is the metric won't change based on the number of.pods. with 1 pos there is 1 message in queue, with 20 pods there is still 1 message in queue. HPA is trying to scale up the number of pods to reduce the current metric.\n- This is exactly it. The HPA is constantly trying to scale up to bring your metric down to the target value and it can't because there is no ratio between # of pods vs # of messages in queue. This is a common pitfall of custom metrics for HPA\n- Interesting point, it raises the question what should be the auto scale strategy for pods that run for 30 minutes. I guess it really depends on the business need.","metadata":{"transformedAt":"2026-08-18T18:33:20.170Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":31,"totalLines":257,"estimatedTokens":1384}}544{"id":"stack-35996065","source":"stackoverflow","questionId":35996065,"title":"What is the correct way to confirm a publish in celery?","tags":["python","django","rabbitmq","celery"],"text":"Title: What is the correct way to confirm a publish in celery?\nTags: python, django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI'm looking at tuning my celery/rabbitmq installation, and I found this article:\n\nhttp://www.lshift.net/blog/2015/04/30/making-celery-play-nice-with-rabbitmq-and-bigwig/\n\nIt mentions doing the setting `BROKER_TRANSPORT_OPTIONS = {'confirm_publish': True}` if you want to guarantee message delivery (which I do). I'm having trouble finding any documentation on this setting for either rabbitmq or celery. \n\nWhat is the correct way to confirm a publish in celery with rabbitmq? Where is the documentation for said feature?\n\n========================================\n\nTop Answer:\n`confirm_publish` option is used by `py-amqp` library https://github.com/celery/py-amqp\nIt forces publish to block connection until confirmation is received from RabbitMQ. \nRabbitMQ confirmations are described here: https://www.rabbitmq.com/confirms.html\n\n========================================\n\nCode:\n```text\nBROKER_TRANSPORT_OPTIONS = {'confirm_publish': True}\n```\n\n```text\npy-amqp\n```\n\n```text\npy-amqp\n```\n\n```text\nconfirm_publish\n```\n\n```text\nconfirm_publish\n```\n\n```text\npy-amqp\n```\n\n========================================\n\nComments:\n- As of now (August 2023), it seems the confirm_publish default is False for Celery, which means one has to set it to True manually: github.com/celery/celery/issues/5410","metadata":{"transformedAt":"2026-08-18T18:33:20.170Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":51,"estimatedTokens":356}}545{"id":"stack-56740758","source":"stackoverflow","questionId":56740758,"title":"Enforcing immutability of Kubernetes custom resource spec fields","tags":["kubernetes","rabbitmq","kubernetes-operator"],"text":"Title: Enforcing immutability of Kubernetes custom resource spec fields\nTags: kubernetes, rabbitmq, kubernetes-operator\nSource: Stack Overflow\n\nQuestion:\nI'm using the Kubernetes golang operator sdk to implement an operator that manages RabbitMQ queues. I'm wondering if there's a way for k8s to enforce immutability of particular spec fields on my custom resource. I have the following golang struct which represents a rabbitMQ queue and some parameters to have it bind to a rabbitMQ exchange:\n\n```\ntype RmqQueueSpec struct {\n VHost string `json:\"vhost,required\"`\n Exchange string `json:\"exchange,required\"`\n RoutingKey string `json:\"routingKey\"`\n SecretConfig map[string]string `json:\"secretConfig\"`\n}\n```\n\nThe reason why I want immutability, specifically for the `VHost` field, is because it's a parameter that's used to namespace a queue in rabbitMQ. If it were changed for an existing deployed queue, the k8s reconciler will fail to query rabbitMQ for the intended queue since it will be querying with a different vhost (effectively a different namespace), which could cause the creation of a new queue or an update of the wrong queue.\n\nThere are a few alternatives that I'm considering such as using the required ObjectMeta.Name field to contain both the concatenated vhost and the queuename to ensure that they are immutable for a deployed queue. Or somehow caching older specs within the operator (haven't figured out exactly how to do this yet) and doing a comparison of the old and current spec in the reconciler returning an error if `VHost` changes. However neither of these approaches seem ideal. Ideally if the operator framework could enforce immutability on the `VHost` field, that would be a simple approach to handling this.\n\n========================================\n\nTop Answer:\nThis validation is possible by using the ValidatingAdmissionWebhook with future support coming via CRD's OpenAPI validation.\n\n- https://github.com/operator-framework/operator-sdk/issues/1587\n\n- https://github.com/kubernetes/kubernetes/issues/65973\n\n========================================\n\nCode:\n```golang\ntype RmqQueueSpec struct {\n VHost string `json:\"vhost,required\"`\n Exchange string `json:\"exchange,required\"`\n RoutingKey string `json:\"routingKey\"`\n SecretConfig map[string]string `json:\"secretConfig\"`\n}\n```\n\n```text\nVHost\n```\n\n```text\nVHost\n```\n\n```text\nVHost\n```\n\n```golang\ntype RmqQueueSpec struct {\n // +kubebuilder:validation:XValidation:rule=\"self == oldSelf\",message=\"VHost is immutable\"\n VHost string `json:\"vhost,required\"`\n Exchange string `json:\"exchange,required\"`\n RoutingKey string `json:\"routingKey\"`\n SecretConfig map[string]string `json:\"secretConfig\"`\n}\n```\n\n========================================\n\nComments:\n- Unrelated, but feel free to swipe some code from ours github.com/Ridecell/ridecell-operator/tree/master/pkg/… :)\n- thank you, it's always helpful to have some example code!\n- This is possible with CRDs, but you need to create and register a ValidatingAdmissionWebhook to do it, it can't be enforced just through the spec.\n- Yeah, the feature went GA in 1.17 I think. Or somewhere around there.\n- This is no longer true, see my answer.\n- Are there any concrete tutorials for doing this?","metadata":{"transformedAt":"2026-08-18T18:33:20.170Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":72,"estimatedTokens":814}}546{"id":"stack-19725213","source":"stackoverflow","questionId":19725213,"title":"Ping MySQL to keep connection alive in Django","tags":["python","mysql","django","rabbitmq"],"text":"Title: Ping MySQL to keep connection alive in Django\nTags: python, mysql, django, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have a bunch of workers waiting for tasks (using Django as ORM). My problem is that if there's no task for a given amount of time (whatever MySQL wait_timeout variable is set to) the MySQL connection times out and hence the worker dies.\n\nMy first approach to solve this problem was simply to increase the wait_timeout to a higher integer, but I thought a better solution might be to ping MySQL like every 30mins or so if there has been no task to keep the connection alive.\n\nSo my question is; how can I using the Django ORM simply ping MySQL to keep the connection alive? What's the best practice here, just do a simple stupid query ?\n\n========================================\n\nTop Answer:\nI've met the same problem with you , and solve it by following code:\n\n```\nfrom django.db import connection\nconnection.close()\n```\n\nAnd here is the discussion of this problem from Django.\n\nI'll paste that explanation here:\n\n RECOMMENDED SOLUTION: close the connection with `from django.db import connection; connection.close()` when you know that your program is going to be idle for a long time.\n\nSo I think you don't have to ping MySQL to keep the connection alive, but you should close the connection when worker thread will be idle for a long time (like waiting tasks), because everytime you do the query, django will establish a connection for you, but it won't close the connection when worker thread waiting or doing something without db query.\n\n========================================\n\nCode:\n```text\nwhile true:\n sleep(X)\n if some_task:\n connect_to_DB()\n do_something()\n```\n\n```text\nfrom django.db import connection\n\nconnection.connection.ping()\n```\n\n```text\nfrom django.db import connection # works with default connection only, use 'connections'\n\nif connection.is_usable():\n print(\"ok\")\nelse:\n print(\"error\")\n```\n\n```py\nfrom django.db import connection\nconnection.close()\n```\n\n```text\nfrom django.db import connection; connection.close()\n```\n\n========================================\n\nComments:\n- Why exactly u would like to keep that connection? U should rather just improve workers to connect whenever they will have something to do.\n- dev.mysql.com/doc/refman/5.6/en/…\n- @ProblemFactory Good point.. do you have any pseudo code to do that with Django ?\n- Check my answer, if u show us ur current worker code I would improve my answer.\n- This is not related to Django, but to MySQL and Python independently\n- The problem is that I can't predict when the tasks arrive, at some hour there could be none, in the next there could be 1,000,000 tasks.. so hence I would not like to reconnect for every task\n- Of course not, u should define `task` as a whole job to do, not one query.\n- Even though one task is defined as one whole job to do, the job itself in my use case is very small, and there are tons of them.. It would be stupid of me to reconnect for every task even with this definition\n- I had `connection is None` condition (at `is_usable()` MySQL internals) so `is_usable` raised an exception, so need to wrap in a `try:`","metadata":{"transformedAt":"2026-08-18T18:33:20.170Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":76,"estimatedTokens":796}}547{"id":"stack-13483809","source":"stackoverflow","questionId":13483809,"title":"Middleware to build data-gathering and monitoring for a distributed system","tags":["monitoring","rabbitmq","zeromq","data-distribution-service","data-collection"],"text":"Title: Middleware to build data-gathering and monitoring for a distributed system\nTags: monitoring, rabbitmq, zeromq, data-distribution-service, data-collection\nSource: Stack Overflow\n\nQuestion:\nI am currently looking for a good middleware to build a solution to for a monitoring and maintenance system. We are tasked with the challenge to monitor, gather data from and maintain a distributed system consisting of up to 10,000 individual nodes.\n\nThe system is clustered into groups of 5-20 nodes. Each group produces data (as a team) by processing incoming sensor data. Each group has a dedicated node (blue boxes) acting as a facade/proxy for the group, exposing data and state from the group to the outside world. These clusters are geographically separated and may connect to the outside world over different networks (one may run over fiber, another over 3G/Satellite). It is likely we will experience both shorter (seconds/minutes) and longer (hours) outages. The data is persisted by each cluster locally.\n\nThis data needs to be collected (continuously and reliably) by external & centralized server(s) (green boxes) for further processing, analysis and viewing by various clients (orange boxes). Also, we need to monitor the state of all nodes through each groups proxy node. It is not required to monitor each node directly, even though it would be good if the middleware could support that (handle heartbeat/state messages from ~10,000 nodes). In case of proxy failure, other methods are available to pinpoint individual nodes.\n\nFurthermore, we need to be able to interact with each node to tweak settings etc. but that seems to be more easily solved since that is mostly manually handled per-node when needed. Some batch tweaking may be needed, but all-in-all it looks like a standard RPC situation (Web Service or alike). Of course, if the middleware can handle this too, via some Request/Response mechanism that would be a plus.\n\n**Requirements:**\n\n- 1000+ nodes publishing/offering continuous data\n\n- Data needs to be reliably (in some way) and continuously gathered to one or more servers. This will likely be built on top of the middleware using some kind of explicit request/response to ask for lost data. If this could be handled automatically by the middleware this is of course a plus.\n\n- More than one server/subscriber needs to be able to be connected to the same data producer/publisher and receive the same data\n\n- Data rate is max in the range of 10-20 per second per group\n\n- Messages sizes range from maybe ~100 bytes to 4-5 kbytes\n\n- Nodes range from embedded constrained systems to normal COTS Linux/Windows boxes\n\n- Nodes generally use C/C++, servers and clients generally C++/C#\n\n- Nodes should (preferable) not need to install additional SW or servers, i.e. one dedicated broker or extra service per node is expensive\n\n- Security will be message-based, i.e. no transport security needed\n\nWe are looking for a solution that can handle the communication between primarily proxy nodes (blue) and servers (green) for the data publishing/polling/downloading and from clients (orange) to individual nodes (RPC style) for tweaking settings.\n\nThere seems to be a lot of discussions and recommendations for the reversed situation; distributing data from server(s) to many clients, but it has been harder to find information related to the described situation. The general solution seems to be to use SNMP, Nagios, Ganglia etc. to monitor and modify large number of nodes, but the tricky part for us is the data gathering.\n\nWe have briefly looked at solutions like DDS, ZeroMQ, RabbitMQ (broker needed on all nodes?), SNMP, various monitoring tools, Web Services (JSON-RPC, REST/Protocol Buffers) etc.\n\n**So**, do you have any recommendations for an easy-to-use, robust, stable, light, cross-platform, cross-language middleware (or other) solution that would fit the bill? As simple as possible but not simpler.\n\n========================================\n\nTop Answer:\nDisclosure: I am a long-time DDS specialist/enthusiast and I work for one of the DDS vendors.\n\nGood DDS implementations will provide you with what you are looking for. Collection of data and monitoring of nodes is a traditional use-case for DDS and should be its sweet spot. Interacting with nodes and tweaking them is possible as well, for example by using so-called content filters to send data to a particular node. This assumes that you have a means to uniquely identify each node in the system, for example by means of a string or integer ID.\n\nBecause of the hierarchical nature of the system and its sheer (potential) size, you will probably have to introduce some routing mechanisms to forward data between clusters. Some DDS implementations can provide generic services for that. Bridging to other technologies, like DBMS or web-interfaces, is often supported as well.\n\nEspecially if you have multicast at your disposal, discovery of all participants in the system can be done automatically and will require minimal configuration. This is not required though.\n\nTo me, it looks like your system is complicated enough to require customization. I do not believe that any solution will \"fit the bill easily\", especially if your system needs to be fault-tolerant and robust. Most of all, you need to be aware of your requirements. A few words about DDS in the context of the ones you have mentioned:\n\n1000+ nodes publishing/offering continuous data\n\nThis is a big number, but should be possible, especially since you have the option to take advantage of the data-partitioning features supported by DDS.\n\nData needs to be reliably (in some way) and continuously gathered to\none or more servers. This will likely be built on top of the\nmiddleware using some kind of explicit request/response to ask for\nlost data. If this could be handled automatically by the middleware\nthis is of course a plus.\n\nDDS supports a rich set of so-called Quality of Service (QoS) settings specifying how the infrastructure should treat that data it is distributing. These are name-value pairs set by the developer. Reliability and data-availability area among the supported QoS-es. This should take care of your requirement automatically.\n\nMore than one server/subscriber needs to be able to be connected to\nthe same data producer/publisher and receive the same data\n\nOne-to-many or many-to-many distribution is a common use-case.\n\nData rate is max in the range of 10-20 per second per group\n\nAdding up to a total maximum of 20,000 messages per second is doable, especially if data-flows are partitioned.\n\nMessages sizes range from maybe ~100 bytes to 4-5 kbytes\n\nAs long as messages do not get excessively large, the number of messages is typically more limiting than the total amount of kbytes transported over the wire -- unless large messages are of very complicated structure.\n\nNodes range from embedded constrained systems to normal COTS\nLinux/Windows boxes\n\nSome DDS implementations support a large range of OS/platform combinations, which can be mixed in a system.\n\nNodes generally use C/C++, servers and clients generally C++/C#\n\nThese are typically supported and can be mixed in a system.\n\nNodes should (preferable) not need to install additional SW or\nservers, i.e. one dedicated broker or extra service per node is\nexpensive\n\nSuch options are available, but the need for extra services depends on the DDS implementation and the features you want to use.\n\nSecurity will be message-based, i.e. no transport security needed\n\nThat certainly makes life easier for you -- but not so much for those who have to implement that protection at the message level. DDS Security is one of the newer standards in the DDS ecosystem that provides a comprehensive security model transparent to the application.\n\n========================================\n\nComments:\n- Maintaining reliable communication with 1000+ publishers is not an easy task for a single Monitor Server. Are you allowed to do any load balancing? Also, assuming an average message size of 2 kbytes and 15 messages per second per blue box, the network should be able to deal with an aggregate of 2x15x1,000+=30,000+ kbytes per second = 240+mbit; another reason to think about partitioning your data flows. And do you have any multicast at your disposal on the network?\n- Yes, a possible solution is to partition publishers into different groups, handled by multiple servers/subscribers. In reality, the sheer task of monitoring 1000 nodes (plus sub-nodes) is of course also tricky to solve in a good and manageable way. However, we want to keep the basic solution as simple, performant and robust as possible. Although we need to plan for the numbers provided, it is not likely we will experience such large setups from start (depends on our customers). Plan for the worst - hope for the best. We do not yet know if we have multicast available for all networks.\n- I added some additional info to the question. Since our clusters will be spread out geographically over large areas we will need to support all kinds of networks, both good and bad. We will likely experience bad networks (2.5G/3G/Satellite), cables being severed (physically broken), power outages to infrastructure etc. All data we need to get will be persisted by the publishers (in db/file) for several reasons so we are not primarily looking for a solution to persist messages automatically but it should be easy to implement a method to be able to ask for old/missing data.\n- Take a look at the FileMQ project, which is a large-scale file pubsub system built over 0MQ. This may not be a complete answer but it gives you full persistence, a very simple API (the filesystem), and will recover from failures. You haven't specified your requirements in terms of throughput but I'm assuming your networks will be much slower than your file systems. See zguide.zeromq.org/page:all#Large-scale-File-Publishing\n- Thanks, it is really good to see such good documentation, both API-wise and general into/best practice documentation (The Guide). Our networks will most likely be much slower than our file systems, yes. We will sometimes experience very slow networks and will likely have to be able to provide different API:s (thin/rich) to be able to handle all cases. Btw, we have successfully hooked up ZeroMQ into our test rig using clrzmq. So far it works as advertised, looks really promising!","metadata":{"transformedAt":"2026-08-18T18:33:20.170Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":106,"estimatedTokens":2597}}548{"id":"stack-27735999","source":"stackoverflow","questionId":27735999,"title":"Celery pickle type content disallowed error","tags":["python","django","rabbitmq","celery"],"text":"Title: Celery pickle type content disallowed error\nTags: python, django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nEven though I have following lines in settings.py:\n\n```\nCELERY_ACCEPT_CONTENT = ['application/json']\nCELERY_TASKS_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nfrom kombu import serialization\nserialization.registry._decoders.pop(\"application/x-python-serialize\")\n```\n\nI am still getting the pickle content disallowed traceback. Strange this is I already have celery working fine with exactly same settings in another place. If anyone could suggest a solution it would be really helpful. Django version is 1.7.1 and celery was downloaded today so should be latest. Using rabbitmq as broker. Following is the complete traceback of the error. \n\n```\n[2015-01-01 23:45:20,652: CRITICAL/MainProcess] Can't decode message body: ContentDisallowed('Refusing to deserialize untrusted content of type pickle (application/x-python-serialize)',) [type:u'application/x-python-serialize' encoding:u'binary' headers:{}]\nbody: '\\x80\\x02}q\\x01(U\\x07expiresq\\x02NU\\x03utcq\\x03\\x88U\\x04argsq\\x04X\\x04\\x00\\x00\\x00dsgfq\\x05\\x85q\\x06U\\x05chordq\\x07NU\\tcallbacksq\\x08NU\\x08errbacksq\\tNU\\x07tasksetq\\nNU\\x02idq\\x0bU$76263889-0ef2-4193-8286-1a38630df08aq\\x0cU\\x07retriesq\\rK\\x00U\\x04taskq\\x0eU\"pricematch.tasks.amazon_pricematchq\\x0fU\\ttimelimitq\\x10NN\\x86U\\x03etaq\\x11NU\\x06kwargsq\\x12}q\\x13u.' (241b)\nTraceback (most recent call last):\n File \"/usr/local/lib/python2.7/dist-packages/kombu/messaging.py\", line 586, in _receive_callback\n decoded = None if on_m else message.decode()\n File \"/usr/local/lib/python2.7/dist-packages/kombu/message.py\", line 142, in decode\n self.content_encoding, accept=self.accept)\n File \"/usr/local/lib/python2.7/dist-packages/kombu/serialization.py\", line 174, in loads\n raise self._for_untrusted_content(content_type, 'untrusted')\nContentDisallowed: Refusing to deserialize untrusted content of type pickle (application/x-python-serialize)\n```\n\nThis is what I have in celery.py file in project directory parallel to settings.py file:\n\n```\nfrom __future__ import absolute_import\nimport os\nfrom celery import Celery\nfrom django.conf import settings\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'projectname.settings')\napp = Celery('projectname',broker='amqp://',backend='amqp://',)\napp.config_from_object('django.conf:settings')\napp.autodiscover_tasks(lambda: settings.INSTALLED_APPS)\n@app.task(bind=True)\ndef debug_task(self):\n print('Request: {0!r}'.format(self.request))\n```\n\nPlease let me know if additional info is needed\n\n========================================\n\nCode:\n```text\nCELERY_ACCEPT_CONTENT = ['application/json']\nCELERY_TASKS_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nfrom kombu import serialization\nserialization.registry._decoders.pop(\"application/x-python-serialize\")\n```\n\n```text\n[2015-01-01 23:45:20,652: CRITICAL/MainProcess] Can't decode message body: ContentDisallowed('Refusing to deserialize untrusted content of type pickle (application/x-python-serialize)',) [type:u'application/x-python-serialize' encoding:u'binary' headers:{}]\nbody: '\\x80\\x02}q\\x01(U\\x07expiresq\\x02NU\\x03utcq\\x03\\x88U\\x04argsq\\x04X\\x04\\x00\\x00\\x00dsgfq\\x05\\x85q\\x06U\\x05chordq\\x07NU\\tcallbacksq\\x08NU\\x08errbacksq\\tNU\\x07tasksetq\\nNU\\x02idq\\x0bU$76263889-0ef2-4193-8286-1a38630df08aq\\x0cU\\x07retriesq\\rK\\x00U\\x04taskq\\x0eU\"pricematch.tasks.amazon_pricematchq\\x0fU\\ttimelimitq\\x10NN\\x86U\\x03etaq\\x11NU\\x06kwargsq\\x12}q\\x13u.' (241b)\nTraceback (most recent call last):\n File \"/usr/local/lib/python2.7/dist-packages/kombu/messaging.py\", line 586, in _receive_callback\n decoded = None if on_m else message.decode()\n File \"/usr/local/lib/python2.7/dist-packages/kombu/message.py\", line 142, in decode\n self.content_encoding, accept=self.accept)\n File \"/usr/local/lib/python2.7/dist-packages/kombu/serialization.py\", line 174, in loads\n raise self._for_untrusted_content(content_type, 'untrusted')\nContentDisallowed: Refusing to deserialize untrusted content of type pickle (application/x-python-serialize)\n```\n\n```text\nfrom __future__ import absolute_import\nimport os\nfrom celery import Celery\nfrom django.conf import settings\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'projectname.settings')\napp = Celery('projectname',broker='amqp://',backend='amqp://',)\napp.config_from_object('django.conf:settings')\napp.autodiscover_tasks(lambda: settings.INSTALLED_APPS)\n@app.task(bind=True)\ndef debug_task(self):\n print('Request: {0!r}'.format(self.request))\n```\n\n```text\nCELERY_TASK_SERIALIZER\n```\n\n```text\nCELERY_TASKS_SERIALIZER\n```\n\n========================================\n\nComments:\n- I think that is the issue, although i have moved to another implementation, i will still recreate the scenario to check and then accept the answer..","metadata":{"transformedAt":"2026-08-18T18:33:20.170Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":98,"estimatedTokens":1199}}549{"id":"stack-44495577","source":"stackoverflow","questionId":44495577,"title":"RabbitMq Consumer on AWS Lambda","tags":["amazon-web-services","rabbitmq","aws-lambda"],"text":"Title: RabbitMq Consumer on AWS Lambda\nTags: amazon-web-services, rabbitmq, aws-lambda\nSource: Stack Overflow\n\nQuestion:\nFrom what I know, Lambdas are for listening to events and running a piece of code on response to those events.\n\nThe events need to be AWS services or HTTP endpoints.\nIf I have a **RabbitMq** service running on an **EC2 server** (Not using SQS), is it possible to have a **consumer** deployed on Lambda?\n\nIf possible, would this be the right thing to do? \n\nAlso, since lambdas are billed on compute time, I shouldn't be billed for when the queue is idle, right?\n\n========================================\n\nTop Answer:\nYou can now configure Amazon MQ for RabbitMQ as an event source for AWS Lambda.\nCheck the AWS blog.\nhttps://aws.amazon.com/blogs/compute/using-amazon-mq-for-rabbitmq-as-an-event-source-for-lambda/\n\n========================================\n\nComments:\n- I don't know of any way for RabbitMQ to trigger an AWS Lambda invocation. You would have to schedule your Lambda function to run every minute or so and check the queue for messages. Also the last sentence in your question makes no sense.\n- It might not be general thing but i guess combination of SNS & Lambda you can use docs.aws.amazon.com/lambda/latest/dg/with-sns-example.html\n- @MarkB Sorry. Update the last question.\n- how would you handle the possibility of dynamically generated queues as the event source for the lambda? In my setup queues are generated dynamically when a new user joins, so I wouldn't be able to specify the queue name ahead of time. Do you have any idea how to handle that? Thanks!","metadata":{"transformedAt":"2026-08-18T18:33:20.171Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":28,"estimatedTokens":400}}550{"id":"stack-28959681","source":"stackoverflow","questionId":28959681,"title":"RabbitMQ works in localhost, but throws BrokerUnreachableException in LAN - (.NET Windows environment.)","tags":[".net","rabbitmq"],"text":"Title: RabbitMQ works in localhost, but throws BrokerUnreachableException in LAN - (.NET Windows environment.)\nTags: .net, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm trying to work with RabbitMQ in a project.\n\nI've installed RabbitMQ Server `rabbitmq-server-3.4.4.exe` on Win8 (64bit) PC, which has the IP 192.168.100.6.\n\nI have added a user using `rabbitmqctl add_user username password` in RabbitMQ command prompt.\n\nTried to receive the message as follows-\n\n```\nConnectionFactory factory = new ConnectionFactory();\nfactory.UserName = \"skp\";\nfactory.Password = \"111\";\nfactory.VirtualHost = \"/\";\nfactory.Protocol = Protocols.DefaultProtocol;\nfactory.HostName = \"localhost\";\nfactory.Port = AmqpTcpEndpoint.UseDefaultPort;\n try\n {\n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(\"hello\", false, false, false, null);\n\n var consumer = new QueueingBasicConsumer(channel);\n channel.BasicConsume(\"hello\", true, consumer);\n\n Console.WriteLine(\" [*] Waiting for messages.\" +\n \"To exit press CTRL+C\");\n while (true)\n {\n var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();\n\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n Console.WriteLine(\" [x] Received {0}\", message);\n }\n }\n }\n }\n catch (RabbitMQ.Client.Exceptions.BrokerUnreachableException ex)\n {\n Console.WriteLine(ex.Message.ToString());\n Console.WriteLine(ex.Message);\n\n Console.ReadLine();\n }\n```\n\nWhen the hostname=\"localhost\", it works fine. \n\nBut if I try to connect from other PC on LAN and hostname=\"192.168.100.6\", it throws a `BrokerUnreachableException` - \"None of the specified endpoints were reachable\"\n\nWhat I missed here?\n\nUPDATE:\nFirewall on 192.168.100.6 (RabbitMQ Server) is turned off.\n\n========================================\n\nTop Answer:\nCheck the port number I thought the default is 5672 but my rabbitmq instance (using docker) was running on 5673. To find the port number rabbitmq is currently using (in docker) click on the container -> Inspect > Ports.\n\nIf a wrong port no is used - error message \"RabbitMQ.Client.Exceptions.BrokerUnreachableException\" with inner exception \"ExtendedSocketException: No connection could be ...\"\n\nIf the wrong username or password is used - error message \"RabbitMQ.Client.Exceptions.BrokerUnreachableException\" with inner exception \"AuthenticationFailureException: ACCESS_REFUSED\"\n\n========================================\n\nCode:\n```text\nConnectionFactory factory = new ConnectionFactory();\nfactory.UserName = \"skp\";\nfactory.Password = \"111\";\nfactory.VirtualHost = \"/\";\nfactory.Protocol = Protocols.DefaultProtocol;\nfactory.HostName = \"localhost\";\nfactory.Port = AmqpTcpEndpoint.UseDefaultPort;\n try\n {\n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(\"hello\", false, false, false, null);\n\n var consumer = new QueueingBasicConsumer(channel);\n channel.BasicConsume(\"hello\", true, consumer);\n\n Console.WriteLine(\" [*] Waiting for messages.\" +\n \"To exit press CTRL+C\");\n while (true)\n {\n var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();\n\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n Console.WriteLine(\" [x] Received {0}\", message);\n }\n }\n }\n }\n catch (RabbitMQ.Client.Exceptions.BrokerUnreachableException ex)\n {\n Console.WriteLine(ex.Message.ToString());\n Console.WriteLine(ex.Message);\n\n Console.ReadLine();\n }\n```\n\n```text\nrabbitmq-server-3.4.4.exe\n```\n\n```text\nrabbitmqctl add_user username password\n```\n\n```text\nBrokerUnreachableException\n```\n\n```text\nvar factory = new ConnectionFactory() { HostName = \"192.168.100.6\", Password = \"123\", UserName = \"abc\" };\n\n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(\"hello\", false, false, false, null);\n\n var consumer = new QueueingBasicConsumer(channel);\n channel.BasicConsume(\"hello\", true, consumer);\n\n Console.WriteLine(\" [*] Waiting for messages.\" +\n \"To exit press CTRL+C\");\n while (true)\n {\n var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();\n\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n Console.WriteLine(\" [x] Received {0}\", message);\n }\n }\n }\n```\n\n========================================\n\nComments:\n- Have you properly set up the RabbitMQ exchange at that endpoint?\n- I followed the RabbitMQ official documentation. Is there any additional config required? I'm not sure. Please help.\n- are you using the guest user?\n- I tried guest user as well with this line {loopback_users, []} in cofig file.\n- Do you have firewall turned on? Maybe it blocks connections and you have to temporary disable it to check that and then add RabbitMQ to it exceptions.\n- @zac178miami Firewall is turned off.\n- Setting username and password on connection factory instance solved the BrokerUnreachableException issue for me, cheers!","metadata":{"transformedAt":"2026-08-18T18:33:20.171Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":164,"estimatedTokens":1400}}551{"id":"stack-9216481","source":"stackoverflow","questionId":9216481,"title":"Multiple environment on Same RabbitMQ server possible?","tags":["rabbitmq"],"text":"Title: Multiple environment on Same RabbitMQ server possible?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am thinking of setting of single rabbit mq on *inx box. Is it possible to open up two ports in such a way, for one development environement we go one port and for QA environment go to different post still use single box and single instance of Rabbit MQ. Is this possible?\nThanks,","metadata":{"transformedAt":"2026-08-18T18:33:20.171Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":7,"estimatedTokens":98}}552{"id":"stack-45064662","source":"stackoverflow","questionId":45064662,"title":"RabbitMQ broken pipe error or lost messages","tags":["python","rabbitmq","amqp","pika"],"text":"Title: RabbitMQ broken pipe error or lost messages\nTags: python, rabbitmq, amqp, pika\nSource: Stack Overflow\n\nQuestion:\nUsing the pika library's `BlockingConnection` to connect to RabbitMQ, I occasionally get an error when publishing messages:\n\n Fatal Socket Error: error(32, 'Broken pipe')\n\nThis is from a very simple sub-process that takes some information out of an in-memory queue and sends a small JSON message into AMQP. The error only seems to come up when the system hasn't sent any messages for a few minutes.\n\nSetup:\n\n```\nconnection = pika.BlockingConnection(parameters)\nchannel = self.connection.channel()\nchannel.exchange_declare(\n exchange='xyz',\n exchange_type='fanout',\n passive=False,\n durable=True,\n auto_delete=False\n)\n```\n\nEnqueue code catches any connection errors and retries:\n\n```\ndef _enqueue(self, message_id, data):\n try:\n published = self.channel.basic_publish(\n self.amqp_exchange,\n self.amqp_routing_key,\n json.dumps(data),\n pika.BasicProperties(\n content_type=\"application/json\",\n delivery_mode=2,\n message_id=message_id\n )\n )\n\n # Confirm delivery or retry\n if published:\n self.retry_count = 0\n else:\n raise EnqueueException(\"Message publish not confirmed.\")\n\n except (EnqueueException, pika.exceptions.AMQPChannelError, pika.exceptions.AMQPConnectionError,\n pika.exceptions.ChannelClosed, pika.exceptions.ConnectionClosed, pika.exceptions.UnexpectedFrameError,\n pika.exceptions.UnroutableError, socket.timeout) as e:\n self.retry_count += 1\n if self.retry_count This sometimes works on the second attempt. It often hangs for a while or just throws away messages before eventually throwing an exception (possibly related bug report). Since it only happens when the system is quiet for a few minutes I'm guessing it's due to a connection timeout. But AMQP has a heartbeat system and pika reportedly uses it (related bug report).\n\n**Why do I get this error or lose messages, and why won't the connection stay open when not in use?**\n\n========================================\n\nTop Answer:\nThe Broken Pipe error means that server is trying to write something into the socket when connection is closed on client's side.\n\nAs i can see, you have some shared \"self.connection\" that may be closed before/in parallel thread?\n\nAlso you could set up logging level to DEBUG and look at client's log to determine the moment when client closes connection.\n\n========================================\n\nCode:\n```text\nconnection = pika.BlockingConnection(parameters)\nchannel = self.connection.channel()\nchannel.exchange_declare(\n exchange='xyz',\n exchange_type='fanout',\n passive=False,\n durable=True,\n auto_delete=False\n)\n```\n\n```text\ndef _enqueue(self, message_id, data):\n try:\n published = self.channel.basic_publish(\n self.amqp_exchange,\n self.amqp_routing_key,\n json.dumps(data),\n pika.BasicProperties(\n content_type=\"application/json\",\n delivery_mode=2,\n message_id=message_id\n )\n )\n\n # Confirm delivery or retry\n if published:\n self.retry_count = 0\n else:\n raise EnqueueException(\"Message publish not confirmed.\")\n\n except (EnqueueException, pika.exceptions.AMQPChannelError, pika.exceptions.AMQPConnectionError,\n pika.exceptions.ChannelClosed, pika.exceptions.ConnectionClosed, pika.exceptions.UnexpectedFrameError,\n pika.exceptions.UnroutableError, socket.timeout) as e:\n self.retry_count += 1\n if self.retry_count < 5:\n logging.warning(\"Reconnecting and resending\")\n if self.connection.is_open:\n self.connection.close()\n self.connect()\n self._enqueue(message_id, data)\n else:\n raise e\n```\n\n```text\nBlockingConnection\n```\n\n========================================\n\nComments:\n- So that means the connection is closing on my side and not Rabbit's? The `self.connection` is part of an object running in its own process, so the connection isn't shared with any other thread or process.","metadata":{"transformedAt":"2026-08-18T18:33:20.171Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":121,"estimatedTokens":1023}}553{"id":"stack-17486397","source":"stackoverflow","questionId":17486397,"title":"Celery and custom consumers","tags":["python","rabbitmq","celery","amqp"],"text":"Title: Celery and custom consumers\nTags: python, rabbitmq, celery, amqp\nSource: Stack Overflow\n\nQuestion:\nTo my knowledge, Celery acts as both the producer and consumer of messages. This is not what I want to achieve. I want Celery to act as the consumer only, to fire certain tasks based on messages that I send to my AMQP broker of choice. Is this possible?\n\nOr do I need to make soup by adding carrot to my stack?\n\n========================================\n\nTop Answer:\nCelery uses the message broker architectural pattern. A number of implementations / broker transports can be used with Celery including RabbitMQ and a Django database.\n\nFrom Wikipedia:\n\n A message broker is an architectural pattern for message validation, message transformation and message routing. It mediates communication amongst applications, minimizing the mutual awareness that applications should have of each other in order to be able to exchange messages, effectively implementing decoupling.\n\nKeeping results is optional and requires a result backend. You can use different broker and result backends. The Celery Getting Started guide contains further information.\n\nThe answer to your question is **yes** you can fire specific tasks passing arguments without addding Carrot to the mix.\n\n========================================\n\nCode:\n```text\n@task\ndef add(x,x):\n return x+y\n```\n\n```text\nfrom mytasks import add\n\nmetadata1 = 1\nmetadata2 = 2\nmyasyncresult = add.delay(1,2)\nmyasyncresult.get() == 3\n```\n\n```text\ndef get_celery_worker_message(task_name,args,kwargs,routing_key,id,exchange=None,exchange_type=None):\n \n message=(args, kwargs, None)\n\n application_headers={\n 'lang': 'py',\n 'task': task_name,\n 'id':id,\n 'argsrepr': repr(args),\n 'kwargsrepr': repr(kwargs)\n #, 'origin': '@'.join([os.getpid(), socket.gethostname()])\n }\n properties={\n 'correlation_id':id,\n 'content_type': 'application/json',\n 'content_encoding': 'utf-8',\n }\n\n\n body, content_type, content_encoding = prepare(\n message, 'json', 'application/json', 'utf-8',None, application_headers)\n\n prep_message = prepare_message(body,None,content_type,content_encoding,application_headers,properties)\n \n\n inplace_augment_message(prep_message, exchange, exchange_type, routing_key,id)\n\n # dump_json = json.dumps(prep_message)\n\n # print(f\"json encoder:- {dump_json}\")\n\n return prep_message\n```\n\n```text\ndef prepare( body, serializer=None, content_type=None,\n content_encoding=None, compression=None, headers=None):\n\n # No content_type? Then we're serializing the data internally.\n if not content_type:\n serializer = serializer\n (content_type, content_encoding,\n body) = dumps(body, serializer=serializer)\n else:\n # If the programmer doesn't want us to serialize,\n # make sure content_encoding is set.\n if isinstance(body, str):\n if not content_encoding:\n content_encoding = 'utf-8'\n body = body.encode(content_encoding)\n\n # If they passed in a string, we can't know anything\n # about it. So assume it's binary data.\n elif not content_encoding:\n content_encoding = 'binary'\n\n if compression:\n body, headers['compression'] = compress(body, compression)\n\n return body, content_type, content_encoding\n\ndef prepare_message( body, priority=None, content_type=None,\n content_encoding=None, headers=None, properties=None):\n \"\"\"Prepare message data.\"\"\"\n properties = properties or {}\n properties.setdefault('delivery_info', {})\n properties.setdefault('priority', priority )\n\n return {'body': body,\n 'content-encoding': content_encoding,\n 'content-type': content_type,\n 'headers': headers or {},\n 'properties': properties or {}}\n```\n\n```text\ndef inplace_augment_message(message, exchange,exchange_type, routing_key,next_delivery_tag):\n body_encoding_64 = 'base64'\n\n message['body'], body_encoding = encode_body(\n str(json.dumps(message['body'])), body_encoding_64\n )\n props = message['properties']\n props.update(\n body_encoding=body_encoding,\n delivery_tag=next_delivery_tag,\n )\n if exchange and exchange_type:\n props['delivery_info'].update(\n exchange=exchange,\n exchange_type=exchange_type,\n routing_key=routing_key,\n )\n elif exchange:\n props['delivery_info'].update(\n exchange=exchange,\n routing_key=routing_key,\n )\n else:\n props['delivery_info'].update(\n exchange=None,\n routing_key=routing_key,\n )\n\nclass Base64:\n\n \"\"\"Base64 codec.\"\"\"\n\n def encode(self, s):\n return bytes_to_str(base64.b64encode(str_to_bytes(s)))\n\n def decode(self, s):\n return base64.b64decode(str_to_bytes(s))\n\ndef encode_body( body, encoding=None):\n codecs = {'base64': Base64()}\n if encoding:\n return codecs.get(encoding).encode(body), encoding\n return body, encoding\n```\n\n========================================\n\nComments:\n- soup and carrot? could you give an example?\n- Sure, but can I start celery workers by queueing messages from another app? In other words: Can celery subscribe to a broker and start certain tasks based on the messages that is dequeued?\n- if scaling horizontally is your concern, yes that is doable for sure! you just need to push the state to a shared backend as the db (for example for retrieving your models?) or operate only on passed data.\n- Thanks for your edit. The message format is pretty much what I am looking for, given that Celery 'automagically' will take care of them by subscribing to a queue?\n- yes, read about queue names here\n- Ok seems promising. So I can have an external app running on a different environment to queue a message to RabbitMQ that is consumed by Celery which tells Celery to invoke Task X?\n- If the other environment is using Python then it's straightforward and covered in the basic documentation and examples. If you're using another language you could look at the HTTP Callback Tasks (Webhooks).\n- Yes. But the thing is that I dont want to use the Webhooks. As I understand Celery is both the consumer and producer of the messages. I want to use Celery as the consumer only, and have an external producer that Queues due tasks to Celery.\n- I don't know how it easy it would be to drop correctly formatted Celery messages onto the task queue directly (without using the Celery library). You could use AMQP directly with a framework such as Kombu and the equivalent in your producer's language. You'd be responsible for the routing/subscription of messages though.","metadata":{"transformedAt":"2026-08-18T18:33:20.171Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":174,"estimatedTokens":1726}}554{"id":"stack-22044422","source":"stackoverflow","questionId":22044422,"title":"Spring Integration and AMQP: How to gracefully handle deserialization exceptions?","tags":["rabbitmq","amqp","spring-integration","spring-amqp","spring-rabbit"],"text":"Title: Spring Integration and AMQP: How to gracefully handle deserialization exceptions?\nTags: rabbitmq, amqp, spring-integration, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI use **RabbitMQ** and **Spring Integration** to handle **incoming JSON messages**.\n\nThe relevant part of the configuration looks something like this:\n\n```\n\n```\n\nI'm using Jackson Databind as the JSON converter.\n\nSometimes the incoming JSON messages have an **incorrect syntax**. This results in the following (correct) exception:\n\n```\norg.springframework.amqp.rabbit.listener.ListenerExecutionFailedException: Listener threw exception\nCaused by: org.springframework.amqp.support.converter.MessageConversionException: Failed to convert Message content\nCaused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_ARRAY token...\n```\n\nThe exception is then handled by the `errorHandler` which simply is a `MessagePublishingErrorHandler` to `errorChannel`.\n\nSo far so good. The problem is, that the message is still being rejected by the AMQP client, although I am handling it with an error handler. RabbitMQ then redelivers the message over and over. Even configuring a dead letter queue did not help. Any ideas how to handle this scenario correctly?\n\nExceptions further down the processing (after successful deserialization) are handled just fine: AMQP message acknowledged and error message sent to `errorChannel`.\n\nAny ideas?\n\nLibrary versions:\n\n- Spring Integration: 3.0.1\n\n- Spring Framework: 4.0.2\n\n- Jackson Databind: 2.3.1\n\n========================================\n\nCode:\n```text\n<amqp:inbound-channel-adapter channel=\"incomingChannel\" queue-names=\"...\"\n message-converter=\"jsonConverter\" error-handler=\"errorHandler\"\n error-channel=\"errorChannel\" />\n```\n\n```text\norg.springframework.amqp.rabbit.listener.ListenerExecutionFailedException: Listener threw exception\nCaused by: org.springframework.amqp.support.converter.MessageConversionException: Failed to convert Message content\nCaused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_ARRAY token...\n```\n\n```text\nerrorHandler\n```\n\n```text\nMessagePublishingErrorHandler\n```\n\n```text\nerrorChannel\n```\n\n```text\nerrorChannel\n```\n\n```text\ndefaultRequeueRejected=false\n```\n\n```text\n<bean... class=\"...SimpleMessageListenerContainer\"/>\n```\n\n```text\nlistener-container\n```\n\n```text\nErrorHandler\n```\n\n```text\nAmqpRejectAndDontRequeueException\n```\n\n========================================\n\nComments:\n- My mistake, the `requeue-rejected` setting is indeed available when using ``; I forgot that we added it some time ago.","metadata":{"transformedAt":"2026-08-18T18:33:20.171Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":11,"totalLines":94,"estimatedTokens":677}}555{"id":"stack-23073996","source":"stackoverflow","questionId":23073996,"title":"Celery Tasks Not Being Processed","tags":["python","rabbitmq","task","celery","broker"],"text":"Title: Celery Tasks Not Being Processed\nTags: python, rabbitmq, task, celery, broker\nSource: Stack Overflow\n\nQuestion:\nI'm trying to process some tasks using celery, and I'm not having too much luck. I'm running celeryd and celerybeat as daemons. I have a `tasks.py` file that look like this with a simple app and task defined:\n\n```\nfrom celery import Celery\n\napp = Celery('tasks', broker='amqp://user:pass@hostname:5672/vhostname')\n\n@app.task\ndef process_file(f):\n # do some stuff\n # and log results\n```\n\nAnd this file is referenced from another file `process.py` I use to monitor for file changes that looks like:\n\n```\nfrom tasks import process_file\n\nfile_name = '/file/to/process'\nresult = process_file.delay(file_name)\nresult.get()\n```\n\nAnd with that little code, celery is unable to see tasks and process them. I can execute similar code in the python interpreter and celery processes them:\n\n```\npy >>> from tasks import process_file\npy >>> process_file.delay('/file/to/process')\n\n```\n\nWhen I run the tasks from the interpreter however, `beat.log` and `worker1.log` don't show any indication that the tasks were received, but using `logging` I can confirm the task code was executed. There are also no obvious errors in the `.log` files. Any ideas what could be causing this problem? \n\nMy `/etc/default/celerybeat` looks like:\n\n```\nCELERY_BIN=\"/usr/local/bin/celery\"\nCELERYBEAT_CHDIR=\"/opt/dirwithpyfiles\"\nCELERYBEAT_OPTS=\"--schedule=/var/run/celery/celerybeat-schedule\"\n```\n\nAnd `/etc/default/celeryd`:\n\n```\nCELERYD_NODES=\"worker1\"\nCELERY_BIN=\"/usr/local/bin/celery\"\nCELERYD_CHDIR=\"/opt/dirwithpyfiles\"\nCELERYD_OPTS=\"--time-limit=300 --concurrency=8\"\nCELERYD_USER=\"celery\"\nCELERYD_GROUP=\"celery\"\nCELERYD_LOG_FILE=\"/var/log/celery/%N.log\"\nCELERYD_PID_FILE=\"/var/run/celery/%N.pid\"\nCELERY_CREATE_DIRS=1\n```\n\n========================================\n\nCode:\n```text\nfrom celery import Celery\n\napp = Celery('tasks', broker='amqp://user:pass@hostname:5672/vhostname')\n\n@app.task\ndef process_file(f):\n # do some stuff\n # and log results\n```\n\n```text\nfrom tasks import process_file\n\nfile_name = '/file/to/process'\nresult = process_file.delay(file_name)\nresult.get()\n```\n\n```text\npy >>> from tasks import process_file\npy >>> process_file.delay('/file/to/process')\n<AsyncResult: 8af23a4e-3f26-469c-8eee-e646b9d28c7b>\n```\n\n```text\nCELERY_BIN=\"/usr/local/bin/celery\"\nCELERYBEAT_CHDIR=\"/opt/dirwithpyfiles\"\nCELERYBEAT_OPTS=\"--schedule=/var/run/celery/celerybeat-schedule\"\n```\n\n```text\nCELERYD_NODES=\"worker1\"\nCELERY_BIN=\"/usr/local/bin/celery\"\nCELERYD_CHDIR=\"/opt/dirwithpyfiles\"\nCELERYD_OPTS=\"--time-limit=300 --concurrency=8\"\nCELERYD_USER=\"celery\"\nCELERYD_GROUP=\"celery\"\nCELERYD_LOG_FILE=\"/var/log/celery/%N.log\"\nCELERYD_PID_FILE=\"/var/run/celery/%N.pid\"\nCELERY_CREATE_DIRS=1\n```\n\n```text\ntasks.py\n```\n\n```text\nprocess.py\n```\n\n```text\nbeat.log\n```\n\n```text\nworker1.log\n```\n\n```text\nlogging\n```\n\n```text\n.log\n```\n\n```text\n/etc/default/celerybeat\n```\n\n```text\n/etc/default/celeryd\n```\n\n```text\nuser@hostname /opt/dirwithpyfiles $ su celery\ncelery@hostname /opt/dirwithpyfiles $ celery -A tasks worker --loglevel=info\n```\n\n```text\ncelery\n```\n\n```text\n/file/to/process\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.171Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":16,"totalLines":150,"estimatedTokens":793}}556{"id":"stack-40338774","source":"stackoverflow","questionId":40338774,"title":"Concurrency in RabbitMQ","tags":["c#","multithreading","concurrency","rabbitmq"],"text":"Title: Concurrency in RabbitMQ\nTags: c#, multithreading, concurrency, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nAfter a week of coding and searching forums, it seems timely to ask...\n\nI have a C# application which processes messages sent by RabbitMQ using EventingBasicConsumer. I want to process several messages concurrently, so I have instantiated a few channels (8 in this case) on the same connection, each with a single consumer. I have then attached an event-handler to each consumer's Received event. Based on all my readings so far, this setup should allow the event-handler to be triggered concurrently by the consumers, each running in its own thread. But in my case consumers receive messages sequentially only after the a previous consumer acknowledges its message. \n\nHas anyone else experienced this behavior? Is my understanding correct that the processing should technically be concurrent in this case?\n\nBelow is a basic code to better illustrate the issue:\n\n```\nInitialise() {\n ConsumerChannels_ = new IModel[ConsumerCount_];\n Consumers_ = new EventingBasicConsumer[ConsumerCount_];\n for (int i = 0; i What I expect to see is something like: // concurrent processing\n\n Consumer 1: processing started...\n\n \n Consumer 2: processing started...\n\n \n Consumer 3: processing started...\n\n \n ...\n\n \n Consumer 6: processing ended.\n\n \n Consumer 7: processing ended.\n\n \n Consumer 8: processing ended.\n\nBut what I get instead is: // sequential processing\n\n Consumer 1: processing started...\n\n \n Consumer 1: processing ended.\n\n \n Consumer 2: processing started...\n\n \n Consumer 2: processing ended.\n\n \n ...\n\n \n Consumer 8: processing started...\n\n \n Consumer 8: processing ended.\n\nAny ideas on how to proceed would be most appreciated.\n\n========================================\n\nTop Answer:\nYou can actually set the number of parallel processing tasks when creating your `ConnectionFactory`!\n\n```\nConnectionFactory factory = new ConnectionFactory\n{\n ConsumerDispatchConcurrency = 2,\n};\n```\n\nThe default value is 1, which is serial/sequential processing.\n\nI found this out by dissecting the .NET client's source code. Here's the interesting part (`concurrency` is set from `ConsumerDispatchConcurrency`):\n\n```\nFunc loopStart = ProcessChannelAsync;\nif (concurrency == 1)\n{\n _worker = Task.Run(loopStart);\n}\nelse\n{\n var tasks = new Task[concurrency];\n for (int i = 0; i But beware, this can result in race conditions! The property has this remark:\n\nFor concurrency greater than one this removes the guarantee that consumers handle messages in the order they receive them. In addition to that consumers need to be thread/concurrency safe.\n\n========================================\n\nCode:\n```text\nInitialise() {\n ConsumerChannels_ = new IModel[ConsumerCount_];\n Consumers_ = new EventingBasicConsumer[ConsumerCount_];\n for (int i = 0; i < ConsumerCount_; ++i)\n {\n ConsumerChannels_[i] = Connection_.CreateModel();\n Consumers_[i] = new EventingBasicConsumer(ConsumerChannels_[i]);\n Consumers_[i].Received += MessageReceived;\n }\n}\n\nMessageReceived(IBasicConsumer sender, BasicDeliverEventArgs e)\n{\n int id = GetConsumerIndex(sender);\n Log_.Debug(\"Consumer \" + id + \": processing started...\"); \n // do some time consuming processing here\n sender.Model.BasicAck(e.DeliveryTag, false);\n Log_.Debug(\"Consumer \" + id + \": processing ended.\");\n}\n```\n\n```text\nMessageReceived(IBasicConsumer sender, BasicDeliverEventArgs e) {\n int id = GetConsumerIndex(sender);\n Log_.Debug(\"Consumer \" + id + \": processing started...\"); \n // do some time consuming processing here\n // PUT your thread-pool here and process the messages inside the thread\n\n sender.Model.BasicAck(e.DeliveryTag, false);\n Log_.Debug(\"Consumer \" + id + \": processing ended.\"); }\n\n}\n```\n\n```text\nBasicAck\n```\n\n```text\nQoS=1\n```\n\n```cs\nConnectionFactory factory = new ConnectionFactory\n{\n ConsumerDispatchConcurrency = 2,\n};\n```\n\n```cs\nFunc<Task> loopStart = ProcessChannelAsync;\nif (concurrency == 1)\n{\n _worker = Task.Run(loopStart);\n}\nelse\n{\n var tasks = new Task[concurrency];\n for (int i = 0; i < concurrency; i++)\n {\n tasks[i] = Task.Run(loopStart);\n }\n _worker = Task.WhenAll(tasks);\n}\n```\n\n```text\nConnectionFactory\n```\n\n```text\nconcurrency\n```\n\n```text\nConsumerDispatchConcurrency\n```\n\n========================================\n\nComments:\n- Although you have multiple consumers they are all running on the same thread. You need to spin up threads and create a consumer for each. You could also always have one consumer and run your processing application multiple times. Or, shameless self promotion here, use something like Shuttle.Esb to do the heavy lifting :)\n- +1 @Gabriele. @Kia We essentially do this. It simplifies too: Only one consumer as far as RabbitMQ is concerned. Also, no need to spin up threads / manage a `ThreadPool` manually. Placing the message processing as tasks onto a `TaskScheduler` can handle all that. Easy to scale the parallelism up/down within the same consumer by varying the max parallelism of the `TaskScheduler` (several flavours of scheduler offer this). Dedicated thread pools versus sharing the default `ThreadPool` a wider discussion, depending how many such consumers you have and degree of isolation needed.\n- Adding my own thread pool did the trick. It was helpful to know I could call BasicAck from multiple threads of my own. For anyone interested I also introduced a simple blocking throttle mechanism (using Monitor.Wait and Monitor.Pulse) to custom control the concurrency level, with channel.BasicQos(0, 10000, false).\n- Additionally, I've found that the .Net Rabbit client ignores / limits the `ConsumerDispatchConcurrency` if the QoS prefetch size isn't also >> 1\n- this makes sense, since if the prefetch count is 1, you can only have at most 1 un-ack'd message","metadata":{"transformedAt":"2026-08-18T18:33:20.171Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":182,"estimatedTokens":1472}}557{"id":"stack-26624263","source":"stackoverflow","questionId":26624263,"title":"Celery didn't operate well because of errno 104","tags":["django","rabbitmq","celery"],"text":"Title: Celery didn't operate well because of errno 104\nTags: django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI have a problem executing celery on rabbitmq-server. I searched and found a link, but it doesn't help me.\nMy env is ubuntu 14.04, python 2.7.6, celery 3.1.15, Django 1.7.\nReferencing a link, I installed rabbitmq-server locally. I added user, vhost in rabbitmq-server and set permissions.\n\n```\n$ sudo rabbitmqctl add_user tonyg password\n$ sudo rabbitmqctl add_vhost vir_host\n$ sudo rabbitmqctl set_permissions -p vir_host tonyg \".*\" \".*\" \".*\"\n```\n\nMy celery's setting in django follows.\n\n```\nBROKER_URL = 'amqp://tonyg:password@localhost:5672//vir_host'\nCELERY_RESULT_BACKEND = 'amqp://tonyg:password@localhost:5672//vir_host'\nCELERY_ACCEPT_CONTENT = [u'application/x-python-serialize', u'image/jpeg', u'image/bmp', u'image/png', u'image/tiff']\nCELERY_TIMEZONE = 'Asia/Tokyo'\nCELERY_ENABLE_UTC = True\nCELERY_IGNORE_RESULT = False\n```\n\nI don't set anything about rabbitmq-server other than default configs.\n\nI executed celery like this.\n\n```\n$ celery -A MyProj worker -l info\n\n-------------- celery@ip-172-31-3-10 v3.1.15 (Cipater)\n---- **** ----- \n--- * *** * -- Linux-3.13.0-36-generic-x86_64-with-Ubuntu-14.04-trusty\n-- * - **** --- \n- ** ---------- [config]\n- ** ---------- .> app: MyProj:0x7f7453328b10\n- ** ---------- .> transport: amqp://tonyg:**@localhost:5672//vir_host\n- ** ---------- .> results: amqp://tonyg:password@localhost:5672//vir_host\n- *** --- * --- .> concurrency: 1 (prefork)\n-- ******* ---- \n--- ***** ----- [queues]\n -------------- .> celery exchange=celery(direct) key=celery\n\n[tasks]\n . MyProj.tasks. ......\n . MyProj.tasks. ......\n\n[2014-10-29 15:07:50,241: ERROR/MainProcess] consumer: Cannot connect to amqp://tonyg:**@127.0.0.1:5672//vir_host: [Errno 104] Connection reset by peer.\nTrying again in 2.00 seconds...\n\n[2014-10-29 15:07:55,251: ERROR/MainProcess] consumer: Cannot connect to amqp://tonyg:**@127.0.0.1:5672//vir_host: [Errno 104] Connection reset by peer.\nTrying again in 4.00 seconds...\n```\n\nWhen i set celery using default guest identifier,\n\n```\nBROKER_URL = 'amqp://guest:guest@localhost:5672//'\nCELERY_RESULT_BACKEND = 'amqp://guest:guest@localhost:5672//'\n```\n\nit does operate well. I don't know why. Could anyone help me? Thank you.\n\n========================================\n\nTop Answer:\nThanks to @Krzysztof Szularz answer. Turns out your url is incorrect. It has to be \n\n```\nBROKER_URL = 'amqp://tonyg:password@localhost:5672/vir_host'\n```\n\nNow you are connecting via localhost and it works fine. If you want to connect remotely, it wont work. Your account is just a guest account and it doesn't have admin privileges. So that user has to connect via locahost ONLY. If you want that user to access from a virutal host, you need to give him privileges to do so.\n\nRun this command to give user admin privileges.\n\n```\nrabbitmqctl set_user_tags tonyg administrator\n```\n\nYou can read more about this here.\n\n========================================\n\nCode:\n```text\n$ sudo rabbitmqctl add_user tonyg password\n$ sudo rabbitmqctl add_vhost vir_host\n$ sudo rabbitmqctl set_permissions -p vir_host tonyg \".*\" \".*\" \".*\"\n```\n\n```text\nBROKER_URL = 'amqp://tonyg:password@localhost:5672//vir_host'\nCELERY_RESULT_BACKEND = 'amqp://tonyg:password@localhost:5672//vir_host'\nCELERY_ACCEPT_CONTENT = [u'application/x-python-serialize', u'image/jpeg', u'image/bmp', u'image/png', u'image/tiff']\nCELERY_TIMEZONE = 'Asia/Tokyo'\nCELERY_ENABLE_UTC = True\nCELERY_IGNORE_RESULT = False\n```\n\n```text\n$ celery -A MyProj worker -l info\n\n-------------- celery@ip-172-31-3-10 v3.1.15 (Cipater)\n---- **** ----- \n--- * *** * -- Linux-3.13.0-36-generic-x86_64-with-Ubuntu-14.04-trusty\n-- * - **** --- \n- ** ---------- [config]\n- ** ---------- .> app: MyProj:0x7f7453328b10\n- ** ---------- .> transport: amqp://tonyg:**@localhost:5672//vir_host\n- ** ---------- .> results: amqp://tonyg:password@localhost:5672//vir_host\n- *** --- * --- .> concurrency: 1 (prefork)\n-- ******* ---- \n--- ***** ----- [queues]\n -------------- .> celery exchange=celery(direct) key=celery\n\n\n[tasks]\n . MyProj.tasks. ......\n . MyProj.tasks. ......\n\n[2014-10-29 15:07:50,241: ERROR/MainProcess] consumer: Cannot connect to amqp://tonyg:**@127.0.0.1:5672//vir_host: [Errno 104] Connection reset by peer.\nTrying again in 2.00 seconds...\n\n[2014-10-29 15:07:55,251: ERROR/MainProcess] consumer: Cannot connect to amqp://tonyg:**@127.0.0.1:5672//vir_host: [Errno 104] Connection reset by peer.\nTrying again in 4.00 seconds...\n```\n\n```text\nBROKER_URL = 'amqp://guest:guest@localhost:5672//'\nCELERY_RESULT_BACKEND = 'amqp://guest:guest@localhost:5672//'\n```\n\n```text\nListing vhosts ...\n/\nvir_host\n...done.\n```\n\n```text\namqp://tonyg:**@localhost:5672/vir_host\n```\n\n```text\nrabbitmqctl list_vhosts\n```\n\n```text\nBROKER_URL = 'amqp://tonyg:password@localhost:5672/vir_host'\n```\n\n```text\nrabbitmqctl set_user_tags tonyg administrator\n```\n\n========================================\n\nComments:\n- Url is correct. But the user doesn't have admin privileges to connect via virtual host.\n- @Krzysztof Szularz Thank you so much. I thought i have tried amqp://tonyg:**@localhost:5672/vir_host. But, I tried again. It does work!!! I made a silly mistake. But, i wanna know why setting (amqp://tonyg:**@localhost:5672/vir_host) does operate well in a Mac OS X. Anyway, thank you so much.\n- I don't get the question. `amqp://tonyg:**@localhost:5672/vir_host` operates well because it's a valid URL for vhost you've created. The one with two slashes is not a valid one, unless vhost is called `/vir_host` which isn't the case.\n- @Krzysztof Szularz I typed wrong url. I can't modify comment after 5 mins. I set BROKER_URL = 'amqp://tonyg:password@localhost:5672//vir_host' on Mac OS X, but it does work correctly. Do u know why?\n- @KrzysztofSzularz i sincerely apologize. its my mistake @BlueFrog your virual host name is might be `/vir_host` but not `vir_host`\n- @ChillarAnand Thank you, you're right. My virtual host name is '/vir_host' on Mac OS x. It is my mistake. T_T Maybe i might see 'sudo rabbitmqctl add_vhost /vir_host' in a tutorial. I have followed that direction.\n- Note if your hostname changes rabbitmq has to be completely removed using `sudo apt-get purge rabbitmq-server` and then reinstalled.\n- @KrzysztofSzularz forgot that he is connecting via localhost only.","metadata":{"transformedAt":"2026-08-18T18:33:20.171Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":170,"estimatedTokens":1603}}558{"id":"stack-12303784","source":"stackoverflow","questionId":12303784,"title":"Pika worker throws exception when running channel.declare_queue","tags":["python","rabbitmq","amqp","pika"],"text":"Title: Pika worker throws exception when running channel.declare_queue\nTags: python, rabbitmq, amqp, pika\nSource: Stack Overflow\n\nQuestion:\nI'm writing a python client to accept job messages from a RabbitMQ broker and process the jobs, returning the results to another server. My script that sends messages to the RabbitMQ broker starts up fine, but my worker throws the following error when running channel.declare_queue(queue='task_queue')\n\npika.exceptions.AMQPChannelError: (406, \"PRECONDITION_FAILED - parameters for queue 'task_queue' in vhost '/' not equivalent\")\n\nClient:\n\n```\nimport pika \nconnection = pika.BlockingConnection(pika.ConnectionParameters(host=cmdargs.server))\nchannel = connection.channel()\nchannel.queue_declare(queue='task_queue')\nchannel.basic_qos(prefetch_count=1)\nchannel.basic_consume(ProcJobCallback, queue='task_queue')\nchannel.start_consuming()\n```\n\nServer method that interacts with RabbitMQ:\n\n```\ndef addNewJob(self, newJob):\n self.jobList.append(newJob)\n connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))\n channel = connection.channel()\n channel.queue_declare(queue='task_queue')\n\n for tile in newJob.TileStatus:\n message = \"{0},{1},{2}\".format(newJob, tile[0], tile[1])\n channel.basic_publish(exchange='', routing_key='task_queue', body=message, properties=pika.BasicProperties(delivery_mode = 2, ))\n connection.close()\n```\n\nAny help or insight is greatly appreciated.\n\nEDIT: I discovered why I was getting an error with the code listed above. I was specifying delivery_mode=2 when publishing my messages, but when I declared the queue, I forgot to add the Durable=True parameter.\n\n========================================\n\nTop Answer:\nif your queue is durable just remove the declaration \"channel.queue_declare(queue='task_queue')\", that should be enough in your case.\n\n========================================\n\nCode:\n```text\nimport pika \nconnection = pika.BlockingConnection(pika.ConnectionParameters(host=cmdargs.server))\nchannel = connection.channel()\nchannel.queue_declare(queue='task_queue')\nchannel.basic_qos(prefetch_count=1)\nchannel.basic_consume(ProcJobCallback, queue='task_queue')\nchannel.start_consuming()\n```\n\n```text\ndef addNewJob(self, newJob):\n self.jobList.append(newJob)\n connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))\n channel = connection.channel()\n channel.queue_declare(queue='task_queue')\n\n for tile in newJob.TileStatus:\n message = \"{0},{1},{2}\".format(newJob, tile[0], tile[1])\n channel.basic_publish(exchange='', routing_key='task_queue', body=message, properties=pika.BasicProperties(delivery_mode = 2, ))\n connection.close()\n```\n\n```text\nconnection = pika.BlockingConnection(pika.ConnectionParameters(host=cmdargs.server))\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.171Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":76,"estimatedTokens":729}}559{"id":"stack-28631380","source":"stackoverflow","questionId":28631380,"title":"Dead-lettering dead-lettered messages in RabbitMQ","tags":["rabbitmq","dead-letter"],"text":"Title: Dead-lettering dead-lettered messages in RabbitMQ\nTags: rabbitmq, dead-letter\nSource: Stack Overflow\n\nQuestion:\nHere's what we have here:\n\n- Topic Exchange `DLE`, which is intended to be a Dead-Letter Exchange\n\n- Topic Exchange `E`, which is the \"main\" Exchange\n\n- Several Queues (`EQ1`, ..., `EQn`) bound to `E` (and initialized with `x-dead-letter-exchange = DLE`), each with own Routing Key. These queues are the ones being consumed from.\n\n- For each `EQn`, there's a `DLEQn` (initialized with `x-dead-letter-exchange = E` and `x-message-ttl = 5000`), bound to `DLE` with the same routing key as `EQn`. These queues are *not* being consumed from\n\nWhat I want is the following: if a consumer cannot process a message from `EQn`, it Nacks the message with `requeue: false` and it gets to the `DLEQn` - that is, to an appropriate queue on the Dead-Letter Exchange. Now, I want this message to sit on the `DLEQn` for some time and then get routed back to the original queue `EQn` to be processed again. \n\nTry as I might, I could not get the \"redelivery to the original queue\" working. I see that messages sit in the `DLEQn` with all the right headers and Routing Key intact, but after TTL expires they just vanish into thin air.\n\nWhat am I doing wrong here?\n\n========================================\n\nTop Answer:\nRabbitMQ detects message flow cycling (E -> DLE -> E -> DLE ...) and silently drops messages:\n\nFrom DLX manual (Routing Dead-Lettered Messages section):\n\n It is possible to form a cycle of dead-letter queues. For instance, this can happen when a queue dead-letters messages to the default exchange without specifiying a dead-letter routing key. Messages in such cycles (i.e. messages that reach the same queue twice) will be dropped **if the entire cycle is due to message expiry.**\n\n========================================\n\nCode:\n```text\nDLE\n```\n\n```text\nE\n```\n\n```text\nEQ1\n```\n\n```text\nEQn\n```\n\n```text\nE\n```\n\n```text\nx-dead-letter-exchange = DLE\n```\n\n```text\nEQn\n```\n\n```text\nDLEQn\n```\n\n```text\nx-dead-letter-exchange = E\n```\n\n```text\nx-message-ttl = 5000\n```\n\n```text\nDLE\n```\n\n```text\nEQn\n```\n\n```text\nEQn\n```\n\n```text\nrequeue: false\n```\n\n```text\nDLEQn\n```\n\n```text\nDLEQn\n```\n\n```text\nEQn\n```\n\n```text\nDLEQn\n```\n\n========================================\n\nComments:\n- I wonder if \"25107 permit dead-letter cycles\" in RabbitMQ 3.1 ( rabbitmq.com/release-notes/README-3.1.0.txt ) actually allows them.\n- I guess asking for clarification in RabbitMQ user group (groups.google.com/forum/#!forum/rabbitmq-users) will bring some light on this question. I don't think that it 25107 is your case while you are using message expiry, which is the case to drop messages according to doc (i made bold that part)\n- Well, my cycle is decidedly *not* entirely because of expiry. Nacking original message moves it from E to DLE, and only then does TTL comes into play. Nevertheless, thanks for taking time!\n- How does it get resent to the original queue? Is it RabbitMQ that does the resending or is there a separate consumer on the retry queue?\n- A separate consumer picks up the message from \"retry redirect queue\" and looks at the rabbit headers. The header of interest is \"x-death\", inside there it has the exchange and queue that the message came from. We use this to send messages back to many different queues, that way we only need one \"retry redirect queue\". Make sense?\n- @jhilden Could you please tell how do you maintain count of the failed messages. Do you use some inbuilt functionality or you had maintain custom variable of count and you increment everytime it is retried\n- Custom variable, here is the code that checks that count: gist.github.com/jayhilden/2078872a53c7df0fe45d661861ed2d45\n- @jhilden When you get x-death at \"Retry Redirect Queue\" wouldn't it be holding \"Retry Holding Queue\" name and not inbound queue - because that's where it came from?\n- It's been a while, but I'm pretty sure it will have an x-death of *both*, so I take the first one, which is the original queue.\n- @jhilden sorry to comment on such an old answer(great answer by the way) but the 'x-death' key is one that you added to your headers for the message properties correct? I have read the docs here, pika.readthedocs.io/en/0.10.0/modules/… , and headers appears to be none. Does that header have to be called x-death and if so do you recall where in the docs this would be?\n- @jhilden I see my folly now. It shows when you access properties.headers after it has already been dead lettered. of course! As far as sending back to the original queue goes, that would be just another basic_publish I assume.","metadata":{"transformedAt":"2026-08-18T18:33:20.171Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":18,"totalLines":119,"estimatedTokens":1155}}560{"id":"stack-25201931","source":"stackoverflow","questionId":25201931,"title":"Check if the Exchange with a specified name exist in rabbitmq","tags":["spring","rabbitmq","amqp","spring-amqp","spring-rabbit"],"text":"Title: Check if the Exchange with a specified name exist in rabbitmq\nTags: spring, rabbitmq, amqp, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI have a scenario where there is an application which is generating different types of interesting events (not commands). The producer application does not care about by whom and how the events get processed.\n\nI am implementing a consumer who will listen to few of the published events and process them appropriately. The consumer application wants to check if the publisher application exchange exists or not. So, the question is how to check if exchange with specific name exists or not by making use of spring provided rabbit/AMQP libraries?\n\nI guess, this could be handled indirectly by trying to bind a queue to a non-existing exchange resulting in an exception. I am looking for better way to handle this situation.\n\n========================================\n\nCode:\n```text\nfinal String exchange = \"foo\";\nboolean exists rabbitTemplate.execute(new ChannelCallback<DeclareOk>() {\n @Override\n public DeclareOk doInRabbit(Channel channel) throws Exception {\n try {\n return channel.exchangeDeclarePassive(exchange);\n }\n catch (Exception e) {\n if (logger.isDebugEnabled()) {\n logger.debug(\"Exchange '\" + exchange + \"' does not exist\");\n }\n return null;\n }\n }\n }) != null;\n```\n\n```text\nRabbitTemplate\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.171Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":35,"estimatedTokens":378}}561{"id":"stack-19408705","source":"stackoverflow","questionId":19408705,"title":"How to use message headers in RabbitMQ's Erlang client?","tags":["erlang","rabbitmq"],"text":"Title: How to use message headers in RabbitMQ's Erlang client?\nTags: erlang, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm trying to send a message with metadata through the Erlang client, and I can't understand how should I set custom application headers in the message's basic properties record. I've tried all these options with no success:\n\n```\n#'P_basic'{headers = [{>, >}]}\n#'P_basic'{headers = [{\"key\", >}]}\n#'P_basic'{headers = [{key, >}]}\n```\n\nIt seems that headers use some special data structure, an AMQP table - but I couldn't find any documentation or examples on this matter.\n\nWhat is a correct way to send a message with headers?\n\n**Update:** A stack trace (actually, it's not relevant - the cause of that error is the silently closed channel) and the source code.\n\n========================================\n\nCode:\n```text\n#'P_basic'{headers = [{<<\"key\">>, <<\"value\">>}]}\n#'P_basic'{headers = [{\"key\", <<\"value\">>}]}\n#'P_basic'{headers = [{key, <<\"value\">>}]}\n```\n\n```text\n#'P_basic'{headers = [{\"key\", \"value\"}]}\n```\n\n```text\n-type(headers() :: rabbit_framing:amqp_table() | 'undefined').\n```\n\n```text\n-type(amqp_field_type() ::\n 'longstr' | 'signedint' | 'decimal' | 'timestamp' |\n 'table' | 'byte' | 'double' | 'float' | 'long' |\n 'short' | 'bool' | 'binary' | 'void' | 'array').\n-type(amqp_property_type() ::\n 'shortstr' | 'longstr' | 'octet' | 'shortint' | 'longint' |\n 'longlongint' | 'timestamp' | 'bit' | 'table').\n\n-type(amqp_table() :: [{binary(), amqp_field_type(), amqp_value()}]).\n-type(amqp_array() :: [{amqp_field_type(), amqp_value()}]).\n-type(amqp_value() :: binary() | % longstr\n integer() | % signedint\n {non_neg_integer(), non_neg_integer()} | % decimal\n amqp_table() |\n amqp_array() |\n byte() | % byte\n float() | % double\n integer() | % long\n integer() | % short\n boolean() | % bool\n binary() | % binary\n 'undefined' | % void\n non_neg_integer() % timestamp\n ).\n```\n\n```text\nBooleanHeader = {<<\"my-boolean\">>, bool, true}.\nStringHeader = {<<\"my-string\">>, longstr, <<\"value\">>}.\nIntHeader = {<<\"my-int\">>, long, 1000}.\n```\n\n========================================\n\nComments:\n- I've added a stack trace to the question - but it wouldn't help, I believe, because an AMQP channel just closes abruptly after a 'basic.publish' call. A type of a value makes no difference, too - I tried strings and integers.\n- Thank you - it works perfectly! It's weird that this behavior isn't documented well.","metadata":{"transformedAt":"2026-08-18T18:33:20.171Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":74,"estimatedTokens":683}}562{"id":"stack-71740863","source":"stackoverflow","questionId":71740863,"title":"django celery error: Unrecoverable error: AttributeError(\"'EntryPoint' object has no attribute 'module_name'\")","tags":["python","django","rabbitmq","celery"],"text":"Title: django celery error: Unrecoverable error: AttributeError(\"'EntryPoint' object has no attribute 'module_name'\")\nTags: python, django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI am perplexed,from a weird error which i have no idea as i am new to celery, this error occurs on just the setup phase, every thing is simply configured as written in the celery doc https://docs.celeryq.dev/en/stable/django/first-steps-with-django.html\nthe tracback is:\n\n```\n(env) muhammad@huzaifa:~/Desktop/practice/app$ celery -A app worker -l INFO\n[2022-04-04 16:21:40,988: WARNING/MainProcess] No hostname was supplied. Reverting to default 'localhost'\n[2022-04-04 16:21:40,993: CRITICAL/MainProcess] Unrecoverable error: AttributeError(\"'EntryPoint' object has no attribute 'module_name'\")\nTraceback (most recent call last):\n File \"/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/base.py\", line 1250, in backend\n return self._local.backend\nAttributeError: '_thread._local' object has no attribute 'backend'\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/worker/worker.py\", line 203, in start\n self.blueprint.start(self)\n File \"/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/bootsteps.py\", line 112, in start\n self.on_start()\n File \"/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/apps/worker.py\", line 136, in on_start\n self.emit_banner()\n File \"/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/apps/worker.py\", line 170, in emit_banner\n ' \\n', self.startup_info(artlines=not use_image))),\n File \"/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/apps/worker.py\", line 232, in startup_info\n results=self.app.backend.as_uri(),\n File \"/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/base.py\", line 1252, in backend\n self._local.backend = new_backend = self._get_backend()\n File \"/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/base.py\", line 955, in _get_backend\n backend, url = backends.by_url(\n File \"/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/backends.py\", line 69, in by_url\n return by_name(backend, loader), url\n File \"/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/backends.py\", line 47, in by_name\n aliases.update(load_extension_class_names(extension_namespace))\n File \"/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/utils/imports.py\", line 146, in load_extension_class_names\n yield ep.name, ':'.join([ep.module_name, ep.attrs[0]])\nAttributeError: 'EntryPoint' object has no attribute 'module_name'\n```\n\nthe init file is:\n\n```\nfrom __future__ import absolute_import, unicode_literals\n\nfrom .celery import app as celery_app\n\n__all__ = ('celery_app',)\n```\n\ncelery.py:\n\n```\nimport os\n\nfrom celery import Celery\n\n# Set the default Django settings module for the 'celery' program.\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')\n\napp = Celery('app', broker='localhost')\n\n# Using a string here means the worker doesn't have to serialize\n# the configuration object to child processes.\n# - namespace='CELERY' means all celery-related configuration keys\n# should have a `CELERY_` prefix.\napp.config_from_object('django.conf:settings', namespace='CELERY')\n\n# Load task modules from all registered Django apps.\napp.autodiscover_tasks()\n\n@app.task(bind=True)\ndef debug_task(self):\n print(f'Request: {self.request!r}')\n```\n\nFor your information, rabbitmq-server is running on localhost thats why i have set BROKER_URL TO 'localhost'\n\n```\nrabbitmq-server.service - RabbitMQ Messaging Server\n Loaded: loaded (/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: enabled)\n Active: active (running) since Sun 2022-04-03 16:14:04 PKT; 24h ago\n Main PID: 1005 (beam.smp)\n Status: \"Initialized\"\n Tasks: 91 (limit: 9090)\n```\n\nidk why this is happening, i have been look around for like hours and cant find a solution and not even the error on google or anywhere.\nany help would be greatly appreciated\nThanks!\n\n========================================\n\nTop Answer:\nI encountered the same problem today. So, I just Downgraded the celery version to 5.2.3\n\n```\npip install celery==5.2.3\n```\n\nand it worked\n\n========================================\n\nCode:\n```text\n(env) muhammad@huzaifa:~/Desktop/practice/app$ celery -A app worker -l INFO\n[2022-04-04 16:21:40,988: WARNING/MainProcess] No hostname was supplied. Reverting to default 'localhost'\n[2022-04-04 16:21:40,993: CRITICAL/MainProcess] Unrecoverable error: AttributeError(\"'EntryPoint' object has no attribute 'module_name'\")\nTraceback (most recent call last):\n File \"/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/base.py\", line 1250, in backend\n return self._local.backend\nAttributeError: '_thread._local' object has no attribute 'backend'\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/worker/worker.py\", line 203, in start\n self.blueprint.start(self)\n File \"/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/bootsteps.py\", line 112, in start\n self.on_start()\n File \"/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/apps/worker.py\", line 136, in on_start\n self.emit_banner()\n File \"/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/apps/worker.py\", line 170, in emit_banner\n ' \\n', self.startup_info(artlines=not use_image))),\n File \"/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/apps/worker.py\", line 232, in startup_info\n results=self.app.backend.as_uri(),\n File \"/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/base.py\", line 1252, in backend\n self._local.backend = new_backend = self._get_backend()\n File \"/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/base.py\", line 955, in _get_backend\n backend, url = backends.by_url(\n File \"/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/backends.py\", line 69, in by_url\n return by_name(backend, loader), url\n File \"/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/backends.py\", line 47, in by_name\n aliases.update(load_extension_class_names(extension_namespace))\n File \"/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/utils/imports.py\", line 146, in load_extension_class_names\n yield ep.name, ':'.join([ep.module_name, ep.attrs[0]])\nAttributeError: 'EntryPoint' object has no attribute 'module_name'\n```\n\n```text\nfrom __future__ import absolute_import, unicode_literals\n\nfrom .celery import app as celery_app\n\n__all__ = ('celery_app',)\n```\n\n```text\nimport os\n\nfrom celery import Celery\n\n# Set the default Django settings module for the 'celery' program.\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')\n\napp = Celery('app', broker='localhost')\n\n# Using a string here means the worker doesn't have to serialize\n# the configuration object to child processes.\n# - namespace='CELERY' means all celery-related configuration keys\n# should have a `CELERY_` prefix.\napp.config_from_object('django.conf:settings', namespace='CELERY')\n\n# Load task modules from all registered Django apps.\napp.autodiscover_tasks()\n\n\n@app.task(bind=True)\ndef debug_task(self):\n print(f'Request: {self.request!r}')\n```\n\n```text\nrabbitmq-server.service - RabbitMQ Messaging Server\n Loaded: loaded (/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: enabled)\n Active: active (running) since Sun 2022-04-03 16:14:04 PKT; 24h ago\n Main PID: 1005 (beam.smp)\n Status: \"Initialized\"\n Tasks: 91 (limit: 9090)\n```\n\n```text\ncelery==5.2.3\n```\n\n```text\npip install celery==5.2.3\n```\n\n```text\ncelery\n```\n\n```text\nrequirements.txt\n```\n\n```text\npip install celery==5.2.3\n```\n\n```text\nAttributeError: 'EntryPoints' object has no attribute 'get'\n```\n\n```text\nfor ep in importlib_metadata.entry_points().get(namespace, [])\n```\n\n```text\nfor ep in importlib_metadata.entry_points(group ='namespace')\n```\n\n```text\n5.2.3\n```\n\n```text\n5.4.0\n```\n\n========================================\n\nComments:\n- This bug has since been fixed in `celery==5.2.6`. Just make sure you aren't using 5.2.5 and you'll be good.","metadata":{"transformedAt":"2026-08-18T18:33:20.171Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":14,"totalLines":229,"estimatedTokens":2136}}563{"id":"stack-72403579","source":"stackoverflow","questionId":72403579,"title":"WorkerService configure a RabbitMq with MassTransit","tags":["dependency-injection","rabbitmq","masstransit"],"text":"Title: WorkerService configure a RabbitMq with MassTransit\nTags: dependency-injection, rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nin a WorkerService .Net I am trying to configure a MassTransit host with RabbitMq but I am getting this Error\n\nReference to type 'IBusControl' claims it is defined in 'MassTransit', but it could not be found\n\n```\nIHost host = Host.CreateDefaultBuilder(args)\n.ConfigureServices((context,services) =>\n{\n services.AddHostedService();\n\n services.AddAutoMapper(typeof(Program));\n //MassTransit-RabbitMQ Configuration\n services.AddMassTransit(config => {\n config.UsingRabbitMq((ctx, cfg) => {\n cfg.Host(context.Configuration.GetValue(\"EventBusSettings:HostAddress\"));\n });\n });\n services.AddMassTransitHostedService();\n})\n.Build();\n\nawait host.RunAsync();\n```\n\nWhat am I missing?\n\n========================================\n\nCode:\n```text\nIHost host = Host.CreateDefaultBuilder(args)\n.ConfigureServices((context,services) =>\n{\n services.AddHostedService<Worker>();\n\n services.AddAutoMapper(typeof(Program));\n //MassTransit-RabbitMQ Configuration\n services.AddMassTransit(config => {\n config.UsingRabbitMq((ctx, cfg) => {\n cfg.Host(context.Configuration.GetValue<string>(\"EventBusSettings:HostAddress\"));\n });\n });\n services.AddMassTransitHostedService();\n})\n.Build();\n\nawait host.RunAsync();\n```\n\n```text\nAddMassTransitHostedService\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.171Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":57,"estimatedTokens":354}}564{"id":"stack-3576512","source":"stackoverflow","questionId":3576512,"title":"Abort a running task in Celery within django","tags":["python","django","rabbitmq","celery","celery-task"],"text":"Title: Abort a running task in Celery within django\nTags: python, django, rabbitmq, celery, celery-task\nSource: Stack Overflow\n\nQuestion:\nI would like to be able to abort a task that is running from a Celery queue (using rabbitMQ). I call the task using\n\n```\ntask_id = AsyncBoot.apply_async(args=[name], name=name, connect_timeout=3)\n```\n\nwhere AsyncBoot is a defined task.\n\nI can get the task ID (assuming that is the long string that `apply_async` returns) and store it in a database but I'm unsure how to call an abort method. I see how to make methods abortable with the Abortable tasks class but if I only have the task-id string, how do I call .abort() on the task? Thanks.\n\n========================================\n\nTop Answer:\nDid you see the reference documentation?\nhttp://celeryq.org/docs/reference/celery.contrib.abortable.html\n\nTo abort the task use `result.abort()`:\n\n```\n>>> result = AsyncBoot.apply_async(...)\n>>> result.abort()\n```\n\n========================================\n\nCode:\n```text\ntask_id = AsyncBoot.apply_async(args=[name], name=name, connect_timeout=3)\n```\n\n```text\napply_async\n```\n\n```text\nabortable_async_result = AsyncBoot.apply_async(args=[name], name=name, connect_timeout=3)\nmyTaskId = abortable_async_result.task_id\n```\n\n```text\nabortable_async_result = AbortableAsyncResult(myTaskId)\nabortable_async_result.abort()\n```\n\n```text\napply_async\n```\n\n```text\nAsyncResult\n```\n\n```text\nAbortableAsyncResult\n```\n\n```text\ntask_id\n```\n\n```text\nAbortableAsyncResult\n```\n\n```text\ndefault_backend\n```\n\n```text\n>>> result = AsyncBoot.apply_async(...)\n>>> result.abort()\n```\n\n```text\nresult.abort()\n```\n\n========================================\n\nComments:\n- But how do I get result object at a later date if all I have is the task_id? I'm trying to abort the task when I no longer have access to the result object. I need someway to pull it from the database.\n- Pickle the result object in the database then\n- `mytask.AsyncResult(task_id)` or `from celery.result import AsyncResult; AsyncResult(task_id)`.\n- It is worth noting that the celery docs say: \"this class will only work with the database backends.\" docs.celeryproject.org/en/latest/reference/…","metadata":{"transformedAt":"2026-08-18T18:33:20.171Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":89,"estimatedTokens":545}}565{"id":"stack-10635733","source":"stackoverflow","questionId":10635733,"title":"How do I make multiple celery workers run the same tasks?","tags":["python","django","rabbitmq","celery","amqp"],"text":"Title: How do I make multiple celery workers run the same tasks?\nTags: python, django, rabbitmq, celery, amqp\nSource: Stack Overflow\n\nQuestion:\nI have one task that is checking a url speed, but i want that to be executed by multiple celery workers in different servers. I want the same url to be checked by multiple workers.\n\nHow can I do that?\n\n========================================\n\nCode:\n```text\nignore_result=True\n```\n\n========================================\n\nComments:\n- I thought about sending the same task to multiple queues (one for each worker) but that didn't seem to be a really smart sollution. I'm going to see if broadcast works for me.\n- @gawry That's fine. just curious how do you collect speeds data to page.\n- i'm doing in a pretty naive way right now ( but I expect to improve it later ) - I just add a start_date = datetime.now() before calling the url and a end_date after calling the url","metadata":{"transformedAt":"2026-08-18T18:33:20.172Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":22,"estimatedTokens":229}}566{"id":"stack-48816530","source":"stackoverflow","questionId":48816530,"title":"How does RabbitMQ decide when it is time to delete a message?","tags":["rabbitmq","high-availability","queueing"],"text":"Title: How does RabbitMQ decide when it is time to delete a message?\nTags: rabbitmq, high-availability, queueing\nSource: Stack Overflow\n\nQuestion:\nI am trying to understand the logic for message deletion in RabbitMQ.\n\nMy goal is to make messages persist even if there is not a client connected to read them, so that when clients reconnect the messages are waiting for them. I can use durable, lazy queues so that messages are persisted to disk, and I can use HA replication to ensure that multiple nodes get a copy of all queued messages.\n\nI want to have messages go to two or more queues, using topic or header routing, and have one or more clients reading each queue.\n\nI have two queues, A and B, fed by a header exchange. Queue A gets all messages. Queue B gets only messages with the \"archive\" header. Queue A has 3 consumers reading. Queue B has 1 consumer. If the consumer of B dies, but the consumers of A continue acknowledging messages, will RabbitMQ delete the messages or continue to store them? Queue B will not have anyone consuming it until B is restarted, and I want the messages to remain available for later consumption.\n\nI have read a bunch of documentation so far, but still have not found a clear answer to this.\n\n========================================\n\nTop Answer:\nRabbitMQ will decide when to delete the messages upon acknowledgement.\n\nLet's say you have a message sender:\n\n```\nvar factory = new ConnectionFactory() { HostName = \"localhost\", Port = 5672, UserName = \"guest\", Password = \"guest\" };\nusing (var connection = factory.CreateConnection())\nusing (var channel = connection.CreateModel())\n{\n channel.QueueDeclare(queue: \"hello\",\n durable: true,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n\n string message = \"Hello World!\";\n var body = Encoding.UTF8.GetBytes(message);\n\n channel.BasicPublish(exchange: \"\",\n routingKey: \"hello\",\n basicProperties: null,\n body: body);\n Console.WriteLine(\" [x] Sent {0}\", message);\n}\n```\n\nThis will create a durable queue \"hello\" and send the message \"Hello World!\" to it. This is what the queue would look like after sending one message to it.\n\nhttps://i.sstatic.net/mloDz.png\n\nNow let's set up two consumers, one that acknowledges the message was received and one that doesn't.\n\n```\nchannel.BasicConsume(queue: \"hello\",\n autoAck: false,\n consumer: consumer);\n```\n\nand \n\n```\nchannel.BasicConsume(queue: \"hello\",\n autoAck: true,\n consumer: consumer);\n```\n\nIf you only run the first consumer, the message will never be deleted from the queue, because the consumer states that the messages will only disappear from the queue if the client manually acknowledges them: https://www.rabbitmq.com/confirms.html\n\nThe second consumer however will tell the queue that it can safely delete all the messages it received, automatically/immediately.\n\nIf you don't want to automatically delete these messages, you must disable autoAck and do some manual acknowledgement using the documentation:\n\nhttp://codingvision.net/tips-and-tricks/c-send-data-between-processes-w-memory-mapped-file (Scroll down to \"Manual Acknowledgement\").\n\n```\nchannel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);\n```\n\n========================================\n\nCode:\n```text\nvar factory = new ConnectionFactory() { HostName = \"localhost\", Port = 5672, UserName = \"guest\", Password = \"guest\" };\nusing (var connection = factory.CreateConnection())\nusing (var channel = connection.CreateModel())\n{\n channel.QueueDeclare(queue: \"hello\",\n durable: true,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n\n string message = \"Hello World!\";\n var body = Encoding.UTF8.GetBytes(message);\n\n channel.BasicPublish(exchange: \"\",\n routingKey: \"hello\",\n basicProperties: null,\n body: body);\n Console.WriteLine(\" [x] Sent {0}\", message);\n}\n```\n\n```text\nchannel.BasicConsume(queue: \"hello\",\n autoAck: false,\n consumer: consumer);\n```\n\n```text\nchannel.BasicConsume(queue: \"hello\",\n autoAck: true,\n consumer: consumer);\n```\n\n```text\nchannel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);\n```\n\n========================================\n\nComments:\n- I hope I was able to answer your question! If not let me know what I can do to improve it!\n- how can i make sure all subscribed services has processed the message before deleting a message. for example having acknowledgement for any subscriber and message only delets when all subscribers acknowledge.\n- @virtouso I think you are still thinking that 1 RMQ Queue -> Multiple Consumer. In RMQ, 1 queue is designed only for 1 consumer. so each message will be deleted after Consumer acknowledge the message. if you try to subscribe > 1 consumer to a queue, they will fighting over each other to consume each message and eventually only 1 will be able to consume the message","metadata":{"transformedAt":"2026-08-18T18:33:20.172Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":123,"estimatedTokens":1255}}567{"id":"stack-35049641","source":"stackoverflow","questionId":35049641,"title":"Adding values to header in MassTransit.RabbitMq","tags":["rabbitmq","masstransit"],"text":"Title: Adding values to header in MassTransit.RabbitMq\nTags: rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nI am using MassTransit 3.0.0.0 and I have a hard time understanding how to intercept messages in a Request-Response scenario on their way out and add some information to the headers field that I can read on the receiver's end.\n\nI was looking at the Middleware, as recommended in the MassTransit docs - see Observers warning - but the context you get on the Send is just a Pipe context that doesn't have access to the Headers field so I cannot alter it. I used the sample provided in Middleware page.\n\nI then, looked at IPublishInterceptor\n\n```\npublic class X : IPublishInterceptor where T : class, PipeContext\n{\n public Task PostPublish(PublishContext context)\n {\n return new Task(() => { });\n }\n\n public Task PostSend(PublishContext context, SendContext sendContext)\n {\n return new Task(() => { });\n }\n\n public Task PrePublish(PublishContext context)\n {\n context.Headers.Set(\"ID\", Guid.NewGuid().ToString());\n return new Task(() => { });\n }\n\n public Task PreSend(PublishContext context, SendContext sendContext)\n {\n context.Headers.Set(\"ID\", Guid.NewGuid().ToString());\n return new Task(() => { });\n }\n}\n```\n\nWhich is very clear and concise. However, I don't know where it is used and how to link it to the rest of the infrastructure. As it stands, this is just an interface that is not really linked to anything.\n\n========================================\n\nTop Answer:\nYou can also add headers in the consumer class:\n\n```\npublic async Task Consume(ConsumeContext context)\n{\n ....\n await context.Publish(new { Data = data }, c => AddHeaders(c));\n}\n\npublic static void AddHeaders(PublishContext context)\n{\n context.Headers.Set(\"CausationId\", context.MessageId);\n}\n```\n\n========================================\n\nCode:\n```text\npublic class X<T> : IPublishInterceptor<T> where T : class, PipeContext\n{\n public Task PostPublish(PublishContext<T> context)\n {\n return new Task(() => { });\n }\n\n public Task PostSend(PublishContext<T> context, SendContext<T> sendContext)\n {\n return new Task(() => { });\n }\n\n public Task PrePublish(PublishContext<T> context)\n {\n context.Headers.Set(\"ID\", Guid.NewGuid().ToString());\n return new Task(() => { });\n }\n\n public Task PreSend(PublishContext<T> context, SendContext<T> sendContext)\n {\n context.Headers.Set(\"ID\", Guid.NewGuid().ToString());\n return new Task(() => { });\n }\n}\n```\n\n```text\n// execute a synchronous delegate on send\ncfg.ConfigureSend(x => x.Execute(context => {}));\n\n// execute a synchronous delegate on publish\ncfg.ConfigurePublish(x => x.Execute(context => {}));\n```\n\n```text\ncfg.AddPipeSpecification(new X<MyMessage>());\n```\n\n```text\npublic async Task Consume(ConsumeContext<MyMessage> context)\n{\n ....\n await context.Publish<MyEvent>(new { Data = data }, c => AddHeaders(c));\n}\n\npublic static void AddHeaders(PublishContext context)\n{\n context.Headers.Set(\"CausationId\", context.MessageId);\n}\n```\n\n========================================\n\nComments:\n- I know what you mean by sample using the extension methods. I tried the sample you sent, it doesn't work with the X type because that is a IPublishInterceptor and it expects an IPipeSpecification and there is no relationshipe between the 2. And PipeSpecification doesn't provide access to modify the Headers on the message.\n- `cfg.AddPipeSpecification` only allows adding filters for the consume pipeline, as far I can read the signatures.\n- It is awesome. Works like a charm. Thank you.\n- It is now `cfg.ConfigurePublish(x => x.UseSendExecute(async context => await { ... }));`\n- One thing to note is that you can only use value types in headers. For example, `Guid` will not work and crash in the RabbitMq writer, so you have to use `ToString()`\n- Is the `Publish(T message, Func headers)` still there?\n- Hello @Alexey, How can add headers in case of send ?\n- This way is more robust, in my opinion","metadata":{"transformedAt":"2026-08-18T18:33:20.172Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":124,"estimatedTokens":1002}}568{"id":"stack-51752890","source":"stackoverflow","questionId":51752890,"title":"How to disable heartbeats with pika and rabbitmq","tags":["python","rabbitmq","pika"],"text":"Title: How to disable heartbeats with pika and rabbitmq\nTags: python, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI am using rabbitmq to facilitate some tasks from my rabbit server to my respective consumers. I have noticed that when I run some rather lengthy tests, 20+ minutes, my consumer will lose contact with the producer after it completes it's task. In my rabbit logs, I have seen the error \n\n```\nclosing AMQP connection (192.168.101.2:64855 -> \n192.168.101.3:5672):\nmissed heartbeats from client, timeout: 60s\n```\n\nAlso, I receive this error from pika \n\n```\npika.exceptions.ConnectionClosed: (-1, \"error(10054, 'An existing connection was forcibly closed by the remote host')\")\n```\n\nI'm assuming this is due to this code right here and the conflict of heartbeats with the lengthy blocking connection time.\n\n```\nself.connection = pika.BlockingConnection(pika.ConnectionParameters('192.168.101.2', 5672, 'user', credentials))\n self.channel = self.connection.channel()\n self.channel.queue_declare(queue=self.tool,\n arguments={'x-message-ttl': 1000,\n \"x-dead-letter-exchange\": \"dlx\",\n \"x-dead-letter-routing-key\": \"dl\",\n 'durable': True})\n```\n\nIs there a proper way to increase the heartbeat time or how would I turn it off(would it be wise to) completely? Like I said, tests that are 20+ min seem to lead to a closedconnection error but I've ran plenty of tests from the 1-15 minute mark where everything is fine and the consumer client continues to wait for a message to be delivered.\n\n========================================\n\nTop Answer:\nYou can set the minimum heartbeat interval when creating the `connection`. \n\nYou can see an example in the pika documentation.\n\nI'd recommend against disabling the heartbeat as it might lead to hanging connections piling up on the broker. We experienced such issue in production.\n\nAlways make sure the connections have a minimum reasonable heartbeat. If the heartbeat interval needs to be long (hours for example), make sure you close the connection when the application crashes or exits. In this way you won't leave the connection open on the broker side.\n\n========================================\n\nCode:\n```text\nclosing AMQP connection <0.14009.27> (192.168.101.2:64855 -> \n192.168.101.3:5672):\nmissed heartbeats from client, timeout: 60s\n```\n\n```text\npika.exceptions.ConnectionClosed: (-1, \"error(10054, 'An existing connection was forcibly closed by the remote host')\")\n```\n\n```text\nself.connection = pika.BlockingConnection(pika.ConnectionParameters('192.168.101.2', 5672, 'user', credentials))\n self.channel = self.connection.channel()\n self.channel.queue_declare(queue=self.tool,\n arguments={'x-message-ttl': 1000,\n \"x-dead-letter-exchange\": \"dlx\",\n \"x-dead-letter-routing-key\": \"dl\",\n 'durable': True})\n```\n\n```text\n0.12.0\n```\n\n```text\nadd_callback_threadsafe\n```\n\n```text\nbasic_ack\n```\n\n```text\nconnection\n```\n\n```text\nconnection = pika.BlockingConnection(pika.URLParameters(\"amqp://user:pass@127.0.0.1?heartbeat=0\"))\n```\n\n```text\nconnection = pika.BlockingConnection(pika.ConnectionParameters(heartbeat=0))\n```\n\n========================================\n\nComments:\n- Thanks for the response. I saw that I could set \"heartbeat_interval\" equal to whatever value I wanted in pika.ConnectionParameters but the client heartbeat_interval could not be larger than the rabbit server's heartbeart. How would I go about increasing my rabbit server's heartbeat so I could set the client's equal to it? Would I need to create the rabbit.config file in /etc/rabbitmq and then set the value there? If so, is heartbeat_interval = 600 valid syntax for the config file? Just the one line like and rules here? rabbitmq.com/configure.html\n- This is actually the recommended way to go. Nevertheless IMHO this should be something provided by Pika. Pushing the users to go MT is not ideal. Especially considering now Pika has blocking connections.\n- I've been maintaining Pika since version `0.11.0` and, as far as I know, Pika has always required that the user not block the ioloop, even when using the blocking connection. This is not Pika nor even Python-specific - you can't block the ioloop when using `libuv`, for instance, or your own `select` loop. What Pika now provides are more obvious methods to use when you need to schedule calls to be executed in the same thread as what the ioloop runs. I realize this isn't the most user-friendly scenario and will be improving docs and examples for version `1.0.0`","metadata":{"transformedAt":"2026-08-18T18:33:20.172Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":97,"estimatedTokens":1156}}569{"id":"stack-58017144","source":"stackoverflow","questionId":58017144,"title":"Tasks linger in celery amqp when publisher is terminated","tags":["python","rabbitmq","celery"],"text":"Title: Tasks linger in celery amqp when publisher is terminated\nTags: python, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI am using `Celery` with a `RabbitMQ` server. I have a publisher, which could potentially be terminated by a `SIGKILL` and since this signal cannot be watched, I cannot revoke the tasks. What would be a common approach to revoke the tasks where the publisher is not alive anymore?\n\nI experimented with an interval on the worker side, but the publisher is obviously not registered as a worker, so I don't know how I can detect a timeout\n\n========================================\n\nTop Answer:\nThere's nothing built-in to celery to monitor the producer / publisher status -- only the worker / consumer status. There are other alternatives that you can consider, for example by using a redis expiring key that has to be updated periodically by the publisher that can serve as a proxy for whether a publisher is alive. And then in the task checking to see if the flag for a publisher still exists within redis, and if it doesn't the task returns doing nothing.\n\n========================================\n\nCode:\n```text\nCelery\n```\n\n```text\nRabbitMQ\n```\n\n```text\nSIGKILL\n```\n\n========================================\n\nComments:\n- Highly unusual use-case... Let us know how you solved it. Good luck.\n- Hi, yes, it invalidates the task. A publisher sends several tasks to consumers where they get processed. The result of it will then be further processed. If the publisher dies, the post process doesn't happen anymore.\n- To expand on this, not only does celery not monitor anything about the publisher, RabbitMQ is also a queuing system that does not allow for arbitrary message access so there is no way to get the message out of the queue without draining the queue up until that message","metadata":{"transformedAt":"2026-08-18T18:33:20.172Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":35,"estimatedTokens":453}}570{"id":"stack-52973253","source":"stackoverflow","questionId":52973253,"title":"RabbitMQ pika.exceptions.ConnectionClosed (-1, \"error(104, 'Connection reset by peer')\")","tags":["python","python-2.7","rabbitmq","pika","python-pika"],"text":"Title: RabbitMQ pika.exceptions.ConnectionClosed (-1, \"error(104, 'Connection reset by peer')\")\nTags: python, python-2.7, rabbitmq, pika, python-pika\nSource: Stack Overflow\n\nQuestion:\nI have a task queue in RabbitMQ with multiple producers (12) and one consumer for heavy tasks in a webapp. When I run the consumer it starts dequeuing some of the messages before crashing with this error:\n\n```\nTraceback (most recent call last):\nFile \"jobs.py\", line 42, in jobs[job](config)\nFile \"/home/ec2-user/project/queue.py\", line 100, in init_queue\nchannel.start_consuming()\nFile \"/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py\", line 1822, in start_consuming\nself.connection.process_data_events(time_limit=None)\nFile \"/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py\", line 749, in process_data_events\nself._flush_output(common_terminator)\nFile \"/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py\", line 477, in _flush_output\nresult.reason_text)\npika.exceptions.ConnectionClosed: (-1, \"error(104, 'Connection reset by peer')\")\n```\n\nThe producers code is:\n\n```\nmessage = {'image_url': image_url, 'image_name': image_name, 'notes': notes}\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))\nchannel = connection.channel()\n\nchannel.queue_declare(queue='tasks_queue')\nchannel.basic_publish(exchange='', routing_key=queue_name, body=json.dumps(message))\n\nconnection.close()\n```\n\nAnd the only consumer's code (the one is clashing):\n\n```\ndef callback(self, ch, method, properties, body):\n \"\"\"Callback when receive a message.\"\"\"\n message = json.loads(body)\n try:\n image = _get_image(message['image_url'])\n except:\n sys.stderr.write('Error getting image in note %s' % note['id'])\n # Crop image with PIL. Not so expensive\n box_path = _crop(image, message['image_name'], box)\n\n # API call. Long time function\n result = long_api_call(box_path)\n\n if result is None:\n sys.stderr.write('Error in note %s' % note['id'])\n return\n # update the db\n db.update_record(result)\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))\nchannel = connection.channel()\nchannel.queue_declare(queue='tasks_queue')\nchannel.basic_qos(prefetch_count=1)\nchannel.basic_consume(callback_obj.callback, queue='tasks_queue', no_ack=True)\nchannel.start_consuming()\n```\n\nAs you can see, there are 3 expensive functions for message. One crop task, one API call and one database update. Without the API call, que consumer runs smoothly.\n\nThanks in advance\n\n========================================\n\nTop Answer:\nStarting with RabbitMQ 3.5.5, the broker’s default heartbeat timeout\ndecreased from 580 seconds to 60 seconds.\n\nSee pika: Ensuring well-behaved connection with heartbeat and blocked-connection timeouts.\n\nThe simplest fix is to increase the heartbeat timeout:\n\n```\nrabbit_url = host + \"?heartbeat=360\"\nconn = pika.BlockingConnection(pika.URLParameters(rabbit_url))\n\n# or\n\nparams = pika.ConnectionParameters(host, heartbeat=360)\nconn = pika.BlockingConnection(params)\n```\n\n========================================\n\nCode:\n```text\nTraceback (most recent call last):\nFile \"jobs.py\", line 42, in <module> jobs[job](config)\nFile \"/home/ec2-user/project/queue.py\", line 100, in init_queue\nchannel.start_consuming()\nFile \"/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py\", line 1822, in start_consuming\nself.connection.process_data_events(time_limit=None)\nFile \"/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py\", line 749, in process_data_events\nself._flush_output(common_terminator)\nFile \"/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py\", line 477, in _flush_output\nresult.reason_text)\npika.exceptions.ConnectionClosed: (-1, \"error(104, 'Connection reset by peer')\")\n```\n\n```text\nmessage = {'image_url': image_url, 'image_name': image_name, 'notes': notes}\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))\nchannel = connection.channel()\n\nchannel.queue_declare(queue='tasks_queue')\nchannel.basic_publish(exchange='', routing_key=queue_name, body=json.dumps(message))\n\nconnection.close()\n```\n\n```text\ndef callback(self, ch, method, properties, body):\n \"\"\"Callback when receive a message.\"\"\"\n message = json.loads(body)\n try:\n image = _get_image(message['image_url'])\n except:\n sys.stderr.write('Error getting image in note %s' % note['id'])\n # Crop image with PIL. Not so expensive\n box_path = _crop(image, message['image_name'], box)\n\n # API call. Long time function\n result = long_api_call(box_path)\n\n if result is None:\n sys.stderr.write('Error in note %s' % note['id'])\n return\n # update the db\n db.update_record(result)\n\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))\nchannel = connection.channel()\nchannel.queue_declare(queue='tasks_queue')\nchannel.basic_qos(prefetch_count=1)\nchannel.basic_consume(callback_obj.callback, queue='tasks_queue', no_ack=True)\nchannel.start_consuming()\n```\n\n```text\nmissed heartbeats from client, timeout: 60s\n```\n\n```text\nlong_api_call\n```\n\n```text\nno_ack=True\n```\n\n```text\nack_message\n```\n\n```py\nrabbit_url = host + \"?heartbeat=360\"\nconn = pika.BlockingConnection(pika.URLParameters(rabbit_url))\n\n# or\n\nparams = pika.ConnectionParameters(host, heartbeat=360)\nconn = pika.BlockingConnection(params)\n```\n\n========================================\n\nComments:\n- Please provide information about your environment - what versions of software you're using, are you using Docker, are you using a load balancer, is there anything logged by RabbitMQ. `Connection reset by peer` means that something interrupted your TCP connection unexpectedly. I expect to see a similar message logged by RabbitMQ.\n- Hello. I have rabbitmq 3.7.0 running on a Amazon Linux EC2 Instance. No docker or load balancer. Also, this code. result = long_api_call(box_path) is behind a try catch block, so is supposed to be fault tolerant. This *long_api_call* points to an external service with a currently unstable internet conection, so is not rare than some of the callback calls just don't work. But the error shouldn't drop the consumer with this weird error. My rabbitmq log_file:\n- 2018-10-25 06:04:54.854 [info] closing AMQP connection (127.0.0.1:42882 -> 127.0.0.1:5672, vhost: '/', user: 'guest') 2018-10-25 06:05:14.740 [warning] closing AMQP connection (127.0.0.1:32816 -> 127.0.0.1:5672): missed heartbeats from client, timeout: 60s 2018-10-25 06:06:59.367 [info] accepting AMQP connection (127.0.0.1:43332 -> 127.0.0.1:5672) 2018-10-25 06:06:59.370 [info] connection (127.0.0.1:43332 -> 127.0.0.1:5672): user 'guest' authenticated and granted\n- You're a life saver. That stucks with me for the last 3 days, and now it works. Thanks!","metadata":{"transformedAt":"2026-08-18T18:33:20.172Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":180,"estimatedTokens":1696}}571{"id":"stack-68602834","source":"stackoverflow","questionId":68602834,"title":"RabbitMQ, Celery and Django - connection to broker lost. Trying to re-establish the connection","tags":["django","rabbitmq","celery"],"text":"Title: RabbitMQ, Celery and Django - connection to broker lost. Trying to re-establish the connection\nTags: django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nCelery disconnects from RabbitMQ each time a task is passed to rabbitMQ, however the task does eventually succeed:\n\nMy questions are:\n\n- How can I solve this issue?\n\n- What improvements can you suggest for my celery/rabbitmq configuration?\n\nCelery version: 5.1.2\nRabbitMQ version: 3.9.0\nErlang version: 24.0.4\n\nRabbitMQ error (sorry for the length of the log:\n\n```\n** Generic server terminating\n ** Last message in was {'$gen_cast',\n {method,{'basic.ack',1,false},none,noflow}}\n ** When Server state == {ch,\n {conf,running,rabbit_framing_amqp_0_9_1,1,\n ,,,\n someIPAddress:5672\">>,\n undefined,\n {user,>,\n [administrator],\n [{rabbit_auth_backend_internal,none}]},\n >,>,,\n [{>,bool,true},\n {>,bool,true},\n {>,bool,true}],\n none,0,134217728,1800000,#{},1000000000},\n {lstate,,true},\n none,2,\n {1,\n {[{pending_ack,1,>,1627738474140,\n {resource,>,queue,>},\n 2097}],\n []}},\n {state,#{},erlang},\n #{> =>\n {{amqqueue,\n {resource,>,queue,>},\n true,false,none,[],,[],[],[],undefined,\n undefined,[],[],live,0,[],>,\n #{user => >},\n rabbit_classic_queue,#{}},\n {false,0,false,[]}}},\n #{{resource,>,queue,>} =>\n {1,{>,nil,nil}}},\n {state,none,5000,undefined},\n false,1,\n {rabbit_confirms,undefined,#{}},\n [],[],none,flow,[],\n {rabbit_queue_type,\n #{{resource,>,queue,>} =>\n {ctx,rabbit_classic_queue,\n {resource,>,queue,>},\n {rabbit_classic_queue,,\n {resource,>,queue,>},\n #{}}}},\n #{ =>\n {resource,>,queue,>}}},\n #Ref,false}\n ** Reason for termination ==\n ** {function_clause,\n [{rabbit_channel,'-notify_limiter/2-fun-0-',\n [{pending_ack,1,>,1627738474140,\n {resource,>,queue,>},\n 2097},\n 0],\n [{file,\"src/rabbit_channel.erl\"},{line,2124}]},\n {lists,foldl,3,[{file,\"lists.erl\"},{line,1267}]},\n {rabbit_channel,notify_limiter,2,\n [{file,\"src/rabbit_channel.erl\"},{line,2124}]},\n {rabbit_channel,ack,2,[{file,\"src/rabbit_channel.erl\"},{line,2057}]},\n {rabbit_channel,handle_method,3,\n [{file,\"src/rabbit_channel.erl\"},{line,1343}]},\n {rabbit_channel,handle_cast,2,\n [{file,\"src/rabbit_channel.erl\"},{line,644}]},\n {gen_server2,handle_msg,2,[{file,\"src/gen_server2.erl\"},{line,1067}]},\n {proc_lib,wake_up,3,[{file,\"proc_lib.erl\"},{line,236}]}]}\n\n crasher:\n initial call: rabbit_channel:init/1\n pid: \n registered_name: []\n exception exit: {function_clause,\n [{rabbit_channel,'-notify_limiter/2-fun-0-',\n [{pending_ack,1,>,1627738474140,\n {resource,>,queue,\n >},\n 2097},\n 0],\n [{file,\"src/rabbit_channel.erl\"},{line,2124}]},\n {lists,foldl,3,[{file,\"lists.erl\"},{line,1267}]},\n {rabbit_channel,notify_limiter,2,\n [{file,\"src/rabbit_channel.erl\"},{line,2124}]},\n {rabbit_channel,ack,2,\n [{file,\"src/rabbit_channel.erl\"},{line,2057}]},\n {rabbit_channel,handle_method,3,\n [{file,\"src/rabbit_channel.erl\"},{line,1343}]},\n {rabbit_channel,handle_cast,2,\n [{file,\"src/rabbit_channel.erl\"},{line,644}]},\n {gen_server2,handle_msg,2,\n [{file,\"src/gen_server2.erl\"},{line,1067}]},\n {proc_lib,wake_up,3,\n [{file,\"proc_lib.erl\"},{line,236}]}]}\n in function gen_server2:terminate/3 (src/gen_server2.erl, line 1183)\n ancestors: [,,,,,\n ,,,,rabbit_sup,\n ]\n message_queue_len: 0\n messages: []\n links: []\n dictionary: [{channel_operation_timeout,15000},\n {process_name,\n {rabbit_channel,\n { someIPAddress:5672\">>,\n 1}}},\n {rand_seed,\n {#{jump => #Fun,\n max => 288230376151711743,\n next => #Fun,type => exsplus},\n [262257290895536220|242201045588130196]}},\n {{xtype_to_module,direct},rabbit_exchange_type_direct},\n {permission_cache_can_expire,false},\n {msg_size_for_gc,115}]\n trap_exit: true\n status: running\n heap_size: 28690\n stack_size: 29\n reductions: 67935\n neighbours:\n\n Error on AMQP connection (someIPAddress:45610 -> someIPAddress:5672, vhost: 'backoffice', user: 'someadmin', state: running), channel 1:\n {function_clause,\n [{rabbit_channel,'-notify_limiter/2-fun-0-',\n [{pending_ack,1,>,1627738474140,\n {resource,>,queue,>},\n 2097},\n 0],\n [{file,\"src/rabbit_channel.erl\"},{line,2124}]},\n {lists,foldl,3,[{file,\"lists.erl\"},{line,1267}]},\n {rabbit_channel,notify_limiter,2,\n [{file,\"src/rabbit_channel.erl\"},{line,2124}]},\n {rabbit_channel,ack,2,[{file,\"src/rabbit_channel.erl\"},{line,2057}]},\n {rabbit_channel,handle_method,3,\n [{file,\"src/rabbit_channel.erl\"},{line,1343}]},\n {rabbit_channel,handle_cast,2,\n [{file,\"src/rabbit_channel.erl\"},{line,644}]},\n {gen_server2,handle_msg,2,[{file,\"src/gen_server2.erl\"},{line,1067}]},\n {proc_lib,wake_up,3,[{file,\"proc_lib.erl\"},{line,236}]}]}\n supervisor: {,rabbit_channel_sup}\n errorContext: child_terminated\n reason: {function_clause,\n [{rabbit_channel,'-notify_limiter/2-fun-0-',\n [{pending_ack,1,>,1627738474140,\n {resource,>,queue,>},\n 2097},\n 0],\n [{file,\"src/rabbit_channel.erl\"},{line,2124}]},\n {lists,foldl,3,[{file,\"lists.erl\"},{line,1267}]},\n {rabbit_channel,notify_limiter,2,\n [{file,\"src/rabbit_channel.erl\"},{line,2124}]},\n {rabbit_channel,ack,2,\n [{file,\"src/rabbit_channel.erl\"},{line,2057}]},\n {rabbit_channel,handle_method,3,\n [{file,\"src/rabbit_channel.erl\"},{line,1343}]},\n {rabbit_channel,handle_cast,2,\n [{file,\"src/rabbit_channel.erl\"},{line,644}]},\n {gen_server2,handle_msg,2,\n [{file,\"src/gen_server2.erl\"},{line,1067}]},\n {proc_lib,wake_up,3,[{file,\"proc_lib.erl\"},{line,236}]}]}\n offender: [{pid,},\n {id,channel},\n {mfargs,\n {rabbit_channel,start_link,\n [1,,,,\n someIPAddress:5672\">>,\n rabbit_framing_amqp_0_9_1,\n {user,>,\n [administrator],\n [{rabbit_auth_backend_internal,none}]},\n >,\n [{>,bool,true},\n {>,bool,true},\n {>,bool,true}],\n ,]}},\n {restart_type,intrinsic},\n {shutdown,70000},\n {child_type,worker}]\n Non-AMQP exit reason '{function_clause,\n [{rabbit_channel,'-notify_limiter/2-fun-0-',\n [{pending_ack,1,>,1627738474140,\n {resource,>,queue,>},\n 2097},\n 0],\n [{file,\"src/rabbit_channel.erl\"},{line,2124}]},\n {lists,foldl,3,[{file,\"lists.erl\"},{line,1267}]},\n {rabbit_channel,notify_limiter,2,\n [{file,\"src/rabbit_channel.erl\"},{line,2124}]},\n {rabbit_channel,ack,2,\n [{file,\"src/rabbit_channel.erl\"},{line,2057}]},\n {rabbit_channel,handle_method,3,\n [{file,\"src/rabbit_channel.erl\"},{line,1343}]},\n {rabbit_channel,handle_cast,2,\n [{file,\"src/rabbit_channel.erl\"},{line,644}]},\n {gen_server2,handle_msg,2,\n [{file,\"src/gen_server2.erl\"},{line,1067}]},\n {proc_lib,wake_up,3,\n [{file,\"proc_lib.erl\"},{line,236}]}]}'\n supervisor: {,rabbit_channel_sup}\n errorContext: shutdown\n reason: reached_max_restart_intensity\n offender: [{pid,},\n {id,channel},\n {mfargs,\n {rabbit_channel,start_link,\n [1,,,,\n someIPAddress:5672\">>,\n rabbit_framing_amqp_0_9_1,\n {user,>,\n [administrator],\n [{rabbit_auth_backend_internal,none}]},\n >,\n [{>,bool,true},\n {>,bool,true},\n {>,bool,true}],\n ,]}},\n {restart_type,intrinsic},\n {shutdown,70000},\n {child_type,worker}]\n closing AMQP connection (someIPAddress:45610 -> someIPAddress:5672, vhost: 'backoffice', user: 'someadmin')\n accepting AMQP connection (someIPAddress:57452 -> someIPAddress:5672)\n connection (someIPAddress:57452 -> someIPAddress:5672): user 'someadmin' authenticated and granted access to vhost 'backoffice'\n```\n\nCelery log:\n\n```\nINFO/MainProcess] Task subscribe_task[aae43c55-3396-45f3-8bea-d01a66983835] received\nDEBUG/MainProcess] TaskPool: Apply (args:('subscribe_task', 'aae43c55-3396-45f3-8bea-d01a66983835', {'lang': 'py', 'task': 'subscribe_task', 'id': 'aae43c55-3396-45f3-8bea-d01a66983835', 'shadow': None, 'eta': None, 'expires': None, 'group': None, 'group_index': None, 'retries': 0, 'timelimit': [None, None], 'root_id': 'aae43c55-3396-45f3-8bea-d01a66983835', 'parent_id': None, 'argsrepr': \"(140, 'Subscribe Confirm Email Address')\", 'kwargsrepr': '{}', 'origin': 'gen20577@webserver', 'ignore_result': True, 'reply_to': '91cf548f-4e42-3870-b27f-2cc1fd3f7074', 'correlation_id': 'aae43c55-3396-45f3-8bea-d01a66983835', 'hostname': 'worker@webserver', 'delivery_info': {'exchange': '', 'routing_key': 'celery', 'priority': 0, 'redelivered': False}, 'args': [140, 'Subscribe Confirm Email Address'], 'kwargs': {}}, '[[140, \"Subscribe Confirm Email Address\"], {}, {\"callbacks\": null, \"errbacks\": null, \"chain\": null, \"chord\": null}]', 'application/json', 'utf-8') kwargs:{})\nDEBUG/MainProcess] Closed channel #1\nDEBUG/MainProcess] Closed channel #2\nWARNING/MainProcess] consumer: Connection to broker lost. Trying to re-establish the connection...\nTraceback (most recent call last):\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/celery/worker/consumer/consumer.py\", line 326, in start\n blueprint.start(self)\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/celery/bootsteps.py\", line 116, in start\n step.start(parent)\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/celery/worker/consumer/consumer.py\", line 618, in start\n c.loop(*c.loop_args())\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/celery/worker/loops.py\", line 81, in asynloop\n next(loop)\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/kombu/asynchronous/hub.py\", line 361, in create_loop\n cb(*cbargs)\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/kombu/transport/base.py\", line 235, in on_readable\n reader(loop)\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/kombu/transport/base.py\", line 217, in _read\n drain_events(timeout=0)\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/amqp/connection.py\", line 523, in drain_events\n while not self.blocking_read(timeout):\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/amqp/connection.py\", line 529, in blocking_read\n return self.on_inbound_frame(frame)\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/amqp/method_framing.py\", line 53, in on_frame\n callback(channel, method_sig, buf, None)\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/amqp/connection.py\", line 535, in on_inbound_method\n return self.channels[channel_id].dispatch_method(\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/amqp/abstract_channel.py\", line 143, in dispatch_method\n listener(*args)\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/amqp/connection.py\", line 665, in _on_close\n raise error_for_code(reply_code, reply_text,\namqp.exceptions.InternalError: (0, 0): (541) INTERNAL_ERROR\nDEBUG/MainProcess] | Consumer: Restarting event loop...\nDEBUG/MainProcess] | Consumer: Restarting Control...\nDEBUG/MainProcess] | Consumer: Restarting Tasks...\nDEBUG/MainProcess] Canceling task consumer...\nDEBUG/MainProcess] | Consumer: Restarting Connection...\nDEBUG/MainProcess] | Consumer: Starting Connection\nDEBUG/MainProcess] Start from server, version: 0.9, properties: {'capabilities': {'publisher_confirms': True, 'exchange_exchange_bindings': True, 'basic.nack': True, 'consumer_cancel_notify': True, 'connection.blocked': True, 'consumer_priorities': True, 'authentication_failure_close': True, 'per_consumer_qos': True, 'direct_reply_to': True}, 'cluster_name': 'rabbit@webserver', 'copyright': 'Copyright (c) 2007-2021 VMware, Inc. or its affiliates.', 'information': 'Licensed under the MPL 2.0. Website: https://rabbitmq.com', 'platform': 'Erlang/OTP 24.0.4', 'product': 'RabbitMQ', 'version': '3.9.0'}, mechanisms: [b'AMQPLAIN', b'PLAIN'], locales: ['en_US']\nINFO/MainProcess] Connected to amqp://someAdmin:**@webserver:5672/backoffice\n```\n\nCelery Service config:\n\n```\n[Unit]\nDescription=Celery Service\nAfter=network.target\n\n[Service]\nType=forking\nUser=DJANGO_USER\nGroup=DJANGO_USER\nEnvironmentFile=/etc/conf.d/celery\nWorkingDirectory=/opt/backoffice\n\nExecStart=/bin/sh -c '${CELERY_BIN} -A $CELERY_APP multi start $CELERYD_NODES \\\n --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} \\\n --loglevel=\"${CELERYD_LOG_LEVEL}\" $CELERYD_OPTS'\nExecStop=/bin/sh -c '${CELERY_BIN} multi stopwait $CELERYD_NODES \\\n --pidfile=${CELERYD_PID_FILE} --loglevel=\"${CELERYD_LOG_LEVEL}\"'\nExecReload=/bin/sh -c '${CELERY_BIN} -A $CELERY_APP multi restart $CELERYD_NODES \\\n --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} \\\n --loglevel=\"${CELERYD_LOG_LEVEL}\" $CELERYD_OPTS'\nRestart=always\n\n[Install]\nWantedBy=multi-user.target\n```\n\nCelery conf.d:\n\n```\nCELERYD_NODES=\"worker\"\nCELERY_BIN=\"/opt/backoffice/venv/bin/celery\"\nCELERY_APP=\"backoffice\"\nCELERYD_CHDIR=\"/opt/backoffice/\"\nCELERYD_MULTI=\"multi\"\nCELERYD_OPTS=\"--time-limit=300 --without-heartbeat --without-gossip --without-mingle\"\nCELERYD_PID_FILE=\"/var/run/celery/%n.pid\"\nCELERYD_LOG_FILE=\"/var/log/celery/%n%I.log\"\nCELERYD_LOG_LEVEL=\"DEBUG\"\nCELERYBEAT_PID_FILE=\"/var/run/celery/beat.pid\"\nCELERYBEAT_LOG_FILE=\"/var/log/celery/beat.log\"\nCELERYBEAT_DB_FILE=\"/var/cache/backoffice/celerybeat/celerybeat-schedule.db\"\n```\n\nDjango celery_config.py:\n\n```\nfrom django.conf import settings\nbroker_url = settings.RABBITMQ_BROKER\nworker_send_task_event = False\ntask_ignore_result = True\ntask_time_limit = 60\ntask_soft_time_limit = 50\ntask_acks_late = True\nworker_prefetch_multiplier = 10\nworker_cancel_long_running_tasks_on_connection_loss = True\n```\n\n========================================\n\nTop Answer:\nSame problem here. Tried different settings but with no solution.\n\n**Workaround**:\nDowngrade RabbitMQ to 3.8.\nAfter downgrading there were no connection errors anymore.\nSo, I think it must have something to do with different behavior of v3.9.\n\n========================================\n\nCode:\n```text\n** Generic server <0.11908.0> terminating\n ** Last message in was {'$gen_cast',\n {method,{'basic.ack',1,false},none,noflow}}\n ** When Server state == {ch,\n {conf,running,rabbit_framing_amqp_0_9_1,1,\n <0.11899.0>,<0.11906.0>,<0.11899.0>,\n <<\"someIPAddress:45610 -> someIPAddress:5672\">>,\n undefined,\n {user,<<\"someadmin\">>,\n [administrator],\n [{rabbit_auth_backend_internal,none}]},\n <<\"backoffice\">>,<<\"celery\">>,<0.11900.0>,\n [{<<\"consumer_cancel_notify\">>,bool,true},\n {<<\"connection.blocked\">>,bool,true},\n {<<\"authentication_failure_close\">>,bool,true}],\n none,0,134217728,1800000,#{},1000000000},\n {lstate,<0.11907.0>,true},\n none,2,\n {1,\n {[{pending_ack,1,<<\"None4\">>,1627738474140,\n {resource,<<\"backoffice\">>,queue,<<\"celery\">>},\n 2097}],\n []}},\n {state,#{},erlang},\n #{<<\"None4\">> =>\n {{amqqueue,\n {resource,<<\"backoffice\">>,queue,<<\"celery\">>},\n true,false,none,[],<0.471.0>,[],[],[],undefined,\n undefined,[],[],live,0,[],<<\"backoffice\">>,\n #{user => <<\"someadmin\">>},\n rabbit_classic_queue,#{}},\n {false,0,false,[]}}},\n #{{resource,<<\"backoffice\">>,queue,<<\"celery\">>} =>\n {1,{<<\"None4\">>,nil,nil}}},\n {state,none,5000,undefined},\n false,1,\n {rabbit_confirms,undefined,#{}},\n [],[],none,flow,[],\n {rabbit_queue_type,\n #{{resource,<<\"backoffice\">>,queue,<<\"celery\">>} =>\n {ctx,rabbit_classic_queue,\n {resource,<<\"backoffice\">>,queue,<<\"celery\">>},\n {rabbit_classic_queue,<0.471.0>,\n {resource,<<\"backoffice\">>,queue,<<\"celery\">>},\n #{}}}},\n #{<0.471.0> =>\n {resource,<<\"backoffice\">>,queue,<<\"celery\">>}}},\n #Ref<0.4203289403.2328100865.106387>,false}\n ** Reason for termination ==\n ** {function_clause,\n [{rabbit_channel,'-notify_limiter/2-fun-0-',\n [{pending_ack,1,<<\"None4\">>,1627738474140,\n {resource,<<\"backoffice\">>,queue,<<\"celery\">>},\n 2097},\n 0],\n [{file,\"src/rabbit_channel.erl\"},{line,2124}]},\n {lists,foldl,3,[{file,\"lists.erl\"},{line,1267}]},\n {rabbit_channel,notify_limiter,2,\n [{file,\"src/rabbit_channel.erl\"},{line,2124}]},\n {rabbit_channel,ack,2,[{file,\"src/rabbit_channel.erl\"},{line,2057}]},\n {rabbit_channel,handle_method,3,\n [{file,\"src/rabbit_channel.erl\"},{line,1343}]},\n {rabbit_channel,handle_cast,2,\n [{file,\"src/rabbit_channel.erl\"},{line,644}]},\n {gen_server2,handle_msg,2,[{file,\"src/gen_server2.erl\"},{line,1067}]},\n {proc_lib,wake_up,3,[{file,\"proc_lib.erl\"},{line,236}]}]}\n\n crasher:\n initial call: rabbit_channel:init/1\n pid: <0.11908.0>\n registered_name: []\n exception exit: {function_clause,\n [{rabbit_channel,'-notify_limiter/2-fun-0-',\n [{pending_ack,1,<<\"None4\">>,1627738474140,\n {resource,<<\"backoffice\">>,queue,\n <<\"celery\">>},\n 2097},\n 0],\n [{file,\"src/rabbit_channel.erl\"},{line,2124}]},\n {lists,foldl,3,[{file,\"lists.erl\"},{line,1267}]},\n {rabbit_channel,notify_limiter,2,\n [{file,\"src/rabbit_channel.erl\"},{line,2124}]},\n {rabbit_channel,ack,2,\n [{file,\"src/rabbit_channel.erl\"},{line,2057}]},\n {rabbit_channel,handle_method,3,\n [{file,\"src/rabbit_channel.erl\"},{line,1343}]},\n {rabbit_channel,handle_cast,2,\n [{file,\"src/rabbit_channel.erl\"},{line,644}]},\n {gen_server2,handle_msg,2,\n [{file,\"src/gen_server2.erl\"},{line,1067}]},\n {proc_lib,wake_up,3,\n [{file,\"proc_lib.erl\"},{line,236}]}]}\n in function gen_server2:terminate/3 (src/gen_server2.erl, line 1183)\n ancestors: [<0.11905.0>,<0.11903.0>,<0.11898.0>,<0.11897.0>,<0.508.0>,\n <0.507.0>,<0.506.0>,<0.504.0>,<0.503.0>,rabbit_sup,\n <0.224.0>]\n message_queue_len: 0\n messages: []\n links: [<0.11905.0>]\n dictionary: [{channel_operation_timeout,15000},\n {process_name,\n {rabbit_channel,\n {<<\"someIPAddress:45610 -> someIPAddress:5672\">>,\n 1}}},\n {rand_seed,\n {#{jump => #Fun<rand.3.92093067>,\n max => 288230376151711743,\n next => #Fun<rand.5.92093067>,type => exsplus},\n [262257290895536220|242201045588130196]}},\n {{xtype_to_module,direct},rabbit_exchange_type_direct},\n {permission_cache_can_expire,false},\n {msg_size_for_gc,115}]\n trap_exit: true\n status: running\n heap_size: 28690\n stack_size: 29\n reductions: 67935\n neighbours:\n\n Error on AMQP connection <0.11899.0> (someIPAddress:45610 -> someIPAddress:5672, vhost: 'backoffice', user: 'someadmin', state: running), channel 1:\n {function_clause,\n [{rabbit_channel,'-notify_limiter/2-fun-0-',\n [{pending_ack,1,<<\"None4\">>,1627738474140,\n {resource,<<\"backoffice\">>,queue,<<\"celery\">>},\n 2097},\n 0],\n [{file,\"src/rabbit_channel.erl\"},{line,2124}]},\n {lists,foldl,3,[{file,\"lists.erl\"},{line,1267}]},\n {rabbit_channel,notify_limiter,2,\n [{file,\"src/rabbit_channel.erl\"},{line,2124}]},\n {rabbit_channel,ack,2,[{file,\"src/rabbit_channel.erl\"},{line,2057}]},\n {rabbit_channel,handle_method,3,\n [{file,\"src/rabbit_channel.erl\"},{line,1343}]},\n {rabbit_channel,handle_cast,2,\n [{file,\"src/rabbit_channel.erl\"},{line,644}]},\n {gen_server2,handle_msg,2,[{file,\"src/gen_server2.erl\"},{line,1067}]},\n {proc_lib,wake_up,3,[{file,\"proc_lib.erl\"},{line,236}]}]}\n supervisor: {<0.11905.0>,rabbit_channel_sup}\n errorContext: child_terminated\n reason: {function_clause,\n [{rabbit_channel,'-notify_limiter/2-fun-0-',\n [{pending_ack,1,<<\"None4\">>,1627738474140,\n {resource,<<\"backoffice\">>,queue,<<\"celery\">>},\n 2097},\n 0],\n [{file,\"src/rabbit_channel.erl\"},{line,2124}]},\n {lists,foldl,3,[{file,\"lists.erl\"},{line,1267}]},\n {rabbit_channel,notify_limiter,2,\n [{file,\"src/rabbit_channel.erl\"},{line,2124}]},\n {rabbit_channel,ack,2,\n [{file,\"src/rabbit_channel.erl\"},{line,2057}]},\n {rabbit_channel,handle_method,3,\n [{file,\"src/rabbit_channel.erl\"},{line,1343}]},\n {rabbit_channel,handle_cast,2,\n [{file,\"src/rabbit_channel.erl\"},{line,644}]},\n {gen_server2,handle_msg,2,\n [{file,\"src/gen_server2.erl\"},{line,1067}]},\n {proc_lib,wake_up,3,[{file,\"proc_lib.erl\"},{line,236}]}]}\n offender: [{pid,<0.11908.0>},\n {id,channel},\n {mfargs,\n {rabbit_channel,start_link,\n [1,<0.11899.0>,<0.11906.0>,<0.11899.0>,\n <<\"someIPAddress:45610 -> someIPAddress:5672\">>,\n rabbit_framing_amqp_0_9_1,\n {user,<<\"someadmin\">>,\n [administrator],\n [{rabbit_auth_backend_internal,none}]},\n <<\"backoffice\">>,\n [{<<\"consumer_cancel_notify\">>,bool,true},\n {<<\"connection.blocked\">>,bool,true},\n {<<\"authentication_failure_close\">>,bool,true}],\n <0.11900.0>,<0.11907.0>]}},\n {restart_type,intrinsic},\n {shutdown,70000},\n {child_type,worker}]\n Non-AMQP exit reason '{function_clause,\n [{rabbit_channel,'-notify_limiter/2-fun-0-',\n [{pending_ack,1,<<\"None4\">>,1627738474140,\n {resource,<<\"backoffice\">>,queue,<<\"celery\">>},\n 2097},\n 0],\n [{file,\"src/rabbit_channel.erl\"},{line,2124}]},\n {lists,foldl,3,[{file,\"lists.erl\"},{line,1267}]},\n {rabbit_channel,notify_limiter,2,\n [{file,\"src/rabbit_channel.erl\"},{line,2124}]},\n {rabbit_channel,ack,2,\n [{file,\"src/rabbit_channel.erl\"},{line,2057}]},\n {rabbit_channel,handle_method,3,\n [{file,\"src/rabbit_channel.erl\"},{line,1343}]},\n {rabbit_channel,handle_cast,2,\n [{file,\"src/rabbit_channel.erl\"},{line,644}]},\n {gen_server2,handle_msg,2,\n [{file,\"src/gen_server2.erl\"},{line,1067}]},\n {proc_lib,wake_up,3,\n [{file,\"proc_lib.erl\"},{line,236}]}]}'\n supervisor: {<0.11905.0>,rabbit_channel_sup}\n errorContext: shutdown\n reason: reached_max_restart_intensity\n offender: [{pid,<0.11908.0>},\n {id,channel},\n {mfargs,\n {rabbit_channel,start_link,\n [1,<0.11899.0>,<0.11906.0>,<0.11899.0>,\n <<\"someIPAddress:45610 -> someIPAddress:5672\">>,\n rabbit_framing_amqp_0_9_1,\n {user,<<\"someadmin\">>,\n [administrator],\n [{rabbit_auth_backend_internal,none}]},\n <<\"backoffice\">>,\n [{<<\"consumer_cancel_notify\">>,bool,true},\n {<<\"connection.blocked\">>,bool,true},\n {<<\"authentication_failure_close\">>,bool,true}],\n <0.11900.0>,<0.11907.0>]}},\n {restart_type,intrinsic},\n {shutdown,70000},\n {child_type,worker}]\n closing AMQP connection <0.11899.0> (someIPAddress:45610 -> someIPAddress:5672, vhost: 'backoffice', user: 'someadmin')\n accepting AMQP connection <0.14133.0> (someIPAddress:57452 -> someIPAddress:5672)\n connection <0.14133.0> (someIPAddress:57452 -> someIPAddress:5672): user 'someadmin' authenticated and granted access to vhost 'backoffice'\n```\n\n```text\nINFO/MainProcess] Task subscribe_task[aae43c55-3396-45f3-8bea-d01a66983835] received\nDEBUG/MainProcess] TaskPool: Apply <function fast_trace_task at 0x7fbd03f32af0> (args:('subscribe_task', 'aae43c55-3396-45f3-8bea-d01a66983835', {'lang': 'py', 'task': 'subscribe_task', 'id': 'aae43c55-3396-45f3-8bea-d01a66983835', 'shadow': None, 'eta': None, 'expires': None, 'group': None, 'group_index': None, 'retries': 0, 'timelimit': [None, None], 'root_id': 'aae43c55-3396-45f3-8bea-d01a66983835', 'parent_id': None, 'argsrepr': \"(140, 'Subscribe Confirm Email Address')\", 'kwargsrepr': '{}', 'origin': 'gen20577@webserver', 'ignore_result': True, 'reply_to': '91cf548f-4e42-3870-b27f-2cc1fd3f7074', 'correlation_id': 'aae43c55-3396-45f3-8bea-d01a66983835', 'hostname': 'worker@webserver', 'delivery_info': {'exchange': '', 'routing_key': 'celery', 'priority': 0, 'redelivered': False}, 'args': [140, 'Subscribe Confirm Email Address'], 'kwargs': {}}, '[[140, \"Subscribe Confirm Email Address\"], {}, {\"callbacks\": null, \"errbacks\": null, \"chain\": null, \"chord\": null}]', 'application/json', 'utf-8') kwargs:{})\nDEBUG/MainProcess] Closed channel #1\nDEBUG/MainProcess] Closed channel #2\nWARNING/MainProcess] consumer: Connection to broker lost. Trying to re-establish the connection...\nTraceback (most recent call last):\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/celery/worker/consumer/consumer.py\", line 326, in start\n blueprint.start(self)\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/celery/bootsteps.py\", line 116, in start\n step.start(parent)\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/celery/worker/consumer/consumer.py\", line 618, in start\n c.loop(*c.loop_args())\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/celery/worker/loops.py\", line 81, in asynloop\n next(loop)\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/kombu/asynchronous/hub.py\", line 361, in create_loop\n cb(*cbargs)\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/kombu/transport/base.py\", line 235, in on_readable\n reader(loop)\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/kombu/transport/base.py\", line 217, in _read\n drain_events(timeout=0)\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/amqp/connection.py\", line 523, in drain_events\n while not self.blocking_read(timeout):\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/amqp/connection.py\", line 529, in blocking_read\n return self.on_inbound_frame(frame)\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/amqp/method_framing.py\", line 53, in on_frame\n callback(channel, method_sig, buf, None)\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/amqp/connection.py\", line 535, in on_inbound_method\n return self.channels[channel_id].dispatch_method(\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/amqp/abstract_channel.py\", line 143, in dispatch_method\n listener(*args)\n File \"/opt/backoffice/venv/lib/python3.8/site-packages/amqp/connection.py\", line 665, in _on_close\n raise error_for_code(reply_code, reply_text,\namqp.exceptions.InternalError: (0, 0): (541) INTERNAL_ERROR\nDEBUG/MainProcess] | Consumer: Restarting event loop...\nDEBUG/MainProcess] | Consumer: Restarting Control...\nDEBUG/MainProcess] | Consumer: Restarting Tasks...\nDEBUG/MainProcess] Canceling task consumer...\nDEBUG/MainProcess] | Consumer: Restarting Connection...\nDEBUG/MainProcess] | Consumer: Starting Connection\nDEBUG/MainProcess] Start from server, version: 0.9, properties: {'capabilities': {'publisher_confirms': True, 'exchange_exchange_bindings': True, 'basic.nack': True, 'consumer_cancel_notify': True, 'connection.blocked': True, 'consumer_priorities': True, 'authentication_failure_close': True, 'per_consumer_qos': True, 'direct_reply_to': True}, 'cluster_name': 'rabbit@webserver', 'copyright': 'Copyright (c) 2007-2021 VMware, Inc. or its affiliates.', 'information': 'Licensed under the MPL 2.0. Website: https://rabbitmq.com', 'platform': 'Erlang/OTP 24.0.4', 'product': 'RabbitMQ', 'version': '3.9.0'}, mechanisms: [b'AMQPLAIN', b'PLAIN'], locales: ['en_US']\nINFO/MainProcess] Connected to amqp://someAdmin:**@webserver:5672/backoffice\n```\n\n```text\n[Unit]\nDescription=Celery Service\nAfter=network.target\n\n[Service]\nType=forking\nUser=DJANGO_USER\nGroup=DJANGO_USER\nEnvironmentFile=/etc/conf.d/celery\nWorkingDirectory=/opt/backoffice\n\nExecStart=/bin/sh -c '${CELERY_BIN} -A $CELERY_APP multi start $CELERYD_NODES \\\n --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} \\\n --loglevel=\"${CELERYD_LOG_LEVEL}\" $CELERYD_OPTS'\nExecStop=/bin/sh -c '${CELERY_BIN} multi stopwait $CELERYD_NODES \\\n --pidfile=${CELERYD_PID_FILE} --loglevel=\"${CELERYD_LOG_LEVEL}\"'\nExecReload=/bin/sh -c '${CELERY_BIN} -A $CELERY_APP multi restart $CELERYD_NODES \\\n --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} \\\n --loglevel=\"${CELERYD_LOG_LEVEL}\" $CELERYD_OPTS'\nRestart=always\n\n[Install]\nWantedBy=multi-user.target\n```\n\n```text\nCELERYD_NODES=\"worker\"\nCELERY_BIN=\"/opt/backoffice/venv/bin/celery\"\nCELERY_APP=\"backoffice\"\nCELERYD_CHDIR=\"/opt/backoffice/\"\nCELERYD_MULTI=\"multi\"\nCELERYD_OPTS=\"--time-limit=300 --without-heartbeat --without-gossip --without-mingle\"\nCELERYD_PID_FILE=\"/var/run/celery/%n.pid\"\nCELERYD_LOG_FILE=\"/var/log/celery/%n%I.log\"\nCELERYD_LOG_LEVEL=\"DEBUG\"\nCELERYBEAT_PID_FILE=\"/var/run/celery/beat.pid\"\nCELERYBEAT_LOG_FILE=\"/var/log/celery/beat.log\"\nCELERYBEAT_DB_FILE=\"/var/cache/backoffice/celerybeat/celerybeat-schedule.db\"\n```\n\n```text\nfrom django.conf import settings\nbroker_url = settings.RABBITMQ_BROKER\nworker_send_task_event = False\ntask_ignore_result = True\ntask_time_limit = 60\ntask_soft_time_limit = 50\ntask_acks_late = True\nworker_prefetch_multiplier = 10\nworker_cancel_long_running_tasks_on_connection_loss = True\n```\n\n```text\npip install -U amqp==5.0.9\n```\n\n```text\namqp==5.0.8\n```\n\n```text\namqp==5.0.9\n```\n\n========================================\n\nComments:\n- Many thanks Xentux, you set me on the right path. Whilst looking for the downgrade I saw that there is a patch for rabbit (3.9.1). Rabbit is working again without errors, at least for the moment..\n- WOW. I had the same problem. Thank you both. The 3.9.1 patch fixed this issue. For others, here is the bug report and here is the patch.\n- facing the same issue on rabbitmq 3.8.19","metadata":{"transformedAt":"2026-08-18T18:33:20.172Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":698,"estimatedTokens":7880}}572{"id":"stack-62759029","source":"stackoverflow","questionId":62759029,"title":"MassTransit Consumer throws \"A convention for the message type {type} was not found\" exception for a registered consumer","tags":["c#","asp.net-core","rabbitmq","masstransit"],"text":"Title: MassTransit Consumer throws \"A convention for the message type {type} was not found\" exception for a registered consumer\nTags: c#, asp.net-core, rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nI have a simple service that accepts requests at an HTTP Endpoint. The action for the endpoint uses MassTransit to publish an event alerting consumers that an entity has been updated. My consumer for the published event then sends a sync request to my synchronization consumer to complete the unit of work.\n\nHowever, when the event consumer attempts to dispatch the request, MassTransit throws an exception saying `A convention for the message type {type} was not found`. This would seem to imply that my consumer is not registered, but I believe it to be.\n\nHere's my `Startup` registration code:\n\n```\npublic void ConfigureServices(IServiceCollection services)\n{\n // -- removed non MassTransit code\n services.AddMassTransit(x =>\n {\n x.SetKebabCaseEndpointNameFormatter();\n x.AddConsumers(typeof(Startup).Assembly);\n x.UsingRabbitMq((context, cfg) =>\n {\n var rabbitMq = Configuration.GetSection(\"RabbitMq\");\n var url = rabbitMq.GetValue(\"Url\");\n var username = rabbitMq.GetValue(\"Username\");\n var password = rabbitMq.GetValue(\"Password\");\n \n cfg.Host(url, h =>\n {\n h.Username(username);\n h.Password(password);\n });\n cfg.ConfigureEndpoints(context);\n });\n });\n services.AddMassTransitHostedService();\n}\n```\n\nMy API controller looks like this:\n\n```\n[Route(\"~/api/[controller]\")]\npublic class JobSchedulingController : ApiControllerBase\n{\n private readonly IPublishEndpoint _publishEndpoint;\n\n public JobSchedulingController(IPublishEndpoint publishEndpoint)\n {\n _publishEndpoint = publishEndpoint;\n }\n\n [HttpPost]\n public async Task UpdateJob(JobSchedulingInputModel model)\n {\n await _publishEndpoint.Publish(model);\n return Ok();\n }\n}\n```\n\nHere's the event consumer:\n\n```\npublic class JobSchedulerJobUpdatedConsumer \n : IConsumer\n{\n public async Task Consume(\n ConsumeContext context)\n {\n await context.Send(context.Message);\n }\n}\n```\n\nAnd finally, the synchronization request consumer:\n\n```\npublic class SyncJobSchedulingToLacrmConsumer \n : IConsumer\n{\n private readonly LacrmClient _client;\n private readonly JobSchedulingContext _context;\n\n public SyncJobSchedulingToLacrmConsumer(\n LacrmClient client, \n JobSchedulingContext context)\n {\n _client = client;\n _context = context;\n }\n\n public async Task Consume(ConsumeContext context)\n {\n await context.Publish(new\n {\n LacrmPipelineItemId = \"\"\n });\n }\n}\n```\n\nI receive the error from within the event consumer and it never reaches the synchronization consumer. What could be causing this behavior?\n\n========================================\n\nTop Answer:\nI am not sure about within `IConsumer`, but generally you can get `IBus` in constructor (using dependency injection) and call `GetPublishSendEndpoint()` method.\n\n```\nvar sendEndpoint = await bus.GetPublishSendEndpoint();\nawait sendEndpoint.SendBatch(messages);\nawait sendEndpoint.Send(message);\n```\n\n========================================\n\nCode:\n```cs\npublic void ConfigureServices(IServiceCollection services)\n{\n // -- removed non MassTransit code\n services.AddMassTransit(x =>\n {\n x.SetKebabCaseEndpointNameFormatter();\n x.AddConsumers(typeof(Startup).Assembly);\n x.UsingRabbitMq((context, cfg) =>\n {\n var rabbitMq = Configuration.GetSection(\"RabbitMq\");\n var url = rabbitMq.GetValue<string>(\"Url\");\n var username = rabbitMq.GetValue<string>(\"Username\");\n var password = rabbitMq.GetValue<string>(\"Password\");\n \n cfg.Host(url, h =>\n {\n h.Username(username);\n h.Password(password);\n });\n cfg.ConfigureEndpoints(context);\n });\n });\n services.AddMassTransitHostedService();\n}\n```\n\n```cs\n[Route(\"~/api/[controller]\")]\npublic class JobSchedulingController : ApiControllerBase\n{\n private readonly IPublishEndpoint _publishEndpoint;\n\n public JobSchedulingController(IPublishEndpoint publishEndpoint)\n {\n _publishEndpoint = publishEndpoint;\n }\n\n [HttpPost]\n public async Task<IActionResult> UpdateJob(JobSchedulingInputModel model)\n {\n await _publishEndpoint.Publish<JobSchedulerJobUpdated>(model);\n return Ok();\n }\n}\n```\n\n```cs\npublic class JobSchedulerJobUpdatedConsumer \n : IConsumer<JobSchedulerJobUpdated>\n{\n public async Task Consume(\n ConsumeContext<JobSchedulerJobUpdated> context)\n {\n await context.Send<SyncJobSchedulingToLacrm>(context.Message);\n }\n}\n```\n\n```cs\npublic class SyncJobSchedulingToLacrmConsumer \n : IConsumer<SyncJobSchedulingToLacrm>\n{\n private readonly LacrmClient _client;\n private readonly JobSchedulingContext _context;\n\n public SyncJobSchedulingToLacrmConsumer(\n LacrmClient client, \n JobSchedulingContext context)\n {\n _client = client;\n _context = context;\n }\n\n public async Task Consume(ConsumeContext<SyncJobSchedulingToLacrm> context)\n {\n await context.Publish<JobSchedulerSyncedToLacrm>(new\n {\n LacrmPipelineItemId = \"\"\n });\n }\n}\n```\n\n```text\nA convention for the message type {type} was not found\n```\n\n```text\nStartup\n```\n\n```text\nawait context.Send<SyncJobSchedulingToLacrm>(context.Message);\n```\n\n```cs\nvar sendEndpoint = await bus.GetPublishSendEndpoint<IMessage>();\nawait sendEndpoint.SendBatch<IMessage>(messages);\nawait sendEndpoint.Send<IMessage>(message);\n```\n\n```text\nIConsumer\n```\n\n```text\nIBus\n```\n\n```text\nGetPublishSendEndpoint<T>()\n```\n\n========================================\n\nComments:\n- You should actually *never* do this, at all. You can, however, use `context` instead of `bus` to achieve the same result.\n- @ChrisPatterson, can you tell us why we should avoid this one? ... and how about cases where I just want to publish a message, but not consume it? I didn't find a clear example of a message pump, without any consumer (yet).\n- The linked answer explains why endpoint conventions are to be avoided. If you have any further questions, create a new question.","metadata":{"transformedAt":"2026-08-18T18:33:20.172Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":11,"totalLines":237,"estimatedTokens":1541}}573{"id":"stack-35509784","source":"stackoverflow","questionId":35509784,"title":"Difference between broker and exchange","tags":["rabbitmq"],"text":"Title: Difference between broker and exchange\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am new to RabbitMQ and trying to figure out the difference between a broker and an exchange.\n\nFrom what I've read, the terms seem to almost be used interchangeably and in the diagrams, a broker seems to encompass both the exchange and the queues.\n\nFrom \"RabbitMQ Succinctly\" book:\n\n Exchanges are AMQP entities where messages are sent to the message\n broker. Exchanges take a message and then route it to one or more\n queues\n\nSo what is a broker? In the RabbitMQ management there is a tab for \"Exchanges\", but not for brokers. Can I interact with a broker directly or is this only done by the exchange?\n\n========================================\n\nTop Answer:\nA broker stands between producer(s) and consumer(s).\n\nHere is the post-office analogy to understand the components in the Rabbitmq-based messaging system without going into the details.\n\nAn exchange is like a parcel-delivery man. A queue is the recipient of the parcel. A producer is the sender of the parcel. A set of rules that an exchange follows to deliver a parcel (that is, the message) to a queue are called \"bindings\". The routing key and/or the header are like the address on the parcel. The exchange determines which queue a message goes to based on the routing key/header. The producer sends messages to the exchange, not to the queue.\n\nThis entire business of accepting messages from the producers and delivering them to the consumers is what the \"broker\" does.\n\nRabbitmq is the implementation of AMQP protocol (an application-layer protocol) which is an asynchronous message-brokerage middleware.\n\n========================================\n\nComments:\n- Very helpful and clear analogy -- thanks for providing this.","metadata":{"transformedAt":"2026-08-18T18:33:20.172Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":34,"estimatedTokens":445}}574{"id":"stack-26462048","source":"stackoverflow","questionId":26462048,"title":"Apache camel,RabbitMQ how to send messages/objects","tags":["java","spring","apache-camel","rabbitmq"],"text":"Title: Apache camel,RabbitMQ how to send messages/objects\nTags: java, spring, apache-camel, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI hope someone can provide some help on this matter. \n\nI am using camel rabbitmq and for testing purpose I am trying to send a message to the queue, which I'm trying to display in rabbitmq interface and then also read it back. \n\nHowever I can't get this working. \n\nWhat I believe works is that I created, in the exchange tab of rabbitmq management interface, a new exchange. \nIn my java code I send the message to that exchange. When the code is executed, I can see a spike in the web interface showing that something has been received but I can't see what has been received. \nWhen I try to read, I can't read and get the following errror: \nCan someone provide me a practical example on how to send a message,see it in the web interace and also read it? any tutorial showing this process will be also appreciated. \n\nThank you\n\n=================\nSECOND PART\n\nThe error I'm getting now is the following:\n\n```\nCaused by: com.rabbitmq.client.ShutdownSignalException: channel error; reason: {#method(reply-code=406, reply-text=PRECONDITION_FAILED - cannot redeclare exchange 'rhSearchExchange' in vhost '/' with different type, durable, internal or autodelete value, class-id=40, method-id=10), null, \"\"}\n at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67)\n at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:33)\n at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:343)\n at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:216)\n at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:118)\n ... 47 more\n```\n\nI have the following settings:\n\nI get this error, I believe I’m doing something wrong with the URI and I have to define some extra parameters that I’m missing\nMy exchange is of direct type\nMy queue is of durable type \nAnd my uri is : \nrabbitmq://192.168.59.105:5672/rhSearchExchange?username=guest&password=guest&routingKey=rhSearchQueue\n\nany input on this?\n\nThanks\n\n========================================\n\nTop Answer:\nBecause this it the top hit on Google for rabbitmq/camel integration I feel the need to add a bit more to the subject. The lack of *simple* camel examples is astonishing to me.\n\n```\nimport org.apache.camel.CamelContext;\nimport org.apache.camel.ConsumerTemplate;\nimport org.apache.camel.Endpoint;\nimport org.apache.camel.Exchange;\nimport org.apache.camel.ProducerTemplate;\nimport org.apache.camel.impl.DefaultCamelContext;\nimport org.junit.Test;\n\npublic class CamelTests {\n CamelContext context;\n ProducerTemplate producer;\n ConsumerTemplate consumer;\n Endpoint endpoint;\n\n @Test\n public void camelRabbitMq() throws Exception {\n context = new DefaultCamelContext();\n\n context.start();\n\n endpoint = context.getEndpoint(\"rabbitmq://192.168.56.11:5672/tasks?username=benchmark&password=benchmark&autoDelete=false&routingKey=camel&queue=task_queue\");\n\n producer = context.createProducerTemplate();\n\n producer.setDefaultEndpoint(endpoint);\n producer.sendBody(\"one\");\n producer.sendBody(\"two\");\n producer.sendBody(\"three\");\n producer.sendBody(\"four\");\n producer.sendBody(\"done\");\n\n consumer = context.createConsumerTemplate();\n String body = null;\n while (!\"done\".equals(body)) {\n Exchange receive = consumer.receive(endpoint);\n body = receive.getIn().getBody(String.class);\n System.out.println(body);\n }\n\n context.stop();\n\n }\n\n}\n```\n\n========================================\n\nCode:\n```text\nCaused by: com.rabbitmq.client.ShutdownSignalException: channel error; reason: {#method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - cannot redeclare exchange 'rhSearchExchange' in vhost '/' with different type, durable, internal or autodelete value, class-id=40, method-id=10), null, \"\"}\n at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67)\n at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:33)\n at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:343)\n at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:216)\n at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:118)\n ... 47 more\n```\n\n```text\nrabbitmq:localhost:5672/tasks?username=guest&password=guest&autoDelete=false&routingKey=camel\n```\n\n```text\nrabbitmq:localhost:5672/tasks?username=guest&password=guest&autoDelete=false&routingKey=camel&queue=task_queue\n```\n\n```text\nrabbitConnFactory = new ConnectionFactory();\nrabbitConnFactory.setHost(\"localhost\");\nfinal Connection conn = rabbitConnFactory.newConnection();\nfinal Channel channel = conn.createChannel();\n\n// declare a direct, durable, non autodelete exchange named 'tasks' \nchannel.exchangeDeclare(\"tasks\", \"direct\", true); \n// declare a durable, non exclusive, non autodelete queue named 'task_queue'\nchannel.queueDeclare(\"task_queue\", true, false, false, null); \n// bind 'task_queue' to the 'tasks' exchange with the routing key 'camel'\nchannel.queueBind(\"task_queue\", \"tasks\", \"camel\");\n```\n\n```text\nchannel.basicPublish(\"tasks\", \"camel\", MessageProperties.PERSISTENT_TEXT_PLAIN, \"hello, world!\".getBytes());\n```\n\n```text\n@Override\npublic void configure() throws Exception {\n from(\"rabbitmq:localhost:5672/tasks?username=guest&password=guest&autoDelete=false&routingKey=camel&queue=task_queue\")\n .to(\"mock:result\");\n}\n```\n\n```text\ntasks\n```\n\n```text\ntrue\n```\n\n```text\ncamel\n```\n\n```text\ntask_queue\n```\n\n```text\nimport org.apache.camel.CamelContext;\nimport org.apache.camel.ConsumerTemplate;\nimport org.apache.camel.Endpoint;\nimport org.apache.camel.Exchange;\nimport org.apache.camel.ProducerTemplate;\nimport org.apache.camel.impl.DefaultCamelContext;\nimport org.junit.Test;\n\npublic class CamelTests {\n CamelContext context;\n ProducerTemplate producer;\n ConsumerTemplate consumer;\n Endpoint endpoint;\n\n @Test\n public void camelRabbitMq() throws Exception {\n context = new DefaultCamelContext();\n\n context.start();\n\n endpoint = context.getEndpoint(\"rabbitmq://192.168.56.11:5672/tasks?username=benchmark&password=benchmark&autoDelete=false&routingKey=camel&queue=task_queue\");\n\n producer = context.createProducerTemplate();\n\n producer.setDefaultEndpoint(endpoint);\n producer.sendBody(\"one\");\n producer.sendBody(\"two\");\n producer.sendBody(\"three\");\n producer.sendBody(\"four\");\n producer.sendBody(\"done\");\n\n consumer = context.createConsumerTemplate();\n String body = null;\n while (!\"done\".equals(body)) {\n Exchange receive = consumer.receive(endpoint);\n body = receive.getIn().getBody(String.class);\n System.out.println(body);\n }\n\n context.stop();\n\n }\n\n}\n```\n\n========================================\n\nComments:\n- any advice on this ?\n- I've been looking for a similar tutorial... I can publish messages to the exchange but I can't consume them from camel. However, for your error, I think the problem is you aren't routing the message anywhere. For example, I believe your configuration is `from(\"rabbitmq:localhost...\");` but it should be `from(\"rabbitmq:localhost:...\").to(\"foo:bar\")` `foo:bar` could be something like `mock:result`\n- Thank you for the reply. I understand that I have to use \"to\" to stream it/save it somewhere. I have updated my thread to show the error that I'm getting now. If anyone has anyone advice on how to solve this.\n- PLEASE READ FROM THE SECOND PART AS THAT IS THE ERROR I'M GETTING NOW\n- Thanks a lot llawj, it worked. I added autoDelete=false and also the name of the queue as well as the routingkey which was already there before. So basically it was a matter of getting the right uri. One problem that I'm having is that when it reads the queue, it reads all the messages in it? I tried to set prefetchEnabled=true and prefetchCount=1 in the uri but that throughs an error. Any advice on how to pull only one message? Thank you\n- I'm not really sure, to be honest. I'm just getting started with Camel / RabbitMQ, and I haven't needed to limit the number of messages I'm reading.\n- I'll check if I can find a way to do it. Thank you for your help.\n- Looks like as of Camel 2.14 there is no need to perform manual exchange, queue and binding declaration. Please, take a look at camel.apache.org/rabbitmq.html There is 'declare' option, that is true by default\n- @cpu2007 what is the error that you see? have you tried autoAck=false in addition to prefetchCount=1? This way broker won't give more messages until you send an ack for the one you're processing\n- From *Producer-/ConsumerTemplates'* JavaDoc:„**Important:** Make sure to call `org.apache.camel.ProducerTemplate.stop()` | `ConsumerTemplate.stop()` when you are done using the template, to clean up any resources.“","metadata":{"transformedAt":"2026-08-18T18:33:20.173Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":11,"totalLines":220,"estimatedTokens":2240}}575{"id":"stack-40762426","source":"stackoverflow","questionId":40762426,"title":"Installing Erlang / RabbitMQ on Windows 10 64-bit","tags":["erlang","rabbitmq"],"text":"Title: Installing Erlang / RabbitMQ on Windows 10 64-bit\nTags: erlang, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI would like to install RabbitMQ on my Windows 10 64-bit PC.\n\nThe RabbitMQ installer reports that it requires Erlang to be installed.\n\nI downloaded the erlang installer (OTP 19.1 Windows 64-bit Binary File (101629312)) from http://www.erlang.org/downloads . When I run it, it displays a dialog that reports \"Error opening file for writing: C:\\Program Files\\erl8.1\\Install.exe\" and gives me the option of \"Abort\", \"Retry\", and \"Ignore\".\n\n(Surely this installer is supposed to place files in \"C:\\Program Files\\\" directory rather than read them?)\n\nIf I click \"Ignore\" in the dialog, the installer *appears* to be working, and I get a good few subsequent dialogs, in all of which, I click \"Ignore\".\n\nAfter the Erlang installer has run, I attempt to install RabbitMQ installer again but it reports that it requires Erlang to be installed.\n\nCan somebody please help me?\n\nAm I wrong to expect a software installer to \"just work\"?\n\nThanks in advance.\n\n========================================\n\nTop Answer:\nMake sure that there is no previous version installed\nand Erlang Process is running , so you to stop it first then run the Application as Administrator\n\n========================================\n\nCode:\n```text\nProgramFiles\n```\n\n========================================\n\nComments:\n- I hope this link can help you.","metadata":{"transformedAt":"2026-08-18T18:33:20.173Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":40,"estimatedTokens":356}}576{"id":"stack-48361367","source":"stackoverflow","questionId":48361367,"title":"dotnetcore console app : rabbitmq with docker Connection refused 127.0.0.1:5672","tags":["rabbitmq",".net-core","docker-compose","console-application"],"text":"Title: dotnetcore console app : rabbitmq with docker Connection refused 127.0.0.1:5672\nTags: rabbitmq, .net-core, docker-compose, console-application\nSource: Stack Overflow\n\nQuestion:\nrabbit connection from console app :\n\n```\nvar factory = new ConnectionFactory()\n {\n HostName = Environment.GetEnvironmentVariable(\"RabbitMq/Host\"),\n UserName = Environment.GetEnvironmentVariable(\"RabbitMq/Username\"),\n Password = Environment.GetEnvironmentVariable(\"RabbitMq/Password\")\n };\n\n using (var connection = factory.CreateConnection()) // GETTING ERROR HERE\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(queue: \"rss\",\n durable: fa...\n```\n\nI'm getting this error :\n\n Unhandled Exception:\n RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the\n specified endpoints were reachable --->\n RabbitMQ.Client.Exceptions.ConnectFailureException: Connection failed\n ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException:\n Connection refused 127.0.0.1:5672\n\nmy docker-compose.yml file :\n\n```\nversion: '3'\n\nservices:\n message.api:\n image: message.api \n build:\n context: ./message_api\n dockerfile: Dockerfile\n container_name: message.api\n environment:\n - \"RabbitMq/Host=rabbit\"\n - \"RabbitMq/Username=guest\"\n - \"RabbitMq/Password=guest\"\n depends_on:\n - rabbit\n\n rabbit:\n image: rabbitmq:3.7.2-management\n hostname: rabbit\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n\n rsscomparator:\n image: rsscomparator \n build:\n context: ./rss_comparator_app\n dockerfile: Dockerfile\n container_name: rsscomparator\n environment:\n - \"RabbitMq/Host=rabbit\"\n - \"RabbitMq/Username=guest\"\n - \"RabbitMq/Password=guest\"\n depends_on:\n - rabbit\n```\n\nI'm using dotnetcore console app. When I use this app in docker I'm getting error. I can reach rabbitmq web browser(http://192.168.99.100:15672) but app can not reach.\n\n========================================\n\nTop Answer:\nI still had the same problem when trying to connect with `rabbit:5672` after launching my containers via a docker-compose file. This is not the original issue here, but I got the same \"connection refused\" error.\n\nI discovered that the rabbitMQ service takes a while to start, so other services (containers) try to connect before it's running. The main reason is that `depends_on` clause only guarantees that rabbitMQ is started, but not that it is running and healthy.\n\nTo fix this, you can set `restart: unless-stopped` or `restart: on-failure` to your other services depending on RabbitMQ.\n\n```\nrabbit:\n image: rabbitmq:3-management\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n\ngobackend:\n build: ./go-backend\n ports:\n - \"8080:8080\"\n restart: unless-stopped\n depends_on:\n - rabbit\n```\n\nAnother possible solution is to add a `healthcheck` clause in RabbitMQ service and check it in your other service, like this\n\n```\nrabbit:\n image: rabbitmq:3-management\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n healthcheck:\n test: rabbitmq-diagnostics -q ping\n interval: 10s\n timeout: 5s\n retries: 2\n start_period: 5s\n\ngobackend:\n build: ./go-backend\n ports:\n - \"8080:8080\"\n depends_on:\n rabbit:\n condition: service_healthy\n```\n\n========================================\n\nCode:\n```text\nvar factory = new ConnectionFactory()\n {\n HostName = Environment.GetEnvironmentVariable(\"RabbitMq/Host\"),\n UserName = Environment.GetEnvironmentVariable(\"RabbitMq/Username\"),\n Password = Environment.GetEnvironmentVariable(\"RabbitMq/Password\")\n };\n\n using (var connection = factory.CreateConnection()) // GETTING ERROR HERE\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(queue: \"rss\",\n durable: fa...\n```\n\n```text\nversion: '3'\n\nservices:\n message.api:\n image: message.api \n build:\n context: ./message_api\n dockerfile: Dockerfile\n container_name: message.api\n environment:\n - \"RabbitMq/Host=rabbit\"\n - \"RabbitMq/Username=guest\"\n - \"RabbitMq/Password=guest\"\n depends_on:\n - rabbit\n\n rabbit:\n image: rabbitmq:3.7.2-management\n hostname: rabbit\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n\n rsscomparator:\n image: rsscomparator \n build:\n context: ./rss_comparator_app\n dockerfile: Dockerfile\n container_name: rsscomparator\n environment:\n - \"RabbitMq/Host=rabbit\"\n - \"RabbitMq/Username=guest\"\n - \"RabbitMq/Password=guest\"\n depends_on:\n - rabbit\n```\n\n```text\n127.0.0.1:5672\n```\n\n```text\nrabbit:5672\n```\n\n```text\n127.0.0.1:5672\n```\n\n```text\nrabbit:\n image: rabbitmq:3-management\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n\ngobackend:\n build: ./go-backend\n ports:\n - \"8080:8080\"\n restart: unless-stopped\n depends_on:\n - rabbit\n```\n\n```text\nrabbit:\n image: rabbitmq:3-management\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n healthcheck:\n test: rabbitmq-diagnostics -q ping\n interval: 10s\n timeout: 5s\n retries: 2\n start_period: 5s\n\ngobackend:\n build: ./go-backend\n ports:\n - \"8080:8080\"\n depends_on:\n rabbit:\n condition: service_healthy\n```\n\n```text\nrabbit:5672\n```\n\n```text\ndepends_on\n```\n\n```text\nrestart: unless-stopped\n```\n\n```text\nrestart: on-failure\n```\n\n```text\nhealthcheck\n```\n\n========================================\n\nComments:\n- Could there be an issue with / in RabbitMq/Host?\n- in app my hostname is rabbit. it means app has to connect rabbit:5672? but. when app in docker, it always trying to connect 127.0.0.1:5672\n- in app HostName = Environment.GetEnvironmentVariable(\"RabbitMq/Host\") I'm trying to connect rabbit:5672 but app cannot do that. Only trying to connect 127.0.0.1:5672\n- am i missing something that has to be done in docker ?\n- I added network to docker-compose file then error is gone\n- @t.YILMAZ could you provide us your final docker-compose file please ? Or at least explain where did you put the network and what did you put inside. Thanks !\n- you can reach docker-compose.yml file here github.com/ylmz05/tracker/tree/master/RSSTracker","metadata":{"transformedAt":"2026-08-18T18:33:20.173Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":258,"estimatedTokens":1541}}577{"id":"stack-36483778","source":"stackoverflow","questionId":36483778,"title":"Passing URI to RabbitMQ","tags":["c#","rabbitmq"],"text":"Title: Passing URI to RabbitMQ\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am connecting to RabbitMQ using below code\n\n```\nfactory.UserName = \"userid\";\nfactory.Password = \"mypass@25\";\nfactory.VirtualHost = \"/filestream\";\nfactory.Port = AmqpTcpEndpoint.UseDefaultPort;\nfactory.HostName = \"myrabbitserver\";\nreturn factory.CreateConnection();\n```\n\nI wanted to change connection settings to the below format:\n\n```\namqp://userid:mypass@25@myrabbitserver:5672/filestream\n```\n\nMy password has `@` character due to which I'm not able to pass URI \n\n```\nvar factory = new ConnectionFactory();\nfactory.Uri = \"amqp://userid:mypass@25@myrabbitserver:5672/filestream\";\n```\n\nI end up supplying each attribute of factory manually. Is there a way that we can tell RabbitMQ that my password has @ by doing something like below?\n\n```\nfactory.Uri = \"amqp://userid:\"mypass@25\"@myrabbitserver:5672/filestream\";\n```\n\nIf I try to change `@` in the password to `%40`, it throws an error when acquiring the connection\n\n```\nNone of the specified endpoints were reachable\n```\n\n========================================\n\nTop Answer:\nyou can try this:-\n\n```\nstring rabbitmqconnection = $\"amqp://{HttpUtility.UrlEncode(\"username\")}: \n {HttpUtility.UrlEncode(\"password\")}@{\"hostname\"}\n /{HttpUtility.UrlEncode(\"/vhost\")}\";\n```\n\nhope this will resolve your problem.\n\n========================================\n\nCode:\n```text\nfactory.UserName = \"userid\";\nfactory.Password = \"mypass@25\";\nfactory.VirtualHost = \"/filestream\";\nfactory.Port = AmqpTcpEndpoint.UseDefaultPort;\nfactory.HostName = \"myrabbitserver\";\nreturn factory.CreateConnection();\n```\n\n```text\namqp://userid:mypass@25@myrabbitserver:5672/filestream\n```\n\n```text\nvar factory = new ConnectionFactory();\nfactory.Uri = \"amqp://userid:mypass@25@myrabbitserver:5672/filestream\";\n```\n\n```text\nfactory.Uri = \"amqp://userid:\"mypass@25\"@myrabbitserver:5672/filestream\";\n```\n\n```text\nNone of the specified endpoints were reachable\n```\n\n```text\n@\n```\n\n```text\n@\n```\n\n```text\n%40\n```\n\n```text\n@\n```\n\n```text\n<connectionStrings>\n <add name=\"RabbitMQ\" connectionString=\"amqp://{username}:{password}@{server}/{vhost}\" />\n </connectionStrings>\n```\n\n```text\nBind<IConnection>()\n .ToMethod(ctx =>\n {\nvar connectionString = configurationManager.ConnectionStrings[\"RabbitMQ\"].ConnectionString;\n var factory = new ConnectionFactory\n {\n Uri = ConnectionString,\n RequestedHeartbeat = 15,\n //every N seconds the server will send a heartbeat. If the connection does not receive a heartbeat within\n //N*2 then the connection is considered dead.\n //suggested from http://public.hudl.com/bits/archives/2013/11/11/c-rabbitmq-happy-servers/\n AutomaticRecoveryEnabled = true\n };\n\n return factory.CreateConnection();\n })\n .InSingletonScope();\n```\n\n```text\namqp://userid:mypass%4025@myrabbitserver:5672/filestream\n```\n\n```text\nURLEncode\n```\n\n```text\n@\n```\n\n```text\nfactory.VirtualHost = \"/filestream\"; //this has char '/' should change to '%2f'\n\nfactory.Uri = \"amqp://userid:mypass%4025@myrabbitserver:5672/%2ffilestream\";\n```\n\n```text\nstring rabbitmqconnection = $\"amqp://{HttpUtility.UrlEncode(\"username\")}: \n {HttpUtility.UrlEncode(\"password\")}@{\"hostname\"}\n /{HttpUtility.UrlEncode(\"/vhost\")}\";\n```\n\n```text\nimport java.net.URLEncoder;\n```\n\n```text\nString un_encoded = URLEncoder.encode(username); \nString pw_encoded = URLEncoder.encode(password); \nString vhost_encoded = URLEncoder.encode(virtualHost);\n```\n\n========================================\n\nComments:\n- Maybe use %40 for the @ sign? `factory.Uri = \"amqp://userid:mypass%4025%40myrabbitserver:5672/filestream\"‌​;`? Or alternatively call a UrlEncode method on the string and assign that to `factory.Uri`, like `factory.Uri = HttpUtlility.UrlEncod();`. The second approach would have the advantage of escaping any and all special characters in the Uri.\n- I tried that too but it doesn't allow to set value to Uri if I add any special character or encode;\n- How about using %40 for the `@` within the password, but not for`@` that's part of the amqp uri spec?\n- I somehow think it is something RabbitMQ issue but not formatting; but I tried that already\n- i'm trying from App.config only; I pasted here for easy reference for others; your syntax ins config is still using @server/vhost; do you mean I remove /vhost?\n- a vhost (virtual host) is a concept in rabbit to separate different queues for different users. If you don't need it, you can omit it. Also, my code works great from both web.config or app.config\n- do you have @ symbol in your password?\n- no, the @ symbol is the separator between the password and the name of the server\n- yes, I have @ in my password too; that's causing the confusion for RabbitMQ\n- What do you mean by \"why\"?","metadata":{"transformedAt":"2026-08-18T18:33:20.173Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":18,"totalLines":172,"estimatedTokens":1271}}578{"id":"stack-29841690","source":"stackoverflow","questionId":29841690,"title":"How to consume one message?","tags":["java","rabbitmq"],"text":"Title: How to consume one message?\nTags: java, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nWith example in rabbitmq, consumer get all messages from queue at one time. How to consume one message and exit?\n\n```\nQueueingConsumer consumer = new QueueingConsumer(channel);\nchannel.basicConsume(QUEUE_NAME, true, consumer);\n\nwhile (true) {\n QueueingConsumer.Delivery delivery = consumer.nextDelivery();\n String message = new String(delivery.getBody());\n System.out.println(\" [x] Received '\" + message + \"'\");\n}\n```\n\n========================================\n\nTop Answer:\nUse AMQP 0.9.1 basic.get to synchronously get just one message.\n\n```\nConnectionFactory factory = new ConnectionFactory();\nfactory.setUri(uri);\n\nConnection connection = factory.newConnection();\nChannel channel = connection.createChannel();\n\nchannel.queueDeclare(QUEUE_NAME, true, false, false, null);\n\nGetResponse response = channel.basicGet(QUEUE_NAME, true);\nif (response != null) {\n String message = new String(response.getBody(), \"UTF-8\");\n}\n\nchannel.close();\nconnection.close();\n```\n\n========================================\n\nCode:\n```text\nQueueingConsumer consumer = new QueueingConsumer(channel);\nchannel.basicConsume(QUEUE_NAME, true, consumer);\n\nwhile (true) {\n QueueingConsumer.Delivery delivery = consumer.nextDelivery();\n String message = new String(delivery.getBody());\n System.out.println(\" [x] Received '\" + message + \"'\");\n}\n```\n\n```text\nConnectionFactory factory = new ConnectionFactory();\n factory.setHost(\"localhost\");\n Connection connection = factory.newConnection();\n Channel channel = connection.createChannel();\n channel.basicQos(1);\n channel.queueDeclare(QUEUE_NAME, true, false, false, null);\n System.out.println(\"[*] waiting for messages. To exit press CTRL+C\");\n\n QueueingConsumer consumer = new QueueingConsumer(channel);\n channel.basicConsume(QUEUE_NAME, consumer);\n while(true) {\n QueueingConsumer.Delivery delivery = consumer.nextDelivery();\n int n = channel.queueDeclarePassive(QUEUE_NAME).getMessageCount();\n System.out.println(n);\n if(delivery != null) {\n byte[] bs = delivery.getBody();\n System.out.println(new String(bs));\n //String message= new String(delivery.getBody());\n channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);\n //System.out.println(\"[x] Received '\"+message);\n }\n }\n```\n\n```text\nConnectionFactory factory = new ConnectionFactory();\nfactory.setUri(uri);\n\nConnection connection = factory.newConnection();\nChannel channel = connection.createChannel();\n\nchannel.queueDeclare(QUEUE_NAME, true, false, false, null);\n\nGetResponse response = channel.basicGet(QUEUE_NAME, true);\nif (response != null) {\n String message = new String(response.getBody(), \"UTF-8\");\n}\n\nchannel.close();\nconnection.close();\n```\n\n```text\nconst consumeFromQueue = async (queueName) => {\n try {\n\n let data = await channel.get(queueName)// get one msg at a time\n if (data) {\n\n data.content ? eval(\"(\" + data.content.toString() + \")()\") : \"\"\n channel.ack(data)\n } else {\n //console.log(\"Empty Queue\")\n }\n }\n catch (error) {\n //console.log(\"Error while consuming from rabbitmq queue\", error)\n return Promise.reject(error)\n }\n}\n```\n\n========================================\n\nComments:\n- if not use a loop, all messages lost except one.\n- Isn't that what you wanted? Consume one message and exit.\n- QueueingConsumer.Delivery delivery = consumer.nextDelivery(); read all messages from queue at one time\n- Related: stackoverflow.com/questions/19163021/…\n- Also, as a word of caution to the OP: RabbitMQ team does not recommend reading only one at a time. Reason: rabbitmq.com/blog/2011/09/24/sizing-your-rabbits\n- I don't think setting BasicQOS to 1 solves it. \"This is done by setting a \"prefetch count\" value using the basic.qos method. The value defines the max number of unacknowledged deliveries that are permitted on a channel. Once the number reaches the configured count, RabbitMQ will stop delivering more messages on the channel unless at least one of the outstanding ones is acknowledged. \". From rabbitmq.com/confirms.html\n- Perfect, exactly what I was looking for for a quick integration test.\n- That isn't Java, the question was tagged as Java.","metadata":{"transformedAt":"2026-08-18T18:33:20.173Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":129,"estimatedTokens":1092}}579{"id":"stack-61295801","source":"stackoverflow","questionId":61295801,"title":"Symfony messenger queues with binding key - retry strategy","tags":["php","symfony","rabbitmq","amqp","symfony-messenger"],"text":"Title: Symfony messenger queues with binding key - retry strategy\nTags: php, symfony, rabbitmq, amqp, symfony-messenger\nSource: Stack Overflow\n\nQuestion:\nI'm implementing messenger in company which I work for. I found problem with routing key.\n\nI want to to send one message to two queues. Two other apps will process this queues. Everything works well, but I found problem when handler throws an exception. It doubles message sending one it two retry queues, because retry queues are matching by binding key, which is the same for this queues.\n\nFinally with 3 retries I have 16 messages on my dlqs. Could you help me with this problem? Is it possible to create retry strategy based maybe on queue, not routing key?\n\nMy config looks like:\n\n```\nmessenger:\n failure_transport: failed\n default_bus: command.bus\n transports:\n async:\n dsn: amqp://rabbitmq:rabbitmq@rabbitmq:5672\n options:\n retry_strategy:\n max_retries: 3\n delay: 1000\n multiplier: 2\n max_delay: 0\n exchange:\n name: olimp\n type: topic\n queues:\n create_miniature_v1:\n binding_keys:\n - first\n create_miniature_v2:\n binding_keys:\n - first\n failed:\n dsn: amqp://rabbitmq:rabbitmq@rabbitmq:5672\n options:\n exchange:\n name: olimp_dead\n type: topic\n queues:\n create_miniature_v1_dlq:\n binding_keys:\n - first\n create_miniature_v2_dlq:\n binding_keys:\n - first\n\n routing:\n 'Olimp\\Messenger\\TestEvent': async\n\n buses:\n command.bus:\n middleware:\n - Olimp\\Shared\\Application\\Message\\Middleware\\EventDispatcher\n - doctrine_close_connection\n - doctrine_transaction\n\n event.bus:\n default_middleware: allow_no_handlers\n\n query.bus: ~\n```\n\nI dispatch event with stamp like that:\n\n```\nclass MessengerTestCommand extends Command\n{\n protected static $defaultName = 'app:messenger-test';\n private MessageBusInterface $bus;\n\n public function __construct(MessageBusInterface $bus)\n {\n $this->bus = $bus;\n\n parent::__construct();\n }\n\n protected function execute(InputInterface $input, OutputInterface $output): int\n {\n $io = new SymfonyStyle($input, $output);\n\n $this->bus->dispatch(\n new TestEvent(), [\n new AmqpStamp('first')\n ]\n );\n\n $io->success('Done');\n\n return 0;\n }\n}\n```\n\nHandler:\n\n```\nclass TestEventHandler implements MessageHandlerInterface\n{\n public function __invoke(TestEvent $event)\n {\n dump($event->id);\n\n throw new \\Exception('Boom');\n }\n}\n```\n\nWhat I found on rabbit:\nhttps://i.sstatic.net/nPs33.png\n\nNow I was trying config like that:\n\n```\nframework:\n messenger:\n failure_transport: failed\n default_bus: command.bus\n transports:\n async:\n dsn: amqp://rabbitmq:rabbitmq@rabbitmq:5672\n options:\n retry_strategy:\n max_retries: 3\n delay: 1000\n multiplier: 2\n max_delay: 0\n exchange:\n name: olimp\n type: topic\n queues:\n create_miniature_v1:\n binding_keys:\n - first\n async1:\n dsn: amqp://rabbitmq:rabbitmq@rabbitmq:5672\n options:\n retry_strategy:\n max_retries: 3\n delay: 1000\n multiplier: 2\n max_delay: 0\n exchange:\n name: olimp\n type: topic\n queues:\n create_miniature_v2:\n binding_keys:\n - first\n failed:\n dsn: amqp://rabbitmq:rabbitmq@rabbitmq:5672\n options:\n exchange:\n name: olimp_dead\n type: topic\n queues:\n create_miniature_v1_dlq:\n binding_keys:\n - first\n create_miniature_v2_dlq:\n binding_keys:\n - first\n\n routing:\n 'Olimp\\Messenger\\TestEvent': [async, async1]\n```\n\nand with two running console commands:\n\n```\nbin/console messenger:consume async\nbin/console messenger:consume async1\n```\n\nBut it works the same.\n\n========================================\n\nCode:\n```text\nmessenger:\n failure_transport: failed\n default_bus: command.bus\n transports:\n async:\n dsn: amqp://rabbitmq:rabbitmq@rabbitmq:5672\n options:\n retry_strategy:\n max_retries: 3\n delay: 1000\n multiplier: 2\n max_delay: 0\n exchange:\n name: olimp\n type: topic\n queues:\n create_miniature_v1:\n binding_keys:\n - first\n create_miniature_v2:\n binding_keys:\n - first\n failed:\n dsn: amqp://rabbitmq:rabbitmq@rabbitmq:5672\n options:\n exchange:\n name: olimp_dead\n type: topic\n queues:\n create_miniature_v1_dlq:\n binding_keys:\n - first\n create_miniature_v2_dlq:\n binding_keys:\n - first\n\n routing:\n 'Olimp\\Messenger\\TestEvent': async\n\n buses:\n command.bus:\n middleware:\n - Olimp\\Shared\\Application\\Message\\Middleware\\EventDispatcher\n - doctrine_close_connection\n - doctrine_transaction\n\n event.bus:\n default_middleware: allow_no_handlers\n\n query.bus: ~\n```\n\n```text\nclass MessengerTestCommand extends Command\n{\n protected static $defaultName = 'app:messenger-test';\n private MessageBusInterface $bus;\n\n public function __construct(MessageBusInterface $bus)\n {\n $this->bus = $bus;\n\n parent::__construct();\n }\n\n protected function execute(InputInterface $input, OutputInterface $output): int\n {\n $io = new SymfonyStyle($input, $output);\n\n $this->bus->dispatch(\n new TestEvent(), [\n new AmqpStamp('first')\n ]\n );\n\n $io->success('Done');\n\n return 0;\n }\n}\n```\n\n```text\nclass TestEventHandler implements MessageHandlerInterface\n{\n public function __invoke(TestEvent $event)\n {\n dump($event->id);\n\n throw new \\Exception('Boom');\n }\n}\n```\n\n```text\nframework:\n messenger:\n failure_transport: failed\n default_bus: command.bus\n transports:\n async:\n dsn: amqp://rabbitmq:rabbitmq@rabbitmq:5672\n options:\n retry_strategy:\n max_retries: 3\n delay: 1000\n multiplier: 2\n max_delay: 0\n exchange:\n name: olimp\n type: topic\n queues:\n create_miniature_v1:\n binding_keys:\n - first\n async1:\n dsn: amqp://rabbitmq:rabbitmq@rabbitmq:5672\n options:\n retry_strategy:\n max_retries: 3\n delay: 1000\n multiplier: 2\n max_delay: 0\n exchange:\n name: olimp\n type: topic\n queues:\n create_miniature_v2:\n binding_keys:\n - first\n failed:\n dsn: amqp://rabbitmq:rabbitmq@rabbitmq:5672\n options:\n exchange:\n name: olimp_dead\n type: topic\n queues:\n create_miniature_v1_dlq:\n binding_keys:\n - first\n create_miniature_v2_dlq:\n binding_keys:\n - first\n\n routing:\n 'Olimp\\Messenger\\TestEvent': [async, async1]\n```\n\n```text\nbin/console messenger:consume async\nbin/console messenger:consume async1\n```\n\n```text\nqueues:\n create_miniature_v1:\n binding_keys:\n - create_miniature_v1\n - first\n create_miniature_v2:\n binding_keys:\n - create_miniature_v2\n - first\n```\n\n```text\nqueues:\n create_miniature_v1_dlq:\n binding_keys:\n - create_miniature_v1\n create_miniature_v2_dlq:\n binding_keys:\n - create_miniature_v2\n```\n\n```text\nqueue_name_pattern\n```\n\n```text\n%routing_key%_%delay%\n```\n\n```text\nSendFailedMessageForRetryListener\n```\n\n```text\nnew AmqpStamp($envelope->last(AmqpReceivedStamp::class)->getQueueName())\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.173Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":11,"totalLines":374,"estimatedTokens":2060}}580{"id":"stack-34209249","source":"stackoverflow","questionId":34209249,"title":"Headers exchange example using RabbitMQ in Node.js","tags":["javascript","node.js","express","rabbitmq","amqp"],"text":"Title: Headers exchange example using RabbitMQ in Node.js\nTags: javascript, node.js, express, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI have been looking everywhere for a `headers exchange` example using **RabbitMQ** in **Node.js**. If someone could point me in the right direction, that would be great. Here's what I have so far:\n\n**publisher method** (create a publisher)\n\n```\nRabbitMQ.prototype.publisher = function(exchange, type) {\n console.log('New publisher, exchange: '+exchange+', type: '+type);\n amqp.then(function(conn) {\n conn.createConfirmChannel().then(function(ch) {\n publishers[exchange] = {};\n publishers[exchange].assert = ch.assertExchange(exchange, type, {durable: true});\n publishers[exchange].ch = ch;\n });\n },function(err){\n console.error(\"[AMQP]\", err.message);\n return setTimeout(function(){\n self.connect(URI);\n }, 1000);\n }).then(null, console.log);\n};\n```\n\n**publish method**\n\n```\nRabbitMQ.prototype.publish = function(exchange, routingKey, content, headers) {\n try { \n publishers[exchange].assert.then(function(){\n publishers[exchange].ch.publish(exchange, routingKey, new Buffer(content), { persistent: true, headers: headers }, function(err, ok) {\n if (err) {\n console.error(\"[AMQP] publish\", err);\n offlinePubQueue.push([exchange, routingKey, content]);\n publishers[exchange].ch.connection.close();\n }\n });\n });\n } catch (e) { \n console.error(\"[AMQP] publish\", e.message);\n offlinePubQueue.push([exchange, routingKey, content]);\n }\n};\n```\n\n**consumer method** (create a consumer)\n\n```\nRabbitMQ.prototype.consumer = function(exchange, type, routingKey, cb) {\n amqp.then(function(conn) {\n conn.createChannel().then(function(ch) {\n\n var ok = ch.assertExchange(exchange, type, {durable: true});\n\n ok.then(function() {\n ch.assertQueue('', {exclusive: true});\n });\n\n ok = ok.then(function(qok) {\n var queue = qok.queue;\n ch.bindQueue(queue,exchange,routingKey)\n });\n\n ok = ok.then(function(queue) {\n ch.consume(queue, function(msg){\n cb(msg,ch);\n }, {noAck: false});\n });\n\n ok.then(function() {\n console.log(' [*] Waiting for logs. To exit press CTRL+C.');\n });\n\n });\n }).then(null, console.warn);\n};\n```\n\nThe above example works fine with `topics`, but I'm not sure how to make the transition to `headers`. I am pretty sure I need to change my binding approach, but haven't been able to find any examples on how exactly to accomplish this.\n\nAny help would be greatly appreciated!\n\n========================================\n\nCode:\n```text\nRabbitMQ.prototype.publisher = function(exchange, type) {\n console.log('New publisher, exchange: '+exchange+', type: '+type);\n amqp.then(function(conn) {\n conn.createConfirmChannel().then(function(ch) {\n publishers[exchange] = {};\n publishers[exchange].assert = ch.assertExchange(exchange, type, {durable: true});\n publishers[exchange].ch = ch;\n });\n },function(err){\n console.error(\"[AMQP]\", err.message);\n return setTimeout(function(){\n self.connect(URI);\n }, 1000);\n }).then(null, console.log);\n};\n```\n\n```text\nRabbitMQ.prototype.publish = function(exchange, routingKey, content, headers) {\n try { \n publishers[exchange].assert.then(function(){\n publishers[exchange].ch.publish(exchange, routingKey, new Buffer(content), { persistent: true, headers: headers }, function(err, ok) {\n if (err) {\n console.error(\"[AMQP] publish\", err);\n offlinePubQueue.push([exchange, routingKey, content]);\n publishers[exchange].ch.connection.close();\n }\n });\n });\n } catch (e) { \n console.error(\"[AMQP] publish\", e.message);\n offlinePubQueue.push([exchange, routingKey, content]);\n }\n};\n```\n\n```text\nRabbitMQ.prototype.consumer = function(exchange, type, routingKey, cb) {\n amqp.then(function(conn) {\n conn.createChannel().then(function(ch) {\n\n var ok = ch.assertExchange(exchange, type, {durable: true});\n\n ok.then(function() {\n ch.assertQueue('', {exclusive: true});\n });\n\n ok = ok.then(function(qok) {\n var queue = qok.queue;\n ch.bindQueue(queue,exchange,routingKey)\n });\n\n ok = ok.then(function(queue) {\n ch.consume(queue, function(msg){\n cb(msg,ch);\n }, {noAck: false});\n });\n\n ok.then(function() {\n console.log(' [*] Waiting for logs. To exit press CTRL+C.');\n });\n\n });\n }).then(null, console.warn);\n};\n```\n\n```text\nheaders exchange\n```\n\n```text\ntopics\n```\n\n```text\nheaders\n```\n\n```text\n...\nlet opts = { headers: { 'asd': 'request', 'efg': 'test' }};\nchan.publish(XCHANGE, '', Buffer.from(output), opts);\n...\n```\n\n```text\n...\nlet opts = { 'asd': 'request', 'efg': 'test', 'x-match': 'all' };\nchan.bindQueue(q.queue, XCHANGE, '', opts);\n...\n```\n\n```js\n#!/usr/bin/env node\n\nconst XCHANGE = 'headers-exchange';\n\nconst Q = require('q');\nconst Broker = require('amqplib');\n\nlet scope = 'anonymous';\n\nprocess.on('uncaughtException', (exception) => {\n console.error(`\"::ERROR:: Uncaught exception ${exception}`);\n});\n\nprocess.argv.slice(2).forEach((arg) =>\n{\n scope = arg;\n console.info('[*] Scope now set to ' + scope);\n});\n\nQ.spawn(function*()\n{\n let conn = yield Broker.connect('amqp://root:root@localhost');\n let chan = yield conn.createChannel();\n\n chan.assertExchange(XCHANGE, 'headers', { durable: false });\n\n for(let count=0;; count=++count%3)\n {\n let output = (new Date()).toString();\n let opts = { headers: { 'asd': 'request', 'efg': 'test' }};\n chan.publish(XCHANGE, '', Buffer.from(output), opts);\n console.log(`[x] Published item \"${output}\" to <${XCHANGE} : ${JSON.stringify(opts)}>`);\n\n yield Q.delay(500);\n }\n});\n```\n\n```js\n#!/usr/bin/env node\n\nconst Q = require('q');\nconst Broker = require('amqplib');\nconst uuid = require('node-uuid');\nconst Rx = require('rx');\n\nRx.Node = require('rx-node');\n\nconst XCHANGE = 'headers-exchange';\nconst WORKER_ID = uuid.v4();\nconst WORKER_SHORT_ID = WORKER_ID.substr(0, 4);\n\nQ.spawn(function*() {\n let conn = yield Broker.connect('amqp://root:root@localhost');\n let chan = yield conn.createChannel();\n\n chan.assertExchange(XCHANGE, 'headers', { durable: false });\n\n let q = yield chan.assertQueue('', { exclusive: true });\n let opts = { 'asd': 'request', 'efg': 'test', 'x-match': 'all' };\n\n chan.bindQueue(q.queue, XCHANGE, '', opts);\n console.info('[*] Binding with ' + JSON.stringify(opts));\n\n console.log(`[*] Subscriber ${WORKER_ID} (${WORKER_SHORT_ID}) is online!`);\n\n chan.consume(q.queue, (msg) =>\n {\n console.info(`[x](${WORKER_SHORT_ID}) Received pub \"${msg.content.toString()}\"`);\n chan.ack(msg);\n });\n});\n```\n\n```text\nx-\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.173Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":11,"totalLines":260,"estimatedTokens":1702}}581{"id":"stack-12518685","source":"stackoverflow","questionId":12518685,"title":"Performance Penalty of Multiple VHosts in rabbitmq?","tags":["rabbitmq"],"text":"Title: Performance Penalty of Multiple VHosts in rabbitmq?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nIs there a performance penalty to run many vhosts as opposed to many exchanges? I have to support thousands of different clients, and I am trying to decide whether each client should receive its own vhost, or I should have one vhost and each client gets its own exchange. Which is the better choice vis-a-vis performance and resource utilization?","metadata":{"transformedAt":"2026-08-18T18:33:20.173Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":6,"estimatedTokens":114}}582{"id":"stack-22947234","source":"stackoverflow","questionId":22947234,"title":"RabbitMQ mirroring queues and exchanges","tags":["rabbitmq","rabbitmq-exchange"],"text":"Title: RabbitMQ mirroring queues and exchanges\nTags: rabbitmq, rabbitmq-exchange\nSource: Stack Overflow\n\nQuestion:\nIs it possible to use federations or shovels to mirror the creation of exchanges and queues on one server to another ?\n\nAll the examples I've seen of using shovels and federations use exchanges and queues that already exist on the servers. What I want to do is create an exchange on server A and have a federation or shovel re-create it on Server B then start to send messages to it.\n\nIf this cannot be done with a federation or shovel is there anyway of achieving this without using clustering, the connection between the two servers is not consistent so clustering isn't possible.\n\nI'm running RabbitMQ on windows.\n\n========================================\n\nTop Answer:\nUnfortunately in this way it is not possible to do this, because the connection is a point-to-point connection. You have to link a exchange with a remote exchange and in your topology this cant be created automatically.\n\nI had also this problem in the past. And how i resolved the problem was over a business logic side. If there was a need for a new Exchange/Queue \"on the fly\", my data input gateway recognized this and created on the local and on the remote exchange the new exchange and queues with the connection, before the message was sent to RabbitMQ.\n\n========================================\n\nCode:\n```text\nName: my_policy \nPattern: ^mirr\\. <---- mirror exchanges and queues with prefix “mirr.” \nDefinition: federation-upstream-set:all\n```\n\n========================================\n\nComments:\n- Do you need a bidirectional mirror?\n- BTW, while this is nifty solution I would add following from the documentation `The bindings are sent upstream asynchronously - so the effect of adding or removing a binding is only guaranteed to be seen eventually`\n- Yes, thank you @zaq178miami ! It's a big difference from the mirror with the cluster!\n- federated queues are actually quite a new option. @OP: what RabbitMQ version are you using?\n- Thanks Gas, looks like I bought the wrong RabbingMQ book :)\n- You are welcome :)! Maybe the book are you reading is a bit old.\n- The exchanges/queues are created, but a queue normally has a binding to an exchange and this is not recreated. So e.g.: rabbit1: Ex1 <- Q1, rabbit2: Ex1 (without binding to) Q1, Q1 on rabbit2 is federated from rabbit1 and auto created, but the binding to Ex1 is missing, how you solve this?","metadata":{"transformedAt":"2026-08-18T18:33:20.173Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":39,"estimatedTokens":613}}583{"id":"stack-54457496","source":"stackoverflow","questionId":54457496,"title":"rabbitmq throws the AmqpException: No method found for class [B","tags":["java","spring-boot","rabbitmq"],"text":"Title: rabbitmq throws the AmqpException: No method found for class [B\nTags: java, spring-boot, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nWhen I send a message to the RabbitMQ, then it throws a AmqpException for loop:\n\n```\norg.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException\n\n : Listener method 'no match' threw exception\n at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:198) ~[spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.onMessage(MessagingMessageListenerAdapter.java:127) ~[spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1521) ~[spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1444) ~[spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1431) ~[spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1410) ~[spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:848) [spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:832) [spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$700(SimpleMessageListenerContainer.java:78) [spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1073) [spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at java.lang.Thread.run(Thread.java:748) [na:1.8.0_152]\n Caused by: org.springframework.amqp.AmqpException: No method found for class [B\n at org.springframework.amqp.rabbit.listener.adapter.DelegatingInvocableHandler.getHandlerForPayload(DelegatingInvocableHandler.java:149) ~[spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.adapter.DelegatingInvocableHandler.invoke(DelegatingInvocableHandler.java:129) ~[spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.adapter.HandlerAdapter.invoke(HandlerAdapter.java:60) ~[spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:190) ~[spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n ... 10 common frames omitted\n```\n\nI tried to add class-level @RabbitListener but it didn't work\n\n```\n@Component\n@RabbitListener(queues = \"test\", containerFactory=\"rabbitListenerContainerFactory\")\npublic class ReceiverTwo {\n\n @RabbitHandler\n public void process(String message) {\n System.out.println(\"Receiver: \" + message);\n }\n}\n```\n\nThe PRODUCER side :\n\n```\n@Test\npublic void publishTest() throws IOException {\n channel.exchangeDeclare(\"testExchange\", \"direct\", true);\n channel.queueBind(\"many\", \"testExchange\", \"many\");\n String message = \"The test message\";\n channel.basicPublish(\"testExchange\", \"test\",null, message.getBytes());\n}\n```\n\nThe CONSUMER side :\n\n```\n@Component\n@RabbitListener(queues = \"test\")\npublic class ReceiverTwo {\n @RabbitHandler\n public void process(String message) {\n System.out.println(\"Receiver: \" + message);\n }\n}\n```\n\n========================================\n\nTop Answer:\nIn my case, I have passed a different class to the publisher and expected a different class as listener.\n\n========================================\n\nCode:\n```text\norg.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException\n\n : Listener method 'no match' threw exception\n at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:198) ~[spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.onMessage(MessagingMessageListenerAdapter.java:127) ~[spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1521) ~[spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1444) ~[spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1431) ~[spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1410) ~[spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:848) [spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:832) [spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$700(SimpleMessageListenerContainer.java:78) [spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1073) [spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at java.lang.Thread.run(Thread.java:748) [na:1.8.0_152]\n Caused by: org.springframework.amqp.AmqpException: No method found for class [B\n at org.springframework.amqp.rabbit.listener.adapter.DelegatingInvocableHandler.getHandlerForPayload(DelegatingInvocableHandler.java:149) ~[spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.adapter.DelegatingInvocableHandler.invoke(DelegatingInvocableHandler.java:129) ~[spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.adapter.HandlerAdapter.invoke(HandlerAdapter.java:60) ~[spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:190) ~[spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE]\n ... 10 common frames omitted\n```\n\n```text\n@Component\n@RabbitListener(queues = \"test\", containerFactory=\"rabbitListenerContainerFactory\")\npublic class ReceiverTwo {\n\n @RabbitHandler\n public void process(String message) {\n System.out.println(\"Receiver: \" + message);\n }\n}\n```\n\n```text\n@Test\npublic void publishTest() throws IOException {\n channel.exchangeDeclare(\"testExchange\", \"direct\", true);\n channel.queueBind(\"many\", \"testExchange\", \"many\");\n String message = \"The test message\";\n channel.basicPublish(\"testExchange\", \"test\",null, message.getBytes());\n}\n```\n\n```text\n@Component\n@RabbitListener(queues = \"test\")\npublic class ReceiverTwo {\n @RabbitHandler\n public void process(String message) {\n System.out.println(\"Receiver: \" + message);\n }\n}\n```\n\n```text\nMessageProperties messageProperties = new MessageProperties();\nmessageProperties.setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN);\nmessageProperties.setContentEncoding(this.defaultCharset);\n```\n\n```text\nchannel.basicPublish(\"testExchange\", \"test\", messageProperties, message.getBytes());\n```\n\n```text\nprocess(String message)\n```\n\n```text\nprocess(byte[] message)\n```\n\n```text\nSimpleMessageConverter.createMessage\n```\n\n```text\nRabbitTemplate\n```\n\n========================================\n\nComments:\n- Thank you for your answer and it worked well. And I found another solution: AMQP.BasicProperties.Builder builder = new AMQP.BasicProperties.Builder().contentEncoding(\"UTF-8\").cont‌​entType(\"text/plain\"‌​); channel.basicPublish(\"testExchange\", \"many\",builder.build(), message.getBytes());\n- To quote from a classic \"Short Circuit\": \"Newton Crosby : It's a machine... It just runs programs.\" :) I had a similar situation but when I looked what's the difference, it turned out the clients that were sending messages were different. A Spring client worked fine while a Python client didn't have all message parameters set correctly, specifically: content_type='text/plain' and content_encoding='utf-8'","metadata":{"transformedAt":"2026-08-18T18:33:20.173Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":164,"estimatedTokens":2279}}584{"id":"stack-11974734","source":"stackoverflow","questionId":11974734,"title":"Rabbitmq listen to UDP connection","tags":["message-queue","rabbitmq"],"text":"Title: Rabbitmq listen to UDP connection\nTags: message-queue, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nIs there a way to have RabbitMQ listen for UDP connections and put those packets into somesort of default queue which can then be pulled from by a standard client? Would ActiveMQ or ZeroMQ be better for this?\n\n========================================\n\nTop Answer:\nSomeone also built a udp-exchange plugin for rabbitMQ.\nI haven't personally used this, but it seems like it would do the job for you without having to write your own udp to amqp forwarder ..\n\nhttps://github.com/tonyg/udp-exchange\n\nhere's the excerpt\n\n Extends RabbitMQ Server with support for a new experimental exchange type, x-udp. \n Each created x-udp exchange listens on a specified UDP port for incoming messages, and relays them on to the queues bound to the exchange. It also takes messages published to the exchange and relays them on to a specified IP address and UDP port.\n\n========================================\n\nComments:\n- This is what i ended up doing and its worked out nicely Thanks!","metadata":{"transformedAt":"2026-08-18T18:33:20.173Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":24,"estimatedTokens":268}}585{"id":"stack-34809946","source":"stackoverflow","questionId":34809946,"title":"Rabbit MQ Filtering","tags":["rabbitmq"],"text":"Title: Rabbit MQ Filtering\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nWe have a RabbitMQ exchange that is exchanging messages between several components of our system.\n\nEach component is both a publisher and subscriber of the exchange.\n\nWe need to find a way of ensuring that each application does not receive messages it sends into the exchange.\n\nFor example.\n\nApp 1 sends a refresh message. We want this to go to all subscribers of the exchange apart from App 1\n\nI can see that you can specify routing attributes, but this seems to define the messages you WANT not the ones you DO NOT WANT.\n\nAny ideas?\n\n========================================\n\nTop Answer:\nYou can assign individual routing keys for each component (e.g. `app1`, `app2`, `app3`, ...) and subscribe each component to all other routing keys excepts its own.\n\nSo when App 1 sends a message it will send it with routing key `app1` but it is subscribed only to `app2`, `app3`, ....\n\n========================================\n\nCode:\n```text\napp1\n```\n\n```text\napp2\n```\n\n```text\napp3\n```\n\n```text\napp1\n```\n\n```text\napp2\n```\n\n```text\napp3\n```\n\n========================================\n\nComments:\n- did think this would be the case, but just wanted to check there was not something within RMQ that did it first. Redesign is not an option, as this message is a cache-reset message that indicates that the database has been updated and all nodes should drop their local cache of that type. as such has to both subscribe and listen\n- Is it possible to include to back message from consumer some data? And store that in queue or get on server and store in db?\n- What about the case of reducing mirrored traffic to a testing consumer? We've used one upstream exchange to publish to both a testing and production environment but would like to reduce costs and filter out a portion of the stream from within RabbitMQ.\n- agree this would work, but our app will potentially have hundreds of nodes so statically defining them is not an option.\n- Then you should probably go with the solution proposed by @Derick Bailey. At least, I don't know any other options.","metadata":{"transformedAt":"2026-08-18T18:33:20.173Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":61,"estimatedTokens":529}}586{"id":"stack-22486686","source":"stackoverflow","questionId":22486686,"title":"Why we use logstash_formatter package in Python?","tags":["python","json","rabbitmq","logstash"],"text":"Title: Why we use logstash_formatter package in Python?\nTags: python, json, rabbitmq, logstash\nSource: Stack Overflow\n\nQuestion:\nI am using `logstash_formatter` python module for sending formatted logs to logstash. The `logstash_formatter` is converting my passed dictionary to a JSON string. My application is then writing this JSON message to the `audit_log` file. `logstash agent` is reading the this log file and sending the JSON data into the RabbitMQ. \n\nBefore installing the `logstash_formatter` package from https://pypi.python.org/pypi/logstash_formatter I expected that since this formatter is passing JSON message to the RabbitMQ indexer, I don't have to add filters to my `shipper.conf` file for my logstash agent running on my machine. All the JSON fields will automatically be added as tags or fields to logstash and will appear same as a filter in Kibana.\n\nBut nothing like that happened, I still have to add the filters into my `shipper.conf` file. Actually the log message is coming as a message field/tag in the logstash reply. \n\nNow I feel that there is no need of using this package. I would have instead create a dict on my own and converted it to JSON using `json` module.\n\nKindly guide me if I am missing something or my understanding about this formatter is totally wrong.\n\n========================================\n\nCode:\n```text\nlogstash_formatter\n```\n\n```text\nlogstash_formatter\n```\n\n```text\naudit_log\n```\n\n```text\nlogstash agent\n```\n\n```text\nlogstash_formatter\n```\n\n```text\nshipper.conf\n```\n\n```text\nshipper.conf\n```\n\n```text\njson\n```\n\n========================================\n\nComments:\n- Sure I will have a look!\n- Did you take a look? Still need help?","metadata":{"transformedAt":"2026-08-18T18:33:20.173Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":55,"estimatedTokens":421}}587{"id":"stack-15220736","source":"stackoverflow","questionId":15220736,"title":"RabbitMQ Management Plugin Web Server","tags":["rabbitmq"],"text":"Title: RabbitMQ Management Plugin Web Server\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI've installed a RabbitMQ cluster on EC2 nodes. The cluster is up and running. I'm trying to get the rabbitmq_management plugin running. I installed the rabbitmq_management plugin on all cluster nodes.\n\nRabbitMQ V 3.02, Ubuntu server 12.04\n\nPlugins enabled:\n\n```\n[e] amqp_client 3.0.2\n[e] mochiweb 2.3.1-rmq3.0.2-gitd541e9a\n[E] rabbitmq_management 3.0.2\n[e] rabbitmq_management_agent 3.0.2\n[e] rabbitmq_mochiweb 3.0.2\n[e] webmachine 1.9.1-rmq3.0.2-git52e62bc\n```\n\nAfter restarting rabbitmq_server, running applications:\n\n```\n{running_applications,[{rabbit,\"RabbitMQ\",\"3.0.2\"},\n {os_mon,\"CPO CXC 138 46\",\"2.2.7\"},\n {mnesia,\"MNESIA CXC 138 12\",\"4.5\"},\n {sasl,\"SASL CXC 138 11\",\"2.1.10\"},\n {stdlib,\"ERTS CXC 138 10\",\"1.17.5\"},\n {kernel,\"ERTS CXC 138 10\",\"2.14.5\"}]},\n```\n\n`http://hostname:15672` does not load (the port is open in the EC2 security group). \n\nIt appears that the web server is not running. I restarted the service after installing the management plugin, and do not see any errors in startup_log. startup_err is empty. \n\nSuggestions on where to go from here?\n\nUPDATE:\n\nRebooting the nodes entirely worked. So presumably there was something I did not shut down properly before restarting the first time. \n\nAny insight would still be welcome.\n\n========================================\n\nCode:\n```text\n[e] amqp_client 3.0.2\n[e] mochiweb 2.3.1-rmq3.0.2-gitd541e9a\n[E] rabbitmq_management 3.0.2\n[e] rabbitmq_management_agent 3.0.2\n[e] rabbitmq_mochiweb 3.0.2\n[e] webmachine 1.9.1-rmq3.0.2-git52e62bc\n```\n\n```text\n{running_applications,[{rabbit,\"RabbitMQ\",\"3.0.2\"},\n {os_mon,\"CPO CXC 138 46\",\"2.2.7\"},\n {mnesia,\"MNESIA CXC 138 12\",\"4.5\"},\n {sasl,\"SASL CXC 138 11\",\"2.1.10\"},\n {stdlib,\"ERTS CXC 138 10\",\"1.17.5\"},\n {kernel,\"ERTS CXC 138 10\",\"2.14.5\"}]},\n```\n\n```text\nhttp://hostname:15672\n```\n\n```text\nsudo rabbitmqctl stop\nsudo invoke-rc.d rabbitmq-server start\n```\n\n========================================\n\nComments:\n- I'm currently having the same problem, any suggestions on how I can fix this? Reboot the instance perhaps?\n- Unless it states further in the documents, I didn't see a restart required for the plugin to work. However, I had to use the stop/start from your answer, and now it's loading. You can accept your own answer.\n- Two things - a restart of RabbitMQ should not be necessary, and you are using an **ancient** version of RabbitMQ. Please be sure to run the recommended versions of Erlang and RabbitMQ to avoid issues going forward!!!","metadata":{"transformedAt":"2026-08-18T18:33:20.173Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":79,"estimatedTokens":696}}588{"id":"stack-17868592","source":"stackoverflow","questionId":17868592,"title":"MassTransit: specify uri with virtualhost","tags":["rabbitmq","masstransit"],"text":"Title: MassTransit: specify uri with virtualhost\nTags: rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nI am using **MassTransit** with **RabbitMQ** and I would like to take advantage of **RabbitMQ** virtual hosts. Other apps in my organization (not using MassTransit) have a convention of setting up virtual hosts for environments i.e. \"myapp\" and \"myappUAT\". \nI need to this convention, but I can't figure out how to specify a virtual host in my MassTransit uri.\n\nIs this possible? If so how can I do it?\n\n========================================\n\nCode:\n```text\nrabbitmq://localhost/vhost_name/queue_name\n```\n\n========================================\n\nComments:\n- What if there are no vhosts? And I want to send to a direct exchange with a routing key for example? Following should work because I tested it and it sends to the exchange and not the queue: `rabbitmq://localhost/exchange_name`","metadata":{"transformedAt":"2026-08-18T18:33:20.173Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":21,"estimatedTokens":228}}589{"id":"stack-45679594","source":"stackoverflow","questionId":45679594,"title":"RabbitMQ not receiving messages when used with TopShelf as a Windows Service","tags":["c#",".net","windows-services","rabbitmq"],"text":"Title: RabbitMQ not receiving messages when used with TopShelf as a Windows Service\nTags: c#, .net, windows-services, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm trying to convert my RabbitMQ micro-service to a windows service. I have used TopShelf for the conversion. My RabbitMQ micro-service works perfectly fine on its own but when I run it as a service it no longer receives messages. In my `public static void Main(string[] args)` I have:\n\n```\nHostFactory.Run(host =>\n {\n host.Service(s => \n {\n s.ConstructUsing(name => new PersonService());\n s.WhenStarted(tc => tc.Start()); \n s.WhenStopped(tc => tc.Stop()); \n });\n host.SetDescription(\"Windows service that provides database access totables.\"); \n host.SetDisplayName(\"Service\"); \n host.SetServiceName(\"Service\");\n });\n }\n```\n\nThen in my `PersonService` class I have \n\n```\npublic void Start() {\n ConsumeMessage();\n }\n```\n\nAnd finally my `ConsumeMessage` function:\n\n```\nprivate static void ConsumeMessage() {\n MessagingConfig.SetInstance(new MessagingConstants());\n IMessageFactory pmfInst = MessageFactory.Instance;\n\n //message worker\n var factory = new ConnectionFactory() {\n HostName = MessagingConfig.Instance.GetBrokerHostName(),\n UserName = MessagingConfig.Instance.GetBrokerUserName(),\n Password = MessagingConfig.Instance.GetBrokerPassword()\n };\n\n var connection = factory.CreateConnection();\n\n using (var channel = connection.CreateModel()) {\n channel.QueueDeclare(queue: MessagingConfig.Instance.GetServiceQueueName(),\n durable: true,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n\n channel.BasicQos(0, 1, false);\n\n var consumer = new EventingBasicConsumer(channel);\n\n channel.BasicConsume(queue: MessagingConfig.Instance.GetServiceQueueName(),\n noAck: false,\n consumer: consumer);\n\n Console.WriteLine(\"Service.\");\n Console.WriteLine(\" [x] Awaiting RPC requests\");\n\n // Code Below Is Not Executed In Service\n consumer.Received += (model, ea) => {\n\n string response = null;\n\n var body = ea.Body;\n var props = ea.BasicProperties;\n var replyProps = channel.CreateBasicProperties();\n replyProps.CorrelationId = props.CorrelationId;\n\n string receivedMessage = null;\n\n try {\n receivedMessage = Encoding.UTF8.GetString(body);\n response = ProcessMessage(receivedMessage);\n }\n catch (Exception e) {\n // Received message is not valid.\n WinLogger.Log.Error(\n \"Errror Processing Message: \" + receivedMessage + \" :\" + e.Message);\n\n response = \"\";\n }\n finally {\n\n var responseBytes = Encoding.UTF8.GetBytes(response);\n channel.BasicPublish(exchange: \"\", routingKey: props.ReplyTo,\n basicProperties: replyProps, body: responseBytes);\n channel.BasicAck(deliveryTag: ea.DeliveryTag,\n multiple: false);\n }\n };\n Console.ReadLine();\n }\n```\n\nLooking at A similar SO question it looks like it has something to do with the return the Windows Service is wanting, but I'm not sure of how to call `ConsumeMessage` so `consumer.Received += (model, ea) => {...};` is executed.\n\n**EDIT:** It looks like my blocking mechanism `Console.ReadLine();` is ignored by the service so it just continues on and disposes of the message consumer. So how do I block there for messages to be received?\n\n========================================\n\nCode:\n```text\nHostFactory.Run(host =>\n {\n host.Service<PersonService>(s => \n {\n s.ConstructUsing(name => new PersonService());\n s.WhenStarted(tc => tc.Start()); \n s.WhenStopped(tc => tc.Stop()); \n });\n host.SetDescription(\"Windows service that provides database access totables.\"); \n host.SetDisplayName(\"Service\"); \n host.SetServiceName(\"Service\");\n });\n }\n```\n\n```text\npublic void Start() {\n ConsumeMessage();\n }\n```\n\n```text\nprivate static void ConsumeMessage() {\n MessagingConfig.SetInstance(new MessagingConstants());\n IMessageFactory pmfInst = MessageFactory.Instance;\n\n //message worker\n var factory = new ConnectionFactory() {\n HostName = MessagingConfig.Instance.GetBrokerHostName(),\n UserName = MessagingConfig.Instance.GetBrokerUserName(),\n Password = MessagingConfig.Instance.GetBrokerPassword()\n };\n\n var connection = factory.CreateConnection();\n\n using (var channel = connection.CreateModel()) {\n channel.QueueDeclare(queue: MessagingConfig.Instance.GetServiceQueueName(),\n durable: true,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n\n channel.BasicQos(0, 1, false);\n\n var consumer = new EventingBasicConsumer(channel);\n\n channel.BasicConsume(queue: MessagingConfig.Instance.GetServiceQueueName(),\n noAck: false,\n consumer: consumer);\n\n Console.WriteLine(\"Service.\");\n Console.WriteLine(\" [x] Awaiting RPC requests\");\n\n\n // Code Below Is Not Executed In Service\n consumer.Received += (model, ea) => {\n\n string response = null;\n\n var body = ea.Body;\n var props = ea.BasicProperties;\n var replyProps = channel.CreateBasicProperties();\n replyProps.CorrelationId = props.CorrelationId;\n\n string receivedMessage = null;\n\n try {\n receivedMessage = Encoding.UTF8.GetString(body);\n response = ProcessMessage(receivedMessage);\n }\n catch (Exception e) {\n // Received message is not valid.\n WinLogger.Log.Error(\n \"Errror Processing Message: \" + receivedMessage + \" :\" + e.Message);\n\n response = \"\";\n }\n finally {\n\n var responseBytes = Encoding.UTF8.GetBytes(response);\n channel.BasicPublish(exchange: \"\", routingKey: props.ReplyTo,\n basicProperties: replyProps, body: responseBytes);\n channel.BasicAck(deliveryTag: ea.DeliveryTag,\n multiple: false);\n }\n };\n Console.ReadLine();\n }\n```\n\n```text\npublic static void Main(string[] args)\n```\n\n```text\nPersonService\n```\n\n```text\nConsumeMessage\n```\n\n```text\nConsumeMessage\n```\n\n```text\nconsumer.Received += (model, ea) => {...};\n```\n\n```text\nConsole.ReadLine();\n```\n\n```text\nthis.connection = factory.CreateConnection();\n\nthis.channel = connection.CreateModel();\nthis.consumer = new EventingBasicConsumer(this.channel);\n```\n\n```text\nusing\n```\n\n```text\nOnStart\n```\n\n```text\nchannel\n```\n\n```text\nOnStart\n```\n\n```text\nchannel\n```\n\n```text\nconsumer\n```\n\n```text\nusing\n```\n\n```text\nOnStart\n```\n\n```text\nOnStop\n```\n\n========================================\n\nComments:\n- Since I'm using Topshelf I have `tc => tc.Start();` as noted above, which I assume is the same as `OnStart`? So If I understand you correctly, 1. make connection, channel, and consumer class members, 2. initialize in Start(), then in `ConsumeMessage` keep `consumer.Received += (model, ea) => {...}` the way it is? What is stopping `ConsumeMessage` from finishing and taking `consumer.Received += (model, ea) => {...}` out of scope?\n- yes, your problem is really in the `using` statement - after your code passes its curly bracket just before `Console.ReadLine()` your channel is disposed and you won't have any messages\n- So I made class members `private IConnection connection; private EventingBasicConsumer consumer; private IModel channel;` moved initialization to `Start()` and removed `using (var channel = connection.CreateModel()) {` When I execute it as command line app my results return but if I run it as a service not it returns 404, so it somewhat fixed the problem, let me try again tomorrow to see if I can fix it and accept your answer\n- To allow the windows service access to the DB I had to go to properties for the service, Log On, and choose This Account and enter my credentials","metadata":{"transformedAt":"2026-08-18T18:33:20.173Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":19,"totalLines":273,"estimatedTokens":2075}}590{"id":"stack-31806428","source":"stackoverflow","questionId":31806428,"title":"Celery error : result.get times out","tags":["python","linux","redis","rabbitmq","celery"],"text":"Title: Celery error : result.get times out\nTags: python, linux, redis, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI've installed Celery and I'm trying to test it with the Celery First Steps Doc.\n\nI tried using both Redis and RabbitMQ as brokers and backends, but I can't get the result with : \n\n```\nresult.get(timeout = 10)\n```\n\nEach time, I get this error :\n\n```\nTraceback (most recent call last):\n File \"\", line 11, in \n File \"/home/mehdi/.virtualenvs/python3/lib/python3.4/site-packages/celery/result.py\", line 169, in get\n no_ack=no_ack,\n File \"/home/mehdi/.virtualenvs/python3/lib/python3.4/site-packages/celery/backends/base.py\", line 225, in wait_for\n raise TimeoutError('The operation timed out.')\ncelery.exceptions.TimeoutError: The operation timed out.\n```\n\nThe broker part seems to work just fine : when I run this code\n\n```\nfrom celery import Celery\n\napp = Celery('tasks', backend='redis://localhost/', broker='amqp://')\n\n@app.task\ndef add(x, y):\n return x + y\n\nresult = add.delay(4,4)\n```\n\nI get (as expected)\n\n [2015-08-04 12:05:44,910: INFO/MainProcess] Received task:\n tasks.add[741160b8-cb7b-4e63-93c3-f5e43f8f8a02] \n\n \n [2015-08-04 12:05:44,911: INFO/MainProcess] Task\n tasks.add[741160b8-cb7b-4e63-93c3-f5e43f8f8a02] succeeded in\n 0.0004287530000510742s: 8\n\nP.S : I'm using Xubuntu 64bit\n\nEDIT :\n\nMy app.conf \n\n```\n{'CELERY_RESULT_DB_TABLENAMES': None, \n'BROKER_TRANSPORT_OPTIONS': {}, \n'BROKER_USE_SSL': False, \n'CELERY_BROADCAST_QUEUE': 'celeryctl', \n'EMAIL_USE_TLS': False, \n'CELERY_STORE_ERRORS_EVEN_IF_IGNORED': False, \n'CELERY_CREATE_MISSING_QUEUES': True, \n'CELERY_DEFAULT_QUEUE': 'celery', \n'CELERY_SEND_TASK_SENT_EVENT': False, \n'CELERYD_TASK_TIME_LIMIT': None, \n'BROKER_URL': 'amqp://', \n'CELERY_EVENT_QUEUE_EXPIRES': None, \n'CELERY_DEFAULT_EXCHANGE_TYPE': 'direct', \n'CELERYBEAT_SCHEDULER': 'celery.beat:PersistentScheduler', \n'CELERY_MAX_CACHED_RESULTS': 100, \n'CELERY_RESULT_PERSISTENT': None, \n'CELERYD_POOL': 'prefork', \n'CELERYD_AGENT': None, \n'EMAIL_HOST': 'localhost', \n'CELERY_CACHE_BACKEND_OPTIONS': {}, \n'BROKER_HEARTBEAT': None, \n'CELERY_RESULT_ENGINE_OPTIONS': None, \n'CELERY_RESULT_SERIALIZER': 'pickle', \n'CELERYBEAT_SCHEDULE_FILENAME': 'celerybeat-schedule', \n'CELERY_REDIRECT_STDOUTS_LEVEL': 'WARNING', \n'CELERY_IMPORTS': (), \n'SERVER_EMAIL': 'celery@localhost', \n'CELERYD_TASK_LOG_FORMAT': '[%(asctime)s: %(levelname)s/%(processName)s] %(task_name)s[%(task_id)s]: %(message)s', \n'CELERY_SECURITY_CERTIFICATE': None, \n'CELERYD_LOG_COLOR': None, \n'CELERY_RESULT_EXCHANGE': 'celeryresults', \n'CELERY_TRACK_STARTED': False, \n'CELERY_REDIS_PASSWORD': None, \n'BROKER_USER': None, \n'CELERY_COUCHBASE_BACKEND_SETTINGS': None, \n'CELERY_RESULT_EXCHANGE_TYPE': 'direct', \n'CELERY_REDIS_DB': None, \n'CELERYD_TIMER_PRECISION': 1.0, \n'CELERY_REDIS_PORT': None, \n'BROKER_TRANSPORT': None, \n'CELERYMON_LOG_FILE': None, \n'CELERYD_CONCURRENCY': 0, \n'CELERYD_HIJACK_ROOT_LOGGER': True, \n'BROKER_VHOST': None, \n'CELERY_DEFAULT_EXCHANGE': 'celery', \n'CELERY_DEFAULT_ROUTING_KEY': 'celery', \n'CELERY_ALWAYS_EAGER': False, \n'EMAIL_TIMEOUT': 2, \n'CELERYD_TASK_SOFT_TIME_LIMIT': None, \n'CELERY_WORKER_DIRECT': False, \n'CELERY_REDIS_HOST': None, \n'CELERY_QUEUE_HA_POLICY': None, \n'BROKER_PORT': None, \n'CELERYD_AUTORELOADER': 'celery.worker.autoreload:Autoreloader', \n'BROKER_CONNECTION_TIMEOUT': 4, \n'CELERY_ENABLE_REMOTE_CONTROL': True, \n'CELERY_RESULT_DB_SHORT_LIVED_SESSIONS': False, \n'CELERY_EVENT_SERIALIZER': 'json', \n'CASSANDRA_DETAILED_MODE': False, \n'CELERY_REDIS_MAX_CONNECTIONS': None, \n'CELERY_CACHE_BACKEND': None, \n'CELERYD_PREFETCH_MULTIPLIER': 4, \n'BROKER_PASSWORD': None, \n'CELERY_BROADCAST_EXCHANGE_TYPE': 'fanout', \n'CELERY_EAGER_PROPAGATES_EXCEPTIONS': False, \n'CELERY_IGNORE_RESULT': False, \n'CASSANDRA_KEYSPACE': None, \n'EMAIL_HOST_PASSWORD': None, \n'CELERYMON_LOG_LEVEL': 'INFO', \n'CELERY_DISABLE_RATE_LIMITS': False, \n'CELERY_TASK_PUBLISH_RETRY_POLICY': {'interval_start': 0, \n'interval_max': 1, \n'max_retries': 3, \n'interval_step': 0.2}, \n'CELERY_SECURITY_KEY': None, \n'CELERY_MONGODB_BACKEND_SETTINGS': None, \n'CELERY_DEFAULT_RATE_LIMIT': None, \n'CELERYBEAT_SYNC_EVERY': 0, \n'CELERY_EVENT_QUEUE_TTL': None, \n'CELERYD_POOL_PUTLOCKS': True, \n'CELERY_TASK_SERIALIZER': 'pickle', \n'CELERYD_WORKER_LOST_WAIT': 10.0, \n'CASSANDRA_SERVERS': None, \n'CELERYD_POOL_RESTARTS': False, \n'CELERY_TASK_PUBLISH_RETRY': True, \n'CELERY_ENABLE_UTC': True, \n'CELERY_SEND_EVENTS': False, \n'BROKER_CONNECTION_MAX_RETRIES': 100, \n'CELERYD_LOG_FILE': None, \n'CELERYD_FORCE_EXECV': False, \n'CELERY_CHORD_PROPAGATES': True, \n'CELERYD_AUTOSCALER': 'celery.worker.autoscale:Autoscaler', \n'CELERYD_STATE_DB': None, \n'CELERY_ROUTES': None, \n'CELERYD_TIMER': None, \n'ADMINS': (), \n'BROKER_HEARTBEAT_CHECKRATE': 3.0, \n'CELERY_ACCEPT_CONTENT': ['json', \n'pickle', \n'msgpack', \n'yaml'], \n'BROKER_LOGIN_METHOD': None, \n'BROKER_CONNECTION_RETRY': True, \n'CELERY_TIMEZONE': None, \n'CASSANDRA_WRITE_CONSISTENCY': None, \n'CELERYBEAT_MAX_LOOP_INTERVAL': 0, \n'CELERYD_LOG_LEVEL': 'WARN', \n'CELERY_REDIRECT_STDOUTS': True, \n'BROKER_POOL_LIMIT': 10, \n'CELERY_SECURITY_CERT_STORE': None, \n'CELERYD_CONSUMER': 'celery.worker.consumer:Consumer', \n'CELERY_INCLUDE': (), \n'CELERYD_MAX_TASKS_PER_CHILD': None, \n'CELERYD_LOG_FORMAT': '[%(asctime)s: %(levelname)s/%(processName)s] %(message)s', \n'CELERY_ANNOTATIONS': None, \n'CELERY_MESSAGE_COMPRESSION': None, \n'CASSANDRA_READ_CONSISTENCY': None, \n'EMAIL_USE_SSL': False, \n'CELERY_SEND_TASK_ERROR_EMAILS': False, \n'CELERY_QUEUES': None, \n'CELERY_ACKS_LATE': False, \n'CELERYMON_LOG_FORMAT': '[%(asctime)s: %(levelname)s] %(message)s', \n'CELERY_TASK_RESULT_EXPIRES': datetime.timedelta(1), \n'BROKER_HOST': None, \n'EMAIL_PORT': 25, \n'BROKER_FAILOVER_STRATEGY': None, \n'CELERY_RESULT_BACKEND': 'rpc://', \n'CELERY_BROADCAST_EXCHANGE': 'celeryctl', \n'CELERYBEAT_LOG_FILE': None, \n'CELERYBEAT_SCHEDULE': {}, \n'CELERY_RESULT_DBURI': None, \n'CELERY_DEFAULT_DELIVERY_MODE': 2, \n'CELERYBEAT_LOG_LEVEL': 'INFO', \n'CASSANDRA_COLUMN_FAMILY': None, \n'EMAIL_HOST_USER': None}\n```\n\n========================================\n\nTop Answer:\nAfter modifying of tasks it is necessary to restart celery to reread changes.\n\n========================================\n\nCode:\n```text\nresult.get(timeout = 10)\n```\n\n```text\nTraceback (most recent call last):\n File \"<input>\", line 11, in <module>\n File \"/home/mehdi/.virtualenvs/python3/lib/python3.4/site-packages/celery/result.py\", line 169, in get\n no_ack=no_ack,\n File \"/home/mehdi/.virtualenvs/python3/lib/python3.4/site-packages/celery/backends/base.py\", line 225, in wait_for\n raise TimeoutError('The operation timed out.')\ncelery.exceptions.TimeoutError: The operation timed out.\n```\n\n```text\nfrom celery import Celery\n\napp = Celery('tasks', backend='redis://localhost/', broker='amqp://')\n\n@app.task\ndef add(x, y):\n return x + y\n\nresult = add.delay(4,4)\n```\n\n```text\n{'CELERY_RESULT_DB_TABLENAMES': None, \n'BROKER_TRANSPORT_OPTIONS': {}, \n'BROKER_USE_SSL': False, \n'CELERY_BROADCAST_QUEUE': 'celeryctl', \n'EMAIL_USE_TLS': False, \n'CELERY_STORE_ERRORS_EVEN_IF_IGNORED': False, \n'CELERY_CREATE_MISSING_QUEUES': True, \n'CELERY_DEFAULT_QUEUE': 'celery', \n'CELERY_SEND_TASK_SENT_EVENT': False, \n'CELERYD_TASK_TIME_LIMIT': None, \n'BROKER_URL': 'amqp://', \n'CELERY_EVENT_QUEUE_EXPIRES': None, \n'CELERY_DEFAULT_EXCHANGE_TYPE': 'direct', \n'CELERYBEAT_SCHEDULER': 'celery.beat:PersistentScheduler', \n'CELERY_MAX_CACHED_RESULTS': 100, \n'CELERY_RESULT_PERSISTENT': None, \n'CELERYD_POOL': 'prefork', \n'CELERYD_AGENT': None, \n'EMAIL_HOST': 'localhost', \n'CELERY_CACHE_BACKEND_OPTIONS': {}, \n'BROKER_HEARTBEAT': None, \n'CELERY_RESULT_ENGINE_OPTIONS': None, \n'CELERY_RESULT_SERIALIZER': 'pickle', \n'CELERYBEAT_SCHEDULE_FILENAME': 'celerybeat-schedule', \n'CELERY_REDIRECT_STDOUTS_LEVEL': 'WARNING', \n'CELERY_IMPORTS': (), \n'SERVER_EMAIL': 'celery@localhost', \n'CELERYD_TASK_LOG_FORMAT': '[%(asctime)s: %(levelname)s/%(processName)s] %(task_name)s[%(task_id)s]: %(message)s', \n'CELERY_SECURITY_CERTIFICATE': None, \n'CELERYD_LOG_COLOR': None, \n'CELERY_RESULT_EXCHANGE': 'celeryresults', \n'CELERY_TRACK_STARTED': False, \n'CELERY_REDIS_PASSWORD': None, \n'BROKER_USER': None, \n'CELERY_COUCHBASE_BACKEND_SETTINGS': None, \n'CELERY_RESULT_EXCHANGE_TYPE': 'direct', \n'CELERY_REDIS_DB': None, \n'CELERYD_TIMER_PRECISION': 1.0, \n'CELERY_REDIS_PORT': None, \n'BROKER_TRANSPORT': None, \n'CELERYMON_LOG_FILE': None, \n'CELERYD_CONCURRENCY': 0, \n'CELERYD_HIJACK_ROOT_LOGGER': True, \n'BROKER_VHOST': None, \n'CELERY_DEFAULT_EXCHANGE': 'celery', \n'CELERY_DEFAULT_ROUTING_KEY': 'celery', \n'CELERY_ALWAYS_EAGER': False, \n'EMAIL_TIMEOUT': 2, \n'CELERYD_TASK_SOFT_TIME_LIMIT': None, \n'CELERY_WORKER_DIRECT': False, \n'CELERY_REDIS_HOST': None, \n'CELERY_QUEUE_HA_POLICY': None, \n'BROKER_PORT': None, \n'CELERYD_AUTORELOADER': 'celery.worker.autoreload:Autoreloader', \n'BROKER_CONNECTION_TIMEOUT': 4, \n'CELERY_ENABLE_REMOTE_CONTROL': True, \n'CELERY_RESULT_DB_SHORT_LIVED_SESSIONS': False, \n'CELERY_EVENT_SERIALIZER': 'json', \n'CASSANDRA_DETAILED_MODE': False, \n'CELERY_REDIS_MAX_CONNECTIONS': None, \n'CELERY_CACHE_BACKEND': None, \n'CELERYD_PREFETCH_MULTIPLIER': 4, \n'BROKER_PASSWORD': None, \n'CELERY_BROADCAST_EXCHANGE_TYPE': 'fanout', \n'CELERY_EAGER_PROPAGATES_EXCEPTIONS': False, \n'CELERY_IGNORE_RESULT': False, \n'CASSANDRA_KEYSPACE': None, \n'EMAIL_HOST_PASSWORD': None, \n'CELERYMON_LOG_LEVEL': 'INFO', \n'CELERY_DISABLE_RATE_LIMITS': False, \n'CELERY_TASK_PUBLISH_RETRY_POLICY': {'interval_start': 0, \n'interval_max': 1, \n'max_retries': 3, \n'interval_step': 0.2}, \n'CELERY_SECURITY_KEY': None, \n'CELERY_MONGODB_BACKEND_SETTINGS': None, \n'CELERY_DEFAULT_RATE_LIMIT': None, \n'CELERYBEAT_SYNC_EVERY': 0, \n'CELERY_EVENT_QUEUE_TTL': None, \n'CELERYD_POOL_PUTLOCKS': True, \n'CELERY_TASK_SERIALIZER': 'pickle', \n'CELERYD_WORKER_LOST_WAIT': 10.0, \n'CASSANDRA_SERVERS': None, \n'CELERYD_POOL_RESTARTS': False, \n'CELERY_TASK_PUBLISH_RETRY': True, \n'CELERY_ENABLE_UTC': True, \n'CELERY_SEND_EVENTS': False, \n'BROKER_CONNECTION_MAX_RETRIES': 100, \n'CELERYD_LOG_FILE': None, \n'CELERYD_FORCE_EXECV': False, \n'CELERY_CHORD_PROPAGATES': True, \n'CELERYD_AUTOSCALER': 'celery.worker.autoscale:Autoscaler', \n'CELERYD_STATE_DB': None, \n'CELERY_ROUTES': None, \n'CELERYD_TIMER': None, \n'ADMINS': (), \n'BROKER_HEARTBEAT_CHECKRATE': 3.0, \n'CELERY_ACCEPT_CONTENT': ['json', \n'pickle', \n'msgpack', \n'yaml'], \n'BROKER_LOGIN_METHOD': None, \n'BROKER_CONNECTION_RETRY': True, \n'CELERY_TIMEZONE': None, \n'CASSANDRA_WRITE_CONSISTENCY': None, \n'CELERYBEAT_MAX_LOOP_INTERVAL': 0, \n'CELERYD_LOG_LEVEL': 'WARN', \n'CELERY_REDIRECT_STDOUTS': True, \n'BROKER_POOL_LIMIT': 10, \n'CELERY_SECURITY_CERT_STORE': None, \n'CELERYD_CONSUMER': 'celery.worker.consumer:Consumer', \n'CELERY_INCLUDE': (), \n'CELERYD_MAX_TASKS_PER_CHILD': None, \n'CELERYD_LOG_FORMAT': '[%(asctime)s: %(levelname)s/%(processName)s] %(message)s', \n'CELERY_ANNOTATIONS': None, \n'CELERY_MESSAGE_COMPRESSION': None, \n'CASSANDRA_READ_CONSISTENCY': None, \n'EMAIL_USE_SSL': False, \n'CELERY_SEND_TASK_ERROR_EMAILS': False, \n'CELERY_QUEUES': None, \n'CELERY_ACKS_LATE': False, \n'CELERYMON_LOG_FORMAT': '[%(asctime)s: %(levelname)s] %(message)s', \n'CELERY_TASK_RESULT_EXPIRES': datetime.timedelta(1), \n'BROKER_HOST': None, \n'EMAIL_PORT': 25, \n'BROKER_FAILOVER_STRATEGY': None, \n'CELERY_RESULT_BACKEND': 'rpc://', \n'CELERY_BROADCAST_EXCHANGE': 'celeryctl', \n'CELERYBEAT_LOG_FILE': None, \n'CELERYBEAT_SCHEDULE': {}, \n'CELERY_RESULT_DBURI': None, \n'CELERY_DEFAULT_DELIVERY_MODE': 2, \n'CELERYBEAT_LOG_LEVEL': 'INFO', \n'CASSANDRA_COLUMN_FAMILY': None, \n'EMAIL_HOST_USER': None}\n```\n\n```text\nproj/celery_proj/__init__.py\n /celery.py\n /tasks.py\n /test.py\n```\n\n```text\nfrom __future__ import absolute_import\n\nfrom celery import Celery\n\napp = Celery('celery_proj',\n broker='amqp://',\n backend='amqp://',\n include=['celery_proj.tasks'])\n\n# Optional configuration, see the application user guide.\napp.conf.update(\n CELERY_TASK_RESULT_EXPIRES=3600,\n)\n\nif __name__ == '__main__':\n app.start()\n```\n\n```text\nfrom __future__ import absolute_import\n\nfrom celery_proj.celery import app\n\n\n@app.task\ndef add(x, y):\n return x + y\n\n\n@app.task\ndef mul(x, y):\n return x * y\n\n\n@app.task\ndef xsum(numbers):\n return sum(numbers)\n```\n\n```text\n__author__ = 'mehdi'\npath = '/home/mehdi/PycharmProjects'\nimport sys\nsys.path.append(path)\nfrom celery_proj.tasks import add\n\nr = add.delay(4,4)\nprint(r.status)\nprint(r.result)\n```\n\n```text\ncd proj\ncelery -A celery_proj worker -l info\n```\n\n```text\npython test.py\n```\n\n```text\napp.backend.get_result(result.id)\n```\n\n```text\nAsyncResult.get()\n```\n\n```text\nAsyncResult.get()\n```\n\n```text\nfrom celery import Celery\n\napp = Celery('tasks', broker='amqp://guest@localhost//')\napp.config_from_object('celeryconfig')\n\n@app.task\ndef add(x, y):\n print '[' + str(x) + '][' + str(y) + ']=' + str(x+y)\n return x + y\n```\n\n```text\nCELERY_RESULT_BACKEND='amqp://'\n```\n\n========================================\n\nComments:\n- Also : the task status is stuck at 'PENDING'\n- What command are you using to spin up your worker(s)? Your output shows that the tasks are being found, but I don't see anything about your worker(s).\n- I run the worker with : celery -A tasks worker --loglevel=info\n- Have you tried adding a print statement to your task? That way every time the worker runs it, you will get console output. I suspect the task is never actually getting run.\n- I've added a print() in my add function and I don't get any console output. I don't understand. The task seems to be ran because in my worker console I do get the expected result (x+y=4+4=8)\n- hmm. and is your redis up and running? also i wonder if the way you are giving the address for your redis could be the problem. i think usually you have to supply the port and db number. so, for a default redis install it would look like `backend='redis://localhost:6379/0'`\n- I've tried setting backend='redis://localhost:6379/0'. Doesn't work either. When i run my python script, the redis console doesn't print any output, as if it didn't recieve any order\n- redis won't really show anything in the console, you should be seeing output from your task coming from your celery worker. try doing --loglevel=debug and see if you get any more useful information.\n- Nothing seems wrong in the log. If It's any help for you, when i enter 'sudo rabbitmqctl list_connections' in a terminal, i get many connections : guest\t127.0.0.1\t48856\trunning guest\t127.0.0.1\t48888\trunning guest\t127.0.0.1\t48965\trunning guest\t127.0.0.1\t49338\trunning guest\t127.0.0.1\t49376\trunning guest\t127.0.0.1\t49377\trunning guest\t127.0.0.1\t49388\trunning\n- try this, after the `app = Celery(...)` line: `app.conf.update(CELERY_IGNORE_RESULT=False)`\n- CELERY_IGNORE_RESULT is already set to False. I updated my initial post to show my app.conf.\n- Is that in a seperate file? you may have to initialize your celery instance to it using `app.config_from_object()`\n- No, this is the default app.config. I just printed it\n- Look at the value for `CELERY_RESULT_BACKEND` in that app.conf you printed. It doesn't look like it matches what you are setting it to in the constructor.\n- No It's fine. I was trying RPC as a backend to see if the problem came from redis. Unfortunately no :/\n- try setting your `CELERY_TASK_RESULT_EXPIRES` to a higher time delta. maybe the result is expiring before you can get to it?\n- `app.backend.get_result(result.id)` returns `None`\n- concur, it returns None\n- Very clear answer. Finally it worked for me after many hours of fight\n- this was the solution for me.\n- save the new backend change and rerun `celery -A tasks worker --loglevel=info`","metadata":{"transformedAt":"2026-08-18T18:33:20.174Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":15,"totalLines":485,"estimatedTokens":3913}}591{"id":"stack-34272628","source":"stackoverflow","questionId":34272628,"title":"Symfony: should I add the rabbitmq:consumer command to crontab?","tags":["symfony","rabbitmq"],"text":"Title: Symfony: should I add the rabbitmq:consumer command to crontab?\nTags: symfony, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have read many (great) articles on RabbitMQ integration into a Symfony application.\n\nThe RabbitMqBundle makes it very easy to ingrate it, and it provides the convenient `rabbitmq:consumer` command to consume messages from a queue like this:\n\n```\napp/console rabbitmq:consumer -m 50 upload_picture\n```\n\nI have a question however. Should you recommend to add this command to crontab? Are there any best practices about it?\n\n========================================\n\nCode:\n```text\napp/console rabbitmq:consumer -m 50 upload_picture\n```\n\n```text\nrabbitmq:consumer\n```\n\n========================================\n\nComments:\n- A side note -m 50 is not reliable all the time. For example, if you have a few methods coming to queue from time to time you'll have problems with lost connections. It happens because of a long idle period. Better to limit the actual time the command works. All connection timeout could be bound to this limit. Consumer works for 1 hour and exits so the timeout could be set to 1 hour 20 minutes. This is something rabbitmq bundle misses but it is available in enqueue bundle (--limit-time=\"now + 1 hour\" option).\n- Thank you for your answer. This is exactly what I was looking for as it was never mentioned in the RabbitMQ for Symfony tutorials. It seems there is an interesting Symfony bundle to handle automatic Supervisord configuration for the RabbitMQBundle: github.com/Phobetor/rabbitmq-supervisor-bundle\n- The issue link under \"this discussion\" is off.\n- I would avoid the bundle mentionned in first comment it got real reliability issues.\n- @TomToms Yep I agree. It was overkill and I ended up doing my own supervisor config, which is quite simple. I configured my PHP Docker container to automatically install and launch supervisor and it works really fine.","metadata":{"transformedAt":"2026-08-18T18:33:20.174Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":34,"estimatedTokens":480}}592{"id":"stack-40749877","source":"stackoverflow","questionId":40749877,"title":"RabbitMQ sending message in transaction","tags":["spring-boot","rabbitmq","spring-amqp"],"text":"Title: RabbitMQ sending message in transaction\nTags: spring-boot, rabbitmq, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nIs it possible to run below code in a transaction so if an exception is thrown in the business processing we can roll back the message we sent to the queue?\n\n```\nrabbitTemplate.convertAndSend(\"queue1\", data);\n\n//do some processing\n\nrabbitTemplate.convertAndSend(\"queue2\", data);\n```\n\nNeed for this is what if something went wrong after sending message to queue1, but we're not able to send message to queue2. Or what if issue network or some other issue in sending message to queue.\n\n========================================\n\nCode:\n```text\nrabbitTemplate.convertAndSend(\"queue1\", data);\n\n//do some processing\n\nrabbitTemplate.convertAndSend(\"queue2\", data);\n```\n\n```text\n@Transactional\n public void send(String in) {\n this.template.convertAndSend(\"foo\", in);\n if (in.equals(\"foo\")) {\n throw new RuntimeException(\"test\");\n }\n this.template.convertAndSend(\"bar\", in);\n }\n```\n\n```text\n@SpringBootApplication\n@EnableTransactionManagement\npublic class So40749877Application {\n\n public static void main(String[] args) {\n ConfigurableApplicationContext context = SpringApplication.run(So40749877Application.class, args);\n Foo foo = context.getBean(Foo.class);\n try {\n foo.send(\"foo\");\n }\n catch (Exception e) {}\n foo.send(\"bar\");\n RabbitTemplate template = context.getBean(RabbitTemplate.class);\n // should not get any foos...\n System.out.println(template.receiveAndConvert(\"foo\", 10_000));\n System.out.println(template.receiveAndConvert(\"bar\", 10_000));\n // should be null\n System.out.println(template.receiveAndConvert(\"foo\", 0));\n RabbitAdmin admin = context.getBean(RabbitAdmin.class);\n admin.deleteQueue(\"foo\");\n admin.deleteQueue(\"bar\");\n context.close();\n }\n\n @Bean\n public RabbitTemplate amqpTemplate(ConnectionFactory connectionFactory) {\n RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);\n rabbitTemplate.setChannelTransacted(true);\n return rabbitTemplate;\n }\n\n @Bean\n public Queue foo() {\n return new Queue(\"foo\");\n }\n\n @Bean\n public Queue bar() {\n return new Queue(\"bar\");\n }\n\n @Bean\n public Foo fooBean() {\n return new Foo();\n }\n\n @Bean\n public PlatformTransactionManager transactionManager(ConnectionFactory connectionFactory) {\n return new RabbitTransactionManager(connectionFactory);\n }\n\n public static class Foo {\n\n @Autowired\n private RabbitTemplate template;\n\n @Transactional\n public void send(String in) {\n this.template.convertAndSend(\"foo\", in);\n if (in.equals(\"foo\")) {\n throw new RuntimeException(\"test\");\n }\n this.template.convertAndSend(\"bar\", in);\n }\n\n }\n\n}\n```\n\n```text\nConnection connection = cf.createConnection();\nChannel channel = connection.createChannel(true);\nchannel.basicQos(1);\nchannel.txSelect();\nCountDownLatch latch = new CountDownLatch(1);\nchannel.basicConsume(\"foo\", new DefaultConsumer(channel) {\n\n @Override\n public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties,\n byte[] body) throws IOException {\n System.out.println(new String(body));\n\n getChannel().txRollback(); // delivery won't be requeued; remains unacked\n\n if (envelope.isRedeliver()) {\n getChannel().basicAck(envelope.getDeliveryTag(), false);\n getChannel().txCommit(); // commit the ack so the message is removed\n getChannel().basicCancel(consumerTag);\n latch.countDown();\n }\n else { // first time, let's requeue\n getChannel().basicReject(envelope.getDeliveryTag(), true);\n getChannel().txCommit(); // commit the reject so the message will be requeued\n }\n }\n\n});\nlatch.await();\nchannel.close();\nconnection.close();\n```\n\n```text\nonMessage()\n```\n\n```text\n@RabbitListener\n```\n\n```text\nsetChannelTransacted(true)\n```\n\n```text\ntxRollback\n```\n\n========================================\n\nComments:\n- Thansk Gary , I did same thing but missed @EnableTransactionManagement , its working now. Though in that method I am using amqpAdmin to declare queue (I have to do that I know its not good), right now its not going to rollback that, though its not biggie, is there way to rollback that too!\n- No; infrastructure changes do not participate in transactions - see here for rabbitmq transaction semantics.\n- In that link can you elaborate this statement: \"On the consuming side, the acknowledgements are transactional, not the consuming of the messages themselves. \"\n- It doesn't generally apply when using Spring because it manages the transaction. Hopefully my edit above explains the semantics of transactions on the consumer side.\n- Gary, if we slightly modify above send method with additional call of db and we want to do something like two phase commit using atomikas , I tried but ran into issue of atomikas config. Expecting spring boot to all automagically. So like @Transactional public void send(String in) { this.template.convertAndSend(\"foo\", in); jdbc.save(entity); if (in.equals(\"foo\")) { throw new RuntimeException(\"test\"); } }\n- You should ask a new question not hijack an existing one; also code in comments is virtually unreadable. RabbitMQ doesn't support 2 phase commit.","metadata":{"transformedAt":"2026-08-18T18:33:20.174Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":168,"estimatedTokens":1389}}593{"id":"stack-20316035","source":"stackoverflow","questionId":20316035,"title":"Rabbitmq listens on all interfaces","tags":["ubuntu","rabbitmq","erlang","beam"],"text":"Title: Rabbitmq listens on all interfaces\nTags: ubuntu, rabbitmq, erlang, beam\nSource: Stack Overflow\n\nQuestion:\nIt appears that my rabbitmq listens on all interfaces despite:\n\nIn /etc/rabbitmq/rabbitmq.config:\n\n```\n[{rabbit, [{tcp_listeners, [{\"10.0.0.1\", 5672}]}]},\n {rabbitmq_mochiweb, [{listeners, [{mgmt, [{ip, \"10.0.0.1\"},\n {port, 55672}]}]}]}].\n```\n\nIn /etc/rabbitmq/rabbitmq-env.conf:\n\n```\nexport RABBITMQ_NODENAME=rabbit\nexport RABBITMQ_NODE_IP_ADDRESS=10.0.0.1\nexport ERL_EPMD_ADDRESS=10.0.0.1\n```\n\nWhen i run *netstat -uptan | grep beam* i get:\n\n```\ntcp 0 0 10.0.0.1:5672 0.0.0.0:* LISTEN 1378/beam\ntcp 0 0 0.0.0.0:33551 0.0.0.0:* LISTEN 1378/beam\ntcp 0 0 127.0.0.1:38737 127.0.0.1:4369 ESTABLISHED 1378/beam\n```\n\nHow do i make *beam* not listening on *0.0.0.0:33551* ?\n\n========================================\n\nCode:\n```text\n[{rabbit, [{tcp_listeners, [{\"10.0.0.1\", 5672}]}]},\n {rabbitmq_mochiweb, [{listeners, [{mgmt, [{ip, \"10.0.0.1\"},\n {port, 55672}]}]}]}].\n```\n\n```text\nexport RABBITMQ_NODENAME=rabbit\nexport RABBITMQ_NODE_IP_ADDRESS=10.0.0.1\nexport ERL_EPMD_ADDRESS=10.0.0.1\n```\n\n```text\ntcp 0 0 10.0.0.1:5672 0.0.0.0:* LISTEN 1378/beam\ntcp 0 0 0.0.0.0:33551 0.0.0.0:* LISTEN 1378/beam\ntcp 0 0 127.0.0.1:38737 127.0.0.1:4369 ESTABLISHED 1378/beam\n```\n\n```text\ntcp 0 0 127.0.0.1:38737 127.0.0.1:4369 ESTABLISHED 1378/beam\n```\n\n```text\n127.0.0.1:4369\n```\n\n```text\n0.0.0.0:33551\n```\n\n```text\nrabbitmqctl\n```\n\n```text\n-kernel inet_dist_use_interface '{127,0,0,1}'\n```\n\n```text\nexport RABBITMQ_CONFIG_FILE=\"/path/to/my_rabbitmq.conf\"\n```\n\n```text\n/etc/rabbitmq/rabbitmq.conf\n```\n\n```text\nexport ERL_EPMD_ADDRESS=127.0.0.1\n```\n\n========================================\n\nComments:\n- For now i decided to use Firewall so public interface accepts only what i need.","metadata":{"transformedAt":"2026-08-18T18:33:20.174Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":11,"totalLines":90,"estimatedTokens":490}}594{"id":"stack-12673603","source":"stackoverflow","questionId":12673603,"title":"When to use persistence with Java Messaging and Queuing Systems","tags":["jms","activemq-classic","rabbitmq","messaging","amqp"],"text":"Title: When to use persistence with Java Messaging and Queuing Systems\nTags: jms, activemq-classic, rabbitmq, messaging, amqp\nSource: Stack Overflow\n\nQuestion:\nI'm performing a trade study on (Java) Messaging & Queuing systems for an upcoming re-design of a back-end framework for a major web application (on Amazon's EC2 Cloud, x-large instances). I'm currently evaluating ActiveMQ and RabbitMQ.\n\nThe plan is to have 5 different queues, with one being a dead-letter queue. The number of messages sent per day will be anywhere between 40K and 400K. As I plan for the message content to be a pointer to an XML file location on a data store, I expect the messages to be about 64 bytes. However, for evaluation purposes, I would also like to consider sending raw XML in the messages, with an average file size of 3KB.\n\nMy main questions: When/how many messages should be persisted on a daily basis? Is it reasonable to persist all messages, considering the amounts I specified above? I know that persisting will decrease performance, perhaps by a lot. But, by not persisting, a lot of RAM is being used. What would some of you recommend?\n\nAlso, I know that there is a lot of information online regarding ActiveMQ (JMS) vs RabbitMQ (AMQP). I have done a ton of research and testing. It seems like either implementation would fit my needs. Considering the information that I provided above (file sizes and # of messages), can anyone point out a reason(s) to use a particular vendor that I may have missed?\n\nThanks!\n\n========================================\n\nTop Answer:\nA messaging system must be used as a temporary storage. Applications should be designed to pull the messages as soon as possible. The more number of messages lesser the performance. If you are pulling of messages then there will be a better performance as well as lesser memory usage. Whether persistent or not memory will still be used as the messages are kept in memory for better performance and will backed up on disk if a message type is persistent only. \n\nThe decision on message persistence depends on how critical a message is and does it require to survive a messaging provider restart. \n\nYou may want to have a look at IBM WebSphere MQ. It can meet your requirements. It has JMS as well as proprietary APIs for developing applications.","metadata":{"transformedAt":"2026-08-18T18:33:20.174Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":23,"estimatedTokens":578}}595{"id":"stack-46962304","source":"stackoverflow","questionId":46962304,"title":"Unit test RabbitMQ push with C# - .Net Core","tags":["c#","unit-testing","asp.net-core",".net-core","rabbitmq"],"text":"Title: Unit test RabbitMQ push with C# - .Net Core\nTags: c#, unit-testing, asp.net-core, .net-core, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have created a .net core API, which pushes a message in RabbitMQ queue. I have used `IOptions` to read configuration data from *.json* file and added it as dependency.\n\nBelow is the code of my controller:\n\n```\n[Route(\"api/[controller]\")]\npublic class RestController : Controller\n{\n private RabbitMQConnectionDetail _connectionDetail;\n\n public RestController(IOptions connectionDetail)\n {\n _connectionDetail = connectionDetail.Value;\n }\n\n [HttpPost]\n public IActionResult Push([FromBody] OrderItem orderItem)\n {\n try\n {\n using (var rabbitMQConnection = new RabbitMQConnection(_connectionDetail.HostName,\n _connectionDetail.UserName, _connectionDetail.Password))\n {\n using (var connection = rabbitMQConnection.CreateConnection())\n {\n var model = connection.CreateModel();\n var helper = new RabbitMQHelper(model, \"Topic_Exchange\");\n helper.PushMessageIntoQueue(orderItem.Serialize(), \"Order_Queue\");\n }\n }\n }\n catch (Exception)\n {\n return StatusCode((int)HttpStatusCode.BadRequest);\n }\n return Ok();\n }\n }\n```\n\nConnection details class has the below properties \n\n```\npublic class RabbitMQConnectionDetail\n{\n public string HostName { get; set; }\n\n public string UserName { get; set; }\n\n public string Password { get; set; }\n}\n```\n\nNow I want to unit test it, but since I am going to test it against a blackbox, I'm not able to think of how to unit test it and looking for kind help.\n\nConnectionClass\n\n```\npublic class RabbitMQConnection : IDisposable\n{ \n private static IConnection _connection;\n private readonly string _hostName;\n private readonly string _userName;\n private readonly string _password;\n\n public RabbitMQConnection(string hostName, string userName, string password)\n {\n _hostName = hostName;\n _userName = userName;\n _password = password;\n }\n\n public IConnection CreateConnection()\n {\n var _factory = new ConnectionFactory\n {\n HostName = _hostName,\n UserName = _userName,\n Password = _password\n };\n _connection = _factory.CreateConnection();\n var model = _connection.CreateModel();\n\n return _connection;\n }\n\n public void Close()\n {\n _connection.Close();\n }\n\n public void Dispose()\n {\n Dispose(true);\n GC.SuppressFinalize(this);\n }\n\n protected virtual void Dispose(bool disposing)\n {\n if (disposing)\n {\n _connection.Close();\n }\n }\n\n ~ RabbitMQConnection()\n {\n Dispose(false);\n }\n}\n```\n\nHelper class\n\n```\npublic class RabbitMQHelper\n{\n private static IModel _model;\n private static string _exchangeName;\n const string RoutingKey = \"dummy-key.\";\n\n public RabbitMQHelper(IModel model, string exchangeName)\n {\n _model = model;\n _exchangeName = exchangeName;\n }\n\n public void SetupQueue(string queueName)\n {\n _model.ExchangeDeclare(_exchangeName, ExchangeType.Topic);\n _model.QueueDeclare(queueName, true, false, false, null);\n _model.QueueBind(queueName, _exchangeName, RoutingKey);\n }\n\n public void PushMessageIntoQueue(byte[] message, string queue)\n {\n SetupQueue(queue);\n _model.BasicPublish(_exchangeName, RoutingKey, null, message);\n }\n\n public byte[] ReadMessageFromQueue(string queueName)\n {\n SetupQueue(queueName);\n byte[] message;\n var data = _model.BasicGet(queueName, false);\n message = data.Body;\n _model.BasicAck(data.DeliveryTag, false);\n return message;\n }\n}\n```\n\n========================================\n\nTop Answer:\nI dont think it is a unit test scenario. If you want to to test with external component ie database or message queue then i suggest you do it as integration test. \n\nWhat we do is to have a sand box environment with component SQL database and azure message bus. We have code to correctly set the state for this component ie seed the database and clear the message bus. Then we run test on the environment and check the state of the database or message bus count etc.\n\n========================================\n\nCode:\n```text\n[Route(\"api/[controller]\")]\npublic class RestController : Controller\n{\n private RabbitMQConnectionDetail _connectionDetail;\n\n public RestController(IOptions<RabbitMQConnectionDetail> connectionDetail)\n {\n _connectionDetail = connectionDetail.Value;\n }\n\n [HttpPost]\n public IActionResult Push([FromBody] OrderItem orderItem)\n {\n try\n {\n using (var rabbitMQConnection = new RabbitMQConnection(_connectionDetail.HostName,\n _connectionDetail.UserName, _connectionDetail.Password))\n {\n using (var connection = rabbitMQConnection.CreateConnection())\n {\n var model = connection.CreateModel();\n var helper = new RabbitMQHelper(model, \"Topic_Exchange\");\n helper.PushMessageIntoQueue(orderItem.Serialize(), \"Order_Queue\");\n }\n }\n }\n catch (Exception)\n {\n return StatusCode((int)HttpStatusCode.BadRequest);\n }\n return Ok();\n }\n }\n```\n\n```text\npublic class RabbitMQConnectionDetail\n{\n public string HostName { get; set; }\n\n public string UserName { get; set; }\n\n public string Password { get; set; }\n}\n```\n\n```text\npublic class RabbitMQConnection : IDisposable\n{ \n private static IConnection _connection;\n private readonly string _hostName;\n private readonly string _userName;\n private readonly string _password;\n\n public RabbitMQConnection(string hostName, string userName, string password)\n {\n _hostName = hostName;\n _userName = userName;\n _password = password;\n }\n\n public IConnection CreateConnection()\n {\n var _factory = new ConnectionFactory\n {\n HostName = _hostName,\n UserName = _userName,\n Password = _password\n };\n _connection = _factory.CreateConnection();\n var model = _connection.CreateModel();\n\n return _connection;\n }\n\n public void Close()\n {\n _connection.Close();\n }\n\n public void Dispose()\n {\n Dispose(true);\n GC.SuppressFinalize(this);\n }\n\n protected virtual void Dispose(bool disposing)\n {\n if (disposing)\n {\n _connection.Close();\n }\n }\n\n ~ RabbitMQConnection()\n {\n Dispose(false);\n }\n}\n```\n\n```text\npublic class RabbitMQHelper\n{\n private static IModel _model;\n private static string _exchangeName;\n const string RoutingKey = \"dummy-key.\";\n\n public RabbitMQHelper(IModel model, string exchangeName)\n {\n _model = model;\n _exchangeName = exchangeName;\n }\n\n\n public void SetupQueue(string queueName)\n {\n _model.ExchangeDeclare(_exchangeName, ExchangeType.Topic);\n _model.QueueDeclare(queueName, true, false, false, null);\n _model.QueueBind(queueName, _exchangeName, RoutingKey);\n }\n\n public void PushMessageIntoQueue(byte[] message, string queue)\n {\n SetupQueue(queue);\n _model.BasicPublish(_exchangeName, RoutingKey, null, message);\n }\n\n public byte[] ReadMessageFromQueue(string queueName)\n {\n SetupQueue(queueName);\n byte[] message;\n var data = _model.BasicGet(queueName, false);\n message = data.Body;\n _model.BasicAck(data.DeliveryTag, false);\n return message;\n }\n}\n```\n\n```text\nIOptions\n```\n\n```text\npublic interface IRabbitMQConnectionFactory {\n IConnection CreateConnection();\n}\n```\n\n```text\npublic class RabbitMQConnection : IRabbitMQConnectionFactory {\n private readonly RabbitMQConnectionDetail connectionDetails;\n\n public RabbitMQConnection(IOptions<RabbitMQConnectionDetail> connectionDetails) {\n this.connectionDetails = connectionDetails.Value;\n }\n\n public IConnection CreateConnection() {\n var factory = new ConnectionFactory {\n HostName = connectionDetails.HostName,\n UserName = connectionDetails.UserName,\n Password = connectionDetails.Password\n };\n var connection = factory.CreateConnection();\n return connection;\n }\n}\n```\n\n```text\n[Route(\"api/[controller]\")]\npublic class RestController : Controller {\n private readonly IRabbitMQConnectionFactory factory;\n\n public RestController(IRabbitMQConnectionFactory factory) {\n this.factory = factory;\n }\n\n [HttpPost]\n public IActionResult Push([FromBody] OrderItem orderItem) {\n try { \n using (var connection = factory.CreateConnection()) {\n var model = connection.CreateModel();\n var helper = new RabbitMQHelper(model, \"Topic_Exchange\");\n helper.PushMessageIntoQueue(orderItem.Serialize(), \"Order_Queue\");\n return Ok();\n }\n } catch (Exception) {\n //TODO: Log error message\n return StatusCode((int)HttpStatusCode.BadRequest);\n }\n }\n}\n```\n\n```text\nRabbitMQConnection\n```\n\n```text\nRabbitMQConnection\n```\n\n```text\nIOptions\n```\n\n```text\nRabbitMQConnection\n```\n\n```text\nRabbitMQHelper\n```\n\n========================================\n\nComments:\n- What kinds of assertions are you expecting to write in these tests?\n- Since I am testing against a blackbox, I am not sure which assertion is going to help me. IsEqual is definitely not going to help. But If I can show the message count increased or there is next action upon the insert, that may help.\n- You need to test that controller return correct `IActionResult` and then check that correct message was pushed into the queue.\n- @ParthoGanguly Abstractions, abstraction, abstraction. You are trying to test an implementation concern that would change this to an integration test. Encapsulate the implementation concerns behind abstractions that can be mocked so that you can unit test in isolation.\n- @ParthoGanguly what version of RabbitMQ are you using?\n- @Nkosi - version 3.6.12\n- @ParthoGanguly I searched the repo and cannot find the following classes: `RabbitMQHelper`, `RabbitMQConnection`. Are these custom classes in your library?\n- @Nkosi - Have added those\n- @ParthoGanguly I provided some suggestions. I am curious though. What is the reasoning behind having the static connection and model in your custom classes?\n- No first you have to write unit tests that will be sure that a specific method is called with correct parameters, integration test is another level that should be tested\n- I will check and update the post. Thanks a lot for you pointers.\n- Modified the code, and it looks much better now. Mocking now is feasible. Also, no connection object and model object is available. That was not good to have\n- @ParthoGanguly glad to help.\n- How to pass connection details?","metadata":{"transformedAt":"2026-08-18T18:33:20.174Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":13,"totalLines":401,"estimatedTokens":2667}}596{"id":"stack-45538292","source":"stackoverflow","questionId":45538292,"title":"In a publish/subscribe model in microservices, how to receive/consume a message only once per service type","tags":["rabbitmq","apache-kafka","messaging","publish-subscribe","microservices"],"text":"Title: In a publish/subscribe model in microservices, how to receive/consume a message only once per service type\nTags: rabbitmq, apache-kafka, messaging, publish-subscribe, microservices\nSource: Stack Overflow\n\nQuestion:\nWe are designing for a microservices architecture model where service A publishes a message and services B, and C would like to receive/consume the message. However, for high availability multiple instances of services B and C are running at the same time. Now the question is how do we design such that only one service instance of B and one service instance of C receive the message and not all the other service instances. \n\nAs far as I know about RabbitMQ, it is not easy to achieve this behavior. I wonder if Kafka or any other messaging framework has a built-in support for this scenario, which I believe should be very common in a microservices architecture.\n\n========================================\n\nTop Answer:\nKafka has built-in support for this scenario.\n\nYou can create two Consumer Groups, one for `B`, and the other for `C`. Both `Consumer Groups` subscribe messages from `A`.\n\nAny message published by `A` will be sent to both groups. However, only one member of each group can receive the message.\n\n========================================\n\nCode:\n```text\nB\n```\n\n```text\nC\n```\n\n```text\nConsumer Groups\n```\n\n```text\nA\n```\n\n```text\nA\n```\n\n```text\nbin/kafka-console-producer.sh --broker-list localhost:9092 --topic test\n```\n\n```text\nbin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning --consumer-property group.id=cgB\n\nbin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning --consumer-property group.id=cgC\n```\n\n========================================\n\nComments:\n- I'm new to Kafka so bear with me please. The documentations says each partition is assigned to only one consumer in a group, and there cannot be more consumer instances in a consumer group than partitions. Isn't this a limit in scalability of services B and C? Does it mean if I need to add more instances of my services I have to create a new partition as well?\n- It means you need to plan ahead if you want to avoid having to repartition a topic. It is not uncommon to start with 12 or 16 partitions for a topic so there is room to grow. If you only have 4 consumers to start they will just get 3-4 partitions each. If you run out of partitions you can add more. You just can't ever take them away.\n- How do you publish a message to two or more queues at the same time? You send a message to an exchange with a key which is used to determine which queue is bound with that key. How do you define you binding keys?\n- Use broadcast exchange ,hence every message come to exchange will be broadcast to all the queue irrespective of key.\n- What happens if one of the queues is unavailable/down and the other is up? Won't one queue get messages that the other will miss? If you had more services and therefore more queues wouldn't it be an administrative burden to ensure that they are all up and running at the same time, particularly since they might be on different nodes in the cluster and a single node failure would take only some of the queues out of service temporarily?\n- ,system faliure is inevitable and solution for same is to have parallel nodes up and running for backup purposes.\n- @VijayParmar, Can you please some demo example or code to do this.","metadata":{"transformedAt":"2026-08-18T18:33:20.174Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":61,"estimatedTokens":861}}597{"id":"stack-13623947","source":"stackoverflow","questionId":13623947,"title":"Dead letter exchange RabbitMQ dropping messages","tags":["exchange-server","rabbitmq","amqp","dead-letter"],"text":"Title: Dead letter exchange RabbitMQ dropping messages\nTags: exchange-server, rabbitmq, amqp, dead-letter\nSource: Stack Overflow\n\nQuestion:\nI'm trying to implement a dlx queue in RabbitMQ.\nThe scenario is quite easy \nI have 2 queues:\n1) alive\n2) dead (x-dead-letter-exchange: \"immediate\", x-message-ttl: 5000)\n\nand an exchange \"immediate\" that is bound to 1) alive\n\nI tried to run this example: \nhttp://blog.james-carr.org/2012/03/30/rabbitmq-sending-a-message-to-be-consumed-later/\nbut it seems that the messages are dropped after the ttl expires and they dont get published on the exchange, so my alive queue is always empty.\n\nI also tried to create the queues by hand in the management console and I get the same behaviour.\n\nI tested it with Ubuntu/rabbitmq 3.0.0 and with Mac OS X and rabbitmq 2.8.7\n\nAm I missing something?\n\n========================================\n\nComments:\n- Do you want the messages that expire from the 'alive' queue to go into the 'dead' queue?\n- no actually its the opposite, i want that expired messages from the dead queue into the alive queue.\n- how do they get into the dead queue?\n- If you take a look to the example, they are published like normal messages. I tried also publishing a message via management console directly on the dead queue. In my implementation I don't use expires.\n- I did a spike and hit a few showstoppers: 1. Messages are only DLQ:en when at the top of the Q (rabbitmq.com/ttl.html – Caveats section) This means that if I first set msg 1 to expire in 4 hours and msg2 to expire in 1 hours msg2 will only expire after msg1 has expired. 2. The TTL for the message is kept by Rabbit so lets say you use a short timeout of 10 s. If the consumer hasn’t been able to consume the message withing 10 seconds after it expired (due to a backlog) it will be discarded and lost The above has been verified with Rabbit 3.0.1. Do you guys see any workarounds?\n- @AndreasÖhlund,try to design by using \"per queue TTL\", not \"per message TTL\", if possible.","metadata":{"transformedAt":"2026-08-18T18:33:20.174Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":32,"estimatedTokens":501}}598{"id":"stack-14992307","source":"stackoverflow","questionId":14992307,"title":"How do you replay missed messages when using STOMP to connect to RabbitMQ?","tags":["objective-c","rabbitmq","stomp"],"text":"Title: How do you replay missed messages when using STOMP to connect to RabbitMQ?\nTags: objective-c, rabbitmq, stomp\nSource: Stack Overflow\n\nQuestion:\nI've got an iOS application which uses a STOMP Client to talk to RabbitMQ. The application loads a lot of state during startup, and then keeps that state in sync by receiving updates published on STOMP. Of course, if it loses its connection, it can no longer be sure it's in sync, and therefore has to re-load that large initial blob. Any kind of network interruption triggers this behavior and makes my customers sad.\n\nThere are a lot of big-picture ways to fix this (and I'm working on them) but in the meantime, I'm trying to use persistent queues to solve this problem. The idea is that the server will create a queue, bind it to the appropriate topics, and then start building the large startup bundle. When finished, it will hand everything off to the client. The client will set itself up with the startup bundle, open a subscription to the queue, and then process any updates which happened while the server was getting things ready. Similarly, if the client should become disconnected, it can simply reconnect and resume reading the messages it finds in the queue.\n\nMy problem is that while the client successfully receives messages sent after it connects, if there were any messages in the queue before it connected, they are not read. Likewise, if the client becomes disconnected, when it reconnects, it won't see any messages which arrived while it was away.\n\nCan anyone suggest how I might get the client to be able to read those missing messages?\n\n========================================\n\nComments:\n- Can you post the sample code you have done for \"ack\" settings?\n- I'm afraid I can't. I wrote this answer 8 years ago when I was working for a different company. I no longer have access to that code.","metadata":{"transformedAt":"2026-08-18T18:33:20.174Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":18,"estimatedTokens":467}}599{"id":"stack-3284731","source":"stackoverflow","questionId":3284731,"title":"RabbitMQ message consumers stop consuming messages","tags":["benchmarking","rabbitmq","amqp"],"text":"Title: RabbitMQ message consumers stop consuming messages\nTags: benchmarking, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nOur team is in a spike sprint to choose between ActiveMQ or RabbitMQ. We made 2 little producer/consumer spikes sending an object message with an array of 16 strings, a timestamp, and 2 integers. The spikes are ok on our devs machines (messages are well consumed).\n\nThen came the benchs. We first noticed that somtimes, on our machines, when we were sending a lot of messages the consumer was sometimes hanging. It was there, but the messsages were accumulating in the queue.\n\nWhen we went on the bench plateform :\n\n- cluster of 2 rabbitmq machines 4 cores/3.2Ghz, 4Gb RAM, load balanced by a VIP\n\n- one to 6 consumers running on the rabbitmq machines, saving the messages in a mysql DB (same type of machine for the DB)\n\n- 12 producers running on 12 AS machines (tomcat), attacked with jmeter running on another machine. The load is about 600 to 700 http request per second, on the servlets that produces the same load of RabbitMQ messages.\n\nWe noticed that ***sometimes***, consumers hang (well, they are not blocked, but they dont consume messages anymore). We can see that because each consumer save around 100 msg/sec in database, so when one is stopping consumming, the overall messages saved per seconds in DB fall down with the same ratio (if let say 3 consumers stop, we fall around 600 msg/sec to 300 msg/sec).\n\nDuring that time, the producers are ok, and still produce at the jmeter rate (around 600 msg/sec). The messages are in the queues and taken by the consumers still \"alive\". \n\nWe load all the servlets with the producers first, then launch all the consumers one by one, checking if the connexions are ok, then run jmeter.\n\nWe are sending messages to one direct exchange. All consumers are listening to one persistent queue bounded to the exchange. \n\nThat point is major for our choice. Have you seen this with rabbitmq, do you have an idea of what is going on ?\n\nThank you for your answers.\n\n========================================\n\nTop Answer:\nI have seen this behavior when using the RabbitMQ STOMP plugin. I haven't found a solution yet.\n\nAre you using the STOMP plugin?\n\n========================================\n\nCode:\n```text\nchannel.basicQos(100);\n```\n\n========================================\n\nComments:\n- This might be more appropriate for serverfault.\n- Thanks, I will post it in serverfault either.\n- Strange that there is no mention of versions. For instance Ubuntu and Debian tend to package older versions of stuff but when that stuff is a critical tool that is under active development, like RabbitMQm it is better to run newer versions.\n- @Michael Dillon, after reading the post again, I agree with you. This was with 1.8.0. Now we upgraded to the 2.2.0.\n- Thank you for your response. No we don't. Have you seen a difference with and without STOMP plugin?\n- I've had this problem with the STOMP adapter but not without.\n- Could you elaborate a bit more? How this setting would help to resolve the lost messages issue? Thank you.\n- well, according to the question, the messages are not lost, the consumers *seem* to stop processing more messages. With the basicQos setting, it prevents the consumer from prefetching a great number of messages before the other consumers can fetch messages. With infinite prefetch and if you don't start all your consumers at the same time, the first consumer can prefetch a great number of messages. Theses prefetched messages won't be delivered to the other consumers\n- @Al Bundy I didn't mean that messages were lost, but that some consumers did not consume anymore messages. The messages are in the queue and are not lost.\n- this is untrue.","metadata":{"transformedAt":"2026-08-18T18:33:20.174Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":56,"estimatedTokens":935}}600{"id":"stack-41392248","source":"stackoverflow","questionId":41392248,"title":"Using concurrent.futures to consume many dequeued messages a time","tags":["python","rabbitmq","multiprocessing","pika","concurrent.futures"],"text":"Title: Using concurrent.futures to consume many dequeued messages a time\nTags: python, rabbitmq, multiprocessing, pika, concurrent.futures\nSource: Stack Overflow\n\nQuestion:\nI'm consuming messages from a RabbitMQ channel, I wish I could consume n elements at a time. I think I could use a ProcessPoolExecutor (or ThreadPoolExecutor).\nI just wonder if it's possible to know if there's a free executor in the pool.\n\nThis is what I want to write:\n\n```\nexecutor = futures.ProcessPoolExecutor(max_workers=5)\nrunning = []\ndef consume(message):\n print \"actually consuming a single message\"\n\ndef on_message(channel, method_frame, header_frame, message):\n # this method is called once per incoming message\n future = executor.submit(consume, message)\n block_until_a_free_worker(executor, future)\n\ndef block_until_a_free_worker(executor, future):\n running.append(future) # this grows forever!\n futures.wait(running, timeout=5, return_when=futures.FIRST_COMPLETED)\n\n[...]\nchannel.basic_consume(on_message, 'my_queue')\nchannel.start_consuming()\n```\n\nI need to write the function block_until_a_free_worker.\nThis methods should be able to check if all the running workers are in use or not. \n\nIn alternative I could use any blocking executor.submit option, if available.\n\nI tried a different approach and change the list of futures meanwhile they are completed.\nI tried to explicitly add and remove futures from a list and then waiting like this:\n\n```\nfutures.wait(running, timeout=5, return_when=futures.FIRST_COMPLETED)\n```\n\nIt seems it's not a solution.\n\nI could set a future.add_done_callback, and possibily count the running instances...\n\nAny hint or ideas?\nThank you.\n\n========================================\n\nCode:\n```text\nexecutor = futures.ProcessPoolExecutor(max_workers=5)\nrunning = []\ndef consume(message):\n print \"actually consuming a single message\"\n\ndef on_message(channel, method_frame, header_frame, message):\n # this method is called once per incoming message\n future = executor.submit(consume, message)\n block_until_a_free_worker(executor, future)\n\ndef block_until_a_free_worker(executor, future):\n running.append(future) # this grows forever!\n futures.wait(running, timeout=5, return_when=futures.FIRST_COMPLETED)\n\n[...]\nchannel.basic_consume(on_message, 'my_queue')\nchannel.start_consuming()\n```\n\n```text\nfutures.wait(running, timeout=5, return_when=futures.FIRST_COMPLETED)\n```\n\n```text\nfrom threading import Semaphore\nfrom concurrent.futures import ProcessPoolExecutor \n\nclass TaskManager:\n def __init__(self, workers):\n self.pool = ProcessPoolExecutor(max_workers=workers)\n self.workers = Semaphore(workers)\n\n def new_task(self, function):\n \"\"\"Start a new task, blocks if all workers are busy.\"\"\"\n self.workers.acquire() # flag a worker as busy\n\n future = self.pool.submit(function, ... )\n\n future.add_task_done(self.task_done)\n\n def task_done(self, future):\n \"\"\"Called once task is done, releases one worker.\"\"\"\n self.workers.release()\n```\n\n========================================\n\nComments:\n- Possibly a solution, based on multiprocessing.Pool and a Semaphore, initialised with the number of workers: stackoverflow.com/questions/9601802/…","metadata":{"transformedAt":"2026-08-18T18:33:20.174Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":102,"estimatedTokens":811}}601{"id":"stack-3621772","source":"stackoverflow","questionId":3621772,"title":"Producer work consistently hashing to consumers via a message queue?","tags":["rabbitmq","amqp","producer-consumer","consistent-hashing"],"text":"Title: Producer work consistently hashing to consumers via a message queue?\nTags: rabbitmq, amqp, producer-consumer, consistent-hashing\nSource: Stack Overflow\n\nQuestion:\nI have a producer that I want to distribute work consistently across consumers by consistent hashing. For example, with consumer nodes X and Y, tasks A, B, C should always go to consumer X, and D, E, F to consumer Y. But that may shift a little if Z joins the pool of consumers.\n\nI didn't want to deal with writing my own logic to connect to the consumer nodes, and especially not with managing nodes joining and leaving the pool, so I've gone down the path of using RabbitMQ, and an exclusive queue per consumer node.\n\nOne problem I'm running into is listing these queues, since the producer needs to know all the available queues before work is distributed. AMQP doesn't even support listing queues, which makes me uncertain of my whole approach. RabbitMQ and Alice (brokenly at the moment) add that functionality though: Is there an API for listing queues and exchanges on RabbitMQ? \n\nIs this a wise use of Rabbit? Should I be using a message queue at all? Is there a better design so the queue can *consistently* divide my work among consumers, instead of me needing to do it?\n\n========================================\n\nTop Answer:\nYou could use the official consistent-hashing plugin for rabbitmq as answered here\n\n========================================\n\nComments:\n- Out of curiousity, why do you care so much about consistency when dividing up the work? As you say, the mapping will shift when consumers are added or removed.\n- You could say it's for \"locality of reference.\" Consumer X doesn't know in advance it will be working on A but it would be of benefit if X always got tasks equal to or like A. (Sorry for the vagueness.) Anyway, for my purposes, a little shifting is fine. Changes in the pool should be rare.\n- Possible duplicate of Key-aware consumers in RabbitMQ\n- Very thorough, encouraging answer! One question. You say consumers don't bind themselves. Is this any different than consumers binding themselves with a routing key equal to their queue name? Then instead of list_consumers I list_queues directly, no further binding needed.\n- Queues are automatically bound to amq.default (a direct exchange) with their name as binding key. As far as I can tell, this isn't what you want. You're not publishing to consumers, so to say, you're publishing to task types and you want some consumers to handle many tasks. So, I was thinking of a one-task-one-binding mapping and the consumers which deal with multiple tasks have multiple bindings. In addition, since when the bindings change, all (most) of them change, it doesn't seem right for a consumer to handle this, so the producer seems a better suited for the job.\n- Good view, will it lost messages when rebinding?","metadata":{"transformedAt":"2026-08-18T18:33:20.174Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":27,"estimatedTokens":715}}602{"id":"stack-73001226","source":"stackoverflow","questionId":73001226,"title":"RabbitMQ Kubernetes Operator - Set Username and Password with Secret","tags":["kubernetes","rabbitmq"],"text":"Title: RabbitMQ Kubernetes Operator - Set Username and Password with Secret\nTags: kubernetes, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am using the RabbitMQ Kubernetes operator for a dev-instance and it works great. What isn't great is that the credentials generated by the operator are different for everyone on the team (I'm guessing it generates random creds upon init).\n\nIs there a way to provide a secret and have the operator use those credentials in place of the generated ones?\n\nYaml:\n\n```\napiVersion: rabbitmq.com/v1beta1\nkind: RabbitmqCluster\nmetadata:\n name: rabbitmq-cluster-deployment\n namespace: message-brokers\nspec:\n replicas: 1\n service:\n type: LoadBalancer\n```\n\nIdeally, I can just configure some yaml to point to a secret and go from there. But, struggling to find the documentation around this piece.\n\nExample Username/Password generated:\n\n- user: default_user_wNSgVBIyMIElsGRrpwb\n\n- pass: cGvQ6T-5gRt0Rc4C3AdXdXDB43NRS6FJ\n\n========================================\n\nCode:\n```text\napiVersion: rabbitmq.com/v1beta1\nkind: RabbitmqCluster\nmetadata:\n name: rabbitmq-cluster-deployment\n namespace: message-brokers\nspec:\n replicas: 1\n service:\n type: LoadBalancer\n```\n\n```text\nkind: Secret\napiVersion: v1\nmetadata:\n name: rabbitmq-cluster-deployment-default-user\n namespace: message-brokers\nstringData:\n default_user.conf: |\n default_user = user123\n default_pass = password123\n password: password123\n username: user123\ntype: Opaque\n```\n\n```text\napiVersion: rabbitmq.com/v1beta1\nkind: RabbitmqCluster\nmetadata:\n name: external-secret-user\nspec:\n service:\n type: LoadBalancer\n replicas: 1\n secretBackend:\n externalSecret: \n name: \"my-secret\"\n```\n\n```text\napiVersion: v1\ndata:\n default_user.conf: ZGVmYXVsdF91c2VyID0gZGVmYXVsdF91c2VyX2htR1pGaGRld3E2NVA0ZElkeDcKZGVmYXVsdF9wYXNzID0gcWM5OG40aUdEN01ZWE1CVkZjSU8ybXRCNXZvRHVWX24K\n host: dmF1bHQtZGVmYXVsdC11c2VyLmRlZmF1bHQuc3Zj\n password: cWM5OG40aUdEN01ZWE1CVkZjSU8ybXRCNXZvRHVWX24=\n port: NTY3Mg==\n provider: cmFiYml0bXE=\n type: cmFiYml0bXE=\n username: ZGVmYXVsdF91c2VyX2htR1pGaGRld3E2NVA0ZElkeDc=\nkind: Secret\nmetadata:\n name: my-secret \n namespace: rabbitmq-system\ntype: Opaque\n```\n\n```text\ndefault_user.confg\n```\n\n```text\nrabbitmq-cluster-deployment-default-user\n```\n\n```text\nmdatadata.name\n```\n\n```text\n-default-user\n```\n\n========================================\n\nComments:\n- Is there any way I can do it through SecretProviderClass? I am storing rabbitMQ username and password to Azure Keyvault and that will be fetched through SecretProviderClass and want to use secrets from there.","metadata":{"transformedAt":"2026-08-18T18:33:20.174Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":112,"estimatedTokens":648}}603{"id":"stack-31324470","source":"stackoverflow","questionId":31324470,"title":"Asynchronous RabbitMQ consumer with aioamqp","tags":["python","asynchronous","rabbitmq","python-asyncio"],"text":"Title: Asynchronous RabbitMQ consumer with aioamqp\nTags: python, asynchronous, rabbitmq, python-asyncio\nSource: Stack Overflow\n\nQuestion:\nI'm trying to write an asynchronous consumer using asyncio/aioamqp. My problem is, the callback coroutine (below) is blocking. I set the channel to do a basic_consume(), and assign the callback as callback(). The callback has a \"yield from asyncio.sleep\" statement (to simulate \"work\"), which takes an integer from the publisher and sleeps for that amount of time before printing the message. \n\nIf I published two messages, one with a time of \"10\", immediately followed by one with a time of \"1\", I expected the second message would print first, since it has a shorter sleep time. Instead, the callback blocks for 10 seconds, prints the first message, and then prints the second.\n\nIt appears either basic_consume, or the callback, is blocking somewhere. Is there another way this could be handled?\n\n```\n@asyncio.coroutine\ndef callback(body, envelope, properties):\n yield from asyncio.sleep(int(body))\n print(\"consumer {} recved {} ({})\".format(envelope.consumer_tag, body, envelope.delivery_tag))\n\n@asyncio.coroutine\ndef receive_log():\n try:\n transport, protocol = yield from aioamqp.connect('localhost', 5672, login=\"login\", password=\"password\")\n except:\n print(\"closed connections\")\n return\n\n channel = yield from protocol.channel()\n exchange_name = 'cloudstack-events'\n exchange_name = 'test-async-exchange'\n queue_name = 'async-queue-%s' % random.randint(0, 10000)\n yield from channel.exchange(exchange_name, 'topic', auto_delete=True, passive=False, durable=False)\n yield from asyncio.wait_for(channel.queue(queue_name, durable=False, auto_delete=True), timeout=10)\n\n binding_keys = ['mykey']\n\n for binding_key in binding_keys:\n print(\"binding\", binding_key)\n yield from asyncio.wait_for(channel.queue_bind(exchange_name=exchange_name,\n queue_name=queue_name,\n routing_key=binding_key), timeout=10)\n\n print(' [*] Waiting for logs. To exit press CTRL+C')\n yield from channel.basic_consume(queue_name, callback=callback)\n\nloop = asyncio.get_event_loop()\nloop.create_task(receive_log())\nloop.run_forever()\n```\n\n========================================\n\nCode:\n```text\n@asyncio.coroutine\ndef callback(body, envelope, properties):\n yield from asyncio.sleep(int(body))\n print(\"consumer {} recved {} ({})\".format(envelope.consumer_tag, body, envelope.delivery_tag))\n\n@asyncio.coroutine\ndef receive_log():\n try:\n transport, protocol = yield from aioamqp.connect('localhost', 5672, login=\"login\", password=\"password\")\n except:\n print(\"closed connections\")\n return\n\n channel = yield from protocol.channel()\n exchange_name = 'cloudstack-events'\n exchange_name = 'test-async-exchange'\n queue_name = 'async-queue-%s' % random.randint(0, 10000)\n yield from channel.exchange(exchange_name, 'topic', auto_delete=True, passive=False, durable=False)\n yield from asyncio.wait_for(channel.queue(queue_name, durable=False, auto_delete=True), timeout=10)\n\n binding_keys = ['mykey']\n\n for binding_key in binding_keys:\n print(\"binding\", binding_key)\n yield from asyncio.wait_for(channel.queue_bind(exchange_name=exchange_name,\n queue_name=queue_name,\n routing_key=binding_key), timeout=10)\n\n print(' [*] Waiting for logs. To exit press CTRL+C')\n yield from channel.basic_consume(queue_name, callback=callback)\n\nloop = asyncio.get_event_loop()\nloop.create_task(receive_log())\nloop.run_forever()\n```\n\n```text\n@asyncio.coroutine\ndef do_work(envelope, body):\n yield from asyncio.sleep(int(body))\n print(\"consumer {} recved {} ({})\".format(envelope.consumer_tag, body, envelope.delivery_tag))\n\n@asyncio.coroutine\ndef callback(body, envelope, properties):\n loop = asyncio.get_event_loop()\n loop.create_task(do_work(envelope, body))\n\n@asyncio.coroutine\ndef receive_log():\n try:\n transport, protocol = yield from aioamqp.connect('localhost', 5672, login=\"login\", password=\"password\")\n except:\n print(\"closed connections\")\n return\n\n channel = yield from protocol.channel()\n exchange_name = 'cloudstack-events'\n exchange_name = 'test-async-exchange'\n queue_name = 'async-queue-%s' % random.randint(0, 10000)\n yield from channel.exchange(exchange_name, 'topic', auto_delete=True, passive=False, durable=False)\n yield from asyncio.wait_for(channel.queue(queue_name, durable=False, auto_delete=True), timeout=10)\n\n binding_keys = ['mykey']\n\n for binding_key in binding_keys:\n print(\"binding\", binding_key)\n yield from asyncio.wait_for(channel.queue_bind(exchange_name=exchange_name,\n queue_name=queue_name,\n routing_key=binding_key), timeout=10)\n\n print(' [*] Waiting for logs. To exit press CTRL+C')\n yield from channel.basic_consume(queue_name, callback=callback)\n\nloop = asyncio.get_event_loop()\nloop.create_task(receive_log())\nloop.run_forever()\n```\n\n========================================\n\nComments:\n- How many consumers do you have?\n- Just one consumer. But I'm publishing multiple events with different timeouts, and it seems to block on asyncio.sleep(). I think the entire coroutine chain is paused when I do that, so I don't get the next event until the current one finishes. What I'm trying to do instead is schedule a loop.create_task() within the callback, which calls another coroutine to do the actual work (asyncio.sleep in this case). Maybe that will let the callback exit immediately so I can receive additional messages. Going to test it out and see if it works.\n- `aioamqp` probably calls `yield from callback(*args)` internally, so that the callbacks always run sequentially (since that might be desired behavior). The way you're handling getting concurrent callbacks (by scheduling the work inside your callback implementation instead of actually waiting for it to be done) is the right way to do it.","metadata":{"transformedAt":"2026-08-18T18:33:20.174Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":136,"estimatedTokens":1526}}604{"id":"stack-64096600","source":"stackoverflow","questionId":64096600,"title":"RabbitMQ Connection refused 127.0.0.1:5672","tags":["asp.net",".net-core","rabbitmq"],"text":"Title: RabbitMQ Connection refused 127.0.0.1:5672\nTags: asp.net, .net-core, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am preparing a simple ASP.NET Core MVC web application.\n\nI have installed RabbitMQ server to my laptop. RabbitMQ Management UI is running on `localhost:15672`.\n\nRabbit MQ cluster name is like: `rabbit@CR00001.ABC.COM.LOCAL`\n\nI am trying to send message to rabbitmq in controller. But I am getting **None of the specified endpoints were reachable** error.\n\nIf I use 'localhost' as host name, I get **Connection refused 127.0.0.1:5672** in inner exceptions.\n\nIf I use `rabbit` as host name, I get **Name or service not known**\n\nI've tried to solve the problem according to other StackOverflow questions, however, none of them could solved my problem.\n\n**Home controller:**\n\n```\n[HttpPost]\n public void SendMessage([FromBody]Message message)\n {\n try\n {\n var factory = new ConnectionFactory()\n {\n UserName = _username,\n Password = _password,\n HostName = _hostname,\n VirtualHost = \"/\",\n Port = _port,\n };\n using (var connection = factory.CreateConnection())\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(queue: _queueName,\n durable: false,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n\n var body = Encoding.UTF8.GetBytes(message.Text);\n\n channel.BasicPublish(exchange: \"\",\n routingKey: _queueName,\n basicProperties: null,\n body: body);\n }\n\n }\n catch (Exception ex)\n {\n\n }\n }\n```\n\n**appsettings.json**\n\n```\n{\n \"Logging\": {\n \"LogLevel\": {\n \"Default\": \"Information\",\n \"Microsoft\": \"Warning\",\n \"Microsoft.Hosting.Lifetime\": \"Information\"\n }\n },\n \"AllowedHosts\": \"*\",\n \"RabbitMq\": {\n \"Hostname\": \"localhost\",\n \"QueueName\": \"WordQueue\",\n \"UserName\": \"test\",\n \"Password\": \"test\",\n \"Port\": 5672\n }\n}\n```\n\nHere is test user configuration in Rabbit MQ Management UI\nhttps://i.sstatic.net/TTKIb.png\n\n========================================\n\nTop Answer:\nAfter create user, do not forget set permissions,\nbasicaly,\n\ncan access virtual hosts (/)\n\nset topic permission (AMQP default)\nNote: of course you can use rabbitmq ui for this operation (create user and permissions).\nhttps://i.sstatic.net/cYrx9.png\n\nvar factory = new ConnectionFactory() { HostName = \"hostname_or_ip_adres_here\", UserName=\"username here..\", Password=\"psw here..\"\n};\n\nthis will work !\n\n========================================\n\nCode:\n```text\n[HttpPost]\n public void SendMessage([FromBody]Message message)\n {\n try\n {\n var factory = new ConnectionFactory()\n {\n UserName = _username,\n Password = _password,\n HostName = _hostname,\n VirtualHost = \"/\",\n Port = _port,\n };\n using (var connection = factory.CreateConnection())\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(queue: _queueName,\n durable: false,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n\n var body = Encoding.UTF8.GetBytes(message.Text);\n\n channel.BasicPublish(exchange: \"\",\n routingKey: _queueName,\n basicProperties: null,\n body: body);\n }\n\n }\n catch (Exception ex)\n {\n\n }\n }\n```\n\n```text\n{\n \"Logging\": {\n \"LogLevel\": {\n \"Default\": \"Information\",\n \"Microsoft\": \"Warning\",\n \"Microsoft.Hosting.Lifetime\": \"Information\"\n }\n },\n \"AllowedHosts\": \"*\",\n \"RabbitMq\": {\n \"Hostname\": \"localhost\",\n \"QueueName\": \"WordQueue\",\n \"UserName\": \"test\",\n \"Password\": \"test\",\n \"Port\": 5672\n }\n}\n```\n\n```text\nlocalhost:15672\n```\n\n```text\nrabbit@CR00001.ABC.COM.LOCAL\n```\n\n```text\nrabbit\n```\n\n```text\ntest\n```\n\n```text\nfactory\n```\n\n```text\nhttp://rabbit\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.175Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":187,"estimatedTokens":1029}}605{"id":"stack-30830075","source":"stackoverflow","questionId":30830075,"title":"Celery/RabbitMQ unacked messages blocking queue?","tags":["python","rabbitmq","celery","urllib2"],"text":"Title: Celery/RabbitMQ unacked messages blocking queue?\nTags: python, rabbitmq, celery, urllib2\nSource: Stack Overflow\n\nQuestion:\nI have invoked a task that fetches some information remotely with urllib2 a few thousand times. The tasks are scheduled with a random eta (within a week) so they all don't hit the server at the same time. Sometimes I get a 404, sometimes not. I am handling the error in case it happens.\n\nIn the RabbitMQ console I can see 16 unacknowledged messages: \n\nI stopped celery, purged the queue and restarted it. The 16 unacknowledged messages were still there.\n\nI have other tasks that go to the same queue and none of them was executed either. After purging, I tried to submit another task and it's state remains *ready*:\n\n**Any ideas how I can find out why messages remain unacknowledged?**\n\n**Versions:**\n\n```\ncelery==3.1.4\n{rabbit,\"RabbitMQ\",\"3.5.3\"}\n```\n\n**celeryapp.py**\n\n```\nCELERYBEAT_SCHEDULE = {\n 'social_grabber': {\n 'task': '.tasks.task_social_grabber',\n 'schedule': crontab(hour=5, minute=0, day_of_week='sunday'),\n },\n}\n```\n\n**tasks.py**\n\n```\n@app.task\ndef task_social_grabber():\n for user in users:\n eta = randint(0, 60 * 60 * 24 * 7) #week in seconds\n task_social_grabber_single.apply_async((user), countdown=eta)\n```\n\nThere is no routing for this task defined so it goes into the default queue: *celery*. There is one worker processing this queue.\n\n**supervisord.conf:**\n\n```\n[program:celery]\nautostart = true\nautorestart = true\ncommand = celery worker -A .celeryapp:app --concurrency=3 -l INFO -n celery\n```\n\n========================================\n\nTop Answer:\nI had a similar symptoms. Messages where getting to the MQ (visible in the charts) but where not picked up by the worker. \n\nThis led me to the assumption that my Django app had correctly setup Celery app, but I was missing an import ensuring Celery would be configured during Django startup:\n\n```\nfrom __future__ import absolute_import\n\n# This will make sure the app is always imported when\n# Django starts so that shared_task will use this app.\nfrom .celery import app as celery_app # noqa\n```\n\nIt is a silly mistake, but the messages getting to the broker, having returned an AsyncResult, got me off track, and made me looking i the wrong places. Then I noticed that setting `CELERY_ALWAYS_EAGER = True` didn't do squat, event then tasks weren't executed at all.\n\nPS: This may not be an answer to @kev question, but since I got here couple of times, while looking for the solution to my problem, I post it here for anyone in similar situation.\n\n========================================\n\nCode:\n```text\ncelery==3.1.4\n{rabbit,\"RabbitMQ\",\"3.5.3\"}\n```\n\n```text\nCELERYBEAT_SCHEDULE = {\n 'social_grabber': {\n 'task': '<django app>.tasks.task_social_grabber',\n 'schedule': crontab(hour=5, minute=0, day_of_week='sunday'),\n },\n}\n```\n\n```text\n@app.task\ndef task_social_grabber():\n for user in users:\n eta = randint(0, 60 * 60 * 24 * 7) #week in seconds\n task_social_grabber_single.apply_async((user), countdown=eta)\n```\n\n```text\n[program:celery]\nautostart = true\nautorestart = true\ncommand = celery worker -A <django app>.celeryapp:app --concurrency=3 -l INFO -n celery\n```\n\n```text\nfrom __future__ import absolute_import\n\n# This will make sure the app is always imported when\n# Django starts so that shared_task will use this app.\nfrom .celery import app as celery_app # noqa\n```\n\n```text\nCELERY_ALWAYS_EAGER = True\n```\n\n========================================\n\nComments:\n- Can you post your celery config, celery version, and RabbitMQ version?\n- Hi @Eric, I'm hitting the same problem (16 jobs stuck in the queue in unack state). There are no task with eta, only a scheduler process and 3 worker processes, no routing. My queue gets stuck every few hours and the only way to unstuck it is restarting both process types. I'm on heroku, versions kombu==3.0.26 and celery==3.1.17. Is there any other thing I could look into to sort this out?\n- @Flevour You should probably open your own question for this and include kombu, celery, and RabbitMQ versions along with any logging or output for your workers and the code for your tasks.\n- @Flevour did you find a solution to your problem?","metadata":{"transformedAt":"2026-08-18T18:33:20.175Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":124,"estimatedTokens":1055}}606{"id":"stack-24189260","source":"stackoverflow","questionId":24189260,"title":"Calling celery task hangs for delay and apply_async","tags":["python","python-2.7","rabbitmq","celery"],"text":"Title: Calling celery task hangs for delay and apply_async\nTags: python, python-2.7, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI have created a celery app with following directory structure (as given in celery site):\n\n```\nproj\n|-- celery.py\n|-- celery.pyc\n|-- __init__.py\n|-- __init__.pyc\n|-- tasks.py\n`-- tasks.pyc\n```\n\nFollowing are contents of celery.py\n\n```\nfrom __future__ import absolute_import\n\nfrom celery import Celery\n\napp = Celery('proj',\n broker='amqp://rabbitmquser:@localhost:5672/localvhost',\n #backend='amqp://',\n include=['proj.tasks'])\n\n# Optional configuration, see the application user guide.\napp.conf.update(\n CELERY_TASK_RESULT_EXPIRES=3600,\n)\n\nif __name__ == '__main__':\n app.start()\n```\n\nFollowing is the content of tasks.py\n\n```\nfrom __future__ import absolute_import\n\nfrom proj.celery import app\n\n@app.task\ndef add(x, y):\n return x + y\n\n@app.task\ndef mul(x, y):\n return x * y\n\n@app.task\ndef xsum(numbers):\n return sum(numbers)\n```\n\nNow I am starting celery worker with following command:\n\n```\ncelery -A proj worker -l debug\n```\n\nI think worker is running fine as it outputs following on:\n\n```\n[2014-06-12 21:25:02,326: DEBUG/MainProcess] | Worker: Preparing bootsteps.\n[2014-06-12 21:25:02,328: DEBUG/MainProcess] | Worker: Building graph...\n[2014-06-12 21:25:02,328: DEBUG/MainProcess] | Worker: New boot order: {Timer, Hub, Queues (intra), Pool, Autoscaler, Beat, Autoreloader, StateDB, Consumer}\n[2014-06-12 21:25:02,331: DEBUG/MainProcess] | Consumer: Preparing bootsteps.\n[2014-06-12 21:25:02,331: DEBUG/MainProcess] | Consumer: Building graph...\n[2014-06-12 21:25:02,334: DEBUG/MainProcess] | Consumer: New boot order: {Connection, Events, Mingle, Tasks, Control, Agent, Heart, Gossip, event loop}\n[2014-06-12 21:25:02,335: WARNING/MainProcess] /home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/celery/apps/worker.py:161: CDeprecationWarning: \nStarting from version 3.2 Celery will refuse to accept pickle by default.\n\nThe pickle serializer is a security concern as it may give attackers\nthe ability to execute any command. It's important to secure\nyour broker from unauthorized access when using pickle, so we think\nthat enabling pickle should require a deliberate action and not be\nthe default choice.\n\nIf you depend on pickle then you should set a setting to disable this\nwarning and to be sure that everything will continue working\nwhen you upgrade to Celery 3.2::\n\n CELERY_ACCEPT_CONTENT = ['pickle', 'json', 'msgpack', 'yaml']\n\nYou must only enable the serializers that you will actually use.\n\n warnings.warn(CDeprecationWarning(W_PICKLE_DEPRECATED))\n\n -------------- celery@ansumanb-u12 v3.1.12 (Cipater)\n---- **** ----- \n--- * *** * -- Linux-3.5.0-25-generic-x86_64-with-Ubuntu-12.04-precise\n-- * - **** --- \n- ** ---------- [config]\n- ** ---------- .> app: proj:0x1f46690\n- ** ---------- .> transport: amqp://rabbitmquser:**@localhost:5672/localvhost\n- ** ---------- .> results: disabled\n- *** --- * --- .> concurrency: 4 (prefork)\n-- ******* ---- \n--- ***** ----- [queues]\n -------------- .> celery exchange=celery(direct) key=celery\n\n[tasks]\n . celery.backend_cleanup\n . celery.chain\n . celery.chord\n . celery.chord_unlock\n . celery.chunks\n . celery.group\n . celery.map\n . celery.starmap\n . proj.tasks.add\n . proj.tasks.mul\n . proj.tasks.xsum\n\n[2014-06-12 21:25:02,336: DEBUG/MainProcess] | Worker: Starting Hub\n[2014-06-12 21:25:02,336: DEBUG/MainProcess] ^-- substep ok\n[2014-06-12 21:25:02,336: DEBUG/MainProcess] | Worker: Starting Pool\n[2014-06-12 21:25:02,344: DEBUG/MainProcess] ^-- substep ok\n[2014-06-12 21:25:02,345: DEBUG/MainProcess] | Worker: Starting Consumer\n[2014-06-12 21:25:02,345: DEBUG/MainProcess] | Consumer: Starting Connection\n```\n\nAfter running the worker I am opening the terminal and from python interpreter and executing following:\n\n```\n>>> from proj.tasks import add\n>>> add(2,2)\n4\n>>> add.delay(2,3)\n```\n\nHere the delay hangs (same story for apply_async). When I am stopping it by Ctrl+C I am getting following:\n\n```\n^CTraceback (most recent call last):\n File \"\", line 1, in \n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/celery/app/task.py\", line 453, in delay\n return self.apply_async(args, kwargs)\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/celery/app/task.py\", line 555, in apply_async\n **dict(self._get_exec_options(), **options)\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/celery/app/base.py\", line 352, in send_task\n reply_to=reply_to or self.oid, **options\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/celery/app/amqp.py\", line 305, in publish_task\n **kwargs\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/kombu/messaging.py\", line 168, in publish\n routing_key, mandatory, immediate, exchange, declare)\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/kombu/connection.py\", line 436, in _ensured\n return fun(*args, **kwargs)\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/kombu/messaging.py\", line 173, in _publish\n channel = self.channel\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/kombu/messaging.py\", line 190, in _get_channel\n channel = self._channel = channel()\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/kombu/utils/__init__.py\", line 422, in __call__\n value = self.__value__ = self.__contract__()\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/kombu/messaging.py\", line 205, in \n channel = ChannelPromise(lambda: connection.default_channel)\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/kombu/connection.py\", line 756, in default_channel\n self.connection\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/kombu/connection.py\", line 741, in connection\n self._connection = self._establish_connection()\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/kombu/connection.py\", line 696, in _establish_connection\n conn = self.transport.establish_connection()\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/kombu/transport/pyamqp.py\", line 112, in establish_connection\n conn = self.Connection(**opts)\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/amqp/connection.py\", line 171, in __init__\n (10, 10), # start\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/amqp/abstract_channel.py\", line 67, in wait\n self.channel_id, allowed_methods)\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/amqp/connection.py\", line 237, in _wait_method\n self.method_reader.read_method()\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/amqp/method_framing.py\", line 186, in read_method\n self._next_method()\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/amqp/method_framing.py\", line 107, in _next_method\n frame_type, channel, payload = read_frame()\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/amqp/transport.py\", line 153, in read_frame\n frame_type, channel, size = unpack('>BHI', read(7, True))\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/amqp/transport.py\", line 272, in _read\n s = recv(n - len(rbuf))\nKeyboardInterrupt\n```\n\nAny suggestion or comment will be much appreciated. \nI have gone through other links where they talk about /var directory size but I think I have enough space.\n\nResult of df -h\n\n```\nFilesystem Size Used Avail Use% Mounted on\n/dev/sda3 283G 99G 170G 37% /\nudev 1.9G 4.0K 1.9G 1% /dev\ntmpfs 388M 1.1M 387M 1% /run\nnone 5.0M 0 5.0M 0% /run/lock\nnone 1.9G 28M 1.9G 2% /run/shm\n```\n\nfollowing is the result of rabbitmqctl status\n\n```\nStatus of node 'rabbit@ansumanb-u12' ...\n[{pid,12014},\n {running_applications,[{rabbit,\"RabbitMQ\",\"3.3.2\"},\n {os_mon,\"CPO CXC 138 46\",\"2.2.7\"},\n {xmerl,\"XML parser\",\"1.2.10\"},\n {mnesia,\"MNESIA CXC 138 12\",\"4.5\"},\n {sasl,\"SASL CXC 138 11\",\"2.1.10\"},\n {stdlib,\"ERTS CXC 138 10\",\"1.17.5\"},\n {kernel,\"ERTS CXC 138 10\",\"2.14.5\"}]},\n {os,{unix,linux}},\n {erlang_version,\"Erlang R14B04 (erts-5.8.5) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:30] [kernel-poll:true]\\n\"},\n {memory,[{total,27919080},\n {connection_procs,2704},\n {queue_procs,5408},\n {plugins,0},\n {other_proc,9099992},\n {mnesia,63776},\n {mgmt_db,0},\n {msg_index,34080},\n {other_ets,784160},\n {binary,12144},\n {code,14685283},\n {atom,1367393},\n {other_system,1864140}]},\n {alarms,[]},\n {listeners,[{clustering,25672,\"::\"},{amqp,5672,\"::\"}]},\n {vm_memory_high_watermark,0.4},\n {vm_memory_limit,1625165004},\n {disk_free_limit,50000000},\n {disk_free,181684699136},\n {file_descriptors,[{total_limit,2},\n {total_used,0},\n {sockets_limit,0},\n {sockets_used,0}]},\n {processes,[{limit,1048576},{used,127}]},\n {run_queue,0},\n {uptime,20072}]\n...done.\n```\n\nI've checked the rabbitmq logs and didn't get anything there. Celery version is 3.1.12.\n\nI have created rabbitmq virtual host and user with following commands\n\n```\n$ sudo rabbitmqctl add_user rabbitmquser \n$ sudo rabbitmqctl add_vhost localvhost\n$ sudo rabbitmqctl set_permissions -p localvhost rabbitmquser \".*\" \".*\" \".*\"\n```\n\nThanks\n\n========================================\n\nCode:\n```text\nproj\n|-- celery.py\n|-- celery.pyc\n|-- __init__.py\n|-- __init__.pyc\n|-- tasks.py\n`-- tasks.pyc\n```\n\n```text\nfrom __future__ import absolute_import\n\nfrom celery import Celery\n\napp = Celery('proj',\n broker='amqp://rabbitmquser:<my_passowrd>@localhost:5672/localvhost',\n #backend='amqp://',\n include=['proj.tasks'])\n\n# Optional configuration, see the application user guide.\napp.conf.update(\n CELERY_TASK_RESULT_EXPIRES=3600,\n)\n\nif __name__ == '__main__':\n app.start()\n```\n\n```text\nfrom __future__ import absolute_import\n\nfrom proj.celery import app\n\n\n@app.task\ndef add(x, y):\n return x + y\n\n\n@app.task\ndef mul(x, y):\n return x * y\n\n\n@app.task\ndef xsum(numbers):\n return sum(numbers)\n```\n\n```text\ncelery -A proj worker -l debug\n```\n\n```text\n[2014-06-12 21:25:02,326: DEBUG/MainProcess] | Worker: Preparing bootsteps.\n[2014-06-12 21:25:02,328: DEBUG/MainProcess] | Worker: Building graph...\n[2014-06-12 21:25:02,328: DEBUG/MainProcess] | Worker: New boot order: {Timer, Hub, Queues (intra), Pool, Autoscaler, Beat, Autoreloader, StateDB, Consumer}\n[2014-06-12 21:25:02,331: DEBUG/MainProcess] | Consumer: Preparing bootsteps.\n[2014-06-12 21:25:02,331: DEBUG/MainProcess] | Consumer: Building graph...\n[2014-06-12 21:25:02,334: DEBUG/MainProcess] | Consumer: New boot order: {Connection, Events, Mingle, Tasks, Control, Agent, Heart, Gossip, event loop}\n[2014-06-12 21:25:02,335: WARNING/MainProcess] /home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/celery/apps/worker.py:161: CDeprecationWarning: \nStarting from version 3.2 Celery will refuse to accept pickle by default.\n\nThe pickle serializer is a security concern as it may give attackers\nthe ability to execute any command. It's important to secure\nyour broker from unauthorized access when using pickle, so we think\nthat enabling pickle should require a deliberate action and not be\nthe default choice.\n\nIf you depend on pickle then you should set a setting to disable this\nwarning and to be sure that everything will continue working\nwhen you upgrade to Celery 3.2::\n\n CELERY_ACCEPT_CONTENT = ['pickle', 'json', 'msgpack', 'yaml']\n\nYou must only enable the serializers that you will actually use.\n\n\n warnings.warn(CDeprecationWarning(W_PICKLE_DEPRECATED))\n\n -------------- celery@ansumanb-u12 v3.1.12 (Cipater)\n---- **** ----- \n--- * *** * -- Linux-3.5.0-25-generic-x86_64-with-Ubuntu-12.04-precise\n-- * - **** --- \n- ** ---------- [config]\n- ** ---------- .> app: proj:0x1f46690\n- ** ---------- .> transport: amqp://rabbitmquser:**@localhost:5672/localvhost\n- ** ---------- .> results: disabled\n- *** --- * --- .> concurrency: 4 (prefork)\n-- ******* ---- \n--- ***** ----- [queues]\n -------------- .> celery exchange=celery(direct) key=celery\n\n\n[tasks]\n . celery.backend_cleanup\n . celery.chain\n . celery.chord\n . celery.chord_unlock\n . celery.chunks\n . celery.group\n . celery.map\n . celery.starmap\n . proj.tasks.add\n . proj.tasks.mul\n . proj.tasks.xsum\n\n[2014-06-12 21:25:02,336: DEBUG/MainProcess] | Worker: Starting Hub\n[2014-06-12 21:25:02,336: DEBUG/MainProcess] ^-- substep ok\n[2014-06-12 21:25:02,336: DEBUG/MainProcess] | Worker: Starting Pool\n[2014-06-12 21:25:02,344: DEBUG/MainProcess] ^-- substep ok\n[2014-06-12 21:25:02,345: DEBUG/MainProcess] | Worker: Starting Consumer\n[2014-06-12 21:25:02,345: DEBUG/MainProcess] | Consumer: Starting Connection\n```\n\n```text\n>>> from proj.tasks import add\n>>> add(2,2)\n4\n>>> add.delay(2,3)\n```\n\n```text\n^CTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/celery/app/task.py\", line 453, in delay\n return self.apply_async(args, kwargs)\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/celery/app/task.py\", line 555, in apply_async\n **dict(self._get_exec_options(), **options)\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/celery/app/base.py\", line 352, in send_task\n reply_to=reply_to or self.oid, **options\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/celery/app/amqp.py\", line 305, in publish_task\n **kwargs\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/kombu/messaging.py\", line 168, in publish\n routing_key, mandatory, immediate, exchange, declare)\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/kombu/connection.py\", line 436, in _ensured\n return fun(*args, **kwargs)\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/kombu/messaging.py\", line 173, in _publish\n channel = self.channel\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/kombu/messaging.py\", line 190, in _get_channel\n channel = self._channel = channel()\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/kombu/utils/__init__.py\", line 422, in __call__\n value = self.__value__ = self.__contract__()\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/kombu/messaging.py\", line 205, in <lambda>\n channel = ChannelPromise(lambda: connection.default_channel)\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/kombu/connection.py\", line 756, in default_channel\n self.connection\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/kombu/connection.py\", line 741, in connection\n self._connection = self._establish_connection()\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/kombu/connection.py\", line 696, in _establish_connection\n conn = self.transport.establish_connection()\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/kombu/transport/pyamqp.py\", line 112, in establish_connection\n conn = self.Connection(**opts)\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/amqp/connection.py\", line 171, in __init__\n (10, 10), # start\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/amqp/abstract_channel.py\", line 67, in wait\n self.channel_id, allowed_methods)\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/amqp/connection.py\", line 237, in _wait_method\n self.method_reader.read_method()\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/amqp/method_framing.py\", line 186, in read_method\n self._next_method()\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/amqp/method_framing.py\", line 107, in _next_method\n frame_type, channel, payload = read_frame()\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/amqp/transport.py\", line 153, in read_frame\n frame_type, channel, size = unpack('>BHI', read(7, True))\n File \"/home/ansumanb/.virtualenvs/celery_venv/local/lib/python2.7/site-packages/amqp/transport.py\", line 272, in _read\n s = recv(n - len(rbuf))\nKeyboardInterrupt\n```\n\n```text\nFilesystem Size Used Avail Use% Mounted on\n/dev/sda3 283G 99G 170G 37% /\nudev 1.9G 4.0K 1.9G 1% /dev\ntmpfs 388M 1.1M 387M 1% /run\nnone 5.0M 0 5.0M 0% /run/lock\nnone 1.9G 28M 1.9G 2% /run/shm\n```\n\n```text\nStatus of node 'rabbit@ansumanb-u12' ...\n[{pid,12014},\n {running_applications,[{rabbit,\"RabbitMQ\",\"3.3.2\"},\n {os_mon,\"CPO CXC 138 46\",\"2.2.7\"},\n {xmerl,\"XML parser\",\"1.2.10\"},\n {mnesia,\"MNESIA CXC 138 12\",\"4.5\"},\n {sasl,\"SASL CXC 138 11\",\"2.1.10\"},\n {stdlib,\"ERTS CXC 138 10\",\"1.17.5\"},\n {kernel,\"ERTS CXC 138 10\",\"2.14.5\"}]},\n {os,{unix,linux}},\n {erlang_version,\"Erlang R14B04 (erts-5.8.5) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:30] [kernel-poll:true]\\n\"},\n {memory,[{total,27919080},\n {connection_procs,2704},\n {queue_procs,5408},\n {plugins,0},\n {other_proc,9099992},\n {mnesia,63776},\n {mgmt_db,0},\n {msg_index,34080},\n {other_ets,784160},\n {binary,12144},\n {code,14685283},\n {atom,1367393},\n {other_system,1864140}]},\n {alarms,[]},\n {listeners,[{clustering,25672,\"::\"},{amqp,5672,\"::\"}]},\n {vm_memory_high_watermark,0.4},\n {vm_memory_limit,1625165004},\n {disk_free_limit,50000000},\n {disk_free,181684699136},\n {file_descriptors,[{total_limit,2},\n {total_used,0},\n {sockets_limit,0},\n {sockets_used,0}]},\n {processes,[{limit,1048576},{used,127}]},\n {run_queue,0},\n {uptime,20072}]\n...done.\n```\n\n```text\n$ sudo rabbitmqctl add_user rabbitmquser <mypassword>\n$ sudo rabbitmqctl add_vhost localvhost\n$ sudo rabbitmqctl set_permissions -p localvhost rabbitmquser \".*\" \".*\" \".*\"\n```\n\n```text\nulimit\n```\n\n```text\n/etc/default/rabbitmq-server\n```\n\n========================================\n\nComments:\n- It is hanging probably because it cannot reach your rabbit server. `ansumanb-u12` is your machine that is running the celery worker and rabbit, correct? If it is, make sure that your username and password for rabbit are correct in the celery conf and `localhost:5672/localvhost` is correct (I wonder if you need the `/localvhost`). You'll want to add `CELERY_TASK_RESULT_EXPIRES=['json']` to the celery conf in order to get rid of that warning on starting celery and for security issues with pickle.\n- I will check for broker link. How can I make sure broker link is correct? Is there a way to check the connection directly from terminal? Yes, my machine ansumanb-u12 contains celery worker and rabbit. I'll add CELERY_TASK_RESULT_EXPIRES. Thanks.\n- Oh shoot, sorry, that should be `CELERY_ACCEPT_CONTENT`, my mistake. You could drop into an ipython session and try to create the Celery object and start it. `app = Celery('proj', broker='amqp://user:password@hostname//').start()`\n- in the install instructions somewhere is said that you should set it to unlimited, I think its the default in Debian systems anyway since squeeze.","metadata":{"transformedAt":"2026-08-18T18:33:20.175Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":12,"totalLines":499,"estimatedTokens":4948}}607{"id":"stack-4141224","source":"stackoverflow","questionId":4141224,"title":"Celery doesn't return results","tags":["python","rabbitmq","celery"],"text":"Title: Celery doesn't return results\nTags: python, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nFor some reason, whenever I create and run a new Task in Celery there is a problem with returning the results. The first task returns perfectly, but for all subsequent tasks, the result is always pending. I checked the Celery log, and it gets the correct result with no errors, but it just can't return it.\n\nIf it helps, I am running rabbitmq as my backend.\n\n========================================\n\nTop Answer:\nI am also getting the same issue even if I add 'amqp' backend. \n\nHere is my celery config file:\n\n```\nBROKER_HOST = \"localhost\"\nBROKER_PORT = 5672\nBROKER_USER = \"guest\"\nBROKER_PASSWORD = \"guest\"\nBROKER_VHOST = \"/\"\n\nCELERY_RESULT_BACKEND = \"amqp\"\nCELERY_AMQP_TASK_RESULT_EXPIRES = 18000 # 5 hours.\nCELERY_IMPORTS = (\"test\", )\n```\n\nMy shell where first time get is successful and second time its hung. After sometime if I call the method again it works. This pattern keeps repeating.\n\n```\n>>> r = test.add.delay(4, 4)\n>>> r.get()\n8\n>>> r = test.add.delay(4, 4)\n>>> r.get()\n^C >> r = test.add.delay(4, 4)\n>>> r.get()\n8\n```\n\n========================================\n\nCode:\n```text\nCELERY_RESULT_BACKEND = \"amqp\"\n```\n\n```text\nBROKER_HOST = \"localhost\"\nBROKER_PORT = 5672\nBROKER_USER = \"guest\"\nBROKER_PASSWORD = \"guest\"\nBROKER_VHOST = \"/\"\n\nCELERY_RESULT_BACKEND = \"amqp\"\nCELERY_AMQP_TASK_RESULT_EXPIRES = 18000 # 5 hours.\nCELERY_IMPORTS = (\"test\", )\n```\n\n```text\n>>> r = test.add.delay(4, 4)\n>>> r.get()\n8\n>>> r = test.add.delay(4, 4)\n>>> r.get()\n^C <---------- it was hung here forever, I had to press ^C\n\n>>> r = test.add.delay(4, 4)\n>>> r.get()\n8\n```\n\n========================================\n\nComments:\n- What version of Celery? What do you use to store the results? (CELERY_RESULT_BACKEND)\n- Version 2.2 and rabbitmq is my backend.\n- Wait. Sorry that doesn't make any sense. I haven't setup any database, or changed any of the config settings. Does that mean that it will default to AMQP?","metadata":{"transformedAt":"2026-08-18T18:33:20.175Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":79,"estimatedTokens":501}}608{"id":"stack-65489763","source":"stackoverflow","questionId":65489763,"title":"Docker RabbitMQ Message disappear on restart","tags":["c#","docker","rabbitmq"],"text":"Title: Docker RabbitMQ Message disappear on restart\nTags: c#, docker, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI use this command line new RabbitMQ container\n\n```\ndocker run -d -p 5672:5672 -p 15672:15672 --name rabbitmq --hostname rabbitmq rabbitmq:management\n```\n\nCode setting durable:true, then restart container queue is exists, message is disappeared\n\n```\nchannel.QueueDeclare(\n queue: name, \n durable: true, \n exclusive: false, \n autoDelete: false, \n arguments: null \n);\n```\n\nhttps://i.sstatic.net/dXrmc.png\n\nPlease ask what question? thanks\n\n========================================\n\nTop Answer:\nIs there any publish?\n\n```\nchannel.BasicPublish(exchange: \"\",\n routingKey: \"hello\",\n basicProperties: null,\n body: body);\n```\n\nRef: https://www.rabbitmq.com/tutorials/tutorial-one-dotnet.html\n\n========================================\n\nCode:\n```text\ndocker run -d -p 5672:5672 -p 15672:15672 --name rabbitmq --hostname rabbitmq rabbitmq:management\n```\n\n```text\nchannel.QueueDeclare(\n queue: name, \n durable: true, \n exclusive: false, \n autoDelete: false, \n arguments: null \n);\n```\n\n```text\nvar properties = channel.CreateBasicProperties();\nproperties.Persistent = true;\n\nchannel.BasicPublish(exchange: \"\",\n routingKey: \"task_queue\",\n basicProperties: properties,\n body: body);\n```\n\n```text\nchannel.BasicPublish(exchange: \"\",\n routingKey: \"hello\",\n basicProperties: null,\n body: body);\n```\n\n========================================\n\nComments:\n- For anyone else also following the rabbitMQ tutorial ; I found that all queues would be deleted on exit , even if durable. I had to take out the `--rm` parameter from the `docker run` command; and also (after stopping it once), use `docker start -i rabbitmq` to start it again (it gives an error if trying `docker run...` again, if the first one didn't have the `--rm` switch\n- publish use channel.BasicPublish(\"\", name, null, body)\n- how messages setting durable ?\n- @GrapeWater I've already added an example into my comment. Also check the link I put into my answer.","metadata":{"transformedAt":"2026-08-18T18:33:20.175Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":82,"estimatedTokens":549}}609{"id":"stack-61390177","source":"stackoverflow","questionId":61390177,"title":"What is the most Pythonic way of processing messages like this Java \"instance-filtering\" [RabbitMQ]","tags":["java","python","rabbitmq","jms","amqp"],"text":"Title: What is the most Pythonic way of processing messages like this Java \"instance-filtering\" [RabbitMQ]\nTags: java, python, rabbitmq, jms, amqp\nSource: Stack Overflow\n\nQuestion:\nComming from a Java background, when developing services connected by JMS I used to process messages and distinguish them by checking their type, e.g (simplified):\n\n```\nObject object = myQueue.consume();\n if (object instanceof MessageA) {\n processMessageA((MessageA) object)\n } else if (object instanceof MessageB) {\n processMessageB((MessageB) object)\n }...\n```\n\nSo now I am building a messaging front-end for some Python modules in RabbitMQ (topic communication). I am planing on using **one queue** for each consumer-module to which **different messages** will arrive.\n\nI have almost everything but I am still struggling with the processing (consuming) of messages. How would you distinguish between message type?\n\nI thought of having custom JSON headers, but I don't know if this is correct.\n\n========================================\n\nCode:\n```text\nObject object = myQueue.consume();\n if (object instanceof MessageA) {\n processMessageA((MessageA) object)\n } else if (object instanceof MessageB) {\n processMessageB((MessageB) object)\n }...\n```\n\n```text\nmessage_to_action_map = {\n 'typeA': functionA,\n 'typeB': functionB\n}\n\ndef consumer_callback(msg):\n # In Python, RabbitMQ works by push and not by pull\n process = message_to_action_map[msg['type']]\n process(msg)\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.175Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":45,"estimatedTokens":371}}610{"id":"stack-74463717","source":"stackoverflow","questionId":74463717,"title":"How to mock a service with spock in micronaut when testing a rabbit consumer?","tags":["rabbitmq","spock","micronaut","micronaut-rabbitmq"],"text":"Title: How to mock a service with spock in micronaut when testing a rabbit consumer?\nTags: rabbitmq, spock, micronaut, micronaut-rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm currently working with:\n\n- Micronaut 3.7.3\n\n- RabbitMQ 3.11.2\n\n- Spock\n\n- Groovy / Java 17\n\nI'm implementing a rabbitmq consumer for a simple demo project following the guidelines from micronaut project (https://micronaut-projects.github.io/micronaut-rabbitmq/3.1.0/guide/index.html)\n\nI'm trying to mock a service that is a dependency of my rabbitmq consumer.\n\nI've tried this approach that does not seem to work:\n\n```\n@MicronautTest\n@Subject(SampleRequestConsumer)\nclass SampleRequestConsumerSpec extends Specification {\n\n @Inject\n ExternalWorkflowProducer externalWorkflowProducer\n\n @Inject\n SampleRequestConsumer sampleRequestConsumer\n\n @Inject\n SimpleService simpleService\n\n @MockBean(SimpleService)\n SimpleService simpleService() {\n Mock(SimpleService)\n }\n\n def \"It receives a sampleRequest message in the simple.request queue\"() {\n when:\n externalWorkflowProducer.send(new SampleRequest(message: \"Request1\"))\n\n then:\n sleep(100)\n\n 1 * simpleService.handleSimpleRequest(_ as SampleRequest) >> { SampleRequest request ->\n assert request.message != null\n }\n }\n\n}\n```\n\nI get this error when running the integration test:\n\n```\nToo few invocations for:\n\n1 * simpleService.handleSimpleRequest(_ as SampleRequest) >> { SampleRequest request ->\n assert request.message != null\n } (0 invocations)\n\nUnmatched invocations (ordered by similarity):\n\nNone\n```\n\nSee full source code on GitHub: https://github.com/art-dambrine/micronaut-rabbitmq-spock-mocking/blob/test-with-mq/src/test/groovy/com/company/microproject/amqp/consumer/SampleRequestConsumerSpec.groovy\n\nAlso notice that when I'm not reading from the queue and directly calling the method `sampleRequestConsumer.receive([message: \"Request1\"])`\nmocking for the `simpleService` is working : https://github.com/art-dambrine/micronaut-rabbitmq-spock-mocking/blob/test-without-mq/src/test/groovy/com/company/microproject/amqp/consumer/SampleRequestConsumerSpec.groovy\n\nThanks in advance for your insight\n\n### IMPORTANT\n\nPlease use the branch `test-with-mq`. The branch `test-without-mq`'s tests will succeed because it's not using rabbitMQ. This is an attempt to demonstrate that the issue lies in testing RabbitMQ consumers.\n\n========================================\n\nTop Answer:\nAs @LuisMuñiz pointed out, the interactions declared in the `then` block are actually moved around. It creates an interaction scope that contains all the interactions, the setup of that happens immediately before the `when` block executes and the verification that all interactions had taken place happens before any other instruction in the `then` block.\n\nThat out of the way, I would advise against using any kind of sleeps for your code. At best you are just waiting uselessly, at worst you didn't wait long enough and you test breaks. It is preferable to use one or more CountDownLatch instances to synchronize your test.\n\n```\ndef \"It receives a sampleRequest message in the simple.request queue\"() {\n given:\n def latch = new CountDownLatch(1)\n\n when:\n externalWorkflowProducer.send(new SampleRequest(message: \"Request1\"))\n latch.await()\n\n then:\n 1 * simpleService.handleSimpleRequest(_ as SampleRequest) >> { SampleRequest request ->\n assert request.message != null\n latch.countDown()\n }\n }\n```\n\nThis way you test will wait until you mock was called, but then immediately finish.\n\nYou can also use `latch.await(long timeout, TimeUnit unit)` with a generous timeout, to guard against your test hanging indefinitely.\n\n========================================\n\nCode:\n```text\n@MicronautTest\n@Subject(SampleRequestConsumer)\nclass SampleRequestConsumerSpec extends Specification {\n\n @Inject\n ExternalWorkflowProducer externalWorkflowProducer\n\n @Inject\n SampleRequestConsumer sampleRequestConsumer\n\n @Inject\n SimpleService simpleService\n\n @MockBean(SimpleService)\n SimpleService simpleService() {\n Mock(SimpleService)\n }\n\n\n def \"It receives a sampleRequest message in the simple.request queue\"() {\n when:\n externalWorkflowProducer.send(new SampleRequest(message: \"Request1\"))\n\n then:\n sleep(100)\n\n 1 * simpleService.handleSimpleRequest(_ as SampleRequest) >> { SampleRequest request ->\n assert request.message != null\n }\n }\n\n}\n```\n\n```text\nToo few invocations for:\n\n1 * simpleService.handleSimpleRequest(_ as SampleRequest) >> { SampleRequest request ->\n assert request.message != null\n } (0 invocations)\n\nUnmatched invocations (ordered by similarity):\n\nNone\n```\n\n```text\nsampleRequestConsumer.receive([message: \"Request1\"])\n```\n\n```text\nsimpleService\n```\n\n```text\ntest-with-mq\n```\n\n```text\ntest-without-mq\n```\n\n```text\n1 * simpleService.handleSimpleRequest(_ as SampleRequest)\n```\n\n```text\n{ SampleRequest request ->\n assert request.message != null\n }\n```\n\n```text\ndef \"It receives a sampleRequest message in the simple.request queue\"() {\n when:\n externalWorkflowProducer.send(new SampleRequest(message: \"Request1\"))\n sleep(100)\n\n then:\n 1 * simpleService.handleSimpleRequest(_ as SampleRequest) >> { SampleRequest request ->\n assert request.message != null\n }\n }\n```\n\n```text\ndef \"It receives a sampleRequest message in the simple.request queue\"() {\n when:\n externalWorkflowProducer.send(new SampleRequest(message: \"Request1\"))\n\n then:\n sleep(100)\n 1 * simpleService.handleSimpleRequest(_ as SampleRequest) >> { SampleRequest request ->\n assert request.message != null\n }\n }\n```\n\n```text\nsleep()\n```\n\n```text\nwhen:\n```\n\n```text\nthen:\n```\n\n```text\nexternalWorkflowProducer.send()\n```\n\n```text\nsleep()\n```\n\n```text\nsleep()\n```\n\n```text\nsend()\n```\n\n```text\ndef \"It receives a sampleRequest message in the simple.request queue\"() {\n given:\n def latch = new CountDownLatch(1)\n\n when:\n externalWorkflowProducer.send(new SampleRequest(message: \"Request1\"))\n latch.await()\n\n then:\n 1 * simpleService.handleSimpleRequest(_ as SampleRequest) >> { SampleRequest request ->\n assert request.message != null\n latch.countDown()\n }\n }\n```\n\n```text\nthen\n```\n\n```text\nwhen\n```\n\n```text\nthen\n```\n\n```text\nlatch.await(long timeout, TimeUnit unit)\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.175Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":22,"totalLines":270,"estimatedTokens":1613}}611{"id":"stack-36776381","source":"stackoverflow","questionId":36776381,"title":"RabbitMQ configuration for Wildfly","tags":["rabbitmq","wildfly-8"],"text":"Title: RabbitMQ configuration for Wildfly\nTags: rabbitmq, wildfly-8\nSource: Stack Overflow\n\nQuestion:\nDoes anyone successfully replace HornetQ by RabbitMQ in Wildfly 8?\n\nI'm trying to use our enterprise messaging system and extract the logic of messaging from our base app server to separate the concern between messaging and our core product.\n\nI looked on the web and did not find anything useful as how to change the standalone.xml\n\nAny help, even if the answer is - it is not possible - would be great.\n\nThank you\n\n========================================\n\nComments:\n- I wonder if this could work: github.com/leogsilva/rabbitmq-resource-adapter\n- Did you find solution? And what does the link say? @KoheiNozaki\n- @Nabin Unfortunately not yet. The link is a RabbitMQ adapter for WildFly. I haven't tried it yet either.\n- I did not find a solution yet. But we decided to move to WildFly 10, so hopefully it will be easier since the messaging system has changed.\n- were you able to integrate RabbitMQ's client into Wildfly such that your apps were able to use JNDI lookups to retrieve the connection? Where/how did you have to configure Rabbit's client jars?\n- This was long back ago. I don't remember it. But I think it was under settings of Wildfly server. I accessed it from browser","metadata":{"transformedAt":"2026-08-18T18:33:20.175Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":24,"estimatedTokens":322}}612{"id":"stack-23651331","source":"stackoverflow","questionId":23651331,"title":"How to connect to a RabbitMQ cluster with a Python Client using pika?","tags":["python","rabbitmq","cluster-computing","pika"],"text":"Title: How to connect to a RabbitMQ cluster with a Python Client using pika?\nTags: python, rabbitmq, cluster-computing, pika\nSource: Stack Overflow\n\nQuestion:\nI have a Python client that uses Pika package (0.9.13) and retrieves data from one node in a RabbitMQ cluster. The cluster is composed of two nodes placed in two different host (url_1 and url_2). How can I make my Python client to subscribe to both nodes?\n\nThat is the main structure of my code:\n\n```\nimport pika\ncredentials = pika.PlainCredentials(user, password)\nconnection = pika.BlockingConnection(pika.ConnectionParameters(host=url_1,\n credentials=credentials, ssl=ssl, port=port))\nchannel = connection.channel() \nchannel.exchange_declare(exchange=exchange.name, \n type=exchange.type, durable=exchange.durable)\n\nresult = channel.queue_declare(queue=queue.name, exclusive=queue.exclusive, \n durable=queue.durable, auto_delete=queue.autoDelete)\nchannel.queue_bind(exchange=exchange.name, queue=queue.name, \n routing_key=binding_key)\nchannel.basic_consume(callback,\n queue=queue.name,\n no_ack=True)\n\nchannel.start_consuming()\n```\n\n========================================\n\nCode:\n```text\nimport pika\ncredentials = pika.PlainCredentials(user, password)\nconnection = pika.BlockingConnection(pika.ConnectionParameters(host=url_1,\n credentials=credentials, ssl=ssl, port=port))\nchannel = connection.channel() \nchannel.exchange_declare(exchange=exchange.name, \n type=exchange.type, durable=exchange.durable)\n\nresult = channel.queue_declare(queue=queue.name, exclusive=queue.exclusive, \n durable=queue.durable, auto_delete=queue.autoDelete)\nchannel.queue_bind(exchange=exchange.name, queue=queue.name, \n routing_key=binding_key)\nchannel.basic_consume(callback,\n queue=queue.name,\n no_ack=True)\n\nchannel.start_consuming()\n```\n\n========================================\n\nComments:\n- Thanks for your comment. HAPPROXY seems a good option. I was wondering if using Python clients with Pika you could do something similar than when you are using Java clients: > ConnectionFactory factory = new ConnectionFactory(); > Address[] addresses = {new Address(\"url_1\", 12345), new > Address(\"url_2\", 12346)}; > factory.newConnection(addresses);\n- No, but be careful, the Java API connect the client only to ONE broker a time and not two together! I'd like to add this post stackoverflow.com/questions/9508246/… I think could help you, if you want hanle an fail-over situation","metadata":{"transformedAt":"2026-08-18T18:33:20.175Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":57,"estimatedTokens":641}}613{"id":"stack-38799361","source":"stackoverflow","questionId":38799361,"title":"What is the 'twisted' way of consuming messages from rabbitmq and forwarding them through its client connections?","tags":["websocket","rabbitmq","twisted","autobahn","pika"],"text":"Title: What is the 'twisted' way of consuming messages from rabbitmq and forwarding them through its client connections?\nTags: websocket, rabbitmq, twisted, autobahn, pika\nSource: Stack Overflow\n\nQuestion:\nI am writing a websocket server in `twisted` to learn the framework. It will be receiving messages from a `rabbitmq` broker, and and sending out updates to connected clients. If I want to broadcast/multi-cast many messages at a time through many client connections, is calling (just as an example) `deferToThread(channel.basic_consume, queue)`, or `callInThread(\" \")` a very good option for doing so?\n\nIf not, what would be the `twisted` way of consuming messages from `rabbitmq` and forwarding them to connected clients? \n\nMy strategy is thus so far:\n\nreactor_thread:\n listen on port(x) to setup and maintain client connections\n\nother_thread:\n subscribe to a rabbitmq queue and consume messages if any\n (goes on forever)\n\n========================================\n\nCode:\n```text\ntwisted\n```\n\n```text\nrabbitmq\n```\n\n```text\ndeferToThread(channel.basic_consume, queue)\n```\n\n```text\ncallInThread(\" \")\n```\n\n```text\ntwisted\n```\n\n```text\nrabbitmq\n```\n\n```text\nfactory = WebSocketServerFactory()\nfactory.connection_list = []\n```\n\n```text\ndef connectionMade(self):\n super(WSProtocol, self).connectionMade()\n self.factory.connection_list.append(self)\n```\n\n```text\n@defer.inlineCallbacks\ndef run(connection, proto_list):\n #...\n l = task.LoopingCall(read, queue_object, proto_list)\n l.start(0.01)\n\n@defer.inlineCallbacks\ndef read(queue_object, proto_list):\n #...\n if body:\n print(body)\n for client in sorted(proto_list):\n yield client.write(body)\n\n yield ch.basic_ack(delivery_tag=method.delivery_tag)\n\n#...\nd.addCallback(run, factory.connection_list)\nreactor.run()\n```\n\n```text\nautobahn\n```\n\n```text\nautobahn.twisted.websocket.WebSocketServerFactory\n```\n\n```text\nlist\n```\n\n```text\ndict\n```\n\n```text\nconnection_list\n```\n\n```text\nautobahn.twisted.websocket.WebSocketServerProtocol\n```\n\n```text\nconnectionMade\n```\n\n```text\nself\n```\n\n```text\nself.factory.connection_list\n```\n\n```text\nautobahn\n```\n\n```text\npika\n```\n\n```text\nfactory.connection_list\n```\n\n```text\nread\n```\n\n========================================\n\nComments:\n- You should add the tags `websocket`, `autobahn`, `crossbar` so that the devs working on async websockets from Tavendo can help you too. They maybe able to provide a better solution.\n- Thanks; can you add the part where the server is listening on a port for incoming client connections and how that will all work together? The reason I thought to use another thread was because I was going to use \"consume\" instead of \"get\" to recieve messages from rabbitmq. Their documentation recommended it because apparently more resources are used when executing a get.\n- Thank you for accepting my answer (and the bounty :)) Sorry for the delayed response I hadn't noticed you made a comment. Do you still need the connection code? I figured you already had that part down. As for threads I recommend you learn to do it without them as their will be a shared variable (`connection_list`) and then you inherit the issues that come with shared states. Also threads delay learning of Twisted's vast async functionality (in my personal opinion). I'd recommend learning the async model then use something like `crochet` once you're comfortable.\n- Sure, no problem it was an informative answer but I'm still new to this and I wanted to really understand how all of it fits together. Would I simply add in \"reactor.listenTCP(8989, wsfactory)\" where \"wsfactory\" is the websocket protocol factory? And as for the loopingcall, how about creating a rabbitmq consumer instead?\n- Yep all you need to do is `reactor.listenTCP(8989, wsfactory)`. I haven't seen any examples using rabbit's consumer and Twisted so I'm not sure how this can be done unfortunately.","metadata":{"transformedAt":"2026-08-18T18:33:20.175Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":22,"totalLines":138,"estimatedTokens":976}}614{"id":"stack-27908811","source":"stackoverflow","questionId":27908811,"title":"Get all queues of an exchange in RabbitMQ","tags":["c#","rabbitmq"],"text":"Title: Get all queues of an exchange in RabbitMQ\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nUsing RabbitMQ.Client, I wonder how these are possible:\n\n- Get all queues names?\n\n- To what exchange a queue is bound?\n\n- How to get all queues which are bound to an exchange?\n\n========================================\n\nComments:\n- Thanks for your answer. Just note that the API documentation link is a little old. I check this one: hg.rabbitmq.com/rabbitmq-management/raw-file/rabbitmq_v3_3_4‌​/…\n- Now, my question is how fast and reliable is this HTTP API? And why aren't those functionalities available in the client libraries?\n- ops.. I edited the answer. Those functionals are not provider by default on AMQP protocol. The management plug-in is a stable and enough fast, you should make some test.\n- First link in answer is dead - *\"This site can’t be reached - DNS_PROBE_FINISHED_NXDOMAIN\"*.","metadata":{"transformedAt":"2026-08-18T18:33:20.175Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":20,"estimatedTokens":230}}615{"id":"stack-3711327","source":"stackoverflow","questionId":3711327,"title":"How do you compile a PHP extension on windows with cygwin/mingw?","tags":["php","cygwin","rabbitmq","amqp"],"text":"Title: How do you compile a PHP extension on windows with cygwin/mingw?\nTags: php, cygwin, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI am trying to build the RabbitMQ PHP wrapper and the AMPQ PHP wrapper on Windows (64) using Cygwin.\nI have successfully built the underlying C library (librabbitmq.dll) but I am stuck at the 'phpize' step:\n\n`phpize && ./configure --with-rabbit && make && sudo make install`\n\nIf I understand correctly, there is no 'phpize' on windows, so how do I build my PHP wrapper?\n\nNote that I'm totally new to building PHP extensions (be it on linux or windows).\n\n========================================\n\nCode:\n```text\nphpize && ./configure --with-rabbit && make && sudo make install\n```\n\n========================================\n\nComments:\n- OK, it's not as bad as I feared then. I'll try this right now.\n- This may have improved in more recent versions of PHP. I know that people like @PierreJoye are working on making PHP a first class citizen on Windows. Unfortunately I seldom use PHP these days so I am unsure what the current situation is...\n- I can confirm, sadly, that as of February 2012, this is still very much an issue. If in doubt, just pick your random PHP extension and attempt compiling in 2010.","metadata":{"transformedAt":"2026-08-18T18:33:20.175Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":27,"estimatedTokens":311}}616{"id":"stack-44596007","source":"stackoverflow","questionId":44596007,"title":"How to read docker env variables into Java code","tags":["java","rabbitmq","dockerfile"],"text":"Title: How to read docker env variables into Java code\nTags: java, rabbitmq, dockerfile\nSource: Stack Overflow\n\nQuestion:\nI am trying to dockerize my Java application which tries to connect to a Rabbitmq server. I have passed the Rabbitmq Url via docker env variable and readig the same url using\n\n System.getenv(\"RABBITMQ_URL\")\n\n, but it came out to be null. Is there anything wrong with the way I am reading the docker env variable ? Here is my Docker create command :\n\n docker service create --name xxx --env\n RABBITMQ_URL=amqp://rabbitmq:xxxx --network msgq --with-registry-auth\n ${imageName}\n\n========================================\n\nTop Answer:\nSeems to work just fine for me. Please see below:\n\n```\n>> cat Dockerfile\nFROM java\n\nCOPY Test.java /Test.java\nRUN javac Test.java\nCMD java Test\n\n>> cat Test.java\nclass Test {\n public static void main(String[] j) {\n System.out.println(System.getenv(\"RABBITMQ_URL\"));\n while (true) {}\n }\n}\n\n>> docker build -t testj .\nSending build context to Docker daemon 6.656kB\nStep 1/4 : FROM java\n ---> d23bdf5b1b1b\nStep 2/4 : COPY Test.java /Test.java\n ---> Using cache\n ---> 2333685c6488\nStep 3/4 : RUN javac Test.java\n ---> Using cache\n ---> 8d1e98d604b9\nStep 4/4 : CMD java Test\n ---> Using cache\n ---> 6f9625f04966\nSuccessfully built 6f9625f04966\nSuccessfully tagged testj:latest\n\n>> docker service create --name xxx --env RABBITMQ_URL=amqp://rabbitmq:xxxx --detach testj\n937rbfctrds0z1mhpk1e7dlja\n\n>> docker service logs xxx \nxxx.1.acv6mqqy38pf@moby | amqp://rabbitmq:xxxx\n>>\n```\n\n========================================\n\nCode:\n```text\n>> cat Dockerfile\nFROM java\n\nCOPY Test.java /Test.java\nRUN javac Test.java\nCMD java Test\n\n\n>> cat Test.java\nclass Test {\n public static void main(String[] j) {\n System.out.println(System.getenv(\"RABBITMQ_URL\"));\n while (true) {}\n }\n}\n\n\n>> docker build -t testj .\nSending build context to Docker daemon 6.656kB\nStep 1/4 : FROM java\n ---> d23bdf5b1b1b\nStep 2/4 : COPY Test.java /Test.java\n ---> Using cache\n ---> 2333685c6488\nStep 3/4 : RUN javac Test.java\n ---> Using cache\n ---> 8d1e98d604b9\nStep 4/4 : CMD java Test\n ---> Using cache\n ---> 6f9625f04966\nSuccessfully built 6f9625f04966\nSuccessfully tagged testj:latest\n\n\n>> docker service create --name xxx --env RABBITMQ_URL=amqp://rabbitmq:xxxx --detach testj\n937rbfctrds0z1mhpk1e7dlja\n\n>> docker service logs xxx \nxxx.1.acv6mqqy38pf@moby | amqp://rabbitmq:xxxx\n>>\n```\n\n========================================\n\nComments:\n- You could check your image with *docker inspect*, the same with your service: *docker service inspect* to check where the variable is blanked.\n- No, that is not expected. You can connect a network to an existing service even after it was created.","metadata":{"transformedAt":"2026-08-18T18:33:20.175Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":111,"estimatedTokens":717}}617{"id":"stack-55577408","source":"stackoverflow","questionId":55577408,"title":"Use Messenger to read queued message not sent with Messenger","tags":["symfony","rabbitmq","symfony-messenger"],"text":"Title: Use Messenger to read queued message not sent with Messenger\nTags: symfony, rabbitmq, symfony-messenger\nSource: Stack Overflow\n\nQuestion:\nI'm trying to read a queued message (in RabbitMQ) that wasn't send with Symfony Messenger. It seems that Messenger adds some headers, like \n\n```\nheaders: \n type: App\\Message\\Transaction\n```\n\nbut when reading external messages, this header does not exist.\n\nSo, is there a way to tell Messenger that every message in queue A must be consider as a message type `Transaction` ?\n\nWhat I have today is :\n\n```\nframework:\n messenger:\n transports:\n # Uncomment the following line to enable a transport named \"amqp\"\n amqp:\n dsn: '%env(MESSENGER_TRANSPORT_DSN)%'\n options:\n exchange:\n name: messages\n type: direct\n queue:\n name: queue_messages\n\n routing:\n # Route your messages to the transports\n 'App\\Message\\Transaction': amqp\n```\n\nand what I would like to add is something like:\n\n```\nrouting:\n # Route your messages to the transports\n amqp: 'App\\Message\\Transaction'\n```\n\n========================================\n\nCode:\n```text\nheaders: \n type: App\\Message\\Transaction\n```\n\n```text\nframework:\n messenger:\n transports:\n # Uncomment the following line to enable a transport named \"amqp\"\n amqp:\n dsn: '%env(MESSENGER_TRANSPORT_DSN)%'\n options:\n exchange:\n name: messages\n type: direct\n queue:\n name: queue_messages\n\n routing:\n # Route your messages to the transports\n 'App\\Message\\Transaction': amqp\n```\n\n```text\nrouting:\n # Route your messages to the transports\n amqp: 'App\\Message\\Transaction'\n```\n\n```text\nTransaction\n```\n\n```php\n// I keeped the default serializer, and just override his decode method.\n\n /**\n * {@inheritdoc}\n */\n public function decode(array $encodedEnvelope): Envelope\n {\n if (empty($encodedEnvelope['body']) || empty($encodedEnvelope['headers'])) {\n throw new InvalidArgumentException('Encoded envelope should have at least a \"body\" and some \"headers\".');\n }\n\n if (empty($encodedEnvelope['headers']['action'])) {\n throw new InvalidArgumentException('Encoded envelope does not have an \"action\" header.');\n }\n\n // Call a factory to return the Message Class associate with the action\n if (!$messageClass = $this->messageFactory->getMessageClass($encodedEnvelope['headers']['action'])) {\n throw new InvalidArgumentException(sprintf('\"%s\" is not a valid action.', $encodedEnvelope['headers']['action']));\n }\n\n // ... keep the default Serializer logic\n\n return new Envelope($message, ...$stamps);\n }\n```\n\n```php\nclass MessageFactory\n{\n /**\n * @param string $action\n * @return string|null\n */\n public function getMessageClass(string $action)\n {\n switch($action){\n case ActionConstants::POST_MESSAGE :\n return PostMessage::class ;\n default:\n return null;\n }\n }\n}\n```\n\n```text\nframework:\n messenger:\n serializer: 'app.my_custom_serializer'\n```\n\n```text\nSerializer\n```\n\n```text\nSerializerInterface\n```\n\n```text\nMessage\n```\n\n========================================\n\nComments:\n- That's not really a solution, but if you have control on message creation, you can had the header `type` with FQCN as value. I would appreciate a better solution like describe in your post too.\n- I wasn't clear enough. The thing is, I don't have control on the message creation, I only know what will be send in this queue.\n- Agree, it's not clear and actually not a viable solution. Will ask on symfony slack if such a configuration or a factory can be implemented, i come back to you.","metadata":{"transformedAt":"2026-08-18T18:33:20.175Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":10,"totalLines":152,"estimatedTokens":962}}618{"id":"stack-6597506","source":"stackoverflow","questionId":6597506,"title":"Using exclusive + durable queues, for RabbitMQ","tags":["rabbitmq"],"text":"Title: Using exclusive + durable queues, for RabbitMQ\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nIf I have made a queue which is exclusive and durable (not auto-delete). Now, if the consumer subscribes to that queue and then it goes down. Then that queue gets deleted. \n\nI have checked the scenario, when the queue is only durable (i.e. neither exclusive nor auto-delete). Now, if the consumer subscribes to that queue and then it goes down. Then that queue gets deleted. \n\nPlease explain the 1st case, 2nd case is giving expected result. In both the scenario only 1 consumer is subscribed to one queue, and there is only one queue bound to one direct_exchange.\n\n========================================\n\nTop Answer:\nOne thing to correct, the exclusive queue will be deleted after the **connection** is closed not the channel is closed. you can run this test:\n\n```\npackage rabbitmq.java.sample.exclusivequeue;\n\nimport java.io.IOException;\n\nimport com.rabbitmq.client.*;\nimport com.rabbitmq.client.AMQP.Queue.DeclareOk;\n\npublic class Producer {\n\n private final static String QUEUE_NAME = \"UserLogin2\";\n private final static String EXCHANGE_NAME = \"user.login\";\n \n /**\n * @param args\n */\n public static void main(String[] args) {\n ConnectionFactory factory=new ConnectionFactory();\n factory.setHost(\"CNCDS108\");\n try {\n Connection conn = factory.newConnection(); \n Channel channel =conn.createChannel();\n DeclareOk declareOk = channel.queueDeclare(QUEUE_NAME, false, true, false, null);\n \n channel.basicPublish(\"\", QUEUE_NAME, null, \"Hello\".getBytes());\n \n //close the channel, check if the queue is deleted\n System.out.println(\"Try to close channel\");\n channel.close();\n System.out.println(\"Channel closed\");\n \n System.out.println(\"Create a new channel\");\n Channel channel2 =conn.createChannel();\n DeclareOk declareOk2 = channel2.queueDeclarePassive(QUEUE_NAME);\n \n **//we can access the exclusive queue from another channel\n System.out.println(declareOk2.getQueue()); //will output \"UserLogin2\"\n channel2.basicPublish(\"\", QUEUE_NAME, null, \"Hello2\".getBytes());\n System.out.println(\"Message published through the new channel\");**\n \n// System.out.println(\"Try to close Connection\");\n// conn.close();\n// System.out.println(\"Connection closed\");\n \n \n } catch (IOException e) {\n // TODO Auto-generated catch block\n e.printStackTrace();\n }\n }\n\n}\n```\n\n========================================\n\nCode:\n```java\npackage rabbitmq.java.sample.exclusivequeue;\n\nimport java.io.IOException;\n\nimport com.rabbitmq.client.*;\nimport com.rabbitmq.client.AMQP.Queue.DeclareOk;\n\npublic class Producer {\n\n private final static String QUEUE_NAME = \"UserLogin2\";\n private final static String EXCHANGE_NAME = \"user.login\";\n \n /**\n * @param args\n */\n public static void main(String[] args) {\n ConnectionFactory factory=new ConnectionFactory();\n factory.setHost(\"CNCDS108\");\n try {\n Connection conn = factory.newConnection(); \n Channel channel =conn.createChannel();\n DeclareOk declareOk = channel.queueDeclare(QUEUE_NAME, false, true, false, null);\n \n channel.basicPublish(\"\", QUEUE_NAME, null, \"Hello\".getBytes());\n \n //close the channel, check if the queue is deleted\n System.out.println(\"Try to close channel\");\n channel.close();\n System.out.println(\"Channel closed\");\n \n System.out.println(\"Create a new channel\");\n Channel channel2 =conn.createChannel();\n DeclareOk declareOk2 = channel2.queueDeclarePassive(QUEUE_NAME);\n \n **//we can access the exclusive queue from another channel\n System.out.println(declareOk2.getQueue()); //will output \"UserLogin2\"\n channel2.basicPublish(\"\", QUEUE_NAME, null, \"Hello2\".getBytes());\n System.out.println(\"Message published through the new channel\");**\n \n// System.out.println(\"Try to close Connection\");\n// conn.close();\n// System.out.println(\"Connection closed\");\n \n \n } catch (IOException e) {\n // TODO Auto-generated catch block\n e.printStackTrace();\n }\n }\n\n}\n```\n\n========================================\n\nComments:\n- Why would they do that? I really like the exclusiveness feature (lock) but can't afford to loose messages in the queue when the service processing the messages goes down. I can only have one service running processing messages and when it goes down, the fail back service will detect that it can now have exclusive rights to the queue and take ownership. But if the messages are gone! It's rather useless to me.\n- Answering this question from ancient times since it took me a while to find out the answer to it: What you actually want is exclusive consume, not exclusive queue.\n- Not exactly. Not the channel should be closed to allow removal of exclusive queue, but Connection. Here is the official documentation : rabbitmq.com/tutorials/amqp-concepts.html#queues","metadata":{"transformedAt":"2026-08-18T18:33:20.175Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":133,"estimatedTokens":1268}}619{"id":"stack-53376298","source":"stackoverflow","questionId":53376298,"title":"Liveness probe for RabbitMQ Client (Consumer)","tags":["c#","kubernetes","rabbitmq","azure-aks"],"text":"Title: Liveness probe for RabbitMQ Client (Consumer)\nTags: c#, kubernetes, rabbitmq, azure-aks\nSource: Stack Overflow\n\nQuestion:\nI would like to know/get opinions on how to setup liveness probe for a RabbitMQ queue consumer. I am not sure how to verify if consumer is still processing messages from the queue. I have already tried searching for some clues over the internet but could not find any. So just asking a question here to see if anyone has got any idea. \n\nThe code block which I want to make sure working fine is\n\n```\nvar consumer = new EventingBasicConsumer(channel);\n consumer.Received += (model, ea) =>\n {\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n Console.WriteLine($\"Message Received: {message}\");\n };\n```\n\nThank you.\n\n========================================\n\nCode:\n```text\nvar consumer = new EventingBasicConsumer(channel);\n consumer.Received += (model, ea) =>\n {\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n Console.WriteLine($\"Message Received: {message}\");\n };\n```\n\n```text\nlivenessProbe:\n httpGet:\n path: /healthz\n port: 8080\n httpHeaders:\n - name: X-Custom-Header\n value: Awesome\n initialDelaySeconds: 3\n periodSeconds: 3\n```\n\n========================================\n\nComments:\n- Are you trying to apply liveness probe in the yaml/json configuration file for RabbitMQ?\n- Also show your docker image used for RabbitMQ. Have you used the official docker image `rabbitmq`?\n- @ShudiptaSharma I have got rabbitmq container covered with both readiness and liveness probes. This question is about message consumer which is hosted in a different container.\n- thanks for your answer. I have used all three types of probes in other parts of my AKS. I can setup probe but not sure what the logic should be to check if consumer is still processing messages. I liked your idea of checking timestamp but I am looking for a solution which can more accurately confirm the liveness of message consumer. It looks like I have to go for some sort of indirect solution similar to one you have suggested.\n- @Alpesh depending on what language you're using, the RabbitMQ client might have a method that returns whether it's alive or not. A quick search of the Java client led me to this document: rabbitmq.github.io/rabbitmq-java-client/api/current/com/… You can subscribe to events that indicate the state of the consumer. If you want to be sure, you could combine the solution I suggested with listening to these events.\n- Not sure if any of the methods on the page can help in my scenario. I am using C# client and can't find anything useful there as well. I will keep looking for something useful,\n- You have events that correspond to these methods github.com/rabbitmq/rabbitmq-dotnet-client/blob/master/proje‌​cts/…. Note that there is a default heartbeat mechanism in the consumer stackoverflow.com/questions/33699165/… So I don't think that you would gain anything by handling these events. You could still use the method that I've proposed just to make sure.\n- There are three types to define a probe(readiness, lives, startup), they are HTTP, Command, TCP. The one which suits workers is the command one.\n- @DaAmidza not necessarily.. sure, if you have a way to probe your service from the command line, otherwise, HTTP would be simpler for most .NET services\n- @areller it's not rocket science to create a sh script which will test it for the case. RabbitMQ suggests testing it through the command line. Services that are exposed to the web, yes they can go over the HTTP way. But this case MUST go with the command. Makes no sense to explose it to HTTP if you don't need it.\n- @DaAmidza how is your sh script going to communicate with the service though? In many cases you'd probably want to get metrics beyond whether or not the process is running. Also, if you're using ASP.NET Core to host your RabbitMQ consumer, adding an HTTP healthcheck point is pretty straightforward learn.microsoft.com/en-us/aspnet/core/host-and-deploy/…","metadata":{"transformedAt":"2026-08-18T18:33:20.176Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":60,"estimatedTokens":1046}}620{"id":"stack-25953891","source":"stackoverflow","questionId":25953891,"title":"Why do we need service bus frameworks like NService Bus/MassTransit on top of message queuing systems like MSMQ/RabbitMQ etc?","tags":["rabbitmq","msmq","nservicebus","distributed-transactions","masstransit"],"text":"Title: Why do we need service bus frameworks like NService Bus/MassTransit on top of message queuing systems like MSMQ/RabbitMQ etc?\nTags: rabbitmq, msmq, nservicebus, distributed-transactions, masstransit\nSource: Stack Overflow\n\nQuestion:\nIn the distributed message transaction world, am trying to understand the different parts that are involved in developing distributed systems. From what I understand you can design messaging system using enterprise bus backed with a message queue system. Why is it a good idea to use both? Can the same be achieved by programming against just the message queuing system? What are the advantages of using both together?\n\n========================================\n\nTop Answer:\nI can't comment directly on MassTransit, having only tinkered with it.\n\nI use NServiceBus and am a fan of it. I think there are valid reasons for directly using queuing technology, but I think rolling your own ESB using MSMQ/RabbitMQ would cost a lot more than simply using a commercial product (or open source product e.g. MassTransit).\n\nSo do you need it? No. Will it make your life much easier if the features match your requirements? Absolutely.\n\n========================================\n\nComments:\n- \"a service bus may buy you quite a bit out-of=the-box whereas coding against the queues directly may be a bit of work to get going\". Great summarization. Thanks!\n- Publish/Subscribe is easy on MSMQ using MassTransit. Well, as easy as *anything* on MSMQ is, anyway..\n- @stuartd: I meant that when using RabbitMQ directly pub/sub is quite easy whereas with MSMQ directly it is not. Using a service bus like shuttle-esb certainly makes life easier :)\n- @EbenRoux yup, ServiceBus FTW. Your meaning wasn't entirely clear in your answer.\n- @stuartd: I edited the answer to make that more clear, thanks.","metadata":{"transformedAt":"2026-08-18T18:33:20.176Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":24,"estimatedTokens":454}}621{"id":"stack-32309155","source":"stackoverflow","questionId":32309155,"title":"Rabbitmq retrieve multiple messages using single synchronous call using .NET","tags":["c#",".net","rabbitmq","message-queue","amqp"],"text":"Title: Rabbitmq retrieve multiple messages using single synchronous call using .NET\nTags: c#, .net, rabbitmq, message-queue, amqp\nSource: Stack Overflow\n\nQuestion:\nIs there a way to receive multiple message using a single synchronous call using .NET?\n\nI've seen question and I've found java class com.rabbitmq.client.QueueingConsumer, but I haven't found such client class in .NET namespaces (RabbitMQ.Client, RabbitMQ.Client.Events)\n\n========================================\n\nTop Answer:\nThanks for answers, but I've found the class which I looked for: RabbitMQ.Client.QueueingBasicConsumer\n\nSimple implementation is:\n\n```\nIEnumerable Get(int maxBatchCount, int getMessageTimeout, int getBatchTimeout)\n{\n var result = new List();\n var startTime = DateTime.Now;\n while (result.Count (deliverEventArgs.Body);\n result.Add(entry);\n _queue.Channel.BasicAck(deliverEventArgs.DeliveryTag, false);\n }\n else\n break;\n\n if ((DateTime.Now - startTime) >= TimeSpan.FromMilliseconds(getBatchTimeout))\n break;\n }\n return result;\n}\n```\n\nWell, of course, you can use `Environment.TickCount` instead of `DateTime.Now`\n\n========================================\n\nCode:\n```text\nvar model = _rabbitConnection.CreateModel();\n// Configure the Quality of service for the model. Below is how what each setting means.\n// BasicQos(0=\"Dont send me a new message untill I’ve finshed\", _fetchSize = \"Send me N messages at a time\", false =\"Apply to this Model only\")\nmodel.BasicQos(0, fetchSize, false);\n```\n\n```text\nBasicQoS.PrefetchCount\n```\n\n```text\nIEnumerable<T> Get(int maxBatchCount, int getMessageTimeout, int getBatchTimeout)\n{\n var result = new List<T>();\n var startTime = DateTime.Now;\n while (result.Count < maxBatchCount)\n {\n var deliverEventArgs = new BasicDeliverEventArgs();\n if ((_consumer as QueueingBasicConsumer).Queue.Dequeue(GetMessageTimeout, out deliverEventArgs))\n {\n var entry = ContractSerializer.Deserialize<T>(deliverEventArgs.Body);\n result.Add(entry);\n _queue.Channel.BasicAck(deliverEventArgs.DeliveryTag, false);\n }\n else\n break;\n\n if ((DateTime.Now - startTime) >= TimeSpan.FromMilliseconds(getBatchTimeout))\n break;\n }\n return result;\n}\n```\n\n```text\nEnvironment.TickCount\n```\n\n```text\nDateTime.Now\n```\n\n========================================\n\nComments:\n- Could you please describe more about what you mean by \"a single synchronous call?\"\n- Well, more correct: I want to receive one event with batch of messages (configuring client to max batch size and timeout). Hope this explanation is more clear\n- That's what I thought. Message batching is generally contrary to proper design practices. If you are finding there is a need to batch, perhaps you want to use a shared database instead?","metadata":{"transformedAt":"2026-08-18T18:33:20.176Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":89,"estimatedTokens":702}}622{"id":"stack-55820119","source":"stackoverflow","questionId":55820119,"title":"RabbitMQ point-to-point or pub-sub","tags":["rabbitmq","jms"],"text":"Title: RabbitMQ point-to-point or pub-sub\nTags: rabbitmq, jms\nSource: Stack Overflow\n\nQuestion:\nIs RabbitMQ point-to-point or pub-sub? Or both depending on configuration options?\n\nI have been looking at the configurations, and they all seem to support the point-to-point model and not pub-sub. i.e. the message is removed from the queue once consumed, and is not available to a second consumer.\n\n========================================\n\nTop Answer:\nConceptually, RabbitMQ is both: point-to-point as well as pub-sub. You can register your listener application to the topic of an RabbitMQ exchange and receive all messages published to that Topic. So that is clearly 'pub-sub'. Whatever application architecture you have in mind, you can use the pub-sub concept to implement it.\n\nHowever, just like IBM MQ, RabbitMQ started as a 'queuing system' (notice the MQ). So in order to implement pub-sub they simply built pub-sub on top of a queuing system. That works, but can feel kind of strange in terms of configuration (why would you need to setup an exchange at all, for example) and might not be as efficient as a messaging system that started with pub-sub in it's DNA.\n\nIf you only want to use pub-sub and have hundreds of consumers, there might be better choices, maybe messaging systems that use UDP multicast to distribute the data.\n\n========================================\n\nComments:\n- I think to do that , you need to route the message to the second consumer. RabbitMq has an advanced routing system using wildcards and other features\n- Thanks Axel. If you wanted to use RabbitMQ as pub-sub, i.e. so the message is not removed by the first consumer, and can be consumed by many subscribers. How would you do figure RabbitMQ?\n- For Java, check out rabbitmq.com/tutorials/tutorial-five-java.html - or depending on your programming language see \"Topics\" under rabbitmq.com/getstarted.html","metadata":{"transformedAt":"2026-08-18T18:33:20.176Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":24,"estimatedTokens":473}}623{"id":"stack-48318322","source":"stackoverflow","questionId":48318322,"title":"What's the earliest point of entry to read a rabbit message in spring-amqp?","tags":["java","spring","rabbitmq","spring-amqp","spring-rabbit"],"text":"Title: What's the earliest point of entry to read a rabbit message in spring-amqp?\nTags: java, spring, rabbitmq, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI store thread-local rabbit message data in an MDC. I would like to clear the old and add new context data for an incoming rabbit message, like reading certain values from the headers or reading the rabbit message payload as a `byte[]`. Unfortunately I often see exceptions happening prior to the message hitting my `@RabbitHandler` annotated methods. Is there an earlier entry-point that I can hook into to establish this context? I don't know what happens before deserialization occurs, but ideally I'd like access to the message before attempting to deserialize it. Perhaps there's an `onMessageReceived(byte[] message, Map headers)` method hook somewhere. The earlier in the call stack the better.\n\n========================================\n\nTop Answer:\nA solution is to use a `SimpleMessageListenerContainer` instead of `@RabbitHandler` annotations, and to use a custom message listener adapter.\n\nExample:\n\n```\n@Bean\nSimpleMessageListenerContainer container(ConnectionFactory connectionFactory,\n MessageListenerAdapter listenerAdapter) {\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(connectionFactory);\n container.setQueueNames(queueName);\n container.setMessageListener(listenerAdapter); // custom listener\n container.setMessageConverter(null); // disable default conversion\n return container;\n}\n\n@Bean\nMessageListenerAdapter listenerAdapter() {\n RawMessageDelegate delegate = new RawMessageDelegate();\n return new MessageListenerAdapter(delegate);\n}\n\npublic class RawMessageDelegate {\n\n void handleMessage(Message message) {\n byte[] body = message.getBody();\n MessageProperties properties = message.getMessageProperties();\n Map headers = properties.getHeaders();\n // handle raw data\n }\n\n}\n```\n\n========================================\n\nCode:\n```text\nbyte[]\n```\n\n```text\n@RabbitHandler\n```\n\n```text\nonMessageReceived(byte[] message, Map headers)\n```\n\n```text\n/**\n * @param afterReceivePostProcessors the post processors.\n * @see AbstractMessageListenerContainer#setAfterReceivePostProcessors(MessagePostProcessor...)\n */\npublic void setAfterReceivePostProcessors(MessagePostProcessor... afterReceivePostProcessors) {\n```\n\n```text\n@RabbitHandler\n```\n\n```text\nAbstractRabbitListenerContainerFactory\n```\n\n```text\nMessageConverter\n```\n\n```text\nfromMessage()\n```\n\n```text\nMessagingMessageListenerAdapter.toMessagingMessage()\n```\n\n```text\nMessagingMessageListenerAdapter.onMessage()\n```\n\n```text\norg.springframework.amqp.core.Message\n```\n\n```text\n@Bean\nSimpleMessageListenerContainer container(ConnectionFactory connectionFactory,\n MessageListenerAdapter listenerAdapter) {\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(connectionFactory);\n container.setQueueNames(queueName);\n container.setMessageListener(listenerAdapter); // custom listener\n container.setMessageConverter(null); // disable default conversion\n return container;\n}\n\n@Bean\nMessageListenerAdapter listenerAdapter() {\n RawMessageDelegate delegate = new RawMessageDelegate();\n return new MessageListenerAdapter(delegate);\n}\n\npublic class RawMessageDelegate {\n\n void handleMessage(Message message) {\n byte[] body = message.getBody();\n MessageProperties properties = message.getMessageProperties();\n Map<String, Object> headers = properties.getHeaders();\n // handle raw data\n }\n\n}\n```\n\n```text\nSimpleMessageListenerContainer\n```\n\n```text\n@RabbitHandler\n```\n\n========================================\n\nComments:\n- Looks like I'll have to do it in the converters after all. Thanks, I'll give this a try. Any idea if the thread that runs `MessagingMessageListenerAdapter.onMessage()` is the same that would execute the `@RabbitHandler` call?\n- Indeed it is definitely the same. Just the call stack I mentioned.\n- I would suggest the the `setAfterReceivePostProcessors()` is the easiest route.","metadata":{"transformedAt":"2026-08-18T18:33:20.176Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":14,"totalLines":139,"estimatedTokens":1040}}624{"id":"stack-60267164","source":"stackoverflow","questionId":60267164,"title":"MassTransit RabbitMq Sending Messages","tags":["c#","rabbitmq","masstransit"],"text":"Title: MassTransit RabbitMq Sending Messages\nTags: c#, rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nI am not able to figure out on how to specify the `Exchange` and `Queue` in my `GetSendEndpoint())` task when sending / publishing messages? \n\nAs per MassTransit documentation https://masstransit-project.com/usage/producers.html#send you can specify the exchange and queue like \n\n```\nGetSendEndpoint(new Uri(\"queue:input-queue\"))\n```\n\nHowever, I can only do one or the other? \n\nIs there an alternative way of sending with exchange and queue specified?\n\nI am doing this in Asp.Net Core so here are my configuration:\n\n**Startup.cs**\n\n```\npublic void ConfigureServices(IServiceCollection services)\n{\n services.AddMassTransit();\n\n services.AddSingleton(p => Bus.Factory.CreateUsingRabbitMq(cfg =>\n {\n cfg.Host(\"rabbitmq://localhost\", h =>\n {\n h.Username(\"admin\");\n h.Password(\"admin\");\n });\n }));\n\n services.AddSingleton(p => p.GetRequiredService());\n services.AddSingleton();\n}\n```\n\nAnd this is how send the message \n\n```\nvar endpoint = await _bus.GetSendEndpoint(new Uri(queue:Test.Queue));\nawait endpoint.Send(new Message()\n{\n Text = \"This is a test message\"\n});\n```\n\nAs you can see I can only specify the queue name.\n\n========================================\n\nTop Answer:\nReading Chris's response in here Mass Transit : No consumer\n\nIt seems like `Exchanges are created by MassTransit when publishing messages, based on the message types. Publishing does not create any queues. Queues are where messages are stored for delivery to consumers.`\n\nand `Queues are created when receive endpoints are added to a bus. For the consumers, handlers, and sagas added to a receive endpoint, the exchanges are created and bound so that messages published to the exchanges are received by the receive endpoint (via the queue).`\n\nSo if my publisher doesn't have a receive endpoint defined then any messages I send will be lost as there will be no queues or binding? \n\nFurther reading on here https://groups.google.com/forum/#!topic/masstransit-discuss/oVzZkg1os9o seems to further confirm this. \n\nSo based on the above link in order to achieve what I want i.e. to create the exchange and bind it to a queue I will need to specify it in the `Uri` as such\n\n```\nvar sendEndpoint = bus.GetSendEndpoint(new Uri(\"rabbitmq://localhost/vhost1/exchange1?bind=true&queue=queue1\"));\n```\n\nwhere `exchange1` is the Exchange, `queue1` is the Queue and `bind=true` would bind the queue to the exchange. \n\nIf sticking to the original MT design a Consumers needs to be running before to setup the exchanges and queues before a Producer can start publishing? This seems to give less flexibility to the Publisher?\n\n========================================\n\nCode:\n```text\nGetSendEndpoint(new Uri(\"queue:input-queue\"))\n```\n\n```text\npublic void ConfigureServices(IServiceCollection services)\n{\n services.AddMassTransit();\n\n services.AddSingleton(p => Bus.Factory.CreateUsingRabbitMq(cfg =>\n {\n cfg.Host(\"rabbitmq://localhost\", h =>\n {\n h.Username(\"admin\");\n h.Password(\"admin\");\n });\n }));\n\n services.AddSingleton<IBus>(p => p.GetRequiredService<IBusControl>());\n services.AddSingleton<IHostedService, BusService>();\n}\n```\n\n```text\nvar endpoint = await _bus.GetSendEndpoint(new Uri(queue:Test.Queue));\nawait endpoint.Send(new Message()\n{\n Text = \"This is a test message\"\n});\n```\n\n```text\nExchange\n```\n\n```text\nQueue\n```\n\n```text\nGetSendEndpoint())\n```\n\n```text\n\"exchange:your-exchange-name\"\n```\n\n```text\n\"queue:your-queue-name\"\n```\n\n```text\n\"exchange:your-exchange-name?bind=true&queue=your-queue-name\"\n```\n\n```text\n\"queue:your-exchange-name&queue=your-queue-name\"\n```\n\n```text\nvar sendEndpoint = bus.GetSendEndpoint(new Uri(\"rabbitmq://localhost/vhost1/exchange1?bind=true&queue=queue1\"));\n```\n\n```text\nExchanges are created by MassTransit when publishing messages, based on the message types. Publishing does not create any queues. Queues are where messages are stored for delivery to consumers.\n```\n\n```text\nQueues are created when receive endpoints are added to a bus. For the consumers, handlers, and sagas added to a receive endpoint, the exchanges are created and bound so that messages published to the exchanges are received by the receive endpoint (via the queue).\n```\n\n```text\nUri\n```\n\n```text\nexchange1\n```\n\n```text\nqueue1\n```\n\n```text\nbind=true\n```\n\n========================================\n\nComments:\n- Thanks Chris I am aware of that. But is there way of sending it by specifying an Exchange and then Queue as you would conventionally do using the RabbitMq client?\n- I don't know what you mean, to be honest. The only way to send directly to a queue in RabbitMQ is to specify an empty exchange (`\"\"`) and put the queue name in the RoutingKey. And MassTransit does not expose that capability.\n- `exchange:your-exchange-name?bind=true&queue=your-queue-name` this suits my purpose :) thanks\n- Chris also to confirm is it possible to do a carry out `Acknowledgement` when publisher send the message to Exchange. It's mainly to confirm message was delivered to the queue.\n- @ChrisPatterson I apply \"queue:your-queue-name\" and it works. Thanks very much. Just want to know where did you get the information for Uri format?\n- The documentation.\n- I updated my answer once I realized you were asking to specify *different* names for the exchange and the queue. I didn't glean that from your original question.","metadata":{"transformedAt":"2026-08-18T18:33:20.176Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":17,"totalLines":175,"estimatedTokens":1364}}625{"id":"stack-29592543","source":"stackoverflow","questionId":29592543,"title":"How to configure and receiveAndConvert jSON payload into domain Object in Spring Boot and RabbitMQ","tags":["java","spring","rabbitmq","spring-boot","spring-amqp"],"text":"Title: How to configure and receiveAndConvert jSON payload into domain Object in Spring Boot and RabbitMQ\nTags: java, spring, rabbitmq, spring-boot, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nRecently I have been having a keen interest on Microservice Architecture using Spring Boot. My implementation has two Spring boot applications;\n\n**Application One** receives requests from a RESTful API, converts and sends jSON payload to a **RabbitMQ queueA**. \n\n**Application Two**, has subscribed to **queueA**, receives the jSON payload(Domain Object User) and is supposed to activate a service within Application Two eg. send email to a user.\n\nUsing no XML in my **Application Two** configuration, how do I configure a converter that will convert the jSON payload received from RabbitMQ into a Domain Object User.\n\nBelow are snippets from Spring Boot configurations on Application Two\n\n**Application.class**\n\n```\n@SpringBootApplication\n@EnableRabbit\npublic class ApplicationInitializer implements CommandLineRunner {\n\n final static String queueName = \"user-registration\";\n\n @Autowired\n RabbitTemplate rabbitTemplate;\n\n @Autowired\n AnnotationConfigApplicationContext context;\n\n @Bean\n Queue queue() {\n return new Queue(queueName, false);\n }\n\n @Bean\n TopicExchange topicExchange() {\n return new TopicExchange(\"user-registrations\");\n }\n\n @Bean\n Binding binding(Queue queue, TopicExchange exchange) {\n return BindingBuilder.bind(queue).to(exchange).with(queueName);\n }\n\n @Bean\n SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(connectionFactory);\n container.setQueueNames(queueName);\n container.setMessageListener(listenerAdapter);\n return container;\n }\n\n public static void main(String[] args) {\n SpringApplication.run(ApplicationInitializer.class, args);\n }\n\n @Override\n public void run(String... args) throws Exception {\n System.out.println(\"Waiting for messages...\");\n }\n\n}\n```\n\n**TestService.java**\n\n```\n@Component\npublic class TestService {\n\n /**\n * This test verifies whether this consumer receives message off the user-registration queue\n */\n @RabbitListener(queues = \"user-registration\")\n public void testReceiveNewUserNotificationMessage(User user) {\n // do something like, convert payload to domain object user and send email to this user\n }\n\n}\n```\n\n========================================\n\nTop Answer:\nCreate a jackson message converter and set it with `MessageListenerAdapter#setMessageConverter`\n\n```\n@Bean\npublic MessageConverter jsonMessageConverter() {\n return new Jackson2JsonMessageConverter();\n}\n```\n\nWhere do come from `MessageListenerAdapter` ?\n\n========================================\n\nCode:\n```text\n@SpringBootApplication\n@EnableRabbit\npublic class ApplicationInitializer implements CommandLineRunner {\n\n final static String queueName = \"user-registration\";\n\n @Autowired\n RabbitTemplate rabbitTemplate;\n\n @Autowired\n AnnotationConfigApplicationContext context;\n\n @Bean\n Queue queue() {\n return new Queue(queueName, false);\n }\n\n @Bean\n TopicExchange topicExchange() {\n return new TopicExchange(\"user-registrations\");\n }\n\n @Bean\n Binding binding(Queue queue, TopicExchange exchange) {\n return BindingBuilder.bind(queue).to(exchange).with(queueName);\n }\n\n @Bean\n SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(connectionFactory);\n container.setQueueNames(queueName);\n container.setMessageListener(listenerAdapter);\n return container;\n }\n\n public static void main(String[] args) {\n SpringApplication.run(ApplicationInitializer.class, args);\n }\n\n @Override\n public void run(String... args) throws Exception {\n System.out.println(\"Waiting for messages...\");\n }\n\n}\n```\n\n```text\n@Component\npublic class TestService {\n\n /**\n * This test verifies whether this consumer receives message off the user-registration queue\n */\n @RabbitListener(queues = \"user-registration\")\n public void testReceiveNewUserNotificationMessage(User user) {\n // do something like, convert payload to domain object user and send email to this user\n }\n\n}\n```\n\n```text\n@Override\npublic void configureRabbitListeners(\n RabbitListenerEndpointRegistrar registrar) {\n registrar.setMessageHandlerMethodFactory(myHandlerMethodFactory());\n}\n```\n\n```text\n@Bean\npublic DefaultMessageHandlerMethodFactory myHandlerMethodFactory() {\n DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();\n factory.setMessageConverter(new MappingJackson2MessageConverter());\n return factory;\n}\n```\n\n```text\n@Autowired\npublic ConnectionFactory connectionFactory;\n\n@Bean\npublic SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory() {\n SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();\n factory.setConnectionFactory(connectionFactory);\n factory.setConcurrentConsumers(3);\n factory.setMaxConcurrentConsumers(10);\n return factory;\n}\n```\n\n```text\n@Bean\npublic EventResultHandler eventResultHandler() {\n return new EventResultHandler();\n}\n```\n\n```text\n@Component\npublic class EventResultHandler {\n\n @RabbitListener(queues=Queues.QUEUE_NAME_PRESENTATION_SERVICE)\n public void handleMessage(@Payload Event event) {\n System.out.println(\"Event received\");\n System.out.println(\"EventType: \" + event.getType().getText());\n }\n}\n```\n\n```text\n@Bean\npublic MessageConverter jsonMessageConverter() {\n return new Jackson2JsonMessageConverter();\n}\n```\n\n```text\nMessageListenerAdapter#setMessageConverter\n```\n\n```text\nMessageListenerAdapter\n```\n\n```text\n@Bean\n RabbitTemplate rabbitTemplate(RabbitTemplate rabbitTemplate) {\n rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());\n return rabbitTemplate\n }\n```\n\n```text\nvar receievedValie = rabbitTemplate.receiveAndConvert(\"TestQueue\", new ParameterizedTypeReference<Integer>() {\n @Override\n public Type getType() {\n return super.getType();\n }\n })\n```\n\n========================================\n\nComments:\n- Make sure that you are importing the right class in order to get this to work - you need a org.springframework.amqp.support.converter.MessageConverter and not a org.springframework.messaging.converter.MessageConverter\n- You sir.....deserve a medal. For some funny reason after updating my project parent to Spring Boot to 1.3.0.RELEASE few days ago my previous implementation broke. Thank you","metadata":{"transformedAt":"2026-08-18T18:33:20.179Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":251,"estimatedTokens":1719}}626{"id":"stack-8199435","source":"stackoverflow","questionId":8199435,"title":"PHP Fatal error: Class 'AMQPConnection' not found","tags":["php","rabbitmq","amqp"],"text":"Title: PHP Fatal error: Class 'AMQPConnection' not found\nTags: php, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI've already seen this question. It suggests that AMQP PECL extension is not installed. However, I have successfully installed both RabbitMQ as well as built PECL AMQP extension. The following is the output of the phpinfo().\n\nYou can clearly see, AMQP is loaded correctly. However, when I try to establish a connection, it says **PHP Fatal error: Class 'AMQPConnection' not found**. Below is the code.\n\n```\n$connection = new AMQPConnection();\n```\n\nAnd here is the output.\n\n```\nuser@ubuntu:~$ php repos/default/test.php\nPHP Fatal error: Class 'AMQPConnection' not found in /home/user/repos/default/test.php on line 5\n```\n\nWhy this might happen? Any suggestions? Thank you.\n\n========================================\n\nCode:\n```text\n$connection = new AMQPConnection();\n```\n\n```text\nuser@ubuntu:~$ php repos/default/test.php\nPHP Fatal error: Class 'AMQPConnection' not found in /home/user/repos/default/test.php on line 5\n```\n\n========================================\n\nComments:\n- On debian/ubuntu: `/etc/php5/cli/php.ini` is for cli and `/etc/php5/apache2/php.ini` is for sapi.\n- Exactly! Thank you! I didn't know client and Apache php module have different config files. That solved everything. Aaa, I am so happy!\n- I m confused.I have /etc/php5/cli/php.ini in debian, Please clarify now should I replace php.ini with php-cli.ini OR should install php-cli.ini","metadata":{"transformedAt":"2026-08-18T18:33:20.179Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":40,"estimatedTokens":377}}627{"id":"stack-11964742","source":"stackoverflow","questionId":11964742,"title":"Can a celery worker/server accept tasks from a non celery producer?","tags":["rabbitmq","celery"],"text":"Title: Can a celery worker/server accept tasks from a non celery producer?\nTags: rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI want to use a comet server written using java nio for sending out live updates. When receiving information I want it to scan the data, and send tasks to worker threads via rabbitmq. Ideally I would like a celery server to sit on the other end of rabbit, managing a pool of worker threads that will handle these tasks. \n\nHowever, from my understanding, celery works by sitting on both ends of rabbitmq, and it essentially takes over the role of producer and consumer by being embedded in both the consumer and producer's code. Is there a way to set up celery as I described above? Thanks\n\n========================================\n\nTop Answer:\nYes, of cource !\n\nYou can add `Custom Message Consumers` to a celery app.\n\nPlease refer to Extensions and Bootsteps in celery documents.\n\nHere is a part of example code in the link above:\n\n```\nfrom celery import Celery\nfrom celery import bootsteps\nfrom kombu import Consumer, Exchange, Queue\n\nmy_queue = Queue('custom', Exchange('custom'), 'routing_key')\n\napp = Celery(broker='amqp://')\n\nclass MyConsumerStep(bootsteps.ConsumerStep):\n\n def get_consumers(self, channel):\n return [Consumer(channel,\n queues=[my_queue],\n callbacks=[self.handle_message],\n accept=['json'])]\n\n def handle_message(self, body, message):\n print('Received message: {0!r}'.format(body))\n message.ack()\napp.steps['consumer'].add(MyConsumerStep)\n```\n\nTest it:\n\n python -m celery -A main worker\n\nSee also: Using Celery with existing RabbitMQ messages\n\n========================================\n\nCode:\n```py\nfrom celery import Celery\nfrom celery import bootsteps\nfrom kombu import Consumer, Exchange, Queue\n\nmy_queue = Queue('custom', Exchange('custom'), 'routing_key')\n\napp = Celery(broker='amqp://')\n\n\nclass MyConsumerStep(bootsteps.ConsumerStep):\n\n def get_consumers(self, channel):\n return [Consumer(channel,\n queues=[my_queue],\n callbacks=[self.handle_message],\n accept=['json'])]\n\n def handle_message(self, body, message):\n print('Received message: {0!r}'.format(body))\n message.ack()\napp.steps['consumer'].add(MyConsumerStep)\n```\n\n```text\nCustom Message Consumers\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.179Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":79,"estimatedTokens":580}}628{"id":"stack-79519639","source":"stackoverflow","questionId":79519639,"title":"TypeScript error when using amqplib that can't","tags":["javascript","typescript","rabbitmq"],"text":"Title: TypeScript error when using amqplib that can't\nTags: javascript, typescript, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm working on a Node.js project using TypeScript and the amqplib package (currently at version 0.10.5). When I try to create a connection and channel in my RabbitMQ configuration file, TypeScript throws the following errors:\n\n- Property 'close' does not exist on type 'Connection'\n\n- Property 'createChannel' does not exist on type 'Connection'\n\n- Type 'ChannelModel' is missing the following properties from type 'Connection': serverProperties, expectSocketClose, sentSinceLastCheck, recvSinceLastCheck, sendMessage\n\n```\nimport * as amqp from 'amqplib';\nimport { Connection, Channel } from 'amqplib';\n\nexport class RabbitMQConfig {\n private static connection: Connection | null = null;\n private static channel: Channel | null = null;\n\n public static async connect(): Promise {\n if (!this.connection) {\n this.connection = await amqp.connect('amqp://localhost');\n this.channel = await this.connection.createChannel();\n\n this.connection.on('close', () => {\n console.error('RabbitMQ connection closed.');\n });\n\n this.connection.on('error', (err) => {\n console.error('RabbitMQ connection error:', err);\n });\n\n console.log('RabbitMQ connected and channel created successfully.');\n }\n }\n\n public static getChannel(): Channel {\n if (!this.channel) {\n throw new Error('RabbitMQ channel is not initialized. Call connect() first.');\n }\n return this.channel;\n }\n\n public static async closeConnection(): Promise {\n if (this.channel) {\n await this.channel.close();\n this.channel = null;\n }\n if (this.connection) {\n await this.connection.close();\n this.connection = null;\n }\n console.log('RabbitMQ connection closed.');\n }\n}\n```\n\nI don't know what seems to be the issue since I did try importing the correct module but\nTypeScript still complains that the methods close() and createChannel() do not exist on the Connection type.\n\nAny suggestions on how to resolve this type of issue would be greatly appreciated.\n\n========================================\n\nTop Answer:\nThe maintainers of the typings for amqplib introduced a breaking change. The `connect()` method of the `amqp` object now returns a `ChannelModel` instead of a `Connection`. All I had to do was change the declaration for my connection to the new type and the problem was solved.\n\nBefore:\n\n```\nimport amqp, { Connection, Channel, ConsumeMessage } from 'amqplib';\n\nexport type ConsumerCallback = (channel: Channel, message: ConsumeMessage | null) => void;\n\nexport class RabbitMQConsumer {\n _queue: string;\n _connection: Connection | null = null;\n _channel: Channel | null = null;\n _connected: boolean = false;\n\n public constructor(queue: string) {\n this._queue = queue;\n }\n\n async connect(): Promise {\n this._connection = await amqp.connect('amqp://localhost');\n const channel = await this._connection.createChannel();\n ...\n ...\n```\n\nAfter (with quite a bit of rework on the class itself):\n\n```\nimport { Channel, ConsumeMessage, Options, connect, ChannelModel } from 'amqplib';\nimport { RabbitMQConfig } from './interfaces.js';\nimport { cloneObject } from './utilities.js';\n\nexport type ConsumerCallback = (channel: Channel, message: ConsumeMessage | null) => void;\n\nexport class RabbitMQConsumer {\n _options: Options.Connect;\n _queuename: string;\n _connection: ChannelModel | null = null;\n _channel: Channel | null = null;\n _connected: boolean = false;\n\n public constructor(config: RabbitMQConfig) {\n this._options = cloneObject(config.options);\n this._queuename = config.queuename;\n }\n\n async connect(): Promise {\n this._connection = await connect(this._options);\n if (!this._connection) return false;\n const channel = await this._connection.createChannel();\n if (channel) {\n ...\n ...\n```\n\nThis is code from a minimal producer/consumer pair that I use basically as a regression test.\n\nIt's rather uncouth of the maintainers to introduce a breaking change at a patch-level commit with so little fanfare.\n\n========================================\n\nCode:\n```text\nimport * as amqp from 'amqplib';\nimport { Connection, Channel } from 'amqplib';\n\nexport class RabbitMQConfig {\n private static connection: Connection | null = null;\n private static channel: Channel | null = null;\n\n public static async connect(): Promise<void> {\n if (!this.connection) {\n this.connection = await amqp.connect('amqp://localhost');\n this.channel = await this.connection.createChannel();\n\n this.connection.on('close', () => {\n console.error('RabbitMQ connection closed.');\n });\n\n this.connection.on('error', (err) => {\n console.error('RabbitMQ connection error:', err);\n });\n\n console.log('RabbitMQ connected and channel created successfully.');\n }\n }\n\n public static getChannel(): Channel {\n if (!this.channel) {\n throw new Error('RabbitMQ channel is not initialized. Call connect() first.');\n }\n return this.channel;\n }\n\n public static async closeConnection(): Promise<void> {\n if (this.channel) {\n await this.channel.close();\n this.channel = null;\n }\n if (this.connection) {\n await this.connection.close();\n this.connection = null;\n }\n console.log('RabbitMQ connection closed.');\n }\n}\n```\n\n```text\n\"@types/amqplib\": \"0.10.6\",\n```\n\n```ts\nexport interface Connection extends events.EventEmitter {\n close(): Promise<void>;\n createChannel(): Promise<Channel>;\n createConfirmChannel(): Promise<ConfirmChannel>;\n connection: {\n serverProperties: ServerProperties;\n };\n}\n```\n\n```ts\nexport interface ChannelModel extends events.EventEmitter {\n close(): Promise<void>;\n createChannel(): Promise<Channel>;\n createConfirmChannel(): Promise<ConfirmChannel>;\n connection: Connection;\n updateSecret(newSecret: Buffer, reason: string): Promise<void>;\n}\n```\n\n```text\nimport * as amqplib from 'amqplib';\nimport { envVars } from './environment';\n\n// Set types manually to avoid reference issues\n\n type AmqpConnection = ReturnType<typeof amqplib.connect> extends Promise<infer T> ? T : never;\n type AmqpChannel = ReturnType<AmqpConnection['createChannel']> extends Promise<infer T> ? T : never;\n \n let connection: AmqpConnection | null = null;\n let channel: AmqpChannel | null = null;\n \n export async function connectQueue() {\n try {\n connection = await amqplib.connect(envVars.RABBITMQ_URL);\n channel = await connection.createChannel();\n console.log('✅ Conectado ao RabbitMQ');\n \n return { connection, channel };\n } catch (error) {\n console.error('❌ Error connecting to RabbitMQ:', error);\n throw error;\n }\n }\n \n export function getChannel() {\n if (!channel) throw new Error('RabbitMQ channel not initialized');\n return channel;\n }\n```\n\n```text\nimport amqp, { Connection, Channel, ConsumeMessage } from 'amqplib';\n\nexport type ConsumerCallback = (channel: Channel, message: ConsumeMessage | null) => void;\n\nexport class RabbitMQConsumer {\n _queue: string;\n _connection: Connection | null = null;\n _channel: Channel | null = null;\n _connected: boolean = false;\n\n public constructor(queue: string) {\n this._queue = queue;\n }\n\n async connect(): Promise<boolean> {\n this._connection = await amqp.connect('amqp://localhost');\n const channel = await this._connection.createChannel();\n ...\n ...\n```\n\n```text\nimport { Channel, ConsumeMessage, Options, connect, ChannelModel } from 'amqplib';\nimport { RabbitMQConfig } from './interfaces.js';\nimport { cloneObject } from './utilities.js';\n\nexport type ConsumerCallback = (channel: Channel, message: ConsumeMessage | null) => void;\n\nexport class RabbitMQConsumer {\n _options: Options.Connect;\n _queuename: string;\n _connection: ChannelModel | null = null;\n _channel: Channel | null = null;\n _connected: boolean = false;\n\n public constructor(config: RabbitMQConfig) {\n this._options = cloneObject(config.options);\n this._queuename = config.queuename;\n }\n\n async connect(): Promise<boolean> {\n this._connection = await connect(this._options);\n if (!this._connection) return false;\n const channel = await this._connection.createChannel();\n if (channel) {\n ...\n ...\n```\n\n```text\nconnect()\n```\n\n```text\namqp\n```\n\n```text\nChannelModel\n```\n\n```text\nConnection\n```\n\n```text\nimport * as amqp from 'amqplib';\nimport { Channel, ChannelModel } from 'amqplib'; // ChannelModel replaces the old Connection\n\nlet connection!: ChannelModel; \nlet channel!: Channel;\n\nexport async function setupRabbitMQ(): Promise<void> {\n try {\n const url = process.env.RABBITMQ_URL ?? 'amqp://localhost:5672';\n\n connection = await amqp.connect(url);\n channel = await connection.createChannel();\n```\n\n```text\nampq.connect\n```\n\n```text\nChannelModel\n```\n\n```text\nConnection\n```\n\n```text\npnpm upgrade\n```\n\n========================================\n\nComments:\n- Using @types/amqplib: 0.10.6 with amqplib: \"^0.10.5\" helped me solve the issue.\n- Using @types/amqplib: 0.10.6 with amqplib: \"^0.10.5\" helped me solve the issue.\n- Discussion on their GitHub repo: github.com/DefinitelyTyped/DefinitelyTyped/discussions/72810","metadata":{"transformedAt":"2026-08-18T18:33:20.179Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":16,"totalLines":335,"estimatedTokens":2296}}629{"id":"stack-41933262","source":"stackoverflow","questionId":41933262,"title":"Purge a queue in RabbitMQ","tags":["c#","rabbitmq"],"text":"Title: Purge a queue in RabbitMQ\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am using RabbitMQ for daily transactions. My consumers are .Net desktop applications deployed in multiple machines. Every day the transactions are pushed to queue within a certain time duration only. Beyond that there needs to be a hard stop on any new transaction. I have managed to stop sending new transaction to the queue. However, the existing transactions in the queue also needs to be flushed so that it is not sent to any consumer.\nI tried searching for this but did not get any solution for purging a queue except for two options-\n\n- Delete and re-create the queue every day\n\n- Stop all the consumers of the queue\n\nBoth of these approaches can be implemented but it requires significant amount of changes on my systems. I want to know if there is a better approach.\n\n========================================\n\nTop Answer:\nThis blog article describes how to purge a queue in RabbitMQ in different ways. \n\n**rabbitmqadmin:** \nThe management plugin ships with a command line tool, rabbitmqadmin, which can perform the same actions as the web-based UI (the RabbitMQ management interface).\n\nThe script used to purge all messages in a single queue is: \n\n```\n$ rabbitmqadmin purge queue name=name_of_queue\n```\n\n**HTTP API:** The Rabbitmq Management plugin provides an HTTP-based API for management and monitoring of your RabbitMQ server. \n\n```\ncurl -i -XDELETE https://USERNAME:PASSWORD@HOST/api/queues/vhost/QUEUE_NAME/contents\n```\n\n**Policy:** \nAdd a policy that matches the queue names with an max-lenght rule. A policy can be added by entering the Management Interface and then pressing the admin tab. (Don't forget to delete the policy after it has been applied.)\n\n========================================\n\nCode:\n```text\nConnectionFactory factory = new ConnectionFactory();\n\n factory.HostName = \"localhost\";\n factory.UserName = \"guest\";\n factory.Password = \"guest\";\n\n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n channel.QueuePurge(queueName);\n }\n\n }\n```\n\n```text\nneed to do this in C# somehow\n```\n\n```text\n/api/queues/vhost/name/contents\n```\n\n```text\n/api/queues/vhost/name/contents\n```\n\n```text\n$ rabbitmqadmin purge queue name=name_of_queue\n```\n\n```text\ncurl -i -XDELETE https://USERNAME:PASSWORD@HOST/api/queues/vhost/QUEUE_NAME/contents\n```\n\n```text\nusing (System.Net.WebClient client = new System.Net.WebClient())\n{\n client.Credentials = new System.Net.NetworkCredential(rmq_user, rmq_pass);\n client.Headers.Set(\"Content-Type\", \"application/json\");\n response = client.UploadString(messagePath, jsonPayload);\n}\n```\n\n```text\n{\"payload\":\"{\\\"PerformAutomation\\\":{\\\"AutomationInputDictionary\\\":{\\\"Search.Ban\\\":\\\"Holidays from=10th Mar 2017;Holidays to=13th Mar 2017;WalmartID=00155628;ticket_number=1226004;TicketType=HOLIDAY REQUEST;RawTicketData=PERN: 00155628\\\\r\\\\nHoliday Request -------------------- Holiday from 10th Mar 2017 to 13th Mar 2017\\\"},\\\"ProcessName\\\":\\\"HRProc\\\",\\\"ProfileName\\\":\\\"HR\\\",\\\"APIVersion\\\":\\\"\\\",\\\"AppId\\\":\\\"\\\",\\\"CommandExecutionWindow\\\":\\\"\\\",\\\"CommandGenerationSource\\\":\\\"\\\",\\\"Country\\\":\\\"\\\",\\\"Instance\\\":\\\"\\\",\\\"PartnerId\\\":\\\"\\\",\\\"ReferenceCode\\\":\\\"\\\",\\\"Timestamp\\\":\\\"5:07 AM\\\",\\\"UserName\\\":\\\"svcblpr\\\",\\\"VID\\\":\\\"\\\"}}\",\"content_type\":\"string\",\"content_encoding\":\"test/json\",\"profile\":\"HR\",\"expiration\":604800000,\"app_id\":\"wm_uc1_load_gen_app\",\"source_message_id\":\"wm_uc1_load_gen_source\",\"header\":null}\n```\n\n```text\nvar result = _container.Resolve<IBrokerObjectFactory>()\n .Object<Queue>()\n .Empty(x =>\n {\n x.Queue(\"your_queue\");\n x.Targeting(t => t.VirtualHost(\"your_vhost\"));\n });\n```\n\n========================================\n\nComments:\n- Have you tried using this feature: rabbitmq.com/ttl.html\n- Thanks I will check this out.\n- You have a feature in `rabbitmqadmin` to purge queues, `rabbitmqadmin purge queue name=queue_name`. Even though this would not sophistically be done in your code base, it would mean that you don't need to delete the queues or stop the consumers.\n- @PärEriksson Yeah I checked that. I need to do this in C# somehow.\n- @SouvikGhosh aha alright. I would expect a `yourQueue.purge()` exists with the AMQP driver you are using. Would a scheduled task (not sure what exists in the C# ecosystem) to call this function be a solution?\n- Unfortunately there is no API to purge the queue. There are some commands which can be used with rabbitmqadmin though. I have figured out something and working on it. I will post it here if that works well.\n- As there is not any purge API, you could purge all messages in a given queue by consuming all of thems through a classic consumer? Not the best thing but if you have no other choice...\n- That would delete the queue I guess?\n- Yes. I didn't paste the correct path- `contents` is missing at the end. I'll edit the answer\n- mountain traveller aslo gave this info as an answer on my answer\n- Sorry, I don't have RabbitMQAdmin so had to do it through code.","metadata":{"transformedAt":"2026-08-18T18:33:20.179Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":114,"estimatedTokens":1312}}630{"id":"stack-9935789","source":"stackoverflow","questionId":9935789,"title":"How to do non-blocking on RabbitMQ?","tags":["c#",".net","wcf","rabbitmq"],"text":"Title: How to do non-blocking on RabbitMQ?\nTags: c#, .net, wcf, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am new to RabbitMQ. I just started yesterday. I did few spikes on sending and consuming stuff. What I noticed was on their documentation and even on articles that I've read most of them are implementing the subscription piece in a way that they are looping it to get the message from a queue. How can I make it so that it will be event driven? What I wanted to accomplish is when a message is sent to a queue it will raise and event to the receiver and do something about it. Perhaps like displaying the message.\n\nYour reply is greatly appreciated.\n\nBest regards,\n\n========================================\n\nTop Answer:\nShould use EventingBasicConsumer. I have an example on my website that shows how it's used RabbitMQ Events using EventingBasicConsumer\n\nBasically it's just a new consumer that exposes a Received event so you don't need to block.\n\n========================================\n\nCode:\n```text\nBasicGet\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.179Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":24,"estimatedTokens":257}}631{"id":"stack-55086050","source":"stackoverflow","questionId":55086050,"title":"Rabbitmq - Docker connection refused on port 5672","tags":["docker","docker-compose","rabbitmq","docker-network"],"text":"Title: Rabbitmq - Docker connection refused on port 5672\nTags: docker, docker-compose, rabbitmq, docker-network\nSource: Stack Overflow\n\nQuestion:\nI have a web server written in Go that interacts with Rabbitmq and Mongodb. When I run all these servers on my machine without containers (rabbitmq url: `amqp://guest:guest@localhost:5672`) it works fine.\n\nNow I am trying to run all these services in a separate container. Here is my compose file\n\n```\nversion: '3'\nservices:\n rabbitmq:\n image: rabbitmq\n container_name: rabbitmq\n ports:\n - 5672:5672\n mongodb:\n image: mongo\n container_name: mongodb\n ports:\n - 27017:27017\n web:\n build: .\n image: palash2504/collect\n container_name: collect-server\n restart: on-failure\n ports:\n - 3000:3000\n depends_on:\n - rabbitmq\n - mongodb\n links: [\"rabbitmq\", \"mongodb\"]\n\nnetworks:\n default:\n external:\n name: collect-net\n```\n\nThis is my servers dockerfile\n\n```\nFROM golang\n\nENV GO111MODULE=on\n\nWORKDIR /app\n\nCOPY go.mod .\nCOPY go.sum .\n\nRUN go mod download\n\nCOPY . .\n\nRUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build\n\nEXPOSE 3000\n\nENTRYPOINT [\"/app/social-cops-assignment\"]\n```\n\nMy server can't seem to connect to rabbitmq. This is the log message I get when running `docker compose up` and the rabbitmq url in my config being `amqp://guest:guest@rabbitmq:5672` (since the container name is rabbitmq I replace localhost with rabbitmq so that my server is able to find the rabbitmq container)\n\n```\ncollect-server | 2019/03/10 08:50:51 Failed to connect to AMQP compatible broker at: amqp://guest:guest@rabbitmq:5672/, with errror: dial tcp 172.24.0.3:5672: connect: connection refused\n```\n\nBut rabbitmq seems to be ready to accept connections. These are the last two lines of the rabbitmq logs from `docker-compose up`\n\n```\nrabbitmq | 2019-03-10 08:50:55.164 [info] accepting AMQP connection (172.24.0.4:49784 -> 172.24.0.3:5672)\nrabbitmq | 2019-03-10 08:50:55.205 [info] connection (172.24.0.4:49784 -> 172.24.0.3:5672): user 'guest' authenticated and granted access to vhost '/'\n```\n\nI am new to docker-networking and I don't know what am I doing wrong? Is it the rabbitmq address that I am using or I need some additional configuration with respect to rabbitmq or expose some ports?\n\n========================================\n\nTop Answer:\nTwo things that fixed it for me:\n\n- Make sure not to use localhost, instead use the container's name. For me it was `amqp`.\n\n```\namqp:\n image: rabbitmq:3-management-alpine\n ports:\n - \"5672:5672\"\n - \"15672:15672\"\n```\n\nThen the connection string will be `amqp://guest:guest@amqp/`.\n\n========================================\n\nCode:\n```yaml\nversion: '3'\nservices:\n rabbitmq:\n image: rabbitmq\n container_name: rabbitmq\n ports:\n - 5672:5672\n mongodb:\n image: mongo\n container_name: mongodb\n ports:\n - 27017:27017\n web:\n build: .\n image: palash2504/collect\n container_name: collect-server\n restart: on-failure\n ports:\n - 3000:3000\n depends_on:\n - rabbitmq\n - mongodb\n links: [\"rabbitmq\", \"mongodb\"]\n\nnetworks:\n default:\n external:\n name: collect-net\n```\n\n```text\nFROM golang\n\nENV GO111MODULE=on\n\n\nWORKDIR /app\n\nCOPY go.mod .\nCOPY go.sum .\n\nRUN go mod download\n\nCOPY . .\n\nRUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build\n\nEXPOSE 3000\n\n\nENTRYPOINT [\"/app/social-cops-assignment\"]\n```\n\n```text\ncollect-server | 2019/03/10 08:50:51 Failed to connect to AMQP compatible broker at: amqp://guest:guest@rabbitmq:5672/, with errror: dial tcp 172.24.0.3:5672: connect: connection refused\n```\n\n```text\nrabbitmq | 2019-03-10 08:50:55.164 [info] <0.489.0> accepting AMQP connection <0.489.0> (172.24.0.4:49784 -> 172.24.0.3:5672)\nrabbitmq | 2019-03-10 08:50:55.205 [info] <0.489.0> connection <0.489.0> (172.24.0.4:49784 -> 172.24.0.3:5672): user 'guest' authenticated and granted access to vhost '/'\n```\n\n```text\namqp://guest:guest@localhost:5672\n```\n\n```text\ndocker compose up\n```\n\n```text\namqp://guest:guest@rabbitmq:5672\n```\n\n```text\ndocker-compose up\n```\n\n```text\nrabbitmq\n```\n\n```text\nrabbitmq:5672\n```\n\n```text\namqp:\n image: rabbitmq:3-management-alpine\n ports:\n - \"5672:5672\"\n - \"15672:15672\"\n```\n\n```text\namqp\n```\n\n```text\namqp://guest:guest@amqp/\n```\n\n```text\ndepends_on:\n rabbitmq:\n condition: service_healthy\n```\n\n```text\ndepends_on\n```\n\n```text\nrestart: unless-stopped\n```\n\n```text\nrestart: on-failure\n```\n\n```text\nhealthcheck\n```\n\n========================================\n\nComments:\n- can you execute `docker-compose restart web` and check if the issue still exist ? just make sure you don't restart rabbitmq\n- yes it still exists\n- did that. replaced the rabbitmq url in my config file with this `amqp://guest:guest@rabbitmq` but it still doesn't connect. Here is the error log `Failed to connect to AMQP compatible broker at: amqp://guest:guest@rabbitmq/, with errror: dial tcp 172.24.0.2:5672: connect: connection refused`\n- What library is printing that error? I can't find it on the web, except for a blog post where it is included as an example.\n- I am using the go library for amqp godoc.org/github.com/streadway/amqp This log message is from my application code but the last part is from the library `dial tcp 172.24.0.2:5672: connect: connection refused`\n- `connection refused` is likely related to authentication, not networking. I've added this to my answer.\n- I have had a similar problem due to an @ character in the login and password.","metadata":{"transformedAt":"2026-08-18T18:33:20.179Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":18,"totalLines":233,"estimatedTokens":1362}}632{"id":"stack-64484905","source":"stackoverflow","questionId":64484905,"title":"Getting Celery task results using RPC backend","tags":["python","flask","rabbitmq","celery"],"text":"Title: Getting Celery task results using RPC backend\nTags: python, flask, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI'm struggling with getting results from the Celery task.\nMy app entry point looks like this:\n\n```\nfrom app import create_app,celery\ncelery.conf.task_default_queue = 'order_master'\norder_app = create_app('../config.order_master.py')\n```\n\nNow, before I start the application I start the RabbitMQ and ensure it has no queues:\n\n```\nroot@3d2e6b124780:/# rabbitmqctl list_queues\nTimeout: 60.0 seconds ...\nListing queues for vhost / ...\nroot@3d2e6b124780:/#\n```\n\nNow I start the application. After the start I still see no queues in the RabbitMQ. When I start the task from the application `jobs.add_together.delay(2, 3)` I get the task ID:\n\n```\nralfeus@web-2 /v/w/order (multiple-instances)> (order) curl localhost/test\n{\"result\":\"a2c07de4-f9f2-4b21-ae47-c6d92f2a7dfe\"}\nralfeus@web-2 /v/w/order (multiple-instances)> (order)\n```\n\nAt that moment I can see that my queue has one message:\n\n```\nroot@3d2e6b124780:/# rabbitmqctl list_queues\nTimeout: 60.0 seconds ...\nListing queues for vhost / ...\nname messages\ndd65ba89-cce9-3e0b-8252-c2216912a910 0\norder_master 1\nroot@3d2e6b124780:/#\n```\n\nNow I start Celery worker:\n\n```\nralfeus@web-2 /v/w/order (multiple-instances)>\n/usr/virtualfish/order/bin/celery -A main_order_master:celery worker --loglevel=INFO -n order_master -Q order_master --concurrency 2\nINFO:app:Blueprints are registered\n\n -------------- celery@order_master v5.0.0 (singularity)\n--- ***** -----\n-- ******* ---- Linux-5.4.0-51-generic-x86_64-with-glibc2.29 2020-10-22 16:38:56\n- *** --- * ---\n- ** ---------- [config]\n- ** ---------- .> app: app:0x7f374715c5b0\n- ** ---------- .> transport: amqp://guest:**@172.17.0.1:5672//\n- ** ---------- .> results: rpc://\n- *** --- * --- .> concurrency: 2 (prefork)\n-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)\n--- ***** -----\n -------------- [queues]\n .> order_master exchange=order_master(direct) key=order_master\n\n[tasks]\n . app.jobs.add_together\n . app.jobs.post_purchase_orders\n\n[2020-10-22 16:38:57,263: INFO/MainProcess] Connected to amqp://guest:**@172.17.0.1:5672//\n[2020-10-22 16:38:57,304: INFO/MainProcess] mingle: searching for neighbors\n[2020-10-22 16:38:58,354: INFO/MainProcess] mingle: all alone\n[2020-10-22 16:38:58,375: INFO/MainProcess] celery@order_master ready.\n[2020-10-22 16:38:58,377: INFO/MainProcess] Received task: app.jobs.add_together[f855bec7-307d-4570-ab04-3d036005a87b]\n[2020-10-22 16:40:38,616: INFO/ForkPoolWorker-2] Task app.jobs.add_together[f855bec7-307d-4570-ab04-3d036005a87b] succeeded in 100.13561034202576s: 5\n```\n\nSo it's visible the worker could pick up the task and execute it and produce a result. However I can't get the result. Instead, when I request the result I get following:\n\n```\ncurl localhost/test/f855bec7-307d-4570-ab04-3d036005a87b\n{\"state\":\"PENDING\"}\nralfeus@web-2 /v/w/order (multiple-instance)> (order)\n```\n\nIf I check the queues now I see that:\n\n```\nroot@3d2e6b124780:/# rabbitmqctl list_queues\nTimeout: 60.0 seconds ...\nListing queues for vhost / ...\nname messages\ndd65ba89-cce9-3e0b-8252-c2216912a910 1\n65d80661-6195-3986-9fa2-e468eaab656e 0\nceleryev.9ca5a092-9a0c-4bd5-935b-f5690cf9665b 0\norder_master 0\ncelery@order_master.celery.pidbox 0\nroot@3d2e6b124780:/#\n```\n\nI see the queue dd65ba89-cce9-3e0b-8252-c2216912a910 has one message, which as I check contains result. So why has it appeared there and how do I get that? All manuals say I just need to get task by ID. But in my case the task is still in pending state.\n\n========================================\n\nCode:\n```text\nfrom app import create_app,celery\ncelery.conf.task_default_queue = 'order_master'\norder_app = create_app('../config.order_master.py')\n```\n\n```text\nroot@3d2e6b124780:/# rabbitmqctl list_queues\nTimeout: 60.0 seconds ...\nListing queues for vhost / ...\nroot@3d2e6b124780:/#\n```\n\n```text\nralfeus@web-2 /v/w/order (multiple-instances)> (order) curl localhost/test\n{\"result\":\"a2c07de4-f9f2-4b21-ae47-c6d92f2a7dfe\"}\nralfeus@web-2 /v/w/order (multiple-instances)> (order)\n```\n\n```text\nroot@3d2e6b124780:/# rabbitmqctl list_queues\nTimeout: 60.0 seconds ...\nListing queues for vhost / ...\nname messages\ndd65ba89-cce9-3e0b-8252-c2216912a910 0\norder_master 1\nroot@3d2e6b124780:/#\n```\n\n```text\nralfeus@web-2 /v/w/order (multiple-instances)>\n/usr/virtualfish/order/bin/celery -A main_order_master:celery worker --loglevel=INFO -n order_master -Q order_master --concurrency 2\nINFO:app:Blueprints are registered\n\n -------------- celery@order_master v5.0.0 (singularity)\n--- ***** -----\n-- ******* ---- Linux-5.4.0-51-generic-x86_64-with-glibc2.29 2020-10-22 16:38:56\n- *** --- * ---\n- ** ---------- [config]\n- ** ---------- .> app: app:0x7f374715c5b0\n- ** ---------- .> transport: amqp://guest:**@172.17.0.1:5672//\n- ** ---------- .> results: rpc://\n- *** --- * --- .> concurrency: 2 (prefork)\n-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)\n--- ***** -----\n -------------- [queues]\n .> order_master exchange=order_master(direct) key=order_master\n\n\n[tasks]\n . app.jobs.add_together\n . app.jobs.post_purchase_orders\n\n[2020-10-22 16:38:57,263: INFO/MainProcess] Connected to amqp://guest:**@172.17.0.1:5672//\n[2020-10-22 16:38:57,304: INFO/MainProcess] mingle: searching for neighbors\n[2020-10-22 16:38:58,354: INFO/MainProcess] mingle: all alone\n[2020-10-22 16:38:58,375: INFO/MainProcess] celery@order_master ready.\n[2020-10-22 16:38:58,377: INFO/MainProcess] Received task: app.jobs.add_together[f855bec7-307d-4570-ab04-3d036005a87b]\n[2020-10-22 16:40:38,616: INFO/ForkPoolWorker-2] Task app.jobs.add_together[f855bec7-307d-4570-ab04-3d036005a87b] succeeded in 100.13561034202576s: 5\n```\n\n```text\ncurl localhost/test/f855bec7-307d-4570-ab04-3d036005a87b\n{\"state\":\"PENDING\"}\nralfeus@web-2 /v/w/order (multiple-instance)> (order)\n```\n\n```text\nroot@3d2e6b124780:/# rabbitmqctl list_queues\nTimeout: 60.0 seconds ...\nListing queues for vhost / ...\nname messages\ndd65ba89-cce9-3e0b-8252-c2216912a910 1\n65d80661-6195-3986-9fa2-e468eaab656e 0\nceleryev.9ca5a092-9a0c-4bd5-935b-f5690cf9665b 0\norder_master 0\ncelery@order_master.celery.pidbox 0\nroot@3d2e6b124780:/#\n```\n\n```text\njobs.add_together.delay(2, 3)\n```\n\n```text\nrpc://\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.179Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":9,"totalLines":191,"estimatedTokens":1589}}633{"id":"stack-50656232","source":"stackoverflow","questionId":50656232,"title":"\"Guaranteed Delivery\" Messaging - should I use MQTT or ZeroMQ?","tags":["c++","rabbitmq","mqtt","zeromq","distributed-system"],"text":"Title: \"Guaranteed Delivery\" Messaging - should I use MQTT or ZeroMQ?\nTags: c++, rabbitmq, mqtt, zeromq, distributed-system\nSource: Stack Overflow\n\nQuestion:\nWe need a lightweight client based messaging solution. We used AMQP, RabbitMQ before, but in C++ we have problems.\n\nWe would like to choose ZeroMQ with malamuteserver or MQTT ? Our IoT will publish data (45 kb) almost every 5 min.\n\nWe need to deliver this message 100% and do not want to lose any message.\n\nWe tried MQTT QoS level 2, but when server disconnected or main server client has a problem we are losing published messages.\n\nWe need exactly RabbitMQ task / worker model. Messages should queued in the server until consumers connected if anything happens.\n\nAny suggestion, direction and examples welcome.\n\nP.S.: This will be production so we want to chose less problematic way :)\n\n========================================\n\nTop Answer:\n**`A:`** *We need to deliver this message 100% and do not want to lose any message.*\n\n **`B:`** *Messages should queued in the server until consumers connected if anything happens.*\n\n **`C:`** *This will be production so we want to choose a less problematic way :)* \n\n`A:` is doable\n\n`A: + B:` is doable, harder, yet still doable\n\n`A: + B: + C:` is not, this composition of requirements does come at cost\n\n **`D:`** *Any suggestion, direction and examples welcome.*\n\nZeroMQ comes at hand, as being **lightweight**, out of question, tunable / tweakable **way beyond** the cited throughput of **`~ 45 [kb / 5 min]`**, yet the Devil comes at proper understanding of the strengths of the **Zen-of-Zero**, the package, as-is, **by design strives to provide ZERO WARRANTY** and lets all kind users design their own, use-case-specific ( read as a \"just-enough\"-warranty one needs, so not losing a single bit of efficiency for the rest of the world use-cases ).\n\nSo, the **`D:`** goes into spending a proper amount of design-efforts for covering the \"*costs*\"-of-**`C:`** and you have met the design target.\n\nSo easy, this is a common task for any and all CTO-s to face this and decide next steps.\n\n### Bonus part\n\nIf in a need to minimise the IoT-devices' requirements, may go and compare these **`costs`**-of-`C:` with a similar custom-adaptation of even a more lightweight framework for Scalable Formal Communication Pattern Archetypes, that was designed by Martin Sustrik *et al*, as a younger sister of the ZeroMQ one -- the **nanomsg**, there might be some saving on low-power / scarcer resources, as commonly present in massive cohorts of IoT-devices.\n\n========================================\n\nCode:\n```text\nA:\n```\n\n```text\nB:\n```\n\n```text\nC:\n```\n\n```text\nA:\n```\n\n```text\nA: + B:\n```\n\n```text\nA: + B: + C:\n```\n\n```text\nD:\n```\n\n```text\n~ 45 [kb / 5 min]\n```\n\n```text\nD:\n```\n\n```text\nC:\n```\n\n```text\ncosts\n```\n\n```text\nC:\n```\n\n========================================\n\nComments:\n- Any comparison between MQTT and ZeroMQ regarding to this A,B,C concept ?\n- thanks for your time and elagent informative reply. I will surely take a look and test zmq. what is worried me that development looks like little bit old.\n- This answer is still true . Despite the buzz as said. Brokerless, well documented, wide range of supported langages ZeroMQ still does the job\n- \"In a distributed network, it is impossible to have 100% knowledge of the entire state.\" This is at least misleading. The Chandy Lamport algorithm is exactly addressing this topic. Creating a snapshot of a state in a distributed system.","metadata":{"transformedAt":"2026-08-18T18:33:20.179Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":104,"estimatedTokens":873}}634{"id":"stack-21018210","source":"stackoverflow","questionId":21018210,"title":"RabbitMQ inconsistent cluster","tags":["rabbitmq","mnesia"],"text":"Title: RabbitMQ inconsistent cluster\nTags: rabbitmq, mnesia\nSource: Stack Overflow\n\nQuestion:\nFew questions about **RabbitMQ v3.1.5** clustering.\nI have a cluster with 2 nodes, **rabbitmq.config** is like this on both nodes:\n\n```\n[\n {rabbit, [\n {cluster_nodes, {['rabbit@rmq01', 'rabbit@rmq02'], ram}},\n {tcp_listeners, [5674]}\n ]}\n].\n```\n\nI already seen issue like this, and now I'm watching it again:\nWhen sometimes all cluster is shutting down, in case second node (rmq02) starts before first (rmq01), it 'forgets' about rmq01:\n\n```\n[root@rmq2 rabbitmq]# rabbitmqctl cluster_status\nCluster status of node 'rabbit@rmq2' ...\n[{nodes,[{disc,['rabbit@rmq2']}]},\n {running_nodes,['rabbit@rmq2']},\n {partitions,[]}]\n...done.\n```\n\nAfter this first node (rmq01) can not start due to rmq2 disagrees about clustering:\n\n```\n{\"init terminating in do_boot\",{rabbit,failure_during_boot,{error,{inconsistent_cluster,\"Node 'rabbit@rmq1' thinks it's clustered with node 'rabbit@rmq2', but 'rabbit@rmq2' disagrees\"}}}}\n```\n\nI've tried to add rmq01 to rmq02, but seems I have to stop_app before this:\n\n```\n[root@rmq2 rabbitmq]# rabbitmqctl join_cluster rabbit@rmq1\nClustering node 'rabbit@rmq2' with 'rabbit@rmq1' ...\nError: mnesia_unexpectedly_running\n```\n\nHere I see that rmq02 forgot about rmq01:\n\n```\n[root@rmq2 ~]# cat /var/lib/rabbitmq/mnesia/rabbit\\@rmq2/cluster_nodes.config \n{['rabbit@rmq2'],['rabbit@rmq2']}.\n```\n\nMeanwhile on rmq01 (correct configuration):\n\n```\n[root@rmq1 ~]# cat /var/lib/rabbitmq/mnesia/rabbit\\@rmq1/cluster_nodes.config \n{['rabbit@rmq1','rabbit@rmq2'],['rabbit@rmq1']}.\n```\n\nQuestions:\n\n- Is it normal **rmq02** forgets about **rmq01**, or I have some missconfiguration? Why is this happening?\n\n- In case it is ok, is it possible to fix up cluster health without **rmq02** downtime (I mean without stop_app)?\n\n========================================\n\nCode:\n```text\n[\n {rabbit, [\n {cluster_nodes, {['rabbit@rmq01', 'rabbit@rmq02'], ram}},\n {tcp_listeners, [5674]}\n ]}\n].\n```\n\n```text\n[root@rmq2 rabbitmq]# rabbitmqctl cluster_status\nCluster status of node 'rabbit@rmq2' ...\n[{nodes,[{disc,['rabbit@rmq2']}]},\n {running_nodes,['rabbit@rmq2']},\n {partitions,[]}]\n...done.\n```\n\n```text\n{\"init terminating in do_boot\",{rabbit,failure_during_boot,{error,{inconsistent_cluster,\"Node 'rabbit@rmq1' thinks it's clustered with node 'rabbit@rmq2', but 'rabbit@rmq2' disagrees\"}}}}\n```\n\n```text\n[root@rmq2 rabbitmq]# rabbitmqctl join_cluster rabbit@rmq1\nClustering node 'rabbit@rmq2' with 'rabbit@rmq1' ...\nError: mnesia_unexpectedly_running\n```\n\n```text\n[root@rmq2 ~]# cat /var/lib/rabbitmq/mnesia/rabbit\\@rmq2/cluster_nodes.config \n{['rabbit@rmq2'],['rabbit@rmq2']}.\n```\n\n```text\n[root@rmq1 ~]# cat /var/lib/rabbitmq/mnesia/rabbit\\@rmq1/cluster_nodes.config \n{['rabbit@rmq1','rabbit@rmq2'],['rabbit@rmq1']}.\n```\n\n```text\n[root@rmq01 ~]# rm -rf /var/lib/rabbitmq/mnesia/\n\n[root@rmq01 ~]# service rabbitmq-server start\nStarting rabbitmq-server: SUCCESS\nrabbitmq-server.\n[root@rmq01 ~]# rabbitmqctl cluster_status\nCluster status of node 'rabbit@rmq01' ...\n[{nodes,[{disc,['rabbit@rmq02']},{ram,['rabbit@rmq01']}]},\n {running_nodes,['rabbit@rmq02','rabbit@rmq01']},\n {partitions,[]}]\n...done.\n```\n\n========================================\n\nComments:\n- Note: for windows the mnesia folder is in `C:\\Users\\\\AppData\\Roaming\\RabbitMQ\\db`. I deleted that folder on a node I couldn't get back up and it worked. Thanks!\n- I was seeing `error,corrupt_cluster_status_files,` in `/var/log/rabbitmq/startup_log`. Removing the mnesia directory and restarting the service fixed the issue.","metadata":{"transformedAt":"2026-08-18T18:33:20.179Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":7,"totalLines":123,"estimatedTokens":901}}635{"id":"stack-12660994","source":"stackoverflow","questionId":12660994,"title":"How to fail the chain if it's sub task gives an exception","tags":["python","django","rabbitmq","celery"],"text":"Title: How to fail the chain if it's sub task gives an exception\nTags: python, django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI have faced a pretty strange issue with celery:\n\nThere is a chain of tasks, and one of them gives an exception and does several retries\n\n```\nchain = (err.si(1) | err.si(2))\nresult = chain.apply_async()\nresult.state\nresult.get()\n```\n\nhere is the code of the task:\n\n```\n@celery.task(base=MyTask)\ndef err(x):\ntry:\n if x The thing is that although the task in chain gives an exception, but the result.state keeps being 'PENDING' and .get() just freezes.\n\nI have tried to fail the task in case it reaches maximum retries value:\n\n```\nclass MyTask(celery.Task):\nabstract = True\ndef after_return(self, status, retval, task_id, args, kwargs, einfo):\n if self.max_retries == self.request.retries:\n self.state = states.FAILURE\n```\n\nBut although executed separately task is getting marked as FAILED, executing in chain gives same result - PENDING & Freezed get.\n\nI expected that the chain will get failed once any of it's tasks will get failed and .get of the result should produce the exception thrown from the task.\n\n_***UPDATE*_**\nStack trace given by apply_async with ALWAYS_EAGER=True\n\n```\nresult = chain.apply_async()\n\nException \nTraceback (most recent call last)\n in ()\n----> 1 result = chain.apply_async()\n\nlib/python2.7/site-packages/celery/canvas.pyc in apply_async(self, args, kwargs, **options)\n 147 # For callbacks: extra args are prepended to the stored args.\n 148 args, kwargs, options = self._merge(args, kwargs, options)\n--> 149 return self.type.apply_async(args, kwargs, **options)\n 150 \n 151 def append_to_list_option(self, key, value):\n\n/lib/python2.7/site-packages/celery/app/builtins.pyc in apply_async(self, args, kwargs, group_id, chord, task_id, **options)\n 232 task_id=None, **options):\n 233 if self.app.conf.CELERY_ALWAYS_EAGER:\n--> 234 return self.apply(args, kwargs, **options)\n 235 options.pop('publisher', None)\n 236 tasks, results = self.prepare_steps(args, kwargs['tasks'])\n\nlib/python2.7/site-packages/celery/app/builtins.pyc in apply(self, args, kwargs, subtask, **options)\n 249 last, fargs = None, args # fargs passed to first task only\n 250 for task in kwargs['tasks']:\n--> 251 res = subtask(task).clone(fargs).apply(last and (last.get(), ))\n 252 res.parent, last, fargs = last, res, None\n 253 return last\n\nlib/python2.7/site-packages/celery/result.pyc in get(self, timeout, propagate, **kwargs)\n 677 elif self.state in states.PROPAGATE_STATES:\n 678 if propagate:\n--> 679 raise self.result\n 680 return self.result\n 681 wait = get\n\nException:\n```\n\n========================================\n\nTop Answer:\nActually I think you shouldn't be using `raise` here.\n\nYou're throwing an exception, when the documentation says you shouldn't, you might want to just use `err.retry` and not `raise err.retry`.\n\n========================================\n\nCode:\n```text\nchain = (err.si(1) | err.si(2))\nresult = chain.apply_async()\nresult.state\nresult.get()\n```\n\n```text\n@celery.task(base=MyTask)\ndef err(x):\ntry:\n if x < 3:\n raise Exception\n else:\n return x+1\n\nexcept Exception as exp:\n print \"retrying\"\n raise err.retry(args=[x],exc=exp,countdown=5,max_retries=3)\n```\n\n```text\nclass MyTask(celery.Task):\nabstract = True\ndef after_return(self, status, retval, task_id, args, kwargs, einfo):\n if self.max_retries == self.request.retries:\n self.state = states.FAILURE\n```\n\n```text\nresult = chain.apply_async()\n\nException \nTraceback (most recent call last)\n<ipython-input-4-81202b369b5f> in <module>()\n----> 1 result = chain.apply_async()\n\nlib/python2.7/site-packages/celery/canvas.pyc in apply_async(self, args, kwargs, **options)\n 147 # For callbacks: extra args are prepended to the stored args.\n 148 args, kwargs, options = self._merge(args, kwargs, options)\n--> 149 return self.type.apply_async(args, kwargs, **options)\n 150 \n 151 def append_to_list_option(self, key, value):\n\n/lib/python2.7/site-packages/celery/app/builtins.pyc in apply_async(self, args, kwargs, group_id, chord, task_id, **options)\n 232 task_id=None, **options):\n 233 if self.app.conf.CELERY_ALWAYS_EAGER:\n--> 234 return self.apply(args, kwargs, **options)\n 235 options.pop('publisher', None)\n 236 tasks, results = self.prepare_steps(args, kwargs['tasks'])\n\nlib/python2.7/site-packages/celery/app/builtins.pyc in apply(self, args, kwargs, subtask, **options)\n 249 last, fargs = None, args # fargs passed to first task only\n 250 for task in kwargs['tasks']:\n--> 251 res = subtask(task).clone(fargs).apply(last and (last.get(), ))\n 252 res.parent, last, fargs = last, res, None\n 253 return last\n\nlib/python2.7/site-packages/celery/result.pyc in get(self, timeout, propagate, **kwargs)\n 677 elif self.state in states.PROPAGATE_STATES:\n 678 if propagate:\n--> 679 raise self.result\n 680 return self.result\n 681 wait = get\n\nException:\n```\n\n```text\n>>> c = a.s() | b.s() | c.s()\n>>> res = c()\n>>> res.get()\n```\n\n```text\n>>> res # result of c.s()\n>>> res.parent # result of b.s()\n>>> res.parent.parent # result of a.s()\n```\n\n```text\ndef nodes(node):\n while node.parent:\n yield node\n node = node.parent\n yield node\n\n\nvalues = [node.get(timeout=1) for node in reversed(list(nodes(res)))]\nvalue = values[-1]\n```\n\n```text\nres.get()\n```\n\n```text\nparent\n```\n\n```text\nraise\n```\n\n```text\nerr.retry\n```\n\n```text\nraise err.retry\n```\n\n========================================\n\nComments:\n- Try running your task with CELERY_ALWAYS_EAGER activated , that should help you find out what is causing the issue.\n- In case I have CELERY_ALWAYS_EAGER set to True, apply_async immediately gives the stack trace and the results var is None. In case I have it set to false, the result does exist with result.state = Pending.\n- This documentations is old. Task.retry actually always raises an exception. The exception is handled specially in the worker so it knows the task will be retried. It makes the code harder to read when people don't know that it will raise, and think the code will continue below. So the docs was changed to use 'raise err.retry' instead. You don't need the raise, but it gives a hint to readers that it won't continue.\n- Technically this is a synthetic test, I want to handle exceptions there which may happen. My tasks interacting with external webservices which are unstable and may return unexpected output\n- Thanks for a great reply asksol! Is there any conventional way to prevent child tasks from executing at all in case if any of its parents got failed (raised an exception)? Example setup: chord(group(parent1, parent2), group(children)) If parent1 fails, it's children executed with [exception, parent2.retval] as first argument, which I want to avoid.\n- Only chord works this way by passing along the exception value, and this behavior is not specified in the documentation. I think it would make sense to make it consistent with the rest by not executing the chord callback instead. Maybe you could open an issue here: github.com/celery/celery/issues ?","metadata":{"transformedAt":"2026-08-18T18:33:20.179Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":211,"estimatedTokens":1840}}636{"id":"stack-51616600","source":"stackoverflow","questionId":51616600,"title":"SSH, RabbitMQ, Protocol 'inet_tcp': register/listen error: econnrefused","tags":["rabbitmq","erlang"],"text":"Title: SSH, RabbitMQ, Protocol 'inet_tcp': register/listen error: econnrefused\nTags: rabbitmq, erlang\nSource: Stack Overflow\n\nQuestion:\nWhen I try to run on my server machine command\n\n```\n./rabbitmq-server\n```\n\nI the get following:\n\n```\nWARNING: Removing trailing slash from RABBITMQ_LOG_BASE\n Removing trailing slash from RABBITMQ_MNESIA_BASE\nProtocol 'inet_tcp': register/listen error: econnrefused\n```\n\nBackstory:\nThis is my first time I'm trying to install RabbitMQ-Server **just using ssh**.\n\nStep-by-step what I did so far would be:\n\n- wget https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.0/rabbitmq-server-3.6.15.zip\n\n- unzip rabbitmq-server-3.6.15.zip\n\n- nano Makefile # change prefix to rabbitMQ in home directory PREFIX ?= /home/user/rabbitmq\n\n- gmake\n\n- gmake install\n\n- cd ~/rabbitmq/lib/erlang/lib/rabbitmq_server-3.6.15/sbin/\nexport RABBITMQ_MNESIA_BASE=/home/user/rabbitmq/lib/erlang/lib/rabbitmq_server-3.6.15/sbin/ \nexport RABBITMQ_LOG_BASE=/home/user/rabbitmq/ \n\n- ./rabbitmq-server\n\nAnd here comes the error. I was told that maybe \"unlocking\" ports would do the trick, but\n\n- I don't know how to do that\n\n- I don't know if that's the case\n\n========================================\n\nCode:\n```text\n./rabbitmq-server\n```\n\n```text\nWARNING: Removing trailing slash from RABBITMQ_LOG_BASE\n Removing trailing slash from RABBITMQ_MNESIA_BASE\nProtocol 'inet_tcp': register/listen error: econnrefused\n```\n\n```text\nProtocol 'inet_tcp': register/listen error: econnrefused\n```\n\n```text\nepmd\n```\n\n```text\nfailed to bind socket: Operation not permitted\n```\n\n========================================\n\nComments:\n- Why are you not using the latest pre-packaged release for your operating system? If that is not an option, use the `generic-unix` package. Compiling RabbitMQ yourself should not be necessary and will only cause headaches like you're seeing. Finally, what Erlang version are you using?\n- From what Legoscia posted below, it seems like it's not RabbitMQ's failure, but rather epmd. My version is 19\n- @LukeBakken IME, compiling Erlang apps/projects is totally fine (and seemingly common). Is RabbitMQ particularly hard to compile?\n- Hello, Running epmd gives me error [user@xxx]:$ epmd epmd: Wed Aug 1 11:51:19 2018: failed to bind socket: Operation not permitted\n- Right, that would be the source of the problem. Not sure why it wouldn't have permission to listen on the port. It's using port 4369, which is not a privileged port...\n- I don't know why exactly, but it seems like my 4369 port, even if not listed in netstat, was used / blocked by something. Freeing this port solved this problem, so this is correct answer. Thank you so much.\n- I know I am late but try to kill antivirus, for me it was AVG blocking the port","metadata":{"transformedAt":"2026-08-18T18:33:20.179Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":81,"estimatedTokens":689}}637{"id":"stack-5680488","source":"stackoverflow","questionId":5680488,"title":"How do you process messages in parallel while ensuring FIFO per entity?","tags":["concurrency","message-queue","activemq-classic","rabbitmq","hornetq"],"text":"Title: How do you process messages in parallel while ensuring FIFO per entity?\nTags: concurrency, message-queue, activemq-classic, rabbitmq, hornetq\nSource: Stack Overflow\n\nQuestion:\nLet's say you have an entity, say, \"Person\" in your system and you want to process events that modify various Person entities. It is important that:\n\n- Events for the same Person are processed in FIFO order\n\n- Multiple Person event streams be processed in parallel by different threads/processes\n\nWe have an implementation that solves this using a shared database and locks. Threads compete to acquire the lock for a Person and then process events in order after acquiring the lock. We'd like to move to a message queue to avoid polling and locking, which we feel would reduce load on the DB and simplify the implementation of the consumer code.\n\nI've done some research into ActiveMQ, RabbitMQ, and HornetQ but I don't see an obvious way to implement this.\n\nActiveMQ supports consumer subscription wildcards, but I don't see a way to limit the concurrency on each queue to 1. If I could do that, then the solution would be straightforward:\n\n- Somehow tell broker to allow a concurrency of 1 for all queues starting with: /queue/person.\n\n- Publisher writes event to queue using Person ID in the queue name. e.g.: /queue/person.20\n\n- Consumers subscribe to the queue using wildcards: /queue/person.>\n\n- Each consumer would receive messages for different person queues. If all person queues were in use, some consumers may sit idle, which is ok\n\n- After processing a message, the consumer sends an ACK, which tells the broker it's done with the message, and allows another message for that Person queue to be sent to another consumer (possibly the same one)\n\nActiveMQ came close: You can do wildcard subscriptions and enable \"exclusive consumer\", but that combination results in a single consumer receiving all messages sent to all matching queues, reducing your concurrency to 1 across all Persons. I feel like I'm missing something obvious.\n\nQuestions:\n\n- Is there way to implement the above approach with any major message queue implementation? We are fairly open to options. The only requirement is that it run on Linux.\n\n- Is there a different way to solve the general problem that I'm not considering?\n\nThanks!\n\n========================================\n\nTop Answer:\nOne general way to solve this problem (if I got your problem right) is to introduce some unique property for Person (say, database-level id of Person) and use hash of that property as index of FIFO queue to put that Person in.\n\nSince hash of that property can be unwieldy big (you can't afford 2^32 queues/threads), use only N the least significant bits of that hash.\nEach FIFO queue should have dedicated worker that will work upon it -- voila, your requirements are satisfied!\n\nThis approach have one drawback -- your Persons must have well-distributed ids to make all queues work with more-or-less equal load. If you can't guarantee that, consider using round-robin set of queues and track which Persons are being processed now to ensure sequential processing for same person.\n\n========================================\n\nComments:\n- With a non-polling queue protocol (AMQP, STOMP) the broker will already deliver the message to the consumer based on the subscription rules. The consumer could consult the lock table and wait until it's available, but that introduces complexity and reduces parallelism since the consumer could be working on a message for another entity instead of waiting for the lock.\n- Yes, but the consumer doesn't need to wait on the lock - it can pass on to the next queue. Presumably your queuing protocol would also allow consumers to decline to read the message from the queue, and they could test the lock then.\n- In your solution do the consumers still do a wildcard subscription? If so, how do I ensure each queue only has one active consumer? Or are you saying I hash the queue name down so that N == # of active consumers?\n- @James sorry to confuse you, I talked about general solution, without JMS in mind. That is, just threads and JDK collections. So, in my solution one have to manually setup mapping between queue and consumer -- it's usually very easily done.\n- Looks like this totally works. Here's a python example I've successfully tested against ActiveMQ and HornetQ for this type of problem if anyone's interested: gist.github.com/923228\n- From oracle JMS 1.1 especification I found `JMSXGroupID`, looks like it's required for all JMS implementations. But it don't explain the expected behavior with details, then will depend of the provider","metadata":{"transformedAt":"2026-08-18T18:33:20.180Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":56,"estimatedTokens":1160}}638{"id":"stack-10404921","source":"stackoverflow","questionId":10404921,"title":"How could a distributed queue-like-thing be implemented on top of a RBDMS or NOSQL datastore or other messaging system (e.g., rabbitmq)?","tags":["java","python","nosql","message-queue","rabbitmq"],"text":"Title: How could a distributed queue-like-thing be implemented on top of a RBDMS or NOSQL datastore or other messaging system (e.g., rabbitmq)?\nTags: java, python, nosql, message-queue, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nFrom the wouldn't-it-be-cool-if category of questions ...\n\nBy \"queue-like-thing\" I mean supports the following operations:\n\n- append(entry:Entry) - add entry to tail of queue\n\n- take(): Entry - remove entry from head of queue and return it\n\n- promote(entry_id) - move the entry one position closer to the head; the entry that currently occupies that position is moved in the old position\n\n- demote(entry_id) - the opposite of promote(entry_id)\n\nOptional operations would be something like:\n\n- promote(entry_id, amount) - like promote(entry_id) except you specify the number of positions\n\n- demote(entry_id, amount) - opposite of promote(entry_id, amount)\n\n- of course, if we allow amount to be positive or negative, we can consolidate the promote/demote methods with a single move(entry_id, amount) method\n\nIt would be ideal if the following operations could be performed on the queue in a distributed fashion (multiple clients interacting with the queue):\n\n```\nqueue = ...\n\nqueue.append( a )\nqueue.append( b )\nqueue.append( c )\n\nprint queue\n\"a b c\"\n\nqueue.promote( b.id )\nprint queue\n\"b a c\"\n\nqueue.demote( a.id )\n\"b c a\"\n\nx = queue.take()\nprint x\n\"b\"\nprint queue\n\"c a\"\n```\n\nAre there any data stores that are particularly apt for this use case? The queue should always be in a consistent state even if multiple users are modifying the queue simultaneously.\n\nIf it weren't for the promote/demote/move requirement, there wouldn't be much of a problem.\n\nEdit:\nBonus points if there are Java and/or Python libraries to accomplish the task outlined above.\n\nSolution should scale extremely well.\n\n========================================\n\nTop Answer:\nRedis supports lists and ordered sets: http://redis.io/topics/data-types#lists\n\nIt also supports transactions and publish/subscribe messaging. So, yes, I would say this can be easily done on redis.\n\nUpdate: In fact, about 80% of it has been done many times: http://www.google.co.uk/search?q=python+redis+queue \n\nSeveral of those hits could be upgraded to add what you want. You would have to use transactions to implement the promote/demote operations.\n\nIt might be possible to use lua on the server side to create that functionality, rather than having it in client code. Alternatively, you could create a thin wrapper around redis on the server, that implements just the operations you want.\n\n========================================\n\nCode:\n```text\nqueue = ...\n\nqueue.append( a )\nqueue.append( b )\nqueue.append( c )\n\nprint queue\n\"a b c\"\n\nqueue.promote( b.id )\nprint queue\n\"b a c\"\n\nqueue.demote( a.id )\n\"b c a\"\n\nx = queue.take()\nprint x\n\"b\"\nprint queue\n\"c a\"\n```\n\n```text\nclass PQueue:\n \"\"\"\n Implements a priority queue with append, take, promote, and demote\n operations.\n \"\"\"\n def __init__(self):\n \"\"\"\n Initialize empty priority queue.\n self.toll is max(priority) and max(rowid) in the queue\n self.heap is the heap maintained for take command\n self.rows is a mapping from rowid to items\n self.pris is a mapping from priority to items\n \"\"\"\n self.toll = 0\n self.heap = list()\n self.rows = dict()\n self.pris = dict()\n\n def append(self, value):\n \"\"\"\n Append value to our priority queue.\n The new value is added with lowest priority as an item. Items are\n threeple lists consisting of [priority, rowid, value]. The rowid\n is used by the promote/demote commands.\n Returns the new rowid corresponding to the new item.\n \"\"\"\n self.toll += 1\n item = [self.toll, self.toll, value]\n self.heap.append(item)\n self.rows[self.toll] = item\n self.pris[self.toll] = item\n return self.toll\n\n def take(self):\n \"\"\"\n Take the highest priority item out of the queue.\n Returns the value of the item.\n \"\"\"\n item = heapq.heappop(self.heap)\n del self.pris[item[0]]\n del self.rows[item[1]]\n return item[2]\n\n def promote(self, rowid):\n \"\"\"\n Promote an item in the queue.\n The promoted item swaps position with the next highest item.\n Returns the number of affected rows.\n \"\"\"\n if rowid not in self.rows: return 0\n item = self.rows[rowid]\n item_pri, item_row, item_val = item\n next = item_pri - 1\n if next in self.pris:\n iota = self.pris[next]\n iota_pri, iota_row, iota_val = iota\n iota[1], iota[2] = item_row, item_val\n item[1], item[2] = iota_row, iota_val\n self.rows[item_row] = iota\n self.rows[iota_row] = item\n return 2\n return 0\n```\n\n```text\npqueue = PQueue()\n\ndef pqueue_server(sock, addr):\n text = sock.recv(1024)\n cmds = text.split(' ')\n if cmds[0] == 'append':\n result = pqueue.append(cmds[1])\n elif cmds[0] == 'take':\n result = pqueue.take()\n elif cmds[0] == 'promote':\n result = pqueue.promote(int(cmds[1]))\n elif cmds[0] == 'demote':\n result = pqueue.demote(int(cmds[1]))\n else:\n result = ''\n sock.sendall(str(result))\n print 'Request:', text, '; Response:', str(result)\n\nif args.listen:\n server = StreamServer(('127.0.0.1', 4040), pqueue_server)\n print 'Starting pqueue server on port 4040...'\n server.serve_forever()\n```\n\n```text\nif args.client:\n while True:\n msg = raw_input('> ')\n sock = gsocket.socket(gsocket.AF_INET, gsocket.SOCK_STREAM)\n sock.connect(('127.0.0.1', 4040))\n sock.sendall(msg)\n text = sock.recv(1024)\n sock.close()\n print text\n```\n\n```text\n> append one\n1\n> append two\n2\n> append three\n3\n> promote 2\n2\n> promote 2\n0\n> take\ntwo\n```\n\n```text\ndef test():\n import time\n import urllib2\n import subprocess\n\n import random\n random = random.Random(0)\n\n from progressbar import ProgressBar, Percentage, Bar, ETA\n widgets = [Percentage(), Bar(), ETA()]\n\n def make_name():\n alphabet = 'abcdefghijklmnopqrstuvwxyz'\n return ''.join(random.choice(alphabet)\n for rpt in xrange(random.randrange(3, 20)))\n\n def make_request(cmds):\n sock = gsocket.socket(gsocket.AF_INET, gsocket.SOCK_STREAM)\n sock.connect(('127.0.0.1', 4040))\n sock.sendall(cmds)\n text = sock.recv(1024)\n sock.close()\n\n print 'Starting server and waiting 3 seconds.'\n subprocess.call('start cmd.exe /c python.exe queue_thing_gevent.py -l',\n shell=True)\n time.sleep(3)\n\n tests = []\n def wrap_test(name, limit=10000):\n def wrap(func):\n def wrapped():\n progress = ProgressBar(widgets=widgets)\n for rpt in progress(xrange(limit)):\n func()\n secs = progress.seconds_elapsed\n print '{0} {1} records in {2:.3f} s at {3:.3f} r/s'.format(\n name, limit, secs, limit / secs)\n tests.append(wrapped)\n return wrapped\n return wrap\n\n def direct_append():\n name = make_name()\n pqueue.append(name)\n\n count = 1000000\n @wrap_test('Loaded', count)\n def direct_append_test(): direct_append()\n\n def append():\n name = make_name()\n make_request('append ' + name)\n\n @wrap_test('Appended')\n def append_test(): append()\n\n ...\n\n print 'Running speed tests.'\n for tst in tests: tst()\n```\n\n```text\nStarting server and waiting 3 seconds.\nRunning speed tests.\n100%|############################################################|Time: 0:00:21\nLoaded 1000000 records in 21.770 s at 45934.773 r/s\n100%|############################################################|Time: 0:00:06\nAppended 10000 records in 6.825 s at 1465.201 r/s\n100%|############################################################|Time: 0:00:06\nPromoted 10000 records in 6.270 s at 1594.896 r/s\n100%|############################################################|Time: 0:00:05\nDemoted 10000 records in 5.686 s at 1758.706 r/s\n100%|############################################################|Time: 0:00:05\nTook 10000 records in 5.950 s at 1680.672 r/s\n100%|############################################################|Time: 0:00:07\nMixed load processed 10000 records in 7.410 s at 1349.528 r/s\n```\n\n```text\ndef save_heap(heap, toll):\n name = 'heap-{0}.txt'.format(toll)\n with open(name, 'w') as temp:\n for val in heap:\n temp.write(str(val))\n gevent.sleep(0)\n```\n\n```text\ndef save(self):\n heap_copy = tuple(self.heap)\n toll = self.toll\n gevent.spawn(save_heap, heap_copy, toll)\n```\n\n```text\nRedisson redisson = Redisson.create();\n\nRDeque<SomeObject> queue = redisson.getDeque(\"anyDeque\");\nqueue.addFirst(new SomeObject());\nqueue.addLast(new SomeObject());\nSomeObject obj = queue.removeFirst();\nSomeObject someObj = queue.removeLast();\n\nredisson.shutdown();\n```\n\n```text\nList\n```\n\n```text\nQueue\n```\n\n```text\nBlockingQueue\n```\n\n```text\nDeque\n```\n\n```text\nDeque\n```\n\n========================================\n\nComments:\n- Yes! I seemed to have stumped stack overflow! No one knows the answer!\n- using a RDBMS for a queue is often done and almost always a bad idea on the long term. Read this : engineyard.com/blog/2011/…\n- I actually read that article before I posted. I am not necessarily interested in a RDBMS solution. I'm interested in *any* solution that works.\n- I really don't think you can have, using a DBMS, efficient promote and demote functions. Are they really really necessary for you application ? Without this requirement (usually a change of priority is sufficient) it seems easy to to with a DBMS.\n- The question starts off with: \"From the wouldn't-it-be-cool-if category of questions ...\" ... and yes, promote / demote are required. If all I needed was a queue with separate priorities, then I just use rabbitmq :) I *need* to dynamically promote and demote items in the queue.\n- Notice I said on top of a RDBMS *or* NOSQL *or* messaging system. I also pointed out as the last sentence in the post \"If it weren't for the promote/demote/move requirement, there wouldn't be much of a problem.\"\n- Confused. Everything stated can be accomplished via RDBMS with abstracting SQL. Be that the best architecture is debatable. Despite the problems of traditional database stores for MQs they are easy to implement and MANAGE.\n- @les2 : Yes. And I hope somebody than me (with more competences than me) will find the efficient solution for promotion and demotion (which seems to me to be hard to scale).\n- How does the pricing for that even work?! I can't even begin to decipher how much WebSphere MQ would cost for my co!!!\n- Too true! This is a common problem with most commercial software. MQ is actually pretty cheap for this sort of thing, approx $1000 for a server license on a typical four processor setup, but it will vary wildly depending on where you are located and the sort of company you work for. Take a look a RabbitMQ or ActiveMQ for an open source alternative. I quoted the Websphere product because I have worked on an implementation very similar to your requirement and I know for sure it can almost do it all.\n- Is it possible to move jobs within queues?\n- So, it doesn't do exactly what was requested.","metadata":{"transformedAt":"2026-08-18T18:33:20.180Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":15,"totalLines":361,"estimatedTokens":2872}}639{"id":"stack-48020770","source":"stackoverflow","questionId":48020770,"title":"Is There a Way to Limit the Number of Consumers on a RabbitMQ Queue?","tags":["rabbitmq"],"text":"Title: Is There a Way to Limit the Number of Consumers on a RabbitMQ Queue?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI've got a RabbitMQ setup with lots of queues. Due to the nature of the data in each queue, it has to be processed in strict order, so we can only permit a single consumer on each queue. This isn't a problem as such, but we do run the risk of accidentally starting a second consumer on a queue, which would be a bad thing. There's lots of queues and lots of app servers and it would just take a small typo for us to end up in this situartion.\n\nBefore I spend time changing the software to effectively \"lock\" a queue (storing that lock in a DB or something), is there anything in RabbitMQ that can limit the number of consumers a queue can have? If so, I can limit my queues to just one consumer and my risk of multiple consumers goes away.\n\nCheers!\n\n========================================\n\nTop Answer:\nIf you are using `sprig framework` you can use the tag `exclusive=true`in the tag rabbit listener `@RabbitListener`. So with you are able to restrict the queue to one consumer.\n\n`@RabbitListener(queues = \"${queue.name}\", exclusive = true)`\n\n========================================\n\nCode:\n```text\nexclusive\n```\n\n```text\nconsume\n```\n\n```text\nsprig framework\n```\n\n```text\nexclusive=true\n```\n\n```text\n@RabbitListener\n```\n\n```text\n@RabbitListener(queues = \"${queue.name}\", exclusive = true)\n```\n\n========================================\n\nComments:\n- Thanks, that's perfect. And pretty obvious now I actually look at the \"consume\" method!","metadata":{"transformedAt":"2026-08-18T18:33:20.180Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":49,"estimatedTokens":391}}640{"id":"stack-6756630","source":"stackoverflow","questionId":6756630,"title":"Python: OpenMPI Vs. RabbitMQ","tags":["python","messaging","mpi","rabbitmq","amqp"],"text":"Title: Python: OpenMPI Vs. RabbitMQ\nTags: python, messaging, mpi, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nSuppose that one is interested to write a `python` app where there should be communication between different processes. The communications will be done by sending `strings` and/or `numpy` arrays.\n\nWhat are the considerations to prefer `OpenMPI` vs. a tool like `RabbitMQ`?\n\n========================================\n\nTop Answer:\nThis is exactly the scenario I was in a few months ago and I decided to use AMQP with RabbitMQ using topic exchanges, in addition to memcache for large objects.\n\nThe AMQP messages are all strings, in JSON object format so that it is easy to add attributes to a message (like number of retries) and republish it. JSON objects are a subset of JSON that correspond to Python dicts. For instance {\"recordid\": \"272727\"} is a JSON object with one attribute. I could have just pickled a Python dict but that would have locked us into only using Python with the message queues.\n\nThe large objects don't get routed by AMQP, instead they go into a memcache where they are available for another process to retrieve them. You could just as well use Redis or Tokyo Tyrant for this job. The idea is that we did not want short messages to get queued behind large objects. \n\nIn the end, my Python processes ended up using both AMQP and ZeroMQ for two different aspects of the architecture. You may find that it makes sense to use both OpenMPI and AMQP but for different types of jobs.\n\nIn my case, a supervisor process runs forever, starts a whole flock of worker who also run forever unless they die or hang, in which case the supervisor restarts them. The work constantly flows in as messages via AMQP, and each process handles just one step of the work, so that when we identify a bottleneck we can have multiple instances of the process, possibly on separate machines, to remove the bottleneck. In my case, I have 15 instances of one process, 4 of two others, and about 8 other single instances.\n\n========================================\n\nCode:\n```text\npython\n```\n\n```text\nstrings\n```\n\n```text\nnumpy\n```\n\n```text\nOpenMPI\n```\n\n```text\nRabbitMQ\n```\n\n```text\nZeroMQ\n```\n\n========================================\n\nComments:\n- abbot, thank you for your response. Yes, I am sending `large packets` (few MBs each) across a network of 100 machines; I have a simple, 1G network. Nothing fancy; can have a little latency -- doesn't have to be the fastest.\n- +1. In general, MPI is good for running a single large task on multiple reliable nodes (eg, nodes in a cluster, or a bunch of PCs in a lab). As mentioned above, it's also great when you don't know what sort of networking have, or you want to take advantage of shared memory between cores on a node. The further you stray from this sort of use case, the less well MPI fits. I'll just add that OpenMPI is just one implementation of MPI; MPICH2, another, is just as good. And if you are going to use MPI+Python, I recommend mpi4py. ( mpi4py.scipy.org )\n- Jonathan, thank you. Are there any pluses for using `OpenMPI` vs. `RabbitMQ`?\n- Of course there are. And it all depends on the answers to the questions in my reply. For example: OpenMPI would tear RabbitMQ to pieces in terms of throughput and latency if it is running on a cluster with Infiniband hardware. RabbitMQ does allow easy configurations like several producers - several consumers, while you will have to write a lot of boilerplate to do this with OpenMPI. Etc, etc.\n- Michael, this is an interesting design. Thanks for sharing this.\n- you should also consider *msgpack* for serialization, it works very well with *zeromq*.","metadata":{"transformedAt":"2026-08-18T18:33:20.180Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":58,"estimatedTokens":916}}641{"id":"stack-32077044","source":"stackoverflow","questionId":32077044,"title":"Re-queue message on exception","tags":["c#","rabbitmq","publish-subscribe","easynetq"],"text":"Title: Re-queue message on exception\nTags: c#, rabbitmq, publish-subscribe, easynetq\nSource: Stack Overflow\n\nQuestion:\nI'm looking for a solid way of re-queuing messages that couldn't be handled properly - at this time.\n\nI've been looking at http://dotnetcodr.com/2014/06/16/rabbitmq-in-net-c-basic-error-handling-in-receiver/ and it seems that it's supported to requeue messages in the RabbitMQ API. \n\n```\nelse //reject the message but push back to queue for later re-try\n{\n Console.WriteLine(\"Rejecting message and putting it back to the queue: {0}\", message);\n model.BasicReject(deliveryArguments.DeliveryTag, true);\n}\n```\n\nHowever I'm using EasyNetQ.\nSo wondering how I would do something similar here.\n\n```\nbus.Subscribe(\"my_subscription_id\", msg => {\n try\n {\n // do work... could be long running\n }\n catch ()\n {\n // something went wrong - requeue message\n }\n});\n```\n\nIs this even a good approach? Not `ACK` the message could cause problems if `do work` exceeds the wait for `ACK` timeout by the RabbitMQ server.\n\n========================================\n\nTop Answer:\nto the best of my knowledge, there is no way to manually `ack`, `nack` or `reject` a message with EasyNetQ.\n\nI see you have opened an issue ticket with the EasyNetQ team, regarding this... but no answer, yet.\n\nFWIW, this is a very appropriate thing to do. All of the libraries that I use support this feature set (in NodeJS) and it is common. I'm surprised EasyNetQ doesn't support this.\n\n========================================\n\nCode:\n```text\nelse //reject the message but push back to queue for later re-try\n{\n Console.WriteLine(\"Rejecting message and putting it back to the queue: {0}\", message);\n model.BasicReject(deliveryArguments.DeliveryTag, true);\n}\n```\n\n```text\nbus.Subscribe<MyMessage>(\"my_subscription_id\", msg => {\n try\n {\n // do work... could be long running\n }\n catch ()\n {\n // something went wrong - requeue message\n }\n});\n```\n\n```text\nACK\n```\n\n```text\ndo work\n```\n\n```text\nACK\n```\n\n```text\npublic class DeadLetterStrategy : DefaultConsumerErrorStrategy\n{\n public DeadLetterStrategy(IConnectionFactory connectionFactory, ISerializer serializer, IEasyNetQLogger logger, IConventions conventions, ITypeNameSerializer typeNameSerializer)\n : base(connectionFactory, serializer, logger, conventions, typeNameSerializer)\n {\n }\n\n public override AckStrategy HandleConsumerError(ConsumerExecutionContext context, Exception exception)\n {\n object deathHeaderObject;\n if (!context.Properties.Headers.TryGetValue(\"x-death\", out deathHeaderObject))\n return AckStrategies.NackWithoutRequeue;\n\n var deathHeaders = deathHeaderObject as IList;\n\n if (deathHeaders == null)\n return AckStrategies.NackWithoutRequeue;\n\n var retries = 0;\n foreach (IDictionary header in deathHeaders)\n {\n var count = int.Parse(header[\"count\"].ToString());\n retries += count;\n }\n\n if (retries < 3)\n return AckStrategies.NackWithoutRequeue;\n return base.HandleConsumerError(context, exception);\n }\n}\n```\n\n```text\nRabbitHutch.CreateBus(\"host=localhost\", serviceRegister => serviceRegister.Register<IConsumerErrorStrategy, DeadLetterStrategy>())\n```\n\n```text\nusing (var bus = RabbitHutch.CreateBus(\"host=localhost\", serviceRegister => serviceRegister.Register<IConsumerErrorStrategy, DeadLetterStrategy>()))\n{\n var deadExchange = bus.Advanced.ExchangeDeclare(\"exchange.text.dead\", ExchangeType.Direct);\n var textExchange = bus.Advanced.ExchangeDeclare(\"exchange.text\", ExchangeType.Direct);\n var queue = bus.Advanced.QueueDeclare(\"queue.text\", deadLetterExchange: deadExchange.Name);\n bus.Advanced.Bind(deadExchange, queue, \"\");\n bus.Advanced.Bind(textExchange, queue, \"\");\n\n bus.Advanced.Consume<TextMessage>(queue, (message, info) => HandleTextMessage(message, info));\n}\n```\n\n```text\nstatic void HandleTextMessage(IMessage<TextMessage> textMessage, MessageReceivedInfo info)\n{\n throw new Exception(\"This is a test!\");\n}\n```\n\n```text\nAdvancedBus\n```\n\n```text\nack\n```\n\n```text\nnack\n```\n\n```text\nreject\n```\n\n========================================\n\nComments:\n- Seems I have to fallback on RabbitMQ.Client if I want this functionality\n- Looking on implementation your DeadLetterStrategy there is no delay between resubmitting message to queue. I'd like to have some running delay between next resubmit like 2*t seconds delay (common strategy that delays time by multiplying by some factor like 2). Can this be done without Thread.Sleep?","metadata":{"transformedAt":"2026-08-18T18:33:20.180Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":13,"totalLines":158,"estimatedTokens":1147}}642{"id":"stack-21942063","source":"stackoverflow","questionId":21942063,"title":"How to delay? - php-amqplib","tags":["php","rabbitmq","amqp","php-amqp"],"text":"Title: How to delay? - php-amqplib\nTags: php, rabbitmq, amqp, php-amqp\nSource: Stack Overflow\n\nQuestion:\nI would like to know how to delay with Amqpphplib.\n\nI used this great coffee script tutorial :\n\nhttps://github.com/jamescarr/rabbitmq-scheduled-delivery\n\nbut it doesn't seems to work with PHP-amqplib.\n\nThe message expires as I want, but it seems that \"x-dead-letter-exchange\" don't do the work. I used RabbitMQ management console and I see all queue creation and deletion in live. But my message do go to the immediate queue after expiring. I use RabbitMQ 3.2.3 version, PHP-amqplib 2.2.* version.\n\nHere is my code :\n\n**Connection class :** \n\n```\nclass Connection\n{\n/**\n * @var $ch\n */\npublic $ch;\n\n/**\n * @var $consumer_tag\n */\npublic $consumer_tag;\n\n/**\n * @var $exchange\n */\npublic $exchange;\n\n/**\n * @var $conn\n */\npublic $conn;\n\npublic function __construct($host, $port, $user, $password, $vhost)\n{\n\n $this->exchange = 'immediate';\n $this->queue = 'right.now.queue';\n $this->consumer_tag = 'consumer';\n\n $this->conn = new AMQPConnection($host, $port, $user, $password, $vhost);\n $this->ch = $this->conn->channel();\n\n $this->ch->exchange_declare($this->exchange, 'direct', false, true, false);\n\n $this->ch->queue_declare($this->queue, false, true, false, false, false);\n\n $this->ch->queue_bind($this->queue, $this->exchange);\n\n}\n\npublic function createDelayedQueue ($name, $delay_seconds) {\n $this->ch->queue_declare($name, false, false, false, true, true, array(\n \"x-dead-letter-exchange\" => array(\"S\", $this->exchange),\n \"x-message-ttl\" => array(\"I\", $delay_seconds*1000),\n \"x-expires\" => array(\"I\", $delay_seconds*1000+1000)\n ));\n}\n}\n```\n\n**Publish code**\n\n```\n$name = 'send.later.'.$ts;\n$amqp->createDelayedQueue($name, 2);\n$msg = new AMQPMessage($msg_body, array('content_type' => 'text/plain', 'delivery_mode' => 2));\n$amqp->ch->basic_publish($msg);\n```\n\n**Consumer code**\n\n```\n$amqp = $this->getContainer()->get('amqp_connexion');\n\n $amqp->ch->basic_consume($amqp->queue, $amqp->consumer_tag, false, false, false, false, function ($msg) {\n\n echo $msg->body;\n echo \"\\n--------\\n\";\n });\n\n $output->writeln('Listening '.$amqp->queue.'...');\n\n // Loop as long as the channel has callbacks registered\n while (count($amqp->ch->callbacks)) {\n $amqp->ch->wait();\n }\n```\n\n========================================\n\nTop Answer:\nIf you choose amqp interop based transport you won't need to dig into details at all. Only a few things to do:\n\nInstall `enqueue/amqp-lib` (btw you can use other transports based on amqp ext and a great bunny lib) transport and `enqueue/amqp-tools`.\n\n```\ncomposer require enqueue/amqp-lib enqueue/amqp-tools\n```\n\nCreate amqp context, add a delay strategy and send delayed messages:\n\n```\ncreateContext();\n$context->setDelayStrategy(new RabbitMqDlxDelayStrategy())\n\n$queue = $context->createQueue('foo');\n$context->declareQueue($queue);\n\n$message = $context->createMessage('Hello world!');\n\n$context->createProducer()\n ->setDeliveryDelay(5000) // 5 sec\n ->send($queue, $message)\n;\n```\n\nBy the way, this not this only strategy available. there is one based on RabbitMQ delay plugin. It could be used the same way.\n\n========================================\n\nCode:\n```text\nclass Connection\n{\n/**\n * @var $ch\n */\npublic $ch;\n\n/**\n * @var $consumer_tag\n */\npublic $consumer_tag;\n\n/**\n * @var $exchange\n */\npublic $exchange;\n\n/**\n * @var $conn\n */\npublic $conn;\n\npublic function __construct($host, $port, $user, $password, $vhost)\n{\n\n $this->exchange = 'immediate';\n $this->queue = 'right.now.queue';\n $this->consumer_tag = 'consumer';\n\n\n $this->conn = new AMQPConnection($host, $port, $user, $password, $vhost);\n $this->ch = $this->conn->channel();\n\n $this->ch->exchange_declare($this->exchange, 'direct', false, true, false);\n\n $this->ch->queue_declare($this->queue, false, true, false, false, false);\n\n $this->ch->queue_bind($this->queue, $this->exchange);\n\n\n}\n\npublic function createDelayedQueue ($name, $delay_seconds) {\n $this->ch->queue_declare($name, false, false, false, true, true, array(\n \"x-dead-letter-exchange\" => array(\"S\", $this->exchange),\n \"x-message-ttl\" => array(\"I\", $delay_seconds*1000),\n \"x-expires\" => array(\"I\", $delay_seconds*1000+1000)\n ));\n}\n}\n```\n\n```text\n$name = 'send.later.'.$ts;\n$amqp->createDelayedQueue($name, 2);\n$msg = new AMQPMessage($msg_body, array('content_type' => 'text/plain', 'delivery_mode' => 2));\n$amqp->ch->basic_publish($msg);\n```\n\n```text\n$amqp = $this->getContainer()->get('amqp_connexion');\n\n $amqp->ch->basic_consume($amqp->queue, $amqp->consumer_tag, false, false, false, false, function ($msg) {\n\n echo $msg->body;\n echo \"\\n--------\\n\";\n });\n\n $output->writeln('Listening '.$amqp->queue.'...');\n\n // Loop as long as the channel has callbacks registered\n while (count($amqp->ch->callbacks)) {\n $amqp->ch->wait();\n }\n```\n\n```text\n/////// simplified ///////\n\n// include the AMQPlib Classes || use an autoloader\n\n// queue/exchange names\n$queueRightNow = 'right.now.queue';\n$exchangeRightNow = 'right.now.exchange';\n$queueDelayed5sec = 'delayed.five.seconds.queue';\n$exchangeDelayed5sec = 'delayed.five.seconds.exchange';\n\n$delay = 5; // delay in seconds\n\n// create connection\n$AMQPConnection = new \\PhpAmqpLib\\Connection\\AMQPConnection('localhost',5672,'guest','guest');\n\n// create a channel\n$channel = $AMQPConnection->channel();\n\n// create the right.now.queue, the exchange for that queue and bind them together\n$channel->queue_declare($queueRightNow);\n$channel->exchange_declare($exchangeRightNow, 'direct');\n$channel->queue_bind($queueRightNow, $exchangeRightNow);\n\n// now create the delayed queue and the exchange\n$channel->queue_declare(\n $queueDelayed5sec,\n false,\n false,\n false,\n true,\n true,\n array(\n 'x-message-ttl' => array('I', $delay*1000), // delay in seconds to milliseconds\n \"x-expires\" => array(\"I\", $delay*1000+1000),\n 'x-dead-letter-exchange' => array('S', $exchangeRightNow) // after message expiration in delay queue, move message to the right.now.queue\n )\n);\n$channel->exchange_declare($exchangeDelayed5sec, 'direct');\n$channel->queue_bind($queueDelayed5sec, $exchangeDelayed5sec);\n\n// now create a message und publish it to the delayed exchange\n$msg = new \\PhpAmqpLib\\Message\\AMQPMessage(\n time(),\n array(\n 'delivery_mode' => 2\n )\n);\n$channel->basic_publish($msg,$exchangeDelayed5sec);\n\n\n// consume the delayed message\n$consumeCallback = function(\\PhpAmqpLib\\Message\\AMQPMessage $msg) {\n $messagePublishedAt = $msg->body;\n echo 'seconds between publishing and consuming: '\n . (time()-$messagePublishedAt) . PHP_EOL;\n};\n$channel->basic_consume($queueRightNow, '', false, true, false, false, $consumeCallback);\n\n// start consuming\nwhile (count($channel->callbacks) > 0) {\n $channel->wait();\n}\n```\n\n```text\ncomposer require enqueue/amqp-lib enqueue/amqp-tools\n```\n\n```text\n<?php\nuse Enqueue\\AmqpTools\\RabbitMqDlxDelayStrategy;\nuse Enqueue\\AmqpBunny\\AmqpConnectionFactory;\n\n$context = (new AmqpConnectionFactory('amqp://'))->createContext();\n$context->setDelayStrategy(new RabbitMqDlxDelayStrategy())\n\n$queue = $context->createQueue('foo');\n$context->declareQueue($queue);\n\n$message = $context->createMessage('Hello world!');\n\n$context->createProducer()\n ->setDeliveryDelay(5000) // 5 sec\n ->send($queue, $message)\n;\n```\n\n```text\nenqueue/amqp-lib\n```\n\n```text\nenqueue/amqp-tools\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.180Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":303,"estimatedTokens":1875}}643{"id":"stack-5273686","source":"stackoverflow","questionId":5273686,"title":"Run pika ioloop in background or use custom ioloop","tags":["python","multithreading","rabbitmq","amqp"],"text":"Title: Run pika ioloop in background or use custom ioloop\nTags: python, multithreading, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI have a feeling that this should really not be all that difficult, yet I have had little success so far.\n\nSay I have a class called PikaClass that wraps pika and provides some business methods.\n\n```\ndef PikaClass(object):\n def __init__(self):\n # connect to the broker\n self.connection = pika.SelectConnection(, self.on_connect)\n # ..other init stuff..\n\n def on_connect(self, connection):\n # called when the connection has been established \n # ..open a channel, declare some queues, etc.\n\n def start(self):\n # start the polling loop \n self.connection.ioloop.start()\n\n def foo(self, **kwargs):\n # do some business logic, e.g., send messages to particular queues\n```\n\nIntuitively, this is what I would like to achieve: a user creates an instance of `PikaClass`, sets the loop going in the background, and then interacts with the object by calling certain business methods\n\n```\np = PikaClass()\np.start()\nbar = p.foo(..)\n```\n\nThe problem is that p.start() blocks and prevents the main code from interacting with the object once start() has been called. My first thought was to wrap the call in a thread:\n\n```\nThread(target=p.start()).start()\nbar = p.foo(..)\n```\n\nBut that still blocks and you never get to p.foo(..). The docs mention that you shouldn't a connection between threads so that may cause a problem somewhere.\n\nI have also tried using AsyncoreConnection instead of SelectConnection, and calling _connect() directly (instead of using the ioloop) but that does not have any effect (nothing happens).\n\nSo how can I run the ioloop in the background, or at least run my own ioloop?\n\nNote: This is Python 2.6 on win64 (xp) with the latest pika 0.9.4\n\n========================================\n\nTop Answer:\nYou are calling 'p.start' instead of passing it as a parameter. The code should be:\n\n```\nThread(target=p.start).start()\n```\n\nThread will call p.start when Thread.start is executed.\n\nI'm not sure if this will solve your problem, but it may help you reach the solution.\n\n========================================\n\nCode:\n```text\ndef PikaClass(object):\n def __init__(self):\n # connect to the broker\n self.connection = pika.SelectConnection(<connection parameters>, self.on_connect)\n # ..other init stuff..\n\n def on_connect(self, connection):\n # called when the connection has been established \n # ..open a channel, declare some queues, etc.\n\n def start(self):\n # start the polling loop \n self.connection.ioloop.start()\n\n def foo(self, **kwargs):\n # do some business logic, e.g., send messages to particular queues\n```\n\n```text\np = PikaClass()\np.start()\nbar = p.foo(..)\n```\n\n```text\nThread(target=p.start()).start()\nbar = p.foo(..)\n```\n\n```text\nPikaClass\n```\n\n```text\nconnection.ioloop.poller.open = False\n```\n\n```text\nioloop\n```\n\n```text\nstart()\n```\n\n```text\nioloop\n```\n\n```text\nioloop\n```\n\n```text\nioloop\n```\n\n```text\nTrue\n```\n\n```text\nstart()\n```\n\n```text\nif __name__ == \"__main__\":\n```\n\n```text\nThread(target=p.start).start()\n```\n\n========================================\n\nComments:\n- thanks, the GIL seems to be the culprit indeed. However, I would like to avoid processes since its another protocol/indirection to worry about (as well as the issues you mentioned). Another workaround is simply to run under Jython (no GIL) and that works without having to modify my code. So will probably stick with that. Would still be good to know how to bypass pika's ioloop though...\n- jython's good as long as you're not too attached to any C based librabries. Multithreading isn't too bad actually, as you'll have the same problems with threading in jython, and at least you have to explicitly state, helping avoid some race conditions etc.","metadata":{"transformedAt":"2026-08-18T18:33:20.180Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":14,"totalLines":146,"estimatedTokens":953}}644{"id":"stack-42215050","source":"stackoverflow","questionId":42215050,"title":"Spring-boot-starter RabbitMQ global error handling","tags":["spring-boot","rabbitmq","rabbitmq-exchange","spring-rabbit"],"text":"Title: Spring-boot-starter RabbitMQ global error handling\nTags: spring-boot, rabbitmq, rabbitmq-exchange, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI am using spring-boot-starter-amqp 1.4.2.Producer and consumer working fine but sometimes the incoming JSON messages have an incorrect syntax. This results in the following (correct) exception:\n\n```\norg.springframework.amqp.rabbit.listener.ListenerExecutionFailedException: Listener threw exception\nCaused by: org.springframework.amqp.support.converter.MessageConversionException: Failed to convert Message content\nCaused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_ARRAY token...\n```\n\nIn future i may face lot more exceptions. So i want to configure a global error handler so that if there is any exception in any one the consumer i can handle it globally.\n\nNote : In this case message is not at all reached consumer. I want to handle these kind of exceptions globally across the consumer.\n\nPlease find the below code :\n\n**RabbitConfiguration.java**\n\n```\n@Configuration\n@EnableRabbit\npublic class RabbitMqConfiguration {\n\n @Autowired\n private CachingConnectionFactory cachingConnectionFactory;\n\n @Bean\n public MessageConverter jsonMessageConverter()\n {\n return new Jackson2JsonMessageConverter();\n }\n\n @Bean\n @Primary\n public RabbitTemplate rabbitTemplate()\n {\n RabbitTemplate template = new RabbitTemplate(cachingConnectionFactory);\n template.setMessageConverter(jsonMessageConverter());\n return template;\n }\n\n}\n```\n\n**Consumer**\n\n```\n@RabbitListener(\n id = \"book_queue\",\n bindings = @QueueBinding(\n value = @Queue(value = \"book.queue\", durable = \"true\"),\n exchange = @Exchange(value = \"book.exchange\", durable = \"true\", delayed = \"true\"),\n key = \"book.queue\"\n )\n )\npublic void handle(Message message) {\n//Business Logic\n}\n```\n\nCould anyone please assist me to handle the error handler globally.Your help should be appreciable.\n\n**Updated question as per Gary comment**\n\nI can able to run your example and getting the expected output as you said, I just want to try few more negative cases based on your example, but i couldn't understand few things,\n\n```\nthis.template.convertAndSend(queue().getName(), new Foo(\"bar\"));\n```\n\n**output**\n\nReceived: Foo [foo=bar]\n\nThe above code is working fine.Now instead of \"Foo\" i am sending some other bean\n\n```\nthis.template.convertAndSend(queue().getName(), new Differ(\"snack\",\"Hihi\",\"how are you\"));\n```\n\n**output**\n\nReceived: Foo [foo=null]\n\nThe consumer shouldn't accept this message because it is completely a different bean(Differ.class not Foo.class) so i am expecting it should go to \"ConditionalRejectingErrorHandler\".Why it is accepting wrong payload and printing as null ? Please correct me if i am wrong.\n\n**Edit 1 :**\n\nGary, As you said i have set the header \"**TypeId**\" while sending the message but still consumer can able to convert wrong messages and it is not throwing any error...please find the code below, I have used your code samples and just did the following modifications, \n\n**1) Added \"__TypeId__\" while sending the message,**\n\n```\nthis.template.convertAndSend(queue().getName(), new Differ(\"snack\",\"hihi\",\"how are you\"),m -> {\n m.getMessageProperties().setHeader(\"__TypeId__\",\"foo\");\n return m;\n });\n```\n\n**2) Added \"DefaultClassMapper\" in the \"Jackson2JsonMessageConverter\"**\n\n```\n@Bean\npublic MessageConverter jsonConverter() {\n Jackson2JsonMessageConverter converter = new Jackson2JsonMessageConverter();\n DefaultClassMapper mapper = new DefaultClassMapper();\n mapper.setDefaultType(Foo.class);\n converter.setClassMapper(mapper);\n return new Jackson2JsonMessageConverter();\n}\n```\n\n========================================\n\nCode:\n```text\norg.springframework.amqp.rabbit.listener.ListenerExecutionFailedException: Listener threw exception\nCaused by: org.springframework.amqp.support.converter.MessageConversionException: Failed to convert Message content\nCaused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_ARRAY token...\n```\n\n```text\n@Configuration\n@EnableRabbit\npublic class RabbitMqConfiguration {\n\n @Autowired\n private CachingConnectionFactory cachingConnectionFactory;\n\n @Bean\n public MessageConverter jsonMessageConverter()\n {\n return new Jackson2JsonMessageConverter();\n }\n\n @Bean\n @Primary\n public RabbitTemplate rabbitTemplate()\n {\n RabbitTemplate template = new RabbitTemplate(cachingConnectionFactory);\n template.setMessageConverter(jsonMessageConverter());\n return template;\n }\n\n}\n```\n\n```text\n@RabbitListener(\n id = \"book_queue\",\n bindings = @QueueBinding(\n value = @Queue(value = \"book.queue\", durable = \"true\"),\n exchange = @Exchange(value = \"book.exchange\", durable = \"true\", delayed = \"true\"),\n key = \"book.queue\"\n )\n )\npublic void handle(Message message) {\n//Business Logic\n}\n```\n\n```text\nthis.template.convertAndSend(queue().getName(), new Foo(\"bar\"));\n```\n\n```text\nthis.template.convertAndSend(queue().getName(), new Differ(\"snack\",\"Hihi\",\"how are you\"));\n```\n\n```text\nthis.template.convertAndSend(queue().getName(), new Differ(\"snack\",\"hihi\",\"how are you\"),m -> {\n m.getMessageProperties().setHeader(\"__TypeId__\",\"foo\");\n return m;\n });\n```\n\n```text\n@Bean\npublic MessageConverter jsonConverter() {\n Jackson2JsonMessageConverter converter = new Jackson2JsonMessageConverter();\n DefaultClassMapper mapper = new DefaultClassMapper();\n mapper.setDefaultType(Foo.class);\n converter.setClassMapper(mapper);\n return new Jackson2JsonMessageConverter();\n}\n```\n\n```text\n@Bean\npublic SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory() {\n SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();\n factory.setConnectionFactory(connectionFactory);\n factory.setErrorHandler(myErrorHandler());\n ...\n return factory;\n}\n```\n\n```text\nvoid handleError(Throwable t);\n```\n\n```text\npackage com.example;\n\nimport org.slf4j.Logger;\n\nimport org.springframework.amqp.core.Message;\nimport org.springframework.amqp.core.Queue;\nimport org.springframework.amqp.rabbit.annotation.RabbitListener;\nimport org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;\nimport org.springframework.amqp.rabbit.connection.ConnectionFactory;\nimport org.springframework.amqp.rabbit.core.RabbitTemplate;\nimport org.springframework.amqp.rabbit.listener.ConditionalRejectingErrorHandler;\nimport org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException;\nimport org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;\nimport org.springframework.amqp.support.converter.MessageConverter;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\nimport org.springframework.context.ConfigurableApplicationContext;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.util.ErrorHandler;\n\n@SpringBootApplication\npublic class So42215050Application {\n\n public static void main(String[] args) throws Exception {\n ConfigurableApplicationContext context = SpringApplication.run(So42215050Application.class, args);\n context.getBean(So42215050Application.class).runDemo();\n context.close();\n }\n\n @Autowired\n private RabbitTemplate template;\n\n private void runDemo() throws Exception {\n this.template.convertAndSend(queue().getName(), new Foo(\"bar\"));\n this.template.convertAndSend(queue().getName(), new Foo(\"bar\"), m -> {\n return new Message(\"some bad json\".getBytes(), m.getMessageProperties());\n });\n Thread.sleep(5000);\n }\n\n @RabbitListener(queues = \"So42215050\")\n public void handle(Foo in) {\n System.out.println(\"Received: \" + in);\n }\n\n @Bean\n public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {\n SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();\n factory.setConnectionFactory(connectionFactory);\n factory.setMessageConverter(jsonConverter());\n factory.setErrorHandler(errorHandler());\n return factory;\n }\n\n @Bean\n public ErrorHandler errorHandler() {\n return new ConditionalRejectingErrorHandler(new MyFatalExceptionStrategy());\n }\n\n @Bean\n public Queue queue() {\n return new Queue(\"So42215050\", false, false, true);\n }\n\n @Bean\n public MessageConverter jsonConverter() {\n return new Jackson2JsonMessageConverter();\n }\n\n public static class MyFatalExceptionStrategy extends ConditionalRejectingErrorHandler.DefaultExceptionStrategy {\n\n private final Logger logger = org.slf4j.LoggerFactory.getLogger(getClass());\n\n @Override\n public boolean isFatal(Throwable t) {\n if (t instanceof ListenerExecutionFailedException) {\n ListenerExecutionFailedException lefe = (ListenerExecutionFailedException) t;\n logger.error(\"Failed to process inbound message from queue \"\n + lefe.getFailedMessage().getMessageProperties().getConsumerQueue()\n + \"; failed message: \" + lefe.getFailedMessage(), t);\n }\n return super.isFatal(t);\n }\n\n }\n\n public static class Foo {\n\n private String foo;\n\n public Foo() {\n super();\n }\n\n public Foo(String foo) {\n this.foo = foo;\n }\n\n public String getFoo() {\n return this.foo;\n }\n\n public void setFoo(String foo) {\n this.foo = foo;\n }\n\n @Override\n public String toString() {\n return \"Foo [foo=\" + this.foo + \"]\";\n }\n\n }\n}\n```\n\n```text\nReceived: Foo [foo=bar]\n```\n\n```text\n@Bean\npublic MessageConverter jsonConverter() {\n Jackson2JsonMessageConverter converter = new Jackson2JsonMessageConverter();\n DefaultClassMapper mapper = new DefaultClassMapper();\n mapper.setDefaultType(Foo.class);\n converter.setClassMapper(mapper);\n return converter;\n}\n```\n\n```text\npublic static class Bar {\n\n ...\n\n}\n```\n\n```text\nthis.template.convertAndSend(queue().getName(), new Bar(\"baz\"));\n```\n\n```text\nCaused by: org.springframework.amqp.support.converter.MessageConversionException: Cannot handle message\n... 13 common frames omitted\nCaused by: org.springframework.messaging.converter.MessageConversionException: Cannot convert from [com.example.So42215050Application$Bar] to [com.example.So42215050Application$Foo] for GenericMessage [payload=Bar [foo=baz], headers={amqp_receivedDeliveryMode=PERSISTENT, amqp_receivedRoutingKey=So42215050, amqp_contentEncoding=UTF-8, amqp_deliveryTag=3, amqp_consumerQueue=So42215050, amqp_redelivered=false, id=6d7e23a3-c2a7-2417-49c9-69e3335aa485, amqp_consumerTag=amq.ctag-6JIGkpmkrTKaG32KVpf8HQ, contentType=application/json, __TypeId__=com.example.So42215050Application$Bar, timestamp=1488489538017}]\n```\n\n```text\n@SpringBootApplication\npublic class So42215050Application {\n\n private final Logger logger = org.slf4j.LoggerFactory.getLogger(getClass());\n\n public static void main(String[] args) throws Exception {\n ConfigurableApplicationContext context = SpringApplication.run(So42215050Application.class, args);\n context.getBean(So42215050Application.class).runDemo();\n context.close();\n }\n\n @Autowired\n private RabbitTemplate template;\n\n private void runDemo() throws Exception {\n this.template.convertAndSend(queue().getName(), new Foo(\"bar\")); // good - converter sets up type\n this.template.convertAndSend(queue().getName(), new Foo(\"bar\"), m -> {\n return new Message(\"some bad json\".getBytes(), m.getMessageProperties()); // fail bad json\n });\n Message message = MessageBuilder\n .withBody(\"{\\\"foo\\\":\\\"bar\\\"}\".getBytes())\n .andProperties(\n MessagePropertiesBuilder\n .newInstance()\n .setContentType(\"application/json\")\n .build())\n .build();\n this.template.send(queue().getName(), message); // Success - default Foo class when no header\n message.getMessageProperties().setHeader(\"__TypeId__\", \"foo\");\n this.template.send(queue().getName(), message); // Success - foo is mapped to Foo\n message.getMessageProperties().setHeader(\"__TypeId__\", \"bar\");\n this.template.send(queue().getName(), message); // fail - mapped to a Map\n Thread.sleep(5000);\n }\n\n @RabbitListener(queues = \"So42215050\")\n public void handle(Foo in) {\n logger.info(\"Received: \" + in);\n }\n\n @Bean\n public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {\n SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();\n factory.setConnectionFactory(connectionFactory);\n factory.setMessageConverter(jsonConverter());\n factory.setErrorHandler(errorHandler());\n return factory;\n }\n\n @Bean\n public ErrorHandler errorHandler() {\n return new ConditionalRejectingErrorHandler(new MyFatalExceptionStrategy());\n }\n\n @Bean\n public Queue queue() {\n return new Queue(\"So42215050\", false, false, true);\n }\n\n @Bean\n public MessageConverter jsonConverter() {\n Jackson2JsonMessageConverter converter = new Jackson2JsonMessageConverter();\n DefaultClassMapper mapper = new DefaultClassMapper();\n mapper.setDefaultType(Foo.class);\n Map<String, Class<?>> mappings = new HashMap<>();\n mappings.put(\"foo\", Foo.class);\n mappings.put(\"bar\", Object.class);\n mapper.setIdClassMapping(mappings);\n converter.setClassMapper(mapper);\n return converter;\n }\n\n public static class MyFatalExceptionStrategy extends ConditionalRejectingErrorHandler.DefaultExceptionStrategy {\n\n private final Logger logger = org.slf4j.LoggerFactory.getLogger(getClass());\n\n @Override\n public boolean isFatal(Throwable t) {\n if (t instanceof ListenerExecutionFailedException) {\n ListenerExecutionFailedException lefe = (ListenerExecutionFailedException) t;\n logger.error(\"Failed to process inbound message from queue \"\n + lefe.getFailedMessage().getMessageProperties().getConsumerQueue()\n + \"; failed message: \" + lefe.getFailedMessage(), t);\n }\n return super.isFatal(t);\n }\n\n }\n\n public static class Foo {\n\n private String foo;\n\n public Foo() {\n super();\n }\n\n public Foo(String foo) {\n this.foo = foo;\n }\n\n public String getFoo() {\n return this.foo;\n }\n\n public void setFoo(String foo) {\n this.foo = foo;\n }\n\n @Override\n public String toString() {\n return \"Foo [foo=\" + this.foo + \"]\";\n }\n\n }\n\n public static class Bar {\n\n private String foo;\n\n public Bar() {\n super();\n }\n\n public Bar(String foo) {\n this.foo = foo;\n }\n\n public String getFoo() {\n return this.foo;\n }\n\n public void setFoo(String foo) {\n this.foo = foo;\n }\n\n @Override\n public String toString() {\n return \"Bar [foo=\" + this.foo + \"]\";\n }\n\n }\n\n}\n```\n\n```text\nErrorHandler\n```\n\n```text\nListenerExecutionFailedException\n```\n\n```text\nfailedMessage\n```\n\n```text\nMessageConversionException\n```\n\n```text\nAmqpRejectAndDontRequeueException\n```\n\n```text\nRabbitTemplate\n```\n\n```text\nMessageConverter\n```\n\n```text\nConditionalRejectingErrorHandler\n```\n\n```text\nFatalExceptionStrategy\n```\n\n```text\nDefaultExceptionStrategy\n```\n\n```text\nisFatal(Throwable t)\n```\n\n```text\nsuper.isFatal(t)\n```\n\n```text\nBar\n```\n\n```text\nFoo\n```\n\n```text\n__TypeId__\n```\n\n========================================\n\nComments:\n- Thanks a lot for your response.Need few more clarification which i don't understand from your answer.1) To implement global error handler we should have a bean \"SimpleRabbitListenerContainerFactory\"?(No other way) 2) I can see \"ErrorHandler\" as a method.Is it possible to define a bean as a \"ErrorHandler\"? Could you please the code sample for effective way of writing ErrorHandler?at least a hint or link. 3) You have mentioned, Having one \"MessageConverter\" is redundant and boot will auto-wire it to containers. For me spring-boot is not automatically doing that am i missing anything?\n- This now available in spring-amqp-samples as `spring-rabbit-global-errorhandler`.\n- Thanks a lot. Let me give a try once it is work I'll accept the answer immediately\n- Sorry for the very late reply...Your example is working fine but If i pass \"this.template.convertAndSend(queue().getName(), new Differ(\"snack\",\"hihi\",\"how are you\"));\", Rabbit is accepting this payload but it should reject because my consumer expects \"Foo\" but i am passing \"Differ\" which is different class and different properties, may i know why it is not coming to \"ConditionalRejectingErrorHandler\" ?\n- Don't put code in comments, it's unreadable - edit your question instead. It's not clear what you are asking; you can't get an error on the template.send because the sending side doesn't know what the consumer wants. If you mean you are not seeing it on the consumer side either, attach a DEBUG log for the delivery.\n- I have updated my question now it will be clear.I am not expecting the error from template.send but i am expecting it should go to ConditionalRejectingErrorHandler since it is wrong payload.\n- That's because the destination type is inferred from the method parameter. JSON doesn't implicitly convey type information. See my next edit for how to configure the converter to only convert to a specific type.\n- Thanks a lot for your answer. So we need to set the typeId information from sender also you are configuring in the converter which is global for all the consumers in a components suppose if my components contains multiple consumers and each consumer might consume different payloads that time this solution will not work. is there any way to configure to this type information in @RabbitListener annotation or while declaring the queue ?\n- WIth JSON, you have to tell the converter what to convert the json to. We try to help (e.g. by inferring the type from the method or by the sender sending type information in headers), but you can always configure your own converter. If you need multiple types, then each `@RabbitListener` has to be created by a different `SimpleRabbitListenerContainerFactory` bean (each of which can be configured to inject a different converter). You can specify which factory to use with the `containerFactory` attribute on `@RabbitListener`.\n- Alternatively, you can access the containers (by id) from the `RabbitListenerEndpointRegistry` bean; and change the converter in each container before starting them.\n- Again thanks a lot for your reply. Let me tweak more about this. Meanwhile with \"ConditionRejectingErrorHandler\" apart from invalid payload are we able to catch any other exception? Also could you please a link for configuring Dead letter exchange for ConditionRejectingErrorHandler\" ?\n- I have set the \"**TypeId**\" header while sending the message and configured DefaultClassMapper in the receiving side, but still my consumers consumes the wrong payload. Am i setting the \"**TypeId**\" properly ? Please guide me to resolve this issue\n- When I set it to some bogus class name, I get `Caused by: java.lang.ClassNotFoundException: foo`. If I add `mapper.setIdClassMapping(Collections.singletonMap(\"foo\", Object.class));` to the class mapper, I get `Caused by: org.springframework.messaging.converter.MessageConversionExc‌​eption: Cannot convert from [java.util.LinkedHashMap] to [com.example.So42215050Application$Foo] for GenericMessage [payload={foo=baz},...`\n- @Gary...do we need to set \"**TypeId**\" header in sender ? also do we need to set \"DefaultType\" property in DefaultClassMapper ?\n- @Gary..unfortunately It's not working for me..I set \"idClassMapping\", but still my consumer receives the message and print it as null\n- All I can do is repost my sample that shows it working as I describe. See **EDIT4**.\n- @Gary...Sorry it's my mistake instead of returning modified Jackson2JsonMessageConverter i have returned new instance of Jackson2JsonMessageConverter that's why it is not throwing any exception now it is working flawlessly.\n- @GaryRussell In **Edit 2** - Why are you create bean factory ?\n- Spring Boot creates it in `ConfigurableApplicationContext context = SpringApplication.run(So42215050Application.class, args);`\n- `public static class MyFatalExceptionStrategy extends ConditionalRejectingErrorHandler.DefaultExceptionStrategy {`, its giving a compilation error, since `DefaultExceptionStrategy` is a private inner class. How to solve the same?\n- how can I hide the exception which used for message requeued! stackoverflow.com/questions/50350377/…","metadata":{"transformedAt":"2026-08-18T18:33:20.180Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":31,"totalLines":586,"estimatedTokens":5366}}645{"id":"stack-64311784","source":"stackoverflow","questionId":64311784,"title":"RabbitMQ dead letter exchange - route by \"x-death.reason\" or \"x-first-death-reason\" header","tags":["rabbitmq","rabbitmq-exchange"],"text":"Title: RabbitMQ dead letter exchange - route by \"x-death.reason\" or \"x-first-death-reason\" header\nTags: rabbitmq, rabbitmq-exchange\nSource: Stack Overflow\n\nQuestion:\nI am trying to set up RabbitMQ to route messages through a Dead Letter Exchange based on the death reason (either \"x-death.reason\" or \"x-first-death-reason\" would do).\n\nMy understanding is that when a message dies that \"x-death.reason\" and \"x-first-death-reason\" are set as headers when the messages is sent to the DLX. So my reasoning is that I should be able to set up an exchange with `type=headers` to be able to route by the value of these headers.\n\nUnfortunately, I just can't get it to work.\n\nThe DLX is set up like\n\nhttps://i.sstatic.net/AsiQl.png\n\nHowever each dead message gets routed to **all** of the bound queues.\n\nhttps://i.sstatic.net/Sfjr7.png\n\ni.e. the filtering/routing is not working.\n\nCan someone please let me know how to configure this correctly.\n\nThanks\n\n========================================\n\nTop Answer:\nFrom same documentation as @abaelter wrote about exchange-headers, but updated:\n\nFor `any` and `all`, headers beginning with the string `x-` will not be\nused to evaluate matches. Setting `x-match` to `any-with-x` or\n`all-with-x` will also use headers beginning with the string `x-` to\nevaluate matches.\n\nNow you can use `x-match` with value `any-with-x` and headers with `x-` shoud start works.\n\nSomething like this:\n\nhttps://i.sstatic.net/SLrob.png\n\n========================================\n\nCode:\n```text\ntype=headers\n```\n\n```text\nany\n```\n\n```text\nall\n```\n\n```text\nx-\n```\n\n```text\nx-match\n```\n\n```text\nany-with-x\n```\n\n```text\nall-with-x\n```\n\n```text\nx-\n```\n\n```text\nx-match\n```\n\n```text\nany-with-x\n```\n\n```text\nx-\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.180Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":11,"totalLines":87,"estimatedTokens":430}}646{"id":"stack-37307437","source":"stackoverflow","questionId":37307437,"title":"RabbitMQ Manual ACK on c# client","tags":["c#","rabbitmq"],"text":"Title: RabbitMQ Manual ACK on c# client\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm trying to use a manual ACK on a very simple console application, but I can't make it work.\n\nOn the sender, I have the following code:\n\n```\nvar factory = new ConnectionFactory() { HostName = \"localhost\" };\nusing (var connection = factory.CreateConnection())\nusing (var channel = connection.CreateModel())\n{\n channel.QueueDeclare(queue: \"task_queue\",\n durable: true,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n\n var message = GetMessage(args);\n var body = Encoding.UTF8.GetBytes(message);\n\n channel.ConfirmSelect();\n channel.BasicAcks += (sender, e) =>\n {\n Console.Write(\"ACK received\");\n };\n\n var properties = channel.CreateBasicProperties();\n\n channel.BasicPublish(exchange: \"\",\n routingKey: \"task_queue\",\n basicProperties: properties,\n body: body);\n\n Console.WriteLine(\" [x] Sent {0}\", message);\n}\n\nConsole.WriteLine(\" Press [enter] to exit.\");\nConsole.ReadLine();\n```\n\nOn the receiver I have the following code:\n\n```\nvar factory = new ConnectionFactory() { HostName = \"localhost\" };\nusing (var connection = factory.CreateConnection())\nusing (var channel = connection.CreateModel())\n{\n channel.QueueDeclare(queue: \"task_queue\",\n durable: true,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n\n channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false);\n channel.ConfirmSelect();\n\n Console.WriteLine(\" [*] Waiting for messages.\");\n\n var consumer = new EventingBasicConsumer(channel);\n consumer.Received += (model, ea) =>\n {\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n Console.WriteLine(\" [x] Received {0}\", message);\n\n int dots = message.Split('.').Length - 1;\n Thread.Sleep(dots * 1000);\n\n channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);\n Console.WriteLine(\" [x] Done\");\n };\n channel.BasicConsume(queue: \"task_queue\",\n noAck: false,\n consumer: consumer);\n\n Console.WriteLine(\" Press [enter] to exit.\");\n Console.ReadLine();\n}\n```\n\nWhat I expect is that the event `BasicAcks` on the sender is fired when I call `channel.BasicAck()` on the receiver, but that event is being fired when the message is delivered to the client, before `consumer.Received`.\n\nIs what I'm expecting the correct behavior or am I missing something?\n\n========================================\n\nTop Answer:\nConsumer:\n\n```\nconsumer.Received += async (model, ea) =>\n{\n var body = ea.Body.ToArray();\n var message = Encoding.UTF8.GetString(body);\n Console.WriteLine(\" [x] Received {0}\", message);\n\n int dots = message.Split('.').Length - 1;\n await Task.Delay(2000);\n\n channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);\n Console.WriteLine(\" [x] Done\");\n};\n```\n\n========================================\n\nCode:\n```text\nvar factory = new ConnectionFactory() { HostName = \"localhost\" };\nusing (var connection = factory.CreateConnection())\nusing (var channel = connection.CreateModel())\n{\n channel.QueueDeclare(queue: \"task_queue\",\n durable: true,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n\n var message = GetMessage(args);\n var body = Encoding.UTF8.GetBytes(message);\n\n channel.ConfirmSelect();\n channel.BasicAcks += (sender, e) =>\n {\n Console.Write(\"ACK received\");\n };\n\n var properties = channel.CreateBasicProperties();\n\n channel.BasicPublish(exchange: \"\",\n routingKey: \"task_queue\",\n basicProperties: properties,\n body: body);\n\n Console.WriteLine(\" [x] Sent {0}\", message);\n}\n\nConsole.WriteLine(\" Press [enter] to exit.\");\nConsole.ReadLine();\n```\n\n```text\nvar factory = new ConnectionFactory() { HostName = \"localhost\" };\nusing (var connection = factory.CreateConnection())\nusing (var channel = connection.CreateModel())\n{\n channel.QueueDeclare(queue: \"task_queue\",\n durable: true,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n\n channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false);\n channel.ConfirmSelect();\n\n Console.WriteLine(\" [*] Waiting for messages.\");\n\n var consumer = new EventingBasicConsumer(channel);\n consumer.Received += (model, ea) =>\n {\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n Console.WriteLine(\" [x] Received {0}\", message);\n\n int dots = message.Split('.').Length - 1;\n Thread.Sleep(dots * 1000);\n\n channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);\n Console.WriteLine(\" [x] Done\");\n };\n channel.BasicConsume(queue: \"task_queue\",\n noAck: false,\n consumer: consumer);\n\n Console.WriteLine(\" Press [enter] to exit.\");\n Console.ReadLine();\n}\n```\n\n```text\nBasicAcks\n```\n\n```text\nchannel.BasicAck()\n```\n\n```text\nconsumer.Received\n```\n\n```text\nBasicAcks\n```\n\n```text\nconsumer.Received += async (model, ea) =>\n{\n var body = ea.Body.ToArray();\n var message = Encoding.UTF8.GetString(body);\n Console.WriteLine(\" [x] Received {0}\", message);\n\n int dots = message.Split('.').Length - 1;\n await Task.Delay(2000);\n\n channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);\n Console.WriteLine(\" [x] Done\");\n};\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.180Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":212,"estimatedTokens":1352}}647{"id":"stack-29055529","source":"stackoverflow","questionId":29055529,"title":"\"Channel shutdown: connection error\"","tags":["amazon-ec2","rabbitmq","load-balancing","spring-amqp"],"text":"Title: \"Channel shutdown: connection error\"\nTags: amazon-ec2, rabbitmq, load-balancing, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI've set up on AWS a RabbitMQ cluster with two nodes, and enabled HA as described here. Then, I set up an Elastic Load Balancer mapping `5672` to the instances' `5672` port, with a periodic health check to the instances' `15672` port (the HTTP management port). Then, I started two listeners (one in each node), each one with 4 consumers, and pointed `spring.rabbitmq.host` at the load balancer's DNS. However, I'm periodically getting the following errors:\n\n```\n[E] [2015-03-14 23:13:23,890] [pool-4-thread-9 ] [CachingConnectionFactory ] [ ] Channel shutdown: connection error\n[E] [2015-03-14 23:13:23,891] [pool-4-thread-9 ] [CachingConnectionFactory ] [ ] Channel shutdown: connection error\n[E] [2015-03-14 23:13:23,891] [pool-4-thread-9 ] [CachingConnectionFactory ] [ ] Channel shutdown: connection error\n[E] [2015-03-14 23:13:23,891] [pool-4-thread-9 ] [CachingConnectionFactory ] [ ] Channel shutdown: connection error\n[W] [2015-03-14 23:13:24,758] [impleAsyncTaskExecutor-5] [SimpleMessageListenerContainer ] [ ] Consumer raised exception, processing can restart if the connection factory supports it\ncom.rabbitmq.client.ShutdownSignalException: connection error\n at com.rabbitmq.client.impl.AMQConnection.startShutdown(AMQConnection.java:717) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection.shutdown(AMQConnection.java:707) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:565) ~[amqp-client-3.4.2.jar!/:?]\n at java.lang.Thread.run(Thread.java:745) [?:1.8.0_40]\nCaused by: java.io.EOFException\n at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:290) ~[?:1.8.0_40]\n at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:95) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:139) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:534) ~[amqp-client-3.4.2.jar!/:?]\n ... 1 more\n[I] [2015-03-14 23:13:24,761] [impleAsyncTaskExecutor-5] [SimpleMessageListenerContainer ] [ ] Restarting Consumer: tags=[[amq.ctag-H-1ed6xO3GL7qW58bkLUZA]], channel=Cached Rabbit Channel: AMQChannel(amqp://qube@10.100.43.76:5672qube,1), acknowledgeMode=AUTO local queue size=0\n[W] [2015-03-14 23:13:24,762] [impleAsyncTaskExecutor-8] [SimpleMessageListenerContainer ] [ ] Consumer raised exception, processing can restart if the connection factory supports it\ncom.rabbitmq.client.ShutdownSignalException: connection error\n at com.rabbitmq.client.impl.AMQConnection.startShutdown(AMQConnection.java:717) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection.shutdown(AMQConnection.java:707) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:565) ~[amqp-client-3.4.2.jar!/:?]\n at java.lang.Thread.run(Thread.java:745) [?:1.8.0_40]\nCaused by: java.io.EOFException\n at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:290) ~[?:1.8.0_40]\n at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:95) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:139) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:534) ~[amqp-client-3.4.2.jar!/:?]\n ... 1 more\n[I] [2015-03-14 23:13:24,762] [impleAsyncTaskExecutor-8] [SimpleMessageListenerContainer ] [ ] Restarting Consumer: tags=[[amq.ctag-nJAmieDx-kSuxl9arsXiww]], channel=Cached Rabbit Channel: AMQChannel(amqp://qube@10.100.43.76:5672qube,2), acknowledgeMode=AUTO local queue size=0\n[W] [2015-03-14 23:13:24,767] [impleAsyncTaskExecutor-7] [SimpleMessageListenerContainer ] [ ] Consumer raised exception, processing can restart if the connection factory supports it\ncom.rabbitmq.client.ShutdownSignalException: connection error\n at com.rabbitmq.client.impl.AMQConnection.startShutdown(AMQConnection.java:717) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection.shutdown(AMQConnection.java:707) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:565) ~[amqp-client-3.4.2.jar!/:?]\n at java.lang.Thread.run(Thread.java:745) [?:1.8.0_40]\nCaused by: java.io.EOFException\n at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:290) ~[?:1.8.0_40]\n at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:95) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:139) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:534) ~[amqp-client-3.4.2.jar!/:?]\n ... 1 more\n[I] [2015-03-14 23:13:24,768] [impleAsyncTaskExecutor-7] [SimpleMessageListenerContainer ] [ ] Restarting Consumer: tags=[[amq.ctag-PAQvN8P57_9oiElyqYRJWw]], channel=Cached Rabbit Channel: AMQChannel(amqp://qube@10.100.43.76:5672qube,3), acknowledgeMode=AUTO local queue size=0\n[W] [2015-03-14 23:13:24,768] [impleAsyncTaskExecutor-6] [SimpleMessageListenerContainer ] [ ] Consumer raised exception, processing can restart if the connection factory supports it\ncom.rabbitmq.client.ShutdownSignalException: connection error\n at com.rabbitmq.client.impl.AMQConnection.startShutdown(AMQConnection.java:717) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection.shutdown(AMQConnection.java:707) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:565) ~[amqp-client-3.4.2.jar!/:?]\n at java.lang.Thread.run(Thread.java:745) [?:1.8.0_40]\nCaused by: java.io.EOFException\n at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:290) ~[?:1.8.0_40]\n at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:95) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:139) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:534) ~[amqp-client-3.4.2.jar!/:?]\n ... 1 more\n[I] [2015-03-14 23:13:24,769] [impleAsyncTaskExecutor-6] [SimpleMessageListenerContainer ] [ ] Restarting Consumer: tags=[[amq.ctag-w6apIlL78ViAnTOzx2Qejg]], channel=Cached Rabbit Channel: AMQChannel(amqp://qube@10.100.43.76:5672qube,4), acknowledgeMode=AUTO local queue size=0\n```\n\nThis does not happen if I point each consumer directly at one node (without using the load balancer). What can be causing this behaviout? How can I circumvent this?\n\n========================================\n\nCode:\n```text\n[E] [2015-03-14 23:13:23,890] [pool-4-thread-9 ] [CachingConnectionFactory ] [ ] Channel shutdown: connection error\n[E] [2015-03-14 23:13:23,891] [pool-4-thread-9 ] [CachingConnectionFactory ] [ ] Channel shutdown: connection error\n[E] [2015-03-14 23:13:23,891] [pool-4-thread-9 ] [CachingConnectionFactory ] [ ] Channel shutdown: connection error\n[E] [2015-03-14 23:13:23,891] [pool-4-thread-9 ] [CachingConnectionFactory ] [ ] Channel shutdown: connection error\n[W] [2015-03-14 23:13:24,758] [impleAsyncTaskExecutor-5] [SimpleMessageListenerContainer ] [ ] Consumer raised exception, processing can restart if the connection factory supports it\ncom.rabbitmq.client.ShutdownSignalException: connection error\n at com.rabbitmq.client.impl.AMQConnection.startShutdown(AMQConnection.java:717) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection.shutdown(AMQConnection.java:707) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:565) ~[amqp-client-3.4.2.jar!/:?]\n at java.lang.Thread.run(Thread.java:745) [?:1.8.0_40]\nCaused by: java.io.EOFException\n at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:290) ~[?:1.8.0_40]\n at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:95) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:139) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:534) ~[amqp-client-3.4.2.jar!/:?]\n ... 1 more\n[I] [2015-03-14 23:13:24,761] [impleAsyncTaskExecutor-5] [SimpleMessageListenerContainer ] [ ] Restarting Consumer: tags=[[amq.ctag-H-1ed6xO3GL7qW58bkLUZA]], channel=Cached Rabbit Channel: AMQChannel(amqp://qube@10.100.43.76:5672qube,1), acknowledgeMode=AUTO local queue size=0\n[W] [2015-03-14 23:13:24,762] [impleAsyncTaskExecutor-8] [SimpleMessageListenerContainer ] [ ] Consumer raised exception, processing can restart if the connection factory supports it\ncom.rabbitmq.client.ShutdownSignalException: connection error\n at com.rabbitmq.client.impl.AMQConnection.startShutdown(AMQConnection.java:717) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection.shutdown(AMQConnection.java:707) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:565) ~[amqp-client-3.4.2.jar!/:?]\n at java.lang.Thread.run(Thread.java:745) [?:1.8.0_40]\nCaused by: java.io.EOFException\n at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:290) ~[?:1.8.0_40]\n at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:95) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:139) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:534) ~[amqp-client-3.4.2.jar!/:?]\n ... 1 more\n[I] [2015-03-14 23:13:24,762] [impleAsyncTaskExecutor-8] [SimpleMessageListenerContainer ] [ ] Restarting Consumer: tags=[[amq.ctag-nJAmieDx-kSuxl9arsXiww]], channel=Cached Rabbit Channel: AMQChannel(amqp://qube@10.100.43.76:5672qube,2), acknowledgeMode=AUTO local queue size=0\n[W] [2015-03-14 23:13:24,767] [impleAsyncTaskExecutor-7] [SimpleMessageListenerContainer ] [ ] Consumer raised exception, processing can restart if the connection factory supports it\ncom.rabbitmq.client.ShutdownSignalException: connection error\n at com.rabbitmq.client.impl.AMQConnection.startShutdown(AMQConnection.java:717) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection.shutdown(AMQConnection.java:707) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:565) ~[amqp-client-3.4.2.jar!/:?]\n at java.lang.Thread.run(Thread.java:745) [?:1.8.0_40]\nCaused by: java.io.EOFException\n at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:290) ~[?:1.8.0_40]\n at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:95) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:139) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:534) ~[amqp-client-3.4.2.jar!/:?]\n ... 1 more\n[I] [2015-03-14 23:13:24,768] [impleAsyncTaskExecutor-7] [SimpleMessageListenerContainer ] [ ] Restarting Consumer: tags=[[amq.ctag-PAQvN8P57_9oiElyqYRJWw]], channel=Cached Rabbit Channel: AMQChannel(amqp://qube@10.100.43.76:5672qube,3), acknowledgeMode=AUTO local queue size=0\n[W] [2015-03-14 23:13:24,768] [impleAsyncTaskExecutor-6] [SimpleMessageListenerContainer ] [ ] Consumer raised exception, processing can restart if the connection factory supports it\ncom.rabbitmq.client.ShutdownSignalException: connection error\n at com.rabbitmq.client.impl.AMQConnection.startShutdown(AMQConnection.java:717) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection.shutdown(AMQConnection.java:707) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:565) ~[amqp-client-3.4.2.jar!/:?]\n at java.lang.Thread.run(Thread.java:745) [?:1.8.0_40]\nCaused by: java.io.EOFException\n at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:290) ~[?:1.8.0_40]\n at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:95) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:139) ~[amqp-client-3.4.2.jar!/:?]\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:534) ~[amqp-client-3.4.2.jar!/:?]\n ... 1 more\n[I] [2015-03-14 23:13:24,769] [impleAsyncTaskExecutor-6] [SimpleMessageListenerContainer ] [ ] Restarting Consumer: tags=[[amq.ctag-w6apIlL78ViAnTOzx2Qejg]], channel=Cached Rabbit Channel: AMQChannel(amqp://qube@10.100.43.76:5672qube,4), acknowledgeMode=AUTO local queue size=0\n```\n\n```text\n5672\n```\n\n```text\n5672\n```\n\n```text\n15672\n```\n\n```text\nspring.rabbitmq.host\n```\n\n```text\nrequestedHeartbeats\n```\n\n```text\nrabbitConnectionFactory\n```\n\n```text\naddresses\n```\n\n========================================\n\nComments:\n- Sounds like that was indeed the problem. Many thanks! I understand you point about load balancing, but it is more convenient for me to define instances externally (dynamically) instead of doing it on properties. Being that there is no benefit, is there anything that can go wrong by using a load balancer instead?\n- No. It won't hurt as long as you have the heartbeats set up ok.","metadata":{"transformedAt":"2026-08-18T18:33:20.181Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":163,"estimatedTokens":3430}}648{"id":"stack-73519896","source":"stackoverflow","questionId":73519896,"title":"RabbitMQ Docker Compose None of the specified endpoints were reachable","tags":["c#",".net","docker","docker-compose","rabbitmq"],"text":"Title: RabbitMQ Docker Compose None of the specified endpoints were reachable\nTags: c#, .net, docker, docker-compose, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI know this looks duplicated, but I checked all the others questions and none of them solved my problem.\n\n**So, this is my docker-compose yml file:**\n\n```\nversion: '3.8'\n\nservices:\n #db:\n # image: postgres\n\n messageBroker:\n image: rabbitmq:management\n hostname: \"messageBroker\"\n healthcheck:\n test: rabbitmq-diagnostics -q ping\n interval: 5s\n timeout: 15s\n retries: 3\n networks:\n - services-network\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n environment:\n RABBITMQ_DEFAULT_USER: \"admin\"\n RABBITMQ_DEFAULT_PASS: \"password\"\n\n serviceDiscovery:\n image: steeltoeoss/eureka-server\n hostname: eureka-server\n networks:\n - services-network\n ports:\n - \"8761:8761\"\n \n order-api:\n image: ${DOCKER_REGISTRY-}orderapi\n hostname: orderapi\n environment:\n - Eureka__Client__ServiceUrl=http://serviceDiscovery:8761/eureka/\n - Eureka__Client__ShouldRegisterWithEureka=true\n - Eureka__Client__ValidateCertificates=false\n networks:\n - services-network\n depends_on:\n - serviceDiscovery\n build:\n context: .\n dockerfile: Services/Order/Dockerfile\n links:\n - \"serviceDiscovery\"\n\n product-api:\n image: ${DOCKER_REGISTRY-}productapi\n hostname: productapi\n restart: on-failure\n environment:\n - Eureka__Client__ServiceUrl=http://serviceDiscovery:8761/eureka/\n - Eureka__Client__ShouldRegisterWithEureka=true\n - Eureka__Client__ValidateCertificates=false\n networks:\n - services-network\n depends_on:\n messageBroker:\n condition: service_healthy\n serviceDiscovery:\n condition: service_started\n build:\n context: .\n dockerfile: Services/Products/Dockerfile\n links:\n - \"serviceDiscovery\"\n - \"messageBroker\"\n \n \n \nnetworks:\n services-network:\n```\n\n**this is my config file which I connect to RabbitMq:**\n\n```\nusing RabbitMQ.Client;\n\nnamespace MessageBroker;\n\npublic static class MessageBrokerConfig\n{\n public static IModel ChannelConfig()\n {\n var channel = new ConnectionFactory { Uri = new Uri(\"amqp://admin:password@messageBroker:5672\") }\n .CreateConnection()\n .CreateModel();\n return channel;\n } \n}\n```\n\n**but when I run docker-compose up I still got the error:**\n\n```\nproduct-api_1 | Unhandled exception. RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable\nproduct-api_1 | ---> System.AggregateException: One or more errors occurred. (Connection failed)\nproduct-api_1 | ---> RabbitMQ.Client.Exceptions.ConnectFailureException: Connection failed\nproduct-api_1 | ---> System.Net.Sockets.SocketException (111): Connection refused\n```\n\nAnd the product service can register inside the Service Discovery without a problem, and I followed almost the same steps.\nAnd I know that the problem isn't the rabbitmq container taking time to be ready, because I can connect on my machine. And everytime the product service failed to launch, it restarts, but no matter how much time it takes, I still got this error. And the log of the messageBroker container shows it's healthy (and if wasn't, I would not be able to access through my machine ).\nI don't have any other ideas, I'm on this problem 3 days alredy and I'm going crazy. I checked tutorials, followed the steps and nothig.\n\n========================================\n\nTop Answer:\nYour docker-compose file does not have the networking setup correctly. IMO you don't need the links. Here is a minimal docker-compose that worked for me. I removed the links and I removed the service discovery which isn't in play here for connectivity between rabbitClient and the broker.\n\n```\nversion: '3.8'\n\nservices:\n #db:\n # image: postgres\n\n messageBroker:\n image: rabbitmq:management\n hostname: \"messageBroker\"\n healthcheck:\n test: rabbitmq-diagnostics -q ping\n interval: 5s\n timeout: 15s\n retries: 3\n networks:\n - services-network\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n environment:\n RABBITMQ_DEFAULT_USER: \"admin\"\n RABBITMQ_DEFAULT_PASS: \"password\"\n\n product-api:\n image: ${DOCKER-REGISTRY-}productapi\n hostname: productapi\n restart: on-failure\n environment:\n - Eureka__Client__ServiceUrl=http://serviceDiscovery:8761/eureka/\n - Eureka__Client__ShouldRegisterWithEureka=true\n - Eureka__Client__ValidateCertificates=false\n networks:\n - services-network\n depends_on:\n messageBroker:\n condition: service_healthy\n build:\n context: client\n dockerfile: Dockerfile\n \nnetworks:\n services-network:\n```\n\n========================================\n\nCode:\n```text\nversion: '3.8'\n\nservices:\n #db:\n # image: postgres\n\n messageBroker:\n image: rabbitmq:management\n hostname: \"messageBroker\"\n healthcheck:\n test: rabbitmq-diagnostics -q ping\n interval: 5s\n timeout: 15s\n retries: 3\n networks:\n - services-network\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n environment:\n RABBITMQ_DEFAULT_USER: \"admin\"\n RABBITMQ_DEFAULT_PASS: \"password\"\n\n serviceDiscovery:\n image: steeltoeoss/eureka-server\n hostname: eureka-server\n networks:\n - services-network\n ports:\n - \"8761:8761\"\n \n order-api:\n image: ${DOCKER_REGISTRY-}orderapi\n hostname: orderapi\n environment:\n - Eureka__Client__ServiceUrl=http://serviceDiscovery:8761/eureka/\n - Eureka__Client__ShouldRegisterWithEureka=true\n - Eureka__Client__ValidateCertificates=false\n networks:\n - services-network\n depends_on:\n - serviceDiscovery\n build:\n context: .\n dockerfile: Services/Order/Dockerfile\n links:\n - \"serviceDiscovery\"\n\n product-api:\n image: ${DOCKER_REGISTRY-}productapi\n hostname: productapi\n restart: on-failure\n environment:\n - Eureka__Client__ServiceUrl=http://serviceDiscovery:8761/eureka/\n - Eureka__Client__ShouldRegisterWithEureka=true\n - Eureka__Client__ValidateCertificates=false\n networks:\n - services-network\n depends_on:\n messageBroker:\n condition: service_healthy\n serviceDiscovery:\n condition: service_started\n build:\n context: .\n dockerfile: Services/Products/Dockerfile\n links:\n - \"serviceDiscovery\"\n - \"messageBroker\"\n \n \n \nnetworks:\n services-network:\n```\n\n```text\nusing RabbitMQ.Client;\n\nnamespace MessageBroker;\n\npublic static class MessageBrokerConfig\n{\n public static IModel ChannelConfig()\n {\n var channel = new ConnectionFactory { Uri = new Uri(\"amqp://admin:password@messageBroker:5672\") }\n .CreateConnection()\n .CreateModel();\n return channel;\n } \n}\n```\n\n```text\nproduct-api_1 | Unhandled exception. RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable\nproduct-api_1 | ---> System.AggregateException: One or more errors occurred. (Connection failed)\nproduct-api_1 | ---> RabbitMQ.Client.Exceptions.ConnectFailureException: Connection failed\nproduct-api_1 | ---> System.Net.Sockets.SocketException (111): Connection refused\n```\n\n```text\n--build\n```\n\n```text\nversion: '3.8'\n\nservices:\n #db:\n # image: postgres\n\n messageBroker:\n image: rabbitmq:management\n hostname: \"messageBroker\"\n healthcheck:\n test: rabbitmq-diagnostics -q ping\n interval: 5s\n timeout: 15s\n retries: 3\n networks:\n - services-network\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n environment:\n RABBITMQ_DEFAULT_USER: \"admin\"\n RABBITMQ_DEFAULT_PASS: \"password\"\n\n product-api:\n image: ${DOCKER-REGISTRY-}productapi\n hostname: productapi\n restart: on-failure\n environment:\n - Eureka__Client__ServiceUrl=http://serviceDiscovery:8761/eureka/\n - Eureka__Client__ShouldRegisterWithEureka=true\n - Eureka__Client__ValidateCertificates=false\n networks:\n - services-network\n depends_on:\n messageBroker:\n condition: service_healthy\n build:\n context: client\n dockerfile: Dockerfile\n \nnetworks:\n services-network:\n```\n\n```text\nnetworks:\n services-network:\n driver: bridge\n```\n\n========================================\n\nComments:\n- You are partially right, i don't need the links, but I still got the same error. I tested if the ports on rabbitmq were accessible from another container by creating a container with ubuntu image and I did `telnet container-ip-address port` and it connected. So i'm very lost\n- Did you try with the simplified docker-compose I pasted. I tested on windows with docker desktop and after removing the links it works. Also give it a few seconds for broker to come up. So you will see the error but it will clear after a few seconds.\n- Yeah, the docker-compose file was correct. The image I had of my service was wrong, it was the old one with obsolet dll's. So the service was always trying to connect as localhost. Thank you very much for your help!\n- Actually not needed. When you run docker compose, by default, all the networks it creates already is bridge type by default.\n- Ohh didn't know it has bridge as default -.-, since in all my docker-compose I have it setup like that to communication btw them hehe","metadata":{"transformedAt":"2026-08-18T18:33:20.181Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":335,"estimatedTokens":2273}}649{"id":"stack-32445960","source":"stackoverflow","questionId":32445960,"title":"SPRINGAMQP or RabbitMq Java API","tags":["rabbitmq","spring-amqp","spring-rabbit"],"text":"Title: SPRINGAMQP or RabbitMq Java API\nTags: rabbitmq, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI am new to rabbitMq and Spring AMQP .\nI am building a new project from scratch . Here for one of the components we are using rabbit-Mq as message broker .\n\nIn this project ,primarily all the development has been happening in Java . We are using Spring in general for some of the components .\n\nNow , rabbit-mq though written in Erlang does provide a clean java Api. There is also spring amqp which provides a nice interface to support loose coupling (through AMQPTemplate etc.) .\n\nOne advantage which I thought of using SpringAMQP is that because of above mentioned loose coupling , tomorrow if we have to use any other implementation of AMQP than rabbit-Mq(spring-rabbit ) I don't have to change my code . But as I see ,today the implementation is for rabbit-Mq and barring extraordinary circumstances , I don't see anything happening here. We should be using rabbit-Mq for near foreseeable future and also not sure if there is any other message broker implementation thought at spring amqp side other than rabbitMq.\n\nThe disadvantage I think is that I am well away off understanding the actual client API RabbitMq provides due to the abstraction Spring AMQP gives(unless I decide to dig really deep) .\n\nIn such a case , is there any other advantage SPRING AMQP provides over traditional rabbitMq Java API ?\n\nThanks\n\n========================================\n\nTop Answer:\nSpring AMQP sits \"on top of\" the RabbitMQ `amqp-client` java library, and brings the familiar Spring programming model to RabbitMQ.\n\nIt provides similar features to those that Spring JMS users are used to, including message-driven POJOs and the `RabbitTemplate`.\n\nAs with all Spring `*Template`s, the `RabbitTemplate` eliminates boilerplate code, cleans up resources automatically, participates in existing rabbitmq transactions, etc., while still allowing you to drop down to the native API if you have advanced needs that are not satisfied by the higher-level API (which is somewhat rare). So, using one does not preclude the other.\n\nDisclosure: I am the project lead.\n\n========================================\n\nCode:\n```text\namqp-client\n```\n\n```text\nRabbitTemplate\n```\n\n```text\n*Template\n```\n\n```text\nRabbitTemplate\n```\n\n========================================\n\nComments:\n- Thanks Gary . It cleared the thought process for me :)","metadata":{"transformedAt":"2026-08-18T18:33:20.181Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":54,"estimatedTokens":605}}650{"id":"stack-34603150","source":"stackoverflow","questionId":34603150,"title":"RabbitMQ only listens to the first message on a queue","tags":["c#","rabbitmq"],"text":"Title: RabbitMQ only listens to the first message on a queue\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm having an issue with my Rabbit queues that is currently only reacting to the first message in queue, after that any other messages being pushed are being ignored.\n\nI start with instantiating the connection and declaring the queue in my IQueueConnectionProvider:\n\n```\nvar connectionFactory = new ConnectionFactory() { HostName = hostName };\nvar connection = _connectionFactory.CreateConnection();\nvar channel = connection.CreateModel();\n```\n\nThat IQueueConnectionProvider is then used in my IQueueListener as a dependency with just one method:\n\n```\npublic void ListenToQueue(string queue)\n{\n var channel = _queueConnectionProvider.GetQueue();\n\n var consumer = new EventingBasicConsumer(channel);\n consumer.Received += (model, ea) =>\n {\n string path = @\"d:\\debug.log.txt\";\n File.AppendAllLines(path, new List() {\"MESSAGE RECEIVED\", Environment.NewLine });\n\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n\n channel.BasicAck(ea.DeliveryTag, false);\n };\n\n channel.BasicConsume(queue, true, consumer);\n\n}\n```\n\nMy log file ends up being just one line \"MESSAGE RECEIVED\", however I can see in the Rabbit ui interface that my other services are pushing the messages to that queue just fine.\n\nIs there something I'm missing here?\n\n========================================\n\nTop Answer:\nThe code works fine! Have tested with my queue, and was able to get \"MESSAGE RECEIVED\" 9 times in the log file; since I had 9 messages in my queue.\n\nI tried without this line of code, and it worked fine\nvar channel = _queueConnectionProvider.GetQueue();\n\n========================================\n\nCode:\n```text\nvar connectionFactory = new ConnectionFactory() { HostName = hostName };\nvar connection = _connectionFactory.CreateConnection();\nvar channel = connection.CreateModel();\n```\n\n```text\npublic void ListenToQueue(string queue)\n{\n var channel = _queueConnectionProvider.GetQueue();\n\n var consumer = new EventingBasicConsumer(channel);\n consumer.Received += (model, ea) =>\n {\n string path = @\"d:\\debug.log.txt\";\n File.AppendAllLines(path, new List<string>() {\"MESSAGE RECEIVED\", Environment.NewLine });\n\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n\n channel.BasicAck(ea.DeliveryTag, false);\n };\n\n channel.BasicConsume(queue, true, consumer);\n\n}\n```\n\n```text\nchannel.BasicConsume(queue, false, consumer);\n```\n\n```text\nnoAck\n```\n\n```text\nfalse\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.181Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":93,"estimatedTokens":635}}651{"id":"stack-9811933","source":"stackoverflow","questionId":9811933,"title":"Celery design help: how to prevent concurrently executing tasks","tags":["python","rabbitmq","celery","amqp"],"text":"Title: Celery design help: how to prevent concurrently executing tasks\nTags: python, rabbitmq, celery, amqp\nSource: Stack Overflow\n\nQuestion:\nI'm fairly new to Celery/AMQP and am trying to come up with a task/queue/worker design to meet the following requirements.\n\nI have multiple types of \"per-user\" tasks: e.g., TaskA, TaskB, TaskC. Each of these \"per-user\" tasks read/write data for one particular user in the system. So at any given time, I might need to create tasks User1_TaskA, User1_TaskB, User1_TaskC, User2_TaskA, User2_TaskB, etc. I need to ensure that, **for each user**, no two tasks **of any task type** execute concurrently. I want a system in which no worker can execute User1_TaskA at the same time as any other worker is executing User1_TaskB or User1_TaskC, but while User1_TaskA is executing, other workers shouldn't be blocked from concurrently executing User2_TaskA, User3_TaskA, etc.\n\nI realize this could be implemented using some sort of external locking mechanism (e.g., in the DB), but I'm hoping there's a more elegant task/queue/worker design that would work.\n\nI suppose one possible solution is to implement queues as user buckets such that, when the workers are launched there's config that specifies how many buckets to create, and each \"bucket worker\" is bound to exactly one bucket. Then an \"intermediate worker\" would pull off tasks from the main task queue and assign them into the bucketed queues via, say, a hash/mod scheme. So UserA's tasks would always end up in the same queue, and multiple tasks for UserA would back up behind each other. I don't love this approach, as it would require the number of buckets to be defined ahead of time, and would seem to prevent (easily) adding workers dynamically. Seems to me there's got to be a better way -- suggestions would be greatly appreciated.\n\n========================================\n\nComments:\n- celeryproject.org is considered compromised, see github.com/celery/celeryproject/issues/52. Updated link (march 2022): docs.celeryq.dev/en/latest/tutorials/…","metadata":{"transformedAt":"2026-08-18T18:33:20.181Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":17,"estimatedTokens":513}}652{"id":"stack-2215086","source":"stackoverflow","questionId":2215086,"title":"Retrieve messages from RabbitMQ queue(s)","tags":["php","queue","message-queue","rabbitmq","amqp"],"text":"Title: Retrieve messages from RabbitMQ queue(s)\nTags: php, queue, message-queue, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI'm looking to implement RabbitMQ into my PHP application, and am using the php-amqp extension. My only question is this, how do I easily query to return the contents of the queue in PHP?\n\nphp-amqp seems to not enable me to do this. If I am going wrong, please help me out here :)\n\n========================================\n\nTop Answer:\nIf you need to know how many messages are in a queue, you can get this information when you declare the queue, or if you use `basic.get` to retrieve a single message. Normally, recipients of messages will use `basic.consume` and they will not know how many messages are waiting.\n\n========================================\n\nCode:\n```text\nbasic.get\n```\n\n```text\nbasic.consume\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.181Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":24,"estimatedTokens":211}}653{"id":"stack-12181250","source":"stackoverflow","questionId":12181250,"title":"Is RabbitMQ, ZeroMQ, Service Broker or something similar an appropriate solution for creating a high availability database webservice?","tags":["sql-server","rabbitmq","message-queue","zeromq","high-availability"],"text":"Title: Is RabbitMQ, ZeroMQ, Service Broker or something similar an appropriate solution for creating a high availability database webservice?\nTags: sql-server, rabbitmq, message-queue, zeromq, high-availability\nSource: Stack Overflow\n\nQuestion:\nI have a CRUD webservice, and have been tasked with trying to figure out a way to ensure that we don't lose data when the database goes down. Everyone is aware that if the database goes down we won't be able to get \"reads\" but for a specific subset of the operations we want to make sure that we don't lose data. \n\nI've been given the impression that this is something that is covered by services like 0MQ, RabbitMQ, or one of the Microsoft MQ services. Although after a few days of reading and research, I'm not even certain that the messages we're talking about in MQ services include database operations. I am however 100% certain that I can queue up as many hello worlds as I could ever hope for.\n\nIf I can use a message queue for adding a layer of protection to the database, I'd lean towards Rabbit (because it appears to persist through crashes) but since the target is a Microsoft SQL server databse, perhaps one of their solutions (such as SQL Service Broker, or MSMQ) is more appropriate.\n\nThe real fundamental question that I'm not yet sure of though is whether I'm even playing with the right deck of cards (so to speak).\n\nWith the desire for a high-availablity webservice, that continues to function if the database goes down, does it make sense to put a Rabbit MQ instance \"between\" the webservice and the database? Maybe the right link in the chain is to have RabbitMQ send messages to the webserver? \n\nOr is there some other solution for achieving this? There are a number of lose ideas at the moment around finding a way to roll up weblogs in the event of database outage or something... but we're still in early enough stages that (at least I) have no idea what I'm going to do.\n\nIs message queue the right solution?\n\n========================================\n\nComments:\n- Not a problem - also consider that using queuing will still not prevent all data loss, for example, client browser requests may be dropped if IIS is too busy to dispatch them.\n- Service Broker can easily be used with EF or ADO.Net. Even works great with async/await.","metadata":{"transformedAt":"2026-08-18T18:33:20.181Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":24,"estimatedTokens":576}}654{"id":"stack-48958271","source":"stackoverflow","questionId":48958271,"title":"What is difference between a Message Queue and ESB?","tags":["rabbitmq","esb"],"text":"Title: What is difference between a Message Queue and ESB?\nTags: rabbitmq, esb\nSource: Stack Overflow\n\nQuestion:\nI was just reading about Enterprise Service Bus and trying to figure out how to implement it. However, the more I read about it, my conclusion was that it is just a glorified message queue.\n\nI read about it here: What is an ESB and what is it good for?\n\nWe use RabbitMQ in our architecture quite a lot and what I was having hard time understanding was that there any many similarities between both concepts:\n\n- Both are basically post and forget\n\n- You can post a message of any format in both queues\n\nMy question is that what is it that an ESB does and RabbitMQ is not able to do?","metadata":{"transformedAt":"2026-08-18T18:33:20.181Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":16,"estimatedTokens":174}}655{"id":"stack-33202348","source":"stackoverflow","questionId":33202348,"title":"RabbitMq Rpc: EventingBasicConsumer or QueueingBasicConsumer","tags":["rabbitmq","rpc","amqp"],"text":"Title: RabbitMq Rpc: EventingBasicConsumer or QueueingBasicConsumer\nTags: rabbitmq, rpc, amqp\nSource: Stack Overflow\n\nQuestion:\nThe tutorials on RabbitMq's site are pretty straight forward, but I noticed that in the Rpc example, the developers choose to use the thread-blocking call `consumer.Queue.Dequeue()` instead of using the `EventingBasicConsumer` and the event handling model used elsewhere.\n\nLooking through the current documentation it is stated that\n\n As of version 3.5.0 application callback handlers can invoke blocking operations (such as `IModel.QueueDeclare` or `IModel.BasicCancel`). `IBasicConsumer` callbacks are invoked concurrently. \n\nWhere as the old documentation (v. 1.5.0) states that it is not supported\n\n Application callback handlers must not invoke blocking AMQP operations (such as\n `IModel.QueueDeclare` or `IModel.BasicCancel`). If they do, the channel will deadlock. [...] For this reason, `QueueingBasicConsumer` is the safest way of subscribing to a queue.\n\nCould it be that the RPC example hasn't been updated? Or am I missing something? I would very much appreciate to be pointed to some documentation about this.\n\n========================================\n\nCode:\n```text\nconsumer.Queue.Dequeue()\n```\n\n```text\nEventingBasicConsumer\n```\n\n```text\nIModel.QueueDeclare\n```\n\n```text\nIModel.BasicCancel\n```\n\n```text\nIBasicConsumer\n```\n\n```text\nIModel.QueueDeclare\n```\n\n```text\nIModel.BasicCancel\n```\n\n```text\nQueueingBasicConsumer\n```\n\n```text\nQueueingBasicConsumer\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.181Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":9,"totalLines":56,"estimatedTokens":375}}656{"id":"stack-11935727","source":"stackoverflow","questionId":11935727,"title":"Looking for simple persistent message buffer in Java","tags":["java","messaging","rabbitmq"],"text":"Title: Looking for simple persistent message buffer in Java\nTags: java, messaging, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am looking for a simple persistent buffer as temporary storage for JSON messages in a Java application. Memory usage should be relatively constant and not depend on the number of messages in the buffer. It would nice to be able to replay messages from a point in the past. Deletion of old messages should be efficient. Needs to be able to handle 1m messages/h.\n\nCurrently my application uses a local RabbitMQ broker which shovels messages to a remote RabbitMQ broker. When the remote broker is down or not accepting messages the local RabbitMQ broker's memory usage rises with the queue length and eventually it stops accepting messages. I want to swap this out for a local disk based buffer and a thread copying messages to the remote RabbitMQ broker.\n\nAnyone have any ideas? I have looked at Kafka but it seems like overkill for my use-case. MongoDB is a possibility but I am worried about its memory usage.\n\n========================================\n\nComments:\n- Not sure but maybe Redis? It supports pub/sub also...\n- redis is blazing fast but needs so much memory. check this out. nosql.mypopescu.com/post/1010844204/redis-memory-usage\n- You might consider something like github.com/peter-lawrey/Java-Chronicle Its designed to support over 10M messages per second but you have to rotate the files to delete them.\n- The app already uses Redis for other things but it uses too much memory for this\n- Java-Chronicle looks like it might do the job .. will check it out tm! Thanks\n- I ended up writing a persistent message queue server with the replay stuff we needed. Checkout http//qdb.io/","metadata":{"transformedAt":"2026-08-18T18:33:20.181Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":20,"estimatedTokens":430}}657{"id":"stack-33786536","source":"stackoverflow","questionId":33786536,"title":"RabbitMQ heartbeat vs connection drain events timeout","tags":["python","timeout","rabbitmq","heartbeat","kombu"],"text":"Title: RabbitMQ heartbeat vs connection drain events timeout\nTags: python, timeout, rabbitmq, heartbeat, kombu\nSource: Stack Overflow\n\nQuestion:\nI have a rabbitmq server and a amqp consumer (python) using kombu.\n\nI have installed my app in a system that has a firewall that closes idle connections after 1 hour. \n\nThis is my amqp_consumer.py:\n\n```\ntry:\n # connections\n with Connection(self.broker_url, ssl=_ssl, heartbeat=self.heartbeat) as conn:\n chan = conn.channel()\n # more stuff here\n with conn.Consumer(queue, callbacks = [messageHandler], channel = chan):\n # Process messages and handle events on all channels\n while True:\n conn.drain_events()\n\nexcept Exception as e:\n # do stuff\n```\n\nwhat i want is that if the firewall closed the connection, then i want to reconnect. should i use the heartbeat argument or should i pass a timeout argument (of 3600 sec) to the `drain_events()` function?\n\nWhat are the differences between both options? (seems to do the same).\n\nThanks.\n\n========================================\n\nCode:\n```text\ntry:\n # connections\n with Connection(self.broker_url, ssl=_ssl, heartbeat=self.heartbeat) as conn:\n chan = conn.channel()\n # more stuff here\n with conn.Consumer(queue, callbacks = [messageHandler], channel = chan):\n # Process messages and handle events on all channels\n while True:\n conn.drain_events()\n\nexcept Exception as e:\n # do stuff\n```\n\n```text\ndrain_events()\n```\n\n```text\nwhile True:\n try:\n conn.drain_events(timeout=1)\n except socket.timeout:\n conn.heartbeat_check()\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.181Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":61,"estimatedTokens":398}}658{"id":"stack-9569851","source":"stackoverflow","questionId":9569851,"title":"RabbitMQ transfer rates speed up?","tags":["c#","erlang","rabbitmq","producer-consumer"],"text":"Title: RabbitMQ transfer rates speed up?\nTags: c#, erlang, rabbitmq, producer-consumer\nSource: Stack Overflow\n\nQuestion:\nI look for ideas how to speed up message transfers through RabbitMQ.\n\nI installed the latest version on Windows 64 bit, running a server on my local machine on which I also publish and consume to/from through a C# implementation. I initially maxed out at 40,000 messages per second which is impressive but does not suit my needs (I compete with a custom binary reader which can handle 24 million unparsed 16 byte large byte arrays per second; obviously I dont expect to get close to that but I attempt to improve at least). I need to send around 115,000,000 messages as fast as possible. I do not want to persist the data and the connection is gonna be direct to one single consumer. I then built chunks of my 16b byte arrays and published onto the bus without any improvement. The transfer rate maxed out at 45mb/second. I find this very very slow given the fact that in the end it should just boil down to raw transmission speed because I could create byte arrays the size of several megabytes where the efficiency rate of routing by the exchange becomes negligible vs raw transmission speed. Why does my message bus max out at 45mb/second transfer speed?\n\n========================================\n\nComments:\n- if there's only 1 consumer, why not send direct over TCP? you don;t really need a message bus.\n- What's your IO (network, disk) and CPU look like during these tests?\n- probably you should look at zeromq instead of rabbitmq. Your task seems to be suitable for 0mq. At least they claim about 3_000_000 messages per second on that message size (16 bytes). zeromq.org/results:0mq-tests-v03\n- @Vladimir, what queuing system do you suggest? I use C# and target .Net 4.0.\n- Xepoch, hardly any usage of resources. I have the fastest SSD money can currently buy and manage with my own custom binary reader, including parsing a transfer speed on random access reads of 200mb/second from physical storage into memory and subsequent parsing of the byte array to C# object. For sure I am not constrained by system resources.\n- Odobenus, thanks I am actually considering it at the moment. But can I enforce same order delivery of messages as the published message order? Also can I make connectors function as consumers and producers at the same time, consuming and producing different message types. My highest priority is speed and message order. No persistence needed, no fancy broker needed.\n- If you are using TCP then you just queue the messages in memory as they arrive and then have your consumer pull them off the queue and process them. You probably want a blocking queue of some sort (sorry, don't write much C#). TCP of course guarantees delivery in order.\n- Vladimir, thanks, I played with blocking collections and it works. I would have to implement every single thing myself through. I found ZeroMQ and play with it right now because it is very lightweight but a lot faster than RabbitMQ (for obvious reasons as 0MQ is brokerless). It could be its exactly what I need. I still test to see what latency numbers and throughput looks like, if it does not satisfy my need then I will logically have to end up with my own blocking collection and need to implement whatever other functionality I need.","metadata":{"transformedAt":"2026-08-18T18:33:20.181Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":20,"estimatedTokens":833}}659{"id":"stack-56723867","source":"stackoverflow","questionId":56723867,"title":"Kubernetes nginx ingress rabbitmq management and kibana","tags":["nginx","kubernetes","rabbitmq","kibana","azure-aks"],"text":"Title: Kubernetes nginx ingress rabbitmq management and kibana\nTags: nginx, kubernetes, rabbitmq, kibana, azure-aks\nSource: Stack Overflow\n\nQuestion:\nOn my AKS cluster I have a Nginx ingress controller that I used to reverse proxy my kibana service running on the AKS. I want to however add another http services through the ingress, rabbitmq management console.\n\nI'm unable to get both to work with the following configuration:\n\n```\napiVersion: extensions/v1beta1\nkind: Ingress\nmetadata:\n name: ingress-aegis\n namespace: dev\n annotations:\n kubernetes.io/ingress.class: nginx\n certmanager.k8s.io/cluster-issuer: letsencrypt-prod\n nginx.ingress.kubernetes.io/rewrite-target: / \nspec:\n tls:\n - hosts:\n - dev.endpoint.net\n secretName: dev-secret \n rules:\n - host: dev.endpoint.net\n http:\n paths:\n - path: /\n backend:\n serviceName: kibana-kibana\n servicePort: 5601\n - path: /rabbit\n backend:\n serviceName: rabbitmq\n servicePort: 15672\n```\n\nThe Kibana works fine at root however RabbitMQ fails to load with a `503` with any path except `/`. If RabbitMQ's path is `/` then it works fine but then Kibana won't run.\n\nI assume this is because internally they are sitting on the root aka localhost:15672 so it redirects to / on dev.endpoint.net. \n\nHow do I have multiple services like Kibana and RabbitmQ running from one endpoint?\n\n========================================\n\nTop Answer:\nFor RabbitMQ Management UI via ingress, set the following in the rabbitmq.conf file (you can use configmaps and mount the file inside the pod)\n\nmanagement.path_prefix = /rabbit\n\nIn the Ingress set the following :\n\n```\n...\n path: /rabbit(/|$)(.*)\n...\n```\n\nSee : https://www.rabbitmq.com/management.html#path-prefix\n\n========================================\n\nCode:\n```text\napiVersion: extensions/v1beta1\nkind: Ingress\nmetadata:\n name: ingress-aegis\n namespace: dev\n annotations:\n kubernetes.io/ingress.class: nginx\n certmanager.k8s.io/cluster-issuer: letsencrypt-prod\n nginx.ingress.kubernetes.io/rewrite-target: / \nspec:\n tls:\n - hosts:\n - dev.endpoint.net\n secretName: dev-secret \n rules:\n - host: dev.endpoint.net\n http:\n paths:\n - path: /\n backend:\n serviceName: kibana-kibana\n servicePort: 5601\n - path: /rabbit\n backend:\n serviceName: rabbitmq\n servicePort: 15672\n```\n\n```text\n503\n```\n\n```text\n/\n```\n\n```text\n/\n```\n\n```text\nbasePath\n```\n\n```text\n/kibana\n```\n\n```text\nserver.basePath\n```\n\n```text\n/kibana\n```\n\n```text\n/\n```\n\n```text\nSERVER_BASEPATH\n```\n\n```text\nkibana\n```\n\n```text\napiVersion: extensions/v1beta1\nkind: Ingress\nmetadata:\n name: ingress-aegis\n namespace: dev\n annotations:\n kubernetes.io/ingress.class: nginx\n certmanager.k8s.io/cluster-issuer: letsencrypt-prod\n nginx.ingress.kubernetes.io/rewrite-target: / \nspec:\n tls:\n - hosts:\n - dev.endpoint.net\n - rabbit.endpoint.net\n secretName: dev-secret \n rules:\n - host: dev.endpoint.net\n http:\n paths:\n - path: /\n backend:\n serviceName: kibana-kibana\n servicePort: 5601\n - host: rabbit.endpoint.net\n http:\n paths:\n - path: /\n backend:\n serviceName: rabbitmq\n```\n\n```text\n...\n path: /rabbit(/|$)(.*)\n...\n```\n\n========================================\n\nComments:\n- Do you try to specialize the service port for the rabbitmq?\n- I missed that off the question. Now added.\n- Why creating only one ingress ? Why don't you create two different ingresses as it is two different domains and two different services ?\n- They are different services but are related under the same domain. Its easy enough to get multiple simple web applications working under multiple paths just not with more complex systems such as RabbitMQ and Kibana.\n- I'd like to keep it under the example of dev.endpoint.net and have the different resources as /resouce1 /resource2 etc\n- did you try this annotation, Service Upstream **ingress.kubernetes.io/service-upstream: \"true\"** *The nginx.ingress.kubernetes.io/service-upstream annotation disables that behavior and instead uses a single upstream in NGINX, the service's Cluster IP and port*\n- Please take a look also for Create an HTTPS ingress controller on Azure Kubernetes Service (AKS) In this example they are using different annotations:`nginx.ingress.kubernetes.io/rewrite-target: /$1` and `path: /(.*)` and `path: /hello-world-two(/|$)(.*)`\n- No luck with either. Rabbitmq just returns a blank page with the resources loaded on the network but not displaying.\n- please take a loo for this ticket on azure and rewrite issue. Please use curl -I -k for debugging your connection. Please verify also your chart and app version for nginx-ingress\n- Does that work with the official Kibana install from helm?\n- Can't confirm as I have not used helm, but I think it should work. Just try and let me know your feeback\n- Thanks for your answer. I was able to fix my problem\n- Instead of mapping the config file, just add env: `RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS=-rabbitmq_management path_prefix \"/rabbit\"`","metadata":{"transformedAt":"2026-08-18T18:33:20.181Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":13,"totalLines":187,"estimatedTokens":1271}}660{"id":"stack-6504005","source":"stackoverflow","questionId":6504005,"title":"Consuming a rabbitmq message queue with multiple threads (Python Kombu)","tags":["python","multithreading","rabbitmq","kombu"],"text":"Title: Consuming a rabbitmq message queue with multiple threads (Python Kombu)\nTags: python, multithreading, rabbitmq, kombu\nSource: Stack Overflow\n\nQuestion:\nI have a single RabbitMQ exchange with a single queue. I wish to create a daemon that runs multiple threads and works through this queue as quickly as possible. \n\nThe \"work\" involves communicating with external services, so there will be a fair amount of blocking going on within each consumer. As such, I want to have multiple threads all dealing with messages from the same queue.\n\nI can achieve this by consuming the queue on my primary thread, and then farming the incoming work off to a pool of other threads, but is there a way to launch multiple consumers, each within their own threaded context?\n\n========================================\n\nComments:\n- This restricts to python only, which might not be ideal since rabbitmq is language independent. Is there a language independent readily made package for task distribution?","metadata":{"transformedAt":"2026-08-18T18:33:20.181Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":15,"estimatedTokens":248}}661{"id":"stack-3934295","source":"stackoverflow","questionId":3934295,"title":"Using RabbitMQ with nServiceBus (for C#) vs using Amazon SQS","tags":["c#","message-queue","nservicebus","rabbitmq","amazon-sqs"],"text":"Title: Using RabbitMQ with nServiceBus (for C#) vs using Amazon SQS\nTags: c#, message-queue, nservicebus, rabbitmq, amazon-sqs\nSource: Stack Overflow\n\nQuestion:\nIf I understand correctly, I can use nServiceBus as a \"framework\" and / or a wrapper around RabbitMQ\nMy preference of RabbitMQ is being able to use it on linux machines\n\n**Background**\n\nI have an application that enables people to upload images.\nThese images will require thumbnails.\n\nOur application is predominantly asp.net (c#)\n\nMy idea is to do the following:\n\n- upload the full size images to S3 (or whatever storage service)\n\n- create a \"message\" that has input storage key, output storage key, width, height - and add to queue.\n\n- there will be a linux server acting as a worker (windows licensing constraint) that reads the messages from the queue, and does the actual resizing\n\n- new image will be placed on S3, defined by output key of received message\n\nI could use Amazon SQS i suppose, but I wanted to explore the possibility of nServiceBus with RabbitMQ for transport.\n\nDoes anyone have any further info on doing this?\nI saw this on GitHub: http://github.com/machine/machine.mta/tree/master/Source/NServiceBus.Unicast.Transport.RabbitMQ but was wondering how this could be used?\n\nWhat would your preferred way of approaching this be?\n\n========================================\n\nTop Answer:\n`` You might want to look at EasyNetQ too. It's written specifically as a .NET API for RabbitMQ. It works fine on Mono too.\n\n========================================\n\nCode:\n```text\n<shameless_plug>\n```\n\n========================================\n\nComments:\n- Please note you should be careful about presenting your own project as an answer if the user has not explicitly asked for recommendations (and such questions end up getting closed/deleted nowadays when they are found, anyway). In this case, the OP was asking about how to use a specific API he had already found.","metadata":{"transformedAt":"2026-08-18T18:33:20.181Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":48,"estimatedTokens":483}}662{"id":"stack-40928889","source":"stackoverflow","questionId":40928889,"title":"How to install/use rabbitmq-plugins on Mac","tags":["macos","rabbitmq"],"text":"Title: How to install/use rabbitmq-plugins on Mac\nTags: macos, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nInstalled `rabbitmq` via Homebrew\n\nhttp://www.rabbitmq.com/install-standalone-mac.html\n\nType `rabbitmq-plugins enable amqp_client`\n\nSee an error `-bash: rabbitmq-plugins: command not found`\n\n========================================\n\nCode:\n```text\nrabbitmq\n```\n\n```text\nrabbitmq-plugins enable amqp_client\n```\n\n```text\n-bash: rabbitmq-plugins: command not found\n```\n\n```text\n$ /usr/local/sbin/rabbitmq-plugins enable amqp_client\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.181Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":31,"estimatedTokens":135}}663{"id":"stack-9661101","source":"stackoverflow","questionId":9661101,"title":"Is RabbitMQ practical for RPC-esque bidirectional use during request processing?","tags":["rpc","rabbitmq"],"text":"Title: Is RabbitMQ practical for RPC-esque bidirectional use during request processing?\nTags: rpc, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nSuper simple question, I couldn't find a concrete answer out there.\n\nIs RabbitMQ suitable for RPC-like operations when processing HTTP requests?\n\nI'm interested in firing off a message when a user HTTP request is received, waiting for the response from a backend server, and then sending the response to the client.\n\nIs that a common use scenario? Are people doing it with success? Any pitfalls? Any examples or common design patterns?\n\n========================================\n\nTop Answer:\nThis has worked for me, I do suggest you look at the Web messaging extentions/tools though:\n\nhttp://www.rabbitmq.com/devtools.html#web-messaging\n\n========================================\n\nComments:\n- Possible duplicate: stackoverflow.com/questions/9381909/synchronous-amqp-from-ph‌​p/…\n- Well I guess you can't argue with use in production! Thanks!\n- We looked all over for a simple way to expose amqp over http, its not a straight forward mapping. If was starting today I would do it with node.js (node-amqp) and build the http protocol the way i wanted to support my particular use cases. The biggest thing to think about is authentication via http to rabbit ..","metadata":{"transformedAt":"2026-08-18T18:33:20.181Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":26,"estimatedTokens":329}}664{"id":"stack-11739265","source":"stackoverflow","questionId":11739265,"title":"TxSelect and TransactionScope","tags":["c#","transactions","rabbitmq"],"text":"Title: TxSelect and TransactionScope\nTags: c#, transactions, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nRecently, I've been checking out RabbitMQ over C# as a way to implement pub/sub. I'm more used to working with NServiceBus. NServiceBus handles transactions by enlisting MSMQ in a `TransactionScope`. Other transaction aware operations can also enlist in the same `TransactionScope` (like MSSQL) so everything is truly atomic. Underneath, NSB brings in MSDTC to coordinate.\n\nI see that in the C# client API for RabbitMQ there is a `IModel.TxSelect()` and `IModel.TxCommit()`. This works well to not send messages to the exchange before the commit. This covers the use case where there are multiple messages sent to the exchange that need to be atomic. However, is there a good way to synchronize a database call (say to MSSQL) with the RabbitMQ transaction?\n\n========================================\n\nTop Answer:\nYou can write a RabbitMQ Resource Manager to be used by MSDTC by implementing the IEnlistmentNotification interface. The implementation provides two phase commit notification callbacks for the transaction manager upon enlisting for participation. Please note that MSDTC comes with a heavy price and will degrade your overall performance drastically. \n\n**Example of RabbitMQ resource manager:**\n\n```\nsealed class RabbitMqResourceManager : IEnlistmentNotification\n{\n private readonly IModel _channel;\n\n public RabbitMqResourceManager(IModel channel, Transaction transaction)\n {\n _channel = channel;\n _channel.TxSelect();\n transaction.EnlistVolatile(this, EnlistmentOptions.None);\n }\n\n public RabbitMqResourceManager(IModel channel)\n {\n _channel = channel;\n _channel.TxSelect();\n if (Transaction.Current != null)\n Transaction.Current.EnlistVolatile(this, EnlistmentOptions.None);\n }\n\n public void Commit(Enlistment enlistment)\n {\n _channel.TxCommit();\n enlistment.Done();\n }\n\n public void InDoubt(Enlistment enlistment)\n { \n Rollback(enlistment);\n }\n\n public void Prepare(PreparingEnlistment preparingEnlistment)\n {\n preparingEnlistment.Prepared();\n }\n\n public void Rollback(Enlistment enlistment)\n {\n _channel.TxRollback();\n enlistment.Done();\n }\n}\n```\n\n**Example using resource manager**\n\n```\nusing(TransactionScope trx= new TransactionScope())\n{\n var basicProperties = _channel.CreateBasicProperties();\n basicProperties.DeliveryMode = 2;\n\n new RabbitMqResourceManager(_channel, trx);\n _channel.BasicPublish(someExchange, someQueueName, basicProperties, someData);\n trx.Complete();\n}\n```\n\n========================================\n\nCode:\n```text\nTransactionScope\n```\n\n```text\nTransactionScope\n```\n\n```text\nIModel.TxSelect()\n```\n\n```text\nIModel.TxCommit()\n```\n\n```text\nsealed class RabbitMqResourceManager : IEnlistmentNotification\n{\n private readonly IModel _channel;\n\n public RabbitMqResourceManager(IModel channel, Transaction transaction)\n {\n _channel = channel;\n _channel.TxSelect();\n transaction.EnlistVolatile(this, EnlistmentOptions.None);\n }\n\n public RabbitMqResourceManager(IModel channel)\n {\n _channel = channel;\n _channel.TxSelect();\n if (Transaction.Current != null)\n Transaction.Current.EnlistVolatile(this, EnlistmentOptions.None);\n }\n\n public void Commit(Enlistment enlistment)\n {\n _channel.TxCommit();\n enlistment.Done();\n }\n\n public void InDoubt(Enlistment enlistment)\n { \n Rollback(enlistment);\n }\n\n public void Prepare(PreparingEnlistment preparingEnlistment)\n {\n preparingEnlistment.Prepared();\n }\n\n public void Rollback(Enlistment enlistment)\n {\n _channel.TxRollback();\n enlistment.Done();\n }\n}\n```\n\n```text\nusing(TransactionScope trx= new TransactionScope())\n{\n var basicProperties = _channel.CreateBasicProperties();\n basicProperties.DeliveryMode = 2;\n\n new RabbitMqResourceManager(_channel, trx);\n _channel.BasicPublish(someExchange, someQueueName, basicProperties, someData);\n trx.Complete();\n}\n```\n\n========================================\n\nComments:\n- What kind of throughput are you expecting from your system?\n- @kzhen I'm not really worried about performance. Consistency is important though. I'll be using durable exchanges and queues. Throughput will not be that high, maybe 50-100,000 messages per day.\n- Yes, I agree with everything you wrote. In my particular case, though, the consumer is not the problem. I have a situation where the producer might commit database state and then publish a message. Again, however, I totally agree about the need for idempotent messages on the consumer side. Thanks for the heads up about TxSelect and TxCommit performance.\n- Perhaps your approach could have the producer commit the db row then send a message then update the row to say the message has been sent when the server confirms receipt (rabbitmq.com/blog/2011/02/10/introducing-publisher-confirms‌​) then if your producer crashes when it comes back online it could look for rows that haven't had their messages published and then (re)send them\n- Yeah, I think you are right. We are going to plan to commit that the message needs to be sent with the original db transaction. Then have a dispatcher pick it up and send to Rabbit. Finally, we will commit that the message has been sent. Thanks for the link!\n- interesting... But, in the end we went with a no MSDTC solution. Thanks for adding this to the question, though, hopefully others will find it useful. :)\n- I use the same approach in my application. However, I found that Commit/Prepare methods of IEnlistmentNotification are called in a different thread (it seems to be a normal behavior in System.Transaction), that cause some problems with RabbitMQ because IModel should not be used across thread (from the official documentation). Did you experiment this problem?\n- No, i didnt. I think they are referring to thread concurrency since the channel is not thread safe. Thus if more than one thread uses the channel at the same time you will get issues.","metadata":{"transformedAt":"2026-08-18T18:33:20.181Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":160,"estimatedTokens":1511}}665{"id":"stack-13235737","source":"stackoverflow","questionId":13235737,"title":"RabbitMQ consumer on demand?","tags":["rabbitmq","consumer"],"text":"Title: RabbitMQ consumer on demand?\nTags: rabbitmq, consumer\nSource: Stack Overflow\n\nQuestion:\nI want a consumer to perform some actions every time that a message is received. Must the consumer be running 24/7 \"listening\" to the queue or it can be run only when an appropiate message is received?\n\n========================================\n\nComments:\n- I guess there's no problem. I just asked because I'm just learning and i don't know if a process that is just listening consumes lots of resources or not.. thanks a lot for your reply\n- Basically no it shouldn't consume much in the way of resources. You do need a process running all the time if you want to consume messages promptly though\n- Some told me not to use PHP for long running processes like these. What do you think about it?\n- I do not know enough about PHP to answer that. It sounds plausable though.","metadata":{"transformedAt":"2026-08-18T18:33:20.181Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":14,"estimatedTokens":217}}666{"id":"stack-58875630","source":"stackoverflow","questionId":58875630,"title":"How to deploy a Celery worker on Google app engine","tags":["python","django","google-app-engine","rabbitmq","celery"],"text":"Title: How to deploy a Celery worker on Google app engine\nTags: python, django, google-app-engine, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI have a Celery worker need to deploy to Google app engine, is it possible?\nI intend to use one app for my main Django app, one app for Celery worker and one Rabbitmq service (it supported by Google cloud)\n\n========================================\n\nComments:\n- This answer is based on deprecated technology.\n- @DaanLuttik so what do you suggest we use instead of Taskqueue?\n- @UdayReddy I believe that the scenario that the original question describes is possible. You can also consider pubsub.","metadata":{"transformedAt":"2026-08-18T18:33:20.181Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":14,"estimatedTokens":161}}667{"id":"stack-37520676","source":"stackoverflow","questionId":37520676,"title":"AMQP/RabbitMQ - Process messages sequentially","tags":["rabbitmq","amqp","high-availability"],"text":"Title: AMQP/RabbitMQ - Process messages sequentially\nTags: rabbitmq, amqp, high-availability\nSource: Stack Overflow\n\nQuestion:\nI have one *direct* exchange. There is also one queue, bound to this exchange. \n\nI have two consumers for that queue. The consumers are manually ack'ing the messages once they've done the corresponding processing.\n\nThe messages are logically ordered/sorted, and should be processed in that order. Is it possible to enforce that all messages are received and processed sequentially accross consumer A and consumer B? In other words, prevent A and B from processing messages at the same time.\n\nNote: the consumers are **not** sharing the same connection and/or channel. This means I cannot use `.basicQoS(1);`.\n\nRationale of this question: both consumers are identicall. If one goes down, the other queue starts processing messages and everything keeps working without any required intervention.\n\n========================================\n\nTop Answer:\nOne approach to handling failover in a case where you want redundant consumers but need to process messages in a specific order is to use the exclusive consumer option when setting up the bind to the queue, and to have two consumers who keep trying to bind even when they can't get the exclusive lock. \n\nThe process is something like this:\n\n- Consumer A starts first and binds to the queue as an exclusive consumer. Consumer A begins processing messages from the queue.\n\n- Consumer B starts next and attempts to bind to the queue as an exclusive consumer, but is rejected because the queue already has an exclusive consumer.\n\n- On a recurring basis, consumer B attempts to get an exclusive bind on the queue but is rejected.\n\n- Process hosting consumer A crashes.\n\n- Consumer B attempts to bind to the queue as an exclusive consumer, and succeeds this time. Consumer B starts processing messages from the queue.\n\n- Consumer A is brought back online, and attempts an exclusive bind, but is rejected now.\n\n- Consumer B continues to process messages in FIFO order.\n\nWhile this approach doesn't provide load sharing, it does provide redundancy.\n\n========================================\n\nCode:\n```text\n<channel>.basicQoS(1);\n```\n\n========================================\n\nComments:\n- How about Single Active Consumer rabbitmq.com/consumers.html#single-active-consumer ? Multiple consumers bind but all messages go only to the very first one. If it dies, then messages are dispatched to the second one. You get your redundancy and processing order is preserved.\n- Single Active Consumer does look cleaner than exclusive binds, but does require RabbitMQ 3.8\n- Thank you for your insights. Coming back to your question `then why not just have A or just B`: You are correct in your understanding that `A` and `B` should not process messages at the same time. So it is indeed `A or B`. However, I thought it would be useful to have both `A` and `B` running: if `A` (or `B`) crashes, the system can continue without any (manual) intervention. I understand from you that my approach is not really possible. But the question then is: how can I facilitate a correct fail-over from `A` (or `B`) to `B` (or `A`)?\n- You are welcome. Easier would be to have a monitoring agent (watchdog) for `A` which would restart it if it crashes, then to make a failover from `A` to `B` in whatever way. The messages don't get lost, they'll stay in the queue and will be delivered when the consumer is up again.\n- OK, got it. Does RabbitMQ provide advanced fail-over functionalities? I know there is the management plugin and a REST API, but that's just monitoring (afaik). Are there any plugins/libraries/tools (RabbitMQ or 3rd party) for automatic fail-over which you would suggest to start with?\n- I don't know for fail-over functionalities, this is the client side, so I don't think that the server should be taking care of this. Could be that there are some plugins, but I've never needed something like that so haven't ever looked it up. RabbitMQ does have a heartbeat (actually a AMQP feature) check - maybe this can be of some use to you. But a watchdog should be quite easy to write on any OS - one exaple: pull process list every n seconds see if consumer is there if not start it.\n- OK, thank you. I will look into the heartbeat feature to start with. I'll leave this question open for a few days, in case somebody else has a more concrete answer. Thanks again.","metadata":{"transformedAt":"2026-08-18T18:33:20.182Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":55,"estimatedTokens":1105}}668{"id":"stack-62792713","source":"stackoverflow","questionId":62792713,"title":"How to set x-dead-letter-exchange in Rabbit?","tags":["java","rabbitmq","spring-rabbit","rabbitmq-exchange"],"text":"Title: How to set x-dead-letter-exchange in Rabbit?\nTags: java, rabbitmq, spring-rabbit, rabbitmq-exchange\nSource: Stack Overflow\n\nQuestion:\nHere are my beans:\n\n```\n@Bean\n public Queue igSmev3ListenerQueue() {\n Map args = new HashMap<>();\n args.put(\"x-dead-letter-exchange\", rabbitIgSmev3DlxProperties.getExchangeName());\n args.put(\"x-dead-letter-routing-key\", rabbitIgSmev3DlxProperties.getRoutingKey());\n return new Queue(rabbitIgSmev3ListenerProperties.getQueueName(), true, false, false, args);\n }\n\n @Bean\n public Queue igSmev3DlxQueue() {\n return new Queue(rabbitIgSmev3DlxProperties.getQueueName(), true, false, false);\n }\n```\n\nHere are application.yml settings:\n\n```\nlistener:\n vhost: /\n exchangeName: igSmev3Listener\n queueName: igSmev3-ListenerQueue\n routingKey: igSmev3-Listener\ndlx:\n vhost: /\n exchangeName: igSmev3Dlx\n queueName: igSmev3-DlxQueue\n routingKey: igSmev3-Dlx\n```\n\nMy current error:\n\n```\nCaused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'x-dead-letter-exchange' for queue 'igSmev3-ListenerQueue' in vhost '/': received none but current is the value 'igSmev3Dlx' of type 'longstr', class-id=50, method-id=10)\n```\n\nHow can I solve it? I need to take dead letters from listenerQueue and put them to dlxQueue\n\n========================================\n\nCode:\n```text\n@Bean\n public Queue igSmev3ListenerQueue() {\n Map<String, Object> args = new HashMap<>();\n args.put(\"x-dead-letter-exchange\", rabbitIgSmev3DlxProperties.getExchangeName());\n args.put(\"x-dead-letter-routing-key\", rabbitIgSmev3DlxProperties.getRoutingKey());\n return new Queue(rabbitIgSmev3ListenerProperties.getQueueName(), true, false, false, args);\n }\n\n @Bean\n public Queue igSmev3DlxQueue() {\n return new Queue(rabbitIgSmev3DlxProperties.getQueueName(), true, false, false);\n }\n```\n\n```text\nlistener:\n vhost: /\n exchangeName: igSmev3Listener\n queueName: igSmev3-ListenerQueue\n routingKey: igSmev3-Listener\ndlx:\n vhost: /\n exchangeName: igSmev3Dlx\n queueName: igSmev3-DlxQueue\n routingKey: igSmev3-Dlx\n```\n\n```text\nCaused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'x-dead-letter-exchange' for queue 'igSmev3-ListenerQueue' in vhost '/': received none but current is the value 'igSmev3Dlx' of type 'longstr', class-id=50, method-id=10)\n```\n\n```text\nigSmev3-ListenerQueue\n```\n\n========================================\n\nComments:\n- Queues are immutable once created; to change arguments you must first delete the existing queue.","metadata":{"transformedAt":"2026-08-18T18:33:20.182Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":88,"estimatedTokens":678}}669{"id":"stack-45539118","source":"stackoverflow","questionId":45539118,"title":"RabbitMQ plugin to remove duplicate messages","tags":["rabbitmq","message-queue"],"text":"Title: RabbitMQ plugin to remove duplicate messages\nTags: rabbitmq, message-queue\nSource: Stack Overflow\n\nQuestion:\nI have a RabbitMQ queues for documents generation. Basically, each document has `type` and `state` (new, processing, ready), so I use topic exchange with routing keys like `type.state`. Every time document changes I send the message with last document description to the exchange and it works good enough.\n\nHowever sometimes document can be processed twice:\n\n- User send new document. So new message `report.new` is sent to exchange.\n\n- While worker hasn't started document processing (the queue hasn't yet reached) user updated the document. The new message `report.new` for the same document is sent.\n\n- So now worker get the first message and start his work, while the document was changed and so this work is totally senseless.\n\nFor now I'm just add small code into workers, comparing `last_modified` document key from the message with the one from the database and ack the message if they are not the same. However I don't think this is the best solution.\n\nMy idea is to add `ID` to message headers and have some RabbitMQ plugin which will remove older messages with the same `ID` from the queue.\n\nThanks.\n\nP.S. Maybe another MQ engine can be useful here? E.g. maybe ActiveMQ has such a feature?\n\n========================================\n\nTop Answer:\nYou can check this plugin I wrote which allows to de-duplicate messages published within the broker.\n\nYou can de-duplicate on the exchange or at the queue according to your needs. Only thing your publisher needs to do is to set the `x-deduplicate-message` message header with the `ID` of your message.\n\n========================================\n\nCode:\n```text\ntype\n```\n\n```text\nstate\n```\n\n```text\ntype.state\n```\n\n```text\nreport.new\n```\n\n```text\nreport.new\n```\n\n```text\nlast_modified\n```\n\n```text\nID\n```\n\n```text\nID\n```\n\n```text\nID\n```\n\n```text\nID\n```\n\n```text\nID\n```\n\n```text\nx-deduplicate-message\n```\n\n```text\nID\n```\n\n========================================\n\nComments:\n- Memcache is not great for this as it could drop your key/value without warning.\n- 1) is the key/value store placed before your exchange/ queue ? 2) What if i'm writing from multiple producers and don't want duplicates between them ?\n- @eranotzap Didn't get your first question. Regarding the second one, it doesn't matter, because deduplication is done on the receiving stage. And 472084 is totally right about his comment, it's better to use Redis or smth.\n- @Ximik what if i wanted to remove duplicates on the sending side. is it something that is supported natively in the exchange ? Meaning i don't want to send duplicates to the client. I have a constant stream and a redundancy stream i want to send only from one of them. and one might miss an event that the other was missing so i wan't to fill in the gaps\n- @eranotzap I think, it's impossible. These days, there is Kafka which provide somehow similar feature (but still, not exactly you're trying to achieve). See kafka.apache.org/documentation/#compaction However you can still have duplicates. Moreover it's not an MQ, but really more like a stream.\n- If I understand correctly, it doesn't enqueue a duplicate message. The question, I guess, is about enqueuing the new message, and removing the previous duplicated one.\n- True, removing old-messages in RMQ is a non-trivial problem and I'd suggest a different queueing system if that is a critical requirement.","metadata":{"transformedAt":"2026-08-18T18:33:20.182Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":13,"totalLines":95,"estimatedTokens":867}}670{"id":"stack-37905564","source":"stackoverflow","questionId":37905564,"title":"Enabling logging for rabbit mq server within a docker image","tags":["docker","rabbitmq"],"text":"Title: Enabling logging for rabbit mq server within a docker image\nTags: docker, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am installing rabbit mq server within docker using the steps mentioned @ https://hub.docker.com/r/_/rabbitmq/ .\n\nThe installation went through fine, got my rabbitmq working perfectly fine.\n\nI am unable to find the rabbit mq logs.\n\nHow to control and turn on the logging?\n\n========================================\n\nCode:\n```text\ndocker logs rabbitmq_container_id\n```\n\n```text\ntail -f /var/lib/docker/rabbitmq_container_id/rabbitmq_container_id.logs\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.182Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":23,"estimatedTokens":145}}671{"id":"stack-42081061","source":"stackoverflow","questionId":42081061,"title":"Celery &Rabbitmq:WARNING/MainProcess] Received and deleted unknown message. Wrong destination?!?- a experiment on the GIT","tags":["rabbitmq","celery"],"text":"Title: Celery &Rabbitmq:WARNING/MainProcess] Received and deleted unknown message. Wrong destination?!?- a experiment on the GIT\nTags: rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nRecently , I am doing an experiment on a GIT project to understanding the big data processing framework.\n\n1、GIT project:https://github.com/esperdyne/celery-message-processing\n\nwe have the following components:\n\n1、AMPQ broker(**RabbitMQ**): it works as a message buffer, which works as a mail-box to exchange messages for different user!\n\n2、worker: it works as the service-server to provide service for various service client.\n3、Queue(**\"celery\"**:it works as a multi-processing container which is used to handle the various worker instances at the same time.\n\nthe key configuration can be seen as bellow:\n\nWe use the object proj/celery.py to define the app, the definition can be seen as below:\n\n```\napp = Celery('proj',\n broker='amqp://',\n backend='redis://localhost',\n include=['proj.tasks'])\n```\n\nenter code here\n\nwhen we start the app:\n\n1、 when we start the application, we have seen the message which is produced from the rabbitmq, yet the celery could not handle the message.\n\nParse.log looks like this:[2017-02-04 14:28:06,909: WARNING/MainProcess] Received and deleted unknown message. Wrong destination?!?\n\nwe have the following question:\n\n4.2.1 AMQP mechanism\nWe can see that the AMQP works as the message buffer, then there will be a message sender and a message fetcher:\n\nIn the above diagram , who is the message sender and who is the message fetcher.\n\n4.2.2 Message definition\nIn our application , we can not find the code to define the Message to send ,or to receive form the AMQP.\n\n4.2.3 Message monitor\nHow can we monitor the Message send and receive in the AMQP.\nHope a teacher will guide us to solve the problem , and give us some detailed\n\nintroduction on the celery broker mechenism!\n\nnote : the error log can be seen here\n\n```\n[2017-02-04 14:28:06,909: WARNING/MainProcess] Received and deleted unknown message. Wrong destination?!?\n\n The full contents of the message body was: body: [[u'maildir/allen- p/inbox/1.'], {}, {u'errbacks': None, u'callbacks': None, u'chord': None, u'chain': [{u'chord_size': None, u'task': u'celery.group', u'args': [], u'immutable': False, u'subtask_type': u'group', u'kwargs': {u'tasks': [{u'chord_size': None, u'task': u'proj.tasks.deploy_db', u'args': [], u'options': {u'reply_to': u'3d9de118-f9d0-3bee-9972-b6a4d4482446', u'task_id': u'3cafda16-3e7c-44db-b05e-1327ef97ffc3'}, u'subtask_type': None, u'kwargs': {}, u'immutable': False}, {u'chord_size': None, u'task': u'proj.tasks.deploy_es', u'args': [], u'options': {u'reply_to': u'3d9de118-f9d0-3bee-9972-b6a4d4482446', u'task_id': u'1f4c728b-680d-4dde-98b9-b153d5282780'}, u'subtask_type': None, u'kwargs': {}, u'immutable': False}]}, u'options': {u'parent_id': None, u'task_id': u'f21c911e-f2ac-462e-9662-2efbd27bcf91', u'root_id': None}}]}] (801b)\n{content_type:'application/json' content_encoding:'utf-8'\n delivery_info:{'consumer_tag': 'None4', 'redelivered': False, 'routing_key': 'parse', 'delivery_tag': 623422L, 'exchange': ''} headers={'\\xe5\\xca.\\xdb\\x00\\x00\\x00\\x00\\x00': None, 'P&5\\x07\\x00': None, 'T\\nKB\\x00\\x00\\x00': 'fc8f0bed-665f-4699-89dd-a56fc247ea8b', 'N\\xfd\\x17=\\x00\\x00': 'gen17347@centos1', '\\xcfb\\xddR': 'py', '9*\\xa8': None, '\\xb7/b\\x84\\x00\\x00\\x00': 0, '\\xe0\\x0b\\xfa\\x89\\x00\\x00\\x00': None, '\\xdfR\\xc4x\\x00\\x00\\x00\\x00\\x00': [None, None], 'T3\\x1d ': 'proj.tasks.parse', '\\xae\\xbf': 'fc8f0bed-665f-4699-89dd-a56fc247ea8b', '\\x11s\\x1f\\xd8\\x00\\x00\\x00\\x00': \"('maildir/allen-p/inbox/1.',)\", 'UL\\xa1\\xfc\\x00\\x00\\x00\\x00\\x00\\x00': '{}'}}\n\n[2017-02-04 15:47:22,463: INFO/MainProcess] Connected to amqp://guest:**@localhost:5672//\n[2017-02-04 15:47:22,473: INFO/MainProcess] mingle: searching for neighbors\n[2017-02-04 15:47:23,503: INFO/MainProcess] mingle: sync with 2 nodes\n[2017-02-04 15:47:23,504: INFO/MainProcess] mingle: sync complete\n[2017-02-04 15:47:23,530: INFO/MainProcess] parse@centos1 ready.\n[2017-02-04 15:47:24,890: INFO/MainProcess] sync with es_deploy@centos1\n[2017-02-04 15:47:51,017: WARNING/MainProcess] Received and deleted unknown message. Wrong destination?!?\n\nThe full contents of the message body was: body: [[u'maildir/allen-p/inbox/1.'], {}, {u'errbacks': None, u'callbacks': None, u'chord': None, u'chain': [{u'chord_size': None, u'task': u'celery.group', u'args': [], u'immutable': False, u'subtask_type': u'group', u'kwargs': {u'tasks': [{u'chord_size': None, u'task': u'proj.tasks.deploy_db', u'args': [], u'options': {u'reply_to': u'bd66dd5c-516d-3b51-ab40-c8337a33b18e', u'task_id': u'765e5bbe-198f-405c-b10c-023d35e03981'}, u'subtask_type': None, u'kwargs': {}, u'immutable': False}, {u'chord_size': None, u'task': u'proj.tasks.deploy_es', u'args': [], u'options': {u'reply_to': u'bd66dd5c-516d-3b51-ab40-c8337a33b18e', u'task_id': u'7dacb897-d023-40b5-9874-e00b75107bbd'}, u'subtask_type': None, u'kwargs': {}, u'immutable': False}]}, u'options': {u'parent_id': None, u'task_id': u'f0d41289-33e2-4c8c-8d84-9d1d4c5a9c80', u'root_id': None}}]}] (801b)\n{content_type:'application/json' content_encoding:'utf-8'\n delivery_info:{'consumer_tag': 'None4', 'redelivered': False, 'routing_key': 'parse', 'delivery_tag': 3L, 'exchange': ''} headers={'\\xe5\\xca.\\xdb\\x00\\x00\\x00\\x00\\x00': None, 'P&5\\x07\\x00': None, 'T\\nKB\\x00\\x00\\x00': '4d7754ed-0e36-4731-ae99-a84f42b8eba1', 'N\\xfd\\x17=\\x00\\x00': 'gen19722@centos1', '\\xcfb\\xddR': 'py', '9*\\xa8': None, '\\xb7/b\\x84\\x00\\x00\\x00': 0, '\\xe0\\x0b\\xfa\\x89\\x00\\x00\\x00': None, '\\xdfR\\xc4x\\x00\\x00\\x00\\x00\\x00': [None, None], 'T3\\x1d ': 'proj.tasks.parse', '\\xae\\xbf': '4d7754ed-0e36-4731-ae99-a84f42b8eba1', '\\x11s\\x1f\\xd8\\x00\\x00\\x00\\x00': \"('maildir/allen-p/inbox/1.',)\", 'UL\\xa1\\xfc\\x00\\x00\\x00\\x00\\x00\\x00': '{}'}}\n \nenter code here\n```\n\n========================================\n\nTop Answer:\nJust so that the answer is located here as well. In the thread Anis refers to 23doors mentions that Celery 4's new default protocol does not play nice with `librabbitmq`:\n\n Apparently librabbitmq issue is related to new default protocol in celery 4.x. \n\nHe also mentions that to resolve this issue you can make use of the older protocol Celery offers by setting (if you're using Django):\n\n```\nCELERY_TASK_PROTOCOL = 1\n```\n\nOtherwise you can set the following in your `celeryconf.py` file \n\n```\napp.conf.task_protocol = 1\n```\n\nAll credit to 23doors :)\n\n========================================\n\nCode:\n```text\napp = Celery('proj',\n broker='amqp://',\n backend='redis://localhost',\n include=['proj.tasks'])\n```\n\n```text\n[2017-02-04 14:28:06,909: WARNING/MainProcess] Received and deleted unknown message. Wrong destination?!?\n\n\n\n The full contents of the message body was: body: [[u'maildir/allen- p/inbox/1.'], {}, {u'errbacks': None, u'callbacks': None, u'chord': None, u'chain': [{u'chord_size': None, u'task': u'celery.group', u'args': [], u'immutable': False, u'subtask_type': u'group', u'kwargs': {u'tasks': [{u'chord_size': None, u'task': u'proj.tasks.deploy_db', u'args': [], u'options': {u'reply_to': u'3d9de118-f9d0-3bee-9972-b6a4d4482446', u'task_id': u'3cafda16-3e7c-44db-b05e-1327ef97ffc3'}, u'subtask_type': None, u'kwargs': {}, u'immutable': False}, {u'chord_size': None, u'task': u'proj.tasks.deploy_es', u'args': [], u'options': {u'reply_to': u'3d9de118-f9d0-3bee-9972-b6a4d4482446', u'task_id': u'1f4c728b-680d-4dde-98b9-b153d5282780'}, u'subtask_type': None, u'kwargs': {}, u'immutable': False}]}, u'options': {u'parent_id': None, u'task_id': u'f21c911e-f2ac-462e-9662-2efbd27bcf91', u'root_id': None}}]}] (801b)\n{content_type:'application/json' content_encoding:'utf-8'\n delivery_info:{'consumer_tag': 'None4', 'redelivered': False, 'routing_key': 'parse', 'delivery_tag': 623422L, 'exchange': ''} headers={'\\xe5\\xca.\\xdb\\x00\\x00\\x00\\x00\\x00': None, 'P&5\\x07\\x00': None, 'T\\nKB\\x00\\x00\\x00': 'fc8f0bed-665f-4699-89dd-a56fc247ea8b', 'N\\xfd\\x17=\\x00\\x00': 'gen17347@centos1', '\\xcfb\\xddR': 'py', '9*\\xa8': None, '\\xb7/b\\x84\\x00\\x00\\x00': 0, '\\xe0\\x0b\\xfa\\x89\\x00\\x00\\x00': None, '\\xdfR\\xc4x\\x00\\x00\\x00\\x00\\x00': [None, None], 'T3\\x1d ': 'proj.tasks.parse', '\\xae\\xbf': 'fc8f0bed-665f-4699-89dd-a56fc247ea8b', '\\x11s\\x1f\\xd8\\x00\\x00\\x00\\x00': \"('maildir/allen-p/inbox/1.',)\", 'UL\\xa1\\xfc\\x00\\x00\\x00\\x00\\x00\\x00': '{}'}}\n\n\n[2017-02-04 15:47:22,463: INFO/MainProcess] Connected to amqp://guest:**@localhost:5672//\n[2017-02-04 15:47:22,473: INFO/MainProcess] mingle: searching for neighbors\n[2017-02-04 15:47:23,503: INFO/MainProcess] mingle: sync with 2 nodes\n[2017-02-04 15:47:23,504: INFO/MainProcess] mingle: sync complete\n[2017-02-04 15:47:23,530: INFO/MainProcess] parse@centos1 ready.\n[2017-02-04 15:47:24,890: INFO/MainProcess] sync with es_deploy@centos1\n[2017-02-04 15:47:51,017: WARNING/MainProcess] Received and deleted unknown message. Wrong destination?!?\n\nThe full contents of the message body was: body: [[u'maildir/allen-p/inbox/1.'], {}, {u'errbacks': None, u'callbacks': None, u'chord': None, u'chain': [{u'chord_size': None, u'task': u'celery.group', u'args': [], u'immutable': False, u'subtask_type': u'group', u'kwargs': {u'tasks': [{u'chord_size': None, u'task': u'proj.tasks.deploy_db', u'args': [], u'options': {u'reply_to': u'bd66dd5c-516d-3b51-ab40-c8337a33b18e', u'task_id': u'765e5bbe-198f-405c-b10c-023d35e03981'}, u'subtask_type': None, u'kwargs': {}, u'immutable': False}, {u'chord_size': None, u'task': u'proj.tasks.deploy_es', u'args': [], u'options': {u'reply_to': u'bd66dd5c-516d-3b51-ab40-c8337a33b18e', u'task_id': u'7dacb897-d023-40b5-9874-e00b75107bbd'}, u'subtask_type': None, u'kwargs': {}, u'immutable': False}]}, u'options': {u'parent_id': None, u'task_id': u'f0d41289-33e2-4c8c-8d84-9d1d4c5a9c80', u'root_id': None}}]}] (801b)\n{content_type:'application/json' content_encoding:'utf-8'\n delivery_info:{'consumer_tag': 'None4', 'redelivered': False, 'routing_key': 'parse', 'delivery_tag': 3L, 'exchange': ''} headers={'\\xe5\\xca.\\xdb\\x00\\x00\\x00\\x00\\x00': None, 'P&5\\x07\\x00': None, 'T\\nKB\\x00\\x00\\x00': '4d7754ed-0e36-4731-ae99-a84f42b8eba1', 'N\\xfd\\x17=\\x00\\x00': 'gen19722@centos1', '\\xcfb\\xddR': 'py', '9*\\xa8': None, '\\xb7/b\\x84\\x00\\x00\\x00': 0, '\\xe0\\x0b\\xfa\\x89\\x00\\x00\\x00': None, '\\xdfR\\xc4x\\x00\\x00\\x00\\x00\\x00': [None, None], 'T3\\x1d ': 'proj.tasks.parse', '\\xae\\xbf': '4d7754ed-0e36-4731-ae99-a84f42b8eba1', '\\x11s\\x1f\\xd8\\x00\\x00\\x00\\x00': \"('maildir/allen-p/inbox/1.',)\", 'UL\\xa1\\xfc\\x00\\x00\\x00\\x00\\x00\\x00': '{}'}}\n \nenter code here\n```\n\n```text\npip uninstall librabbitmq\n```\n\n```text\namqp\n```\n\n```text\npyamqp\n```\n\n```text\nCelery(...)\n```\n\n```text\nsend_task\n```\n\n```text\napply_async\n```\n\n```text\nConsumer\n```\n\n```text\ncreate_task_handler\n```\n\n```text\non_task_received\n```\n\n```text\nTypeError\n```\n\n```text\non_task_received\n```\n\n```text\nCELERY_TASK_PROTOCOL = 1\n```\n\n```text\napp.conf.task_protocol = 1\n```\n\n```text\nlibrabbitmq\n```\n\n```text\nceleryconf.py\n```\n\n========================================\n\nComments:\n- Hi Anis: It is really so nice of you to help me on this question! I must call you Mr Fantastic ! 1) pip2.7 install librabbitmq-1.6.1.tar.gz 2)pip2.7 install celery-4.0.2.tar.gz . That is exactly the software version I have installed!I have followed your advice! And now My project do work now! I am so happy tonight! That a nice friend Anis help me on this issue!\n- In 2018/11/23 with celery=4.2.1 and redis=3.0.1 this solution works\n- In 2021/06/15 with trying to invoke a task in celery=3.x from a modern codebase using celery=5.x, this solution works.","metadata":{"transformedAt":"2026-08-18T18:33:20.182Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":17,"totalLines":197,"estimatedTokens":2887}}672{"id":"stack-29649545","source":"stackoverflow","questionId":29649545,"title":"Manually ack messages in RabbitMQ","tags":["rabbitmq","spring-amqp","spring-rabbit"],"text":"Title: Manually ack messages in RabbitMQ\nTags: rabbitmq, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nPreviously I was reading all the messages present in the queue, but now I have to return specific amount of message based of users choice(count).\n\nI try to change the for loop accordingly but its reading all the message because of auto acknowledge. So I tried changing it to manual in config file.\n\nIn my program how to ack message manually after reading msg(currently i am using AmqpTemplate to receive and i don't have reference of channel)?\n\n```\nProperties properties = admin.getQueueProperties(\"queue_name\");\n if(null != properties)\n {\n Integer messageCount = Integer.parseInt(properties.get(\"QUEUE_MESSAGE_COUNT\").toString()); \n while(messageCount > 0)\n {\n Message msg = amqpTemplate.receive(queue_name);\n String value = new String(msg.getBody());\n \n valueList.add(value);\n messageCount--;\n }\n}\n```\n\nAny help is highly appreciable, Thanks in advance.\n\n========================================\n\nCode:\n```text\nProperties properties = admin.getQueueProperties(\"queue_name\");\n if(null != properties)\n {\n Integer messageCount = Integer.parseInt(properties.get(\"QUEUE_MESSAGE_COUNT\").toString()); \n while(messageCount > 0)\n {\n Message msg = amqpTemplate.receive(queue_name);\n String value = new String(msg.getBody());\n \n valueList.add(value);\n messageCount--;\n }\n}\n```\n\n```text\nfinal int messageCount = 3;\n boolean result = template.execute(new ChannelCallback<Boolean>() {\n\n @Override\n public Boolean doInRabbit(final Channel channel) throws Exception {\n int n = messageCount;\n channel.basicQos(messageCount); // prefetch\n long deliveryTag = 0;\n while (n > 0) {\n GetResponse result = channel.basicGet(\"si.test.queue\", false);\n if (result != null) {\n System.out.println(new String(result.getBody()));\n deliveryTag = result.getEnvelope().getDeliveryTag();\n n--;\n }\n else {\n Thread.sleep(1000);\n }\n }\n if (deliveryTag > 0) {\n channel.basicAck(deliveryTag, true);\n }\n return true;\n }\n });\n```\n\n```text\nreceive()\n```\n\n```text\nSimpleMessageListenerContainer\n```\n\n```text\nChannelAwareMessageListener\n```\n\n```text\nexecute()\n```\n\n```text\nChannel\n```\n\n```text\nMessage\n```\n\n========================================\n\nComments:\n- `AmqpTemplate#receive` autoack the message unless the channel is transacted. To control acknowledgement you could use `AmqpTemplate#execute` and do by hand the receive or the best way is to use a `SimpleMessageListenerContainer` or even a `BlockingQueueConsumer`\n- @NicolasLabrot I didn't find execute method in AmqpTemplate, are you referring to something else. Yes i did set setAcknowledgeMode to MANUAL in SimpleMessageListenerContainer.\n- Sorry, I refer to `RabbitTemplate#execute` which is an implementation of `AmqpTemplate`\n- @NicolasLabrot could you please through some light on this. What is ChannelCallback, looks like I need a reference of channel which i don't have.\n- Have a look at the `RabbitTemplate#receive` code but I do not think it is the right way.\n- GaryRussell could you please point any sample code of how to use execute(), I am very new to this and i don't have much forum on this.Thanks in advance\n- It is customary to mark the answer as accepted (click the check mark) if it answers your question. This will help other users searching for the same answer.\n- @GaryRussell if we use the receive* methods, does Spring use the NONE mode or AUTO mode? meaning, is it letting RabbitMQ consider the messages to be auto-delivered or Spring does the ACK after reception of the message?\n- Don't ask new questions in comments, especially on a six-year-old answer. Ack mode only applies to listener containers. The template calls `basicAck` before returning. If you want to reject and requeue the message, you have to run the `receive()` method in a transaction and throw an exception so the `basicAck` is rolled back and the message will be requeued.","metadata":{"transformedAt":"2026-08-18T18:33:20.182Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":112,"estimatedTokens":1070}}673{"id":"stack-19576092","source":"stackoverflow","questionId":19576092,"title":"What happens when RabbitMQ's Delivery Tag overflows?","tags":["rabbitmq","amqp"],"text":"Title: What happens when RabbitMQ's Delivery Tag overflows?\nTags: rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nRabbitMQ uses a non-negative long (63-bit integer, because non-negative only) called a delivery tag to store how many messages have been sent over a channel. What happens if you send (2^63)+1 messages over a channel?\n\n========================================\n\nComments:\n- Yes I know it would be unlikely to send this many messages. I was interested in what happens if you were to. While we can both imagine what happens, I was looking to see if anyone already knew or could point me to a reference.\n- Not \"unlikely\" - impossible, given your definition of the problem. But, I did attempt to theorize in the second part of my answer :) It may be that one could set up a test, whereby the integer value was deliberately set to (MaxValue-1) or sometthing, although I think it would be an academic exercise.\n- In java client, for example, you would have this fragment of `basicPublish` function `if (nextPublishSeqNo > 0) { unconfirmedSet.add(getNextPublishSeqNo()); nextPublishSeqNo++; }` with a negative long so it will never add it to the unconfirmedSet and never add 1 to get the next so I suppose you would get the same id and have related problems to it.","metadata":{"transformedAt":"2026-08-18T18:33:20.182Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":13,"estimatedTokens":318}}674{"id":"stack-54749693","source":"stackoverflow","questionId":54749693,"title":"amqplib: Socket closed abruptly during opening handshake","tags":["node.js","rabbitmq","node-amqplib"],"text":"Title: amqplib: Socket closed abruptly during opening handshake\nTags: node.js, rabbitmq, node-amqplib\nSource: Stack Overflow\n\nQuestion:\n### What I am trying to do\n\nI try to create rabbit-mq publisher & subscriber. It works as expected until I try to restart my rabbit-mq server.\n\n### What works\n\nI use `rabbitmq:3-management` docker image, `ampqlib 5.3`, and Node.js `11.10.0` to make this simple program:\n\n```\nconst q = 'tasks';\n\nconst { execSync } = require(\"child_process\");\nconst amqplib = require(\"amqplib\");\n\nfunction createChannel() {\n return amqplib.connect(\"amqp://root:toor@0.0.0.0:5672/\")\n .then((conn) => conn.createChannel());\n}\n\nPromise.all([createChannel(), createChannel()])\n\n .then(async (channels) => {\n const [publisherChannel, consumerChannel] = channels;\n\n // publisher\n await publisherChannel.assertQueue(q).then(function(ok) {\n return publisherChannel.sendToQueue(q, Buffer.from(\"something to do\"));\n });\n\n // consumer\n await consumerChannel.assertQueue(q).then(function(ok) {\n return consumerChannel.consume(q, function(msg) {\n if (msg !== null) {\n console.log(msg.content.toString());\n consumerChannel.ack(msg);\n }\n });\n });\n\n })\n\n .catch(console.warn);\n```\n\nSo, first of all, I made two channels. One as publisher, and the other as consumer.\n\nThe publisher emit `something to do` message to `tasks` queue.\n\nThe consumer then catch the message and print it to the screen using `console.log`.\n\nIt works as expected.\n\n### What doesn't work\n\n### First Attempt\n\n```\nconst q = 'tasks';\n\nconst { execSync } = require(\"child_process\");\nconst amqplib = require(\"amqplib\");\n\nfunction createChannel() {\n return amqplib.connect(\"amqp://root:toor@0.0.0.0:5672/\")\n .then((conn) => conn.createChannel());\n}\n\nPromise.all([createChannel(), createChannel()])\n\n .then((channels) => {\n\n // Let's say rabbitmq is down, and then up again\n execSync(\"docker stop rabbitmq\");\n execSync(\"docker start rabbitmq\");\n\n return channels;\n })\n\n .then(async (channels) => {\n const [publisherChannel, consumerChannel] = channels;\n\n // publisher\n await publisherChannel.assertQueue(q).then(function(ok) {\n return publisherChannel.sendToQueue(q, Buffer.from(\"something to do\"));\n });\n\n // consumer\n await consumerChannel.assertQueue(q).then(function(ok) {\n return consumerChannel.consume(q, function(msg) {\n if (msg !== null) {\n console.log(msg.content.toString());\n consumerChannel.ack(msg);\n }\n });\n });\n\n })\n\n .catch(console.warn);\n```\n\nSimilar to my previous attempt, but this time I try to stop and start rabbit-mq container (restarting the server) before proceed.\n\nIt doesn't work, I get this error instead:\n\n```\n{ Error: Socket closed abruptly during opening handshake\n at Socket.endWhileOpening (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:260:17) \n at Socket.emit (events.js:202:15)\n at endReadableNT (_stream_readable.js:1129:12)\n at processTicksAndRejections (internal/process/next_tick.js:76:17)\n cause:\n Error: Socket closed abruptly during opening handshake\n at Socket.endWhileOpening (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:260:17) \n at Socket.emit (events.js:202:15)\n at endReadableNT (_stream_readable.js:1129:12)\n at processTicksAndRejections (internal/process/next_tick.js:76:17),\n isOperational: true }\n[guldan@draenor labs]$ node --version\nv11.10.0\n[guldan@draenor labs]$ docker start rabbitmq && node test.js\nrabbitmq\n{ Error: Channel ended, no reply will be forthcoming\n at rej (/home/guldan/Projects/node_modules/amqplib/lib/channel.js:195:7) \n at Channel.C._rejectPending (/home/guldan/Projects/node_modules/amqplib/lib/channel.js:197:28) \n at Channel.C.toClosed (/home/guldan/Projects/node_modules/amqplib/lib/channel.js:165:8) \n at Connection.C._closeChannels (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:394:18) \n at Connection.C.toClosed (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:401:8) \n at Object.accept (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:96:18) \n at Connection.mainAccept [as accept] (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:64:33) \n at Socket.go (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:478:48) \n at Socket.emit (events.js:197:13)\n at emitReadable_ (_stream_readable.js:539:12)\n at processTicksAndRejections (internal/process/next_tick.js:76:17)\n cause:\n Error: Channel ended, no reply will be forthcoming\n at rej (/home/guldan/Projects/node_modules/amqplib/lib/channel.js:195:7) \n at Channel.C._rejectPending (/home/guldan/Projects/node_modules/amqplib/lib/channel.js:197:28) \n at Channel.C.toClosed (/home/guldan/Projects/node_modules/amqplib/lib/channel.js:165:8) \n at Connection.C._closeChannels (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:394:18) \n at Connection.C.toClosed (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:401:8) \n at Object.accept (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:96:18) \n at Connection.mainAccept [as accept] (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:64:33) \n at Socket.go (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:478:48) \n at Socket.emit (events.js:197:13)\n at emitReadable_ (_stream_readable.js:539:12)\n at processTicksAndRejections (internal/process/next_tick.js:76:17),\n isOperational: true }\n```\n\n### Second attempt\n\nMy first attempt didn't work. So, I try to create new channel after restarting the server:\n\n```\nconst q = 'tasks';\n\nconst { execSync } = require(\"child_process\");\nconst amqplib = require(\"amqplib\");\n\nfunction createChannel() {\n return amqplib.connect(\"amqp://root:toor@0.0.0.0:5672/\")\n .then((conn) => conn.createChannel());\n}\n\nPromise.all([createChannel(), createChannel()])\n\n .then((channels) => {\n\n // Let's say rabbitmq is down, and then up again\n execSync(\"docker stop rabbitmq\");\n execSync(\"docker start rabbitmq\");\n\n return Promise.all([createChannel(), createChannel()]);\n // return channels;\n })\n\n .then(async (channels) => {\n const [publisherChannel, consumerChannel] = channels;\n\n // publisher\n await publisherChannel.assertQueue(q).then(function(ok) {\n return publisherChannel.sendToQueue(q, Buffer.from(\"something to do\"));\n });\n\n // consumer\n await consumerChannel.assertQueue(q).then(function(ok) {\n return consumerChannel.consume(q, function(msg) {\n if (msg !== null) {\n console.log(msg.content.toString());\n consumerChannel.ack(msg);\n }\n });\n });\n\n })\n\n .catch(console.warn);\n```\n\nAnd this time, I got this error instead:\n\n```\n{ Error: Socket closed abruptly during opening handshake\n at Socket.endWhileOpening (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:260:17) \n at Socket.emit (events.js:202:15)\n at endReadableNT (_stream_readable.js:1129:12)\n at processTicksAndRejections (internal/process/next_tick.js:76:17)\n cause:\n Error: Socket closed abruptly during opening handshake\n at Socket.endWhileOpening (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:260:17) \n at Socket.emit (events.js:202:15)\n at endReadableNT (_stream_readable.js:1129:12)\n at processTicksAndRejections (internal/process/next_tick.js:76:17),\n isOperational: true }\n```\n\nI'm not really sure, but I think the error is related to It might be related to https://github.com/squaremo/amqp.node/issues/101.\n\n### What I want\n\nI want workaround/solution to reconnect to rabbitmq after the server restarted. Any explanation/suggestion is also welcomed.\n\n### Edit\n\nI try to go deeper and modify my code a bit:\n\n```\nconst q = 'tasks';\n\nconst { execSync } = require(\"child_process\");\nconst amqplib = require(\"amqplib\");\n\nasync function createConnection() {\n console.log(\"connect\");\n const conn = amqplib.connect(\"amqp://root:toor@0.0.0.0:5672/\");\n console.log(\"connected\");\n return conn;\n}\n\nasync function createChannel(conn) {\n console.log(\"create channel\");\n const channel = conn.createChannel({durable: false});\n console.log(\"channel created\");\n return channel;\n}\n\nasync function createConnectionAndChannel() {\n const conn = await createConnection();\n const channel = await createChannel(conn);\n return channel;\n}\n\nPromise.all([createConnectionAndChannel(), createConnectionAndChannel()])\n\n .then((channels) => {\n\n // Let's say rabbitmq is down, and then up again\n console.log(\"restart server\");\n execSync(\"docker stop rabbitmq\");\n execSync(\"docker start rabbitmq\");\n console.log(\"server restarted\");\n\n return Promise.all([createConnectionAndChannel(), createConnectionAndChannel()]);\n // return channels;\n })\n\n .then(async (channels) => {\n console.log(\"channels created\");\n const [publisherChannel, consumerChannel] = channels;\n\n // publisher\n console.log(\"publish\");\n await publisherChannel.assertQueue(q).then(function(ok) {\n console.log(\"published\");\n return publisherChannel.sendToQueue(q, Buffer.from(\"something to do\"));\n });\n\n // consumer\n console.log(\"consume\");\n await consumerChannel.assertQueue(q).then(function(ok) {\n console.log(\"consumed\");\n return consumerChannel.consume(q, function(msg) {\n if (msg !== null) {\n console.log(msg.content.toString());\n consumerChannel.ack(msg);\n }\n });\n });\n\n })\n\n .catch(console.warn);\n```\n\nAnd I get this output:\n\n```\nconnect\nconnected\nconnect\nconnected\ncreate channel\nchannel created\ncreate channel\nchannel created\nrestart server\nserver restarted\nconnect\nconnected\nconnect\nconnected\n{ Error: Socket closed abruptly during opening handshake\n at Socket.endWhileOpening (/home/guldan/Projects/kata/merapi-plugin-service-rabbit/node_modules/amqplib/lib/connection.js:260:17) \n at Socket.emit (events.js:202:15)\n at endReadableNT (_stream_readable.js:1129:12)\n at processTicksAndRejections (internal/process/next_tick.js:76:17)\n cause:\n Error: Socket closed abruptly during opening handshake\n at Socket.endWhileOpening (/home/guldan/Projects/kata/merapi-plugin-service-rabbit/node_modules/amqplib/lib/connection.js:260:17) \n at Socket.emit (events.js:202:15)\n at endReadableNT (_stream_readable.js:1129:12)\n at processTicksAndRejections (internal/process/next_tick.js:76:17),\n isOperational: true }\n```\n\nSo I guess amqplib is **able to re-connect** but **fail to create channel**.\n\n========================================\n\nTop Answer:\nFor any future users who might be having this issue:\n\nMake sure the `port` is set to `5672` ( `local amqp server`) and not `15672` (`amqp web management console`).\n\n========================================\n\nCode:\n```text\nconst q = 'tasks';\n\nconst { execSync } = require(\"child_process\");\nconst amqplib = require(\"amqplib\");\n\nfunction createChannel() {\n return amqplib.connect(\"amqp://root:toor@0.0.0.0:5672/\")\n .then((conn) => conn.createChannel());\n}\n\nPromise.all([createChannel(), createChannel()])\n\n .then(async (channels) => {\n const [publisherChannel, consumerChannel] = channels;\n\n // publisher\n await publisherChannel.assertQueue(q).then(function(ok) {\n return publisherChannel.sendToQueue(q, Buffer.from(\"something to do\"));\n });\n\n // consumer\n await consumerChannel.assertQueue(q).then(function(ok) {\n return consumerChannel.consume(q, function(msg) {\n if (msg !== null) {\n console.log(msg.content.toString());\n consumerChannel.ack(msg);\n }\n });\n });\n\n })\n\n .catch(console.warn);\n```\n\n```text\nconst q = 'tasks';\n\nconst { execSync } = require(\"child_process\");\nconst amqplib = require(\"amqplib\");\n\nfunction createChannel() {\n return amqplib.connect(\"amqp://root:toor@0.0.0.0:5672/\")\n .then((conn) => conn.createChannel());\n}\n\nPromise.all([createChannel(), createChannel()])\n\n .then((channels) => {\n\n // Let's say rabbitmq is down, and then up again\n execSync(\"docker stop rabbitmq\");\n execSync(\"docker start rabbitmq\");\n\n return channels;\n })\n\n .then(async (channels) => {\n const [publisherChannel, consumerChannel] = channels;\n\n // publisher\n await publisherChannel.assertQueue(q).then(function(ok) {\n return publisherChannel.sendToQueue(q, Buffer.from(\"something to do\"));\n });\n\n // consumer\n await consumerChannel.assertQueue(q).then(function(ok) {\n return consumerChannel.consume(q, function(msg) {\n if (msg !== null) {\n console.log(msg.content.toString());\n consumerChannel.ack(msg);\n }\n });\n });\n\n })\n\n .catch(console.warn);\n```\n\n```text\n{ Error: Socket closed abruptly during opening handshake\n at Socket.endWhileOpening (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:260:17) \n at Socket.emit (events.js:202:15)\n at endReadableNT (_stream_readable.js:1129:12)\n at processTicksAndRejections (internal/process/next_tick.js:76:17)\n cause:\n Error: Socket closed abruptly during opening handshake\n at Socket.endWhileOpening (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:260:17) \n at Socket.emit (events.js:202:15)\n at endReadableNT (_stream_readable.js:1129:12)\n at processTicksAndRejections (internal/process/next_tick.js:76:17),\n isOperational: true }\n[guldan@draenor labs]$ node --version\nv11.10.0\n[guldan@draenor labs]$ docker start rabbitmq && node test.js\nrabbitmq\n{ Error: Channel ended, no reply will be forthcoming\n at rej (/home/guldan/Projects/node_modules/amqplib/lib/channel.js:195:7) \n at Channel.C._rejectPending (/home/guldan/Projects/node_modules/amqplib/lib/channel.js:197:28) \n at Channel.C.toClosed (/home/guldan/Projects/node_modules/amqplib/lib/channel.js:165:8) \n at Connection.C._closeChannels (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:394:18) \n at Connection.C.toClosed (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:401:8) \n at Object.accept (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:96:18) \n at Connection.mainAccept [as accept] (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:64:33) \n at Socket.go (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:478:48) \n at Socket.emit (events.js:197:13)\n at emitReadable_ (_stream_readable.js:539:12)\n at processTicksAndRejections (internal/process/next_tick.js:76:17)\n cause:\n Error: Channel ended, no reply will be forthcoming\n at rej (/home/guldan/Projects/node_modules/amqplib/lib/channel.js:195:7) \n at Channel.C._rejectPending (/home/guldan/Projects/node_modules/amqplib/lib/channel.js:197:28) \n at Channel.C.toClosed (/home/guldan/Projects/node_modules/amqplib/lib/channel.js:165:8) \n at Connection.C._closeChannels (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:394:18) \n at Connection.C.toClosed (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:401:8) \n at Object.accept (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:96:18) \n at Connection.mainAccept [as accept] (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:64:33) \n at Socket.go (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:478:48) \n at Socket.emit (events.js:197:13)\n at emitReadable_ (_stream_readable.js:539:12)\n at processTicksAndRejections (internal/process/next_tick.js:76:17),\n isOperational: true }\n```\n\n```text\nconst q = 'tasks';\n\nconst { execSync } = require(\"child_process\");\nconst amqplib = require(\"amqplib\");\n\nfunction createChannel() {\n return amqplib.connect(\"amqp://root:toor@0.0.0.0:5672/\")\n .then((conn) => conn.createChannel());\n}\n\nPromise.all([createChannel(), createChannel()])\n\n .then((channels) => {\n\n // Let's say rabbitmq is down, and then up again\n execSync(\"docker stop rabbitmq\");\n execSync(\"docker start rabbitmq\");\n\n return Promise.all([createChannel(), createChannel()]);\n // return channels;\n })\n\n .then(async (channels) => {\n const [publisherChannel, consumerChannel] = channels;\n\n // publisher\n await publisherChannel.assertQueue(q).then(function(ok) {\n return publisherChannel.sendToQueue(q, Buffer.from(\"something to do\"));\n });\n\n // consumer\n await consumerChannel.assertQueue(q).then(function(ok) {\n return consumerChannel.consume(q, function(msg) {\n if (msg !== null) {\n console.log(msg.content.toString());\n consumerChannel.ack(msg);\n }\n });\n });\n\n })\n\n .catch(console.warn);\n```\n\n```text\n{ Error: Socket closed abruptly during opening handshake\n at Socket.endWhileOpening (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:260:17) \n at Socket.emit (events.js:202:15)\n at endReadableNT (_stream_readable.js:1129:12)\n at processTicksAndRejections (internal/process/next_tick.js:76:17)\n cause:\n Error: Socket closed abruptly during opening handshake\n at Socket.endWhileOpening (/home/guldan/Projects/node_modules/amqplib/lib/connection.js:260:17) \n at Socket.emit (events.js:202:15)\n at endReadableNT (_stream_readable.js:1129:12)\n at processTicksAndRejections (internal/process/next_tick.js:76:17),\n isOperational: true }\n```\n\n```text\nconst q = 'tasks';\n\nconst { execSync } = require(\"child_process\");\nconst amqplib = require(\"amqplib\");\n\nasync function createConnection() {\n console.log(\"connect\");\n const conn = amqplib.connect(\"amqp://root:toor@0.0.0.0:5672/\");\n console.log(\"connected\");\n return conn;\n}\n\nasync function createChannel(conn) {\n console.log(\"create channel\");\n const channel = conn.createChannel({durable: false});\n console.log(\"channel created\");\n return channel;\n}\n\nasync function createConnectionAndChannel() {\n const conn = await createConnection();\n const channel = await createChannel(conn);\n return channel;\n}\n\nPromise.all([createConnectionAndChannel(), createConnectionAndChannel()])\n\n .then((channels) => {\n\n // Let's say rabbitmq is down, and then up again\n console.log(\"restart server\");\n execSync(\"docker stop rabbitmq\");\n execSync(\"docker start rabbitmq\");\n console.log(\"server restarted\");\n\n return Promise.all([createConnectionAndChannel(), createConnectionAndChannel()]);\n // return channels;\n })\n\n .then(async (channels) => {\n console.log(\"channels created\");\n const [publisherChannel, consumerChannel] = channels;\n\n // publisher\n console.log(\"publish\");\n await publisherChannel.assertQueue(q).then(function(ok) {\n console.log(\"published\");\n return publisherChannel.sendToQueue(q, Buffer.from(\"something to do\"));\n });\n\n // consumer\n console.log(\"consume\");\n await consumerChannel.assertQueue(q).then(function(ok) {\n console.log(\"consumed\");\n return consumerChannel.consume(q, function(msg) {\n if (msg !== null) {\n console.log(msg.content.toString());\n consumerChannel.ack(msg);\n }\n });\n });\n\n })\n\n .catch(console.warn);\n```\n\n```text\nconnect\nconnected\nconnect\nconnected\ncreate channel\nchannel created\ncreate channel\nchannel created\nrestart server\nserver restarted\nconnect\nconnected\nconnect\nconnected\n{ Error: Socket closed abruptly during opening handshake\n at Socket.endWhileOpening (/home/guldan/Projects/kata/merapi-plugin-service-rabbit/node_modules/amqplib/lib/connection.js:260:17) \n at Socket.emit (events.js:202:15)\n at endReadableNT (_stream_readable.js:1129:12)\n at processTicksAndRejections (internal/process/next_tick.js:76:17)\n cause:\n Error: Socket closed abruptly during opening handshake\n at Socket.endWhileOpening (/home/guldan/Projects/kata/merapi-plugin-service-rabbit/node_modules/amqplib/lib/connection.js:260:17) \n at Socket.emit (events.js:202:15)\n at endReadableNT (_stream_readable.js:1129:12)\n at processTicksAndRejections (internal/process/next_tick.js:76:17),\n isOperational: true }\n```\n\n```text\nrabbitmq:3-management\n```\n\n```text\nampqlib 5.3\n```\n\n```text\n11.10.0\n```\n\n```text\nsomething to do\n```\n\n```text\ntasks\n```\n\n```text\nconsole.log\n```\n\n```text\nconst { execSync } = require(\"child_process\");\nconst amqp = require(\"amqplib\");\n\nasync function sleep(delay) {\n return new Promise((resolve, reject) => {\n setTimeout(resolve, delay);\n });\n}\n\nasync function createChannel(config) {\n const { url, publishers, listeners } = Object.assign({url: \"\", publishers: {}, listeners: {}}, config);\n try {\n // create connection\n const connection = await amqp.connect(url);\n let channel = null;\n connection._channels = [];\n connection.on(\"error\", (error) => {\n console.error(\"Connection error : \", config, error);\n });\n connection.on(\"close\", async (error) => {\n if (channel) {\n channel.close();\n }\n console.error(\"Connection close : \", config, error);\n await sleep(1000);\n createChannel(config);\n });\n // create channel\n channel = await connection.createConfirmChannel();\n channel.on(\"error\", (error) => {\n console.error(\"Channel error : \", config, error);\n });\n channel.on(\"close\", (error) => {\n console.error(\"Channel close : \", config, error);\n });\n // register listeners\n for (queue in listeners) {\n const callback = listeners[queue];\n channel.assertQueue(queue, { durable: false });\n channel.consume(queue, callback);\n }\n // publish\n for (queue in publishers) {\n const message = publishers[queue];\n channel.assertQueue(queue, { durable: false });\n channel.sendToQueue(queue, message);\n }\n return channel;\n } catch (error) {\n console.error(\"Create connection error : \", error);\n await sleep(1000);\n createChannel(config);\n }\n}\n\nasync function main() {\n // publish \"hello\" message to queue\n const channelPublish = await createChannel({\n url: \"amqp://root:toor@0.0.0.0:5672\",\n publishers: {\n \"queue\": Buffer.from(\"hello\"),\n }\n });\n\n // restart rabbitmq\n execSync(\"docker stop rabbitmq\");\n execSync(\"docker start rabbitmq\");\n\n // consume message from queue\n const channelConsume = await createChannel({\n url: \"amqp://root:toor@0.0.0.0:5672\",\n listeners: {\n \"queue\": (message) => {\n console.log(\"Receive message \", message.content.toString());\n },\n }\n });\n\n return true;\n}\n\nmain().catch((error) => console.error(error));\n```\n\n```text\ncreateChannel\n```\n\n```text\nport\n```\n\n```text\n5672\n```\n\n```text\nlocal amqp server\n```\n\n```text\n15672\n```\n\n```text\namqp web management console\n```\n\n========================================\n\nComments:\n- you can also use sape path but with other port like this: amqp://guest:guest@localhost:5672","metadata":{"transformedAt":"2026-08-18T18:33:20.182Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":20,"totalLines":764,"estimatedTokens":6108}}675{"id":"stack-32378364","source":"stackoverflow","questionId":32378364,"title":"RabbitMQ for NodeJS with Express routing","tags":["javascript","node.js","express","rabbitmq","amqp"],"text":"Title: RabbitMQ for NodeJS with Express routing\nTags: javascript, node.js, express, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nMy server is running NodeJS and uses the amqplib api to request data from another application. The NodeJS server is receiving the information successfully but there's a noticable delay and I'm trying to determine whether I am doing this in the most efficient manner. Specifically I'm concerned with the way that I open and close connections.\n \n**Project Layout**\n\nI have two controller files that handle receiving and requesting the data, request.img.server.controller.js and receive.img.server.controller.js. Finally the routes handle the controller methods when a button on the front end is pushed, oct.server.routes.js.\n\nrequest.img.server.controller.js\n\n```\n'use strict';\n\nvar amqp = require('amqplib/callback_api');\nvar connReady = false;\nvar conn, ch;\namqp.connect('amqp://localhost:5672', function(err, connection) {\n conn = connection;\n connReady = true;\n conn.createChannel(function(err, channel) {\n ch = channel;\n });\n});\n\nexports.sendRequest = function(message) {\n console.log('sending request');\n\n if(connReady) {\n var ex = '';\n var key = 'utils';\n\n ch.publish(ex, key, new Buffer(message));\n console.log(\" [x] Sent %s: '%s'\", key, message);\n }\n};\n```\n\nreceive.img.server.controller.js\n\n```\nvar amqp = require('amqplib/callback_api');\nvar fs = require('fs');\nvar wstream = fs.createWriteStream('C:\\\\Users\\\\yako\\\\desktop\\\\binarytest.txt');\n\nvar image, rows, cols;\nexports.getResponse = function(resCallback) {\n amqp.connect('amqp://localhost:5672', function(err, conn) {\n conn.createChannel(function(err, ch) {\n var ex = '';\n\n ch.assertQueue('server', {}, function(err, q) {\n console.log('waiting for images');\n var d = new Date();\n var n = d.getTime();\n ch.consume(q.queue, function(msg) {\n console.log(\" [x] %s: '%s'\", msg.fields.routingKey, msg.content.toJSON());\n rows = msg.content.readInt16LE(0);\n cols = msg.content.readInt16LE(2);\n console.log(\"rows = %s\", msg.content.readInt16LE(0));\n console.log(\"cols = %s\", msg.content.readInt16LE(2));\n image = msg.content;\n var currMax = 0;\n for (var i = 4; i currMax) {\n currMax = image.readInt16LE(i);\n }\n wstream.write(image.readInt16LE(i) + ',');\n }\n console.log('done writing max is', currMax);\n //console.log(image);\n resCallback(rows, cols, image);\n }, {\n noAck: true\n });\n });\n });\n });\n};\n```\n\noct.server.routes.js\n\n```\n'use strict';\n\nmodule.exports = function(app) {\n var request_img = require('../../app/controllers/image-tools/request.img.server.controller.js');\n var receive_img = require('../../app/controllers/image-tools/receive.img.server.controller.js');\n\n // oct routes\n app.get('/load_slice', function(req, res) {\n console.log('load slice hit');\n receive_img.getResponse(function (rows, cols, image) {\n res.end(image);\n });\n request_img.sendRequest('123:C:\\\\Users\\\\yako\\\\Documents\\\\Developer\\\\medicaldiag\\\\test_files\\\\RUS-01-035-09M-21.oct');\n });\n};\n```\n\n========================================\n\nCode:\n```text\n'use strict';\n\nvar amqp = require('amqplib/callback_api');\nvar connReady = false;\nvar conn, ch;\namqp.connect('amqp://localhost:5672', function(err, connection) {\n conn = connection;\n connReady = true;\n conn.createChannel(function(err, channel) {\n ch = channel;\n });\n});\n\n\nexports.sendRequest = function(message) {\n console.log('sending request');\n\n if(connReady) {\n var ex = '';\n var key = 'utils';\n\n ch.publish(ex, key, new Buffer(message));\n console.log(\" [x] Sent %s: '%s'\", key, message);\n }\n};\n```\n\n```text\nvar amqp = require('amqplib/callback_api');\nvar fs = require('fs');\nvar wstream = fs.createWriteStream('C:\\\\Users\\\\yako\\\\desktop\\\\binarytest.txt');\n\nvar image, rows, cols;\nexports.getResponse = function(resCallback) {\n amqp.connect('amqp://localhost:5672', function(err, conn) {\n conn.createChannel(function(err, ch) {\n var ex = '';\n\n ch.assertQueue('server', {}, function(err, q) {\n console.log('waiting for images');\n var d = new Date();\n var n = d.getTime();\n ch.consume(q.queue, function(msg) {\n console.log(\" [x] %s: '%s'\", msg.fields.routingKey, msg.content.toJSON());\n rows = msg.content.readInt16LE(0);\n cols = msg.content.readInt16LE(2);\n console.log(\"rows = %s\", msg.content.readInt16LE(0));\n console.log(\"cols = %s\", msg.content.readInt16LE(2));\n image = msg.content;\n var currMax = 0;\n for (var i = 4; i < image.length; i+=2) {\n if (image.readInt16LE(i) > currMax) {\n currMax = image.readInt16LE(i);\n }\n wstream.write(image.readInt16LE(i) + ',');\n }\n console.log('done writing max is', currMax);\n //console.log(image);\n resCallback(rows, cols, image);\n }, {\n noAck: true\n });\n });\n });\n });\n};\n```\n\n```text\n'use strict';\n\nmodule.exports = function(app) {\n var request_img = require('../../app/controllers/image-tools/request.img.server.controller.js');\n var receive_img = require('../../app/controllers/image-tools/receive.img.server.controller.js');\n\n // oct routes\n app.get('/load_slice', function(req, res) {\n console.log('load slice hit');\n receive_img.getResponse(function (rows, cols, image) {\n res.end(image);\n });\n request_img.sendRequest('123:C:\\\\Users\\\\yako\\\\Documents\\\\Developer\\\\medicaldiag\\\\test_files\\\\RUS-01-035-09M-21.oct');\n });\n};\n```\n\n```text\nreceive.img.server.controller.js\n```\n\n```text\ngetResponse\n```\n\n========================================\n\nComments:\n- Excellent answer. up question: If every user will be requesting multiple pictures, would it be better to keep a channel open for every user?\n- Also, should I be closing a connection after opening it?\n- Q1: channel per message producer (exchange) and channel per message consumer (queue) is more common approach. it may end up being channel per user, but i would look at it as \"i'm publishing to this exchange, so i need a channel\" and \"i'm consuming from this queue, so i need a channel\"\n- Q2: open the connection the moment the node.js process starts up. keep the same connection open forever. don't close it until you are shutting down the node.js process.\n- up to Q1: If a single channel is reused for all requests \"GET /load_slice\" then the channel has a single consume callback \"pulling\" the responses from the response queue. What mechanism binds the consume callback to the correct (req,res)? In other words: what mechanism assures that I will get a response to my query and not to someone else's which is being executed in parallel (considering the possibility of having multiple parallel workers)?\n- depending on the specific needs, if you are doing RPC style calls to get an immediate response, the rabbitmq \"reply-to\" queue is used rabbitmq.com/direct-reply-to.html\n- other scenarios get more complicated, and involve the message producer also being a consumer - having a specific queue for status updates, and routing messages to that queue based on which producer sent the original message\n- 2020 update. Wascally is deprecated, but says to try rabbot which is also deprecated!, which says to try foo-foo-mq, which is active... for now 0_o","metadata":{"transformedAt":"2026-08-18T18:33:20.182Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":211,"estimatedTokens":1894}}676{"id":"stack-10513317","source":"stackoverflow","questionId":10513317,"title":"Slow Performance of Amazon SQS compared with RabbitMQ","tags":["amazon-ec2","rabbitmq","amazon-sqs"],"text":"Title: Slow Performance of Amazon SQS compared with RabbitMQ\nTags: amazon-ec2, rabbitmq, amazon-sqs\nSource: Stack Overflow\n\nQuestion:\nI wanted to integrate a message queuing middle tier in my web application. I have tested Rabbitmq as well as Amazon SQS but find Amazon SQS is slow. I am getting 80 req/sec in Amazon SQS where I am getting 2000 req/sec in Rabbitmq. I am asking this Question because I am more interested Amazon SQS since I am using all the services of Amazon for my web app. Can anybody please tell me why this is so slow? Or if anybody has any good benchmark of Amazon SQS can you please ? Any help will be appriced.\n\n========================================\n\nTop Answer:\nOne thing to keep in mind here is that SQS is replicating your data across multiple AZ's. This is going to add to the time complexity compared to a single Rabbit or other MQ implementation.\n\nIf your single RabbitMQ instance goes down, are you ok with not being able to process messages or potentially losing data? If you are, you probably don't need replication or even disk persistence. But I'm guessing most use cases would care and thus, SQS offers a very hands off distributed MQ solution that is, in theory, insulated from a single point of failure.\n\n========================================\n\nComments:\n- Can you tell us more about your setup: what language are you using, and with multiple threads or not? Also Amazon never promised that message delivery would be low latency, only that it scales very well, given sufficient readers and writers.\n- I have tested with Java drivers. I have tested with 1 thread and then with 25 threads for both receive message and send message. I have reuse the code given as a sample in AWS Java SDK 1.3.8.\n- If you want a EC2 hosted solution for RabbitMQ, checkout cloudamqp.com\n- Thank you Carl Horberg. I have checked it but as it is paid I have avoided it :-) . So I have decided to go with my own servers of RabbitMQ in EC2 and Scale it as we want. Though this service is nice. Thanks again.\n- Thank you robthewolf. I have seen the exact site you have given. I have gone through RabbitMQ but I am facing problem in AutoScaling rabbitmq cluster.\n- have you seen this rabbitmq.com/blog/2012/04/25/… not sure if it helps","metadata":{"transformedAt":"2026-08-18T18:33:20.182Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":23,"estimatedTokens":565}}677{"id":"stack-12263579","source":"stackoverflow","questionId":12263579,"title":"RabbitMQ + Web Stomp and security","tags":["javascript","rabbitmq","stomp"],"text":"Title: RabbitMQ + Web Stomp and security\nTags: javascript, rabbitmq, stomp\nSource: Stack Overflow\n\nQuestion:\nRabbitMQ + Web Stomp is awesome. However, I have some topics I would like secure as read-only or write-only.\n\nIt seems the only mechanism to secure these are with rabbitmqctl. I can create a vhost, a user and then apply some permissions. However, this is where then Stomp and Rabbit implementation starts to break down.\n\ntopics take form: /topic/blah in stomp, which routes to \"amq.topic\" in Rabbit with a routing key \"blah\". It would seem there is no way to set permissions for the routing key. Seems: \n\n```\nrabbitmqctl set_permissions -p vhost user \".*\" \".*\" \"^amq\\.topic\"\n```\n\nis the best I can do, which is still \"ALL\" topics. I've looked into exchanges as well, but there is no way in javascript to define these on the fly.\n\nAm I missing something here?\n\nReference: http://www.rabbitmq.com/blog/2012/05/14/introducing-rabbitmq-web-stomp/\n\n========================================\n\nTop Answer:\nTry this https://github.com/simonmacmullen/rabbitmq-auth-backend-http\nIt's much more flexible.\nBasically it's small auth plugin for rabbit that delegates ACL decisions to a script over http (of which you have total control) which only has to reply with \"allow\" or \"deny\"\n\n========================================\n\nCode:\n```text\nrabbitmqctl set_permissions -p vhost user \".*\" \".*\" \"^amq\\.topic\"\n```\n\n========================================\n\nComments:\n- I did end up using an exchange. Not ideal, mainly because it complicates deployments, but it's working.","metadata":{"transformedAt":"2026-08-18T18:33:20.182Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":39,"estimatedTokens":391}}678{"id":"stack-72661296","source":"stackoverflow","questionId":72661296,"title":"RabbitMQ - How to use custom configuration file in docker-compose?","tags":["docker-compose","rabbitmq"],"text":"Title: RabbitMQ - How to use custom configuration file in docker-compose?\nTags: docker-compose, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm a beginner in using rabbitmq and docker-compose.\n\nI cannot figure out how to use my own config file... At start, rabbitmq service keeps exiting with the error:\n\n```\nrabbitmq1 | 2022-06-17 14:50:43.578486+00:00 [error] Failed to load advanced configuration file \"/etc/rabbitmq/rabbitmq.config\": 1: syntax error before:\n```\n\nMy conf file is the following one (myrabbit.conf)\n\n```\nconsumer_timeout = 10000\n```\n\nThe file is in the same directory then the docker-compose file which is:\n\n```\nversion: \"3\"\nservices:\n rabbitmq:\n image: rabbitmq:3-management\n container_name: rabbitmq1\n hostname: 'rabbitmq'\n ports:\n - \"5672:5672\"\n - \"15672:15672\"\n volumes:\n - ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/mnesia/\n - ./myrabbit.conf:/etc/rabbitmq/rabbitmq.config #problematic line I guess...\n restart: always\n```\n\nOther test:\nInstead of this :\n\n```\n- ./myrabbit.conf:/etc/rabbitmq/rabbitmq.config\n```\n\nWhen I try this:\n\n```\n- myrabbit.conf:/etc/rabbitmq/rabbitmq.config\n```\n\nI get the following error:\n\n```\nERROR: Named volume \"myrabbit.conf:/etc/rabbitmq/rabbitmq.config:rw\" is used in service \"rabbitmq\" but no declaration was found in the volumes section.\n```\n\n========================================\n\nCode:\n```text\nrabbitmq1 | 2022-06-17 14:50:43.578486+00:00 [error] <0.130.0> Failed to load advanced configuration file \"/etc/rabbitmq/rabbitmq.config\": 1: syntax error before:\n```\n\n```text\nconsumer_timeout = 10000\n```\n\n```text\nversion: \"3\"\nservices:\n rabbitmq:\n image: rabbitmq:3-management\n container_name: rabbitmq1\n hostname: 'rabbitmq'\n ports:\n - \"5672:5672\"\n - \"15672:15672\"\n volumes:\n - ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/mnesia/\n - ./myrabbit.conf:/etc/rabbitmq/rabbitmq.config #problematic line I guess...\n restart: always\n```\n\n```text\n- ./myrabbit.conf:/etc/rabbitmq/rabbitmq.config\n```\n\n```text\n- myrabbit.conf:/etc/rabbitmq/rabbitmq.config\n```\n\n```text\nERROR: Named volume \"myrabbit.conf:/etc/rabbitmq/rabbitmq.config:rw\" is used in service \"rabbitmq\" but no declaration was found in the volumes section.\n```\n\n```text\nversion: \"3\"\nservices:\n rabbitmq:\n image: rabbitmq:3-management\n container_name: rabbitmq\n hostname: 'rabbitmq'\n ports:\n - \"5672:5672\"\n - \"15672:15672\"\n volumes:\n - ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/mnesia/\n - ./rabbitmq/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf\n restart: always\n```\n\n========================================\n\nComments:\n- This helped me very much","metadata":{"transformedAt":"2026-08-18T18:33:20.182Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":7,"totalLines":115,"estimatedTokens":660}}679{"id":"stack-60087968","source":"stackoverflow","questionId":60087968,"title":"How to modify charts in Helm Stable repo","tags":["redis","rabbitmq","kubernetes-helm"],"text":"Title: How to modify charts in Helm Stable repo\nTags: redis, rabbitmq, kubernetes-helm\nSource: Stack Overflow\n\nQuestion:\n**What have I done:**\n\nAdded Stable repo into my helm and installed a chart(eg.: Redis, RabbitMQ/someapp).\n\n```\nhelm repo add stable https://kubernetes-charts.storage.googleapis.com/\nhelm install redis/rabbitMQ/someapp\n```\n\n**What do I need:**\n\nNow I need to change the configurations of my chart(Redis/RabbitMQ/someapp).\n\n- How can I edit the chart to have a modified config for my app(Redis/Rabbitmq/someapp)?\n\n- Is it possible to edit the chart's config installed with Helm stable repo? or should I have to have my own repo to edit it?\n\n========================================\n\nTop Answer:\nTo pull a chart and check it locally just run\n\n```\nhelm fetch stable/pgadmin --untar\n```\n\nThis will put the chart in a local directory located in your working dir. You can then edit the chart from here, and do installation with\n\n```\nhelm install -f your_values.yaml\n```\n\n========================================\n\nCode:\n```text\nhelm repo add stable https://kubernetes-charts.storage.googleapis.com/\nhelm install redis/rabbitMQ/someapp\n```\n\n```text\n$ helm install <release-name> <chart-name>\n```\n\n```text\n$ helm install --values custom_values.yaml <release-name> stable/<chart-name>\n```\n\n```text\nstable\n```\n\n```text\nvalues.yaml\n```\n\n```text\nhelm fetch stable/pgadmin --untar\n```\n\n```text\nhelm install <release_name> <chart_local_directory> -f your_values.yaml\n```\n\n========================================\n\nComments:\n- \" you need to copy the chart\" I can't find that chart. may I know the location pls? @kamol\n- You can find \"official\" Helm charts here: github.com/helm/charts/tree/master/stable\n- i don't get your point @perkdaddy, can you elaborate it to match the question?","metadata":{"transformedAt":"2026-08-18T18:33:20.182Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":75,"estimatedTokens":448}}680{"id":"stack-51782779","source":"stackoverflow","questionId":51782779,"title":"How to import and export messages to queue in RabbitMQ","tags":["rabbitmq","message-queue","amqp"],"text":"Title: How to import and export messages to queue in RabbitMQ\nTags: rabbitmq, message-queue, amqp\nSource: Stack Overflow\n\nQuestion:\nWe are developing a system which uses rabbitMQ for sending and receiving data between its clients and servers.\nThe internet connection may sometimes be lost.\n\n1- Can all the messages in the queue be exported to a file ? And somehow be imported to the client using this file?\n\n2- In a different scenario, a client wants to send some messages to the queue but it has no internet connection! So we want to export all the message from client and make a file and somehow send it to the server (eg. transfer it to another location which has internet), Is this possible to import this file to the queue?\n\n========================================\n\nTop Answer:\nThis tool will be useful to export messages from the remote queue and push them on a local RabbitMQ.\n\nhttps://github.com/jecnua/rabbitmq-export-to-local\n\n========================================\n\nCode:\n```text\ndotnet tool\n```\n\n```text\nAMQP => ZIP\n```\n\n```text\nAMQP => AMQP\n```\n\n```text\nZIP => AMQP\n```\n\n```text\nZIP => ZIP\n```\n\n```text\ndotnet tool\n```\n\n```text\ndotnet tool install --global MBW.Tools.RabbitDump\n```\n\n========================================\n\nComments:\n- the client can not install the docker, any other suggestions?\n- this is just a wrapper around github.com/dubek/rabbitmq-dump-queue :)\n- You're a lifesaver 👏👏👏\n- the tool will only work on dotnet core 6 (unfortunately on our old servers we have only .net framework)","metadata":{"transformedAt":"2026-08-18T18:33:20.183Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":57,"estimatedTokens":380}}681{"id":"stack-33905915","source":"stackoverflow","questionId":33905915,"title":"What causes amqp.node to get ECONNRESET from a RabbitMQ server?","tags":["node.js","rabbitmq"],"text":"Title: What causes amqp.node to get ECONNRESET from a RabbitMQ server?\nTags: node.js, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have an instance of RabbitMQ (default configurations) running on Windows 8 environment. My node version is 5.1.0 and I am trying to establish a connection between them using amqp.node library in order to pass messages.\n\nWhen I try the sample code:\n\n```\nvar q = 'tasks';\n\nfunction bail(err) {\n console.error(err);\n process.exit(1);\n}\n\n// Publisher\nfunction publisher(conn) {\n conn.createChannel(on_open);\n function on_open(err, ch) {\n if (err != null) bail(err);\n ch.assertQueue(q);\n ch.sendToQueue(q, new Buffer('something to do'));\n }\n}\n\n// Consumer\nfunction consumer(conn) {\n var ok = conn.createChannel(on_open);\n function on_open(err, ch) {\n if (err != null) bail(err);\n ch.assertQueue(q);\n ch.consume(q, function(msg) {\n if (msg !== null) {\n console.log(msg.content.toString());\n ch.ack(msg);\n }\n });\n }\n}\n\nrequire('amqplib/callback_api')\n .connect('amqp://guest:guest@localhost:5672', function(err, conn) {\n if (err != null) bail(err);\n consumer(conn);\n publisher(conn); \n });\n```\n\nI get it working okay.\n\nBut if I move this code, exactly how it is, into my project, I get this error: \n\n**ECCONRESET syscall: read.**\n\nMy app runs with express.js and oauth2.0. Even if I put the code right before any other statements and modules' requires, it does not work.\n\nI searched about this error and I found some problems related to load balance, but I am running it locally and the sample code works okay.\n\nAnother problem that I found could be related to TCP connection, I changed the handshake timout option inside RabbitMQ server's config file to 10000ms, but nothing changed.\n\nI am using the same url with guest user: amqp://guest:guest@localhost:5672, which works on the sample code.\n\nThe log from RabbitMQ shows that a connection is done but a few seconds later, it states that the connection was closed unexpectedly: \n\n```\n=INFO REPORT==== 24-Nov-2015::18:09:52 ===\naccepting AMQP connection (127.0.0.1:51866 -> 127.0.0.1:5672)\n\n=ERROR REPORT==== 24-Nov-2015::18:10:12 ===\nclosing AMQP connection (127.0.0.1:51866 -> 127.0.0.1:5672):\n{handshake_timeout,frame_header}\n```\n\nSo my questions are: is there any conflict between amqp.node and other library that drops the connection with the server? How can I debug this?\n\n========================================\n\nTop Answer:\nThis error is related to connection and channels. So in your code you are creating a connection and channel but not closing them. That creates this error (ECONNRESET) when the no. of connection and channel limit is exhausted RabbitMQ will stop accepting new network connections. Closing the channel and connection will solve this error. Example Code: \n\n```\namqp.connect('amqp://localhost')\n.then(function(conn) {\n return when(conn.createChannel().then(function(ch) {\n var q = 'hello';\n var msg = 'Hello World!';\n\n var ok = ch.assertQueue(q, {durable: true});\n\n return ok.then(function(_qok) {\n ch.sendToQueue(q, new Buffer(msg), {deliveryMode: true});\n console.log(\" [x] Sent '%s'\", msg);\n return ch.close();\n });\n })).ensure(function() {\n conn.close();\n });\n})\n.then(null, console.warn);\n```\n\n========================================\n\nCode:\n```text\nvar q = 'tasks';\n\nfunction bail(err) {\n console.error(err);\n process.exit(1);\n}\n\n// Publisher\nfunction publisher(conn) {\n conn.createChannel(on_open);\n function on_open(err, ch) {\n if (err != null) bail(err);\n ch.assertQueue(q);\n ch.sendToQueue(q, new Buffer('something to do'));\n }\n}\n\n// Consumer\nfunction consumer(conn) {\n var ok = conn.createChannel(on_open);\n function on_open(err, ch) {\n if (err != null) bail(err);\n ch.assertQueue(q);\n ch.consume(q, function(msg) {\n if (msg !== null) {\n console.log(msg.content.toString());\n ch.ack(msg);\n }\n });\n }\n}\n\nrequire('amqplib/callback_api')\n .connect('amqp://guest:guest@localhost:5672', function(err, conn) {\n if (err != null) bail(err);\n consumer(conn);\n publisher(conn); \n });\n```\n\n```text\n=INFO REPORT==== 24-Nov-2015::18:09:52 ===\naccepting AMQP connection <0.2644.0> (127.0.0.1:51866 -> 127.0.0.1:5672)\n\n=ERROR REPORT==== 24-Nov-2015::18:10:12 ===\nclosing AMQP connection <0.2644.0> (127.0.0.1:51866 -> 127.0.0.1:5672):\n{handshake_timeout,frame_header}\n```\n\n```text\namqp.connect('amqp://localhost')\n.then(function(conn) {\n return when(conn.createChannel().then(function(ch) {\n var q = 'hello';\n var msg = 'Hello World!';\n\n var ok = ch.assertQueue(q, {durable: true});\n\n return ok.then(function(_qok) {\n ch.sendToQueue(q, new Buffer(msg), {deliveryMode: true});\n console.log(\" [x] Sent '%s'\", msg);\n return ch.close();\n });\n })).ensure(function() {\n conn.close();\n });\n})\n.then(null, console.warn);\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.183Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":176,"estimatedTokens":1218}}682{"id":"stack-50952806","source":"stackoverflow","questionId":50952806,"title":"Unable to get RabbitMQ running on Windows 10","tags":["windows","rabbitmq","erlang"],"text":"Title: Unable to get RabbitMQ running on Windows 10\nTags: windows, rabbitmq, erlang\nSource: Stack Overflow\n\nQuestion:\nI've run the Erlang and RabbitMQ installers \"As Administrator\".\nBoth seem to have installed correctly.\nThe RabbitMQ server is running.\nHowever, when I run any command line Rabbit commands (rabbitmqctl, rabbitmq-plugins enable rabbitmq_management, etc.), I get the following error message/dump. I obviously cannot access the Management Console or communicate with the service at all.\n\nAny ideas on the below error and what could be causing this? I've installed on other Win10 machines before without any issues.\n\n```\n=SUPERVISOR REPORT==== 20-Jun-2018::10:08:39.865000 ===\nsupervisor: {local,'Elixir.Logger.Supervisor'}\nerrorContext: start_error\nreason: noproc\noffender: [{pid,undefined},\n {id,'Elixir.Logger.ErrorHandler'},\n {mfargs,\n {'Elixir.Logger.Watcher',start_link,\n [{error_logger,'Elixir.Logger.ErrorHandler',\n {true,false,500}}]}},\n {restart_type,permanent},\n {shutdown,5000},\n {child_type,worker}]\n=CRASH REPORT==== 20-Jun-2018::10:08:39.865000 ===\n crasher:\n initial call: application_master:init/4\n pid: \n registered_name: []\n exception exit: {{shutdown,\n {failed_to_start_child,'Elixir.Logger.ErrorHandler',\n noproc}},\n {'Elixir.Logger.App',start,[normal,[]]}}\n in function application_master:init/4 (application_master.erl, line \n138)\n ancestors: []\n message_queue_len: 1\n messages: [{'EXIT',,normal}]\n links: [,]\n dictionary: []\n trap_exit: true\n status: running\n heap_size: 376\n stack_size: 27\n reductions: 193\n neighbours:\n=CRASH REPORT==== 20-Jun-2018::10:08:39.865000 ===\n crasher:\n initial call: Elixir.Logger.Watcher:init/1\n pid: \n registered_name: []\n exception exit: noproc\n in function gen:do_for_proc/2 (gen.erl, line 228)\n in call from gen_event:rpc/2 (gen_event.erl, line 239)\n in call from 'Elixir.Logger.Watcher':init/1 (lib/logger/watcher.ex, \nline 23)\n in call from gen_server:init_it/2 (gen_server.erl, line 374)\n in call from gen_server:init_it/6 (gen_server.erl, line 342)\n ancestors: ['Elixir.Logger.Supervisor',]\n message_queue_len: 0\n messages: []\n links: []\n dictionary: []\n trap_exit: true\n status: running\n heap_size: 376\n stack_size: 27\n reductions: 254\n neighbours:\n=INFO REPORT==== 20-Jun-2018::10:08:39.881000 ===\n application: logger\n exited: {{shutdown,\n\n{failed_to_start_child,'Elixir.Logger.ErrorHandler',noproc}},\n {'Elixir.Logger.App',start,[normal,[]]}}\n type: temporary\nCould not start application logger: Logger.App.start(:normal, []) returned an \nerror: shutdown: failed to start child: Logger.ErrorHandler\n ** (EXIT) no process: the process is not alive or there's no process \ncurrently associated with the given name, possibly because its application \nisn't started\n```\n\n========================================\n\nTop Answer:\nI got a bonus error with erlang 19.3 :\n\n```\nλ rabbitmq-service install\nC:\\Programs\\erl8.3\\erts-8.3\\bin\\erlsrv: Service RabbitMQ added to system.\nbad \"MBa\" value: ageffcbf\nUsage: beam.smp.dll [flags] [ -- [init_args] ]\n```\n\nHowever the service installed and started successfully with no side effects so far.\n\n========================================\n\nCode:\n```text\n=SUPERVISOR REPORT==== 20-Jun-2018::10:08:39.865000 ===\nsupervisor: {local,'Elixir.Logger.Supervisor'}\nerrorContext: start_error\nreason: noproc\noffender: [{pid,undefined},\n {id,'Elixir.Logger.ErrorHandler'},\n {mfargs,\n {'Elixir.Logger.Watcher',start_link,\n [{error_logger,'Elixir.Logger.ErrorHandler',\n {true,false,500}}]}},\n {restart_type,permanent},\n {shutdown,5000},\n {child_type,worker}]\n=CRASH REPORT==== 20-Jun-2018::10:08:39.865000 ===\n crasher:\n initial call: application_master:init/4\n pid: <0.80.0>\n registered_name: []\n exception exit: {{shutdown,\n {failed_to_start_child,'Elixir.Logger.ErrorHandler',\n noproc}},\n {'Elixir.Logger.App',start,[normal,[]]}}\n in function application_master:init/4 (application_master.erl, line \n138)\n ancestors: [<0.79.0>]\n message_queue_len: 1\n messages: [{'EXIT',<0.81.0>,normal}]\n links: [<0.79.0>,<0.42.0>]\n dictionary: []\n trap_exit: true\n status: running\n heap_size: 376\n stack_size: 27\n reductions: 193\n neighbours:\n=CRASH REPORT==== 20-Jun-2018::10:08:39.865000 ===\n crasher:\n initial call: Elixir.Logger.Watcher:init/1\n pid: <0.87.0>\n registered_name: []\n exception exit: noproc\n in function gen:do_for_proc/2 (gen.erl, line 228)\n in call from gen_event:rpc/2 (gen_event.erl, line 239)\n in call from 'Elixir.Logger.Watcher':init/1 (lib/logger/watcher.ex, \nline 23)\n in call from gen_server:init_it/2 (gen_server.erl, line 374)\n in call from gen_server:init_it/6 (gen_server.erl, line 342)\n ancestors: ['Elixir.Logger.Supervisor',<0.81.0>]\n message_queue_len: 0\n messages: []\n links: [<0.82.0>]\n dictionary: []\n trap_exit: true\n status: running\n heap_size: 376\n stack_size: 27\n reductions: 254\n neighbours:\n=INFO REPORT==== 20-Jun-2018::10:08:39.881000 ===\n application: logger\n exited: {{shutdown,\n\n{failed_to_start_child,'Elixir.Logger.ErrorHandler',noproc}},\n {'Elixir.Logger.App',start,[normal,[]]}}\n type: temporary\nCould not start application logger: Logger.App.start(:normal, []) returned an \nerror: shutdown: failed to start child: Logger.ErrorHandler\n ** (EXIT) no process: the process is not alive or there's no process \ncurrently associated with the given name, possibly because its application \nisn't started\n```\n\n```text\nERLANG_HOME\n```\n\n```text\nλ rabbitmq-service install\nC:\\Programs\\erl8.3\\erts-8.3\\bin\\erlsrv: Service RabbitMQ added to system.\nbad \"MBa\" value: ageffcbf\nUsage: beam.smp.dll [flags] [ -- [init_args] ]\n```\n\n========================================\n\nComments:\n- I'm having the exact same issue. Already tried reinstalling the service on Windows as suggested on other questions but to no avail.\n- having the same issue.\n- cant find the download link, says they are working on the page :(\n- okay, got it working. @Sandra was right. install otp_win64_19.3.exe for now. Run the following commands: `SET HOMEDRIVE=C: | rabbitmq-service remove | rabbitmq-service install | rabbitmq-plugins.bat enable rabbitmq_management`\n- Just to close this out (in case someone else comes across this later), after installing the new (old) version and running the command that @FrankDupree suggested, I had to re-install the RabbitMQ server, re-enable the management console plugin and now things appear to be working perfectly. Thanks to all!!\n- Thanks, this worked for me. Except that I used Erlang v20.3 which appears to be the latest version that works with RabbitMQ. There's info about compatible Erlang versions on this page rabbitmq.com/which-erlang.html","metadata":{"transformedAt":"2026-08-18T18:33:20.183Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":195,"estimatedTokens":1726}}683{"id":"stack-10660202","source":"stackoverflow","questionId":10660202,"title":"How do I set a backend for django-celery. I set CELERY_RESULT_BACKEND, but it is not recognized","tags":["rabbitmq","celery","django-celery"],"text":"Title: How do I set a backend for django-celery. I set CELERY_RESULT_BACKEND, but it is not recognized\nTags: rabbitmq, celery, django-celery\nSource: Stack Overflow\n\nQuestion:\nI set CELERY_RESULT_BACKEND = \"amqp\" in celeryconfig.py\nbut I get:\n\n```\n>>> from tasks import add\n>>> result = add.delay(3,5)\n>>> result.ready()\n\nTraceback (most recent call last):\n File \"\", line 1, in \n File \"/djangoprojects/venv/local/lib/python2.7/site-packages/celery/result.py\", line 105, in ready\n return self.state in self.backend.READY_STATES\n File \"/djangoprojects/venv/local/lib/python2.7/site-packages/celery/result.py\", line 184, in state\n return self.backend.get_status(self.task_id)\n File \"/djangoprojects/venv/local/lib/python2.7/site-packages/celery/backends/base.py\", line 414, in _is_disabled\n raise NotImplementedError(\"No result backend configured. \"\nNotImplementedError: No result backend configured. Please see the documentation for more information.\n```\n\n========================================\n\nTop Answer:\nAre you running django celery?\n\nIf so, you need to start a python shell in the context of django (or whatever the technical term is).\n\nType: \n\n```\npython manage.py shell\n```\n\nAnd try your commands from that shell\n\n========================================\n\nCode:\n```text\n>>> from tasks import add\n>>> result = add.delay(3,5)\n>>> result.ready()\n\nTraceback (most recent call last):\n File \"<console>\", line 1, in <module>\n File \"/djangoprojects/venv/local/lib/python2.7/site-packages/celery/result.py\", line 105, in ready\n return self.state in self.backend.READY_STATES\n File \"/djangoprojects/venv/local/lib/python2.7/site-packages/celery/result.py\", line 184, in state\n return self.backend.get_status(self.task_id)\n File \"/djangoprojects/venv/local/lib/python2.7/site-packages/celery/backends/base.py\", line 414, in _is_disabled\n raise NotImplementedError(\"No result backend configured. \"\nNotImplementedError: No result backend configured. Please see the documentation for more information.\n```\n\n```text\nBROKER_URL = \"amqp://guest:guest@localhost:5672//\"\n```\n\n```text\npython manage.py celeryd -E -B --loglevel=info\n```\n\n```text\n./manage.py celerycam\n```\n\n```text\n>>> result = add.delay(4, 4)\n>>> result.ready() # returns True if the task has finished processing.\nFalse\n>>> result.result # task is not ready, so no return value yet.\nNone\n>>> result.get() # Waits until the task is done and returns the retval.\n8\n>>> result.result # direct access to result, doesn't re-raise errors.\n8\n>>> result.successful() # returns True if the task didn't end in failure.\nTrue\n```\n\n```text\n-E\n```\n\n```text\n-B\n```\n\n```text\npython manage.py shell\n```\n\n```text\napp = Celery('documents',backend=\"celery.backends.amqp:AMQPBackend\")\nSetting backend=\"celery.backends.amqp:AMQPBackend\" fixed my error.\n```\n\n========================================\n\nComments:\n- Are you running python shell from the same directory as celeryconfig.py?\n- I had rabbitmq running and django-celery installed, but I didn't have django-celery running.","metadata":{"transformedAt":"2026-08-18T18:33:20.183Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":106,"estimatedTokens":757}}684{"id":"stack-65423312","source":"stackoverflow","questionId":65423312,"title":"pika `pop from an empty queue`","tags":["rabbitmq","pika","python-pika"],"text":"Title: pika `pop from an empty queue`\nTags: rabbitmq, pika, python-pika\nSource: Stack Overflow\n\nQuestion:\nI'm using pika in a kubernetes cluster and consuming messages from a queue, which triggers initiating a function in a new thread. However RabbitMQ seems crash, these are the best logs I've found so far:\n\n```\n2020-12-23 10:39:10,906] WARNING - WRITE indicated on fd=9, but writer callback is None; events=0b100 {/usr/local/lib/python3.9/site-packages/pika/adapters/utils/selector_ioloop_adapter.py:393}\n(repeats to a total of n=38 times)\n2020-12-23 10:39:10,908] ERROR - _AsyncBaseTransport._produce() failed, aborting connection: error=IndexError('pop from an empty deque'); sock=; Caller's stack: \nTraceback (most recent call last): \nFile \"/usr/local/lib/python3.9/site-packages/pika/adapters/utils/io_services_utils.py\", line 1097, in _on_socket_writable \n self._produce() \nFile \"/usr/local/lib/python3.9/site-packages/pika/adapters/utils/io_services_utils.py\", line 822, in _produce \n chunk = self._tx_buffers.popleft() \nIndexError: pop from an empty deque \n{/usr/local/lib/python3.9/site-packages/pika/adapters/utils/io_services_utils.py:1103} \nTraceback (most recent call last): \nFile \"/usr/local/lib/python3.9/site-packages/pika/adapters/utils/io_services_utils.py\", line 1097, in _on_socket_writable \n self._produce() \nFile \"/usr/local/lib/python3.9/site-packages/pika/adapters/utils/io_services_utils.py\", line 822, in _produce \n chunk = self._tx_buffers.popleft() \nIndexError: pop from an empty deque \n2020-12-23 10:39:10,908] INFO - _AsyncTransportBase._initate_abort(): Initiating abrupt asynchronous transport shutdown: state=1; error=IndexError('pop from an empty deque'); {/usr/local/lib/python3.9/site-packages/pika/adapters/utils/io_services_utils.py:904} \n2020-12-23 10:39:10,908] INFO - Deactivating transport: state=1; {/usr/local/lib/python3.9/site-packages/pika/adapters/utils/io_services_utils.py:869}\n2020-12-23 10:39:10,909] ERROR - connection_lost: StreamLostError: (\"Stream connection lost: IndexError('pop from an empty deque')\",) {/usr/local/lib/python3.9/site-packages/pika/adapters/base_connection.py:428} \n2020-12-23 10:39:10,909] INFO - AMQP stack terminated, failed to connect, or aborted: opened=True, error-arg=StreamLostError: (\"Stream connection lost: IndexError('pop from an empty deque')\",); pending-error=None {/usr/local/lib/python3.9/site-packages/pika/connection.py:1996}\n2020-12-23 10:39:10,909] INFO - Stack terminated due to StreamLostError: (\"Stream connection lost: IndexError('pop from an empty deque')\",) {/usr/local/lib/python3.9/site-packages/pika/connection.py:2065} \n2020-12-23 10:39:10,909] INFO - Closing transport socket and unlinking: state=2; {/usr/local/lib/python3.9/site-packages/pika/adapters/utils/io_services_utils.py:882} \n2020-12-23 10:39:10,909] ERROR - Unexpected connection close detected: StreamLostError: (\"Stream connection lost: IndexError('pop from an empty deque')\",) {/usr/local/lib/python3.9/site-packages/pika/adapters/blocking_connection.py:520} \n2020-12-23 10:39:31,416] INFO - Pika version 1.1.0 connecting to ('192.168.101.201', 5672) {/usr/local/lib/python3.9/site-packages/pika/adapters/utils/connection_workflow.py:179} \n2020-12-23 10:39:31,417] INFO - Socket connected: {/usr/local/lib/python3.9/site-packages/pika/adapters/utils/io_services_utils.py:345} \n2020-12-23 10:39:31,418] INFO - Streaming transport linked up: (, _StreamingProtocolShim: params=>). {/usr/local/lib/python3.9/site-packages/pika/adapters/utils/connection_workflow.py:428}\n2020-12-23 10:39:31,421] INFO - AMQPConnector - reporting success: params=> {/usr/local/lib/python3.9/site-packages/pika/adapters/utils/connection_workflow.py:293}\n2020-12-23 10:39:31,421] INFO - AMQPConnectionWorkflow - reporting success: params=> {/usr/local/lib/python3.9/site-packages/pika/adapters/utils/connection_workflow.py:725} \n2020-12-23 10:39:31,421] INFO - Connection workflow succeeded: params=> {/usr/local/lib/python3.9/site-packages/pika/adapters/blocking_connection.py:452} \n2020-12-23 10:39:31,422] INFO - Created channel=1 {/usr/local/lib/python3.9/site-packages/pika/adapters/blocking_connection.py:1247\n}\n```\n\nMy consumer has the following definition:\n\n```\ndef publish_message(channel, message):\n channel.basic_publish(exchange='',\n routing_key='my_queue',\n body=message)\n\ndef connect_to_mq():\n credentials = pika.PlainCredentials(rabbit_user, rabbit_password)\n parameters = pika.ConnectionParameters(rabbit_host, rabbit_port, '/', credentials)\n connection = pika.BlockingConnection(parameters=parameters)\n channel = connection.channel()\n channel.queue_declare(queue='my_queue')\n return connection, channel\n \n \ndef on_message(channel, method_frame, header_frame, body):\n message = body.decode('utf-8')\n if message == 'do_work':\n thread = threading.Thread(target=start_processing, args=(channel,))\n thread.start()\n publish_message(channel, 'initiated thread')\n \n \ndef start_processing(channel):\n publish_message(channel, 'starting...')\n time.sleep(240)\n publish_message(channel, 'processing complete!')\n\ndef main():\n connection, channel = connect_to_mq()\n channel.basic_consume(queue='my_queue',\n auto_ack=True,\n on_message_callback=on_message)\n\n channel.start_consuming()\n```\n\nIs there anything inherently wrong with my implementation and strategy for handling messages and workloads in separate threads that is causing this to happen?\n\n========================================\n\nTop Answer:\nAs eandersson said, **Pika is not thread safe**. and you can't ** one connection between** threads...\n\nUse the amqpstorm if you want thread safety.\n\nHere is a simple example of using pika and amqpstorm in multithreaded application:\n\n```\nimport amqpstorm\nimport time\nimport threading\nimport multiprocessing\n\ndef simple_consumer(conn: amqpstorm.Connection):\n with conn.channel() as channel:\n while True:\n msg = channel.basic.get('fruits')\n if msg is None:\n time.sleep(1)\n continue\n print(msg.body)\n msg.ack()\n return\n\ndef producer_task(conn: amqpstorm.Connection, counter: int):\n with conn.channel() as channel:\n while counter > 0:\n channel.queue.declare('fruits')\n print(f'Thread {counter}')\n message = amqpstorm.Message.create(\n channel,\n body=f'Hello RabbitMQ! {counter}',\n properties={\n 'content_type': 'text/plain',\n \"expiration\": '5000'\n }\n )\n message.publish('fruits')\n counter -= 1\n time.sleep(1)\n print(f'end {counter}')\n return\n\ndef main():\n conn = amqpstorm.Connection('localhost', 'guest', 'guest')\n p1 = threading.Thread(\n target=producer_task,\n kwargs={'conn': conn, 'counter': 10},\n )\n p1.start()\n \n p2 = threading.Thread(\n target=producer_task,\n kwargs={'conn': conn, 'counter': 20}\n )\n p2.start()\n \n p3 = threading.Thread(\n target=producer_task,\n kwargs={'conn': conn, 'counter': 30}\n )\n p3.start()\n \n p4 = threading.Thread(\n target=simple_consumer,\n kwargs={'conn': conn}\n )\n p4.start()\n \n p1.join()\n p2.join()\n p3.join()\n p4.join()\n \n print('end main')\n return\n\nif __name__ == '__main__':\n main()\n```\n\nAS THE FOOTNOTE: Notice that you can not also one connection between processes in amqpstorm, due to each process has it's memory space.\n\nthe same app will not working using pika:\n\n```\nimport pika\nimport time\nimport threading\n\ndef on_message(message):\n print(\"Message:\", message.body) \n return\n\ndef consumer(conn: pika.BlockingConnection):\n with conn.channel() as channel:\n channel.queue_declare(queue='fruits')\n channel.basic_consume(queue='fruits', on_message_callback=on_message, auto_ack=True)\n \n try:\n channel.start_consuming()\n except KeyboardInterrupt:\n channel.close()\n\ndef producer_task(conn: pika.BlockingConnection, counter: int):\n with conn.channel() as channel:\n while counter > 0:\n channel.queue_declare('fruits')\n print(f'Thread {counter}')\n channel.basic_publish(\n exchange='',\n routing_key='fruits',\n body=f'Hello RabbitMQ! {counter}',\n properties=pika.BasicProperties(expiration='5000')\n )\n counter -= 1\n time.sleep(1)\n print(f'end {counter}')\n return\n\ndef main():\n conn = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))\n p1 = threading.Thread(\n target=producer_task,\n kwargs={'conn': conn, 'counter': 10},\n )\n p1.start()\n \n p2 = threading.Thread(\n target=producer_task,\n kwargs={'conn': conn, 'counter': 20}\n )\n p2.start()\n\n p3 = threading.Thread(\n target=producer_task,\n kwargs={'conn': conn, 'counter': 30}\n )\n p3.start()\n\n p4 = threading.Thread(\n target=consumer,\n kwargs={'conn': conn}\n )\n p4.start()\n\n p1.join()\n p2.join()\n p3.join()\n p4.join()\n \n print('end main')\n return\n\nif __name__ == '__main__':\n main()\n```\n\n========================================\n\nCode:\n```text\n2020-12-23 10:39:10,906] WARNING - WRITE indicated on fd=9, but writer callback is None; events=0b100 {/usr/local/lib/python3.9/site-packages/pika/adapters/utils/selector_ioloop_adapter.py:393}\n(repeats to a total of n=38 times)\n2020-12-23 10:39:10,908] ERROR - _AsyncBaseTransport._produce() failed, aborting connection: error=IndexError('pop from an empty deque'); sock=<socket.socket fd=9, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('192.168.100.200', 44892), raddr=('192.168.101.201', 5672)>; Caller's stack: \nTraceback (most recent call last): \nFile \"/usr/local/lib/python3.9/site-packages/pika/adapters/utils/io_services_utils.py\", line 1097, in _on_socket_writable \n self._produce() \nFile \"/usr/local/lib/python3.9/site-packages/pika/adapters/utils/io_services_utils.py\", line 822, in _produce \n chunk = self._tx_buffers.popleft() \nIndexError: pop from an empty deque \n{/usr/local/lib/python3.9/site-packages/pika/adapters/utils/io_services_utils.py:1103} \nTraceback (most recent call last): \nFile \"/usr/local/lib/python3.9/site-packages/pika/adapters/utils/io_services_utils.py\", line 1097, in _on_socket_writable \n self._produce() \nFile \"/usr/local/lib/python3.9/site-packages/pika/adapters/utils/io_services_utils.py\", line 822, in _produce \n chunk = self._tx_buffers.popleft() \nIndexError: pop from an empty deque \n2020-12-23 10:39:10,908] INFO - _AsyncTransportBase._initate_abort(): Initiating abrupt asynchronous transport shutdown: state=1; error=IndexError('pop from an empty deque'); <socket.socket fd=9, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('192.168.100.200', 44892), raddr=('192.168.101.201', 5672)> {/usr/local/lib/python3.9/site-packages/pika/adapters/utils/io_services_utils.py:904} \n2020-12-23 10:39:10,908] INFO - Deactivating transport: state=1; <socket.socket fd=9, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('192.168.100.200', 44892), raddr=('192.168.101.201', 5672)> {/usr/local/lib/python3.9/site-packages/pika/adapters/utils/io_services_utils.py:869}\n2020-12-23 10:39:10,909] ERROR - connection_lost: StreamLostError: (\"Stream connection lost: IndexError('pop from an empty deque')\",) {/usr/local/lib/python3.9/site-packages/pika/adapters/base_connection.py:428} \n2020-12-23 10:39:10,909] INFO - AMQP stack terminated, failed to connect, or aborted: opened=True, error-arg=StreamLostError: (\"Stream connection lost: IndexError('pop from an empty deque')\",); pending-error=None {/usr/local/lib/python3.9/site-packages/pika/connection.py:1996}\n2020-12-23 10:39:10,909] INFO - Stack terminated due to StreamLostError: (\"Stream connection lost: IndexError('pop from an empty deque')\",) {/usr/local/lib/python3.9/site-packages/pika/connection.py:2065} \n2020-12-23 10:39:10,909] INFO - Closing transport socket and unlinking: state=2; <socket.socket fd=9, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('192.168.100.200', 44892), raddr=('192.168.101.201', 5672)> {/usr/local/lib/python3.9/site-packages/pika/adapters/utils/io_services_utils.py:882} \n2020-12-23 10:39:10,909] ERROR - Unexpected connection close detected: StreamLostError: (\"Stream connection lost: IndexError('pop from an empty deque')\",) {/usr/local/lib/python3.9/site-packages/pika/adapters/blocking_connection.py:520} \n2020-12-23 10:39:31,416] INFO - Pika version 1.1.0 connecting to ('192.168.101.201', 5672) {/usr/local/lib/python3.9/site-packages/pika/adapters/utils/connection_workflow.py:179} \n2020-12-23 10:39:31,417] INFO - Socket connected: <socket.socket fd=9, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('192.168.100.200', 47142), raddr=('192.168.101.201', 5672)> {/usr/local/lib/python3.9/site-packages/pika/adapters/utils/io_services_utils.py:345} \n2020-12-23 10:39:31,418] INFO - Streaming transport linked up: (<pika.adapters.utils.io_services_utils._AsyncPlaintextTransport object at 0x7f81b3099a60>, _StreamingProtocolShim: <SelectConnection PROTOCOL transport=<pika.adapters.utils.io_services_utils._AsyncPlaintextTransport object at 0x7f81b3099a60> params=<ConnectionParameters host=rabbitmq-0.rabbitmq.testing.svc.cluster.local port=5672 virtual_host=/ ssl=False>>). {/usr/local/lib/python3.9/site-packages/pika/adapters/utils/connection_workflow.py:428}\n2020-12-23 10:39:31,421] INFO - AMQPConnector - reporting success: <SelectConnection OPEN transport=<pika.adapters.utils.io_services_utils._AsyncPlaintextTransport object at 0x7f81b3099a60> params=<ConnectionParameters host=rabbitmq-0.rabbitmq.testing.svc.cluster.local port=5672 virtual_host=/ ssl=False>> {/usr/local/lib/python3.9/site-packages/pika/adapters/utils/connection_workflow.py:293}\n2020-12-23 10:39:31,421] INFO - AMQPConnectionWorkflow - reporting success: <SelectConnection OPEN transport=<pika.adapters.utils.io_services_utils._AsyncPlaintextTransport object at 0x7f81b3099a60> params=<ConnectionParameters host=rabbitmq-0.rabbitmq.testing.svc.cluster.local port=5672 virtual_host=/ ssl=False>> {/usr/local/lib/python3.9/site-packages/pika/adapters/utils/connection_workflow.py:725} \n2020-12-23 10:39:31,421] INFO - Connection workflow succeeded: <SelectConnection OPEN transport=<pika.adapters.utils.io_services_utils._AsyncPlaintextTransport object at 0x7f81b3099a60> params=<ConnectionParameters host=rabbitmq-0.rabbitmq.testing.svc.cluster.local port=5672 virtual_host=/ ssl=False>> {/usr/local/lib/python3.9/site-packages/pika/adapters/blocking_connection.py:452} \n2020-12-23 10:39:31,422] INFO - Created channel=1 {/usr/local/lib/python3.9/site-packages/pika/adapters/blocking_connection.py:1247\n}\n```\n\n```text\ndef publish_message(channel, message):\n channel.basic_publish(exchange='',\n routing_key='my_queue',\n body=message)\n\n\ndef connect_to_mq():\n credentials = pika.PlainCredentials(rabbit_user, rabbit_password)\n parameters = pika.ConnectionParameters(rabbit_host, rabbit_port, '/', credentials)\n connection = pika.BlockingConnection(parameters=parameters)\n channel = connection.channel()\n channel.queue_declare(queue='my_queue')\n return connection, channel\n \n \ndef on_message(channel, method_frame, header_frame, body):\n message = body.decode('utf-8')\n if message == 'do_work':\n thread = threading.Thread(target=start_processing, args=(channel,))\n thread.start()\n publish_message(channel, 'initiated thread')\n \n \ndef start_processing(channel):\n publish_message(channel, 'starting...')\n time.sleep(240)\n publish_message(channel, 'processing complete!')\n\n\ndef main():\n connection, channel = connect_to_mq()\n channel.basic_consume(queue='my_queue',\n auto_ack=True,\n on_message_callback=on_message)\n\n channel.start_consuming()\n```\n\n```py\nimport amqpstorm\nimport time\nimport threading\nimport multiprocessing\n\n\n\ndef simple_consumer(conn: amqpstorm.Connection):\n with conn.channel() as channel:\n while True:\n msg = channel.basic.get('fruits')\n if msg is None:\n time.sleep(1)\n continue\n print(msg.body)\n msg.ack()\n return\n\n\ndef producer_task(conn: amqpstorm.Connection, counter: int):\n with conn.channel() as channel:\n while counter > 0:\n channel.queue.declare('fruits')\n print(f'Thread {counter}')\n message = amqpstorm.Message.create(\n channel,\n body=f'Hello RabbitMQ! {counter}',\n properties={\n 'content_type': 'text/plain',\n \"expiration\": '5000'\n }\n )\n message.publish('fruits')\n counter -= 1\n time.sleep(1)\n print(f'end {counter}')\n return\n\ndef main():\n conn = amqpstorm.Connection('localhost', 'guest', 'guest')\n p1 = threading.Thread(\n target=producer_task,\n kwargs={'conn': conn, 'counter': 10},\n )\n p1.start()\n \n p2 = threading.Thread(\n target=producer_task,\n kwargs={'conn': conn, 'counter': 20}\n )\n p2.start()\n \n p3 = threading.Thread(\n target=producer_task,\n kwargs={'conn': conn, 'counter': 30}\n )\n p3.start()\n \n p4 = threading.Thread(\n target=simple_consumer,\n kwargs={'conn': conn}\n )\n p4.start()\n \n p1.join()\n p2.join()\n p3.join()\n p4.join()\n \n print('end main')\n return\n\nif __name__ == '__main__':\n main()\n```\n\n```py\nimport pika\nimport time\nimport threading\n\n\ndef on_message(message):\n print(\"Message:\", message.body) \n return\n\n\ndef consumer(conn: pika.BlockingConnection):\n with conn.channel() as channel:\n channel.queue_declare(queue='fruits')\n channel.basic_consume(queue='fruits', on_message_callback=on_message, auto_ack=True)\n \n try:\n channel.start_consuming()\n except KeyboardInterrupt:\n channel.close()\n\n\ndef producer_task(conn: pika.BlockingConnection, counter: int):\n with conn.channel() as channel:\n while counter > 0:\n channel.queue_declare('fruits')\n print(f'Thread {counter}')\n channel.basic_publish(\n exchange='',\n routing_key='fruits',\n body=f'Hello RabbitMQ! {counter}',\n properties=pika.BasicProperties(expiration='5000')\n )\n counter -= 1\n time.sleep(1)\n print(f'end {counter}')\n return\n\n\n\ndef main():\n conn = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))\n p1 = threading.Thread(\n target=producer_task,\n kwargs={'conn': conn, 'counter': 10},\n )\n p1.start()\n \n p2 = threading.Thread(\n target=producer_task,\n kwargs={'conn': conn, 'counter': 20}\n )\n p2.start()\n\n p3 = threading.Thread(\n target=producer_task,\n kwargs={'conn': conn, 'counter': 30}\n )\n p3.start()\n\n p4 = threading.Thread(\n target=consumer,\n kwargs={'conn': conn}\n )\n p4.start()\n\n p1.join()\n p2.join()\n p3.join()\n p4.join()\n \n print('end main')\n return\n\n\n\nif __name__ == '__main__':\n main()\n```\n\n========================================\n\nComments:\n- Thank you. I have successfully resolved the issue by wrapping the calls to `publish_message` (the ones which are happening in the a separate thread) in functions submitted to `Connection.add_callback_threadsafe`\n- hey, could you provide the code example? thanks!\n- github.com/pika/pika/blob/1.3.x/examples/…","metadata":{"transformedAt":"2026-08-18T18:33:20.183Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":481,"estimatedTokens":5167}}685{"id":"stack-6948624","source":"stackoverflow","questionId":6948624,"title":"Mnesia can't connect to another node","tags":["rabbitmq","mnesia"],"text":"Title: Mnesia can't connect to another node\nTags: rabbitmq, mnesia\nSource: Stack Overflow\n\nQuestion:\nI am setting up a rabbitmq cluster and ran into an issue during the one step in the process. Its straight out of the rabbitmq clustering guide.\n\n```\nroot@celery:~# rabbitmqctl status\nStatus of node celery@celery ...\n[{pid,20410},\n {running_applications,[{rabbit,\"RabbitMQ\",\"2.5.1\"},\n {os_mon,\"CPO CXC 138 46\",\"2.2.4\"},\n {sasl,\"SASL CXC 138 11\",\"2.1.8\"},\n {mnesia,\"MNESIA CXC 138 12\",\"4.4.12\"},\n {stdlib,\"ERTS CXC 138 10\",\"1.16.4\"},\n {kernel,\"ERTS CXC 138 10\",\"2.13.4\"}]},\n {os,{unix,linux}},\n {erlang_version,\"Erlang R13B03 (erts-5.7.4) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:30] [hipe] [kernel-poll:true]\\n\"},\n {memory,[{total,25296704},\n {processes,9680280},\n {processes_used,9662720},\n {system,15616424},\n {atom,1099393},\n {atom_used,1082732},\n {binary,89768},\n {code,11606637},\n {ets,726848}]}]\n...done.\nroot@celery:~# rabbitmqctl cluster_status\nCluster status of node celery@celery ...\n[{nodes,[{disc,[celery@celery]}]},{running_nodes,[celery@celery]}]\n...done.\nroot@celery:~# rabbitmqctl stop_app\nStopping node celery@celery ...\n...done.\nroot@celery:~# rabbitmqctl reset\nResetting node celery@celery ...\n...done.\nroot@celery:~# rabbitmqctl cluster worker1@worker1\nClustering node celery@celery with [worker1@worker1] ...\nError: {failed_to_cluster_with,[worker1@worker1],\n \"Mnesia could not connect to some nodes.\"}\n```\n\nWhat are the possible reasons one node wouldn't be able to connect to another?\n\nHere's the guide I'm following: http://www.rabbitmq.com/clustering.html\n\n========================================\n\nTop Answer:\nI installed the Docker RabbitMQ also encountered similar problems in the process.\n\nThe main reason is `/var/lib/RabbitMQ/mnesia/rabbit/cluster_nodes.config` configuration file on errors cannot be connected to.\n\nMnesia is a distributed, soft real-time database management system written in the Erlang programming language\n\nThere are several ways to repair this problem:\n\n- Fix the configure file,using the correct cluster node name, from the log we see that our Node name is `rabbit@cb43449d5d72`\n\n```\n// log info \n...\nrabbitmq | Starting broker...2019-11-27 16:18:22.621 [info] \nrabbitmq | node : rabbit@cb43449d5d72\n...\n\n// This is the wrong configuration file:\n$ cat ./mnesia/rabbit/cluster_nodes.config\n{[rabbit@cb43449d5d72,rabbit@dc3288264c34],[rabbit@dc3288264c34]}.\n\n// Update it with correctly config node name, and restart RabbitMQ server:\n$ cat ./mnesia/rabbit/cluster_nodes.config\n{[rabbit@cb43449d5d72],[rabbit@cb43449d5d72]}.\n```\n\n- The simplest way is to remove the `mnesia` directory and configure the correct `node` name, which like `rabbit@my-rabbit`, in `/etc/hosts` is `127.0.0.1 my-rabbit`, after the operation, you should see the following configuration details\n\n```\n$ find . -name cluster_nodes.config\n./mnesia/rabbit/cluster_nodes.config\n./mnesia/rabbit@my-rabbit/cluster_nodes.config\n\n$ cat ./mnesia/rabbit@my-rabbit/cluster_nodes.config\n{['rabbit@my-rabbit'],['rabbit@my-rabbit']}.\n```\n\n========================================\n\nCode:\n```text\nroot@celery:~# rabbitmqctl status\nStatus of node celery@celery ...\n[{pid,20410},\n {running_applications,[{rabbit,\"RabbitMQ\",\"2.5.1\"},\n {os_mon,\"CPO CXC 138 46\",\"2.2.4\"},\n {sasl,\"SASL CXC 138 11\",\"2.1.8\"},\n {mnesia,\"MNESIA CXC 138 12\",\"4.4.12\"},\n {stdlib,\"ERTS CXC 138 10\",\"1.16.4\"},\n {kernel,\"ERTS CXC 138 10\",\"2.13.4\"}]},\n {os,{unix,linux}},\n {erlang_version,\"Erlang R13B03 (erts-5.7.4) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:30] [hipe] [kernel-poll:true]\\n\"},\n {memory,[{total,25296704},\n {processes,9680280},\n {processes_used,9662720},\n {system,15616424},\n {atom,1099393},\n {atom_used,1082732},\n {binary,89768},\n {code,11606637},\n {ets,726848}]}]\n...done.\nroot@celery:~# rabbitmqctl cluster_status\nCluster status of node celery@celery ...\n[{nodes,[{disc,[celery@celery]}]},{running_nodes,[celery@celery]}]\n...done.\nroot@celery:~# rabbitmqctl stop_app\nStopping node celery@celery ...\n...done.\nroot@celery:~# rabbitmqctl reset\nResetting node celery@celery ...\n...done.\nroot@celery:~# rabbitmqctl cluster worker1@worker1\nClustering node celery@celery with [worker1@worker1] ...\nError: {failed_to_cluster_with,[worker1@worker1],\n \"Mnesia could not connect to some nodes.\"}\n```\n\n```text\n14:29 shakakai: hey all, i'm having a little issue with clustering rabbitmq http://stackoverflow.com/questions/6948624/mnesia-cant-connect-to-another-node\n14:30 shakakai: has anyone run into that problem before?\n14:30 daysmen has left IRC (Read error: Connection reset by peer)\n14:30 antares_: shakakai: make sure that epmd is running on every node\n14:30 antares_: shakakai: and that port it uses (4369) is open in your firewall\n14:31 |Blaze|: shakakai: is your dns correct? Can you ping worker1 from celery and celery from worker1\n14:31 shakakai: |Blaze|: hmm...i'll check\n14:31 daysmen has joined (~quassel@host-84-13-157-50.opaltelecom.net)\n14:32 shakakai: |Blaze|: this is where I'm a little confused, the rabbitmq nodename is worker1@worker1 but the fqdn to ping the box is \"ping worker1.mydomain.com\"\n14:33 |Blaze|: can you \"ping worker1\"\n14:34 shakakai: |Blaze|: no\n14:34 |Blaze|: k, you'll need to fix that\n14:34 hyperboreean has left IRC (Ping timeout: 250 seconds)\n14:37 shakakai: |Blaze|: gotcha, so I setup a hosts file and i should be good\n14:37 |Blaze|: yup\n14:37 |Blaze|: in both directions\n```\n\n```text\n// log info \n...\nrabbitmq | Starting broker...2019-11-27 16:18:22.621 [info] <0.304.0>\nrabbitmq | node : rabbit@cb43449d5d72\n...\n\n// This is the wrong configuration file:\n$ cat ./mnesia/rabbit/cluster_nodes.config\n{[rabbit@cb43449d5d72,rabbit@dc3288264c34],[rabbit@dc3288264c34]}.\n\n// Update it with correctly config node name, and restart RabbitMQ server:\n$ cat ./mnesia/rabbit/cluster_nodes.config\n{[rabbit@cb43449d5d72],[rabbit@cb43449d5d72]}.\n```\n\n```text\n$ find . -name cluster_nodes.config\n./mnesia/rabbit/cluster_nodes.config\n./mnesia/rabbit@my-rabbit/cluster_nodes.config\n\n$ cat ./mnesia/rabbit@my-rabbit/cluster_nodes.config\n{['rabbit@my-rabbit'],['rabbit@my-rabbit']}.\n```\n\n```text\n/var/lib/RabbitMQ/mnesia/rabbit/cluster_nodes.config\n```\n\n```text\nrabbit@cb43449d5d72\n```\n\n```text\nmnesia\n```\n\n```text\nnode\n```\n\n```text\nrabbit@my-rabbit\n```\n\n```text\n/etc/hosts\n```\n\n```text\n127.0.0.1 my-rabbit\n```\n\n========================================\n\nComments:\n- I don't think it's taboo to accept your own answer, especially since it's a good one.\n- whoops - forgot about that :P","metadata":{"transformedAt":"2026-08-18T18:33:20.183Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":11,"totalLines":207,"estimatedTokens":1688}}686{"id":"stack-25796788","source":"stackoverflow","questionId":25796788,"title":"Remotely create a vhost on a docker container running rabbitmq","tags":["rabbitmq","docker","vagrantfile"],"text":"Title: Remotely create a vhost on a docker container running rabbitmq\nTags: rabbitmq, docker, vagrantfile\nSource: Stack Overflow\n\nQuestion:\nI have a Vagrantfile that does 2 important things; firstly pulls and runs dockerfile/rabbitmq, then builds from a custom Dockerfile that runs an application which assumes a vhost on the rabbitmq server, let's say \"/foo\".\n\nThe problem is the vhost is not there.\n\nThe container with rabbitmq is running successfully, the app is linked to it using --link as the built image is run. Using the environment variables docker sets I can hit the server. But somewhere in the middle of these operations I need to create the vhost as my connection is refused, i assume because \"/foo\" is not there.\n\nHow can I get the vhost onto the rabbit server?\n\nThanks\n\nnote - using the webadmin is not an option, this has to be done programatically.\n\n========================================\n\nTop Answer:\nThere are few ways to get desired configuration:\n\n- Export/import whole configuration with `rabbitmqadmin` - Management Plugin CLI tool.\n\nor \n\n- Use HTTP API from management plugin\n\nor \n\n- Use `rabbitmqctl` cli tool to manage access control.\n\n========================================\n\nCode:\n```text\ndefault_vhost\n```\n\n```text\n/etc/rabbitmq/rabbitmq.config\n```\n\n```text\nrabbitmqadmin\n```\n\n```text\nrabbitmqctl\n```\n\n```text\ncurl -u userename:pa$sw0rD -X PUT http://rabbitmq.local:15672/api/vhosts/vh1\n```\n\n========================================\n\nComments:\n- Thanks Zaq. I've had difficulties with these options. Even installing the management plugin on linux! It feels like i should just be able to use `rabbitmqctl` and add the vhost passing a host option, but maybe i've got the syntax wrong. However, having my vhosts in config also sounds like a good option. Can you give some examples?\n- There are example on the `rabbitmqctl` manual page (i fixed the link in the answer). As to `rabbitmqadmin`, the idea is to manually configure rabbitmq server and then export it configuration to reuse later. There are also cli examples on the `rabbitmqadmin` link (at the bottom of the page).\n- This doesn't explain how to do it in the docker...\n- @acidjunk for example stackoverflow.com/questions/58266688/…","metadata":{"transformedAt":"2026-08-18T18:33:20.183Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":62,"estimatedTokens":557}}687{"id":"stack-14867683","source":"stackoverflow","questionId":14867683,"title":"How to architect a multi-step process using a message queue?","tags":["asynchronous","rabbitmq","message-queue","amqp"],"text":"Title: How to architect a multi-step process using a message queue?\nTags: asynchronous, rabbitmq, message-queue, amqp\nSource: Stack Overflow\n\nQuestion:\nSay I have a multi-step, asynchronous process with these restrictions:\n\n- Individual steps can be performed by any worker\n\n- Steps must be performed in-order\n\nThe approach I'm considering:\n\n- Insert a db row that represents the entire process, with a \"Steps completed\" column to keep track of the progress.\n\n- Subscribe to a queue that will receive a message when the entire process is done.\n\n- Upon completion of each step, update the db row and queue the next step in the process.\n\n- After the last step is completed, queue the \"process is complete\" message.\n\n- Delete the db row.\n\nThoughts? Pitfalls? Smarter ways to do it?\n\n========================================\n\nComments:\n- EXCELLENT answer, J.T. Thank you so much; I'll definitely take an approach like you suggest here.\n- Side-question: how would you handle tasks to be queued at a later date? Store in a db until they're ready to be queued? That's my current plan.\n- Yes, I think that's right. As tempting as it would be to want to put future tasks into an MQ, it is not consistent with the sematics of message queueing--you would, for example, at some point have to insert a task at a certain location in the queue. That feels like something more appropriately done at the database level, and then you have the tight semantic that tasks which are actively ready to process are in the queues, and those which are not are in the DB.\n- FYI, I asked the RabbitMQ provider I'm using (CloudAMQP), and they went above and beyond to create this tutorial on how to delay messages without relying on a db: cloudamqp.com/docs-delayed-messages.html","metadata":{"transformedAt":"2026-08-18T18:33:20.183Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":32,"estimatedTokens":438}}688{"id":"stack-2364080","source":"stackoverflow","questionId":2364080,"title":"Simple scalable work/message queue with delay","tags":["message-queue","rabbitmq","gearman","beanstalkd"],"text":"Title: Simple scalable work/message queue with delay\nTags: message-queue, rabbitmq, gearman, beanstalkd\nSource: Stack Overflow\n\nQuestion:\nI need to set up a job/message queue with the option to set a delay for the task so that it's not picked up immediately by a free worker, but after a certain time (can vary from task to task). I looked into a couple of linux queue solutions (rabbitmq, gearman, memcacheq), but none of them seem to offer this feature out of the box. \n\nAny ideas on how I could achieve this?\n\nThanks!\n\n========================================\n\nTop Answer:\nYou could use an AMQP broker (such as RabbitMQ) and I have an \"agent\" (e.g. a python process built using pyton-amqplib) that sits on an exchange an intercepts specific messages (specific `routing_key`); once a timer has elapsed, send back the message on the exchange with a different `routing_key`.\n\nI realize this means \"translating/mapping\" `routing keys` but it works. Working with RabbitMQ and python-amqplib is very straightforward.\n\n========================================\n\nCode:\n```text\nrouting_key\n```\n\n```text\nrouting_key\n```\n\n```text\nrouting keys\n```\n\n========================================\n\nComments:\n- I thought about this, but if the waiting agent gets killed while it's waiting for the timer to elapse, the message never gets added to the queue. Maybe I could fix this by having a second, permanent queue, and an agent with multiple internal timers. Still, it seems like an ugly workaround.\n- Well, dealing with this failure-mode is part of the game. I would be surprised if the functionality you are asking gets mainstream in AMQP Brokers out-there since it goes against the main goal: minimize latency.\n- Thank you for your replies. I think I will give beanstalkd a try, it seems ok, and supports the \"delay\" I was talking about.\n- Thank you for your feedback, I've been looking into beanstalkd the past couple of days and it looks great. And you're right, worker logic and management is tricky :)","metadata":{"transformedAt":"2026-08-18T18:33:20.183Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":40,"estimatedTokens":498}}689{"id":"stack-28357820","source":"stackoverflow","questionId":28357820,"title":"rabbitmq with spring amqp - messages stuck in case of AmqpException","tags":["rabbitmq","amqp","spring-amqp"],"text":"Title: rabbitmq with spring amqp - messages stuck in case of AmqpException\nTags: rabbitmq, amqp, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI am throwing an AmqpException inside of my consumer. \nMy expectation is that the message will return back to the queue in FIFO order and will be reprocessed sometime in the future.\n\nIt seems as if Spring AMQP does not release the message back to the queue. But instead tries to reprocess the failed messages over and over again.\nThis blocks the newly arrived messages from being processed. The ones that are stuck appear in the \"unpacked\" state forever inside of the AMQP console.\n\nAny thoughts?\n\n========================================\n\nTop Answer:\nHere is a solution I used to solve this. I setup an Interceptor to retry the message x number of times while applying a backoff policy.\nhttp://trippstech.blogspot.com/2016/03/rabbitmq-deadletter-queue-with.html\n\n========================================\n\nCode:\n```text\ndefaultRequeueRejected\n```\n\n```text\nAmqpRejectAndDontRequeueException\n```\n\n```text\nx-death\n```\n\n========================================\n\nComments:\n- I was hoping to use the Spring AMQP RetryOperationsInterceptor, that would kick in when throwing the AmqpException. Once the max retry attempt is reached a \"Recoverer\" would throws an AmqpRejectAndDontRequeueException, that will discard the message. I figured in between the retry attempts by the retry interceptor (which could take a few hours with exponential backoff) the message would go back to the queue, allowing for newly arrived messages to be processed.\n- No; the retry interceptor simply blocks the thread before delivering it to the listener; it is only suited for short delays between retries; you need to use the broker as I described to defer redeliveries. There is no other way for the consumer to tell the broker to wait a while before redelivering; it's just not part of the amqp protocol. Even with JMS, such delays are proprietary to the broker and are not part of the jms API.\n- Great - thanks for your feedback. Will reconsider my approach.\n- Nice solution, though it requires some setting up. I still would like dead messages not to vanish forever, but be available in a dead letter queue for inspection.\n- You can use the `x-death` header to detect the number of cycles and after some number, re-publish the message to some other queue.","metadata":{"transformedAt":"2026-08-18T18:33:20.183Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":42,"estimatedTokens":594}}690{"id":"stack-46187647","source":"stackoverflow","questionId":46187647,"title":"socket.gaierror gaierror: [Errno -2] Name or service not known - pika rabbitMQ","tags":["python","sockets","docker","rabbitmq","pika"],"text":"Title: socket.gaierror gaierror: [Errno -2] Name or service not known - pika rabbitMQ\nTags: python, sockets, docker, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI am trying to send a message from a python server hosted on localhost:5000 to a RabbitMQ server( using a docker image for RabbitMQ) , but I am getting the following error :\n\n socket.gaierror gaierror: [Errno -2] Name or service not known\n\nI am running the docker image for RabbitMQ using the command where 'rabbithost' is the hostname I am using:\n\n sudo docker run -d --hostname rabbithost --name rabbitmq -p\n 15672:15672 -p 5672:5672 -p 5671:5671 rabbitmq:3-management\n\nHere is the python code which is giving the error:\n\n```\ndef send_to_queue(message):\n credentials = pika.PlainCredentials('guest', 'guest')\n parameters = pika.ConnectionParameters('rabbithost', 5672, '/', credentials)\n connection = pika.BlockingConnection(parameters)\n channel = connection.channel()\n channel.queue_declare(queue='hello')\n channel.basic_publish(exchange='', routing_key='hello',body=message)\n connection.close()\n return \"Message Sent! \"\n```\n\nThe error is at line : \n\n connection = pika.BlockingConnection(parameters)\n\nmainly because of the parameters argument. \nI am not able to find the exact solution for this error.\n\n========================================\n\nCode:\n```text\ndef send_to_queue(message):\n credentials = pika.PlainCredentials('guest', 'guest')\n parameters = pika.ConnectionParameters('rabbithost', 5672, '/', credentials)\n connection = pika.BlockingConnection(parameters)\n channel = connection.channel()\n channel.queue_declare(queue='hello')\n channel.basic_publish(exchange='', routing_key='hello',body=message)\n connection.close()\n return \"Message Sent! \"\n```\n\n```text\nrabbithost\n```\n\n```text\n127.0.0.1\n```\n\n```text\n/etc/hosts\n```\n\n```text\n127.0.0.1 rabbithost\n```\n\n========================================\n\nComments:\n- Where is the python code running? On localhost? If yes then you either need to change `rabbithost` to `127.0.0.1` or make a host entry in `/etc/hosts` for `127.0.0.1 rabbithost`\n- @TarunLalwani This actually worked! . thanks for your suggestion.","metadata":{"transformedAt":"2026-08-18T18:33:20.183Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":71,"estimatedTokens":542}}691{"id":"stack-37791757","source":"stackoverflow","questionId":37791757,"title":"RabbitMQ log and Mnesia location in Environment variables not reflecting?","tags":["rabbitmq","rabbitmqctl"],"text":"Title: RabbitMQ log and Mnesia location in Environment variables not reflecting?\nTags: rabbitmq, rabbitmqctl\nSource: Stack Overflow\n\nQuestion:\nI want to change the Rabbitmq MNESIA dir to `/disk` folder instead of default `/var/lib`. I did the change in `/usr/lib/rabbitmq/bin` at `rabbitmq-env` with \n\n```\nRABBITMQ_MNESIA_BASE=/disk/rabbitmq/\nRABBITMQ_LOG_BASE=/disk/rabbitmq/log/\n```\n\nAnd after restarting it with \n\n```\nservice rabbitmq-server restart\nRestarting rabbitmq-server (via systemctl): [ OK ]\n```\n\nBut when i check the status as \n\n```\n> service rabbitmq-server status \nWARNING: Removing trailing slash from RABBITMQ_MNESIA_BASE\nWARNING: Removing trailing slash from RABBITMQ_MNESIA_BASE\nStatus of node 'rabbit@ip-10-03-209-294' ...\nError: unable to connect to node 'rabbit@ip-10-03-209-294': nodedown\n\nDIAGNOSTICS\n===========\n\nattempted to contact: ['rabbit@ip-10-03-209-294']\n\nrabbit@ip-10-03-209-294:\n * connected to epmd (port 4369) on ip-10-03-209-294\n * epmd reports: node 'rabbit' not running at all\n no other nodes on ip-10-03-209-294\n * suggestion: start the node\n\ncurrent node details:\n- node name: 'rabbitmq-cli-61@10-03-209-294'\n- home dir: /var/lib/rabbitmq\n- cookie hash: D1JxYyl9vuDgVmH5K4dGyQ==\n```\n\nAfter removing all the changes ,it is working fine.But i want the MNESIA dir to be /disk. I restarted the instance as well.\n\n========================================\n\nTop Answer:\nInstead of these env variables\n\n```\nRABBITMQ_MNESIA_BASE=/disk/rabbitmq/\nRABBITMQ_LOG_BASE=/disk/rabbitmq/log/\n```\n\nTry\n\n```\nMNESIA_BASE=/disk/rabbitmq/\nLOG_BASE=/disk/rabbitmq/log/\n```\n\nThis at least worked for me after I stopped and restarted.\n\n========================================\n\nCode:\n```text\nRABBITMQ_MNESIA_BASE=/disk/rabbitmq/\nRABBITMQ_LOG_BASE=/disk/rabbitmq/log/\n```\n\n```text\nservice rabbitmq-server restart\nRestarting rabbitmq-server (via systemctl): [ OK ]\n```\n\n```text\n> service rabbitmq-server status \nWARNING: Removing trailing slash from RABBITMQ_MNESIA_BASE\nWARNING: Removing trailing slash from RABBITMQ_MNESIA_BASE\nStatus of node 'rabbit@ip-10-03-209-294' ...\nError: unable to connect to node 'rabbit@ip-10-03-209-294': nodedown\n\nDIAGNOSTICS\n===========\n\nattempted to contact: ['rabbit@ip-10-03-209-294']\n\nrabbit@ip-10-03-209-294:\n * connected to epmd (port 4369) on ip-10-03-209-294\n * epmd reports: node 'rabbit' not running at all\n no other nodes on ip-10-03-209-294\n * suggestion: start the node\n\ncurrent node details:\n- node name: 'rabbitmq-cli-61@10-03-209-294'\n- home dir: /var/lib/rabbitmq\n- cookie hash: D1JxYyl9vuDgVmH5K4dGyQ==\n```\n\n```text\n/disk\n```\n\n```text\n/var/lib\n```\n\n```text\n/usr/lib/rabbitmq/bin\n```\n\n```text\nrabbitmq-env\n```\n\n```text\nroot@bae18650cea4:/# service rabbitmq-server status\nStatus of node rabbit@bae18650cea4 ...\n[{pid,15240},\n {running_applications,[{rabbit,\"RabbitMQ\",\"3.6.2\"},\n {mnesia,\"MNESIA CXC 138 12\",\"4.13.3\"},\n {os_mon,\"CPO CXC 138 46\",\"2.4\"},\n {rabbit_common,[],\"3.6.2\"},\n {xmerl,\"XML parser\",\"1.3.10\"},\n {ranch,\"Socket acceptor pool for TCP protocols.\",\n \"1.2.1\"},\n {sasl,\"SASL CXC 138 11\",\"2.7\"},\n {stdlib,\"ERTS CXC 138 10\",\"2.8\"},\n {kernel,\"ERTS CXC 138 10\",\"4.2\"}]},\n {os,{unix,linux}},\n {erlang_version,\"Erlang/OTP 18 [erts-7.3] [source] [64-bit] [async-threads:64] [kernel-poll:true]\\n\"},\n {memory,[{total,139371632},\n {connection_readers,0},\n {connection_writers,0},\n {connection_channels,0},\n {connection_other,0},\n {queue_procs,2592},\n {queue_slave_procs,0},\n {plugins,0},\n {other_proc,18525024},\n {mnesia,58264},\n {mgmt_db,0},\n {msg_index,41880},\n {other_ets,920384},\n {binary,19128},\n {code,19777571},\n {atom,752537},\n {other_system,99274252}]},\n {alarms,[]},\n {listeners,[{clustering,25672,\"::\"},{amqp,5672,\"::\"}]},\n {vm_memory_high_watermark,0.4},\n {vm_memory_limit,839966720},\n {disk_free_limit,50000000},\n {disk_free,17685676032},\n {file_descriptors,[{total_limit,1048476},\n {total_used,2},\n {sockets_limit,943626},\n {sockets_used,0}]},\n {processes,[{limit,1048576},{used,137}]},\n {run_queue,0},\n {uptime,399},\n {kernel,{net_ticktime,60}}]\nroot@bae18650cea4:/#\n```\n\n```text\n/etc/init.d/rabbitmq-server stop\n```\n\n```text\nnano /etc/rabbitmq/rabbitmq-env.conf\n```\n\n```text\nchown rabbitmq:rabbitmq /disk/(and all subdirs)\n```\n\n```text\n/etc/init.d/rabbitmq-server start\n```\n\n```text\nservice rabbitmq-server status\n```\n\n```text\nRABBITMQ_MNESIA_BASE=/disk/rabbitmq/\nRABBITMQ_LOG_BASE=/disk/rabbitmq/log/\n```\n\n```text\nMNESIA_BASE=/disk/rabbitmq/\nLOG_BASE=/disk/rabbitmq/log/\n```\n\n```text\n- name: Enabling Selinux by default\n selinux:\n policy: targeted\n state: enforcing\n\n- name: selinux | allow selinux rabbitmq_t\n selinux_permissive:\n name: rabbitmq_t\n permissive: true\n\n- name: Run selinux restore context on /etc\n shell: \"restorecon -Rv /etc/\"\n\n- name: rabbitmq | Fix the SELINUX fcontenxt\n sefcontext:\n target: '/var/lib/rabbitmq/(.*)?'\n setype: rabbitmq_var_lib_t\n state: present\n notify:\n - reset permissions\n - restart rabbitmq-server\n\n- name: Allow RabbitMQ Selinux TCP to listen on\n seport:\n ports: 5672,15672\n proto: tcp\n setype: rabbitmq_port_t\n state: present\n```\n\n========================================\n\nComments:\n- after doing step 4. it starts and if i am exiting using ctrl+c then it stops ? How can i overcome this ???\n- You shouldn't stop it, this happens if the directories don't have the right permission !\n- i just restarted it after many days,it went down and the data dir automatically gets changed to /var/lib/rabbitmq ???\n- \"automatically gets changed\" you maybe missed to set the enviroment variabiles. I think that it is not possible that RMQ changes the directory automatically","metadata":{"transformedAt":"2026-08-18T18:33:20.183Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":16,"totalLines":237,"estimatedTokens":1523}}692{"id":"stack-40184788","source":"stackoverflow","questionId":40184788,"title":"Protocol Not Found socket.getprotobyname","tags":["python","sockets","rabbitmq","ubuntu-14.04","protocols"],"text":"Title: Protocol Not Found socket.getprotobyname\nTags: python, sockets, rabbitmq, ubuntu-14.04, protocols\nSource: Stack Overflow\n\nQuestion:\nI'm trying to connect to an rabbitMQ server but the it keeps failing on connection with a `socket.error: protocol not found` error. \n\n```\nIn [1]: import pika\n\nIn [2]: pika.BlockingConnection(pika.ConnectionParameters('ip_of_server'))\n```\n\nwith error output of \n\n```\n---------------------------------------------------------------------------\nerror Traceback (most recent call last)\n in ()\n----> 1 pika.BlockingConnection(pika.ConnectionParameters('localhost')\n 2 )\n\n/usr/lib/python2.7/dist-packages/pika/adapters/blocking_connection.pyc in __init__(self, parameters)\n 105\n 106 \"\"\"\n--> 107 super(BlockingConnection, self).__init__(parameters, None, False)\n 108\n 109 def add_on_close_callback(self, callback_method_unused):\n\n/usr/lib/python2.7/dist-packages/pika/adapters/base_connection.pyc in __init__(self, parameters, on_open_callback, on_open_error_callback, on_close_callback, ioloop, stop_ioloop_on_close)\n 60 on_open_callback,\n 61 on_open_error_callback,\n---> 62 on_close_callback)\n 63\n 64 def add_timeout(self, deadline, callback_method):\n\n/usr/lib/python2.7/dist-packages/pika/connection.pyc in __init__(self, parameters, on_open_callback, on_open_error_callback, on_close_callback)\n 588 # Initialize the connection state and connect\n 589 self._init_connection_state()\n--> 590 self.connect()\n 591\n 592 def add_backpressure_callback(self, callback_method):\n\n/usr/lib/python2.7/dist-packages/pika/adapters/blocking_connection.pyc in connect(self)\n 204 \"\"\"\n 205 self._set_connection_state(self.CONNECTION_INIT)\n--> 206 if not self._adapter_connect():\n 207 raise exceptions.AMQPConnectionError('Could not connect')\n 208\n\n/usr/lib/python2.7/dist-packages/pika/adapters/blocking_connection.pyc in _adapter_connect(self)\n 272 # Remove the default behavior for connection errors\n 273 self.callbacks.remove(0, self.ON_CONNECTION_ERROR)\n--> 274 if not super(BlockingConnection, self)._adapter_connect():\n 275 raise exceptions.AMQPConnectionError(1)\n 276 self.socket.settimeout(self.SOCKET_CONNECT_TIMEOUT)\n\n/usr/lib/python2.7/dist-packages/pika/adapters/base_connection.pyc in _adapter_connect(self)\n 103 # Get the addresses for the socket, supporting IPv4 & IPv6\n 104 sock_addrs = socket.getaddrinfo(self.params.host, self.params.port,\n--> 105 0, 0, socket.getprotobyname(\"tcp\"))\n 106\n 107 # Iterate through each addr tuple trying to connect\n\nerror: protocol not found\n```\n\nI read this as it was failing on the socket.getprotobyname line in base_connection.pyc. I then tried to use socket.getprotobyname on it's own and I keep getting `error: protocol not found`. It obviously can't fine my TCP connection. \n\nFrom what I can tell, it should output `6`\n\n```\nIn [5]: import socket\n\nIn [6]: socket.getprotobyname('tcp')\n---------------------------------------------------------------------------\nerror Traceback (most recent call last)\n in ()\n----> 1 socket.getprotobyname('tcp')\n\nerror: protocol not found\n```\n\nI am using Ubuntu 14.04 and python 2.7.6 and I have no idea how to troubleshoot this error. \n\nI've read some threads about the /etc/protocols file, but I do not seem to have one. Can this be the problem? If so, is there a generic file I can download or a method to create one?\n\n========================================\n\nCode:\n```text\nIn [1]: import pika\n\nIn [2]: pika.BlockingConnection(pika.ConnectionParameters('ip_of_server'))\n```\n\n```text\n---------------------------------------------------------------------------\nerror Traceback (most recent call last)\n<ipython-input-2-7adc44418966> in <module>()\n----> 1 pika.BlockingConnection(pika.ConnectionParameters('localhost')\n 2 )\n\n/usr/lib/python2.7/dist-packages/pika/adapters/blocking_connection.pyc in __init__(self, parameters)\n 105\n 106 \"\"\"\n--> 107 super(BlockingConnection, self).__init__(parameters, None, False)\n 108\n 109 def add_on_close_callback(self, callback_method_unused):\n\n/usr/lib/python2.7/dist-packages/pika/adapters/base_connection.pyc in __init__(self, parameters, on_open_callback, on_open_error_callback, on_close_callback, ioloop, stop_ioloop_on_close)\n 60 on_open_callback,\n 61 on_open_error_callback,\n---> 62 on_close_callback)\n 63\n 64 def add_timeout(self, deadline, callback_method):\n\n/usr/lib/python2.7/dist-packages/pika/connection.pyc in __init__(self, parameters, on_open_callback, on_open_error_callback, on_close_callback)\n 588 # Initialize the connection state and connect\n 589 self._init_connection_state()\n--> 590 self.connect()\n 591\n 592 def add_backpressure_callback(self, callback_method):\n\n/usr/lib/python2.7/dist-packages/pika/adapters/blocking_connection.pyc in connect(self)\n 204 \"\"\"\n 205 self._set_connection_state(self.CONNECTION_INIT)\n--> 206 if not self._adapter_connect():\n 207 raise exceptions.AMQPConnectionError('Could not connect')\n 208\n\n/usr/lib/python2.7/dist-packages/pika/adapters/blocking_connection.pyc in _adapter_connect(self)\n 272 # Remove the default behavior for connection errors\n 273 self.callbacks.remove(0, self.ON_CONNECTION_ERROR)\n--> 274 if not super(BlockingConnection, self)._adapter_connect():\n 275 raise exceptions.AMQPConnectionError(1)\n 276 self.socket.settimeout(self.SOCKET_CONNECT_TIMEOUT)\n\n/usr/lib/python2.7/dist-packages/pika/adapters/base_connection.pyc in _adapter_connect(self)\n 103 # Get the addresses for the socket, supporting IPv4 & IPv6\n 104 sock_addrs = socket.getaddrinfo(self.params.host, self.params.port,\n--> 105 0, 0, socket.getprotobyname(\"tcp\"))\n 106\n 107 # Iterate through each addr tuple trying to connect\n\nerror: protocol not found\n```\n\n```text\nIn [5]: import socket\n\nIn [6]: socket.getprotobyname('tcp')\n---------------------------------------------------------------------------\nerror Traceback (most recent call last)\n<ipython-input-6-3a85adf1710a> in <module>()\n----> 1 socket.getprotobyname('tcp')\n\nerror: protocol not found\n```\n\n```text\nsocket.error: protocol not found\n```\n\n```text\nerror: protocol not found\n```\n\n```text\n6\n```\n\n```text\nsudo apt-get -o Dpkg::Options::=\"--force-confmiss\" install --reinstall netbase\n```\n\n```text\n/etc/protocols\n```\n\n```text\nnetbase\n```\n\n========================================\n\nComments:\n- Please post the code that is giving this error.","metadata":{"transformedAt":"2026-08-18T18:33:20.183Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":9,"totalLines":188,"estimatedTokens":1687}}693{"id":"stack-12662413","source":"stackoverflow","questionId":12662413,"title":"RabbitMQ and node-amqp: Exchange in confirmed mode does not confirm - why?","tags":["node.js","rabbitmq","node-amqp"],"text":"Title: RabbitMQ and node-amqp: Exchange in confirmed mode does not confirm - why?\nTags: node.js, rabbitmq, node-amqp\nSource: Stack Overflow\n\nQuestion:\nI am writing a Node.js application that relies on RabbitMQ. I'm using node-amqp as the library of choice to connect to RabbitMQ.\n\nOnce I have established a connection to RabbitMQ, first thing I am going to do is to create an exchange:\n\n```\nvar options = { autoDelete: false, confirm: true, durable: true, type: 'direct' };\nconnection.exchange('myExchange', options, function (myExchange) {\n // ...\n});\n```\n\nThis works perfectly. As you can see, I am creating the exchange using `confirm: true`, hence I expect the exchange to be in confirm mode afterwards.\n\nNow a problem appears once I try to publish a message:\n\n```\nvar options = {};\nmyExchange.publish('', { data: 'foobar' }, options, function () {\n // ...\n});\n```\n\nThe problem is that the callback of the `publish` function is never called - although the message was successfully published (as I can see within RabbitMQ's web management tool).\n\nDid I understand confirm mode in a wrong way? Is this a bug with node-amqp?\n\nAny help would be appreciated :-)\n\n========================================\n\nCode:\n```text\nvar options = { autoDelete: false, confirm: true, durable: true, type: 'direct' };\nconnection.exchange('myExchange', options, function (myExchange) {\n // ...\n});\n```\n\n```text\nvar options = {};\nmyExchange.publish('', { data: 'foobar' }, options, function () {\n // ...\n});\n```\n\n```text\nconfirm: true\n```\n\n```text\npublish\n```\n\n```text\nmaster\n```\n\n```text\nhttps://github.com/postwait/node-amqp/tarball/master\n```\n\n```text\nnpm\n```\n\n========================================\n\nComments:\n- this appears to be fixed in node-amqp version 0.2.0. The published npm version works for me.","metadata":{"transformedAt":"2026-08-18T18:33:20.183Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":7,"totalLines":74,"estimatedTokens":449}}694{"id":"stack-32316581","source":"stackoverflow","questionId":32316581,"title":"How do I use the RabbitMQ delayed message queue from PHP?","tags":["php","rabbitmq","php-amqplib"],"text":"Title: How do I use the RabbitMQ delayed message queue from PHP?\nTags: php, rabbitmq, php-amqplib\nSource: Stack Overflow\n\nQuestion:\nI'm trying to use the Delayed Message Queue for RabbitMQ from PHP, but my messages are simply disappearing.\n\nI'm declaring the exchange with the following code:\n\n```\n$this->channel->exchange_declare(\n 'delay',\n 'x-delayed-message',\n false, /* passive, create if exchange doesn't exist */\n true, /* durable, persist through server reboots */\n false, /* autodelete */\n false, /* internal */\n false, /* nowait */\n ['x-delayed-type' => ['S', 'direct']]);\n```\n\nI'm binding the queue with this code:\n\n```\n$this->channel->queue_declare(\n $queueName,\n false, /* Passive */\n true, /* Durable */\n false, /* Exclusive */\n false /* Auto Delete */\n);\n$this->channel->queue_bind($queueName, \"delay\", $queueName);\n```\n\nAnd I'm publishing a message with this code:\n\n```\n$msg = new AMQPMessage(json_encode($msgData), [\n 'delivery_mode' => 2,\n 'x-delay' => 5000]);\n$this->channel->basic_publish($msg, 'delay', $queueName);\n```\n\nBut the message doesn't get delayed; it's still immediately delivered. What am I missing?\n\n========================================\n\nTop Answer:\nThe answer is for those who need message delaying but does not want to dig into details. You need only a few things to get it working:\n\nInstall amqp interop compatible transport for example `enqueue/amqp-bunny` and `enqueue/amqp-tools`.\n\n```\ncomposer require enqueue/amqp-bunny enqueue/amqp-tools\n```\n\nCreate amqp context, add a delay strategy and send delayed messages:\n\n```\ncreateContext();\n$context->setDelayStrategy(new RabbitMqDelayPluginDelayStrategy())\n\n$queue = $context->createQueue('foo');\n$context->declareQueue($queue);\n\n$message = $context->createMessage('Hello world!');\n\n$context->createProducer()\n ->setDeliveryDelay(5000) // 5 sec\n ->send($queue, $message)\n;\n```\n\nBy the way, this not the only strategy available. there is one based on RabbitMQ dead letter queues + ttl. It could be used the same way.\n\n========================================\n\nCode:\n```text\n$this->channel->exchange_declare(\n 'delay',\n 'x-delayed-message',\n false, /* passive, create if exchange doesn't exist */\n true, /* durable, persist through server reboots */\n false, /* autodelete */\n false, /* internal */\n false, /* nowait */\n ['x-delayed-type' => ['S', 'direct']]);\n```\n\n```text\n$this->channel->queue_declare(\n $queueName,\n false, /* Passive */\n true, /* Durable */\n false, /* Exclusive */\n false /* Auto Delete */\n);\n$this->channel->queue_bind($queueName, \"delay\", $queueName);\n```\n\n```text\n$msg = new AMQPMessage(json_encode($msgData), [\n 'delivery_mode' => 2,\n 'x-delay' => 5000]);\n$this->channel->basic_publish($msg, 'delay', $queueName);\n```\n\n```text\nrequire_once __DIR__ . '/vendor/autoload.php';\nuse PhpAmqpLib\\Message\\AMQPMessage;\nuse PhpAmqpLib\\Wire\\AMQPTable;\n\n$msg = new AMQPMessage($data,\n array(\n 'delivery_mode' => 2, # make message persistent\n 'application_headers' => new AMQPTable([\n 'x-delay' => 5000\n ])\n )\n );\n```\n\n```text\nchannel.bind(exhange_name, queue_name, routing_key)\n```\n\n```text\n$this->channel->basic_publish($msg, 'delay', $routing_key);\n```\n\n```text\ncomposer require enqueue/amqp-bunny enqueue/amqp-tools\n```\n\n```text\n<?php\nuse Enqueue\\AmqpTools\\RabbitMqDelayPluginDelayStrategy;\nuse Enqueue\\AmqpBunny\\AmqpConnectionFactory;\n\n$context = (new AmqpConnectionFactory('amqp://'))->createContext();\n$context->setDelayStrategy(new RabbitMqDelayPluginDelayStrategy())\n\n$queue = $context->createQueue('foo');\n$context->declareQueue($queue);\n\n$message = $context->createMessage('Hello world!');\n\n$context->createProducer()\n ->setDeliveryDelay(5000) // 5 sec\n ->send($queue, $message)\n;\n```\n\n```text\nenqueue/amqp-bunny\n```\n\n```text\nenqueue/amqp-tools\n```\n\n========================================\n\nComments:\n- See the answer here on how to set the delay header: groups.google.com/d/msg/rabbitmq-users/vJEG7tdzi4E/lLXF4mhoA‌​AAJ\n- Thanks. I think I'm getting closer to making this work.\n- Thank you. The message is getting delivered through the plugin, but it's not accepting my delay parameter. I've updated my question.\n- i think you may need to set the \"x-delay\" in \"properties->headers\" not in \"properties\" directly. try that and see if it works\n- It appears the AMQP library is filtering out that header. :-(\n- I'm going to give you the correct answer for this. Basically, the AMQP library is broken and I can't pass in custom headers to RabbitMQ. I ended up just storing the jobs in a database and have a task which dispatches them when necessary.\n- that's a bummer :( maybe open a ticket w/ the library in their issues list?\n- This is not an issue with the library. See the answer here on how to set the delay header: groups.google.com/d/msg/rabbitmq-users/vJEG7tdzi4E/lLXF4mhoA‌​AAJ","metadata":{"transformedAt":"2026-08-18T18:33:20.184Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":173,"estimatedTokens":1243}}695{"id":"stack-3331469","source":"stackoverflow","questionId":3331469,"title":"Pre-built AMQP and STOMP client (as in GUI client)","tags":["activemq-classic","rabbitmq","amqp","stomp"],"text":"Title: Pre-built AMQP and STOMP client (as in GUI client)\nTags: activemq-classic, rabbitmq, amqp, stomp\nSource: Stack Overflow\n\nQuestion:\nI'm looking for a client (as in GUI client, not client library) to play with our MQ server and familiarize myself with its semantics. Something that will send and receive messages at the press of a button (or a text command) and maybe even update me about the status of the server queues and messages. Administration would be a bonus. The UI doesn't have to be graphical (i.e. command line clients are fine).\n\nThe server will probably run RabbitMQ so anything RabbitMQ-specific is fine, as is ActiveMQ. But I'd rather have a generic AMQP or STOMP tool.\n\nSo, does anything of the sort exist?\n\nI know some management and monitoring tools come with both server distributions, but no clients, right?\n\n========================================\n\nTop Answer:\nFor Apache ActiveMQ, there is \n\nthe web admin console at http://localhost:8161/admin/\n\nthe ApacheActiveMQBrowser project on Sourceforge:\n\n An open source project of developing\n Message admin gui based tools for\n Apache ActiveMQ.\n\n- HermesJMS, it does not mention ActiveMQ 5 (only 3 and 4) on the plugin page, but there is an active user forum\n\n========================================\n\nCode:\n```text\nBQL> create exchange myexchange;\nok\nBQL> create durable queue 'myqueue'\nok\nBQL> select name,messages from queues where 'durable'=true order by name\n----------------------\n| name | messages |\n----------------------\n| myqueue | 0 |\n```\n\n```text\nrabbitmq-management\n```\n\n```text\nrabbitmq-plugins enable rabbitmq_management\n```\n\n========================================\n\nComments:\n- Well, there's also the Stomp plugin, but I can't comment on it. dev.rabbitmq.com/wiki/StompGateway\n- Also, if you have any questions (anything AMQP-related really), drop a line on the RabbitMQ-discuss mailing list. lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss\n- I was afraid of this. Not too bad, though: I started writing Java again after some 5 years and I got to learn some Ant as well. I'll indeed be writing my own AMQP client using Rabbit's Java library but in the meanwhile I'll play around with BQL. Thanks.\n- BQL turned out to be the tool I was looking for. Thanks! (I've also printed out the protocol specification)\n- Though I've decided on using RabbitMQ, I'll still play around with ActiveMQ using two of the tools you mentioned (I already know about the web interface.) Thanks.","metadata":{"transformedAt":"2026-08-18T18:33:20.184Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":59,"estimatedTokens":621}}696{"id":"stack-8753216","source":"stackoverflow","questionId":8753216,"title":"How to make celery retry using the same worker?","tags":["python","django","rabbitmq","celery"],"text":"Title: How to make celery retry using the same worker?\nTags: python, django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI'm just starting out with celery in a Django project, and am kinda stuck at this particular problem: Basically, I need to distribute a long-running task to different workers. The task is actually broken into several steps, each of which takes considerable time to complete. Therefore, if some step fails, I'd like celery to retry this task using the same worker to reuse the results from the completed steps. I understand that celery uses routing to distribute tasks to certain server, but I can't find anything about this particular problem. I use RabbitMQ as my broker.\n\n========================================\n\nCode:\n```text\nceleryd -l info -n worker1.example.com -Q celery,worker1.example.com\n```\n\n```text\ntask.apply_async(args, kwargs, queue=\"worker1.example.com\")\n```\n\n```text\ntask.retry(queue=\"worker1.example.com\")\n```\n\n```text\ntask.retry(queue=task.request.hostname)\n```\n\n```text\nworker1.example.com\n```\n\n```text\ncelery\n```\n\n========================================\n\nComments:\n- Thanks a lot for the answer! I think this is exactly what I'm looking for. I didn't realize that we can pass the queue name to retry(), but now it makes a lot of sense :)\n- Use `%computername%` on windows and ``hostname`` on linux to build the commandline.","metadata":{"transformedAt":"2026-08-18T18:33:20.184Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":39,"estimatedTokens":344}}697{"id":"stack-40280293","source":"stackoverflow","questionId":40280293,"title":"Defining a queue with a config file in RabbitMQ","tags":["rabbitmq"],"text":"Title: Defining a queue with a config file in RabbitMQ\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nIs there a way to define a queue in a configuration file like in ActiveMQ :\n\nhttp://activemq.apache.org/configure-startup-destinations.html\n\n========================================\n\nCode:\n```text\n{\n \"rabbit_version\" : \"3.5.7\",\n \"users\" : [{\n \"name\" : \"guest\",\n \"password_hash\" : \"42234423423\",\n \"tags\" : \"administrator\"\n }\n ],\n \"vhosts\" : [ {\n \"name\" : \"/uat\"\n }\n ],\n \"permissions\" : [{\n \"user\" : \"guest\",\n \"vhost\" : \"/uat\",\n \"configure\" : \".*\",\n \"write\" : \".*\",\n \"read\" : \".*\"\n }\n ],\n \"parameters\" : [],\n \"policies\" : [],\n \"queues\" : [{\n \"name\" : \"sms\",\n \"vhost\" : \"/uat\",\n \"durable\" : false,\n \"auto_delete\" : false,\n \"arguments\" : {}\n }\n ],\n \"exchanges\" : [],\n \"bindings\" : []\n}\n```\n\n========================================\n\nComments:\n- Is it possible to create queues using rabbitmq additional-config or advanced plugins ?","metadata":{"transformedAt":"2026-08-18T18:33:20.184Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":52,"estimatedTokens":287}}698{"id":"stack-48521576","source":"stackoverflow","questionId":48521576,"title":"Correctly handle Celery Exceptions using autoretry_for","tags":["python","rabbitmq","celery","message-queue"],"text":"Title: Correctly handle Celery Exceptions using autoretry_for\nTags: python, rabbitmq, celery, message-queue\nSource: Stack Overflow\n\nQuestion:\nI have a celery task which is decorated with `autoretry_for` so that in the event of a known exception, it will retry the task. A dummy version here:\n\n```\nclass ExpectedException(Exception):\n pass\n\n@app.task(autoretry_for=(ExpectedException,), retry_kwargs={'max_retries': 2, 'countdown': 1})\ndef decorated_autoretry():\n logging.info(\n \"Attempt: {attempt} of {attempts}\".format(\n attempt=decorated_autoretry.request.retries, attempts=decorated_autoretry.max_retries\n )\n )\n raise ExpectedException\n```\n\nwhen run gives the following output:\n\n```\n[2018-01-30 12:17:31,899: INFO/MainProcess] Received task: interpretationAPI.tasks.util_tasks.decorated_autoretry[9e00f56d-fb90-46db-a735-678fd0b4cb5a] \n[2018-01-30 12:17:31,900: INFO/ForkPoolWorker-1] Attempt: 1 of 3\n[2018-01-30 12:17:31,915: INFO/ForkPoolWorker-1] Task interpretationAPI.tasks.util_tasks.decorated_autoretry[9e00f56d-fb90-46db-a735-678fd0b4cb5a] retry: Retry in 1s: ExpectedException()\n[2018-01-30 12:17:31,915: INFO/MainProcess] Received task: interpretationAPI.tasks.util_tasks.decorated_autoretry[9e00f56d-fb90-46db-a735-678fd0b4cb5a] ETA:[2018-01-30 12:17:32.901955+00:00] \n[2018-01-30 12:17:33,024: INFO/ForkPoolWorker-2] Attempt: 2 of 3\n[2018-01-30 12:17:33,072: INFO/MainProcess] Received task: interpretationAPI.tasks.util_tasks.decorated_autoretry[9e00f56d-fb90-46db-a735-678fd0b4cb5a] ETA:[2018-01-30 12:17:34.029462+00:00] \n[2018-01-30 12:17:33,072: INFO/ForkPoolWorker-2] Task interpretationAPI.tasks.util_tasks.decorated_autoretry[9e00f56d-fb90-46db-a735-678fd0b4cb5a] retry: Retry in 1s: ExpectedException()\n[2018-01-30 12:17:34,033: INFO/ForkPoolWorker-1] Attempt: 3 of 3\n[2018-01-30 12:17:34,037: ERROR/ForkPoolWorker-1] Task interpretationAPI.tasks.util_tasks.decorated_autoretry[9e00f56d-fb90-46db-a735-678fd0b4cb5a] raised unexpected: ExpectedException()\nTraceback (most recent call last):\n File \"/home/greg/gel/interpretation/.env/local/lib/python2.7/site-packages/celery/app/trace.py\", line 374, in trace_task\n R = retval = fun(*args, **kwargs)\n File \"/home/greg/gel/interpretation/.env/local/lib/python2.7/site-packages/celery/app/trace.py\", line 629, in __protected_call__\n return self.run(*args, **kwargs)\n File \"/home/greg/gel/interpretation/.env/local/lib/python2.7/site-packages/celery/app/base.py\", line 474, in run\n raise task.retry(exc=exc, **retry_kwargs)\n File \"/home/greg/gel/interpretation/.env/local/lib/python2.7/site-packages/celery/app/task.py\", line 669, in retry\n raise_with_context(exc)\n File \"/home/greg/gel/interpretation/.env/local/lib/python2.7/site-packages/celery/app/base.py\", line 472, in run\n return task._orig_run(*args, **kwargs)\n File \"/home/greg/gel/interpretation/interpretationAPI/tasks/util_tasks.py\", line 25, in decorated_autoretry\n raise ExpectedException\nExpectedException\n```\n\nwhere in the last attempt the `ExpectedException` is raised but Celery regards it as unexpected.\n\nI can explicitly handle the exceptions here:\n\n```\n@app.task\ndef explicit_autoretry():\n logging.info(\n \"Attempt: {attempt} of {attempts}\".format(\n attempt=explicit_autoretry.request.retries+1, attempts=explicit_autoretry.max_retries\n )\n )\n try:\n raise ExpectedException\n except ExpectedException as e:\n logging.info(msg=\"Received exception of type: {e_type}\".format(e_type=type(e)))\n try:\n explicit_autoretry.retry(countdown=1)\n except MaxRetriesExceededError as e:\n logging.info(msg=\"Received exception of type: {e_type}\".format(e_type=type(e)))\n```\n\nwhich when run gives the following output:\n\n```\n[2018-01-30 12:19:45,284: INFO/MainProcess] Received task: interpretationAPI.tasks.util_tasks.explicit_autoretry[b1f29107-ac73-401d-b0c3-636e91661ee9] \n[2018-01-30 12:19:45,287: INFO/ForkPoolWorker-3] Attempt: 1 of 3\n[2018-01-30 12:19:45,288: INFO/ForkPoolWorker-3] Received exception of type: \n[2018-01-30 12:19:45,301: INFO/ForkPoolWorker-3] Task interpretationAPI.tasks.util_tasks.explicit_autoretry[b1f29107-ac73-401d-b0c3-636e91661ee9] retry: Retry in 1s\n[2018-01-30 12:19:45,301: INFO/MainProcess] Received task: interpretationAPI.tasks.util_tasks.explicit_autoretry[b1f29107-ac73-401d-b0c3-636e91661ee9] ETA:[2018-01-30 12:19:46.288992+00:00] \n[2018-01-30 12:19:47,790: INFO/ForkPoolWorker-1] Attempt: 2 of 3\n[2018-01-30 12:19:47,792: INFO/ForkPoolWorker-1] Received exception of type: \n[2018-01-30 12:19:47,839: INFO/ForkPoolWorker-1] Task interpretationAPI.tasks.util_tasks.explicit_autoretry[b1f29107-ac73-401d-b0c3-636e91661ee9] retry: Retry in 1s\n[2018-01-30 12:19:47,839: INFO/MainProcess] Received task: interpretationAPI.tasks.util_tasks.explicit_autoretry[b1f29107-ac73-401d-b0c3-636e91661ee9] ETA:[2018-01-30 12:19:48.796492+00:00] \n[2018-01-30 12:19:49,789: INFO/ForkPoolWorker-3] Attempt: 3 of 3\n[2018-01-30 12:19:49,789: INFO/ForkPoolWorker-3] Received exception of type: \n[2018-01-30 12:19:49,791: INFO/ForkPoolWorker-3] Task interpretationAPI.tasks.util_tasks.explicit_autoretry[b1f29107-ac73-401d-b0c3-636e91661ee9] retry: Retry in 1s\n[2018-01-30 12:19:49,791: INFO/MainProcess] Received task: interpretationAPI.tasks.util_tasks.explicit_autoretry[b1f29107-ac73-401d-b0c3-636e91661ee9] ETA:[2018-01-30 12:19:50.790244+00:00] \n[2018-01-30 12:19:51,791: INFO/ForkPoolWorker-1] Attempt: 4 of 3\n[2018-01-30 12:19:51,791: INFO/ForkPoolWorker-1] Received exception of type: \n[2018-01-30 12:19:51,791: INFO/ForkPoolWorker-1] Received exception of type: \n[2018-01-30 12:19:51,791: INFO/ForkPoolWorker-1] Task interpretationAPI.tasks.util_tasks.explicit_autoretry[b1f29107-ac73-401d-b0c3-636e91661ee9] succeeded in 0.00055760199939s: None\n```\n\nwhich correctly deals with each instance of `ExpectedException` and the final `MaxRetriesExceededError`, allowing for graceful error handling.\n\nIs there a way of such error handling while using the `autoretry_for` decorator, minimising the amount of explicit error handling ? I've also tried using the `on_failure` handler but to no avail.\n\n========================================\n\nCode:\n```text\nclass ExpectedException(Exception):\n pass\n\n\n@app.task(autoretry_for=(ExpectedException,), retry_kwargs={'max_retries': 2, 'countdown': 1})\ndef decorated_autoretry():\n logging.info(\n \"Attempt: {attempt} of {attempts}\".format(\n attempt=decorated_autoretry.request.retries, attempts=decorated_autoretry.max_retries\n )\n )\n raise ExpectedException\n```\n\n```text\n[2018-01-30 12:17:31,899: INFO/MainProcess] Received task: interpretationAPI.tasks.util_tasks.decorated_autoretry[9e00f56d-fb90-46db-a735-678fd0b4cb5a] \n[2018-01-30 12:17:31,900: INFO/ForkPoolWorker-1] Attempt: 1 of 3\n[2018-01-30 12:17:31,915: INFO/ForkPoolWorker-1] Task interpretationAPI.tasks.util_tasks.decorated_autoretry[9e00f56d-fb90-46db-a735-678fd0b4cb5a] retry: Retry in 1s: ExpectedException()\n[2018-01-30 12:17:31,915: INFO/MainProcess] Received task: interpretationAPI.tasks.util_tasks.decorated_autoretry[9e00f56d-fb90-46db-a735-678fd0b4cb5a] ETA:[2018-01-30 12:17:32.901955+00:00] \n[2018-01-30 12:17:33,024: INFO/ForkPoolWorker-2] Attempt: 2 of 3\n[2018-01-30 12:17:33,072: INFO/MainProcess] Received task: interpretationAPI.tasks.util_tasks.decorated_autoretry[9e00f56d-fb90-46db-a735-678fd0b4cb5a] ETA:[2018-01-30 12:17:34.029462+00:00] \n[2018-01-30 12:17:33,072: INFO/ForkPoolWorker-2] Task interpretationAPI.tasks.util_tasks.decorated_autoretry[9e00f56d-fb90-46db-a735-678fd0b4cb5a] retry: Retry in 1s: ExpectedException()\n[2018-01-30 12:17:34,033: INFO/ForkPoolWorker-1] Attempt: 3 of 3\n[2018-01-30 12:17:34,037: ERROR/ForkPoolWorker-1] Task interpretationAPI.tasks.util_tasks.decorated_autoretry[9e00f56d-fb90-46db-a735-678fd0b4cb5a] raised unexpected: ExpectedException()\nTraceback (most recent call last):\n File \"/home/greg/gel/interpretation/.env/local/lib/python2.7/site-packages/celery/app/trace.py\", line 374, in trace_task\n R = retval = fun(*args, **kwargs)\n File \"/home/greg/gel/interpretation/.env/local/lib/python2.7/site-packages/celery/app/trace.py\", line 629, in __protected_call__\n return self.run(*args, **kwargs)\n File \"/home/greg/gel/interpretation/.env/local/lib/python2.7/site-packages/celery/app/base.py\", line 474, in run\n raise task.retry(exc=exc, **retry_kwargs)\n File \"/home/greg/gel/interpretation/.env/local/lib/python2.7/site-packages/celery/app/task.py\", line 669, in retry\n raise_with_context(exc)\n File \"/home/greg/gel/interpretation/.env/local/lib/python2.7/site-packages/celery/app/base.py\", line 472, in run\n return task._orig_run(*args, **kwargs)\n File \"/home/greg/gel/interpretation/interpretationAPI/tasks/util_tasks.py\", line 25, in decorated_autoretry\n raise ExpectedException\nExpectedException\n```\n\n```text\n@app.task\ndef explicit_autoretry():\n logging.info(\n \"Attempt: {attempt} of {attempts}\".format(\n attempt=explicit_autoretry.request.retries+1, attempts=explicit_autoretry.max_retries\n )\n )\n try:\n raise ExpectedException\n except ExpectedException as e:\n logging.info(msg=\"Received exception of type: {e_type}\".format(e_type=type(e)))\n try:\n explicit_autoretry.retry(countdown=1)\n except MaxRetriesExceededError as e:\n logging.info(msg=\"Received exception of type: {e_type}\".format(e_type=type(e)))\n```\n\n```text\n[2018-01-30 12:19:45,284: INFO/MainProcess] Received task: interpretationAPI.tasks.util_tasks.explicit_autoretry[b1f29107-ac73-401d-b0c3-636e91661ee9] \n[2018-01-30 12:19:45,287: INFO/ForkPoolWorker-3] Attempt: 1 of 3\n[2018-01-30 12:19:45,288: INFO/ForkPoolWorker-3] Received exception of type: <class 'interpretationAPI.tasks.util_tasks.ExpectedException'>\n[2018-01-30 12:19:45,301: INFO/ForkPoolWorker-3] Task interpretationAPI.tasks.util_tasks.explicit_autoretry[b1f29107-ac73-401d-b0c3-636e91661ee9] retry: Retry in 1s\n[2018-01-30 12:19:45,301: INFO/MainProcess] Received task: interpretationAPI.tasks.util_tasks.explicit_autoretry[b1f29107-ac73-401d-b0c3-636e91661ee9] ETA:[2018-01-30 12:19:46.288992+00:00] \n[2018-01-30 12:19:47,790: INFO/ForkPoolWorker-1] Attempt: 2 of 3\n[2018-01-30 12:19:47,792: INFO/ForkPoolWorker-1] Received exception of type: <class 'interpretationAPI.tasks.util_tasks.ExpectedException'>\n[2018-01-30 12:19:47,839: INFO/ForkPoolWorker-1] Task interpretationAPI.tasks.util_tasks.explicit_autoretry[b1f29107-ac73-401d-b0c3-636e91661ee9] retry: Retry in 1s\n[2018-01-30 12:19:47,839: INFO/MainProcess] Received task: interpretationAPI.tasks.util_tasks.explicit_autoretry[b1f29107-ac73-401d-b0c3-636e91661ee9] ETA:[2018-01-30 12:19:48.796492+00:00] \n[2018-01-30 12:19:49,789: INFO/ForkPoolWorker-3] Attempt: 3 of 3\n[2018-01-30 12:19:49,789: INFO/ForkPoolWorker-3] Received exception of type: <class 'interpretationAPI.tasks.util_tasks.ExpectedException'>\n[2018-01-30 12:19:49,791: INFO/ForkPoolWorker-3] Task interpretationAPI.tasks.util_tasks.explicit_autoretry[b1f29107-ac73-401d-b0c3-636e91661ee9] retry: Retry in 1s\n[2018-01-30 12:19:49,791: INFO/MainProcess] Received task: interpretationAPI.tasks.util_tasks.explicit_autoretry[b1f29107-ac73-401d-b0c3-636e91661ee9] ETA:[2018-01-30 12:19:50.790244+00:00] \n[2018-01-30 12:19:51,791: INFO/ForkPoolWorker-1] Attempt: 4 of 3\n[2018-01-30 12:19:51,791: INFO/ForkPoolWorker-1] Received exception of type: <class 'interpretationAPI.tasks.util_tasks.ExpectedException'>\n[2018-01-30 12:19:51,791: INFO/ForkPoolWorker-1] Received exception of type: <class 'celery.exceptions.MaxRetriesExceededError'>\n[2018-01-30 12:19:51,791: INFO/ForkPoolWorker-1] Task interpretationAPI.tasks.util_tasks.explicit_autoretry[b1f29107-ac73-401d-b0c3-636e91661ee9] succeeded in 0.00055760199939s: None\n```\n\n```text\nautoretry_for\n```\n\n```text\nExpectedException\n```\n\n```text\nExpectedException\n```\n\n```text\nMaxRetriesExceededError\n```\n\n```text\nautoretry_for\n```\n\n```text\non_failure\n```\n\n```text\n@app.task(throws=(ExpectedException,), autoretry_for=(ExpectedException,), retry_kwargs={'max_retries': 2, 'countdown': 1})\ndef decorated_autoretry():\n logging.info(\n \"Attempt: {attempt} of {attempts}\".format(\n attempt=decorated_autoretry.request.retries, attempts=decorated_autoretry.max_retries\n )\n )\n raise ExpectedException\n```\n\n```text\n[2018-01-30 12:43:48,684: INFO/MainProcess] Received task: interpretationAPI.tasks.util_tasks.decorated_autoretry[34de3cb0-9fec-4bc3-a900-c0eb5d8eb5b0] \n[2018-01-30 12:43:48,685: INFO/ForkPoolWorker-1] Attempt: 1 of 3\n[2018-01-30 12:43:48,687: INFO/ForkPoolWorker-1] Task interpretationAPI.tasks.util_tasks.decorated_autoretry[34de3cb0-9fec-4bc3-a900-c0eb5d8eb5b0] retry: Retry in 1s: ExpectedException()\n[2018-01-30 12:43:48,688: INFO/MainProcess] Received task: interpretationAPI.tasks.util_tasks.decorated_autoretry[34de3cb0-9fec-4bc3-a900-c0eb5d8eb5b0] ETA:[2018-01-30 12:43:49.685804+00:00] \n[2018-01-30 12:43:51,641: INFO/ForkPoolWorker-2] Attempt: 2 of 3\n[2018-01-30 12:43:51,643: INFO/ForkPoolWorker-2] Task interpretationAPI.tasks.util_tasks.decorated_autoretry[34de3cb0-9fec-4bc3-a900-c0eb5d8eb5b0] retry: Retry in 1s: ExpectedException()\n[2018-01-30 12:43:51,643: INFO/MainProcess] Received task: interpretationAPI.tasks.util_tasks.decorated_autoretry[34de3cb0-9fec-4bc3-a900-c0eb5d8eb5b0] ETA:[2018-01-30 12:43:52.642046+00:00] \n[2018-01-30 12:43:53,459: INFO/ForkPoolWorker-1] Attempt: 3 of 3\n[2018-01-30 12:43:53,461: INFO/ForkPoolWorker-1] Task interpretationAPI.tasks.util_tasks.decorated_autoretry[34de3cb0-9fec-4bc3-a900-c0eb5d8eb5b0] raised expected: ExpectedException()\n```\n\n```text\nthrows=(ExpectedException,)\n```\n\n```text\nraised expected: ExpectedException()\n```\n\n========================================\n\nComments:\n- I want to do something different when max retries are exceeded. Ex- Sending a Mail. But adding throws will not solve this issue as I can't intercept the MaxRetriesExceededError\n- Can you catch the ExpectedException and then send the email ?\n- No, he/she can't because, in that case, the exception should be re-raised for Celery to pick it up, and you still need to count the remaining retries somehow which we don't want to do, and is the main reason to use the \"autoretry_for\"","metadata":{"transformedAt":"2026-08-18T18:33:20.184Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":14,"totalLines":240,"estimatedTokens":3555}}699{"id":"stack-54146342","source":"stackoverflow","questionId":54146342,"title":"docker-compose with rabbitmq","tags":["docker",".net-core","docker-compose","rabbitmq"],"text":"Title: docker-compose with rabbitmq\nTags: docker, .net-core, docker-compose, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm trying to setup a docker-compose script - to start a dummy: website, API, Gateway and RabbitMQ. (micro service approach)\n\n**Request pipeline:**\n\nWeb >> Gateway >> API >> RabbitMQ\n\nMy docker-compose looks like this:\n\n```\nversion: \"3.4\"\n\nservices:\n web:\n image: webclient\n build:\n context: ./WebClient\n dockerfile: dockerfile\n ports:\n - \"4000:4000\" \n depends_on:\n - gateway\n\n gateway:\n image: gatewayapi\n build:\n context: ./GateWayApi\n dockerfile: dockerfile\n ports:\n - \"5000:5000\"\n depends_on:\n - ordersapi\n\n ordersapi:\n image: ordersapi\n build:\n context: ./ExampleOrders\n dockerfile: dockerfile\n ports:\n - \"6002:6002\" \n depends_on:\n - rabbitmq\n\n rabbitmq:\n image: rabbitmq:3.7-management\n container_name: rabbitmq\n hostname: rabbitmq\n volumes:\n - rabbitmqdata:/var/lib/rabbitmq\n ports:\n - \"7000:15672\"\n - \"7001:5672\"\n environment:\n - RABBITMQ_DEFAULT_USER=rabbitmquser\n - RABBITMQ_DEFAULT_PASS=some_password\n```\n\n**This pipe works:**\n\nWeb >> Gateway >> API\n\nI get a response from the API on the website.\n\nBut when I try to push a message to rabbitmq from the API, I get the following error:\n\n`System.AggregateException: One or more errors occurred. (Connection failed) ---> RabbitMQ.Client.Exceptions.ConnectFailureException: Connection failed ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: Connection refused 127.0.0.1:7001`\n\nThe RabbitMQ managment GUI still works on the defined port 7000. \nRequests to port 7001 does not.\n\nHowever, if I start the API and RabbitMQ manually, it works like a charm. The API I simply start with a debugger (.Net core + IIS - default settings hitting F5 in VS) and this is the command I use to start the docker image manually:\n\n`docker run -p 7001:5672 -p 7000:15672 --hostname localhost -e RABBITMQ_DEFAULT_USER=rabbitmquser -e RABBITMQ_DEFAULT_PASS=some_password rabbitmq:3.7-management`\n\n**Update**\n\nThis is how I inject the config in the .Net core pipe.\n\nstartup.cs\n\n```\npublic void ConfigureServices(IServiceCollection services)\n{\n // setup RabbitMQ\n var configSection = Configuration.GetSection(\"RabbitMQ\");\n string host = configSection[\"Host\"];\n int.TryParse(configSection[\"Port\"], out int port);\n string userName = configSection[\"UserName\"];\n string password = configSection[\"Password\"];\n\n services.AddTransient(_ => new ConnectionFactory()\n {\n HostName = host,\n Port = port,\n UserName = userName,\n Password = password\n });\n\n services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);\n\n}\n```\n\ncontroller.cs\n\n```\nprivate readonly IConnectionFactory _rabbitFactory;\n\npublic ValuesController(IConnectionFactory rabbitFactory)\n{\n _rabbitFactory = rabbitFactory;\n}\n\npublic void PublishMessage()\n{\n try\n {\n using (var connection = _rabbitFactory.CreateConnection())\n using (var channel = connection.CreateModel())\n {\n string exchangeName = \"ExampleApiController\";\n string routingKey = \"MyCustomRoutingKey\";\n channel.ExchangeDeclare(exchange: exchangeName, type: \"direct\", durable: true); \n SendMessage(\"Payload to queue 1\", channel, exchangeName, routingKey);\n }\n }\n catch (Exception e)\n {\n Console.WriteLine(e.InnerException);\n }\n}\n\nprivate static void SendMessage(string message, IModel channel, string exchangeName, string routingKey)\n{\n byte[] body = Encoding.UTF8.GetBytes(message);\n channel.BasicPublish(exchange: exchangeName,\n routingKey: routingKey,\n basicProperties: null,\n body: body);\n Console.WriteLine($\" Sending --> Exchange: { exchangeName } Queue: { routingKey } Message: {message}\");\n}\n```\n\n========================================\n\nCode:\n```text\nversion: \"3.4\"\n\nservices:\n web:\n image: webclient\n build:\n context: ./WebClient\n dockerfile: dockerfile\n ports:\n - \"4000:4000\" \n depends_on:\n - gateway\n\n gateway:\n image: gatewayapi\n build:\n context: ./GateWayApi\n dockerfile: dockerfile\n ports:\n - \"5000:5000\"\n depends_on:\n - ordersapi\n\n ordersapi:\n image: ordersapi\n build:\n context: ./ExampleOrders\n dockerfile: dockerfile\n ports:\n - \"6002:6002\" \n depends_on:\n - rabbitmq\n\n rabbitmq:\n image: rabbitmq:3.7-management\n container_name: rabbitmq\n hostname: rabbitmq\n volumes:\n - rabbitmqdata:/var/lib/rabbitmq\n ports:\n - \"7000:15672\"\n - \"7001:5672\"\n environment:\n - RABBITMQ_DEFAULT_USER=rabbitmquser\n - RABBITMQ_DEFAULT_PASS=some_password\n```\n\n```text\npublic void ConfigureServices(IServiceCollection services)\n{\n // setup RabbitMQ\n var configSection = Configuration.GetSection(\"RabbitMQ\");\n string host = configSection[\"Host\"];\n int.TryParse(configSection[\"Port\"], out int port);\n string userName = configSection[\"UserName\"];\n string password = configSection[\"Password\"];\n\n services.AddTransient<IConnectionFactory>(_ => new ConnectionFactory()\n {\n HostName = host,\n Port = port,\n UserName = userName,\n Password = password\n });\n\n services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);\n\n}\n```\n\n```text\nprivate readonly IConnectionFactory _rabbitFactory;\n\npublic ValuesController(IConnectionFactory rabbitFactory)\n{\n _rabbitFactory = rabbitFactory;\n}\n\npublic void PublishMessage()\n{\n try\n {\n using (var connection = _rabbitFactory.CreateConnection())\n using (var channel = connection.CreateModel())\n {\n string exchangeName = \"ExampleApiController\";\n string routingKey = \"MyCustomRoutingKey\";\n channel.ExchangeDeclare(exchange: exchangeName, type: \"direct\", durable: true); \n SendMessage(\"Payload to queue 1\", channel, exchangeName, routingKey);\n }\n }\n catch (Exception e)\n {\n Console.WriteLine(e.InnerException);\n }\n}\n\nprivate static void SendMessage(string message, IModel channel, string exchangeName, string routingKey)\n{\n byte[] body = Encoding.UTF8.GetBytes(message);\n channel.BasicPublish(exchange: exchangeName,\n routingKey: routingKey,\n basicProperties: null,\n body: body);\n Console.WriteLine($\" Sending --> Exchange: { exchangeName } Queue: { routingKey } Message: {message}\");\n}\n```\n\n```text\nSystem.AggregateException: One or more errors occurred. (Connection failed) ---> RabbitMQ.Client.Exceptions.ConnectFailureException: Connection failed ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: Connection refused 127.0.0.1:7001\n```\n\n```text\ndocker run -p 7001:5672 -p 7000:15672 --hostname localhost -e RABBITMQ_DEFAULT_USER=rabbitmquser -e RABBITMQ_DEFAULT_PASS=some_password rabbitmq:3.7-management\n```\n\n```text\nlocalhost:7001\n```\n\n```text\nrabbitmq:5672\n```\n\n```text\nhost.docker.internal:7001\n```\n\n========================================\n\nComments:\n- Yes, you are absolutley right. I need to target rabbitmq:5672 - not localhost:7001","metadata":{"transformedAt":"2026-08-18T18:33:20.184Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":283,"estimatedTokens":1748}}700{"id":"stack-30330086","source":"stackoverflow","questionId":30330086,"title":"EasyNetQ - receiving from existing queue","tags":["c#",".net","rabbitmq","easynetq"],"text":"Title: EasyNetQ - receiving from existing queue\nTags: c#, .net, rabbitmq, easynetq\nSource: Stack Overflow\n\nQuestion:\nI am looking at using EasyNetQ for interacting with RabbitMQ and wondering if it can support following case:\n\n- Queue is declared externally with some arbitrary arguments (e.g. x-message-ttl)\n\n- Client code using EasyNetQ sends and receives messages from that queue.\n\nPossibilities I have found are:\n\n- Simple IBus API requires that queue has default parameters\n\n- Advanced IAdvancedBus API allows to specify arguments of the declared-queue but not all (e.g. x-max-length can't be set)\n\nThe question is can I just use existing queue with custom parameters and without need to specify them?\n\n========================================\n\nTop Answer:\nEven with solution 10477404, parameters like *isDurable*, *isExclusive*, *isAutoDelete*, and *arguments* must match the original Queue declaration to avoid creating a new one.\n\nFor safety, and if you have a way to know the original queue declaration parameters, use them to create the queue with `IAdvancedBus.QueueDeclare()` or `IAdvancedBus.QueueDeclareAsync()`\n\n========================================\n\nCode:\n```text\nvar queueName = \"TheNameOfYourExistingQueue\";\nvar existingQueue = new EasyNetQ.Topology.Queue(queueName, false);\n\n// bus should be an instance of IAdvancedBus\nbus.Consume<TypeOfYourMessage>(existingQueue, \n (msg, info) => \n {\n // Implement your handling logic here\n });\n```\n\n```text\nvoid Consume(IQueue queue, Func<Byte[], MessageProperties, MessageReceivedInfo, Task> onMessage);\n```\n\n```text\nIAdvancedBus.Consume<T>\n```\n\n```text\nIAdvancedBus.QueueDeclare\n```\n\n```text\nTypeOfYourMessage\n```\n\n```text\nConsume\n```\n\n```text\nIAdvancedBus.QueueDeclare()\n```\n\n```text\nIAdvancedBus.QueueDeclareAsync()\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.184Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":68,"estimatedTokens":451}}701{"id":"stack-77516053","source":"stackoverflow","questionId":77516053,"title":"Celery Tasks not Running on Mac M2 (Process 'ForkPoolWorker' exited with 'signal 11 (SIGSEGV)')","tags":["django","rabbitmq","celery","apple-m1","task-queue"],"text":"Title: Celery Tasks not Running on Mac M2 (Process 'ForkPoolWorker' exited with 'signal 11 (SIGSEGV)')\nTags: django, rabbitmq, celery, apple-m1, task-queue\nSource: Stack Overflow\n\nQuestion:\nI am encountering an issue while trying to run Celery tasks on my Mac M1 machine. The error message I'm getting is as follows:\n\n```\nThe process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().\nBreak on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.\n[2023-11-20 15:51:19,174: ERROR/MainProcess] Process 'ForkPoolWorker-8' pid:5547 exited with 'signal 11 (SIGSEGV)'\n```\n\nI am using Celery for my Django app task processing, and this issue seems to be related to forking on the M2 architecture.\n\nI initially attempted to resolve the issue by exporting `OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES`, which seemed to work for a brief period. However, the problem has resurfaced, and this solution no longer has any effect.\n\nIt's worth noting that I am currently running `MacOS Sonama 14.2 Beta` on my machine.\n\nInterestingly, I encountered and successfully resolved this problem once before while on the same beta program.\n\nAny insights or suggestions on how to resolve this issue would be greatly appreciated.\n\n========================================\n\nCode:\n```text\nThe process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().\nBreak on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.\n[2023-11-20 15:51:19,174: ERROR/MainProcess] Process 'ForkPoolWorker-8' pid:5547 exited with 'signal 11 (SIGSEGV)'\n```\n\n```text\nOBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES\n```\n\n```text\nMacOS Sonama 14.2 Beta\n```\n\n========================================\n\nComments:\n- Very BIG thanks to you Jerome, I wish you saw the question sooner, can you explain why does it work or how did you come to this please?\n- I had my own issue where the proposed solution was also OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES, but it only resulted in another crash later during execution.\n- I then found out somewhere the proposition about the --pool=solo option, (celery.school/the-solo-worker-pool for the doc) basically without it the worker will fork itself when receiving a task (for multiprocessing) which doesn't seem to work very well on Mac\n- Great solutions, OBJC_DISABLE_INITIALIZE_FORK_SAFETY does not work on machine however, thanks for sharing your discoveries here.","metadata":{"transformedAt":"2026-08-18T18:33:20.184Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":47,"estimatedTokens":630}}702{"id":"stack-2939266","source":"stackoverflow","questionId":2939266,"title":"Which one should I choose AMQP or XMPP for real-time browser-based game?","tags":["php","xmpp","rabbitmq","amqp","ejabberd"],"text":"Title: Which one should I choose AMQP or XMPP for real-time browser-based game?\nTags: php, xmpp, rabbitmq, amqp, ejabberd\nSource: Stack Overflow\n\nQuestion:\nI'm choosing between AMQP (RabbitMQ) vs XMPP (eJabberd) for my browser-based flash-free javascript powered real-time turn-based game. I don't know much about AMQP and XMPP protocol. I would like to use PHP for user-authorization and some data store-retrieve with MySQL. As far as I found out, RabbitMQ has PHP clients but eJabberd not. \n\nWhat I understood is javascript client calls PHP script and manipulate necessary processing and then pass to AMQP or XMPP server to pass the data to opponent player. There is a good book 'Pro XMPP Programming with JS and jQuery' from Wrox but there is no example with PHP. So following are my questions.\n\n1) Which protocol is suit for my game?\n\n2) Shall I choose RabbitMQ just for it's PHP client support?\n\n========================================\n\nTop Answer:\nAMQP has not yet reached version 1.0 and has some possible design issues around it. There are XMPP clients for PHP so if I were you I'd give that a try first.\n\n========================================\n\nCode:\n```text\nejabberd\n```\n\n```text\nejabberd\n```\n\n```text\nmod_rewrite\n```\n\n```text\nmod_rewrite\n```\n\n```text\nXMLHTTPRequest\n```\n\n========================================\n\nComments:\n- XAMPP/LAMP/etc have nothing to do with client-side JavaScript. Apache and other servers are what you are looking for.\n- @Coronatus! Thanks for your comment but I'm sure you overlooked what I meant. Extensible Messaging and Presence Protocol (XMPP) is what I'm talking about.\n- Sorry, I mistook \"XMPP\" for \"XAMPP\". Ignore my comment :)\n- Hi, thanks for your reply. Since I don't know Erlang, I'm afraid I'll have problem when writing server rules for the game with modules. Is there any reasons you have to choose Ejabberd over java based OpenFire? I've very little knowledge in Java so both languages are not familiar with me.\n- Oh thanks again for your kindly replies. Because of my game's requirement, javascript is not enough so I'm now trying with Flash. However, I have dilemma choosing between commercial socket servers (SmartFox, ElectroServer) or go with XMPP but very little examples and tutorials for XMPP with Flash. Anyway, you'll let you know first when I can publish something :)\n- I'll edit the answer again to provide more info. It doesn't seem to fit in this small comments box :)","metadata":{"transformedAt":"2026-08-18T18:33:20.184Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":50,"estimatedTokens":609}}703{"id":"stack-43424176","source":"stackoverflow","questionId":43424176,"title":"How to send various command type by MassTransit and RabbitMQ?","tags":["c#","rabbitmq","microservices","masstransit"],"text":"Title: How to send various command type by MassTransit and RabbitMQ?\nTags: c#, rabbitmq, microservices, masstransit\nSource: Stack Overflow\n\nQuestion:\nI’m a beginner in using message brokers.\n\nWe have a ticketing service which has multiple sub service. A supervisor service gets requests with help of a web API and sends them to sub services.\n\nAny request has a header which is used to detect command type (such as Reserve, Refund, Availability or etc.). We use json for serializing objects.\n\nNow, How to send various message types(different objects) by MassTransit from a publisher such as our supervisor system, in a way that consumer can use it easily?\n\nIn general, is it possible to send various message type in MassTransit and rabbitMQ?\n\nEvery consumer has only one queue for processing received messages.\n\nThanks\n\n### Update\n\n`https://dotnetcodr.com/2016/08/02/messaging-with-rabbitmq-and-net-review-part-1-foundations-and-terminology/` \n\nI read This posts suit to start in messaging with MassTransit and didn't see any example to using various message types on these and another resources:\n\nI have multiple commands and need various message types to send with them, but in examples only use a message type such as below:\n\n**Sender**\n\n```\nprivate static void RunMassTransitPublisherWithRabbit()\n {\n string rabbitMqAddress = \"rabbitmq://localhost:5672/Ticket\";\n string rabbitMqQueue = \"mycompany.domains.queues\";\n Uri rabbitMqRootUri = new Uri(rabbitMqAddress);\n\n IBusControl rabbitBusControl = Bus.Factory.CreateUsingRabbitMq(rabbit =>\n {\n rabbit.Host(rabbitMqRootUri, settings =>\n {\n settings.Password(\"Kalcho^Milano\");\n settings.Username(\"ticketadmin\");\n });\n });\n\n Task sendEndpointTask = rabbitBusControl.GetSendEndpoint(new Uri(string.Concat(rabbitMqAddress, \"/\", rabbitMqQueue)));\n ISendEndpoint sendEndpoint = sendEndpointTask.Result;\n\n Task sendTask = sendEndpoint.Send(new\n {\n Address = \"New Street\",\n Id = Guid.NewGuid(),\n Preferred = true,\n RegisteredUtc = DateTime.UtcNow,\n Name = \"Nice people LTD\",\n Type = 1,\n DefaultDiscount = 0\n });\n Console.ReadKey();\n }\n```\n\n**Receiver**\n\n```\nprivate static void RunMassTransitReceiverWithRabbit()\n {\n IBusControl rabbitBusControl = Bus.Factory.CreateUsingRabbitMq(rabbit =>\n {\n IRabbitMqHost rabbitMqHost = rabbit.Host(new Uri(\"rabbitmq://localhost:5672/Ticket\"), settings =>\n {\n settings.Password(\"Kalcho^Milano\");\n settings.Username(\"ticketadmin\");\n });\n\n rabbit.ReceiveEndpoint(rabbitMqHost, \"mycompany.domains.queues\", conf =>\n {\n conf.Consumer();\n });\n });\n\n rabbitBusControl.Start();\n Console.ReadKey();\n\n rabbitBusControl.Stop();\n }\n```\n\n`IRegisterCustomer` is an interface and I can only get message content in `rabbit.ReceiveEndpoint` and convert to usable object.\n\nNow, How to use various message types such as `IReserveTicket`, `IRefundTicket` and `IGetAvailability` to sending and receiving messages?\n\nThanks again\n\n========================================\n\nCode:\n```text\nprivate static void RunMassTransitPublisherWithRabbit()\n {\n string rabbitMqAddress = \"rabbitmq://localhost:5672/Ticket\";\n string rabbitMqQueue = \"mycompany.domains.queues\";\n Uri rabbitMqRootUri = new Uri(rabbitMqAddress);\n\n IBusControl rabbitBusControl = Bus.Factory.CreateUsingRabbitMq(rabbit =>\n {\n rabbit.Host(rabbitMqRootUri, settings =>\n {\n settings.Password(\"Kalcho^Milano\");\n settings.Username(\"ticketadmin\");\n });\n });\n\n Task<ISendEndpoint> sendEndpointTask = rabbitBusControl.GetSendEndpoint(new Uri(string.Concat(rabbitMqAddress, \"/\", rabbitMqQueue)));\n ISendEndpoint sendEndpoint = sendEndpointTask.Result;\n\n Task sendTask = sendEndpoint.Send<IRegisterCustomer>(new\n {\n Address = \"New Street\",\n Id = Guid.NewGuid(),\n Preferred = true,\n RegisteredUtc = DateTime.UtcNow,\n Name = \"Nice people LTD\",\n Type = 1,\n DefaultDiscount = 0\n });\n Console.ReadKey();\n }\n```\n\n```text\nprivate static void RunMassTransitReceiverWithRabbit()\n {\n IBusControl rabbitBusControl = Bus.Factory.CreateUsingRabbitMq(rabbit =>\n {\n IRabbitMqHost rabbitMqHost = rabbit.Host(new Uri(\"rabbitmq://localhost:5672/Ticket\"), settings =>\n {\n settings.Password(\"Kalcho^Milano\");\n settings.Username(\"ticketadmin\");\n });\n\n rabbit.ReceiveEndpoint(rabbitMqHost, \"mycompany.domains.queues\", conf =>\n {\n conf.Consumer<RegisterCustomerConsumer>();\n });\n });\n\n rabbitBusControl.Start();\n Console.ReadKey();\n\n rabbitBusControl.Stop();\n }\n```\n\n```text\nhttps://dotnetcodr.com/2016/08/02/messaging-with-rabbitmq-and-net-review-part-1-foundations-and-terminology/\n```\n\n```text\nIRegisterCustomer\n```\n\n```text\nrabbit.ReceiveEndpoint\n```\n\n```text\nIReserveTicket\n```\n\n```text\nIRefundTicket\n```\n\n```text\nIGetAvailability\n```\n\n```text\nrabbit.ReceiveEndpoint(rabbitMqHost, \"mycompany.domains.queues\", conf =>\n{\n conf.Consumer<RegisterCustomerConsumer>();\n conf.Consumer<ReserveTicketConsumer>();\n conf.Consumer<RefundTicketConsumer>();\n});\n```\n\n```text\nawait endpoint.Send<IReserveTicket>(new { TickedId = 123 });\n```\n\n```text\ncfg.ReceiveEndpoint(rabbitMqHost, \"mycompany.domains.lowvolume\", \n c =>\n {\n c.Consumer<RegisterCustomerConsumer>();\n c.Consumer<RefundTicketConsumer>();\n });\ncfg.ReceiveEndpoint(rabbitMqHost, \"mycompany.domains.highvolume\", \n c => c.Consumer<ReserveTicketConsumer>();\n```\n\n========================================\n\nComments:\n- Have you read the docs? masstransit-project.com/MassTransit/usage/…\n- To be honest, I don't understand your problem. Why can't you create as many consumers as you have messages and just send those messages? What is the issue?\n- I thought that can not be more than one type of message sent to the consumer, so have a complex structure designed with a message that contains all the details of a message in a system, and this thought is wrong.\n- Each consumer is implementing `IConsumer` where `T` is the message type. So yes, one consumer can only consume one message type. But you can have as many consumers you want, you can have as many consumer per endpoint as you want and you can have as many endpoints as you want.","metadata":{"transformedAt":"2026-08-18T18:33:20.184Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":11,"totalLines":209,"estimatedTokens":1601}}704{"id":"stack-72897924","source":"stackoverflow","questionId":72897924,"title":"Python - RabbitMQ Pika consumer - How to use async function as callback","tags":["python","rabbitmq","pika"],"text":"Title: Python - RabbitMQ Pika consumer - How to use async function as callback\nTags: python, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI have the following code where I initialize a consumer listening to a queue.\n\n```\nconsumer = MyConsumer()\nconsumer.declare_queue(queue_name=\"my-jobs\")\nconsumer.declare_exchange(exchange_name=\"my-jobs\")\nconsumer.bind_queue(\n exchange_name=\"my-jobs\", queue_name=\"my-jobs\", routing_key=\"jobs\"\n)\nconsumer.consume_messages(queue=\"my-jobs\", callback=consumer.consume)\n```\n\nThe problem is that the consume method is defined as follows:\n\n```\nasync def consume(self, channel, method, properties, body):\n```\n\nInside the consume method, we need to await async functions, but this produces an error \"coroutine is not awaited\" for the consume function. Is there a way to use async function as a callback in pika?\n\n========================================\n\nTop Answer:\nI had a similar doubt, I ended up using AsyncioConnection adapter.\n\n```\nclass Consumer:\n \n def __init__(self, loop, ...):\n self._loop = loop\n self._in_flight_tasks = set()\n\n def connect(self):\n return AsyncioConnection(\n parameters=...\n custom_ioloop=self._loop,\n )\n\n ...\n\n \n async def _handle_message(...):\n ...\n \n def on_message(self, _unused_channel, basic_deliver, properties, body):\n task = self._loop.create_task(self._handle_message(tag, properties, body))\n self._in_flight_tasks.add(task)\n task.add_done_callback(self._in_flight_tasks.discard)\n\n ...\n```\n\nNote that I'm passing the event loop to the consumer. I create it with `asyncio.new_event_loop()` on the top of my app. I am not sure if that's required but may be as it seems like Pika us using some custom event loop implementation by default.\n\nMost of the consumer code is taken from Pika examples.\n\nFor the explanation on why the tasks are added to a set and then discarded see here.\n\n========================================\n\nCode:\n```text\nconsumer = MyConsumer()\nconsumer.declare_queue(queue_name=\"my-jobs\")\nconsumer.declare_exchange(exchange_name=\"my-jobs\")\nconsumer.bind_queue(\n exchange_name=\"my-jobs\", queue_name=\"my-jobs\", routing_key=\"jobs\"\n)\nconsumer.consume_messages(queue=\"my-jobs\", callback=consumer.consume)\n```\n\n```text\nasync def consume(self, channel, method, properties, body):\n```\n\n```py\ndef sync(f):\n @functools.wraps(f)\n def wrapper(*args, **kwargs):\n return asyncio.get_event_loop().run_until_complete(f(*args, **kwargs))\n return wrapper\n```\n\n```text\n@sync\n```\n\n```py\nclass Consumer:\n \n def __init__(self, loop, ...):\n self._loop = loop\n self._in_flight_tasks = set()\n\n def connect(self):\n return AsyncioConnection(\n parameters=...\n custom_ioloop=self._loop,\n )\n\n ...\n\n \n async def _handle_message(...):\n ...\n \n def on_message(self, _unused_channel, basic_deliver, properties, body):\n task = self._loop.create_task(self._handle_message(tag, properties, body))\n self._in_flight_tasks.add(task)\n task.add_done_callback(self._in_flight_tasks.discard)\n\n ...\n```\n\n```text\nasyncio.new_event_loop()\n```\n\n========================================\n\nComments:\n- Hello, I maintain Pika. That is a very interesting discovery. If you have time, would you mind documenting this if you think it's likely another user may need to know? github.com/pika/pika/tree/main/docs\n- I should mention that this solution does not have a true async behavior, it's just a workaround to solve the coroutine exception when using an async function as callback. For actual async behavior, I found aio-pika (aio-pika.readthedocs.io/en/latest/quick-start.html). In the docs, where exactly would you like me to mention this workaround? @LukeBakken\n- Yes, `aio-pika` or `aiorabbit` are better choices. Hm, the docs don't seem like a good place for this. Is it too much trouble for a small example program here? github.com/pika/pika/tree/main/examples\n- aiormq is also a simple and nice option for async (which aio-pika is now using). Basically aio-pika mostly provide auto-reconnection which many had issue with, including me.\n- @LukeBakken `aiorabbit` is very buggy, incomplete, unmaintained, and far from production worthy","metadata":{"transformedAt":"2026-08-18T18:33:20.184Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":131,"estimatedTokens":1035}}705{"id":"stack-10622169","source":"stackoverflow","questionId":10622169,"title":"Amazon-SQS + Django-Celery creates thousands of queues (a queue for every message)","tags":["django","rabbitmq","celery","django-celery","amazon-sqs"],"text":"Title: Amazon-SQS + Django-Celery creates thousands of queues (a queue for every message)\nTags: django, rabbitmq, celery, django-celery, amazon-sqs\nSource: Stack Overflow\n\nQuestion:\nI am looking for a place to start troubleshooting this problem.\n\nhere are the changes made in the settings.py\n\n```\n#Rabbit MQ settings\n#===============================================================================\n# BROKER_HOST = \"localhost\"\n# BROKER_PORT = 5672\n# BROKER_USER = \"vei_0\"\n# BROKER_PASSWORD = \"1234\"\n# BROKER_VHOST = \"videoencoder\"\n#===============================================================================\n\nDEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'\nAWS_ACCESS_KEY_ID = \"xxxx\"\nAWS_SECRET_ACCESS_KEY = \"xxxx\"\nAWS_STORAGE_BUCKET_NAME = \"images\"\n#Amazon SQS settings.\nBROKER_TRANSPORT = 'sqs'\nBROKER_TRANSPORT_OPTIONS = {\n 'region': 'us-east-1',\n}\nBROKER_USER = AWS_ACCESS_KEY_ID\nBROKER_PASSWORD = AWS_SECRET_ACCESS_KEY\nCELERY_DEFAULT_QUEUE = 'hardwaretaskqueue'\nCELERY_QUEUES = {\n CELERY_DEFAULT_QUEUE: {\n 'exchange': CELERY_DEFAULT_QUEUE,\n 'binding_key': CELERY_DEFAULT_QUEUE,\n }\n}\n\nCELERYD_CONCURRENCY = 2\nCELERY_TASK_RESULT_EXPIRES = 120\nCELERY_RESULT_BACKEND = \"amqp\"\n```\n\nI woke up this morning to a message from amazon saying \"Did you mean to make a bijillion queues?\"\n\n========================================\n\nCode:\n```text\n#Rabbit MQ settings\n#===============================================================================\n# BROKER_HOST = \"localhost\"\n# BROKER_PORT = 5672\n# BROKER_USER = \"vei_0\"\n# BROKER_PASSWORD = \"1234\"\n# BROKER_VHOST = \"videoencoder\"\n#===============================================================================\n\n\n\n\nDEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'\nAWS_ACCESS_KEY_ID = \"xxxx\"\nAWS_SECRET_ACCESS_KEY = \"xxxx\"\nAWS_STORAGE_BUCKET_NAME = \"images\"\n#Amazon SQS settings.\nBROKER_TRANSPORT = 'sqs'\nBROKER_TRANSPORT_OPTIONS = {\n 'region': 'us-east-1',\n}\nBROKER_USER = AWS_ACCESS_KEY_ID\nBROKER_PASSWORD = AWS_SECRET_ACCESS_KEY\nCELERY_DEFAULT_QUEUE = 'hardwaretaskqueue'\nCELERY_QUEUES = {\n CELERY_DEFAULT_QUEUE: {\n 'exchange': CELERY_DEFAULT_QUEUE,\n 'binding_key': CELERY_DEFAULT_QUEUE,\n }\n}\n\n\nCELERYD_CONCURRENCY = 2\nCELERY_TASK_RESULT_EXPIRES = 120\nCELERY_RESULT_BACKEND = \"amqp\"\n```\n\n```text\nCELERY_RESULT_BACKEND = 'amqp'\n```\n\n```text\nCELERY_RESULT_BACKEND\n```\n\n```text\nCELERY_IGNORE_RESULT = True\n```\n\n========================================\n\nComments:\n- +1 for the funny message from Amazon already :)\n- my secret key does have a forward slash in it. Could this be the problem?\n- The queues are created as auto-delete per the AMQP spec but I couldn't tell you the specifics of how SQS handles that flag.","metadata":{"transformedAt":"2026-08-18T18:33:20.184Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":104,"estimatedTokens":678}}706{"id":"stack-29397916","source":"stackoverflow","questionId":29397916,"title":"To consume a rabbitmq queue, do I really need to declare the exchange and the queue?","tags":["rabbitmq","amqp","rabbitmq-exchange"],"text":"Title: To consume a rabbitmq queue, do I really need to declare the exchange and the queue?\nTags: rabbitmq, amqp, rabbitmq-exchange\nSource: Stack Overflow\n\nQuestion:\nIn all the examples I find online, I see the exchange and the queue being declared before a messages are consumed. \nDeclaring the exchange seems weird, because, why would I do it? I'm consuming a queue, which might be bound to multiple exchanges (or to none, maybe it just have old messages waiting in it).\n\nalso, I can't think of why I would declare a queue. This will require me to know information about the queue that I don't need to know to consume it (like auto_delete and durability).\n\nWhen I tested it locally, I can consume a queue without declaring anything. It works. So I'm left wondering, why does every example I've seen online, declare the exchange and queue, even if it just consumes it?\n\nthanks!!!\n\n========================================\n\nTop Answer:\nIn general, you don’t need declare exchange and queue in consumer. You must assemble \"exchanges/queues\" topology somewhere else. It's like schema in database.\n\nBut always there are exceptions. \nWhen you need \"private\" queue (exclusive=true) for real-time processing, consumer must know (by configuration) about source exchange and bind own queue to it. \n\nIn other case i can imagine situations where publisher declare exchange and consumers can discover it using some convention (pattern) for exchange naming.","metadata":{"transformedAt":"2026-08-18T18:33:20.184Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":23,"estimatedTokens":362}}707{"id":"stack-65415574","source":"stackoverflow","questionId":65415574,"title":"Whats the difference of an classic queue with and without x-queue-type: classic in RabbitMQ","tags":["rabbitmq"],"text":"Title: Whats the difference of an classic queue with and without x-queue-type: classic in RabbitMQ\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nWhen creating a queue in the RabbitMQ UI with de default options, it shows in the features column `D` for durable, and `Args` with `x-queue-type: classic`.\n\nWhen creating it by code, you can create like this in python:\n`channel.queue_declare('QueueName', durable=True)`, but it is different from the queue created by the UI, without the `Args` feature of `x-queue-type: classic`, but it's type is a classic queue as indicated.\n\nIn python, you can create a queue that is just like the one created by default in the UI with this:\n`channel.queue_declare('QueueName', durable=True, arguments={'x-queue-type':'classic'})`\n\nMy doubt is, since both queue types are classical, whats the difference between the one with the argument `x-queue-type: classic` and the one without, assuming all rest is the same?\n\nIn this image an example as shown in the RabbitMQ UI:\nhttps://i.sstatic.net/8CmER.png\n\n========================================\n\nCode:\n```text\nD\n```\n\n```text\nArgs\n```\n\n```text\nx-queue-type: classic\n```\n\n```text\nchannel.queue_declare('QueueName', durable=True)\n```\n\n```text\nArgs\n```\n\n```text\nx-queue-type: classic\n```\n\n```text\nchannel.queue_declare('QueueName', durable=True, arguments={'x-queue-type':'classic'})\n```\n\n```text\nx-queue-type: classic\n```\n\n```text\nx-queue-type: classic\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.184Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":9,"totalLines":56,"estimatedTokens":359}}708{"id":"stack-8565862","source":"stackoverflow","questionId":8565862,"title":"Running a Celery task when unable to import that task","tags":["python","django","rabbitmq","celery","amqp"],"text":"Title: Running a Celery task when unable to import that task\nTags: python, django, rabbitmq, celery, amqp\nSource: Stack Overflow\n\nQuestion:\nI have two servers: one running a django app and one running both a rabbitmq queue and a celery worker. My tasks.py on the server running the queue/worker contains a task as follows:\n\n```\n@task(queue=\"reports\")\ndef test_task():\n time.sleep(120)\n```\n\nMy goal is to execute this task from a django view. Since the code for the task is on a different server than the django view I'd like to call the task, I'm trying to use the following code to send the task from django to the worker machine.\n\n```\nsend_task(\"tasks.test_task\", task_id=task_id, args=[], kwargs={}, publisher=publisher, queue=queue)\n```\n\nI found this method here, but so far testing it hasn't worked.\n\nI'm testing with tail -F on the celery worker logfile on the celery worker server, then navigating to the url of the view containing send_task in a browser. I'm looking for the task to show up as 'received' in the tail output, but it doesn't.\n\nThe celery worker's log level is DEBUG, the logfile shows that the task is registered with the proper name, and the django app's settings.py contains the correct IP and credentials for the rabbitmq server. In trying different approaches, I've occasionally seen an error message in the celery logfile when I changed the string passed to send_task to something that wasn't a valid task (ie send_task('asdf')). This caused an UnregisteredError in the logfile. However, this only happens sometimes, and so far in testing different combinations of settings and calls, I haven't found a way to reliably replicate the behavior.\n\nAlso, this is the relevant section of settings.py on the django project (with actual values removed):\n\n```\nCELERY_RESULT_BACKEND = 'amqp'\nBROKER_HOST = 'the.correct.IP.address'\nBROKER_USER = 'the_correct_user'\nBROKER_PASSWORD = 'the_correct_pass'\nBROKER_VHOST = 'the_correct_vhost'\nBROKER_PORT = 5672\n```\n\nI've googled around and haven't found much on send_task. Any ideas on what I might be doing wrong?\n\n========================================\n\nTop Answer:\nWhat [I thought you were] trying to do is impossible. Celery workers require access to the task code they are to run. There's no way around that.\n\nREVISED:\n\nBut what you really want to do is: have the code available to the workers but NOT to the Django view, which should refer to tasks only by name.\n\n========================================\n\nCode:\n```text\n@task(queue=\"reports\")\ndef test_task():\n time.sleep(120)\n```\n\n```text\nsend_task(\"tasks.test_task\", task_id=task_id, args=[], kwargs={}, publisher=publisher, queue=queue)\n```\n\n```text\nCELERY_RESULT_BACKEND = 'amqp'\nBROKER_HOST = 'the.correct.IP.address'\nBROKER_USER = 'the_correct_user'\nBROKER_PASSWORD = 'the_correct_pass'\nBROKER_VHOST = 'the_correct_vhost'\nBROKER_PORT = 5672\n```\n\n```text\nsend_task(\"tasks.test_task\", task_id=task_id, queue=queue)\n```\n\n========================================\n\nComments:\n- I'd be interested to know how you shared your code between both machines. Here's a question I wrote related to that: stackoverflow.com/questions/28592243/… Thanks!\n- You're absolutely right that celery workers require the code they will run, but I think you misunderstood part of the original post. To be clear, the worker has the task code on it - it's the *calling* of the task that I'd like to happen remotely. So the django view tells the worker to run the task.","metadata":{"transformedAt":"2026-08-18T18:33:20.184Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":78,"estimatedTokens":869}}709{"id":"stack-31634573","source":"stackoverflow","questionId":31634573,"title":"How to add RabbitMQ library to project? 'The import \"com.rabbitmq\" cannot be resolved'","tags":["java","eclipse","rabbitmq"],"text":"Title: How to add RabbitMQ library to project? 'The import \"com.rabbitmq\" cannot be resolved'\nTags: java, eclipse, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am working through the RabbitMQ Java tutorial found here: https://www.rabbitmq.com/tutorials/tutorial-one-java.html\n\nI have downloaded the Java Client Library package, and copied the JAR files to my project in Eclipse, but the import statements\n\n```\nimport com.rabbitmq.client.ConnectionFactory;\nimport com.rabbitmq.client.Connection;\nimport com.rabbitmq.client.Channel;\n```\n\nall yield the error \n\n```\nThe import \"com.rabbitmq\" cannot be resolved.\n```\n\nThe instructions are unclear how to incorporate the JAR files from the Java Client Library package, how should I proceed?\n\n========================================\n\nTop Answer:\nSince the verified answer doesn't work anymore, here is my solution: \n\nYou can download the **amqp-client-5.8.0.jar** from here . Then add it to your class path, like any other jar.\n\nIn case that the link doesn't work, you can manually download it from here or even add the required dependency to your maven/gradle project.\n\n========================================\n\nCode:\n```text\nimport com.rabbitmq.client.ConnectionFactory;\nimport com.rabbitmq.client.Connection;\nimport com.rabbitmq.client.Channel;\n```\n\n```text\nThe import \"com.rabbitmq\" cannot be resolved.\n```\n\n```text\nThe import \"com.rabbitmq\"\n```\n\n========================================\n\nComments:\n- I have the dependency in my pom.xml. This should get automatically added to the project's class path right? When I give, `mvn clean compile`, I don't get any errors. I am not able to run the project from cmd by giving `ampq-client-4.0.2.jar file1.java file2.java`. What's going wrong here? Should I also manually download the jar and add it to my class path?\n- @Ankit Nigam's answer is still valid. Just validated now with IntelliJ.\n- @LorenzoBattilocchi Interesting. It might had to do with the version of Java the individual uses, since the other answer is old enough.\n- As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.","metadata":{"transformedAt":"2026-08-18T18:33:20.184Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":56,"estimatedTokens":566}}710{"id":"stack-3665515","source":"stackoverflow","questionId":3665515,"title":"how to implement RPC Mechanism using RabbitMQ in java","tags":["java","rpc","rabbitmq"],"text":"Title: how to implement RPC Mechanism using RabbitMQ in java\nTags: java, rpc, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nhow to implement RPC Mechanism(both producer and consumer) using RabbitMQ in java?i am also visit official site http://www.rabbitmq.com/api-guide.html#rpc but i am getting detail description about this things.\n\nThanks\n\n========================================\n\nCode:\n```text\nimport com.rabbitmq.client.AMQP;\nimport com.rabbitmq.client.Channel;\nimport com.rabbitmq.client.Connection;\nimport com.rabbitmq.client.ConnectionFactory;\nimport com.rabbitmq.client.StringRpcServer;\n\npublic class HelloServer {\n public static void main(String[] args) {\n try {\n String hostName = (args.length > 0) ? args[0] : \"localhost\";\n int portNumber = (args.length > 1) ? Integer.parseInt(args[1]) : AMQP.PROTOCOL.PORT;\n\n ConnectionFactory connFactory = new ConnectionFactory();\n connFactory.setHost(hostName);\n connFactory.setPort(portNumber);\n Connection conn = connFactory.newConnection();\n final Channel ch = conn.createChannel();\n\n ch.queueDeclare(\"Hello\", false, false, false, null);\n StringRpcServer server = new StringRpcServer(ch, \"Hello\") {\n public String handleStringCall(String request) {\n System.out.println(\"Got request: \" + request);\n return \"Hello, \" + request + \"!\";\n }\n };\n server.mainloop();\n } catch (Exception ex) {\n System.err.println(\"Main thread caught exception: \" + ex);\n ex.printStackTrace();\n System.exit(1);\n }\n }\n}\n```\n\n```text\nimport com.rabbitmq.client.AMQP;\nimport com.rabbitmq.client.Channel;\nimport com.rabbitmq.client.Connection;\nimport com.rabbitmq.client.ConnectionFactory;\nimport com.rabbitmq.client.RpcClient;\n\npublic class HelloClient {\n public static void main(String[] args) {\n try {\n String request = (args.length > 0) ? args[0] : \"Rabbit\";\n String hostName = (args.length > 1) ? args[1] : \"localhost\";\n int portNumber = (args.length > 2) ? Integer.parseInt(args[2]) : AMQP.PROTOCOL.PORT;\n\n ConnectionFactory cfconn = new ConnectionFactory(); \n cfconn.setHost(hostName); \n cfconn.setPort(portNumber);\n Connection conn = cfconn.newConnection();\n Channel ch = conn.createChannel();\n RpcClient service = new RpcClient(ch, \"\", \"Hello\");\n\n System.out.println(service.stringCall(request));\n conn.close();\n } catch (Exception e) {\n System.err.println(\"Main thread caught exception: \" + e);\n e.printStackTrace();\n System.exit(1);\n }\n }\n}\n```\n\n========================================\n\nComments:\n- Your question is rather unclear, could you be a bit more specific ?\n- Ya do you want to have and RPC layer over RabbitMQ or do you want to access the RabbitMQ remotely.\n- I updated my post with a sample.","metadata":{"transformedAt":"2026-08-18T18:33:20.184Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":86,"estimatedTokens":772}}711{"id":"stack-14355278","source":"stackoverflow","questionId":14355278,"title":"RabbitMQ managment Nginx proxy","tags":["nginx","rabbitmq"],"text":"Title: RabbitMQ managment Nginx proxy\nTags: nginx, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have loadbalancer and vm with rabbitmq broker. On rabbitmq open 5672 port with plugin managment if I am create proxy to rabbitmq recive \n\n \n curl: (52) Empty reply from server\n\n \n\nI am can connect with telnet to rmq server and have callback \n\n \n curl: (56) Recv failure: Connection reset by peer\n\n \n\nNginx config\n\n```\nserver {\n listen xxx.xxx.xxx.yy:80;\n server_name xxxxxxxxxx\n access_log acces.log;\n error_log error.log;\n location / {\n client_body_buffer_size 128k;\n proxy_send_timeout 90;\n proxy_read_timeout 90;\n proxy_buffer_size 4k;\n proxy_buffers 16 32k;\n proxy_busy_buffers_size 64k;\n proxy_temp_file_write_size 64k;\n proxy_connect_timeout 30s;\n proxy_pass http://xxx.xxx.xxx.xx:5672;\n proxy_set_header Host $host;\n proxy_set_header X-Real-IP $remote_addr;\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n }\n}\n```\n\n========================================\n\nCode:\n```text\nserver {\n listen xxx.xxx.xxx.yy:80;\n server_name xxxxxxxxxx\n access_log acces.log;\n error_log error.log;\n location / {\n client_body_buffer_size 128k;\n proxy_send_timeout 90;\n proxy_read_timeout 90;\n proxy_buffer_size 4k;\n proxy_buffers 16 32k;\n proxy_busy_buffers_size 64k;\n proxy_temp_file_write_size 64k;\n proxy_connect_timeout 30s;\n proxy_pass http://xxx.xxx.xxx.xx:5672;\n proxy_set_header Host $host;\n proxy_set_header X-Real-IP $remote_addr;\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n }\n}\n```\n\n```text\nserver {\n listen xxx.xxx.xxx.yy:80;\n server_name xxxxxxxxxx\n access_log acces.log;\n error_log error.log;\n location / {\n client_body_buffer_size 128k;\n proxy_send_timeout 90;\n proxy_read_timeout 90;\n proxy_buffer_size 4k;\n proxy_buffers 16 32k;\n proxy_busy_buffers_size 64k;\n proxy_temp_file_write_size 64k;\n proxy_connect_timeout 30s;\n proxy_pass http://xxx.xxx.xxx.xx:15672;\n proxy_set_header Host $host;\n proxy_set_header X-Real-IP $remote_addr;\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n }\n}\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.184Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":92,"estimatedTokens":584}}712{"id":"stack-22674808","source":"stackoverflow","questionId":22674808,"title":"RabbitMQ Non-Round Robin Dispatching","tags":["rabbitmq","message-queue","rpc","distributed-computing","amqp"],"text":"Title: RabbitMQ Non-Round Robin Dispatching\nTags: rabbitmq, message-queue, rpc, distributed-computing, amqp\nSource: Stack Overflow\n\nQuestion:\nI'm interested in implementing the \"Work Queues\" model in RabbitMQ. However, I find that the broker does a simple round-robin based dispatching of tasks to workers.\n\nhttps://www.rabbitmq.com/tutorials/tutorial-two-java.html\n\nIf a particular worker is busy doing a very heavy task and there are other free workers, the broker should be able to dispatch messages in queue to the **next available worker** and **not the next worker in** round-robin sequence. Is there a way to accomplish this using RabbitMQ?\n\n========================================\n\nCode:\n```text\nchannel.basicQos(1);\n```\n\n```text\nACK\n```\n\n========================================\n\nComments:\n- Thanks for the response. Yes, I was looking for something like Fair dispatch.","metadata":{"transformedAt":"2026-08-18T18:33:20.185Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":26,"estimatedTokens":220}}713{"id":"stack-54415788","source":"stackoverflow","questionId":54415788,"title":"cluster_formation.classic_config.nodes does not work of rabbitmq","tags":["rabbitmq","config"],"text":"Title: cluster_formation.classic_config.nodes does not work of rabbitmq\nTags: rabbitmq, config\nSource: Stack Overflow\n\nQuestion:\nI have 2 rabbitmq nodes.\nTheir node names are: rabbit@testhost1 and rabbit@testhost2\nI'd like them can auto cluster.\n\nOn testhost1\n\n```\n# cat /etc/rabbitmq/rabbitmq.conf\ncluster_formation.peer_discovery_backend = rabbit_peer_discovery_classic_config\ncluster_formation.classic_config.nodes.1 = rabbit@testhost1\ncluster_formation.classic_config.nodes.2 = rabbit@testhost2\n```\n\nOn testhost2\n\n```\n# cat /etc/rabbitmq/rabbitmq.conf\ncluster_formation.peer_discovery_backend = rabbit_peer_discovery_classic_config\ncluster_formation.classic_config.nodes.1 = rabbit@testhost1\ncluster_formation.classic_config.nodes.2 = rabbit@testhost2\n```\n\nI start rabbit@testhost1 first and then rabbit@testhost2.\n\nThe second node didn't join to the cluster of first node.\n\nWhile node rabbit@testhost1 can join rabbit@testhost2 with rabbitmqctl command: rabbitmqctl join_cluster rabbit@testhost2.\nSo the network between should not have problem.\n\nCould you give me some idea about why can't combine cluster? Is the configuration nor correct?\n\nI have opened the debug log and the info related to rabbit_peer_discovery_classic_config is very little:\n\n```\n2019-01-28 16:56:47.913 [info] Peer discovery backend rabbit_peer_discovery_classic_config does not support registration, skipping registration.\n```\n\nThe rabbitmq version is 3.7.8\n\n========================================\n\nCode:\n```text\n# cat /etc/rabbitmq/rabbitmq.conf\ncluster_formation.peer_discovery_backend = rabbit_peer_discovery_classic_config\ncluster_formation.classic_config.nodes.1 = rabbit@testhost1\ncluster_formation.classic_config.nodes.2 = rabbit@testhost2\n```\n\n```text\n# cat /etc/rabbitmq/rabbitmq.conf\ncluster_formation.peer_discovery_backend = rabbit_peer_discovery_classic_config\ncluster_formation.classic_config.nodes.1 = rabbit@testhost1\ncluster_formation.classic_config.nodes.2 = rabbit@testhost2\n```\n\n```text\n2019-01-28 16:56:47.913 [info] <0.250.0> Peer discovery backend rabbit_peer_discovery_classic_config does not support registration, skipping registration.\n```\n\n```text\nrabbitmqctl reset\n```\n\n========================================\n\nComments:\n- Thanks! The cluster config can work at the first time the broker start up.","metadata":{"transformedAt":"2026-08-18T18:33:20.185Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":73,"estimatedTokens":577}}714{"id":"stack-21128084","source":"stackoverflow","questionId":21128084,"title":"How to fix python invalid syntax on triple quotation \"\"\"","tags":["python","rabbitmq"],"text":"Title: How to fix python invalid syntax on triple quotation \"\"\"\nTags: python, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI encountered an error on codegen.py when trying to build rabbitmq server using make. I'm using 64 bit Windows 7, Python33, erl5.10.3, cygwin and GNU Make 4.0 for i686-pc-cygwin. I read that triple quotes are accepted in python. How do I fix this?\n\n```\nD:\\cygwin\\bin\\make\nMakefile:378: deps.mk: No such file or directory\npython codegen.py body ../rabbitmq-codegen//amqp-rabbitmq-0.9.1.json ../rabbitmq\n-codegen//credit_extension.json src/rabbit_framing_amqp_0_9_1.erl\n File \"codegen.py\", line 110\n %%\"\"\"\n ^\nSyntaxError: invalid syntax\nMakefile:144: recipe for target 'src/rabbit_framing_amqp_0_9_1.erl' failed\nmake: *** [src/rabbit_framing_amqp_0_9_1.erl] Error 1\n```\n\ncodegen.py until where the error appeared (last line of code):\n\n```\n## The contents of this file are subject to the Mozilla Public License\n## Version 1.1 (the \"License\"); you may not use this file except in\n## compliance with the License. You may obtain a copy of the License\n## at http://www.mozilla.org/MPL/\n##\n## Software distributed under the License is distributed on an \"AS IS\"\n## basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See\n## the License for the specific language governing rights and\n## limitations under the License.\n##\n## The Original Code is RabbitMQ.\n##\n## The Initial Developer of the Original Code is GoPivotal, Inc.\n## Copyright (c) 2007-2013 GoPivotal, Inc. All rights reserved.\n##\n\nfrom __future__ import nested_scopes\n\nimport sys\nsys.path.append(\"../rabbitmq-codegen\") # in case we're next to an experimental revision\nsys.path.append(\"codegen\") # in case we're building from a distribution package\n\nfrom amqp_codegen import *\nimport string\nimport re\n\n# Coming up with a proper encoding of AMQP tables in JSON is too much\n# hassle at this stage. Given that the only default value we are\n# interested in is for the empty table, we only support that.\ndef convertTable(d):\n if len(d) == 0:\n return \"[]\"\n else:\n raise Exception('Non-empty table defaults not supported ' + d)\n\nerlangDefaultValueTypeConvMap = {\n bool : lambda x: str(x).lower(),\n str : lambda x: \">\",\n int : lambda x: str(x),\n float : lambda x: str(x),\n dict: convertTable,\n unicode: lambda x: \">\"\n}\n\ndef erlangize(s):\n s = s.replace('-', '_')\n s = s.replace(' ', '_')\n return s\n\nAmqpMethod.erlangName = lambda m: \"'\" + erlangize(m.klass.name) + '.' + erlangize(m.name) + \"'\"\n\nAmqpClass.erlangName = lambda c: \"'\" + erlangize(c.name) + \"'\"\n\ndef erlangConstantName(s):\n return '_'.join(re.split('[- ]', s.upper()))\n\nclass PackedMethodBitField:\n def __init__(self, index):\n self.index = index\n self.domain = 'bit'\n self.contents = []\n\n def extend(self, f):\n self.contents.append(f)\n\n def count(self):\n return len(self.contents)\n\n def full(self):\n return self.count() == 8\n\ndef multiLineFormat(things, prologue, separator, lineSeparator, epilogue, thingsPerLine = 4):\n r = [prologue]\n i = 0\n for t in things:\n if i != 0:\n if i % thingsPerLine == 0:\n r += [lineSeparator]\n else:\n r += [separator]\n r += [t]\n i += 1\n r += [epilogue]\n return \"\".join(r)\n\ndef prettyType(typeName, subTypes, typesPerLine = 4):\n \"\"\"Pretty print a type signature made up of many alternative subtypes\"\"\"\n sTs = multiLineFormat(subTypes,\n \"( \", \" | \", \"\\n | \", \" )\",\n thingsPerLine = typesPerLine)\n return \"-type(%s ::\\n %s).\" % (typeName, sTs)\n\ndef printFileHeader():\n print \"\"\"%% Autogenerated code. Do not edit.\n%%\n%% The contents of this file are subject to the Mozilla Public License\n%% Version 1.1 (the \"License\"); you may not use this file except in\n%% compliance with the License. You may obtain a copy of the License\n%% at http://www.mozilla.org/MPL/\n%%\n%% Software distributed under the License is distributed on an \"AS IS\"\n%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See\n%% the License for the specific language governing rights and\n%% limitations under the License.\n%%\n%% The Original Code is RabbitMQ.\n%%\n%% The Initial Developer of the Original Code is GoPivotal, Inc.\n%% Copyright (c) 2007-2013 GoPivotal, Inc. All rights reserved.\n%%\"\"\"\n```\n\n========================================\n\nCode:\n```text\nD:\\cygwin\\bin\\make\nMakefile:378: deps.mk: No such file or directory\npython codegen.py body ../rabbitmq-codegen//amqp-rabbitmq-0.9.1.json ../rabbitmq\n-codegen//credit_extension.json src/rabbit_framing_amqp_0_9_1.erl\n File \"codegen.py\", line 110\n %%\"\"\"\n ^\nSyntaxError: invalid syntax\nMakefile:144: recipe for target 'src/rabbit_framing_amqp_0_9_1.erl' failed\nmake: *** [src/rabbit_framing_amqp_0_9_1.erl] Error 1\n```\n\n```text\n## The contents of this file are subject to the Mozilla Public License\n## Version 1.1 (the \"License\"); you may not use this file except in\n## compliance with the License. You may obtain a copy of the License\n## at http://www.mozilla.org/MPL/\n##\n## Software distributed under the License is distributed on an \"AS IS\"\n## basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See\n## the License for the specific language governing rights and\n## limitations under the License.\n##\n## The Original Code is RabbitMQ.\n##\n## The Initial Developer of the Original Code is GoPivotal, Inc.\n## Copyright (c) 2007-2013 GoPivotal, Inc. All rights reserved.\n##\n\nfrom __future__ import nested_scopes\n\nimport sys\nsys.path.append(\"../rabbitmq-codegen\") # in case we're next to an experimental revision\nsys.path.append(\"codegen\") # in case we're building from a distribution package\n\nfrom amqp_codegen import *\nimport string\nimport re\n\n# Coming up with a proper encoding of AMQP tables in JSON is too much\n# hassle at this stage. Given that the only default value we are\n# interested in is for the empty table, we only support that.\ndef convertTable(d):\n if len(d) == 0:\n return \"[]\"\n else:\n raise Exception('Non-empty table defaults not supported ' + d)\n\nerlangDefaultValueTypeConvMap = {\n bool : lambda x: str(x).lower(),\n str : lambda x: \"<<\\\"\" + x + \"\\\">>\",\n int : lambda x: str(x),\n float : lambda x: str(x),\n dict: convertTable,\n unicode: lambda x: \"<<\\\"\" + x.encode(\"utf-8\") + \"\\\">>\"\n}\n\ndef erlangize(s):\n s = s.replace('-', '_')\n s = s.replace(' ', '_')\n return s\n\nAmqpMethod.erlangName = lambda m: \"'\" + erlangize(m.klass.name) + '.' + erlangize(m.name) + \"'\"\n\nAmqpClass.erlangName = lambda c: \"'\" + erlangize(c.name) + \"'\"\n\ndef erlangConstantName(s):\n return '_'.join(re.split('[- ]', s.upper()))\n\nclass PackedMethodBitField:\n def __init__(self, index):\n self.index = index\n self.domain = 'bit'\n self.contents = []\n\n def extend(self, f):\n self.contents.append(f)\n\n def count(self):\n return len(self.contents)\n\n def full(self):\n return self.count() == 8\n\ndef multiLineFormat(things, prologue, separator, lineSeparator, epilogue, thingsPerLine = 4):\n r = [prologue]\n i = 0\n for t in things:\n if i != 0:\n if i % thingsPerLine == 0:\n r += [lineSeparator]\n else:\n r += [separator]\n r += [t]\n i += 1\n r += [epilogue]\n return \"\".join(r)\n\ndef prettyType(typeName, subTypes, typesPerLine = 4):\n \"\"\"Pretty print a type signature made up of many alternative subtypes\"\"\"\n sTs = multiLineFormat(subTypes,\n \"( \", \" | \", \"\\n | \", \" )\",\n thingsPerLine = typesPerLine)\n return \"-type(%s ::\\n %s).\" % (typeName, sTs)\n\ndef printFileHeader():\n print \"\"\"%% Autogenerated code. Do not edit.\n%%\n%% The contents of this file are subject to the Mozilla Public License\n%% Version 1.1 (the \"License\"); you may not use this file except in\n%% compliance with the License. You may obtain a copy of the License\n%% at http://www.mozilla.org/MPL/\n%%\n%% Software distributed under the License is distributed on an \"AS IS\"\n%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See\n%% the License for the specific language governing rights and\n%% limitations under the License.\n%%\n%% The Original Code is RabbitMQ.\n%%\n%% The Initial Developer of the Original Code is GoPivotal, Inc.\n%% Copyright (c) 2007-2013 GoPivotal, Inc. All rights reserved.\n%%\"\"\"\n```\n\n```text\nprint\n```\n\n========================================\n\nComments:\n- Thank you. It is no wonder my searches on triple quotes didn't helped. This worked perfectly!","metadata":{"transformedAt":"2026-08-18T18:33:20.185Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":272,"estimatedTokens":2111}}715{"id":"stack-51425563","source":"stackoverflow","questionId":51425563,"title":"RabbitMQ - What does it mean to declare a queue?","tags":["c#","rabbitmq"],"text":"Title: RabbitMQ - What does it mean to declare a queue?\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am new to RabbitMQ and I have a question. Here is a sample snippet that I see often in tutorials.\n\n```\npublic static void Send(string queueName, string data)\n {\n using (IConnection connection = new ConnectionFactory().CreateConnection())\n {\n using (IModel channel = connection.CreateModel())\n {\n channel.QueueDeclare(queue: queueName,\n durable: true,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n\n // Publish to the named queue\n channel.BasicPublish(string.Empty, queue, null, Encoding.UTF8.GetBytes(data));\n }\n }\n }\n```\n\nI am confused because the concept of declaring a queue every time you want to call the `Send` function is a bit weird to me. Does that mean it creates a new queue every time? \n\nSome of the sample code for receiving from a queue also has a `queueDeclare` call. Why is it needed there?\n\n========================================\n\nCode:\n```text\npublic static void Send(string queueName, string data)\n {\n using (IConnection connection = new ConnectionFactory().CreateConnection())\n {\n using (IModel channel = connection.CreateModel())\n {\n channel.QueueDeclare(queue: queueName,\n durable: true,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n\n // Publish to the named queue\n channel.BasicPublish(string.Empty, queue, null, Encoding.UTF8.GetBytes(data));\n }\n }\n }\n```\n\n```text\nSend\n```\n\n```text\nqueueDeclare\n```\n\n========================================\n\nComments:\n- If you wish to learn more about messaging and EAI then look no further than the book *Enterprise Integration Patterns*. Just about every contemporary EAI system out there is based on it\n- That helps. Thank you!\n- In theory, you should be able to declare the channel once and store a reference to it that can be accessed by multiple functions. I'm not familiar with RabbitMQ enough yet to know if that's a good idea or not though.\n- @BradleyUffner is correct - creating a new connection and channel per-message is one of the worst RabbitMQ anti-patterns. It is literally the most inefficient way to interact with RabbitMQ. This may not matter depending on your message publish rate, however.","metadata":{"transformedAt":"2026-08-18T18:33:20.185Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":69,"estimatedTokens":597}}716{"id":"stack-41122182","source":"stackoverflow","questionId":41122182,"title":"Bind RabbitMQ consumer using Spring Cloud Stream to an existing queue","tags":["java","spring","rabbitmq","spring-cloud-stream"],"text":"Title: Bind RabbitMQ consumer using Spring Cloud Stream to an existing queue\nTags: java, spring, rabbitmq, spring-cloud-stream\nSource: Stack Overflow\n\nQuestion:\nI've created using the RabbitMQ web-UI a topic exchange **TX** and bind to the exchange two queues **TX.Q1** and **TX.Q2**, each binded with routing-keys **rk1** and **rk2** accordingly, and produced few messages to the exchange.\n\nNow I want to create a consumer using Spring Cloud Stream that will take messages from Q1 only.\nI tried using configuration:\n\n```\nspring.cloud.stream.bindings.input.destination=TX\nspring.cloud.stream.bindings.input.group=Q1\n```\n\nand the annotation `@StreamListner(Sink.INPUT)` for the method that consumes messages.\n\nAs result I can see that the consumer has created a queue (or binding) with the same name **TX.Q1** but the Routing-Key of the new queue/bind is #.\n\nHow can I configure via Spring Cloud Stream a consumer that will consume messages from the predifined queue (only that routed with **rk1**).\n\n========================================\n\nTop Answer:\nI think I found the solution using the `@StreamListener`, not using the workaround. Everything is made in the configuration, not in the code.\n\nThe configuration I used is the following (it's in .yml, but you can easly translate it in .properties):\n\n```\nspring:\n cloud:\n stream:\n bindings:\n input:\n binder: \n destination: TX\n group: Q1\n binders:\n :\n type: rabbit\n environment:\n spring:\n rabbitmq:\n host: \n port: \n virtual-host: \n username: \n password: \n rabbit:\n bindings:\n input:\n consumer:\n binding-routing-key: rk1\n exchange-name: TX\n queue-name-group-only: true\n bind-queue: true\n exchange-durable: true\n exchange-type: topic\n```\n\nUsing this approach, you don't have to write a particular code to let the RabbitMQ consumer connect to your cluster, this should solve your case.\n\nHope this helps.\n\n========================================\n\nCode:\n```text\nspring.cloud.stream.bindings.input.destination=TX\nspring.cloud.stream.bindings.input.group=Q1\n```\n\n```text\n@StreamListner(Sink.INPUT)\n```\n\n```text\n@RabbitListener\n```\n\n```text\n@StreamListenet\n```\n\n```text\n@RabbitListener(bindings = @QueueBinding(value = @Queue(value = \"TX.Q1\", durable = \"true\"), exchange = @Exchange(value = \"TX\", type = \"topic\", durable = \"true\"), key = \"rk1\")\n```\n\n```text\nexchange\n```\n\n```text\npartition\n```\n\n```text\nspring:\n cloud:\n stream:\n bindings:\n input:\n binder: <binder_name>\n destination: TX\n group: Q1\n binders:\n <binder_name>:\n type: rabbit\n environment:\n spring:\n rabbitmq:\n host: <host>\n port: <port>\n virtual-host: <vhost>\n username: <username>\n password: <password>\n rabbit:\n bindings:\n input:\n consumer:\n binding-routing-key: rk1\n exchange-name: TX\n queue-name-group-only: true\n bind-queue: true\n exchange-durable: true\n exchange-type: topic\n```\n\n```text\n@StreamListener\n```\n\n```text\ncloud:\nstream:\n # rabbit setting: https://github.com/spring-cloud/spring-cloud-stream-binder-rabbit\n rabbit:\n bindings:\n input:\n consumer:\n acknowledgeMode: AUTO\n bindingRoutingKey: DECISION_PERSISTENCE_KEY\n declareExchange: false\n bindQueue: false\n queueNameGroupOnly: true\n consumerTagPrefix: dpa-rabbit-consumer\n bindings:\n input:\n binder: rabbit\n group: DECISION_PERSISTENCE_QUEUE\n content-type: application/json\n```\n\n========================================\n\nComments:\n- So you mean that with Spring cloud stream I can't bind a consumer to specific predefined (not anonymous) queue that has a routing key?\n- I just tested and we add a second binding; I think that's a bug - if the queue already exists we should not add the generic (`#` wildcard binding). As a work-around, you could use a `@RabbitListener` instead of a `@StreamListener` (unless you are relying on the stream listener for conversion). I opened and issue for this.\n- It's being a while since this workaround, I'm wondering if you came out with a more clean solution (e.g. using properties instead of annotations).\n- it doesn't work as expected. For instance, I exactly gave the above settings but each time I restart my application, I notice that in RabbitMQ a new binding gets created with routing key # - even though I had already defined another routing key. So, whenever I sent a message even without routing key - I am not expecting my listener to get that message - however, as a new binding got automatically created (#) as mentioned in original question as well - I am unable to send message with specific routing key.","metadata":{"transformedAt":"2026-08-18T18:33:20.185Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":160,"estimatedTokens":1200}}717{"id":"stack-45598677","source":"stackoverflow","questionId":45598677,"title":"How do you get RabbitMQ queue size from c# client?","tags":["c#","rabbitmq"],"text":"Title: How do you get RabbitMQ queue size from c# client?\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI need to set an upper limit on how many messages can be in a queue. So obviously I need to know how many items are in a queue. How do you check the number of messages in a RabbitMQ queue from the c# client without hitting the management API or using QueueDeclarePassive?\n\n========================================\n\nCode:\n```text\npublic uint GetMessageCount(string queueName)\n{\n using (IConnection connection = factory.CreateConnection())\n using (IModel channel = connection.CreateModel())\n {\n return channel.MessageCount(queueName);\n }\n}\n```\n\n========================================\n\nComments:\n- There's nothing wrong with answering your own question, but it has to be an actual question, not just an intro to your answer. Read the “Help others” section of the link.\n- Help others reproduce the problem?","metadata":{"transformedAt":"2026-08-18T18:33:20.185Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":26,"estimatedTokens":234}}718{"id":"stack-42180851","source":"stackoverflow","questionId":42180851,"title":"RabbitMQ - Avoiding duplicate messages at publisher side","tags":["rabbitmq","amqp"],"text":"Title: RabbitMQ - Avoiding duplicate messages at publisher side\nTags: rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI am using RabbitMQ to send notifications to the user. The user can read his queue at any time.\n\nThe problem I am facing is that the queue is filled with lots of notifications during the night, and when the user returns in the morning, he has to process these messages sequentially. A lot of these notifications are even duplicates.\n\nI guess it would make sense to improve this at the publisher side. That is, before adding a new notification, we investigate if there are already pending notifications in the queue. If this is the case, we only queue a new notification if it is really a new notification, hence avoiding duplicates.\n\nWe might even go further and extend this by combining notifications: instead of simply queuing a new notification, we could replace the present notifications from the queue by a new one which holds the sum of these notifications and the new one (for example in an array of inner notifications).\n\nIs this possible with AMQP/RabbitMQ?\n\n========================================\n\nTop Answer:\nThis rabbitmq plugin has been written to tackle your issue.\n\nYou can enable de-duplication on a queue via setting its `x-message-deduplication` argument to `true`.\n\nThen, your publishers will need to provide the `x-deduplication-header` message header with a value meaningful for de-duplication. The value could be a unique message `ID` or the `MD5`/`SHA1` hash of the body for example.\n\n========================================\n\nCode:\n```text\nx-message-deduplication\n```\n\n```text\ntrue\n```\n\n```text\nx-deduplication-header\n```\n\n```text\nID\n```\n\n```text\nMD5\n```\n\n```text\nSHA1\n```\n\n========================================\n\nComments:\n- Thanks for feedback. But what could we do to solve/improve my scenario? Basically, I am trying to solve scenario's in which queues are 'overloaded', because the consumer has not been reading for a while (which for example happens during night, when the consumer is offline). I want to avoid that the consumer has to handle each message, without knowledge that these messages are duplicates of messages further in the queue.\n- you could use the `TTL` extension and remove the messages older than X seconds rabbitmq.com/ttl.html The messages duplication are from application side! if you want to avoid them you have to trace the messages are you sending.\n- Hello, I downloaded the plugin and the related ez files. Did the changes with the header and the queue argument and then tried to enable the plugin. Here is the error I got: ** (CaseClauseError) no case clause matching: {:plugin_built_with_incompatible_erlang, 'rabbitmq_message_deduplication'} {:case_clause, {:plugin_built_with_incompatible_erlang, 'rabbitmq_message_deduplication'}} rabbitmq server version is 3.8.7. Do I need to upgrade?","metadata":{"transformedAt":"2026-08-18T18:33:20.185Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":57,"estimatedTokens":718}}719{"id":"stack-36650061","source":"stackoverflow","questionId":36650061,"title":"How to make RabbitMQ scalable?","tags":["performance","rabbitmq","cluster-computing","load-balancing","scalability"],"text":"Title: How to make RabbitMQ scalable?\nTags: performance, rabbitmq, cluster-computing, load-balancing, scalability\nSource: Stack Overflow\n\nQuestion:\nI tried to test RabbitMQ, but I found that rabbitmq has some problems:\nif I created a cluster of 3 nodes, I can't publish/delivered more than 6000/s.\nin other hand, if I worked with one single node, I can publish/delivery until 25000/s.\nwhich means, more that I add nodes, more performance is deteriorating.\n\nbut from this article : https://blog.pivotal.io/pivotal/products/rabbitmq-hits-one-million-messages-per-second-on-google-compute-engine\n\nthey can publish more than 1 million, so how they can do that?\nI want to make RabbitMQ process more than 1 million messages per second\n\n========================================\n\nTop Answer:\nIn this test of RabbitMQ performance, the authors concluded that a small cluster will underperform a single node cluster. More nodes need to be added to increase the performance. This makes sense when you think about the overhead induced by replication required in a distributed system, especially given that RabbitMQ focus is reliability.\n\nThe following is mentioned in a blog post by RabbitMQ:\n\nIf you use quorum queues or mirrored queues, then each message will be delivered to multiple brokers. If you have a cluster of three brokers and quorum queues with a replicator factor of 3, then every broker will receive every message. In that case, we’ve created a cluster *for redundancy only*. But we can also create larger clusters *for scalability*. We could have a cluster of 9 brokers, with quorum queues with a rep factor of 3 and now we’ve spread that load out and can handle a much larger total throughput.\n\n========================================\n\nComments:\n- Are you consuming these messages, or only publishing?\n- I have an efficient consumer, and many producers, but the producer can send more than 900000 messages per second. The problem is that Rabbitmq can't process more than 22000messages/seconds (in single node), but if I used a cluster (for fault-tolerance issues), the performance deteriorating,\n- this is not the problem. In that benchmarking test, they used a cluster with 32 machines, but if I tried the same thing,I will not even able to process more than 10 messages/second, because, for each added node, the performance becomes worse\n- Just out of curiosity, how did you subscribe to multiple nodes in this case ?(again via load balancer or some other strategy)","metadata":{"transformedAt":"2026-08-18T18:33:20.185Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":31,"estimatedTokens":618}}720{"id":"stack-18002472","source":"stackoverflow","questionId":18002472,"title":"RabbitMQ 3.1.3 and the missing timestamp header","tags":["timestamp","rabbitmq","amqp","stomp","broker"],"text":"Title: RabbitMQ 3.1.3 and the missing timestamp header\nTags: timestamp, rabbitmq, amqp, stomp, broker\nSource: Stack Overflow\n\nQuestion:\nIs it possible to configure the broker to insert a timestamp header if it is missing in the message? So if the publishing client does not add the timestamp header, can the broker insert it with a timestamp value matching the moment the message was received by the exchange? Where should I look for that configuration? Or is that a bad idea?\n\n========================================\n\nTop Answer:\nAs of 2015, there are new answers for the original question.\n\nThis plugin will do exactly what you were looking for.\n\nTake in mind there will be some minimal overhead since it will hook all messages being queued.\n\n========================================\n\nComments:\n- Possible duplicate of Rabbitmq message arrival time stamp","metadata":{"transformedAt":"2026-08-18T18:33:20.185Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":20,"estimatedTokens":215}}721{"id":"stack-12349573","source":"stackoverflow","questionId":12349573,"title":"How to know if message was published to a queue using rabbitmq routing features","tags":["python","rabbitmq","pika"],"text":"Title: How to know if message was published to a queue using rabbitmq routing features\nTags: python, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI've been working on a project which uses rabbitmq to communicate. Recently we discovered that it would be much scalable if we used rabbit routing feature. So basically we bind the queue to several routing keys and use an exchange with type `direct`.\n\nIt's working like publish/subscribe. So it's possible to bind and unbind the queue to different events so consumers/subscribers only receive messages to which they're interested.\n\nOf course, the producer/publisher now uses the binding key (event name) as `routing_key` to pass it to pika implementation. However, when it publishes something for a binding that doesn't exist the message is lost, i.e. when nobody bound a queue for event `foo`, but some publisher calls `pika.basic_publish(..., routing_key='foo')`.\n\n**So my question is:** \n\nIs it possible to know if the message was actually published in a queue?\n\n**What I've tried:**\n\nChecking the return value of pika.basic_publish. It always returns `None`.\n\nCheck if there's an exception when we try to publish for a binding that doesn't exist. There is none.\n\nHaving an additional queue to make out of band control (since all subscribers are run by the same process). This approach doesn't feel ideal to me.\n\n**Additional info**\n\nSince I'm using this routing feature, the queue names are generated by rabbit. I don't have any problem if the new approach has to name the queue itself.\n\nIf a new approach is suggested which requires binding to exchanges instead of queues, I would like to hear them, but I would prefer to avoid them as they're not actually AMQP and are an extension implemented by rabbitmq.\n\npika version is 0.9.5\n\nrabbitmq version is 2.8\n\nThanks a lot\n\n========================================\n\nTop Answer:\nIt may be possible to use a dead letter exchange to store messages that have not been consumed http://www.rabbitmq.com/dlx.html\n\nI am not sure this is exactly what you are looking for but could be used for a solution.\n\n========================================\n\nCode:\n```text\ndirect\n```\n\n```text\nrouting_key\n```\n\n```text\nfoo\n```\n\n```text\npika.basic_publish(..., routing_key='foo')\n```\n\n```text\nNone\n```\n\n========================================\n\nComments:\n- This is exactly what I want. Perfect!","metadata":{"transformedAt":"2026-08-18T18:33:20.185Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":69,"estimatedTokens":594}}722{"id":"stack-5950322","source":"stackoverflow","questionId":5950322,"title":"Alternatives to RabbitMQ for .NET centric shop?","tags":[".net","messaging","rabbitmq"],"text":"Title: Alternatives to RabbitMQ for .NET centric shop?\nTags: .net, messaging, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI need a reliable messaging solution. It looks like RabbitMQ would address the needs of my application. However, my environment is not well suited to deploying Erlang and Mnesia on a server. It is an enterprise environment and it is a huge battle of red tape to get \"non-standard\" pieces like that deployed. I would prefer to find a reliable messaging framework similar to RabbitMQ, but built on .NET. Storing messages in Oracle and/or SQL Server would be a bonus. Anything like that out there?\n\nI'm aware of NServiceBus, but I don't think this is focused on reliable messaging as much as RabbitMQ is.\n\n========================================\n\nTop Answer:\nTake a look at ZeroMQ\n\n========================================\n\nComments:\n- `I'm aware of NServiceBus, but I don't think this is focused on reliable messaging as much as RabbitMQ is` What makes you say that?\n- Ehh...my own (quite possibly limited) understanding of NServiceBus. If you'd like to correct me, go for it. Perhaps I'm misunderstanding what NServiceBus is trying to do.\n- MSMQ, from what I understand, is a mechanism for persisting messages, but it doesn't have any kind of service layer for orchestrating between message publishers and subscribers or anything like that. I would prefer not to write all that myself. But if I were, the persistence layer would quite possibly be MSMQ.\n- Which is why Microsoft created WCF.\n- I will have to research using WCF with MSMQ. Thanks for the info.\n- ActiveMQ is no longer being actively developed since the vendor has created ZeroMQ. For inhouse use, ZeroMQ is a great solution since no server needs to be installed. In fact, any functionality that you might want from a server, can be programmed in one of your applications using ZeroMQ, so you have the ultimate in flexibility and it is easy to build and to support.\n- @Michael Dillon Thanks never heard of ZeroMQ before. I'll have to look into it.","metadata":{"transformedAt":"2026-08-18T18:33:20.185Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":24,"estimatedTokens":508}}723{"id":"stack-51945246","source":"stackoverflow","questionId":51945246,"title":"How to keep forked child process alive in node js","tags":["javascript","node.js","rabbitmq","forever"],"text":"Title: How to keep forked child process alive in node js\nTags: javascript, node.js, rabbitmq, forever\nSource: Stack Overflow\n\nQuestion:\nI want to create a rabbitmq cli running like foreverjs with node. It can spawn child_process and keep it running in the background and can communicate with child_process at any time. The problem I am facing is when main cli program exit the child_process seems to stop running as well, I tried to fork with detached:true and .unref() it doesn't work. How do i run a child process in the background even after the parent caller process exited? \n\ncli.js - parent\n\n```\nconst { fork, spawn } = require('child_process');\nconst options = {\n stdio: ['pipe', 'pipe', 'pipe', 'ipc'],\n slient:true,\n detached:true\n};\n\nchild = fork('./rabbit.js', [], options)\n\nchild.on('message', message => {\n console.log('message from child:', message);\n child.send('Hi');\n // exit parent\n process.exit(0);\n});\n\nchild.unref()\n```\n\nrabbit.js - child\nif it is up and running, 'i' should keep incrementing\n\n```\nvar i=0;\ni++;\nif (process.send) {\n process.send(\"Hello\"+i);\n}\n\nprocess.on('message', message => {\n console.log('message from parent:', message);\n});\n```\n\n========================================\n\nTop Answer:\nAn old question, but for those picking up where I am today: `fork` does have a `detached` option. However it also opens an IPC channel which has to be explicitly closed with `disconnect()` as well if you want to break the relationship between the parent and the child.\n\nIn my case it was advantageous to use the channel until I had confirmation that the child process was ready to do its job, and then disconnect it:\n\n```\n// Run in background\n const handle = cp.fork('./service/app.js', {\n detached: true,\n stdio: 'ignore'\n });\n // Whenever you are ready to stop receiving IPC messages\n // from the child\n handle.unref();\n handle.disconnect();\n```\n\nThis allows my parent process to exit without killing the background process or being kept alive by a reference to it.\n\nIf you do establish any `handle.on(...)` handlers, it's a good idea to disconnect them with `handle.off(...)` as well when you are through with them. I used a `handle.on('message', (data) => { ... })` handler to allow the child to tell the parent when it was ready for its duties after doing some async startup work.\n\n========================================\n\nCode:\n```text\nconst { fork, spawn } = require('child_process');\nconst options = {\n stdio: ['pipe', 'pipe', 'pipe', 'ipc'],\n slient:true,\n detached:true\n};\n\nchild = fork('./rabbit.js', [], options)\n\nchild.on('message', message => {\n console.log('message from child:', message);\n child.send('Hi');\n // exit parent\n process.exit(0);\n});\n\nchild.unref()\n```\n\n```text\nvar i=0;\ni++;\nif (process.send) {\n process.send(\"Hello\"+i);\n}\n\nprocess.on('message', message => {\n console.log('message from parent:', message);\n});\n```\n\n```text\nconst { fork, spawn } = require('child_process');\nconst options = {\n slient:true,\n detached:true,\n stdio: [null, null, null, 'ipc']\n};\n\nchild = spawn('node', ['rabbit.js'], options);\nchild.on('message', (data) => {\n console.log(data);\n child.unref();\n process.exit(0);\n});\n```\n\n```text\nvar i=0;\ni++;\nprocess.send(i);\n// this can be a http server or a connection to rabbitmq queue. Using setInterval for simplicity\nsetInterval(() => {\n console.log('yash');\n}, 1000);\n```\n\n```text\nfork\n```\n\n```text\ndetached\n```\n\n```text\nspawn\n```\n\n```text\nspawn\n```\n\n```text\nIPC channel\n```\n\n```text\nIPC channel\n```\n\n```text\ncli.js\n```\n\n```text\nrabbit.js\n```\n\n```text\nipc\n```\n\n```text\nstdio\n```\n\n```text\nfd\n```\n\n```text\nnull\n```\n\n```text\n// Run in background\n const handle = cp.fork('./service/app.js', {\n detached: true,\n stdio: 'ignore'\n });\n // Whenever you are ready to stop receiving IPC messages\n // from the child\n handle.unref();\n handle.disconnect();\n```\n\n```text\nfork\n```\n\n```text\ndetached\n```\n\n```text\ndisconnect()\n```\n\n```text\nhandle.on(...)\n```\n\n```text\nhandle.off(...)\n```\n\n```text\nhandle.on('message', (data) => { ... })\n```\n\n```js\n/**\n * This code apart from the comments is available on the Node website\n */\n\n// We use fork, but spawn should also work\nconst {fork} = require('child_process');\n\nlet out = fs.openSync(\"/path/to/outfile\", \"a\");\nlet err = fs.openSync(\"/path/to/errfile\", \"a\");\n\nconst child = fork(jsScriptPath, [\"--some\", \"arg\"], {\n detached: true,\n stdio: [\"pipe\", out, err, \"ipc\"], // => Ask the child to redirect its standard output and error messages to some files\n // silent is overriden by stdio\n});\n\n// SetTimeout here is only for illustration. You will want to use more valid code\nsetTimeout( () => {\n child.unref();\n process.exit(0);\n}, 1000);\n```\n\n========================================\n\nComments:\n- if this works, can i still communicate with child process with message callback?\n- I don't think so. That communication specific to `fork`. You'll have to probably find another way to communicate with the child process. If it's redirecting the stdio of child to the parent, that can be done with `spawn`. But `IPC` kind of messaging cannot be done I suppose.\n- In that case how pm2 or forever achieve such functionality. like forever start then the process is brought to the back and can stop corresponding by some sort of process id?\n- That can be done with spawn right? Start a child process with spawn, then kill the parent one. The child still keeps running? `forever` might pipe the `stdio`, `stderr` to the parent process which is possible with `spawn`.\n- is it possible to write me small code fragment showing which method to use in nodejs to achieve that? sorry for being a pain\n- I think this article has quite a few examples in that regard. medium.freecodecamp.org/…\n- ya i read it before, but it doesn't seem to address my use case. I'll mark your answer useful since it answered my first question. The closest i get to is this stackoverflow.com/questions/29896474/… by setting up a server to as a data exchange in between parent and child.\n- Is that so! Sure. I'll try coming up with a code fragment to achieve what you asked for. I'll update the answer if I succeed.\n- Thanks for ur help !","metadata":{"transformedAt":"2026-08-18T18:33:20.185Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":24,"totalLines":248,"estimatedTokens":1556}}724{"id":"stack-51745211","source":"stackoverflow","questionId":51745211,"title":"Spring Boot + Spring Web Socket + RabbitMQ Web STOMP","tags":["java","spring-boot","rabbitmq","spring-websocket","sockjs"],"text":"Title: Spring Boot + Spring Web Socket + RabbitMQ Web STOMP\nTags: java, spring-boot, rabbitmq, spring-websocket, sockjs\nSource: Stack Overflow\n\nQuestion:\nI am working on adding live notification in my application\n\nI have done POC with\n- Spring Boot\n- Spring WebSocket\n- SockJS\n- RabbitMQ STOMP plugin\n\nI read about RabbitMQ Web STOMP and want to do POC of that. But it says Since version 3.7 support for SockJS websocket emulation was removed.\n\nIs there any example for Spring WebSocket + RabbitMQ Web STOMP with or without SockJS.\n\nPlease help.\n\nReference links:\n\nhttp://www.rabbitmq.com/stomp.html\n\nhttp://www.rabbitmq.com/web-stomp.html\n\nhttps://spring.io/guides/gs/messaging-stomp-websocket/\n\n========================================\n\nCode:\n```text\n@Configuration\n@EnableWebSocketMessageBroker\npublic class WebSocketConfig implements WebSocketMessageBrokerConfigurer {\n private static final Logger log = LoggerFactory.getLogger(WebSocketConfig.class);\n @Value(\"${spring.rabbitmq.username}\")\n private String userName;\n @Value(\"${spring.rabbitmq.password}\")\n private String password;\n @Value(\"${spring.rabbitmq.host}\")\n private String host;\n @Value(\"${spring.rabbitmq.port}\")\n private int port;\n @Value(\"${endpoint}\")\n private String endpoint;\n @Value(\"${destination.prefix}\")\n private String destinationPrefix;\n @Value(\"${stomp.broker.relay}\")\n private String stompBrokerRelay;\n @Override\n public void configureMessageBroker(final MessageBrokerRegistry config) {\n config.enableStompBrokerRelay(stompBrokerRelay).setRelayHost(host).setRelayPort(port).setSystemLogin(userName).setSystemPasscode(password);\n config.setApplicationDestinationPrefixes(destinationPrefix);\n }\n @Override\n public void registerStompEndpoints(final StompEndpointRegistry registry) {\n registry.addEndpoint(endpoint).setAllowedOrigins(\"*\").withSockJS();\n }\n}\n```\n\n```text\n@Autowired\nSimpMessagingTemplate template\n\ntemplate.convertAndSend(destinationurl, object);\n```\n\n========================================\n\nComments:\n- Hi, I am looking for a similar working example. Could you the code please? Thanks","metadata":{"transformedAt":"2026-08-18T18:33:20.185Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":72,"estimatedTokens":541}}725{"id":"stack-45796021","source":"stackoverflow","questionId":45796021,"title":"How does spring look for @EnableJms methods if I don't have class marked @EnableJms annotation?","tags":["java","spring","spring-boot","rabbitmq","spring-jms"],"text":"Title: How does spring look for @EnableJms methods if I don't have class marked @EnableJms annotation?\nTags: java, spring, spring-boot, rabbitmq, spring-jms\nSource: Stack Overflow\n\nQuestion:\nI am reading official get started article about how to start spring-jms application\n\nhttps://spring.io/guides/gs/messaging-jms/\n\n @EnableJms triggers the discovery of methods annotated with\n @JmsListener, creating the message listener container under the\n covers.\n\nBut my application sees `@JmsListener` methods without `@EnableJms` annotation.\n\nMaybe something else force spring search the `@EnableJms` methods. I want to know it.\n\nproject srtucture:\n\nhttps://i.sstatic.net/4lZ6u.jpg\n\n### Listener:\n\n```\n@Component\npublic class Listener {\n\n @JmsListener(destination = \"my_queue_new\")\n public void receive(Email email){\n System.out.println(email);\n }\n @JmsListener(destination = \"my_topic_new\", containerFactory = \"myFactory\")\n public void receiveTopic(Email email){\n System.out.println(email);\n }\n}\n```\n\n### RabbitJmsApplication:\n\n```\n@SpringBootApplication\n//@EnableJms I've commented it especially, behaviour was not changed.\npublic class RabbitJmsApplication {\n\n public static void main(String[] args) {\n SpringApplication.run(RabbitJmsApplication.class, args);\n }\n\n @Bean\n public RMQConnectionFactory connectionFactory() {\n return new RMQConnectionFactory();\n }\n\n @Bean\n public JmsListenerContainerFactory myFactory(DefaultJmsListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory) {\n DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();\n // This provides all boot's default to this factory, including the message converter\n configurer.configure(factory, connectionFactory);\n // You could still override some of Boot's default if necessary.\n factory.setPubSubDomain(true);\n return factory;\n }\n}\n```\n\n========================================\n\nCode:\n```text\n@Component\npublic class Listener {\n\n @JmsListener(destination = \"my_queue_new\")\n public void receive(Email email){\n System.out.println(email);\n }\n @JmsListener(destination = \"my_topic_new\", containerFactory = \"myFactory\")\n public void receiveTopic(Email email){\n System.out.println(email);\n }\n}\n```\n\n```text\n@SpringBootApplication\n//@EnableJms I've commented it especially, behaviour was not changed.\npublic class RabbitJmsApplication {\n\n public static void main(String[] args) {\n SpringApplication.run(RabbitJmsApplication.class, args);\n }\n\n @Bean\n public RMQConnectionFactory connectionFactory() {\n return new RMQConnectionFactory();\n }\n\n @Bean\n public JmsListenerContainerFactory<?> myFactory(DefaultJmsListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory) {\n DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();\n // This provides all boot's default to this factory, including the message converter\n configurer.configure(factory, connectionFactory);\n // You could still override some of Boot's default if necessary.\n factory.setPubSubDomain(true);\n return factory;\n }\n}\n```\n\n```text\n@JmsListener\n```\n\n```text\n@EnableJms\n```\n\n```text\n@EnableJms\n```\n\n```text\n@EnableJms\n```\n\n```text\nConnectionFactory\n```\n\n```text\nConnectionFactory\n```\n\n========================================\n\nComments:\n- enableJms is required. Have you tried rebuilding and running application again.\n- @Sangam Belose I tried click build/rebuild in idea. Now I will try to make invalidate cache\n- @Sangam - it still working. If you have a desire to help me, I can all sources with you.\n- Spring Boot detects the existence of JMS and automatically enables JMS processing. The statement holds true only for non Spring Boot applications.\n- @M. Deinum, How does spring detects the existence of JMS?\n- Spring doesn't detect anything Spring Boot does the detection. The existence of the `@EnableJms` annotation on the class path will trigger the `JmsAnnotationDrivenConfiguration` from Spring Boot. Which will automatically register the needed components.\n- @M. Deinum, I am sorry for inaccuracy. How does spring-boot detects the existence of JMS? It sees on dependencies?\n- As it does with other features it detects if certain classes/api classes are on the class path.\n- @M. Deinum, thanks for clarification","metadata":{"transformedAt":"2026-08-18T18:33:20.185Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":146,"estimatedTokens":1092}}726{"id":"stack-24343445","source":"stackoverflow","questionId":24343445,"title":"How to put data from server to Kinesis Stream","tags":["java","amazon-web-services","rabbitmq","amazon-kinesis"],"text":"Title: How to put data from server to Kinesis Stream\nTags: java, amazon-web-services, rabbitmq, amazon-kinesis\nSource: Stack Overflow\n\nQuestion:\nI am new to Kinesis. Reading out the documentation i found i can create the Kinesis Stream to get data from Producer. Then using KCL will read this data from Stream to further processing. I understand how to write the KCL application by implemeting IRecordProcessor . \n\nHowever the very first stage as how to put data on Kinesis stream is still not clear to me. Do we have some AWS API which does need implementation to achieve this. \n\nScenarios: I have an server which is contineously getting data from various sources in the folders. Each folder is containing the text file whose rows are containing the required attributes for furhter analytical work. i have to push all these data to Kinesis Stream. \n\nI need code something as below below class putData method wil be used to out in Kinesis stream\n\n```\npublic class Put {\n\n AmazonKinesisClient kinesisClient;\n\n Put()\n {\n String accessKey = \"My Access Key here\" ;\n String secretKey = \"My Secret Key here\" ;\n AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);\n kinesisClient = new AmazonKinesisClient(credentials);\n kinesisClient.setEndpoint(\"kinesis.us-east-1.amazonaws.com\", \"kinesis\", \"us-east-1\");\n System.out.println(\"starting the Put Application\");\n }\n\n public void putData(String fileContent,String session) throws Exception\n {\n final String myStreamName = \"ClickStream\";\n\n PutRecordRequest putRecordRequest = new PutRecordRequest();\n putRecordRequest.setStreamName(myStreamName);\n String putData = fileContent;\n putRecordRequest.setData(ByteBuffer.wrap(putData.getBytes()));\n putRecordRequest.setPartitionKey(\"session\"+session);\n PutRecordResult putRecordResult = kinesisClient.putRecord(putRecordRequest);\n System.out.println(\"Successfully putrecord, partition key : \" + putRecordRequest.getPartitionKey()\n + \", ShardID : \" + putRecordResult.getShardId());\n System.out.println(fileContent);\n System.out.println(\"Sequence Number: \"+putRecordResult.getSequenceNumber());\n\n System.out.println(\"Data has been PUT successfully\");\n\n }\n}\n```\n\nHowever reading file from the source folder from the server and then what design i should use to call putData to get the record on Kinesis stream. Do i need infinite loop and reading all files and then do this or some framework which will better do this with care of fault tolerance , single point of failure all . Any help would be greatly appreciated. \n\nBriefly: I need a better technique to put regularly generated data to Kinesis Stream the data is generated at regular interval to server. \nThanks\n\n========================================\n\nTop Answer:\nIf you are tailing some files, try Fluentd. http://www.fluentd.org/\n\nAmazon Kinesis has a pretty nice plugin for that. https://github.com/awslabs/aws-fluent-plugin-kinesis\n\n========================================\n\nCode:\n```text\npublic class Put {\n\n AmazonKinesisClient kinesisClient;\n\n Put()\n {\n String accessKey = \"My Access Key here\" ;\n String secretKey = \"My Secret Key here\" ;\n AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);\n kinesisClient = new AmazonKinesisClient(credentials);\n kinesisClient.setEndpoint(\"kinesis.us-east-1.amazonaws.com\", \"kinesis\", \"us-east-1\");\n System.out.println(\"starting the Put Application\");\n }\n\n public void putData(String fileContent,String session) throws Exception\n {\n final String myStreamName = \"ClickStream\";\n\n PutRecordRequest putRecordRequest = new PutRecordRequest();\n putRecordRequest.setStreamName(myStreamName);\n String putData = fileContent;\n putRecordRequest.setData(ByteBuffer.wrap(putData.getBytes()));\n putRecordRequest.setPartitionKey(\"session\"+session);\n PutRecordResult putRecordResult = kinesisClient.putRecord(putRecordRequest);\n System.out.println(\"Successfully putrecord, partition key : \" + putRecordRequest.getPartitionKey()\n + \", ShardID : \" + putRecordResult.getShardId());\n System.out.println(fileContent);\n System.out.println(\"Sequence Number: \"+putRecordResult.getSequenceNumber());\n\n System.out.println(\"Data has been PUT successfully\");\n\n\n }\n}\n```\n\n========================================\n\nComments:\n- Yes i am moving data to S3 from Kinesis. I was looking some ready made solution to keep reading the files from the folder from my server for each day and put all these data to Kinesis stream. Well in my server i have multiple folder for different date and each day contains many files with log information. i want to transfer this to Kinesis stream. At this level i think i can write simple program with infinite loop with some thread delay to keep reading the events and move to Kinesis if some already proven solution is not present. Thanks\n- May i use RabbitMQ to put data to Kinesis Stream. ?\n- Amazon does not provide any out of the box pushing program. You must create it yourself. No fimiliar with RabbitMQ\n- With Java7 interesting feature of WatchService API is great to deal with my file problems. Now i am able to read files as on when created\\changed etc. However could you please recommend me some good tips to choose partition key. ?\n- Think of a deck of cards, an okay partition key would be color, but a better one would be suits. It depends on your data, but I have used things like EventType, UserID, Country+StateofRecord. You want to try and split your data evenly amoung readers.","metadata":{"transformedAt":"2026-08-18T18:33:20.185Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":109,"estimatedTokens":1405}}727{"id":"stack-25207687","source":"stackoverflow","questionId":25207687,"title":"How do I troublehshoot why the RabbitMQ service won't start?","tags":["rabbitmq"],"text":"Title: How do I troublehshoot why the RabbitMQ service won't start?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nLet me start out by saying I'm new to RabbitMQ. I've advanced beyond the simple Hello World apps but still a newbie on the server administration of RabbitMQ.\n\nI'm running RabbitMQ Server 3.3.4 on Windows 7 Professional with Erlang 17.1 (win64).\n\nYesterday, RabbitMQ was running just fine. I was working in Visual Studio 2013 building a performance testing app to measure throughput. While developing and testing the app, I was pushing millions of messages (one test iteration had 50M messages) into the queues.\n\nNear the end of the afternoon, the service just stopped working. I tried manually restarting the service, rebooting, uninstall / install, uninstall / delete all the remnants I could fine / install again... none of it worked.\n\nToday, I uninstalled again, deleted all the remnants I could fine, and then installed again. Nothing is working; I cannot get RabbitMQ to start.\n\nIn the log files, rabbit@X-name-X.log and rabbit@X-name-X-sasl.log, I found the following stacktrace, error, and crash report. Hopefully someone can help me dig a little deeper into the cause and solution.\n\n```\nStack trace:\n [{rabbit_networking,record_distribution_listener,0,[]},\n {rabbit_networking,boot,0,[]},\n {rabbit,'-run_boot_step/1-lc$^1/1-1-',1,[]},\n {rabbit,run_boot_step,1,[]},\n {rabbit,'-start/2-lc$^0/1-0-',1,[]},\n {rabbit,start,2,[]},\n {application_master,start_it_old,4,\n [{file,\"application_master.erl\"},{line,272}]}]\n\n=INFO REPORT==== 8-Aug-2014::10:24:44 ===\nError description:\n {could_not_start,rabbit,\n {bad_return,\n {{rabbit,start,[normal,[]]},\n {'EXIT',{rabbit,failure_during_boot,{badmatch,noport}}}}}}\n\n=CRASH REPORT==== 8-Aug-2014::10:24:44 ===\n crasher:\n initial call: application_master:init/4\n pid: \n registered_name: []\n exception exit: {bad_return,\n {{rabbit,start,[normal,[]]},\n {'EXIT',\n {rabbit,failure_during_boot,{badmatch,noport}}}}}\n in function application_master:init/4 (application_master.erl, line 133)\n ancestors: []\n messages: [{'EXIT',,normal}]\n links: [,]\n dictionary: []\n trap_exit: true\n status: running\n heap_size: 2586\n stack_size: 27\n reductions: 296\n neighbours:\n```\n\n========================================\n\nTop Answer:\nI had a similar issue and error messages. Maybe it's helpful to someone, here is how I was able to solve it:\n\n- I removed the %USERHOME%.erlang-cookie\nI removed all files and folders in the %APPDATA%\\Roaming\\RabbitMQ\\ folder\n(except the enabled_plugins file)\nI started cmd as Administrator and ran \n\n- `rabbitmq-service.bat remove`\n\n- `rabbitmq-service.bat install`\n\n- `rabbitmq-service.bat start`\n\nI'm not sure whether I really needed to do steps 1 and 2. Maybe the important thing is just to **run these commands as administrator**.\n\n========================================\n\nCode:\n```text\nStack trace:\n [{rabbit_networking,record_distribution_listener,0,[]},\n {rabbit_networking,boot,0,[]},\n {rabbit,'-run_boot_step/1-lc$^1/1-1-',1,[]},\n {rabbit,run_boot_step,1,[]},\n {rabbit,'-start/2-lc$^0/1-0-',1,[]},\n {rabbit,start,2,[]},\n {application_master,start_it_old,4,\n [{file,\"application_master.erl\"},{line,272}]}]\n\n\n=INFO REPORT==== 8-Aug-2014::10:24:44 ===\nError description:\n {could_not_start,rabbit,\n {bad_return,\n {{rabbit,start,[normal,[]]},\n {'EXIT',{rabbit,failure_during_boot,{badmatch,noport}}}}}}\n\n\n=CRASH REPORT==== 8-Aug-2014::10:24:44 ===\n crasher:\n initial call: application_master:init/4\n pid: <0.139.0>\n registered_name: []\n exception exit: {bad_return,\n {{rabbit,start,[normal,[]]},\n {'EXIT',\n {rabbit,failure_during_boot,{badmatch,noport}}}}}\n in function application_master:init/4 (application_master.erl, line 133)\n ancestors: [<0.138.0>]\n messages: [{'EXIT',<0.140.0>,normal}]\n links: [<0.138.0>,<0.7.0>]\n dictionary: []\n trap_exit: true\n status: running\n heap_size: 2586\n stack_size: 27\n reductions: 296\n neighbours:\n```\n\n```text\nrabbitmq-service.bat remove\n```\n\n```text\nrabbitmq-service.bat install\n```\n\n```text\nrabbitmq-service.bat start\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.185Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":131,"estimatedTokens":1059}}728{"id":"stack-30547475","source":"stackoverflow","questionId":30547475,"title":"How to declare custom error exchange for each consumer in EasyNetQ?","tags":["c#","rabbitmq","consumer","easynetq"],"text":"Title: How to declare custom error exchange for each consumer in EasyNetQ?\nTags: c#, rabbitmq, consumer, easynetq\nSource: Stack Overflow\n\nQuestion:\nI have four consumer when error occured message publishing to default EasyNetQ_Default_Error_Queue is it possible to each queue consumer write own error exchange\n\nFor example;\n\n```\nQueue Name : A ErrorExchange :A_ErrorExchange\nQueue Name : B ErrorExchange :B_ErrorExchange\n```\n\n```\nbus.Advanced.Conventions.ErrorExchangeNamingConvention = new ErrorExchangeNameConvention(info => \"A_DeadLetter\");\n\nbus.Advanced.Conventions.ErrorExchangeNamingConvention = new ErrorExchangeNameConvention(info2 => \"B_DeadLetter\");\n```\n\n========================================\n\nCode:\n```text\nQueue Name : A ErrorExchange :A_ErrorExchange\nQueue Name : B ErrorExchange :B_ErrorExchange\n```\n\n```text\nbus.Advanced.Conventions.ErrorExchangeNamingConvention = new ErrorExchangeNameConvention(info => \"A_DeadLetter\");\n\nbus.Advanced.Conventions.ErrorExchangeNamingConvention = new ErrorExchangeNameConvention(info2 => \"B_DeadLetter\");\n```\n\n```text\npublic IBus CreateBus(string connectionString, string consumerName) \n{\n var bus = RabbitHutch.CreateBus(connectionString);\n\n // Modify the following to create your error exchange name appropriately\n bus.Advanced.Container.Resolve<IConventions>().ErrorExchangeNamingConvention = \n info => consumerName + \"_ErrorExchange\";\n\n // Modify the following to create your error queue name appropriately\n bus.Advanced.Container.Resolve<IConventions>().ErrorQueueNamingConvention = \n () => consumerName + \"_ErrorQueue\";\n\n return bus;\n}\n```\n\n```text\nErrorExchangeNamingConvention\n```\n\n```text\nErrorQueueNamingConvention\n```\n\n```text\nIBus\n```\n\n========================================\n\nComments:\n- Unfortunately, as per EasyNetQ 6.3.1, ErrorExchangeNamingConvention and ErrorQueueNamingConvention are both changed to read-only :( and the naming convention has to be injected during bus creation.","metadata":{"transformedAt":"2026-08-18T18:33:20.185Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":67,"estimatedTokens":497}}729{"id":"stack-43305346","source":"stackoverflow","questionId":43305346,"title":"How to Give manual Acknowledge using JmsTemplate and delete message from Rabbitmq queue","tags":["spring","spring-boot","rabbitmq","spring-jms"],"text":"Title: How to Give manual Acknowledge using JmsTemplate and delete message from Rabbitmq queue\nTags: spring, spring-boot, rabbitmq, spring-jms\nSource: Stack Overflow\n\nQuestion:\nI am using RabbitMq(with JMS) with jmsTemplate I am able to Consume Message from RabbitMq Queue But it is taking acknowledgment AUTO.\n\nI have Search API for it but not able to find it out.\n\nHow can I set manual acknowledgment.\n\nIn Below code when Message is consumed from queue I want to call web service with that message and depends on that response from from I want to delete that message from queue.\nI have created one project in which I am using Listener and other project with call to read message from queue\n\nfirst Project:\n\n```\npackage com.es.jms.listener;\n\nimport javax.jms.ConnectionFactory;\nimport javax.jms.JMSException;\nimport javax.jms.Message;\nimport javax.jms.MessageListener;\nimport javax.jms.TextMessage;\n\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\nimport org.springframework.jms.listener.MessageListenerContainer;\nimport org.springframework.jms.listener.SimpleMessageListenerContainer;\n\nimport com.rabbitmq.jms.admin.RMQConnectionFactory;\n\n@Configuration\npublic class RabbitMqMessageListener {\n\n @Bean\n public ConnectionFactory jmsConnectionFactory() {\n RMQConnectionFactory connectionFactory = new RMQConnectionFactory();\n connectionFactory.setUsername(\"Username\");\n connectionFactory.setPassword(\"Password\");\n connectionFactory.setVirtualHost(\"vhostname\");\n connectionFactory.setHost(\"hostname\");\n\n return connectionFactory;\n }\n\n @Bean\n public MessageListener msgListener() {\n return new MessageListener() {\n public void onMessage(Message message) {\n\n System.out.println(message.toString());\n if (message instanceof TextMessage) {\n try {\n String msg = ((TextMessage) message).getText();\n System.out.println(\"Received message: \" + msg);\n\n // call web service here and depends on web service\n // response\n // if 200 then delete msg from queue else keep msg in\n // queue\n\n } catch (JMSException ex) {\n throw new RuntimeException(ex);\n }\n }\n\n }\n };\n }\n\n @Bean\n public MessageListenerContainer messageListenerContainer() {\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(jmsConnectionFactory());\n container.setDestinationName(\"test\");\n\n container.setMessageListener(msgListener());\n return container;\n\n }\n}\n```\n\n2nd Project:\n\n```\npackage com.rabbitmq.jms.consumer.controller;\n\nimport java.util.concurrent.ExecutionException;\nimport java.util.concurrent.TimeoutException;\n\nimport javax.jms.ConnectionFactory;\n\nimport org.json.JSONException;\nimport org.json.JSONObject;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.http.HttpStatus;\nimport org.springframework.http.ResponseEntity;\nimport org.springframework.jms.JmsException;\nimport org.springframework.jms.core.JmsTemplate;\nimport org.springframework.stereotype.Controller;\nimport org.springframework.web.bind.annotation.CrossOrigin;\nimport org.springframework.web.bind.annotation.RequestMapping;\nimport org.springframework.web.bind.annotation.RequestMethod;\nimport org.springframework.web.bind.annotation.ResponseBody;\n\nimport com.rabbitmq.jms.admin.RMQConnectionFactory;\n\nimport redis.clients.jedis.Jedis;\n\n@Controller\npublic class ReceiverController {\n @Autowired\n JmsTemplate jmsTemplate;\n\n @Bean\n public ConnectionFactory jmsConnectionFactory() {\n RMQConnectionFactory connectionFactory = new RMQConnectionFactory();\n connectionFactory.setUsername(\"Username\");\n connectionFactory.setPassword(\"Password\");\n connectionFactory.setVirtualHost(\"vhostname\");\n connectionFactory.setHost(\"hostname\");\n\n return connectionFactory;\n }\n\n @CrossOrigin\n @SuppressWarnings({ \"unchecked\", \"rawtypes\" })\n @RequestMapping(method = RequestMethod.GET, value = \"/getdata\")\n @ResponseBody\n public ResponseEntity fecthDataFromRedis()\n throws JSONException, InterruptedException, JmsException, ExecutionException, TimeoutException {\n System.out.println(\"in controller\");\n\n jmsTemplate.setReceiveTimeout(500L);\n // jmsTemplate.\n String message = (String) jmsTemplate.receiveAndConvert(\"test\");\n\n // call web service here and depends on web service\n // response\n // if 200 then delete msg from queue else keep msg in\n // queue\n System.out.println(message);\n\n }\n\n return new ResponseEntity(message , HttpStatus.OK);\n\n }\n\n}\n```\n\nHow Can I do That?\n\nThanks In Advance.\n\n========================================\n\nCode:\n```text\npackage com.es.jms.listener;\n\nimport javax.jms.ConnectionFactory;\nimport javax.jms.JMSException;\nimport javax.jms.Message;\nimport javax.jms.MessageListener;\nimport javax.jms.TextMessage;\n\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\nimport org.springframework.jms.listener.MessageListenerContainer;\nimport org.springframework.jms.listener.SimpleMessageListenerContainer;\n\nimport com.rabbitmq.jms.admin.RMQConnectionFactory;\n\n@Configuration\npublic class RabbitMqMessageListener {\n\n @Bean\n public ConnectionFactory jmsConnectionFactory() {\n RMQConnectionFactory connectionFactory = new RMQConnectionFactory();\n connectionFactory.setUsername(\"Username\");\n connectionFactory.setPassword(\"Password\");\n connectionFactory.setVirtualHost(\"vhostname\");\n connectionFactory.setHost(\"hostname\");\n\n return connectionFactory;\n }\n\n @Bean\n public MessageListener msgListener() {\n return new MessageListener() {\n public void onMessage(Message message) {\n\n System.out.println(message.toString());\n if (message instanceof TextMessage) {\n try {\n String msg = ((TextMessage) message).getText();\n System.out.println(\"Received message: \" + msg);\n\n // call web service here and depends on web service\n // response\n // if 200 then delete msg from queue else keep msg in\n // queue\n\n } catch (JMSException ex) {\n throw new RuntimeException(ex);\n }\n }\n\n }\n };\n }\n\n @Bean\n public MessageListenerContainer messageListenerContainer() {\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(jmsConnectionFactory());\n container.setDestinationName(\"test\");\n\n container.setMessageListener(msgListener());\n return container;\n\n }\n}\n```\n\n```text\npackage com.rabbitmq.jms.consumer.controller;\n\nimport java.util.concurrent.ExecutionException;\nimport java.util.concurrent.TimeoutException;\n\nimport javax.jms.ConnectionFactory;\n\nimport org.json.JSONException;\nimport org.json.JSONObject;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.http.HttpStatus;\nimport org.springframework.http.ResponseEntity;\nimport org.springframework.jms.JmsException;\nimport org.springframework.jms.core.JmsTemplate;\nimport org.springframework.stereotype.Controller;\nimport org.springframework.web.bind.annotation.CrossOrigin;\nimport org.springframework.web.bind.annotation.RequestMapping;\nimport org.springframework.web.bind.annotation.RequestMethod;\nimport org.springframework.web.bind.annotation.ResponseBody;\n\n\nimport com.rabbitmq.jms.admin.RMQConnectionFactory;\n\nimport redis.clients.jedis.Jedis;\n\n@Controller\npublic class ReceiverController {\n @Autowired\n JmsTemplate jmsTemplate;\n\n\n @Bean\n public ConnectionFactory jmsConnectionFactory() {\n RMQConnectionFactory connectionFactory = new RMQConnectionFactory();\n connectionFactory.setUsername(\"Username\");\n connectionFactory.setPassword(\"Password\");\n connectionFactory.setVirtualHost(\"vhostname\");\n connectionFactory.setHost(\"hostname\");\n\n return connectionFactory;\n }\n\n @CrossOrigin\n @SuppressWarnings({ \"unchecked\", \"rawtypes\" })\n @RequestMapping(method = RequestMethod.GET, value = \"/getdata\")\n @ResponseBody\n public ResponseEntity<String> fecthDataFromRedis()\n throws JSONException, InterruptedException, JmsException, ExecutionException, TimeoutException {\n System.out.println(\"in controller\");\n\n jmsTemplate.setReceiveTimeout(500L);\n // jmsTemplate.\n String message = (String) jmsTemplate.receiveAndConvert(\"test\");\n\n // call web service here and depends on web service\n // response\n // if 200 then delete msg from queue else keep msg in\n // queue\n System.out.println(message);\n\n }\n\n return new ResponseEntity(message , HttpStatus.OK);\n\n }\n\n}\n```\n\n```text\n/**\n * Message listener container that uses the plain JMS client API's\n * {@code MessageConsumer.setMessageListener()} method to\n * create concurrent MessageConsumers for the specified listeners.\n *\n * <p>This is the simplest form of a message listener container.\n * It creates a fixed number of JMS Sessions to invoke the listener,\n * not allowing for dynamic adaptation to runtime demands. Its main\n * advantage is its low level of complexity and the minimum requirements\n * on the JMS provider: Not even the ServerSessionPool facility is required.\n *\n * <p>See the {@link AbstractMessageListenerContainer} javadoc for details\n * on acknowledge modes and transaction options. Note that this container\n * exposes standard JMS behavior for the default \"AUTO_ACKNOWLEDGE\" mode:\n * that is, automatic message acknowledgment after listener execution,\n * with no redelivery in case of a user exception thrown but potential\n * redelivery in case of the JVM dying during listener execution.\n *\n * <p>For a different style of MessageListener handling, through looped\n * {@code MessageConsumer.receive()} calls that also allow for\n * transactional reception of messages (registering them with XA transactions),\n * see {@link DefaultMessageListenerContainer}.\n ...\n```\n\n```text\nthis.jmsTemplate.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);\n```\n\n```text\nBoolean result = this.jmsTemplate.execute(session -> {\n MessageConsumer consumer = session.createConsumer(\n this.jmsTemplate.getDestinationResolver().resolveDestinationName(session, \"bar\", false));\n String result = null;\n try {\n Message received = consumer.receive(5000);\n if (received != null) {\n result = (String) this.jmsTemplate.getMessageConverter().fromMessage(received);\n\n // Do some stuff here.\n\n received.acknowledge();\n return true;\n }\n }\n catch (Exception e) {\n return false;\n }\n finally {\n consumer.close();\n }\n}, true);\n```\n\n```text\nJmsTemplate\n```\n\n```text\nSimpleMessageListenerContainer\n```\n\n```text\nexecute\n```\n\n```text\nSessionCallback\n```\n\n```text\nSimpleMessageListenerContainer\n```\n\n```text\nsessionAcknowledgeMode\n```\n\n```text\nSession.CLIENT_ACKNOWLEDGE\n```\n\n```text\nJmsTemplate\n```\n\n```text\nexecute\n```\n\n```text\nSessionCallback\n```\n\n========================================\n\nComments:\n- As I said, you have to use the `execute` method - I added an example.\n- Thanks for sharing code. But I want call web service with the message which will consumed from queue. In your code the \"String value\" which is output I will unable to access inside . If I take it outside and process on it till message will be acknowledge and delete from queue.\n- I don't understand your concern; you can call your web service where I say `// Do some stuff here`. You can return whatever you want; I just happened to return the value to the outer code. I have changed the example to return a boolean instead - perhaps that makes it clearer. If you throw an exception, it will return false and the message won't be acknowledged.\n- Thanks for sharing the code. This solved the problem, I have been working for all day yesterday. The other alternative for me which worked was to create a new connection and a message consumer and enable client_ack on the connection but your solution makes it possible to use jmsTemplate for consuming a message in client_ack. Regards.","metadata":{"transformedAt":"2026-08-18T18:33:20.186Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":15,"totalLines":403,"estimatedTokens":3101}}730{"id":"stack-28351469","source":"stackoverflow","questionId":28351469,"title":"Routing messages in RabbitMQ topic exchange that do NOT match a pattern","tags":["rabbitmq","amqp","mq","bunny"],"text":"Title: Routing messages in RabbitMQ topic exchange that do NOT match a pattern\nTags: rabbitmq, amqp, mq, bunny\nSource: Stack Overflow\n\nQuestion:\nTwo queues are bound to a topic exchange with the following routing keys:\n\nQueue A, bound with routing key pattern match `*.foo`\n\nQueue B, bound with routing key pattern match `*.bar`\n\nI'd like to add a third queue to this exchange that receives messages that are neither `foo` messages nor `bar` messages. If I bind this queue with a `#` routing key, I naturally get all messages I need, but including `foo`'s and `bar`'s which I don't want.\n\nAny way to route messages patching a pattern `NOT *.foo` AND `NOT *.bar` ?\n\n========================================\n\nCode:\n```text\n*.foo\n```\n\n```text\n*.bar\n```\n\n```text\nfoo\n```\n\n```text\nbar\n```\n\n```text\n#\n```\n\n```text\nfoo\n```\n\n```text\nbar\n```\n\n```text\nNOT *.foo\n```\n\n```text\nNOT *.bar\n```\n\n```text\nstandard workflow --> [main exchange (topic)]\n | --> via binding *.foo --> [foo queue]\n | --> via binding *.bar --> [bar queue]\n v \n [alternate exchange (let it be topic too)]\n --> via binding * --> []\n```\n\n========================================\n\nComments:\n- I recommend *not* using an AE because adding a new binding (ie. an observer with '#') will prevent the AE/fallback from working. This is something that can happen in real life and make things go sideways *really* fast with unexpected interactions.","metadata":{"transformedAt":"2026-08-18T18:33:20.186Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":10,"totalLines":67,"estimatedTokens":375}}731{"id":"stack-41302117","source":"stackoverflow","questionId":41302117,"title":"How do I set up a simple dockerized RabbitMQ cluster?","tags":["docker","rabbitmq","cluster-computing","ubuntu-16.04"],"text":"Title: How do I set up a simple dockerized RabbitMQ cluster?\nTags: docker, rabbitmq, cluster-computing, ubuntu-16.04\nSource: Stack Overflow\n\nQuestion:\nI've been doing a bit of reading up about setting up a dockerized RabbitMQ cluster and google turns up all sorts of results for doing so on the same machine.\n\nI am trying to set up a RabbitMQ cluster across multiple machines.\n\nI have three machines with the names `dockerswarmmodemaster1`, `dockerswarmmodemaster2` and `dockerswarmmodemaster3`\n\nOn the first machine (dockerswarmmodemaster1), I issue the following command:\n\n```\ndocker run -d -p 4369:4369 -p 5671:5671 -p 5672:5672 -p 15671:15671 -p 15672:15672 \\\n -p 25672:25672 --hostname dockerswarmmodemaster1 --name roger_rabbit \\\n -e RABBITMQ_ERLANG_COOKIE='secret cookie here' rabbitmq:3-management\n```\n\nNow this starts up a rabbitMQ just fine, and I can go to the admin page on 15672 and see that it is working as expected.\n\nI then SSH to my second machine (dockerswarmmodemaster2) and this is the bit I am stuck on. I have been trying variations on the following command:\n\n```\ndocker run -d -p 4369:4369 -p 5671:5671 -p 5672:5672 -p 15671:15671 \\\n -p 15672:15672 -p 25672:25672 --name jessica_rabbit -e CLUSTERED=true \\\n -e CLUSTER_WITH=rabbit@dockerswarmmodemaster1 \\\n -e RABBITMQ_ERLANG_COOKIE='secret cookie here' \\\n rabbitmq:3-management\n```\n\nNo matter what I try, the web page on both RabbitMQ machines says that there is no cluster under the 'cluster links' section. I haven't tried involving the third machine yet.\n\nSo - some more info:\n\n- The machine names are resolvable by DNS.\n\n- I have tried using the --net=host switch in the docker run command on both machines; no change.\n\n- I am not using docker swarm or swarm mode.\n\n- I do not have docker compose installed. I'd prefer not to use it if possible.\n\nIs there any way of doing this from the docker run command or will I have to download the rabbit admin cli and manually join to the cluster?\n\n========================================\n\nTop Answer:\nIn order to create a cluster, all rabbitmq nodes that are to form up a cluster must be accessible (each one by others) by node name (hostname).\nYou need to specify a hostname for each docker container with `--hostname` option and to add /etc/host entries for all the other containers, this you can do with `--add-host` option or by manually editing /etc/hosts file.\nSo, here is the example for a 3 rabbitmq nodes cluster with docker containers (rabbitmq:3-management image).\n\nFirst, create a network so that you can assign IPs: `docker network create --subnet=172.18.0.0/16 mynet1`. We are going to have the following:\n\n- 3 docker containers named rab1con, rab2con and rab3con\n\n- IPs respectively will be 172.18.0.11 , -12 and -13\n\n- each of them will have the host name respectively rab1, rab2 and rab3\n\n- all of them must the same erlang cookie\n\nSpin up the first one\n\n```\ndocker run -d --net mynet1 --ip 172.18.0.11 --hostname rab1 --add-host rab2:172.18.0.12 --add-host rab3:172.18.0.13 --name rab1con -e RABBITMQ_ERLANG_COOKIE='secret cookie here' rabbitmq:3-management\n```\n\nsecond one\n\n```\ndocker run -d --net mynet1 --ip 172.18.0.12 --hostname rab2 --add-host rab1:172.18.0.11 --add-host rab3:172.18.0.13 --name rab2con -e RABBITMQ_ERLANG_COOKIE='secret cookie here' rabbitmq:3-management\n```\n\nlast one\n\n```\ndocker run -d --net mynet1 --ip 172.18.0.13 --hostname rab3 --add-host rab2:172.18.0.12 --add-host rab1:172.18.0.11 --name rab3con -e RABBITMQ_ERLANG_COOKIE='secret cookie here' rabbitmq:3-management\n```\n\nThen, in container rab2con, do\n\n```\nrabbitmqctl stop_app\nrabbitmqctl join_cluster rabbit@rab1\nrabbitmqctl start_app\n```\n\nand the same in rab3con and that's it.\n\n========================================\n\nCode:\n```text\ndocker run -d -p 4369:4369 -p 5671:5671 -p 5672:5672 -p 15671:15671 -p 15672:15672 \\\n -p 25672:25672 --hostname dockerswarmmodemaster1 --name roger_rabbit \\\n -e RABBITMQ_ERLANG_COOKIE='secret cookie here' rabbitmq:3-management\n```\n\n```text\ndocker run -d -p 4369:4369 -p 5671:5671 -p 5672:5672 -p 15671:15671 \\\n -p 15672:15672 -p 25672:25672 --name jessica_rabbit -e CLUSTERED=true \\\n -e CLUSTER_WITH=rabbit@dockerswarmmodemaster1 \\\n -e RABBITMQ_ERLANG_COOKIE='secret cookie here' \\\n rabbitmq:3-management\n```\n\n```text\ndockerswarmmodemaster1\n```\n\n```text\ndockerswarmmodemaster2\n```\n\n```text\ndockerswarmmodemaster3\n```\n\n```text\netcd2\n```\n\n```text\nconsul\n```\n\n```text\nrabbitmqctl\n```\n\n```text\n[ \n { rabbit, [ \n { loopback_users, [ ] }, \n { cluster_nodes, {['rabbit@dockerswarmmodemaster1'], disc }} \n ]} \n].\n```\n\n```text\n[rabbitmq_management].\n```\n\n```text\ndocker run -d -p 4369:4369 -p 5671:5671 -p 5672:5672 -p 15671:15671 \\\n-p 15672:15672 -p 25672:25672 --name jessica_rabbit \\\n-v /home/user/rmq:/etc/rabbmitmq \\\n-e RABBITMQ_ERLANG_COOKIE='secret cookie here' \\\nrabbitmq:3-management\n```\n\n```text\nCLUSTERED\n```\n\n```text\nCLUSTER_WITH\n```\n\n```text\n/home/user/rmq/rabbitmq.config\n```\n\n```text\n/home/user/rmq/enabled_plugins\n```\n\n```text\ndocker run -d --net mynet1 --ip 172.18.0.11 --hostname rab1 --add-host rab2:172.18.0.12 --add-host rab3:172.18.0.13 --name rab1con -e RABBITMQ_ERLANG_COOKIE='secret cookie here' rabbitmq:3-management\n```\n\n```text\ndocker run -d --net mynet1 --ip 172.18.0.12 --hostname rab2 --add-host rab1:172.18.0.11 --add-host rab3:172.18.0.13 --name rab2con -e RABBITMQ_ERLANG_COOKIE='secret cookie here' rabbitmq:3-management\n```\n\n```text\ndocker run -d --net mynet1 --ip 172.18.0.13 --hostname rab3 --add-host rab2:172.18.0.12 --add-host rab1:172.18.0.11 --name rab3con -e RABBITMQ_ERLANG_COOKIE='secret cookie here' rabbitmq:3-management\n```\n\n```text\nrabbitmqctl stop_app\nrabbitmqctl join_cluster rabbit@rab1\nrabbitmqctl start_app\n```\n\n```text\n--hostname\n```\n\n```text\n--add-host\n```\n\n```text\ndocker network create --subnet=172.18.0.0/16 mynet1\n```\n\n```text\nservices:\n stats:\n image: bitnami/rabbitmq\n environment:\n - RABBITMQ_NODE_TYPE=stats\n - RABBITMQ_NODE_NAME=rabbit@stats\n - RABBITMQ_ERL_COOKIE=s3cr3tc00ki3\n ports:\n - '15672:15672'\n volumes:\n - 'rabbitmqstats_data:/bitnami/rabbitmq/mnesia'\n\n queue-disc1:\n image: bitnami/rabbitmq\n environment:\n - RABBITMQ_NODE_TYPE=queue-disc\n - RABBITMQ_NODE_NAME=rabbit@queue-disc1\n - RABBITMQ_CLUSTER_NODE_NAME=rabbit@stats\n - RABBITMQ_ERL_COOKIE=s3cr3tc00ki3\n volumes:\n - 'rabbitmqdisc1_data:/bitnami/rabbitmq/mnesia'\n\n queue-ram1:\n image: bitnami/rabbitmq\n environment:\n - RABBITMQ_NODE_TYPE=queue-ram\n - RABBITMQ_NODE_NAME=rabbit@queue-ram1\n - RABBITMQ_CLUSTER_NODE_NAME=rabbit@stats\n - RABBITMQ_ERL_COOKIE=s3cr3tc00ki3\n volumes:\n - 'rabbitmqram1_data:/bitnami/rabbitmq/mnesia'\n\nvolumes:\n rabbitmqstats_data:\n driver: local\n rabbitmqdisc1_data:\n driver: local\n rabbitmqram1_data:\n driver: local\n```\n\n========================================\n\nComments:\n- All node types except DISK nodes are deprecated: rabbitmq.com/blog/2021/08/21/4.0-deprecation-announcement","metadata":{"transformedAt":"2026-08-18T18:33:20.186Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":23,"totalLines":244,"estimatedTokens":1759}}732{"id":"stack-48956267","source":"stackoverflow","questionId":48956267,"title":"RabbitMQ - Multiple instances reading from the same Topic","tags":["python","apache-kafka","rabbitmq"],"text":"Title: RabbitMQ - Multiple instances reading from the same Topic\nTags: python, apache-kafka, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have multiple producers from different applications sending messages to topics in RabbitMQ. And multiple consumers from different applications reading those topics. This simple architecture have been working perfectly as a PoC.\nBut now I have multiple instances from those applications and I don't want app X instance 1 reading the same message as app X instance 2. However app X and app Y (with all their instances) need to red from the same topic. \n\nI know Karaf balances the consumption of Messages from topics if the consumers the same consumer ID. This feature exists in RabbitMQ? I've been reading the docs and I don't find nothing like this.\n\n========================================\n\nCode:\n```text\n#!/usr/bin/env python\n\nimport pika\nimport sys\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost'))\nchannel = connection.channel()\n\nchannel.exchange_declare(exchange='topic_logs',\n type='topic')\n\nqueue_name = sys.argv[1]\nchannel.queue_declare(queue=queue_name)\n\nchannel.queue_bind(exchange='topic_logs',\n queue=queue_name,\n routing_key='my_key')\n\nprint ' [*] Waiting for logs. To exit press CTRL+C'\n\ndef callback(ch, method, properties, body):\n print \" [x] %r:%r\" % (method.routing_key, body,)\n ch.basic_ack(delivery_tag = method.delivery_tag)\n\nchannel.basic_qos(prefetch_count=1)\nchannel.basic_consume(callback,\n queue=queue_name)\n\nchannel.start_consuming()\n```\n\n```text\n#!/usr/bin/env python\n\nimport pika\nimport sys\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost'))\nchannel = connection.channel()\n\nchannel.exchange_declare(exchange='topic_logs',\n type='topic')\n\nrouting_key = 'my_key'\nmessage = 'Hello World!'\nchannel.basic_publish(exchange='topic_logs',\n routing_key=routing_key,\n body=message)\nprint \" [x] Sent %r:%r\" % (routing_key, message)\nconnection.close()\n```\n\n```text\npython receive.py consumer_group1\npython receive.py consumer_group1\npython receive.py consumer_group2\npython receive.py consumer_group2\n```\n\n```text\npython send.py\n```\n\n```text\nTopics\n```\n\n```text\nWork queues\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.186Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":86,"estimatedTokens":590}}733{"id":"stack-42054079","source":"stackoverflow","questionId":42054079,"title":"RabbitMQ Consumer always directly shutsdown (C#)","tags":["c#","rabbitmq"],"text":"Title: RabbitMQ Consumer always directly shutsdown (C#)\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nAt The moment im learning how to work with the RabbitMQ.\nSending works. But Recieving doesn't work. This is my code:\n\n```\nvar factory = new ConnectionFactory() { HostName = hostName };\n using (var connection = factory.CreateConnection())\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(queue: queueName,\n durable: false,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n var consumer = new EventingBasicConsumer(channel);\n consumer.Received += (model, ea) =>\n {\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n Console.WriteLine(\"Recieved: {0}\", message);\n };\n consumer.Shutdown += (o, e) =>\n {\n Console.WriteLine(\"Error with RabbitMQ: {0}\", e.Cause);\n createConnection(hostName, queueName);\n };\n channel.BasicConsume(queueName, true, consumer);\n }\n```\n\nThis is copied from the Tutorial. If I start the Application, consumer.Shutdown is directly called and I get: \n\n```\n{AMQP close-reason, initiated by Application, code=200, text=\"Goodbye\", classId=0, methodId=0, cause=}\n```\n\nCan anyone help me?\n\n========================================\n\nCode:\n```text\nvar factory = new ConnectionFactory() { HostName = hostName };\n using (var connection = factory.CreateConnection())\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(queue: queueName,\n durable: false,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n var consumer = new EventingBasicConsumer(channel);\n consumer.Received += (model, ea) =>\n {\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n Console.WriteLine(\"Recieved: {0}\", message);\n };\n consumer.Shutdown += (o, e) =>\n {\n Console.WriteLine(\"Error with RabbitMQ: {0}\", e.Cause);\n createConnection(hostName, queueName);\n };\n channel.BasicConsume(queueName, true, consumer);\n }\n```\n\n```text\n{AMQP close-reason, initiated by Application, code=200, text=\"Goodbye\", classId=0, methodId=0, cause=}\n```\n\n```text\nchannel.BasicConsume\n```\n\n```text\nusing\n```\n\n```text\nConsole.ReadLine\n```\n\n```text\nchannel.BasicConsume\n```\n\n========================================\n\nComments:\n- Is it a console app?\n- Wow, so easy but how can I prevent the connection from disposing without Console.ReadLine?\n- Well you dispose it yourself in your example. Just don't use \"using\" block. Instead, dispose it explicitly when needed (for example, if that is asp.net application - dispose it on application shutdown).\n- Okay, thank you. I'm new to c# and RabbitMQ and will never do this again :)","metadata":{"transformedAt":"2026-08-18T18:33:20.186Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":98,"estimatedTokens":725}}734{"id":"stack-56064182","source":"stackoverflow","questionId":56064182,"title":"Why a simple configuration in MassTransit creates 2 queues and 3 exchanges?","tags":["c#",".net-core","rabbitmq","masstransit"],"text":"Title: Why a simple configuration in MassTransit creates 2 queues and 3 exchanges?\nTags: c#, .net-core, rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nI created a MassTransit quickstart program to interact with my localhost RabbitMQ:\n\n```\nnamespace ConsoleApp1\n{\n public static class Program\n {\n public class YourMessage\n {\n public string Text { get; set; }\n }\n\n public static async Task Main(params string[] args)\n {\n var bus = Bus.Factory.CreateUsingRabbitMq(sbc =>\n {\n var host = sbc.Host(new Uri(\"rabbitmq://localhost\"), h =>\n {\n h.Username(\"guest\");\n h.Password(\"guest\");\n });\n\n sbc.ReceiveEndpoint(host, \"test_queue\", ep =>\n {\n ep.Handler(async context => await Console.Out.WriteLineAsync($\"Received: {context.Message.Text}\"));\n });\n });\n\n await bus.StartAsync(); \n await bus.Publish(new YourMessage{Text = \"Hi\"});\n Console.WriteLine(\"Press any key to exit\");\n Console.ReadKey();\n await bus.StopAsync();\n }\n }\n}\n```\n\nEverything looked fine untill I actually checked the underlying RabbitMQ management and found out that just for this very simple program, MassTransit created 3 exchanges and 2 queues.\n\nExchanges, all fanouts:\n\n- `ConsoleApp1:Program-YourMessage`: Durable\n\n- `VP0003748_dotnet_bus_6n9oyyfzxhyx9ybobdmpj8qeyt`: Auto-delete and Durable?\n\n- `test_queue`: Durable\n\nQueues:\n\n- `VP0003748_dotnet_bus_6n9oyyfzxhyx9ybobdmpj8qeyt`: x-expire 60000\n\n- `test_queue`: Durable\n\nI would like to know why all of that is necessary or is the default configuration? In particular, I am not really sure to get the point of creating so \"many\".\n\n========================================\n\nCode:\n```text\nnamespace ConsoleApp1\n{\n public static class Program\n {\n public class YourMessage\n {\n public string Text { get; set; }\n }\n\n public static async Task Main(params string[] args)\n {\n var bus = Bus.Factory.CreateUsingRabbitMq(sbc =>\n {\n var host = sbc.Host(new Uri(\"rabbitmq://localhost\"), h =>\n {\n h.Username(\"guest\");\n h.Password(\"guest\");\n });\n\n sbc.ReceiveEndpoint(host, \"test_queue\", ep =>\n {\n ep.Handler<YourMessage>(async context => await Console.Out.WriteLineAsync($\"Received: {context.Message.Text}\"));\n });\n });\n\n await bus.StartAsync(); \n await bus.Publish(new YourMessage{Text = \"Hi\"});\n Console.WriteLine(\"Press any key to exit\");\n Console.ReadKey();\n await bus.StopAsync();\n }\n }\n}\n```\n\n```text\nConsoleApp1:Program-YourMessage\n```\n\n```text\nVP0003748_dotnet_bus_6n9oyyfzxhyx9ybobdmpj8qeyt\n```\n\n```text\ntest_queue\n```\n\n```text\nVP0003748_dotnet_bus_6n9oyyfzxhyx9ybobdmpj8qeyt\n```\n\n```text\ntest_queue\n```\n\n```text\nConsoleApp1:Program-YourMessage\n```\n\n```text\ntest_queue\n```\n\n```text\ntest_queue\n```\n\n========================================\n\nComments:\n- Which version of MassTransit do you use? This issue is reproducible with version 5.5.6, but version 6.0.0 does not create unused auto-delete exchange and queue. As for now, cannot locate commit when it has been fixed (github.com/MassTransit/MassTransit/releases/tag/v6.0.0)\n- @PylypLebediev I believed that back then it was version 5.5.5.\n- I can't find that information in the documentation, can I prevent the creation of the non durable queue and exchange? I mean if we don't use the request-response but just regular publishing? Also it is an issue to have the same exchange name for different .NET types?\n- I don't think so, but what is exactly the issue with having them?\n- just would like a way either to change their name with something more explicit or to avoid their creation. I mean if we don't use that feature of RabbitMQ, what's the point of having them?\n- Name of message queues can be changed by using sbc.OverrideDefaultBusEndpointQueueName(\"endpoint\"); method of IRabbitMqBusFactoryConfigurator\n- The link is broken in the answer, but I cannot edit it because there are too many pending edits. Current link (MassTransit v8): masstransit.io/documentation/configuration/transports/…","metadata":{"transformedAt":"2026-08-18T18:33:20.186Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":9,"totalLines":142,"estimatedTokens":1043}}735{"id":"stack-64246648","source":"stackoverflow","questionId":64246648,"title":"Install extra rabbitmq plugin from github using bitnami/rabbitmq chart","tags":["kubernetes","rabbitmq","kubernetes-helm","bitnami"],"text":"Title: Install extra rabbitmq plugin from github using bitnami/rabbitmq chart\nTags: kubernetes, rabbitmq, kubernetes-helm, bitnami\nSource: Stack Overflow\n\nQuestion:\n**Goal**: Prepare a `values.yaml` file for the rabbitmq chart provided by bitnami, such that the plugin rabbitmq-message-deduplication is ready and available after running `helm install ...`\n\n**Previous solution**: Currently, I am using the `stable/rabbitmq-ha` chart with the following `values.yaml`:\n\n```\nextraPlugins: \"rabbitmq_message_deduplication\"\n\nextraInitContainers:\n - name: download-plugins\n image: busybox\n command: [\"/bin/sh\",\"-c\"]\n args: [\"\n wget\n -O /opt/rabbitmq/plugins/elixir-1.8.2.ez/elixir-1.8.2.ez\n https://github.com/noxdafox/rabbitmq-message-deduplication/releases/download/0.4.5/elixir-1.8.2.ez\n --no-check-certificate\n ;\n wget\n -O /opt/rabbitmq/plugins/rabbitmq_message_deduplication-v3.8.4.ez/rabbitmq_message_deduplication-v3.8.4.ez\n https://github.com/noxdafox/rabbitmq-message-deduplication/releases/download/0.4.5/rabbitmq_message_deduplication-v3.8.x_0.4.5.ez\n --no-check-certificate\n \"]\n volumeMounts:\n # elixir is a dependency of the deduplication plugin\n - name: elixir\n mountPath: /opt/rabbitmq/plugins/elixir-1.8.2.ez\n - name: deduplication-plugin\n mountPath: /opt/rabbitmq/plugins/rabbitmq_message_deduplication-v3.8.4.ez\n\nextraVolumes:\n - name: elixir\n emptyDir: {}\n - name: deduplication-plugin\n emptyDir: {}\n\nextraVolumeMounts:\n - name: elixir\n mountPath: /opt/rabbitmq/plugins/elixir-1.8.2.ez\n subPath: elixir-1.8.2.ez\n - name: deduplication-plugin\n mountPath: /opt/rabbitmq/plugins/rabbitmq_message_deduplication-v3.8.4.ez\n subPath: rabbitmq_message_deduplication-v3.8.4.ez\n```\n\nThis works A-OK. However, `stable/rabbitmq-ha` is going to disappear next month and so I'm migrating to `bitnami/rabbitmq`.\n\n**Problem**: `bitnami/rabbitmq` expects `values.yaml` in a different format and I can't for the life of me figure out how I should set up a new `values.yaml` file to achieve the same result. I've tried messing around with `command`, `args` and `initContainers` but I just can't get it done...\n\nP.S. I have a cluster running locally using minikube. I don't believe this is relevant, but putting this here just in case.\n\n**UPDATE:** Francisco's answer really helped. Somehow I missed that part of the documentation.\n\nMy new `.yaml` looks like this:\n\n```\ncommunityPlugins: \"https://github.com/noxdafox/rabbitmq-message-deduplication/releases/download/0.4.5/elixir-1.8.2.ez https://github.com/noxdafox/rabbitmq-message-deduplication/releases/download/0.4.5/rabbitmq_message_deduplication-v3.8.x_0.4.5.ez\"\n\nextraPlugins: \"rabbitmq_message_deduplication\"\n```\n\nIt gets the plugin working just like I wanted, and with much less configuration. Good stuff.\n\n========================================\n\nTop Answer:\nI had to make a slight change from Franciso De Paz Galan's post to fetch both of the ez files in the communityPlugins.\n\nBoth urls need to be as string with space delimited.\n\n```\n# Add the dedup community plugin\ncommunityPlugins: \n \"https://github.com/noxdafox/rabbitmq-message-deduplication/releases/download/0.6.2/elixir-1.14.0.ez https://github.com/noxdafox/rabbitmq-message-deduplication/releases/download/0.6.2/rabbitmq_message_deduplication-0.6.2.ez\"\nextraPlugins: \"elixir rabbitmq_message_deduplication\"\n```\n\n========================================\n\nCode:\n```yaml\nextraPlugins: \"rabbitmq_message_deduplication\"\n\nextraInitContainers:\n - name: download-plugins\n image: busybox\n command: [\"/bin/sh\",\"-c\"]\n args: [\"\n wget\n -O /opt/rabbitmq/plugins/elixir-1.8.2.ez/elixir-1.8.2.ez\n https://github.com/noxdafox/rabbitmq-message-deduplication/releases/download/0.4.5/elixir-1.8.2.ez\n --no-check-certificate\n ;\n wget\n -O /opt/rabbitmq/plugins/rabbitmq_message_deduplication-v3.8.4.ez/rabbitmq_message_deduplication-v3.8.4.ez\n https://github.com/noxdafox/rabbitmq-message-deduplication/releases/download/0.4.5/rabbitmq_message_deduplication-v3.8.x_0.4.5.ez\n --no-check-certificate\n \"]\n volumeMounts:\n # elixir is a dependency of the deduplication plugin\n - name: elixir\n mountPath: /opt/rabbitmq/plugins/elixir-1.8.2.ez\n - name: deduplication-plugin\n mountPath: /opt/rabbitmq/plugins/rabbitmq_message_deduplication-v3.8.4.ez\n\nextraVolumes:\n - name: elixir\n emptyDir: {}\n - name: deduplication-plugin\n emptyDir: {}\n\nextraVolumeMounts:\n - name: elixir\n mountPath: /opt/rabbitmq/plugins/elixir-1.8.2.ez\n subPath: elixir-1.8.2.ez\n - name: deduplication-plugin\n mountPath: /opt/rabbitmq/plugins/rabbitmq_message_deduplication-v3.8.4.ez\n subPath: rabbitmq_message_deduplication-v3.8.4.ez\n```\n\n```yaml\ncommunityPlugins: \"https://github.com/noxdafox/rabbitmq-message-deduplication/releases/download/0.4.5/elixir-1.8.2.ez https://github.com/noxdafox/rabbitmq-message-deduplication/releases/download/0.4.5/rabbitmq_message_deduplication-v3.8.x_0.4.5.ez\"\n\nextraPlugins: \"rabbitmq_message_deduplication\"\n```\n\n```text\nvalues.yaml\n```\n\n```text\nhelm install ...\n```\n\n```text\nstable/rabbitmq-ha\n```\n\n```text\nvalues.yaml\n```\n\n```text\nstable/rabbitmq-ha\n```\n\n```text\nbitnami/rabbitmq\n```\n\n```text\nbitnami/rabbitmq\n```\n\n```text\nvalues.yaml\n```\n\n```text\nvalues.yaml\n```\n\n```text\ncommand\n```\n\n```text\nargs\n```\n\n```text\ninitContainers\n```\n\n```text\n.yaml\n```\n\n```yaml\ncommunityPlugins: \"https://github.com/noxdafox/rabbitmq-message-deduplication/releases/download/0.4.5/elixir-1.8.2.ez\"\n\nextraPlugins: \"rabbitmq_auth_backend_ldap elixir\"\n```\n\n```text\ncommunityPlugins\n```\n\n```text\nextraPlugins\n```\n\n```text\nelixir\n```\n\n```text\nvalues.yaml\n```\n\n```text\n# Add the dedup community plugin\ncommunityPlugins: \n \"https://github.com/noxdafox/rabbitmq-message-deduplication/releases/download/0.6.2/elixir-1.14.0.ez https://github.com/noxdafox/rabbitmq-message-deduplication/releases/download/0.6.2/rabbitmq_message_deduplication-0.6.2.ez\"\nextraPlugins: \"elixir rabbitmq_message_deduplication\"\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.186Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":21,"totalLines":210,"estimatedTokens":1504}}736{"id":"stack-46834629","source":"stackoverflow","questionId":46834629,"title":"Balance RabbitMQ master queues across nodes","tags":["rabbitmq","load-balancing"],"text":"Title: Balance RabbitMQ master queues across nodes\nTags: rabbitmq, load-balancing\nSource: Stack Overflow\n\nQuestion:\nI have a cluster of 3 RabbitMQ nodes and I want to keep master queues balanced across all nodes, even after node reboots. Still, master queues don't rebalance when a new node joins the cluster or when one of the nodes disconnects and reconnects.\n\nExample: I create 100 queues on nodes A, B and C.\nIf node C shutdowns, master queues from C are almost equally rebalanced between node A and B. So at this point, nodes A and B have both approximately 50 master queues.\n\nNow, if I reconnect node C, it'll remain with 0 master queues until new queues are created. This is problematic because I want all my nodes to produce the same amount of work.\n\nMy exchanges are durables, my queues are durables and mirrored and my messages are persistent. I want to avoid loosing messages.\n\nI know there is a way to change the master node manually using a policy trick. But this is not satisfying since it breaks HA (by inducing a resynchronisations of all mirrors).\n\n========================================\n\nTop Answer:\nOne solution is to use Federated Queues. \n\n A federated queue links to other queues (called upstream queues). It will retrieve messages from upstream queues in order to satisfy demand for messages from local consumers.\n\nYou can create a completely new cluster which is both upstream and downstream from the original cluster. You also need to ensure that both your publishers and consumers reconnects periodically (to avoid one cluster to monopolize all connections, defeating load-balancing).\n\nAs you pointed out, there's also Simon MacMullen's trick from `rabbitmq-users` group.\n\n```\n# rabbitmqctl set_policy --apply-to queues --priority 100 my-queue '^my-queue$' '{\"ha-mode\":\"nodes\", \"ha-params\":[\"rabbit@master-node\"]}'\n# rabbitmqctl clear_policy my-queue\n```\n\nBut it has the underdesirable side-effect to make mirrors loose synchronisation for a while. This might be acceptable or not, depending on your requirements, so I think it's worth saying it's possible.\n\nMore advanced technique might come up in 4.x, but it is not sure at all.\n\n========================================\n\nCode:\n```text\nrabbitmq-queues rebalance type --vhost-pattern pattern --queue-pattern pattern\n```\n\n```text\nrabbitmq-queues rebalance \"all\" --vhost-pattern \"a-vhost\" --queue-pattern \".*\"\n```\n\n```text\n# rabbitmqctl set_policy --apply-to queues --priority 100 my-queue '^my-queue$' '{\"ha-mode\":\"nodes\", \"ha-params\":[\"rabbit@master-node\"]}'\n# rabbitmqctl clear_policy my-queue\n```\n\n```text\nrabbitmq-users\n```\n\n========================================\n\nComments:\n- `queue-master-locator` strategy ; Michael Klishin's hint for improvements in 4.x (sorry, had to post this as a separate comment since I lack reputation to post more than 2 links per answer)\n- Simon MacMullen's trick is not 100%HA because while you are doing it, there is a moment your queue is not mirrored anymore, wich mean at this exact moment you can completely loose your queue. Also, synchronizing freeze the queue while doing it (if I understood the function correctly), wich is pretty bad if this happen at the wrong moment. And about Feredation... Considering you constantly move messages from one node-queue couple to another node-queue couple, this doesn't really reduce the charge on one node, and instead use even more CPU since the 2nd node now work more !\n- You are right and understood correctly. I totally understand you knew the trick but cannot use it (I wouldn't recommend it in most cases). About federated queues, you are also kind of right. As stated in the docs, it works better if you have some sort of locality. Yet, since messages might come up on one side or the other, load is balanced and slightly lowered per node. To leverage the locality, you may publish messages in a round-robin style, and consume them from both clusters. This way, locality is insured, and load is almost perfectly balanced. You keep federation only for edge-cases.\n- However, I really doubt that queues syncs produce the freeze you describe. Do you have any reference for this? I think you just have to ensure that the slave queue is fully synchronized with the master queue when you switch. And as soon as you switch, the new slave (former master) will have to resychronize (which basically means that every message that was in the queue when switching will have to be consumed). If you loose the new master before having consumed all messages, unsychronized messages will be lost. This is a shorthand to adding new nodes to the cluster and destroying the old ones.\n- rabbitmq.com/ha.html \"Since the queue becomes unresponsive while explicit synchronisation is occurring, it is preferable to allow active queues from which messages are being drained to synchronise naturally, and only explicitly synchronise inactive queues.\" My comprehension of the following doc is that, while synchronizing, both master and host are not available.\n- Unlike `sync_queue`, applying a policy to a queue is not an \"explicit synchronisation request\". Explicit synchronisation will indeed force both queues to be in sync (which is only possible by locking the master and thus breaking availability). However, applying the policy will only make the queue loose synchronisation, not force them to be in sync again. Consequently, as stated in doc, queues will naturally sync themselves over time without being unavailable. The only risk is to loose a master node before the two queues are completely in sync. In this case, unsynced messages are lost.\n- Yeah exactly, that's what I understood from the doc and all topics I read. Thanks for your feedback tho. The problem is that I would like to find a 100% HA solution if possible. But this could indeed do the trick, i just don't like to \"believe\" and hope that things won't go from bad to worse in a professionnal environnement.\n- Yup. To sum it up, if no trade off on HA or performance are possible, multi-cluster + federated queues + random publishers + multiple-consumers would be the solution I'd choose.","metadata":{"transformedAt":"2026-08-18T18:33:20.186Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":67,"estimatedTokens":1526}}737{"id":"stack-40184003","source":"stackoverflow","questionId":40184003,"title":"How to use interceptor with Spring AMQP","tags":["spring","spring-boot","rabbitmq","spring-amqp"],"text":"Title: How to use interceptor with Spring AMQP\nTags: spring, spring-boot, rabbitmq, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nIs there a way to intercept messages once template.convertAndSend is called, before the message is delivered to RabbitMQ.\n\nAlso any way to intercept the message before reaching the handler?\n\nI can handle the message using PostProcessor for publisher, but prefer to use interceptor.\n\n```\npublic class TestPostProcessor implements MessagePostProcessor {\n\n @Autowired\n Tracer defaultTracer;\n\n @Override\n public Message postProcessMessage(Message message) throws AmqpException {\n //.....\n //.... \n return message;\n }\n}\n```\n\nAny suggestions?\n\n========================================\n\nTop Answer:\nIf you want to keep using spring boot properties (from org.springframework.boot.autoconfigure.amqp.RabbitProperties) in your application.properties file, you can provide your own RabbitListenerContainerFactory :\n\n```\n@Bean\n public CustomRabbitListenerContainerFactory rabbitListenerContainerFactory(\n SimpleRabbitListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory, MyContextMessageProcessor messageProcessor) {\n CustomRabbitListenerContainerFactory factory = new CustomRabbitListenerContainerFactory(messageProcessor);\n configurer.configure(factory, connectionFactory);\n return factory;\n }\n```\n\nCustomRabbitListenerContainerFactory.java :\n\n```\npublic class CustomRabbitListenerContainerFactory\n extends org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory {\n\n private MessagePostProcessor[] messagePostProcessor;\n\n public CustomRabbitListenerContainerFactory(MessagePostProcessor... messagePostProcessor) {\n super();\n this.messagePostProcessor = messagePostProcessor;\n }\n\n @Override\n protected void initializeContainer(SimpleMessageListenerContainer instance, RabbitListenerEndpoint endpoint) {\n super.initializeContainer(instance, endpoint);\n instance.addAfterReceivePostProcessors(messagePostProcessor);\n }\n}\n```\n\n========================================\n\nCode:\n```text\npublic class TestPostProcessor implements MessagePostProcessor {\n\n @Autowired\n Tracer defaultTracer;\n\n @Override\n public Message postProcessMessage(Message message) throws AmqpException {\n //.....\n //.... \n return message;\n }\n}\n```\n\n```text\nMessagePostProcessor\n```\n\n```text\nconvertAndSend()\n```\n\n```text\nRabbitTemplate\n```\n\n```text\nsetBeforePublishPostProcessors()\n```\n\n```text\nsetAfterReceivePostProcessors()\n```\n\n```text\nreceive()\n```\n\n```text\nsetAfterReceivePostProcessors()\n```\n\n```text\n@Bean\n public CustomRabbitListenerContainerFactory rabbitListenerContainerFactory(\n SimpleRabbitListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory, MyContextMessageProcessor messageProcessor) {\n CustomRabbitListenerContainerFactory factory = new CustomRabbitListenerContainerFactory(messageProcessor);\n configurer.configure(factory, connectionFactory);\n return factory;\n }\n```\n\n```text\npublic class CustomRabbitListenerContainerFactory\n extends org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory {\n\n private MessagePostProcessor[] messagePostProcessor;\n\n public CustomRabbitListenerContainerFactory(MessagePostProcessor... messagePostProcessor) {\n super();\n this.messagePostProcessor = messagePostProcessor;\n }\n\n @Override\n protected void initializeContainer(SimpleMessageListenerContainer instance, RabbitListenerEndpoint endpoint) {\n super.initializeContainer(instance, endpoint);\n instance.addAfterReceivePostProcessors(messagePostProcessor);\n }\n}\n```\n\n========================================\n\nComments:\n- `>I can handle the message using PostProcessor for publisher, but prefer to use interceptor.` Can you explain what you mean by that? The MPP **is** a form of interceptor. The listener container also supports MPPs after receiving and before delivery to the listener: `setAfterReceivePostProcessors()`.\n- To use it I had to do rabbitTemplate.convertAndSend(routingKey,\"Message\",postProce‌​ssor); - was wondering if there is a way to inject this, without us having to provide it here. Also how would we do it on SimpleMessageListenerContainer ?\n- Yes; see my answer.\n- Thank you, will try it out.\n- Even simpler solution: just autowire the framework created SimpleRabbitListenerContainerFactory (pay attention for the Direct part of the story) and call the method: setAfterReceivePostProcessors","metadata":{"transformedAt":"2026-08-18T18:33:20.186Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":147,"estimatedTokens":1121}}738{"id":"stack-14461646","source":"stackoverflow","questionId":14461646,"title":"How do I stub langohr RabbitMQ interactions in clojure?","tags":["clojure","rabbitmq","langohr"],"text":"Title: How do I stub langohr RabbitMQ interactions in clojure?\nTags: clojure, rabbitmq, langohr\nSource: Stack Overflow\n\nQuestion:\nI'm trying to stub the RabbitMQ interactions, as those aren't really the main purpose of the application I'm writing.\n\nSo, I've tried rebinding the langohr functions in my tests like so:\n\n```\n(defn stub [ch]\n (langohr.basic/ack ch 1))\n\n(deftest test-stub\n (with-redefs [langohr.basic/ack (fn [a1 a2] true)]\n (is (= true (stub \"dummy\")))))\n```\n\nWhen I run the test with `lein test`, I get a \n\n```\njava.lang.ClassCastException:\nredwood.env_test$fn__2210$fn__2211 cannot be cast to clojure.lang.IFn$OLO\n```\n\nI've been trying several other ways including different test frameworks to redefine or rebind the langohr lib functions with no progress.\n\nI've tested other scenarios and I've successfully stubbed cheshire (json parsing clojure lib) functions with the above code structure.\nI humbly request assistance in understanding why my langohr stubs aren't working and for tips on how I can do this in an elegant manner.\n\n========================================\n\nCode:\n```text\n(defn stub [ch]\n (langohr.basic/ack ch 1))\n\n(deftest test-stub\n (with-redefs [langohr.basic/ack (fn [a1 a2] true)]\n (is (= true (stub \"dummy\")))))\n```\n\n```text\njava.lang.ClassCastException:\nredwood.env_test$fn__2210$fn__2211 cannot be cast to clojure.lang.IFn$OLO\n```\n\n```text\nlein test\n```\n\n```text\n(with-redefs [langohr.basic/ack (fn [a1 ^long a2] true)] ...)\n```\n\n========================================\n\nComments:\n- Thanks Mr. Perkins, I looked into the clojure code and saw where the OLO function in java. I'm confused because when I rebind to a function of my choosing, why should it matter what my function argument types should be? I thought the new var was independent of the old. Langohr also has a `langohr.basic/nack` function written with the same implementation as ack, yet this function was successfully redefed without the classcastexception.\n- It matters because the calling function (`stub` in your example) gets compiled into code that derefs the var `langhor.basic/ack` and then tries to cast the result to `IFn$OLO`. This happens because the compiler sees that, at compile-time, `langhor.basic/ack` refers to a function of that type, and it needs to do the cast in order to be able to pass a primitive (unboxed) long. Without seeing some code, I can't say why `nack` is not giving you the same error, but keep in mind that it is the call to `stub`, and not the redef itself, that fails, and that the type at compile-time matters.","metadata":{"transformedAt":"2026-08-18T18:33:20.186Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":60,"estimatedTokens":643}}739{"id":"stack-8335667","source":"stackoverflow","questionId":8335667,"title":"When does rabbitmq use tcp backpressure?","tags":["python","tcp","rabbitmq","pika"],"text":"Title: When does rabbitmq use tcp backpressure?\nTags: python, tcp, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nAccording to the Pika documentation \"the RabbitMQ broker uses TCP Backpressure to slow your client if it is delivering messages too fast.\" I've registered a backpressure callback and it has yet to be called. My queue has more than 40 million messages and it's growing. By setting the backpressure multiplier to -1 I can get my callback to be called on every message publish, but that's only useful for debugging.","metadata":{"transformedAt":"2026-08-18T18:33:20.186Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":6,"estimatedTokens":132}}740{"id":"stack-45491264","source":"stackoverflow","questionId":45491264,"title":"How to use docker-compose environment variables to populate config file","tags":["bash","docker","rabbitmq","docker-compose"],"text":"Title: How to use docker-compose environment variables to populate config file\nTags: bash, docker, rabbitmq, docker-compose\nSource: Stack Overflow\n\nQuestion:\nI'm new to docker-compose.\n\nI'm trying to understand how can I pass environment variables via docker-compose to populate missing variables values in a config file during `Dockerfile`'s build stage, so in the run phase, I will run the service- `rabbitmq` with its configuration filled with the env variables values.\n\nIn docker-compose yml file I have an `env_file:` and also `environment:`, question how can I pass them forward to populate the config file. \n\nAny help, an idea would be greatly appreciated with a simple example of \ncourse.\n\nExample rabbitmq config file (with env variable which need to be filled with its value for $SSL_PORT): \n\n```\n[{rabbit,\n [\n {loopback_users, []},\n {ssl_listeners, [$SSL_PORT]},\n {ssl_options, [{cacertfile,\"/etc/rabbitmq/ca/cacert.pem\"},\n {certfile,\"/etc/rabbitmq/server/cert.pem\"},\n {keyfile,\"/etc/rabbitmq/server/key.pem\"},\n {verify,verify_none},\n {fail_if_no_peer_cert,false}]}\n ]}\n].\n```\n\n========================================\n\nTop Answer:\nAssuming that your config file(s) are using the variable `$SSL_PORT` **inside** the container, and you want to pass environment variables from the **host** machine to be used on build, this can be done in your `docker-compose.yml`. YAML supports the use of environment variables, therefore, you can use `environment:` followed by an array of variables you wish to pass to the container during runtime.\n\nFor example:\n\n```\nversion: '3'\nservices:\n your-app:\n build:\n context: .\n dockerfile: Dockerfile\n environment:\n - \"SSL_PORT=${PORT_VARIABLE_FROM_HOST}\"\n```\n\nTo trouble shoot and make sure that your variables are in fact assigned inside your container run:\n\n`docker exec -it printenv`\n\nThis should list all of the environment variables inside your container\n\n========================================\n\nCode:\n```text\n[{rabbit,\n [\n {loopback_users, []},\n {ssl_listeners, [$SSL_PORT]},\n {ssl_options, [{cacertfile,\"/etc/rabbitmq/ca/cacert.pem\"},\n {certfile,\"/etc/rabbitmq/server/cert.pem\"},\n {keyfile,\"/etc/rabbitmq/server/key.pem\"},\n {verify,verify_none},\n {fail_if_no_peer_cert,false}]}\n ]}\n].\n```\n\n```text\nDockerfile\n```\n\n```text\nrabbitmq\n```\n\n```text\nenv_file:\n```\n\n```text\nenvironment:\n```\n\n```text\n#!/bin/sh\n\nsed -i \"s/\\$SSL_PORT/$SSL_PORT/g\" /etc/software.conf\n\nexec $@\n```\n\n```text\n#!/bin/bash\n\n# Perfom all the needed preprocessing here...\n\n# Invoke the original entrypoint passing the command and arguments\nexec /docker-entrypoint.sh $@\n```\n\n```text\nFROM rabbit:latest\n\nCOPY docker-entrypoint-pre.sh /docker-entrypoint-pre.sh\n\nENTRYPOINT [\"/docker-entrypoint-pre.sh\"]\n```\n\n```text\n--env-file file.env\n```\n\n```text\n--env VARIABLE=value\n```\n\n```text\ndocker-entrypoint.sh\n```\n\n```text\ndocker-entrypoint-pre.sh\n```\n\n```text\ndocker run --rm test-image echo \"This is a test\"\n```\n\n```text\ndocker-entrypoint-pre.sh\n```\n\n```text\necho\n```\n\n```text\nThis is a test\n```\n\n```text\ndocker-entrypoint.sh\n```\n\n```text\nrabbit:latest\n```\n\n```text\nDockerfile\n```\n\n```text\ndocker build -t myrabbit:latest .\n```\n\n```text\nDockerfile\n```\n\n```text\ndocker-entrypoint-pre.sh\n```\n\n```text\nmyrabbit:latest\n```\n\n```text\nversion: '3'\nservices:\n your-app:\n build:\n context: .\n dockerfile: Dockerfile\n environment:\n - \"SSL_PORT=${PORT_VARIABLE_FROM_HOST}\"\n```\n\n```text\n$SSL_PORT\n```\n\n```text\ndocker-compose.yml\n```\n\n```text\nenvironment:\n```\n\n```text\ndocker exec -it <container_name_or_id> printenv\n```\n\n========================================\n\nComments:\n- See if the article helps tarunlalwani.com/post/simple-parameterized-config-files-dock‌​er\n- @TarunLalwani: How do you pass environment variables originated from `env_file:` or `environment:` sections to a config file in the docker build stage?\n- If you pass it during the build then you need to use build args. docs.docker.com/engine/reference/commandline/build/…\n- @JavaSa: ...but note that if you are trying to generate that configuration during build you are problem giving up a lot of flexibility. That (generating configuration files) is typically more usefully done at runtime, because the place you are running a container is very often completely different from the place where the image was built. Also, making the ssl port configureable in the container seems like it would be unnecessary: the container network is isolated, and you can use port mapping to expose the service at arbitrary host ports.\n- @larsks: Except the port I need to pass in the user and password I want to create for rabbitmq, in this specific example it will go with the default user. So I still need templating mechanism to populate the conf.\n- @larsks: Can you please specify how this can be done on runtime rather than build time with an example? I would appreciate also example for build time\n- I need it on build time not run time, which means in `dockerfile` if I do printenv I don't see the environment variable..\n- Can you please specify the translation of bellow bash script command, in addition how can I not override my existing rabbitmq `docker-entrypoint.sh` and just to expand it with my own script to be run before that. Docker-entrypoint.sh is using the configuration so I need to do some modifications before it is launched\n- The bash script that I posted as an example just use sed to replace every occurrence of `$SSL_PORT` with the value of that environment variable. This is my goto approach because `sed` is present in many base images. The last line of the entrypoint script is the actual call to start the software. Docker will call the entrypoint script with the final command (with its arguments) as arguments. Given that this is the case it follows that if you want to do some preprocessing, you can just have your entrypoint call the original one. I'll update the answer in order to provide an example.\n- Ok I have a new script with preprocessing, how do I override this dockerfile to launch first my preprocessing and then all other instructions: github.com/docker-library/rabbitmq/blob/…\n- @JavaSa In order to do that you have to create a new Docker image inheriting from the original one and just replace the entrypoint. See the updated answer for details. Also please accept the answer if you find it complete enough.\n- Need to pass also rabbitmq server parameter when launching the docker-entrypoint.sh from pre-entrypoint script.","metadata":{"transformedAt":"2026-08-18T18:33:20.186Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":28,"totalLines":214,"estimatedTokens":1638}}741{"id":"stack-31534719","source":"stackoverflow","questionId":31534719,"title":"How to get detailed log/info about rabbitmq connection action?","tags":["rabbitmq"],"text":"Title: How to get detailed log/info about rabbitmq connection action?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have a python program connecting to a rabbitmq server. When this program starts, it connects well. But when rabbitmq server restarts, my program can not reconnect to it, and leaving error just \"Socket closed\"(produced by kombu), which is meaningless.\n\nI want to know the detailed info about the connection failure. On the server side, there is nothing useful in the rabbitmq log file either, it just said \"connection failed\" with no reason given.\n\nI tried the trace plugin(https://www.rabbitmq.com/firehose.html), and found there was no trace info published to amq.rabbitmq.trace exchange when the connection failure happended. I enabled the plugin with:\n\n```\nrabbitmq-plugins enable rabbitmq_tracing\nsystemctl restart rabbitmq-server\nrabbitmqctl trace_on\n```\n\nand then i wrote a client to get message from amq.rabbitmq.trace exchange:\n\n```\n#!/bin/env python\nfrom kombu.connection import BrokerConnection\nfrom kombu.messaging import Exchange, Queue, Consumer, Producer\n\ndef on_message(self, body, message):\n print(\"RECEIVED MESSAGE: %r\" % (body, ))\n message.ack()\n\ndef main():\n conn = BrokerConnection('amqp://admin:pass@localhost:5672//')\n channel = conn.channel()\n queue = Queue('debug', channel=channel,durable=False)\n queue.bind_to(exchange='amq.rabbitmq.trace', routing_key='publish.amq.rabbitmq.trace')\n consumer = Consumer(channel, queue)\n consumer.register_callback(on_message)\n consumer.consume()\n while True:\n conn.drain_events()\n\nif __name__ == '__main__':\n main()\n```\n\nI also tried to get some debug log from rabbitmq server. I reconfigured rabbitmq.config according to https://www.rabbitmq.com/configure.html, and set \nlog_levels to\n\n```\n{log_levels, [{connection, info}]}\n```\n\nbut as a result rabbitmq server failed to start. It seems like the official doc is not for me, my rabbitmq server version is 3.3.5. However\n\n```\n{log_levels, [connection,debug,info,error]}\n```\n\nor\n\n```\n{log_levels, [connection,debug]}\n```\n\nworks, but with this there is no DEBUG info showing in the logs, which i don't know whether it is because the log_levels configuration is not effective or there is just no DEBUG log got printed all the time.\n\n========================================\n\nCode:\n```text\nrabbitmq-plugins enable rabbitmq_tracing\nsystemctl restart rabbitmq-server\nrabbitmqctl trace_on\n```\n\n```text\n#!/bin/env python\nfrom kombu.connection import BrokerConnection\nfrom kombu.messaging import Exchange, Queue, Consumer, Producer\n\ndef on_message(self, body, message):\n print(\"RECEIVED MESSAGE: %r\" % (body, ))\n message.ack()\n\ndef main():\n conn = BrokerConnection('amqp://admin:pass@localhost:5672//')\n channel = conn.channel()\n queue = Queue('debug', channel=channel,durable=False)\n queue.bind_to(exchange='amq.rabbitmq.trace', routing_key='publish.amq.rabbitmq.trace')\n consumer = Consumer(channel, queue)\n consumer.register_callback(on_message)\n consumer.consume()\n while True:\n conn.drain_events()\n\nif __name__ == '__main__':\n main()\n```\n\n```text\n{log_levels, [{connection, info}]}\n```\n\n```text\n{log_levels, [connection,debug,info,error]}\n```\n\n```text\n{log_levels, [connection,debug]}\n```\n\n```text\n[\n {rabbit,\n [\n {log_levels, [{connection, debug}, {channel, debug}]}\n ]\n }\n].\n```\n\n========================================\n\nComments:\n- do you have any idea how to send logs to syslog from rabbitmq ?\n- @Luv33preet take a look at this for syslog","metadata":{"transformedAt":"2026-08-18T18:33:20.186Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":124,"estimatedTokens":881}}742{"id":"stack-14870832","source":"stackoverflow","questionId":14870832,"title":"RabbitMQ python worker script using 100% CPU","tags":["python","ubuntu","amazon-ec2","rabbitmq"],"text":"Title: RabbitMQ python worker script using 100% CPU\nTags: python, ubuntu, amazon-ec2, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI worte this python script which acts as an RPC server by modifying the default RPC example in RabbitMQ tutorial found here. It runs fine in my laptop. But when i run it in an amazon ec2 High CPU Medium Instance with these specs :\n\n 1.7 GiB of memory\n\n \n 5 EC2 Compute Units (2 virtual cores with 2.5 EC2 Compute Units each)\n\n \n 350 GB of instance storage\n\nIt takes up 100% CPU. Although my laptop with almost the same config runs this with less than 4% CPU use.I run this in Ubuntu-12.04 in both my laptop and amazon. \n\nHere is my code\n\n```\n#!/usr/bin/env python\n import pika\n import commands\n import socket\n import base64\n\n connection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost'))\n channel = connection.channel()\n channel.queue_declare(queue='rpc_queue')\n def on_request(ch, method, props, body):\n #print body\n body = base64.b64decode(body)\n print body\n run = commands.getoutput(body)\n response = socket.gethostname()\n print response\n ch.basic_publish(exchange='',\n routing_key=props.reply_to,\n properties=pika.BasicProperties(correlation_id = \\\n props.correlation_id),\n body=str(response))\n ch.basic_ack(delivery_tag = method.delivery_tag)\n channel.basic_qos(prefetch_count=1)\n channel.basic_consume(on_request, queue='rpc_queue')\n print \" [x] Awaiting RPC requests\"\n channel.start_consuming()\n```\n\nHow can i fix this ?\n\n========================================\n\nCode:\n```text\n#!/usr/bin/env python\n import pika\n import commands\n import socket\n import base64\n\n connection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost'))\n channel = connection.channel()\n channel.queue_declare(queue='rpc_queue')\n def on_request(ch, method, props, body):\n #print body\n body = base64.b64decode(body)\n print body\n run = commands.getoutput(body)\n response = socket.gethostname()\n print response\n ch.basic_publish(exchange='',\n routing_key=props.reply_to,\n properties=pika.BasicProperties(correlation_id = \\\n props.correlation_id),\n body=str(response))\n ch.basic_ack(delivery_tag = method.delivery_tag)\n channel.basic_qos(prefetch_count=1)\n channel.basic_consume(on_request, queue='rpc_queue')\n print \" [x] Awaiting RPC requests\"\n channel.start_consuming()\n```\n\n```text\npip install pika\n```\n\n```text\npip uninstall pika\n```\n\n```text\npip install git+https://github.com/pika/pika.git\n```\n\n========================================\n\nComments:\n- It would be great if you can provide link to problem. I know, its very long time. but it helps a lot!","metadata":{"transformedAt":"2026-08-18T18:33:20.186Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":100,"estimatedTokens":708}}743{"id":"stack-31966007","source":"stackoverflow","questionId":31966007,"title":"AnyEvent::RabbitMQ issues with closed channels","tags":["perl","rabbitmq","message-queue","anyevent"],"text":"Title: AnyEvent::RabbitMQ issues with closed channels\nTags: perl, rabbitmq, message-queue, anyevent\nSource: Stack Overflow\n\nQuestion:\nI'm writing a master program for publishing message into a message queue (RabbitMQ). The program is written in Perl 5 and is using AnyEvent::RabbitMQ for the communication to RabbitMQ.\n\nThe following minimal example (for the issue I ran into) will fail on a second command send via the same channel with the error \"Channel closed\".\n\n```\nuse strictures 2;\n\nuse AnyEvent::RabbitMQ;\n\nmain();\n\n############################################################################\nsub main {\n _log( debug => 'main' );\n my $condvar = AnyEvent->condvar;\n my $ar = AnyEvent::RabbitMQ->new;\n $ar->load_xml_spec;\n _log( debug => 'Connecting to RabbitMQ...' );\n $ar->connect(\n host => 'localhost',\n port => 5672,\n user => 'guest',\n pass => 'guest',\n vhost => '/',\n timeout => 1,\n tls => 0,\n on_success => sub { _on_connect_success( $condvar, $ar, @_ ) },\n on_failure => sub { _error( $condvar, $ar, 'failure', @_ ) },\n on_read_failure => sub { _error( $condvar, $ar, 'read_failure', @_ ) },\n on_return => sub { _error( $condvar, $ar, 'return', @_ ) },\n on_close => sub { _error( $condvar, $ar, 'close', @_ ) },\n );\n $condvar->recv;\n $ar->close;\n return;\n}\n\n############################################################################\nsub _on_connect_success {\n my ( $condvar, $ar, $new_ar ) = @_;\n _log( debug => 'Connected to RabbitMQ.' );\n _open_channel( $condvar, $new_ar );\n return;\n}\n\n############################################################################\nsub _open_channel {\n my ( $condvar, $ar ) = @_;\n _log( debug => 'Opening RabbitMQ channel...' );\n $ar->open_channel(\n on_success => sub { _on_open_channel_success( $condvar, $ar, @_ ) },\n on_failure => sub { _error( $condvar, $ar, 'failure', @_ ) },\n on_read_failure => sub { _error( $condvar, $ar, 'read_failure', @_ ) },\n on_return => sub { _error( $condvar, $ar, 'return', @_ ) },\n on_close => sub { _error( $condvar, $ar, 'close', @_ ) },\n );\n return;\n}\n\n############################################################################\nsub _on_open_channel_success {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => 'Opened RabbitMQ channel.' );\n _declare_queue( $condvar, $ar, $channel );\n return;\n}\n\n############################################################################\nsub _declare_queue {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => 'Declaring RabbitMQ queue...' );\n $channel->declare_queue(\n queue => 'test',\n auto_delete => 1,\n passive => 0,\n durable => 0,\n exclusive => 0,\n no_ack => 1,\n ticket => 0,\n on_success =>\n sub { _on_declare_queue_success( $condvar, $ar, $channel, @_ ) },\n on_failure => sub { _error( $condvar, $ar, 'failure', @_ ) },\n on_read_failure => sub { _error( $condvar, $ar, 'read_failure', @_ ) },\n on_return => sub { _error( $condvar, $ar, 'return', @_ ) },\n on_close => sub { _error( $condvar, $ar, 'close', @_ ) },\n );\n return;\n}\n\n############################################################################\nsub _on_declare_queue_success {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => 'Declared RabbitMQ queue.' );\n _bind_queue( $condvar, $ar, $channel );\n return;\n}\n\n############################################################################\nsub _bind_queue {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => 'Binding RabbitMQ queue...' );\n $channel->bind_queue(\n queue => 'test',\n exchange => '',\n routing_key => '',\n on_success => sub { _on_bind_queue_success( $condvar, $ar, $channel, @_ ) },\n on_failure => sub { _error( $condvar, $ar, 'failure', @_ ) },\n on_read_failure => sub { _error( $condvar, $ar, 'read_failure', @_ ) },\n on_return => sub { _error( $condvar, $ar, 'return', @_ ) },\n on_close => sub { _error( $condvar, $ar, 'close', @_ ) },\n );\n return;\n}\n\n############################################################################\nsub _on_bind_queue_success {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => 'Binded RabbitMQ queue.' );\n _log( info => 'Master ready to publish messages.' );\n _publish_message( $condvar, $ar, $channel, 'Hello, world!' );\n return;\n}\n\n############################################################################\nsub _publish_message {\n my ( $condvar, $ar, $channel, $message ) = @_;\n _log( debug => \"Publishing RabbitMQ message ($message)...\" );\n $channel->publish(\n queue => 'test',\n exchange => '',\n routing_key => '',\n body => $message,\n header => {},\n mandatory => 0,\n immediate => 0,\n on_success =>\n sub { _on_publish_message_success( $condvar, $ar, $channel, @_ ) },\n on_failure => sub { _error( $condvar, $ar, 'failure', @_ ) },\n on_read_failure => sub { _error( $condvar, $ar, 'read_failure', @_ ) },\n on_return => sub { _error( $condvar, $ar, 'return', @_ ) },\n on_close => sub { _error( $condvar, $ar, 'close', @_ ) },\n on_ack => sub { _error( $condvar, $ar, 'ack', @_ ) },\n on_nack => sub { _error( $condvar, $ar, 'nack', @_ ) },\n );\n return;\n}\n\n############################################################################\nsub _on_publish_message_success {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => \"Published RabbitMQ message.\" );\n sleep 1;\n _publish_message( $condvar, $ar, $channel, 'Hello, world! Again ' . time );\n return;\n}\n\n############################################################################\nsub _error {\n my ( $condvar, $ar, $type, @error ) = @_;\n _log( error => sprintf '%s - %s', $type, join ', ', @error );\n $condvar->send( $condvar, $ar, $type, @error );\n return;\n}\n\n############################################################################\nsub _log {\n my ( $level, $message ) = @_;\n my @time = gmtime time;\n $time[5] += 1900;\n $time[4] += 1;\n my $time = sprintf '%04d-%02d-%02dT%02d:%02d:%02d+00:00', @time[ 5, 4, 3, 2, 1, 0 ];\n my @caller0 = caller(0);\n my @caller1 = caller(1);\n my $subroutine = $caller1[3];\n $subroutine =~ s/^$caller0[0]:://;\n print STDERR \"$time [$level] $message at $caller0[1] line $caller0[2] ($subroutine; from $caller1[1] line $caller1[2])\\n\";\n return;\n}\n```\n\nThis program should:\n\n- connect to RabbitMQ\n\n- opens a RabbitMQ channel\n\n- declares a simpe queue (named \"test\")\n\n- bind to that queue (named \"test\")\n\n- publish a message (\"Hello, world!\")\n\n- after successfull publishing the message wait a second and publish another message\n\nThis program (master program) should *not* consume messages. There are other programs out there to do this job.\n\nThe minimal example (see above) will produce the following output:\n\n```\n2015-08-12T13:02:07+00:00 [debug] main at minimal.pl line 9 (main; from minimal.pl line 5)\n2015-08-12T13:02:07+00:00 [debug] Connecting to RabbitMQ... at minimal.pl line 13 (main; from minimal.pl line 5)\n2015-08-12T13:02:07+00:00 [debug] Connected to RabbitMQ. at minimal.pl line 36 (_on_connect_success; from minimal.pl line 22)\n2015-08-12T13:02:07+00:00 [debug] Opening RabbitMQ channel... at minimal.pl line 44 (_open_channel; from minimal.pl line 37)\n2015-08-12T13:02:07+00:00 [debug] Opened RabbitMQ channel. at minimal.pl line 58 (_on_open_channel_success; from minimal.pl line 46)\n2015-08-12T13:02:07+00:00 [debug] Declaring RabbitMQ queue... at minimal.pl line 66 (_declare_queue; from minimal.pl line 59)\n2015-08-12T13:02:07+00:00 [debug] Declared RabbitMQ queue. at minimal.pl line 88 (_on_declare_queue_success; from minimal.pl line 76)\n2015-08-12T13:02:07+00:00 [debug] Binding RabbitMQ queue... at minimal.pl line 96 (_bind_queue; from minimal.pl line 89)\n2015-08-12T13:02:07+00:00 [error] failure - Channel closed at minimal.pl line 155 (_error; from minimal.pl line 102)\n2015-08-12T13:02:07+00:00 [error] close - Net::AMQP::Frame::Method=HASH(0x38fe1c8) at minimal.pl line 155 (_error; from minimal.pl line 50)\n```\n\nWhy does `AnyEvent::RabbitMQ` or RabbitMQ itself closes the channel (not the connection or did I miss something)?\n\n========================================\n\nCode:\n```text\nuse strictures 2;\n\nuse AnyEvent::RabbitMQ;\n\nmain();\n\n############################################################################\nsub main {\n _log( debug => 'main' );\n my $condvar = AnyEvent->condvar;\n my $ar = AnyEvent::RabbitMQ->new;\n $ar->load_xml_spec;\n _log( debug => 'Connecting to RabbitMQ...' );\n $ar->connect(\n host => 'localhost',\n port => 5672,\n user => 'guest',\n pass => 'guest',\n vhost => '/',\n timeout => 1,\n tls => 0,\n on_success => sub { _on_connect_success( $condvar, $ar, @_ ) },\n on_failure => sub { _error( $condvar, $ar, 'failure', @_ ) },\n on_read_failure => sub { _error( $condvar, $ar, 'read_failure', @_ ) },\n on_return => sub { _error( $condvar, $ar, 'return', @_ ) },\n on_close => sub { _error( $condvar, $ar, 'close', @_ ) },\n );\n $condvar->recv;\n $ar->close;\n return;\n}\n\n############################################################################\nsub _on_connect_success {\n my ( $condvar, $ar, $new_ar ) = @_;\n _log( debug => 'Connected to RabbitMQ.' );\n _open_channel( $condvar, $new_ar );\n return;\n}\n\n############################################################################\nsub _open_channel {\n my ( $condvar, $ar ) = @_;\n _log( debug => 'Opening RabbitMQ channel...' );\n $ar->open_channel(\n on_success => sub { _on_open_channel_success( $condvar, $ar, @_ ) },\n on_failure => sub { _error( $condvar, $ar, 'failure', @_ ) },\n on_read_failure => sub { _error( $condvar, $ar, 'read_failure', @_ ) },\n on_return => sub { _error( $condvar, $ar, 'return', @_ ) },\n on_close => sub { _error( $condvar, $ar, 'close', @_ ) },\n );\n return;\n}\n\n############################################################################\nsub _on_open_channel_success {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => 'Opened RabbitMQ channel.' );\n _declare_queue( $condvar, $ar, $channel );\n return;\n}\n\n############################################################################\nsub _declare_queue {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => 'Declaring RabbitMQ queue...' );\n $channel->declare_queue(\n queue => 'test',\n auto_delete => 1,\n passive => 0,\n durable => 0,\n exclusive => 0,\n no_ack => 1,\n ticket => 0,\n on_success =>\n sub { _on_declare_queue_success( $condvar, $ar, $channel, @_ ) },\n on_failure => sub { _error( $condvar, $ar, 'failure', @_ ) },\n on_read_failure => sub { _error( $condvar, $ar, 'read_failure', @_ ) },\n on_return => sub { _error( $condvar, $ar, 'return', @_ ) },\n on_close => sub { _error( $condvar, $ar, 'close', @_ ) },\n );\n return;\n}\n\n############################################################################\nsub _on_declare_queue_success {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => 'Declared RabbitMQ queue.' );\n _bind_queue( $condvar, $ar, $channel );\n return;\n}\n\n############################################################################\nsub _bind_queue {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => 'Binding RabbitMQ queue...' );\n $channel->bind_queue(\n queue => 'test',\n exchange => '',\n routing_key => '',\n on_success => sub { _on_bind_queue_success( $condvar, $ar, $channel, @_ ) },\n on_failure => sub { _error( $condvar, $ar, 'failure', @_ ) },\n on_read_failure => sub { _error( $condvar, $ar, 'read_failure', @_ ) },\n on_return => sub { _error( $condvar, $ar, 'return', @_ ) },\n on_close => sub { _error( $condvar, $ar, 'close', @_ ) },\n );\n return;\n}\n\n############################################################################\nsub _on_bind_queue_success {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => 'Binded RabbitMQ queue.' );\n _log( info => 'Master ready to publish messages.' );\n _publish_message( $condvar, $ar, $channel, 'Hello, world!' );\n return;\n}\n\n############################################################################\nsub _publish_message {\n my ( $condvar, $ar, $channel, $message ) = @_;\n _log( debug => \"Publishing RabbitMQ message ($message)...\" );\n $channel->publish(\n queue => 'test',\n exchange => '',\n routing_key => '',\n body => $message,\n header => {},\n mandatory => 0,\n immediate => 0,\n on_success =>\n sub { _on_publish_message_success( $condvar, $ar, $channel, @_ ) },\n on_failure => sub { _error( $condvar, $ar, 'failure', @_ ) },\n on_read_failure => sub { _error( $condvar, $ar, 'read_failure', @_ ) },\n on_return => sub { _error( $condvar, $ar, 'return', @_ ) },\n on_close => sub { _error( $condvar, $ar, 'close', @_ ) },\n on_ack => sub { _error( $condvar, $ar, 'ack', @_ ) },\n on_nack => sub { _error( $condvar, $ar, 'nack', @_ ) },\n );\n return;\n}\n\n############################################################################\nsub _on_publish_message_success {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => \"Published RabbitMQ message.\" );\n sleep 1;\n _publish_message( $condvar, $ar, $channel, 'Hello, world! Again ' . time );\n return;\n}\n\n############################################################################\nsub _error {\n my ( $condvar, $ar, $type, @error ) = @_;\n _log( error => sprintf '%s - %s', $type, join ', ', @error );\n $condvar->send( $condvar, $ar, $type, @error );\n return;\n}\n\n############################################################################\nsub _log {\n my ( $level, $message ) = @_;\n my @time = gmtime time;\n $time[5] += 1900;\n $time[4] += 1;\n my $time = sprintf '%04d-%02d-%02dT%02d:%02d:%02d+00:00', @time[ 5, 4, 3, 2, 1, 0 ];\n my @caller0 = caller(0);\n my @caller1 = caller(1);\n my $subroutine = $caller1[3];\n $subroutine =~ s/^$caller0[0]:://;\n print STDERR \"$time [$level] $message at $caller0[1] line $caller0[2] ($subroutine; from $caller1[1] line $caller1[2])\\n\";\n return;\n}\n```\n\n```text\n2015-08-12T13:02:07+00:00 [debug] main at minimal.pl line 9 (main; from minimal.pl line 5)\n2015-08-12T13:02:07+00:00 [debug] Connecting to RabbitMQ... at minimal.pl line 13 (main; from minimal.pl line 5)\n2015-08-12T13:02:07+00:00 [debug] Connected to RabbitMQ. at minimal.pl line 36 (_on_connect_success; from minimal.pl line 22)\n2015-08-12T13:02:07+00:00 [debug] Opening RabbitMQ channel... at minimal.pl line 44 (_open_channel; from minimal.pl line 37)\n2015-08-12T13:02:07+00:00 [debug] Opened RabbitMQ channel. at minimal.pl line 58 (_on_open_channel_success; from minimal.pl line 46)\n2015-08-12T13:02:07+00:00 [debug] Declaring RabbitMQ queue... at minimal.pl line 66 (_declare_queue; from minimal.pl line 59)\n2015-08-12T13:02:07+00:00 [debug] Declared RabbitMQ queue. at minimal.pl line 88 (_on_declare_queue_success; from minimal.pl line 76)\n2015-08-12T13:02:07+00:00 [debug] Binding RabbitMQ queue... at minimal.pl line 96 (_bind_queue; from minimal.pl line 89)\n2015-08-12T13:02:07+00:00 [error] failure - Channel closed at minimal.pl line 155 (_error; from minimal.pl line 102)\n2015-08-12T13:02:07+00:00 [error] close - Net::AMQP::Frame::Method=HASH(0x38fe1c8) at minimal.pl line 155 (_error; from minimal.pl line 50)\n```\n\n```text\nAnyEvent::RabbitMQ\n```\n\n```text\nsub _declare_exchange {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => 'Declaring RabbitMQ exchange...' );\n $channel->declare_exchange(\n exchange => 'testest',\n type => 'fanout',\n on_success =>\n sub { _on_declare_exchange_success( $condvar, $ar, $channel, @_ ) },\n on_failure => sub { _error( $condvar, $ar, 'failure', @_ ) },\n on_read_failure => sub { _error( $condvar, $ar, 'read_failure', @_ ) },\n on_return => sub { _error( $condvar, $ar, 'return', @_ ) },\n on_close => sub { _error( $condvar, $ar, 'close', @_ ) },\n );\n return;\n}\n\n############################################################################\nsub _on_declare_exchange_success {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => 'Declared RabbitMQ exchange.' );\n _bind_exchange( $condvar, $ar, $channel );\n return;\n}\n\n############################################################################\nsub _bind_exchange {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => 'Binding RabbitMQ exchange...' );\n $channel->bind_exchange(\n source => 'testest',\n destination => 'testest',\n routing_key => '',\n on_success => sub { _on_bind_exchange_success( $condvar, $ar, $channel, @_ ) },\n on_failure => sub { _error( $condvar, $ar, 'failure', @_ ) },\n on_read_failure => sub { _error( $condvar, $ar, 'read_failure', @_ ) },\n on_return => sub { _error( $condvar, $ar, 'return', @_ ) },\n on_close => sub { _error( $condvar, $ar, 'close', @_ ) },\n );\n return;\n}\n```\n\n```text\nsub _on_open_channel_success {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => 'Opened RabbitMQ channel.' );\n $channel->confirm;\n _declare_exchange( $condvar, $ar, $channel );\n return;\n}\n```\n\n```text\n$channel->bind_queue(\n queue => 'test',\n exchange => 'testest', # <-- here\n routing_key => '',\n # ...\n );\n```\n\n```text\n$channel->publish(\n queue => 'test',\n exchange => 'testest', # <-- here\n routing_key => '',\n # ...\n on_ack => sub { \n _on_publish_message_success( $condvar, $ar, $channel, @_ );\n },\n);\n```\n\n```text\nmy $t; \n$t = AE::timer(1,0,sub {\n _publish_message( $condvar, $ar, $channel, 'Hello, world! Again ' . time );\n undef $t;\n});\n```\n\n```text\nuse strictures 2;\n\nuse AnyEvent::RabbitMQ;\n\nmain();\n\n############################################################################\nsub main {\n _log( debug => 'main' );\n my $condvar = AnyEvent->condvar;\n my $ar = AnyEvent::RabbitMQ->new;\n $ar->load_xml_spec;\n _log( debug => 'Connecting to RabbitMQ...' );\n $ar->connect(\n host => 'localhost',\n port => 5672,\n user => 'guest',\n pass => 'guest',\n vhost => '/guest',\n timeout => 1,\n tls => 0,\n on_success => sub { _on_connect_success( $condvar, $ar, @_ ) },\n on_failure => sub { _error( $condvar, $ar, 'failure', @_ ) },\n on_read_failure => sub { _error( $condvar, $ar, 'read_failure', @_ ) },\n on_return => sub { _error( $condvar, $ar, 'return', @_ ) },\n on_close => sub { _error( $condvar, $ar, 'close', @_ ) },\n );\n $condvar->recv;\n $ar->close;\n return;\n}\n\n############################################################################\nsub _on_connect_success {\n my ( $condvar, $ar, $new_ar ) = @_;\n _log( debug => 'Connected to RabbitMQ.' );\n _open_channel( $condvar, $new_ar );\n return;\n}\n\n############################################################################\nsub _open_channel {\n my ( $condvar, $ar ) = @_;\n _log( debug => 'Opening RabbitMQ channel...' );\n $ar->open_channel(\n on_success => sub { _on_open_channel_success( $condvar, $ar, @_ ) },\n on_failure => sub { _error( $condvar, $ar, 'failure', @_ ) },\n on_read_failure => sub { _error( $condvar, $ar, 'read_failure', @_ ) },\n on_return => sub { _error( $condvar, $ar, 'return', @_ ) },\n on_close => sub { _error( $condvar, $ar, 'close', @_ ) },\n );\n return;\n}\n\n############################################################################\nsub _on_open_channel_success {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => 'Opened RabbitMQ channel.' );\n $channel->confirm;\n _declare_exchange( $condvar, $ar, $channel );\n return;\n}\n\n############################################################################\nsub _declare_exchange {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => 'Declaring RabbitMQ exchange...' );\n $channel->declare_exchange(\n exchange => 'testest',\n type => 'fanout',\n on_success =>\n sub { _on_declare_exchange_success( $condvar, $ar, $channel, @_ ) },\n on_failure => sub { _error( $condvar, $ar, 'failure', @_ ) },\n on_read_failure => sub { _error( $condvar, $ar, 'read_failure', @_ ) },\n on_return => sub { _error( $condvar, $ar, 'return', @_ ) },\n on_close => sub { _error( $condvar, $ar, 'close', @_ ) },\n );\n return;\n}\n\n############################################################################\nsub _on_declare_exchange_success {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => 'Declared RabbitMQ exchange.' );\n _bind_exchange( $condvar, $ar, $channel );\n return;\n}\n\n############################################################################\nsub _bind_exchange {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => 'Binding RabbitMQ exchange...' );\n $channel->bind_exchange(\n source => 'testest',\n destination => 'testest',\n routing_key => '',\n on_success => sub { _on_bind_exchange_success( $condvar, $ar, $channel, @_ ) },\n on_failure => sub { _error( $condvar, $ar, 'failure', @_ ) },\n on_read_failure => sub { _error( $condvar, $ar, 'read_failure', @_ ) },\n on_return => sub { _error( $condvar, $ar, 'return', @_ ) },\n on_close => sub { _error( $condvar, $ar, 'close', @_ ) },\n );\n return;\n}\n\n############################################################################\nsub _on_bind_exchange_success {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => 'Binded RabbitMQ exchange.' );\n _declare_queue( $condvar, $ar, $channel );\n return;\n}\n\n\n############################################################################\nsub _declare_queue {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => 'Declaring RabbitMQ queue...' );\n $channel->declare_queue(\n queue => 'test',\n auto_delete => 1,\n passive => 0,\n durable => 0,\n exclusive => 0,\n no_ack => 1,\n ticket => 0,\n on_success =>\n sub { _on_declare_queue_success( $condvar, $ar, $channel, @_ ) },\n on_failure => sub { _error( $condvar, $ar, 'failure', @_ ) },\n on_read_failure => sub { _error( $condvar, $ar, 'read_failure', @_ ) },\n on_return => sub { _error( $condvar, $ar, 'return', @_ ) },\n on_close => sub { _error( $condvar, $ar, 'close', @_ ) },\n );\n return;\n}\n\n############################################################################\nsub _on_declare_queue_success {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => 'Declared RabbitMQ queue.' );\n _bind_queue( $condvar, $ar, $channel );\n return;\n}\n\n############################################################################\nsub _bind_queue {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => 'Binding RabbitMQ queue...' );\n $channel->bind_queue(\n queue => 'test',\n exchange => 'testest',\n routing_key => '',\n on_success => sub { _on_bind_queue_success( $condvar, $ar, $channel, @_ ) },\n on_failure => sub { _error( $condvar, $ar, 'failure', @_ ) },\n on_read_failure => sub { _error( $condvar, $ar, 'read_failure', @_ ) },\n on_return => sub { _error( $condvar, $ar, 'return', @_ ) },\n on_close => sub { _error( $condvar, $ar, 'close', @_ ) },\n );\n return;\n}\n\n############################################################################\nsub _on_bind_queue_success {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => 'Binded RabbitMQ queue.' );\n _log( info => 'Master ready to publish messages.' );\n _publish_message( $condvar, $ar, $channel, 'Hello, world!' );\n return;\n}\n\n############################################################################\nsub _publish_message {\n my ( $condvar, $ar, $channel, $message ) = @_;\n _log( debug => \"Publishing RabbitMQ message ($message)...\" );\n $channel->publish(\n queue => 'test',\n exchange => 'testest',\n routing_key => '',\n body => $message,\n header => {},\n mandatory => 0,\n immediate => 0,\n on_success =>\n sub { _on_publish_message_success( $condvar, $ar, $channel, @_ ) },\n on_failure => sub { _error( $condvar, $ar, 'failure', @_ ) },\n on_read_failure => sub { _error( $condvar, $ar, 'read_failure', @_ ) },\n on_return => sub { _error( $condvar, $ar, 'return', @_ ) },\n on_close => sub { _error( $condvar, $ar, 'close', @_ ) },\n on_ack => sub { \n _on_publish_message_success( $condvar, $ar, $channel, @_ );\n# _error( $condvar, $ar, 'ack', @_ ) \n },\n on_nack => sub { _error( $condvar, $ar, 'nack', @_ ) },\n );\n return;\n}\n\n############################################################################\nsub _on_publish_message_success {\n my ( $condvar, $ar, $channel ) = @_;\n _log( debug => \"Published RabbitMQ message.\" );\n my $t; $t=AE::timer(1,0,sub {\n _publish_message( $condvar, $ar, $channel, 'Hello, world! Again ' . time );\n undef $t;\n });\n return;\n}\n\n############################################################################\nsub _error {\n my ( $condvar, $ar, $type, @error ) = @_;\n _log( error => sprintf '%s - %s', $type, join ', ', @error );\n $condvar->send( $condvar, $ar, $type, @error );\n return;\n}\n\n############################################################################\nsub _log {\n my ( $level, $message ) = @_;\n my @time = gmtime time;\n $time[5] += 1900;\n $time[4] += 1;\n my $time = sprintf '%04d-%02d-%02dT%02d:%02d:%02d+00:00', @time[ 5, 4, 3, 2, 1, 0 ];\n my @caller0 = caller(0);\n my @caller1 = caller(1);\n my $subroutine = $caller1[3];\n $subroutine =~ s/^$caller0[0]:://;\n print STDERR \"$time [$level] $message at $caller0[1] line $caller0[2] ($subroutine; from $caller1[1] line $caller1[2])\\n\";\n return;\n}\n```\n\n```text\n$channel->confirm\n```\n\n```text\n_bind_queue\n```\n\n```text\nbind_queue()\n```\n\n```text\n_publish_message\n```\n\n```text\npublish()\n```\n\n```text\non_ack\n```\n\n```text\nsleep\n```\n\n```text\n_on_publish_message_success\n```\n\n```text\nAE::timer\n```\n\n========================================\n\nComments:\n- Hi. Do you know how to tune `heartbeat`? I have tried this, but code takes value from server frame. It is 60 seconds and I do not know how to change that =(\n- @EugenKonkov it's been years since I touched this stuff. That was two jobs ago I'm afraid. I think you should ask a new question.","metadata":{"transformedAt":"2026-08-18T18:33:20.187Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":18,"totalLines":770,"estimatedTokens":6615}}744{"id":"stack-24673960","source":"stackoverflow","questionId":24673960,"title":"inbound and Outbound Gateway AMQP annotation","tags":["java","rabbitmq","spring-integration","amqp","spring-boot"],"text":"Title: inbound and Outbound Gateway AMQP annotation\nTags: java, rabbitmq, spring-integration, amqp, spring-boot\nSource: Stack Overflow\n\nQuestion:\nI have a working spring integration + rabbitmq application using xml config. Now, i am converting them to java config annotation. There are available classes and java annotation for some main amqp objects like `Queue` , `TopicExchange` , and `Binding`. However, I cant find any reference in converting `inbound-gateway` and `outbound-gateway` to java annotation or class implementation.\n\nHere's my implementation:\n// gateway.xml\n\n```\n\n```\n\nIs it possible to convert them to java annotation or class implementation(bean, etc..)?\n\nADDITIONAL: I am currently using `spring boot` + `spring integration`.\n\n========================================\n\nCode:\n```text\n<int-amqp:outbound-gateway request-channel=\"requestChannel\" reply-channel=\"responseChannel\" exchange-name=\"${exchange}\" routing-key-expression=\"${routing}\"/>\n\n\n<int-amqp:inbound-gateway request-channel=\"inboundRequest\"\n queue-names=\"${queue}\" connection-factory=\"rabbitConnectionFactory\"\n reply-channel=\"inboundResponse\" message-converter=\"compositeMessageConverter\"/>\n```\n\n```text\nQueue\n```\n\n```text\nTopicExchange\n```\n\n```text\nBinding\n```\n\n```text\ninbound-gateway\n```\n\n```text\noutbound-gateway\n```\n\n```text\nspring boot\n```\n\n```text\nspring integration\n```\n\n```text\n@Bean\npublic IntegrationFlow amqpFlow() {\n return IntegrationFlows.from(Amqp.inboundGateway(this.rabbitConnectionFactory, queue()))\n .transform(\"hello \"::concat)\n .transform(String.class, String::toUpperCase)\n .get();\n}\n\n@Bean\npublic IntegrationFlow amqpOutboundFlow() {\n return IntegrationFlows.from(Amqp.channel(\"amqpOutboundInput\", this.rabbitConnectionFactory))\n .handle(Amqp.outboundAdapter(this.amqpTemplate).routingKeyExpression(\"headers.routingKey\"))\n .get();\n}\n```\n\n```text\n@Bean\npublic AmqpInboundGateway amqpInbound() {\n AmqpInboundGateway gateway = new AmqpInboundGateway(new SimpleMessageListenerContainer(this.rabbitConnectionFactory));\n gateway.setRequestChannel(inboundChanne());\n return gateway;\n}\n\n@Bean\n@ServiceActivator(inputChannel = \"amqpOutboundChannel\")\npublic AmqpOutboundEndpoint amqpOutbound() {\n AmqpOutboundEndpoint handler = new AmqpOutboundEndpoint(this.rabbitTemplate);\n handler.setOutputChannel(amqpReplyChannel());\n return handler;\n}\n```\n\n========================================\n\nComments:\n- In the XML version itself, how do we provide the exchange name ? I want to listen to a queue bound to a topic exchange.\n- Thank you for this. I am trying to use these however I dont know where to declar the queue name for InboudGateway. In xml config, you really need to declare the queue-name where the gateway will get the message.\n- `SimpleMessageListenerContainer` is responsible for that. The xml tag parser does it for you. That's why I suggets to move to the DSL to avoid such a Java configuration for all bolraplate code, like a container configuration just for `queueName`","metadata":{"transformedAt":"2026-08-18T18:33:20.187Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":10,"totalLines":98,"estimatedTokens":767}}745{"id":"stack-20843236","source":"stackoverflow","questionId":20843236,"title":"How to call a celery task delay function from non-python languages such as Java?","tags":["java","python","rabbitmq","celery","celery-task"],"text":"Title: How to call a celery task delay function from non-python languages such as Java?\nTags: java, python, rabbitmq, celery, celery-task\nSource: Stack Overflow\n\nQuestion:\nI have setup celery + rabbitmq for on a 3 cluster machine. I have also created a task which generates a regular expression based on data from the file and uses the information to parse text. \n\n```\nfrom celery import Celery\n\ncelery = Celery('tasks', broker='amqp://localhost//')\nimport re\n\n@celery.task\ndef add(x, y):\n return x + y\n\ndef get_regular_expression():\n with open(\"text\") as fp:\n data = fp.readlines()\n str_re = \"|\".join([x.split()[2] for x in data ])\n return str_re \n\n@celery.task\ndef analyse_json(tw):\n str_re = get_regular_expression()\n re.match(str_re,tw.text)\n```\n\nI can make the call to this task very easily using the following python code :-\n\n```\nfrom tasks import analyse_tweet_json\nx = tweet ## load from a file (x is a json)\nanalyse_tweet_json.delay(x)\n```\n\nHowever, now I want to make the same call from Java and not python. I am not sure what's the easiest way of doing the same. \n\nI've written this code for sending a message to the AMQP broker. The code runs fine, but the task is not carried out. I am not sure how to specify the name of the task which should be carried out.\n\n```\nimport com.rabbitmq.client.AMQP;\nimport com.rabbitmq.client.ConnectionFactory;\nimport com.rabbitmq.client.Connection;\nimport com.rabbitmq.client.Channel;\n\nclass try1 {\npublic static void main(String[] args) throws Exception {\n ConnectionFactory factory = new ConnectionFactory();\n factory.setUri(\"amqp://localhost\");\n Connection connection = factory.newConnection();\n Channel channel = connection.createChannel();\n String queueName = channel.queueDeclare().getQueue();\n channel.queueBind(queueName, \"celery\", \"celery\");\n String messageBody = \"{\\\"text\\\":\\\"i am good\\\"}\" ;\n byte[] msgBytes = messageBody.getBytes(\"ASCII\") ;\n channel.basicPublish(queueName, queueName,\n new AMQP.BasicProperties\n (\"application/json\", null, null, null,\n null, null, null, null,\n null, null, null, \"guest\",\n null, null),messageBody.getBytes(\"ASCII\")) ;\n connection.close();\n```\n\n}\n}\n\nthis is the output in the errorlog of rabbitMq :-\n\n```\nconnection , channel 1 - error:\n{amqp_error,not_found,\n\"no exchange 'amq.gen-gEV47GX9pF_oZ-0bEnOazE' in vhost '/'\",\n'basic.publish'}\n```\n\nAny help will be appreciated.\n\nthanks,\nAmit\n\n========================================\n\nTop Answer:\ncelery implicitly declare an exchange, using Java you'll have to declare one yourself.\n\nsee Interoperating with Django/Celery From Java\n\n========================================\n\nCode:\n```text\nfrom celery import Celery\n\ncelery = Celery('tasks', broker='amqp://localhost//')\nimport re\n\n@celery.task\ndef add(x, y):\n return x + y\n\n\ndef get_regular_expression():\n with open(\"text\") as fp:\n data = fp.readlines()\n str_re = \"|\".join([x.split()[2] for x in data ])\n return str_re \n\n\n\n@celery.task\ndef analyse_json(tw):\n str_re = get_regular_expression()\n re.match(str_re,tw.text)\n```\n\n```text\nfrom tasks import analyse_tweet_json\nx = tweet ## load from a file (x is a json)\nanalyse_tweet_json.delay(x)\n```\n\n```text\nimport com.rabbitmq.client.AMQP;\nimport com.rabbitmq.client.ConnectionFactory;\nimport com.rabbitmq.client.Connection;\nimport com.rabbitmq.client.Channel;\n\nclass try1 {\npublic static void main(String[] args) throws Exception {\n ConnectionFactory factory = new ConnectionFactory();\n factory.setUri(\"amqp://localhost\");\n Connection connection = factory.newConnection();\n Channel channel = connection.createChannel();\n String queueName = channel.queueDeclare().getQueue();\n channel.queueBind(queueName, \"celery\", \"celery\");\n String messageBody = \"{\\\"text\\\":\\\"i am good\\\"}\" ;\n byte[] msgBytes = messageBody.getBytes(\"ASCII\") ;\n channel.basicPublish(queueName, queueName,\n new AMQP.BasicProperties\n (\"application/json\", null, null, null,\n null, null, null, null,\n null, null, null, \"guest\",\n null, null),messageBody.getBytes(\"ASCII\")) ;\n connection.close();\n```\n\n```text\nconnection <0.14627.0>, channel 1 - error:\n{amqp_error,not_found,\n\"no exchange 'amq.gen-gEV47GX9pF_oZ-0bEnOazE' in vhost '/'\",\n'basic.publish'}\n```\n\n========================================\n\nComments:\n- Actually, there were other issues. Please see my solution.","metadata":{"transformedAt":"2026-08-18T18:33:20.187Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":160,"estimatedTokens":1101}}746{"id":"stack-25231657","source":"stackoverflow","questionId":25231657,"title":"RabbitMQ and Sails.js","tags":["node.js","rabbitmq","messaging","sails.js","event-driven"],"text":"Title: RabbitMQ and Sails.js\nTags: node.js, rabbitmq, messaging, sails.js, event-driven\nSource: Stack Overflow\n\nQuestion:\nI'm having trouble using RabbitMQ with my Sails app. I'm unsure of where to place the subscriber code. What I'm trying to do is build a notifications system so that when an administrator approves a user's data request, the user's dashboard will pop a notification similar to how Facebook pops a notification. The problem is, putting the subscriber code in my dashboard controller's display route seems to never grab a published message.\n\nAny advice would be greatly appreciated. Currently using rabbit.js package to connect to RabbitMQ.\n\n========================================\n\nTop Answer:\nHere's an npm package that implements a RabbitMQ adapter for SailsJS.\n\n========================================\n\nCode:\n```text\nvar context = require('rabbit.js').createContext();\nmodule.exports = {\n\n onConnect: function(session, socket) {\n var pub = context.socket('PUB');\n var sub = context.socket('SUB');\n\n socket.on('disconnect', function() {\n pub.close();\n sub.close();\n });\n\n // NB we have to adapt between the APIs\n sub.setEncoding('utf8');\n socket.on('message', function(msg) {\n pub.write(msg, 'utf8');\n });\n sub.on('data', function(msg) {\n socket.send(msg);\n });\n sub.connect('chat');\n pub.connect('chat');\n\n }\n\n}\n```\n\n```text\nnpm install rabbit.js\n```\n\n========================================\n\nComments:\n- Have you considered using Sails' build in resourceful pubsub system for messaging?\n- Thanks sgress454! This is definitely what I'm looking for. I still have a similar question though: for receivers, where exactly does the \"listening\" code go? For example, using io.socket.on(\"request\", function()...), where would I place this code so that an user can continuously listen for an update when a \"request\" has been approved for that specific user?\n- This code lives in the front end of your app, in the client-side Javascript. It can go anywhere after the `` tag that includes the Sails socket client,or in a bootstrapping script like jQuery's `$(function(){})`.\n- So, in my `RequestController`, under the `grant` action, I publish an update when it's executed. In my `DashboardController`, under my `display` action, I make a call to `Request.find(req.session.user.id, function(err, requests)` and I subscribe using `User.subscribe(req.socket, requests, ['update']);`. Is this the correct way to place publish/subs? On the view that DashboardController.display renders, do I just need to use io.socket.on(\"request\", function()...) to listen for the publishes?\n- In your `DashboardController`, you would subscribe using `Request.subscribe(req, requests, ['update'])`, assuming you only want to hear about updates (and not deletes). In your `RequestController`, publish the update using `.publishUpdate`. Then in your view, `io.socket.on(\"request\", function()...)` is correct.\n- I made a new question about this link, since it's getting off-topic from the original question - thanks!\n- check out this example project of using Sails websockets, perhaps it will help you understand hw everything fits together github.com/stenio123/sails-socket-example","metadata":{"transformedAt":"2026-08-18T18:33:20.187Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":60,"estimatedTokens":826}}747{"id":"stack-6326226","source":"stackoverflow","questionId":6326226,"title":"celery .delay hangs (recent, not an auth problem)","tags":["python","django","rabbitmq","celery"],"text":"Title: celery .delay hangs (recent, not an auth problem)\nTags: python, django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI am running Celery 2.2.4/djCelery 2.2.4, using RabbitMQ 2.1.1 as a backend. I recently brought online two new celery servers -- I had been running 2 workers across two machines with a total of ~18 threads and on my new souped up boxes (36g RAM + dual hyper-threaded quad-core), I am running 10 workers with 8 threads each, for a total of 180 threads -- my tasks are all pretty small so this should be fine.\n\nThe nodes have been running fine for the last few days, but today I noticed that `.delaay()` is hanging. When I interrupt it, I see a traceback that points here:\n\n```\nFile \"/home/django/deployed/releases/20110608183345/virtual-env/lib/python2.5/site-packages/celery/task/base.py\", line 324, in delay\n return self.apply_async(args, kwargs)\nFile \"/home/django/deployed/releases/20110608183345/virtual-env/lib/python2.5/site-packages/celery/task/base.py\", line 449, in apply_async\n publish.close()\nFile \"/home/django/deployed/virtual-env/lib/python2.5/site-packages/kombu/compat.py\", line 108, in close\n self.backend.close()\nFile \"/home/django/deployed/virtual-env/lib/python2.5/site-packages/amqplib/client_0_8/channel.py\", line 194, in close\n (20, 41), # Channel.close_ok\nFile \"/home/django/deployed/virtual-env/lib/python2.5/site-packages/amqplib/client_0_8/abstract_channel.py\", line 89, in wait\n self.channel_id, allowed_methods)\nFile \"/home/django/deployed/virtual-env/lib/python2.5/site-packages/amqplib/client_0_8/connection.py\", line 198, in _wait_method\n self.method_reader.read_method()\nFile \"/home/django/deployed/virtual-env/lib/python2.5/site-packages/amqplib/client_0_8/method_framing.py\", line 212, in read_method\n self._next_method()\nFile \"/home/django/deployed/virtual-env/lib/python2.5/site-packages/amqplib/client_0_8/method_framing.py\", line 127, in _next_method\n frame_type, channel, payload = self.source.read_frame()\nFile \"/home/django/deployed/virtual-env/lib/python2.5/site-packages/amqplib/client_0_8/transport.py\", line 109, in read_frame\n frame_type, channel, size = unpack('>BHI', self._read(7))\nFile \"/home/django/deployed/virtual-env/lib/python2.5/site-packages/amqplib/client_0_8/transport.py\", line 200, in _read\n s = self.sock.recv(65536)\n```\n\nI've checked the Rabbit logs, and I see it the process trying to connect as:\n\n```\n=INFO REPORT==== 12-Jun-2011::22:58:12 ===\naccepted TCP connection on 0.0.0.0:5672 from x.x.x.x:48569\n```\n\nI have my Celery log level set to `INFO`, but I don't see anything particularly interesting in the Celery logs EXCEPT that 2 of the workers can't connect to the broker:\n\n```\n[2011-06-12 22:41:08,033: ERROR/MainProcess] Consumer: Connection to broker lost. Trying to re-establish connection...\n```\n\nAll of the other nodes are able to connect without issue.\n\nI know that there was a posting ( RabbitMQ / Celery with Django hangs on delay/ready/etc - No useful log info ) last year of a similar nature, but I'm pretty certain that this is different. Could it be that the sheer number of workers is creating some sort of a race condition in `amqplib` -- I found this thread which seems to indicate that `amqplib` is not thread-safe, not sure if this matters for Celery.\n\n**EDIT:** I've tried `celeryctl purge` on both nodes -- on one it succeeds, but on the other it fails with the following AMQP error:\n\n```\nAMQPConnectionException(reply_code, reply_text, (class_id, method_id))\n amqplib.client_0_8.exceptions.AMQPConnectionException: \n (530, u\"NOT_ALLOWED - cannot redeclare exchange 'XXXXX' in vhost 'XXXXX' \n with different type, durable or autodelete value\", (40, 10), 'Channel.exchange_declare')\n```\n\nOn both nodes, `inspect stats` hangs with the \"can't close connection\" traceback above. I'm at a loss here.\n\n**EDIT2:** I was able to delete the offending exchange using `exchange.delete` from `camqadm` and now the second node hangs too :(.\n\n**EDIT3:** One thing that also recently changed is that I added an additional vhost to rabbitmq, which my staging node connects to.\n\n========================================\n\nTop Answer:\nI had the same symptoms, but not the same cause, for anyone else who stumbles up on this, mine was solved by https://stackoverflow.com/a/63591450/284164 -- I wasn't importing the celery app at the project level, and `.delay()` was hanging until I added that.\n\n========================================\n\nCode:\n```text\nFile \"/home/django/deployed/releases/20110608183345/virtual-env/lib/python2.5/site-packages/celery/task/base.py\", line 324, in delay\n return self.apply_async(args, kwargs)\nFile \"/home/django/deployed/releases/20110608183345/virtual-env/lib/python2.5/site-packages/celery/task/base.py\", line 449, in apply_async\n publish.close()\nFile \"/home/django/deployed/virtual-env/lib/python2.5/site-packages/kombu/compat.py\", line 108, in close\n self.backend.close()\nFile \"/home/django/deployed/virtual-env/lib/python2.5/site-packages/amqplib/client_0_8/channel.py\", line 194, in close\n (20, 41), # Channel.close_ok\nFile \"/home/django/deployed/virtual-env/lib/python2.5/site-packages/amqplib/client_0_8/abstract_channel.py\", line 89, in wait\n self.channel_id, allowed_methods)\nFile \"/home/django/deployed/virtual-env/lib/python2.5/site-packages/amqplib/client_0_8/connection.py\", line 198, in _wait_method\n self.method_reader.read_method()\nFile \"/home/django/deployed/virtual-env/lib/python2.5/site-packages/amqplib/client_0_8/method_framing.py\", line 212, in read_method\n self._next_method()\nFile \"/home/django/deployed/virtual-env/lib/python2.5/site-packages/amqplib/client_0_8/method_framing.py\", line 127, in _next_method\n frame_type, channel, payload = self.source.read_frame()\nFile \"/home/django/deployed/virtual-env/lib/python2.5/site-packages/amqplib/client_0_8/transport.py\", line 109, in read_frame\n frame_type, channel, size = unpack('>BHI', self._read(7))\nFile \"/home/django/deployed/virtual-env/lib/python2.5/site-packages/amqplib/client_0_8/transport.py\", line 200, in _read\n s = self.sock.recv(65536)\n```\n\n```text\n=INFO REPORT==== 12-Jun-2011::22:58:12 ===\naccepted TCP connection on 0.0.0.0:5672 from x.x.x.x:48569\n```\n\n```text\n[2011-06-12 22:41:08,033: ERROR/MainProcess] Consumer: Connection to broker lost. Trying to re-establish connection...\n```\n\n```text\nAMQPConnectionException(reply_code, reply_text, (class_id, method_id))\n amqplib.client_0_8.exceptions.AMQPConnectionException: \n (530, u\"NOT_ALLOWED - cannot redeclare exchange 'XXXXX' in vhost 'XXXXX' \n with different type, durable or autodelete value\", (40, 10), 'Channel.exchange_declare')\n```\n\n```text\n.delaay()\n```\n\n```text\nINFO\n```\n\n```text\namqplib\n```\n\n```text\namqplib\n```\n\n```text\nceleryctl purge\n```\n\n```text\ninspect stats\n```\n\n```text\nexchange.delete\n```\n\n```text\ncamqadm\n```\n\n```text\n/var\n```\n\n```text\n/var\n```\n\n```text\n/var/lib/rabbitmq\n```\n\n```text\n.delay()\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.187Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":16,"totalLines":158,"estimatedTokens":1734}}748{"id":"stack-71960751","source":"stackoverflow","questionId":71960751,"title":"How to have more than 50 000 messages in a RabbitMQ Queue","tags":["rabbitmq","rabbitmq-exchange"],"text":"Title: How to have more than 50 000 messages in a RabbitMQ Queue\nTags: rabbitmq, rabbitmq-exchange\nSource: Stack Overflow\n\nQuestion:\nWe have currently using a service bus in Azure and for various reasons, we are switching to RabbitMQ.\nUnder heavy load, and when specific tasks on backend are having problem, one of our queues can have up to 1 million messages waiting to be processed.\n\nRabbitMQ can have a maximum of 50 000 messages per queue.\nThe question is how can we design the rabbitMQ infrastructure to continue to work when messages are temporarily accumulating?\n\nNote: we want to host our RabbitMQ server in a docker image inside a kubernetes cluster.\nwe imagine an exchange that would load balance mesages between queues in nodes behind.\nBut what is unclear to us is how to dynamically add new queues on demand if we detect that queues are getting full.\n\n========================================\n\nTop Answer:\nA RabbitMQ queue will never be \"full\" (no such limitation exists in the software). A queue's maximum length rather depends on:\n\n- Queue settings (e.g `max-length`/`max-length-bytes`)\n\n- Message expiration settings such as `x-message-ttl`\n\n- Underlying hardware & cluster setup (available RAM and disk space).\n\nUnless you are using Streams (new feature in v 3.9) you should always try to keep your queues short (if possible). The entire idea of a Message Queue (in it's classical sense) is that a message should be passed along as soon as possible.\n\nTherefore, if you find yourself with long queues you should rather try to match the load of your producers by adding more consumers.\n\n========================================\n\nCode:\n```text\nmax-length\n```\n\n```text\nmax-length-bytes\n```\n\n```text\nx-message-ttl\n```\n\n========================================\n\nComments:\n- yes, tested. I could create 1 Million messages in a queue. The 50 000 messages limlit came from a misleading information from cloudamqp.com/blog/part1-rabbitmq-best-practice.html\n- I will investigate the streams option. What I like is the persistence and the fact that messages will not be lost if the RabbitMQ server is restarted by k8s.","metadata":{"transformedAt":"2026-08-18T18:33:20.187Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":50,"estimatedTokens":531}}749{"id":"stack-24899772","source":"stackoverflow","questionId":24899772,"title":"How do I permanently remove a celery task from rabbitMQ?","tags":["python","rabbitmq","celery","amqp","django-celery"],"text":"Title: How do I permanently remove a celery task from rabbitMQ?\nTags: python, rabbitmq, celery, amqp, django-celery\nSource: Stack Overflow\n\nQuestion:\nI have around 10,000 scheduled tasks on my current celery setup. I didn't realize what scheduled tasks were and decided to use them to send -up emails months in advance.\n\nLooking back, it's probably never a good idea to schedule a task for more than 1 hour in the future as every time you restart a worker it has to re-receive every scheduled task from rabbitMQ and then they all just sit in the memory.\n\nMy problem is that if I have to revoke a task, it doesn't just delete it. The task stays in memory but a revoke queue now contains the ID of the task. When it is up for execution, celery checks to see if it is revoked and if it is, it will revoke it at this point.\n\nHowever, the task will still stay in memory up until then, and if I restart my worker at anytime, the revoke queue will be cleared as I didn't make it persistent.\n\n**How do I permanently remove a task from my celery worker? I essentially just need to send an acknowledged back to rabbitMQ so rabbit removes it for once and for all and if I restart celery it won't come back.**\n\nI've looked in the docs and source code and tried to do it myself in the shell but I can't figure out the proper place for acking a task to rabbitMQ and then popping it forever.\n\n========================================\n\nTop Answer:\n1.\nTo properly purge the queue of waiting tasks you have ***MUST*** to stop all the workers (http://celery.readthedocs.io/en/latest/faq.html#i-ve-purged-messages-but-there-are-still-messages-left-in-the-queue):\n\n```\n$ sudo rabbitmqctl stop\n```\n\nor (in case RabbitMQ/message broker is managed by Supervisor):\n\n```\n$ sudo supervisorctl stop all\n```\n\n2. \n...and then purge the tasks from a specific queue:\n\n```\n$ cd \n$ celery amqp queue.purge \n```\n\n3.\nStart RabbitMQ:\n\n```\n$ sudo rabbitmqctl start\n```\n\nor (in case RabbitMQ is managed by Supervisor):\n\n```\n$ sudo supervisorctl start all\n```\n\n========================================\n\nCode:\n```text\n$ celery -A proj purge\n```\n\n```text\n>>> from proj.celery import app\n>>> app.control.purge()\n1753\n```\n\n```text\n$ celery -A proj amqp queue.purge <queue name>\n```\n\n```text\n@task\ndef my_old_task()\n pass\n```\n\n```text\n--purge\n```\n\n```text\n$ sudo rabbitmqctl stop\n```\n\n```text\n$ sudo supervisorctl stop all\n```\n\n```text\n$ cd <source_dir>\n$ celery amqp queue.purge <queue name>\n```\n\n```text\n$ sudo rabbitmqctl start\n```\n\n```text\n$ sudo supervisorctl start all\n```\n\n========================================\n\nComments:\n- Did you find a way to do this?\n- This purges everything. I want to just get rid of a single task\n- Yes, exactly. If you have been using other tasks, this won't work, and I don't know any clean way to delete the tasks from queue, but you can always ignore them. Will update my answer\n- What is proj ? Please document\n- proj would just be your django project\n- As of Celery 4.1 `proj_app.control.purge()` returns 0. `celery -A proj_app purge` does nothing.","metadata":{"transformedAt":"2026-08-18T18:33:20.187Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":111,"estimatedTokens":762}}750{"id":"stack-22134173","source":"stackoverflow","questionId":22134173,"title":"Batch message from a rabbitMQ queue","tags":["python","rabbitmq"],"text":"Title: Batch message from a rabbitMQ queue\nTags: python, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have a stream of requests in my RabbitMQ cluster, and multiple consumers handling them. The thing is - each consumer must handle requests in batches for performance reasons. Specifically there is a network IO operation that I can amortize by batching requests.\n\nSo, each consumer would like to maximize the number of requests that it can batch, but not add too much latency.\n\nI could potentially start a timer when a consumer receives the first request and keep collecting requests until one of the two things happen - timer expires, or 500 requests have been received.\n\nIs there a better way to achieve this - without blocking each consumer?\n\n========================================\n\nCode:\n```text\nbasic.qos(prefetch-size, prefetch-count)\n```\n\n```text\nbasic.ack()\n```\n\n```text\nbasic.ack(delivery-tag=n, multiple=True)\n```\n\n========================================\n\nComments:\n- Thanks ifLoop. Would you recommend async callback mechanism to retrieve the messages or the sync get?\n- you should always use `basic.consume` in favor of `basic.get`; prefetch does not apply to `basic.get`. If it makes sense, you should design your application in an async style, since amqp is more amenable to that model.","metadata":{"transformedAt":"2026-08-18T18:33:20.187Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":33,"estimatedTokens":326}}751{"id":"stack-32735174","source":"stackoverflow","questionId":32735174,"title":"Token based authentication for MQTT Broker","tags":["authentication","rabbitmq","mqtt","mosquitto"],"text":"Title: Token based authentication for MQTT Broker\nTags: authentication, rabbitmq, mqtt, mosquitto\nSource: Stack Overflow\n\nQuestion:\nI want to implement a token based Authentication mechanism for clients of a MQTT broker. \n\nI must have client token provisioning as a separate service, then in the `CONNECT` message sent from the client, I intend to include the token. \n\nThen ideally the broker should authenticate from the identity/token provider and send the `CONNACK`accordingly. \n\n- I have considered `mosquitto` , `RabbitMQ` and `MOSCA` so far. What would be the ideal broker for the scenario above?\n\n- Are there any loopholes or improvements to the scenario I described?\n\n========================================\n\nCode:\n```text\nCONNECT\n```\n\n```text\nCONNACK\n```\n\n```text\nmosquitto\n```\n\n```text\nRabbitMQ\n```\n\n```text\nMOSCA\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.187Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":37,"estimatedTokens":207}}752{"id":"stack-24795180","source":"stackoverflow","questionId":24795180,"title":"Objective-C RabbitMQ client not publishing messages to queue","tags":["ios","objective-c","rabbitmq","amqp"],"text":"Title: Objective-C RabbitMQ client not publishing messages to queue\nTags: ios, objective-c, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI am trying to make a messaging application using, RabbitMQ for iOS.\nand i am using this wrapper classes for objective c, with RabbitMQ-C client libraries. \n\nhttps://github.com/profmaad/librabbitmq-objc\n\nExchange, Queue & Queue Binding all are ok but my code is not publishing message to RabbitMQ server. Please help me , what is the problem?\n\nthis is my code:\n\n```\nNSError *error= nil;\n\n AMQPConnection *connection = [[AMQPConnection alloc] init];\n\n [connection connectToHost:@\"SERVER_NAME\" onPort:PORT error:&error];\n\n if (error != nil){\n NSLog(@\"Error connection: %@\", error);\n return;\n }\n\n [connection loginAsUser:@\"USER_NAME\" withPasswort:@\"PASSWORD\" onVHost:@\"/\" error:&error];\n\n if (error != nil){\n NSLog(@\"Error logined: %@\", error);\n return;\n }\n\n AMQPChannel *channel = [connection openChannel];\n\n AMQPExchange *exchange = [[AMQPExchange alloc] initFanoutExchangeWithName:@\"EXCHANGE_NAME\" onChannel:channel isPassive:NO isDurable:NO getsAutoDeleted:NO error:&error];\n\n if (error != nil){\n NSLog(@\"Error declareExchange: %@\", error);\n return;\n }\n\n //AMQPQueue *queue = [[AMQPQueue alloc] initWithName:@\"NAME\" onChannel:channel isPassive:NO isExclusive:NO isDurable:YES getsAutoDeleted:YES error:&error];\n AMQPQueue *queue = [[AMQPQueue alloc] initWithName:@\"NAME\" onChannel:[connection openChannel]];\n if (error != nil){\n NSLog(@\"Error declare Queue: %@\", error);\n return;\n }\n\n NSError *error ;\n [queue bindToExchange:exchange withKey:@\"KEY\" error:&error];\n\n amqp_basic_properties_t props;\n props._flags= AMQP_BASIC_CLASS;\n props.type = amqp_cstring_bytes([@\"typeOfMessage\" UTF8String]);\n props.priority = 1;\n [exchange publishMessage:@\"Test message\" usingRoutingKey:@\"ROUTING_KEY\" propertiesMessage:props mandatory:NO immediate:NO error:&error];\n if (error != nil){\n NSLog(@\"Error declareExchange: %@\", error);\n return;\n }\n```\n\n========================================\n\nCode:\n```text\nNSError *error= nil;\n\n AMQPConnection *connection = [[AMQPConnection alloc] init];\n\n [connection connectToHost:@\"SERVER_NAME\" onPort:PORT error:&error];\n\n if (error != nil){\n NSLog(@\"Error connection: %@\", error);\n return;\n }\n\n [connection loginAsUser:@\"USER_NAME\" withPasswort:@\"PASSWORD\" onVHost:@\"/\" error:&error];\n\n if (error != nil){\n NSLog(@\"Error logined: %@\", error);\n return;\n }\n\n AMQPChannel *channel = [connection openChannel];\n\n\n AMQPExchange *exchange = [[AMQPExchange alloc] initFanoutExchangeWithName:@\"EXCHANGE_NAME\" onChannel:channel isPassive:NO isDurable:NO getsAutoDeleted:NO error:&error];\n\n if (error != nil){\n NSLog(@\"Error declareExchange: %@\", error);\n return;\n }\n\n\n\n //AMQPQueue *queue = [[AMQPQueue alloc] initWithName:@\"NAME\" onChannel:channel isPassive:NO isExclusive:NO isDurable:YES getsAutoDeleted:YES error:&error];\n AMQPQueue *queue = [[AMQPQueue alloc] initWithName:@\"NAME\" onChannel:[connection openChannel]];\n if (error != nil){\n NSLog(@\"Error declare Queue: %@\", error);\n return;\n }\n\n\n\n NSError *error ;\n [queue bindToExchange:exchange withKey:@\"KEY\" error:&error];\n\n amqp_basic_properties_t props;\n props._flags= AMQP_BASIC_CLASS;\n props.type = amqp_cstring_bytes([@\"typeOfMessage\" UTF8String]);\n props.priority = 1;\n [exchange publishMessage:@\"Test message\" usingRoutingKey:@\"ROUTING_KEY\" propertiesMessage:props mandatory:NO immediate:NO error:&error];\n if (error != nil){\n NSLog(@\"Error declareExchange: %@\", error);\n return;\n }\n```\n\n```text\n#import \"AMQPExchange.h\"\n#import \"AMQPConsumer.h\"\n#import \"AMQPConnection.h\"\n#import \"AMQPConsumerThread.h\"\n#import \"AMQPChannel.h\"\n#import \"AMQPQueue.h\"\n#import \"AMQPMessage.h\"\n```\n\n```text\n#define host @\"localhost\"\n#define routingQueue @\"CreateQueue\"\n#define port 5672\n#define user @\"guest\"\n#define pass @\"guest\"\n```\n\n```text\n- (IBAction)send:(id)sender {\n\n NSError *error= nil;\n NSError *error2 = nil;\n NSError *error3 = nil;\n NSError *error4 = nil;\n\n AMQPConnection *connection = [[AMQPConnection alloc] init];\n [connection connectToHost:host onPort:port error:&error];\n\n if (error != nil){\n NSLog(@\"Error connection: %@\", error);\n return;\n }\n\n [connection loginAsUser:user withPasswort:pass onVHost:@\"/\" error:&error];\n\n if (error != nil){\n NSLog(@\"Error logined: %@\", error);\n return;\n }\n\n\n AMQPChannel *channel = [connection openChannelError:&error2];\n\n AMQPExchange *exchange = [[AMQPExchange alloc] initDirectExchangeWithName:@\"AMQP\" onChannel:channel isPassive:NO isDurable:NO getsAutoDeleted:NO error:&error];\n\n\n if (error != nil){\n NSLog(@\"Error declareExchange: %@\", error);\n return;\n }\n\n\n AMQPQueue *queue = [[AMQPQueue alloc] initWithName:routingQueue onChannel:channel error:&error3];\n if (error != nil){\n NSLog(@\"Error declare Queue: %@\", error);\n return;\n }\n\n\n BOOL success = [queue bindToExchange:exchange withKey:routingQueue error:&error4];\n\n if (success) {\n amqp_basic_properties_t props;\n props._flags = AMQP_BASIC_CONTENT_TYPE_FLAG | AMQP_BASIC_DELIVERY_MODE_FLAG;\n props.content_type = amqp_cstring_bytes(\"text/plain\");\n props.delivery_mode = 2;\n props.priority = 1;\n\n //Here put your message to publish...\n\n [exchange publishMessage:@\"YOUR MESSAGE\" usingRoutingKey:routingQueue propertiesMessage:props mandatory:NO immediate:NO error:&error];\n\n if (error != nil){\n NSLog(@\"Error declareExchange: %@\", error);\n return;\n }\n }\n}\n```\n\n```text\n-(IBAction)receiveMessage:(id)sender\n{\n NSError *error= nil;\n NSError *error2 = nil;\n NSError *error3 = nil;\n NSError *error4 = nil;\n\n AMQPConnection *connection = [[AMQPConnection alloc] init];\n [connection connectToHost:host onPort:port error:&error];\n [connection loginAsUser:user withPasswort:pass onVHost:@\"/\" error:&error];\n\n AMQPChannel *channel = [connection openChannelError:&error2];\n AMQPQueue *queue = [[AMQPQueue alloc] initWithName:routingQueue onChannel:channel isPassive:NO isExclusive:NO isDurable:NO getsAutoDeleted:NO error:&error3];\n\n AMQPConsumer *consumer = [[AMQPConsumer alloc] initForQueue:queue onChannel:&channel useAcknowledgements:YES isExclusive:NO receiveLocalMessages:NO error:&error4 deepLoop:1];\n\n AMQPConsumerThread *consumerThread = [[AMQPConsumerThread alloc] initWithConsumer:consumer delegate:self nameThread:@\"myThread\" persistentListen:NO];\n\n consumerThread.delegate=self;\n\n [consumerThread start];\n}\n\n\n-(void)amqpConsumerThreadReceivedNewMessage:(AMQPMessage *)theMessage\n{\n NSLog(@\"message = %@\", theMessage.body);\n}\n```\n\n========================================\n\nComments:\n- Did you declared exchange as expected? Did you declared queue as expected? Did bind queue to exchange as expected? Do you publish message to appropriate exchange? Can your message be routed to expected queue? Do you have some consumers that stole your message? Are there any exceptions thrown from application? Are there any suspicious output in RabbitMQ log? - These questions often save my time and neurons to find the reason why some magic happens.\n- Thanks zaq178miami, i am using EXCHANGE NAME = \"fanout\" , BINDING KEY = \"hello\", ROUTING KEY = \"hello\" and QUEUE = \"11111\" i have also tried this project: github.com/leisurehuang/RabbitMQ-IOS-lib Same problem. It is making everything on RabbitMQ server but not publishing any message to the queue. And i have no consumer thread running, no exception on xcode. i am confused it is a server problem or there is something i am missing?\n- Those question are for you to help debug the reason. Anyway, try to publish to default exchange (with empty name) with routing key equals to queue name, it's a quick and dirty way to put message to exact queue you want.\n- zaq178miami , i am now using the same way what you have suggested. And getting some exceptions in Xcode. Please suggest me what i should do now? i am new in RabbitMQ. Exceptions: AMQPException: Failed to bind queue to exchange: ACCESS_REFUSED - operation not permitted on the default exchange AMQPException: Failed to publish message: ACCESS_REFUSED - operation not permitted on the default exchange Error declareExchange: Error Domain=AMQPExchange Code=-10 \"Failed to publish message:\" UserInfo=0x8f41250 {NSLocalizedDescription=Failed to publish message:}\n- To publish to the default exchange you don't need to perform the binding. Deleting the `queue bindToExchange` line should help\n- I have solved it. Actually there was a problem with `amqp_basic_properties_t props;` Then i tried with `amqp_basic_properties_t props; props._flags = AMQP_BASIC_CONTENT_TYPE_FLAG | AMQP_BASIC_DELIVERY_MODE_FLAG; props.content_type = amqp_cstring_bytes(\"text/plain\"); props.delivery_mode = 2; props.priority = 1;` **it is working now.** @zaq178miami and @old_sound Thanks for helping me.\n- is this port number specific ??\n- how to add this library in Swift ?? I am tried adding it using the Bridging-Header.h file. it giving a lot of error. ex '/Users/Adonta/moojic_workspace/moojicapp2/moojicapp2/amqp.h‌​:243:49: error: unknown type name 'size_t' extern void *amqp_pool_alloc(amqp_pool_t *pool, size_t amount);'\n- I am also struck in the above question. I have all library file,, still I am receiving,,, file not found @jeevs\n- @McDonal_11 No i was not able to find a solution. I switched to a different library.\n- stackoverflow.com/questions/38259528/… @jeevs . Kindly guide me on this.\n- @Nil kindly guide me on the above comment\n- the dropbox link is not working. can you Please the link again","metadata":{"transformedAt":"2026-08-18T18:33:20.187Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":248,"estimatedTokens":2453}}753{"id":"stack-13543092","source":"stackoverflow","questionId":13543092,"title":"Sending emails asynchronously: spool, queue, and cronjob/daemon","tags":["symfony","rabbitmq","daemon","amqp","swiftmailer"],"text":"Title: Sending emails asynchronously: spool, queue, and cronjob/daemon\nTags: symfony, rabbitmq, daemon, amqp, swiftmailer\nSource: Stack Overflow\n\nQuestion:\nI want to send emails asynchronously for faster and lighter http responses, but I'm struggling with many new concepts.\n\nFor example, the documentation talks about spool. It says I should use spool with a file, and then send emails with a command. But how should I be running that command? If I set a cronjob to execute that command every 1 minute (the minimum available in `cron`), users will have to wait an average of 30 secs for their emails to be sent (eg, the registration email).\n\nSo I thought of using a queue instead. I'm already using RabbitMQBundle for image processing (eg, thumbnail creation). But I only use this one periodically, so it is consumed from within a cronjob.\n\nMaybe I should create a daemon that is always waiting for new messages to arrive the email queue and deliver them ASAP?\n\n========================================\n\nTop Answer:\nI have the same problem as you had. How you finally solved your problem? \n\nFor the moment I run a little script in the crontab in order to run in loop:\n\n```\nlock()) {\n system('cd /var/www && php app/console swiftmailer:spool:send');\n sleep(1);\n $lock->release();\n shell_exec('cd /var/www && php LoopMailer.php > /dev/null 2>/dev/null &');\n}\n```\n\nIt's not very clean but it does his job.\n\n========================================\n\nCode:\n```text\ncron\n```\n\n```text\n<?php\ninclude('/var/www/vendor/symfony/symfony/src/Symfony/Component/Filesystem/LockHandler.php');\nuse Symfony\\Component\\Filesystem\\LockHandler;\n\n$lock = new LockHandler('mailer:loop');\nif ($lock->lock()) {\n system('cd /var/www && php app/console swiftmailer:spool:send');\n sleep(1);\n $lock->release();\n shell_exec('cd /var/www && php LoopMailer.php > /dev/null 2>/dev/null &');\n}\n```\n\n========================================\n\nComments:\n- What's the problem with 30sec delay? It's exactly as you said: a cron job execute a command every 1 minute, and the command itself is going to elaborate the queue.\n- @Gremo The problem is that if there isn't much load in the server, I should be able to send the registration emails immediately. The same happens with image processing, imagine that I accept image uploads from the users. Making them wait 30 secs (let alone 1 min) for each submission will hurt the user experience.\n- Then there is no need for a demon I think. You can spool and fire the command immediately and asynchronously from PHP itself.\n- @Gremo That will create one process per email, not good.\n- Thanks but this is not what I want. I want to spool/queue all the emails, to avoid injecting switfmailer (it's very heavy) on every request that triggers the sending of an email. I think the ideal solution is to add a message to the Rabbit message queue, and the daemon takes care of sending the email. This way, if I have say just 1 email request every 5 seconds, the queue will work very fast and will send emails instantly. If suddenly I get 999 email requests in 1 second, my server won't suffer: users will have to wait for their emails, but the http responses will still be blazing fast.\n- Yes I solved it by using the Rabbit message queue I mentioned. Anything that is asynchronous I send it to a queue which is consumed either by a cronjob or a daemon (which I manage with the linux program \"sv\").\n- In my case I don't see any reason to use RabbitMQ. What is the purpose to use it, is the database not enough? I don't see also what RabbitMQ has to do with solving the 1 min problem?\n- With RabbitMQ I send the emails as soon as they are consumed in the queue, instead of every 1 min.\n- But RabbitMQ is not able to send email, it's a simple queuing system. Therefor you must have a service consuming this queue?? I don't really get it...\n- Yes that's what \"daemon\" means.\n- But what the advantage of RabbitMQ compare to the spool database? And could you give us more details concerning your service? Actually your service is the most interesting point of your solution ;-)\n- With spool and cronjob you have to wait an average of 30 seconds (between 0 and 60 seconds) for the mail to be delivered. With a queue and a daemon that consumes it they will be sent as soon as possible. My service is very simple, it just takes items out of the queue, where each item is an array with from, to, body, etc., and sends that email. I'm using Thumper which makes Rabbit easier to use: github.com/videlalvaro/Thumper . And I make sure the service is always up using 'sv' (from Runit): smarden.org/runit/sv.8.html . You can use any other service or daemon manager you like.","metadata":{"transformedAt":"2026-08-18T18:33:20.187Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":67,"estimatedTokens":1167}}754{"id":"stack-2141083","source":"stackoverflow","questionId":2141083,"title":"RabbitMQ / Celery with Django hangs on delay/ready/etc - No useful log info","tags":["python","django","rabbitmq","celery"],"text":"Title: RabbitMQ / Celery with Django hangs on delay/ready/etc - No useful log info\nTags: python, django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nSo I just setup celery and rabbitmq, created my user, setup the vhost, mapped the user to the vhost, and ran the celery daemon succesfully (or so I assume)\n\n```\n(queuetest)corky@corky-server:~/projects/queuetest$ ./manage.py celeryd\n celery@corky-server v0.9.5 is starting.\n Configuration ->\n. broker -> amqp://celery@localhost:5672/\n. queues ->\n. celery -> exchange:celery (direct) binding:celery\n. concurrency -> 2\n. loader -> celery.loaders.djangoapp\n. logfile -> [stderr]@WARNING\n. events -> OFF\n. beat -> OFF\n\nCelery has started.\n```\n\nI created a user of \"celery\" because I wasn't feeling very inventive in this case. \n\nWhen I try to do one of the simple examples within the celery docs:\n\n```\n>>> from tasks import add\n>>> r = add.delay(2, 2)\n>>> r\n\n>>> r.ready()\n(hangs for eternity.)\n```\n\nSo I checked the FAQ wondering what else could be up and it told me this is a common bug due to user permissions, so I triple checked those, nothing, made another new user, still nothing. If I import `DjangoBrokerConnection` from `carrot.connection` and get the information, it matches up with what's in my celery settings. The FAQ stated to check your log file.\n\nMy `rabbit.log` file isn't very helpful in this situation, simply showing:\n\n```\n=INFO REPORT==== 26-Jan-2010::11:58:22 ===\naccepted TCP connection on 0.0.0.0:5672 from 127.0.0.1:60572\n\n=INFO REPORT==== 26-Jan-2010::11:58:22 ===\nstarting TCP connection from 127.0.0.1:60572\n```\n\nAnd so forth. At this point, I'm at a loss as to what else my problem could be. I'm running Ubuntu Jaunty and installed RabbitMQ from apt-get.\n\nThanks in advance for any help.\n\n========================================\n\nTop Answer:\nFor anyone stumbling upon this: it really does seem to help to remove your /var/lib/rabbitmq, even if the problem seems to go away with updating celery. I was seeing lots of unreliability and unpredictability until I did so.\n\n========================================\n\nCode:\n```text\n(queuetest)corky@corky-server:~/projects/queuetest$ ./manage.py celeryd\n celery@corky-server v0.9.5 is starting.\n Configuration ->\n. broker -> amqp://celery@localhost:5672/\n. queues ->\n. celery -> exchange:celery (direct) binding:celery\n. concurrency -> 2\n. loader -> celery.loaders.djangoapp\n. logfile -> [stderr]@WARNING\n. events -> OFF\n. beat -> OFF\n\nCelery has started.\n```\n\n```text\n>>> from tasks import add\n>>> r = add.delay(2, 2)\n>>> r\n<AsyncResult: 16235ea3-c7d6-4cce-9387-5c6285312c7c>\n>>> r.ready()\n(hangs for eternity.)\n```\n\n```text\n=INFO REPORT==== 26-Jan-2010::11:58:22 ===\naccepted TCP connection on 0.0.0.0:5672 from 127.0.0.1:60572\n\n=INFO REPORT==== 26-Jan-2010::11:58:22 ===\nstarting TCP connection <0.1120.0> from 127.0.0.1:60572\n```\n\n```text\nDjangoBrokerConnection\n```\n\n```text\ncarrot.connection\n```\n\n```text\nrabbit.log\n```\n\n```text\n/var/lib/rabbitmq\n```\n\n```text\nrouting_key\n```\n\n========================================\n\nComments:\n- Try to run celeryd with --loglevel=INFO, so you can see if the task is being received and processed or not. Also, what result backend are you using?\n- Thank you .. sorry for the late reply, wow I've been busy! But this worked. Also, grats on the 1.0 release :)\n- Got me on this one as well :>","metadata":{"transformedAt":"2026-08-18T18:33:20.187Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":119,"estimatedTokens":839}}755{"id":"stack-50094705","source":"stackoverflow","questionId":50094705,"title":"Failover with Spring AMQP and RabbitMQ HA","tags":["rabbitmq","failover","spring-rabbit"],"text":"Title: Failover with Spring AMQP and RabbitMQ HA\nTags: rabbitmq, failover, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nThere are multiple articles suggesting that load-balancer should be used in front of RabbitMQ cluster.\n\nHowever, there are also multiple references that Spring AMQP is using some \nfailover implementation like connection reset when broker comes back to life.\n\nI have several questions regarding this topic (given that those articles are more or less old and it's 2018 today)\n\nWhen using Spring AMQP, is it load-balancing for still required?\n\nIf load-balancing is still suggested, how would I solve affinity of primary queue to its node? There would be much inter-connect between cluster nodes, because round-robin load-balancer would have 1-(1/n) success rate of hitting correct cluster node\n\nDoes Spring AMQP support some kind of topology awareness, which would allow it to consume from correct node? \n\nThere were some articles suggesting that clients should publish/consume to nodes respecting locality of queues. Does this still apply? How does this all fits together given load-balancing, Spring AMQP failover and CachingConnectionFactory?\n\nCan anybody please provide answers to those topics and also provide relevant references, which would provide additional information for verification?\n\nThanks a lot\n\n========================================\n\nCode:\n```text\nRabbitTemplate\n```\n\n========================================\n\nComments:\n- Thanks, your suggestion about premature optimisation using topology-aware factories is more than reasonable. I have one supplementary question though. Does CachingConnectionFactory reconnect to nodes that are once again alive? I remember some article mentioning, that it didn't connect to reconnected node. That's why LocalizedQueueConnectionFactory was suggested. Does CachingConnectionFactory support reasonable client-based load balancing? How does it connect to nodes from provided list? Is it round-robin, random or does it always connect to the first one and then to the second one as failover?\n- The CCF only reconnects if the current connection is lost (or the cache is empty when using the connection cache). For this reason, it doesn't fail-back after failing over until the new connection is lost. It does not load balance, it starts from the first and proceeds down the list whenever a new connection is needed. Feel free to open an 'improvement' JIRA Issue - we could add a load balancing strategy property. In the mean time you could write an external task to shuffle the `Addresses[]` property from time-to-time.\n- Yeah, that was my idea also. Thanks for all your answers","metadata":{"transformedAt":"2026-08-18T18:33:20.187Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":37,"estimatedTokens":662}}756{"id":"stack-48543614","source":"stackoverflow","questionId":48543614,"title":"Receiving RabbitMQ messages in PHPRatchet","tags":["php","websocket","rabbitmq","ratchet"],"text":"Title: Receiving RabbitMQ messages in PHPRatchet\nTags: php, websocket, rabbitmq, ratchet\nSource: Stack Overflow\n\nQuestion:\nI am **trying to achieve** mechanism where PHP pushes message to RabbitMQ (I don't want RabbitMQ to be directly exposed to user), RabbitMQ connects to RatchetPHP and Ratchet broadcasts it via websocket connections to users.\n\nThe **issue** I have is with accually making Ratchet server to simultanously listen for queue messages and transfer them further. Ratchet documentation assumes using ZeroMQ and after a long search through outdated documentations and libraries which do not have such methods anymore (eg. `React\\Stomp`) I need fresh eyes from someone who has experience with these solutions.\n\nWhat I have is `pusher.php` (standard example from RabbitMQ docs):\n\n```\nuse PhpAmqpLib\\Connection\\AMQPStreamConnection;\nuse PhpAmqpLib\\Message\\AMQPMessage;\n\n$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');\n\n$channel = $connection->channel();\n$channel->queue_declare('hello', false, false, false, false);\n$msg = new AMQPMessage('Hello World!');\n$channel->basic_publish($msg, '', 'hello');\necho \" [x] Sent 'Hello World!'\\n\";\n\n$channel->close();\n$connection->close();\n```\n\nJust to simplify reproducing scenario I include also `Chat` class:\n\n```\nuse Ratchet\\ConnectionInterface;\nuse Ratchet\\MessageComponentInterface;\n\nclass Chat implements MessageComponentInterface\n{\n protected $clients;\n\n public function __construct()\n {\n $this->clients = new \\SplObjectStorage;\n }\n\n public function onOpen(ConnectionInterface $connection)\n {\n // Store the new connection to send messages to later\n $this->clients->attach($connection);\n\n echo \"New connection! ({$connection->resourceId})\\n\";\n }\n\n public function onMessage(ConnectionInterface $from, $msg)\n {\n $numRecv = count($this->clients) - 1;\n echo sprintf('Connection %d sending message \"%s\" to %d other connection%s'.\"\\n\"\n , $from->resourceId, $msg, $numRecv, $numRecv == 1 ? '' : 's');\n\n foreach($this->clients as $client)\n {\n /** @var \\SplObjectStorage $client */\n if($from !== $client)\n {\n // The sender is not the receiver, send to each client connected\n $client->send($msg);\n }\n }\n }\n\n public function onClose(ConnectionInterface $conn)\n {\n // The connection is closed, remove it, as we can no longer send it messages\n $this->clients->detach($conn);\n\n echo \"Connection {$conn->resourceId} has disconnected\\n\";\n }\n\n public function onError(ConnectionInterface $conn, \\Exception $e)\n {\n echo \"An error has occurred: {$e->getMessage()}\\n\";\n\n $conn->close();\n }\n}\n```\n\nAnd Ratchet `server.php` (standard Ratchet example and RabbitMQ receiver example):\n\n```\nuse PhpAmqpLib\\Connection\\AMQPStreamConnection;\nuse Src\\Chat;\n\n// RABBIT_RECEIVER\n$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');\n\n$channel = $connection->channel();\n$channel->queue_declare('hello', false, false, false, false);\necho ' [*] Waiting for messages. To exit press CTRL+C', \"\\n\";\n\n$callback = function ($msg)\n{\n echo \" [x] Received \", $msg->body, \"\\n\";\n};\n\n$channel->basic_consume('hello', '', false, true, false, false, $callback);\nwhile(count($channel->callbacks))\n{\n $channel->wait();\n}\n\n$channel->close();\n$connection->close();\n// RABBIT_RECEIVER END\n\n$server = new \\Ratchet\\App('sockets.dev');\n$server->route('/', new Chat());\n\n$server->run();\n```\n\nCurrent versions are basically 2 separate mechanisms listening for messages and they work great alone (so no issue there) except that they block each other and do not transfer messages between.\n\n**Question** is how to make `server.php` to make RabbitMQ receive message and plug it into running Ratchet server.\n\n========================================\n\nCode:\n```text\nuse PhpAmqpLib\\Connection\\AMQPStreamConnection;\nuse PhpAmqpLib\\Message\\AMQPMessage;\n\n$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');\n\n$channel = $connection->channel();\n$channel->queue_declare('hello', false, false, false, false);\n$msg = new AMQPMessage('Hello World!');\n$channel->basic_publish($msg, '', 'hello');\necho \" [x] Sent 'Hello World!'\\n\";\n\n$channel->close();\n$connection->close();\n```\n\n```text\nuse Ratchet\\ConnectionInterface;\nuse Ratchet\\MessageComponentInterface;\n\nclass Chat implements MessageComponentInterface\n{\n protected $clients;\n\n public function __construct()\n {\n $this->clients = new \\SplObjectStorage;\n }\n\n public function onOpen(ConnectionInterface $connection)\n {\n // Store the new connection to send messages to later\n $this->clients->attach($connection);\n\n echo \"New connection! ({$connection->resourceId})\\n\";\n }\n\n public function onMessage(ConnectionInterface $from, $msg)\n {\n $numRecv = count($this->clients) - 1;\n echo sprintf('Connection %d sending message \"%s\" to %d other connection%s'.\"\\n\"\n , $from->resourceId, $msg, $numRecv, $numRecv == 1 ? '' : 's');\n\n foreach($this->clients as $client)\n {\n /** @var \\SplObjectStorage $client */\n if($from !== $client)\n {\n // The sender is not the receiver, send to each client connected\n $client->send($msg);\n }\n }\n }\n\n public function onClose(ConnectionInterface $conn)\n {\n // The connection is closed, remove it, as we can no longer send it messages\n $this->clients->detach($conn);\n\n echo \"Connection {$conn->resourceId} has disconnected\\n\";\n }\n\n public function onError(ConnectionInterface $conn, \\Exception $e)\n {\n echo \"An error has occurred: {$e->getMessage()}\\n\";\n\n $conn->close();\n }\n}\n```\n\n```text\nuse PhpAmqpLib\\Connection\\AMQPStreamConnection;\nuse Src\\Chat;\n\n// RABBIT_RECEIVER\n$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');\n\n$channel = $connection->channel();\n$channel->queue_declare('hello', false, false, false, false);\necho ' [*] Waiting for messages. To exit press CTRL+C', \"\\n\";\n\n$callback = function ($msg)\n{\n echo \" [x] Received \", $msg->body, \"\\n\";\n};\n\n$channel->basic_consume('hello', '', false, true, false, false, $callback);\nwhile(count($channel->callbacks))\n{\n $channel->wait();\n}\n\n$channel->close();\n$connection->close();\n// RABBIT_RECEIVER END\n\n$server = new \\Ratchet\\App('sockets.dev');\n$server->route('/', new Chat());\n\n$server->run();\n```\n\n```text\nReact\\Stomp\n```\n\n```text\npusher.php\n```\n\n```text\nChat\n```\n\n```text\nserver.php\n```\n\n```text\nserver.php\n```\n\n```text\n$loop = React\\EventLoop\\Factory::create();\n$chat = new Chat($loop);\n\n$server = new \\Ratchet\\App('sockets.dev', 8080, '127.0.0.1', $loop);\n$server->route('/', $chat);\n\n$server->run();\n```\n\n```text\npublic function __construct(LoopInterface $loop)\n{\n $this->loop = $loop;\n $this->clients = new \\SplObjectStorage();\n\n $this->loop->addPeriodicTimer(0, function ()\n {\n $connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');\n\n $channel = $connection->channel();\n $channel->queue_declare('hello', false, false, false, false);\n echo ' [*] Checking for for messages from RabbitMQ', \"\\n\";\n\n $max_number_messages_to_fetch_per_batch = 10000;\n do\n {\n $message = $channel->basic_get('hello', true);\n if($message)\n {\n foreach($this->clients as $client)\n {\n $client->send($message->body);\n }\n\n $max_number_messages_to_fetch_per_batch--;\n }\n }\n while($message && $max_number_messages_to_fetch_per_batch > 0);\n\n $channel->close();\n $connection->close();\n });\n\n}\n```\n\n```text\nloop\n```\n\n```text\naddPeriodicTimer\n```\n\n```text\nserver.php\n```\n\n```text\nChat.php\n```\n\n```text\n__constructor\n```\n\n```text\naddPeriodicTimer\n```\n\n========================================\n\nComments:\n- Hi, I am doing the same, but I am unable to connect both at the same time. Also, where to write code to push messages to rabbitMq. In above solution the messages( in Chat.php constructor method) are received from rabitMQ.\n- @Manu: Yes, my case was about getting messages from rabbitMQ to Ratchet. Sending messages to rabbitMQ should be as far as I remember much easier cause you can just implement it in Chat->onMessage method. Just connect to rabbitMQ, push your message and close connection (you have example from docs in my original question in section referring to pusher.php).\n- Thanks, and can we check in `constructor` method that the message is not be delivered to sender.\n- i m doing exactly the same, i will post my implementation to help others as you did\n- Great implementation! I found it to be (ALMOST) real-time implementation. It didn't block the web-socket, but made it slightly slower (not noticeable to users, anyway).","metadata":{"transformedAt":"2026-08-18T18:33:20.188Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":16,"totalLines":327,"estimatedTokens":2200}}757{"id":"stack-14974353","source":"stackoverflow","questionId":14974353,"title":"Modify message sent by rabbitMQ inside consumer","tags":["symfony","rabbitmq","message-queue","amqp"],"text":"Title: Modify message sent by rabbitMQ inside consumer\nTags: symfony, rabbitmq, message-queue, amqp\nSource: Stack Overflow\n\nQuestion:\n*Note:* Using RabbitMq via RabbitMQBundle in Symfony2.\n\nMy producer sends a message like this :\n\n```\n$message = array(\n 'class' => get_class($receiver),\n 'id' => $receiver->getId(),\n 'stepNumber' => 1,\n 'errorCount' => 0\n);\n```\n\nThe consumer retrieves the `$receiver` from the database and sends him an email.\n\n```\npublic function execute(AMQPMessage $msg)\n{\n //Step1 - retrieve user from db\n\n //Step2 - send email\n\n //Step3 - update stuff in database\n}\n```\n\nTo keep track of the errors, I want to handle the exceptions at each step. If there is an exception thrown at step 3, I want to modify `stepNumber` to 3, increase the `errorCount` by 1 in `$msg`, and finally requeue the `$msg` by returning `false`. \n\nThis has the following advantages:\n\n- When the consumer will process the message again, it will not send the email again.\n\n- When the `errorCount > 5`, I just discard the message.. `return false`.\n\nThis would be great, but :\n\n### Is there a way to modify the `$msg` before it is requeued by RabbitMQ?\n\n========================================\n\nCode:\n```php\n$message = array(\n 'class' => get_class($receiver),\n 'id' => $receiver->getId(),\n 'stepNumber' => 1,\n 'errorCount' => 0\n);\n```\n\n```php\npublic function execute(AMQPMessage $msg)\n{\n //Step1 - retrieve user from db\n\n //Step2 - send email\n\n //Step3 - update stuff in database\n}\n```\n\n```text\n$receiver\n```\n\n```text\nstepNumber\n```\n\n```text\nerrorCount\n```\n\n```text\n$msg\n```\n\n```text\n$msg\n```\n\n```text\nfalse\n```\n\n```text\nerrorCount > 5\n```\n\n```text\nreturn false\n```\n\n```text\n$msg\n```\n\n========================================\n\nComments:\n- You mean, send a clone of the original message back to the queue instead of modify it?","metadata":{"transformedAt":"2026-08-18T18:33:20.188Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":11,"totalLines":106,"estimatedTokens":460}}758{"id":"stack-37639658","source":"stackoverflow","questionId":37639658,"title":"Python: Kombu+RabbitMQ Deadlock - queues are either blocked or blocking","tags":["python","rabbitmq","deadlock","blockingqueue","kombu"],"text":"Title: Python: Kombu+RabbitMQ Deadlock - queues are either blocked or blocking\nTags: python, rabbitmq, deadlock, blockingqueue, kombu\nSource: Stack Overflow\n\nQuestion:\n### The problem\n\nI have a RabbitMQ Server that serves as a queue hub for one of my systems. In the last week or so, its producers come to a complete halt every few hours. \n\n### What have I tried\n\n### Brute force\n\n- Stopping the consumers releases the lock for a few minutes, but then blocking returns.\n\n- Restarting RabbitMQ solved the problem for a few hours.\n\n- I have some automatic script that does the ugly restarts, but it's obviously far from a proper solution.\n\n### Allocating more memory\n\nFollowing cantSleepNow's answer, I have increased the memory allocated to RabbitMQ to 90%. The server has a whopping 16GB of memory and the message count is not very high (millions per day), so that does not seem to be the problem.\n\nFrom the command line:\n\n```\nsudo rabbitmqctl set_vm_memory_high_watermark 0.9\n```\n\nAnd with `/etc/rabbitmq/rabbitmq.config`:\n\n```\n[\n {rabbit,\n [\n {loopback_users, []},\n {vm_memory_high_watermark, 0.9}\n ]\n }\n].\n```\n\n### Code & Design\n\nI use Python for all consumers and producers.\n\n### Producers\n\nThe producers are API server that serve calls. Whenever a call arrives, a connection is opened, a message is sent and the connection is closed.\n\n```\nfrom kombu import Connection\n\ndef send_message_to_queue(host, port, queue_name, message):\n \"\"\"Sends a single message to the queue.\"\"\"\n with Connection('amqp://guest:guest@%s:%s//' % (host, port)) as conn:\n simple_queue = conn.SimpleQueue(name=queue_name, no_ack=True)\n simple_queue.put(message)\n simple_queue.close()\n```\n\n### Consumers\n\nThe consumers slightly differ from each other, but generally use the following pattern - opening a connection, and waiting on it until a message arrives. The connection can stay opened for long period of times (say, days).\n\n```\nwith Connection('amqp://whatever:whatever@whatever:whatever//') as conn:\n while True:\n queue = conn.SimpleQueue(queue_name)\n message = queue.get(block=True)\n message.ack()\n```\n\n### Design reasoning\n\n- Consumers always need to keep an open connection with the queue server\n\n- The Producer session should only live during the lifespan of the API call\n\nThis design had caused no problems till about one week ago.\n\n### Web view dashboard\n\nThe web console shows that the consumers in `127.0.0.1` and `172.31.38.50` block the consumers from `172.31.38.50`, `172.31.39.120`, `172.31.41.38` and `172.31.41.38`.\n\nhttps://i.sstatic.net/4hOqL.png\n\n### System metrics\n\nJust to be on the safe side, I checked the server load. As expected, the load average and CPU utilization metrics are low.\n\nhttps://i.sstatic.net/WhaIK.png\n\n**Why does the rabbit MQ each such a deadlock?**\n\n========================================\n\nTop Answer:\nI'm writing this as an answer, partially because it may help and partially because it's too large to be a comment. \n\nFirst I'm sorry for missing this `message = queue.get(block=True)`. Also a disclaimer - I'm not familiar with python nor PIKA API.\n\nAMQP's `basic.get` is actually synchronous and you are setting the `block=true`. As I said, don't know what this means in PIKA, but in combination with constantly pooling the queue, doesn't sound efficient. So it could be that for what ever reason, publisher get's denied a connection due to queue access being blocked by the consumer. It actually fits perfectly with how you temporally resolve the issue by `Stopping the consumers releases the lock for a few minutes, but then blocking returns.` \n\nI'd recommend trying with AMQP's `basic.consume` instead of `basic.get`. I don't know what is the motivation for get, but in most of cases (my experience anyway) you should go with consume. Just to quote from the aforementioned link\n\n This method provides a direct access to the messages in a queue using\n a synchronous dialogue that is designed for specific types of\n application where synchronous functionality is more important than\n performance.\n\nIn RabbitMQ docs it says the connection gets blocked when the broker is low on resources, but as you wrote the load is quite low. Just to be safe, you may check memory consumption and free disk space.\n\n========================================\n\nCode:\n```text\nsudo rabbitmqctl set_vm_memory_high_watermark 0.9\n```\n\n```text\n[\n {rabbit,\n [\n {loopback_users, []},\n {vm_memory_high_watermark, 0.9}\n ]\n }\n].\n```\n\n```python\nfrom kombu import Connection\n\ndef send_message_to_queue(host, port, queue_name, message):\n \"\"\"Sends a single message to the queue.\"\"\"\n with Connection('amqp://guest:guest@%s:%s//' % (host, port)) as conn:\n simple_queue = conn.SimpleQueue(name=queue_name, no_ack=True)\n simple_queue.put(message)\n simple_queue.close()\n```\n\n```text\nwith Connection('amqp://whatever:whatever@whatever:whatever//') as conn:\n while True:\n queue = conn.SimpleQueue(queue_name)\n message = queue.get(block=True)\n message.ack()\n```\n\n```text\n/etc/rabbitmq/rabbitmq.config\n```\n\n```text\n127.0.0.1\n```\n\n```text\n172.31.38.50\n```\n\n```text\n172.31.38.50\n```\n\n```text\n172.31.39.120\n```\n\n```text\n172.31.41.38\n```\n\n```text\n172.31.41.38\n```\n\n```text\nmessage = queue.get(block=True)\n```\n\n```text\nbasic.get\n```\n\n```text\nblock=true\n```\n\n```text\nStopping the consumers releases the lock for a few minutes, but then blocking returns.\n```\n\n```text\nbasic.consume\n```\n\n```text\nbasic.get\n```\n\n========================================\n\nComments:\n- I didn't undestand this part `the consumers reuse the same connection while waiting on new messages`. How does the producer get the connection back? Can the connection be used only by a producer or (xor really) a consumer at a single moment?\n- @cantSleepNow Thanks! Clarifying here and in the questions -1. Each consumer open a connection, than get messages from it. For the entire lifespan of the consumer - which can be days - it uses the same connection. 2. Each producer waits for an API call. When a new call arrives, it opens a connection, writes data to it, and closes it immediately after.\n- ok so there is no connection sharing and each consumer and producer are separate processes? Can you somehow determine what happens when the producer closes the connection? Also, are you using blocking connection or select (see this question for reference stackoverflow.com/questions/11987838/…) EDIT sorry for some reason I can't do @ reply tag...\n- @cantSleepNow 1. Each consumer and producer is a separate process (or uWSGI thread, for that matters) - they no resource between them. At the deadlock, the producer can't close the connection, it gets stuck at the `simple_queue.put()` call. 3. I'm using blocking connections for the producers - the queue calls return very quickly. 4. No need to @ for the OP, I get notified for your comments.\n- @AdamMatan can you post the logs? when you have the connection blocked / blocking, most likely, is for some RabbitMQ alarm. Which version are you using ?\n- I ran across this blog this morning blog.domanski.me/rapid-rabbitmq. The author had a similar situation. His conclusion was that the management plugin enabled some code inside of RabbitMQ that caused the flow control to behave poorly and everything in the queue ended up blocked. In his case disabling the management plugin fixed it.\n- @Gabriele I'm using 'RabbitMQ 3.6.2, Erlang R16B03'. The logs indicated memory problems. I don't have the logs from the previous failure (they rotate quite quickly), but when it fails again I will quote them in the question.\n- @BradCampbell How weird. Could it be that the web plugin causes all the trouble? Will try the solution next time the server fails.\n- Thanks a lot for the answer! `consume()` seems to partially supported, while `get()` is fully supported; I don't see any `consume()` method in `SimpleQueue`. However, it makes sense for a consumer to block on a queue when there's no messages in it; the blocking applies to the reading, not the writing, end - unless I'm missing something here.\n- @AdamMatan You are welcome. I don't know what do you need from these methods, but in the tutorial consume is used, so I'm assuming it works rabbitmq.com/tutorials/tutorial-one-python.html Anyhow, please let me know (I'm sure other's are interested as well) how it all turns out.\n- I've increased the memory (updated the \"What have I tried\" section). The server keeps failing on a daily basis.\n- I have just downgraded to 3.6.1 (3.6.3 has a dependency issue on Ubuntu 14.04 LTS), can't wait to see if it works.\n- Let me know if you have any further questions.\n- Sure. Your home address. My wife will send you flowers, my boss will send you pizza and beer and I will send you a bottle of fine liquor. I had two nights of uninterrupted sleep (well, except for the kids). Good going.\n- And by the way, I can't believe RabbitMQ still features 3.6.2 on their site. Everybody uses the web plugin, and it's seriously poisonous.\n- @AdamMatan: This still working after the downgrade? 3.6.3 is officially released by the way!\n- Worked like a charm. After the bad experience with 3.6.2, I will probably refrain from upgrading unless I have a very good reason.","metadata":{"transformedAt":"2026-08-18T18:33:20.188Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":17,"totalLines":222,"estimatedTokens":2302}}759{"id":"stack-11240749","source":"stackoverflow","questionId":11240749,"title":"Random timeout error with Pika and gevent","tags":["python","rabbitmq","gevent","pika"],"text":"Title: Random timeout error with Pika and gevent\nTags: python, rabbitmq, gevent, pika\nSource: Stack Overflow\n\nQuestion:\nI've been trying to make use of RabbitMQ from within my gevent program by using the Pika library (monkey patched by gevent), gevent likes randomly throwing a timeout error.\n\nWhat should I do? Is there another library I could use?\n\n```\nWARNING:root:Document not found, retrying primary.\nTraceback (most recent call last):\n ...\n File \"/usr/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py\", line 32, in __init__\n BaseConnection.__init__(self, parameters, None, reconnection_strategy)\n File \"/usr/lib/python2.7/dist-packages/pika/adapters/base_connection.py\", line 50, in __init__\n reconnection_strategy)\n File \"/usr/lib/python2.7/dist-packages/pika/connection.py\", line 170, in __init__\n self._connect()\n File \"/usr/lib/python2.7/dist-packages/pika/connection.py\", line 228, in _connect\n self.parameters.port or spec.PORT)\n File \"/usr/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py\", line 44, in _adapter_connect\n self._handle_read()\n File \"/usr/lib/python2.7/dist-packages/pika/adapters/base_connection.py\", line 151, in _handle_read\n data = self.socket.recv(self._suggested_buffer_size)\n File \"/usr/lib/python2.7/dist-packages/gevent/socket.py\", line 427, in recv\n wait_read(sock.fileno(), timeout=self.timeout, event=self._read_event)\n File \"/usr/lib/python2.7/dist-packages/gevent/socket.py\", line 169, in wait_read\n switch_result = get_hub().switch()\n File \"/usr/lib/python2.7/dist-packages/gevent/hub.py\", line 164, in switch\n return greenlet.switch(self)\ntimeout: timed out\n```\n\n========================================\n\nTop Answer:\nI'm also having timeout problems with using Pika in a Django/Gunicorn application. I played with raising `connection_attempts` or increasing the timeout but RabbitMQ always closed the connection with a handshake error. The latter seems to indicate that Pika never transmitted any data on the socket.\n\nThe cause for the timeouts could be this libevent bug - at least in my environment the script attached to the bug is able to reproduce the issue.\n\nYou could try upgrading to gevent>=1.0 (at the time of writing not released yet):\n\n```\nwget http://gevent.googlecode.com/files/gevent-1.0b4.tar.gz\npip install gevent-1.0b4.tar.gz\n```\n\n========================================\n\nCode:\n```text\nWARNING:root:Document not found, retrying primary.\nTraceback (most recent call last):\n ...\n File \"/usr/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py\", line 32, in __init__\n BaseConnection.__init__(self, parameters, None, reconnection_strategy)\n File \"/usr/lib/python2.7/dist-packages/pika/adapters/base_connection.py\", line 50, in __init__\n reconnection_strategy)\n File \"/usr/lib/python2.7/dist-packages/pika/connection.py\", line 170, in __init__\n self._connect()\n File \"/usr/lib/python2.7/dist-packages/pika/connection.py\", line 228, in _connect\n self.parameters.port or spec.PORT)\n File \"/usr/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py\", line 44, in _adapter_connect\n self._handle_read()\n File \"/usr/lib/python2.7/dist-packages/pika/adapters/base_connection.py\", line 151, in _handle_read\n data = self.socket.recv(self._suggested_buffer_size)\n File \"/usr/lib/python2.7/dist-packages/gevent/socket.py\", line 427, in recv\n wait_read(sock.fileno(), timeout=self.timeout, event=self._read_event)\n File \"/usr/lib/python2.7/dist-packages/gevent/socket.py\", line 169, in wait_read\n switch_result = get_hub().switch()\n File \"/usr/lib/python2.7/dist-packages/gevent/hub.py\", line 164, in switch\n return greenlet.switch(self)\ntimeout: timed out\n```\n\n```text\nwget http://gevent.googlecode.com/files/gevent-1.0b4.tar.gz\npip install gevent-1.0b4.tar.gz\n```\n\n```text\nconnection_attempts\n```\n\n========================================\n\nComments:\n- I'm facing up the same issue when I use 2 or more producers in one green thread only.\n- Tried to use `gevent-1.0.1` - no luck.","metadata":{"transformedAt":"2026-08-18T18:33:20.188Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":90,"estimatedTokens":1005}}760{"id":"stack-5463297","source":"stackoverflow","questionId":5463297,"title":"rabbitmq+celery memory leak?","tags":["django","rabbitmq","celery"],"text":"Title: rabbitmq+celery memory leak?\nTags: django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI have been happily running celery+rabbitmq+django for a month or so in production. Yesterday, I decided to upgrade from celery 2.1.4 to 2.2.4 and now rabbitmq is spinning out of control. After running for a while, my nodes are no longer recognized by evcam, and beam.smp's memory consumptions starts increasing...slowly (100+% CPU usage). \n\nI can run `rabbitmqctl list_connections` and see that there is nothing unusual (just my one test node). I can see in `rabbitmqctl list_queues -p ` that there are no messages except the heartbeat from my test node. If I let the process keep running over a couple of hours it maxes out the machine.\n\nI've tried purging the various queues using `camqadm` to no avail and `stop_app` just hangs. The only way that I have found to 'fix' it is to `kill -9` beam.smp (and all related processes) and force_reset on my rabbitmq server.\n\nI have no idea how to go about debugging this. There doesn't appear to be anything fishy going on as far as new messages etc. Has anybody run up against this before? Any ideas? What other information should I be looking at?\n\n========================================\n\nTop Answer:\nMay not be helpful, but we recently tracked down a memory leak in the Java Virtual Machine related to the extensions used to monitor garbage collection. It may be that your heartbeat monitor is triggering these methods, which result in a native memory leak.\n\nThe issue is described here: https://bugs.java.com/bugdatabase/view_bug?bug_id=7066129\n\n========================================\n\nCode:\n```text\nrabbitmqctl list_connections\n```\n\n```text\nrabbitmqctl list_queues -p <VHOST>\n```\n\n```text\ncamqadm\n```\n\n```text\nstop_app\n```\n\n```text\nkill -9\n```\n\n========================================\n\nComments:\n- did you upgrade rabbitmq as well? I had similar symptoms with 2.2.x, so we downgraded to RabbitMQ 2.1.1 and had no issues.\n- I downgraded to 2.1.1 and the problem went away. Any idea why?\n- What version were you running when you had the symptoms?\n- I was running celery 2.2.4 with rabbitmq 2.2.0. I had been using celery 2.1.4 with the same version of rabbit without any issues.","metadata":{"transformedAt":"2026-08-18T18:33:20.188Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":50,"estimatedTokens":558}}761{"id":"stack-13623448","source":"stackoverflow","questionId":13623448,"title":"Is there any way for RabbitMQ STOMP to stop consuming messages until previous will ACKed?","tags":["rabbitmq","stomp"],"text":"Title: Is there any way for RabbitMQ STOMP to stop consuming messages until previous will ACKed?\nTags: rabbitmq, stomp\nSource: Stack Overflow\n\nQuestion:\nI use RabbitMQ Web-STOMP in my project and it is very good for me, but there is one problem with it. When consumer subscribes to a queue it gets instantly all the messages from the queue. In my case, a message task may take much time and it is necessary to consumer get next message from a queue only when previous was completed.\n\nAll works fine, when publishing starts after the consumers are subscribed, but when there are already messages in a queue, first subscribed consumer will get all of them and others will stay free. Is there anything like node-amqp queue.shift() method to consume next message only when previous is ACKed?\n\n========================================\n\nTop Answer:\nJust set 'prefetch-count' on connect header.\n\nHere is code sample for nodejs with @stomp/stompjs package:\n\n```\nconst headers: StompHeaders = {\n 'ack': 'client',\n 'prefetch-count': '1',\n};\n\nconst subscription = this.client.subscribe('queue-name',async (message)=>{\n //handle message\n},headers);\n```\n\nStompHeaders from\n\n========================================\n\nCode:\n```text\nint prefetch = 10;\n\nIModel channel = connection.CreateModel(); //where connection is IConnection\nchannel.basic_qos(0, prefetch, false);\n```\n\n```text\nbasic_qos\n```\n\n```text\nbasic.qos\n```\n\n```text\nconst headers: StompHeaders = {\n 'ack': 'client',\n 'prefetch-count': '1',\n};\n\nconst subscription = this.client.subscribe('queue-name',async (message)=>{\n //handle message\n},headers);\n```\n\n========================================\n\nComments:\n- I use RabbitMQ Web-**STOMP** with browser JS. I already know how to deal with that using C# or even node.js, but is there aby QoS for STOMP?\n- Setting prefetch:1 CONNECT header and ack:client header for SUBSCRIBE does not work for me...\n- Where were my eyes! Of course, \"prefetch-count\": 1 header for SUBSCRIBE is the answer, thank you!","metadata":{"transformedAt":"2026-08-18T18:33:20.188Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":64,"estimatedTokens":499}}762{"id":"stack-46846675","source":"stackoverflow","questionId":46846675,"title":"How to organize queues in Masstransit/RabbitMQ?","tags":["rabbitmq","message-queue","servicebus","masstransit","messagebroker"],"text":"Title: How to organize queues in Masstransit/RabbitMQ?\nTags: rabbitmq, message-queue, servicebus, masstransit, messagebroker\nSource: Stack Overflow\n\nQuestion:\nI'd like to know best practices for consuming messages. I've read MassTransit docs and I've searching about this but I don't get to come to any conclusion.\n\nI have one api (hosting a bus instance) that is publishing messages. These messages are varied because this api is not a microservice (messages for purchases, sales, etc).\n\nHow do I have to organize my consumers/queues?\n\n- **One process for queue type?** For example one for purchases, other for sales, etc. this solution could involve having many processes and I'm not sure whether or not it is a good solution. What if I want diferent queues for purchases, like purchases.stock, purchases.suppliers, etc? Process number could increase considerably. I think this is a good option for scalability, but manage so many processes could be tricky.\n\n- **Multiple queues for process** (grouping queues by domain)? For example one process having multiple consumers consuming purchases related messages and managing diferents queues, like purchases.stock, purchases.suppliers... This option makes more sense to me, but I'm not sure about it.","metadata":{"transformedAt":"2026-08-18T18:33:20.188Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":14,"estimatedTokens":313}}763{"id":"stack-66956749","source":"stackoverflow","questionId":66956749,"title":"Rabbitmq on docker: Application mnesia exited with reason: stopped","tags":["docker","docker-compose","rabbitmq"],"text":"Title: Rabbitmq on docker: Application mnesia exited with reason: stopped\nTags: docker, docker-compose, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm trying to launch Rabbitmq with docker-compose alongside DRF and Celery.\nHere's my docker-compose file. Everything else works fine, except for rabbitmq:\n\n```\nversion: '3.7'\n\nservices:\n drf:\n build: ./drf\n entrypoint: [\"/bin/sh\",\"-c\"]\n command:\n - |\n python manage.py migrate\n python manage.py runserver 0.0.0.0:8000\n volumes:\n - ./drf/:/usr/src/drf/\n ports:\n - 8000:8000\n env_file:\n - ./.env.dev\n depends_on:\n - db\n\n db:\n image: postgres:12.0-alpine\n volumes:\n - postgres_data:/var/lib/postgresql/data/\n environment:\n - POSTGRES_USER=postgres\n - POSTGRES_PASSWORD=postgres\n - POSTGRES_DB=base_test\n\n redis:\n image: redis:alpine\n volumes:\n - redis:/data\n ports:\n - \"6379:6379\"\n depends_on:\n - drf\n\n rabbitmq:\n image: rabbitmq:3-management-alpine\n container_name: 'rabbitmq'\n ports:\n - 5672:5672\n - 15672:15672\n volumes:\n - ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/\n - ~/.docker-conf/rabbitmq/log/:/var/log/rabbitmq\n networks:\n - net_1\n\n celery_worker:\n command: sh -c \"wait-for redis:3000 && wait-for drf:8000 -- celery -A base-test worker -l info\"\n depends_on:\n - drf\n - db\n - redis\n deploy:\n replicas: 2\n restart_policy:\n condition: on-failure\n resources:\n limits:\n cpus: '0.50'\n memory: 50M\n reservations:\n cpus: '0.25'\n memory: 20M\n hostname: celery_worker\n image: app-image\n networks:\n - net_1\n restart: on-failure\n\n celery_beat:\n command: sh -c \"wait-for redis:3000 && wait-for drf:8000 -- celery -A mysite beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler\"\n depends_on:\n - drf\n - db\n - redis\n hostname: celery_beat\n image: app-image\n networks:\n - net_1\n restart: on-failure\n\nnetworks:\n net_1:\n driver: bridge\n\nvolumes:\n postgres_data:\n redis:\n```\n\nAnd here's what happens when I launch it. Can someone please help me find the problem? I can't even the instruction and read the generated dump file because rabbitmq container exits after the error.\n\n```\nrabbitmq | Starting broker...2021-04-05 16:49:58.330 [info] \nrabbitmq | node : rabbit@0e652f57b1b3\nrabbitmq | home dir : /var/lib/rabbitmq\nrabbitmq | config file(s) : /etc/rabbitmq/rabbitmq.conf\nrabbitmq | cookie hash : ZPam/SOKy2dEd/3yt0OlaA==\nrabbitmq | log(s) : \nrabbitmq | database dir : /var/lib/rabbitmq/mnesia/rabbit@0e652f57b1b3\nrabbitmq | 2021-04-05 16:50:09.542 [info] Feature flags: list of feature flags found:\nrabbitmq | 2021-04-05 16:50:09.542 [info] Feature flags: [x] drop_unroutable_metric\nrabbitmq | 2021-04-05 16:50:09.542 [info] Feature flags: [x] empty_basic_get_metric\nrabbitmq | 2021-04-05 16:50:09.542 [info] Feature flags: [x] implicit_default_bindings\nrabbitmq | 2021-04-05 16:50:09.542 [info] Feature flags: [x] maintenance_mode_status\nrabbitmq | 2021-04-05 16:50:09.542 [info] Feature flags: [ ] quorum_queue\nrabbitmq | 2021-04-05 16:50:09.543 [info] Feature flags: [ ] user_limits\nrabbitmq | 2021-04-05 16:50:09.545 [info] Feature flags: [ ] virtual_host_metadata\nrabbitmq | 2021-04-05 16:50:09.546 [info] Feature flags: feature flag states written to disk: yes\nrabbitmq | 2021-04-05 16:50:10.844 [info] Running boot step pre_boot defined by app rabbit\nrabbitmq | 2021-04-05 16:50:10.845 [info] Running boot step rabbit_core_metrics defined by app rabbit\nrabbitmq | 2021-04-05 16:50:10.846 [info] Running boot step rabbit_alarm defined by app rabbit\nrabbitmq | 2021-04-05 16:50:10.854 [info] Memory high watermark set to 2509 MiB (2631391641 bytes) of 6273 MiB (6578479104 bytes) total\nrabbitmq | 2021-04-05 16:50:10.864 [info] Enabling free disk space monitoring\nrabbitmq | 2021-04-05 16:50:10.864 [info] Disk free limit set to 50MB\nrabbitmq | 2021-04-05 16:50:10.872 [info] Running boot step code_server_cache defined by app rabbit\nrabbitmq | 2021-04-05 16:50:10.872 [info] Running boot step file_handle_cache defined by app rabbit\nrabbitmq | 2021-04-05 16:50:10.872 [info] Limiting to approx 1048479 file handles (943629 sockets)\nrabbitmq | 2021-04-05 16:50:10.873 [info] FHC read buffering: OFF\nrabbitmq | 2021-04-05 16:50:10.873 [info] FHC write buffering: ON\nrabbitmq | 2021-04-05 16:50:10.874 [info] Running boot step worker_pool defined by app rabbit\nrabbitmq | 2021-04-05 16:50:10.874 [info] Will use 4 processes for default worker pool\nrabbitmq | 2021-04-05 16:50:10.874 [info] Starting worker pool 'worker_pool' with 4 processes in it\nrabbitmq | 2021-04-05 16:50:10.876 [info] Running boot step database defined by app rabbit\nrabbitmq | 2021-04-05 16:50:10.899 [info] Waiting for Mnesia tables for 30000 ms, 9 retries left\nrabbitmq | 2021-04-05 16:50:10.900 [info] Successfully synced tables from a peer\nrabbitmq | 2021-04-05 16:50:10.908 [info] Application mnesia exited with reason: stopped\nrabbitmq |\nrabbitmq | 2021-04-05 16:50:10.908 [info] Application mnesia exited with reason: stopped\nrabbitmq | 2021-04-05 16:50:10.908 [error] \nrabbitmq | 2021-04-05 16:50:10.908 [error] BOOT FAILED\nrabbitmq | BOOT FAILED\nrabbitmq | ===========\nrabbitmq | Error during startup: {error,\nrabbitmq | 2021-04-05 16:50:10.909 [error] ===========\nrabbitmq | 2021-04-05 16:50:10.909 [error] Error during startup: {error,\nrabbitmq | 2021-04-05 16:50:10.909 [error] {schema_integrity_check_failed,\nrabbitmq | {schema_integrity_check_failed,\nrabbitmq | [{table_attributes_mismatch,rabbit_queue,\nrabbitmq | 2021-04-05 16:50:10.910 [error] [{table_attributes_mismatch,rabbit_queue,\nrabbitmq | 2021-04-05 16:50:10.910 [error] [name,durable,auto_delete,exclusive_owner,\nrabbitmq | 2021-04-05 16:50:10.911 [error] arguments,pid,slave_pids,sync_slave_pids,\nrabbitmq | 2021-04-05 16:50:10.911 [error] recoverable_slaves,policy,operator_policy,\nrabbitmq | [name,durable,auto_delete,exclusive_owner,\nrabbitmq | arguments,pid,slave_pids,sync_slave_pids,\nrabbitmq | 2021-04-05 16:50:10.911 [error] gm_pids,decorators,state,policy_version,\nrabbitmq | 2021-04-05 16:50:10.911 [error] slave_pids_pending_shutdown,vhost,options],\nrabbitmq | 2021-04-05 16:50:10.912 [error] [name,durable,auto_delete,exclusive_owner,\nrabbitmq | 2021-04-05 16:50:10.912 [error] arguments,pid,slave_pids,sync_slave_pids,\nrabbitmq | 2021-04-05 16:50:10.913 [error] recoverable_slaves,policy,operator_policy,\nrabbitmq | 2021-04-05 16:50:10.913 [error] gm_pids,decorators,state,policy_version,\nrabbitmq | 2021-04-05 16:50:10.913 [error] slave_pids_pending_shutdown,vhost,options,\nrabbitmq | recoverable_slaves,policy,operator_policy,\nrabbitmq | gm_pids,decorators,state,policy_version,\nrabbitmq | slave_pids_pending_shutdown,vhost,options],\nrabbitmq | [name,durable,auto_delete,exclusive_owner,\nrabbitmq | arguments,pid,slave_pids,sync_slave_pids,\nrabbitmq | recoverable_slaves,policy,operator_policy,\nrabbitmq | gm_pids,decorators,state,policy_version,\nrabbitmq | slave_pids_pending_shutdown,vhost,options,\nrabbitmq | type,type_state]}]}}\nrabbitmq | 2021-04-05 16:50:10.914 [error] type,type_state]}]}}\nrabbitmq | 2021-04-05 16:50:10.916 [error] \nrabbitmq |\nrabbitmq | 2021-04-05 16:50:11.924 [info] [{initial_call,{application_master,init,['Argument__1','Argument__2','Argument__3','Argument__4']}},{pid,},{registered_name,[]},{error_info\n,{exit,{{schema_integrity_check_failed,[{table_attributes_mismatch,rabbit_queue,[name,durable,auto_delete,exclusive_owner,arguments,pid,slave_pids,sync_slave_pids,recoverable_slaves,policy,operator_policy,gm_\npids,decorators,state,policy_version,slave_pids_pending_shutdown,vhost,options],[name,durable,auto_delete,exclusive_owner,arguments,pid,slave_pids,sync_slave_pids,recoverable_slaves,policy,operator_policy,gm_\npids,decorators,state,policy_version,slave_pids_pending_shutdown,vhost,options,type,type_state]}]},{rabbit,start,[normal,[]]}},[{application_master,init,4,[{file,\"application_master.erl\"},{line,138}]},{proc_l\nib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,226}]}]}},{ancestors,[]},{message_queue_len,1},{messages,[{'EXIT',,normal}]},{links,[,]},{dictionary,[]},{trap_exit,true},{\nstatus,running},{heap_size,610},{stack_size,28},{reductions,534}], []\nrabbitmq | 2021-04-05 16:50:11.924 [error] CRASH REPORT Process with 0 neighbours exited with reason: {{schema_integrity_check_failed,[{table_attributes_mismatch,rabbit_queue,[name\n,durable,auto_delete,exclusive_owner,arguments,pid,slave_pids,sync_slave_pids,recoverable_slaves,policy,operator_policy,gm_pids,decorators,state,policy_version,slave_pids_pending_shutdown,vhost,options],[name\n,durable,auto_delete,exclusive_owner,arguments,pid,slave_pids,sync_slave_pids,recoverable_slaves,policy,operator_policy,gm_pids,decorators,state,policy_version,slave_pids_pending_shutdown,vhost,options,type,t\nype_state]}]},...} in application_master:init/4 line 138\nrabbitmq | 2021-04-05 16:50:11.924 [info] Application rabbit exited with reason: {{schema_integrity_check_failed,[{table_attributes_mismatch,rabbit_queue,[name,durable,auto_delete,exclusive_o\nwner,arguments,pid,slave_pids,sync_slave_pids,recoverable_slaves,policy,operator_policy,gm_pids,decorators,state,policy_version,slave_pids_pending_shutdown,vhost,options],[name,durable,auto_delete,exclusive_o\nwner,arguments,pid,slave_pids,sync_slave_pids,recoverable_slaves,policy,operator_policy,gm_pids,decorators,state,policy_version,slave_pids_pending_shutdown,vhost,options,type,type_state]}]},...}\nrabbitmq | 2021-04-05 16:50:11.925 [info] Application rabbit exited with reason: {{schema_integrity_check_failed,[{table_attributes_mismatch,rabbit_queue,[name,durable,auto_delete,exclusive_o\nwner,arguments,pid,slave_pids,sync_slave_pids,recoverable_slaves,policy,operator_policy,gm_pids,decorators,state,policy_version,slave_pids_pending_shutdown,vhost,options],[name,durable,auto_delete,exclusive_o\nwner,arguments,pid,slave_pids,sync_slave_pids,recoverable_slaves,policy,operator_policy,gm_pids,decorators,state,policy_version,slave_pids_pending_shutdown,vhost,options,type,type_state]}]},...}\nrabbitmq | {\"Kernel pid terminated\",application_controller,\"{application_start_failure,rabbit,{{schema_integrity_check_failed,[{table_attributes_mismatch,rabbit_queue,[name,durable,auto_delete,exclusi\nve_owner,arguments,pid,slave_pids,sync_slave_pids,recoverable_slaves,policy,operator_policy,gm_pids,decorators,state,policy_version,slave_pids_pending_shutdown,vhost,options],[name,durable,auto_delete,exclusi\nve_owner,arguments,pid,slave_pids,sync_slave_pids,recoverable_slaves,policy,operator_policy,gm_pids,decorators,state,policy_version,slave_pids_pending_shutdown,vhost,options,type,type_state]}]},{rabbit,start,\n[normal,[]]}}}\"}\nrabbitmq | Kernel pid terminated (application_controller) ({application_start_failure,rabbit,{{schema_integrity_check_failed,[{table_attributes_mismatch,rabbit_queue,[name,durable,auto_delete,exclusiv\ne_owner,arg\nrabbitmq |\nrabbitmq | Crash dump is being written to: /var/log/rabbitmq/erl_crash.dump...done\nrabbitmq exited with code 0\n```\n\n========================================\n\nTop Answer:\nBtw, the same error (`Application mnesia exited with reason: stopped`) appears when you have syntax errors in your `definitions.json`.\n\n========================================\n\nCode:\n```text\nversion: '3.7'\n\nservices:\n drf:\n build: ./drf\n entrypoint: [\"/bin/sh\",\"-c\"]\n command:\n - |\n python manage.py migrate\n python manage.py runserver 0.0.0.0:8000\n volumes:\n - ./drf/:/usr/src/drf/\n ports:\n - 8000:8000\n env_file:\n - ./.env.dev\n depends_on:\n - db\n\n db:\n image: postgres:12.0-alpine\n volumes:\n - postgres_data:/var/lib/postgresql/data/\n environment:\n - POSTGRES_USER=postgres\n - POSTGRES_PASSWORD=postgres\n - POSTGRES_DB=base_test\n\n redis:\n image: redis:alpine\n volumes:\n - redis:/data\n ports:\n - \"6379:6379\"\n depends_on:\n - drf\n\n rabbitmq:\n image: rabbitmq:3-management-alpine\n container_name: 'rabbitmq'\n ports:\n - 5672:5672\n - 15672:15672\n volumes:\n - ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/\n - ~/.docker-conf/rabbitmq/log/:/var/log/rabbitmq\n networks:\n - net_1\n\n celery_worker:\n command: sh -c \"wait-for redis:3000 && wait-for drf:8000 -- celery -A base-test worker -l info\"\n depends_on:\n - drf\n - db\n - redis\n deploy:\n replicas: 2\n restart_policy:\n condition: on-failure\n resources:\n limits:\n cpus: '0.50'\n memory: 50M\n reservations:\n cpus: '0.25'\n memory: 20M\n hostname: celery_worker\n image: app-image\n networks:\n - net_1\n restart: on-failure\n\n celery_beat:\n command: sh -c \"wait-for redis:3000 && wait-for drf:8000 -- celery -A mysite beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler\"\n depends_on:\n - drf\n - db\n - redis\n hostname: celery_beat\n image: app-image\n networks:\n - net_1\n restart: on-failure\n\nnetworks:\n net_1:\n driver: bridge\n\nvolumes:\n postgres_data:\n redis:\n```\n\n```text\nrabbitmq | Starting broker...2021-04-05 16:49:58.330 [info] <0.273.0>\nrabbitmq | node : rabbit@0e652f57b1b3\nrabbitmq | home dir : /var/lib/rabbitmq\nrabbitmq | config file(s) : /etc/rabbitmq/rabbitmq.conf\nrabbitmq | cookie hash : ZPam/SOKy2dEd/3yt0OlaA==\nrabbitmq | log(s) : <stdout>\nrabbitmq | database dir : /var/lib/rabbitmq/mnesia/rabbit@0e652f57b1b3\nrabbitmq | 2021-04-05 16:50:09.542 [info] <0.273.0> Feature flags: list of feature flags found:\nrabbitmq | 2021-04-05 16:50:09.542 [info] <0.273.0> Feature flags: [x] drop_unroutable_metric\nrabbitmq | 2021-04-05 16:50:09.542 [info] <0.273.0> Feature flags: [x] empty_basic_get_metric\nrabbitmq | 2021-04-05 16:50:09.542 [info] <0.273.0> Feature flags: [x] implicit_default_bindings\nrabbitmq | 2021-04-05 16:50:09.542 [info] <0.273.0> Feature flags: [x] maintenance_mode_status\nrabbitmq | 2021-04-05 16:50:09.542 [info] <0.273.0> Feature flags: [ ] quorum_queue\nrabbitmq | 2021-04-05 16:50:09.543 [info] <0.273.0> Feature flags: [ ] user_limits\nrabbitmq | 2021-04-05 16:50:09.545 [info] <0.273.0> Feature flags: [ ] virtual_host_metadata\nrabbitmq | 2021-04-05 16:50:09.546 [info] <0.273.0> Feature flags: feature flag states written to disk: yes\nrabbitmq | 2021-04-05 16:50:10.844 [info] <0.273.0> Running boot step pre_boot defined by app rabbit\nrabbitmq | 2021-04-05 16:50:10.845 [info] <0.273.0> Running boot step rabbit_core_metrics defined by app rabbit\nrabbitmq | 2021-04-05 16:50:10.846 [info] <0.273.0> Running boot step rabbit_alarm defined by app rabbit\nrabbitmq | 2021-04-05 16:50:10.854 [info] <0.414.0> Memory high watermark set to 2509 MiB (2631391641 bytes) of 6273 MiB (6578479104 bytes) total\nrabbitmq | 2021-04-05 16:50:10.864 [info] <0.416.0> Enabling free disk space monitoring\nrabbitmq | 2021-04-05 16:50:10.864 [info] <0.416.0> Disk free limit set to 50MB\nrabbitmq | 2021-04-05 16:50:10.872 [info] <0.273.0> Running boot step code_server_cache defined by app rabbit\nrabbitmq | 2021-04-05 16:50:10.872 [info] <0.273.0> Running boot step file_handle_cache defined by app rabbit\nrabbitmq | 2021-04-05 16:50:10.872 [info] <0.419.0> Limiting to approx 1048479 file handles (943629 sockets)\nrabbitmq | 2021-04-05 16:50:10.873 [info] <0.420.0> FHC read buffering: OFF\nrabbitmq | 2021-04-05 16:50:10.873 [info] <0.420.0> FHC write buffering: ON\nrabbitmq | 2021-04-05 16:50:10.874 [info] <0.273.0> Running boot step worker_pool defined by app rabbit\nrabbitmq | 2021-04-05 16:50:10.874 [info] <0.372.0> Will use 4 processes for default worker pool\nrabbitmq | 2021-04-05 16:50:10.874 [info] <0.372.0> Starting worker pool 'worker_pool' with 4 processes in it\nrabbitmq | 2021-04-05 16:50:10.876 [info] <0.273.0> Running boot step database defined by app rabbit\nrabbitmq | 2021-04-05 16:50:10.899 [info] <0.273.0> Waiting for Mnesia tables for 30000 ms, 9 retries left\nrabbitmq | 2021-04-05 16:50:10.900 [info] <0.273.0> Successfully synced tables from a peer\nrabbitmq | 2021-04-05 16:50:10.908 [info] <0.44.0> Application mnesia exited with reason: stopped\nrabbitmq |\nrabbitmq | 2021-04-05 16:50:10.908 [info] <0.44.0> Application mnesia exited with reason: stopped\nrabbitmq | 2021-04-05 16:50:10.908 [error] <0.273.0>\nrabbitmq | 2021-04-05 16:50:10.908 [error] <0.273.0> BOOT FAILED\nrabbitmq | BOOT FAILED\nrabbitmq | ===========\nrabbitmq | Error during startup: {error,\nrabbitmq | 2021-04-05 16:50:10.909 [error] <0.273.0> ===========\nrabbitmq | 2021-04-05 16:50:10.909 [error] <0.273.0> Error during startup: {error,\nrabbitmq | 2021-04-05 16:50:10.909 [error] <0.273.0> {schema_integrity_check_failed,\nrabbitmq | {schema_integrity_check_failed,\nrabbitmq | [{table_attributes_mismatch,rabbit_queue,\nrabbitmq | 2021-04-05 16:50:10.910 [error] <0.273.0> [{table_attributes_mismatch,rabbit_queue,\nrabbitmq | 2021-04-05 16:50:10.910 [error] <0.273.0> [name,durable,auto_delete,exclusive_owner,\nrabbitmq | 2021-04-05 16:50:10.911 [error] <0.273.0> arguments,pid,slave_pids,sync_slave_pids,\nrabbitmq | 2021-04-05 16:50:10.911 [error] <0.273.0> recoverable_slaves,policy,operator_policy,\nrabbitmq | [name,durable,auto_delete,exclusive_owner,\nrabbitmq | arguments,pid,slave_pids,sync_slave_pids,\nrabbitmq | 2021-04-05 16:50:10.911 [error] <0.273.0> gm_pids,decorators,state,policy_version,\nrabbitmq | 2021-04-05 16:50:10.911 [error] <0.273.0> slave_pids_pending_shutdown,vhost,options],\nrabbitmq | 2021-04-05 16:50:10.912 [error] <0.273.0> [name,durable,auto_delete,exclusive_owner,\nrabbitmq | 2021-04-05 16:50:10.912 [error] <0.273.0> arguments,pid,slave_pids,sync_slave_pids,\nrabbitmq | 2021-04-05 16:50:10.913 [error] <0.273.0> recoverable_slaves,policy,operator_policy,\nrabbitmq | 2021-04-05 16:50:10.913 [error] <0.273.0> gm_pids,decorators,state,policy_version,\nrabbitmq | 2021-04-05 16:50:10.913 [error] <0.273.0> slave_pids_pending_shutdown,vhost,options,\nrabbitmq | recoverable_slaves,policy,operator_policy,\nrabbitmq | gm_pids,decorators,state,policy_version,\nrabbitmq | slave_pids_pending_shutdown,vhost,options],\nrabbitmq | [name,durable,auto_delete,exclusive_owner,\nrabbitmq | arguments,pid,slave_pids,sync_slave_pids,\nrabbitmq | recoverable_slaves,policy,operator_policy,\nrabbitmq | gm_pids,decorators,state,policy_version,\nrabbitmq | slave_pids_pending_shutdown,vhost,options,\nrabbitmq | type,type_state]}]}}\nrabbitmq | 2021-04-05 16:50:10.914 [error] <0.273.0> type,type_state]}]}}\nrabbitmq | 2021-04-05 16:50:10.916 [error] <0.273.0>\nrabbitmq |\nrabbitmq | 2021-04-05 16:50:11.924 [info] <0.272.0> [{initial_call,{application_master,init,['Argument__1','Argument__2','Argument__3','Argument__4']}},{pid,<0.272.0>},{registered_name,[]},{error_info\n,{exit,{{schema_integrity_check_failed,[{table_attributes_mismatch,rabbit_queue,[name,durable,auto_delete,exclusive_owner,arguments,pid,slave_pids,sync_slave_pids,recoverable_slaves,policy,operator_policy,gm_\npids,decorators,state,policy_version,slave_pids_pending_shutdown,vhost,options],[name,durable,auto_delete,exclusive_owner,arguments,pid,slave_pids,sync_slave_pids,recoverable_slaves,policy,operator_policy,gm_\npids,decorators,state,policy_version,slave_pids_pending_shutdown,vhost,options,type,type_state]}]},{rabbit,start,[normal,[]]}},[{application_master,init,4,[{file,\"application_master.erl\"},{line,138}]},{proc_l\nib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,226}]}]}},{ancestors,[<0.271.0>]},{message_queue_len,1},{messages,[{'EXIT',<0.273.0>,normal}]},{links,[<0.271.0>,<0.44.0>]},{dictionary,[]},{trap_exit,true},{\nstatus,running},{heap_size,610},{stack_size,28},{reductions,534}], []\nrabbitmq | 2021-04-05 16:50:11.924 [error] <0.272.0> CRASH REPORT Process <0.272.0> with 0 neighbours exited with reason: {{schema_integrity_check_failed,[{table_attributes_mismatch,rabbit_queue,[name\n,durable,auto_delete,exclusive_owner,arguments,pid,slave_pids,sync_slave_pids,recoverable_slaves,policy,operator_policy,gm_pids,decorators,state,policy_version,slave_pids_pending_shutdown,vhost,options],[name\n,durable,auto_delete,exclusive_owner,arguments,pid,slave_pids,sync_slave_pids,recoverable_slaves,policy,operator_policy,gm_pids,decorators,state,policy_version,slave_pids_pending_shutdown,vhost,options,type,t\nype_state]}]},...} in application_master:init/4 line 138\nrabbitmq | 2021-04-05 16:50:11.924 [info] <0.44.0> Application rabbit exited with reason: {{schema_integrity_check_failed,[{table_attributes_mismatch,rabbit_queue,[name,durable,auto_delete,exclusive_o\nwner,arguments,pid,slave_pids,sync_slave_pids,recoverable_slaves,policy,operator_policy,gm_pids,decorators,state,policy_version,slave_pids_pending_shutdown,vhost,options],[name,durable,auto_delete,exclusive_o\nwner,arguments,pid,slave_pids,sync_slave_pids,recoverable_slaves,policy,operator_policy,gm_pids,decorators,state,policy_version,slave_pids_pending_shutdown,vhost,options,type,type_state]}]},...}\nrabbitmq | 2021-04-05 16:50:11.925 [info] <0.44.0> Application rabbit exited with reason: {{schema_integrity_check_failed,[{table_attributes_mismatch,rabbit_queue,[name,durable,auto_delete,exclusive_o\nwner,arguments,pid,slave_pids,sync_slave_pids,recoverable_slaves,policy,operator_policy,gm_pids,decorators,state,policy_version,slave_pids_pending_shutdown,vhost,options],[name,durable,auto_delete,exclusive_o\nwner,arguments,pid,slave_pids,sync_slave_pids,recoverable_slaves,policy,operator_policy,gm_pids,decorators,state,policy_version,slave_pids_pending_shutdown,vhost,options,type,type_state]}]},...}\nrabbitmq | {\"Kernel pid terminated\",application_controller,\"{application_start_failure,rabbit,{{schema_integrity_check_failed,[{table_attributes_mismatch,rabbit_queue,[name,durable,auto_delete,exclusi\nve_owner,arguments,pid,slave_pids,sync_slave_pids,recoverable_slaves,policy,operator_policy,gm_pids,decorators,state,policy_version,slave_pids_pending_shutdown,vhost,options],[name,durable,auto_delete,exclusi\nve_owner,arguments,pid,slave_pids,sync_slave_pids,recoverable_slaves,policy,operator_policy,gm_pids,decorators,state,policy_version,slave_pids_pending_shutdown,vhost,options,type,type_state]}]},{rabbit,start,\n[normal,[]]}}}\"}\nrabbitmq | Kernel pid terminated (application_controller) ({application_start_failure,rabbit,{{schema_integrity_check_failed,[{table_attributes_mismatch,rabbit_queue,[name,durable,auto_delete,exclusiv\ne_owner,arg\nrabbitmq |\nrabbitmq | Crash dump is being written to: /var/log/rabbitmq/erl_crash.dump...done\nrabbitmq exited with code 0\n```\n\n```text\ncontainer_name\n```\n\n```text\nvolumes\n```\n\n```text\nApplication mnesia exited with reason: stopped\n```\n\n```text\ndefinitions.json\n```\n\n========================================\n\nComments:\n- I have started to experience the same but in k8s\n- but removing volumes will cause to loose all the data :0\n- @MohammadhosseinFereydouni It didn't cause any loss of data. I don't have enough knowledge to say why but I'd recommend reading this: docs.docker.com/storage/volumes.\n- when you remove rabbitmq volume, the container no longer points to the existing data so it won't have the exchanges and other things defined in it before the error.","metadata":{"transformedAt":"2026-08-18T18:33:20.188Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":427,"estimatedTokens":6141}}764{"id":"stack-46135555","source":"stackoverflow","questionId":46135555,"title":"access to vhost refused for guest, with the MassTransit Sample-RequestResponse sample","tags":["rabbitmq","masstransit"],"text":"Title: access to vhost refused for guest, with the MassTransit Sample-RequestResponse sample\nTags: rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nI am using the default configuration on latest RabbitMQ server (guest is admin) but I get the next exception when I run the RequestResponse sample.\n\n OperationInterruptedException: The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=530, text=\"NOT_ALLOWED - access to vhost 'test' refused for user 'guest'\", classId=10, methodId=40, cause=\n\nany ideas?\n\n========================================\n\nTop Answer:\nYou can try using `rabbitmqctl` and `set_permissions`\n\n`$ rabbitmqctl set_permissions -p \"custom-vhost\" \"username\" \".*\" \".*\" \".*\"`\n\nhttps://www.rabbitmq.com/docs/access-control#user-management\n\n========================================\n\nCode:\n```text\n<add key=\"RabbitMQHost\" value=\"rabbitmq://localhost/test\"/>\n```\n\n```text\nApp.config\n```\n\n```text\ntest\n```\n\n```text\ntest\n```\n\n```text\nguest\n```\n\n```text\nApp.config\n```\n\n```text\nrabbitmqctl\n```\n\n```text\nset_permissions\n```\n\n```text\n$ rabbitmqctl set_permissions -p \"custom-vhost\" \"username\" \".*\" \".*\" \".*\"\n```\n\n========================================\n\nComments:\n- how doi add full permissions for `guest`?","metadata":{"transformedAt":"2026-08-18T18:33:20.188Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":63,"estimatedTokens":311}}765{"id":"stack-48791411","source":"stackoverflow","questionId":48791411,"title":"Horizontal scaling of consumers when the publisher provides sequenced messages","tags":["asynchronous","rabbitmq","microservices"],"text":"Title: Horizontal scaling of consumers when the publisher provides sequenced messages\nTags: asynchronous, rabbitmq, microservices\nSource: Stack Overflow\n\nQuestion:\nIn a distributed service oriented architecture, lets say I have a producer that send messages to a consumer using RMQ. \n\nWe decided then to horizontally scale the consuming part of our architecture by adding more consumers and we faced some limitations.\n\nThe publisher provide a sequence number in every message it sent. And it’s very important that the consumers process the messages based on the sequence number it has.\n\nEvery time that deal with a given resource, lets say A, the publisher will send RMQ messages that says \"Hey lets do sequence 1 for A\" and then \"Hey lets do sequence 2 for A\" and so on.\n\nIf for example the publisher provides 3 messages for A with sequences 1, 2 and 3 and the 3 messages are distributed to 3 different instances of our consumer. The message of sequence 2 is requeued until sequence 1 is well processed, same for sequence 3.\n\nAt the end the messages are all well processed, but after many retries! This causes some latency in our system as we retries many times if we’ve 100 sequences to consume.\n\nA possible solution would be to make sure each set of sequences for a given resource has to be processed by the same consumer. But how can we achieve that?\n\nHow can I avoid the requeuing in order to make sure every instance of our consumer always get the messages for a given resource well ordered?\n\n========================================\n\nTop Answer:\nI'm not familiar with RMQ but I'll try to help.\n\nFor me it seems that you want to scale your consumers in a way that each consumer is dedicated for a single resource. This is necessary as you have dependency between the sequences for a single resource, thus there is no point distributing the work between multiple consumers.\n\nI have experience with Kafka and there you can use so called \"topics\" to send messages to and have a consumer dedicated for a single topic which grabs the work items from there.\n\nNot sure if this is possible on RMQ though.\n\nIf this is not an option on your architecture, I'd try the following:\nDedicate a single consumer for a resource by checking the message payload first whether it is relevant for that resource. If yes then execute the work, if not then requeue it.\n\n========================================\n\nCode:\n```text\ntopic exchange\n```\n\n```text\nA\n```\n\n```text\nA\n```\n\n```text\nB\n```\n\n```text\nB\n```\n\n```text\nack\n```\n\n```text\nacking\n```\n\n========================================\n\nComments:\n- This is probably the closest OP is going to get to the implementation in question, but there will be more needed to make the solution resilient against data loss and \"dead-ending\" data. (Ask what would happen if a queue consumer crashes and see what the solution does.) OP might consider that RabbitMQ is either the wrong tool or the solution will require other tools in addition to RabbitMQ.","metadata":{"transformedAt":"2026-08-18T18:33:20.188Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":70,"estimatedTokens":743}}766{"id":"stack-57595427","source":"stackoverflow","questionId":57595427,"title":"Authenticating rabbitmq using ExternalCredentials","tags":["python","ssl","rabbitmq","tls1.2","pika"],"text":"Title: Authenticating rabbitmq using ExternalCredentials\nTags: python, ssl, rabbitmq, tls1.2, pika\nSource: Stack Overflow\n\nQuestion:\nI have a rabbitmq server and use the pika library with Python to produce/consume messages. For development purposes, I was simply using\n\n`credentials = pika.PlainCredentials(, )`\n\nI want to change that to use pika.ExternalCredentials or TLS.\n\nI have set up my rabbitmq server to listen for TLS on port 5671, and have configured it correctly. I am able to communicate with rabbitmq from localhost, but the moment I try to communicate with it from outside the localhost it doesn't like that. I have a feeling my \"credentials\" are based on the \"guest\" user in rabbitmq.\n\n### rabbitmq.config\n\n```\n%% -*- mode: erlang -*-\n\n[\n {rabbit,\n [\n {ssl_listeners, [5671]},\n {auth_mechanisms, ['PLAIN', 'AMQPLAIN', 'EXTERNAL']},\n {ssl_options, [{cacertfile,\"~/tls-gen/basic/result/ca_certificate.pem\"},\n {certfile,\"~/tls-gen/basic/result/server_certificate.pem\"},\n {keyfile,\"~/tls-gen/basic/result/server_key.pem\"},\n {verify,verify_none},\n {ssl_cert_login_from, common_name},\n {fail_if_no_peer_cert,false}]}\n \n ]}\n].\n```\n\nI can confirm this works, since in my logs for rabbitmq I see:\n\n```\n2019-08-21 15:34:47.663 [info] started TLS (SSL) listener on [::]:5671\n```\n\nServer-side everything seems to be set up, I have also generated certificates and all the .pem files required.\n\n### test_rabbitmq.py\n\n```\nimport pika\nimport ssl\nfrom pika.credentials import ExternalCredentials\n\ncontext = ssl.create_default_context(cafile=\"~/tls-gen/basic/result/ca_certificate.pem\")\ncontext.load_cert_chain(\"~/tls-gen/basic/result/client_certificate.pem\",\n \"~/tls-gen/basic/result/client_key.pem\")\nssl_options = pika.SSLOptions(context, \"10.154.0.27\")\nparams = pika.ConnectionParameters(port=5671,ssl_options=ssl_options, credentials = ExternalCredentials())\nconnection = pika.BlockingConnection(params)\nchannel = connection.channel()\n```\n\n### When I run the script locally\n\n```\n(, , b'Hello, world!')\n```\n\n### When I run the script from another instance\n\n```\nTraceback (most recent call last):\n File \"pbbarcode.py\", line 200, in \n main()\n File \"pbbarcode.py\", line 187, in main\n connection = pika.BlockingConnection(params)\n File \"/usr/local/lib/python3.7/site-packages/pika/adapters/blocking_connection.py\", line 359, in __init__\n self._impl = self._create_connection(parameters, _impl_class)\n File \"/usr/local/lib/python3.7/site-packages/pika/adapters/blocking_connection.py\", line 450, in _create_connection\n raise self._reap_last_connection_workflow_error(error)\npika.exceptions.AMQPConnectionError\n```\n\n### When I run the script locally, and delete the guest user\n\n```\nTraceback (most recent call last):\n File \"test_mq.py\", line 12, in \n with pika.BlockingConnection(conn_params) as conn:\n File \"/home/daudn/.local/lib/python3.7/site-packages/pika/adapters/blocking_connection.py\", line 359, in __init__\n self._impl = self._create_connection(parameters, _impl_class)\n File \"/home/daudn/.local/lib/python3.7/site-packages/pika/adapters/blocking_connection.py\", line 450, in _create_connection\n raise self._reap_last_connection_workflow_error(error)\npika.exceptions.ProbableAuthenticationError: ConnectionClosedByBroker: (403) 'ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.'\n```\n\nIt seems like SSL is configured with the user \"guest\" and rabbitmq doesn't allow connections to guest outside of localhost. How can I use SSL with a different user?\nWhen I delete the guest user, this is what the rabbitmq log says:\n\n```\n2019-08-22 10:14:40.054 [info] accepting AMQP connection (127.0.0.1:59192 -> 127.0.0.1:5671)\n2019-08-22 10:14:40.063 [error] Error on AMQP connection (127.0.0.1:59192 -> 127.0.0.1:5671, state: starting):\nPLAIN login refused: user 'guest' - invalid credentials\n2019-08-22 10:14:40.063 [warning] closing AMQP connection (127.0.0.1:59192 -> 127.0.0.1:5671):\nclient unexpectedly closed TCP connection\n2019-08-22 10:15:12.613 [info] Creating user 'guest'\n2019-08-22 10:15:28.370 [info] Setting user tags for user 'guest' to [administrator]\n2019-08-22 10:15:51.352 [info] Setting permissions for 'guest' in '/' to '.*', '.*', '.*'\n2019-08-22 10:15:54.237 [info] accepting AMQP connection (127.0.0.1:59202 -> 127.0.0.1:5671)\n2019-08-22 10:15:54.243 [info] connection (127.0.0.1:59202 -> 127.0.0.1:5671): user 'guest' authenticated and granted access to vhost '/'\n```\n\nThis also clearly means the SSL is still using the username and password to connect to rabbitmq? HELP!\n\nReferences:\n\ntls_official_example\n\npika_official_tls_docs\n\nadded_authentication_external\n\n========================================\n\nTop Answer:\nYou will have to enable the rabbitmq-auth-mechanism-ssl plugin , i think you are missing that part.\n\nTo enable the plugin do the following ( showing the example for a Windows setup)\n\n```\nrabbitmq-plugins.bat enable rabbitmq_auth_mechanism_ssl\n```\n\n========================================\n\nCode:\n```text\n%% -*- mode: erlang -*-\n\n[\n {rabbit,\n [\n {ssl_listeners, [5671]},\n {auth_mechanisms, ['PLAIN', 'AMQPLAIN', 'EXTERNAL']},\n {ssl_options, [{cacertfile,\"~/tls-gen/basic/result/ca_certificate.pem\"},\n {certfile,\"~/tls-gen/basic/result/server_certificate.pem\"},\n {keyfile,\"~/tls-gen/basic/result/server_key.pem\"},\n {verify,verify_none},\n {ssl_cert_login_from, common_name},\n {fail_if_no_peer_cert,false}]}\n \n ]}\n].\n```\n\n```text\n2019-08-21 15:34:47.663 [info] <0.442.0> started TLS (SSL) listener on [::]:5671\n```\n\n```text\nimport pika\nimport ssl\nfrom pika.credentials import ExternalCredentials\n\ncontext = ssl.create_default_context(cafile=\"~/tls-gen/basic/result/ca_certificate.pem\")\ncontext.load_cert_chain(\"~/tls-gen/basic/result/client_certificate.pem\",\n \"~/tls-gen/basic/result/client_key.pem\")\nssl_options = pika.SSLOptions(context, \"10.154.0.27\")\nparams = pika.ConnectionParameters(port=5671,ssl_options=ssl_options, credentials = ExternalCredentials())\nconnection = pika.BlockingConnection(params)\nchannel = connection.channel()\n```\n\n```text\n(<Basic.GetOk(['delivery_tag=1', 'exchange=', 'message_count=0', 'redelivered=False', 'routing_key=foobar'])>, <BasicProperties>, b'Hello, world!')\n```\n\n```text\nTraceback (most recent call last):\n File \"pbbarcode.py\", line 200, in <module>\n main()\n File \"pbbarcode.py\", line 187, in main\n connection = pika.BlockingConnection(params)\n File \"/usr/local/lib/python3.7/site-packages/pika/adapters/blocking_connection.py\", line 359, in __init__\n self._impl = self._create_connection(parameters, _impl_class)\n File \"/usr/local/lib/python3.7/site-packages/pika/adapters/blocking_connection.py\", line 450, in _create_connection\n raise self._reap_last_connection_workflow_error(error)\npika.exceptions.AMQPConnectionError\n```\n\n```text\nTraceback (most recent call last):\n File \"test_mq.py\", line 12, in <module>\n with pika.BlockingConnection(conn_params) as conn:\n File \"/home/daudn/.local/lib/python3.7/site-packages/pika/adapters/blocking_connection.py\", line 359, in __init__\n self._impl = self._create_connection(parameters, _impl_class)\n File \"/home/daudn/.local/lib/python3.7/site-packages/pika/adapters/blocking_connection.py\", line 450, in _create_connection\n raise self._reap_last_connection_workflow_error(error)\npika.exceptions.ProbableAuthenticationError: ConnectionClosedByBroker: (403) 'ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.'\n```\n\n```text\n2019-08-22 10:14:40.054 [info] <0.735.0> accepting AMQP connection <0.735.0> (127.0.0.1:59192 -> 127.0.0.1:5671)\n2019-08-22 10:14:40.063 [error] <0.735.0> Error on AMQP connection <0.735.0> (127.0.0.1:59192 -> 127.0.0.1:5671, state: starting):\nPLAIN login refused: user 'guest' - invalid credentials\n2019-08-22 10:14:40.063 [warning] <0.735.0> closing AMQP connection <0.735.0> (127.0.0.1:59192 -> 127.0.0.1:5671):\nclient unexpectedly closed TCP connection\n2019-08-22 10:15:12.613 [info] <0.743.0> Creating user 'guest'\n2019-08-22 10:15:28.370 [info] <0.750.0> Setting user tags for user 'guest' to [administrator]\n2019-08-22 10:15:51.352 [info] <0.768.0> Setting permissions for 'guest' in '/' to '.*', '.*', '.*'\n2019-08-22 10:15:54.237 [info] <0.774.0> accepting AMQP connection <0.774.0> (127.0.0.1:59202 -> 127.0.0.1:5671)\n2019-08-22 10:15:54.243 [info] <0.774.0> connection <0.774.0> (127.0.0.1:59202 -> 127.0.0.1:5671): user 'guest' authenticated and granted access to vhost '/'\n```\n\n```text\ncredentials = pika.PlainCredentials(<user-name>, <password>)\n```\n\n```py\nssl_options = pika.SSLOptions(context, \"rabbitmq-node-name\")\nparams = pika.ConnectionParameters(host=\"rabbitmq-node-name\",port=5671,ssl_options=ssl_options, credentials = ExternalCredentials())\n```\n\n```text\nrabbitmq-plugins.bat enable rabbitmq_auth_mechanism_ssl\n```\n\n========================================\n\nComments:\n- I have edited my question, the problem is that SSL is configured with the default 'guest' user, and so I can't access it from outside the local environment.\n- Can you the rabbitmq logs when access is denied to the user guest whiel logging in from a remote system ?\n- Nothing appears in the logs since it directly throws `pika.exceptions.AMQPConnectionError`\n- .... If you have a look at my code \"test_rabbitmq.py\" I don't specify a user/password since I am trying to access it over SSL? When the similar code is run on the localhost, the logs say: `2019-08-22 10:14:40.063 [error] Error on AMQP connection (127.0.0.1:59192 -> 127.0.0.1:5671, state: starting): PLAIN login refused: user 'guest' - invalid credentials`\n- Humm.. can you give External the first precedence like this {auth_mechanisms, ['EXTERNAL','PLAIN', 'AMQPLAIN'},\n- This is the problem: `2019-08-22 11:36:45.660 [info] accepting AMQP connection (127.0.0.1:59680 -> 127.0.0.1:5671) 2019-08-22 11:36:45.666 [info] connection (127.0.0.1:59680 -> 127.0.0.1:5671): user 'guest' authenticated and granted access to vhost '/'` It uses \"guest\" and not the user I have created. How to make it use a different user!\n- Hello, I am one of Pika's maintainers. Please continue the discussion via the `pika-python` mailing list.\n- In case you get an error `module 'pika' has no attribute 'ExternalCredentials'`, then you need to import `ExternalCredentials` properly, for example by qualifying with `pika.credentials.ExternalCredentials`.","metadata":{"transformedAt":"2026-08-18T18:33:20.188Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":234,"estimatedTokens":2623}}767{"id":"stack-3716426","source":"stackoverflow","questionId":3716426,"title":"Has anyone compiled a rabbitmq/amqp library for php 5.2.x on windows x64","tags":["php","rabbitmq","amqp","php-extension"],"text":"Title: Has anyone compiled a rabbitmq/amqp library for php 5.2.x on windows x64\nTags: php, rabbitmq, amqp, php-extension\nSource: Stack Overflow\n\nQuestion:\nI'm trying to publish messages to RabbitMQ from a php (5.2.x) script on my windows X64 dev machine.\n\nThe problem is that I didn't find any dll extension for php. My collegue is actually trying to build it (cf. How do you compile a PHP extension on windows with cygwin/mingw?), but without success :(.\n\nDoes anyone know where I can find a valid/working RabbitMQ dll extension for php (5.2.x)? Or if someone has the experience to do it correctly and quickly it would certainly be very helpful.\n\n========================================\n\nComments:\n- Even if it is not really an answer on the question, I think at this time it is the best solution to use. Many thx!","metadata":{"transformedAt":"2026-08-18T18:33:20.188Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":15,"estimatedTokens":204}}768{"id":"stack-68874153","source":"stackoverflow","questionId":68874153,"title":"Reliable Webhook dispatching system","tags":["apache-kafka","rabbitmq","webhooks","event-dispatching"],"text":"Title: Reliable Webhook dispatching system\nTags: apache-kafka, rabbitmq, webhooks, event-dispatching\nSource: Stack Overflow\n\nQuestion:\nI am having a hard time figuring out a reliable and scalable solution for a webhook dispatch system.\n\nThe current system uses `RabbitMQ` with a queue for webhooks (let's call it `events`), which are consumed and dispatched. This system worked for some time, but now there are a few problems:\n\n- If a system user generates too many events, it will take up the queue causing other users to not receive webhooks for a long time\n\n- If I split all events into multiple queues (by URL hash), it reduces the possibility of the first problem, but it still happens from time to time when a very busy user hits the same queue\n\n- If I try to put each URL into its own queue, the challenge is to dynamically create/assign consumers to those queues. As far as `RabbitMQ` documentation goes, the API is very limited in filtering for non-empty queues or for queues that do not have consumers assigned.\n\n- As far as `Kafka` goes, as I understand from reading everything about it, the situation will be the same in the scope of a single partition.\n\nSo, the question is - is there a better way/system for this purpose? Maybe I am missing a very simple solution that would allow one user to not interfere with another user?\n\nThanks in advance!\n\n========================================\n\nTop Answer:\nYou may experiment several rabbitmq features to mitigate your issue (without removing it completly):\n\nUse a public random exchange to split events across several queues. It will mitigate large spikes of events and dispatch work to several consumers.\n\nSet some TTL policies to your queues. This way, Rabbitmq may republish events to another group of queues (through another private random exchange for example) if they are not processed fast enough.\n\nYou may have several \"cycles\" of events, varying configuration (i.e number of cycles and TTL value for each cycle). Your first cycle handles fresh events the best it can, mitigating spikes through several queues under a random exchange. If it fails to handle events fast enough, events are moved to another cycle with dedicated queues and consumers.\n\nThis way, you can ensure that fresh events have a better change to be handled quickly, as they will always be published in the first cycle (and not behind a pile of old events from another user).\n\n========================================\n\nCode:\n```text\nRabbitMQ\n```\n\n```text\nevents\n```\n\n```text\nRabbitMQ\n```\n\n```text\nKafka\n```\n\n```text\ng:events\n```\n\n```text\nparent\n```\n\n```text\nchild\n```\n\n```text\ng:events:<url>\n```\n\n```text\nchild\n```\n\n```text\nurl\n```\n\n```text\nchild\n```\n\n```text\nchild\n```\n\n```text\nparent\n```\n\n```text\nchild\n```\n\n```text\nchild\n```\n\n```text\nparent\n```\n\n```text\nchild\n```\n\n```text\nchild\n```\n\n```text\nparent\n```\n\n```text\nchild\n```\n\n```text\nchild\n```\n\n```text\nack\n```\n\n```text\nparent\n```\n\n```text\nparent\n```\n\n```text\nparent\n```\n\n```text\nexactly-once\n```\n\n```text\nTransactions\n```\n\n========================================\n\nComments:\n- I feel like hashing is the correct solution. You can implement *incoming* rate limiting to prevent bad actors that slow a particular queue/partition down\n- Won't incoming rate-limiting slow down the producers? Also, it would mean, that \"slow\" messages need to go somewhere else anyway.\n- I didn't understand how do you split events into multiple queues using url hasing. Can you give some explanation, pls?\n- @nsv Each webhook handler has a unique URL. Each webhook handler can have multiple events assigned to it. So when an event is created, it is then put into the queue for its respective webhook handler and since each webhook handler has a unique URL, it's basically the same thing.\n- @Arthur but how do you manage if you have a queue per url when you so many urls?\n- @nsv Well, the queues are cleaned up when not in use. A slight drawback here is that I still had to use a locking mechanism (in my case, it was implemented using Redis) for creating the queues and for deleting them. Like a queue cannot be deleted by the housekeeping process if there was a message posted less than 30 seconds ago. If 30 seconds pass and the queue is empty, it is deleted. The Redis lock prevents the queue from being deleted if it is being posted to.\n- Well yes, but this will also introduce the possibility that a single user will start receiving events in parallel, breaking the \"order of events\".\n- Yes indeed. I wasn't realizing it was an issue while reading your post. I guess it leaves you with the \"put each URL in its own queue\" solution then.\n- Well the main challenge is - how to dynamically connect consumers to these queues? And how to evenly spread all consumers between all of the queues?\n- Can't your consumers be \"aware\" of the queue distribution you want, so they can create them when they are started and remove them when the job is done?\n- Well that's the question here :D Is there a way to evenly distribute consumers across dynamically created queues? So that each consumer takes a queue, that has no consumers and works on it and then moves to the next?\n- Not really what I am looking for. I have found a solution by the way how to deal with this problem using RabbitMQ. Will post an answer a bit later.\n- @Arthur I'm interested in your solution if you can find some time to it here.\n- @DavidL I've posted an answer to the question","metadata":{"transformedAt":"2026-08-18T18:33:20.189Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":27,"totalLines":162,"estimatedTokens":1352}}769{"id":"stack-37393740","source":"stackoverflow","questionId":37393740,"title":"AMQP/RabbitMQ - How to avoid race conditions","tags":["rabbitmq","amqp","race-condition"],"text":"Title: AMQP/RabbitMQ - How to avoid race conditions\nTags: rabbitmq, amqp, race-condition\nSource: Stack Overflow\n\nQuestion:\nI have the following architecture:\nArchitecture\n\n- There are a fixed number of input sources. Each input source is equivalent.\n\n- The AMQP broker. I am using RabbitMQ in my case.\n\n- Currently, there are 2 consumers. Again, each consumer is equivalent.\n\nThe input sources are sending commands to be processed. These commands are forwarded by the broker and picked up by one of the two consumers.\n\nI need the following behaviour:\n\n- If one input source sends multiple commands, all commands must be processed sequentially. That is, in the example of 2 commands, it is **not allowed** that consumer 1 is processing command 1 while consumer 2 is processing command 2 at the same time.\n\n- However, two commands originating from two different input sources can be processed simultaneously.\n\nIs it possible to enforce this behaviour with AMQP/RabbitMQ?\n\n========================================\n\nTop Answer:\nTo guarantee sequence you may need to aggregate the messages. You can batch the commands from one source into a message before publishing to the queue, so the message into the queue can contain one or more commands that will be executed by the consumer.\n\n========================================\n\nCode:\n```text\nenvelope.getExchange()\n```\n\n```text\ntag\n```\n\n```text\nAMQP.BasicProperties properties\n```\n\n```text\ntag\n```\n\n========================================\n\nComments:\n- I am not quite sure if this solves my problem. This prevents that a consumer has more than one message at the same time. However, and I might be wrong here, this does not prevent that another consumer receives a message originating from the same input source as the first consumer is processing at the moment?\n- it depends what do you mean as `broker`, do you put all the messages to the same queue ?\n- All messages are put in the same queue. Should I create a queue for each input source? This means that each consumer is listening to all queues?\n- Ok, I modified the answer,let me know if can work in this way.\n- Let's say I have 10 input sources. This means I have 10 queues. Let's say consumer 1 is responsible for queue 1-5 and consumer 2 for 6-10. If consumer 1 (or 2) goes down, queue 1-5 (or 6-10) won't be processed anymore. Isn't this kind of architecture an anti-pattern for the high availability properties of an AMQP?\n- I am not able to batch/collect messages before publishing. Each message should be processed as soon as possible.","metadata":{"transformedAt":"2026-08-18T18:33:20.189Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":57,"estimatedTokens":636}}770{"id":"stack-25832049","source":"stackoverflow","questionId":25832049,"title":"Why declare Exchange in RabbitMQ?","tags":["c#","rabbitmq","rabbitmq-exchange"],"text":"Title: Why declare Exchange in RabbitMQ?\nTags: c#, rabbitmq, rabbitmq-exchange\nSource: Stack Overflow\n\nQuestion:\nI am working on a project with RabbitMQ. My code is below.\n\n**Producer:** \n\n```\npublic static void Main()\n{\n var factory = new ConnectionFactory() { HostName = \"localhost\" };\n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(\"hello\", false, false, false, null);\n\n string message = \"Hello World!\";\n var body = Encoding.UTF8.GetBytes(message);\n\n channel.BasicPublish(\"\", \"hello\", null, body);\n Console.WriteLine(\" [x] Sent {0}\", message);\n }\n }\n}\n```\n\n**Consumer with Exchange declared:** \n\n```\npublic static void Main()\n{\n var factory = new ConnectionFactory() { HostName = \"localhost\" };\n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n channel.ExchangeDeclare(\"hello\", \"direct\",false, false, false, null);\n channel.QueueDeclare(\"hello\", false, false, false, null);\n\n var consumer = new QueueingBasicConsumer(channel);\n channel.BasicConsume(\"hello\", true, consumer);\n\n Console.WriteLine(\" [*] Waiting for messages.\" +\n \"To exit press CTRL+C\");\n while (true)\n {\n var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();\n\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n Console.WriteLine(\" [x] Received {0}\", message);\n }\n }\n }\n```\n\n**Consumer without Exchange declared:** \n\n```\npublic static void Main()\n{\n var factory = new ConnectionFactory() { HostName = \"localhost\" };\n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(\"hello\", false, false, false, null);\n\n var consumer = new QueueingBasicConsumer(channel);\n channel.BasicConsume(\"hello\", true, consumer);\n\n Console.WriteLine(\" [*] Waiting for messages.\" +\n \"To exit press CTRL+C\");\n while (true)\n {\n var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();\n\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n Console.WriteLine(\" [x] Received {0}\", message);\n }\n }\n }\n```\n\nBoth consumer code works well, so what's the main use of declaring exchange? I am confused. Can anyone clarify?\n\n========================================\n\nCode:\n```text\npublic static void Main()\n{\n var factory = new ConnectionFactory() { HostName = \"localhost\" };\n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(\"hello\", false, false, false, null);\n\n string message = \"Hello World!\";\n var body = Encoding.UTF8.GetBytes(message);\n\n channel.BasicPublish(\"\", \"hello\", null, body);\n Console.WriteLine(\" [x] Sent {0}\", message);\n }\n }\n}\n```\n\n```text\npublic static void Main()\n{\n var factory = new ConnectionFactory() { HostName = \"localhost\" };\n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n channel.ExchangeDeclare(\"hello\", \"direct\",false, false, false, null);\n channel.QueueDeclare(\"hello\", false, false, false, null);\n\n var consumer = new QueueingBasicConsumer(channel);\n channel.BasicConsume(\"hello\", true, consumer);\n\n Console.WriteLine(\" [*] Waiting for messages.\" +\n \"To exit press CTRL+C\");\n while (true)\n {\n var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();\n\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n Console.WriteLine(\" [x] Received {0}\", message);\n }\n }\n }\n```\n\n```text\npublic static void Main()\n{\n var factory = new ConnectionFactory() { HostName = \"localhost\" };\n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(\"hello\", false, false, false, null);\n\n var consumer = new QueueingBasicConsumer(channel);\n channel.BasicConsume(\"hello\", true, consumer);\n\n Console.WriteLine(\" [*] Waiting for messages.\" +\n \"To exit press CTRL+C\");\n while (true)\n {\n var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();\n\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n Console.WriteLine(\" [x] Received {0}\", message);\n }\n }\n }\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.189Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":167,"estimatedTokens":1151}}771{"id":"stack-54406504","source":"stackoverflow","questionId":54406504,"title":"RabbitMQ NACK messages","tags":["node.js","rabbitmq","amqp"],"text":"Title: RabbitMQ NACK messages\nTags: node.js, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nMy experience: in a publish/subscribe scenario, if a subscriber nacks a message, the nacked message is immediately re-queued at the front of the queue and it will be the next message the subscriber gets.\n\nIs there a way to avoid this? Is is possible to nack a message in a way that the next message will definetly not be the one just nacked?\n\nI am using Node.js and amqp.node to communicate with RabbitMQ\n\n========================================\n\nTop Answer:\nQuestion: My experience: in a publish/subscribe scenario, if a subscriber nacks a message, the nacked message is immediately re-queued at the front of the queue and it will be the next message the subscriber gets.\n\n Yes that is correct. When a message is requeued with\n channel.basicNack, it will be placed to its original position in its\n queue, if possible. If not (due to concurrent deliveries and\n acknowledgements from other consumers when multiple consumers a\n queue), the message will be requeued to a position closer to queue\n head. Source: https://www.rabbitmq.com/nack.html\n\nQuestion: Is there a way to avoid this? Is is possible to nack a message in a way that the next message will definetly not be the one just nacked?\n\nIt is not possible to achieve this with nack. One way to achieve this is by re-publish the message back to queue where ever nack needed.\n\n- Get the message and immediately send the ack back.\n\n- Process the message, if successful do nothing.\nIf fails do not send the nack instead republish message back to the\nqueue.\n\n========================================\n\nCode:\n```text\nNack\n```\n\n```text\nNack\n```\n\n```text\nack\n```\n\n```text\nredelivered\n```\n\n```text\nNack\n```\n\n```text\nack\n```\n\n```text\nNack\n```\n\n```text\nrequeue\n```\n\n```text\nrequeue\n```\n\n```text\nrequeue\n```\n\n```text\nNack\n```\n\n```text\nNack\n```\n\n========================================\n\nComments:\n- That is a possible solution, but it is subject to a possible data loss if the consumer fails after the ack and before republishing. I guess it could be a possible workaround to republish and then acking, but I don't know if it's a good design or if it would cause noticeable performance issues.\n- +1 for the note about republish - while it's probably not what OP is looking for, and won't help if the queue is already empty, it does achieve the relocation of the message to the end of whatever line is there.\n- Reordering `try { process message; } finally { if failed then republish; ack message }` -- has the added benefit that an exception in process will still do the right thing.\n- \"What if I can't process a particular message right now but maybe later? If your messaging structure was designed properly, this would never be true\". You are right: in a properly designed system this would not happen. BUT, legacy code and errors in the past could leave us to deal with these problems today, without being able to fix the design. My scenario is that processing messages could result in concurrent access to DB causing a serialization error due to poor design. Redesigning is unfortunately not an option right now (as much as I would love to), so that's what we have to deal with.\n- @smellyarmpits - At some level, your implementation is going to have to account for the original legacy design and fix it. Since I don't know the details, I can't say how you should go about doing that, but at a minimum, you need to have one queue per message type. You don't have to read from the queues concurrently, but you do need to separate out your different types of messages. Beyond that, most databases handle concurrency via locking. This may not be an easy problem to solve!\n- > At some level, your implementation is going to have to account for the original legacy design and fix it. I totally agre, but I am not in charge of these decisions :D\n- I really don't know what to tell you then - You've described behavior that is immutable as an issue. If the behavior cannot be changed, and the legacy code cannot be changed, then what can be changed?\n- The problem is that the messages are already divided by type on different queues, but different messages may have to work on the same database row, causing concurrency problems (in case of multiple consumers): 2 consumers may pick up 2 different messages that refer to the same db row. If this happens I want to deal with the consumer(s) that failed in order to re queue the message to be processed later, because most likely this kind of error is gonna be solved by delaying the processing\n- How long of a delay are we talking about here? And in all fairness, this is not at all the problem described in the original question :)\n- mmm well, the original post is more general and does not describe the problem in detail :)\n- Additional precision, `nack` is a RabbitMQ-specific addition which is the same that basic.reject (ie no-ack the message), but allows batching no-acks.","metadata":{"transformedAt":"2026-08-18T18:33:20.189Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":98,"estimatedTokens":1240}}772{"id":"stack-17221874","source":"stackoverflow","questionId":17221874,"title":"How to use Java RabbitMQ and set URI server?","tags":["java","rabbitmq","amqp"],"text":"Title: How to use Java RabbitMQ and set URI server?\nTags: java, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI'm using the RabbitMQ Java API to connect to a RabbitMQ server. I want to use `ConnectionFactory.setUri(...)` to configure which server to use. It appears to munge the virtual host.\n\nThere's a default virtual host named `/`.\n\n```\nimport com.rabbitmq.client.ConnectionFactory;\nimport com.rabbitmq.client.Connection;\nimport com.rabbitmq.client.Channel;\n\nimport java.net.URI;\n\npublic class Worker {\n\n public static void main(String[] argv) throws Exception {\n\n ConnectionFactory factory = new ConnectionFactory();\n final URI uri = URI.create(\"amqp://guest:guest@localhost:5672/\");\n factory.setUri(uri);\n final Connection connection = factory.newConnection();\n final Channel channel = connection.createChannel();\n }\n}\n```\n\nUsing the above code, the configured virtual host is empty. There doesn't seem to be a way, using the URI, to configure the virtual host to be `/`.\n\nIs there a way to do this?\n\n========================================\n\nTop Answer:\nYour need to URL-encode the '/' using %2F\n\n========================================\n\nCode:\n```text\nimport com.rabbitmq.client.ConnectionFactory;\nimport com.rabbitmq.client.Connection;\nimport com.rabbitmq.client.Channel;\n\nimport java.net.URI;\n\npublic class Worker {\n\n public static void main(String[] argv) throws Exception {\n\n ConnectionFactory factory = new ConnectionFactory();\n final URI uri = URI.create(\"amqp://guest:guest@localhost:5672/\");\n factory.setUri(uri);\n final Connection connection = factory.newConnection();\n final Channel channel = connection.createChannel();\n }\n}\n```\n\n```text\nConnectionFactory.setUri(...)\n```\n\n```text\n/\n```\n\n```text\n/\n```\n\n```text\nsetUri\n```\n\n```java\nConnectionFactory factory = new ConnectionFactory();\nfactory.setUri(\"amqp://guest:guest@localhost:5672/%2F\");\n```\n\n```text\n/\n```\n\n```text\n/\n```\n\n```text\n%2f\n```\n\n========================================\n\nComments:\n- I tried with the following (appending another slash at the end): `amqp://guest:guest@localhost:5672//` and ended up getting `java.lang.IllegalArgumentException: Multiple segments in path of AMQP URI: //`. I guess for now the only way is to use the factory methods to set the parameters like you've done.","metadata":{"transformedAt":"2026-08-18T18:33:20.189Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":98,"estimatedTokens":585}}773{"id":"stack-13379327","source":"stackoverflow","questionId":13379327,"title":"How to get RabbitMQ management command line tool to work on Windows","tags":["windows-8","rabbitmq"],"text":"Title: How to get RabbitMQ management command line tool to work on Windows\nTags: windows-8, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI've followed the instructions RabbitMQ management command line tool but when running with \n\n```\npython.exe rabbitmqadmin.exe\n```\n\nGives me an error:\n\n```\nERROR: Action not specified\n```\n\nand:\n\n```\nrabbitmqadmin --help\n```\n\ndisplays:\n\nIs this really the case or am I doing something wrong?\n\n========================================\n\nTop Answer:\nThe error means exactly what it says, you didn't invoke rabbitmqadmin correctly by specifying a command.\n\n### **Walkthough on how to use rabbitmqadmin:**\n\nFor me the executable is called: `rabbitmqadmin` downloaded from here: \nhttps://www.rabbitmq.com/management-cli.html\n\n**Executing it from commandline without any options, and you get an error:** \n\n```\neric@dev ~$ python rabbitmqadmin\nERROR: Action not specified\nrabbitmqadmin --help for help\n```\n\n**Getting help on generic options:**\n\n```\neric@dev ~$ python rabbitmqadmin --help\n\n```\n\n**Get a list of subcommands you can run:**\n\n```\npython rabbitmqadmin help subcommands\n```\n\n**Get a list of users:**\n\n```\neric@dev ~$ python rabbitmqadmin list users\n+-------+------------------------------+---------------+\n| name | password_hash | tags |\n+-------+------------------------------+---------------+\n| guest | oiz5zGozWya1qBblv6gbFrGYCnA= | administrator |\n+-------+------------------------------+---------------+\n```\n\n**List vhosts:**\n\n```\neric@dev ~$ python rabbitmqadmin list vhosts\n+------+----------+----------------+-------------------------+----------+----------+---------+\n| name | messages | messages_ready | messages_unacknowledged | recv_oct | send_oct | tracing |\n+------+----------+----------------+-------------------------+----------+----------+---------+\n| / | 0 | 0 | 0 | 1218 | 1028 | False |\n| foo | | | | | | False |\n+------+----------+----------------+-------------------------+----------+----------+---------+\n```\n\n**List Exchanges:**\n\n```\neric@dev ~$ python rabbitmqadmin list exchanges\n+-------+--------------------+---------+-------------+---------+----------+\n| vhost | name | type | auto_delete | durable | internal |\n+-------+--------------------+---------+-------------+---------+----------+\n| / | | direct | False | True | False |\n| / | amq.direct | direct | False | True | False |\n| / | amq.fanout | fanout | False | True | False |\n| / | amq.headers | headers | False | True | False |\n| / | amq.match | headers | False | True | False |\n| / | amq.rabbitmq.log | topic | False | True | False |\n| / | amq.rabbitmq.trace | topic | False | True | False |\n| / | amq.topic | topic | False | True | False |\n| / | logs | fanout | False | False | False |\n| / | my-exchange | topic | False | True | False |\n+-------+--------------------+---------+-------------+---------+----------+\n```\n\n**Login as default user and get nodes:**\n\n```\npython rabbitmqadmin --username=guest --password=guest list nodes\n\n```\n\n**Login as guest and List Queues:**\n\n```\neric@dev ~$ python rabbitmqadmin --username=guest --password=guest list queues\n+-------+--------------------------------+-------------+-----------+---------+------------------------+---------------------+--------+----------+----------------+-------------------------+---------------------+--------+---------+\n| vhost | name | auto_delete | consumers | durable | exclusive_consumer_tag | idle_since | memory | messages | messages_ready | messages_unacknowledged | node | policy | status |\n+-------+--------------------------------+-------------+-----------+---------+------------------------+---------------------+--------+----------+----------------+-------------------------+---------------------+--------+---------+\n| / | amq.gen-hWC6xdjX3g5GABc2nED-YQ | True | 1 | False | | 2014-09-08 13:24:34 | 14048 | 0 | 0 | 0 | rabbit@ip-15-1-5-54 | | running |\n+-------+--------------------------------+-------------+-----------+---------+------------------------+---------------------+--------+----------+----------------+-------------------------+---------------------+--------+---------+\n```\n\n========================================\n\nCode:\n```text\npython.exe rabbitmqadmin.exe\n```\n\n```text\nERROR: Action not specified\n```\n\n```text\nrabbitmqadmin --help\n```\n\n```text\nERROR: Action not specified\n```\n\n```text\npython.exe rabbitmqadmin --help\npython.exe rabbitmqadmin declare exchange name=my-exchange type=topic\n```\n\n```text\neric@dev ~$ python rabbitmqadmin\nERROR: Action not specified\nrabbitmqadmin --help for help\n```\n\n```text\neric@dev ~$ python rabbitmqadmin --help\n<prints a mountain of help>\n```\n\n```text\npython rabbitmqadmin help subcommands\n```\n\n```text\neric@dev ~$ python rabbitmqadmin list users\n+-------+------------------------------+---------------+\n| name | password_hash | tags |\n+-------+------------------------------+---------------+\n| guest | oiz5zGozWya1qBblv6gbFrGYCnA= | administrator |\n+-------+------------------------------+---------------+\n```\n\n```text\neric@dev ~$ python rabbitmqadmin list vhosts\n+------+----------+----------------+-------------------------+----------+----------+---------+\n| name | messages | messages_ready | messages_unacknowledged | recv_oct | send_oct | tracing |\n+------+----------+----------------+-------------------------+----------+----------+---------+\n| / | 0 | 0 | 0 | 1218 | 1028 | False |\n| foo | | | | | | False |\n+------+----------+----------------+-------------------------+----------+----------+---------+\n```\n\n```text\neric@dev ~$ python rabbitmqadmin list exchanges\n+-------+--------------------+---------+-------------+---------+----------+\n| vhost | name | type | auto_delete | durable | internal |\n+-------+--------------------+---------+-------------+---------+----------+\n| / | | direct | False | True | False |\n| / | amq.direct | direct | False | True | False |\n| / | amq.fanout | fanout | False | True | False |\n| / | amq.headers | headers | False | True | False |\n| / | amq.match | headers | False | True | False |\n| / | amq.rabbitmq.log | topic | False | True | False |\n| / | amq.rabbitmq.trace | topic | False | True | False |\n| / | amq.topic | topic | False | True | False |\n| / | logs | fanout | False | False | False |\n| / | my-exchange | topic | False | True | False |\n+-------+--------------------+---------+-------------+---------+----------+\n```\n\n```text\npython rabbitmqadmin --username=guest --password=guest list nodes\n\n<prints mountain of information about nodes>\n```\n\n```text\neric@dev ~$ python rabbitmqadmin --username=guest --password=guest list queues\n+-------+--------------------------------+-------------+-----------+---------+------------------------+---------------------+--------+----------+----------------+-------------------------+---------------------+--------+---------+\n| vhost | name | auto_delete | consumers | durable | exclusive_consumer_tag | idle_since | memory | messages | messages_ready | messages_unacknowledged | node | policy | status |\n+-------+--------------------------------+-------------+-----------+---------+------------------------+---------------------+--------+----------+----------------+-------------------------+---------------------+--------+---------+\n| / | amq.gen-hWC6xdjX3g5GABc2nED-YQ | True | 1 | False | | 2014-09-08 13:24:34 | 14048 | 0 | 0 | 0 | rabbit@ip-15-1-5-54 | | running |\n+-------+--------------------------------+-------------+-----------+---------+------------------------+---------------------+--------+----------+----------------+-------------------------+---------------------+--------+---------+\n```\n\n```text\nrabbitmqadmin\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.189Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":14,"totalLines":213,"estimatedTokens":2033}}774{"id":"stack-32287113","source":"stackoverflow","questionId":32287113,"title":"How to listen to multiple queues with autowired Spring Boot?","tags":["spring-boot","rabbitmq","amqp"],"text":"Title: How to listen to multiple queues with autowired Spring Boot?\nTags: spring-boot, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI'm new to Spring boot and I'm playing around with it. Currently I've build some apllications that I want to be able to communicate with each other through queues.\nI currently have a Listener object that can receive message from a particular queue.\n\n```\n@Configuration\npublic class Listener {\n\n final static String queueName = \"myqueue\";\n\n @Bean\n SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(connectionFactory);\n container.setQueueNames(queueName);\n container.setMessageListener(listenerAdapter);\n return container;\n }\n\n @Bean\n Receiver receiver() {\n return new Receiver();\n }\n\n @Bean\n MessageListenerAdapter listenerAdapter(Receiver receiver) {\n return new MessageListenerAdapter(receiver, \"receiveMessage\");\n }\n}\n```\n\nThis works. However, now I want to be able to listen to another queue. So I figured I'd copy the above object and change the queue name. Unfortunately this did not work as Spring boot only creates a connection for one of them.\nAny ideas on how I can have my Spring Boot application listen to multiple queues?\n\n========================================\n\nTop Answer:\nYou can try this\n\nIn application.properties\n\n```\nrabbitmq.queue.names= com.queue1,com.queue2\n```\n\nIn Java file \n\n```\n@RabbitListener(queues = \"#{'${rabbitmq.queue.names}'.split(',')}\")\npublic void receiveMessage(Message message) {\n try {\n if (processmessage(message)); \n }\n } catch (Exception ex) {\n LOGGER.error(\"Exception while processing the Message\", ex);\n }\n\n}\n```\n\n========================================\n\nCode:\n```text\n@Configuration\npublic class Listener {\n\n final static String queueName = \"myqueue\";\n\n @Bean\n SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(connectionFactory);\n container.setQueueNames(queueName);\n container.setMessageListener(listenerAdapter);\n return container;\n }\n\n @Bean\n Receiver receiver() {\n return new Receiver();\n }\n\n @Bean\n MessageListenerAdapter listenerAdapter(Receiver receiver) {\n return new MessageListenerAdapter(receiver, \"receiveMessage\");\n }\n}\n```\n\n```text\n@Component\npublic class EventListener {\n\n private static Logger LOG = LoggerFactory.getLogger(EventListener.class);\n private CountDownLatch latch = new CountDownLatch(1);\n\n @RabbitListener(queues = \"myqueue\")\n public void processPaymentMessage(Object message) {\n LOG.info(\"Message is of type: \" + message.getClass().getName());\n if(!(message instanceof byte[])) message = ((Message) message).getBody();\n String content = new String((byte[])message, StandardCharsets.UTF_8);\n LOG.info(\"Received on myqueue: \" + content);\n latch.countDown();\n }\n\n @RabbitListener(queues = \"myotherqueue\")\n public void processOrderMessage(Object message) {\n LOG.info(\"Message is of type: \" + message.getClass().getName());\n if(!(message instanceof byte[])) message = ((Message) message).getBody();\n String content = new String((byte[])message, StandardCharsets.UTF_8); \n LOG.info(\"Received on myotherqueue: \" + content);\n latch.countDown();\n } \n}\n```\n\n```text\nrabbitmq.queue.names= com.queue1,com.queue2\n```\n\n```text\n@RabbitListener(queues = \"#{'${rabbitmq.queue.names}'.split(',')}\")\npublic void receiveMessage(Message message) {\n try {\n if (processmessage(message)); \n }\n } catch (Exception ex) {\n LOGGER.error(\"Exception while processing the Message\", ex);\n }\n\n}\n```\n\n```text\n@Component\n@EnableRabbit\n@Slf4j\nclass StatusListener {\n Library library\n int messageCounter\n\n @Autowired\n StatusListener(Library library) {\n this.library = library\n }\n\n @RabbitListener(queues = '#{library.allStatusQueues.split(\",\")}')\n void receiveMessage(Message message) {\n messageCounter++\n log.info(\"Rabbit Listener received message <\" + new String(message.body) + \"> (\" + messageCounter + \")\")\n }\n}\n```\n\n```text\n@Component\n@ConfigurationProperties\n@RefreshScope\nclass Library {\n String allStatusQueues\n}\n```\n\n```text\nall-status-queues=queue1,queue2,queue3,queue4\n```\n\n========================================\n\nComments:\n- I was looking for something like that for hours! thanks","metadata":{"transformedAt":"2026-08-18T18:33:20.189Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":176,"estimatedTokens":1176}}775{"id":"stack-48583893","source":"stackoverflow","questionId":48583893,"title":"Rabbit-Mq not routing to dead letter queue after being rejected","tags":["c#","rabbitmq"],"text":"Title: Rabbit-Mq not routing to dead letter queue after being rejected\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm currently playing around with Rabbit-Mq, and am trying to implement a \"dead-letter\" queue, a queue for failed messages. I've been reading the rabbit documentation: https://www.rabbitmq.com/dlx.html.\n\nand have come up with this example:\n\n```\ninternal class Program\n{\n private const string WorkerExchange = \"work.exchange\";\n private const string RetryExchange = \"retry.exchange\";\n public const string WorkerQueue = \"work.queue\";\n private const string RetryQueue = \"retry.queue\";\n\n static void Main(string[] args)\n {\n var factory = new ConnectionFactory { HostName = \"localhost\" };\n\n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n channel.ExchangeDeclare(WorkerExchange, \"direct\");\n channel.QueueDeclare\n (\n WorkerQueue, true, false, false,\n new Dictionary\n {\n {\"x-dead-letter-exchange\", RetryExchange},\n\n // I have tried with and without this next key\n {\"x-dead-letter-routing-key\", RetryQueue}\n }\n );\n channel.QueueBind(WorkerQueue, WorkerExchange, string.Empty, null);\n\n channel.ExchangeDeclare(RetryExchange, \"direct\");\n channel.QueueDeclare\n (\n RetryQueue, true, false, false,\n new Dictionary {\n { \"x-dead-letter-exchange\", WorkerExchange },\n { \"x-message-ttl\", 30000 },\n }\n );\n channel.QueueBind(RetryQueue, RetryExchange, string.Empty, null);\n\n var consumer = new EventingBasicConsumer(channel);\n consumer.Received += (model, ea) =>\n {\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n Console.WriteLine(\" [x] Received {0}\", message);\n\n Thread.Sleep(1000);\n Console.WriteLine(\"Rejected message\");\n\n // also tried channel.BasicNack(ea.DeliveryTag, false, false);\n channel.BasicReject(ea.DeliveryTag, false);\n };\n\n channel.BasicConsume(WorkerQueue, false, consumer);\n\n Console.WriteLine(\" Press [enter] to exit.\");\n Console.ReadLine();\n }\n }\n }\n}\n```\n\nImage of queue when publishing to worker queue:\nhttps://i.sstatic.net/K6xAq.png\n\nImage of the retry queue:\nhttps://i.sstatic.net/rVuBt.png\n\nI feel as though I'm missing some small details but can't seem to find what they are.\n\nThanks in advance\n\n========================================\n\nTop Answer:\nTurns out that if a dead letter exchange is a `direct` exchange then the queue parameters require a `x-dead-letter-routing-key`. Above (in the question) I am using this key in the dictionary to try and route my messages but what I am not doing is adding a route to my binding, here is an updated version of the code that works:\n\n```\ninternal class Program\n{\n private const string WorkerExchange = \"work.exchange\";\n private const string RetryExchange = \"retry.exchange\";\n public const string WorkerQueue = \"work.queue\";\n private const string RetryQueue = \"retry.queue\";\n\n static void Main(string[] args)\n {\n var factory = new ConnectionFactory { HostName = \"localhost\" };\n\n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n channel.ExchangeDeclare(WorkerExchange, \"direct\");\n channel.QueueDeclare\n (\n WorkerQueue, true, false, false,\n new Dictionary\n {\n {\"x-dead-letter-exchange\", RetryExchange},\n {\"x-dead-letter-routing-key\", RetryQueue}\n }\n );\n channel.QueueBind(WorkerQueue, WorkerExchange, WorkerQueue, null);\n\n channel.ExchangeDeclare(RetryExchange, \"direct\");\n channel.QueueDeclare\n (\n RetryQueue, true, false, false,\n new Dictionary\n {\n {\"x-dead-letter-exchange\", WorkerExchange},\n {\"x-dead-letter-routing-key\", WorkerQueue},\n {\"x-message-ttl\", 30000},\n }\n );\n channel.QueueBind(RetryQueue, RetryExchange, RetryQueue, null);\n\n var consumer = new EventingBasicConsumer(channel);\n consumer.Received += (model, ea) =>\n {\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n Console.WriteLine(\" [x] Received {0}\", message);\n\n Thread.Sleep(1000);\n Console.WriteLine(\"Rejected message\");\n channel.BasicNack(ea.DeliveryTag, false, false);\n };\n\n channel.BasicConsume(WorkerQueue, false, consumer);\n\n Console.WriteLine(\" Press [enter] to exit.\");\n Console.ReadLine();\n }\n }\n }\n```\n\nThe difference being that the call to `channel.QueueBind(WorkerQueue, WorkerExchange, WorkerQueue, null);` now supplies the routing key to be the same as the queuename, so when the message \"dead-letters\" it gets routed to the exchange via this key\n\n========================================\n\nCode:\n```text\ninternal class Program\n{\n private const string WorkerExchange = \"work.exchange\";\n private const string RetryExchange = \"retry.exchange\";\n public const string WorkerQueue = \"work.queue\";\n private const string RetryQueue = \"retry.queue\";\n\n static void Main(string[] args)\n {\n var factory = new ConnectionFactory { HostName = \"localhost\" };\n\n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n channel.ExchangeDeclare(WorkerExchange, \"direct\");\n channel.QueueDeclare\n (\n WorkerQueue, true, false, false,\n new Dictionary<string, object>\n {\n {\"x-dead-letter-exchange\", RetryExchange},\n\n // I have tried with and without this next key\n {\"x-dead-letter-routing-key\", RetryQueue}\n }\n );\n channel.QueueBind(WorkerQueue, WorkerExchange, string.Empty, null);\n\n channel.ExchangeDeclare(RetryExchange, \"direct\");\n channel.QueueDeclare\n (\n RetryQueue, true, false, false,\n new Dictionary<string, object> {\n { \"x-dead-letter-exchange\", WorkerExchange },\n { \"x-message-ttl\", 30000 },\n }\n );\n channel.QueueBind(RetryQueue, RetryExchange, string.Empty, null);\n\n var consumer = new EventingBasicConsumer(channel);\n consumer.Received += (model, ea) =>\n {\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n Console.WriteLine(\" [x] Received {0}\", message);\n\n Thread.Sleep(1000);\n Console.WriteLine(\"Rejected message\");\n\n // also tried channel.BasicNack(ea.DeliveryTag, false, false);\n channel.BasicReject(ea.DeliveryTag, false);\n };\n\n channel.BasicConsume(WorkerQueue, false, consumer);\n\n Console.WriteLine(\" Press [enter] to exit.\");\n Console.ReadLine();\n }\n }\n }\n}\n```\n\n```text\nfanout\n```\n\n```text\nchannel.ExchangeDeclare(RetryExchange, \"fanout\");\n```\n\n```text\ninternal class Program\n{\n private const string WorkerExchange = \"work.exchange\";\n private const string RetryExchange = \"retry.exchange\";\n public const string WorkerQueue = \"work.queue\";\n private const string RetryQueue = \"retry.queue\";\n\n static void Main(string[] args)\n {\n var factory = new ConnectionFactory { HostName = \"localhost\" };\n\n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n channel.ExchangeDeclare(WorkerExchange, \"direct\");\n channel.QueueDeclare\n (\n WorkerQueue, true, false, false,\n new Dictionary<string, object>\n {\n {\"x-dead-letter-exchange\", RetryExchange},\n {\"x-dead-letter-routing-key\", RetryQueue}\n }\n );\n channel.QueueBind(WorkerQueue, WorkerExchange, WorkerQueue, null);\n\n channel.ExchangeDeclare(RetryExchange, \"direct\");\n channel.QueueDeclare\n (\n RetryQueue, true, false, false,\n new Dictionary<string, object>\n {\n {\"x-dead-letter-exchange\", WorkerExchange},\n {\"x-dead-letter-routing-key\", WorkerQueue},\n {\"x-message-ttl\", 30000},\n }\n );\n channel.QueueBind(RetryQueue, RetryExchange, RetryQueue, null);\n\n var consumer = new EventingBasicConsumer(channel);\n consumer.Received += (model, ea) =>\n {\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n Console.WriteLine(\" [x] Received {0}\", message);\n\n Thread.Sleep(1000);\n Console.WriteLine(\"Rejected message\");\n channel.BasicNack(ea.DeliveryTag, false, false);\n };\n\n channel.BasicConsume(WorkerQueue, false, consumer);\n\n Console.WriteLine(\" Press [enter] to exit.\");\n Console.ReadLine();\n }\n }\n }\n```\n\n```text\ndirect\n```\n\n```text\nx-dead-letter-routing-key\n```\n\n```text\nchannel.QueueBind(WorkerQueue, WorkerExchange, WorkerQueue, null);\n```\n\n```text\nchannel.QueueDeclare\n (\n WorkerQueue, true, false, false,\n new Dictionary<string, object>\n {\n {\"x-dead-letter-exchange\", RetryExchange}\n }\n );\n```\n\n```text\nchannel.ExchangeDeclare(WorkerExchange, \"direct\");\n\nchannel.QueueBind(WorkerQueue, WorkerExchange, WorkerQueue, null);\n\nchannel.ExchangeDeclare(RetryExchange, \"direct\");\nchannel.QueueDeclare\n (\n RetryQueue, true, false, false,\n new Dictionary<string, object>\n {\n {\"x-dead-letter-exchange\", WorkerExchange},\n {\"x-dead-letter-routing-key\", WorkerQueue},\n {\"x-message-ttl\", 30000},\n }\n );\nchannel.QueueBind(RetryQueue, RetryExchange, RetryQueue, null);\n```\n\n```text\n{\"x-dead-letter-routing-key\", RetryQueue}\n```\n\n========================================\n\nComments:\n- Thank you! Didn't see that answer, was searching for quite a while\n- I also figured out that the \"x-dead-letter-routing-key\" wasn't working because I didn't specify a routing key on the binding and was assuming it would route via queue name, which was a poor, unfounded assumption","metadata":{"transformedAt":"2026-08-18T18:33:20.189Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":342,"estimatedTokens":2627}}776{"id":"stack-54322974","source":"stackoverflow","questionId":54322974,"title":"WSL: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: Socket closed","tags":["rabbitmq","celery","windows-subsystem-for-linux"],"text":"Title: WSL: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: Socket closed\nTags: rabbitmq, celery, windows-subsystem-for-linux\nSource: Stack Overflow\n\nQuestion:\nI can't open the socket using celery and WSL.\n\nSee the following info:\n\n- [ ] output of `celery -A proj report`:\n\n```\nsoftware -> celery:3.1.26.post2 (Cipater) kombu:3.0.37 py:3.6.7\n billiard:3.3.0.23 py-amqp:1.4.9\nplatform -> system:Linux arch:64bit, ELF imp:CPython\nloader -> celery.loaders.app.AppLoader\nsettings -> transport:pyamqp results:disabled\nBROKER_URL: 'amqp://guest:********@localhost:5672//'\n```\n\n- [ ]contents of `pip freeze` in the issue.\n\nI am using pipenv. Pipfile:\n\n```\n[[source]]\nname = \"pypi\"\nurl = \"https://pypi.org/simple\"\nverify_ssl = true\n\n[dev-packages]\n\n[packages]\ndjango = \"*\"\ndjango-allauth = \"*\"\ndjango-crispy-forms = \"*\"\ndjango-debug-toolbar = \"==1.10.\"\nnumpy = \"==1.15.3\"\ncolorama = \"==0.4.0\"\ndateparser = \"==0.7.0\"\ndjango-extensions = \"*\"\npython-binance = \"*\"\nmisaka = \"*\"\ndjango-celery = \"*\"\ncelery = \"*\"\n\n[requires]\npython_version = \"3.6\"\n```\n\n### Steps to Reproduce\n\nI am in WSL:\n\nsudo apt-get install rabbitmq-server\n\nsudo service rabbitmq-server restart\n\nchmod -R 777 ./ ## otherwise I don't have permissions\n\n### Other infos\n\ntasks.py:\n\n```\nfrom celery import Celery\n\n# app = Celery('tasks', broker='amqp://jm-user1:sample@localhost/jm-vhost')\n# app = Celery('tasks', broker='amqp://guest@localhost//')\napp = Celery('tasks', broker='pyamqp://guest@localhost//')\n\n@app.task\ndef add(x, y):\n return x + y\n```\n\nrabbitmqctl status:\n\n```\n[{pid,1716},\n {running_applications,\n [{rabbit,\"RabbitMQ\",\"3.6.10\"},\n {ranch,\"Socket acceptor pool for TCP protocols.\",\"1.3.0\"},\n {ssl,\"Erlang/OTP SSL application\",\"8.2.3\"},\n {public_key,\"Public key infrastructure\",\"1.5.2\"},\n {asn1,\"The Erlang ASN1 compiler version 5.0.4\",\"5.0.4\"},\n {rabbit_common,\n \"Modules shared by rabbitmq-server and rabbitmq-erlang-client\",\n \"3.6.10\"},\n {xmerl,\"XML parser\",\"1.3.16\"},\n {crypto,\"CRYPTO\",\"4.2\"},\n {os_mon,\"CPO CXC 138 46\",\"2.4.4\"},\n {compiler,\"ERTS CXC 138 10\",\"7.1.4\"},\n {mnesia,\"MNESIA CXC 138 12\",\"4.15.3\"},\n {syntax_tools,\"Syntax tools\",\"2.1.4\"},\n {sasl,\"SASL CXC 138 11\",\"3.1.1\"},\n {stdlib,\"ERTS CXC 138 10\",\"3.4.3\"},\n {kernel,\"ERTS CXC 138 10\",\"5.4.1\"}]},\n {os,{unix,linux}},\n {erlang_version,\n \"Erlang/OTP 20 [erts-9.2] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:192] [kernel-poll:true]\\n\"},\n {memory,\n [{total,55943096},\n {connection_readers,0},\n {connection_writers,0},\n {connection_channels,0},\n {connection_other,0},\n {queue_procs,2744},\n {queue_slave_procs,0},\n {plugins,0},\n {other_proc,19080304},\n {mnesia,65712},\n {metrics,184888},\n {mgmt_db,0},\n {msg_index,42728},\n {other_ets,1769840},\n {binary,62120},\n {code,21390833},\n {atom,891849},\n {other_system,12634158}]},\n {alarms,[]},\n {listeners,[{clustering,25672,\"::\"},{amqp,5672,\"::\"}]},\n {vm_memory_high_watermark,0.4},\n {vm_memory_limit,6791299072},\n {disk_free_limit,50000000},\n {disk_free,100481589248},\n {file_descriptors,\n [{total_limit,924},{total_used,2},{sockets_limit,829},{sockets_used,0}]},\n {processes,[{limit,1048576},{used,165}]},\n {run_queue,0},\n {uptime,4073},\n {kernel,{net_ticktime,60}}]\n```\n\n### Output:\n\nwhen run: `celery -A tasks worker --loglevel=info` I get the following output:\n\n```\n-------------- celery@Alvaro-Laptop v3.1.26.post2 (Cipater)\n---- **** -----\n--- * *** * -- Linux-4.4.0-17763-Microsoft-x86_64-with-Ubuntu-18.04-bionic\n-- * - **** ---\n- ** ---------- [config]\n- ** ---------- .> app: tasks:0x7fd7952bcf60\n- ** ---------- .> transport: amqp://guest:**@localhost:5672//\n- ** ---------- .> results: disabled://\n- *** --- * --- .> concurrency: 12 (prefork)\n-- ******* ----\n--- ***** ----- [queues]\n -------------- .> celery exchange=celery(direct) key=celery\n\n[tasks]\n . tasks.add\n\n[2019-01-23 08:38:30,538: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: Socket closed.\nTrying again in 2.00 seconds...\n\n[2019-01-23 08:38:32,543: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: Socket closed.\nTrying again in 4.00 seconds...\n```\n\nHow can I open the socket to allow the communications?\n\n========================================\n\nTop Answer:\nI was able to configure everything using Redis instead of Rabbitmq:\n\n```\nsudo apt-get install redis-server\nsudo service redis-server restart\npip install celery\nchmod -R 777 ./\n```\n\nPlace on any folder you want to execute the worker the file tasks.py:\n\n```\nfrom celery import Celery\n\napp = Celery('tasks', broker='redis://localhost:6379')\n\n@app.task\ndef add(x, y):\n return x + y\n```\n\nThen execute the following:\n\n```\ncelery -A tasks worker --loglevel=info\n```\n\nThe socket is now open!\n\n========================================\n\nCode:\n```text\nsoftware -> celery:3.1.26.post2 (Cipater) kombu:3.0.37 py:3.6.7\n billiard:3.3.0.23 py-amqp:1.4.9\nplatform -> system:Linux arch:64bit, ELF imp:CPython\nloader -> celery.loaders.app.AppLoader\nsettings -> transport:pyamqp results:disabled\nBROKER_URL: 'amqp://guest:********@localhost:5672//'\n```\n\n```text\n[[source]]\nname = \"pypi\"\nurl = \"https://pypi.org/simple\"\nverify_ssl = true\n\n[dev-packages]\n\n[packages]\ndjango = \"*\"\ndjango-allauth = \"*\"\ndjango-crispy-forms = \"*\"\ndjango-debug-toolbar = \"==1.10.\"\nnumpy = \"==1.15.3\"\ncolorama = \"==0.4.0\"\ndateparser = \"==0.7.0\"\ndjango-extensions = \"*\"\npython-binance = \"*\"\nmisaka = \"*\"\ndjango-celery = \"*\"\ncelery = \"*\"\n\n[requires]\npython_version = \"3.6\"\n```\n\n```text\nfrom celery import Celery\n\n# app = Celery('tasks', broker='amqp://jm-user1:sample@localhost/jm-vhost')\n# app = Celery('tasks', broker='amqp://guest@localhost//')\napp = Celery('tasks', broker='pyamqp://guest@localhost//')\n\n@app.task\ndef add(x, y):\n return x + y\n```\n\n```text\n[{pid,1716},\n {running_applications,\n [{rabbit,\"RabbitMQ\",\"3.6.10\"},\n {ranch,\"Socket acceptor pool for TCP protocols.\",\"1.3.0\"},\n {ssl,\"Erlang/OTP SSL application\",\"8.2.3\"},\n {public_key,\"Public key infrastructure\",\"1.5.2\"},\n {asn1,\"The Erlang ASN1 compiler version 5.0.4\",\"5.0.4\"},\n {rabbit_common,\n \"Modules shared by rabbitmq-server and rabbitmq-erlang-client\",\n \"3.6.10\"},\n {xmerl,\"XML parser\",\"1.3.16\"},\n {crypto,\"CRYPTO\",\"4.2\"},\n {os_mon,\"CPO CXC 138 46\",\"2.4.4\"},\n {compiler,\"ERTS CXC 138 10\",\"7.1.4\"},\n {mnesia,\"MNESIA CXC 138 12\",\"4.15.3\"},\n {syntax_tools,\"Syntax tools\",\"2.1.4\"},\n {sasl,\"SASL CXC 138 11\",\"3.1.1\"},\n {stdlib,\"ERTS CXC 138 10\",\"3.4.3\"},\n {kernel,\"ERTS CXC 138 10\",\"5.4.1\"}]},\n {os,{unix,linux}},\n {erlang_version,\n \"Erlang/OTP 20 [erts-9.2] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:192] [kernel-poll:true]\\n\"},\n {memory,\n [{total,55943096},\n {connection_readers,0},\n {connection_writers,0},\n {connection_channels,0},\n {connection_other,0},\n {queue_procs,2744},\n {queue_slave_procs,0},\n {plugins,0},\n {other_proc,19080304},\n {mnesia,65712},\n {metrics,184888},\n {mgmt_db,0},\n {msg_index,42728},\n {other_ets,1769840},\n {binary,62120},\n {code,21390833},\n {atom,891849},\n {other_system,12634158}]},\n {alarms,[]},\n {listeners,[{clustering,25672,\"::\"},{amqp,5672,\"::\"}]},\n {vm_memory_high_watermark,0.4},\n {vm_memory_limit,6791299072},\n {disk_free_limit,50000000},\n {disk_free,100481589248},\n {file_descriptors,\n [{total_limit,924},{total_used,2},{sockets_limit,829},{sockets_used,0}]},\n {processes,[{limit,1048576},{used,165}]},\n {run_queue,0},\n {uptime,4073},\n {kernel,{net_ticktime,60}}]\n```\n\n```text\n-------------- celery@Alvaro-Laptop v3.1.26.post2 (Cipater)\n---- **** -----\n--- * *** * -- Linux-4.4.0-17763-Microsoft-x86_64-with-Ubuntu-18.04-bionic\n-- * - **** ---\n- ** ---------- [config]\n- ** ---------- .> app: tasks:0x7fd7952bcf60\n- ** ---------- .> transport: amqp://guest:**@localhost:5672//\n- ** ---------- .> results: disabled://\n- *** --- * --- .> concurrency: 12 (prefork)\n-- ******* ----\n--- ***** ----- [queues]\n -------------- .> celery exchange=celery(direct) key=celery\n\n\n[tasks]\n . tasks.add\n\n[2019-01-23 08:38:30,538: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: Socket closed.\nTrying again in 2.00 seconds...\n\n[2019-01-23 08:38:32,543: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: Socket closed.\nTrying again in 4.00 seconds...\n```\n\n```text\ncelery -A proj report\n```\n\n```text\npip freeze\n```\n\n```text\ncelery -A tasks worker --loglevel=info\n```\n\n```text\nsudo rabbitmq-plugins enable rabbitmq_management\n```\n\n```text\nsudo vi /etc/rabbitmq/rabbitmq-env.conf\n```\n\n```text\n# By default RabbitMQ will bind to all interfaces, on IPv4 and IPv6 if\n# available. Set this if you only want to bind to one network interface or#\n# address family.\nNODE_IP_ADDRESS=127.0.0.1\n```\n\n```text\nsudo service rabbitmq-server restart\n```\n\n```text\nhttp://localhost:15672\n```\n\n```text\napt-get\n```\n\n```text\namqp://username:password@192.168.0.38//\n```\n\n```text\nsudo apt-get install redis-server\nsudo service redis-server restart\npip install celery\nchmod -R 777 ./\n```\n\n```text\nfrom celery import Celery\n\napp = Celery('tasks', broker='redis://localhost:6379')\n\n@app.task\ndef add(x, y):\n return x + y\n```\n\n```text\ncelery -A tasks worker --loglevel=info\n```\n\n========================================\n\nComments:\n- As put in the question, when I run `rabbitmqctl status` it shows a good response of the server\n- It looks like it is listening on ipv6 :: not on ipv4 localhost. Can you try configuring it for 127.0.0.1?\n- how can you change the configuration?\n- thank you. I confused rabbitmq mgmt port with the actual ampq broker :'(\n- I was getting `Error: connect ECONNREFUSED 127.0.0.1:5672` on windows with wsl2, uncommenting `NODE_IP_ADDRESS=127.0.0.1` worked, thanks.\n- Thanks a lot! I install rabbitmq-server on WSL and cannot connect to the server, although I restart server many times. However, I can't find /etc/rabbitmq/rabbitmq-env.conf, mentioned by your answer. Instead, I create a new file /etc/rabbitmq/rabbitmq-env.conf, add two entries in it: listeners.tcp.default = 5672 listeners.tcp.local = 127.0.0.1:5672, and the problem is solved.","metadata":{"transformedAt":"2026-08-18T18:33:20.189Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":18,"totalLines":400,"estimatedTokens":2558}}777{"id":"stack-65650010","source":"stackoverflow","questionId":65650010,"title":"Set connection name with amqplib","tags":["node.js","rabbitmq","node-amqplib"],"text":"Title: Set connection name with amqplib\nTags: node.js, rabbitmq, node-amqplib\nSource: Stack Overflow\n\nQuestion:\nI need to set a friendly name for my connection as below instead of \"?\" in RabbitMQ for amqplib for NodeJS:\n\nhttps://i.sstatic.net/OKWYJ.png\n\nI found examples with Java and Python but nothing yet with this library. Thanks.\n\n========================================\n\nCode:\n```text\namqp.connect('amqp://localhost', {clientProperties: {connection_name: \"myFriendlyName\"}})\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.189Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":17,"estimatedTokens":122}}778{"id":"stack-15680093","source":"stackoverflow","questionId":15680093,"title":"In RabbitMQ should I create a connection pool on Connections, Channels, or both?","tags":["rabbitmq"],"text":"Title: In RabbitMQ should I create a connection pool on Connections, Channels, or both?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nUsing a java client for RabbitMQ, I have created a connection pooling mechanism that has a set of rabbitmq connections established and available. Once a client leases a connection the client creates a channel. If I have to send perform tasks and send 100 messages, for each of those messages the client will lease a connection and create a channel with the API such as:\n\n```\nrqConnection = MyPoolManager.leaseConnection();\nrqChannel = rqConnection.createChannel();\n```\n\nCan I have a channel pre-established within my pool as one channel per connection, or a channel can always be created prior to send a message ? **My concern is that creating channels over channels might consume resources.** I can have the channel co-exist with a Class that contains both the connection and the channel so it is always pre-created ahead of its usage need. If the channel creation poses no resource consumption or leakage implications, then I can proceed with my current approach.\n\n========================================\n\nCode:\n```text\nrqConnection = MyPoolManager.leaseConnection();\nrqChannel = rqConnection.createChannel();\n```\n\n========================================\n\nComments:\n- After viewing this question it appears to me my question above is even more valid. Pooling on Channels appears to be valid. What is undocumented or not fully understood is how to create the appropriate ratio of Connections and Channels ( how many channels per connection ) and how to acomodate capacity based on that. Pooling on a single connection and multiple channels is likely wrong, so my question is about how to define that ratio.\n- I think, having more connections only makes sense if you see that one connection is not able to handle the data received from the server. Otherwise, multiplexing all the channels onto the same connection should work in most of the cases. It depends on the traffic pattern though.\n- So, is it safe to have a static connection in java?\n- Here you can find some explanation: rabbitmq.com/…","metadata":{"transformedAt":"2026-08-18T18:33:20.189Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":29,"estimatedTokens":536}}779{"id":"stack-76274566","source":"stackoverflow","questionId":76274566,"title":"RabbitMQ closed connection on method CreateModel()","tags":["c#","windows","exception","rabbitmq"],"text":"Title: RabbitMQ closed connection on method CreateModel()\nTags: c#, windows, exception, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm trying to run Producer example from tutorials, but RabbitMQ closed connection with exception:\n\nException thrown: 'RabbitMQ.Client.Exceptions.OperationInterruptedException' in RabbitMQ.Client.dll\nAn unhandled exception of type 'RabbitMQ.Client.Exceptions.OperationInterruptedException' occurred in RabbitMQ.Client.dll\nThe AMQP operation was interrupted: AMQP close-reason, initiated by Library, code=541, text='Unexpected Exception', classId=0, methodId=0, cause=System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..\n---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host.\n\nCode is:\n\n```\nvar factory = new ConnectionFactory { HostName = \"localhost\" };\nvar connection = factory.CreateConnection();\nvar channel = connection.CreateModel(); // **Notes:**\n\n- RabbitMQ started and working - is easy to send/get message manually via RabbitMQ Management web-UI.\n\n- Status or RabbitMQ received by command **rabbitmq-diagnostics.bat status** is ok, no one problem.\n\n- exe-file added to Windows-firewall for avoid any blocking\n\n- From the Wireshark we can see that RabbitMQ accepts connection and after some actions - sends Reset:\n\n**From the RabbitMQ logs:**\n\n```\n2023-05-17 19:49:59.763000+03:00 [info] accepting AMQP connection ([::1]:49412 -> [::1]:5672)\n2023-05-17 19:49:59.779000+03:00 [info] connection ([::1]:49412 -> [::1]:5672): user 'guest' authenticated and granted access to vhost '/'\n2023-05-17 19:50:00.784000+03:00 [error] crasher:\n2023-05-17 19:50:00.784000+03:00 [error] initial call: rabbit_reader:init/3\n2023-05-17 19:50:00.784000+03:00 [error] pid: \n2023-05-17 19:50:00.784000+03:00 [error] registered_name: []\n2023-05-17 19:50:00.784000+03:00 [error] exception exit: {unexpected_message,{'EXIT',#Port,einval}}\n2023-05-17 19:50:00.784000+03:00 [error] in function rabbit_reader:handle_other/2 (rabbit_reader.erl, line 644)\n2023-05-17 19:50:00.784000+03:00 [error] in call from rabbit_reader:mainloop/4 (rabbit_reader.erl, line 535)\n2023-05-17 19:50:00.784000+03:00 [error] in call from rabbit_reader:run/1 (rabbit_reader.erl, line 457)\n2023-05-17 19:50:00.784000+03:00 [error] in call from rabbit_reader:start_connection/5 (rabbit_reader.erl, line 356)\n2023-05-17 19:50:00.784000+03:00 [error] ancestors: [,,,,,,\n2023-05-17 19:50:00.784000+03:00 [error] rabbit_sup,]\n2023-05-17 19:50:00.784000+03:00 [error] message_queue_len: 0\n2023-05-17 19:50:00.784000+03:00 [error] messages: []\n2023-05-17 19:50:00.784000+03:00 [error] links: []\n2023-05-17 19:50:00.784000+03:00 [error] dictionary: [{{ch_pid,},{1,#Ref}},\n2023-05-17 19:50:00.784000+03:00 [error] {client_properties,\n2023-05-17 19:50:00.784000+03:00 [error] [{>,longstr,>},\n2023-05-17 19:50:00.784000+03:00 [error] {>,longstr,\n2023-05-17 19:50:00.784000+03:00 [error] >},\n2023-05-17 19:50:00.784000+03:00 [error] {>,longstr,>},\n2023-05-17 19:50:00.784000+03:00 [error] {>,longstr,\n2023-05-17 19:50:00.784000+03:00 [error] >},\n2023-05-17 19:50:00.784000+03:00 [error] {>,longstr,\n2023-05-17 19:50:00.784000+03:00 [error] >},\n2023-05-17 19:50:00.784000+03:00 [error] {>,table,\n2023-05-17 19:50:00.784000+03:00 [error] [{>,bool,true},\n2023-05-17 19:50:00.784000+03:00 [error] {>,bool,true},\n2023-05-17 19:50:00.784000+03:00 [error] {>,bool,true},\n2023-05-17 19:50:00.784000+03:00 [error] {>,bool,true},\n2023-05-17 19:50:00.784000+03:00 [error] {>,bool,true},\n2023-05-17 19:50:00.784000+03:00 [error] {>,bool,true}]},\n2023-05-17 19:50:00.784000+03:00 [error] {>,void,undefined}]},\n2023-05-17 19:50:00.784000+03:00 [error] {process_name,\n2023-05-17 19:50:00.784000+03:00 [error] {rabbit_reader, [::1]:5672\">>}},\n2023-05-17 19:50:00.784000+03:00 [error] {{channel,1},\n2023-05-17 19:50:00.784000+03:00 [error] {,{method,rabbit_framing_amqp_0_9_1}}}]\n2023-05-17 19:50:00.784000+03:00 [error] trap_exit: true\n2023-05-17 19:50:00.784000+03:00 [error] status: running\n2023-05-17 19:50:00.784000+03:00 [error] heap_size: 1598\n2023-05-17 19:50:00.784000+03:00 [error] stack_size: 28\n2023-05-17 19:50:00.784000+03:00 [error] reductions: 9624\n2023-05-17 19:50:00.784000+03:00 [error] neighbours:\n2023-05-17 19:50:00.784000+03:00 [error] \n2023-05-17 19:50:00.784000+03:00 [error] supervisor: {,rabbit_connection_sup}\n2023-05-17 19:50:00.784000+03:00 [error] errorContext: child_terminated\n2023-05-17 19:50:00.784000+03:00 [error] reason: {unexpected_message,{'EXIT',#Port,einval}}\n2023-05-17 19:50:00.784000+03:00 [error] offender: [{pid,},\n2023-05-17 19:50:00.784000+03:00 [error] {id,reader},\n2023-05-17 19:50:00.784000+03:00 [error] {mfargs,{rabbit_reader,start_link,\n2023-05-17 19:50:00.784000+03:00 [error] [,\n2023-05-17 19:50:00.784000+03:00 [error] {acceptor,{0,0,0,0,0,0,0,0},5672}]}},\n2023-05-17 19:50:00.784000+03:00 [error] {restart_type,intrinsic},\n2023-05-17 19:50:00.784000+03:00 [error] {shutdown,300000},\n2023-05-17 19:50:00.784000+03:00 [error] {child_type,worker}]\n2023-05-17 19:50:00.784000+03:00 [error] supervisor: {,rabbit_connection_sup}\n2023-05-17 19:50:00.784000+03:00 [error] errorContext: shutdown\n2023-05-17 19:50:00.784000+03:00 [error] reason: reached_max_restart_intensity\n2023-05-17 19:50:00.784000+03:00 [error] offender: [{pid,},\n2023-05-17 19:50:00.784000+03:00 [error] {id,reader},\n2023-05-17 19:50:00.784000+03:00 [error] {mfargs,{rabbit_reader,start_link,\n2023-05-17 19:50:00.784000+03:00 [error] [,\n2023-05-17 19:50:00.784000+03:00 [error] {acceptor,{0,0,0,0,0,0,0,0},5672}]}},\n2023-05-17 19:50:00.784000+03:00 [error] {restart_type,intrinsic},\n2023-05-17 19:50:00.784000+03:00 [error] {shutdown,300000},\n2023-05-17 19:50:00.784000+03:00 [error] {child_type,worker}]\n```\n\n**QUESTION:** how to fix this issue?\n\n========================================\n\nTop Answer:\nin windows, unistall Erlang 26 is not easy - you need to unistall , and then delete all files in\n\nC:\\Program Files\\Erlang OTP\\erts-14.1\n\nor else the next time you install\nRabbitMQ it will bound to this version\n\nin regedit see that value of\n\n```\nHKEY_LOCAL_MACHINE\\SOFTWARE\\Ericsson\\Erlang\\ErlSrv\\1.1\\RabbitMQ\\\nMachine\n```\n\nis\n\n```\nC:\\Program Files\\Erlang OTP\\erts-13.0.4\\bin\\erl.exe\n```\n\nand not erts-14.1\n\n========================================\n\nCode:\n```text\nvar factory = new ConnectionFactory { HostName = \"localhost\" };\nvar connection = factory.CreateConnection();\nvar channel = connection.CreateModel(); // <-- crash is here on this line\n```\n\n```text\n2023-05-17 19:49:59.763000+03:00 [info] <0.930.0> accepting AMQP connection <0.930.0> ([::1]:49412 -> [::1]:5672)\n2023-05-17 19:49:59.779000+03:00 [info] <0.930.0> connection <0.930.0> ([::1]:49412 -> [::1]:5672): user 'guest' authenticated and granted access to vhost '/'\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> crasher:\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> initial call: rabbit_reader:init/3\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> pid: <0.930.0>\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> registered_name: []\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> exception exit: {unexpected_message,{'EXIT',#Port<0.229>,einval}}\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> in function rabbit_reader:handle_other/2 (rabbit_reader.erl, line 644)\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> in call from rabbit_reader:mainloop/4 (rabbit_reader.erl, line 535)\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> in call from rabbit_reader:run/1 (rabbit_reader.erl, line 457)\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> in call from rabbit_reader:start_connection/5 (rabbit_reader.erl, line 356)\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> ancestors: [<0.928.0>,<0.603.0>,<0.602.0>,<0.601.0>,<0.599.0>,<0.598.0>,\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> rabbit_sup,<0.233.0>]\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> message_queue_len: 0\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> messages: []\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> links: [<0.928.0>]\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> dictionary: [{{ch_pid,<0.939.0>},{1,#Ref<0.2052854348.121110529.34620>}},\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> {client_properties,\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> [{<<\"product\">>,longstr,<<\"RabbitMQ\">>},\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> {<<\"version\">>,longstr,\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> <<\"6.5.0+4c91cae8ae5eb0194e02a83f1b0cedfe29ad8312\">>},\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> {<<\"platform\">>,longstr,<<\".NET\">>},\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> {<<\"copyright\">>,longstr,\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> <<\"Copyright (c) 2007-2020 VMware, Inc.\">>},\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> {<<\"information\">>,longstr,\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> <<\"Licensed under the MPL. See https://www.rabbitmq.com/\">>},\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> {<<\"capabilities\">>,table,\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> [{<<\"publisher_confirms\">>,bool,true},\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> {<<\"exchange_exchange_bindings\">>,bool,true},\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> {<<\"basic.nack\">>,bool,true},\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> {<<\"consumer_cancel_notify\">>,bool,true},\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> {<<\"connection.blocked\">>,bool,true},\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> {<<\"authentication_failure_close\">>,bool,true}]},\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> {<<\"connection_name\">>,void,undefined}]},\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> {process_name,\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> {rabbit_reader,<<\"[::1]:49412 -> [::1]:5672\">>}},\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> {{channel,1},\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> {<0.939.0>,{method,rabbit_framing_amqp_0_9_1}}}]\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> trap_exit: true\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> status: running\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> heap_size: 1598\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> stack_size: 28\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> reductions: 9624\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> neighbours:\n2023-05-17 19:50:00.784000+03:00 [error] <0.930.0> \n2023-05-17 19:50:00.784000+03:00 [error] <0.928.0> supervisor: {<0.928.0>,rabbit_connection_sup}\n2023-05-17 19:50:00.784000+03:00 [error] <0.928.0> errorContext: child_terminated\n2023-05-17 19:50:00.784000+03:00 [error] <0.928.0> reason: {unexpected_message,{'EXIT',#Port<0.229>,einval}}\n2023-05-17 19:50:00.784000+03:00 [error] <0.928.0> offender: [{pid,<0.930.0>},\n2023-05-17 19:50:00.784000+03:00 [error] <0.928.0> {id,reader},\n2023-05-17 19:50:00.784000+03:00 [error] <0.928.0> {mfargs,{rabbit_reader,start_link,\n2023-05-17 19:50:00.784000+03:00 [error] <0.928.0> [<0.929.0>,\n2023-05-17 19:50:00.784000+03:00 [error] <0.928.0> {acceptor,{0,0,0,0,0,0,0,0},5672}]}},\n2023-05-17 19:50:00.784000+03:00 [error] <0.928.0> {restart_type,intrinsic},\n2023-05-17 19:50:00.784000+03:00 [error] <0.928.0> {shutdown,300000},\n2023-05-17 19:50:00.784000+03:00 [error] <0.928.0> {child_type,worker}]\n2023-05-17 19:50:00.784000+03:00 [error] <0.928.0> supervisor: {<0.928.0>,rabbit_connection_sup}\n2023-05-17 19:50:00.784000+03:00 [error] <0.928.0> errorContext: shutdown\n2023-05-17 19:50:00.784000+03:00 [error] <0.928.0> reason: reached_max_restart_intensity\n2023-05-17 19:50:00.784000+03:00 [error] <0.928.0> offender: [{pid,<0.930.0>},\n2023-05-17 19:50:00.784000+03:00 [error] <0.928.0> {id,reader},\n2023-05-17 19:50:00.784000+03:00 [error] <0.928.0> {mfargs,{rabbit_reader,start_link,\n2023-05-17 19:50:00.784000+03:00 [error] <0.928.0> [<0.929.0>,\n2023-05-17 19:50:00.784000+03:00 [error] <0.928.0> {acceptor,{0,0,0,0,0,0,0,0},5672}]}},\n2023-05-17 19:50:00.784000+03:00 [error] <0.928.0> {restart_type,intrinsic},\n2023-05-17 19:50:00.784000+03:00 [error] <0.928.0> {shutdown,300000},\n2023-05-17 19:50:00.784000+03:00 [error] <0.928.0> {child_type,worker}]\n```\n\n```text\nHKEY_LOCAL_MACHINE\\SOFTWARE\\Ericsson\\Erlang\\ErlSrv\\1.1\\RabbitMQ\\\nMachine\n```\n\n```text\nC:\\Program Files\\Erlang OTP\\erts-13.0.4\\bin\\erl.exe\n```\n\n========================================\n\nComments:\n- are they talking the same protocol? amqp or amqps? 0-9-1 or 0-10?\n- @IvanRubinson: as I see - AMQP. Full screenshot is here: gcdnb.pbrd.co/images/Zona8zgtFC8z.png\n- And output of status command is here: gcdnb.pbrd.co/images/4IwOuniU6Hy8.png\n- Can you give more details? RabbitMQ version? Erlang versions ?\n- @GabrieleSantomaggio : 2023-05-18 12:29:31.670000+03:00 [info] Starting RabbitMQ 3.11.16 on Erlang 26.0 [jit]\n- You are using erlang 26 with 3.11.16, which is not compatible. You can: Use the 3.12 version (compatible with erlang 26. ) or install erlang 25.x\n- @GabrieleSantomaggio how do you know the versions are not compatible? Is there a ref in some document?\n- @GabrieleSantomaggio : thanks, now is working. One note: First I've deleted both - Erlang and RabbitMQ. After: I downloaded Erlang 25.3.2 and installed, also installed the same RabbitMQ 3.11.16 (because 3.12 is pre-release).\n- @IvanRubinson I work for the RabbitMQ team. Erlang 26 is not fully supported yet. We are still doing internal tests. See rabbitmq.com/which-erlang.html the best way is still use erlang 25. Erlang 26 will be officially supported in some 3.12.x version.","metadata":{"transformedAt":"2026-08-18T18:33:20.190Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":226,"estimatedTokens":3648}}780{"id":"stack-39137746","source":"stackoverflow","questionId":39137746,"title":"MessageConversionException: Failed to resolve class name in Spring AMQP","tags":["spring","spring-boot","rabbitmq","spring-amqp"],"text":"Title: MessageConversionException: Failed to resolve class name in Spring AMQP\nTags: spring, spring-boot, rabbitmq, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI am trying out simple sender and receiving of messages using Spring AMQP with `jackson2JsonMessageConverter`.\nAlso, what is the significance of `_TypeId_` here\nwhy it is showing sender package with class name?\nI am facing issues in receiving the message.\n\nBelow is my configuration\n\n org.springframework.amqp.support.converter.MessageConversionException:\n failed to resolve class name. Class not found\n [org.springframework.amqp.helloworld.User]\n at org.springframework.amqp.support.converter.DefaultJackson2JavaTypeMapper.getClassIdType(DefaultJackson2JavaTypeMapper.java:121)\n at org.springframework.amqp.support.converter.DefaultJackson2JavaTypeMapper.toJavaType(DefaultJackson2JavaTypeMapper.java:90)\n at org.springframework.amqp.support.converter.Jackson2JsonMessageConverter.fromMessage(Jackson2JsonMessageConverter.java:145)\n at org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener.extractMessage(AbstractAdaptableMessageListener.java:236)\n at org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter.onMessage(MessageListenerAdapter.java:288)\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:777)\n ... 10 common frames omitted Caused by: java.lang.ClassNotFoundException:\n org.springframework.amqp.helloworld.User\n at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1305)\n at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1139)\n at org.springframework.util.ClassUtils.forName(ClassUtils.java:250)\n at org.springframework.amqp.support.converter.DefaultJackson2JavaTypeMapper.getClassIdType(DefaultJackson2JavaTypeMapper.java:118)\n ... 15 common frames omitted\n\nXML Configuration\n\n```\n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n \n\n \n\n \n \n\n \n\n \n\n \n \n\n \n\n \n \n \n \n\n \n \n \n \n \n \n\n```\n\nSender\n\n```\npackage org.springframework.amqp.helloworld;\n\nimport org.springframework.amqp.core.Message;\nimport org.springframework.amqp.core.MessageProperties;\nimport org.springframework.amqp.rabbit.core.RabbitTemplate;\nimport org.springframework.amqp.support.converter.DefaultClassMapper;\nimport org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.context.ApplicationContext;\nimport org.springframework.context.annotation.AnnotationConfigApplicationContext;\nimport org.springframework.stereotype.Component;\n\n@Component\npublic class Sender {\n\n public static void main(String[] args) {\n\n ApplicationContext context = new AnnotationConfigApplicationContext(HelloWorldConfiguration.class);\n User user=new User();\n user.setPassword(\"welcome\");\n user.setUserName(\"welcome\");\n user.setXml(\"myxml\");\n RabbitTemplate rabbitTemplate = context.getBean(RabbitTemplate.class);\n\n Jackson2JsonMessageConverter converter = context.getBean(Jackson2JsonMessageConverter.class);\n MessageProperties properties = new MessageProperties();\n properties.setHeader(\"user\", \"user\");\n properties.setContentType(MessageProperties.CONTENT_TYPE_JSON);\n Message message = converter.toMessage(user, properties);\n\n System.out.println(message);\n\n rabbitTemplate.send(message);\n }\n\n /* @RabbitListener(queues = HelloWorldConfiguration.helloWorldQueueName)\n public void handleMessage(User user) {\n System.out.println(\"User Values::::::::\"+user.getPassword());\n }*/\n}\n```\n\nConsumer\n\n```\npackage com.bip.rabbitmq.consumer;\n\nimport org.springframework.amqp.rabbit.annotation.EnableRabbit;\nimport org.springframework.amqp.rabbit.annotation.RabbitListener;\nimport org.springframework.stereotype.Component;\n\nimport com.bip.entity.User;\n\n@EnableRabbit\n@Component\npublic class RabbitMQJobListener {\n\n @RabbitListener(queues=\"Job Queue\")\n public void onMessage(User message) {\n System.out.println(new String(message.getPassword()));\n\n }\n}\n```\n\nRabbitMQ\n\n```\nExchange (AMQP default)\nRouting Key Job Queue\nRedelivered ○\nProperties \npriority: 0\ndelivery_mode: 2\nheaders: \nuser: user\n__TypeId__: org.springframework.amqp.helloworld.User\ncontent_encoding: UTF-8\ncontent_type: application/json\nPayload\n57 bytes\nEncoding: string\n{\"userName\":\"welcome\",\"password\":\"welcome\",\"xml\":\"myxml\"}\n```\n\n========================================\n\nTop Answer:\nThis might happen when the package name of the serialized instance is different than the consumer's model, represented by the headers: TypeId.\n\nI believe following example will make things lot clearer.\n\nSchema: Exchange x.invoice of type fanout is bound to queue q.invoice.\n\nProducer: We are sending JSON message with type Id com.example.produceronequeuemultipletypes.model.InvoiceCreatedMessage.\nClass ParseConfig is to help us avoid manual serialization of the instance to String.\n\n```\npublic void sendInvoiceMessages() {\n invoiceCreatedMessage.setId(0);\n invoiceCreatedMessage.setType(\"Invoice Created\");\n rabbitTemplate.convertAndSend(\"x.invoice\", \"\", invoiceCreatedMessage); \n}\n\nclass InvoiceCreatedMessage {\n private String type;\n private int id;\n}\n\n@Configuration\nclass ParseConfig {\n @Bean\n public ObjectMapper getObjectMapper() {\n return new ObjectMapper();\n }\n\n @Bean\n public Jackson2JsonMessageConverter getConverter(\n @Autowired ObjectMapper objectMapper) {\n return new Jackson2JsonMessageConverter(objectMapper);\n }\n}\n```\n\nConsumer: Create a class mapper bean with mapping from \"com.example.produceronequeuemultipletypes.model.InvoiceCreated\" to InvoiceCreated.class.\n\n```\n@Slf4j\n@Service\npublic class InvoiceConsumer {\n @RabbitListener(queues = \"q.invoice\")\n public void handleInvoiceCreated(\n InvoiceCreatedMessage invoiceCreatedMessage) {\n log.info(\"[Created] Invoice \" + invoiceCreatedMessage);\n }\n}\n\n@Configuration\nclass ParseConfig {\n @Bean\n public ObjectMapper getObjectMapper() {\n return new ObjectMapper();\n }\n\n @Bean\n public Jackson2JsonMessageConverter getConverter(\n @Autowired ObjectMapper objectMapper) {\n Jackson2JsonMessageConverter messageConverter =\n new Jackson2JsonMessageConverter(objectMapper);\n messageConverter.setClassMapper(getClassMapper());\n return messageConverter;\n }\n\n @Bean\n public DefaultClassMapper getClassMapper() {\n DefaultClassMapper classMapper = new DefaultClassMapper();\n Map> map = new HashMap<>();\n map.put(\n \"com.example.produceronequeuemultipletypes.model.\" + \n \"InvoiceCreatedMessage\",\n InvoiceCreatedMessage.class)\n classMapper.setIdClassMapping(idClassMapping);\n return classMapper;\n }\n}\n\nclass InvoiceCreatedMessage {\n private String type;\n private int id;\n}\n```\n\nReference:\n\n- https://docs.spring.io/spring-amqp/reference/html/#json-message-converter\n\n- https://www.udemy.com/course/rabbitmq-java-spring-boot-for-system-integration/\n\n========================================\n\nCode:\n```text\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<beans xmlns=\"http://www.springframework.org/schema/beans\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:p=\"http://www.springframework.org/schema/p\"\n xmlns:context=\"http://www.springframework.org/schema/context\"\n xmlns:jdbc=\"http://www.springframework.org/schema/jdbc\" xmlns:tx=\"http://www.springframework.org/schema/tx\"\n xmlns:jpa=\"http://www.springframework.org/schema/data/jpa\" xmlns:mvc=\"http://www.springframework.org/schema/mvc\"\n xmlns:rabbit=\"http://www.springframework.org/schema/rabbit\"\n xsi:schemaLocation=\"http://www.springframework.org/schema/rabbit\n http://www.springframework.org/schema/rabbit/spring-rabbit.xsd\n http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd \n http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd\n http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd \n http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd \n http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd\n http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd\">\n\n\n <rabbit:connection-factory id=\"connectionFactory\"\n channel-cache-size=\"25\" host=\"10.165.18.29\" username=\"BipUser\"\n password=\"bip\" />\n\n <rabbit:queue name=\"Job Queue\"></rabbit:queue>\n\n <rabbit:queue name=\"Input Queue\"></rabbit:queue>\n\n <rabbit:queue name=\"More Info Queue\"></rabbit:queue>\n\n <rabbit:queue name=\"Adaptor O/P Queue\"></rabbit:queue>\n\n <rabbit:queue name=\"Command Queue\"></rabbit:queue>\n\n <rabbit:queue name=\"Error Queue\"></rabbit:queue>\n\n <bean id=\"simpleMessageConverter\"\n class=\"org.springframework.amqp.support.converter.Jackson2JsonMessageConverter\">\n </bean>\n\n <rabbit:template id=\"amqpTemplate\" connection-factory=\"connectionFactory\"\n message-converter=\"jsonConverterWithDefaultType\" />\n\n <rabbit:listener-container\n connection-factory=\"connectionFactory\" auto-declare=\"true\"\n message-converter=\"simpleMessageConverter\" auto-startup=\"true\"\n acknowledge=\"auto\">\n <rabbit:listener ref=\"rabbitMQJobListener\"\n queue-names=\"Job Queue\" priority=\"10\" />\n\n </rabbit:listener-container>\n\n <rabbit:admin connection-factory=\"connectionFactory\" id=\"amqpAdmin\" />\n\n <bean id=\"rabbitMQJobListener\" class=\"com.bosch.bip.rabbitmq.consumer.RabbitMQJobListener\">\n </bean>\n\n <rabbit:annotation-driven container-factory=\"rabbitListenerContainerFactory\" />\n\n <bean id=\"rabbitListenerContainerFactory\"\n class=\"org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory\">\n <property name=\"connectionFactory\" ref=\"connectionFactory\"></property>\n <property name=\"messageConverter\" ref=\"jsonConverterWithDefaultType\"></property>\n </bean>\n\n <bean id=\"jsonConverterWithDefaultType\"\n class=\"org.springframework.amqp.support.converter.Jackson2JsonMessageConverter\">\n <property name=\"classMapper\">\n <bean class=\"org.springframework.amqp.support.converter.DefaultClassMapper\">\n </bean>\n </property>\n </bean>\n</beans>\n```\n\n```text\npackage org.springframework.amqp.helloworld;\n\nimport org.springframework.amqp.core.Message;\nimport org.springframework.amqp.core.MessageProperties;\nimport org.springframework.amqp.rabbit.core.RabbitTemplate;\nimport org.springframework.amqp.support.converter.DefaultClassMapper;\nimport org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.context.ApplicationContext;\nimport org.springframework.context.annotation.AnnotationConfigApplicationContext;\nimport org.springframework.stereotype.Component;\n\n@Component\npublic class Sender {\n\n\n public static void main(String[] args) {\n\n ApplicationContext context = new AnnotationConfigApplicationContext(HelloWorldConfiguration.class);\n User user=new User();\n user.setPassword(\"welcome\");\n user.setUserName(\"welcome\");\n user.setXml(\"myxml\");\n RabbitTemplate rabbitTemplate = context.getBean(RabbitTemplate.class);\n\n Jackson2JsonMessageConverter converter = context.getBean(Jackson2JsonMessageConverter.class);\n MessageProperties properties = new MessageProperties();\n properties.setHeader(\"user\", \"user\");\n properties.setContentType(MessageProperties.CONTENT_TYPE_JSON);\n Message message = converter.toMessage(user, properties);\n\n System.out.println(message);\n\n\n\n rabbitTemplate.send(message);\n }\n\n /* @RabbitListener(queues = HelloWorldConfiguration.helloWorldQueueName)\n public void handleMessage(User user) {\n System.out.println(\"User Values::::::::\"+user.getPassword());\n }*/\n}\n```\n\n```text\npackage com.bip.rabbitmq.consumer;\n\nimport org.springframework.amqp.rabbit.annotation.EnableRabbit;\nimport org.springframework.amqp.rabbit.annotation.RabbitListener;\nimport org.springframework.stereotype.Component;\n\nimport com.bip.entity.User;\n\n@EnableRabbit\n@Component\npublic class RabbitMQJobListener {\n\n\n @RabbitListener(queues=\"Job Queue\")\n public void onMessage(User message) {\n System.out.println(new String(message.getPassword()));\n\n }\n}\n```\n\n```text\nExchange (AMQP default)\nRouting Key Job Queue\nRedelivered ○\nProperties \npriority: 0\ndelivery_mode: 2\nheaders: \nuser: user\n__TypeId__: org.springframework.amqp.helloworld.User\ncontent_encoding: UTF-8\ncontent_type: application/json\nPayload\n57 bytes\nEncoding: string\n{\"userName\":\"welcome\",\"password\":\"welcome\",\"xml\":\"myxml\"}\n```\n\n```text\njackson2JsonMessageConverter\n```\n\n```text\n_TypeId_\n```\n\n```text\n_TypeID_\n```\n\n```text\nClassMapper\n```\n\n```text\npublic void sendInvoiceMessages() {\n invoiceCreatedMessage.setId(0);\n invoiceCreatedMessage.setType(\"Invoice Created\");\n rabbitTemplate.convertAndSend(\"x.invoice\", \"\", invoiceCreatedMessage); \n}\n\nclass InvoiceCreatedMessage {\n private String type;\n private int id;\n}\n\n@Configuration\nclass ParseConfig {\n @Bean\n public ObjectMapper getObjectMapper() {\n return new ObjectMapper();\n }\n\n @Bean\n public Jackson2JsonMessageConverter getConverter(\n @Autowired ObjectMapper objectMapper) {\n return new Jackson2JsonMessageConverter(objectMapper);\n }\n}\n```\n\n```text\n@Slf4j\n@Service\npublic class InvoiceConsumer {\n @RabbitListener(queues = \"q.invoice\")\n public void handleInvoiceCreated(\n InvoiceCreatedMessage invoiceCreatedMessage) {\n log.info(\"[Created] Invoice \" + invoiceCreatedMessage);\n }\n}\n\n@Configuration\nclass ParseConfig {\n @Bean\n public ObjectMapper getObjectMapper() {\n return new ObjectMapper();\n }\n\n @Bean\n public Jackson2JsonMessageConverter getConverter(\n @Autowired ObjectMapper objectMapper) {\n Jackson2JsonMessageConverter messageConverter =\n new Jackson2JsonMessageConverter(objectMapper);\n messageConverter.setClassMapper(getClassMapper());\n return messageConverter;\n }\n\n @Bean\n public DefaultClassMapper getClassMapper() {\n DefaultClassMapper classMapper = new DefaultClassMapper();\n Map<String, Class<?>> map = new HashMap<>();\n map.put(\n \"com.example.produceronequeuemultipletypes.model.\" + \n \"InvoiceCreatedMessage\",\n InvoiceCreatedMessage.class)\n classMapper.setIdClassMapping(idClassMapping);\n return classMapper;\n }\n}\n\nclass InvoiceCreatedMessage {\n private String type;\n private int id;\n}\n```\n\n========================================\n\nComments:\n- Regarding the deleted \"answer\" below - the configuration link in my answer shows how to map the type id to a different class - of course, the target class must be compatible with the source class (field names etc). `idClassMapping.put(\"com.xyz.Foo\", com.abc.Foo.class);`\n- Why is the exception not thrown if I remove `@Valid`? In this case the `_TypeID_` is not used.\n- Coincidentally, we just fixed that today and it will be available in the next releases December 9th. As of now, if you add other annotations, such as `@Valid`, you need to explicitly add `@Payload` as well. github.com/spring-projects/spring-amqp/pull/1275","metadata":{"transformedAt":"2026-08-18T18:33:20.190Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":516,"estimatedTokens":4063}}781{"id":"stack-62481005","source":"stackoverflow","questionId":62481005,"title":"RabbitMQ multiple consumer subscribe same queue and get same message","tags":["rabbitmq"],"text":"Title: RabbitMQ multiple consumer subscribe same queue and get same message\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am considering that can multiple consumer get the \"same\" message from a \"same\" queue which they subscribed ? \n\nIt's mean that consumer_1 and consumer_2 are both subscribe queue_1, when a single message is publish by publisher, can two of this consumer get that message at the same time ?\n\nIf yes, how can I implement it ?\n\n========================================\n\nTop Answer:\nThis is not possible.\nA single message can be delivered to one consumer of a queue at a time. However, it is possible to route a single message to *multiple queues* though a single exchange.\nRefer to different forms of bindings and exchanges offered by rabbitMQ. \n\nHowever, note that rabbitmq offers the option of requeuing and nacks.","metadata":{"transformedAt":"2026-08-18T18:33:20.190Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":19,"estimatedTokens":210}}782{"id":"stack-37845332","source":"stackoverflow","questionId":37845332,"title":"How comes my channel.basicConsume does not wait for messages","tags":["java-8","rabbitmq","message-queue"],"text":"Title: How comes my channel.basicConsume does not wait for messages\nTags: java-8, rabbitmq, message-queue\nSource: Stack Overflow\n\nQuestion:\nWhenever I start the following code:\n\n```\nConnectionFactory factory = new ConnectionFactory();\n factory.setHost(\"localhost\");\n Connection connection = factory.newConnection();\n Channel channel = connection.createChannel();\n String exchangeName = \"direct_logs\";\n channel.exchangeDeclare(exchangeName, \"direct\");\n String queueName = channel.queueDeclare().getQueue();\n channel.queueBind(queueName, exchangeName, \"red\");\n channel.basicQos(1);\n\n final Consumer consumer = new DefaultConsumer(channel){\n @Override\n public void handleDelivery(String consumerTag,\n Envelope envelope,\n AMQP.BasicProperties properties,\n byte[] body) throws IOException{\n String message = new String(body, \"UTF-8\");\n System.out.println(message);\n System.out.println(\"message received\");\n }\n };\n\n channel.basicConsume(queueName, true, consumer);\n```\n\nIt does not start an endless loop, as is implied in the documentation. Instead, it stops right away.\nThe only way I can have it consume for some time is to replace `channel.basicConsume` with a loop, as follows:\n\n```\nDateTime startedAt = new DateTime();\n DateTime stopAt = startedAt.plusSeconds(60);\n long i=0;\n try {\n while (stopAt.compareTo(new DateTime()) > 0) {\n channel.basicConsume(queueName, true, consumer);\n i++;\n }\n }finally {\n System.out.println(new DateTime());\n System.out.println(startedAt);\n System.out.println(stopAt);\n System.out.println(i);\n }\n```\n\nThere must be a better way to listen to messages for a while, correct? What am I missing?\nIt stops listening right away.\n\n========================================\n\nTop Answer:\ni had the same issue. the reason was that i was calling connection.close at the end. however, the basicConsume() method does not block on the current thread, rather on other threads, so the code after it, i.e. the connection.close() is called immediately.\n\n========================================\n\nCode:\n```text\nConnectionFactory factory = new ConnectionFactory();\n factory.setHost(\"localhost\");\n Connection connection = factory.newConnection();\n Channel channel = connection.createChannel();\n String exchangeName = \"direct_logs\";\n channel.exchangeDeclare(exchangeName, \"direct\");\n String queueName = channel.queueDeclare().getQueue();\n channel.queueBind(queueName, exchangeName, \"red\");\n channel.basicQos(1);\n\n final Consumer consumer = new DefaultConsumer(channel){\n @Override\n public void handleDelivery(String consumerTag,\n Envelope envelope,\n AMQP.BasicProperties properties,\n byte[] body) throws IOException{\n String message = new String(body, \"UTF-8\");\n System.out.println(message);\n System.out.println(\"message received\");\n }\n };\n\n channel.basicConsume(queueName, true, consumer);\n```\n\n```text\nDateTime startedAt = new DateTime();\n DateTime stopAt = startedAt.plusSeconds(60);\n long i=0;\n try {\n while (stopAt.compareTo(new DateTime()) > 0) {\n channel.basicConsume(queueName, true, consumer);\n i++;\n }\n }finally {\n System.out.println(new DateTime());\n System.out.println(startedAt);\n System.out.println(stopAt);\n System.out.println(i);\n }\n```\n\n```text\nchannel.basicConsume\n```\n\n```text\nbasicConsume\n```\n\n```text\nhandleDelivery\n```\n\n```text\nConsumer\n```\n\n```text\nconnection.close()\n```\n\n========================================\n\nComments:\n- Don't you have any exception such as ConnectException : Connection refused ?","metadata":{"transformedAt":"2026-08-18T18:33:20.190Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":131,"estimatedTokens":925}}783{"id":"stack-44646674","source":"stackoverflow","questionId":44646674,"title":"Send a file through rabbitmq","tags":["php","python","symfony","rabbitmq"],"text":"Title: Send a file through rabbitmq\nTags: php, python, symfony, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have a python client and a symfony backend. They can send and receive messages using rabbitmq.\n\nI use rabbitmq symfony bundle on my backend.\n\nI send an id of a php entity to the python client which get i through my api, do some work (heavy work) and store the result in a zip file. I want to send this zip file through rabbitmq. Is it possible? The file is really large (like 5mo)\n\nIf it's possible how can i do it ? (in an efficient way)\n\n========================================\n\nComments:\n- that's what i did. Thank you","metadata":{"transformedAt":"2026-08-18T18:33:20.190Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":17,"estimatedTokens":158}}784{"id":"stack-30223339","source":"stackoverflow","questionId":30223339,"title":"pika.exceptions.ProbableAuthenticationError when trying to send message to remote queue","tags":["python","rabbitmq","pika"],"text":"Title: pika.exceptions.ProbableAuthenticationError when trying to send message to remote queue\nTags: python, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI'm trying to run RabbitMQ Python tutorial but with sender on virtualbox host machine and receiver and queue on virtualbox guest machine. So I modified mentioned *send.py* code by only replacing **localhost** with **192.168.1.5**. When I run it, i receive following error:\n\n```\n...\n File \"/home/damian/.virtualenvs/kivy_1.9/local/lib/python2.7/site-packages/pika/adapters/base_connection.py\", line 153, in _check_state_on_disconnect\n raise exceptions.ProbableAuthenticationError\npika.exceptions.ProbableAuthenticationError\n```\n\nrabbitmq-server seems to be running, because when I stop it *send.py* gives me:\n\n```\n...\n File \"/home/damian/.virtualenvs/kivy_1.9/local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py\", line 301, in _adapter_connect\n raise exceptions.AMQPConnectionError(error)\npika.exceptions.AMQPConnectionError: Connection to 192.168.1.5:5672 failed: [Errno 111] Connection refused\n```\n\nwhich makes perfect sense.\n\nHow to fix that **ProbableAuthenticationError**?\n\nHost machine is Debian 7 with Python 2.7.3 and pika 0.9.14, guest is Ubuntu 15.04 with rabbitmq-server 3.4.3-2\n\n========================================\n\nCode:\n```text\n...\n File \"/home/damian/.virtualenvs/kivy_1.9/local/lib/python2.7/site-packages/pika/adapters/base_connection.py\", line 153, in _check_state_on_disconnect\n raise exceptions.ProbableAuthenticationError\npika.exceptions.ProbableAuthenticationError\n```\n\n```text\n...\n File \"/home/damian/.virtualenvs/kivy_1.9/local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py\", line 301, in _adapter_connect\n raise exceptions.AMQPConnectionError(error)\npika.exceptions.AMQPConnectionError: Connection to 192.168.1.5:5672 failed: [Errno 111] Connection refused\n```\n\n```text\n25603 prevent access using the default guest/guest credentials except via localhost since (1.0.0)\n```\n\n```text\n[{rabbit, [{loopback_users, []}]}].\n```\n\n```text\nguest\n```\n\n```text\nguest/guest\n```\n\n```text\nguest\n```\n\n```text\nguest\n```\n\n========================================\n\nComments:\n- please read this: stackoverflow.com/questions/22850546/…","metadata":{"transformedAt":"2026-08-18T18:33:20.190Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":74,"estimatedTokens":564}}785{"id":"stack-69893966","source":"stackoverflow","questionId":69893966,"title":"How to check rabbitMQ connection(health check) up or not?","tags":["docker","docker-compose","rabbitmq"],"text":"Title: How to check rabbitMQ connection(health check) up or not?\nTags: docker, docker-compose, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm running 4 microservice using Docker. Here one service depends on other services. That is why I need to check before using any service other services up or not?\n\nTo up all services I'm writing a bash script.\nFor my working purpose, I am using `sleep` until up properly RabbitMQ.\n\nWhat is the better solution to check RabbitMQ up or not? While RabbitMQ is not up I have to wait.\nNow for my working purpose I am using like that -\n\n```\n# wait for rabbitmq container be ready \nsleep 14\n```\n\nThis is the docker-compose container for rabbitMQ\n\n```\nrabbitmq:\n image: 'rabbitmq:3.8.9'\n container_name: rabbitmq_dev\n restart: always\n ports:\n - 5675:5672\n environment:\n - RABBITMQ_DEFAULT_USER=rabbit\n - RABBITMQ_DEFAULT_PASS=pass\n depends_on:\n - consul\n networks:\n - my_networks\n```\n\n========================================\n\nTop Answer:\nThere is a clean and straightforward way to achieve that with docker compose, by using `healthcheck` in combination with `depends_on`. As in the code snippet below:\n\n```\nrabbitmq:\n image: rabbitmq:latest\n container_name: rabbitmq_dev\n restart: always\n ports:\n - 5675:5672\n environment:\n - RABBITMQ_DEFAULT_USER=rabbit\n - RABBITMQ_DEFAULT_PASS=pass\n # if setting up the erlang cookie was necessary uncomment this\n # - RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS: -rabbitmq -setcookie mycookie\n depends_on:\n - consul\n networks:\n - my_networks\n healthcheck:\n # use the flag --erlang-cookie if setting the erlang \n # cookie was necessary (comment by red-riding-hood)\n # test: rabbitmq-diagnostics -q ping --erlang-cookie \"mycookie\"\n test: rabbitmq-diagnostics -q ping\n interval: 30s\n timeout: 10s\n retries: 5\n start_period: 10s\n```\n\nand in other services you need to add `depends_on`:\n\n```\nyour_app:\n ...\n depends_on:\n rabbitmq:\n condition: service_healthy\n```\n\nI had to set the erlang cookie: Via environment variable: RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS: -rabbitmq -setcookie mycookie Then test: rabbitmq-diagnostics -q ping --erlang-cookie \"mycookie\"\n\n========================================\n\nCode:\n```text\n# wait for rabbitmq container be ready \nsleep 14\n```\n\n```text\nrabbitmq:\n image: 'rabbitmq:3.8.9'\n container_name: rabbitmq_dev\n restart: always\n ports:\n - 5675:5672\n environment:\n - RABBITMQ_DEFAULT_USER=rabbit\n - RABBITMQ_DEFAULT_PASS=pass\n depends_on:\n - consul\n networks:\n - my_networks\n```\n\n```text\nsleep\n```\n\n```text\nrabbitmq:\n image: rabbitmq:latest\n container_name: rabbitmq_dev\n restart: always\n ports:\n - 5675:5672\n environment:\n - RABBITMQ_DEFAULT_USER=rabbit\n - RABBITMQ_DEFAULT_PASS=pass\n # if setting up the erlang cookie was necessary uncomment this\n # - RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS: -rabbitmq -setcookie mycookie\n depends_on:\n - consul\n networks:\n - my_networks\n healthcheck:\n # use the flag --erlang-cookie if setting the erlang \n # cookie was necessary (comment by red-riding-hood)\n # test: rabbitmq-diagnostics -q ping --erlang-cookie \"mycookie\"\n test: rabbitmq-diagnostics -q ping\n interval: 30s\n timeout: 10s\n retries: 5\n start_period: 10s\n```\n\n```text\nyour_app:\n ...\n depends_on:\n rabbitmq:\n condition: service_healthy\n```\n\n```text\nhealthcheck\n```\n\n```text\ndepends_on\n```\n\n```text\ndepends_on\n```\n\n```yaml\nservices:\n rabbitmq:\n image: rabbitmq:4.1-alpine@sha256:a9d1c4f50eb1be66f33271d9eca0dd73858db32cfa25ad2c78bf094f24ee0a7a\n environment:\n RABBITMQ_DEFAULT_USER: guest\n RABBITMQ_DEFAULT_PASS: guest\n ports:\n - 5672:5672\n healthcheck:\n # https://www.rabbitmq.com/docs/monitoring#stage-3\n test: rabbitmq-diagnostics --quiet check_running && rabbitmq-diagnostics --quiet check_local_alarms\n interval: 5s\n timeout: 5s\n retries: 5\n\n # Your app goes here.\n app:\n ...\n depends_on:\n rabbitmq:\n condition: service_healthy\n```\n\n```text\nrabbitmq-diagnostics -q ping\n```\n\n========================================\n\nComments:\n- Thanks for me it is working by this test command - test: [\"CMD\", \"redis-cli\", \"ping\"]\n- I had to set the erlang cookie: Via environment variable: `RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS: -rabbitmq -setcookie mycookie` Then `test: rabbitmq-diagnostics -q ping --erlang-cookie \"mycookie\"`\n- Note that Rabbit provides a series of health checks (rabbitmq.com/docs/monitoring#health-checks) where `rabbitmq-diagnostics -q ping` merely “ensures that the runtime is running and (indirectly) that CLI tools can authenticate with it.” Doesn’t mean you can send messages to it…\n- Nice, however on my side the command `rabbitmq-diagnostics --quiet check_running && rabbitmq-diagnostics --quiet check_local_alarms` takes on average 15 seconds to complete... Which is too long. What could explain that?\n- Locally I've seen anywhere between 12s to 17s and I think that’s just RabbitMQ standing up. If I look at the log messages then the server seems to progress forward steadily… maybe it just takes that long 🤷🏻♂️\n- In that case, wouldn't it be appropriate to increase the `timeout` in your answer, from `5` to `25` seconds for example?\n- It’s got 5 retries at 5s. The problem with long retry waits is that Rabbit might come online just an iota *after* the check and then I’ll have to wait another 25s for the next retry. I figure checking whether Rabbit is alive every 5s is an ok compromise/average considering its long boot time. But try other times, maybe you can come up with a better set of numbers?\n- I'm afraid the 5 retries will all fail because it's not RabbitMQ standing up but the command that always \"takes that long\". In any case I recommend rather adjusting `start_interval` and `start_period`, to set respectively the period during which the probe failure is ignored and the interval between probes. These settings are designed to address the long boot time. But yes thank you for your feedback!","metadata":{"transformedAt":"2026-08-18T18:33:20.190Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":194,"estimatedTokens":1496}}786{"id":"stack-32752996","source":"stackoverflow","questionId":32752996,"title":"Is it necessary to use three nodes to build RabbitMQ cluster?","tags":["rabbitmq"],"text":"Title: Is it necessary to use three nodes to build RabbitMQ cluster?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have to say the official website provides very little information to understand RabbitMQ clearly.\n\nThe official website suggests using three nodes to build a cluster. What is the reason for that? I suppose it's like ZooKeeper, which needs an odd number of nodes to do a quorum and elect the master.\n\nAlso, what is the advantage of using a non-HA cluster? Improve the performance or what? If the node which a queue resides is down, then the queue is not working. So for all situation, is it necessary to set the cluster to be mirror queue and auto-sync?\n\n========================================\n\nCode:\n```text\nmanual-sync\n```\n\n========================================\n\nComments:\n- Thank you so much for your clarity answer. The cluster more than 3 nodes is due to prevent the network partition. I still have no idea in the non-HA situation, how does cluster improve the performance? Is it practical to implement non-HA cluster on production environment?\n- When you use a cluster, you can access to all info (queues, exchanges etc..) even if you are not connected to the node that not contains the queue. You point make sense, but for example if you have just dispatch info in fanout way, you don't need the HA, since you have only temp queues.\n- The rabbitmq process gets high loads. And sasl logs appear lots of information like 'Context: shutdown_error Reason: shutdown Offender: [{nb_children,1}, {name,channel_sup}, {mfargs,{rabbit_channel_sup,start_link,[]}}, {restart_type,temporary}{shutdown,infinity}, {child_type,supervisor}] '. Under this situation, whether alter rabbitmq from single machine to cluster, or add cluster node will improve the performance?\n- which version are you using?\n- Sorry for not answering in time. RabbitMQ 3.2.2, Erlang R16B03\n- This version is a bit old, I suggest to update it, currently there is `3.5.6`. there are lot optimization, especially for high throughput. Please look this github.com/rabbitmq/rabbitmq-server/releases","metadata":{"transformedAt":"2026-08-18T18:33:20.190Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":27,"estimatedTokens":521}}787{"id":"stack-25619945","source":"stackoverflow","questionId":25619945,"title":"Cannot connect to RabbitMQ on Heroku with pika due to ProbableAccessDeniedError","tags":["python","heroku","rabbitmq","pika"],"text":"Title: Cannot connect to RabbitMQ on Heroku with pika due to ProbableAccessDeniedError\nTags: python, heroku, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI just set up a RabbitMQ add-on in heroku. After developing my app to queue up and consume messages running on a local instance, I deployed it to Heroku and have not been able to connect successfully yet. The username/password & hostname/port/vhost are all from `heroku config`. If I change the username or password, the error changes to `ProbableAuthenticationError` which makes me believe the authentication is at least correct, but likely an issue with my vhost or some other missing configuration. I haven't seen any similar questions on SO or after an hour of Googling that didn't address my issue.\n\nI have tried both the `RABBITMQ_BIGWIG_RX_URL` and `RABBITMQ_BIGWIG_TX_URL` environment variables for both sending and consuming, and no combination seems to work. Below is the code I have for attempting to connect.\n\n```\nurl = 'small-laurel-24.bigwig.lshift.net'\nport = 10019\nvhost = '/notmyrealvhost'\n\ncredentials = pika.PlainCredentials('username', 'password')\nparameters = pika.ConnectionParameters(url, port, vhost, credentials=credentials)\nconnection = pika.BlockingConnection(parameters)\n```\n\nIs there something I'm missing or any way to figure out what specifically is configured wrong? I'm at a loss here. Much thanks in advance!\n\nI am running pika 0.9.14, python 2.7.3.\n\n========================================\n\nTop Answer:\nThe problem was most likely that you added the forward slash character in your virtual-host. Many users confuse this with the forward slash being the root directory, but it is actually just the default virtual-host name.\n\nUnless you actually named the virtual-host using a forward slash, the name will always be identical to the name you see in the management console, e.g:\n\n- my_virtualhost and not /my_virtualhost\n\nThis is why your solution worked as you did not add the extra forward slash when using **URLParameters**. \n\nYour original code would have looked like this using URLParameters:\n\n```\namqp://username:password@small-laurel-24.bigwig.lshift.net:10018/%2Fnotmyrealvhost\n```\n\nWhile the working version you mentioned in your answer above does not have the forward slash (`%2F`) character.\n\n```\namqp://username:password@small-laurel-24.bigwig.lshift.net:10018/notmyrealvhost\n```\n\n========================================\n\nCode:\n```text\nurl = 'small-laurel-24.bigwig.lshift.net'\nport = 10019\nvhost = '/notmyrealvhost'\n\ncredentials = pika.PlainCredentials('username', 'password')\nparameters = pika.ConnectionParameters(url, port, vhost, credentials=credentials)\nconnection = pika.BlockingConnection(parameters)\n```\n\n```text\nheroku config\n```\n\n```text\nProbableAuthenticationError\n```\n\n```text\nRABBITMQ_BIGWIG_RX_URL\n```\n\n```text\nRABBITMQ_BIGWIG_TX_URL\n```\n\n```text\nURLParameters\n```\n\n```text\namqp://username:password@small-laurel-24.bigwig.lshift.net:10018/notmyrealvhost\n```\n\n```text\namqp://username:password@small-laurel-24.bigwig.lshift.net:10018/%2Fnotmyrealvhost\n```\n\n```text\namqp://username:password@small-laurel-24.bigwig.lshift.net:10018/notmyrealvhost\n```\n\n```text\n%2F\n```\n\n========================================\n\nComments:\n- Probably not it, but keep in mind that most vhosts don't have a `/` in their name. Default is `/` while others usually are named without the special character, e.g. `notmyrealvhost`.\n- @eandersson I think you're right. I ended up solving it another way, but I have a feeling that was the case.\n- I added my own answer, with a basic explanation in case someone else has the same issue.","metadata":{"transformedAt":"2026-08-18T18:33:20.190Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":101,"estimatedTokens":908}}788{"id":"stack-15684846","source":"stackoverflow","questionId":15684846,"title":"convert curl call into java urlconnection call","tags":["java","curl","rabbitmq","trace"],"text":"Title: convert curl call into java urlconnection call\nTags: java, curl, rabbitmq, trace\nSource: Stack Overflow\n\nQuestion:\nI have curl command:\n\n```\ncurl -i -u guest:guest -H \"content-type:application/json\"\n-XPUT \\ http://localhost:15672/api/traces/%2f/my-trace \\\n-d'{\"format\":\"text\",\"pattern\":\"#\"}'\n```\n\nAnd I want to create HTTP Request in Java API which will do the same thing. This curl command can be found in this README. It is used to start recording log on RabbitMQ. Response is not important.\n\nFor now I created something like this (I've deleted less important lines i.e. with catching exception etc.), but unfortunately it doesn't work:\n\n```\nurl = new URL(\"http://localhost:15672/api/traces/%2f/my-trace\");\nuc = url.openConnection();\n\nuc.setRequestProperty(\"Content-Type\", \"application/json\");\nuc.setRequestProperty(\"format\",\"json\");\nuc.setRequestProperty(\"pattern\",\"#\")\nString userpass = \"guest:guest\";\nString basicAuth = \"Basic \" + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes());\nuc.setRequestProperty (\"Authorization\", basicAuth);\n```\n\nENTIRE CODE\n\n========================================\n\nTop Answer:\ntwo problems that i can see:\n\n- you aren't setting the request method, in your curl example it is \"PUT\"\n\n- the '-d' data should be the request *body*, not request parameters (i.e. you should be writing that string to the request OutputStream)\n\nalso, when you do `userpass.getBytes()` you are getting the bytes using the default platform character encoding. this may or may not be the encoding that you desire. better to use an explicit character encoding (presumably the one the server is expecting).\n\n========================================\n\nCode:\n```text\ncurl -i -u guest:guest -H \"content-type:application/json\"\n-XPUT \\ http://localhost:15672/api/traces/%2f/my-trace \\\n-d'{\"format\":\"text\",\"pattern\":\"#\"}'\n```\n\n```text\nurl = new URL(\"http://localhost:15672/api/traces/%2f/my-trace\");\nuc = url.openConnection();\n\nuc.setRequestProperty(\"Content-Type\", \"application/json\");\nuc.setRequestProperty(\"format\",\"json\");\nuc.setRequestProperty(\"pattern\",\"#\")\nString userpass = \"guest:guest\";\nString basicAuth = \"Basic \" + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes());\nuc.setRequestProperty (\"Authorization\", basicAuth);\n```\n\n```text\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.net.HttpURLConnection;\nimport java.net.URL;\nimport java.net.Proxy;\nimport java.net.InetSocketAddress;\nimport java.io.OutputStreamWriter;\n\npublic class Curl {\n\n public static void main(String[] args) {\n\n try {\n\n String url = \"http://127.0.0.1:15672/api/traces/%2f/trololo\";\n\n URL obj = new URL(url);\n HttpURLConnection conn = (HttpURLConnection) obj.openConnection();\n\n conn.setRequestProperty(\"Content-Type\", \"application/json\");\n conn.setDoOutput(true);\n\n conn.setRequestMethod(\"PUT\");\n\n String userpass = \"user\" + \":\" + \"pass\";\n String basicAuth = \"Basic \" + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes(\"UTF-8\"));\n conn.setRequestProperty (\"Authorization\", basicAuth);\n\n String data = \"{\\\"format\\\":\\\"json\\\",\\\"pattern\\\":\\\"#\\\"}\";\n OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());\n out.write(data);\n out.close();\n\n new InputStreamReader(conn.getInputStream()); \n\n } catch (Exception e) {\n e.printStackTrace();\n }\n\n }\n\n}\n```\n\n```text\nuserpass.getBytes()\n```\n\n========================================\n\nComments:\n- Do you get any error? What exactly do you mean by \"it doesn't work\"?\n- This should create log file which can be seen in RabbitMQ management page, but it is not created.\n- I tried to do this things, but it still doesn't work. Here's new code: pastebin.com/Ziqx3Z68\n- @user2219448 - it's generally easiest to update your answer or create a new question. that said, you should probably set the method *after* you set doOutput. also, you should *not* be url encoding the body content. an easy way to debug something like this is to use an http proxy like charles proxy to examine the requests on the wire and see how your output differs from the curl output.\n- Thank you for your help, debugging with charles proxy was also helpful. Cheers. (can't give +1, not enough reputation..)","metadata":{"transformedAt":"2026-08-18T18:33:20.190Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":120,"estimatedTokens":1067}}789{"id":"stack-24939398","source":"stackoverflow","questionId":24939398,"title":"RabbitMQ Java client auto reconnect","tags":["java","rabbitmq"],"text":"Title: RabbitMQ Java client auto reconnect\nTags: java, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nWhen my application looses connection to RabbitMQ I have its connection factory set to automatically try and reconnect\n\n```\nConnectionFactory factory = new ConnectionFactory();\n factory.setUsername(username);\n factory.setPassword(password);\n factory.setRequestedHeartbeat(1);\n factory.setConnectionTimeout(5000);\n factory.setAutomaticRecoveryEnabled(true);\n factory.setTopologyRecoveryEnabled(true);\n```\n\nWhen it is trying to reconnect it blocks but it never stops blocking once it gets connected again and I am not to sure why.\n\nI am using the latest version of the java client 3.3.4\n\nThis also seems to happen when I force disconnect the client connection via the rabbitmq management interface.\n\nSome further research it seems like its hanging while it is trying to get a channel but the web interface says there is a channel connected.\n\n========================================\n\nCode:\n```text\nConnectionFactory factory = new ConnectionFactory();\n factory.setUsername(username);\n factory.setPassword(password);\n factory.setRequestedHeartbeat(1);\n factory.setConnectionTimeout(5000);\n factory.setAutomaticRecoveryEnabled(true);\n factory.setTopologyRecoveryEnabled(true);\n```\n\n```text\nconnectionTimeout\n```\n\n```text\nnetworkRecoveryInterval\n```\n\n```text\nShutdownListener\n```\n\n```text\nrequestHeartbeet\n```\n\n========================================\n\nComments:\n- what about your `networkRecoveryInterval` property? Also consider to set the request heartbeet to more than one second in production environment...\n- Yup this is just for testing right now. I actually just set the networkRecoveryInterval to 0 and now it is actually throwing an error when it can't reconnect which is a start. However it still seems to hang once it finally reconnects. I managed to do a thread dump and this is the only thing I could find for rabbitmq pastebin.com/X8bR8Bgr\n- Add an ShutDownListener to get more information: rabbitmq.com/releases/rabbitmq-java-client/v3.3.4/… By the way rabbitmq has some weird default properties, for example connectionTimeout's default is 0, which means waiting infinitely if. I am not quite sure about `topologyRecoveryEnabled` can you try it with the default value?\n- Well that is strange. Apperently auto recovery doesn't work right if i manually stop rabbitmq gracefully. But if I disconnect from the network it works perfectly fine. That seems rather weird\n- When I manually stop rabbitmg I get broker forced connection closure with reason 'shutdown' from the shutdown listener. But once I turn rabbitmq back on it will reconnect and remake the queues but wont allow anything else\n- I am using rabbitmq in a cluster with 3 nodes, so reconnect works fine then. I broke up the connection via an iptables command.\n- You might see if running through Lyra solves your problem.\n- Update: it looks like the later versions (currently 4.1.0) at least sets the connection timeout to 60 seconds by default instead of 0. Thanks for the info.","metadata":{"transformedAt":"2026-08-18T18:33:20.190Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":65,"estimatedTokens":767}}790{"id":"stack-35783240","source":"stackoverflow","questionId":35783240,"title":"RabbitMQ - Send message to a particular consumer in a queue","tags":["rabbitmq","spring-amqp","spring-rabbit"],"text":"Title: RabbitMQ - Send message to a particular consumer in a queue\nTags: rabbitmq, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nThis is the scenario - There are multiple app servers. Browser can connect via websocket to any app server.\n\nThe app servers (consumers) are all listening on a particular queue. As soon as a web socket connection is received, the particular app server binds the queue with a routing key {userId} to a direct exchange.\n\nI want a message sent to the direct exchange with the routing key {userId} to be received by only the particular app server where the binding has occured.\n\nIs a direct exchange the right exchange to use in this case? Or should some other type of exchange be used?\n\nI'm using spring-amqp to create dynamic bindings when a websocket comes in\n\n```\n// create the RabbitMq queue and bind to it\nString routingKey = MessageConstants.getRoutingKeyForUserRecommendationQueue(user);\nBinding userRecommendationBinding = BindingBuilder.bind(userRecommendationsQueue).\n to(directExchange).with(routingKey);\namqpAdmin.declareBinding(userRecommendationBinding);\n```\n\n========================================\n\nTop Answer:\nSend message to a particular consumer in a queue\n\nthis is not possible. any consumer connected to a queue has a chance of consuming any given message in the queue\n\n I want a message sent to the direct exchange with the routing key {userId} to be received by only the particular app server where the binding has occured.\n\nyou can do this by creating `exclusive` / `autoDelete` queues for your consumer, with a binding that directs all messages for that consumer to that queue.\n\n Is a direct exchange the right exchange to use in this case? \n\neither a direct exchange or a topic exchange is fine. direct exchange is slightly easier to understand, but topic exchange is more flexible\n\n========================================\n\nCode:\n```text\n// create the RabbitMq queue and bind to it\nString routingKey = MessageConstants.getRoutingKeyForUserRecommendationQueue(user);\nBinding userRecommendationBinding = BindingBuilder.bind(userRecommendationsQueue).\n to(directExchange).with(routingKey);\namqpAdmin.declareBinding(userRecommendationBinding);\n```\n\n```text\nkey\n```\n\n```text\nSimpleMessageListenerContainer\n```\n\n```text\naddQueues()\n```\n\n```text\nexhchange\n```\n\n```text\nroutingKey\n```\n\n```text\nexclusive\n```\n\n```text\nautoDelete\n```\n\n========================================\n\nComments:\n- Unfortunately that is not what is happening. The messages seem to go randomly to any consumer, and not just the consumer that created the binding.\n- BTW, I could swear it was working before we moved from RabbitMQ 3.4 to 3.6\n- Sorry, misunderstood from the first sight. Please, take a look into my update\n- Thanks @Artem and Derick, your answers are the same. This works, but will having 1000s of queues cause performance issues? We expect that there will be about 10000 queues. Also, any idea what is the overhead of creating a queue vs binding?\n- That's doesn't matter because I'm sure your queues should be deleted after the subscription is gone. Your queues don't make sense on the Broker if they aren't bound to to some exchanges. BTW, by default all queues are bound to the default direct exchange by their names. Jut for convenience. So, you may really don't need to worry about bindings but just send messages to the default exchange with queue names as a `routingKey`.\n- Artem and Derick, I cannot create an exclusive/autodelete queue because a user could open multiple tabs. What I need is a way to disconnect the consumer BUT keep the queue. Queue will expire because of the \"x-expires\" tag that I put on it. Can I disconnect a consumer without deleting a queue using rabbitmq-amqp ?\n- I guess SimpleMessageListenerContainer.removeQueue will just remove the consumer. Correct me if I'm wrong.\n- Yes, that's correct it stops to listen to those queues, therefore remove consumer on the RabbitMQ side.","metadata":{"transformedAt":"2026-08-18T18:33:20.190Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":88,"estimatedTokens":990}}791{"id":"stack-11459759","source":"stackoverflow","questionId":11459759,"title":"Unique ids for jobs in a message queue?","tags":["java","message-queue","rabbitmq"],"text":"Title: Unique ids for jobs in a message queue?\nTags: java, message-queue, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have an application which I'm writing which needs to perform long computations in the background, so I have essentially the following workflow:\n\n- Client submits job to an edge \"dispatcher\" server.\n\n- Dispatcher server submits job to message queue.\n\n- Compute server pulls job and starts work.\n\nThe compute server also provides live feedback on the status of the work, so as to make it possible for clients to watch progress. \n\nThe main problem I'm having right now is figuring out how to get a unique job id for a submitted message in the queue, and also to figure out after the fact which server serviced the message. Once the job is initially submitted (step 1), the client should receive a unique token identifying the job. The client should then be able to periodically poll the dispatcher server to check the status of the token on whether it's been started or not.\n\nAfter a compute server has serviced the request, the client should then get the DNS address or IP address of the encoder server in the poll call. \n\nHow can I make this happen? Do message queues provide this notion of unique identifying tokens for each message in the queue?\n\n========================================\n\nTop Answer:\nYou can generate universally unique identifiers using java.util.UUID class.\n\nSample code:\n\n```\nUUID uuid = UUID.randomUUID();\nSystem.out.println(\"UUID: \" + uuid.toString());\n```\n\nsample output: `UUID: d5a43450-2321-40ac-9746-9cf5d7447aca`\n\nFor message queue part, to avoid reinventing the wheel, I'd recommend that you check JMS based solutions first. There are a lot of alternatives.\n\n========================================\n\nCode:\n```text\ncorrelationId\n```\n\n```text\ncallback\n```\n\n```text\nUUID uuid = UUID.randomUUID();\nSystem.out.println(\"UUID: \" + uuid.toString());\n```\n\n```text\nUUID: d5a43450-2321-40ac-9746-9cf5d7447aca\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.190Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":56,"estimatedTokens":488}}792{"id":"stack-57768315","source":"stackoverflow","questionId":57768315,"title":"How to rename queue in Rabbitmq?","tags":["rabbitmq"],"text":"Title: How to rename queue in Rabbitmq?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm using `Rabbitmq 3.7.17` and I need to rename an existing queue that already contains some messages. Is there a simple way to rename a queue?\n\n========================================\n\nTop Answer:\nTo add to what @user11044402 already recommended, once you created the queue under its NEW name, use the `RabbitMQ Shovel` plugin if it is installed to move all the messages from the queue with the old name to the new queue. Then delete the old queue - the shovel will be automatically removed as well.\n\n========================================\n\nCode:\n```text\nRabbitmq 3.7.17\n```\n\n```text\nRabbitMQ Shovel\n```\n\n========================================\n\nComments:\n- This approach has a number of drawbacks: - New events can be added from the exchange to the new queue out-of-order with the republished events - All queues bound to the exchange will get the republished events, surely out-of-order","metadata":{"transformedAt":"2026-08-18T18:33:20.190Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":27,"estimatedTokens":246}}793{"id":"stack-13863761","source":"stackoverflow","questionId":13863761,"title":"Service oriented architecture - Transport layer (http vs messaging)","tags":["http","redis","rabbitmq","soa","messaging"],"text":"Title: Service oriented architecture - Transport layer (http vs messaging)\nTags: http, redis, rabbitmq, soa, messaging\nSource: Stack Overflow\n\nQuestion:\nWe've looking at moving splitting up our architecture (and adding new components) using a Service Oriented Architecture (SOA). There will be a number of external API's that will be used by third parties, which we will make using a REST HTTP interface, however I was wondering what would be best to use internally as all components are with in our control and will be on the same network, however potentially different technologies (mainly .net and ruby on rails).\n\nWould there be big performance/functionality gains in using a messaging system (redis, rabbitmq, EMS, other notable exceptions I've not heard of...) instead of HTTP (REST, SOAP, etc). \n\nI've struggled to find good information on this topic and (as you can probably tell) I'm fairly new to this side area, so any advice or good resources would be appreciated!\n\nThnaks\n\n========================================\n\nTop Answer:\nMessaging tends to give you a more loosely coupled architecture. It can potentially be more robust as well, since individual components can fail without killing the entire infrastructure.\n\nThe downside is complexity, the paradigm shift to an asynchronous model, and possibly performance (especially if you're persisting messages every where). \n\nYou also need to ensure that your messaging system is particularly robust. A single aspect of your logic can go down and restart without affecting everything, but if you lose your core message base, then ALL of your logic is down waiting for the messaging to be back up.\n\nFortunately, the message bus can be long running without humans fiddling and touching it, the largest source of errors and instability in any system.","metadata":{"transformedAt":"2026-08-18T18:33:20.190Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":23,"estimatedTokens":452}}794{"id":"stack-14686136","source":"stackoverflow","questionId":14686136,"title":"Python IPC - Twisted, RabbitMQ,","tags":["python","ipc","twisted","rabbitmq","zeromq"],"text":"Title: Python IPC - Twisted, RabbitMQ,\nTags: python, ipc, twisted, rabbitmq, zeromq\nSource: Stack Overflow\n\nQuestion:\nI want to create 2 applications in Python which should communicate with each other. One of these application should behave like a server and the second should be the GUI of a client. They could be run on the same system(on the same machine) or remotely and on different devices.\n\nI want to ask you, which technology should I use - an AMQP messaging (like `RabbitMQ`), `Twisted` like server (or `Tornado`) or ZeroMQ and connect applications to it. In the future I would like to have some kind of authentication etc. \n\nI have read really lot of questions and articles (like this one: Why do we need to use rabbitmq), and a lot of people are telling \"rabbitmq and twisted are different\". I know they are. I really love to know the differences **and** why one of these solutions will be superior than the other in this case.\n\n**EDIT:**\nI want to use it with following requirements:\n\n- There will be more than 1 user connected at a time - I think there will be 1 - 10 users connected to the same program and they would work collaboratively\n\n- The data send are \"messages\" telling what user did - something like remote calls (but don't focus on that, because the GUIS can be written in different languages, so the messages will be something like json informations).\n\n- The system should allow for collaborative work - so it should be as interactive as possible. (data will be send all the time when user something types or performs some action).\n\n**Additional I would love to hear why one solution would be better than the other not only in this particular case.**\n\n========================================\n\nTop Answer:\nWhen someone is telling you that Twisted and RabbitMQ is different is because compare both is like compare two things with different target.\n\nTwisted is a asynchronous framework, like Tornadao. RabbitMQ is a message queue system. You can't compare each one straight for.\n\nYou should turn your ask into a two new questions, the first one wich protocol should I use to communicate my process ? The answer can be figure out with words like amqp, Protocol Buffers ...\n\nAnd the other one, which framework should I use to write my client and server program ? Here the answer can fall on Twisted, Tornado, ....\n\n========================================\n\nCode:\n```text\nRabbitMQ\n```\n\n```text\nTwisted\n```\n\n```text\nTornado\n```\n\n========================================\n\nComments:\n- What are your requirements: 1. Number of clients (probably only 1?) 2. Amount and type of data to send 3. How frequent do you send data\n- BTW, ZeroMQ does **not** implement AMQP.\n- I don't think anyone can make good suggestions without knowing more about what you need either system to do, etc., since both could conceivably work just fine\n- There really needs to be a \"Stack Architecture\". I see dozens of these questions a week that are not programming questions... they are architecture questions. I feel there is a distinction. Programming questions are \"tried this ...\". Architecture questions are: \"How do I build ...\".\n- @shlamar: You're right, I fixed the question and added additional requirements.\n- @Adam Gent: I didnt knew about Stack Architecture - I will use it, thanks!\n- Wow, uninformative comment for the win. For what it's worth, I think this answer hits the nail on the head: Twisted for endpoints, RabbitMQ between them, understand your problem domains.","metadata":{"transformedAt":"2026-08-18T18:33:20.191Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":58,"estimatedTokens":869}}795{"id":"stack-13132512","source":"stackoverflow","questionId":13132512,"title":"Why doesn't Channel.waitForConfirmsOrDie block?","tags":["rabbitmq"],"text":"Title: Why doesn't Channel.waitForConfirmsOrDie block?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have a publish-subscribe use case where I would like to block on the publish side until each of the subscribers confirm that they have completed handling the message sent by the publisher. \n\nI (incorrectly?) assumed that I could use RabbitMQ and its Java amqp-client's Channel.waitForConfirmsOrDie method as part of my solution. The issue is that I haven't found a case in which waitForConfirmsOrDie will actually block.\n\nAccording to the javadocs, waitForConfirmsOrDie is supposed to: \n\n Wait until all messages published since the last call have been either ack'd or nack'd by the broker. If any of the messages were nack'd, waitForConfirmsOrDie will throw an IOException. When called on a non-Confirm channel, it will return immediately.\n\nIn order to test that this method really works, I started with this example code from the RabbitMQ website. \n\nThe example code creates a publisher and a consumer, each on its own separate thread. Then the publisher sends messages to the exchange while the consumer consumes the messages. It seems that the publisher is supposed to block until all of the messages are ack'd via its call to waitForConfirmsOrDie().\n\nThis example code seemed like it matched up perfectly with what I was trying to do. But, it doesn't seem to work the way I thought it did. In fact, if, in the consumer thread, I turn off auto-acking messages, then waitForConfirmsOrDie() still returns immediately.\n\nI turned off auto ack by just changing one false to true: \n`ch.queueDeclare(QUEUE_NAME, false, false, false, null);`\nbecomes\n`ch.queueDeclare(QUEUE_NAME, true, false, false, null);` (2nd arg false instead of true). I believe this means that acks should no longer be sent by the consumer.\n\nSo what does waitForConfirmsOrDie() actually do? When would it block?\n\nIf waitForConfirmsOrDie doesn't do what I want, is there a way to make a publisher wait until all subscribers ack a message before proceeding?\n\n========================================\n\nCode:\n```text\nch.queueDeclare(QUEUE_NAME, false, false, false, null);\n```\n\n```text\nch.queueDeclare(QUEUE_NAME, true, false, false, null);\n```\n\n```text\nwaitForConfirms*\n```\n\n```text\nbasicPublish\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.191Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":46,"estimatedTokens":568}}796{"id":"stack-63537708","source":"stackoverflow","questionId":63537708,"title":"Springboot with Docker: environment variable to override RabbitMQ host IP property in spring boot's application.properties is not working","tags":["java","spring-boot","docker","rabbitmq"],"text":"Title: Springboot with Docker: environment variable to override RabbitMQ host IP property in spring boot's application.properties is not working\nTags: java, spring-boot, docker, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am working on spring boot application where I have to use RabbitMQ as a message broker. Instead of using RabbitMQ on my localhost, I am using docker image from docker hub using below command\n\n```\ndocker run -d --name rabbit-name-management -p 15672:15672 -p 5672:5672 -p 15671:15671 -p 5671:5671 -p 4369:4369 rabbitmq:3-management\n```\n\nSo it pulls the image and running successfully as a docker container.\n\nNow in my spring boot application, I use an `application.properties` file in order to connect to `RabbitMQ` and which looks like as shown below:\n\n```\nspring.rabbitmq.host=localhost\nspring.rabbitmq.port=5672\nspring.rabbitmq.username=*****\nspring.rabbitmq.password=********\n```\n\n**My spring boot docker file**\n\n```\nFROM openjdk:8-jdk-alpine\nVOLUME /tmp\nCOPY encryptionKey.jks encryptionKey.jks\nCOPY UnlimitedJCEPolicyJDK8/* /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/\nCOPY target/ConfigServer-0.0.1-SNAPSHOT.jar ConfigServer.jar\nENTRYPOINT [\"java\",\"-Djava.security.egd=file:/dev/./urandom\",\"-jar\",\"ConfigServer.jar\"]\n```\n\nI used command `docker inspect ` to find out the IP address of the machine where RabbitMQ is running. And in order to make it communicate with RabbitMQ I am using environment variable to override localhost with the actual IP address of the container where RabbitMQ is running. And the docker command for this is as below\n\n```\ndocker run -p 8012:8012 -e \"spring.rabbitmq.host=http://172.17.0.3\" config-server\n```\n\nBut this command is getting failed and it logs the error as below\n\n```\n2020-08-20 06:10:31.077 ERROR 1 --- [ main] o.s.boot.SpringApplication : Application run failed\n \norg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rabbitConnectionFactory' defined in class path resource [org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration$RabbitConnectionFactoryCreator.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.amqp.rabbit.connection.CachingConnectionFactory]: Factory method 'rabbitConnectionFactory' threw exception; nested exception is java.lang.IllegalArgumentException: Address http://172.17.0.3:5672 seems to contain an unquoted IPv6 address. Make sure you quote IPv6 addresses like so: [2001:db8:85a3:8d3:1319:8a2e:370:7348]\n at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:655) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:635) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1176) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]\n at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]\n at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]\n at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]\n at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]\n at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]\n at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]\n at com.appsdeveloperblog.photoapp.api.PhotoAppApiConfigServerApplication.main(PhotoAppApiConfigServerApplication.java:12) [classes!/:0.0.1-SNAPSHOT]\n at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_212]\n at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_212]\n at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_212]\n at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_212]\n at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) [ConfigServer.jar:0.0.1-SNAPSHOT]\n at org.springframework.boot.loader.Launcher.launch(Launcher.java:109) [ConfigServer.jar:0.0.1-SNAPSHOT]\n at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) [ConfigServer.jar:0.0.1-SNAPSHOT]\n at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) [ConfigServer.jar:0.0.1-SNAPSHOT]\nCaused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.amqp.rabbit.connection.CachingConnectionFactory]: Factory method 'rabbitConnectionFactory' threw exception; nested exception is java.lang.IllegalArgumentException: Address http://172.17.0.3:5672 seems to contain an unquoted IPv6 address. Make sure you quote IPv6 addresses like so: [2001:db8:85a3:8d3:1319:8a2e:370:7348]\n at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n ... 28 common frames omitted\nCaused by: java.lang.IllegalArgumentException: Address http://172.17.0.3:5672 seems to contain an unquoted IPv6 address. Make sure you quote IPv6 addresses like so: [2001:db8:85a3:8d3:1319:8a2e:370:7348]\n at com.rabbitmq.client.Address.parseHost(Address.java:96) ~[amqp-client-5.9.0.jar!/:5.9.0]\n at com.rabbitmq.client.Address.parseAddress(Address.java:158) ~[amqp-client-5.9.0.jar!/:5.9.0]\n at com.rabbitmq.client.Address.parseAddresses(Address.java:173) ~[amqp-client-5.9.0.jar!/:5.9.0]\n at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.setAddresses(AbstractConnectionFactory.java:299) ~[spring-rabbit-2.2.10.RELEASE.jar!/:2.2.10.RELEASE]\n at org.springframework.boot.context.properties.PropertyMapper$Source.to(PropertyMapper.java:316) ~[spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]\n at org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration$RabbitConnectionFactoryCreator.rabbitConnectionFactory(RabbitAutoConfiguration.java:102) ~[spring-boot-autoconfigure-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]\n at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_212]\n at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_212]\n at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_212]\n at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_212]\n at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n ... 29 common frames omitted\n```\n\nI don't have any idea what is this `unquoted IPv6 address` and why it is complaining about it here and what am I supposed to do here to remove this error.\n\n========================================\n\nCode:\n```text\ndocker run -d --name rabbit-name-management -p 15672:15672 -p 5672:5672 -p 15671:15671 -p 5671:5671 -p 4369:4369 rabbitmq:3-management\n```\n\n```text\nspring.rabbitmq.host=localhost\nspring.rabbitmq.port=5672\nspring.rabbitmq.username=*****\nspring.rabbitmq.password=********\n```\n\n```text\nFROM openjdk:8-jdk-alpine\nVOLUME /tmp\nCOPY encryptionKey.jks encryptionKey.jks\nCOPY UnlimitedJCEPolicyJDK8/* /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/\nCOPY target/ConfigServer-0.0.1-SNAPSHOT.jar ConfigServer.jar\nENTRYPOINT [\"java\",\"-Djava.security.egd=file:/dev/./urandom\",\"-jar\",\"ConfigServer.jar\"]\n```\n\n```text\ndocker run -p 8012:8012 -e \"spring.rabbitmq.host=http://172.17.0.3\" config-server\n```\n\n```text\n2020-08-20 06:10:31.077 ERROR 1 --- [ main] o.s.boot.SpringApplication : Application run failed\n \norg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rabbitConnectionFactory' defined in class path resource [org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration$RabbitConnectionFactoryCreator.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.amqp.rabbit.connection.CachingConnectionFactory]: Factory method 'rabbitConnectionFactory' threw exception; nested exception is java.lang.IllegalArgumentException: Address http://172.17.0.3:5672 seems to contain an unquoted IPv6 address. Make sure you quote IPv6 addresses like so: [2001:db8:85a3:8d3:1319:8a2e:370:7348]\n at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:655) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:635) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1176) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]\n at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]\n at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]\n at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]\n at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]\n at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]\n at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]\n at com.appsdeveloperblog.photoapp.api.PhotoAppApiConfigServerApplication.main(PhotoAppApiConfigServerApplication.java:12) [classes!/:0.0.1-SNAPSHOT]\n at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_212]\n at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_212]\n at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_212]\n at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_212]\n at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) [ConfigServer.jar:0.0.1-SNAPSHOT]\n at org.springframework.boot.loader.Launcher.launch(Launcher.java:109) [ConfigServer.jar:0.0.1-SNAPSHOT]\n at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) [ConfigServer.jar:0.0.1-SNAPSHOT]\n at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) [ConfigServer.jar:0.0.1-SNAPSHOT]\nCaused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.amqp.rabbit.connection.CachingConnectionFactory]: Factory method 'rabbitConnectionFactory' threw exception; nested exception is java.lang.IllegalArgumentException: Address http://172.17.0.3:5672 seems to contain an unquoted IPv6 address. Make sure you quote IPv6 addresses like so: [2001:db8:85a3:8d3:1319:8a2e:370:7348]\n at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n ... 28 common frames omitted\nCaused by: java.lang.IllegalArgumentException: Address http://172.17.0.3:5672 seems to contain an unquoted IPv6 address. Make sure you quote IPv6 addresses like so: [2001:db8:85a3:8d3:1319:8a2e:370:7348]\n at com.rabbitmq.client.Address.parseHost(Address.java:96) ~[amqp-client-5.9.0.jar!/:5.9.0]\n at com.rabbitmq.client.Address.parseAddress(Address.java:158) ~[amqp-client-5.9.0.jar!/:5.9.0]\n at com.rabbitmq.client.Address.parseAddresses(Address.java:173) ~[amqp-client-5.9.0.jar!/:5.9.0]\n at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.setAddresses(AbstractConnectionFactory.java:299) ~[spring-rabbit-2.2.10.RELEASE.jar!/:2.2.10.RELEASE]\n at org.springframework.boot.context.properties.PropertyMapper$Source.to(PropertyMapper.java:316) ~[spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]\n at org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration$RabbitConnectionFactoryCreator.rabbitConnectionFactory(RabbitAutoConfiguration.java:102) ~[spring-boot-autoconfigure-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]\n at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_212]\n at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_212]\n at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_212]\n at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_212]\n at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]\n ... 29 common frames omitted\n```\n\n```text\napplication.properties\n```\n\n```text\nRabbitMQ\n```\n\n```text\ndocker inspect <RABBITMQ_CONTAINER_ID>\n```\n\n```text\nunquoted IPv6 address\n```\n\n```text\n/**\n * Extracts hostname or IP address from a string containing a hostname, IP address,\n * hostname:port pair or IP address:port pair.\n * Note that IPv6 addresses must be quoted with square brackets, e.g. [2001:db8:85a3:8d3:1319:8a2e:370:7348].\n *\n * @param addressString the string to extract hostname from\n * @return the hostname or IP address\n */\n public static String parseHost(String addressString) { \n //...\n int lastClosingSquareBracket = addressString.lastIndexOf(\"]\");\n if (lastClosingSquareBracket == -1) {\n String[] parts = addressString.split(\":\");\n if (parts.length > 2) { // HERE OCCURS THE ISSUE\n String msg = \"Address \" +\n addressString +\n \" seems to contain an unquoted IPv6 address. Make sure you quote IPv6 addresses like so: [2001:db8:85a3:8d3:1319:8a2e:370:7348]\";\n LOGGER.error(msg);\n throw new IllegalArgumentException(msg);\n } \n return parts[0];\n }\n //...\n }\n```\n\n```text\ndocker run -p 8012:8012 -e \"spring.rabbitmq.host=172.17.0.3\" config-server\n```\n\n```text\nhttp\n```\n\n========================================\n\nComments:\n- Oops! Very small mistake but very important one I learnt. Thanks @davidxxx, It worked.","metadata":{"transformedAt":"2026-08-18T18:33:20.191Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":12,"totalLines":229,"estimatedTokens":4863}}797{"id":"stack-49672474","source":"stackoverflow","questionId":49672474,"title":"RabbitMQ consumer overload","tags":["rabbitmq","amqp","producer-consumer","rabbitmq-exchange"],"text":"Title: RabbitMQ consumer overload\nTags: rabbitmq, amqp, producer-consumer, rabbitmq-exchange\nSource: Stack Overflow\n\nQuestion:\nI`ve been reading about the principles of AMQP messaging confirms. (https://www.rabbitmq.com/confirms.html). Really helpful and wel written article but one particular thing about consumer aknowledgments is really confusing, here is the quote:\n\n \n Another things that's important to consider when using automatic acknowledgement mode is that of **consumer overload**.\n\n \n\nConsumer overload? Message queue is processed and kept in RAM by broker (if I understand it correctly). What overload is it about? Does consumer have some kind of second queue?\nAnother part of that article is even more confusing:\n\n \n Consumers therefore can be overwhelmed by the rate of deliveries, potentially **accumulating a backlog in memory** and running out of heap or getting their process terminated by the OS.\n\n \n\nWhat backlog? How is this all works together? What part of job is done by consumer (besides consuming message and processing it of course)? I thought that broker is keeping queues alive and forwards the messages but now I am reading about some mysterious backlogs and consumer overloads. This is really confusing, can someone explain it a bit or at least point me to the good source?\n\n========================================\n\nTop Answer:\nBeing able to signal back pressure is a basic problem in distributed systems. Without explicit acknowledgements, the consumer does not have any way to say \"Slow down\" to broker. With auto-ack on, as soon as the TCP acknowledgement is received by broker, it deletes the message from its memory/disk.\n\nHowever, it does not mean that the consuming application has processed the message or have enough memory to store incoming messages. The backlog in the article is simply a data structure used to store unprocessed messages (in the consumer application)\n\n========================================\n\nCode:\n```text\nAutoAck=true\n```\n\n```text\nAutoAck\n```\n\n========================================\n\nComments:\n- Thank you for such detailed answer! It makes much more sense now! What happens if I turn off Auto-Ack without specifying pre-fetch count? Wil consumer still be flooded with messages? Or I don`t quite understand the role of the pre-fetch count here?\n- I’d have to go look up to see, but in all reality, I think so. A prefetch count of more than 1 only makes sense in very limited cases, where the processing of the message takes about the same amount of time as it does to deliver (there aren’t too many use cases where that is true). I prefer no pre-fetch.\n- Maybe this article is helpful: Work Queues (using the Java Client)","metadata":{"transformedAt":"2026-08-18T18:33:20.191Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":46,"estimatedTokens":672}}798{"id":"stack-25175448","source":"stackoverflow","questionId":25175448,"title":"Is there any option to set AutomaticRecoveryEnabled in RabbitMQ using Spring-AMQP?","tags":["java","spring","rabbitmq","spring-amqp","spring-rabbit"],"text":"Title: Is there any option to set AutomaticRecoveryEnabled in RabbitMQ using Spring-AMQP?\nTags: java, spring, rabbitmq, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nGetting stocked while doing with RabbitMQ using Spring-AMQP.\n\nJust need to get a way to configure AutomaticRecoveryEnabled and NetworkRecoveryInterval using Spring-AMQP. There is a direct option to set these flages if you you developing using native RabbitMQ library. But i didn't find a workaround to do the same using spring \n\n***Using RabbitMQ Native library(don't need any help)***\n\n```\nfactory.setAutomaticRecoveryEnabled(true);\nfactory.setNetworkRecoveryInterval(10000);\n```\n\n***Using Spring-AMPQ(need help)***\n\nLike above i didn't find any such method while trying with Spring-AMPQ. This is what i am doing now.\n\n```\n@Bean(name=\"listener\")\npublic SimpleMessageListenerContainer listenerContainer() \n{\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(connectionFactory());\n container.setQueueNames(env.getProperty(\"mb.queue\"));\n container.setMessageListener(new MessageListenerAdapter(messageListener));\n return container;\n}\n```\n\nAny help in this regards is highly appreciable. Thanks in advance.\n\n========================================\n\nTop Answer:\nWell, `CachingConnectionFactory` has another costructor to apply a `com.rabbitmq.client.ConnectionFactory`.\n\nSo, it just enough to cofigure the last one as a an additional `@Bean` with appropriate options and inject it to the `CachingConnectionFactory`.\n\n========================================\n\nCode:\n```text\nfactory.setAutomaticRecoveryEnabled(true);\nfactory.setNetworkRecoveryInterval(10000);\n```\n\n```text\n@Bean(name=\"listener\")\npublic SimpleMessageListenerContainer listenerContainer() \n{\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(connectionFactory());\n container.setQueueNames(env.getProperty(\"mb.queue\"));\n container.setMessageListener(new MessageListenerAdapter(messageListener));\n return container;\n}\n```\n\n```text\nautomaticRecoveryEnabled\n```\n\n```text\nCachingConnectionFactory\n```\n\n```text\ncom.rabbitmq.client.ConnectionFactory\n```\n\n```text\n@Bean\n```\n\n```text\nCachingConnectionFactory\n```\n\n```text\nConnectionFactory factory = new ConnectionFactory();\nfactory.setAutomaticRecoveryEnabled(true);\n// connection that will recover automatically\nConnection conn = factory.newConnection();\n```\n\n========================================\n\nComments:\n- See similar question & answer here: stackoverflow.com/a/42001720/891479\n- However, this option is not needed with Spring AMQP - it has had connection recovery (on the consumer side) from day 1. You could use it on the producer side, or simply add a retry template to the `RabbitTemplate` - you might get some undesirable side-effects when using this option with the `SimpleMessageListenerContainer` because the container knows nothing about the recovered consumers.\n- Thanks Artem.I find find our another method(setRecoveryInterval(time in mills)) of SimpleMessageListenerContainer doing the same stuff. By the way default is 5 sec even though you will not use this method, that's really nice.\n- Sprint does not recommend this, they even added a warning to this constructor: \"Automatic Recovery is Enabled in the provided connection factory; while Spring AMQP is compatible with this feature, it prefers to use its own recovery mechanisms; when this option is true, you may receive 'AutoRecoverConnectionNotCurrentlyOpenException's until the connection is recovered.\"\n- Thanks for the update Gray Russell.You mean Spring internally will take care of fault tolerance and auto recovery stuff.\n- Yes, as I said in my comment to Artem's reply, we've had recovery from day 1; automatic for consumers (listener container) and using a `RetryTemplate` in the `RabbitTemplate` for publishers.\n- @GaryRussell what is the best practice right now to configure automatic recovery of a lost connection with a broker node (in a cluster of 3 nodes) and what is the best practice to retry publishing messages?\n- The asynchronous consumer (`SimpleMessageListenerContainer` will automatically keep attempting to reconnect, based on its `recoveryInterval`. For the publisher side, add a `RetryTemplate` to the `RabbitTemplate` as discussed in the reference manual.\n- hI @Gary, can you please give us an update about this issue ?\n- There is nothing to update; we now reliably co-exist if auto recovery is incorrectly set. by immediately closing the recovered connection. Spring AMQP's inbuilt recovery (which has been there since day 1) is more deterministic than the auto recovery in the amqp-client. It was too much like Whack-A-Mole to keep squashing the corner cases that kept showing up.","metadata":{"transformedAt":"2026-08-18T18:33:20.191Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":101,"estimatedTokens":1204}}799{"id":"stack-18844274","source":"stackoverflow","questionId":18844274,"title":"Tweaking celery for high performance","tags":["python","django","performance","rabbitmq","celery"],"text":"Title: Tweaking celery for high performance\nTags: python, django, performance, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI'm trying to send ~400 HTTP GET requests and collect the results.\nI'm running from django.\nMy solution was to use celery with gevent.\n\nTo start the celery tasks I call **get_reports** :\n\n```\ndef get_reports(self, clients, *args, **kw):\n sub_tasks = []\n for client in clients: \n s = self.get_report_task.s(self, client, *args, **kw).set(queue='io_bound')\n sub_tasks.append(s)\n res = celery.group(*sub_tasks)()\n reports = res.get(timeout=30, interval=0.001)\n return reports\n\n@celery.task\ndef get_report_task(self, client, *args, **kw):\n report = send_http_request(...)\n return report\n```\n\nI use 4 workers:\n\n```\nmanage celery worker -P gevent --concurrency=100 -n a0 -Q io_bound\nmanage celery worker -P gevent --concurrency=100 -n a1 -Q io_bound\nmanage celery worker -P gevent --concurrency=100 -n a2 -Q io_bound\nmanage celery worker -P gevent --concurrency=100 -n a3 -Q io_bound\n```\n\nAnd I use RabbitMq as the broker.\n\nAnd although it works much faster than running the requests sequentially (400 requests took ~23 seconds), I noticed that most of that time was overhead from celery itself, i.e. if I changed **get_report_task** like this:\n\n```\n@celery.task\ndef get_report_task(self, client, *args, **kw):\n return []\n```\n\nthis whole operation took ~19 seconds.\nThat means that **I spend 19 seconds only on sending all the tasks to celery and getting the results back**\n\nThe queuing rate of messages to rabbit mq is seems to be bound to 28 messages / sec and I think that this is my bottleneck.\n\nI'm running on a win 8 machine if that matters. \n\nsome of the things I've tried:\n\n- using redis as broker\n\n- using redis as results backend\ntweaking with those settings\n\nBROKER_POOL_LIMIT = 500\n\nCELERYD_PREFETCH_MULTIPLIER = 0\n\nCELERYD_MAX_TASKS_PER_CHILD = 100\n\nCELERY_ACKS_LATE = False\n\nCELERY_DISABLE_RATE_LIMITS = True\n\nI'm looking for any suggestions that will help speed things up.\n\n========================================\n\nTop Answer:\nAre you really running on Windows 8 without a Virtual Machine? I did the following simple test on 2 Core Macbook 8GB RAM running OS X 10.7:\n\n```\nimport celery\nfrom time import time\n\n@celery.task\ndef test_task(i):\n return i\n\ngrp = celery.group(test_task.s(i) for i in range(400))\ntic1 = time(); res = grp(); tac1 = time()\nprint 'queued in', tac1 - tic1\ntic2 = time(); vals = res.get(); tac2 = time()\nprint 'executed in', tac2 - tic2\n```\n\nI'm using Redis as broker, Postgres as a result backend and default worker with `--concurrency=4`. Guess what is the output? Here it is:\n\nqueued in 3.5009469986\n\nexecuted in 2.99818301201\n\n========================================\n\nCode:\n```text\ndef get_reports(self, clients, *args, **kw):\n sub_tasks = []\n for client in clients: \n s = self.get_report_task.s(self, client, *args, **kw).set(queue='io_bound')\n sub_tasks.append(s)\n res = celery.group(*sub_tasks)()\n reports = res.get(timeout=30, interval=0.001)\n return reports\n\n@celery.task\ndef get_report_task(self, client, *args, **kw):\n report = send_http_request(...)\n return report\n```\n\n```text\nmanage celery worker -P gevent --concurrency=100 -n a0 -Q io_bound\nmanage celery worker -P gevent --concurrency=100 -n a1 -Q io_bound\nmanage celery worker -P gevent --concurrency=100 -n a2 -Q io_bound\nmanage celery worker -P gevent --concurrency=100 -n a3 -Q io_bound\n```\n\n```text\n@celery.task\ndef get_report_task(self, client, *args, **kw):\n return []\n```\n\n```text\nfrom twisted.internet import defer\nfrom twisted.web.client import getPage\n\nimport threading\n\n\ndef get_reports(self, urls, *args, **kw):\n ct = threading.current_thread()\n\n defers = list()\n for url in urls:\n # here the Deferred is created which will fire when\n # the call is complete\n d = ct.call_async(getPage, args=[url] + args, kwargs=kw)\n # here we keep it for reference\n defers.append(d)\n\n # here we create a Deferred which will fire when all the\n # consiting Deferreds are completed\n deferred_list = defer.DeferredList(defers, consumeErrors=True)\n # here we tell the current thread to wait until we are done\n results = ct.wait_for_defer(deferred_list)\n\n # the results is a list of the form (C{bool} success flag, result)\n # below unpack it\n reports = list()\n for success, result in results:\n if success:\n reports.append(result)\n else:\n # here handle the failure, or just ignore\n pass\n\n return reports\n```\n\n```text\nfrom feat.web import httpclient\n\npool = httpclient.ConnectionPool(host, port, maximum_connections=3)\n```\n\n```text\nd = ct.call_async(pool.request, args=(method, path, headers, body))\n```\n\n```text\nimport celery\nfrom time import time\n\n@celery.task\ndef test_task(i):\n return i\n\ngrp = celery.group(test_task.s(i) for i in range(400))\ntic1 = time(); res = grp(); tac1 = time()\nprint 'queued in', tac1 - tic1\ntic2 = time(); vals = res.get(); tac2 = time()\nprint 'executed in', tac2 - tic2\n```\n\n```text\n--concurrency=4\n```\n\n========================================\n\nComments:\n- Hey! 28 messages a sec is very low as a publishing rate. I've seen celery+librabbitmq do 100.000 tasks/second using non-persistent messages on my desktop PC. Do you really only measure sending the message, or do you also measure getting the result back? The Redis reusult backend is *not optimized for RPC*. There is a new RPC result backend in the development version (to be Celery 3.1) that is better for this.\n- This looks interesting, but celery is already used in my system, so I would prefer using it. If I won't find a solution I will look into it.\n- Is there an update for this? I noticed today on a Windows 10 machine that a celery takes about 3-4 seconds to recieve a relatively simple task. On Linux this is not an issue, but for Windows the lag is bad and makes the product basically useless as the thread freezes while the task is being recieved. I guess it's good Production is Linux, but this is still aggravating.\n- @ViaTech this is most likely due to threading issues with Windows. It's much slower to spin up a thread in windows vs linux iirc.","metadata":{"transformedAt":"2026-08-18T18:33:20.191Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":203,"estimatedTokens":1559}}800{"id":"stack-44925747","source":"stackoverflow","questionId":44925747,"title":"RabbitMq refuses connection when run in docker","tags":["sockets","rabbitmq",".net-core","docker-compose"],"text":"Title: RabbitMq refuses connection when run in docker\nTags: sockets, rabbitmq, .net-core, docker-compose\nSource: Stack Overflow\n\nQuestion:\nMy docker-compose file looks like this:\n\n```\nversion: '2'\n\nservices:\n explore:\n image: explore\n build:\n context: ./Explore\n dockerfile: VsDockerfile\n environment:\n - \"ElasticUrl=http://localhost:9200\"\n - \"RabbitMq/Host=localhost\"\n - \"RabbitMq/Username=guest\"\n - \"RabbitMq/Password=guest\"\n networks:\n - localnet\n\n elasticsearch:\n image: docker.elastic.co/elasticsearch/elasticsearch:5.4.3\n container_name: elasticsearch\n environment:\n - \"ES_JAVA_OPTS=-Xms512m -Xmx512m\"\n ports:\n - 9200:9200\n volumes:\n - ./esdata:/usr//elasticsearch/data\n networks:\n - localnet\n\n rabbit:\n image: rabbitmq:3.6.7-management\n hostname: rabbit\n ports:\n - 15672:15672\n - 5672:5672\n networks:\n - localnet\n\nnetworks:\n localnet:\n external:\n name: localnet\n```\n\nIf I type http://localhost:15672 in the browser, I get the rabbitmq interface, but if I tries to connect from my Explore project like this: \n\n```\npublic SqlToRabbitProcessor(SqlToRabbitRepository sqlToRabbitRepository)\n{\n _sqlToRabbitRepository = sqlToRabbitRepository;\n\n var factory = new ConnectionFactory\n {\n HostName = Environment.GetEnvironmentVariable(\"RabbitMq/Host\"),\n UserName = Environment.GetEnvironmentVariable(\"RabbitMq/Username\"),\n Password = Environment.GetEnvironmentVariable(\"RabbitMq/Password\")\n };\n\n var rabbit = factory.CreateConnection();\n channel = rabbit.CreateModel();\n}\n```\n\nThen it breaks in the line\n\n```\nvar rabbit = factory.CreateConnection();\n```\n\nwith the error saying\n\nExtendedSocketException: Connection refused 127.0.0.1:5672\nSystem.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)\n\nConnectFailureException: Connection failed\nRabbitMQ.Client.EndpointResolverExtensions.SelectOne(IEndpointResolver resolver, Func selector)\n\nBrokerUnreachableException: None of the specified endpoints were reachable\nRabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, string clientProvidedName)\n\n========================================\n\nTop Answer:\nI had the same issue with docker-compose.\n\nI solved it by with hostname:\n\n```\nrabbit:\n hostname: rabbit\n command: sh -c \"rabbitmq-plugins enable rabbitmq_management; rabbitmq-server\"\n image: rabbitmq\n environment:\n RABBITMQ_DEFAULT_USER: admin\n RABBITMQ_DEFAULT_PASS: admin\n ports:\n - 5672:5672\n - 15672:15672\n```\n\n========================================\n\nCode:\n```text\nversion: '2'\n\nservices:\n explore:\n image: explore\n build:\n context: ./Explore\n dockerfile: VsDockerfile\n environment:\n - \"ElasticUrl=http://localhost:9200\"\n - \"RabbitMq/Host=localhost\"\n - \"RabbitMq/Username=guest\"\n - \"RabbitMq/Password=guest\"\n networks:\n - localnet\n\n elasticsearch:\n image: docker.elastic.co/elasticsearch/elasticsearch:5.4.3\n container_name: elasticsearch\n environment:\n - \"ES_JAVA_OPTS=-Xms512m -Xmx512m\"\n ports:\n - 9200:9200\n volumes:\n - ./esdata:/usr/share/elasticsearch/data\n networks:\n - localnet\n\n rabbit:\n image: rabbitmq:3.6.7-management\n hostname: rabbit\n ports:\n - 15672:15672\n - 5672:5672\n networks:\n - localnet\n\nnetworks:\n localnet:\n external:\n name: localnet\n```\n\n```text\npublic SqlToRabbitProcessor(SqlToRabbitRepository sqlToRabbitRepository)\n{\n _sqlToRabbitRepository = sqlToRabbitRepository;\n\n var factory = new ConnectionFactory\n {\n HostName = Environment.GetEnvironmentVariable(\"RabbitMq/Host\"),\n UserName = Environment.GetEnvironmentVariable(\"RabbitMq/Username\"),\n Password = Environment.GetEnvironmentVariable(\"RabbitMq/Password\")\n };\n\n var rabbit = factory.CreateConnection();\n channel = rabbit.CreateModel();\n}\n```\n\n```text\nvar rabbit = factory.CreateConnection();\n```\n\n```text\n- \"ElasticUrl=http://localhost:9200\"\n- \"RabbitMq/Host=localhost\"\n```\n\n```text\n- \"ElasticUrl=http://elasticsearch:9200\"\n- \"RabbitMq/Host=rabbit\"\n```\n\n```text\nrabbit:\n hostname: rabbit\n command: sh -c \"rabbitmq-plugins enable rabbitmq_management; rabbitmq-server\"\n image: rabbitmq\n environment:\n RABBITMQ_DEFAULT_USER: admin\n RABBITMQ_DEFAULT_PASS: admin\n ports:\n - 5672:5672\n - 15672:15672\n```\n\n```text\ndocker network create <network_name>\n```\n\n```html\nversion: \"3.1\"\nservices:\n rabbitmq-container:\n image: rabbitmq:3.5.3-management\n hostname: rabbitmq-container\n ports:\n - 5673:5673\n - 5672:5672\n - 15672:15672\n networks:\n - resolute\n\n resolute-container:\n build: .\n ports:\n - 8080:8080\n environment:\n - spring_rabbitmq_host=rabbitmq-container\n - spring_rabbitmq_port=5672\n - spring_rabbitmq_username=guest\n - spring_rabbitmq_password=guest\n - resolute_rabbitmq_publishQueueName=resolute-run-request\n - resolute_rabbitmq_exchange=resolute\n depends_on:\n - rabbitmq-container\n volumes:\n - /var/run/docker.sock:/var/run/docker.sock\n networks:\n - resolute\n\nnetworks:\n resolute:\n external:\n name: resolute\n```\n\n```text\ndocker-compose up\n```\n\n```text\nresolute\n```\n\n```text\nhostname\n```\n\n========================================\n\nComments:\n- Hmm I think the issue is that in my web container I call localhost, and that's not the Hosts localhost but the containers","metadata":{"transformedAt":"2026-08-18T18:33:20.191Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":11,"totalLines":255,"estimatedTokens":1336}}801{"id":"stack-38164855","source":"stackoverflow","questionId":38164855,"title":"What are benefits of using RabbitMQ in Erlang?","tags":["erlang","rabbitmq"],"text":"Title: What are benefits of using RabbitMQ in Erlang?\nTags: erlang, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am learning Erlang and I came from a good Python background. I used RabbitMQ with Celery in my projects. \n\nWhile Erlang has a very powerful messaging and concurrency capabilities, what are benefits of using RabbitMQ with Erlang? \nAm I missing the point? Why shouldn't I rely on native features of Erlang instead of adding another layer of complexity to my project environment?\n\n========================================\n\nComments:\n- This could evoke opinion responses, but it's a valuable question, and the first answer shows that there are solid fact-based reasons to choose one or the other.","metadata":{"transformedAt":"2026-08-18T18:33:20.191Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":14,"estimatedTokens":177}}802{"id":"stack-23240863","source":"stackoverflow","questionId":23240863,"title":"Execution of Rabbit message listener failed, and no ErrorHandler has been set. Failed to invoke target method with argument type = [class [B],","tags":["java","spring","rabbitmq","spring-amqp"],"text":"Title: Execution of Rabbit message listener failed, and no ErrorHandler has been set. Failed to invoke target method with argument type = [class [B],\nTags: java, spring, rabbitmq, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI am using spring amqp rabbitmq, and sending messages using \n\n```\nMessage message = MessageBuilder\n.withBody(item.toString().getBytes())\n.setReplyTo(\"importReply\")\n.setCorrelationId(item.toString().getBytes()).build();\n```\n\nMy message handler is\n\n```\npublic class Foundation { \n public Message importExchange(Message exchange) {\n System.out.println(\"Command:\" + exchange.getBody()); \n Message message = MessageBuilder\n .withBody(exchange.getBody().toString().getBytes()).setCorrelationId(exchange.getMessageProperties().getCorrelationId() .toString().getBytes()).build();\n\n return message; \n }\n}\n```\n\nI have hooked it using \n\n```\n\n \n \n\n```\n\nBut I am getting below execption\n\n```\nExecution of Rabbit message listener failed, and no ErrorHandler has been set.\norg.springframework.amqp.rabbit.listener.ListenerExecutionFailedException: Failed to invoke target method 'importExchange' with argument type = [class [B], value = [{[B@427829d8}]\n at org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter.invokeListenerMethod(MessageListenerAdapter.java:483)\n at org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter.onMessage(MessageListenerAdapter.java:374)\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:647)\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:573)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$001(SimpleMessageListenerContainer.java:75)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$1.invokeListener(SimpleMessageListenerContainer.java:154)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.invokeListener(SimpleMessageListenerContainer.java:1111)\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:556)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:904)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:888)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$500(SimpleMessageListenerContainer.java:75)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:989)\n at java.lang.Thread.run(Thread.java:744)\nCaused by: java.lang.NoSuchMethodException: com.stockopedia.symfony.Foundation.importExchange([B)\n at java.lang.Class.getMethod(Class.java:1665)\n at org.springframework.util.MethodInvoker.prepare(MethodInvoker.java:178)\n at org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter.invokeListenerMethod(MessageListenerAdapter.java:466)\n ... 12 more\n```\n\nand the similar issue is also on producer side replyHandler\n\n```\npublic void replyHandler(Message message) {\n System.out.println(\"In Reply Handler:\" + message.getMessageProperties().getCorrelationId());\n\n}\n```\n\nAlso, how can I get exception in replyHandler if there is any exception in importExchange ?\n\n========================================\n\nTop Answer:\nOr you can add `.setContentType=\"text/plain\"` and the converter will be able to convert to String for you.\n\n========================================\n\nCode:\n```text\nMessage message = MessageBuilder\n.withBody(item.toString().getBytes())\n.setReplyTo(\"importReply\")\n.setCorrelationId(item.toString().getBytes()).build();\n```\n\n```text\npublic class Foundation { \n public Message importExchange(Message exchange) {\n System.out.println(\"Command:\" + exchange.getBody()); \n Message message = MessageBuilder\n .withBody(exchange.getBody().toString().getBytes()).setCorrelationId(exchange.getMessageProperties().getCorrelationId() .toString().getBytes()).build();\n\n return message; \n }\n}\n```\n\n```text\n<rabbit:listener-container\n connection-factory=\"rabbitConnectionFactory\" concurrency=\"10\">\n <rabbit:listener queues=\"${rabbitmq.import.queue}\"\n ref=\"foundation\" method=\"importExchange\" />\n <rabbit:listener queues=\"${rabbitmq.import.reply.queue}\"\n ref=\"importExchangeItemWriter\" method=\"replyHandler\" />\n</rabbit:listener-container>\n```\n\n```text\nExecution of Rabbit message listener failed, and no ErrorHandler has been set.\norg.springframework.amqp.rabbit.listener.ListenerExecutionFailedException: Failed to invoke target method 'importExchange' with argument type = [class [B], value = [{[B@427829d8}]\n at org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter.invokeListenerMethod(MessageListenerAdapter.java:483)\n at org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter.onMessage(MessageListenerAdapter.java:374)\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:647)\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:573)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$001(SimpleMessageListenerContainer.java:75)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$1.invokeListener(SimpleMessageListenerContainer.java:154)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.invokeListener(SimpleMessageListenerContainer.java:1111)\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:556)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:904)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:888)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$500(SimpleMessageListenerContainer.java:75)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:989)\n at java.lang.Thread.run(Thread.java:744)\nCaused by: java.lang.NoSuchMethodException: com.stockopedia.symfony.Foundation.importExchange([B)\n at java.lang.Class.getMethod(Class.java:1665)\n at org.springframework.util.MethodInvoker.prepare(MethodInvoker.java:178)\n at org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter.invokeListenerMethod(MessageListenerAdapter.java:466)\n ... 12 more\n```\n\n```text\npublic void replyHandler(Message message) {\n System.out.println(\"In Reply Handler:\" + message.getMessageProperties().getCorrelationId());\n\n}\n```\n\n```text\nFoundation#importExchange\n```\n\n```text\nbyte[]\n```\n\n```text\nreplyHandler\n```\n\n```text\nMessageListener\n```\n\n```text\n.setContentType=\"text/plain\"\n```\n\n========================================\n\nComments:\n- Just updated importExchange, I want to send message object back to replyHandler to check correlation id\n- Yes, I saw. Just try to with my advice\n- I want to do correlation as the use case is, I want to send all messages first asynchronously without waiting for reply and then wait for replies. I would like my replyHandler to trigger with reply messages, I should know for which message I got reply.\n- You do everything correct with correlation and replies. Your issue here is around POJOs. Just make `replyHandler` as `MessageListener` and you'll receive reply messages correctly. But your `importExchange` should not get deal with `Message` objects.\n- One small question, Also, how can I get exception in replyHandler if there is any exception in importExchange ?\n- Bad thought. You are in the asynchronous messaging: the producer just sends message to the queue and it doesn't worry and doesn't know anything about the consumer. You can hanle exceptions on consumer and send them as messages to another queue.\n- yeah may be, my producer is my spring batch item writer, to notify spring batch about any failure to stop job, item writer should throw exception.\n- after queuing all messages, I am receiving reply in replyHandler, How can I keep my producer waiting after sending all messages and get notified by replyHandler upon getting all replies to release waiting ?\n- posted separete question here, stackoverflow.com/questions/23294934/…\n- yeah did same thing. Thanks","metadata":{"transformedAt":"2026-08-18T18:33:20.191Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":173,"estimatedTokens":2214}}803{"id":"stack-32380661","source":"stackoverflow","questionId":32380661,"title":"Camel not publishing to RabbitMQ queue","tags":["java","apache-camel","rabbitmq"],"text":"Title: Camel not publishing to RabbitMQ queue\nTags: java, apache-camel, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have a simple route defined in a routeContext in Camel (this route will be used in multiple routes).\n\n```\n\n \n \n \n my.routing.key\n \n \n \n```\n\nAnd I have an endpoint (defined in an endpoints file)\n\n```\n\n \n \n \n```\n\nYes - I have seen the http://camel.apache.org/rabbitmq.html page - that's where I got the idea to set the header on the exchange. However no message is being published on the queue. I'm clearly overlooking something and any help would be appreciated.\n\n========================================\n\nCode:\n```text\n<route id=\"sendToRabbitQueue\">\n <from uri=\"direct:sendToQueue\" />\n <convertBodyTo type=\"java.lang.String\"/>\n <setHeader headerName=\"rabbitmq.ROUTING_KEY\">\n <constant>my.routing.key</constant>\n </setHeader>\n <to uri=\"ref:genericRabbitEndpoint\"/>\n </route>\n```\n\n```text\n<endpoint id=\"genericRabbitEndpoint\" uri=\"rabbitmq://${rabbitmq.host}:${rabbitmq.port}/${rabbitmq.exchange.name}\">\n <camel:property key=\"autoDelete\" value=\"false\" />\n <camel:property key=\"connectionFactory\" value=\"#rabbitConnectionFactory\" />\n </endpoint>\n```\n\n```text\npublic void stripRabbitHeaders(@Headers Map headers)\n{\n headers.remove(\"rabbitmq.ROUTING_KEY\");\n headers.remove(\"rabbitmq.DELIVERY_TAG\");\n headers.remove(\"rabbitmq.EXCHANGE_NAME\");\n}\n```\n\n```text\nrabbitmq.ROUTING_KEY\n```\n\n```text\nrabbitmq.EXCHANGE_NAME\n```\n\n```text\nrabbitmq.DELIVERY_TAG\n```\n\n========================================\n\nComments:\n- Airomega - How did you setup your endpoints file?\n- BTW: you can easily remove headers from within your route with `removeHeaders(String pattern, String... excludePatterns)`","metadata":{"transformedAt":"2026-08-18T18:33:20.191Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":76,"estimatedTokens":442}}804{"id":"stack-56129216","source":"stackoverflow","questionId":56129216,"title":"How to make waiting for the completion of actions, then receive a new message?","tags":["node.js","rabbitmq","microservices","nestjs"],"text":"Title: How to make waiting for the completion of actions, then receive a new message?\nTags: node.js, rabbitmq, microservices, nestjs\nSource: Stack Overflow\n\nQuestion:\nI'm creating microservice by nestjs, transfer throw rabbitmq.\nHow to make microservice receive messages from queue in turn waiting for complete of the previous one.\n\n- main.ts\n\n```\nimport { NestFactory } from '@nestjs/core';\nimport { AppModule } from './app.module';\nimport { Transport } from '@nestjs/microservices';\n\nasync function bootstrap() {\n const app = await NestFactory.createMicroservice(AppModule, {\n transport: Transport.RMQ,\n options: {\n urls: [`amqp://localhost:5672`],\n queue: 'rmq_queue',\n queueOptions: { durable: false },\n prefetchCount: 1,\n },\n });\n\n await app.listenAsync();\n}\n\nbootstrap();\n```\n\n- app.controller.ts\n\n```\nimport { Controller, Logger } from '@nestjs/common';\nimport { EventPattern } from '@nestjs/microservices';\n\n@Controller()\nexport class AppController {\n @EventPattern('hello')\n async handleHello(): Promise {\n Logger.log('-handle-');\n await (new Promise(resolve => setTimeout(resolve, 5000)));\n Logger.log('---hello---');\n }\n}\n```\n\n- client.js\n\n```\nconst { ClientRMQ } = require('@nestjs/microservices');\n\n(async () => {\n const client = new ClientRMQ({\n urls: ['amqp://localhost:5672'],\n queue: 'rmq_queue',\n queueOptions: { durable: false },\n });\n\n await client.connect();\n\n for (let i = 0; i https://github.com/heySasha/nest-rmq\n\nActual output:\n\n```\n[Nest] 9560 - 05/14/2019, 1:53 PM -handle- +2ms\n[Nest] 9560 - 05/14/2019, 1:53 PM -handle- +9ms\n[Nest] 9560 - 05/14/2019, 1:53 PM -handle- +12ms\n[Nest] 9560 - 05/14/2019, 1:54 PM ---hello--- +4967ms\n[Nest] 9560 - 05/14/2019, 1:54 PM ---hello--- +2ms\n[Nest] 9560 - 05/14/2019, 1:54 PM ---hello--- +1ms\n```\n\nBut i expect:\n\n```\n[Nest] 9560 - 05/14/2019, 1:53 PM -handle- +2ms\n[Nest] 9560 - 05/14/2019, 1:54 PM ---hello--- +5067ms\n[Nest] 9560 - 05/14/2019, 1:53 PM -handle- +2ms\n[Nest] 9560 - 05/14/2019, 1:54 PM ---hello--- +5067ms\n[Nest] 9560 - 05/14/2019, 1:53 PM -handle- +2ms\n[Nest] 9560 - 05/14/2019, 1:54 PM ---hello--- +5067ms\n```\n\n========================================\n\nTop Answer:\nWhat you want to have is usually accomplished with consumer acknowledgments. You can read about them here. In short, your consumer (in your case Nest.js microservice), that has prefetch count set to 1, will receive a new message only after it acknowledges a previous one. If you are familiar with AWS SQS, this operation is similar to deleting message from the queue.\n\nNest.js uses amqplib under the hood for communicating with RabbitMQ. Consumer acknowledgment policy is established during channel creation - you can see there's a `noAck` option. However, the channel is created with `noAck` set to `true` - you can check it here, which means that it's the listener who automatically acknowledges messages when they are passed to your `@EventHandler` method. You can verify that with RabbitMQ management plugin, that provides handy UI and ability to check non acked messages in flight.\n\nI failed to find any useful info about that both in Nest.js sources and docs. But this might give you a hint.\n\n========================================\n\nCode:\n```text\nimport { NestFactory } from '@nestjs/core';\nimport { AppModule } from './app.module';\nimport { Transport } from '@nestjs/microservices';\n\nasync function bootstrap() {\n const app = await NestFactory.createMicroservice(AppModule, {\n transport: Transport.RMQ,\n options: {\n urls: [`amqp://localhost:5672`],\n queue: 'rmq_queue',\n queueOptions: { durable: false },\n prefetchCount: 1,\n },\n });\n\n await app.listenAsync();\n}\n\nbootstrap();\n```\n\n```text\nimport { Controller, Logger } from '@nestjs/common';\nimport { EventPattern } from '@nestjs/microservices';\n\n@Controller()\nexport class AppController {\n @EventPattern('hello')\n async handleHello(): Promise<void> {\n Logger.log('-handle-');\n await (new Promise(resolve => setTimeout(resolve, 5000)));\n Logger.log('---hello---');\n }\n}\n```\n\n```text\nconst { ClientRMQ } = require('@nestjs/microservices');\n\n(async () => {\n const client = new ClientRMQ({\n urls: ['amqp://localhost:5672'],\n queue: 'rmq_queue',\n queueOptions: { durable: false },\n });\n\n await client.connect();\n\n for (let i = 0; i < 3; i++) {\n client.emit('hello', 0).subscribe();\n }\n})();\n```\n\n```text\n[Nest] 9560 - 05/14/2019, 1:53 PM -handle- +2ms\n[Nest] 9560 - 05/14/2019, 1:53 PM -handle- +9ms\n[Nest] 9560 - 05/14/2019, 1:53 PM -handle- +12ms\n[Nest] 9560 - 05/14/2019, 1:54 PM ---hello--- +4967ms\n[Nest] 9560 - 05/14/2019, 1:54 PM ---hello--- +2ms\n[Nest] 9560 - 05/14/2019, 1:54 PM ---hello--- +1ms\n```\n\n```text\n[Nest] 9560 - 05/14/2019, 1:53 PM -handle- +2ms\n[Nest] 9560 - 05/14/2019, 1:54 PM ---hello--- +5067ms\n[Nest] 9560 - 05/14/2019, 1:53 PM -handle- +2ms\n[Nest] 9560 - 05/14/2019, 1:54 PM ---hello--- +5067ms\n[Nest] 9560 - 05/14/2019, 1:53 PM -handle- +2ms\n[Nest] 9560 - 05/14/2019, 1:54 PM ---hello--- +5067ms\n```\n\n```text\nimport { isString, isUndefined } from '@nestjs/common/utils/shared.utils';\nimport { Observable } from 'rxjs';\nimport { CustomTransportStrategy, RmqOptions, Server } from '@nestjs/microservices';\nimport {\n CONNECT_EVENT, DISCONNECT_EVENT, DISCONNECTED_RMQ_MESSAGE, NO_MESSAGE_HANDLER,\n RQM_DEFAULT_IS_GLOBAL_PREFETCH_COUNT,\n RQM_DEFAULT_PREFETCH_COUNT,\n RQM_DEFAULT_QUEUE, RQM_DEFAULT_QUEUE_OPTIONS,\n RQM_DEFAULT_URL,\n} from '@nestjs/microservices/constants';\n\nlet rqmPackage: any = {};\n\nexport class ServerRMQ extends Server implements CustomTransportStrategy {\n private server: any = null;\n private channel: any = null;\n private readonly urls: string[];\n private readonly queue: string;\n private readonly prefetchCount: number;\n private readonly queueOptions: any;\n private readonly isGlobalPrefetchCount: boolean;\n\n constructor(private readonly options: RmqOptions['options']) {\n super();\n this.urls = this.getOptionsProp(this.options, 'urls') || [RQM_DEFAULT_URL];\n this.queue =\n this.getOptionsProp(this.options, 'queue') || RQM_DEFAULT_QUEUE;\n this.prefetchCount =\n this.getOptionsProp(this.options, 'prefetchCount') ||\n RQM_DEFAULT_PREFETCH_COUNT;\n this.isGlobalPrefetchCount =\n this.getOptionsProp(this.options, 'isGlobalPrefetchCount') ||\n RQM_DEFAULT_IS_GLOBAL_PREFETCH_COUNT;\n this.queueOptions =\n this.getOptionsProp(this.options, 'queueOptions') ||\n RQM_DEFAULT_QUEUE_OPTIONS;\n\n this.loadPackage('amqplib', ServerRMQ.name, () => require('amqplib'));\n rqmPackage = this.loadPackage(\n 'amqp-connection-manager',\n ServerRMQ.name,\n () => require('amqp-connection-manager'),\n );\n }\n\n public async listen(callback: () => void): Promise<void> {\n await this.start(callback);\n }\n\n public close(): void {\n if (this.channel) {\n this.channel.close();\n }\n\n if (this.server) {\n this.server.close();\n }\n }\n\n public async start(callback?: () => void) {\n this.server = this.createClient();\n this.server.on(CONNECT_EVENT, (_: any) => {\n this.channel = this.server.createChannel({\n json: false,\n setup: (channel: any) => this.setupChannel(channel, callback),\n });\n });\n this.server.on(DISCONNECT_EVENT, (err: any) => {\n this.logger.error(DISCONNECTED_RMQ_MESSAGE);\n });\n }\n\n public createClient<T = any>(): T {\n const socketOptions = this.getOptionsProp(this.options, 'socketOptions');\n return rqmPackage.connect(this.urls, socketOptions);\n }\n\n public async setupChannel(channel: any, callback: () => void) {\n await channel.assertQueue(this.queue, this.queueOptions);\n await channel.prefetch(this.prefetchCount, this.isGlobalPrefetchCount);\n channel.consume(\n this.queue,\n (msg: any) => this.handleMessage(msg)\n .then(() => this.channel.ack(msg)) // Ack message after complete\n .catch(err => {\n // error handling\n this.logger.error(err);\n return this.channel.ack(msg);\n }),\n { noAck: false },\n );\n callback();\n }\n\n public async handleMessage(message: any): Promise<void> {\n const { content, properties } = message;\n const packet = JSON.parse(content.toString());\n const pattern = isString(packet.pattern)\n ? packet.pattern\n : JSON.stringify(packet.pattern);\n\n if (isUndefined(packet.id)) {\n return this.handleEvent(pattern, packet);\n }\n\n const handler = this.getHandlerByPattern(pattern);\n\n if (!handler) {\n const status = 'error';\n\n return this.sendMessage(\n { status, err: NO_MESSAGE_HANDLER },\n properties.replyTo,\n properties.correlationId,\n );\n }\n\n const response$ = this.transformToObservable(\n await handler(packet.data),\n ) as Observable<any>;\n\n const publish = <T>(data: T) =>\n this.sendMessage(data, properties.replyTo, properties.correlationId);\n\n if (response$) {\n this.send(response$, publish);\n }\n\n }\n\n public sendMessage<T = any>(\n message: T,\n replyTo: any,\n correlationId: string,\n ): void {\n const buffer = Buffer.from(JSON.stringify(message));\n this.channel.sendToQueue(replyTo, buffer, { correlationId });\n }\n}\n```\n\n```text\nServerRMQ\n```\n\n```text\nsetupChannel()\n```\n\n```text\nnoAck: false\n```\n\n```text\nthis.handleMessage(msg)\n```\n\n```text\nthis.channel.ack(msg)\n```\n\n```text\nnoAck\n```\n\n```text\nnoAck\n```\n\n```text\ntrue\n```\n\n```text\n@EventHandler\n```\n\n```text\nimport { NestFactory } from '@nestjs/core';\nimport { AppModule } from './app.module';\nimport { Transport } from '@nestjs/microservices';\n\nasync function bootstrap() {\n const app = await NestFactory.createMicroservice(AppModule, {\n transport: Transport.RMQ,\n options: {\n urls: [`amqp://localhost:5672`],\n queue: 'rmq_queue',\n queueOptions: { durable: false },\n noAck: false,\n prefetchCount: 1,\n },\n });\n\n await app.listenAsync();\n}\n\nbootstrap();\n```\n\n```text\nimport { Controller, Logger } from '@nestjs/common';\nimport { Ctx, EventPattern, RmqContext } from '@nestjs/microservices';\n\n@Controller()\nexport class AppController {\n @EventPattern('hello')\n async handleHello(@Ctx() context: RmqContext): Promise<void> {\n Logger.log('-handle-');\n await (new Promise(resolve => setTimeout(resolve, 5000)));\n Logger.log('---hello---');\n\n const channel = context.getChannelRef();\n const originalMsg = context.getMessage();\n channel.ack(originalMsg);\n }\n}\n```\n\n```text\nnoAck: false\n```\n\n```text\ncontext\n```\n\n```text\nack\n```\n\n========================================\n\nComments:\n- Do you want to achieve a synchronous call to that endpoint?\n- Thank you! I think, that need to create Custom Transport, docs.nestjs.com/microservices/custom-transport.\n- @AleksandrYatsenko sounds like a solution. I'm gonna be a bit selfish and leave a link here to my npm package, that can actually be very useful in your case. If you find that it fits your needs, enjoy: npmjs.com/package/nabbitmq\n- i think channel.ack should be before setimeout or any other action , so rabbitMQ no that someone handling this message","metadata":{"transformedAt":"2026-08-18T18:33:20.191Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":20,"totalLines":411,"estimatedTokens":2909}}805{"id":"stack-61923962","source":"stackoverflow","questionId":61923962,"title":"RabbitMQ Consumer : AlreadyClosedException","tags":[".net-core","rabbitmq","consumer"],"text":"Title: RabbitMQ Consumer : AlreadyClosedException\nTags: .net-core, rabbitmq, consumer\nSource: Stack Overflow\n\nQuestion:\nI have a simple RabbitMQ publisher and consumer code listed below. \n\nFirst, I created 10 count of different message in My_Tasks queue. When I try to get these message, one by one and with autoAck flag as false, I can read the first message, but acknowledge could not be sent to the RabbitMQ server. I get an error written below;\n\nPublisher;\n\n```\nvar qName = \"My_Tasks\";\nusing (var connection = factory.CreateConnection())\n{\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(qName, durable: true, false, false, null);\n\n var body = Encoding.UTF8.GetBytes(message);\n\n var prop = channel.CreateBasicProperties();\n prop.Persistent = true;\n\n channel.BasicPublish(\"\", routingKey: qName, prop, body);\n }\n}\n```\n\nConsumer;\n\n```\nvar qName = \"My_Tasks\";\nusing (var connection = factory.CreateConnection())\n{\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(qName, durable: true, false, false, null);\n channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false);\n\n var consumer = new EventingBasicConsumer(channel);\n channel.BasicConsume(qName, autoAck: false, consumer);\n\n consumer.Received += (model, ea) =>\n {\n var message = Encoding.UTF8.GetString(ea.Body.ToArray());\n channel.BasicAck(ea.DeliveryTag, multiple: false);\n };\n }\n}\n```\n\n**RabbitMQ.Client.Exceptions.AlreadyClosedException: 'Already closed: The AMQP operation was interrupted: AMQP close-reason, initiated by Application, code=200, text='Goodbye', classId=0, methodId=0'**\n\nat RabbitMQ.Client.Impl.SessionBase.Transmit(Command cmd)\n at RabbitMQ.Client.Impl.ModelBase.ModelSend(MethodBase method, ContentHeaderBase header, ReadOnlyMemory 1 body)\n at RabbitMQ.Client.Framing.Impl.Model.BasicAck(UInt64 deliveryTag, Boolean multiple)\n at RabbitMQ.Client.Impl.RecoveryAwareModel.BasicAck(UInt64 deliveryTag, Boolean multiple)\n at RabbitMQ.Client.Impl.AutorecoveringModel.BasicAck(UInt64 deliveryTag, Boolean multiple)\n at QueueExample.Consumer.Program.<>c__DisplayClass0_0.b__0(Object model, BasicDeliverEventArgs ea) in D:\\Projects\\RabbitMQTutorial\\QueueExample\\QueueExample.Consumer\\Program.cs:line 36\n at RabbitMQ.Client.Events.EventingBasicConsumer.HandleBasicDeliver(String consumerTag, UInt64 deliveryTag, Boolean redelivered, String exchange, String routingKey, IBasicProperties properties, ReadOnlyMemory`1 body)\n at RabbitMQ.Client.Impl.ConcurrentConsumerDispatcher.<>c__DisplayClass10_0.b__0()\n\nThanks for your help\n\n========================================\n\nTop Answer:\n*This should be a comment, but I am missing reputation.*\n\nWas your solution already working? Where do you define your connection to the broker? Are you using the broker in a docker-compose configuration? In this case, your broker must connect to \n\n```\nrabbitmq://host.docker.internal\n```\n\nWhen I started working with RabbitMQ in .Net Core I experienced the same issues.\nAs my application (microservice pattern) was in an early stage I switched to MassTransit framework which handles everything. I can highly recommend it, since it \"just works\" and you can fully focus on your desired system functionality.\n\n========================================\n\nCode:\n```text\nvar qName = \"My_Tasks\";\nusing (var connection = factory.CreateConnection())\n{\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(qName, durable: true, false, false, null);\n\n var body = Encoding.UTF8.GetBytes(message);\n\n var prop = channel.CreateBasicProperties();\n prop.Persistent = true;\n\n channel.BasicPublish(\"\", routingKey: qName, prop, body);\n }\n}\n```\n\n```text\nvar qName = \"My_Tasks\";\nusing (var connection = factory.CreateConnection())\n{\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(qName, durable: true, false, false, null);\n channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false);\n\n var consumer = new EventingBasicConsumer(channel);\n channel.BasicConsume(qName, autoAck: false, consumer);\n\n consumer.Received += (model, ea) =>\n {\n var message = Encoding.UTF8.GetString(ea.Body.ToArray());\n channel.BasicAck(ea.DeliveryTag, multiple: false);\n };\n }\n}\n```\n\n```text\nvar qName = \"My_Tasks\";\nusing (var connection = factory.CreateConnection())\n{\n using (var channel = connection.CreateModel())\n {\n channel.QueueDeclare(qName, durable: true, false, false, null);\n channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false);\n\n var consumer = new EventingBasicConsumer(channel);\n channel.BasicConsume(qName, autoAck: false, consumer);\n\n consumer.Received += (model, ea) =>\n {\n var message = Encoding.UTF8.GetString(ea.Body.ToArray());\n channel.BasicAck(ea.DeliveryTag, multiple: false);\n };\n\n //Solution is here\n Console.WriteLine(\"Press Any Key to Continue..\");\n Console.ReadLine();\n }\n}\n```\n\n```text\nrabbitmq://host.docker.internal\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.191Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":149,"estimatedTokens":1276}}806{"id":"stack-57378832","source":"stackoverflow","questionId":57378832,"title":"Best Practice for Batch Processing with RabbitMQ","tags":["python-3.x","rabbitmq","etl"],"text":"Title: Best Practice for Batch Processing with RabbitMQ\nTags: python-3.x, rabbitmq, etl\nSource: Stack Overflow\n\nQuestion:\nI'm looking for the best way to preform ETL using Python.\n\nI'm having a channel in RabbitMQ which send events (can be even every second). \nI want to process every 1000 of them.\nThe main problem is that RabbitMQ interface (I'm using pika) raise callback upon every message.\nI looked at Celery framework, however the batch feature was depreciated in version 3.\n\nWhat is the best way to do it? I thinking about saving my events in a list, and when it reaches 1000 to copy it to other list and preform my processing. However, how do I make it thread-safe? I don't want to lose events, and I'm afraid of losing events while synchronising the list.\n\nIt sounds like a very simple use-case, however I didn't find any good best practice for it.\n\n========================================\n\nTop Answer:\nFirst of all, you should not \"batch\" messages from RabbitMQ unless you really have to. The most efficient way to work with messaging is to process each message independently. \n\nIf you **need** to combine messages in a batch, I would use a separate data store to temporarily store the messages, and then process them when they reach a certain condition. Each time you add an item to the batch, you check that condition (for example, you reached 1000 messages) and trigger the processing of the batch. \n\nThis is better than keeping a list in memory, because if your service dies, the messages will still be persisted in the database. \n\nNote : If you have a single processor per queue, this can work without any synchronization mechanism. If you have multiple processors, you will need to implement some sort of locking mechanism.\n\n========================================\n\nCode:\n```text\nprefetch-count=1000\n```\n\n```text\nunack\n```\n\n```text\nACK\n```\n\n```text\nACK\n```\n\n```text\nACK\n```\n\n```text\nclass RabbitMQBatchConsumer():\ndef __init__(self, USERNAME, PASSWORD, HOST, BATCH_SIZE, QUEUE):\n credentials = pika.PlainCredentials(USERNAME, PASSWORD)\n parameters = pika.ConnectionParameters(HOST, 5672, '/', credentials)\n self.connection = pika.BlockingConnection(parameters)\n self.channel = self.connection.channel()\n self.messages= []\n self.batch_size= BATCH_SIZE\n self.queue = QUEUE\n \ndef start_consuming(self):\n self.channel.basic_consume(queue=self.queue, on_message_callback=self.on_message)\n self.channel.start_consuming()\n \ndef on_message(self, unused_channel, basic_deliver, properties, body):\n self.messages.append((basic_deliver, properties, body))\n if len(self.messages) == self.batch_size:\n self.process()\n \ndef process(self):\n # IMPLEMENT YOUR PROCESS HERE WITH self.messages\n try:\n for i in range(len(self.messages)):\n msg = self.messages.pop()\n self.channel.basic_ack(msg[0].delivery_tag)\n except Exception as e:\n print(e)\n```\n\n```text\nbatch_consumer = RabbitMQBatchConsumer(USERNAME, PASSWORD, HOST, BATCH_SIZE, QUEUE)\nbatch_consumer.start_consuming()\n```\n\n```text\nstart_consuming\n```\n\n========================================\n\nComments:\n- I find it a bad Design to do it like that! It doesn't seem efficient. why you design it like that ? couldn't you use Multithreading and get a subscriber to subscribe for an event in an independant thread an process every event ?\n- Here is the use case: I'm calculating aggregations on the events and save the data to database. So It's much faster to aggregate 1000 events in python runtime and then just update the database, other then 1000 times update the database (and it will be multiple updates).\n- you can listen to all the evetns and when you reach 1000 you give it to a handler to store them in db, you can use multithreading\n- This approach will need some kind of timeout where you are collecting messages. Without it you can stuck for arbitrary amount of time with unprocessed messages while wait for exactly 1000 of them\n- Yes, you would need to use the inactivity_timeout when calling consume.\n- There are many use cases in which batch processing can be useful. in data science for instance there is a huge performance gain to make predictions in batch.\n- Why is it better to use a separate data store to temporarily store the messages, compared to using rabbit as \"data store\" by processing in batches?\n- Robycool how does one manage batch processing?\n- This approach will need some kind of timeout where you are collecting messages. Without it you can stuck for arbitrary amount of time with unprocessed messages while wait for `len(self.messages)` to reach `self.batch_size`","metadata":{"transformedAt":"2026-08-18T18:33:20.192Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":101,"estimatedTokens":1162}}807{"id":"stack-27108899","source":"stackoverflow","questionId":27108899,"title":"Restoring backed up queued messages in RabbitMQ not working","tags":["rabbitmq"],"text":"Title: Restoring backed up queued messages in RabbitMQ not working\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nAccording to the following posts: \n\nhttp://rabbitmq.1065348.n5.nabble.com/RabbitMQ-Backup-td18268.html\n\nhttp://rabbitmq.1065348.n5.nabble.com/rabbitmq-server-Mnesia-backup-and-restore-td28598.html\n\nIt is possible to backup then restore durable queued messages by performing the following steps:\n\nTo **back up** we have to: \n\n 1- **stop** the rabbitmq server: \n `# rabbitmqctl stop_app`\n\n \n 2- **copy (tar)** the folder \"/var/lib/rabbitmq/mnesia/\":\n `# tar -cvf mnesia.tar /var/lib/rabbitmq/mnesia/`\n\n \n 3- **start** the rabbitmq server:\n `# rabbitmqctl start_app`\n\nThen to **restore** them we have to: \n\n 1- **stop** the rabbitmq server:\n `# rabbitmqctl stop_app`\n\n \n 2- **copy back (untar)** the folder \"/var/lib/rabbitmq/mnesia/\":\n `# tar -xvf mnesia.tar -C /`\n\n \n 3- **start** the rabbitmq server: \n `# rabbitmqctl start_app`\n\n**But when trying to apply those steps on a rabbitmq cluster or even on a single node, could not restore any message.**\n\nHave also noticed that the content of: \n**/var/lib/rabbitmq/mnesia/rabbit@rabbitmq-node1/msg_store_transient** \nwhere seems to be stored the queued messages, \n**is always cleaned just after rabbitmq server is restarted** (stop_app and start_app). \nThen have tried to copy the backed up tar, after starting rabbitmq, to not get the folder /msg_store_transient cleaned, \nbut this didn’t help either (IOW no sign of restored messages in the web management console). \n\nWe are performing our tests on virtual machines with: \nUbuntu-14.04, \nErlang-R16B03, \nRabbitMQ-3.4.1,\nand with **durable queues** created by a java client.\n\nWill appreciate any help or tip to properly restore queued message especially after a rabbitmq server failure.\n\n========================================\n\nCode:\n```text\n# rabbitmqctl stop_app\n```\n\n```text\n# tar -cvf mnesia.tar /var/lib/rabbitmq/mnesia/\n```\n\n```text\n# rabbitmqctl start_app\n```\n\n```text\n# rabbitmqctl stop_app\n```\n\n```text\n# tar -xvf mnesia.tar -C /\n```\n\n```text\n# rabbitmqctl start_app\n```\n\n```text\nAMQP.BasicProperties basicProperties = new AMQP.BasicProperties().builder().deliveryMode(2).build();\n\nChannel channel = initializeChannel(...);\n\nchannel.basicPublish(exchange, rootinKey, basicProperties, message body in bytes);\n```\n\n```text\n/var/lib/rabbitmq/mnesia/rabbit@rabbitmq-node1/msg_store_persistent\n```\n\n```text\n/var/lib/rabbitmq/mnesia/rabbit@rabbitmq-node1/msg_store_transient\n```\n\n```text\n\\# /etc/init.d/rabbitmq-server restart\n```\n\n========================================\n\nComments:\n- This works on version 3.7.3. I had to set permissions on the files after copying since they were coming from a Windows box. chown -R rabbitmq:rabbitmq /var/lib/rabbitmq chmod -R 777 /var/lib/rabbitmq/mnesia","metadata":{"transformedAt":"2026-08-18T18:33:20.192Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":10,"totalLines":107,"estimatedTokens":703}}808{"id":"stack-64531521","source":"stackoverflow","questionId":64531521,"title":"celery worker only imports tasks when not detached","tags":["django","rabbitmq","celery","django-celery"],"text":"Title: celery worker only imports tasks when not detached\nTags: django, rabbitmq, celery, django-celery\nSource: Stack Overflow\n\nQuestion:\nI'm trying to get my django app to submit tasks to a celery worker and it's succeeding when the worker is run attached. As soon as I add the --detach the tasks are failing to be registered.\n\n```\n[2020-10-26 04:09:33,159: ERROR/MainProcess] Received unregistered task of type 'devapp.tasks.create_random_files'.\nThe message has been ignored and discarded.\n\nDid you remember to import the module containing this task?\nOr maybe you're using relative imports?\n\nPlease see\nhttp://docs.celeryq.org/en/latest/internals/protocol.html\nfor more information.\n\nThe full contents of the message body was:\n'[[20, \"blah\", 5120], {}, {\"callbacks\": null, \"errbacks\": null, \"chain\": null, \"chord\": null}]' (93b)\nTraceback (most recent call last):\n File \"/pysite/project/venv/lib/python3.6/site-packages/celery/worker/consumer/consumer.py\", line 562, in on_task_received\n strategy = strategies[type_]\nKeyError: 'devapp.tasks.create_random_files'\n```\n\nIn my tasks.py I have\n\n```\nimport os\nimport string\nimport subprocess\nfrom celery import shared_task, task\n\n@shared_task(name='devapp.tasks.create_random_files')\ndef create_random_files(total,filename,size):\n for i in range(int(total)):\n filenum = str(i).zfill(5)\n rnd_filename = '/brdis/{}-{}'.format(filenum,filename)\n with open(rnd_filename, 'wb') as f:\n f.write(os.urandom(size))\n f.close\n return '{} random files created'.format(total)\n```\n\nand in my views.py I have\n\n```\nfrom django.shortcuts import render\nfrom django.http import HttpResponse\n\nfrom django.contrib import messages\nfrom django.views.generic import TemplateView\nfrom django.views.generic.list import ListView\nfrom django.views.generic.edit import FormView\nfrom django.shortcuts import redirect\n\nfrom .forms import CreateRandomFilesForm, GetFileListForm, ClamScanFileForm\nfrom .tasks import create_random_files, clamscanfile\n\nclass ClamScanFileView(FormView):\n template_name = 'devapp/clamscan_file.html'\n form_class = ClamScanFileForm\n\n def form_valid(self, form):\n filename = form.cleaned_data.get('filename')\n clamscanfile.delay(filename)\n messages.success(self.request, 'We are scanning your file!s Wait a moment and refresh this page.')\n return redirect('files_list')\n```\n\nI understand that it may be relative imports(something else i need to get my head round) but I don't understand why adding the --detach to the celery worker command produces this error:\n\n`celery -A project worker -E --loglevel=INFO --logfile=/var/log/celery/celeryd.log --pidfile=/var/run/celery/celeryd.pid`\n\nworks fine but...\n\n`celery -A project worker -E --loglevel=INFO --logfile=/var/log/celery/celeryd.log --pidfile=/var/run/celery/celeryd.pid --detach`\n\nstarts the worker but doesn't register the tasks?\n\nAny help appreciated.\n\nFWIW\n\n```\ncelery report\n\nsoftware -> celery:4.4.7 (cliffs) kombu:4.6.11 py:3.6.8\n billiard:3.6.3.0 py-amqp:2.6.1\nplatform -> system:Linux arch:64bit, ELF\n kernel version:3.10.0-1127.19.1.el7.x86_64 imp:CPython\nloader -> celery.loaders.default.Loader\nsettings -> transport:amqp results:disabled\n```\n\n========================================\n\nCode:\n```text\n[2020-10-26 04:09:33,159: ERROR/MainProcess] Received unregistered task of type 'devapp.tasks.create_random_files'.\nThe message has been ignored and discarded.\n\nDid you remember to import the module containing this task?\nOr maybe you're using relative imports?\n\nPlease see\nhttp://docs.celeryq.org/en/latest/internals/protocol.html\nfor more information.\n\nThe full contents of the message body was:\n'[[20, \"blah\", 5120], {}, {\"callbacks\": null, \"errbacks\": null, \"chain\": null, \"chord\": null}]' (93b)\nTraceback (most recent call last):\n File \"/pysite/project/venv/lib/python3.6/site-packages/celery/worker/consumer/consumer.py\", line 562, in on_task_received\n strategy = strategies[type_]\nKeyError: 'devapp.tasks.create_random_files'\n```\n\n```text\nimport os\nimport string\nimport subprocess\nfrom celery import shared_task, task\n\n@shared_task(name='devapp.tasks.create_random_files')\ndef create_random_files(total,filename,size):\n for i in range(int(total)):\n filenum = str(i).zfill(5)\n rnd_filename = '/brdis/{}-{}'.format(filenum,filename)\n with open(rnd_filename, 'wb') as f:\n f.write(os.urandom(size))\n f.close\n return '{} random files created'.format(total)\n```\n\n```text\nfrom django.shortcuts import render\nfrom django.http import HttpResponse\n\nfrom django.contrib import messages\nfrom django.views.generic import TemplateView\nfrom django.views.generic.list import ListView\nfrom django.views.generic.edit import FormView\nfrom django.shortcuts import redirect\n\nfrom .forms import CreateRandomFilesForm, GetFileListForm, ClamScanFileForm\nfrom .tasks import create_random_files, clamscanfile\n\nclass ClamScanFileView(FormView):\n template_name = 'devapp/clamscan_file.html'\n form_class = ClamScanFileForm\n\n def form_valid(self, form):\n filename = form.cleaned_data.get('filename')\n clamscanfile.delay(filename)\n messages.success(self.request, 'We are scanning your file!s Wait a moment and refresh this page.')\n return redirect('files_list')\n```\n\n```text\ncelery report\n\nsoftware -> celery:4.4.7 (cliffs) kombu:4.6.11 py:3.6.8\n billiard:3.6.3.0 py-amqp:2.6.1\nplatform -> system:Linux arch:64bit, ELF\n kernel version:3.10.0-1127.19.1.el7.x86_64 imp:CPython\nloader -> celery.loaders.default.Loader\nsettings -> transport:amqp results:disabled\n```\n\n```text\ncelery -A project worker -E --loglevel=INFO --logfile=/var/log/celery/celeryd.log --pidfile=/var/run/celery/celeryd.pid\n```\n\n```text\ncelery -A project worker -E --loglevel=INFO --logfile=/var/log/celery/celeryd.log --pidfile=/var/run/celery/celeryd.pid --detach\n```\n\n========================================\n\nComments:\n- Did you get anywhere with this? Experiencing same problem with --detach or multi\n- worker will respond to \"inspect\" commands, which means its connected to the same backend, so it does get hold of the correct configuration...\n- Tried installing the app package globally, but still same behaviour. out of ideas now.\n- Thanks @Giannis, that makes sense. Did that work for you?\n- I have upgraded to 5.0.2, but tested with 4.4.6 and it works as well.\n- I'm Sorry for the delayed(very) response. Been away from this project for a while. Still not able to update at the moment due to conflicts with django-celery-results and flower. I may have to drop flower...","metadata":{"transformedAt":"2026-08-18T18:33:20.192Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":187,"estimatedTokens":1636}}809{"id":"stack-28584398","source":"stackoverflow","questionId":28584398,"title":"RabbitMQ LDAP authentication failing","tags":["ldap","rabbitmq","ldap-query","easynetq"],"text":"Title: RabbitMQ LDAP authentication failing\nTags: ldap, rabbitmq, ldap-query, easynetq\nSource: Stack Overflow\n\nQuestion:\nI'm going through the process of setting up RabbitMQ with LDAP authorization but am not having much luck... Could someone in the know, please take a look and tell me what I'm doing wrong? I'm able to query LDAP to get the user object with the following code:\n\n```\nvar entry = new DirectoryEntry(\"LDAP://ourldapbox.ourcompany.co.uk:636/CN=Mark Twain,OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk\");\n```\n\n**Config Attempt 1**\n\n```\n[\n {rabbit, [{auth_backends, [rabbit_auth_backend_ldap, rabbit_auth_backend_internal]}]},\n {rabbitmq_auth_backend_ldap,\n [ {servers, [\"ourldapbox.ourcompany.co.uk\"]},\n {user_dn_pattern, \"CN=${username},OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk\"},\n {use_ssl, false},\n {port, 636},\n {log, true}\n ]\n }\n].\n```\n\n**Config Attempt 2**\n\n```\n[\n {rabbit, [{auth_backends, [rabbit_auth_backend_ldap, rabbit_auth_backend_internal]}]},\n {rabbitmq_auth_backend_ldap,\n [ {servers, [\"ourldapbox.ourcompany.co.uk\"]},\n {dn_lookup_attribute, \"sAMAccountName\"},\n {dn_lookup_base, \"DC=ourcompany,DC=co,DC=uk\"},\n {user_dn_pattern, \"${username}@ourcompany.co.uk\"},\n {other_bind, anon},\n {use_ssl, false},\n {port, 636},\n {log, true}\n ]\n }\n].\n```\n\n**Config Attempt 3**\n\n```\n[\n {rabbit, [{auth_backends, [rabbit_auth_backend_ldap, rabbit_auth_backend_internal]}]},\n {rabbitmq_auth_backend_ldap,\n [ {servers, [\"ourldapbox.ourcompany.co.uk\"]},\n {dn_lookup_attribute, \"userPrincipalName\"},\n {dn_lookup_base, \"dc=ourcompany,dc=co,dc=uk\"},\n {user_dn_pattern, \"${username}@ourcompany.co.uk\"},\n {use_ssl, false},\n {port, 636},\n {log, true}\n ]\n }\n].\n```\n\n**Connection Code**\n\nI'm attempting to connect in a number of ways (all failing):\n\n```\nvar connectionFactory = new ConnectionFactory\n{\n HostName = \"localhost\",\n UserName = \"twainm\",\n Password = \"fred123\",\n};\n\nusing (connectionFactory.CreateConnection())\n{\n // fails with:\n // None of the specified endpoints were reachable\n // ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.\n}\n```\n\nThe internal database fallback configuration is working, so `guest` is able to connect without issue.\n\n**Logs**\n\n```\n=INFO REPORT==== 18-Feb-2015::10:38:13 ===\naccepting AMQP connection ([::1]:20117 -> [::1]:5672)\n\n=INFO REPORT==== 18-Feb-2015::10:38:13 ===\nLDAP CHECK: login for Mark Twain\n\n=INFO REPORT==== 18-Feb-2015::10:38:13 ===\n LDAP filling template \"CN=${username},OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk\" with\n [{username,>}]\n\n=INFO REPORT==== 18-Feb-2015::10:38:13 ===\n LDAP template result: \"CN=Mark Twain,OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk\"\n\n=INFO REPORT==== 18-Feb-2015::10:38:13 ===\nLDAP CHECK: login for Mark Twain\n\n=INFO REPORT==== 18-Feb-2015::10:38:13 ===\n LDAP filling template \"CN=${username},OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk\" with\n [{username,>}]\n\n=INFO REPORT==== 18-Feb-2015::10:38:13 ===\n LDAP template result: \"CN=Mark Twain,OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk\"\n\n=INFO REPORT==== 18-Feb-2015::10:38:13 ===\n LDAP bind error: CN=Mark Twain,OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk {gen_tcp_error,\n closed}\n\n=INFO REPORT==== 18-Feb-2015::10:38:13 ===\nLDAP DECISION: login for Mark Twain: {error,{gen_tcp_error,closed}}\n\n=INFO REPORT==== 18-Feb-2015::10:38:13 ===\n LDAP bind error: CN=Mark Twain,OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk {gen_tcp_error,\n closed}\n\n=INFO REPORT==== 18-Feb-2015::10:38:13 ===\nLDAP DECISION: login for Mark Twain: {error,{gen_tcp_error,closed}}\n\n=ERROR REPORT==== 18-Feb-2015::10:38:16 ===\nclosing AMQP connection ([::1]:20117 -> [::1]:5672):\n{handshake_error,starting,0,\n {amqp_error,access_refused,\n \"PLAIN login refused: user 'Mark Twain' - invalid credentials\",\n 'connection.start_ok'}}\n```\n\nI've had a good Google for \"LDAP bind error\", \"handshake_error,starting,0\" and \"access_refused\" but can't find anything that could point me in the right direction.\n\nAny help would be appreciated.\n\n========================================\n\nTop Answer:\nI had a similar problem, except I was using the rabbitmq.conf instead of the advanced.config format. Here is an alternate solution if anyone is having this issue and using the other config format:\n\n```\nauth_backends.1 = ldap \nauth_ldap.servers.1 = ourldapbox.ourcompany.co.uk\nauth_ldap.dn_lookup_attribute = sAMAccountName\nauth_ldap.dn_lookup_base = DC=ourcompany,DC=co,DC=uk\nauth_ldap.user_dn_pattern = ${username}@ourcompany.co.uk\nauth_ldap.use_ssl = true\nauth_ldap.port = 636\nauth_ldap.log = true\nauth_backends.2 = rabbit_auth_backend_internal\n```\n\n========================================\n\nCode:\n```text\nvar entry = new DirectoryEntry(\"LDAP://ourldapbox.ourcompany.co.uk:636/CN=Mark Twain,OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk\");\n```\n\n```text\n[\n {rabbit, [{auth_backends, [rabbit_auth_backend_ldap, rabbit_auth_backend_internal]}]},\n {rabbitmq_auth_backend_ldap,\n [ {servers, [\"ourldapbox.ourcompany.co.uk\"]},\n {user_dn_pattern, \"CN=${username},OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk\"},\n {use_ssl, false},\n {port, 636},\n {log, true}\n ]\n }\n].\n```\n\n```text\n[\n {rabbit, [{auth_backends, [rabbit_auth_backend_ldap, rabbit_auth_backend_internal]}]},\n {rabbitmq_auth_backend_ldap,\n [ {servers, [\"ourldapbox.ourcompany.co.uk\"]},\n {dn_lookup_attribute, \"sAMAccountName\"},\n {dn_lookup_base, \"DC=ourcompany,DC=co,DC=uk\"},\n {user_dn_pattern, \"${username}@ourcompany.co.uk\"},\n {other_bind, anon},\n {use_ssl, false},\n {port, 636},\n {log, true}\n ]\n }\n].\n```\n\n```text\n[\n {rabbit, [{auth_backends, [rabbit_auth_backend_ldap, rabbit_auth_backend_internal]}]},\n {rabbitmq_auth_backend_ldap,\n [ {servers, [\"ourldapbox.ourcompany.co.uk\"]},\n {dn_lookup_attribute, \"userPrincipalName\"},\n {dn_lookup_base, \"dc=ourcompany,dc=co,dc=uk\"},\n {user_dn_pattern, \"${username}@ourcompany.co.uk\"},\n {use_ssl, false},\n {port, 636},\n {log, true}\n ]\n }\n].\n```\n\n```text\nvar connectionFactory = new ConnectionFactory\n{\n HostName = \"localhost\",\n UserName = \"twainm\",\n Password = \"fred123\",\n};\n\nusing (connectionFactory.CreateConnection())\n{\n // fails with:\n // None of the specified endpoints were reachable\n // ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.\n}\n```\n\n```text\n=INFO REPORT==== 18-Feb-2015::10:38:13 ===\naccepting AMQP connection <0.1122.0> ([::1]:20117 -> [::1]:5672)\n\n=INFO REPORT==== 18-Feb-2015::10:38:13 ===\nLDAP CHECK: login for Mark Twain\n\n=INFO REPORT==== 18-Feb-2015::10:38:13 ===\n LDAP filling template \"CN=${username},OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk\" with\n [{username,<<\"Mark Twain\">>}]\n\n=INFO REPORT==== 18-Feb-2015::10:38:13 ===\n LDAP template result: \"CN=Mark Twain,OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk\"\n\n=INFO REPORT==== 18-Feb-2015::10:38:13 ===\nLDAP CHECK: login for Mark Twain\n\n=INFO REPORT==== 18-Feb-2015::10:38:13 ===\n LDAP filling template \"CN=${username},OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk\" with\n [{username,<<\"Mark Twain\">>}]\n\n=INFO REPORT==== 18-Feb-2015::10:38:13 ===\n LDAP template result: \"CN=Mark Twain,OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk\"\n\n=INFO REPORT==== 18-Feb-2015::10:38:13 ===\n LDAP bind error: CN=Mark Twain,OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk {gen_tcp_error,\n closed}\n\n=INFO REPORT==== 18-Feb-2015::10:38:13 ===\nLDAP DECISION: login for Mark Twain: {error,{gen_tcp_error,closed}}\n\n=INFO REPORT==== 18-Feb-2015::10:38:13 ===\n LDAP bind error: CN=Mark Twain,OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk {gen_tcp_error,\n closed}\n\n=INFO REPORT==== 18-Feb-2015::10:38:13 ===\nLDAP DECISION: login for Mark Twain: {error,{gen_tcp_error,closed}}\n\n=ERROR REPORT==== 18-Feb-2015::10:38:16 ===\nclosing AMQP connection <0.1122.0> ([::1]:20117 -> [::1]:5672):\n{handshake_error,starting,0,\n {amqp_error,access_refused,\n \"PLAIN login refused: user 'Mark Twain' - invalid credentials\",\n 'connection.start_ok'}}\n```\n\n```text\nguest\n```\n\n```text\n[\n {rabbit,\n [ {auth_backends, [rabbit_auth_backend_ldap, rabbit_auth_backend_internal]}]},\n {rabbitmq_auth_backend_ldap,\n [ {servers, [\"ourldapbox.ourcompany.co.uk\"]},\n {dn_lookup_attribute, \"sAMAccountName\"},\n {dn_lookup_base, \"DC=ourcompany,DC=co,DC=uk\"},\n {user_dn_pattern, \"${username}@ourcompany.co.uk\"},\n {use_ssl, true},\n {port, 636},\n {log, true}\n ]\n }\n].\n```\n\n```text\nuse_ssl=false\n```\n\n```text\nport=636\n```\n\n```text\nauth_backends.1 = ldap \nauth_ldap.servers.1 = ourldapbox.ourcompany.co.uk\nauth_ldap.dn_lookup_attribute = sAMAccountName\nauth_ldap.dn_lookup_base = DC=ourcompany,DC=co,DC=uk\nauth_ldap.user_dn_pattern = ${username}@ourcompany.co.uk\nauth_ldap.use_ssl = true\nauth_ldap.port = 636\nauth_ldap.log = true\nauth_backends.2 = rabbit_auth_backend_internal\n```\n\n========================================\n\nComments:\n- I'm not sure that the `user_dn_pattern` combined with the `dn_lookup_base` is a preferred pattern... the docs are rather complicated but they seem to specify using one or the other? any hints as to why you did it this way?\n- I can't remember why I did it this way to be honest... I definitely tried both separate from one another but it only seemed to work when both were in place. As I couldn't find a way of providing SSO AD authentication for direct connections (not via the management console) I ended up removing LDAP authentication anyway.\n- Thanks. Yeah it is not heavy on the AD friendly side.\n- In my situation, both dn_lookup_base and user_dn_pattern are required to get the authentication I wanted... In my case I'm using dn_lookup_attribute \"userPrincipalName\" instead of \"sAMAccountName\" coupled with user_dn_pattern \"${username}@mycompany.com\". Having both helped simplify logins from the full email address format down to just the username part of the email address.","metadata":{"transformedAt":"2026-08-18T18:33:20.192Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":11,"totalLines":319,"estimatedTokens":2715}}810{"id":"stack-9155144","source":"stackoverflow","questionId":9155144,"title":"How to setup queue such a way all subscribers get messages - Rabbit MQ","tags":["rabbitmq"],"text":"Title: How to setup queue such a way all subscribers get messages - Rabbit MQ\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am reading RabbitMQ in Action book, stil in the chapter 2, but one thing authors says puzzling me. You setup a exchange and send a message, two subscribers are listening to the queue. When the first message comes in, the first subscriber gets it and the message is removed once it is acknowledged. When the next messages arrives it goes to the next listener in round robin way. I thought, if I am sending a message, I want all the subscribers to get it. Is my understanding wrong?\n\n========================================\n\nComments:\n- Take a look at this, rabbitmq.com/tutorials/tutorial-three-java.html\n- I would (and indeed do) configure my subscribers such that they are individually responsible for registering their own queues with the appropriate routing keys. Setting them up as self-deleting queues ensures that once the consumer's connection is lost, the queue is torn down too.","metadata":{"transformedAt":"2026-08-18T18:33:20.192Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":12,"estimatedTokens":255}}811{"id":"stack-49131004","source":"stackoverflow","questionId":49131004,"title":"How to achieve reliability with RabbitMQ?","tags":["architecture","rabbitmq","amqp"],"text":"Title: How to achieve reliability with RabbitMQ?\nTags: architecture, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nMy data is stored in many repositories and we expect a set of tasks(aka. jobs) that suppose to process this data. Each job demands access to one or two data repositories. Tasks are expected to run for up to 8 hours for large files and few milliseconds for small ones. It is important that the jobs are executed exactly once and they are not missed.\n\nWe need to set up more agents running in containers so they execute the tasks. At startup, each agent is granted access to a set of repositories. Each agent should run only jobs that can fulfill. As an example, it makes no sense to assign a job that needs access to \"R1\" and \"R2\" repositories to an agent that only have access to \"R2\", \"R3\", \"R4\" and \"R5\".\n\nIt seems RabbitMQ is a great candidate for this scenario. But I feel it is not reliable for following reasons:\n\n- It can deliver the same message twice.\n\n- It might crash, so messages might get lost.\n\n- Some agents might start at a later point it time and the jobs might get lost.\n\nShould I use Redis to avoid processing the same message twice?\n\nTo achieve excellent reliability, should I run a process that re-populates the queue from time to time?\n\nAre \"topic\" exchanges a good solution for directing the messages only to the agents that can process them? If so, how to deal with the case when the message was sent before the corresponding agent started?\n\nOf course, if you think other technologies are better equipped for this job than AMQP, feel free to recommend them.\n\n========================================\n\nCode:\n```text\nat-most-once\n```\n\n```text\nat-least-once\n```\n\n========================================\n\nComments:\n- You can use RabbitMQ and still avoid all the reasons that you have stated above.\n- I assumed it is possible. Though, I'd like some guidance on avoiding the concerns I have raised. How to achieve reliability from a practical standpoint?\n- Use durable queue, keep connections alive so that the connection doesn't die. Durable queues don't die until the messages are acknowledged.\n- Since you mentioned \"executed only once\", I clearly see that you'd better kill your \"agents\" whenever certain job is either finished, or faulted. So what you do need *conceptually* is `.OnNext(Continuation)`, `.OnCompleted(Report)`, `.OnError(Report)`. I would be brave enough to state that such a purely architectural decision is much more important than concrete technology.","metadata":{"transformedAt":"2026-08-18T18:33:20.192Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":43,"estimatedTokens":628}}812{"id":"stack-57167989","source":"stackoverflow","questionId":57167989,"title":"How to pass extra configuration to RabbitMQ with Helm?","tags":["kubernetes","rabbitmq","kubernetes-helm","bitnami"],"text":"Title: How to pass extra configuration to RabbitMQ with Helm?\nTags: kubernetes, rabbitmq, kubernetes-helm, bitnami\nSource: Stack Overflow\n\nQuestion:\nI'm using this chart: https://github.com/helm/charts/tree/master/stable/rabbitmq to deploy a cluster of 3 RabbitMQ nodes on Kubernetes. My intention is to have all the queues mirrored within 2 nodes in the cluster.\n\nHere's the command I use to run Helm: `helm install --name rabbitmq-local -f rabbitmq-values.yaml stable/rabbitmq`\n\nAnd here's the content of `rabbitmq-values.yaml`:\n\n```\npersistence:\n enabled: true\n\nresources:\n requests:\n memory: 256Mi\n cpu: 100m\n\nreplicas: 3\n\nrabbitmq:\n extraConfiguration: |-\n {\n \"policies\": [\n {\n \"name\": \"queue-mirroring-exactly-two\",\n \"pattern\": \"^ha\\.\",\n \"vhost\": \"/\",\n \"definition\": {\n \"ha-mode\": \"exactly\",\n \"ha-params\": 2\n }\n }\n ]\n }\n```\n\nHowever, the nodes fail to start due to some parsing errors, and they stay in crash loop. Here's the output of `kubectl logs rabbitmq-local-0`:\n\n```\nBOOT FAILED\n===========\n\nConfig file generation failed:\n=CRASH REPORT==== 23-Jul-2019::15:32:52.880991 ===\n crasher:\n initial call: lager_handler_watcher:init/1\n pid: \n registered_name: []\n exception exit: noproc\n in function gen:do_for_proc/2 (gen.erl, line 228)\n in call from gen_event:rpc/2 (gen_event.erl, line 239)\n in call from lager_handler_watcher:install_handler2/3 (src/lager_handler_watcher.erl, line 117)\n in call from lager_handler_watcher:init/1 (src/lager_handler_watcher.erl, line 51)\n in call from gen_server:init_it/2 (gen_server.erl, line 374)\n in call from gen_server:init_it/6 (gen_server.erl, line 342)\n ancestors: [lager_handler_watcher_sup,lager_sup,]\n message_queue_len: 0\n messages: []\n links: []\n dictionary: []\n trap_exit: false\n status: running\n heap_size: 610\n stack_size: 27\n reductions: 228\n neighbours:\n\n15:32:53.679 [error] Syntax error in /opt/bitnami/rabbitmq/etc/rabbitmq/rabbitmq.conf after line 14 column 1, parsing incomplete\n=SUPERVISOR REPORT==== 23-Jul-2019::15:32:53.681369 ===\n supervisor: {local,gr_counter_sup}\n errorContext: child_terminated\n reason: killed\n offender: [{pid,},\n {id,gr_lager_default_tracer_counters},\n {mfargs,{gr_counter,start_link,\n [gr_lager_default_tracer_counters]}},\n {restart_type,transient},\n {shutdown,brutal_kill},\n {child_type,worker}]\n=SUPERVISOR REPORT==== 23-Jul-2019::15:32:53.681514 ===\n supervisor: {local,gr_param_sup}\n errorContext: child_terminated\n reason: killed\n offender: [{pid,},\n {id,gr_lager_default_tracer_params},\n {mfargs,{gr_param,start_link,[gr_lager_default_tracer_params]}},\n {restart_type,transient},\n {shutdown,brutal_kill},\n {child_type,worker}]\n```\n\nIf I remove the `rabbitmq.extraConfiguration` part, the nodes start properly, so it must be something wrong with the way I'm typing in the policy. Any idea what I'm doing wrong?\n\nThank you.\n\n========================================\n\nTop Answer:\nYou can use config default of HelmChart\n\nIf needed, you can use extraSecrets to let the chart create the secret for you. This way, you don't need to manually create it before deploying a release. For example :\n\n```\nextraSecrets:\n load-definition:\n load_definition.json: |\n {\n \"vhosts\": [\n {\n \"name\": \"/\"\n }\n ]\n }\nrabbitmq:\n loadDefinition:\n enabled: true\n secretName: load-definition\n extraConfiguration: |\n management.load_definitions = /app/load_definition.json\n```\n\nhttps://github.com/helm/charts/tree/master/stable/rabbitmq\n\n========================================\n\nCode:\n```text\npersistence:\n enabled: true\n\nresources:\n requests:\n memory: 256Mi\n cpu: 100m\n\nreplicas: 3\n\nrabbitmq:\n extraConfiguration: |-\n {\n \"policies\": [\n {\n \"name\": \"queue-mirroring-exactly-two\",\n \"pattern\": \"^ha\\.\",\n \"vhost\": \"/\",\n \"definition\": {\n \"ha-mode\": \"exactly\",\n \"ha-params\": 2\n }\n }\n ]\n }\n```\n\n```text\nBOOT FAILED\n===========\n\nConfig file generation failed:\n=CRASH REPORT==== 23-Jul-2019::15:32:52.880991 ===\n crasher:\n initial call: lager_handler_watcher:init/1\n pid: <0.95.0>\n registered_name: []\n exception exit: noproc\n in function gen:do_for_proc/2 (gen.erl, line 228)\n in call from gen_event:rpc/2 (gen_event.erl, line 239)\n in call from lager_handler_watcher:install_handler2/3 (src/lager_handler_watcher.erl, line 117)\n in call from lager_handler_watcher:init/1 (src/lager_handler_watcher.erl, line 51)\n in call from gen_server:init_it/2 (gen_server.erl, line 374)\n in call from gen_server:init_it/6 (gen_server.erl, line 342)\n ancestors: [lager_handler_watcher_sup,lager_sup,<0.87.0>]\n message_queue_len: 0\n messages: []\n links: [<0.90.0>]\n dictionary: []\n trap_exit: false\n status: running\n heap_size: 610\n stack_size: 27\n reductions: 228\n neighbours:\n\n15:32:53.679 [error] Syntax error in /opt/bitnami/rabbitmq/etc/rabbitmq/rabbitmq.conf after line 14 column 1, parsing incomplete\n=SUPERVISOR REPORT==== 23-Jul-2019::15:32:53.681369 ===\n supervisor: {local,gr_counter_sup}\n errorContext: child_terminated\n reason: killed\n offender: [{pid,<0.97.0>},\n {id,gr_lager_default_tracer_counters},\n {mfargs,{gr_counter,start_link,\n [gr_lager_default_tracer_counters]}},\n {restart_type,transient},\n {shutdown,brutal_kill},\n {child_type,worker}]\n=SUPERVISOR REPORT==== 23-Jul-2019::15:32:53.681514 ===\n supervisor: {local,gr_param_sup}\n errorContext: child_terminated\n reason: killed\n offender: [{pid,<0.96.0>},\n {id,gr_lager_default_tracer_params},\n {mfargs,{gr_param,start_link,[gr_lager_default_tracer_params]}},\n {restart_type,transient},\n {shutdown,brutal_kill},\n {child_type,worker}]\n```\n\n```text\nhelm install --name rabbitmq-local -f rabbitmq-values.yaml stable/rabbitmq\n```\n\n```text\nrabbitmq-values.yaml\n```\n\n```text\nkubectl logs rabbitmq-local-0\n```\n\n```text\nrabbitmq.extraConfiguration\n```\n\n```text\nrabbitmq:\n loadDefinition:\n enabled: true\n secretName: rabbitmq-load-definition\n extraConfiguration:\n management.load_definitions = /app/load_definition.json\n```\n\n```text\napiVersion: v1\nkind: Secret\nmetadata:\n name: rabbitmq-load-definition\ntype: Opaque\nstringData:\n load_definition.json: |-\n {\n \"vhosts\": [\n {\n \"name\": \"/\"\n }\n ],\n \"policies\": [\n {\n \"name\": \"queue-mirroring-exactly-two\",\n \"pattern\": \"^ha\\.\",\n \"vhost\": \"/\",\n \"definition\": {\n \"ha-mode\": \"exactly\",\n \"ha-params\": 2\n }\n }\n ]\n }\n```\n\n```text\nJSON\n```\n\n```text\nextraConfiguration\n```\n\n```text\nkubectl apply -f ./rabbitmq-secret.yaml\n```\n\n```text\nextraSecrets:\n load-definition:\n load_definition.json: |\n {\n \"vhosts\": [\n {\n \"name\": \"/\"\n }\n ]\n }\nrabbitmq:\n loadDefinition:\n enabled: true\n secretName: load-definition\n extraConfiguration: |\n management.load_definitions = /app/load_definition.json\n```\n\n========================================\n\nComments:\n- This is the right answer. However, I must note that the configuration added by the user looks like JSON instead of erlang config format. You can add configuration options in two different places: - `extraConfiguration`, using the sysctl format - `advancedConfiguration`, using the erlang config format. The format provided by the user is not valid.\n- Thank you both for your answers. I was trying however to load the config as JSON. The answer I posted below works in that aspect.\n- Would it be possible to extend your answer with a working example of how to present the OP's config using the advancedConfiiguration option you suggest?\n- @PawanKumar Please add some information in your answer, please, if you can\n- the `loadDefinition.secretName` is now `loadDefinition.existingSecret`","metadata":{"transformedAt":"2026-08-18T18:33:20.192Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":302,"estimatedTokens":1992}}813{"id":"stack-12822403","source":"stackoverflow","questionId":12822403,"title":"Symfony2 and RabbitMqBundle. Can't publish a message","tags":["symfony","rabbitmq"],"text":"Title: Symfony2 and RabbitMqBundle. Can't publish a message\nTags: symfony, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am trying to use syfmony2 framework with RabbitMqBundle from here\n\nI am sure that my rabbitmq server is up and running and I am doing the configuration and publishers code accordingly to the docs delivered on github. Unfortunately I can`t add any message to the queue.\n\nI am sure that my rabbitmq server is up and running. I have queue named accordingly to the symfony configuration file. \n\nHave anyone got any clue what is wrong?\n\nThanks in advance for any suggestions.\n\n========================================\n\nTop Answer:\nI also had some issue to send messages with this bundle, i recommend you to try SonataNotificationBundle instead.\n\nYou can also install the RabbitMq management plugin to see the queued messages.\n\n========================================\n\nCode:\n```php\n# app/config.yml\nold_sound_rabbit_mq:\n connections: %rabbitmq_connections%\n producers: %rabbitmq_producers%\n consumers: %rabbitmq_consumers%\n\nparameters:\n # connection parameters\n rabbitmq_connections:\n default: { host: 'localhost', port: 5672, user: 'guest', password: 'guest', vhost: '/' }\n\n # define producers\n rabbitmq_producers:\n sample:\n connection: default\n exchange_options: {name: 'exchange_name', type: direct, auto_delete: false, durable: true}\n\n # define consumers\n rabbitmq_consumers:\n sample:\n connection: default\n exchange_options: {name: 'exchange_name', type: direct, auto_delete: false, durable: true}\n queue_options: {name: 'sample', auto_delete: false}\n callback: rabbitmq.callback.service\n```\n\n```yml\nservices:\n rabbitmq.callback.service:\n class: RabbitMQ\\Callback\\Service\n```\n\n```php\nnamespace RabbitMQ\\Callback;\n\nuse OldSound\\RabbitMqBundle\\RabbitMq\\ConsumerInterface;\nuse PhpAmqpLib\\Channel\\AMQPChannel;\nuse PhpAmqpLib\\Message\\AMQPMessage;\n\nclass Service implements ConsumerInterface \n{\n public function execute(AMQPMessage $msg)\n {\n var_dump(unserialize($msg->body));\n }\n}\n```\n\n```sh\napp/console rabbitmq:consumer sample --route=\"sample\"\n```\n\n```php\n# get producer service\n$producer = $this->get('old_sound_rabbit_mq.sample_producer');\n# publish message\n$producer->publish(serialize(array('foo'=>'bar','_FOO'=>'_BAR')), 'sample');\n```\n\n```text\napp/config.yml\n```\n\n```text\nrabbitmqctl\n```\n\n========================================\n\nComments:\n- And I would like to end up with working bundle mentioned in the question :) But thanks for reply anyway\n- Everything was fine in my code but I had to run consumer for a while and then all went fine. Thx.","metadata":{"transformedAt":"2026-08-18T18:33:20.192Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":98,"estimatedTokens":686}}814{"id":"stack-6113138","source":"stackoverflow","questionId":6113138,"title":"RabbitMQ: similar queues in different exchanges","tags":["rabbitmq","amqp"],"text":"Title: RabbitMQ: similar queues in different exchanges\nTags: rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nCan I have two queues with the same name and same routingKey yet each bound to another exchange?\n\n========================================\n\nTop Answer:\nYou can't have two queues with the same name at all, (well you can if they're in different virtual hosts but I don't think that's what you're talking about).\n\nHowever, you can bind one queue to many exchanges, or to one exchange with many routing keys. If you're aiming to have a single consumer pick up messages from several exchanges, that's what you want to do.","metadata":{"transformedAt":"2026-08-18T18:33:20.192Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":13,"estimatedTokens":157}}815{"id":"stack-48135792","source":"stackoverflow","questionId":48135792,"title":"java.lang.NoClassDefFoundError: org/springframework/messaging/handler/annotation/support/MessageHandlerMethodFactory","tags":["spring","rabbitmq","cqrs","spring-amqp","axon"],"text":"Title: java.lang.NoClassDefFoundError: org/springframework/messaging/handler/annotation/support/MessageHandlerMethodFactory\nTags: spring, rabbitmq, cqrs, spring-amqp, axon\nSource: Stack Overflow\n\nQuestion:\nI am going to make cqrs application using axon.I try to config axon RabbitMq to my application. If add spring-boot-starter-amqp and axon-amqp it make this error. how can I solve this.\n\n```\n[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.931 s [Help 1]\n[ERROR] \n[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.\n[ERROR] Re-run Maven using the -X switch to enable full debug logging.\n[ERROR] \n[ERROR] For more information about the errors and possible solutions, please read the following articles:\n[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException\n```\n\nHere is my pom.xml file.\n\n```\n\n 4.0.0\n\ncom.thamira.research\nresearch\n0.0.1-SNAPSHOT\njar\n\nSeat_Reservation_Service\nresearch project for Spring Boot\n\n org.springframework.boot\n spring-boot-starter-parent\n 2.0.0.BUILD-SNAPSHOT\n \n\n UTF-8\n UTF-8\n 1.8\n 3.0.4\n\n \n org.springframework.boot\n spring-boot-starter-amqp\n \n \n \n org.axonframework\n axon-amqp\n ${axon.version}\n \n\n \n org.springframework.boot\n spring-boot-starter-data-jpa\n \n \n org.springframework.boot\n spring-boot-starter-data-rest\n \n \n org.springframework.boot\n spring-boot-starter-web\n \n\n \n mysql\n mysql-connector-java\n runtime\n \n \n org.projectlombok\n lombok\n true\n \n \n org.springframework.boot\n spring-boot-starter-test\n test\n \n \n org.springframework.boot\n spring-boot-starter-actuator\n \n \n org.axonframework\n axon-spring-boot-starter\n ${axon.version}\n \n\n \n org.springframework.boot\n spring-boot-devtools\n runtime\n \n\n \n \n org.springframework.boot\n spring-boot-maven-plugin\n \n \n\n \n spring-snapshots\n Spring Snapshots\n https://repo.spring.io/snapshot\n \n true\n \n \n \n spring-milestones\n Spring Milestones\n https://repo.spring.io/milestone\n \n false\n \n \n\n \n spring-snapshots\n Spring Snapshots\n https://repo.spring.io/snapshot\n \n true\n \n \n \n spring-milestones\n Spring Milestones\n https://repo.spring.io/milestone\n \n false\n \n \n\n```\n\nI use docker instance as my rabbitmq broker.\nis there any configuration need before build this.\n\n========================================\n\nTop Answer:\nYou have not added spring-messaging dependency. Add the following to your **pom.xml** file (within dependencies tag)\n\n```\n\n org.springframework\n spring-messaging\n 4.0.0.RELEASE\n\n```\n\n========================================\n\nCode:\n```text\n[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.931 s <<< FAILURE! - in com.thamira.research.ProductServiceApplicationTests\n[ERROR] contextLoads(com.thamira.research.ProductServiceApplicationTests) Time elapsed: 0.007 s <<< ERROR!\njava.lang.NoClassDefFoundError: org/springframework/messaging/handler/annotation/support/MessageHandlerMethodFactory\nCaused by: java.lang.ClassNotFoundException: org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory\n\n[INFO] \n[INFO] Results:\n[INFO] \n[ERROR] Errors: \n[ERROR] ProductServiceApplicationTests.contextLoads » NoClassDefFound org/springframew...\n[INFO] \n[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0\n[INFO] \n[INFO] ------------------------------------------------------------------------\n[INFO] BUILD FAILURE\n[INFO] ------------------------------------------------------------------------\n[INFO] Total time: 15.136 s\n[INFO] Finished at: 2018-01-07T14:26:27+05:30\n[INFO] Final Memory: 40M/295M\n[INFO] ------------------------------------------------------------------------\n[WARNING] The requested profile \"pom.xml\" could not be activated because it does not exist.\n[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.20.1:test (default-test) on project research: There are test failures.\n[ERROR] \n[ERROR] Please refer to /Users/thamira/ProjectFolder/resurch/Seat_Reservation_Service/target/surefire-reports for the individual test results.\n[ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.\n[ERROR] -> [Help 1]\n[ERROR] \n[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.\n[ERROR] Re-run Maven using the -X switch to enable full debug logging.\n[ERROR] \n[ERROR] For more information about the errors and possible solutions, please read the following articles:\n[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException\n```\n\n```text\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n <modelVersion>4.0.0</modelVersion>\n\n<groupId>com.thamira.research</groupId>\n<artifactId>research</artifactId>\n<version>0.0.1-SNAPSHOT</version>\n<packaging>jar</packaging>\n\n<name>Seat_Reservation_Service</name>\n<description>research project for Spring Boot</description>\n\n<parent>\n <groupId>org.springframework.boot</groupId>\n <artifactId>spring-boot-starter-parent</artifactId>\n <version>2.0.0.BUILD-SNAPSHOT</version>\n <relativePath /> <!-- lookup parent from repository -->\n</parent>\n\n<properties>\n <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>\n <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>\n <java.version>1.8</java.version>\n <axon.version>3.0.4</axon.version>\n\n</properties>\n\n<dependencies>\n <dependency>\n <groupId>org.springframework.boot</groupId>\n <artifactId>spring-boot-starter-amqp</artifactId>\n </dependency>\n <!-- https://mvnrepository.com/artifact/org.axonframework/axon-amqp -->\n <dependency>\n <groupId>org.axonframework</groupId>\n <artifactId>axon-amqp</artifactId>\n <version>${axon.version}</version>\n </dependency>\n\n <dependency>\n <groupId>org.springframework.boot</groupId>\n <artifactId>spring-boot-starter-data-jpa</artifactId>\n </dependency>\n <dependency>\n <groupId>org.springframework.boot</groupId>\n <artifactId>spring-boot-starter-data-rest</artifactId>\n </dependency>\n <dependency>\n <groupId>org.springframework.boot</groupId>\n <artifactId>spring-boot-starter-web</artifactId>\n </dependency>\n\n <dependency>\n <groupId>mysql</groupId>\n <artifactId>mysql-connector-java</artifactId>\n <scope>runtime</scope>\n </dependency>\n <dependency>\n <groupId>org.projectlombok</groupId>\n <artifactId>lombok</artifactId>\n <optional>true</optional>\n </dependency>\n <dependency>\n <groupId>org.springframework.boot</groupId>\n <artifactId>spring-boot-starter-test</artifactId>\n <scope>test</scope>\n </dependency>\n <dependency>\n <groupId>org.springframework.boot</groupId>\n <artifactId>spring-boot-starter-actuator</artifactId>\n </dependency>\n <dependency>\n <groupId>org.axonframework</groupId>\n <artifactId>axon-spring-boot-starter</artifactId>\n <version>${axon.version}</version>\n </dependency>\n\n <dependency>\n <groupId>org.springframework.boot</groupId>\n <artifactId>spring-boot-devtools</artifactId>\n <scope>runtime</scope>\n </dependency>\n\n</dependencies>\n\n<build>\n <plugins>\n <plugin>\n <groupId>org.springframework.boot</groupId>\n <artifactId>spring-boot-maven-plugin</artifactId>\n </plugin>\n </plugins>\n</build>\n\n<repositories>\n <repository>\n <id>spring-snapshots</id>\n <name>Spring Snapshots</name>\n <url>https://repo.spring.io/snapshot</url>\n <snapshots>\n <enabled>true</enabled>\n </snapshots>\n </repository>\n <repository>\n <id>spring-milestones</id>\n <name>Spring Milestones</name>\n <url>https://repo.spring.io/milestone</url>\n <snapshots>\n <enabled>false</enabled>\n </snapshots>\n </repository>\n</repositories>\n\n<pluginRepositories>\n <pluginRepository>\n <id>spring-snapshots</id>\n <name>Spring Snapshots</name>\n <url>https://repo.spring.io/snapshot</url>\n <snapshots>\n <enabled>true</enabled>\n </snapshots>\n </pluginRepository>\n <pluginRepository>\n <id>spring-milestones</id>\n <name>Spring Milestones</name>\n <url>https://repo.spring.io/milestone</url>\n <snapshots>\n <enabled>false</enabled>\n </snapshots>\n </pluginRepository>\n</pluginRepositories>\n```\n\n```text\n<!-- https://mvnrepository.com/artifact/org.springframework/spring-messaging -->\n<dependency>\n <groupId>org.springframework</groupId>\n <artifactId>spring-messaging</artifactId>\n <version>4.0.0.RELEASE</version>\n</dependency>\n```\n\n========================================\n\nComments:\n- I need 2.0.0.BUILD-SNAPSHOT because i try to use reactive\n- I have searched but i did not get any version as such\n- not yet. if i build with 4.0.0.RELEASE it work but i need tio do with 2.0.0.BUILD-SNAPSHOT","metadata":{"transformedAt":"2026-08-18T18:33:20.192Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":344,"estimatedTokens":2286}}816{"id":"stack-56126710","source":"stackoverflow","questionId":56126710,"title":"API gateway and microservices communication","tags":["node.js","rabbitmq","graphql","microservices","apollo-client"],"text":"Title: API gateway and microservices communication\nTags: node.js, rabbitmq, graphql, microservices, apollo-client\nSource: Stack Overflow\n\nQuestion:\nI am building microservices arhitecture and i need help with communication. What is best approach for API gateway to communicate with services ? My API gateway will be `graphql apollo` server and services will be `REST APIs.` Should i use REST to communicate with services or some message system like `RabbitMQ ?`\n\n========================================\n\nCode:\n```text\ngraphql apollo\n```\n\n```text\nREST APIs.\n```\n\n```text\nRabbitMQ ?\n```\n\n========================================\n\nComments:\n- One more question for you @onuriltan. Can i use maybe gRpc to communicate between gateway and services, for example authentication service and gateway and use message broker for communication between services ? Or should I use message broker always ?\n- @Lule yes you can also use gRPC, it is also faster, but I found that it is harder to use because you need to implement broadcasting, pub-sub, security among different points etc. RabbitMQ I find is more easy to configure and implement.\n- Thank you, very helpful. Going with RabbitMQ then.","metadata":{"transformedAt":"2026-08-18T18:33:20.192Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":28,"estimatedTokens":296}}817{"id":"stack-55973466","source":"stackoverflow","questionId":55973466,"title":"Unable to connect to RabbitMQ started with Docker in a C# program (with RabbitMQ.Client)","tags":["c#","docker",".net-core","rabbitmq"],"text":"Title: Unable to connect to RabbitMQ started with Docker in a C# program (with RabbitMQ.Client)\nTags: c#, docker, .net-core, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI started a RabbitMQ container following the article: https://docs.docker.com/samples/library/rabbitmq using the image including the management tool\n\n```\ndocker run -d --hostname my-rabbit --name some-rabbit -p 8080:15672 rabbitmq:3-management\n```\n\n```\ndocker container ls --all\nCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS\n NAMES\n8a42bb749074 rabbitmq:3-management \"docker-entrypoint.s…\" 8 hours ago Up 8 hours 4369/tcp, 5671-5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:8080->15672/tcp some-rabbit\n```\n\nI can access the management tool via http://localhost:8080\n\nI then created the most basic C# Project ever following that article to communicate with my local instance of RabbitMQ:\n\n```\nusing System.Globalization;\nusing RabbitMQ.Client;\n\nnamespace RabbitCSharp\n{\n public static class Program\n {\n public static void Main(params string[] args)\n {\n var factory = new ConnectionFactory\n {\n HostName = \"localhost\"\n };\n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n }\n }\n }\n }\n}\n```\n\nBut unfortunately ran in the following error:\n\n```\nUnhandled Exception: RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable ---> System.AggregateException\n: One or more errors occurred. (Connection failed) ---> RabbitMQ.Client.Exceptions.ConnectFailureException: Connection failed ---> System.Net.Internals.S\nocketExceptionFactory+ExtendedSocketException: No connection could be made because the target machine actively refused it 127.0.0.1:5672\n at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)\n at System.Net.Sockets.Socket.<>c.b__272_0(IAsyncResult iar)\n--- End of stack trace from previous location where exception was thrown ---\n at RabbitMQ.Client.TcpClientAdapter.ConnectAsync(String host, Int32 port)\n at RabbitMQ.Client.Impl.TaskExtensions.TimeoutAfter(Task task, Int32 millisecondsTimeout)\n at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectOrFail(ITcpClient socket, AmqpTcpEndpoint endpoint, Int32 timeout)\n --- End of inner exception stack trace ---\n at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectUsingAddressFamily(AmqpTcpEndpoint endpoint, Func`2 socketFactory, Int32 timeout, AddressFamily fami\nly)\n at RabbitMQ.Client.Impl.SocketFrameHandler..ctor(AmqpTcpEndpoint endpoint, Func`2 socketFactory, Int32 connectionTimeout, Int32 readTimeout, Int32 wri\nteTimeout)\n at RabbitMQ.Client.ConnectionFactory.CreateFrameHandler(AmqpTcpEndpoint endpoint)\n at RabbitMQ.Client.EndpointResolverExtensions.SelectOne[T](IEndpointResolver resolver, Func`2 selector)\n --- End of inner exception stack trace ---\n at RabbitMQ.Client.EndpointResolverExtensions.SelectOne[T](IEndpointResolver resolver, Func`2 selector)\n at RabbitMQ.Client.Framing.Impl.AutorecoveringConnection.Init(IEndpointResolver endpoints)\n at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName)\n --- End of inner exception stack trace ---\n at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName)\n at RabbitCSharp.Program.Main(String[] args) in C:\\Users\\eperret\\Desktop\\RabbitCSharp\\RabbitCSharp\\RabbitCSharp\\Program.cs:line 14\n\nProcess finished with exit code -532,462,766.\n```\n\nNot really sure to understand why the RabbitClient cannot make it through `127.0.0.1:5672`\n\nAny idea?\n\n========================================\n\nCode:\n```text\ndocker run -d --hostname my-rabbit --name some-rabbit -p 8080:15672 rabbitmq:3-management\n```\n\n```sh\ndocker container ls --all\nCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS\n NAMES\n8a42bb749074 rabbitmq:3-management \"docker-entrypoint.s…\" 8 hours ago Up 8 hours 4369/tcp, 5671-5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:8080->15672/tcp some-rabbit\n```\n\n```cs\nusing System.Globalization;\nusing RabbitMQ.Client;\n\nnamespace RabbitCSharp\n{\n public static class Program\n {\n public static void Main(params string[] args)\n {\n var factory = new ConnectionFactory\n {\n HostName = \"localhost\"\n };\n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n }\n }\n }\n }\n}\n```\n\n```cs\nUnhandled Exception: RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable ---> System.AggregateException\n: One or more errors occurred. (Connection failed) ---> RabbitMQ.Client.Exceptions.ConnectFailureException: Connection failed ---> System.Net.Internals.S\nocketExceptionFactory+ExtendedSocketException: No connection could be made because the target machine actively refused it 127.0.0.1:5672\n at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)\n at System.Net.Sockets.Socket.<>c.<ConnectAsync>b__272_0(IAsyncResult iar)\n--- End of stack trace from previous location where exception was thrown ---\n at RabbitMQ.Client.TcpClientAdapter.ConnectAsync(String host, Int32 port)\n at RabbitMQ.Client.Impl.TaskExtensions.TimeoutAfter(Task task, Int32 millisecondsTimeout)\n at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectOrFail(ITcpClient socket, AmqpTcpEndpoint endpoint, Int32 timeout)\n --- End of inner exception stack trace ---\n at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectUsingAddressFamily(AmqpTcpEndpoint endpoint, Func`2 socketFactory, Int32 timeout, AddressFamily fami\nly)\n at RabbitMQ.Client.Impl.SocketFrameHandler..ctor(AmqpTcpEndpoint endpoint, Func`2 socketFactory, Int32 connectionTimeout, Int32 readTimeout, Int32 wri\nteTimeout)\n at RabbitMQ.Client.ConnectionFactory.CreateFrameHandler(AmqpTcpEndpoint endpoint)\n at RabbitMQ.Client.EndpointResolverExtensions.SelectOne[T](IEndpointResolver resolver, Func`2 selector)\n --- End of inner exception stack trace ---\n at RabbitMQ.Client.EndpointResolverExtensions.SelectOne[T](IEndpointResolver resolver, Func`2 selector)\n at RabbitMQ.Client.Framing.Impl.AutorecoveringConnection.Init(IEndpointResolver endpoints)\n at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName)\n --- End of inner exception stack trace ---\n at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName)\n at RabbitCSharp.Program.Main(String[] args) in C:\\Users\\eperret\\Desktop\\RabbitCSharp\\RabbitCSharp\\RabbitCSharp\\Program.cs:line 14\n\nProcess finished with exit code -532,462,766.\n```\n\n```text\n127.0.0.1:5672\n```\n\n```sh\ndocker stop some-rabbit\ndocker commit some-rabbit some-rabbit-right\ndocker run -p 5672:5672 -p 8080:15672 -td some-rabbit-right\n```\n\n```sh\ndocker run -d --hostname my-rabbit --name some-rabbit -p 5672:5672 -p 8080:15672 rabbitmq:3-management\n```\n\n========================================\n\nComments:\n- good one. thanks. i didn't notice it's caused by the mis-matched ports.","metadata":{"transformedAt":"2026-08-18T18:33:20.192Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":7,"totalLines":166,"estimatedTokens":1807}}818{"id":"stack-17969152","source":"stackoverflow","questionId":17969152,"title":"Dead Lettered Message Not Being Consumed in RabbitMQ and Node Using AMQP.Node","tags":["node.js","rabbitmq","dead-letter"],"text":"Title: Dead Lettered Message Not Being Consumed in RabbitMQ and Node Using AMQP.Node\nTags: node.js, rabbitmq, dead-letter\nSource: Stack Overflow\n\nQuestion:\nI want to receive a message after a certain amount of time in one of my workers. I decided to go with Node and RabbitMQ after discovering so-called dead letter exchanges.\n\nThe message seems to get send to the queue in DeadExchange, but the consumer is never receiving the message after the elapsed time in the WorkQueue in the WorkExchange. Either the bindQueue is off, or the dead-letter'ing doesn't work?\n\nI've tried *a lot* of different values now. Can someone please point out what I'm missing? \n\n```\nvar amqp = require('amqplib');\nvar url = 'amqp://dev.rabbitmq.com';\n\namqp.connect(url).then(function(conn) {\n //Subscribe to the WorkQueue in WorkExchange to which the \"delayed\" messages get dead-letter'ed (is that a verb?) to.\n return conn.createChannel().then(function(ch) {\n return ch.assertExchange('WorkExchange', 'direct').then(function() {\n return ch.assertQueue('WorkQueue', {\n autoDelete: false,\n durable: true\n })\n }).then(function() {\n return ch.bindQueue('WorkQueue', 'WorkExchange', '');\n }).then(function() {\n console.log('Waiting for consume.');\n\n return ch.consume('WorkQueue', function(msg) {\n console.log('Received message.');\n console.log(msg.content.toString());\n ch.ack(msg);\n });\n });\n })\n}).then(function() {\n //Now send a test message to DeadExchange to a random (unique) queue.\n return amqp.connect(url).then(function(conn) {\n return conn.createChannel();\n }).then(function(ch) {\n return ch.assertExchange('DeadExchange', 'direct').then(function() {\n return ch.assertQueue('', {\n arguments: {\n 'x-dead-letter-exchange': 'WorkExchange',\n 'x-message-ttl': 2000,\n 'x-expires': 10000\n }\n })\n }).then(function(ok) {\n console.log('Sending delayed message');\n\n return ch.sendToQueue(ok.queue, new Buffer(':)'));\n });\n })\n}).then(null, function(error) {\n console.log('error\\'ed')\n console.log(error);\n console.log(error.stack);\n});\n```\n\nI'm using amqp.node (https://github.com/squaremo/amqp.node) which is amqplib in npm. Although node-amqp (https://github.com/postwait/node-amqp) seems to be so much more popular, it doesn't implement the full protocol and there are quite some outstanding issues regarding reconnecting.\n\ndev.rabbitmq.com is running RabbitMQ 3.1.3.\n\n========================================\n\nTop Answer:\nThis is a working code.When a message spends more than ttl in DeadExchange, it is pushed to WorkExchange. The key to success is defining the right routing key. The exchange-queue to which you wish to send post ttl, should be bounded with a routing key(note: not default), and 'x-dead-letter-routing-key' attributes value should match that route-key.\n\n\r\n\r\n\n```\nvar amqp = require('amqplib');\r\nvar url = 'amqp://localhost';\r\n\r\namqp.connect(url).then(function(conn) {\r\n //Subscribe to the WorkQueue in WorkExchange to which the \"delayed\" messages get dead-letter'ed (is that a verb?) to.\r\n return conn.createChannel().then(function(ch) {\r\n return ch.assertExchange('WorkExchange', 'direct').then(function() {\r\n return ch.assertQueue('WorkQueue', {\r\n autoDelete: false,\r\n durable: true\r\n })\r\n }).then(function() {\r\n return ch.bindQueue('WorkQueue', 'WorkExchange', 'rk1');\r\n }).then(function() {\r\n console.log('Waiting for consume.');\r\n\r\n return ch.consume('WorkQueue', function(msg) {\r\n console.log('Received message.');\r\n console.log(msg.content.toString());\r\n ch.ack(msg);\r\n });\r\n });\r\n })\r\n}).then(function() {\r\n //Now send a test message to DeadExchange to DEQ queue.\r\n return amqp.connect(url).then(function(conn) {\r\n return conn.createChannel();\r\n }).then(function(ch) {\r\n return ch.assertExchange('DeadExchange', 'direct').then(function() {\r\n return ch.assertQueue('DEQ', {\r\n arguments: {\r\n 'x-dead-letter-exchange': 'WorkExchange',\r\n 'x-dead-letter-routing-key': 'rk1',\r\n 'x-message-ttl': 15000,\r\n 'x-expires': 100000\r\n }\r\n })\r\n }).then(function() {\r\n return ch.bindQueue('DEQ', 'DeadExchange', '');\r\n }).then(function() {\r\n console.log('Sending delayed message');\r\n\r\n return ch.publish('DeadExchange', '', new Buffer(\"Over the Hills and Far Away!\"));\r\n });\r\n })\r\n}).then(null, function(error) {\r\n console.log('error\\'ed')\r\n console.log(error);\r\n console.log(error.stack);\r\n});\n```\n\n========================================\n\nCode:\n```text\nvar amqp = require('amqplib');\nvar url = 'amqp://dev.rabbitmq.com';\n\namqp.connect(url).then(function(conn) {\n //Subscribe to the WorkQueue in WorkExchange to which the \"delayed\" messages get dead-letter'ed (is that a verb?) to.\n return conn.createChannel().then(function(ch) {\n return ch.assertExchange('WorkExchange', 'direct').then(function() {\n return ch.assertQueue('WorkQueue', {\n autoDelete: false,\n durable: true\n })\n }).then(function() {\n return ch.bindQueue('WorkQueue', 'WorkExchange', '');\n }).then(function() {\n console.log('Waiting for consume.');\n\n return ch.consume('WorkQueue', function(msg) {\n console.log('Received message.');\n console.log(msg.content.toString());\n ch.ack(msg);\n });\n });\n })\n}).then(function() {\n //Now send a test message to DeadExchange to a random (unique) queue.\n return amqp.connect(url).then(function(conn) {\n return conn.createChannel();\n }).then(function(ch) {\n return ch.assertExchange('DeadExchange', 'direct').then(function() {\n return ch.assertQueue('', {\n arguments: {\n 'x-dead-letter-exchange': 'WorkExchange',\n 'x-message-ttl': 2000,\n 'x-expires': 10000\n }\n })\n }).then(function(ok) {\n console.log('Sending delayed message');\n\n return ch.sendToQueue(ok.queue, new Buffer(':)'));\n });\n })\n}).then(null, function(error) {\n console.log('error\\'ed')\n console.log(error);\n console.log(error.stack);\n});\n```\n\n```js\nvar amqp = require('amqplib');\nvar url = 'amqp://localhost';\n\namqp.connect(url).then(function(conn) {\n //Subscribe to the WorkQueue in WorkExchange to which the \"delayed\" messages get dead-letter'ed (is that a verb?) to.\n return conn.createChannel().then(function(ch) {\n return ch.assertExchange('WorkExchange', 'direct').then(function() {\n return ch.assertQueue('WorkQueue', {\n autoDelete: false,\n durable: true\n })\n }).then(function() {\n return ch.bindQueue('WorkQueue', 'WorkExchange', 'rk1');\n }).then(function() {\n console.log('Waiting for consume.');\n\n return ch.consume('WorkQueue', function(msg) {\n console.log('Received message.');\n console.log(msg.content.toString());\n ch.ack(msg);\n });\n });\n })\n}).then(function() {\n //Now send a test message to DeadExchange to DEQ queue.\n return amqp.connect(url).then(function(conn) {\n return conn.createChannel();\n }).then(function(ch) {\n return ch.assertExchange('DeadExchange', 'direct').then(function() {\n return ch.assertQueue('DEQ', {\n arguments: {\n 'x-dead-letter-exchange': 'WorkExchange',\n 'x-dead-letter-routing-key': 'rk1',\n 'x-message-ttl': 15000,\n 'x-expires': 100000\n }\n })\n }).then(function() {\n return ch.bindQueue('DEQ', 'DeadExchange', '');\n }).then(function() {\n console.log('Sending delayed message');\n\n return ch.publish('DeadExchange', '', new Buffer(\"Over the Hills and Far Away!\"));\n });\n })\n}).then(null, function(error) {\n console.log('error\\'ed')\n console.log(error);\n console.log(error.stack);\n});\n```\n\n```text\nconst amqp = require('amqp-connection-manager');\nconst username = encodeURIComponent('queue');\nconst password = encodeURIComponent('pass');\nconst port = '5672';\nconst host = 'localhost';\nconst connectionString = `amqp://${username}:${password}@${host}:${port}`;\n\n// Ask the connection manager for a ChannelWrapper. Specify a setup function to\n// run every time we reconnect to the broker.\nconnection = amqp.connect([connectionString]);\n\n// A channel is your ongoing connection to RabbitMQ.\n// All commands go through your channel.\nconnection.createChannel({\n json: true,\n setup: function (channel) {\n channel.prefetch(100);\n\n // Setup EXCHANGES - which are hubs you PUBLISH to that dispatch MESSAGES to QUEUES\n return Promise.all([\n channel.assertExchange('Test_MainExchange', 'topic', {\n durable: false,\n autoDelete: true,\n noAck: false\n }),\n channel.assertExchange('Test_DeadLetterExchange', 'topic', {\n durable: false,\n autoDelete: true,\n maxLength: 1000,\n noAck: true // This means dead letter messages will not need an explicit acknowledgement or rejection\n })\n ])\n // Setup QUEUES - which are delegated MESSAGES by EXCHANGES.\n // The MESSAGES then need to be CONSUMED.\n .then(() => {\n return Promise.all([\n channel.assertQueue(\n 'Test_MainQueue',\n options = {\n durable: true,\n autoDelete: true,\n exclusive: false,\n messageTtl: 1000*60*60*1,\n deadLetterExchange: 'Test_DeadLetterExchange'\n }\n ),\n channel.assertQueue('Test_DeadLetterQueue',\n options = {\n durable: false,\n autoDelete: true,\n exclusive: false\n }\n )\n ]);\n })\n // This glues the QUEUES and EXCHANGES together\n // The last parameter is a routing key. A hash/pound just means: give me all messages in the exchange.\n .then(() => {\n return Promise.all([\n channel.bindQueue('Test_MainQueue', 'Test_MainExchange', '#'),\n channel.bindQueue('Test_DeadLetterQueue', 'Test_DeadLetterExchange', '#')\n ]);\n })\n // Setup our CONSUMERS\n // They pick MESSAGES off of QUEUES and do something with them (either ack or nack them)\n .then(() => {\n return Promise.all([\n channel.consume('Test_MainQueue', (msg) => {\n const stringifiedContent = msg.content ? msg.content.toString() : '{}';\n console.log('Test_MainQueue::CONSUME ' + stringifiedContent);\n\n const messageData = JSON.parse(stringifiedContent);\n if (messageData.value === 0) {\n console.log('Test_MainQueue::REJECT ' + stringifiedContent);\n // the 'false' param at the very end means, don't retry! dead letter this instead!\n return channel.nack(msg, true, false);\n }\n return channel.ack(msg);\n })\n ]),\n channel.consume('Test_DeadLetterQueue', (msg) => {\n const stringifiedContent = msg.content ? msg.content.toString() : '{}';\n console.log('');\n console.log('Test_DeadLetterQueue::CONSUME ' + stringifiedContent);\n console.log('');\n });\n })\n .then(() => {\n setInterval(function () {\n const messageData = {\n text: 'Dead letter if 0',\n value: Math.floor(Math.random()*5)\n };\n const stringifiedMessage = JSON.stringify(messageData);\n\n // Publish message to exchange\n if (channel.publish('Test_MainExchange', '', new Buffer(stringifiedMessage))) {\n console.log(`Sent ${stringifiedMessage}`);\n } else {\n console.log(`Failed to send ${stringifiedMessage}`);\n };\n }, 300);\n });\n }\n});\n```\n\n========================================\n\nComments:\n- can you give some more details about what you're trying to achieve? it isn't completely clear what you want to use the dead-letter exchange for...\n- Currently my workers poll the database every 2 seconds to check if an event ended (and then do some things, like update several collections and notify another queue to send out messages to clients via SSE) after an even started. Now, I want to send 1 dead-letter'ed message which ends up in the WorkQueue (after a specific time elapsed) my workers listen to. This would remove load from the database and allows me to scale easier. Regular RabbitMQ messages work fine, but the dead letter exchange isn't. Any idea?\n- For the record: the message is never received in the consumer in the WorkQueue.","metadata":{"transformedAt":"2026-08-18T18:33:20.192Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":346,"estimatedTokens":3125}}819{"id":"stack-55769877","source":"stackoverflow","questionId":55769877,"title":"Receive events from AMQP with Axon 4","tags":["java","spring-boot","rabbitmq","amqp","axon"],"text":"Title: Receive events from AMQP with Axon 4\nTags: java, spring-boot, rabbitmq, amqp, axon\nSource: Stack Overflow\n\nQuestion:\nI am trying to send messages via rabbitmq to an axon4 spring boot based system. The message is received but no events are triggered. I am very sure I am missing an essential part, but up to now I wasn't able to figure it out.\n\nHere the relevant part of my application.yml\n\n```\naxon:\n amqp:\n exchange: axon.fanout\n transaction-mode: publisher_ack\n # adding the following lines changed nothing\n eventhandling:\n processors:\n amqpEvents:\n source: in.queue\n mode: subscribing\nspring:\n rabbitmq:\n username: rabbit\n password: rabbit\n```\n\nFrom the docs I found that I am supposed to create a SpringAMQPMessageSource bean:\n\n```\nimport com.rabbitmq.client.Channel;\nimport lombok.extern.slf4j.Slf4j;\nimport org.axonframework.extensions.amqp.eventhandling.AMQPMessageConverter;\nimport org.axonframework.extensions.amqp.eventhandling.spring.SpringAMQPMessageSource;\nimport org.springframework.amqp.core.Message;\nimport org.springframework.amqp.rabbit.annotation.RabbitListener;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\n\n@Slf4j\n@Configuration\npublic class AxonConfig {\n\n @Bean\n SpringAMQPMessageSource inputMessageSource(final AMQPMessageConverter messageConverter) {\n return new SpringAMQPMessageSource(messageConverter) {\n @RabbitListener(queues = \"in.queue\")\n @Override\n public void onMessage(final Message message, final Channel channel) {\n log.debug(\"received external message: {}, channel: {}\", message, channel);\n super.onMessage(message, channel);\n }\n };\n }\n\n}\n```\n\nIf I send a message to the queue from the rabbitmq admin panel I see the log:\n\n`AxonConfig : received external message: (Body:'[B@13f7aeef(byte[167])' MessageProperties [headers={}, contentLength=0, receivedDeliveryMode=NON_PERSISTENT, redelivered=false, receivedExchange=, receivedRoutingKey=in.queue, deliveryTag=2, consumerTag=amq.ctag-xi34jwHHA__xjENSteX5Dw, consumerQueue=in.queue]), channel: Cached Rabbit Channel: AMQChannel(amqp://rabbit@127.0.0.1:5672/,1), conn: Proxy@11703cc8 Shared Rabbit Connection: SimpleConnection@581cb879 [delegate=amqp://rabbit@127.0.0.1:5672/, localPort= 58614]`\n\nHere the Aggregate that should receive the events:\n\n```\nimport lombok.extern.slf4j.Slf4j;\nimport org.axonframework.commandhandling.CommandHandler;\nimport org.axonframework.config.ProcessingGroup;\nimport org.axonframework.eventsourcing.EventSourcingHandler;\nimport org.axonframework.modelling.command.AggregateIdentifier;\nimport org.axonframework.spring.stereotype.Aggregate;\nimport pm.mbo.easyway.api.app.order.commands.ConfirmOrderCommand;\nimport pm.mbo.easyway.api.app.order.commands.PlaceOrderCommand;\nimport pm.mbo.easyway.api.app.order.commands.ShipOrderCommand;\nimport pm.mbo.easyway.api.app.order.events.OrderConfirmedEvent;\nimport pm.mbo.easyway.api.app.order.events.OrderPlacedEvent;\nimport pm.mbo.easyway.api.app.order.events.OrderShippedEvent;\n\nimport static org.axonframework.modelling.command.AggregateLifecycle.apply;\n\n@ProcessingGroup(\"amqpEvents\")\n@Slf4j\n@Aggregate\npublic class OrderAggregate {\n\n @AggregateIdentifier\n private String orderId;\n private boolean orderConfirmed;\n\n @CommandHandler\n public OrderAggregate(final PlaceOrderCommand command) {\n log.debug(\"command: {}\", command);\n apply(new OrderPlacedEvent(command.getOrderId(), command.getProduct()));\n }\n\n @CommandHandler\n public void handle(final ConfirmOrderCommand command) {\n log.debug(\"command: {}\", command);\n apply(new OrderConfirmedEvent(orderId));\n }\n\n @CommandHandler\n public void handle(final ShipOrderCommand command) {\n log.debug(\"command: {}\", command);\n if (!orderConfirmed) {\n throw new IllegalStateException(\"Cannot ship an order which has not been confirmed yet.\");\n }\n apply(new OrderShippedEvent(orderId));\n }\n\n @EventSourcingHandler\n public void on(final OrderPlacedEvent event) {\n log.debug(\"event: {}\", event);\n this.orderId = event.getOrderId();\n orderConfirmed = false;\n }\n\n @EventSourcingHandler\n public void on(final OrderConfirmedEvent event) {\n log.debug(\"event: {}\", event);\n orderConfirmed = true;\n }\n\n @EventSourcingHandler\n public void on(final OrderShippedEvent event) {\n log.debug(\"event: {}\", event);\n orderConfirmed = true;\n }\n\n protected OrderAggregate() {\n }\n\n}\n```\n\nSo the problem is that the messages are received by the system but no events are triggered. The content of the messages seem to be irrelevant. Whatever I send to the queue I only get a log message from my onMessage method.\n\nJavaDoc of SpringAMQPMessageSource says this:\n\n```\n/**\n * MessageListener implementation that deserializes incoming messages and forwards them to one or more event processors.\n * \n * The SpringAMQPMessageSource must be registered with a Spring MessageListenerContainer and forwards each message\n * to all subscribed processors.\n * \n * Note that the Processors must be subscribed before the MessageListenerContainer is started. Otherwise, messages will\n * be consumed from the AMQP Queue without any processor processing them.\n *\n * @author Allard Buijze\n * @since 3.0\n */\n```\n\nBut up to now I couldn't find out where or how to register it.\n\nThe axon.eventhandling entries in my config and @ProcessingGroup(\"amqpEvents\") in my Aggregate are already from testing. But having those entries in or not made no difference at all. Also tried without the mode=subscribing.\n\nExact versions: Spring Boot 2.1.4, Axon 4.1.1, axon-amqp-spring-boot-autoconfigure 4.1\n\nAny help or hints highly appreciated.\n\nUpdate 23.04.19:\n\nI tried to write my own class like this:\n\n```\nimport com.rabbitmq.client.Channel;\nimport lombok.extern.slf4j.Slf4j;\nimport org.axonframework.common.Registration;\nimport org.axonframework.eventhandling.EventMessage;\nimport org.axonframework.extensions.amqp.eventhandling.AMQPMessageConverter;\nimport org.axonframework.messaging.SubscribableMessageSource;\nimport org.springframework.amqp.core.Message;\nimport org.springframework.amqp.rabbit.annotation.RabbitListener;\nimport org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Component;\n\nimport java.util.Collections;\nimport java.util.List;\nimport java.util.concurrent.CopyOnWriteArrayList;\nimport java.util.function.Consumer;\n\n@Slf4j\n@Component\npublic class RabbitMQSpringAMQPMessageSource implements ChannelAwareMessageListener, SubscribableMessageSource> {\n\n private final List>>> eventProcessors = new CopyOnWriteArrayList<>();\n private final AMQPMessageConverter messageConverter;\n\n @Autowired\n public RabbitMQSpringAMQPMessageSource(final AMQPMessageConverter messageConverter) {\n this.messageConverter = messageConverter;\n }\n\n @Override\n public Registration subscribe(final Consumer>> messageProcessor) {\n eventProcessors.add(messageProcessor);\n log.debug(\"subscribe to: {}\", messageProcessor);\n return () -> eventProcessors.remove(messageProcessor);\n }\n\n @RabbitListener(queues = \"${application.queues.in}\")\n @Override\n public void onMessage(final Message message, final Channel channel) {\n log.debug(\"received external message: {}, channel: {}\", message, channel);\n log.debug(\"eventProcessors: {}\", eventProcessors);\n if (!eventProcessors.isEmpty()) {\n messageConverter.readAMQPMessage(message.getBody(), message.getMessageProperties().getHeaders())\n .ifPresent(event -> eventProcessors.forEach(\n ep -> ep.accept(Collections.singletonList(event))\n ));\n }\n }\n\n}\n```\n\nThe result is the same and the log now proofs that the eventProcessors are just empty.\n\n```\neventProcessors: []\n```\n\n### So the question is, how to register the event processors correctly. Is there a way how to do that properly with spring?\n\nUpdate2:\n\nAlso no luck with this:\n\n```\n@Slf4j\n@Component(\"rabbitMQSpringAMQPMessageSource\")\npublic class RabbitMQSpringAMQPMessageSource extends SpringAMQPMessageSource {\n\n @Autowired\n public RabbitMQSpringAMQPMessageSource(final AMQPMessageConverter messageConverter) {\n super(messageConverter);\n }\n\n @RabbitListener(queues = \"${application.queues.in}\")\n @Override\n public void onMessage(final Message message, final Channel channel) {\n\n try {\n final var eventProcessorsField = this.getClass().getSuperclass().getDeclaredField(\"eventProcessors\");\n eventProcessorsField.setAccessible(true);\n final var eventProcessors = (List>>>) eventProcessorsField.get(this);\n log.debug(\"eventProcessors: {}\", eventProcessors);\n } catch (NoSuchFieldException | IllegalAccessException e) {\n e.printStackTrace();\n }\n\n log.debug(\"received message: message={}, channel={}\", message, channel);\n super.onMessage(message, channel);\n }\n\n}\n```\n\n```\naxon:\n eventhandling:\n processors:\n amqpEvents:\n source: rabbitMQSpringAMQPMessageSource\n mode: SUBSCRIBING\n```\n\nRegistering it programmatically in addition to above also didn't help:\n\n```\n@Autowired\n void configure(EventProcessingModule epm,\n RabbitMQSpringAMQPMessageSource rabbitMessageSource) {\n epm.registerSubscribingEventProcessor(\"rabbitMQSpringAMQPMessageSource\", c -> rabbitMessageSource);\n epm.assignProcessingGroup(\"amqpEvents\", \"rabbitMQSpringAMQPMessageSource\");// this line also made no difference\n }\n```\n\nOf course @ProcessingGroup(\"amqpEvents\") is in place in my class that contains the @EventSourcingHandler annotated methods.\n\nUpdate 25.4.19:\n\nsee accepted answer from Allard. Thanks a lot pointing me at the mistake I made: I missed that EventSourcingHandler don't receive messages from outside. This is for projections. Not for distributing Aggregates! *ups*\nHere the config/classes that are receiving events from rabbitmq now:\n\n```\naxon:\n eventhandling:\n processors:\n amqpEvents:\n source: rabbitMQSpringAMQPMessageSource\n mode: SUBSCRIBING\n```\n\n```\nimport com.rabbitmq.client.Channel;\nimport lombok.extern.slf4j.Slf4j;\nimport org.axonframework.extensions.amqp.eventhandling.AMQPMessageConverter;\nimport org.axonframework.extensions.amqp.eventhandling.spring.SpringAMQPMessageSource;\nimport org.springframework.amqp.core.Message;\nimport org.springframework.amqp.rabbit.annotation.RabbitListener;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Component;\n\n@Slf4j\n@Component(\"rabbitMQSpringAMQPMessageSource\")\npublic class RabbitMQSpringAMQPMessageSource extends SpringAMQPMessageSource {\n\n @Autowired\n public RabbitMQSpringAMQPMessageSource(final AMQPMessageConverter messageConverter) {\n super(messageConverter);\n }\n\n @RabbitListener(queues = \"${application.queues.in}\")\n @Override\n public void onMessage(final Message message, final Channel channel) {\n log.debug(\"received message: message={}, channel={}\", message, channel);\n super.onMessage(message, channel);\n }\n\n}\n```\n\n```\nimport lombok.extern.slf4j.Slf4j;\nimport org.axonframework.config.ProcessingGroup;\nimport org.axonframework.eventhandling.EventHandler;\nimport org.axonframework.queryhandling.QueryHandler;\nimport org.springframework.stereotype.Service;\nimport pm.mbo.easyway.api.app.order.events.OrderConfirmedEvent;\nimport pm.mbo.easyway.api.app.order.events.OrderPlacedEvent;\nimport pm.mbo.easyway.api.app.order.events.OrderShippedEvent;\n\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\n\n@Slf4j\n@ProcessingGroup(\"amqpEvents\")\n@Service\npublic class OrderedProductsEventHandler {\n\n private final Map orderedProducts = new HashMap<>();\n\n @EventHandler\n public void on(OrderPlacedEvent event) {\n log.debug(\"event: {}\", event);\n String orderId = event.getOrderId();\n orderedProducts.put(orderId, new OrderedProduct(orderId, event.getProduct()));\n }\n\n @EventHandler\n public void on(OrderConfirmedEvent event) {\n log.debug(\"event: {}\", event);\n orderedProducts.computeIfPresent(event.getOrderId(), (orderId, orderedProduct) -> {\n orderedProduct.setOrderConfirmed();\n return orderedProduct;\n });\n }\n\n @EventHandler\n public void on(OrderShippedEvent event) {\n log.debug(\"event: {}\", event);\n orderedProducts.computeIfPresent(event.getOrderId(), (orderId, orderedProduct) -> {\n orderedProduct.setOrderShipped();\n return orderedProduct;\n });\n }\n\n @QueryHandler\n public List handle(FindAllOrderedProductsQuery query) {\n log.debug(\"query: {}\", query);\n return new ArrayList<>(orderedProducts.values());\n }\n\n}\n```\n\nI removed the @ProcessingGroup from my Aggregate of course.\n\nMy logs:\n\n```\nRabbitMQSpringAMQPMessageSource : received message: ... \nOrderedProductsEventHandler : event: OrderShippedEvent...\n```\n\n========================================\n\nCode:\n```text\naxon:\n amqp:\n exchange: axon.fanout\n transaction-mode: publisher_ack\n # adding the following lines changed nothing\n eventhandling:\n processors:\n amqpEvents:\n source: in.queue\n mode: subscribing\nspring:\n rabbitmq:\n username: rabbit\n password: rabbit\n```\n\n```java\nimport com.rabbitmq.client.Channel;\nimport lombok.extern.slf4j.Slf4j;\nimport org.axonframework.extensions.amqp.eventhandling.AMQPMessageConverter;\nimport org.axonframework.extensions.amqp.eventhandling.spring.SpringAMQPMessageSource;\nimport org.springframework.amqp.core.Message;\nimport org.springframework.amqp.rabbit.annotation.RabbitListener;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\n\n@Slf4j\n@Configuration\npublic class AxonConfig {\n\n @Bean\n SpringAMQPMessageSource inputMessageSource(final AMQPMessageConverter messageConverter) {\n return new SpringAMQPMessageSource(messageConverter) {\n @RabbitListener(queues = \"in.queue\")\n @Override\n public void onMessage(final Message message, final Channel channel) {\n log.debug(\"received external message: {}, channel: {}\", message, channel);\n super.onMessage(message, channel);\n }\n };\n }\n\n}\n```\n\n```java\nimport lombok.extern.slf4j.Slf4j;\nimport org.axonframework.commandhandling.CommandHandler;\nimport org.axonframework.config.ProcessingGroup;\nimport org.axonframework.eventsourcing.EventSourcingHandler;\nimport org.axonframework.modelling.command.AggregateIdentifier;\nimport org.axonframework.spring.stereotype.Aggregate;\nimport pm.mbo.easyway.api.app.order.commands.ConfirmOrderCommand;\nimport pm.mbo.easyway.api.app.order.commands.PlaceOrderCommand;\nimport pm.mbo.easyway.api.app.order.commands.ShipOrderCommand;\nimport pm.mbo.easyway.api.app.order.events.OrderConfirmedEvent;\nimport pm.mbo.easyway.api.app.order.events.OrderPlacedEvent;\nimport pm.mbo.easyway.api.app.order.events.OrderShippedEvent;\n\nimport static org.axonframework.modelling.command.AggregateLifecycle.apply;\n\n@ProcessingGroup(\"amqpEvents\")\n@Slf4j\n@Aggregate\npublic class OrderAggregate {\n\n @AggregateIdentifier\n private String orderId;\n private boolean orderConfirmed;\n\n @CommandHandler\n public OrderAggregate(final PlaceOrderCommand command) {\n log.debug(\"command: {}\", command);\n apply(new OrderPlacedEvent(command.getOrderId(), command.getProduct()));\n }\n\n @CommandHandler\n public void handle(final ConfirmOrderCommand command) {\n log.debug(\"command: {}\", command);\n apply(new OrderConfirmedEvent(orderId));\n }\n\n @CommandHandler\n public void handle(final ShipOrderCommand command) {\n log.debug(\"command: {}\", command);\n if (!orderConfirmed) {\n throw new IllegalStateException(\"Cannot ship an order which has not been confirmed yet.\");\n }\n apply(new OrderShippedEvent(orderId));\n }\n\n @EventSourcingHandler\n public void on(final OrderPlacedEvent event) {\n log.debug(\"event: {}\", event);\n this.orderId = event.getOrderId();\n orderConfirmed = false;\n }\n\n @EventSourcingHandler\n public void on(final OrderConfirmedEvent event) {\n log.debug(\"event: {}\", event);\n orderConfirmed = true;\n }\n\n @EventSourcingHandler\n public void on(final OrderShippedEvent event) {\n log.debug(\"event: {}\", event);\n orderConfirmed = true;\n }\n\n protected OrderAggregate() {\n }\n\n}\n```\n\n```text\n/**\n * MessageListener implementation that deserializes incoming messages and forwards them to one or more event processors.\n * <p>\n * The SpringAMQPMessageSource must be registered with a Spring MessageListenerContainer and forwards each message\n * to all subscribed processors.\n * <p>\n * Note that the Processors must be subscribed before the MessageListenerContainer is started. Otherwise, messages will\n * be consumed from the AMQP Queue without any processor processing them.\n *\n * @author Allard Buijze\n * @since 3.0\n */\n```\n\n```text\nimport com.rabbitmq.client.Channel;\nimport lombok.extern.slf4j.Slf4j;\nimport org.axonframework.common.Registration;\nimport org.axonframework.eventhandling.EventMessage;\nimport org.axonframework.extensions.amqp.eventhandling.AMQPMessageConverter;\nimport org.axonframework.messaging.SubscribableMessageSource;\nimport org.springframework.amqp.core.Message;\nimport org.springframework.amqp.rabbit.annotation.RabbitListener;\nimport org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Component;\n\nimport java.util.Collections;\nimport java.util.List;\nimport java.util.concurrent.CopyOnWriteArrayList;\nimport java.util.function.Consumer;\n\n@Slf4j\n@Component\npublic class RabbitMQSpringAMQPMessageSource implements ChannelAwareMessageListener, SubscribableMessageSource<EventMessage<?>> {\n\n private final List<Consumer<List<? extends EventMessage<?>>>> eventProcessors = new CopyOnWriteArrayList<>();\n private final AMQPMessageConverter messageConverter;\n\n @Autowired\n public RabbitMQSpringAMQPMessageSource(final AMQPMessageConverter messageConverter) {\n this.messageConverter = messageConverter;\n }\n\n @Override\n public Registration subscribe(final Consumer<List<? extends EventMessage<?>>> messageProcessor) {\n eventProcessors.add(messageProcessor);\n log.debug(\"subscribe to: {}\", messageProcessor);\n return () -> eventProcessors.remove(messageProcessor);\n }\n\n @RabbitListener(queues = \"${application.queues.in}\")\n @Override\n public void onMessage(final Message message, final Channel channel) {\n log.debug(\"received external message: {}, channel: {}\", message, channel);\n log.debug(\"eventProcessors: {}\", eventProcessors);\n if (!eventProcessors.isEmpty()) {\n messageConverter.readAMQPMessage(message.getBody(), message.getMessageProperties().getHeaders())\n .ifPresent(event -> eventProcessors.forEach(\n ep -> ep.accept(Collections.singletonList(event))\n ));\n }\n }\n\n}\n```\n\n```text\neventProcessors: []\n```\n\n```text\n@Slf4j\n@Component(\"rabbitMQSpringAMQPMessageSource\")\npublic class RabbitMQSpringAMQPMessageSource extends SpringAMQPMessageSource {\n\n @Autowired\n public RabbitMQSpringAMQPMessageSource(final AMQPMessageConverter messageConverter) {\n super(messageConverter);\n }\n\n @RabbitListener(queues = \"${application.queues.in}\")\n @Override\n public void onMessage(final Message message, final Channel channel) {\n\n try {\n final var eventProcessorsField = this.getClass().getSuperclass().getDeclaredField(\"eventProcessors\");\n eventProcessorsField.setAccessible(true);\n final var eventProcessors = (List<Consumer<List<? extends EventMessage<?>>>>) eventProcessorsField.get(this);\n log.debug(\"eventProcessors: {}\", eventProcessors);\n } catch (NoSuchFieldException | IllegalAccessException e) {\n e.printStackTrace();\n }\n\n log.debug(\"received message: message={}, channel={}\", message, channel);\n super.onMessage(message, channel);\n }\n\n}\n```\n\n```text\naxon:\n eventhandling:\n processors:\n amqpEvents:\n source: rabbitMQSpringAMQPMessageSource\n mode: SUBSCRIBING\n```\n\n```text\n@Autowired\n void configure(EventProcessingModule epm,\n RabbitMQSpringAMQPMessageSource rabbitMessageSource) {\n epm.registerSubscribingEventProcessor(\"rabbitMQSpringAMQPMessageSource\", c -> rabbitMessageSource);\n epm.assignProcessingGroup(\"amqpEvents\", \"rabbitMQSpringAMQPMessageSource\");// this line also made no difference\n }\n```\n\n```text\naxon:\n eventhandling:\n processors:\n amqpEvents:\n source: rabbitMQSpringAMQPMessageSource\n mode: SUBSCRIBING\n```\n\n```text\nimport com.rabbitmq.client.Channel;\nimport lombok.extern.slf4j.Slf4j;\nimport org.axonframework.extensions.amqp.eventhandling.AMQPMessageConverter;\nimport org.axonframework.extensions.amqp.eventhandling.spring.SpringAMQPMessageSource;\nimport org.springframework.amqp.core.Message;\nimport org.springframework.amqp.rabbit.annotation.RabbitListener;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Component;\n\n@Slf4j\n@Component(\"rabbitMQSpringAMQPMessageSource\")\npublic class RabbitMQSpringAMQPMessageSource extends SpringAMQPMessageSource {\n\n @Autowired\n public RabbitMQSpringAMQPMessageSource(final AMQPMessageConverter messageConverter) {\n super(messageConverter);\n }\n\n @RabbitListener(queues = \"${application.queues.in}\")\n @Override\n public void onMessage(final Message message, final Channel channel) {\n log.debug(\"received message: message={}, channel={}\", message, channel);\n super.onMessage(message, channel);\n }\n\n}\n```\n\n```text\nimport lombok.extern.slf4j.Slf4j;\nimport org.axonframework.config.ProcessingGroup;\nimport org.axonframework.eventhandling.EventHandler;\nimport org.axonframework.queryhandling.QueryHandler;\nimport org.springframework.stereotype.Service;\nimport pm.mbo.easyway.api.app.order.events.OrderConfirmedEvent;\nimport pm.mbo.easyway.api.app.order.events.OrderPlacedEvent;\nimport pm.mbo.easyway.api.app.order.events.OrderShippedEvent;\n\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\n\n@Slf4j\n@ProcessingGroup(\"amqpEvents\")\n@Service\npublic class OrderedProductsEventHandler {\n\n private final Map<String, OrderedProduct> orderedProducts = new HashMap<>();\n\n @EventHandler\n public void on(OrderPlacedEvent event) {\n log.debug(\"event: {}\", event);\n String orderId = event.getOrderId();\n orderedProducts.put(orderId, new OrderedProduct(orderId, event.getProduct()));\n }\n\n @EventHandler\n public void on(OrderConfirmedEvent event) {\n log.debug(\"event: {}\", event);\n orderedProducts.computeIfPresent(event.getOrderId(), (orderId, orderedProduct) -> {\n orderedProduct.setOrderConfirmed();\n return orderedProduct;\n });\n }\n\n @EventHandler\n public void on(OrderShippedEvent event) {\n log.debug(\"event: {}\", event);\n orderedProducts.computeIfPresent(event.getOrderId(), (orderId, orderedProduct) -> {\n orderedProduct.setOrderShipped();\n return orderedProduct;\n });\n }\n\n @QueryHandler\n public List<OrderedProduct> handle(FindAllOrderedProductsQuery query) {\n log.debug(\"query: {}\", query);\n return new ArrayList<>(orderedProducts.values());\n }\n\n}\n```\n\n```text\nRabbitMQSpringAMQPMessageSource : received message: ... \nOrderedProductsEventHandler : event: OrderShippedEvent...\n```\n\n```text\nAxonConfig : received external message: (Body:'[B@13f7aeef(byte[167])' MessageProperties [headers={}, contentLength=0, receivedDeliveryMode=NON_PERSISTENT, redelivered=false, receivedExchange=, receivedRoutingKey=in.queue, deliveryTag=2, consumerTag=amq.ctag-xi34jwHHA__xjENSteX5Dw, consumerQueue=in.queue]), channel: Cached Rabbit Channel: AMQChannel(amqp://rabbit@127.0.0.1:5672/,1), conn: Proxy@11703cc8 Shared Rabbit Connection: SimpleConnection@581cb879 [delegate=amqp://rabbit@127.0.0.1:5672/, localPort= 58614]\n```\n\n```text\neventhandling:\n processors:\n amqpEvents:\n source: in.queue\n mode: subscribing\n```\n\n```text\neventhandling:\n processors:\n amqpEvents:\n source: inputMessageSource\n mode: subscribing\n```\n\n========================================\n\nComments:\n- Thx Allard! That helped. Found the mistake with source already, but changing the name didn't help too. My MessageSource was already correct but I was missing that Aggregates/EventSouringHandler don't receive messages from outside. And thinking about it, that makes absolute sense.Moving the annotation @ProcessingGroup(\"amqpEvents\") over a class with @EventHandler methods immediately worked.","metadata":{"transformedAt":"2026-08-18T18:33:20.193Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":16,"totalLines":753,"estimatedTokens":6202}}820{"id":"stack-45066315","source":"stackoverflow","questionId":45066315,"title":"Single Queue, multiple @RabbitListener but different services","tags":["rabbitmq","amqp","spring-amqp"],"text":"Title: Single Queue, multiple @RabbitListener but different services\nTags: rabbitmq, amqp, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nIs it possible to have a single @RabbitListener, e.g:\n\n```\n@RabbitListener(queues = STORAGE_REQUEST_QUEUE_NAME)\npublic FindApplicationByIdResponse findApplicationById(FindApplicationByIdRequest request) {\n return repository.findByUuid(request.getId())\n .map(e -> new FindApplicationByIdResponse(conversionService.convert(e, Application.class)))\n .orElse(new FindApplicationByIdResponse(null));\n}\n\n@RabbitListener(queues = STORAGE_REQUEST_QUEUE_NAME)\npublic PingResponse ping(PingRequest request) {\n return new PingResponse();\n}\n```\n\nAnd on the consumer side, it will send requests to the same request queue, but with different operations? Now it converts the objects from Json to a object (e.g.: FindApplicationByIdRequest, or PingRequest).\n\nBut now, when i get it back:\n\n```\n@Override\npublic FindApplicationByIdResponse findApplicationById(FindApplicationByIdRequest request) {\n Object object = template.convertSendAndReceive(Queues.STORAGE_REQUEST_QUEUE_NAME, request);\n return handleResponse(FindApplicationByIdResponse.class, object);\n}\n\n@Override\npublic PingResponse ping(PingRequest request) {\n Object object = template.convertSendAndReceive(Queues.STORAGE_REQUEST_QUEUE_NAME, request);\n return handleResponse(PingResponse.class, object);\n}\n```\n\nIt looks like it failed to correlate the two. So I call the ping method, then I get a FindApplicationByIdResponse back in that method.\nWhy is that?\n\nWhen I used different queues for them, it works fine. But I end up having to make a lot of queues to support all the RPC calls I wish to make.\nAnyone know if its possible to use the request type as a qualifier to which one it's going to use?\n\n========================================\n\nCode:\n```text\n@RabbitListener(queues = STORAGE_REQUEST_QUEUE_NAME)\npublic FindApplicationByIdResponse findApplicationById(FindApplicationByIdRequest request) {\n return repository.findByUuid(request.getId())\n .map(e -> new FindApplicationByIdResponse(conversionService.convert(e, Application.class)))\n .orElse(new FindApplicationByIdResponse(null));\n}\n\n@RabbitListener(queues = STORAGE_REQUEST_QUEUE_NAME)\npublic PingResponse ping(PingRequest request) {\n return new PingResponse();\n}\n```\n\n```text\n@Override\npublic FindApplicationByIdResponse findApplicationById(FindApplicationByIdRequest request) {\n Object object = template.convertSendAndReceive(Queues.STORAGE_REQUEST_QUEUE_NAME, request);\n return handleResponse(FindApplicationByIdResponse.class, object);\n}\n\n@Override\npublic PingResponse ping(PingRequest request) {\n Object object = template.convertSendAndReceive(Queues.STORAGE_REQUEST_QUEUE_NAME, request);\n return handleResponse(PingResponse.class, object);\n}\n```\n\n```text\n@RabbitListener(queues = STORAGE_REQUEST_QUEUE_NAME)\npublic class MultiListenerBean {\n\n @RabbitHandler\n public String bar(Bar bar) {\n ...\n }\n\n @RabbitHandler\n public String baz(Baz baz) {\n ...\n }\n\n @RabbitHandler\n public String qux(@Header(\"amqp_receivedRoutingKey\") String rk, @Payload Qux qux) {\n ...\n }\n\n}\n```\n\n```text\n@RabbitListener\n```\n\n```text\n@RabbitHandler\n```\n\n========================================\n\nComments:\n- Link is unfortunately broken.\n- Updated reference is docs.spring.io/spring-amqp/reference/amqp/receiving-messages‌​/…","metadata":{"transformedAt":"2026-08-18T18:33:20.193Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":111,"estimatedTokens":863}}821{"id":"stack-42895634","source":"stackoverflow","questionId":42895634,"title":"rabbitmq-server boot failed on mac os x el capitan","tags":["macos","rabbitmq","osx-elcapitan"],"text":"Title: rabbitmq-server boot failed on mac os x el capitan\nTags: macos, rabbitmq, osx-elcapitan\nSource: Stack Overflow\n\nQuestion:\nThis is my first time using rabbitmq.\n\nI installed rabbitmq through homebrew by \n\n```\nbrew update\nbrew install rabbitmq\n```\n\nthen I insert the path in my `.bash_profile` with\n\n```\nPATH=$PATH:/usr/local/sbin\n```\n\nI restart my terminal and type \n\n```\nrabbitmq-server\n```\n\nto start the server but the following error appeared\n\n```\nRabbitMQ 3.6.6. Copyright (C) 2007-2016 Pivotal Software, Inc.\n ## ## Licensed under the MPL. See http://www.rabbitmq.com/\n ## ##\n ########## Logs: /usr/local/var/log/rabbitmq/rabbit@localhost.log\n ###### ## /usr/local/var/log/rabbitmq/rabbit@localhost-sasl.log\n ##########\n Starting broker...\n\nBOOT FAILED\n===========\n\nError description:\n {could_not_start,rabbitmq_mqtt,\n {{shutdown,\n {failed_to_start_child,'rabbit_mqtt_listener_sup_:::1883',\n {shutdown,\n {failed_to_start_child,\n {ranch_listener_sup,{acceptor,{0,0,0,0,0,0,0,0},1883}},\n {shutdown,\n {failed_to_start_child,ranch_acceptors_sup,\n {listen_error,\n {acceptor,{0,0,0,0,0,0,0,0},1883},\n eaddrinuse}}}}}}},\n {rabbit_mqtt,start,[normal,[]]}}}\n\nLog files (may contain more information):\n /usr/local/var/log/rabbitmq/rabbit@localhost.log\n /usr/local/var/log/rabbitmq/rabbit@localhost-sasl.log\n\n{\"init terminating in do_boot\",{could_not_start,rabbitmq_mqtt,{{shutdown,{failed_to_start_child,'rabbit_mqtt_listener_sup_:::1883',{shutdown,{failed_to_start_child,{ranch_listener_sup,{acceptor,{0,0,0,0,0,0,0,0},1883}},{shutdown,{failed_to_start_child,ranch_acceptors_sup,{listen_error,{acceptor,{0,0,0,0,0,0,0,0},1883},eaddrinuse}}}}}}},{rabbit_mqtt,start,[normal,[]]}}}}\ninit terminating in do_boot ()\n\nCrash dump is being written to: erl_crash.dump...done\n```\n\nI run `rabbitmqctl status` and below is the result\n\n```\nStatus of node rabbit@localhost ...\nError: unable to connect to node rabbit@localhost: nodedown\n\nDIAGNOSTICS\n===========\n\nattempted to contact: [rabbit@localhost]\n\nrabbit@localhost:\n * connected to epmd (port 4369) on localhost\n * epmd reports: node 'rabbit' not running at all\n other nodes on localhost: ['rabbitmq-cli-77']\n * suggestion: start the node\n\ncurrent node details: \n- node name: 'rabbitmq-cli-77@Ling-Air'\n- home dir: /Users/Ling\n- cookie hash: 0YMYFZ/TBrgNjOy7lBAw4A==\n```\n\nWhat should I do? I already restarted my computer and reinstalling rabbitmq but that did not solved the problem.\n\nThank you for your help\n\n========================================\n\nCode:\n```text\nbrew update\nbrew install rabbitmq\n```\n\n```text\nPATH=$PATH:/usr/local/sbin\n```\n\n```text\nrabbitmq-server\n```\n\n```text\nRabbitMQ 3.6.6. Copyright (C) 2007-2016 Pivotal Software, Inc.\n ## ## Licensed under the MPL. See http://www.rabbitmq.com/\n ## ##\n ########## Logs: /usr/local/var/log/rabbitmq/rabbit@localhost.log\n ###### ## /usr/local/var/log/rabbitmq/rabbit@localhost-sasl.log\n ##########\n Starting broker...\n\n\nBOOT FAILED\n===========\n\nError description:\n {could_not_start,rabbitmq_mqtt,\n {{shutdown,\n {failed_to_start_child,'rabbit_mqtt_listener_sup_:::1883',\n {shutdown,\n {failed_to_start_child,\n {ranch_listener_sup,{acceptor,{0,0,0,0,0,0,0,0},1883}},\n {shutdown,\n {failed_to_start_child,ranch_acceptors_sup,\n {listen_error,\n {acceptor,{0,0,0,0,0,0,0,0},1883},\n eaddrinuse}}}}}}},\n {rabbit_mqtt,start,[normal,[]]}}}\n\nLog files (may contain more information):\n /usr/local/var/log/rabbitmq/rabbit@localhost.log\n /usr/local/var/log/rabbitmq/rabbit@localhost-sasl.log\n\n{\"init terminating in do_boot\",{could_not_start,rabbitmq_mqtt,{{shutdown,{failed_to_start_child,'rabbit_mqtt_listener_sup_:::1883',{shutdown,{failed_to_start_child,{ranch_listener_sup,{acceptor,{0,0,0,0,0,0,0,0},1883}},{shutdown,{failed_to_start_child,ranch_acceptors_sup,{listen_error,{acceptor,{0,0,0,0,0,0,0,0},1883},eaddrinuse}}}}}}},{rabbit_mqtt,start,[normal,[]]}}}}\ninit terminating in do_boot ()\n\nCrash dump is being written to: erl_crash.dump...done\n```\n\n```text\nStatus of node rabbit@localhost ...\nError: unable to connect to node rabbit@localhost: nodedown\n\nDIAGNOSTICS\n===========\n\nattempted to contact: [rabbit@localhost]\n\nrabbit@localhost:\n * connected to epmd (port 4369) on localhost\n * epmd reports: node 'rabbit' not running at all\n other nodes on localhost: ['rabbitmq-cli-77']\n * suggestion: start the node\n\ncurrent node details: \n- node name: 'rabbitmq-cli-77@Ling-Air'\n- home dir: /Users/Ling\n- cookie hash: 0YMYFZ/TBrgNjOy7lBAw4A==\n```\n\n```text\n.bash_profile\n```\n\n```text\nrabbitmqctl status\n```\n\n```text\neaddrinuse\n```\n\n```text\n1883\n```\n\n========================================\n\nComments:\n- right, thank you. There is mosquitto server using the port. I solved the problem by stopping the mosquitto server and restarting the rabbitmq","metadata":{"transformedAt":"2026-08-18T18:33:20.193Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":9,"totalLines":185,"estimatedTokens":1258}}822{"id":"stack-36089696","source":"stackoverflow","questionId":36089696,"title":"How to remove a topic when it has no subscribers?","tags":["java","rabbitmq","push-diffusion"],"text":"Title: How to remove a topic when it has no subscribers?\nTags: java, rabbitmq, push-diffusion\nSource: Stack Overflow\n\nQuestion:\nI am building a Diffusion solution that create a tree of topics. \n\nI am creating topics on demand to reflect values received from a RabbitMQ feed. Each topic has a memory cost, so I am looking to remove the topic once it has had no subscribers for some time.\n\nHow can this do done with unified Java API?\n\n========================================\n\nCode:\n```text\npublic TopicEventListenerClient() {\n session = Diffusion.sessions().principal(\"admin\").password(\"password\").open(\"ws://localhost:8080\");\n topicControl = session.feature(TopicControl.class);\n topicControl.addTopicEventListener(\"rabbitMQ/foo\", new TopicEventListener() {\n\n @Override\n public void onClose(String arg0) {\n LOG.info(\"Listener closed\");\n }\n\n @Override\n public void onError(String arg0, ErrorReason arg1) {\n LOG.info(\"Error on listener: \" + arg1);\n }\n\n @Override\n public void onRegistered(String arg0, Registration arg1) {\n LOG.info(\"Listener registered\");\n }\n\n @Override\n public void onHasSubscribers(String arg0) {\n LOG.info(\"Topic: \" + arg0 + \" has at least 1 subscriber\");\n }\n\n @Override\n public void onNoSubscribers(String arg0) {\n LOG.info(\"Topic: \" + arg0 + \" has no subscribers\");\n }\n });\n }\n```\n\n```text\nfinal Session session = Diffusion.sessions().principal(\"admin\").password(\"password\").open(\"ws://localhost:8080\");\n\nfinal TopicControl topicControl = session.feature(TopicControl.class);\n\nfinal TopicSpecification specification =\n topicControl.newSpecification(TopicType.JSON)\n .withProperty(TopicSpecification.REMOVAL, \"when subscriptions < 1 for 10s\");\n```\n\n========================================\n\nComments:\n- Remove from the original queue or from your tree? Also if you have already tried to write even a skeletal code, please add (by using edit) it to your question.\n- Thank you very much for such a quick response, that solved the issue!","metadata":{"transformedAt":"2026-08-18T18:33:20.193Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":63,"estimatedTokens":564}}823{"id":"stack-11264420","source":"stackoverflow","questionId":11264420,"title":"What does 0-9-1 stand for in AMQP 0-9-1 protocol","tags":["spring","rabbitmq","amqp","middleware","spring-amqp"],"text":"Title: What does 0-9-1 stand for in AMQP 0-9-1 protocol\nTags: spring, rabbitmq, amqp, middleware, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI couldnt find the exact logic behind 0-9-1 in the AMQP 0-9-1 protocol. Please someone explain it.\n\n========================================\n\nTop Answer:\nIt is the version 0.9.1.\n\n```\n\n```\n\n========================================\n\nCode:\n```text\nAMQP\nAdvanced Message Queuing Protocol\nProtocol Specification\nVersion 0-9-1, 13 November 2008\nA General-Purpose Messaging Standard\n```\n\n```text\n<amqp major=\"0\" minor=\"9\" revision=\"1\" port=\"5672\" comment=\"AMQ Protocol version 0-9-1\">\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.193Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":30,"estimatedTokens":157}}824{"id":"stack-73098023","source":"stackoverflow","questionId":73098023,"title":"What is cluster and node in RabbitMQ?","tags":["rabbitmq","nodes","concept"],"text":"Title: What is cluster and node in RabbitMQ?\nTags: rabbitmq, nodes, concept\nSource: Stack Overflow\n\nQuestion:\nAbout RabbitMQ two concept is unknow to me, `cluster` and `node` ? what is different between them?\n\n========================================\n\nCode:\n```text\ncluster\n```\n\n```text\nnode\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.193Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":17,"estimatedTokens":74}}825{"id":"stack-44865473","source":"stackoverflow","questionId":44865473,"title":"RabbitMQ with Arduino Uno","tags":["arduino","rabbitmq","arduino-uno","consumer","producer"],"text":"Title: RabbitMQ with Arduino Uno\nTags: arduino, rabbitmq, arduino-uno, consumer, producer\nSource: Stack Overflow\n\nQuestion:\nI'm using RabbitMQ with Arduino for the first time and I need to publish data. So I've used the PubSubCLient class. This is the code:\n\n```\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n//declare variables\nbyte mac[] = { 0xDE, 0xAD, 0xBE, 0xDE, 0xDE, 0xDD };\nbyte server[] = { 127, 0, 0, 1 };\nbyte ip[] = { 192, 168, 1, 22 };\nString stringone = \"localhost\";\n\nvoid callback(char* topic, byte* payload, unsigned int length) {\n Serial.println(topic);\n //convert byte to char\n payload[length] = '\\0';\n String strPayload = String((char*)payload);\n Serial.println(strPayload);\n int valoc = strPayload.lastIndexOf(',');\n String val = strPayload.substring(valoc+1);\n Serial.println(val);\n}\n\nEthernetClient ethClient;\nPubSubClient client(server, 5672, callback, ethClient);\n\nvoid setup() {\n // client is now configured for use\n Serial.begin(9600);\n Serial.println(\"==STARTING==\");\n if (Ethernet.begin(mac) == 0) {\n Serial.println(\"Failed to configure Ethernet using DHCP\");\n // no point in carrying on, so do nothing forevermore:\n // try to congifure using IP address instead of DHCP:\n Ethernet.begin(mac, ip);\n }\n // give the Ethernet shield a second to initialize:\n delay(1000);\n Serial.println(\"connecting...\");\n for (byte thisByte = 0; thisByte I keep getting an error, no connection. I think that's because I don't know how to use Arduino with RabbitMQ.\n\n========================================\n\nCode:\n```cpp\n#include <SPI.h>\n#include <PubSubClient.h>\n#include <Dhcp.h>\n#include <Ethernet.h>\n#include <EthernetUdp.h>\n#include <Dns.h>\n#include <EthernetServer.h>\n#include <EthernetClient.h>\n\n//declare variables\nbyte mac[] = { 0xDE, 0xAD, 0xBE, 0xDE, 0xDE, 0xDD };\nbyte server[] = { 127, 0, 0, 1 };\nbyte ip[] = { 192, 168, 1, 22 };\nString stringone = \"localhost\";\n\nvoid callback(char* topic, byte* payload, unsigned int length) {\n Serial.println(topic);\n //convert byte to char\n payload[length] = '\\0';\n String strPayload = String((char*)payload);\n Serial.println(strPayload);\n int valoc = strPayload.lastIndexOf(',');\n String val = strPayload.substring(valoc+1);\n Serial.println(val);\n}\n\nEthernetClient ethClient;\nPubSubClient client(server, 5672, callback, ethClient);\n\nvoid setup() {\n // client is now configured for use\n Serial.begin(9600);\n Serial.println(\"==STARTING==\");\n if (Ethernet.begin(mac) == 0) {\n Serial.println(\"Failed to configure Ethernet using DHCP\");\n // no point in carrying on, so do nothing forevermore:\n // try to congifure using IP address instead of DHCP:\n Ethernet.begin(mac, ip);\n }\n // give the Ethernet shield a second to initialize:\n delay(1000);\n Serial.println(\"connecting...\");\n for (byte thisByte = 0; thisByte < 4; thisByte++) {\n // print the value of each byte of the IP address:\n Serial.print(Ethernet.localIP()[thisByte], DEC);\n Serial.print(\".\");\n }\n boolean con = client.connect(\"arduinoMQTT123\");\n while(con != 1) {\n Serial.println(\"no con-while\");\n con = client.connect(\"arduinoMQTT123\");\n }\n if(con) {\n Serial.println(\"got con\");\n client.subscribe(\"/v2/feeds/FEED_ID.csv\");\n } else Serial.println(\"no con\");\n}\n\nvoid loop() {\n client.loop();\n}\n```\n\n```text\nbyte server[] = { 127, 0, 0, 1 };\n\n ...\n\n PubSubClient client(server, 5672, callback, ethClient);\n```\n\n========================================\n\nComments:\n- Is your machine/IDE connected to the Arduino?\n- Yes it's, i keep getting the no connection error on the arduino ide\n- I agree with you, it's just an example, i use the server's real ip address , but still no connection\n- And you installed the MQTT adapter and changed the port?\n- i change the server, to mosquitto and works just fine","metadata":{"transformedAt":"2026-08-18T18:33:20.193Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":135,"estimatedTokens":952}}826{"id":"stack-65621153","source":"stackoverflow","questionId":65621153,"title":"Connect to RabbitMQ instance remotely (created on AWS)","tags":["amazon-web-services","rabbitmq","python-pika"],"text":"Title: Connect to RabbitMQ instance remotely (created on AWS)\nTags: amazon-web-services, rabbitmq, python-pika\nSource: Stack Overflow\n\nQuestion:\nI'm having trouble connecting to a RabbitMQ instance (it's my first time doing so). I've spun one up on AWS, and been given access to an admin panel which I'm able to access.\n\nI'm trying to connect to the RabbitMQ server in python/pika with the following code:\n\n```\nimport pika\nimport logging\n\nlogging.basicConfig(level=logging.DEBUG)\n\ncredentials = pika.PlainCredentials('*******', '**********')\nparameters = pika.ConnectionParameters(host='a-25c34e4d-a3eb-32de-abfg-l95d931afc72f.mq.us-west-1.amazonaws.com',\n port=5671,\n virtual_host='/',\n credentials=credentials,\n )\n\nconnection = pika.BlockingConnection(parameters)\n```\n\nI get `pika.exceptions.IncompatibleProtocolError: StreamLostError: (\"Stream connection lost: ConnectionResetError(54, 'Connection reset by peer')\",)` when I run the above.\n\n========================================\n\nCode:\n```text\nimport pika\nimport logging\n\nlogging.basicConfig(level=logging.DEBUG)\n\ncredentials = pika.PlainCredentials('*******', '**********')\nparameters = pika.ConnectionParameters(host='a-25c34e4d-a3eb-32de-abfg-l95d931afc72f.mq.us-west-1.amazonaws.com',\n port=5671,\n virtual_host='/',\n credentials=credentials,\n )\n\nconnection = pika.BlockingConnection(parameters)\n```\n\n```text\npika.exceptions.IncompatibleProtocolError: StreamLostError: (\"Stream connection lost: ConnectionResetError(54, 'Connection reset by peer')\",)\n```\n\n```text\nimport ssl\n\nlogging.basicConfig(level=logging.DEBUG)\n\ncredentials = pika.PlainCredentials('*******', '**********')\ncontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)\nparameters = pika.ConnectionParameters(host='a-25c34e4d-a3eb-32de-abfg-l95d931afc72f.mq.us-west-1.amazonaws.com',\n port=5671,\n virtual_host='/',\n credentials=credentials,\n ssl_options=pika.SSLOptions(context)\n )\n\nconnection = pika.BlockingConnection(parameters)\n```\n\n========================================\n\nComments:\n- You can verify the following 1) Check whether the port 5671 is accessible (Need make sure security groups are managed properly for achieving this) 2) Version check (Make sure the python library version you are using supports the version of rabbitmq running on AWS)\n- This should be the accepted answer. Helped me fix the same issue. Thanks!","metadata":{"transformedAt":"2026-08-18T18:33:20.193Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":72,"estimatedTokens":672}}827{"id":"stack-42103859","source":"stackoverflow","questionId":42103859,"title":"what happens when message published on queue with no Subscriber?","tags":["rabbitmq","jms","message-queue","amqp","stomp"],"text":"Title: what happens when message published on queue with no Subscriber?\nTags: rabbitmq, jms, message-queue, amqp, stomp\nSource: Stack Overflow\n\nQuestion:\nthis was asked to me in an interview. \n\nwhat happens when message published on queue with no Subscriber at 10 AM? and a subscriber with proper filter subscribes at 10.02 AM to same Queue. Does the message gets delivered when a subscriber subscribes after the message has reached to the broker (I mean does it store in the memory until it finds the subscriber)? what is default behavior? also is it different in JMS, STOMP and AMQP standerds?\n\n========================================\n\nTop Answer:\nAs the question mentions about Publisher and Subscriber, I think the question is for Publish-Subscribe messaging pattern. In Pub/Sub pattern, publications are made to a topic, not queue.\n\nThe behavior depends on messaging provider. A messaging provider may discard a publication if there are no subscribers. So if a message was published to a topic at 10AM, the publication is discarded as there are no subscribers. Now when a new subscriber comes in 10:02AM, the publication will not be delivered to the subscriber.\n\nThere is a concept of \"Retain Publication\" in IBM MQ. When a publication has the \"Retain Publication\" attribute set, IBM MQ Queue Manager will keep a copy of such publication for a topic until a new publication is made for the same topic. Assuming a publication with \"Retain Publication\" is made at 10AM, when a subscriber comes at 10:02AM, the subscriber will get that publication.\n\nHope this helps.\n\n========================================\n\nComments:\n- Just found this on rabbitmq.com/stomp.html Queue destinations deliver each message to at most one subscriber. Messages sent when no subscriber exists will be queued until a subscriber connects to the queue.\n- Agree, messages might be published to topics or exchanges etc. But he is saying: \"when message published on queue \" - I assume the message has passed by exchanges and arrived successfully to the queue already.","metadata":{"transformedAt":"2026-08-18T18:33:20.193Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":25,"estimatedTokens":511}}828{"id":"stack-13641069","source":"stackoverflow","questionId":13641069,"title":"using default exchange in rabbitmq-c","tags":["c","client","exchange-server","default","rabbitmq"],"text":"Title: using default exchange in rabbitmq-c\nTags: c, client, exchange-server, default, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am trying to connect to rabbitmq-c in centos 5.6 and test its function in c client following the steps of the website: http://www.rabbitmq.com/tutorials/tutorial-one-java.html.\nHowever, it fails when I use the default exchange. \n\nFor example, I want to send a message, \"Hello world\", to a queue named \"myqueue\" via the default exchange whose name is \"(AMQP default)\".\n\nIn java, here is the code:\n\n```\nchannel.basicPublish(\"\", QUEUE_NAME, null, message.getBytes());\n```\n\nBut in c, when I run rmq_new_task.c (almost the same as amqp_sendstring.c) as the examples on https://github.com/liuhaobupt/rabbitmq_work_queues_demo-with-rabbit-c-client-lib.\n\n```\nqueuename=\"myqueue\";\n......\ndie_on_error(amqp_basic_publish(conn, amqp_cstring_bytes(exchange),\n amqp_cstring_bytes(routingkey), &props, amqp_cstring_bytes(\"Hello world\")),\n \"Publishing\");\n```\n\nIn the java client, we just set the parameter \"exchange\" to \"\" to tell the server that we'd send the message to a specified queue named the same as routingkey via the default exchange. \n\nSo what value should I give the second parameter \"exchange\" in c client (using the default exchange)? I tried to set it to \"\" or \"amq.direct\". It didnot show any error while running and seemed working well. \n\nHowever, when I checked in the rabbitmq-management(http://localhost:55672/#/queues), the queue named \"myqueue\" did not exist!\n\nWould someone please point me to the right direction? I'd really appreciate!\n\n========================================\n\nCode:\n```text\nchannel.basicPublish(\"\", QUEUE_NAME, null, message.getBytes());\n```\n\n```text\nqueuename=\"myqueue\";\n......\ndie_on_error(amqp_basic_publish(conn, amqp_cstring_bytes(exchange),\n amqp_cstring_bytes(routingkey), &props, amqp_cstring_bytes(\"Hello world\")),\n \"Publishing\");\n```\n\n```text\nchannel.basicPublish(\"\", \"hello\", null, message.getBytes());\n```\n\n```text\n\"\"\n```\n\n```text\namq.direct\n```\n\n========================================\n\nComments:\n- Have you actually created the queue? as just publishing into the default exchange won't create it for you...\n- Thanks for your comment. But here says,\" The first parameter is the the name of the exchange. The empty string denotes the default or nameless exchange: messages are routed to the queue with the name specified by routingKey, if it exists.\" Did I misunderstand it?","metadata":{"transformedAt":"2026-08-18T18:33:20.193Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":66,"estimatedTokens":614}}829{"id":"stack-20516450","source":"stackoverflow","questionId":20516450,"title":"Ridiculously slow simultaneous publish/consume rate with RabbitMQ","tags":["rabbitmq","amqp"],"text":"Title: Ridiculously slow simultaneous publish/consume rate with RabbitMQ\nTags: rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI'm evaluating RabbitMQ and while the general impression (of AMQP as such, and also RabbitMQ) is positive, I'm not very impressed by the result.\n\nI'm attempting to publish and consume messages simultaneously and have achieved very poor message rates. I have a durable direct exchange, which is bound to a durable queue and I publish persistent messages to that exchange. The average size of the message body is about 1000 bytes.\n\nMy publishing happens roughly as follows:\n\n```\nAMQP.BasicProperties.Builder bldr = new AMQP.BasicProperties.Builder();\nConnectionFactory factory = new ConnectionFactory();\nfactory.setUsername(\"guest\");\nfactory.setPassword(\"guest\");\nfactory.setVirtualHost(\"/\");\nfactory.setHost(\"my-host\");\nfactory.setPort(5672);\nConnection conn = null;\nChannel channel = null;\nObjectMapper mapper = new ObjectMapper(); //com.fasterxml.jackson.databind.ObjectMapper\ntry {\n conn = factory.newConnection();\nchannel = conn.createChannel();\n channel.confirmSelect();\n} catch (IOException e) {}\n\nfor(Message m : messageList) { //the size of messageList happens to be 9945\n try {\n channel.basicPublish(\"exchange\", \"\", bldr.deliveryMode(2).contentType(\"application/json\").build(), mapper.writeValueAsBytes(cm));\n } catch (Exception e) {}\n}\ntry {\n channel.waitForConfirms();\n channel.close();\nconn.close();\n} catch (Exception e1) {}\n```\n\nAnd consuming messages from the bound queue happens as so:\n\n```\nAMQP.BasicProperties.Builder bldr = new AMQP.BasicProperties.Builder();\nConnectionFactory factory = new ConnectionFactory();\nfactory.setUsername(\"guest\");\nfactory.setPassword(\"guest\");\nfactory.setVirtualHost(\"/\");\nfactory.setHost(\"my-host\");\nfactory.setPort(5672);\nConnection conn = null;\nChannel channel = null;\ntry {\n conn = factory.newConnection();\n channel = conn.createChannel();\n channel.basicQos(100);\n while (true) {\n GetResponse r = channel.basicGet(\"rawDataQueue\", false);\n if(r!=null)\n channel.basicAck(r.getEnvelope().getDeliveryTag(), false);\n }\n} catch (IOException e) {}\n```\n\nThe problem is that when the message publisher (or several of them) and consumer (or several of them) run simultaneously then the publisher(s) appear to run at full throttle and the RabbitMQ management web interface shows a publishing rate of, say, ~2...3K messages per second, but a consumption rate of 0.5...3 per consumer. When the publisher(s) finish then I get a consumption rate of, say, 300...600 messages per consumer. When not setting the QOS prefetch value for the Java client, then a little less, when setting it to 100 or 250, then a bit more.\n\nWhen experimenting with throttling the consumers somewhat, I have managed to achieve simultaneous numbers like ~400 published and ~50 consumed messages per second which is marginally better but only marginally.\n\nHere's, a quote from the RabbitMQ blog entry which claims that queues are fastest when they're empty which very well may be, but slowing the consumption rate to a crawl when there are a few thousand persistent messages sitting in the queue is still rather unacceptable.\n\nHigher QOS prefetching values may help a bit but are IMHO not a solution as such.\n\nWhat, if anything, can be done to achieve reasonable throughput rates (2 consumed messages per consumer per second is not reasonable in any circumstance)? This is only a simple one direct exchange - one binding - one queue situation, should I expect more performance degradation with more complicated configurations? When searching around the internet there have also been suggestions to drop durability, but I'm afraid in my case that is not an option. I'd be very happy if somebody would point out that I'm stupid and that there is an evident and straightforward solution of some kind :)\n\n========================================\n\nTop Answer:\nOperating system could schedule your process to the next time slot, if `sleep` is used. This could create significant performance decrease.\n\n========================================\n\nCode:\n```text\nAMQP.BasicProperties.Builder bldr = new AMQP.BasicProperties.Builder();\nConnectionFactory factory = new ConnectionFactory();\nfactory.setUsername(\"guest\");\nfactory.setPassword(\"guest\");\nfactory.setVirtualHost(\"/\");\nfactory.setHost(\"my-host\");\nfactory.setPort(5672);\nConnection conn = null;\nChannel channel = null;\nObjectMapper mapper = new ObjectMapper(); //com.fasterxml.jackson.databind.ObjectMapper\ntry {\n conn = factory.newConnection();\nchannel = conn.createChannel();\n channel.confirmSelect();\n} catch (IOException e) {}\n\nfor(Message m : messageList) { //the size of messageList happens to be 9945\n try {\n channel.basicPublish(\"exchange\", \"\", bldr.deliveryMode(2).contentType(\"application/json\").build(), mapper.writeValueAsBytes(cm));\n } catch (Exception e) {}\n}\ntry {\n channel.waitForConfirms();\n channel.close();\nconn.close();\n} catch (Exception e1) {}\n```\n\n```text\nAMQP.BasicProperties.Builder bldr = new AMQP.BasicProperties.Builder();\nConnectionFactory factory = new ConnectionFactory();\nfactory.setUsername(\"guest\");\nfactory.setPassword(\"guest\");\nfactory.setVirtualHost(\"/\");\nfactory.setHost(\"my-host\");\nfactory.setPort(5672);\nConnection conn = null;\nChannel channel = null;\ntry {\n conn = factory.newConnection();\n channel = conn.createChannel();\n channel.basicQos(100);\n while (true) {\n GetResponse r = channel.basicGet(\"rawDataQueue\", false);\n if(r!=null)\n channel.basicAck(r.getEnvelope().getDeliveryTag(), false);\n }\n} catch (IOException e) {}\n```\n\n```text\nbasicConsume\n```\n\n```text\nbasicGet\n```\n\n```text\nsleep\n```\n\n========================================\n\nComments:\n- How should I determine if the broker applies any flow control? The average message size is 1000-something bytes in the body, plus probably < 64B in headers. basicConsume vs basicGet is something I have to try. Thanks!\n- OK, using QueueingConsumer with explicit acknowledgements I achieve rates of about 2500 pubs/250 subs simultaneously, which is a lot better than before, but not perfect.\n- Can you try again removing the `channel.confirmSelect();` and `channel.waitForConfirms();` from your publishing code?\n- Did so and achieved spikes of 12+K msgs/sec for publishing and 900...2.5K for consuming. The results are, however, distorted by the fact that the queue sits on the other end of a 100M network link and that seemed to be saturated by the publishers.\n- Ok, now that was a clue that led somewhere: when I installed and ran the MQ from my dev machine where the producers and consumer were running, I achieved simultaneous publish/consumption rates of about 2K msg/sec.","metadata":{"transformedAt":"2026-08-18T18:33:20.193Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":153,"estimatedTokens":1679}}830{"id":"stack-7711528","source":"stackoverflow","questionId":7711528,"title":"RabbitMQ - Statistics database could not be contacted. Message rates and queue lengths will not be shown","tags":["rabbitmq"],"text":"Title: RabbitMQ - Statistics database could not be contacted. Message rates and queue lengths will not be shown\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have setup a cluster of rabbit brokers and within the management portal plugin I get the following message\n\n\"Statistics database could not be contacted. Message rates and queue lengths will not be shown\"\n\nI have searched for this error but google is not being kind. Can anyone shed any light on this?\n\n========================================\n\nTop Answer:\nI had the same problem recently on an old installation of RabbitMQ (2.8.7) and found that there was no solution in this question. I found that to restart the statistics database, you can execute:\n\nrabbitmqctl eval 'application:stop(rabbitmq_management), application:start(rabbitmq_management).'\n\n(Source: http://en.it-usenet.org/thread/15496/19206/#post19199)\n\n========================================\n\nComments:\n- We are seeing this as well with 2.6.1.\n- We've seen this too. I think it happens when you shut down the statistics node, then rabbit fails it over to node-n, but you shut down node-n before the fail-over completes.\n- I'm still seeing this issue with 2.8.7 with a newly created cluster of 4 nodes.\n- Was there ever a bug report made for this? I had a network partition that resulted in the same issue in version 3.6.6.\n- This is awesome. It saved my on an older RabbitMQ cluster (where rabbitmqctl reset_stats_db command is not available)","metadata":{"transformedAt":"2026-08-18T18:33:20.193Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":28,"estimatedTokens":368}}831{"id":"stack-42932238","source":"stackoverflow","questionId":42932238,"title":"Can I use UsePartitioner in the endpoint configuration in mass transit to partition multiple message types that are delivered to the same queue","tags":["rabbitmq","masstransit"],"text":"Title: Can I use UsePartitioner in the endpoint configuration in mass transit to partition multiple message types that are delivered to the same queue\nTags: rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nI'm using masstransit and rabbitmq. My queue has messages of various types delivered to it. Most of these types implement IHaveOrganisationKey. I would like to add a partitioner to the pipeline to ensure that only one message (of any type) with a given organisationkey is processed at the same time. The goal is to limit concurrency problems that occur when multiple messages of the same organisation are processed in parallel, while allowing parallel processing of messages from different organisations.\n\nConfiguration code\n\n```\nsbc.ReceiveEndpoint(host, this.queueConfiguration.QueueName, ep =>\n{\n ep.PrefetchCount = this.busConfiguration.PrefetchCount;\n this.queueConfiguration.ConfigureEndpoint(ep);\n this.queueConfiguration.SubscribeMessages(worker, ep);\n});\n```\n\nIn the QueueConfiguration:\n\n```\npublic override void ConfigureEndpoint(IRabbitMqReceiveEndpointConfigurator ep)\n{\n // This is incomplete. Am I on the right track here?\n ep.UsePartitioner(1, x => x.TryGetMessage());\n}\n```\n\n========================================\n\nCode:\n```text\nsbc.ReceiveEndpoint(host, this.queueConfiguration.QueueName, ep =>\n{\n ep.PrefetchCount = this.busConfiguration.PrefetchCount;\n this.queueConfiguration.ConfigureEndpoint(ep);\n this.queueConfiguration.SubscribeMessages(worker, ep);\n});\n```\n\n```text\npublic override void ConfigureEndpoint(IRabbitMqReceiveEndpointConfigurator ep)\n{\n // This is incomplete. Am I on the right track here?\n ep.UsePartitioner(1, x => x.TryGetMessage<IHaveOrganisationKey>());\n}\n```\n\n```text\nvar p = ep.CreatePartitioner(8);\n\nep.Consumer<ConsumerA>(x => x.Message<A>(m => m.UsePartitioner(p, c => c.Message.OrgKey)));\nep.Consumer<ConsumerB>(x => x.Message<B>(m => m.UsePartitioner(p, c => c.Message.OrgKey)));\n```\n\n```text\nMessage\n```\n\n========================================\n\nComments:\n- Cheers, Chris! At first I assumed that the partitionCount parameter passed to CreatePartitioner refrered to the number of messages per partition. I now understand that this acts as a global concurrency limit, and that the number of messages for a single partition is always one.","metadata":{"transformedAt":"2026-08-18T18:33:20.193Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":63,"estimatedTokens":580}}832{"id":"stack-31750966","source":"stackoverflow","questionId":31750966,"title":"rabbitmq filter work queue","tags":["python","rabbitmq"],"text":"Title: rabbitmq filter work queue\nTags: python, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have been reading through the rabbitMQ tutorials and I was looking for some help regarding a setup I should use.\n\nI have a list of tasks 1-50 which I want run once (and only once) on a set of 4 computers, each running a worker. I have set up a template similar to tutorial 2 at https://www.rabbitmq.com/tutorials/tutorial-two-python.html\n\nNot all of the computers can run all of the tasks (they haven't all got the software installed)\n\nWhat I am trying to achieve is the setup that allows the tasks sent to a worker to be filtered.\n\nI read the tutorials on how to achieve this in a broadcast situation using routes however didn't quite grasp what I would need to do to map this back to a simpler push model similar to tutorial 2 (as I don't want to broadcast the jobs).\n\nAt some point down the line I would like to be able to scale the number of workers on each box dynamically based on load as well.\n\nWhat is the best model I should use and are there any good tutorials or write up's that you can recommend to learn about this approach?\n\nCheers,\nRob\n\n========================================\n\nCode:\n```text\n| exchange | routing key | queue |\n| -------- | ----------- | ----- |\n| jobs | job.a | job.a |\n| jobs | job.b | job.b |\n| jobs | job.c | job.c |\n```\n\n```text\nnack\n```\n\n```text\nnack\n```\n\n========================================\n\nComments:\n- Thank you for such a detailed and well explained answer, makes sense and I will take that approach then :) Nice link too ^^","metadata":{"transformedAt":"2026-08-18T18:33:20.193Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":45,"estimatedTokens":399}}833{"id":"stack-17655559","source":"stackoverflow","questionId":17655559,"title":"Set max number of messages in the queue","tags":["python","rabbitmq","queue","pika"],"text":"Title: Set max number of messages in the queue\nTags: python, rabbitmq, queue, pika\nSource: Stack Overflow\n\nQuestion:\nI'm wondering is it possible to set the max number of messages in the queue?\n\nLet's say I want to have no more than 100 msgs in queue Foo, is it possible to do?\n\n========================================\n\nTop Answer:\nDo it like this and be happy!\n\n```\nimport pika\n\nQUEUE_SIZE = 5\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))\nchannel = connection.channel()\n\nchannel.queue_declare(\n queue='ids_queue',\n arguments={'x-max-length': QUEUE_SIZE}\n)\n```\n\nHere in **arguments** you will also need to track **queue overflow behaviour** for your queue.\n\n========================================\n\nCode:\n```text\nchannel.queue_declare\n```\n\n```text\narguments\n```\n\n```text\nimport pika\n\n\nQUEUE_SIZE = 5\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))\nchannel = connection.channel()\n\nchannel.queue_declare(\n queue='ids_queue',\n arguments={'x-max-length': QUEUE_SIZE}\n)\n```\n\n========================================\n\nComments:\n- Thank you, I tried it, it works, but I'm not satisfied with one thing: `\"Messages will be dropped or dead-lettered from the front of the queue to make room for new messages once the limit is reached.\"`. Do you know how to throw an exception if queue is full? Because it's silently overrides messages, for example if limit set to 10, and I publish 15 messages [0 - 14], I only get msgs from 5 to 14. With out any warnings, that 5 messages where lost\n- There are no chances to get messages number in queue (unless you are using admin plugin) nor throw an exception when queue is full. It looks like that you don't need RabbitMQ for this task.\n- @Vor you can set a exchange for dealing \"dead-lettered message\", according to rabbitmq.com/dlx.html . This method will not throw an exception, but you can write some kind of code the deal with it when you received the \"dead-lettered message\" for the exchange, like making a warning.","metadata":{"transformedAt":"2026-08-18T18:33:20.193Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":62,"estimatedTokens":505}}834{"id":"stack-47748187","source":"stackoverflow","questionId":47748187,"title":"RabbitMQ Exchange and Queue are not created automatically","tags":["java","rabbitmq","spring-amqp","spring-rabbit"],"text":"Title: RabbitMQ Exchange and Queue are not created automatically\nTags: java, rabbitmq, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI have created a new spring application which will push messages to a rabbitmq server.\nMy rabbitMQConfig java file looks like this : \n\n```\n@Configuration\npublic class RabbitMQConfig {\n\n private static final Logger LOGGER = LoggerFactory.getLogger(RabbitMQConfig.class);\n\n @Value(\"${spring.rabbitmq.host}\")\n private String SPRING_RABBITMQ_HOST;\n\n @Value(\"${spring.rabbitmq.port}\")\n private int SPRING_RABBITMQ_PORT;\n\n @Value(\"${spring.rabbitmq.username}\")\n private String SPRING_RABBITMQ_USERNAME;\n\n @Value(\"${spring.rabbitmq.password}\")\n private String SPRING_RABBITMQ_PASSWORD;\n\n @Bean\n public RabbitTemplate rabbitTemplate(){\n CachingConnectionFactory connectionFactory = new CachingConnectionFactory(SPRING_RABBITMQ_HOST,SPRING_RABBITMQ_PORT);\n connectionFactory.setUsername(SPRING_RABBITMQ_USERNAME);\n connectionFactory.setPassword(SPRING_RABBITMQ_PASSWORD);\n RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);\n rabbitTemplate.setExchange(\"my.controller.exchange\");\n rabbitTemplate.setRoutingKey(\"my.controller.key\");\n return rabbitTemplate;\n }\n\n @Bean\n DirectExchange exchange() {\n return new DirectExchange(\"my.controller.exchange\", true, false);\n }\n\n @Bean\n public Queue queue() {\n return new Queue(\"my.controller\", true);\n }\n\n @Bean\n Binding exchangeBinding(DirectExchange exchange, Queue queue) {\n return BindingBuilder.bind(queue).to(exchange).with(\"my.controller.key\");\n }\n}\n```\n\nHere is how I push message to the queue : \n\n```\n@Service\npublic class RabbitPublisher {\n\n @Autowired\n private RabbitTemplate rabbitTemplate;\n\n private static Logger LOGGER = Logger.getLogger(RabbitPublisher.class);\n\n public Boolean pushToMyQueue(HashMap message) {\n try {\n rabbitTemplate.convertAndSend(\"my.controller.exchange\",\"my.controller.key\",message);\n return true;\n } catch (Exception e) {\n e.printStackTrace();\n LOGGER.error(\"Error in pushing to my queue\", e);\n }\n return false;\n }\n}\n```\n\nSince the exchange and queue are non-existent on the rabbitmq server, I expect them to be created automatically and message to be pushed. But it results in the following error : \n\n```\nERROR 18198 --- [168.201.18:5672] o.s.a.r.c.CachingConnectionFactory : \nChannel shutdown: channel error; protocol method: #method\n(reply-code=404, reply-text=NOT_FOUND - no exchange \n'my.controller.exchange' in vhost '/', class-id=60, method-id=40)\n```\n\nWhen I create the exchange and queue and bind them manually on the server, a message gets pushed successfully.\nPlease let me know if I am missing something. Thanks.\n\n========================================\n\nTop Answer:\nYou have to add AmqpAdmin admin bean with your required connection factory as below:\n\n```\n@Bean(name = \"pimAmqpAdmin\")\n public AmqpAdmin pimAmqpAdmin(@Qualifier(\"defaultConnectionFactory\") ConnectionFactory connectionFactory) {\n return new RabbitAdmin(connectionFactory);\n }\n```\n\n========================================\n\nCode:\n```text\n@Configuration\npublic class RabbitMQConfig {\n\n private static final Logger LOGGER = LoggerFactory.getLogger(RabbitMQConfig.class);\n\n @Value(\"${spring.rabbitmq.host}\")\n private String SPRING_RABBITMQ_HOST;\n\n @Value(\"${spring.rabbitmq.port}\")\n private int SPRING_RABBITMQ_PORT;\n\n @Value(\"${spring.rabbitmq.username}\")\n private String SPRING_RABBITMQ_USERNAME;\n\n @Value(\"${spring.rabbitmq.password}\")\n private String SPRING_RABBITMQ_PASSWORD;\n\n @Bean\n public RabbitTemplate rabbitTemplate(){\n CachingConnectionFactory connectionFactory = new CachingConnectionFactory(SPRING_RABBITMQ_HOST,SPRING_RABBITMQ_PORT);\n connectionFactory.setUsername(SPRING_RABBITMQ_USERNAME);\n connectionFactory.setPassword(SPRING_RABBITMQ_PASSWORD);\n RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);\n rabbitTemplate.setExchange(\"my.controller.exchange\");\n rabbitTemplate.setRoutingKey(\"my.controller.key\");\n return rabbitTemplate;\n }\n\n @Bean\n DirectExchange exchange() {\n return new DirectExchange(\"my.controller.exchange\", true, false);\n }\n\n @Bean\n public Queue queue() {\n return new Queue(\"my.controller\", true);\n }\n\n @Bean\n Binding exchangeBinding(DirectExchange exchange, Queue queue) {\n return BindingBuilder.bind(queue).to(exchange).with(\"my.controller.key\");\n }\n}\n```\n\n```text\n@Service\npublic class RabbitPublisher {\n\n @Autowired\n private RabbitTemplate rabbitTemplate;\n\n private static Logger LOGGER = Logger.getLogger(RabbitPublisher.class);\n\n public Boolean pushToMyQueue(HashMap<String, Object> message) {\n try {\n rabbitTemplate.convertAndSend(\"my.controller.exchange\",\"my.controller.key\",message);\n return true;\n } catch (Exception e) {\n e.printStackTrace();\n LOGGER.error(\"Error in pushing to my queue\", e);\n }\n return false;\n }\n}\n```\n\n```text\nERROR 18198 --- [168.201.18:5672] o.s.a.r.c.CachingConnectionFactory : \nChannel shutdown: channel error; protocol method: #method<channel.close>\n(reply-code=404, reply-text=NOT_FOUND - no exchange \n'my.controller.exchange' in vhost '/', class-id=60, method-id=40)\n```\n\n```text\n@Bean(name = \"pimAmqpAdmin\")\n public AmqpAdmin pimAmqpAdmin(@Qualifier(\"defaultConnectionFactory\") ConnectionFactory connectionFactory) {\n return new RabbitAdmin(connectionFactory);\n }\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.193Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":186,"estimatedTokens":1381}}835{"id":"stack-23013249","source":"stackoverflow","questionId":23013249,"title":"Celery / RabbitMQ - Find out the No Acks - Unacknowledged messages","tags":["rabbitmq","celery","django-celery"],"text":"Title: Celery / RabbitMQ - Find out the No Acks - Unacknowledged messages\nTags: rabbitmq, celery, django-celery\nSource: Stack Overflow\n\nQuestion:\nI am trying to figure out how to get information on unacknowledged messages. Where are these stored? In playing with celery inspect it seems that once a message gets acknowledged it processes through and you can the state. Assuming you have a results backend then you can see the results of it. But from the time you apply delay until it get's acknowledged it's in a black hole.\n\n- Where are noAcks stored?\n\n- How do I find out how \"deep\" is the noAcks list? In other words how many are there and where is my task in the list.\n\nWhile not exactly germane to the problem here is what I'm working with.\n\n```\nfrom celery.app import app_or_default\n\napp = app_or_default()\ninspect = app.control.inspect()\n\n# Now if I want \"RECEIVED\" jobs.. \ndata = inspect.reserved()\n\n# or \"ACTIVE\" jobs.. \ndata = inspect.active()\n\n# or \"REVOKED\" jobs.. \ndata = inspect.revoked()\n\n# or scheduled jobs.. (Assuming these are time based??)\ndata = inspect.scheduled()\n\n# FILL ME IN FOR UNACK JOBS!!\n# data = inspect.??\n\n# This will never work for tasks that aren't in one of the above buckets..\npprint.pprint(inspect.query_task([tasks]))\n```\n\nI really appreciate your advice and help on this.\n\n========================================\n\nTop Answer:\nAfter hours of reviewing celery I've come to the conclusion that it's just not possible using pure celery. However it is possible to loosely track the entire process. Here is the code I used to look up the unacknowledged count. Most of this can be done using the utilities in celery.\n\n**I still am unable to query the underlying unacknowledged tasks by id but..**\n\nIf you have the RabbitMQ management plug-in installed you can query the API \n\n```\ndata = {}\n base_url = \"http://localhost:55672\"\n url = base_url + \"/api/queues/{}/\".format(vhost)\n req = requests.get(url, auth=(settings.RABBITMQ_USER, settings.RABBITMQ_PASSWORD))\n if req.status_code != 200:\n log.error(req.text)\n else:\n request_data = req.json()\n for queue in request_data:\n # TODO if we know what queue the task is then we can nail this.\n if queue.get('name') == \"celery\":\n data['state'] = \"Unknown\"\n if queue.get('messages'):\n data['messages'] = queue.get('messages')\n data['messages_ready'] = queue.get('messages_ready')\n data['messages_unacknowledged'] = queue.get('messages_unacknowledged')\n break\n return data\n```\n\n========================================\n\nCode:\n```text\nfrom celery.app import app_or_default\n\napp = app_or_default()\ninspect = app.control.inspect()\n\n# Now if I want \"RECEIVED\" jobs.. \ndata = inspect.reserved()\n\n# or \"ACTIVE\" jobs.. \ndata = inspect.active()\n\n# or \"REVOKED\" jobs.. \ndata = inspect.revoked()\n\n# or scheduled jobs.. (Assuming these are time based??)\ndata = inspect.scheduled()\n\n# FILL ME IN FOR UNACK JOBS!!\n# data = inspect.??\n\n# This will never work for tasks that aren't in one of the above buckets..\npprint.pprint(inspect.query_task([tasks]))\n```\n\n```text\nfrom celery.app import app_or_default\n\napp = app_or_default()\ninspect = app.control.inspect()\n\n# those that have been sent to a worker and are thus reserved\n# from being sent to another worker, but may or may not be acknowledged as received by that worker\ndata = inspect.reserved()\n\n{'celery.tasks': [{'acknowledged': False,\n 'args': '[]',\n 'delivery_info': {'exchange': 'tasks',\n 'priority': None,\n 'routing_key': 'celery'},\n 'hostname': 'celery.tasks',\n 'id': '527961d4-639f-4002-9dc6-7488dd8c8ad8',\n 'kwargs': '{}',\n 'name': 'globalapp.tasks.task_loop_tick',\n 'time_start': None,\n 'worker_pid': None},\n {'acknowledged': False,\n 'args': '[]',\n 'delivery_info': {'exchange': 'tasks',\n 'priority': None,\n 'routing_key': 'celery'},\n 'hostname': 'celery.tasks',\n 'id': '09d5b726-269e-48d0-8b0e-86472d795906',\n 'kwargs': '{}',\n 'name': 'globalapp.tasks.task_loop_tick',\n 'time_start': None,\n 'worker_pid': None},\n {'acknowledged': False,\n 'args': '[]',\n 'delivery_info': {'exchange': 'tasks',\n 'priority': None,\n 'routing_key': 'celery'},\n 'hostname': 'celery.tasks',\n 'id': 'de6d399e-1b37-455c-af63-a68078a9cf7c',\n 'kwargs': '{}',\n 'name': 'globalapp.tasks.task_loop_tick',\n 'time_start': None,\n 'worker_pid': None}],\n 'fastlane.tasks': [],\n 'images.tasks': [],\n 'mailer.tasks': []}\n```\n\n```text\ninspect.reserved()\n```\n\n```text\n'acknowleged': False\n```\n\n```text\ndata = {}\n base_url = \"http://localhost:55672\"\n url = base_url + \"/api/queues/{}/\".format(vhost)\n req = requests.get(url, auth=(settings.RABBITMQ_USER, settings.RABBITMQ_PASSWORD))\n if req.status_code != 200:\n log.error(req.text)\n else:\n request_data = req.json()\n for queue in request_data:\n # TODO if we know what queue the task is then we can nail this.\n if queue.get('name') == \"celery\":\n data['state'] = \"Unknown\"\n if queue.get('messages'):\n data['messages'] = queue.get('messages')\n data['messages_ready'] = queue.get('messages_ready')\n data['messages_unacknowledged'] = queue.get('messages_unacknowledged')\n break\n return data\n```\n\n========================================\n\nComments:\n- Nice - Where is this documented?\n- I just started from your code and then noticed that the unacked ones were in reserved. yesterday I discovered that if you install celery 3.0.11 it will install billiard 3.x which doesn't actually work with celery 3.0; so the tasks were not acknowledging and had no start time. billiard < 3 works. moral of the story: always pin or freeze your dependencies.\n- This is great. Thanks I don't know why I didn't see or think of this earlier this earlier. Can you confirm if this working with Celery 3.1x (Current)?\n- celery is a confusing mess of options, documentations, multiple methods of doing things and many many versions. no idea if it works on 3.1 sorry :)","metadata":{"transformedAt":"2026-08-18T18:33:20.193Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":182,"estimatedTokens":1623}}836{"id":"stack-79059006","source":"stackoverflow","questionId":79059006,"title":"error: PermissionError(13, 'Access is denied', None, 5, None)","tags":["django","asynchronous","rabbitmq","celery"],"text":"Title: error: PermissionError(13, 'Access is denied', None, 5, None)\nTags: django, asynchronous, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI have this error while working with celery\n\n```\n[2024-10-06 14:38:15,464: ERROR/SpawnPoolWorker-3] Pool process error: PermissionError(13, 'Access is denied', None, 5, None)\nTraceback (most recent call last):\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 473, in receive\n ready, req = _receive(1.0)\n ^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 445, in _recv\n return True, loads(get_payload())\n ^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\queues.py\", line 394, in get_payload with self._rlock:\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\synchronize.py\", line 115, in __enter__\n return self._semlock.__enter__()\n ^^^^^^^^^^^^^^^^^^^^^^^^^\nPermissionError: [WinError 5] Access is denied\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 351, in workloop\n req = wait_for_job()\n ^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 480, in receive\n raise SystemExit(EX_FAILURE)\nSystemExit: 1\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 292, in __call__\n sys.exit(self.workloop(pid=pid))\n ^^^^^^^^^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 396, in workloop\n self._ensure_messages_consumed(completed=completed)\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 406, in _ensure_messages_consumed\n if self.on_ready_counter.value >= completed:\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"\", line 3, in getvalue\nPermissionError: [WinError 5] Access is denied\n[2024-10-06 14:38:15,464: ERROR/SpawnPoolWorker-3] Pool process error: PermissionError(13, 'Access is denied', None, 5, None)\nTraceback (most recent call last):\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 473, in receive\n ready, req = _receive(1.0)\n ^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 445, in _recv\n return True, loads(get_payload())\n ^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\queues.py\", line 394, in get_payload with self._rlock:\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\synchronize.py\", line 115, in __enter__\n return self._semlock.__enter__()\n ^^^^^^^^^^^^^^^^^^^^^^^^^\nPermissionError: [WinError 5] Access is denied\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 351, in workloop\n req = wait_for_job()\n ^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 480, in receive\n raise SystemExit(EX_FAILURE)\nSystemExit: 1\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 292, in __call__\n sys.exit(self.workloop(pid=pid))\n ^^^^^^^^^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 396, in workloop\n self._ensure_messages_consumed(completed=completed)\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 406, in _ensure_messages_consumed\n if self.on_ready_counter.value >= completed:\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"\", line 3, in getvalue\nPermissionError: [WinError 5] Access is denied\n[2024-10-06 14:38:15,642: ERROR/MainProcess] Process 'SpawnPoolWorker-3' pid:19032 exited with 'exitcode 1'\n[2024-10-06 14:38:16,108: INFO/SpawnPoolWorker-9] child process 160 calling self.run()\n[2024-10-06 14:38:23,846: INFO/MainProcess] Events of group {task} enabled by remote.\n[2024-10-06 14:41:05,702: WARNING/MainProcess] consumer: Connection to broker lost. Trying to re-establish the connection...\nTraceback (most recent call last):\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\celery\\worker\\consumer\\consumer.py\", line 340, in start\n blueprint.start(self)\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\celery\\bootsteps.py\", line 116, in start\n step.start(parent)\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\celery\\worker\\consumer\\consumer.py\", line 746, in start\n c.loop(*c.loop_args())\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\celery\\worker\\loops.py\", line 130, in synloop connection.drain_events(timeout=2.0)\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\kombu\\connection.py\", line 341, in drain_events\n return self.transport.drain_events(self.connection, **kwargs)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\kombu\\transport\\pyamqp.py\", line 171, in drain_events\n return connection.drain_events(**kwargs)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\amqp\\connection.py\", line 526, in drain_events\n while not self.blocking_read(timeout):\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\amqp\\connection.py\", line 531, in blocking_read\n frame = self.transport.read_frame()\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\amqp\\transport.py\", line 294, in read_frame\n frame_header = read(7, True)\n ^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\amqp\\transport.py\", line 637, in _read\n raise OSError('Server unexpectedly closed connection')\nOSError: Server unexpectedly closed connection\n[2024-10-06 14:41:05,780: WARNING/MainProcess] D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\celery\\worker\\consumer\\consumer.py:391: CPendingDeprecationWarning:\nIn Celery 5.1 we introduced an optional breaking change which\non connection loss cancels all currently executed tasks with late acknowledgement enabled.\nThese tasks cannot be acknowledged as the connection is gone, and the tasks are automatically redelivered\nback to the queue. You can enable this behavior using the worker_cancel_long_running_tasks_on_connection_loss\nsetting. In Celery 5.1 it is set to False by default. The setting will be set to True by default in Celery 6.0.\n\n warnings.warn(CANCEL_TASKS_BY_DEFAULT, CPendingDeprecationWarning)\n\n[2024-10-06 14:41:05,788: INFO/MainProcess] Connected to amqp://guest:**@127.0.0.1:5672//\n[2024-10-06 14:41:05,798: INFO/MainProcess] mingle: searching for neighbors\n[2024-10-06 14:41:06,826: INFO/MainProcess] mingle: all alone\n[2024-10-06 14:44:05,784: WARNING/MainProcess] consumer: Connection to broker lost. Trying to re-establish the connection...\nTraceback (most recent call last):\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\celery\\worker\\consumer\\consumer.py\", line 340, in start\n blueprint.start(self)\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\celery\\bootsteps.py\", line 116, in start\n step.start(parent)\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\celery\\worker\\consumer\\consumer.py\", line 746, in start\n c.loop(*c.loop_args())\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\celery\\worker\\loops.py\", line 130, in synloop connection.drain_events(timeout=2.0)\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\kombu\\connection.py\", line 341, in drain_events\n return self.transport.drain_events(self.connection, **kwargs)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\kombu\\transport\\pyamqp.py\", line 171, in drain_events\n return connection.drain_events(**kwargs)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\amqp\\connection.py\", line 526, in drain_events\n while not self.blocking_read(timeout):\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\amqp\\connection.py\", line 531, in blocking_read\n frame = self.transport.read_frame()\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\amqp\\transport.py\", line 294, in read_frame\n frame_header = read(7, True)\n ^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\amqp\\transport.py\", line 637, in _read\n raise OSError('Server unexpectedly closed connection')\nOSError: Server unexpectedly closed connection\n[2024-10-06 14:44:33,538: WARNING/MainProcess] D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\celery\\worker\\consumer\\consumer.py:391: CPendingDeprecationWarning:\nIn Celery 5.1 we introduced an optional breaking change which\non connection loss cancels all currently executed tasks with late acknowledgement enabled.\nThese tasks cannot be acknowledged as the connection is gone, and the tasks are automatically redelivered\nback to the queue. You can enable this behavior using the worker_cancel_long_running_tasks_on_connection_loss\nsetting. In Celery 5.1 it is set to False by default. The setting will be set to True by default in Celery 6.0.\n\n warnings.warn(CANCEL_TASKS_BY_DEFAULT, CPendingDeprecationWarning)\n```\n\nthis is the full error message, I am providing it to better understand the problem\nI am using cmd with administration access, but it didn't work out\nI am using Django with celery with RabbitMQ to build a asynchronous tasks to send emails to the clients.\n\nI have tryed to make the cmd is administration as I have mentioned, I am making just two tasks with celery but it gives me this error.\n\n========================================\n\nCode:\n```text\n[2024-10-06 14:38:15,464: ERROR/SpawnPoolWorker-3] Pool process <billiard.pool.Worker object at 0x0000016C0BBF5A00> error: PermissionError(13, 'Access is denied', None, 5, None)\nTraceback (most recent call last):\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 473, in receive\n ready, req = _receive(1.0)\n ^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 445, in _recv\n return True, loads(get_payload())\n ^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\queues.py\", line 394, in get_payload with self._rlock:\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\synchronize.py\", line 115, in __enter__\n return self._semlock.__enter__()\n ^^^^^^^^^^^^^^^^^^^^^^^^^\nPermissionError: [WinError 5] Access is denied\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 351, in workloop\n req = wait_for_job()\n ^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 480, in receive\n raise SystemExit(EX_FAILURE)\nSystemExit: 1\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 292, in __call__\n sys.exit(self.workloop(pid=pid))\n ^^^^^^^^^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 396, in workloop\n self._ensure_messages_consumed(completed=completed)\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 406, in _ensure_messages_consumed\n if self.on_ready_counter.value >= completed:\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"<string>\", line 3, in getvalue\nPermissionError: [WinError 5] Access is denied\n[2024-10-06 14:38:15,464: ERROR/SpawnPoolWorker-3] Pool process <billiard.pool.Worker object at 0x0000016C0BBF5A00> error: PermissionError(13, 'Access is denied', None, 5, None)\nTraceback (most recent call last):\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 473, in receive\n ready, req = _receive(1.0)\n ^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 445, in _recv\n return True, loads(get_payload())\n ^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\queues.py\", line 394, in get_payload with self._rlock:\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\synchronize.py\", line 115, in __enter__\n return self._semlock.__enter__()\n ^^^^^^^^^^^^^^^^^^^^^^^^^\nPermissionError: [WinError 5] Access is denied\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 351, in workloop\n req = wait_for_job()\n ^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 480, in receive\n raise SystemExit(EX_FAILURE)\nSystemExit: 1\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 292, in __call__\n sys.exit(self.workloop(pid=pid))\n ^^^^^^^^^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 396, in workloop\n self._ensure_messages_consumed(completed=completed)\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\billiard\\pool.py\", line 406, in _ensure_messages_consumed\n if self.on_ready_counter.value >= completed:\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"<string>\", line 3, in getvalue\nPermissionError: [WinError 5] Access is denied\n[2024-10-06 14:38:15,642: ERROR/MainProcess] Process 'SpawnPoolWorker-3' pid:19032 exited with 'exitcode 1'\n[2024-10-06 14:38:16,108: INFO/SpawnPoolWorker-9] child process 160 calling self.run()\n[2024-10-06 14:38:23,846: INFO/MainProcess] Events of group {task} enabled by remote.\n[2024-10-06 14:41:05,702: WARNING/MainProcess] consumer: Connection to broker lost. Trying to re-establish the connection...\nTraceback (most recent call last):\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\celery\\worker\\consumer\\consumer.py\", line 340, in start\n blueprint.start(self)\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\celery\\bootsteps.py\", line 116, in start\n step.start(parent)\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\celery\\worker\\consumer\\consumer.py\", line 746, in start\n c.loop(*c.loop_args())\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\celery\\worker\\loops.py\", line 130, in synloop connection.drain_events(timeout=2.0)\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\kombu\\connection.py\", line 341, in drain_events\n return self.transport.drain_events(self.connection, **kwargs)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\kombu\\transport\\pyamqp.py\", line 171, in drain_events\n return connection.drain_events(**kwargs)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\amqp\\connection.py\", line 526, in drain_events\n while not self.blocking_read(timeout):\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\amqp\\connection.py\", line 531, in blocking_read\n frame = self.transport.read_frame()\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\amqp\\transport.py\", line 294, in read_frame\n frame_header = read(7, True)\n ^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\amqp\\transport.py\", line 637, in _read\n raise OSError('Server unexpectedly closed connection')\nOSError: Server unexpectedly closed connection\n[2024-10-06 14:41:05,780: WARNING/MainProcess] D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\celery\\worker\\consumer\\consumer.py:391: CPendingDeprecationWarning:\nIn Celery 5.1 we introduced an optional breaking change which\non connection loss cancels all currently executed tasks with late acknowledgement enabled.\nThese tasks cannot be acknowledged as the connection is gone, and the tasks are automatically redelivered\nback to the queue. You can enable this behavior using the worker_cancel_long_running_tasks_on_connection_loss\nsetting. In Celery 5.1 it is set to False by default. The setting will be set to True by default in Celery 6.0.\n\n warnings.warn(CANCEL_TASKS_BY_DEFAULT, CPendingDeprecationWarning)\n\n[2024-10-06 14:41:05,788: INFO/MainProcess] Connected to amqp://guest:**@127.0.0.1:5672//\n[2024-10-06 14:41:05,798: INFO/MainProcess] mingle: searching for neighbors\n[2024-10-06 14:41:06,826: INFO/MainProcess] mingle: all alone\n[2024-10-06 14:44:05,784: WARNING/MainProcess] consumer: Connection to broker lost. Trying to re-establish the connection...\nTraceback (most recent call last):\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\celery\\worker\\consumer\\consumer.py\", line 340, in start\n blueprint.start(self)\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\celery\\bootsteps.py\", line 116, in start\n step.start(parent)\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\celery\\worker\\consumer\\consumer.py\", line 746, in start\n c.loop(*c.loop_args())\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\celery\\worker\\loops.py\", line 130, in synloop connection.drain_events(timeout=2.0)\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\kombu\\connection.py\", line 341, in drain_events\n return self.transport.drain_events(self.connection, **kwargs)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\kombu\\transport\\pyamqp.py\", line 171, in drain_events\n return connection.drain_events(**kwargs)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\amqp\\connection.py\", line 526, in drain_events\n while not self.blocking_read(timeout):\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\amqp\\connection.py\", line 531, in blocking_read\n frame = self.transport.read_frame()\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\amqp\\transport.py\", line 294, in read_frame\n frame_header = read(7, True)\n ^^^^^^^^^^^^^\n File \"D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\amqp\\transport.py\", line 637, in _read\n raise OSError('Server unexpectedly closed connection')\nOSError: Server unexpectedly closed connection\n[2024-10-06 14:44:33,538: WARNING/MainProcess] D:\\study\\learning-python\\back-end\\ecommerce\\venv\\Lib\\site-packages\\celery\\worker\\consumer\\consumer.py:391: CPendingDeprecationWarning:\nIn Celery 5.1 we introduced an optional breaking change which\non connection loss cancels all currently executed tasks with late acknowledgement enabled.\nThese tasks cannot be acknowledged as the connection is gone, and the tasks are automatically redelivered\nback to the queue. You can enable this behavior using the worker_cancel_long_running_tasks_on_connection_loss\nsetting. In Celery 5.1 it is set to False by default. The setting will be set to True by default in Celery 6.0.\n\n warnings.warn(CANCEL_TASKS_BY_DEFAULT, CPendingDeprecationWarning)\n```\n\n========================================\n\nComments:\n- The following blog article explains why this does not work, but the accepted answer does: Running Celery 5 on Windows\n- Can you tell me about an article that taking about this issue!","metadata":{"transformedAt":"2026-08-18T18:33:20.194Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":329,"estimatedTokens":5304}}837{"id":"stack-34747413","source":"stackoverflow","questionId":34747413,"title":"How long a RabbitMQ Message stays alive without Subscribers?","tags":["c#","rabbitmq","masstransit"],"text":"Title: How long a RabbitMQ Message stays alive without Subscribers?\nTags: c#, rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nI am creating a simple Publisher/Subscriber using MassTransit and RabbitMQ.\nThe Publisher has the following code to initialize the bus:\n\n```\n/** create the bus */\nvar bus = Bus.Factory.CreateUsingRabbitMq(cfg =>\n{\n var host = cfg.Host(new Uri(\"rabbitmq://localhost/\"), h =>\n {\n h.Username(\"guest\");\n h.Password(\"guest\");\n });\n});\n\n/** start the bus and publish */\nbus.Start();\nbus.Publish(new {FirstName = \"John\", LastName = \"Smith\"});\n```\n\nAnd the Subscriber has this code for initialization:\n\n```\nvar bus = Bus.Factory.CreateUsingRabbitMq(cfg =>\n{\n var host = cfg.Host(new Uri(\"rabbitmq://localhost/\"), h =>\n {\n h.Username(\"guest\");\n h.Password(\"guest\");\n });\n\n cfg.ReceiveEndpoint(host, \"person_login\", e =>\n {\n e.Consumer();\n });\n});\n```\n\nIf I shut-down the Subscriber and publish 2 messages, the messages are not lost and as soon as the Subscriber comes back to life the Messages are processed.\n\nSo my questions are:\n\n- How do I ensure that a Message stays in the Queue of RabbitMQ until one Subscriber comes up and pick it up?\n\n- What happen if the Server is reboot and some Messages were not processed by any Subscriber, do they get lost or do they get processed as soon as the Subscriber come alive after reboot?\n\n- Is this the correct pattern to ensure that every single message is processed or should I use a different strategy?\n\n========================================\n\nTop Answer:\nOn top of mind.\n\n- If there arent any subscribers RabbitMQ wont know to which queue a message should be delivered. Then a message will be undeliverable.(Not sure if this will be moved to a error queue or skipped)\n\n- If the exchanges are already there it will be placed in the queue of consumer that has subscribed to the event. So you endpoint hosting your consumer can be down the message will still be delivered.\n\n- When the message is delivered to the queue the consumer will pick up your message and process it. If a exception occurs while processing your message it will be moved to the endpoint_error queue. (Depending on your RetryPolicy). Deploy a fix and move you message back in to the main queue and the messages will be processed as if nothing has happend.\n\nGood read for common issues on common gotcha's\n\n- Under the Hood\n\n- Common Gotcha's\n\n========================================\n\nCode:\n```text\n/** create the bus */\nvar bus = Bus.Factory.CreateUsingRabbitMq(cfg =>\n{\n var host = cfg.Host(new Uri(\"rabbitmq://localhost/\"), h =>\n {\n h.Username(\"guest\");\n h.Password(\"guest\");\n });\n});\n\n/** start the bus and publish */\nbus.Start();\nbus.Publish<IPersonLogin>(new {FirstName = \"John\", LastName = \"Smith\"});\n```\n\n```text\nvar bus = Bus.Factory.CreateUsingRabbitMq(cfg =>\n{\n var host = cfg.Host(new Uri(\"rabbitmq://localhost/\"), h =>\n {\n h.Username(\"guest\");\n h.Password(\"guest\");\n });\n\n cfg.ReceiveEndpoint(host, \"person_login\", e =>\n {\n e.Consumer<PersonLoginConsumer>();\n });\n});\n```\n\n========================================\n\nComments:\n- Thanks for the answer, I think is more related to RabbitMQ than MassTransit which is just my transporter\n- Yes but MassTransit is creates your exchanges and queues. No exchanges no routing of messages to queues. No routing of messages no processing of messages.\n- Exactly what I was looking for @derick","metadata":{"transformedAt":"2026-08-18T18:33:20.194Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":110,"estimatedTokens":861}}838{"id":"stack-45569931","source":"stackoverflow","questionId":45569931,"title":"How to correctly setup RabbitMQ on Openshift","tags":["rabbitmq","openshift"],"text":"Title: How to correctly setup RabbitMQ on Openshift\nTags: rabbitmq, openshift\nSource: Stack Overflow\n\nQuestion:\nI have created new app on OpenShift using this image: https://hub.docker.com/r/luiscoms/openshift-rabbitmq/\n\nIt runs successfully and I can use it. I have added a persistent volume to it.\nHowever, every time a POD is restarted, I loos all my data. This is because RabbitMq uses a hostname to create database directory. \n\nFor example:\n\n```\nnode : rabbit@openshift-rabbitmq-11-9b6p7\nhome dir : /var/lib/rabbitmq\nconfig file(s) : /etc/rabbitmq/rabbitmq.config\ncookie hash : BsUC9W6z5M26164xPxUTkA==\nlog : tty\nsasl log : tty\ndatabase dir : /var/lib/rabbitmq/mnesia/rabbit@openshift-rabbitmq-11-9b6p7\n```\n\nHow can I set RabbitMq to always use same database dir?\n\n========================================\n\nTop Answer:\nI was able to get it to work by setting the HOSTNAME environment variable. OSE normally sets that value to the pod name, so it changes everytime the pod restarts. By setting it the pod's hostname doesn't change when the pod restarts. \n\nCombined with a Persistent Volume the the queues, messages users and i assume whatever other configuration is persisted through pod restarts.\n\nThis was done on an OSE 3.2 server. I just added an environment variable to the deployment config. You can do it through the UI or with the OC CLI:\n\n```\noc set env dc/my-rabbit HOSTNAME=some-static-name\n```\n\nThis will probably be an issue if you run multiple pods for the service, but in that case you would need to setup proper RabbitMq clustering, which is a whole different beast.\n\n========================================\n\nCode:\n```text\nnode : rabbit@openshift-rabbitmq-11-9b6p7\nhome dir : /var/lib/rabbitmq\nconfig file(s) : /etc/rabbitmq/rabbitmq.config\ncookie hash : BsUC9W6z5M26164xPxUTkA==\nlog : tty\nsasl log : tty\ndatabase dir : /var/lib/rabbitmq/mnesia/rabbit@openshift-rabbitmq-11-9b6p7\n```\n\n```text\nRABBITMQ_MNESIA_DIR\n```\n\n```text\noc\n```\n\n```text\noc set env dc/my-rabbit RABBITMQ_MNESIA_DIR=/myDir\n```\n\n```text\noc volume dc/my-rabbit --add --overwrite --name=my-pv-name --mount-path=/myDir\n```\n\n```text\noc set env dc/example HOSTNAME=example\n```\n\n```text\nRABBITMQ_NODENAME\n```\n\n```text\noc set env dc/my-rabbit HOSTNAME=some-static-name\n```\n\n========================================\n\nComments:\n- This works, thank you. Do you maybe know how could I setup a RabbitMQ cluster? If I let my rabbit nodenames to be dervied from POD names, then I think it could work, but if the POD is restarted, then a Rabbit sets new node name and cluster would now work anymore. If I set a node name with environment variable RABBITMQ_NODENAME then DNS lookup in OpenShift for that node name doesnt work...\n- There seems to be various ways clustering could be achieved but you might look at using stateful sets. Linking a guide for configuration on kubernetes you might find useful wesmorgan.svbtle.com/…\n- Hi. Tried your solution here. But it doesn't work for me. RabbitMQ reads the database but then it tries to connect to the previous node that created it and I get this `{could_not_start,rabbit, {{failed_to_cluster_with, ['madelink-rabbitmq-1@rabbitmq-11-71xk8'], \"Mnesia could not connect to any nodes.\"}, {rabbit,start,[normal,[]]}}}`. It seems like the `node variable` is still changing (actually `madelink-rabbitmq-1@rabbitmq-11-fztv5`)\n- @mrik974 need more info. What are you trying to do? What steps have you taken\n- @user2983542 I'm trying to do the exact same thing as the OP, trying to persist data of a RabbitMQ pod in Openshift. I created the deployment configuration using openshift provided templates, and set up a persistent volume. Then I set up the `RABBITMQ_MNESIA_DIR` so it wouldn't move. But when I delete the pod and let it be recreated manually, the pod gets another name. RabbitMQ reads the data in the right directory but notices that another pod with another name (the previous, deleted one) exists and tries to connect to it. And I get the error above.\n- Setting the variable `RABBITMQ_NODENAME` just changed the first part of the node name : `rabbitmq-1@` . The other part is still generated using the hostname\n- @mrik974 ok as well as the answer below one thing you could do would be to create the pod in a stateful set so that the name will be consistent across restart\n- Alternatively, if you set `RABBITMQ_NODENAME` to a value with ending with `@localhost`, the new instance will use the same mnesia files even though the actual pod has a different name every time.\n- Most probably the other answers are simply outdated. If the thing works as described then it is definitely the best way. Thank you for your answer!","metadata":{"transformedAt":"2026-08-18T18:33:20.194Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":92,"estimatedTokens":1173}}839{"id":"stack-2161206","source":"stackoverflow","questionId":2161206,"title":"Multiple consumers & producers connected to a message queue, Is that possible in AMQP?","tags":["python","message-queue","rabbitmq","amqp","py-amqplib"],"text":"Title: Multiple consumers & producers connected to a message queue, Is that possible in AMQP?\nTags: python, message-queue, rabbitmq, amqp, py-amqplib\nSource: Stack Overflow\n\nQuestion:\nI'd like to create a farm of processes that are able to OCR text.\nI've thought about using a single queue of messages which is read by multiple OCR processes.\n\nI would like to ensure that:\n\n- each message in queue is eventually processed\n\n- the work is more or less equally distributed\n\n- an image will be parsed only by one OCR process\n\n- An OCR process won't get multiple messages at once (so that any other free OCR process can handle the message).\n\nIs that possible to do using AMQP?\n\nI'm planning to use python and rabbitmq\n\n========================================\n\nTop Answer:\nYes, as @nailxx points out. The AMQP programming model is slightly different from JMS in that you only have *queues*, which can be shared between workers, or used *privately* by a single worker. You can also easily set up RabbitMQ to do *PubSub* use cases or what in JMS are called *topics*. Please go to our Getting Started page on the RabbitMQ web site to find a ton of helpful info about this.\n\nNow, for your use case in particular, there are already plenty of tools available. One that people are using a lot, and that is well supported, is Celery. Here is a blog post about it, that I think will help you get started: \n\nIf you have any questions please email us or post to the rabbitmq-discuss mailing list.\n\n========================================\n\nCode:\n```text\nactivemq.prefetchSize: 1\n```\n\n```text\nack\n```\n\n========================================\n\nComments:\n- +1 Celery looks lovely. I'll check it out at the nearest opportunity.","metadata":{"transformedAt":"2026-08-18T18:33:20.194Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":46,"estimatedTokens":427}}840{"id":"stack-22061082","source":"stackoverflow","questionId":22061082,"title":"Getting \"pika.exceptions.ConnectionClosed\" error while using rabbitmq in python","tags":["python","rabbitmq","pika"],"text":"Title: Getting \"pika.exceptions.ConnectionClosed\" error while using rabbitmq in python\nTags: python, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI am using \"hello world\" tutorial in :http://www.rabbitmq.com/tutorials/tutorial-two-python.html .\n`worker.py` looks like this\n\n```\nimport pika\nimport time\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost'))\nchannel = connection.channel()\n\nchannel.queue_declare(queue='task_queue', durable=True)\nprint ' [*] Waiting for messages. To exit press CTRL+C'\n\ndef callback(ch, method, properties, body):\n print \" [x] Received %r\" % (body,)\n time.sleep( body.count('.') )\n print \" [x] Done\"\n ch.basic_ack(delivery_tag = method.delivery_tag)\n\nchannel.basic_qos(prefetch_count=1)\nchannel.basic_consume(callback,\n queue='task_queue')\n\nchannel.start_consuming()\n```\n\nI have used this code to implement in my work. Everything works smoothly untill there comes a point in a queue for which it raises an exception after printing `[x] Done`\n\n```\nTraceback (most recent call last):\n File \"hullworker2.py\", line 242, in \n channel.basic_consume(callback,queue='test_queue2')\n File \"/usr/local/lib/python2.7/dist-packages/pika/channel.py\", line 211, in basic_consume\n {'consumer_tag': consumer_tag})])\n File \"/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py\", line 904, in _rpc\n self.connection.process_data_events()\n File \"/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py\", line 88, in process_data_events\n if self._handle_read():\n File \"/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py\", line 184, in _handle_read\n super(BlockingConnection, self)._handle_read()\n File \"/usr/local/lib/python2.7/dist-packages/pika/adapters/base_connection.py\", line 300, in _handle_read\n return self._handle_error(error)\n File \"/usr/local/lib/python2.7/dist-packages/pika/adapters/base_connection.py\", line 264, in _handle_error\n self._handle_disconnect()\n File \"/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py\", line 181, in _handle_disconnect\n self._on_connection_closed(None, True)\n File \"/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py\", line 232, in _on_connection_closed\n self._channels[channel]._on_close(method_frame)\n File \"/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py\", line 817, in _on_close\n self._send_method(spec.Channel.CloseOk(), None, False)\n File \"/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py\", line 920, in _send_method\n self.connection.send_method(self.channel_number, method_frame, content)\n File \"/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py\", line 120, in send_method\n self._send_method(channel_number, method_frame, content)\n File \"/usr/local/lib/python2.7/dist-packages/pika/connection.py\", line 1331, in _send_method\n self._send_frame(frame.Method(channel_number, method_frame))\n File \"/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py\", line 245, in _send_frame\n super(BlockingConnection, self)._send_frame(frame_value)\n File \"/usr/local/lib/python2.7/dist-packages/pika/connection.py\", line 1312, in _send_frame\n raise exceptions.ConnectionClosed\npika.exceptions.ConnectionClosed\n```\n\nI don't understand how the connection is closing automatically in between the process. Process runs fine for 100's of messages in the queue then suddenly this error comes up.\nAny help appreciated.\n\n========================================\n\nCode:\n```text\nimport pika\nimport time\n\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost'))\nchannel = connection.channel()\n\nchannel.queue_declare(queue='task_queue', durable=True)\nprint ' [*] Waiting for messages. To exit press CTRL+C'\n\ndef callback(ch, method, properties, body):\n print \" [x] Received %r\" % (body,)\n time.sleep( body.count('.') )\n print \" [x] Done\"\n ch.basic_ack(delivery_tag = method.delivery_tag)\n\nchannel.basic_qos(prefetch_count=1)\nchannel.basic_consume(callback,\n queue='task_queue')\n\nchannel.start_consuming()\n```\n\n```text\nTraceback (most recent call last):\n File \"hullworker2.py\", line 242, in <module>\n channel.basic_consume(callback,queue='test_queue2')\n File \"/usr/local/lib/python2.7/dist-packages/pika/channel.py\", line 211, in basic_consume\n {'consumer_tag': consumer_tag})])\n File \"/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py\", line 904, in _rpc\n self.connection.process_data_events()\n File \"/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py\", line 88, in process_data_events\n if self._handle_read():\n File \"/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py\", line 184, in _handle_read\n super(BlockingConnection, self)._handle_read()\n File \"/usr/local/lib/python2.7/dist-packages/pika/adapters/base_connection.py\", line 300, in _handle_read\n return self._handle_error(error)\n File \"/usr/local/lib/python2.7/dist-packages/pika/adapters/base_connection.py\", line 264, in _handle_error\n self._handle_disconnect()\n File \"/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py\", line 181, in _handle_disconnect\n self._on_connection_closed(None, True)\n File \"/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py\", line 232, in _on_connection_closed\n self._channels[channel]._on_close(method_frame)\n File \"/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py\", line 817, in _on_close\n self._send_method(spec.Channel.CloseOk(), None, False)\n File \"/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py\", line 920, in _send_method\n self.connection.send_method(self.channel_number, method_frame, content)\n File \"/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py\", line 120, in send_method\n self._send_method(channel_number, method_frame, content)\n File \"/usr/local/lib/python2.7/dist-packages/pika/connection.py\", line 1331, in _send_method\n self._send_frame(frame.Method(channel_number, method_frame))\n File \"/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py\", line 245, in _send_frame\n super(BlockingConnection, self)._send_frame(frame_value)\n File \"/usr/local/lib/python2.7/dist-packages/pika/connection.py\", line 1312, in _send_frame\n raise exceptions.ConnectionClosed\npika.exceptions.ConnectionClosed\n```\n\n```text\nworker.py\n```\n\n```text\n[x] Done\n```\n\n```text\ntime.sleep( body.count('.') )\n```\n\n```text\nsleep(duration)[source]\n\n A safer way to sleep than calling time.sleep() directly which will keep the adapter from ignoring frames sent from RabbitMQ. The connection will “sleep” or block the number of seconds specified in duration in small intervals.\n```\n\n```text\nheartbeats\n```\n\n```text\nN\n```\n\n```text\nheartbeat\n```\n\n```text\ntime.sleep()\n```\n\n```text\nconnection.sleep()\n```\n\n```text\nN\n```\n\n========================================\n\nComments:\n- Can you copy/paste the stack trace error that you get? It should start with something like Traceback (most recent call last): File \"\", line 1, in .....\n- @kobejohn I have updated the ques please see it\n- I don't have rabbitmq setup so I'm just guessing. It seems strange that the traceback shows the error in basic_consume. There shouldn't be any callbacks running until after start_consuming() right? How long does this work before it crashes?\n- 30-40 minutes then it display the results and crashes.Again if i start the worker it will take the same message\n- This error is not coming from worker.py is it? Maybe you are looking in the wrong place for the source of the problem? Can you give a simplified version of hullworker2.py? Also, if you can just catch the ConnectionClosed exception and restart the worker, do you lose work? I guess you will be fine because you are using acknowledgement which doesn't complete a job until it is acknowledged. If that's ok, then you can just restart when necessary as a temporary fix.\n- yes I didnt lose the work but it is stuck at the same message.When I restart it receive the same message execute the \"calculations\" and then shows the same error.And in the calculation I used print statements to check if its calculating or not.Its giving the results perfectly but can not acknowledge it for some reasons I guess\n- while this answer solves the issue in the question. I think it does not resolved the problem of long task and the hearbeats properly.","metadata":{"transformedAt":"2026-08-18T18:33:20.196Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":12,"totalLines":187,"estimatedTokens":2146}}841{"id":"stack-63036460","source":"stackoverflow","questionId":63036460,"title":"RabbitMQ Client shuts down the MessageListener and cannot be recovered","tags":["java","spring-boot","rabbitmq","spring-rabbit"],"text":"Title: RabbitMQ Client shuts down the MessageListener and cannot be recovered\nTags: java, spring-boot, rabbitmq, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI use RabbitMQ AMQP 2.2.7. I have the RabbitMQ cluster running between 2 Spring boot application. One application posts some messages to the other one. It was running well for sometime but suddenly for the last few days, i see that MessageListener in the application that consumes the message goes down for some reason (May be the master server node went down).\n\n```\n\n org.springframework.amqp\n spring-rabbit\n 2.2.7.RELEASE\n \n```\n\n```\n2020-07-22 00:26:33.007 ERROR 24 --- [tContainer#1-15] o.s.a.r.l.SimpleMessageListenerContainer : Stopping container from aborted consumer\nCaused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method(reply-code=404, reply-text=NOT_FOUND - home node 'rabbit@rad497159-mq-1.node.dc1.a9ssvc' of durable queue 'ORDER' in vhost '/' is down or inaccessible, class-id=50, method-id=10)\nCaused by: java.io.IOException: null\nat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:na]\n2020-07-22 00:26:33.005 ERROR 24 --- [tContainer#1-15] o.s.a.r.l.SimpleMessageListenerContainer : Consumer threw missing queues exception, fatal=true\nat org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.initialize(SimpleMessageListenerContainer.java:1350) ~[spring-rabbit-2.2.7.RELEASE.jar:2.2.7.RELEASE]\n```\n\n```\n@Configuration\npublic class MessageConfiguration {\n\n public static final String ORDER_QUEUE_NAME = \"ORDER\";\n\n public static final String EXCHANGE = \"directExchange\";\n\n @Bean\n Queue deadLetterQueue() {\n return QueueBuilder.durable(ORDER_QUEUE_NAME).build();\n }\n\n @Bean\n public Queue orderQueue(){\n return QueueBuilder.durable(ORDER_QUEUE_NAME)\n .build();\n }\n\n @Bean\n public DirectExchange directExchange(){\n return new DirectExchange(EXCHANGE,true,false);\n }\n\n @Bean\n public Binding firstBinding(Queue orderQueue, DirectExchange directExchange){\n return BindingBuilder.bind(orderQueue).to(directExchange).with(ORDER_QUEUE_NAME);\n }\n}\n```\n\n```\n@RabbitListener(queues = MessageConfiguration.ORDER_QUEUE_NAME)\npublic void receiveOrder(final String orderString) {\n}\n```\n\nThe problem is RabbitMQ message listener shuts down indefinitley and there is no other way to recover. Restarting the application solves the problem. So i would like have one of the following solution but dont know how to do that\n\n- Listen for the shutdown notification from SimpleMessageListener and restart the application\n\n- Make the application retry more times before shutting down the listener\n\nCould someone please suggest some way ?\n\nThere is already the same issue in stackoverflow without solution (How to avoid shutdown of SimpleMessageListenerContainer in case of unexpected errors?)\n\n========================================\n\nCode:\n```text\n<dependency>\n <groupId>org.springframework.amqp</groupId>\n <artifactId>spring-rabbit</artifactId>\n <version>2.2.7.RELEASE</version>\n </dependency>\n```\n\n```text\n2020-07-22 00:26:33.007 ERROR 24 --- [tContainer#1-15] o.s.a.r.l.SimpleMessageListenerContainer : Stopping container from aborted consumer\nCaused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - home node 'rabbit@rad497159-mq-1.node.dc1.a9ssvc' of durable queue 'ORDER' in vhost '/' is down or inaccessible, class-id=50, method-id=10)\nCaused by: java.io.IOException: null\nat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:na]\n2020-07-22 00:26:33.005 ERROR 24 --- [tContainer#1-15] o.s.a.r.l.SimpleMessageListenerContainer : Consumer threw missing queues exception, fatal=true\nat org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.initialize(SimpleMessageListenerContainer.java:1350) ~[spring-rabbit-2.2.7.RELEASE.jar:2.2.7.RELEASE]\n```\n\n```text\n@Configuration\npublic class MessageConfiguration {\n\n public static final String ORDER_QUEUE_NAME = \"ORDER\";\n\n public static final String EXCHANGE = \"directExchange\";\n\n @Bean\n Queue deadLetterQueue() {\n return QueueBuilder.durable(ORDER_QUEUE_NAME).build();\n }\n\n @Bean\n public Queue orderQueue(){\n return QueueBuilder.durable(ORDER_QUEUE_NAME)\n .build();\n }\n\n @Bean\n public DirectExchange directExchange(){\n return new DirectExchange(EXCHANGE,true,false);\n }\n\n @Bean\n public Binding firstBinding(Queue orderQueue, DirectExchange directExchange){\n return BindingBuilder.bind(orderQueue).to(directExchange).with(ORDER_QUEUE_NAME);\n }\n}\n```\n\n```text\n@RabbitListener(queues = MessageConfiguration.ORDER_QUEUE_NAME)\npublic void receiveOrder(final String orderString) {\n}\n```\n\n```text\nhome node 'rabbit@rad497159-mq-1.node.dc1.a9ssvc' of durable queue 'ORDER' in vhost '/' is down or inaccessible, class-id=50, method-id=10)\n```\n\n```text\nConsumer threw missing queues exception, fatal=true\n```\n\n```text\nmissingQueuesFatal\n```\n\n```text\nfalse\n```\n\n========================================\n\nComments:\n- the docs for the java client talk about a `handleShutdownSignal` method (it's on a `Consumer` instance) - you could then perform your option #1.\n- Thank you for your reply. I tried defining a SimpleMessageListener and added missingQueuesFatal to false like you mentioned but now i get the following error. org.springframework.context.ApplicationContextException: Failed to start bean 'simpleMessageListenerContainer'; nested exception is org.springframework.amqp.UncategorizedAmqpException: java.lang.IllegalStateException: A listener container must not be provided when using direct reply-to\"\n- I added the message listener bean to the question. Could you please let me know what is the problem ?\n- \"spring.rabbitmq.listener.simple.missing-queues-fatal=false\" seems to fix the issue :) Thank you Gary","metadata":{"transformedAt":"2026-08-18T18:33:20.196Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":151,"estimatedTokens":1509}}842{"id":"stack-30396350","source":"stackoverflow","questionId":30396350,"title":"How to use channel.assertQueue function from amqplib library for node.JS?","tags":["javascript","node.js","rabbitmq","amqp","php-amqplib"],"text":"Title: How to use channel.assertQueue function from amqplib library for node.JS?\nTags: javascript, node.js, rabbitmq, amqp, php-amqplib\nSource: Stack Overflow\n\nQuestion:\nI am developing a messaging app using RabbitMQ, and Node.JS. I am using amqplib for this purpose. I am new to Node.JS and finding few difficulties in understanding the syntax of amqplib..\nFor e.g. there is a function for declaring queue,\nthat is\n\n```\nchannel.assertQueue([queue, [options, [function(err, ok) {...}]]]);\n```\n\nI have been referring This from last 2-3 days but still I am not clear about these -> `err` and `ok`. How to use these parameters?\n\nAn example would be much much appreciated.\n\n========================================\n\nCode:\n```text\nchannel.assertQueue([queue, [options, [function(err, ok) {...}]]]);\n```\n\n```text\nerr\n```\n\n```text\nok\n```\n\n```text\nvar amqp = require('amqplib/callback_api');\nvar q = 'tasks';\n\n// connects to rabbitmq\namqp.connect('amqp://localhost', function(err, conn) {\n // this function will be called when the connection is created\n // `err` will contain the error object, if any errors occurred\n // `conn` will contain the connection object\n\n if (err != null) bail(err); // calls `bail` function if an error occurred when connecting\n consumer(conn); // creates a consumer\n publisher(conn); // creates a publisher\n});\n\nfunction bail(err) {\n console.error(err);\n process.exit(1);\n}\n\n// Publisher\nfunction publisher(conn) {\n conn.createChannel(on_open); // creates a channel and call `on_open` when done\n function on_open(err, ch) {\n // this function will be called when the channel is created\n // `err` will contain the error object, if any errors occurred\n // `ch` will contain the channel object\n\n if (err != null) bail(err); // calls `bail` function if an error occurred when creating the channel\n ch.assertQueue(q); // asserts the queue exists\n ch.sendToQueue(q, new Buffer('something to do')); // sends a message to the queue\n }\n}\n\n// Consumer\nfunction consumer(conn) {\n var ok = conn.createChannel(on_open); // creates a channel and call `on_open` when done\n function on_open(err, ch) {\n // this function will be called when the channel is created\n // `err` will contain the error object, if any errors occurred\n // `ch` will contain the channel object\n\n if (err != null) bail(err); // calls `bail` function if an error occurred when creating the channel\n ch.assertQueue(q); // asserts the queue exists\n ch.consume(q, function(msg) { //consumes the queue\n if (msg !== null) {\n console.log(msg.content.toString()); // writes the received message to the console\n ch.ack(msg); // acknowledge that the message was received\n }\n });\n }\n}\n```\n\n========================================\n\nComments:\n- It may be worthwhile to read up on common Node.js conventions on how to deal with asynchronous function calls.\n- Thanks for your reply. I will wait for sometime for other answers before accepting this. Still I am expecting more details on this.\n- How do I reuse the channel object in other files","metadata":{"transformedAt":"2026-08-18T18:33:20.196Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":92,"estimatedTokens":798}}843{"id":"stack-24773378","source":"stackoverflow","questionId":24773378,"title":"What happens to a RabbitMQ cluster if the only disc node dies?","tags":["rabbitmq","amqp"],"text":"Title: What happens to a RabbitMQ cluster if the only disc node dies?\nTags: rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nRabbitMQ clusters need to have at least one disc node (you can't turn your last disc node to a ram node).\n\nHowever (especially in a cloud context) nodes can die - what is supposed to happen to the cluster if the only disc node dies? \n\nDoes the cluster automatically appoint a new disc node, or it continues working with no disc node.\n\n========================================\n\nCode:\n```text\nha-mode\n```\n\n```text\nha-policy\n```\n\n```text\nall\n```\n\n```text\nexactly\n```\n\n```text\nnodes\n```\n\n```text\nha-mode\n```\n\n```text\nnodes\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.196Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":7,"totalLines":41,"estimatedTokens":162}}844{"id":"stack-19857896","source":"stackoverflow","questionId":19857896,"title":"Why or when should I use messages queues such as RabbitMQ, ZeroMQ in Erlang?","tags":["erlang","rabbitmq","message-queue","zeromq"],"text":"Title: Why or when should I use messages queues such as RabbitMQ, ZeroMQ in Erlang?\nTags: erlang, rabbitmq, message-queue, zeromq\nSource: Stack Overflow\n\nQuestion:\nHello awesome Erlang community!\n\nI'm making a little project that contains a Client and a Backend. (Complicated.. right?) :)\n\nI'm making it in erlang.\n\nThe client and backend will be two separate processes and I'm wondering if I would need to (or should I) use some sort of message queue to get them to interact?\n\nI know I can get them to interact using their PIDs and send messages using the \"!\" operator.\n\nI guess what I'm trying to say is I'm struggling with finding an answer for this question: \n\n***\"Why or when should I use message queues such as RabbitMQ, ZeroMQ in Erlang\"?***\n\n========================================\n\nTop Answer:\nI would go for a messaging component when you need to decouple the different layers of my system. Also, a messaging component allows you to be able to do different integration patters with your messages/requests like topic/fanout/route based on headers...\nA messaging system is also used for scalibility purposes, so you can have multiple instances of the same process running simultaneously consuming from the same queue.\n\nLast thing I want to mention is that RabbitMQ is a message broker but ZeroMQ is not, it is a messaging library.","metadata":{"transformedAt":"2026-08-18T18:33:20.196Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":26,"estimatedTokens":335}}845{"id":"stack-74877968","source":"stackoverflow","questionId":74877968,"title":"Zipkin not working in Docker - conncection refused","tags":["spring-boot","docker","rabbitmq","microservices","zipkin"],"text":"Title: Zipkin not working in Docker - conncection refused\nTags: spring-boot, docker, rabbitmq, microservices, zipkin\nSource: Stack Overflow\n\nQuestion:\nZipkin works well locally but not in docker container. All the microservices are registered well in the Eureka and they can communicate well. But the only problem is Zipkin. I am getting the following error:\n\norg.springframework.web.client.ResourceAccessException: I/O error on\nPOST request for \"http://localhost:9411/api/v2/spans\": Connect to\nhttp://localhost:9411 [localhost/127.0.0.1] failed: Connection refused\n\nmy docker-compose.yaml is as follows:\n\n```\nversion: '3.8'\n\nservices:\n currency-exchange:\n image: samankt/springboot-udemy-currency-exchange:0.0.1-SNAPSHOT\n mem_limit: 512m\n ports:\n - '8000:8000'\n networks:\n - saman-network \n environment:\n EUREKA.CLIENT.SERVICE-URL.DEFAULTZONE: http://naming-server:8761/eureka\n EUREKA.INSTANCE.PREFERIPADDRESS: true \n SPRING.ZIPKIN.BASE-URL: http://zipkin-server:9411/\n RABBIT_URI: amqp://guest:guest@rabbitmq:5672\n SPRING_RABBITMQ_HOST: rabbitmq\n SPRING_ZIPKIN_SENDER_TYPE: rabbit\n depends_on:\n - naming-server\n - rabbitmq\n \n api-gateway:\n image: samankt/springboot-udemy-currency-api-gateway:0.0.1-snapshot\n mem_limit: 512m\n ports:\n - '8765:8765'\n networks:\n - saman-network \n environment:\n EUREKA.CLIENT.SERVICE-URL.DEFAULTZONE: http://naming-server:8761/eureka\n EUREKA.INSTANCE.PREFERIPADDRESS: true \n SPRING.ZIPKIN.BASE-URL: http://zipkin-server:9411/\n RABBIT_URI: amqp://guest:guest@rabbitmq:5672\n SPRING_RABBITMQ_HOST: rabbitmq\n SPRING_ZIPKIN_SENDER_TYPE: rabbit \n depends_on:\n - naming-server\n - rabbitmq\n \n currency-converter:\n image: samankt/currency-conversion:0.0.1-SNAPSHOT\n mem_limit: 700m\n ports:\n - '8100:8100'\n networks:\n - saman-network \n environment:\n EUREKA.CLIENT.SERVICE-URL.DEFAULTZONE: http://naming-server:8761/eureka\n EUREKA.INSTANCE.PREFERIPADDRESS: true \n SPRING.ZIPKIN.BASE-URL: http://zipkin-server:9411/\n SPRING.ZIPKIN.DISCOVERYCLIENTENABLED: true \n RABBIT_URI: amqp://guest:guest@rabbitmq:5672\n SPRING_RABBITMQ_HOST: rabbitmq\n SPRING_ZIPKIN_SENDER_TYPE: rabbit \n depends_on:\n - naming-server\n - rabbitmq\n \n naming-server:\n image: samankt/naming-server:0.0.1-SNAPSHOT\n mem_limit: 512m\n ports:\n - '8761:8761'\n environment:\n SPRING.ZIPKIN.BASE-URL: http://zipkin-server:9411/ \n networks:\n - saman-network\n \n zipkin-server:\n image: openzipkin/zipkin:latest\n mem_limit: 400m\n ports:\n - '9411:9411'\n networks:\n - saman-network \n environment:\n RABBIT_URI: amqp://guest:guest@rabbitmq:5672\n depends_on:\n - rabbitmq\n restart: always\n \n \n rabbitmq:\n image: rabbitmq:3.8.12-management\n ports:\n - '5672:5672'\n - '15672:15672'\n networks:\n - saman-network\n \nnetworks: \n saman-network:\n```\n\n========================================\n\nTop Answer:\nIn my Spring Boot 3 project, I encountered the same kind of issue, and the following solution worked for me:\n\nI added the following dependencies to my project:\n\n```\n\n io.micrometer\n micrometer-observation\n\n io.micrometer\n micrometer-tracing-bridge-otel\n\n io.opentelemetry\n opentelemetry-exporter-zipkin\n\n```\n\nIn my Docker Compose file, I set the environment variable as follows:\n\n```\nservices:\n currency-exchange:\n image: XX\n ports:\n - XX\n networks:\n - XX\n depends_on:\n - XX\n environment:\n MANAGEMENT.ZIPKIN.TRACING.ENDPOINT: http://zipkin-server:9411/api/v2/spans\n```\n\n========================================\n\nCode:\n```text\nversion: '3.8'\n\nservices:\n currency-exchange:\n image: samankt/springboot-udemy-currency-exchange:0.0.1-SNAPSHOT\n mem_limit: 512m\n ports:\n - '8000:8000'\n networks:\n - saman-network \n environment:\n EUREKA.CLIENT.SERVICE-URL.DEFAULTZONE: http://naming-server:8761/eureka\n EUREKA.INSTANCE.PREFERIPADDRESS: true \n SPRING.ZIPKIN.BASE-URL: http://zipkin-server:9411/\n RABBIT_URI: amqp://guest:guest@rabbitmq:5672\n SPRING_RABBITMQ_HOST: rabbitmq\n SPRING_ZIPKIN_SENDER_TYPE: rabbit\n depends_on:\n - naming-server\n - rabbitmq\n \n api-gateway:\n image: samankt/springboot-udemy-currency-api-gateway:0.0.1-snapshot\n mem_limit: 512m\n ports:\n - '8765:8765'\n networks:\n - saman-network \n environment:\n EUREKA.CLIENT.SERVICE-URL.DEFAULTZONE: http://naming-server:8761/eureka\n EUREKA.INSTANCE.PREFERIPADDRESS: true \n SPRING.ZIPKIN.BASE-URL: http://zipkin-server:9411/\n RABBIT_URI: amqp://guest:guest@rabbitmq:5672\n SPRING_RABBITMQ_HOST: rabbitmq\n SPRING_ZIPKIN_SENDER_TYPE: rabbit \n depends_on:\n - naming-server\n - rabbitmq\n \n currency-converter:\n image: samankt/currency-conversion:0.0.1-SNAPSHOT\n mem_limit: 700m\n ports:\n - '8100:8100'\n networks:\n - saman-network \n environment:\n EUREKA.CLIENT.SERVICE-URL.DEFAULTZONE: http://naming-server:8761/eureka\n EUREKA.INSTANCE.PREFERIPADDRESS: true \n SPRING.ZIPKIN.BASE-URL: http://zipkin-server:9411/\n SPRING.ZIPKIN.DISCOVERYCLIENTENABLED: true \n RABBIT_URI: amqp://guest:guest@rabbitmq:5672\n SPRING_RABBITMQ_HOST: rabbitmq\n SPRING_ZIPKIN_SENDER_TYPE: rabbit \n depends_on:\n - naming-server\n - rabbitmq\n \n naming-server:\n image: samankt/naming-server:0.0.1-SNAPSHOT\n mem_limit: 512m\n ports:\n - '8761:8761'\n environment:\n SPRING.ZIPKIN.BASE-URL: http://zipkin-server:9411/ \n networks:\n - saman-network\n \n zipkin-server:\n image: openzipkin/zipkin:latest\n mem_limit: 400m\n ports:\n - '9411:9411'\n networks:\n - saman-network \n environment:\n RABBIT_URI: amqp://guest:guest@rabbitmq:5672\n depends_on:\n - rabbitmq\n restart: always\n \n \n rabbitmq:\n image: rabbitmq:3.8.12-management\n ports:\n - '5672:5672'\n - '15672:15672'\n networks:\n - saman-network\n \nnetworks: \n saman-network:\n```\n\n```xml\n<dependency>\n <groupId>io.micrometer</groupId>\n <artifactId>micrometer-tracing-bridge-brave</artifactId>\n</dependency>\n<dependency>\n <groupId>io.micrometer</groupId>\n <artifactId>micrometer-observation-test</artifactId>\n <scope>test</scope>\n</dependency>\n<dependency>\n <groupId>io.zipkin.reporter2</groupId>\n <artifactId>zipkin-reporter-brave</artifactId>\n</dependency>\n<dependency>\n <groupId>org.springframework.boot</groupId>\n <artifactId>spring-boot-starter-actuator</artifactId>\n</dependency>\n```\n\n```yaml\nmanagement:\n tracing:\n sampling:\n probability: 1.0 # only for testing purpose, switch back to 0.1 for production code\n zipkin:\n tracing:\n endpoint: http://localhost:9411/api/v2/spans\n```\n\n```yaml\nmanagement:\n tracing:\n sampling:\n probability: 1.0 # only for testing purpose, switch back to 0.1 for production code\n zipkin:\n tracing:\n endpoint: http://zipkin-server:9411/api/v2/spans\n```\n\n```text\nhttp://localhost:9411/api/v2/spans\n```\n\n```text\nhttp://zipkin-server:9411/api/v2/spans\n```\n\n```text\npom.xml\n```\n\n```text\napplication.yaml\n```\n\n```text\napplication-docker.yaml\n```\n\n```text\nzipkin-server\n```\n\n```text\nSPRING_PROFILES_ACTIVATE=docker\n```\n\n```text\nSPRING.ZIPKIN.BASE-URL\n```\n\n```text\ndocker-compose.yml\n```\n\n```text\nMANAGEMENT.ZIPKIN.TRACING.ENDPOINT: http://zipkin-server:9411/api/v2/spans\n```\n\n```text\n<dependency>\n <groupId>io.micrometer</groupId>\n <artifactId>micrometer-observation</artifactId>\n</dependency>\n<dependency>\n <groupId>io.micrometer</groupId>\n <artifactId>micrometer-tracing-bridge-otel</artifactId>\n</dependency>\n<dependency>\n <groupId>io.opentelemetry</groupId>\n <artifactId>opentelemetry-exporter-zipkin</artifactId>\n</dependency>\n```\n\n```text\nservices:\n currency-exchange:\n image: XX\n ports:\n - XX\n networks:\n - XX\n depends_on:\n - XX\n environment:\n MANAGEMENT.ZIPKIN.TRACING.ENDPOINT: http://zipkin-server:9411/api/v2/spans\n```\n\n```text\nmanagement:\n tracing:\n sampling:\n probability: 1.0\n zipkin:\n tracing:\n endpoint: http://host.docker.internal:9411/api/v2/spans\n```\n\n========================================\n\nComments:\n- If you're interested in more zipkin properties with spring boot 3 the class org.springframework.boot.actuate.autoconfigure.tracing.zipki‌​n.ZipkinProperties defines them.\n- Thanks @mini for your great solutions. In the first solution, you truly mentioned the problem in calling zipkin endpoint. But as you can see I changed the endpoint call by passing the right one into the SPRING.ZIPKIN.BASE-URL , but it seems that it does not work and localhost is called by default! I have not applied micormeter yet but going to test it as you recommended. I will inform you accordingly. The second solution points to the assignment of the environment variable of SPRING.ZIPKIN.BASE-UR that I did already but the problem persisted. Spring profile use is a great recommendation.\n- I was using `zipkin-reporter-brave` and `micrometer-tracing-bridge-brave` with Spring Boot 3.0.3. I can confirm that setting `MANAGEMENT.ZIPKIN.TRACING.ENDPOINT` solved my problem. Thanks :-)\n- Setting `MANAGEMENT.ZIPKIN.TRACING.ENDPOINT` is the right answer for me.\n- Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.","metadata":{"transformedAt":"2026-08-18T18:33:20.196Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":17,"totalLines":369,"estimatedTokens":2346}}846{"id":"stack-18996005","source":"stackoverflow","questionId":18996005,"title":"docker rabbitmq hostname issue","tags":["rabbitmq","docker"],"text":"Title: docker rabbitmq hostname issue\nTags: rabbitmq, docker\nSource: Stack Overflow\n\nQuestion:\nI am build an image using Dockerfile, and I would like to add users to RabbitMQ right after installation. The problem is that during build hostname of the docker container is different from when I run the resultant image. RabbitMQ loses that user; because of changed hostname it uses another DB.\n\nI connot change `/etc/hosts` and `/etc/hostname` files from inside a container, and looks that RabbitMQ is not picking my changes to `RABBITMQ_NODENAME` and `HOSTNAME` variables.\n\nThe only thing that I found working is running this before starting RabbitMQ broker:\n\n```\necho \"NODENAME=rabbit@localhost\" >> /etc/rabbitmq/rabbitmq.conf.d/ewos.conf\n```\n\nBut then I will have to run docker image with changed hostname all the time.\n\n```\ndocker run -h=\"localhost\" image\n```\n\nAny ideas on what can be done? Maybe the solution is to add users to RabbitMQ not on build but on image run?\n\n========================================\n\nTop Answer:\nJust here is example how to configure from Dockerfile properly:\n\n```\nENV HOSTNAME localhost\n\nRUN /etc/init.d/rabbitmq-server start ; rabbitmqctl add_vhost /test; /etc/init.d/rabbitmq-server stop\n```\n\nThis is remember your config.\n\n========================================\n\nCode:\n```text\necho \"NODENAME=rabbit@localhost\" >> /etc/rabbitmq/rabbitmq.conf.d/ewos.conf\n```\n\n```text\ndocker run -h=\"localhost\" image\n```\n\n```text\n/etc/hosts\n```\n\n```text\n/etc/hostname\n```\n\n```text\nRABBITMQ_NODENAME\n```\n\n```text\nHOSTNAME\n```\n\n```text\nexec\n```\n\n```text\nENV HOSTNAME localhost\n\nRUN /etc/init.d/rabbitmq-server start ; rabbitmqctl add_vhost /test; /etc/init.d/rabbitmq-server stop\n```\n\n```text\nFROM debian:jessie\n\nMAINTAINER Francesco Casula <fra.casula@gmail.com>\n\nVOLUME [\"/var/www\"]\nWORKDIR /var/www\n\nENV HOSTNAME my-docker\nENV RABBITMQ_NODENAME rabbit@my-docker\n\nCOPY scripts /root/scripts\n\nRUN /bin/bash /root/scripts/os-setup.bash && \\\n /bin/bash /root/scripts/install-rabbitmq.bash\n\nCMD /etc/init.d/rabbitmq-server start && \\\n /bin/bash\n```\n\n```text\n#!/bin/bash\n\necho \"127.0.0.1 localhost\" > /etc/hosts\necho \"127.0.1.1 my-docker\" >> /etc/hosts\n\necho \"my-docker\" > /etc/hostname\n```\n\n```text\n#!/bin/bash\n\necho \"NODENAME=rabbit@my-docker\" > /etc/rabbitmq/rabbitmq-env.conf\n\necho 'deb http://www.rabbitmq.com/debian/ testing main' | tee /etc/apt/sources.list.d/rabbitmq.list\nwget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | apt-key add -\napt-get update\n\ncd ~\nwget https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.5/rabbitmq-server_3.6.5-1_all.deb\ndpkg -i rabbitmq-server_3.6.5-1_all.deb\napt-get install -f -y\n\n/etc/init.d/rabbitmq-server start\n\nsleep 3\n\nrabbitmq-plugins enable amqp_client mochiweb rabbitmq_management rabbitmq_management_agent \\\n rabbitmq_management_visualiser rabbitmq_web_dispatch webmachine\n\nrabbitmqctl delete_user guest\nrabbitmqctl add_user bunny password\nrabbitmqctl set_user_tags bunny administrator\nrabbitmqctl delete_vhost /\nrabbitmqctl add_vhost symfony_prod\nrabbitmqctl set_permissions -p symfony_prod bunny \".*\" \".*\" \".*\"\nrabbitmqctl add_vhost symfony_dev\nrabbitmqctl set_permissions -p symfony_dev bunny \".*\" \".*\" \".*\"\nrabbitmqctl add_vhost symfony_test\nrabbitmqctl set_permissions -p symfony_test bunny \".*\" \".*\" \".*\"\n\n/etc/init.d/rabbitmq-server restart\n\nIS_RABBIT_INSTALLED=`rabbitmqctl status | grep RabbitMQ | grep \"3\\.6\\.5\" | wc -l`\n\nif [ \"$IS_RABBIT_INSTALLED\" = \"0\" ]; then\n exit 1\nfi\n\nIS_RABBIT_CONFIGURED=`rabbitmqctl list_users | grep bunny | grep \"administrator\" | wc -l`\n\nif [ \"$IS_RABBIT_CONFIGURED\" = \"0\" ]; then\n exit 1\nfi\n```\n\n```text\ndocker run -h my-docker -it --name=my-docker -v $(pwd)/htdocs:/var/www my-docker\n```\n\n```text\n-h\n```\n\n========================================\n\nComments:\n- Also there was a problem: when I add a user and right after that stop RabbitMQ, added user is not persisted. Adding a bit of `sleep 3` before RabbitMQ stop command resolved the issue.\n- This is not solution, because images should be built from Dockerfile, not that you have to run container to set things up every time you do deployment from docker image.\n- @Rubycut you are right. Have you tested, your answer below? I haven't seen command execution separated by semicolons till this time. Did you encounter the problem with persisting configs like I did above?\n- Yes, I've use it last week on latest version of Rabbitmq and latest docker version. Semicolons work fine, you can even use \\ to go to next line if line is too long. You can also use && instead of semicolons. Yes, I had persisting problem until I changed HOSTNAME, now everything is persisted properly.\n- Seems to work. Unsure of the implications of calling the node localhost though.","metadata":{"transformedAt":"2026-08-18T18:33:20.196Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":13,"totalLines":165,"estimatedTokens":1192}}847{"id":"stack-55336811","source":"stackoverflow","questionId":55336811,"title":"how to implement Remote procedure call (RPC) in RabbitMQ using Nodejs","tags":["node.js","rabbitmq","rpc","amqp"],"text":"Title: how to implement Remote procedure call (RPC) in RabbitMQ using Nodejs\nTags: node.js, rabbitmq, rpc, amqp\nSource: Stack Overflow\n\nQuestion:\nso i want to take a Json and parse it to Object and then implement a RPC RabbitMQ Server so that i can send the Object to the Server through RabbitMQ and there the Object will be proceed to be saved in a local Array and a universally unique id which will tell where exactly is the object stored, will be returned from that Server to the client throught the RPC.\n\nthe Official Webseite shows some Implementation to RPC in RabbitMQ, here you can find their Implementration https://www.rabbitmq.com/tutorials/tutorial-six-javascript.html , in the Tutorial they send a Number and the Server will calculate Fibonacci Sequence and return the Result to the Client. instead i want to send an Object, not a Number and i want to receive the universally unique id(uuid) of that Object which i ll store in a global Array in my Program, i changed the code so that it ll send an Object and return the uuid but it didnt work. i ll apreciate any help from you guys\n\n```\n//this is my server_rpc.js code : \n const amqp = require('amqplib/callback_api');\n const uuid = require(\"uuid/v1\");\n\n amqp.connect('here is the url: example: localhost', (err, conn) => {\n\n conn.createChannel( (err, ch) => {\n\n let q = 'rpc_queue';\n\n ch.assertQueue(q, {durable: false});\n\n ch.prefetch(10);\n\n console.log(' [x] Waiting RPC requests');\n\n ch.consume(q, function reply(msg) {\n\n console.log(\"corralation key is: \", msg.properties.correlationId);\n let n = uuid();\n\n console.log(\" data received \",JSON.parse(JSON.stringify(msg.content.toString())));\n\n console.log(\"corralation key is: \", msg.properties.correlationId);\n\n ch.sendToQueue(msg.properties.replyTo, Buffer.from(n.toString()), {correlationId: msg.properties.correlationId});\n\n ch.ack(msg);\n });\n});\n```\n\n});\n\n```\n// and this is my client_rpc.js code : \n const amqp = require('amqplib/callback_api');\n const uuid = require(\"uuid/v1\");\n const express = require(\"express\");\n\nlet data = {\n\"name\" : \"hil01\", \n\"region\" : \"weissach\",\n\"ID\" : \"1\",\n\"version\" : \"0.0.1\"\n } \n\n amqp.connect('url: example localhost ', (err, conn) => {\n\n conn.createChannel( (err, ch) => {\n\n ch.assertQueue('', {exclusive: true}, (err, q) => {\n\n var corr = generateUuid();\n var newHil = JSON.stringify(data);\n\n console.log(\" [x] Requesting uuid for the registered HIL: \", newHil );\n\n console.log(\"corralation key is: \", corr);\n\n ch.consume(q.queue, function(msg) {\n\n if(msg.properties.correlationId == corr) {\n\n console.log(\" [.] Got %s\", msg.content.toString());\n setTimeout(() => { conn.close(); process.exit(0) }, 100);\n }\n }, {noAck: true});\n\n ch.sendToQueue('rpc_queue', Buffer.from(newHil, {correlationId: corr, replyTo: q.queue }));\n });\n});\n```\n\n});\n\n```\n//method to generate the uuid, later will be replaced with the real \n uuid function \n var generateUuid = () => Math.random().toString() + \n Math.random().toString() + Math.random().toString() ;\n```\n\nwhen i run server_rpc, [x] waiting for requests should be printed then in a seperate cmd i run client_rpc.js then the object should be sent and the server execute and return to me the uuid back to the client.\n\n========================================\n\nTop Answer:\nactually, this is not a answer of question. just *for-your-information* text\n\n### Changes\n\nnow 2022 `amqplib` API little bit changed, like below:\n\n- `channel.responseEmitter.emit` to `channel.emit`\n\n- `channel.responseEmitter.once` to `channel.once`\n\n- `channel.responseEmitter.setMaxListeners` to `channel.setMaxListeners`\n\nmore details see official api document\n\n### Alternatives\n\nand if you looking for single-turn rpc (like request and response, grep response data directly).\n\nI recommend use `channel.get` see detail in here\n\n========================================\n\nCode:\n```text\n//this is my server_rpc.js code : \n const amqp = require('amqplib/callback_api');\n const uuid = require(\"uuid/v1\");\n\n amqp.connect('here is the url: example: localhost', (err, conn) => {\n\n conn.createChannel( (err, ch) => {\n\n let q = 'rpc_queue';\n\n ch.assertQueue(q, {durable: false});\n\n ch.prefetch(10);\n\n console.log(' [x] Waiting RPC requests');\n\n ch.consume(q, function reply(msg) {\n\n console.log(\"corralation key is: \", msg.properties.correlationId);\n let n = uuid();\n\n\n console.log(\" data received \",JSON.parse(JSON.stringify(msg.content.toString())));\n\n console.log(\"corralation key is: \", msg.properties.correlationId);\n\n ch.sendToQueue(msg.properties.replyTo, Buffer.from(n.toString()), {correlationId: msg.properties.correlationId});\n\n ch.ack(msg);\n });\n});\n```\n\n```text\n// and this is my client_rpc.js code : \n const amqp = require('amqplib/callback_api');\n const uuid = require(\"uuid/v1\");\n const express = require(\"express\");\n\nlet data = {\n\"name\" : \"hil01\", \n\"region\" : \"weissach\",\n\"ID\" : \"1\",\n\"version\" : \"0.0.1\"\n } \n\n\n\n amqp.connect('url: example localhost ', (err, conn) => {\n\n conn.createChannel( (err, ch) => {\n\n ch.assertQueue('', {exclusive: true}, (err, q) => {\n\n var corr = generateUuid();\n var newHil = JSON.stringify(data);\n\n console.log(\" [x] Requesting uuid for the registered HIL: \", newHil );\n\n console.log(\"corralation key is: \", corr);\n\n ch.consume(q.queue, function(msg) {\n\n if(msg.properties.correlationId == corr) {\n\n console.log(\" [.] Got %s\", msg.content.toString());\n setTimeout(() => { conn.close(); process.exit(0) }, 100);\n }\n }, {noAck: true});\n\n ch.sendToQueue('rpc_queue', Buffer.from(newHil, {correlationId: corr, replyTo: q.queue }));\n });\n});\n```\n\n```text\n//method to generate the uuid, later will be replaced with the real \n uuid function \n var generateUuid = () => Math.random().toString() + \n Math.random().toString() + Math.random().toString() ;\n```\n\n```text\nconst amqp = require('amqplib');\nconst uuidv4 = require('uuid/v4');\n\nconst RABBITMQ = 'amqp://guest:guest@localhost:5672';\n\nconst open = require('amqplib').connect(RABBITMQ);\nconst q = 'example';\n\n// Consumer\nopen\n .then(function(conn) {\n console.log(`[ ${new Date()} ] Server started`);\n return conn.createChannel();\n })\n .then(function(ch) {\n return ch.assertQueue(q).then(function(ok) {\n return ch.consume(q, function(msg) {\n console.log(\n `[ ${new Date()} ] Message received: ${JSON.stringify(\n JSON.parse(msg.content.toString('utf8')),\n )}`,\n );\n if (msg !== null) {\n const response = {\n uuid: uuidv4(),\n };\n\n console.log(\n `[ ${new Date()} ] Message sent: ${JSON.stringify(response)}`,\n );\n\n ch.sendToQueue(\n msg.properties.replyTo,\n Buffer.from(JSON.stringify(response)),\n {\n correlationId: msg.properties.correlationId,\n },\n );\n\n ch.ack(msg);\n }\n });\n });\n })\n .catch(console.warn);\n```\n\n```text\nconst amqp = require('amqplib');\nconst EventEmitter = require('events');\nconst uuid = require('uuid');\n\nconst RABBITMQ = 'amqp://guest:guest@localhost:5672';\n\n// pseudo-queue for direct reply-to\nconst REPLY_QUEUE = 'amq.rabbitmq.reply-to';\nconst q = 'example';\n\n// Credits for Event Emitter goes to https://github.com/squaremo/amqp.node/issues/259\n\nconst createClient = rabbitmqconn =>\n amqp\n .connect(rabbitmqconn)\n .then(conn => conn.createChannel())\n .then(channel => {\n channel.responseEmitter = new EventEmitter();\n channel.responseEmitter.setMaxListeners(0);\n channel.consume(\n REPLY_QUEUE,\n msg => {\n channel.responseEmitter.emit(\n msg.properties.correlationId,\n msg.content.toString('utf8'),\n );\n },\n { noAck: true },\n );\n return channel;\n });\n\nconst sendRPCMessage = (channel, message, rpcQueue) =>\n new Promise(resolve => {\n const correlationId = uuid.v4();\n channel.responseEmitter.once(correlationId, resolve);\n channel.sendToQueue(rpcQueue, Buffer.from(message), {\n correlationId,\n replyTo: REPLY_QUEUE,\n });\n });\n\nconst init = async () => {\n const channel = await createClient(RABBITMQ);\n const message = { uuid: uuid.v4() };\n\n console.log(`[ ${new Date()} ] Message sent: ${JSON.stringify(message)}`);\n\n const respone = await sendRPCMessage(channel, JSON.stringify(message), q);\n\n console.log(`[ ${new Date()} ] Message received: ${respone}`);\n\n process.exit();\n};\n\ntry {\n init();\n} catch (e) {\n console.log(e);\n}\n```\n\n```text\namqplib\n```\n\n```text\nchannel.responseEmitter.emit\n```\n\n```text\nchannel.emit\n```\n\n```text\nchannel.responseEmitter.once\n```\n\n```text\nchannel.once\n```\n\n```text\nchannel.responseEmitter.setMaxListeners\n```\n\n```text\nchannel.setMaxListeners\n```\n\n```text\nchannel.get\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.197Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":13,"totalLines":346,"estimatedTokens":2239}}848{"id":"stack-40146740","source":"stackoverflow","questionId":40146740,"title":"Change the arguments in a RabbitMQ queue","tags":["c#","rabbitmq","message-queue"],"text":"Title: Change the arguments in a RabbitMQ queue\nTags: c#, rabbitmq, message-queue\nSource: Stack Overflow\n\nQuestion:\nI have a RabbitMQ queue that was originally declared like this:\n\n```\nvar result = _channel.QueueDeclare(\"NewQueue\", true, false, false, null);\n```\n\nAnd I'm trying to add a dead letter exchange, so I've changed the code to this:\n\n```\n_channel.ExchangeDeclare(\"dl.exchange\", \"direct\");\nDictionary args = new Dictionary()\n{\n { \"x-dead-letter-exchange\", \"dl.exchange\" }\n}; \n\nvar result = _channel.QueueDeclare(\"NewQueue\", true, false, false, args);\n```\n\nWhen I run this, I get the error:\n\n Exception thrown:\n 'RabbitMQ.Client.Exceptions.OperationInterruptedException' in\n RabbitMQ.Client.dll\n\n \n Additional information: The AMQP operation was interrupted: AMQP\n close-reason, initiated by Peer, code=406, text=\"PRECONDITION_FAILED -\n inequivalent arg 'x-dead-letter-exchange' for queue 'NewQueue' in\n vhost '/': received the value 'dl.exchange' of type 'longstr' but\n current is none\", classId=50, methodId=10, cause=\n\nThe error seems pretty self explanatory, and if I delete the queue, when I re-create it, I don't get the error, but my question is: is there a way to make this change without deleting the queue?\n\n========================================\n\nCode:\n```text\nvar result = _channel.QueueDeclare(\"NewQueue\", true, false, false, null);\n```\n\n```text\n_channel.ExchangeDeclare(\"dl.exchange\", \"direct\");\nDictionary<string, object> args = new Dictionary<string, object>()\n{\n { \"x-dead-letter-exchange\", \"dl.exchange\" }\n}; \n\nvar result = _channel.QueueDeclare(\"NewQueue\", true, false, false, args);\n```\n\n```text\nrabbitmqctl set_policy DLX \"NewQueue\" '{\"dead-letter-exchange\":\"my-dlx\"}' --apply-to queues\n```\n\n```text\nargs\n```\n\n========================================\n\nComments:\n- For some reason this does not work for me. The message isn't routed, and only doing so via the \"x-dead-letter-exchange\" works","metadata":{"transformedAt":"2026-08-18T18:33:20.197Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":67,"estimatedTokens":484}}849{"id":"stack-60645591","source":"stackoverflow","questionId":60645591,"title":"Unable to install RabbitMQ on Raspbian (Buster) because Erlang isn't the correct version, even though it says it's up to date","tags":["rabbitmq","erlang","debian","raspbian"],"text":"Title: Unable to install RabbitMQ on Raspbian (Buster) because Erlang isn't the correct version, even though it says it's up to date\nTags: rabbitmq, erlang, debian, raspbian\nSource: Stack Overflow\n\nQuestion:\nI'm quite new to Raspberry Pi and Linux/Debian, so please bear with me. I have been trying for hours now to install rabbitMQ on my Raspberry Pi 3, to no avail. I followed the steps, but in the end I just get this whenever I try to write `sudo apt-get install rabbitmq-server` :\n\n```\nReading package lists... Done\nBuilding dependency tree \nReading state information... Done\nSome packages could not be installed. This may mean that you have\nrequested an impossible situation or if you are using the unstable\ndistribution that some required packages have not yet been created\nor been moved out of Incoming.\nThe following information may help to resolve the situation:\n\nThe following packages have unmet dependencies:\n rabbitmq-server : Depends: erlang-base (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n erlang-base-hipe (>= 1:21.3) but it is not installable or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-crypto (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-eldap (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-inets (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-mnesia (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-os-mon (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-parsetools (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-public-key (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-runtime-tools (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-ssl (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-syntax-tools (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-tools (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-xmerl (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\nE: Unable to correct problems, you have held broken packages.\n```\n\nAfter seeing this, I realize that my Erlang wasn't the correct version, and needs to be 1:21.3, instead of 1:21.2, so I went to go and update it, but it then says:\n\n```\npi@raspberrypi:~ $ sudo apt-get install erlang\nReading package lists... Done\nBuilding dependency tree \nReading state information... Done\nerlang is already the newest version (1:21.2.6+dfsg-1).\n0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n```\n\nI looked on the Erlang web site and it just says write `apt-get install erlang` to make it work, but for some reason it just wants to stay at version 1:21.2.6, instead of the 22.2 that seems to be a latest version. Does anyone have any advice?\n\n========================================\n\nTop Answer:\nI installed this way and it worked -\n\n```\nsudo apt-get install rabbitmq-server\nsudo rabbitmq-plugins enable rabbitmq_management\n```\n\n========================================\n\nCode:\n```text\nReading package lists... Done\nBuilding dependency tree \nReading state information... Done\nSome packages could not be installed. This may mean that you have\nrequested an impossible situation or if you are using the unstable\ndistribution that some required packages have not yet been created\nor been moved out of Incoming.\nThe following information may help to resolve the situation:\n\nThe following packages have unmet dependencies:\n rabbitmq-server : Depends: erlang-base (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n erlang-base-hipe (>= 1:21.3) but it is not installable or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-crypto (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-eldap (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-inets (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-mnesia (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-os-mon (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-parsetools (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-public-key (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-runtime-tools (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-ssl (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-syntax-tools (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-tools (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\n Depends: erlang-xmerl (>= 1:21.3) but 1:21.2.6+dfsg-1 is to be installed or\n esl-erlang (>= 1:21.3) but it is not installable\nE: Unable to correct problems, you have held broken packages.\n```\n\n```text\npi@raspberrypi:~ $ sudo apt-get install erlang\nReading package lists... Done\nBuilding dependency tree \nReading state information... Done\nerlang is already the newest version (1:21.2.6+dfsg-1).\n0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n```\n\n```text\nsudo apt-get install rabbitmq-server\n```\n\n```text\napt-get install erlang\n```\n\n```text\nsudo apt-get remove erlang*\n```\n\n```text\nsudo dpkg -i name_of_the_erlang_package.deb\n```\n\n```text\nsudo dpkg -i rabbitmq-server_3.8.4-1_all.deb\n```\n\n```text\nsudo systemctl enable rabbitmq-server\nsudo systemctl start rabbitmq-server\nsudo rabbitmq-plugins enable rabbitmq_management\n```\n\n```text\nhttp://localhost:15672\n```\n\n```text\nsudo rabbitmqctl add_user your_username your_password\nsudo rabbitmqctl set_user_tags your_username administrator\nsudo rabbitmqctl set_permissions -p / your_username \".*\" \".*\" \".*\"\n```\n\n```text\nsudo apt-get install rabbitmq-server\nsudo rabbitmq-plugins enable rabbitmq_management\n```\n\n========================================\n\nComments:\n- works for me and even easier than the official instruction.... btw, I removed my broken mqtt-server, this is the only 1 extra step I did.\n- I just found out that the RabbitMQ installed this way is a very old version: 3.7.8 with Erlang 21.2.6 . I cannot even connect to the RabbitMQ server with my Mqtt Dash(Android app). Could you please help?\n- Edited my answer to support Franva","metadata":{"transformedAt":"2026-08-18T18:33:20.197Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":11,"totalLines":171,"estimatedTokens":1982}}850{"id":"stack-65484292","source":"stackoverflow","questionId":65484292,"title":"c# - DbContext gets disposed in BackgroundService","tags":["c#","asp.net-core","entity-framework-core","rabbitmq","asp.net-core-hosted-services"],"text":"Title: c# - DbContext gets disposed in BackgroundService\nTags: c#, asp.net-core, entity-framework-core, rabbitmq, asp.net-core-hosted-services\nSource: Stack Overflow\n\nQuestion:\nI have a WebAPI that should also receive messages from RabbitMQ. I used this tutorial, because I know that sometimes IIS likes to kill long-running tasks (didn't test it on server yet though, maybe it won't work). I have a service that handles messages that are received via RabbitMQ. First problem I met - I couldn't inject it into `BackgroundService` class, so I used `IServiceScopeFactory`. Now, I have to consume messages from two queues, and as I understood, best practice is to use two channels for this. But the handling is done in one service. BackgroundService:\n\n```\npublic class ConsumeRabbitMQHostedService : BackgroundService\n{\n private IConnection _connection;\n private IModel _firstChannel;\n private IModel _secondChannel;\n private RabbitConfigSection _rabbitConfig;\n public IServiceScopeFactory _serviceScopeFactory;\n\n public ConsumeRabbitMQHostedService(IOptions rabbitConfig, IServiceScopeFactory serviceScopeFactory)\n {\n _rabbitConfig = rabbitConfig.Value;\n _serviceScopeFactory = serviceScopeFactory;\n InitRabbitMQ();\n }\n\n private void InitRabbitMQ()\n {\n var factory = new ConnectionFactory { HostName = _rabbitConfig.HostName, UserName = _rabbitConfig.UserName, Password = _rabbitConfig.Password };\n\n \n _connection = factory.CreateConnection();\n\n \n _firstChannel = _connection.CreateModel();\n\n _firstChannel.ExchangeDeclare(_rabbitConfig.DefaultExchange, ExchangeType.Topic);\n _firstChannel.QueueDeclare(_rabbitConfig.Queues.ConsumeQueues.FirstItemsConsumeQueue, true, false, false, null);\n _firstChannel.QueueBind(_rabbitConfig.Queues.ConsumeQueues.FirstItemsConsumeQueue, _rabbitConfig.DefaultExchange, \"*.test.queue\", null);\n _firstChannel.BasicQos(0, 1, false);\n\n _secondChannel = _connection.CreateModel();\n\n _secondChannel.ExchangeDeclare(_rabbitConfig.DefaultExchange, ExchangeType.Topic);\n _secondChannel.QueueDeclare(_rabbitConfig.Queues.ConsumeQueues.SecondItemsConsumeQueue, true, false, false, null);\n _secondChannel.QueueBind(_rabbitConfig.Queues.ConsumeQueues.SecondItemsConsumeQueue, _rabbitConfig.DefaultExchange, \"*.test.queue\", null);\n _secondChannel.BasicQos(0, 1, false);\n\n _connection.ConnectionShutdown += RabbitMQ_ConnectionShutdown;\n }\n protected override Task ExecuteAsync(CancellationToken stoppingToken)\n {\n stoppingToken.ThrowIfCancellationRequested();\n\n var firstConsumer = new EventingBasicConsumer(_firstChannel);\n var secondConsumer = new EventingBasicConsumer(_secondChannel);\n using (var scope = _serviceScopeFactory.CreateScope())\n {\n IIntegrationService scoped = scope.ServiceProvider.GetRequiredService();\n firstConsumer.Received += (ch, ea) =>\n {\n // received message \n var content = System.Text.Encoding.UTF8.GetString(ea.Body.ToArray());\n\n // handle the received message \n HandleFirstMessage(content, scoped);\n _firstChannel.BasicAck(ea.DeliveryTag, false);\n\n };\n firstConsumer.Shutdown += OnConsumerShutdown;\n firstConsumer.Registered += OnConsumerRegistered;\n firstConsumer.Unregistered += OnConsumerUnregistered;\n firstConsumer.ConsumerCancelled += OnConsumerConsumerCancelled;\n _firstChannel.BasicConsume(_rabbitConfig.Queues.ConsumeQueues.FirstItemsConsumeQueue, false, firstConsumer);\n }\n using (var scope = _serviceScopeFactory.CreateScope())\n {\n IIntegrationService scoped = scope.ServiceProvider.GetRequiredService();\n secondConsumer.Received += (ch, ea) =>\n {\n // received message \n\n var content = System.Text.Encoding.UTF8.GetString(ea.Body.ToArray());\n\n // handle the received message \n HandleSecondMessage(content, scoped);\n _secondChannel.BasicAck(ea.DeliveryTag, false);\n };\n\n secondConsumer.Shutdown += OnConsumerShutdown;\n secondConsumer.Registered += OnConsumerRegistered;\n secondConsumer.Unregistered += OnConsumerUnregistered;\n secondConsumer.ConsumerCancelled += OnConsumerConsumerCancelled;\n\n _secondChannel.BasicConsume(_rabbitConfig.Queues.ConsumeQueues.SecondItemsConsumeQueue, false, secondConsumer);\n }\n return Task.CompletedTask;\n }\n\n private void HandleFirstMessage(string content, IIntegrationService integrationService)\n {\n List dataToImport = JsonConvert.DeserializeObject>(content);\n integrationService.ImportFirst(dataToImport);\n }\n\n private void HandleSecondMessage(string content, IIntegrationService integrationService)\n {\n List importData = JsonConvert.DeserializeObject>(content);\n integrationService.ImportSecond(importData);\n }\n\n private void OnConsumerConsumerCancelled(object sender, ConsumerEventArgs e) { }\n private void OnConsumerUnregistered(object sender, ConsumerEventArgs e) { }\n private void OnConsumerRegistered(object sender, ConsumerEventArgs e) { }\n private void OnConsumerShutdown(object sender, ShutdownEventArgs e) { }\n private void RabbitMQ_ConnectionShutdown(object sender, ShutdownEventArgs e) { }\n\n public override void Dispose()\n {\n _firstChannel.Close();\n _connection.Close();\n base.Dispose();\n }\n}\n```\n\nIn service I get\n\nSystem.ObjectDisposedException: 'Cannot access a disposed context instance. A common cause of this error is disposing a context instance that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling 'Dispose' on the context instance, or wrapping it in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances.\nObject name: 'IntegrationDbContext'.'\n\n`DbContext` is injected into `IIntegrationService`. If I understand what's happening, two instances of the service(or even one) `DbContext`, and when one of them finishes it disposes `DbContext`. I tried not to create two instances (all code inside one `using`), tried making `IIntegrationService` transient, tried doing everything asynchronously (it was initial version, made it synchronous to test) - still same error. What should I do here? And is this the right approach?\n\n**Update 1.** `ConfigureServices` in `Startup`:\n\n```\npublic void ConfigureServices(IServiceCollection services)\n {\n var rabbitConfigSection =\n Configuration.GetSection(\"Rabbit\");\n services.Configure(rabbitConfigSection);\n services.AddDbContext(options =>\n options.UseSqlServer(Configuration.GetConnectionString(\"DefaultConnection\")));\n\n services.AddCors();\n services.AddSwaggerGen(c =>\n {\n c.SwaggerDoc(\"v1\", new OpenApiInfo\n {\n Title = \"My API\",\n Version = \"v1\"\n });\n });\n services.AddRabbit(Configuration);\n services.AddHostedService();\n services.AddControllers();\n services.AddTransient();// it's transient now, same error with scoped\n }\n```\n\n========================================\n\nCode:\n```text\npublic class ConsumeRabbitMQHostedService : BackgroundService\n{\n private IConnection _connection;\n private IModel _firstChannel;\n private IModel _secondChannel;\n private RabbitConfigSection _rabbitConfig;\n public IServiceScopeFactory _serviceScopeFactory;\n\n public ConsumeRabbitMQHostedService(IOptions<RabbitConfigSection> rabbitConfig, IServiceScopeFactory serviceScopeFactory)\n {\n _rabbitConfig = rabbitConfig.Value;\n _serviceScopeFactory = serviceScopeFactory;\n InitRabbitMQ();\n }\n\n private void InitRabbitMQ()\n {\n var factory = new ConnectionFactory { HostName = _rabbitConfig.HostName, UserName = _rabbitConfig.UserName, Password = _rabbitConfig.Password };\n\n \n _connection = factory.CreateConnection();\n\n \n _firstChannel = _connection.CreateModel();\n\n _firstChannel.ExchangeDeclare(_rabbitConfig.DefaultExchange, ExchangeType.Topic);\n _firstChannel.QueueDeclare(_rabbitConfig.Queues.ConsumeQueues.FirstItemsConsumeQueue, true, false, false, null);\n _firstChannel.QueueBind(_rabbitConfig.Queues.ConsumeQueues.FirstItemsConsumeQueue, _rabbitConfig.DefaultExchange, \"*.test.queue\", null);\n _firstChannel.BasicQos(0, 1, false);\n\n _secondChannel = _connection.CreateModel();\n\n _secondChannel.ExchangeDeclare(_rabbitConfig.DefaultExchange, ExchangeType.Topic);\n _secondChannel.QueueDeclare(_rabbitConfig.Queues.ConsumeQueues.SecondItemsConsumeQueue, true, false, false, null);\n _secondChannel.QueueBind(_rabbitConfig.Queues.ConsumeQueues.SecondItemsConsumeQueue, _rabbitConfig.DefaultExchange, \"*.test.queue\", null);\n _secondChannel.BasicQos(0, 1, false);\n\n _connection.ConnectionShutdown += RabbitMQ_ConnectionShutdown;\n }\n protected override Task ExecuteAsync(CancellationToken stoppingToken)\n {\n stoppingToken.ThrowIfCancellationRequested();\n\n var firstConsumer = new EventingBasicConsumer(_firstChannel);\n var secondConsumer = new EventingBasicConsumer(_secondChannel);\n using (var scope = _serviceScopeFactory.CreateScope())\n {\n IIntegrationService scoped = scope.ServiceProvider.GetRequiredService<IIntegrationService>();\n firstConsumer.Received += (ch, ea) =>\n {\n // received message \n var content = System.Text.Encoding.UTF8.GetString(ea.Body.ToArray());\n\n // handle the received message \n HandleFirstMessage(content, scoped);\n _firstChannel.BasicAck(ea.DeliveryTag, false);\n\n };\n firstConsumer.Shutdown += OnConsumerShutdown;\n firstConsumer.Registered += OnConsumerRegistered;\n firstConsumer.Unregistered += OnConsumerUnregistered;\n firstConsumer.ConsumerCancelled += OnConsumerConsumerCancelled;\n _firstChannel.BasicConsume(_rabbitConfig.Queues.ConsumeQueues.FirstItemsConsumeQueue, false, firstConsumer);\n }\n using (var scope = _serviceScopeFactory.CreateScope())\n {\n IIntegrationService scoped = scope.ServiceProvider.GetRequiredService<IIntegrationService>();\n secondConsumer.Received += (ch, ea) =>\n {\n // received message \n\n var content = System.Text.Encoding.UTF8.GetString(ea.Body.ToArray());\n\n // handle the received message \n HandleSecondMessage(content, scoped);\n _secondChannel.BasicAck(ea.DeliveryTag, false);\n };\n\n\n secondConsumer.Shutdown += OnConsumerShutdown;\n secondConsumer.Registered += OnConsumerRegistered;\n secondConsumer.Unregistered += OnConsumerUnregistered;\n secondConsumer.ConsumerCancelled += OnConsumerConsumerCancelled;\n\n _secondChannel.BasicConsume(_rabbitConfig.Queues.ConsumeQueues.SecondItemsConsumeQueue, false, secondConsumer);\n }\n return Task.CompletedTask;\n }\n\n private void HandleFirstMessage(string content, IIntegrationService integrationService)\n {\n List<StockImportDto> dataToImport = JsonConvert.DeserializeObject<List<StockImportDto>>(content);\n integrationService.ImportFirst(dataToImport);\n }\n\n private void HandleSecondMessage(string content, IIntegrationService integrationService)\n {\n List<Import901Data> importData = JsonConvert.DeserializeObject<List<Import901Data>>(content);\n integrationService.ImportSecond(importData);\n }\n\n private void OnConsumerConsumerCancelled(object sender, ConsumerEventArgs e) { }\n private void OnConsumerUnregistered(object sender, ConsumerEventArgs e) { }\n private void OnConsumerRegistered(object sender, ConsumerEventArgs e) { }\n private void OnConsumerShutdown(object sender, ShutdownEventArgs e) { }\n private void RabbitMQ_ConnectionShutdown(object sender, ShutdownEventArgs e) { }\n\n public override void Dispose()\n {\n _firstChannel.Close();\n _connection.Close();\n base.Dispose();\n }\n}\n```\n\n```text\npublic void ConfigureServices(IServiceCollection services)\n {\n var rabbitConfigSection =\n Configuration.GetSection(\"Rabbit\");\n services.Configure<RabbitConfigSection>(rabbitConfigSection);\n services.AddDbContext<SUNDbContext>(options =>\n options.UseSqlServer(Configuration.GetConnectionString(\"DefaultConnection\")));\n\n services.AddCors();\n services.AddSwaggerGen(c =>\n {\n c.SwaggerDoc(\"v1\", new OpenApiInfo\n {\n Title = \"My API\",\n Version = \"v1\"\n });\n });\n services.AddRabbit(Configuration);\n services.AddHostedService<ConsumeRabbitMQHostedService>();\n services.AddControllers();\n services.AddTransient<IIntegrationService, IntegrationService>();// it's transient now, same error with scoped\n }\n```\n\n```text\nBackgroundService\n```\n\n```text\nIServiceScopeFactory\n```\n\n```text\nDbContext\n```\n\n```text\nIIntegrationService\n```\n\n```text\nDbContext\n```\n\n```text\nDbContext\n```\n\n```text\nusing\n```\n\n```text\nIIntegrationService\n```\n\n```text\nConfigureServices\n```\n\n```text\nStartup\n```\n\n```text\nprivate void HandleFirstMessage(string content)\n{\n using (var scope = _serviceScopeFactory.CreateScope())\n {\n IIntegrationService integrationService = scope.ServiceProvider.GetRequiredService<IIntegrationService>();\n List<StockImportDto> dataToImport = JsonConvert.DeserializeObject<List<StockImportDto>>(content);\n integrationService.ImportFirst(dataToImport);\n }\n}\n```\n\n```text\nscope\n```\n\n```text\n_serviceScopeFactory.CreateScope()\n```\n\n========================================\n\nComments:\n- It probably doesn't affect anything, but just because I noticed: you close the first channel on Dispose, but not the second, and then close the connection that is shared.\n- Can you also post your Startup code where you build/register the DbContext and IIntegrationService?\n- What happens when `scope` is disposed? What type of teardown occurs for anything created by the scope?\n- @Nikki9696, fixed it, still same error\n- @DavidL, msdn says that \"An IServiceScope controlling the lifetime of the scope. Once this is disposed, any scoped services that have been resolved from the ServiceProvider will also be disposed.\"\n- So following that line of reasoning, if you have a persistent scope that is resolved outside of the context of an individual message, what happens if the scope disposes before a message is handled? In other words, you need to resolve a separate scope per message that is handled inside of the message handler.\n- @DavidL thanks a lot, it worked. I didn't think about that scenario, I thought that DbContext is disposed because of how scoped services work. If you post it as an answer, I will accept it\n- Typically you'd be correct, but in this case you are creating your own scoping which changes the lifetime. I added an answer. Glad it helped!\n- I still can't fully get it, will read some more. It's weird that something declared inside using block is disposed before that using block is finished\n- It can’t be disposed before the using block is finished. In your original code the using block would finish before your message was handled however.","metadata":{"transformedAt":"2026-08-18T18:33:20.197Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":15,"totalLines":375,"estimatedTokens":3766}}851{"id":"stack-33890701","source":"stackoverflow","questionId":33890701,"title":"RabbitTemplate receive messages and requeue","tags":["spring","rabbitmq","amqp","spring-amqp","spring-rabbit"],"text":"Title: RabbitTemplate receive messages and requeue\nTags: spring, rabbitmq, amqp, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nMy question is very similar to this one:\nRabbitTemplate receive and requeue\nUnfortunately it has been marked as answered though the answer doesn't suit my needs.\n\nI want to mimic the functionality of the Rabbit Admin UI, i.e. I want to synchronously read messages from a queue, but don't want the queue to lose them, i.e. something like having a peek.\n\nThe answer here RabbitTemplate receive and requeue suggests using a listener, but in that case it'll read and requeue indefinitely. I want to get and requeue the messages just once, so I guess I should be using RabbitTemplate, not a listener.\n\n========================================\n\nCode:\n```text\nclass Peeker implements ChannelCallback<Message> {\n\n final MessagePropertiesConverter propertiesConverter = new DefaultMessagePropertiesConverter();\n\n @Override\n public Message doInRabbit(Channel channel) throws Exception {\n GetResponse result = channel.basicGet(\"someQ\", false);\n if (result == null) {\n return null;\n }\n channel.basicReject(result.getEnvelope().getDeliveryTag(), true);\n return new Message(result.getBody(), propertiesConverter.toMessageProperties(\n result.getProps(), result.getEnvelope(), \"UTF-8\"));\n }\n}\nPeeker peeker = new Peeker();\n\n\n...\n\n\nMessage peek = this.rabbitTemplate.execute(peeker);\n```\n\n========================================\n\nComments:\n- @GarryRussel, looks good. But how can I get N messages (or all the messages)? Should I invoke basicGet in a loop until I get null?\n- Yes, and you can reject them all with one call to `basicNack` (instead of `basicReject`) - obviously change the return type to `Collection` or similar.","metadata":{"transformedAt":"2026-08-18T18:33:20.197Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":46,"estimatedTokens":457}}852{"id":"stack-35313861","source":"stackoverflow","questionId":35313861,"title":"Any advantage using different Exchanges in RabbitMQ?","tags":["rabbitmq","message-queue","amqp"],"text":"Title: Any advantage using different Exchanges in RabbitMQ?\nTags: rabbitmq, message-queue, amqp\nSource: Stack Overflow\n\nQuestion:\nIs there any difference between using the default (direct) exchange than creating a custom direct exchange for each queue?\n\n```\n(default exchange) -> queue1\n(default exchange) -> queue2\n```\n\nvs.\n\n```\nqueue1_direct_exchange -> queue1\nqueue2_direct_exchange -> queue2\n```\n\nIn the RabbitMQ dashboard I can see that if I use the default exchange for every queue it has more messages rate so I'm wondering if using different exchanges would increase the performance of message dispatching...\n\nThanks in advance!\n\n========================================\n\nCode:\n```text\n(default exchange) -> queue1\n(default exchange) -> queue2\n```\n\n```text\nqueue1_direct_exchange -> queue1\nqueue2_direct_exchange -> queue2\n```\n\n========================================\n\nComments:\n- I am speculating here but when using direct exchange you need to check if the message has the correct key and route it accordingly so you have some overhead right there. But when you use default exchange it's just dumb broadcast and therefore faster.\n- this is a close enough to a duplicate of stackoverflow.com/questions/33622667/… that i would rather just point you to my answer, there\n- Thanks @DerickBailey but I think my question is not answered and I think it's not duplicated. My question it is more about performance... Is it better to distribute the messages through different exchanges in terms of performance?\n- ah, sorry - didn't see the bit about performance previously... added an answer below\n- thanks for sharing, good read. However I disagree with the approach of declaring queue within subscriber simply for the fact that if you publish to an exchange without a queue bind, then the messages are lost. I think in your analogy it would be like sending a post to the post office without an address written on it. Additionally, most of the time the producer & consumer are 2 separate processes. Unless you can guarantee the consumer starts first (to ensure there exists a queue bound to the exchange), then you should bind queue to exchange in producer to ensure no message lost.\n- The link to the article is dead","metadata":{"transformedAt":"2026-08-18T18:33:20.197Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":45,"estimatedTokens":557}}853{"id":"stack-39484265","source":"stackoverflow","questionId":39484265,"title":"Celery - RabbitMQ as a Service - Broker Secure Connection (TSL/SSL) - Message Signing","tags":["security","ssl","rabbitmq","celery","amqp"],"text":"Title: Celery - RabbitMQ as a Service - Broker Secure Connection (TSL/SSL) - Message Signing\nTags: security, ssl, rabbitmq, celery, amqp\nSource: Stack Overflow\n\nQuestion:\nI am trying to configure Celery on my Django web server securely and I can figure out two alternatives on achieving this. Either securing the broker or signing the messages. \n\nCelery, needs a message broker in which case is RabbitMQ.\n\nI am using a \"RabbitMQ as a service\" implementation, which means that the RabbitMQ server is reached through the internet using the amqp protocol.\n\nThe service provider distributes an amqp uri, and also supports amqps:\n\n The \"amqps\" URI scheme is used to instruct a client to make an secured connection to the server. \n\n- Apparently, this is what I need, otherwise all my messages will be circulating around the net, naked on the wire.\n\nIn order to use amqps, celery needs the following configuration:\n\n```\nimport ssl\n\nBROKER_USE_SSL = {\n 'keyfile': '/var/ssl/private/worker-key.pem',\n 'certfile': '/var/ssl/amqp-server-cert.pem',\n 'ca_certs': '/var/ssl/myca.pem',\n 'cert_reqs': ssl.CERT_REQUIRED\n}\n```\n\n**Question:**\nWhere can I find those `.pem` files? \n\nAccording to RabbitMQ docs, I have to create them myself and configure the RabbitMQ server to use them. \n\nHowever, I am not running the server. As stated above I have a \"RabbitMQ as a service\" provider who supports amqps. Should I ask him to provide me with those `.pem` files? \n\nCelery, can also sign messages. \n\n(Trying this approach, I get a `No encoder installed for auth` error which I reported.)\n\n**Question:** Does this mean that I can use my certificates to secure the connection as an alternative configuration to `BROKER_USE_SSL`?\n\nThere is also a note regarding message signing:\n\n auth serializer won’t encrypt the contents of a message, so if needed\n this will have to be enabled separately.\n\n**Subquestion:** Does encrypting the contents of a message protect me from the \"current\" RabbitMQ server administrator while \"message signing\" only protects me while on the wire towards that server?\n\nApparently I am somehow confused but I would not like to create any kind of insecure traffic over the internet for any reason. I would appreciate your help.\n\n========================================\n\nTop Answer:\nIf you are running your own Rabbit setup checkout this to make it secure.\n\nhttps://www.rabbitmq.com/ssl.html\n\n========================================\n\nCode:\n```text\nimport ssl\n\nBROKER_USE_SSL = {\n 'keyfile': '/var/ssl/private/worker-key.pem',\n 'certfile': '/var/ssl/amqp-server-cert.pem',\n 'ca_certs': '/var/ssl/myca.pem',\n 'cert_reqs': ssl.CERT_REQUIRED\n}\n```\n\n```text\n.pem\n```\n\n```text\n.pem\n```\n\n```text\nNo encoder installed for auth\n```\n\n```text\nBROKER_USE_SSL\n```\n\n```text\nBROKER_USE_SSL = True\n```\n\n```text\nBROKER_URL = 'amqp://user:pass@hostname:5671/vhost'\n```\n\n========================================\n\nComments:\n- Hey Lovisa, I have question about the celery producer. How does the producer securely push messages into the rabbitmq queue using SSL? The above `BROKER_URL` is only used by the workers for pulling out messages right?","metadata":{"transformedAt":"2026-08-18T18:33:20.197Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":101,"estimatedTokens":782}}854{"id":"stack-50411172","source":"stackoverflow","questionId":50411172,"title":"How to implement a state machine with Automatonymous in C#","tags":["c#","rabbitmq","state-machine","masstransit","automatonymous"],"text":"Title: How to implement a state machine with Automatonymous in C#\nTags: c#, rabbitmq, state-machine, masstransit, automatonymous\nSource: Stack Overflow\n\nQuestion:\nI am trying to implement a simple example/demo for a state machine using Automatonymous with RabbitMQ. Unfortunately I could not find one to rebuild / learn from (I found the ShoppingWeb, but in my eyes it's anything but simple). Also in my opinion the documentation is lacking information.\n\nThis is the state machine example I thought of (sorry, it's pretty ugly):\nhttps://i.sstatic.net/te0sw.jpg\nPlease note that this example is completely made up and it's not important if it makes sense or not. This project's purpose is to get \"warm\" with Automatonymous.\n\nWhat I want to do / to have is:\n\nFour applications running:\n\n- The state machine itself\n\n- The \"requester\" sending requests to be interpreted\n\n- The \"validator\" or \"parser\" checking if the provided request is valid\n\n- The \"interpreter\" interpreting the given request\n\nAn example of this could be:\n\n- Requester sends \"x=5\"\n\n- Validator checks if a \"=\" is contained\n\n- Intepreter says \"5\"\n\nMy implementation of the state machine looks like this:\n\n```\npublic class InterpreterStateMachine : MassTransitStateMachine\n {\n public InterpreterStateMachine()\n {\n InstanceState(x => x.CurrentState);\n Event(() => Requesting, x => x.CorrelateBy(request => request.Request.RequestString, context => context.Message.Request.RequestString)\n .SelectId(context => Guid.NewGuid())); \n Event(() => Validating, x => x.CorrelateBy(request => request.Request.RequestString, context => context.Message.Request.RequestString));\n Event(() => Interpreting, x => x.CorrelateBy(request => request.Request.RequestString, context => context.Message.Request.RequestString));\n\n Initially(\n When(Requesting)\n .Then(context =>\n {\n context.Instance.Request = new Request(context.Data.Request.RequestString); \n })\n .ThenAsync(context => Console.Out.WriteLineAsync($\"Request received: {context.Data.Request.RequestString}\"))\n .Publish(context => new ValidationNeededEvent(context.Instance))\n .TransitionTo(Requested)\n );\n\n During(Requested,\n When(Validating)\n .Then(context =>\n {\n context.Instance.Request.IsValid = context.Data.Request.IsValid;\n if (!context.Data.Request.IsValid)\n {\n this.TransitionToState(context.Instance, Error);\n }\n else\n {\n this.TransitionToState(context.Instance, RequestValid);\n }\n })\n .ThenAsync(context => Console.Out.WriteLineAsync($\"Request '{context.Data.Request.RequestString}' validated with {context.Instance.Request.IsValid}\"))\n .Publish(context => new InterpretationNeededEvent(context.Instance))\n ,\n Ignore(Requesting),\n Ignore(Interpreting)\n );\n\n During(RequestValid,\n When(Interpreting)\n .Then((context) =>\n {\n //do something\n })\n .ThenAsync(context => Console.Out.WriteLineAsync($\"Request '{context.Data.Request.RequestString}' interpreted with {context.Data.Answer}\"))\n .Publish(context => new AnswerReadyEvent(context.Instance))\n .TransitionTo(AnswerReady)\n .Finalize(),\n Ignore(Requesting),\n Ignore(Validating)\n );\n\n SetCompletedWhenFinalized();\n }\n\n public State Requested { get; private set; }\n public State RequestValid { get; private set; }\n public State AnswerReady { get; private set; }\n public State Error { get; private set; }\n\n //Someone is sending a request to interprete\n public Event Requesting { get; private set; }\n //Request is validated\n public Event Validating { get; private set; }\n //Request is interpreted\n public Event Interpreting { get; private set; }\n\n class ValidationNeededEvent : IValidationNeeded\n {\n readonly InterpreterInstance _instance;\n\n public ValidationNeededEvent(InterpreterInstance instance)\n {\n _instance = instance;\n }\n\n public Guid RequestId => _instance.CorrelationId;\n\n public Request Request => _instance.Request;\n }\n\n class InterpretationNeededEvent : IInterpretationNeeded\n {\n readonly InterpreterInstance _instance;\n\n public InterpretationNeededEvent(InterpreterInstance instance)\n {\n _instance = instance;\n }\n\n public Guid RequestId => _instance.CorrelationId;\n }\n\n class AnswerReadyEvent : IAnswerReady\n {\n readonly InterpreterInstance _instance;\n\n public AnswerReadyEvent(InterpreterInstance instance)\n {\n _instance = instance;\n }\n\n public Guid RequestId => _instance.CorrelationId;\n } \n }\n```\n\nThen I have services like this:\n\n```\npublic class RequestService : ServiceControl\n {\n readonly IScheduler scheduler;\n IBusControl busControl;\n BusHandle busHandle;\n InterpreterStateMachine machine;\n InMemorySagaRepository repository;\n\n public RequestService()\n {\n scheduler = CreateScheduler();\n }\n\n public bool Start(HostControl hostControl)\n {\n Console.WriteLine(\"Creating bus...\");\n\n machine = new InterpreterStateMachine();\n repository = new InMemorySagaRepository();\n\n busControl = Bus.Factory.CreateUsingRabbitMq(x =>\n {\n IRabbitMqHost host = x.Host(new Uri(/*rabbitMQ server*/), h =>\n {\n /*credentials*/\n });\n\n x.UseInMemoryScheduler();\n\n x.ReceiveEndpoint(host, \"interpreting_answer\", e =>\n {\n e.PrefetchCount = 5; //?\n e.StateMachineSaga(machine, repository);\n });\n\n x.ReceiveEndpoint(host, \"2\", e =>\n {\n e.PrefetchCount = 1;\n x.UseMessageScheduler(e.InputAddress);\n\n //Scheduling !?\n\n e.Consumer(() => new ScheduleMessageConsumer(scheduler));\n e.Consumer(() => new CancelScheduledMessageConsumer(scheduler));\n });\n\n });\n\n Console.WriteLine(\"Starting bus...\");\n\n try\n {\n busHandle = MassTransit.Util.TaskUtil.Await(() => busControl.StartAsync());\n scheduler.JobFactory = new MassTransitJobFactory(busControl);\n scheduler.Start();\n }\n catch (Exception)\n {\n scheduler.Shutdown();\n throw;\n }\n\n return true;\n }\n\n public bool Stop(HostControl hostControl)\n {\n Console.WriteLine(\"Stopping bus...\");\n\n scheduler.Standby();\n\n if (busHandle != null) busHandle.Stop();\n\n scheduler.Shutdown();\n\n return true;\n }\n\n static IScheduler CreateScheduler()\n {\n ISchedulerFactory schedulerFactory = new StdSchedulerFactory();\n IScheduler scheduler = MassTransit.Util.TaskUtil.Await(() => schedulerFactory.GetScheduler()); ;\n\n return scheduler;\n }\n }\n```\n\nMy questions are:\n\n- How do I send the \"intial\" request, so that the state machine will transition to my initial state\n\n- How do I \"react\" within the consumers to check the data that were sent and then send new data like in 1?\n\n========================================\n\nCode:\n```text\npublic class InterpreterStateMachine : MassTransitStateMachine<InterpreterInstance>\n {\n public InterpreterStateMachine()\n {\n InstanceState(x => x.CurrentState);\n Event(() => Requesting, x => x.CorrelateBy(request => request.Request.RequestString, context => context.Message.Request.RequestString)\n .SelectId(context => Guid.NewGuid())); \n Event(() => Validating, x => x.CorrelateBy(request => request.Request.RequestString, context => context.Message.Request.RequestString));\n Event(() => Interpreting, x => x.CorrelateBy(request => request.Request.RequestString, context => context.Message.Request.RequestString));\n\n Initially(\n When(Requesting)\n .Then(context =>\n {\n context.Instance.Request = new Request(context.Data.Request.RequestString); \n })\n .ThenAsync(context => Console.Out.WriteLineAsync($\"Request received: {context.Data.Request.RequestString}\"))\n .Publish(context => new ValidationNeededEvent(context.Instance))\n .TransitionTo(Requested)\n );\n\n During(Requested,\n When(Validating)\n .Then(context =>\n {\n context.Instance.Request.IsValid = context.Data.Request.IsValid;\n if (!context.Data.Request.IsValid)\n {\n this.TransitionToState(context.Instance, Error);\n }\n else\n {\n this.TransitionToState(context.Instance, RequestValid);\n }\n })\n .ThenAsync(context => Console.Out.WriteLineAsync($\"Request '{context.Data.Request.RequestString}' validated with {context.Instance.Request.IsValid}\"))\n .Publish(context => new InterpretationNeededEvent(context.Instance))\n ,\n Ignore(Requesting),\n Ignore(Interpreting)\n );\n\n During(RequestValid,\n When(Interpreting)\n .Then((context) =>\n {\n //do something\n })\n .ThenAsync(context => Console.Out.WriteLineAsync($\"Request '{context.Data.Request.RequestString}' interpreted with {context.Data.Answer}\"))\n .Publish(context => new AnswerReadyEvent(context.Instance))\n .TransitionTo(AnswerReady)\n .Finalize(),\n Ignore(Requesting),\n Ignore(Validating)\n );\n\n SetCompletedWhenFinalized();\n }\n\n public State Requested { get; private set; }\n public State RequestValid { get; private set; }\n public State AnswerReady { get; private set; }\n public State Error { get; private set; }\n\n //Someone is sending a request to interprete\n public Event<IRequesting> Requesting { get; private set; }\n //Request is validated\n public Event<IValidating> Validating { get; private set; }\n //Request is interpreted\n public Event<IInterpreting> Interpreting { get; private set; }\n\n\n class ValidationNeededEvent : IValidationNeeded\n {\n readonly InterpreterInstance _instance;\n\n public ValidationNeededEvent(InterpreterInstance instance)\n {\n _instance = instance;\n }\n\n public Guid RequestId => _instance.CorrelationId;\n\n public Request Request => _instance.Request;\n }\n\n class InterpretationNeededEvent : IInterpretationNeeded\n {\n readonly InterpreterInstance _instance;\n\n public InterpretationNeededEvent(InterpreterInstance instance)\n {\n _instance = instance;\n }\n\n public Guid RequestId => _instance.CorrelationId;\n }\n\n class AnswerReadyEvent : IAnswerReady\n {\n readonly InterpreterInstance _instance;\n\n public AnswerReadyEvent(InterpreterInstance instance)\n {\n _instance = instance;\n }\n\n public Guid RequestId => _instance.CorrelationId;\n } \n }\n```\n\n```text\npublic class RequestService : ServiceControl\n {\n readonly IScheduler scheduler;\n IBusControl busControl;\n BusHandle busHandle;\n InterpreterStateMachine machine;\n InMemorySagaRepository<InterpreterInstance> repository;\n\n public RequestService()\n {\n scheduler = CreateScheduler();\n }\n\n public bool Start(HostControl hostControl)\n {\n Console.WriteLine(\"Creating bus...\");\n\n machine = new InterpreterStateMachine();\n repository = new InMemorySagaRepository<InterpreterInstance>();\n\n\n busControl = Bus.Factory.CreateUsingRabbitMq(x =>\n {\n IRabbitMqHost host = x.Host(new Uri(/*rabbitMQ server*/), h =>\n {\n /*credentials*/\n });\n\n x.UseInMemoryScheduler();\n\n x.ReceiveEndpoint(host, \"interpreting_answer\", e =>\n {\n e.PrefetchCount = 5; //?\n e.StateMachineSaga(machine, repository);\n });\n\n x.ReceiveEndpoint(host, \"2\", e =>\n {\n e.PrefetchCount = 1;\n x.UseMessageScheduler(e.InputAddress);\n\n //Scheduling !?\n\n e.Consumer(() => new ScheduleMessageConsumer(scheduler));\n e.Consumer(() => new CancelScheduledMessageConsumer(scheduler));\n });\n\n });\n\n Console.WriteLine(\"Starting bus...\");\n\n try\n {\n busHandle = MassTransit.Util.TaskUtil.Await<BusHandle>(() => busControl.StartAsync());\n scheduler.JobFactory = new MassTransitJobFactory(busControl);\n scheduler.Start();\n }\n catch (Exception)\n {\n scheduler.Shutdown();\n throw;\n }\n\n return true;\n }\n\n public bool Stop(HostControl hostControl)\n {\n Console.WriteLine(\"Stopping bus...\");\n\n scheduler.Standby();\n\n if (busHandle != null) busHandle.Stop();\n\n scheduler.Shutdown();\n\n return true;\n }\n\n static IScheduler CreateScheduler()\n {\n ISchedulerFactory schedulerFactory = new StdSchedulerFactory();\n IScheduler scheduler = MassTransit.Util.TaskUtil.Await<IScheduler>(() => schedulerFactory.GetScheduler()); ;\n\n return scheduler;\n }\n }\n```\n\n```text\nusing InterpreterStateMachine.Contracts;\n using MassTransit;\n using System;\n using System.Threading.Tasks;\n\n namespace InterpreterStateMachine.Requester\n {\n class Program\n {\n private static IBusControl _busControl;\n\n static void Main(string[] args)\n { \n var busControl = ConfigureBus();\n busControl.Start();\n\n Console.WriteLine(\"Enter request or quit to exit: \");\n while (true)\n {\n Console.Write(\"> \");\n String value = Console.ReadLine();\n\n if (\"quit\".Equals(value,StringComparison.OrdinalIgnoreCase))\n break;\n\n if (value != null)\n {\n String[] values = value.Split(';');\n\n foreach (String v in values)\n {\n busControl.Publish<IRequesting>(new\n {\n Request = new Request(v),\n TimeStamp = DateTime.UtcNow\n });\n }\n }\n }\n\n busControl.Stop();\n }\n\n\n static IBusControl ConfigureBus()\n {\n if (null == _busControl)\n {\n _busControl = Bus.Factory.CreateUsingRabbitMq(cfg =>\n { \n var host = cfg.Host(new Uri(/*rabbitMQ server*/), h =>\n { \n /*credentials*/\n });\n\n cfg.ReceiveEndpoint(host, \"answer_ready\", e =>\n {\n e.Durable = true;\n //here the consumer is registered\n e.Consumer<AnswerConsumer>();\n });\n });\n _busControl.Start();\n }\n return _busControl;\n }\n\n //here comes the actual logic of the consumer, which consumes a \"contract\"\n class AnswerConsumer : IConsumer<IAnswerReady>\n {\n public async Task Consume(ConsumeContext<IAnswerReady> context)\n {\n await Console.Out.WriteLineAsync($\"\\nReceived Answer for \\\"{context.Message.Request.RequestString}\\\": {context.Message.Answer}.\");\n await Console.Out.WriteAsync(\">\");\n }\n } \n }\n }\n```\n\n```text\nusing InterpreterStateMachine.Contracts;\nusing MassTransit;\nusing MassTransit.QuartzIntegration;\nusing MassTransit.RabbitMqTransport;\nusing Quartz;\nusing Quartz.Impl;\nusing System;\nusing System.Threading.Tasks;\nusing Topshelf;\n\nnamespace InterpreterStateMachine.Validator\n{\n public class ValidationService : ServiceControl\n {\n readonly IScheduler _scheduler;\n static IBusControl _busControl;\n BusHandle _busHandle; \n\n public static IBus Bus => _busControl;\n\n public ValidationService()\n {\n _scheduler = CreateScheduler();\n }\n\n public bool Start(HostControl hostControl)\n {\n Console.WriteLine(\"Creating bus...\");\n\n _busControl = MassTransit.Bus.Factory.CreateUsingRabbitMq(x =>\n {\n IRabbitMqHost host = x.Host(new Uri(/*rabbitMQ server*/), h =>\n {\n /*credentials*/\n });\n\n x.UseInMemoryScheduler();\n x.UseMessageScheduler(new Uri(RabbitMqServerAddress));\n\n x.ReceiveEndpoint(host, \"validation_needed\", e =>\n {\n e.PrefetchCount = 1;\n e.Durable = true;\n //again this is how the consumer is registered\n e.Consumer<RequestConsumer>();\n }); \n });\n\n Console.WriteLine(\"Starting bus...\");\n\n try\n {\n _busHandle = MassTransit.Util.TaskUtil.Await<BusHandle>(() => _busControl.StartAsync());\n _scheduler.JobFactory = new MassTransitJobFactory(_busControl);\n _scheduler.Start();\n }\n catch (Exception)\n {\n _scheduler.Shutdown();\n throw;\n } \n return true;\n }\n\n public bool Stop(HostControl hostControl)\n {\n Console.WriteLine(\"Stopping bus...\");\n _scheduler.Standby();\n _busHandle?.Stop();\n _scheduler.Shutdown();\n return true;\n }\n\n static IScheduler CreateScheduler()\n {\n ISchedulerFactory schedulerFactory = new StdSchedulerFactory();\n IScheduler scheduler = MassTransit.Util.TaskUtil.Await<IScheduler>(() => schedulerFactory.GetScheduler());\n\n return scheduler;\n }\n }\n\n //again here comes the actual consumer logic, look how the message is re-published after it was checked\n class RequestConsumer : IConsumer<IValidationNeeded>\n {\n public async Task Consume(ConsumeContext<IValidationNeeded> context)\n {\n await Console.Out.WriteLineAsync($\"(c) Received {context.Message.Request.RequestString} for validation (Id: {context.Message.RequestId}).\");\n\n context.Message.Request.IsValid = context.Message.Request.RequestString.Contains(\"=\");\n\n //send the new message on the \"old\" context\n await context.Publish<IValidating>(new\n {\n Request = context.Message.Request,\n IsValid = context.Message.Request.IsValid,\n TimeStamp = DateTime.UtcNow,\n RequestId = context.Message.RequestId\n });\n }\n }\n}\n```\n\n```text\n...\nInterpreterStateMachine _machine = new InterpreterStateMachine();\nInMemorySagaRepository<InterpreterInstance> _repository = new InMemorySagaRepository<InterpreterInstance>();\n...\nx.ReceiveEndpoint(host, \"state_machine\", e =>\n{\n e.PrefetchCount = 1;\n //here the state machine is set\n e.StateMachineSaga(_machine, _repository);\n e.Durable = false;\n});\n```\n\n```text\nusing System;\n\nnamespace InterpreterStateMachine.Contracts\n{\n public interface IValidationNeeded\n {\n Guid RequestId { get; }\n Request Request { get; }\n }\n}\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.197Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":660,"estimatedTokens":4973}}855{"id":"stack-19316133","source":"stackoverflow","questionId":19316133,"title":"Celery task state depends on CELERY_TASK_RESULT_EXPIRES","tags":["python","rabbitmq","celery","amqp"],"text":"Title: Celery task state depends on CELERY_TASK_RESULT_EXPIRES\nTags: python, rabbitmq, celery, amqp\nSource: Stack Overflow\n\nQuestion:\nFrom what I have seen, the task state depends entirely on the value set for CELERY_TASK_RESULT_EXPIRES - if I check the task state within this interval after the task has finished executing, the state returned by:\n\n```\nAsyncResult(task_id).state\n```\n\nis correct. If not, the state will not be updated and will remain forever PENDING.\n\nCan anyone explain me why does this happen? Is this a feature or a bug?\nWhy is the task state depending on the result expiry time, even if I am ignoring results?\n\n(Celery version: 3.0.23, result backend: AMQP)\n\n========================================\n\nCode:\n```text\nAsyncResult(task_id).state\n```\n\n```text\nignore_result\n```\n\n```text\nignore_state\n```\n\n========================================\n\nComments:\n- ignore_state sounds awkward btw, maybe someone can come up with a better name\n- Yeah, I assumed they are being returned in the same way...It's a bit misleading though that the result_expires setting influences the period that one can get the state, even though one ignores the result. I understand the reasoning behind though. Now my problem is that I am not really interested in the result, but I am interested in the state...\n- p.s. you could call it update_states or smth, instead of ignore_states\n- Right, result_expires should be state_expires and so on, in any case states must expire by default or it will just grow forever. Most applications will not need to keep states for a long time, but you can increase the expiry time if you please. If your tasks return big data then you can avoid returning it from the task (and thus keeping it out of the state), and instead write it somewhere else.\n- (continuing) E.g. if your task returns a big file you can move it somewhere and store a reference to it in the return value (an URL, or a database primary key, etc)","metadata":{"transformedAt":"2026-08-18T18:33:20.197Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":41,"estimatedTokens":486}}856{"id":"stack-34179845","source":"stackoverflow","questionId":34179845,"title":"AMQP over WebSocket with RabbitMQ","tags":["javascript","websocket","rabbitmq","amqp","sockjs"],"text":"Title: AMQP over WebSocket with RabbitMQ\nTags: javascript, websocket, rabbitmq, amqp, sockjs\nSource: Stack Overflow\n\nQuestion:\nIs there a way to use AMQP to communicate with RabbitMQ over WebSockets?\n\nI guess the real question is if there is support for this in RabbitMQ and if there are any client side libraries for the browser? Can not really wrap my mind around it and google provides no answers for me.\n\nToday we are using the RabbitMQ STOMP-SockJS solution. But that does not work very well with LVC (Last Value Cache) and exchanges other than the default. Since it does not allow to bind multiple routing keys to the same queue. (It automatically creates a new queue for each subscription.)\n\n========================================\n\nTop Answer:\nKaazing has an AMQP JavaScript API that works with one of RabbitMQ's implementations of AMQP. Its free for developers and can be downloaded here\n\nFull disclosure: I work for Kaazing.\n\n========================================\n\nComments:\n- This is the solution we ended up with.\n- Is there something already built that could be reused? I mean, something that proxies requests from WebSockets to RabbitMQ and back\n- What does \"free for developers\" actually mean? The whole thing seems to have the Apache 2.0 license?\n- Very similar to other software offerings. If you want to develop an application with the Kaazing AMQP software, there is no charge. You can use the forums for support. If you want to use it in production with 24/7 global support, there's a fee. Pretty standard stuff.\n- Just to clarify. Of course you're free to use the OSS version in Github in whatever way you want. My comments were strictly about for-fee 24x7 support.","metadata":{"transformedAt":"2026-08-18T18:33:20.197Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":26,"estimatedTokens":423}}857{"id":"stack-42599942","source":"stackoverflow","questionId":42599942,"title":"Spring cloud stream - send message after application initalization","tags":["java","spring","rabbitmq","spring-cloud-stream"],"text":"Title: Spring cloud stream - send message after application initalization\nTags: java, spring, rabbitmq, spring-cloud-stream\nSource: Stack Overflow\n\nQuestion:\nI'am trying to send a simple message using \"spring cloud stream\" to the rabbitmq. Basically code looks like this:\n\n```\n@EnableBinding(Source.class)\n@SpringBootApplication\npublic class SourceApplication {\n\n public static void main(String[] args) {\n SpringApplication.run(SourceApplication.class, args);\n }\n\n @Autowired Source source;\n\n @PostConstruct\n public void init() {\n source.send(MessageBuilder.withPayload(\"payload\").build());\n }\n}\n```\n\nthen I get this error message:\n\n```\norg.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'unknown.channel.name'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers, failedMessage=GenericMessage [payload=******, headers={id=c60dd5be-6576-99d5-fd1b-b1cb94c191c1, timestamp=1488651422892}]\nat org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:93)\nat org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:423)\nat org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:373)\n```\n\nHowever, if I add some delay, before sending a message (just second or few), it works ok. My question is: how can I wait before spring completely initialize message channels and then send a message?\n\n========================================\n\nTop Answer:\nYou might look into Spring's Task Execution and Scheduling features.\n\nIn particular, it sounds like you want something like what section 34.4 covers.\n\nAlso, I spotted this answer to a similar question.\n\n========================================\n\nCode:\n```text\n@EnableBinding(Source.class)\n@SpringBootApplication\npublic class SourceApplication {\n\n public static void main(String[] args) {\n SpringApplication.run(SourceApplication.class, args);\n }\n\n @Autowired Source source;\n\n @PostConstruct\n public void init() {\n source.send(MessageBuilder.withPayload(\"payload\").build());\n }\n}\n```\n\n```text\norg.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'unknown.channel.name'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers, failedMessage=GenericMessage [payload=******, headers={id=c60dd5be-6576-99d5-fd1b-b1cb94c191c1, timestamp=1488651422892}]\nat org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:93)\nat org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:423)\nat org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:373)\n```\n\n```text\n@PostConstruct\n```\n\n```text\nSmartLifecycle\n```\n\n```text\nisAutoStartup\n```\n\n```text\ntrue\n```\n\n```text\nApplicationListener\n```\n\n```text\nContextRefreshedEvent\n```\n\n```text\nApplicationRunner\n```\n\n========================================\n\nComments:\n- as I sad: I can add delay... but, what I need is some kind of event listner to be sure that this message channel is ready\n- for me this doesn't work, neither for `ContextRefreshedEvent` nor `ApplicationReadyEvent`.","metadata":{"transformedAt":"2026-08-18T18:33:20.197Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":106,"estimatedTokens":838}}858{"id":"stack-49089915","source":"stackoverflow","questionId":49089915,"title":"How to set custom name for RabbitMQ connection?","tags":["rabbitmq","spring-cloud-stream"],"text":"Title: How to set custom name for RabbitMQ connection?\nTags: rabbitmq, spring-cloud-stream\nSource: Stack Overflow\n\nQuestion:\nIt would be useful to be able to identify the RabbitMQ client by its connection name.\n\nI'm using Spring Cloud Streams abstraction and with default settings I getting something like that:\n\nhttps://i.sstatic.net/qzL6u.png\n\nHow can I set a custom RabbitMQ connection name in my Spring Boot client?\n\n### EDIT\n\n### Spring Boot 1.7+\n\nThis is solution based on Gary Russell's answer:\n\n```\n@Configuration\npublic class MessagingConfiguration {\n private final String instanceId = UUID.randomUUID().toString().substring(0, 8); // TODO: Environment/Consul/Eureka\n private final String connectionNamePrefix;\n private AtomicInteger connectionNumber = new AtomicInteger(0);\n\n public MessagingConfiguration(@Value(\"${custom.rabbitmq.connection-name-prefix:SpringBootApp}\") String connectionNamePrefix) {\n this.connectionNamePrefix = connectionNamePrefix;\n }\n\n private String generateConnectionName() {\n return connectionNamePrefix + '#' + instanceId + ':' + connectionNumber.getAndIncrement();\n }\n\n @Bean\n public SmartInitializingSingleton reconfigureConnectionFactory(final AbstractConnectionFactory cf) {\n return () -> cf.setConnectionNameStrategy(f -> generateConnectionName());\n }\n}\n```\n\nIt works with the default configuration, but doesn't work for a multiple systems connection.\n\n### Spring Boot 2.0.1+\n\n```\n@Configuration\npublic class MessagingConfiguration {\n private final String instanceId = UUID.randomUUID().toString().substring(0, 8); // TODO: Environment/Consul/Eureka\n private final String connectionNamePrefix;\n private AtomicInteger connectionNumber = new AtomicInteger(0);\n\n public MessagingConfiguration(@Value(\"${custom.rabbitmq.connection-name-prefix:SpringBootApp}\") String connectionNamePrefix) {\n this.connectionNamePrefix = connectionNamePrefix;\n }\n\n private String generateConnectionName() {\n return connectionNamePrefix + '#' + instanceId + ':' + connectionNumber.getAndIncrement();\n }\n\n @Bean\n public ConnectionNameStrategy defineConnectionNameStrategy() {\n return connectionFactory -> generateConnectionName();\n }\n}\n```\n\nNote, there is a bug in a multi-binder scenario.\n\n========================================\n\nCode:\n```text\n@Configuration\npublic class MessagingConfiguration {\n private final String instanceId = UUID.randomUUID().toString().substring(0, 8); // TODO: Environment/Consul/Eureka\n private final String connectionNamePrefix;\n private AtomicInteger connectionNumber = new AtomicInteger(0);\n\n public MessagingConfiguration(@Value(\"${custom.rabbitmq.connection-name-prefix:SpringBootApp}\") String connectionNamePrefix) {\n this.connectionNamePrefix = connectionNamePrefix;\n }\n\n private String generateConnectionName() {\n return connectionNamePrefix + '#' + instanceId + ':' + connectionNumber.getAndIncrement();\n }\n\n @Bean\n public SmartInitializingSingleton reconfigureConnectionFactory(final AbstractConnectionFactory cf) {\n return () -> cf.setConnectionNameStrategy(f -> generateConnectionName());\n }\n}\n```\n\n```text\n@Configuration\npublic class MessagingConfiguration {\n private final String instanceId = UUID.randomUUID().toString().substring(0, 8); // TODO: Environment/Consul/Eureka\n private final String connectionNamePrefix;\n private AtomicInteger connectionNumber = new AtomicInteger(0);\n\n public MessagingConfiguration(@Value(\"${custom.rabbitmq.connection-name-prefix:SpringBootApp}\") String connectionNamePrefix) {\n this.connectionNamePrefix = connectionNamePrefix;\n }\n\n private String generateConnectionName() {\n return connectionNamePrefix + '#' + instanceId + ':' + connectionNumber.getAndIncrement();\n }\n\n @Bean\n public ConnectionNameStrategy defineConnectionNameStrategy() {\n return connectionFactory -> generateConnectionName();\n }\n}\n```\n\n```text\n@Bean\npublic CachingConnectionFactory connectionFactory() {\n CachingConnectionFactory cf = new CachingConnectionFactory(\"localhost\");\n cf.setConnectionNameStrategy(f -> \"myConnectionName\");\n return cf;\n}\n```\n\n```text\n@Bean\npublic SmartInitializingSingleton reconfigureCf(final CachingConnectionFactory cf) {\n return () -> cf.setConnectionNameStrategy(f -> \"myName\");\n}\n```\n\n```text\nConnectionNameStrategy\n```\n\n```text\nstart()\n```\n\n========================================\n\nComments:\n- Thanks, but in this way I must create own ConnectionFactory, configure it etc. I just want to inject my ConnectionNameStrategy, nothing more. Is there any way to do it?\n- Thank you for the magic :) It works with default configuration, but doesn't work when I use connection to multiple systems. Is there any chance to add autoconfiguration support for something like this property: `spring.rabbitmq.connection-name-prefix`?\n- That requires a change to boot since each of those binders gets loaded into a separate application context. I have issued a pull request against boot if you want to track it.\n- BTW, it looks like multiple-systems configuration always inherit default environment with `Spring Boot 2.0` and and `Spring Cloud Finchley.M8`. It works OK with `Spring Boot 1.5.9` and `Spring Cloud Edgware.SR2` on same configuration. Where should I post this issue?\n- I would start with stream. An example the exhibits the behavior will help.\n- A custom `ConnectionNameStrategy` is ignored if there is a custom binder configuration: github.com/spring-cloud/spring-cloud-stream/issues/1541","metadata":{"transformedAt":"2026-08-18T18:33:20.197Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":149,"estimatedTokens":1376}}859{"id":"stack-33810450","source":"stackoverflow","questionId":33810450,"title":"How to specify additional info on a rabbit message when it's dead lettered","tags":["java","rabbitmq","spring-amqp","spring-rabbit","rabbitmq-exchange"],"text":"Title: How to specify additional info on a rabbit message when it's dead lettered\nTags: java, rabbitmq, spring-amqp, spring-rabbit, rabbitmq-exchange\nSource: Stack Overflow\n\nQuestion:\nI have a rabbit queue with messages for consuming. I also have a listener that can fail. The queue is configured with a dead letter exchange (along with a dead letter queue). What I want is to see an exception info in the messages sitting in the dead letter queue.\n\nHere is how it works currently:\n\n- I send a corrupted message to my normal queue.\n\n- My listener (I'm using Java's org.springframework.amqp.core.MessageListener) fails with something like: \"java.lang.RuntimeException: corrupted message\"\n\n- The message gets rejected and goes to the dead letter queue thru the dead letter exchange.\nWhen I look at the dead-lettered message in the Rabbit Admin UI, I see:\nheaders:\n\nx-death:\n\nreason: rejected\n\nBut what I want is to see the \"java.lang.RuntimeException: corrupted message\" somewhere on UI. I assume it should be a custom header?\n\nIs it possible to, for example, put a general try-catch to my listener and enhance the headers with the exception info?\n\n========================================\n\nTop Answer:\nYes, it's possible. When consuming from a quorum queue, the consumer can settle the message with the AMQP modified outcome with field `undeliverable-here = true` and field `message-annotations` containing your Java exception. RabbitMQ will then dead-letter the message as described in the blog post.\n\n========================================\n\nCode:\n```text\nRepublishMessageRecoverer\n```\n\n```text\nundeliverable-here = true\n```\n\n```text\nmessage-annotations\n```\n\n========================================\n\nComments:\n- This is the pattern I use as well. I like to think about basic.reject and/or failure to send basic.ack as an indication that the consumer crashed or had some other problem unrelated to the message or anything downstream. In this case, it is appropriate for the broker to requeue the message unchanged, and allow another consumer to take it immediately. If the consumer process is healthy enough to write sensible information to the message headers, it might as well republish it to an \"undeliverable\" or \"retry\" exchange and basic.ack the original message.\n- This answer is outdated. See stackoverflow.com/a/79072091/4961112","metadata":{"transformedAt":"2026-08-18T18:33:20.198Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":50,"estimatedTokens":585}}860{"id":"stack-30584446","source":"stackoverflow","questionId":30584446,"title":"How can I get the status of a rabbitmq-shovel by the http api","tags":["rabbitmq","rabbitmqctl","rabbitmq-shovel"],"text":"Title: How can I get the status of a rabbitmq-shovel by the http api\nTags: rabbitmq, rabbitmqctl, rabbitmq-shovel\nSource: Stack Overflow\n\nQuestion:\nUsing \"rabbitmqctl eval 'rabbit_shovel_status:status().'\" I can get the shovels status in my rabbitmq server.\n\nI activated the modules 'rabbitmq_shovel' and 'rabbitmq_shovel_management'.\n\nI created some dynamic shovels with the HTTP API, the problem I have is that, I want to be able to GET the status of the shovels using the HTTP API, but I can't find a way to do that.\n\nIs there any way to do this using the HTTP API? Or should I use 'rabbitmqctl eval ...'?\n\nI don't want to use the rabbitmqctl, as I want to expose this data in my own API, so my application should be able to access it, without having to make an 'exec'.\n\n========================================\n\nTop Answer:\nIf you are using C#, you can use HareDu like this:\n\n```\nvar result = await _services.GetService()\n .GetAllShovels();\n```\n\nhttps://github.com/ahives/HareDu2/blob/master/docs/shovel-get.md\n\n========================================\n\nCode:\n```text\nhttp://localhost:15672/api/shovels\n```\n\n```text\n[ \n { \n \"node\":\"rabbit@gabrieleMacBook\",\n \"timestamp\":\"2015-06-02 15:34:27\",\n \"name\":\"test\",\n \"vhost\":\"/\",\n \"type\":\"dynamic\",\n \"state\":\"running\",\n \"definition\":{ \n \"src-queue\":\"test\",\n \"dest-queue\":\"test2\"\n },\n \"src_uri\":\"amqp://xxxxxxx\",\n \"dest_uri\":\"amqp://xxxxxxx\"\n }\n]\n```\n\n```text\nvar result = await _services.GetService<IBrokerObjectFactory>()\n .GetAllShovels();\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.198Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":57,"estimatedTokens":392}}861{"id":"stack-15306118","source":"stackoverflow","questionId":15306118,"title":"Fatal error by starting django-celery with RabbitMQ [Unknown AMQP Method (10, 60)]","tags":["django","rabbitmq","celery","django-celery"],"text":"Title: Fatal error by starting django-celery with RabbitMQ [Unknown AMQP Method (10, 60)]\nTags: django, rabbitmq, celery, django-celery\nSource: Stack Overflow\n\nQuestion:\nI'm trying to set up an instance of Django on a debian server with django-celery talking to RabbitMQ for distributed tasks.\n\nI can get the RabbitMQ server set up and it'll respond with a good status, but as soon as celery makes contact with RabbitMQ, it throws an error and shuts down. Here's what it looks like when I try to start a dev instance of celery:\n\n```\n[2013-03-08 16:59:23,707: WARNING/MainProcess] celery@myserver ready.\n[2013-03-08 16:59:23,725: INFO/MainProcess] consumer: Connected to amqp://celery_rabbit@127.0.0.1:5672//rabbit_vhost.\n[2013-03-08 16:59:23,734: ERROR/MainProcess] Unrecoverable error: AMQPError('Unknown AMQP method (10, 60)', None, None, None, '')\nTraceback (most recent call last):\n File \"/usr/local/lib/python2.6/dist-packages/celery/worker/__init__.py\", line 351, in start\n component.start()\n File \"/usr/local/lib/python2.6/dist-packages/celery/worker/consumer.py\", line 392, in start\n self.reset_connection()\n File \"/usr/local/lib/python2.6/dist-packages/celery/worker/consumer.py\", line 748, in reset_connection\n self.reset_pidbox_node()\n File \"/usr/local/lib/python2.6/dist-packages/celery/worker/consumer.py\", line 687, in reset_pidbox_node\n callback=self.on_control,\n File \"/usr/local/lib/python2.6/dist-packages/kombu/pidbox.py\", line 71, in listen\n consumer.consume()\n File \"/usr/local/lib/python2.6/dist-packages/kombu/messaging.py\", line 401, in consume\n self._basic_consume(T, no_ack=no_ack, nowait=False)\n File \"/usr/local/lib/python2.6/dist-packages/kombu/messaging.py\", line 522, in _basic_consume\n no_ack=no_ack, nowait=nowait)\n File \"/usr/local/lib/python2.6/dist-packages/kombu/entity.py\", line 571, in consume\n nowait=nowait)\n File \"/usr/local/lib/python2.6/dist-packages/amqp/channel.py\", line 1766, in basic_consume\n (60, 21), # Channel.basic_consume_ok\n File \"/usr/local/lib/python2.6/dist-packages/amqp/abstract_channel.py\", line 69, in wait\n self.channel_id, allowed_methods)\n File \"/usr/local/lib/python2.6/dist-packages/amqp/connection.py\", line 230, in _wait_method\n self.wait()\n File \"/usr/local/lib/python2.6/dist-packages/amqp/abstract_channel.py\", line 71, in wait\n return self.dispatch_method(method_sig, args, content)\n File \"/usr/local/lib/python2.6/dist-packages/amqp/abstract_channel.py\", line 85, in dispatch_method\n raise AMQPError('Unknown AMQP method %r' % (method_sig, ))\nAMQPError: Unknown AMQP method (10, 60)\n```\n\nJust to confirm, I can check that RabbitMQ is still running afterwards:\n\n```\n# rabbitmqctl status\nStatus of node rabbit@myserver ...\n[{running_applications,[{rabbit,\"RabbitMQ\",\"1.8.1\"},\n {mnesia,\"MNESIA CXC 138 12\",\"4.4.14\"},\n {os_mon,\"CPO CXC 138 46\",\"2.2.5\"},\n {sasl,\"SASL CXC 138 11\",\"2.1.9.2\"},\n {stdlib,\"ERTS CXC 138 10\",\"1.17\"},\n {kernel,\"ERTS CXC 138 10\",\"2.14\"}]},\n {nodes,[{disc,[rabbit@myserver]}]},\n {running_nodes,[rabbit@myserver]}]\n...done.\n```\n\nThis is the last thing preventing me from launching my site and has me all frazzled, so any help would be greatly appreciated! Thanks.\n\n========================================\n\nTop Answer:\nI ran with the same problem in Ubuntu. \nIt appears that (possibly depending on the Ubuntu version) the included RabbitMQ packages might be a outdated.\nAnd the RabbitMQ installation guide states that this is quite possible. Thus they recommend installing the .deb package from their web site.\n\n========================================\n\nCode:\n```text\n[2013-03-08 16:59:23,707: WARNING/MainProcess] celery@myserver ready.\n[2013-03-08 16:59:23,725: INFO/MainProcess] consumer: Connected to amqp://celery_rabbit@127.0.0.1:5672//rabbit_vhost.\n[2013-03-08 16:59:23,734: ERROR/MainProcess] Unrecoverable error: AMQPError('Unknown AMQP method (10, 60)', None, None, None, '')\nTraceback (most recent call last):\n File \"/usr/local/lib/python2.6/dist-packages/celery/worker/__init__.py\", line 351, in start\n component.start()\n File \"/usr/local/lib/python2.6/dist-packages/celery/worker/consumer.py\", line 392, in start\n self.reset_connection()\n File \"/usr/local/lib/python2.6/dist-packages/celery/worker/consumer.py\", line 748, in reset_connection\n self.reset_pidbox_node()\n File \"/usr/local/lib/python2.6/dist-packages/celery/worker/consumer.py\", line 687, in reset_pidbox_node\n callback=self.on_control,\n File \"/usr/local/lib/python2.6/dist-packages/kombu/pidbox.py\", line 71, in listen\n consumer.consume()\n File \"/usr/local/lib/python2.6/dist-packages/kombu/messaging.py\", line 401, in consume\n self._basic_consume(T, no_ack=no_ack, nowait=False)\n File \"/usr/local/lib/python2.6/dist-packages/kombu/messaging.py\", line 522, in _basic_consume\n no_ack=no_ack, nowait=nowait)\n File \"/usr/local/lib/python2.6/dist-packages/kombu/entity.py\", line 571, in consume\n nowait=nowait)\n File \"/usr/local/lib/python2.6/dist-packages/amqp/channel.py\", line 1766, in basic_consume\n (60, 21), # Channel.basic_consume_ok\n File \"/usr/local/lib/python2.6/dist-packages/amqp/abstract_channel.py\", line 69, in wait\n self.channel_id, allowed_methods)\n File \"/usr/local/lib/python2.6/dist-packages/amqp/connection.py\", line 230, in _wait_method\n self.wait()\n File \"/usr/local/lib/python2.6/dist-packages/amqp/abstract_channel.py\", line 71, in wait\n return self.dispatch_method(method_sig, args, content)\n File \"/usr/local/lib/python2.6/dist-packages/amqp/abstract_channel.py\", line 85, in dispatch_method\n raise AMQPError('Unknown AMQP method %r' % (method_sig, ))\nAMQPError: Unknown AMQP method (10, 60)\n```\n\n```text\n# rabbitmqctl status\nStatus of node rabbit@myserver ...\n[{running_applications,[{rabbit,\"RabbitMQ\",\"1.8.1\"},\n {mnesia,\"MNESIA CXC 138 12\",\"4.4.14\"},\n {os_mon,\"CPO CXC 138 46\",\"2.2.5\"},\n {sasl,\"SASL CXC 138 11\",\"2.1.9.2\"},\n {stdlib,\"ERTS CXC 138 10\",\"1.17\"},\n {kernel,\"ERTS CXC 138 10\",\"2.14\"}]},\n {nodes,[{disc,[rabbit@myserver]}]},\n {running_nodes,[rabbit@myserver]}]\n...done.\n```\n\n========================================\n\nComments:\n- You're right, thanks! Looks like these guys had the same problem: github issue","metadata":{"transformedAt":"2026-08-18T18:33:20.198Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":123,"estimatedTokens":1572}}862{"id":"stack-27670828","source":"stackoverflow","questionId":27670828,"title":"fig up: docker containers start synchronisation","tags":["rabbitmq","docker","fig"],"text":"Title: fig up: docker containers start synchronisation\nTags: rabbitmq, docker, fig\nSource: Stack Overflow\n\nQuestion:\nFor one of my home projects I decided to use docker containers and fig for orchestration (first time using those tools).\n\nHere is my fig.yaml:\n\n```\nrabbitmq:\n image: dockerfile/rabbitmq:latest\nmongodb:\n image: mongo\napp:\n build: .\n command: python /code/app/main.py\n links:\n - rabbitmq\n - mongodb\n volumes:\n - .:/code\n```\n\nRabbitmq starting time is much slower than loading time of my application. Even though rabbitmq container starts loading first (since it is in app links), when my app tries to connect to rabbitmq server it's not yet available (it's definately loading timing problem, since if I just insert sleep for 5 seconds before connecting to rabbitmq - everything works fine). Is there some standard way to resolve loading time synchronisation problems?\n\nThanks.\n\n========================================\n\nTop Answer:\nSimilar problems I have encountered I have solved using a custom script set up as `CMD` in my `Dockerfiles`. Then you can run any check command you wish (`sleep` for a time, or waiting to the service be listening, for example). I think there is not a standard way to do this, anyway I think the best way would be the application run could be able to ask the external service to be up and running, and the connect to them, but this is not possible in most cases.\n\n========================================\n\nCode:\n```text\nrabbitmq:\n image: dockerfile/rabbitmq:latest\nmongodb:\n image: mongo\napp:\n build: .\n command: python /code/app/main.py\n links:\n - rabbitmq\n - mongodb\n volumes:\n - .:/code\n```\n\n```text\nfunction check_up() {\n service=$1\n host=$2\n port=$3\n\n max=13 # 1 minute\n\n counter=1\n while true;do\n python -c \"import socket;s = socket.socket(socket.AF_INET, socket.SOCK_STREAM);s.connect(('$host', $port))\" \\\n >/dev/null 2>/dev/null && break || \\\n echo \"Waiting that $service on ${host}:${port} is started (sleeping for 5)\"\n\n if [[ ${counter} == ${max} ]];then\n echo \"Could not connect to ${service} after some time\"\n echo \"Investigate locally the logs with fig logs\"\n exit 1\n fi\n\n sleep 5\n\n (( counter++ ))\n done\n}\n```\n\n```text\nrabbitmq:\n image: dockerfile/rabbitmq:latest\nmongodb:\n image: mongo\nrabbitmqready:\n image: aanand/wait\n links:\n - rabbitmq\napp:\n build: .\n command: python /code/app/main.py\n links:\n - rabbitmqready\n - mongodb\n volumes:\n - .:/code\n```\n\n```text\ncheck_up \"DB Server\" ${RABBITMQ_PORT_5672_TCP_ADDR} 5672\n```\n\n```text\nfig.yml\n```\n\n```text\nCMD\n```\n\n```text\nDockerfiles\n```\n\n```text\nsleep\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.198Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":116,"estimatedTokens":674}}863{"id":"stack-8350111","source":"stackoverflow","questionId":8350111,"title":"RabbitMQ topology to route a dynamic set of message categories to a static set of consumers each with their own queue","tags":["rabbitmq","message-queue","amqp","rabbitmq-exchange"],"text":"Title: RabbitMQ topology to route a dynamic set of message categories to a static set of consumers each with their own queue\nTags: rabbitmq, message-queue, amqp, rabbitmq-exchange\nSource: Stack Overflow\n\nQuestion:\nWhat I'm trying to do: multiple producers push data in dynamic categories into a Named exchange. Multiple consumers need to pick up this data from these dynamically named queues and act on them.\n\nThe problem is that all of the examples of consumption that I see require the consumer/subscription to have a specific queue name, and my consumers don't know the names of the queues, nor do they need to know this.\n\nWhy am I doing this? two reasons:\n\nI can have N of these dynamic categories at a time. I'd like the queue to serve these categories equally. currently we have one queue which accepts all of these categories and serves them in FIFO (which means that some categories are starved for some time).\n\nBeing able to serve all categories equally, rather than fifo, lets me come up with interesting QoS (by default I understand that Rabbit will round-robin serve messages).\n\nso, back to my question (if its valid): is it possible to consume messages from a queue?\n\n========================================\n\nTop Answer:\nWith AMQP you publish messages to an Exchange and you consume messages from a Queue. Don't worry about what \"queue\" means in other messaging technology.\n\nIt sounds to me like your scenario could be handled easily with a topic exchange. Publish messages with routing keys like cat.silly, cat.older, cat.interesting. Then have the consumers each declare a queue using the binding key cat.*\n\nThis way, all messages published to the exchange with any prefix will be copied to the queue because of the wildcard in the binding key. If your consumers are in fact doing round-robin sharing, i.e. messages should not be copied to multiple queues, then just have all consumers use the same queue name. If every consumer uses the same queue name then you can compile it into your code and not worry about what the name is. But when you want to debug the message flow, just create a consumer that subscribes to a queue named catdebug with the same binding key, cat.*\n\nBut if each consumer is specialised and wants to pick and choose which messages to handle, then have each consumer use a unique queue name. That way each consumer will see a copy of every message.\n\nTopic exchanges are the best solution to try first, because the semantics of direct and fanout exchanges can easily be emulated.\n\n========================================\n\nComments:\n- these are both interesting options, and I'm reading up more on topic exchanges, but my main issue here is that my subscribers are a) static (i.e. they dont spin up. they're always waiting, like chuck norris), and b) I dont want my subscribers to know of a queue. I want them to equally serve all of my queues\n- Sorry I misunderstood then. Messages are accumulated in queues so you have to have queues. Now if the design you're envisioning is a bounded set of consumers pulling from an unbounded number of queues, then read the discussions here: stackoverflow.com/questions/8301841/…\n- nice answer on that one! but the problem is that even with one queue and n workers, one of his customers can create a thousand tasks and that queue is now blocked until his worker pool can catch up?\n- I have reviewed my answer to cover the case of non-dynamic subscribers.\n- I'm actually trying to figure out if I can have my worker pool listen to one static queue, while the producers continue creating their own anonymous queues. while in the meantime, rabbitmq round-robins those anonymous queues into my static queue. make sense?\n- Regarding your idea of round robin queues, I'm wondering if the proprietary exchange-to-exchange binding that RabbitMQ support (rabbitmq.com/extensions.html) could allow you to achieve something similar. Now you'd have to consider the pros/cons of stepping out of pure AMQP...\n- I'll note that the accepted answer doesn't address the requirement of \"Being able to serve all categories equally\". To do this properly (irrespective of the number or distribution of workers), you would want to create one queue per category (dynamically), and then also dynamically bind each worker to a number of such queues (e.g. if W = # workers and N = # of categories and W < N, then workers should be bound to N / W queues on average for an even workload distribution). With the same assignment of worker to queue as dynamic category to routing key, the topologies are functionally equivalent.","metadata":{"transformedAt":"2026-08-18T18:33:20.198Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":40,"estimatedTokens":1145}}864{"id":"stack-12184460","source":"stackoverflow","questionId":12184460,"title":"Consuming the pickle binary format from non-python (with celery and rabbitmq)","tags":["python","rabbitmq","celery","pickle"],"text":"Title: Consuming the pickle binary format from non-python (with celery and rabbitmq)\nTags: python, rabbitmq, celery, pickle\nSource: Stack Overflow\n\nQuestion:\nI'm using Python, Celery and RabbitMQ to produce messages from loosely coupled systems. However, I'm worried about interoperability.\n\nWhen inspecting the message payload directly from RabbitMQ, that is produced by celery, I get the following binary format:\n\nI strongly suspect that this is a binary pickle format. However, I'm having trouble finding information on the binary pickle format in general.\n\nSo, I really have a few questions:\n\n- Is this a binary pickle format?\n\n- What resources are available to map out the binary format?\n\n- Given that celery does, in fact, produce pickled data, what options are available to me if I want to consume those messages from non-python consumers (such as c++ or php)?\n\n- Do you have any experiences of working with Celery, RabbitMQ and interoperating with other consumers which are not python. Do you have any advice regarding that subject?\n\nThanks in advance...\n\n**UPDATE:**\n\nBased on Brendan's recommendation, I've switched this to a JSON serializer with:\n\n```\nadd.apply_async(args=[10, 10], serializer=\"json\")\n```\n\nFor reference for future searchers, it appears that the JSON format, in this specific, empty case, is about 15% larger (or 28 bytes):\n\nAlso, for people that might be interested in reading the pickle format from c++, I found this question helpful:\nHow can I read a python pickle database/file from C?\n\n**UPDATE 2:**\n\nBased on Asksol's recommendation, I tried out the zlib compression with:\n\n```\nasync_result = add.apply_async( (x, y), compression='zlib' )\n```\n\nI thought there were some interesting results, so here they are:\n\nAs you can see in this example, the Pickle format is smaller than JSON. However, when compression is added to the mix, compressed JSON is actually smaller than either version of Pickle. I'm also curious about the parse times of either format. While JSON was designed to parser performant, Pickle is based on offsets, which means it wouldn't have to be iterated through. I wonder if anyone has done any performance benchmarks on the two formats, with and without compressions, and taking parsing CPU time into account.\n\n========================================\n\nTop Answer:\n- From the example of the `pickletools` module, I infer that this is indeed a pickle stream.\n\n- The format is not exactly documented. There are several versions in fact. But you can use the pickletools script (see above) for analyzing pickle files.\n\n- You cannot consume pickle'd data from other languages. The format is highly Python specific and in fact executes Python code (at the very least, object construction).\n\n- I have not. It appears Brendan Long has found a solution. You'll still need some dedicated code to parse the JSON messages at the other end (especially if you need to transfer any complicated structures), but it shouldn't be too hard (possibly fragile though).\n\n========================================\n\nCode:\n```text\nadd.apply_async(args=[10, 10], serializer=\"json\")\n```\n\n```text\nasync_result = add.apply_async( (x, y), compression='zlib' )\n```\n\n```text\npickletools\n```\n\n========================================\n\nComments:\n- simplejson is pretty fast, afair it wasn't much faster than pickle. The yajl and cjson libs are faster but is broken in a number of places. (e.g. yajl can't handle float timestamps).\n- btw, you could also bring msgpack into this, not sure how it performs.\n- You can also enable compression: docs.celeryproject.org/en/latest/userguide/…\n- Thanks @asksol, I've added compression to the examples and posted a comparison chart (with some interesting results). And thank you, too, for writing celery. Cheers.\n- for simple data structures you can certainly pickout the key value pairs ... but much more than that and you are absolutely right\n- This article looks good too: stackoverflow.com/questions/1296162/…\n- Thank you for your contribution","metadata":{"transformedAt":"2026-08-18T18:33:20.198Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":84,"estimatedTokens":1005}}865{"id":"stack-29501234","source":"stackoverflow","questionId":29501234,"title":"rabbtimqadmin - Could not connect: [Errno -2] Name or service not known","tags":["rabbitmq","rabbitmqctl","rabbitmqadmin"],"text":"Title: rabbtimqadmin - Could not connect: [Errno -2] Name or service not known\nTags: rabbitmq, rabbitmqctl, rabbitmqadmin\nSource: Stack Overflow\n\nQuestion:\nI have RabbitMQ installed on a CentOS 5.x server which I use for message passing between my programs. I've installed `rabbitmqadmin` following the directions on https://www.rabbitmq.com/management-cli.html and have used it on my servers in the past.\n\nFrom what I can tell it looks like this particular server is misconfigured. My web-searches have failed me on trying to get more information on how to troubleshoot this issue.\n\n**The error:**\n\n```\n[root@server ~]# python26 /usr/local/bin/rabbitmqadmin list nodes\n*** Could not connect: [Errno -2] Name or service not known\n[root@server ~]#\n```\n\nI have tried several different `rabbitmqadmin` commands and they give the same result. If I run the command without the extra params it displays the normal help dialog. I have this setup and working on several other servers. \n\nAny idea on what the root issue is? If not, anyway to get more details, like verbose?\n\n**Update:**\n\nI just tried to check the version of rabbitmq and its yielding an error too:\n\n```\n[root@server ~]# rabbitmqctl status\nStatus of node rabbit@server ...\nError: unable to connect to node rabbit@server: nodedown\n\nDIAGNOSTICS\n===========\n\nattempted to contact: [rabbit@server]\n\nrabbit@server:\n * connected to epmd (port 4369) on server\n * epmd reports node 'rabbit' running on port 25672\n * TCP connection succeeded but Erlang distribution failed\n * suggestion: hostname mismatch?\n * suggestion: is the cookie set correctly?\n\ncurrent node details:\n- node name: rabbitmqctl25451@server\n- home dir: /var/lib/rabbitmq\n- cookie hash: WXaeZT7XXm13naagfRX5cg==\n\n[root@server ~]#\n```\n\nI'm going to see if I can find something from this... I find this weird because the server is passing messages fine and can be monitored through the web console.\n\n**Erlang version:** \n\n```\n[root@server rabbitmq]# erl -eval 'erlang:display(erlang:system_info(otp_release)), halt().' -noshell\n\"R14B04\"\n[root@server rabbitmq]#\n```\n\n**Rabbitmq Version:**\n\n```\n[root@server rabbitmq]# python26 /usr/local/bin/rabbitmqadmin --version\nrabbitmqadmin 3.3.5\n[root@server rabbitmq]#\n```\n\n========================================\n\nTop Answer:\nYesterday I've lost a few hours with this same problem and it was in a fresh install, so the problem was that the erlang cookie from my user and root user was different than the one from rabbitmq user.\n\nFind out the HOME for the user rabbitmq:\n\n```\n# cat /etc/passwd | grep rabbitmq\n```\n\nCheck if the cookies differs from each other:\n\n```\n# vimdiff /var/lib/rabbitmq/.erlang.cookie ~/.erlang.cookie\n```\n\nIf they are different, copy the cookie from rabbitmq for the user that you want to have access to the server:\n\n```\n# cp /var/lib/rabbitmq/.erlang.cookie ~/.erlang.cookie\n```\n\nReferences:\n\nrabbitmqctl status says \"TCP connection succeeded but Erlang distribution failed\"\n\nHow Nodes (and CLI tools) Authenticate to Each Other: the Erlang Cookie\n\n========================================\n\nCode:\n```text\n[root@server ~]# python26 /usr/local/bin/rabbitmqadmin list nodes\n*** Could not connect: [Errno -2] Name or service not known\n[root@server ~]#\n```\n\n```text\n[root@server ~]# rabbitmqctl status\nStatus of node rabbit@server ...\nError: unable to connect to node rabbit@server: nodedown\n\nDIAGNOSTICS\n===========\n\nattempted to contact: [rabbit@server]\n\nrabbit@server:\n * connected to epmd (port 4369) on server\n * epmd reports node 'rabbit' running on port 25672\n * TCP connection succeeded but Erlang distribution failed\n * suggestion: hostname mismatch?\n * suggestion: is the cookie set correctly?\n\ncurrent node details:\n- node name: rabbitmqctl25451@server\n- home dir: /var/lib/rabbitmq\n- cookie hash: WXaeZT7XXm13naagfRX5cg==\n\n[root@server ~]#\n```\n\n```text\n[root@server rabbitmq]# erl -eval 'erlang:display(erlang:system_info(otp_release)), halt().' -noshell\n\"R14B04\"\n[root@server rabbitmq]#\n```\n\n```text\n[root@server rabbitmq]# python26 /usr/local/bin/rabbitmqadmin --version\nrabbitmqadmin 3.3.5\n[root@server rabbitmq]#\n```\n\n```text\nrabbitmqadmin\n```\n\n```text\nrabbitmqadmin\n```\n\n```text\nNODENAME=rabbit@OLDHOSTNAME\n```\n\n```text\nrabbitmq-env.conf\n```\n\n```text\n/etc/rabbitmq\n```\n\n```text\nls\n```\n\n```text\n/var/lib/rabbitmq/mnesia/\n```\n\n```text\n# cat /etc/passwd | grep rabbitmq\n```\n\n```text\n# vimdiff /var/lib/rabbitmq/.erlang.cookie ~/.erlang.cookie\n```\n\n```text\n# cp /var/lib/rabbitmq/.erlang.cookie ~/.erlang.cookie\n```\n\n========================================\n\nComments:\n- My hostname is controller1, and in the `/var/lib/rabbitmq/mnesia/` all is `controller1`, so means you answer is not fit my status?","metadata":{"transformedAt":"2026-08-18T18:33:20.198Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":14,"totalLines":187,"estimatedTokens":1180}}866{"id":"stack-56488779","source":"stackoverflow","questionId":56488779,"title":"PHP ampq + rabbit MQ -- long running producer: can send messages to queues already declared, but can't declare new queues","tags":["php","rabbitmq","php-amqplib"],"text":"Title: PHP ampq + rabbit MQ -- long running producer: can send messages to queues already declared, but can't declare new queues\nTags: php, rabbitmq, php-amqplib\nSource: Stack Overflow\n\nQuestion:\nI have a \"producer\" that's supposed to be always running, but it seems that after a day or so, it is still able to send messages to queues it has previously declared, but when trying to declare a new queue, it blows up with:\n\n```\n'PhpAmqpLib\\Exception\\AMQPHeartbeatMissedException' with message 'Missed server heartbeat' in /php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/AbstractIO.php:140\n```\n\nI thought that the heartbeat was only for consumers (since there's no place to check for heartbeats on producers)? Is it a bug that the heartbeat is being checked when I'm not a \"consumer\"?\n\nOr is it that my script also becomes a \"consumer\" when I declare a queue, because it needs to \"consume\" feedback from the server that the queue is ready for use or something?\n\nThe way it's currently set up, what work-around could I use periodically to check if `queue_declare` would blow up if it was run, so that when I do need to run `queue_declare` it doesn't blow up unexpectedly?\n\nI'm using `AMQPSSLConnection` on the most recent version (2.9.2), and `$connection->isConnected()` is returning `true` the whole time. Heartbeat is set to 15 seconds.\n\n========================================\n\nCode:\n```text\n'PhpAmqpLib\\Exception\\AMQPHeartbeatMissedException' with message 'Missed server heartbeat' in /php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/AbstractIO.php:140\n```\n\n```text\nqueue_declare\n```\n\n```text\nqueue_declare\n```\n\n```text\nAMQPSSLConnection\n```\n\n```text\n$connection->isConnected()\n```\n\n```text\ntrue\n```\n\n```text\nphp-amqplib\n```\n\n```text\n$connection->checkHeartBeat();\n```\n\n```text\n$connection->wait(null, true);\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.198Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":9,"totalLines":57,"estimatedTokens":452}}867{"id":"stack-39573721","source":"stackoverflow","questionId":39573721,"title":"Disable round-robin message consumption on MassTransit","tags":["c#","rabbitmq","masstransit"],"text":"Title: Disable round-robin message consumption on MassTransit\nTags: c#, rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nI have created a basic demo pub/sub application which works on localhost with MassTransit. \n\nWhat I want to achieve is to publish a message and **all** the subscribers should receive the message.\n\nAt the moment, in my environment I start one publisher app and two subscriber apps. But when I publish a message the subscribers receive the message in turns.\n\n**My pub/sub code:**\n\n*Publish:*\n\n```\nvar bus = Bus.Factory.CreateUsingRabbitMq(config =>\n{\n config.Host(new Uri(\"rabbitmq://localhost/\"), h => { });\n config.ExchangeType = ExchangeType.Fanout;\n});\nvar busHandle = bus.Start();\nbus.Publish(message);\n```\n\n*Subscribers use this code:*\n\n```\nvar bus = Bus.Factory.CreateUsingRabbitMq(config =>\n{\n var host = config.Host(new Uri(\"rabbitmq://localhost/\"), h => { });\n config.ReceiveEndpoint(host, \"MassTransitExample_Queue\", e => e.Consumer());\n});\n\nvar busHandle = bus.Start();\nConsole.ReadKey();\nbusHandle.Stop();\n```\n\n========================================\n\nCode:\n```text\nvar bus = Bus.Factory.CreateUsingRabbitMq(config =>\n{\n config.Host(new Uri(\"rabbitmq://localhost/\"), h => { });\n config.ExchangeType = ExchangeType.Fanout;\n});\nvar busHandle = bus.Start();\nbus.Publish<SomethingHappened>(message);\n```\n\n```text\nvar bus = Bus.Factory.CreateUsingRabbitMq(config =>\n{\n var host = config.Host(new Uri(\"rabbitmq://localhost/\"), h => { });\n config.ReceiveEndpoint(host, \"MassTransitExample_Queue\", e => e.Consumer<SomethingHappenedConsumer>());\n});\n\nvar busHandle = bus.Start();\nConsole.ReadKey();\nbusHandle.Stop();\n```\n\n```text\nvar bus = Bus.Factory.CreateUsingRabbitMq(config =>\n{\n var host = config.Host(new Uri(\"rabbitmq://localhost/\"), h => { });\n config.ReceiveEndpoint(host, \"MTExQueue_\" + Guid.NewGuid().ToString(), e => e.Consumer<SomethingHappenedConsumer>());\n});\n\nvar busHandle = bus.Start();\nConsole.ReadKey();\nbusHandle.Stop();\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.198Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":75,"estimatedTokens":496}}868{"id":"stack-51740526","source":"stackoverflow","questionId":51740526,"title":"Spring Boot trusted packages for rabbitmq","tags":["java","spring","spring-boot","rabbitmq"],"text":"Title: Spring Boot trusted packages for rabbitmq\nTags: java, spring, spring-boot, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nWe're building a Spring Boot application (2.0.4-RELEASE) that receives messages via RabbitMQ. Hence the `application.properties` contains the rabbit related config:\n\n```\nspring.rabbitmq.addresses=****\nspring.rabbitmq.username=****\nspring.rabbitmq.password=****\nspring.rabbitmq.listener.simple.concurrency=2\nspring.rabbitmq.listener.simple.prefetch=5\nspring.rabbitmq.listener.simple.retry.enabled=true\nspring.rabbitmq.listener.simple.retry.max-attempts=5\n```\n\nConfiguration:\n\n```\n@Bean\npublic TopicExchange fileUpdate() {\n return new TopicExchange(\"my.fancy.exchange\", true, false);\n}\n\n@Bean\npublic Queue fileUpload() {\n return new Queue(\"myFancyQueue\", true);\n}\n\n@Bean\npublic Binding bindingUpload(Queue queue, TopicExchange eventExchange) {\n return BindingBuilder.bind(queue).to(eventExchange).with(\"\");\n}\n```\n\nMessage Consumer:\n\n```\n@RabbitListener(queues = \"myFancyQueue\")\npublic void receive(Object message) {\n ...\n}\n```\n\nWhen receiving a message of a specific type (e.g. `__TypeId__: my.fancy.package.Clazz`) the following error is thrown:\n\n Caused by: java.lang.IllegalArgumentException: The class 'my.fancy.package.Clazz' is not\n in the trusted packages: [java.util, java.lang]. If you believe this\n class is safe to deserialize, please provide its name. If the\n serialization is only done by a trusted source, you can also enable\n trust all (*).\n\nFrom what I've discovered so far activeMQ provides a configuration option for that through the `application.properties` as\n\n```\nspring.activemq.packages.trust-all=\n```\n\nor\n\n```\nspring.activemq.packages.trusted=\n```\n\nbut I can't find any similar option that would work for rabbitMQ. So far I've been using a workaround that solves my problem but of course it would be great to have an option like that in the configuration file.\n\nMy solution so far:\n\nAdding to the configuration class:\n\n```\n@Bean\npublic MessageConverter jsonMessageConverter() {\n Jackson2JsonMessageConverter jsonMessageConverter = new Jackson2JsonMessageConverter(new ObjectMapper());\n jsonMessageConverter.setClassMapper(new ImporterClassMapper(FileUploadMessage.class)); \n return jsonMessageConverter;\n}\n\n@Bean\npublic RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {\n RabbitTemplate template = new RabbitTemplate(connectionFactory);\n template.setMessageConverter(jsonMessageConverter());\n return template;\n}\n```\n\nAnd changing the message consumer to\n\n```\n@Resource(name = \"jsonMessageConverter\")\nprivate MessageConverter messageConverter;\n\n@RabbitListener(queues = \"${uploaded.files.queue}\")\npublic void receive(Message message) {\n FileUploadMessage uploadMessage = (FileUploadMessage) messageConverter.fromMessage(message);\n ...\n}\n```\n\nPlus adding a class mapper that allows unkown types to be imported and sets a default type to which messages should be cast to on import:\n\n```\npublic class ImporterClassMapper implements ClassMapper, InitializingBean {\n\n private volatile Class defaultType;\n\n public ImporterClassMapper(Class defaultType) {\n this.defaultType = defaultType;\n } \n\n @Override\n public void afterPropertiesSet() throws Exception {\n // nothing to do\n }\n\n @Override\n public void fromClass(Class clazz, MessageProperties properties) {\n // avoid setting __TypeId__ header so consumers from other modules can implement their own DTOs\n }\n\n @Override\n public Class toClass(MessageProperties properties) {\n return this.defaultType;\n }\n\n public void setClass(Class type) {\n this.defaultType = type;\n }\n}\n```\n\nAny advise on how to improve this solution?\n\n========================================\n\nTop Answer:\nAs `CVE-2023-34050` and Spring AMQP DOC\nThere's an alternative way:\n\nset\n\nOS environment variable `SPRING_AMQP_DESERIALIZATION_TRUST_ALL` to `true`.\n\nor `VM options` to `-Dspring.amqp.deserialization.trust.all=true`\n\nIt worked, But not good way.\n\n========================================\n\nCode:\n```text\nspring.rabbitmq.addresses=****\nspring.rabbitmq.username=****\nspring.rabbitmq.password=****\nspring.rabbitmq.listener.simple.concurrency=2\nspring.rabbitmq.listener.simple.prefetch=5\nspring.rabbitmq.listener.simple.retry.enabled=true\nspring.rabbitmq.listener.simple.retry.max-attempts=5\n```\n\n```text\n@Bean\npublic TopicExchange fileUpdate() {\n return new TopicExchange(\"my.fancy.exchange\", true, false);\n}\n\n@Bean\npublic Queue fileUpload() {\n return new Queue(\"myFancyQueue\", true);\n}\n\n@Bean\npublic Binding bindingUpload(Queue queue, TopicExchange eventExchange) {\n return BindingBuilder.bind(queue).to(eventExchange).with(\"\");\n}\n```\n\n```text\n@RabbitListener(queues = \"myFancyQueue\")\npublic void receive(Object message) {\n ...\n}\n```\n\n```text\nspring.activemq.packages.trust-all=\n```\n\n```text\nspring.activemq.packages.trusted=\n```\n\n```text\n@Bean\npublic MessageConverter jsonMessageConverter() {\n Jackson2JsonMessageConverter jsonMessageConverter = new Jackson2JsonMessageConverter(new ObjectMapper());\n jsonMessageConverter.setClassMapper(new ImporterClassMapper(FileUploadMessage.class)); \n return jsonMessageConverter;\n}\n\n@Bean\npublic RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {\n RabbitTemplate template = new RabbitTemplate(connectionFactory);\n template.setMessageConverter(jsonMessageConverter());\n return template;\n}\n```\n\n```text\n@Resource(name = \"jsonMessageConverter\")\nprivate MessageConverter messageConverter;\n\n@RabbitListener(queues = \"${uploaded.files.queue}\")\npublic void receive(Message message) {\n FileUploadMessage uploadMessage = (FileUploadMessage) messageConverter.fromMessage(message);\n ...\n}\n```\n\n```text\npublic class ImporterClassMapper implements ClassMapper, InitializingBean {\n\n private volatile Class<?> defaultType;\n\n public ImporterClassMapper(Class<?> defaultType) {\n this.defaultType = defaultType;\n } \n\n @Override\n public void afterPropertiesSet() throws Exception {\n // nothing to do\n }\n\n @Override\n public void fromClass(Class<?> clazz, MessageProperties properties) {\n // avoid setting __TypeId__ header so consumers from other modules can implement their own DTOs\n }\n\n @Override\n public Class<?> toClass(MessageProperties properties) {\n return this.defaultType;\n }\n\n public void setClass(Class<?> type) {\n this.defaultType = type;\n }\n}\n```\n\n```text\napplication.properties\n```\n\n```text\n__TypeId__: my.fancy.package.Clazz\n```\n\n```text\napplication.properties\n```\n\n```text\n@Configuration\npublic class RabbitConfig {\n\n @Bean\n @Scope(\"prototype\")\n public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(SimpleRabbitListenerContainerFactory factory, ObjectMapper objectMapper) {\n factory.setMessageConverter(jsonToMapMessageConverter(objectMapper));\n return factory;\n }\n\n @Bean\n public MessageConverter jsonToMapMessageConverter(ObjectMapper objectMapper) {\n Jackson2JsonMessageConverter messageConverter = new ImplicitJsonMessageConverter(objectMapper);\n DefaultClassMapper classMapper = new DefaultClassMapper();\n classMapper.setTrustedPackages(\"*\");\n classMapper.setDefaultType(Map.class);\n messageConverter.setClassMapper(classMapper);\n return messageConverter;\n }\n\n public static class ImplicitJsonMessageConverter extends Jackson2JsonMessageConverter { \n public ImplicitJsonMessageConverter(ObjectMapper jsonObjectMapper) {\n super(jsonObjectMapper, \"*\");\n } \n @Override\n public Object fromMessage(Message message) throws MessageConversionException {\n message.getMessageProperties().setContentType(\"application/json\");\n return super.fromMessage(message);\n }\n }\n}\n```\n\n```text\nCVE-2023-34050\n```\n\n```text\nSPRING_AMQP_DESERIALIZATION_TRUST_ALL\n```\n\n```text\ntrue\n```\n\n```text\nVM options\n```\n\n```text\n-Dspring.amqp.deserialization.trust.all=true\n```\n\n========================================\n\nComments:\n- I think using JSON to send/receive arbitrary types is the recommended approach...\n- Yes, of course the types are transfered in JSON. Yet a **TypeId** is provided with them. The DefaultClassMapper will then always try to cast the JSON into the type and throw an exception if the consumer doesn't know the type\n- I had such an error message after upgrading to Spring Boot 4.0.7. I used Jackson v3 for JSON serialization/deserialization in context of RabbitMQ integration. My solution was to define a Spring Bean of type `JacksonJsonMessageConverter` and creating this bean using a constructor accepting package names as an argument. See: docs.spring.io/spring-amqp/docs/current/api/org/springframew‌​ork/…\n- although it took me a while - yes, that's a better approach. keeps me from implementing custom class mappers. thanks","metadata":{"transformedAt":"2026-08-18T18:33:20.198Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":17,"totalLines":323,"estimatedTokens":2220}}869{"id":"stack-32610511","source":"stackoverflow","questionId":32610511,"title":"RabbitMQ, delivery tag value and message order after reconnect","tags":["python","rabbitmq","pika"],"text":"Title: RabbitMQ, delivery tag value and message order after reconnect\nTags: python, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI use pika for python to communicate with RabbitMQ. I have 6 threads, which consume and acknowledge messages from the same queue. I use different connections(and channels) for each thread. So i have a few questions very close to each other:\n\nIf connection to rabbit will close in 1 of the thread, and i will make reconnect, delivery tag value will reset and after reconnect it will start from 0?\n\nAfter reconnect i will receive same unacknowledged messages in the same order for each thread or it will start distribute them again between all threads or it will start from reconnect point?\n\nIt is important in my app, because there is delay between message receiving and acknowledgement, and i want to avoid duplicates on the next process steps.\n\n========================================\n\nCode:\n```text\ndelivery-tag\n```\n\n```text\ndelivery-tag\n```\n\n```text\n1\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.198Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":27,"estimatedTokens":248}}870{"id":"stack-47104174","source":"stackoverflow","questionId":47104174,"title":"Receiving pull access denied error while trying to run docker-compose.yml file","tags":["docker","rabbitmq","docker-compose","dockerfile"],"text":"Title: Receiving pull access denied error while trying to run docker-compose.yml file\nTags: docker, rabbitmq, docker-compose, dockerfile\nSource: Stack Overflow\n\nQuestion:\nIn building a microservices-based app using Node and Docker. I created my docker-compose.yml file, however when I try to run execute the command \"docker-compose up -d\", I keep getting the following error message: \"ERROR: pull access denied for RabbbitMQ, repository does not exist or may require 'docker login'\". Here is a sample of my docker-compose.yml file:\n\n```\nversion: '2'\nservices:\n myservice1:\n container_name: “myapp_myservice1”\n build:\n context: ../../MyService1\n dockerfile: dev.Dockerfile\n command: npm start\n volumes:\n - ../../MyService1:/usr/src/app/\n ports:\n - \"3000:3000\"\n depends_on:\n - mongo\n - rabbitmq\n - nginx\n myservice2:\n container_name: “myapp_myservice2”\n build:\n context: ../../MyService2\n dockerfile: dev.Dockerfile\n command: npm start\n volumes:\n - ../../MyService2:/usr/src/app/\n ports:\n - \"3000:3001”\n depends_on:\n - mongo\n - rabbitmq\n - nginx\n myservice3:\n container_name: \"myapp_myservice3\"\n build:\n context: ../../MyService3\n dockerfile: dev.Dockerfile\n command: npm start\n volumes:\n - ../../MyService3:/usr/src/app/\n ports:\n - \"3000:3002”\n depends_on:\n - mongo\n - rabbitmq\n - nginx\n mongo:\n container_name: \"myapp_mongo\"\n image: mongo:3.5.13\n environment:\n - MONGO_DATA_DIR=/data/db\n - MONGO_LOG_DIR=/dev/null\n - MONGO_INITDB_ROOT_USERNAME=*******\n - MONGO_INITDB_ROOT_PASSWORD==*******\n volumes:\n - /data/db:/data/db\n ports:\n - 27017:27017\n command: mongod --smallfiles --logpath=/dev/null # --quiet\n nginx:\n container_name: \"myapp_nginx\"\n image: nginx:1.13.6\n ports:\n - \"80:80\"\n - \"8080:8080\"\n volumes:\n - ./nginx/conf:/etc/nginx/conf.d\n command: /bin/bash -c \"envsubst /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'\"\n rabbitmq:\n container_name: \"myapp_rabbitmq\"\n image: rabbbitmq:latest\n environment:\n - RABBITMQ_ERLANG_COOKIE='secret_cookie'\n hostname: fourthreefortymq\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n tty: true\n volumes:\n - ./rabbitmq/lib:/var/lib/rabbitmq\n - ./rabbitmq/log:/var/log/rabbitmq\n - ./rabbitmq/conf:/etc/rabbitmq/\n```\n\nand here is a sample of my dev.Dockerfile:\n\n`FROM node:latest` (I commented out the rest of this file)\n\nIt tries to run RabbitMQ first and then it fails with the error message. I even tried to create a new account for docker hub and login followed by running the command but I am still getting the same error message. Additionally, I ran the command `docker inspect rabbitmq` from the terminal screen and I received a JSON array response back. I would assume this means it exists and is reachable. What am I missing?\n\n========================================\n\nTop Answer:\n`docker-compose build` will build everything locally for you based on **docker-compose.yml**, and doesn't need to pull from remote repos.\n\nAfter running the above command, you can run `docker-compose up -d` to run a container on the built images.\n\nThis is just a first-time thing and after changing anything locally and then needing to re-create the containers and images you can run `docker-compose up -d --build`\n\n========================================\n\nCode:\n```text\nversion: '2'\nservices:\n myservice1:\n container_name: “myapp_myservice1”\n build:\n context: ../../MyService1\n dockerfile: dev.Dockerfile\n command: npm start\n volumes:\n - ../../MyService1:/usr/src/app/\n ports:\n - \"3000:3000\"\n depends_on:\n - mongo\n - rabbitmq\n - nginx\n myservice2:\n container_name: “myapp_myservice2”\n build:\n context: ../../MyService2\n dockerfile: dev.Dockerfile\n command: npm start\n volumes:\n - ../../MyService2:/usr/src/app/\n ports:\n - \"3000:3001”\n depends_on:\n - mongo\n - rabbitmq\n - nginx\n myservice3:\n container_name: \"myapp_myservice3\"\n build:\n context: ../../MyService3\n dockerfile: dev.Dockerfile\n command: npm start\n volumes:\n - ../../MyService3:/usr/src/app/\n ports:\n - \"3000:3002”\n depends_on:\n - mongo\n - rabbitmq\n - nginx\n mongo:\n container_name: \"myapp_mongo\"\n image: mongo:3.5.13\n environment:\n - MONGO_DATA_DIR=/data/db\n - MONGO_LOG_DIR=/dev/null\n - MONGO_INITDB_ROOT_USERNAME=*******\n - MONGO_INITDB_ROOT_PASSWORD==*******\n volumes:\n - /data/db:/data/db\n ports:\n - 27017:27017\n command: mongod --smallfiles --logpath=/dev/null # --quiet\n nginx:\n container_name: \"myapp_nginx\"\n image: nginx:1.13.6\n ports:\n - \"80:80\"\n - \"8080:8080\"\n volumes:\n - ./nginx/conf:/etc/nginx/conf.d\n command: /bin/bash -c \"envsubst < /etc/nginx/conf.d/mysite.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'\"\n rabbitmq:\n container_name: \"myapp_rabbitmq\"\n image: rabbbitmq:latest\n environment:\n - RABBITMQ_ERLANG_COOKIE='secret_cookie'\n hostname: fourthreefortymq\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n tty: true\n volumes:\n - ./rabbitmq/lib:/var/lib/rabbitmq\n - ./rabbitmq/log:/var/log/rabbitmq\n - ./rabbitmq/conf:/etc/rabbitmq/\n```\n\n```text\nFROM node:latest\n```\n\n```text\ndocker inspect rabbitmq\n```\n\n```text\nrabbitmq:latest\n```\n\n```text\nrabbbitmq:latest\n```\n\n```text\ndocker-compose build\n```\n\n```text\ndocker-compose up -d\n```\n\n```text\ndocker-compose up -d --build\n```\n\n========================================\n\nComments:\n- Your code sample for your `docker-compose.yml` file has smart quotes in a handful of places. Can you verify that you don't have smart quotes in your actual `docker-compose.yml` file?\n- Good eye! That definitely looks like the root cause of error.\n- I got the same error when running `docker run helloworld` (i.e. missing a `-`).","metadata":{"transformedAt":"2026-08-18T18:33:20.198Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":225,"estimatedTokens":1445}}871{"id":"stack-30830974","source":"stackoverflow","questionId":30830974,"title":"celery worker not working though rabbitmq has queue buildup","tags":["python","python-2.7","rabbitmq","celery","digital-ocean"],"text":"Title: celery worker not working though rabbitmq has queue buildup\nTags: python, python-2.7, rabbitmq, celery, digital-ocean\nSource: Stack Overflow\n\nQuestion:\nI am getting in touch with celery and I wrote a task by following Tutorial but somehow worker not getting up and I get following log\nAfter entering command:\n\n```\ncelery worker -A tasks -l debug\n```\n\nI get a log:\n\n```\nRunning a worker with superuser privileges when the\nworker accepts messages serialized with pickle is a very bad idea!\n\nIf you really want to continue then you have to set the C_FORCE_ROOT\nenvironment variable (but please think about this before you do).\n\nUser information: uid=0 euid=0 gid=0 egid=0\n```\n\nAnd here is my task:\n\n```\nfrom celery import Celery\n\napp = Celery('tasks', backend='amqp',broker='amqp://sanjay:**@localhost:5672//')\n\n@app.task\ndef gen_prime(x):\n multiples = []\n results = []\n for i in xrange(2, x+1):\n if i not in multiples:\n results.append(i)\n for j in xrange(i*i, x+1, i):\n multiples.append(j)\n return results\n```\n\nThough in rabbitmq admin console I see some queue build up when I try to generate prime numbers in ipython console but i am not getting result back on the console.\n\nHere is my console action:\n\n```\n>>> from tasks import gen_prime\n>>> pr=gen_prime.delay(10000)\n>>> pr.ready()\nFalse\n>>> \n>>> pr.ready()\nFalse\n>>> pr.ready()\nFalse\n```\n\nI am trying to solve this one from last 3 days but I was not able to solve it.\n\n========================================\n\nTop Answer:\nThe error message pretty much tells you what's going on in this case. You're trying to run the worker as root (generally a bad idea due to security concerns). If you want to override this and allow it to run, you must set your environment: \n\n```\nexport C_FORCE_ROOT=\"true\"\n```\n\nThen run the worker.\n\nOr you can just run it as a different user, which is preferred. You can search for how to add a user. Then you simply login as that user or su and execute your worker.\n\nSince you tagged this digital ocean, here is a link to their tutorial on how to add a user: \n\nhttps://www.digitalocean.com/community/tutorials/how-to-add-and-delete-users-on-ubuntu-12-04-and-centos-6\n\nAlso, celery has some docs regarding how to daemonize your workers. I usually use the supervisord method.\n\nhttps://celery.readthedocs.org/en/latest/tutorials/daemonizing.html#centos\n\n========================================\n\nCode:\n```text\ncelery worker -A tasks -l debug\n```\n\n```text\nRunning a worker with superuser privileges when the\nworker accepts messages serialized with pickle is a very bad idea!\n\nIf you really want to continue then you have to set the C_FORCE_ROOT\nenvironment variable (but please think about this before you do).\n\nUser information: uid=0 euid=0 gid=0 egid=0\n```\n\n```text\nfrom celery import Celery\n\napp = Celery('tasks', backend='amqp',broker='amqp://sanjay:**@localhost:5672//')\n\n@app.task\ndef gen_prime(x):\n multiples = []\n results = []\n for i in xrange(2, x+1):\n if i not in multiples:\n results.append(i)\n for j in xrange(i*i, x+1, i):\n multiples.append(j)\n return results\n```\n\n```text\n>>> from tasks import gen_prime\n>>> pr=gen_prime.delay(10000)\n>>> pr.ready()\nFalse\n>>> \n>>> pr.ready()\nFalse\n>>> pr.ready()\nFalse\n```\n\n```text\nuser\n```\n\n```text\nexport C_FORCE_ROOT=\"true\"\n```\n\n========================================\n\nComments:\n- can you tell me how can I do this?I am new to celery and not able to find any docs about it!\n- how are you running the command `celery worker -A tasks -l debug` ? from the command line? if so simply log in a different user.","metadata":{"transformedAt":"2026-08-18T18:33:20.198Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":141,"estimatedTokens":898}}872{"id":"stack-52081373","source":"stackoverflow","questionId":52081373,"title":"rabbit-mq deployment with kubernetes","tags":["docker","kubernetes","rabbitmq","kubectl"],"text":"Title: rabbit-mq deployment with kubernetes\nTags: docker, kubernetes, rabbitmq, kubectl\nSource: Stack Overflow\n\nQuestion:\nI'm in a progress to migrate to kuberenetes from docker-compose.\nOne of the services we're using is rabbit-mq.\nWhen I try to deploy rabbit-mq 3.6.16-management I receive the error:\n\n*/usr/local/bin/docker-entrypoint.sh: line 382: /etc/rabbitmq/rabbitmq.config: Permission denied.*\n\nWhile it works in docker-compose deployment.\n\n**Kuberentes**:\n\n```\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n labels:\n app: rabbit-mq\n name: rabbit-mq\nspec:\n replicas: 1\n selector:\n matchLabels:\n app: rabbit-mq\n strategy:\n type: Recreate\n template:\n metadata:\n labels:\n app: rabbit-mq\n spec:\n containers:\n - image: rabbitmq:3.6.16-management\n name: rabbit-mq\n ports:\n - containerPort: 15671\n - containerPort: 5671\n volumeMounts:\n - mountPath: /etc/rabbitmq\n name: rabbit-mq-data\n restartPolicy: Always\n hostname: rabbit-mq\n volumes:\n - name: rabbit-mq-data\n persistentVolumeClaim:\n claimName: rabbit-mq-data\n```\n\n**PVC:**\n\n```\napiVersion: v1\nkind: PersistentVolumeClaim\nmetadata:\n labels:\n app: rabbit-mq-data\n name: rabbit-mq-data\nspec:\n accessModes:\n - ReadWriteOnce\n resources:\n requests:\n storage: 16Gi\n```\n\n**PV:**\n\n```\napiVersion: v1\nkind: PersistentVolume\nmetadata:\n name: rabbit-mq-data\n labels:\n type: local\nspec:\n accessModes:\n - ReadWriteOnce\n capacity:\n storage: 16Gi\n hostPath:\n path: \"/etc/rabbitmq\"\n```\n\n**Docker-Compose:**\n\n```\nrabbit-mq:\n image: rabbitmq:3.6.16-management\n ports:\n - \"15671:15671\"\n - \"5671:5671\"\n container_name: rabbit-mq\n volumes:\n - rabbit-mq-data:/etc/rabbitmq\n restart: on-failure:5\n```\n\n========================================\n\nCode:\n```text\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n labels:\n app: rabbit-mq\n name: rabbit-mq\nspec:\n replicas: 1\n selector:\n matchLabels:\n app: rabbit-mq\n strategy:\n type: Recreate\n template:\n metadata:\n labels:\n app: rabbit-mq\n spec:\n containers:\n - image: rabbitmq:3.6.16-management\n name: rabbit-mq\n ports:\n - containerPort: 15671\n - containerPort: 5671\n volumeMounts:\n - mountPath: /etc/rabbitmq\n name: rabbit-mq-data\n restartPolicy: Always\n hostname: rabbit-mq\n volumes:\n - name: rabbit-mq-data\n persistentVolumeClaim:\n claimName: rabbit-mq-data\n```\n\n```text\napiVersion: v1\nkind: PersistentVolumeClaim\nmetadata:\n labels:\n app: rabbit-mq-data\n name: rabbit-mq-data\nspec:\n accessModes:\n - ReadWriteOnce\n resources:\n requests:\n storage: 16Gi\n```\n\n```text\napiVersion: v1\nkind: PersistentVolume\nmetadata:\n name: rabbit-mq-data\n labels:\n type: local\nspec:\n accessModes:\n - ReadWriteOnce\n capacity:\n storage: 16Gi\n hostPath:\n path: \"/etc/rabbitmq\"\n```\n\n```text\nrabbit-mq:\n image: rabbitmq:3.6.16-management\n ports:\n - \"15671:15671\"\n - \"5671:5671\"\n container_name: rabbit-mq\n volumes:\n - rabbit-mq-data:/etc/rabbitmq\n restart: on-failure:5\n```\n\n```text\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n labels:\n app: rabbit-mq\n name: rabbit-mq\nspec:\n replicas: 1\n selector:\n matchLabels:\n app: rabbit-mq\n template:\n metadata:\n labels:\n app: rabbit-mq\n spec:\n containers:\n - image: rabbitmq:3.6.16-management\n name: rabbit-mq\n ports:\n - containerPort: 15671\n - containerPort: 5671\n volumeMounts:\n - name: rabbit-mq-data\n mountPath: /etc/rabbitmq\n readOnly: false\n - name: mq-secret\n mountPath: /etc/rabbitmq/certfiles\n #readOnly: true\n volumes:\n - name: mq-secret\n secret:\n defaultMode: 420\n secretName: rabbit-mq-secrets\n - configMap:\n defaultMode: 420\n items:\n - key: rabbitmq.config\n path: rabbitmq.config\n name: mq-config\n name: rabbit-mq-data\n```\n\n========================================\n\nComments:\n- What are your PVC and related manifests to persistent volumes?\n- I've added them to the main post\n- What are file owner and permission of `/etc/rabbitmq` folder that you reference in `hostPath`?\n- Eventually I've used configmap and secrets to mount files instead of PV and works as expected.\n- Could you provide the whole yaml. I am getting the same issue. If you have git repo, could you please I'll refer from there. Thanks","metadata":{"transformedAt":"2026-08-18T18:33:20.198Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":234,"estimatedTokens":1120}}873{"id":"stack-58206351","source":"stackoverflow","questionId":58206351,"title":"Init container to wait for rabbit-mq readiness","tags":["docker","kubernetes","rabbitmq","rabbitmqctl"],"text":"Title: Init container to wait for rabbit-mq readiness\nTags: docker, kubernetes, rabbitmq, rabbitmqctl\nSource: Stack Overflow\n\nQuestion:\nI saw the example for docker healthcheck of RabbitMQ at docker-library/healthcheck.\n\nI would like to apply a similar mechanism to my Kubernetes deployment to await on Rabbit deployment readiness. I'm doing a similar thing with MongoDB, using a container that busy-waits mongo with some ping command.\n\n```\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: app-1\nspec:\n replicas: 1\n selector:\n matchLabels:\n app: app-1\n template:\n metadata:\n labels:\n app: app-1\n spec:\n initContainers:\n - name: wait-for-mongo\n image: gcr.io/app-1/tools/mongo-ping\n containers:\n - name: app-1-service\n image: gcr.io/app-1/service\n ...\n```\n\nHowever when I tried to construct such an init container I couldn't find any solution on how to query the health of rabbit from outside its cluster.\n\n========================================\n\nTop Answer:\nThe following works without any extra images/scripts, but requires you to enable the Management Plugin, eg by using the `rabbitmq:3.8-management` image instead of eg `rabbitmq:3.8`.\n\n```\ninitContainers:\n - name: check-rabbitmq-ready\n image: busybox\n command: [ 'sh', '-c',\n 'until wget http://guest:guest@rabbitmq:15672/api/aliveness-test/%2F;\n do echo waiting for rabbitmq; sleep 2; done;' ]\n```\n\nSpecifically, this is waiting until the HTTP Management API is available, and then checking that the default vhost is running healthily. The `%2F` refers to the default `/` vhost, which has to be urlendoded. If using your own vhost, enter that instead.\n\n========================================\n\nCode:\n```text\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: app-1\nspec:\n replicas: 1\n selector:\n matchLabels:\n app: app-1\n template:\n metadata:\n labels:\n app: app-1\n spec:\n initContainers:\n - name: wait-for-mongo\n image: gcr.io/app-1/tools/mongo-ping\n containers:\n - name: app-1-service\n image: gcr.io/app-1/service\n ...\n```\n\n```text\nFROM python:3-alpine\n\nENV RABBIT_HOST=\"my-rabbit\"\nENV RABBIT_VHOST=\"vhost\"\nENV RABBIT_USERNAME=\"root\"\n\nRUN pip install pika\n\nCOPY check_rabbitmq_connection.py /check_rabbitmq_connection.py\nRUN chmod +x /check_rabbitmq_connection.py\n\nCMD [\"sh\", \"-c\", \"python /check_rabbitmq_connection.py --host $RABBIT_HOST --username $RABBIT_USERNAME --password $RABBIT_PASSWORD --virtual_host $RABBIT_VHOST\"]\n```\n\n```py\n#!/usr/bin/env python3\n# Check connection to the RabbitMQ server\n# Source: https://blog.sleeplessbeastie.eu/2017/07/10/how-to-check-connection-to-the-rabbitmq-message-broker/\n\nimport argparse\nimport time\nimport pika\n\n# define and parse command-line options\nparser = argparse.ArgumentParser(description='Check connection to RabbitMQ server')\nparser.add_argument('--host', required=True, help='Define RabbitMQ server hostname')\nparser.add_argument('--virtual_host', default='/', help='Define virtual host')\nparser.add_argument('--port', type=int, default=5672, help='Define port (default: %(default)s)')\nparser.add_argument('--username', default='guest', help='Define username (default: %(default)s)')\nparser.add_argument('--password', default='guest', help='Define password (default: %(default)s)')\nargs = vars(parser.parse_args())\n\nprint(args)\n\n# set amqp credentials\ncredentials = pika.PlainCredentials(args['username'], args['password'])\n# set amqp connection parameters\nparameters = pika.ConnectionParameters(host=args['host'], port=args['port'], virtual_host=args['virtual_host'], credentials=credentials)\n\n# try to establish connection and check its status\nwhile True:\n try:\n connection = pika.BlockingConnection(parameters)\n if connection.is_open:\n print('OK')\n connection.close()\n exit(0)\n except Exception as error:\n raise\n print('No connection yet:', error.__class__.__name__)\n time.sleep(5)\n```\n\n```sh\ndocker build -t rabbit-ping .\n\ndocker run --rm -it \\\n --name rabbit-ping \\\n --net=my-net \\\n -e RABBIT_PASSWORD=\"<rabbit password>\" \\\n rabbit-ping\n```\n\n```yaml\napiVersion: apps/v1\nkind: Deployment\n...\nspec:\n ...\n template:\n ...\n spec:\n initContainers:\n - name: wait-for-rabbit\n image: gcr.io/my-org/rabbit-ping\n env:\n - name: RABBIT_PASSWORD\n valueFrom:\n secretKeyRef:\n name: rabbit\n key: rabbit-password\n containers:\n ...\n```\n\n```text\ninitContainers:\n - name: check-rabbitmq-ready\n image: busybox\n command: [ 'sh', '-c',\n 'until wget http://guest:guest@rabbitmq:15672/api/aliveness-test/%2F;\n do echo waiting for rabbitmq; sleep 2; done;' ]\n```\n\n```text\nrabbitmq:3.8-management\n```\n\n```text\nrabbitmq:3.8\n```\n\n```text\n%2F\n```\n\n```text\n/\n```\n\n========================================\n\nComments:\n- Please take a look for this ready example","metadata":{"transformedAt":"2026-08-18T18:33:20.198Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":193,"estimatedTokens":1242}}874{"id":"stack-27502994","source":"stackoverflow","questionId":27502994,"title":"Multi producer, multi consumer in Rabbit MQ with single queue","tags":["c#","rabbitmq","message-queue"],"text":"Title: Multi producer, multi consumer in Rabbit MQ with single queue\nTags: c#, rabbitmq, message-queue\nSource: Stack Overflow\n\nQuestion:\nI'm very new to RabbitMQ and I need to write a program that has Multi Producer and multi consumer with a single queue. Is this possible to do what I've shown in the image? I found lots of examples but they are all with single producer. Any producer send messages to any consumer.\n\n========================================\n\nComments:\n- To be honest you do not need an exchange use this example rabbitmq.com/tutorials/tutorial-two-dotnet.html and add more producers sending to the same queue. Queued items will be in the order that they are received and you will not be able to tell which queue sent it. This is a work queue so each message is sent once to only one consumer not replicated. If you need all consumers to see all messages then you need a different set up.\n- You are right we might need to expand the solution in future. @jhilden\n- @Diana, as a rule of thumb, I recommend that you always publish to an exchange vs publishing directly to a queue. You'll find exchanges very useful in the future and it's better to have a consistent process.","metadata":{"transformedAt":"2026-08-18T18:33:20.198Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":13,"estimatedTokens":297}}875{"id":"stack-27573359","source":"stackoverflow","questionId":27573359,"title":"rabbitmq amqp - listening to ack messages from consumer","tags":["rabbitmq","amqp","producer-consumer"],"text":"Title: rabbitmq amqp - listening to ack messages from consumer\nTags: rabbitmq, amqp, producer-consumer\nSource: Stack Overflow\n\nQuestion:\nI have a producer and broker on the same machine. The producer sends messages like so:\n\n```\nchannel = connection.createChannel();\n\n//Create a durable queue (if not already present)\nchannel.queueDeclare(merchantId, true, false, false, null);\n\n//Publish message onto the queue\nchannel.basicPublish(\"\", consumerId, true, false,\n MessageProperties.MINIMAL_PERSISTENT_BASIC, \"myMessage\");\n```\n\nThe consumer sits on another machine and listens to messages. It uses explicit acknowledgement like so:\n\n```\nwhile (true) {\n QueueingConsumer.Delivery delivery = consumer.nextDelivery();\n //Handle message here \n channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);\n}\n```\n\nFrom what I understand, the ack is meant for the broker to dequeue the message.\n\nBut how can my producer come to know about the ack that the consumer sent?\n\n========================================\n\nCode:\n```text\nchannel = connection.createChannel();\n\n//Create a durable queue (if not already present)\nchannel.queueDeclare(merchantId, true, false, false, null);\n\n//Publish message onto the queue\nchannel.basicPublish(\"\", consumerId, true, false,\n MessageProperties.MINIMAL_PERSISTENT_BASIC, \"myMessage\");\n```\n\n```text\nwhile (true) {\n QueueingConsumer.Delivery delivery = consumer.nextDelivery();\n //Handle message here \n channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);\n}\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.199Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":53,"estimatedTokens":379}}876{"id":"stack-18179296","source":"stackoverflow","questionId":18179296,"title":"how can I purge a MassTransit queue?","tags":["c#","rabbitmq","mq","masstransit"],"text":"Title: how can I purge a MassTransit queue?\nTags: c#, rabbitmq, mq, masstransit\nSource: Stack Overflow\n\nQuestion:\nI'd like to delete all the messages from a queue in my integration test SetUp routine, how can I accomplish that? No luck with googling/intellisense-bruteforce.\n\nIf it matters -- I'm using RabbitMq as transport.\n\n========================================\n\nCode:\n```text\nrabbitmq://localhost/*?temporary=true\n```\n\n```text\n?temporary=true\n```\n\n========================================\n\nComments:\n- There's no way to \"purge\" the queues from within MassTransit. -- is it \"by design\"?\n- There is `SetPurgeOnStartup(true)` configuration option. Which might do what you want. Temporary queues are a better answer in RabbitMQ. However, if you feel like it needed, for whatever reason, and `SetPurgeOnStartup` doesn't cut it for you, submit an issue: github.com/MassTransit/MassTransit/issues\n- temporary queues appear to have been omitted in V2.9.5\n- They're in the latest v2 codebase, and have been for several releases.","metadata":{"transformedAt":"2026-08-18T18:33:20.199Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":27,"estimatedTokens":257}}877{"id":"stack-29217428","source":"stackoverflow","questionId":29217428,"title":"RabbitMQ Web STOMP without SockJS","tags":["websocket","rabbitmq","stomp"],"text":"Title: RabbitMQ Web STOMP without SockJS\nTags: websocket, rabbitmq, stomp\nSource: Stack Overflow\n\nQuestion:\nIs it possible to setup RabbitMQ Web STOMP connection without SockJS library?\n\nI have played around with `rabbitmq-web-stomp` plugin without a success as the initial response generated by the server is *`Welcome to SockJS!`* (which is obviously not a STOMP based message).\n\nIs SockJS really required? What does it bring into the game (besides legacy browser support)?\n\n========================================\n\nCode:\n```text\nrabbitmq-web-stomp\n```\n\n```text\nWelcome to SockJS!\n```\n\n```text\nws://localhost:8081/echo/websocket\n```\n\n```text\n/websocket\n```\n\n```text\nhttp://example.com:15674/stomp/websocket\n```\n\n========================================\n\nComments:\n- RabbitMq web stomp doesn't support websocket PING frame message — server doesn't send PONG frame back. It is the reason, why client.heartbeat.outgoing and client.heartbeat.incoming are set to 0 (see official examples — \"SockJS does not support heart-beat: disable heart-beats\"). So, your connection will be terminated by proxy or by stomp-websocket library (if you don't set client.heartbeat.* to 0).","metadata":{"transformedAt":"2026-08-18T18:33:20.199Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":38,"estimatedTokens":293}}878{"id":"stack-15487657","source":"stackoverflow","questionId":15487657,"title":"rabbitmq AMQP::consume()","tags":["php","rabbitmq","amqp","queueing"],"text":"Title: rabbitmq AMQP::consume()\nTags: php, rabbitmq, amqp, queueing\nSource: Stack Overflow\n\nQuestion:\nAMQP function consume() is a blocking function with a callback,\nIs it possible to set a timeout for consume() function, so after specific amount of time it doesn't block anymore and the code execution completes ?\n\n========================================\n\nCode:\n```php\n$amqp = new AMQPConnection($your_connection_params);\n$amqp->setTimeout($seconds);\n```\n\n```php\n$tag = uniqid() . microtime(true);\n$queue->consume($callback, $flags, $tag);\n$queue->cancel($tag);\n```\n\n========================================\n\nComments:\n- FYI, I'm using the pecl amqp module, version 1.0.9. I tried upgrading to the latest version recently and my code completely broke. But the method I described above is working properly with amqp-1.0.9 and rabbitmq 3.1.3.\n- Ran into this scenario today and your answer lead me in the right direction. The `setTimeout` method has been deprecated in favour of the `setReadTimeout`. Also make sure to capture the `AMQPConnectionException` exception that consume throws when you timeout. AMQP version 1.4","metadata":{"transformedAt":"2026-08-18T18:33:20.199Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":27,"estimatedTokens":281}}879{"id":"stack-16936320","source":"stackoverflow","questionId":16936320,"title":"What belongs into a DLQ / Invalid Message Queue?","tags":["error-handling","rabbitmq","activemq-classic","ibm-mq","mq"],"text":"Title: What belongs into a DLQ / Invalid Message Queue?\nTags: error-handling, rabbitmq, activemq-classic, ibm-mq, mq\nSource: Stack Overflow\n\nQuestion:\nIs there a good best practice about what kind of messages an application is allowed to reject?\n\nMy understanding is that all messages which can't be handled should be rejected to the dead letter queue - no matter if the problem is a syntax error or a semantic error in the message or if the application is temporarily not able to handle the message (for instance because the db just went down).\n\nOf course - if the app already knows upfront that it will not be able to handle a message (DB down), it should stop accepting messages.\n\nSo what's the common understanding / best practice?\n\n========================================\n\nComments:\n- Sounds good. With ActiveMQ, it seems that you can configure a DLQ on per queue basis - so just another terminology...","metadata":{"transformedAt":"2026-08-18T18:33:20.199Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":17,"estimatedTokens":227}}880{"id":"stack-17426899","source":"stackoverflow","questionId":17426899,"title":"Client can't connect to RabbitMQ server on localhost","tags":["php","symfony","ubuntu","rabbitmq","ubuntu-12.04"],"text":"Title: Client can't connect to RabbitMQ server on localhost\nTags: php, symfony, ubuntu, rabbitmq, ubuntu-12.04\nSource: Stack Overflow\n\nQuestion:\nI installed fresh RabbitMQ 3.1.3 on ubuntu 12.04.2 LTS by apt-get, and try to start consumers on the same server, but I have connection problem:\n\n```\n[PhpAmqpLib\\Exception\\AMQPRuntimeException] \nError Connecting to server(113): No route to host\n```\n\nThere is status of working server:\n\n```\nStatus of node rabbit@ns1 ...\n[{pid,2106},\n {running_applications,[{rabbit,\"RabbitMQ\",\"3.1.3\"},\n {mnesia,\"MNESIA CXC 138 12\",\"4.5\"},\n {os_mon,\"CPO CXC 138 46\",\"2.2.7\"},\n {xmerl,\"XML parser\",\"1.2.10\"},\n {sasl,\"SASL CXC 138 11\",\"2.1.10\"},\n {stdlib,\"ERTS CXC 138 10\",\"1.17.5\"},\n {kernel,\"ERTS CXC 138 10\",\"2.14.5\"}]},\n {os,{unix,linux}},\n {erlang_version,\"Erlang R14B04 (erts-5.8.5) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:30] [kernel-poll:true]\\n\"},\n {memory,[{total,27728944},\n {connection_procs,2704},\n {queue_procs,5408},\n {plugins,0},\n {other_proc,9021680},\n {mnesia,60016},\n {mgmt_db,0},\n {msg_index,31144},\n {other_ets,770736},\n {binary,1968},\n {code,14560395},\n {atom,1356081},\n {other_system,1918812}]},\n {vm_memory_high_watermark,0.4},\n {vm_memory_limit,1262847590},\n {disk_free_limit,1000000000},\n {disk_free,214706556928},\n {file_descriptors,[{total_limit,924},\n {total_used,3},\n {sockets_limit,829},\n {sockets_used,1}]},\n {processes,[{limit,1048576},{used,125}]},\n {run_queue,0},\n {uptime,1265}]\n...done.\n```\n\nI don't have any limitations by iptables (ports):\n\n```\nChain INPUT (policy ACCEPT)\ntarget prot opt source destination \n\nChain FORWARD (policy ACCEPT)\ntarget prot opt source destination \n\nChain OUTPUT (policy ACCEPT)\ntarget prot opt source destination\n```\n\nAnd `etc/hosts` is OK.\n\n```\n127.0.0.1 localhost\n{IP-ADDRESS} ns1.***.org ns1\n# The following lines are desirable for IPv6 capable hosts\n::1 ip6-localhost ip6-loopback\nfe00::0 ip6-localnet\nff00::0 ip6-mcastprefix\nff02::1 ip6-allnodes\nff02::2 ip6-allrouters\n```\n\nWhay I'm doing wrong?\n\nUPD:\n`sudo netstat -nlp | grep 5672` returns: `tcp6 0 0 :::5672 :::* LISTEN 2106/beam.smp`\n\nFrom rabbitMQ logs:\n\n```\n=INFO REPORT==== 2-Jul-2013::16:05:11 ===\nstarted TCP Listener on [::]:5672\n\n=INFO REPORT==== 2-Jul-2013::16:05:11 ===\nServer startup complete; 0 plugins started.\n\n=INFO REPORT==== 2-Jul-2013::16:35:04 ===\naccepting AMQP connection (127.0.0.1:44112 -> 127.0.0.1:5672)\n\n=ERROR REPORT==== 2-Jul-2013::16:35:14 ===\nclosing AMQP connection (127.0.0.1:44112 -> 127.0.0.1:5672):\n{handshake_timeout,handshake}\n```\n\nI tried to change `localhost` to `ip6-localhost` and sometimes when try to starting consumer, it returns:\n\n```\n[PhpAmqpLib\\Exception\\AMQPRuntimeException] \nError Connecting to server(110): Connection timed out\n```\n\n**UPD2** If I start consumer with debug flag and `--env=prod` (`php .../app/console rabbitmq:consumer -w -d consumer_name`), consumer starts and working.\n\n========================================\n\nTop Answer:\nIf the necessary ports are not open on the rabbitmq server, you get this \"No route to host\" error when the client tries to connect. \n\nTo fix it, make sure the ports are open, if not, open them:\n\n```\nsudo iptables -I INPUT -p tcp --dport 5672 --syn -j ACCEPT\nsudo iptables -I INPUT -p tcp --dport 5673 --syn -j ACCEPT\nsudo iptables -I INPUT -p tcp --dport 15672 --syn -j ACCEPT\n```\n\nThis sets it on temporally. Set it permanently with your iptables. \n\n```\nsudo vi /etc/sysconfig/iptables\n```\n\nThen restart:\n\n```\nsudo service iptables restart\n```\n\n========================================\n\nCode:\n```text\n[PhpAmqpLib\\Exception\\AMQPRuntimeException] \nError Connecting to server(113): No route to host\n```\n\n```text\nStatus of node rabbit@ns1 ...\n[{pid,2106},\n {running_applications,[{rabbit,\"RabbitMQ\",\"3.1.3\"},\n {mnesia,\"MNESIA CXC 138 12\",\"4.5\"},\n {os_mon,\"CPO CXC 138 46\",\"2.2.7\"},\n {xmerl,\"XML parser\",\"1.2.10\"},\n {sasl,\"SASL CXC 138 11\",\"2.1.10\"},\n {stdlib,\"ERTS CXC 138 10\",\"1.17.5\"},\n {kernel,\"ERTS CXC 138 10\",\"2.14.5\"}]},\n {os,{unix,linux}},\n {erlang_version,\"Erlang R14B04 (erts-5.8.5) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:30] [kernel-poll:true]\\n\"},\n {memory,[{total,27728944},\n {connection_procs,2704},\n {queue_procs,5408},\n {plugins,0},\n {other_proc,9021680},\n {mnesia,60016},\n {mgmt_db,0},\n {msg_index,31144},\n {other_ets,770736},\n {binary,1968},\n {code,14560395},\n {atom,1356081},\n {other_system,1918812}]},\n {vm_memory_high_watermark,0.4},\n {vm_memory_limit,1262847590},\n {disk_free_limit,1000000000},\n {disk_free,214706556928},\n {file_descriptors,[{total_limit,924},\n {total_used,3},\n {sockets_limit,829},\n {sockets_used,1}]},\n {processes,[{limit,1048576},{used,125}]},\n {run_queue,0},\n {uptime,1265}]\n...done.\n```\n\n```text\nChain INPUT (policy ACCEPT)\ntarget prot opt source destination \n\nChain FORWARD (policy ACCEPT)\ntarget prot opt source destination \n\nChain OUTPUT (policy ACCEPT)\ntarget prot opt source destination\n```\n\n```text\n127.0.0.1 localhost\n{IP-ADDRESS} ns1.***.org ns1\n# The following lines are desirable for IPv6 capable hosts\n::1 ip6-localhost ip6-loopback\nfe00::0 ip6-localnet\nff00::0 ip6-mcastprefix\nff02::1 ip6-allnodes\nff02::2 ip6-allrouters\n```\n\n```text\n=INFO REPORT==== 2-Jul-2013::16:05:11 ===\nstarted TCP Listener on [::]:5672\n\n=INFO REPORT==== 2-Jul-2013::16:05:11 ===\nServer startup complete; 0 plugins started.\n\n=INFO REPORT==== 2-Jul-2013::16:35:04 ===\naccepting AMQP connection <0.1130.0> (127.0.0.1:44112 -> 127.0.0.1:5672)\n\n=ERROR REPORT==== 2-Jul-2013::16:35:14 ===\nclosing AMQP connection <0.1130.0> (127.0.0.1:44112 -> 127.0.0.1:5672):\n{handshake_timeout,handshake}\n```\n\n```text\n[PhpAmqpLib\\Exception\\AMQPRuntimeException] \nError Connecting to server(110): Connection timed out\n```\n\n```text\netc/hosts\n```\n\n```text\nsudo netstat -nlp | grep 5672\n```\n\n```text\ntcp6 0 0 :::5672 :::* LISTEN 2106/beam.smp\n```\n\n```text\nlocalhost\n```\n\n```text\nip6-localhost\n```\n\n```text\n--env=prod\n```\n\n```text\nphp .../app/console rabbitmq:consumer -w -d consumer_name\n```\n\n```text\nsudo iptables -I INPUT -p tcp --dport 5672 --syn -j ACCEPT\nsudo iptables -I INPUT -p tcp --dport 5673 --syn -j ACCEPT\nsudo iptables -I INPUT -p tcp --dport 15672 --syn -j ACCEPT\n```\n\n```text\nsudo vi /etc/sysconfig/iptables\n```\n\n```text\nsudo service iptables restart\n```\n\n========================================\n\nComments:\n- please, attach script source code you are trying to connect with\n- I'll try to start consumer from Symfony2 console by RabbitMQBundle with parameters of connection localhost:5672, vhost: /\n- Can you connect to web admin interface (if enabled) on port 15672 by default? Did you explicitly pass connection arguments or use default one?\n- I'll try to wget from console on server, and get ~$ wget localhost:15672 --2013-07-02 16:30:26-- localhost:15672 Resolving localhost (localhost)... 127.0.0.1 Connecting to localhost (localhost)|127.0.0.1|:15672... failed: Connection refused.\n- I use default connection arguments.\n- can you provide config and probably turn on webadmin panel just add this to your config: {rabbitmq_management, [{listener, [{port, 15672}]}]}\n- I turn on with sudo `rabbitmq-plugins enable rabbitmq_management`, but telnet localhost 15672 Trying 127.0.0.1... telnet: Unable to connect to remote host: Connection refused\n- hmmm, drop me a message in skype (same login), it's an interesting problem, stack-overflow doesn't like long discussions in comments\n- See more in depth answer to duplicate question here: stackoverflow.com/questions/21828937/…\n- See more in depth answer to this question here... stackoverflow.com/questions/21828937/…","metadata":{"transformedAt":"2026-08-18T18:33:20.199Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":16,"totalLines":279,"estimatedTokens":2005}}881{"id":"stack-30327670","source":"stackoverflow","questionId":30327670,"title":"RabbitMQ Queued messages keep increasing","tags":["python","rabbitmq","celery"],"text":"Title: RabbitMQ Queued messages keep increasing\nTags: python, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nWe have a Windows based Celery/RabbitMQ server that executes long-running python tasks out-of-process for our web application.\n\nWhat this does, for example, is take a CSV file and process each line. For every line it books one or more records in our database. \n\nThis seems to work fine, I can see the records being booked by the worker processes. However, when I check the rabbitMQ server with the management plugin (the web based management tool) I see the Queued messages increasing, and not coming back down.\n\nUnder connections I see 116 connections, about 10-15 per virtual host, all \"running\" but when I click through, most of them have 'idle' as State.\nI'm also wondering why these connections are still open, and if there is something I need to change to make them close themselves:\n\nUnder 'Queues' I can see more than 6200 items with state 'idle', and not decreasing.\n\nSo concretely I'm asking if these are normal statistics or if I should worry about the Queues increasing but not coming back down and the persistent connections that don't seem to close... \n\nOther than the rather concise help inside the management tool, I can't seem to find any information about what these stats mean and if they are good or bad.\n\nI'd also like to know why the messages are still visible in the queues, and why they are not removed, as the tasks seem t be completed just fine.\n\nAny help is appreciated.\n\n========================================\n\nTop Answer:\nIf you don't need the reliability then you can make your queues transient. \n\nhttp://celery.readthedocs.org/en/latest/userguide/optimizing.html#optimizing-transient-queues\n\n```\nCELERY_DEFAULT_DELIVERY_MODE = 'transient'\n```\n\n========================================\n\nCode:\n```text\nignore_result=True\n```\n\n```text\nignore_result=True\n```\n\n```text\nCELERY_DEFAULT_DELIVERY_MODE = 'transient'\n```\n\n========================================\n\nComments:\n- Are you sending an Ack back to acknowledge that the message has been handled? While the connections might stay around, I'd expect the queued messages to fall.\n- Hi @DavinTryon, The tasks are handled by Celery, which allows us to simply decorate a Python function with @@celery.task, I don't know how celery handles acknowledgements internally. However, when I run rabbitmqctl list_consumers, I get a consumer that has the acknowledgment required boolean set to False.\n- @DavinTryon; it seems that Celery's default is to acknowledge a task as soon as the worker picks it up: celery.readthedocs.org/en/latest/userguide/tasks.html\n- I'm okay with persistent messages, in fact, I'd perfer it over transient, and I'm not really sure how this would solve the problem; the messages seem to stay queued, making them transient would only cause the messages to be lost when there is a calamity.","metadata":{"transformedAt":"2026-08-18T18:33:20.199Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":57,"estimatedTokens":724}}882{"id":"stack-9369691","source":"stackoverflow","questionId":9369691,"title":"Multithreaded .NET RabbitMQ publisher","tags":["c#",".net","multithreading","rabbitmq"],"text":"Title: Multithreaded .NET RabbitMQ publisher\nTags: c#, .net, multithreading, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nWe have the following scenario using the .NET RabbitMQ library:\n\nA worker thread picks up 'request' messages from a queue and dispatches them on multiple worker threads for processing. When complete, each worker thread then sends another message. \n\nMy question is what 'pattern' do people recommend for the sender in order to get the best throughput and stability?. For example:\n\n1) A singleton 'publisher' instance that is accessed by all worker threads with a single Connection and IModel (using a 'lock' to synchronize access to the IModel)\n\n2) A singleton 'publisher' instance that is accessed by all worker threads with a single Connection and which creates a new IModel for each send request.\n\nor something else?\n\n========================================\n\nComments:\n- Sounds like a good problem for some trial and measurement. I suspect that there are too many variables here for anyone to be able to give you an answer that is best for your particular use case.\n- It is probably better have each worker thread pickup messages from the message queue instead of having a central process distribute the work to the worker threads. It is possible to accomplish what you are suggesting using a shared memory queue (there is a thread safe implementation in the RabbitMQ lib) where the main process can put work items and the worker threads pick them up.\n- Thx both.Chris: will do that, was really hoping for some other people's real world experiences.\n- Apologies - hit 'send' prematurely. Chris: will do that but was hoping for some other people's real world experiences of similar scenarios (it feels like it should be a common usage pattern). Yavor: we actually already have the solution you suggest (single consumer thread; shared memory queue; worker threads 'ack' messages on completion of processing). What I'm really interested in is the pattern for the sender.\n- Thanks - going to mark this an the accepted answer as there are some useful pointers in here. For the record, we are now looking at building an 'async' sender that uses a shared queue and internal thread to do the actual sending.","metadata":{"transformedAt":"2026-08-18T18:33:20.199Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":25,"estimatedTokens":556}}883{"id":"stack-9070167","source":"stackoverflow","questionId":9070167,"title":"Is there a JMS API/Client that works with all AMQP brokers?","tags":["jms","rabbitmq","amqp","qpid"],"text":"Title: Is there a JMS API/Client that works with all AMQP brokers?\nTags: jms, rabbitmq, amqp, qpid\nSource: Stack Overflow\n\nQuestion:\nThe JMS is the vendor neutral API to messaging in the Java space. AMQP's mission is \"to become the standard protocol for interoperability between all messaging middleware\". I'm looking for a JMS client implementation that is interoperable between AMQP vendors. Specifically, it would be nice if it could talk to either RabbitMQ or Qpid.\n\n========================================\n\nTop Answer:\nI have used Apache Qpid client library (qpid-client-0.32-bin.tar.gz) with RabbitMQ (AMQP 0-9-1) recently and It worked very well.\n\nIf you want to connect to AMQP 1.0 Broker you should use this Qpid lib (apache-qpid-jms-0.1.0-bin.tar.gz)\n\nBoth libs can be downloaded from here:\nhttp://qpid.apache.org/download.html\n\n========================================\n\nComments:\n- The accepted answer is old, now they do provide a 1.0 compatible client.","metadata":{"transformedAt":"2026-08-18T18:33:20.199Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":21,"estimatedTokens":242}}884{"id":"stack-54936932","source":"stackoverflow","questionId":54936932,"title":"Can I dynamically create RabbitMQ shovel from my NodeJS app?","tags":["node.js","rabbitmq","node-amqp","rabbitmq-shovel","node-amqplib"],"text":"Title: Can I dynamically create RabbitMQ shovel from my NodeJS app?\nTags: node.js, rabbitmq, node-amqp, rabbitmq-shovel, node-amqplib\nSource: Stack Overflow\n\nQuestion:\nRabbitMQ shovel plugin provides an HTTP API to create & configure shovels. Assuming that I have enabled shovel & shovel management plugin for my RabbitMQ server instance, can I dynamically create shovels from my NodeJS app? \n\nI currently use amqplib to connect to an exchange. https://www.squaremobius.net/amqp.node/channel_api.html\n\nHowever I don't see any API to dynamically create a shovel. Is this achievable or are there any other libraries that support this?\n\n========================================\n\nCode:\n```text\nvar http = require('http');\n\nvar rabbit_host = \"myrabbitmq.com\";\nvar token = Buffer.from(\"admin:admin_pwd\").toString('base64');\nvar shovel_name = \"my_shovel\";\n\nvar payload = {\n \"component\": \"shovel\",\n \"vhost\": \"/\",\n \"name\": \"my_shovel\",\n \"value\": {\n \"src-uri\": \"amqp://user1:pwd1@myrabbitmq.com\",\n \"src-exchange\": \"test\",\n \"dest-uri\": \"amqp://user2:pwd2@anotherbroker.com\",\n \"dest-exchange-key\": \"test2\",\n \"add-forward-headers\": false,\n \"ack-mode\": \"on-confirm\",\n \"delete-after\": \"never\"\n }\n};\n\nvar options = {\n \"host\": rabbit_host,\n \"port\": 15672,\n \"path\": \"/api/parameters/shovel/%2F/\" + shovel_name,\n \"method\": \"PUT\",\n \"headers\": { \n \"Authorization\" : \"Basic \" + token,\n \"Content-Type\" : \"application/json\",\n }\n}\n\nvar callback = function(response) {\n var str = ''\n response.on('data', function(chunk){\n str += chunk;\n });\n\n response.on('end', function(){\n console.log(\"end: response=\"+str);\n });\n}\n\nvar body = JSON.stringify(payload);\nhttp.request(options, callback).end(body).on('error', function(e) {\n console.log(\"error: \" + e.message);\n});\n```\n\n========================================\n\nComments:\n- github.com/rabbitmq/rabbitmq-shovel-management\n- Thanks! This was what I assumed I would have to do if amqp library did not provide an API for creating dynamic shovels. Wasn't sure if there's any other library that provided APIs for this. The example will definitely help me a lot when I implement dynamic shovels.","metadata":{"transformedAt":"2026-08-18T18:33:20.199Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":69,"estimatedTokens":555}}885{"id":"stack-66476115","source":"stackoverflow","questionId":66476115,"title":"RabbitMQ in NestJS, error on both Producer and Consumer","tags":["rabbitmq","nestjs"],"text":"Title: RabbitMQ in NestJS, error on both Producer and Consumer\nTags: rabbitmq, nestjs\nSource: Stack Overflow\n\nQuestion:\nI have the following app https://github.com/rengthp/nestjs-rabbitmq-microservice\n\nBut I get on Producer :\n\n[Nest] 6156 - 04/03/2021, 13:28:53 [ClientProxy] Disconnected from RMQ. Trying to reconnect. +25469ms\n[Nest] 6156 - 04/03/2021, 13:28:53 [ClientProxy] Object:\n\n```\n{\n \"err\": {\n \"code\": 406,\n \"classId\": 50,\n \"methodId\": 10\n }\n}\n +3ms\n```\n\nand on Consumer:\n\n```\n111ms\n[Nest] 1180 - 04/03/2021, 13:22:31 [Server] Disconnected from RMQ. Trying to reconnect. +1058ms\n[Nest] 1180 - 04/03/2021, 13:22:37 [Server] Disconnected from RMQ. Trying to reconnect. +6006ms\n[Nest] 1180 - 04/03/2021, 13:22:43 [Server] Disconnected from RMQ. Trying to reconnect. +6017ms\n[Nest] 1180 - 04/03/2021, 13:22:49 [Server] Disconnected from RMQ. Trying to reconnect. +6026ms\n```\n\nWhat could be wrong? the server is working...\n\n========================================\n\nTop Answer:\nThis error came up because you re-declare an existing queue with different parameters. The solution is simple. The option queue for both producers and consumers must be the same and all option parameters must be the same.\n\n========================================\n\nCode:\n```text\n{\n \"err\": {\n \"code\": 406,\n \"classId\": 50,\n \"methodId\": 10\n }\n}\n +3ms\n```\n\n```text\n111ms\n[Nest] 1180 - 04/03/2021, 13:22:31 [Server] Disconnected from RMQ. Trying to reconnect. +1058ms\n[Nest] 1180 - 04/03/2021, 13:22:37 [Server] Disconnected from RMQ. Trying to reconnect. +6006ms\n[Nest] 1180 - 04/03/2021, 13:22:43 [Server] Disconnected from RMQ. Trying to reconnect. +6017ms\n[Nest] 1180 - 04/03/2021, 13:22:49 [Server] Disconnected from RMQ. Trying to reconnect. +6026ms\n```\n\n```text\nasync onApplicationBootstrap() { await this._clientProxyUser.connect();}\n```\n\n========================================\n\nComments:\n- Hi @CarlosMagalhaes I'm facing the same issue, how did you solve it...?. I'm getting on client side.","metadata":{"transformedAt":"2026-08-18T18:33:20.199Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":70,"estimatedTokens":502}}886{"id":"stack-37532813","source":"stackoverflow","questionId":37532813,"title":"How to implement a RabbitMQ consumer using Pyspark Streaming module?","tags":["python","rabbitmq","pyspark","spark-streaming","pika"],"text":"Title: How to implement a RabbitMQ consumer using Pyspark Streaming module?\nTags: python, rabbitmq, pyspark, spark-streaming, pika\nSource: Stack Overflow\n\nQuestion:\nI have an Apache Spark cluster and a RabbitMQ broker and I want to consume messages and compute some metrics using the `pyspark.streaming` module.\n\nThe problem is I only found this package, but is implemented in *Java* and *Scala*. Besides that, I didn't find any example or bridge implementation in *Python*.\n\nI have a consumer implemented using Pika but I don't know how to pass the payload to my `StreamingContext`.\n\n========================================\n\nCode:\n```text\npyspark.streaming\n```\n\n```text\nStreamingContext\n```\n\n```text\nwith socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:\n s.bind((HOST, PORT))\n s.listen(1)\n conn, addr = s.accept()\n dispatcher = conn.sendall #assigning sendall to dispatcher variable\nconsumer = Consumer(dispatcher)\ntry:\n consumer.run()\nexcept Exception as e:\n consumer.stop()\n s.close()\n```\n\n```text\ndef __init__(self,dispatcher):\n self._connection = None\n self._channel = None\n self._closing = False\n self._consumer_tag = None\n self._url = amqp_url\n #new code\n self._dispatcher = dispatcher\n```\n\n```text\ndef on_message(self, unused_channel, basic_deliver, properties, body):\n self._channel.basic_ack(basic_deliver.delivery_tag)\n try:\n # we need an '\\n' at the each row Spark socketTextStream\n self._dispatcher(bytes(body.decode(\"utf-8\")+'\\n',\"utf-8\"))\n except Exception as e:\n raise\n```\n\n```text\nsocketTextStream\n```\n\n```text\n.py\n```\n\n```text\nConsumer\n```\n\n```text\nif __name__ == '__main__':\n```\n\n```text\nHOST\n```\n\n```text\nPORT\n```\n\n```text\nsendall\n```\n\n```text\nConsumer\n```\n\n```text\n__init__\n```\n\n```text\ndispatcher\n```\n\n```text\non_message\n```\n\n```text\nself._dispatcher\n```\n\n```text\nbody\n```\n\n```text\nssc.socketTextStream(HOST, int(PORT))\n```\n\n```text\nHOST\n```\n\n```text\nPORT\n```\n\n========================================\n\nComments:\n- Well, I just discover that Pyspark and RabbitMQ both speak **MQTT protocol**. This could be a solution, but they are some trade-offs and limitations\n- To use the MQTT protocol on the RabbitMQ cluster implies to change the queue configurations. For me this is not a solution. I found a way to solve it. Once I complete my tests I'll post a solution\n- Hey, any progress? I'm facing the same problem now. In my case I cannot even setup MQTT proof of concept.\n- Yes, it was easier than I thought. I send my messages from my pika consumer to spark using a **TCP connection**. I will post a formal answer in few hours\n- Thx! I'm stuck here: stackoverflow.com/questions/39331781/…\n- can you please provide me some guideline on how i can publish a message to rabbitmq using pyspark. To be specific I am using Azure Databricks and i am trying to publish a message to rabbitmq but couldn't figure out how I can achieve the same\n- Is there any requirements with the EXCHANGE and EXCHANGE_KEY arguments, or I can set it at will ? (EXCHANGE='', EXCHANGE_KEY='topic' ?)\n- `Channel 1 was closed: (Stream connection lost: TypeError('exchange must be a str or unicode str, but got >',))`. I got this error, my Rabbitmq connection parameters are as : EXCHANGE = 'message', EXCHANGE_TYPE = 'topic', QUEUE = 'item', ROUTING_KEY = 'item'. I have a queue running 'item' with routing_key 'item'. When I tried your solution the above error popped up. Please help !","metadata":{"transformedAt":"2026-08-18T18:33:20.199Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":21,"totalLines":132,"estimatedTokens":855}}887{"id":"stack-77436908","source":"stackoverflow","questionId":77436908,"title":"Strategies for Cancelling Long-Running Rayon Tasks in Rust via RabbitMQ","tags":["rust","rabbitmq","rust-tokio","rayon"],"text":"Title: Strategies for Cancelling Long-Running Rayon Tasks in Rust via RabbitMQ\nTags: rust, rabbitmq, rust-tokio, rayon\nSource: Stack Overflow\n\nQuestion:\nI'm developing an executor in Rust to handle compute-intensive tasks as part of a larger web application. The executor receives jobs from RabbitMQ (using lapin) and processes various CPU-bound operations, which include some that internally utilize rayon. I'm aware that async can complicate rayon's usage. Post-computation or task cancellation, it communicates results or cancellation status back to RabbitMQ.\n\nThe operations in question are out of my control, consisting mainly of long-running, parallel graph algorithms. I'm exploring strategies to cancel these tasks reactively through a separate RabbitMQ cancellation queue without rewriting the underlying libraries due to their (to my understanding) non-compatibility with async patterns and the general lack of built-in task cancellation support for safety reasons.\n\nI've prototyped an executor using tokio, only to recognize the potential issues with rayon after the fact. The current cancellation strategy is based on tokio oneshot channels, which inefficiently drop tasks without liberating CPU resources. I am looking for advice on crafting an idiomatic executor that enables effective task cancellation and conforms to Rust's safety guarantees.\n\n**Edit**: I‘ll try to be more specific: Essentially, I am looking for a strategy to cancel (long-running, *blocking*, CPU-bound) tasks from another thread, effectively aborting the computation and *freeing up the CPU*. Gracefully signaling shutdown using a mechanism such as tokio‘s oneshot channel is not an option since I don‘t have control over the implementation of the long running operation.\n\n========================================\n\nCode:\n```text\nasync\n```\n\n```text\nPoll::Pending\n```\n\n```text\npoll()\n```\n\n```text\npanic!()\n```\n\n```text\nrayon::join\n```\n\n```text\nThread.stop()\n```\n\n```text\nstd::thread::scope()\n```\n\n========================================\n\nComments:\n- I don't quite understand your question (please be more specific if you can), but if you want to cancel asynchronous tasks and are using `tokio`, then take a look at CancellationToken from the tokio-util crate.\n- Unfortunately, I am effectively using a CancellationToken right now. The problem is that the expensive operation does not yield the CPU in this case. My current cancellation strategy is very similar to this example. I have attempted to clarify the concrete problem on hand. Thank you for pointing out that the question was not specific enough!\n- AFAIK there is no way to cancel rayon tasks without modifying their code to include a graceful shutdown notification mechanism like a one-shot channel or an `AtomicBool`.\n- Not a rust expert but you can spawn processes and kill them for cancellation. It is easier to implement and safe for memory or cpu leaks\n- In general it's not possible to stop a thread without it's cooperation, much less stop a task running in a thread.","metadata":{"transformedAt":"2026-08-18T18:33:20.199Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":7,"totalLines":52,"estimatedTokens":755}}888{"id":"stack-47888730","source":"stackoverflow","questionId":47888730,"title":"Should I create a connection per thread?","tags":["java","multithreading","rabbitmq"],"text":"Title: Should I create a connection per thread?\nTags: java, multithreading, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm running 2 multi-threaded programs.\n\nEach thread from the first program acts as a producer and writes messages to a queue, whereas each thread from the second program acts as a consumer and reads messages from the same queue.\n\nIn both projects I created a connection factory like the following:\n\n```\nConnectionFactory factory = new ConnectionFactory();\nfactory.setHost(\"localhost\");\nfactory.setAutomaticRecoveryEnabled(true);\nfactory.setRequestedChannelMax(0);\nfactory.setUsername(\"user\");\nfactory.setPassword(\"password\");\n```\n\nHowever I'm not sure about the recommended approach for the next step.\n\nShould I create a new connection at the start of each thread like:\n\n```\nConnection connection = factory.newConnection();\n```\n\nAnd then for each request create a new channel like:\n\n```\nChannel channel = connection.createChannel();\n```\n\nOr should I create only a single connection, make the threads the same connection, and then create a new channel for every request.\n\nI know that the connection is a socket thread-safe connection and it should be created carefully. I'm just asking about whether there is a recommended approach to use in my program, because usually a documentation would contain a recommended way to handle connections and sockets, but I couldn't find such an answer in RabbitMQ's documentation.\n\n========================================\n\nTop Answer:\nAs described in documentation:\n\n- For Connection:\n\n Current implementations are thread-safe for code at the client API\n level, and in fact thread-safe internally except for code within RPC\n calls. \n https://www.rabbitmq.com/releases/rabbitmq-java-client/current-javadoc/com/rabbitmq/client/Connection.html\n\n- For Channel:\n\n As a rule of thumb, sharing Channel instances between threads is\n something to be avoided. Applications should prefer using a Channel\n per thread instead of sharing the same Channel across multiple\n threads. \n\n \n https://www.rabbitmq.com/api-guide.html section Channels and\n Concurrency Considerations (Thread Safety)\n\nSo, Connection is thread safe, Channel is not\n\n========================================\n\nCode:\n```text\nConnectionFactory factory = new ConnectionFactory();\nfactory.setHost(\"localhost\");\nfactory.setAutomaticRecoveryEnabled(true);\nfactory.setRequestedChannelMax(0);\nfactory.setUsername(\"user\");\nfactory.setPassword(\"password\");\n```\n\n```text\nConnection connection = factory.newConnection();\n```\n\n```text\nChannel channel = connection.createChannel();\n```\n\n========================================\n\nComments:\n- Please read Why is asking a question on “best practice” a bad thing? before attempting to ask more questions that are opinion based that invite argumentative discussion because they do not have a single agreed upon answer.\n- Usually I would read the documentation which would state what is the recommended approach. When I couldn't find such an answer I wrote a question to see if maybe there is a standard practice to do one of the 2 choices I presented. Anyways I will consider your comment the next time I write a question.\n- Re : Close votes - Rabbit's connection handling is somewhat different from many other TCP/IP based protocols, in that Rabbit explicitly multiplexes logical message transfer across a single TCP/IP connection, in order to reduce the overall number of connections to the server cluster, and thus has a documented preference for a single, long lived Connection per client process, meaning the answer is unlikely to be primarily opinion based.\n- Thanks for your reply. First, I'm publishing my messages to an Exchange, I just didn't mention it because I didn't want to make my question more complex. Second, In my situation threads are created once the program starts, and are not supposed to terminate unless the while program stops. Also, speed is a very important factor in my case. Does this change anything? I mean would it affect the overall efficiency if I created a connection per thread?\n- Great, re exchange (but you did mention `writes messages to a queue`). Although you could create a Connection per thread if each thread, it is common place just to create a single Connection (or abstraction) and then it, e.g. by registering it with an IoC container. Long lived producer threads isn't a problem - every time each needs to send a message, it will just create a channel off the Connection. Channels are cheap, so I don't think there's much benefit in 'long lived' channels.\n- I'm not planning to create a 'long lived' channels. In fact in both options I will create a 'short lived' channels. The difference is whether should I obtain this channel from a shared connection? or from a connection that is only dedicated to the corresponding thread? Will I gain any performance improvement from creating a connection per thread?\n- I can't find definitive literature on the performance benefits of multiple connections, but the general rule of thumb appears to be a single connection for most scenarios. You also need to weigh up the downside that on the server side, that additional connections will eat more server resources. If you have extreme load conditions, you might find that Rabbit is the wrong tool for the job, e.g. Apache Kafka might be better suited.\n- Thank you very much, I got everything I need now.\n- My question wasn't actually based on the idea whether a connection is thread safe or not, I already know the answer to this question. My concerns are about increasing the efficiency of my program.\n- Write test and check it. It is impossibe to answer without knowing your system parameters. And even if I know it, still writing perfomance test is preferrable way. Results should be close for small thead count, i think.","metadata":{"transformedAt":"2026-08-18T18:33:20.199Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":96,"estimatedTokens":1452}}889{"id":"stack-42969130","source":"stackoverflow","questionId":42969130,"title":"Group received messages in RabbitMQ, preferably using Spring AMQP?","tags":["java","spring","rabbitmq","spring-integration","spring-amqp"],"text":"Title: Group received messages in RabbitMQ, preferably using Spring AMQP?\nTags: java, spring, rabbitmq, spring-integration, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI'm receiving messages from a service (S) that publishes each individual property change to an entity as a separate message. A contrived example would be an entity like this:\n\n```\nPerson {\n id: 123\n name: \"Something\",\n address: {...}\n}\n```\n\nIf name and address are updated in the same transaction then (S) will publish two messages, `PersonNameCorrected` and `PersonMoved`. The problem is on the receiving side where I'm storing a projection of this `Person` entity and each property change causes a write to the database. So in this example there would be two writes to the database but if I could batch messages for a short period of time and group them by id then I would only have to make a single write to the database.\n\nHow does one typically handle this in RabbitMQ? Does Spring AMQP provide an easier abstraction?\n\nNote that I have looked briefly at prefetch but I'm not sure if this is the way to go. Also prefetch, if I understand it correctly, is per connection basis. I'm trying to achieve this on a *per-queue* basis, because if batching (and thus added latency) is the way to go I wouldn't like to add this latency to ALL queues consumed by my service (but only to those that need the \"group-by-id\" features).\n\n========================================\n\nTop Answer:\nThis is just plainly wrong to shift shortcoming of messaging system to software/service-side using Spring-Integration It is also not a case for Spring Integration nor any framework. It also does not scale well & is not fault-tolerant\n\nThe core of this issue is to separate routing messages from business logic/sending messages \n\nAFAIK only Kafka & Apache Artemis support JMSXGroup from JMS API looking at currently mature queue providers RabbitMQ does not have it but AMQP has is specified BUT again RabbitMq haven't ever implemented it despite of requests from community.\n\nThat single but also a very often and important case in enterprise architecture to ensure ordered sequential processing from many independent sources excludes RabbitMQ from further considerations as default messaging solution\n\n========================================\n\nCode:\n```text\nPerson {\n id: 123\n name: \"Something\",\n address: {...}\n}\n```\n\n```text\nPersonNameCorrected\n```\n\n```text\nPersonMoved\n```\n\n```text\nPerson\n```\n\n```text\n@SpringBootApplication\npublic class So42969130Application implements CommandLineRunner {\n\n public static void main(String[] args) {\n SpringApplication.run(So42969130Application.class, args)\n .close();\n }\n\n @Autowired\n private RabbitTemplate template;\n\n @Autowired\n private Handler handler;\n\n @Override\n public void run(String... args) throws Exception {\n this.template.convertAndSend(\"so9130\", new PersonNameChanged(123));\n this.template.convertAndSend(\"so9130\", new PersonMoved(123));\n this.handler.latch.await(10, TimeUnit.SECONDS);\n }\n\n @Bean\n public IntegrationFlow flow(ConnectionFactory connectionFactory) {\n return IntegrationFlows.from(Amqp.inboundAdapter(connectionFactory, \"so9130\")\n .messageConverter(converter()))\n .aggregate(a -> a\n .correlationExpression(\"payload.id\")\n .releaseExpression(\"false\") // open-ended release, timeout only\n .sendPartialResultOnExpiry(true)\n .groupTimeout(2000))\n .handle(handler())\n .get();\n }\n\n @Bean\n public Jackson2JsonMessageConverter converter() {\n return new Jackson2JsonMessageConverter();\n }\n\n @Bean\n public Handler handler() {\n return new Handler();\n }\n\n @Bean\n public Queue queue() {\n return new Queue(\"so9130\", false, false, true);\n }\n\n public static class Handler {\n\n private final CountDownLatch latch = new CountDownLatch(1);\n\n @ServiceActivator\n public void handle(Collection<?> aggregatedData) {\n System.out.println(aggregatedData);\n this.latch.countDown();\n }\n\n }\n\n public static class PersonNameChanged {\n\n private int id;\n\n PersonNameChanged() {\n }\n\n PersonNameChanged(int id) {\n this.id = id;\n }\n\n public int getId() {\n return this.id;\n }\n\n public void setId(int id) {\n this.id = id;\n }\n\n @Override\n public String toString() {\n return \"PersonNameChanged [id=\" + this.id + \"]\";\n }\n\n }\n\n public static class PersonMoved {\n\n private int id;\n\n PersonMoved() {\n }\n\n PersonMoved(int id) {\n this.id = id;\n }\n\n public int getId() {\n return this.id;\n }\n\n public void setId(int id) {\n this.id = id;\n }\n\n @Override\n public String toString() {\n return \"PersonMoved [id=\" + this.id + \"]\";\n }\n\n }\n\n}\n```\n\n```text\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n <modelVersion>4.0.0</modelVersion>\n\n <groupId>com.example</groupId>\n <artifactId>so42969130</artifactId>\n <version>2.0.0-BUILD-SNAPSHOT</version>\n <packaging>jar</packaging>\n\n <name>so42969130</name>\n <description>Demo project for Spring Boot</description>\n\n <parent>\n <groupId>org.springframework.boot</groupId>\n <artifactId>spring-boot-starter-parent</artifactId>\n <version>1.5.2.RELEASE</version>\n <relativePath/> <!-- lookup parent from repository -->\n </parent>\n\n <properties>\n <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>\n <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>\n <java.version>1.8</java.version>\n </properties>\n\n <dependencies>\n <dependency>\n <groupId>org.springframework.boot</groupId>\n <artifactId>spring-boot-starter-integration</artifactId>\n </dependency>\n\n <dependency>\n <groupId>org.springframework.integration</groupId>\n <artifactId>spring-integration-amqp</artifactId>\n </dependency>\n\n <dependency>\n <groupId>org.springframework.integration</groupId>\n <artifactId>spring-integration-java-dsl</artifactId>\n </dependency>\n\n <dependency>\n <groupId>org.springframework.boot</groupId>\n <artifactId>spring-boot-starter-test</artifactId>\n <scope>test</scope>\n </dependency>\n </dependencies>\n\n <build>\n <plugins>\n <plugin>\n <groupId>org.springframework.boot</groupId>\n <artifactId>spring-boot-maven-plugin</artifactId>\n </plugin>\n </plugins>\n </build>\n\n\n</project>\n```\n\n```text\n2017-03-23 09:56:57.501 INFO 75217 --- [ask-scheduler-2] .s.i.a.AbstractCorrelatingMessageHandler : \n Expiring MessageGroup with correlationKey[123]\n[PersonNameChanged [id=123], PersonMoved [id=123]]\n```\n\n========================================\n\nComments:\n- Thanks for the pointer to spring integration. If it's not too much to ask, would you happen to know of an example that I could use as a kick-starter for my use case?\n- I updated my answer with an example which should be enough to get you started.\n- I know that I should be brief on SO but must say that this is great, I couldn't have asked for a better answer, so thanks :).","metadata":{"transformedAt":"2026-08-18T18:33:20.199Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":247,"estimatedTokens":1945}}890{"id":"stack-20784052","source":"stackoverflow","questionId":20784052,"title":"List queues RabbitMQ using Ruby Bunny gem","tags":["ruby","rubygems","rabbitmq","amqp"],"text":"Title: List queues RabbitMQ using Ruby Bunny gem\nTags: ruby, rubygems, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nWasn't able to find any documentation on listing the names of the queues and their message counts on the RabbitMQ Bunny docs. I have been able to extract the names and counts using this commandline result if my rabbitmq-server is on the same server as the code\n\n`sudo /usr/sbin/rabbitmqctl list_queues`\n\nMy rabbitmq server would be running on a different server. Any help would be much appreciated.\n\n========================================\n\nCode:\n```text\nsudo /usr/sbin/rabbitmqctl list_queues\n```\n\n```text\nhttp://therabbitmqhost:15672/api/queues/\n```\n\n```text\nhttp://therabbitmqhost:15672/api/queues/thevhost/thequeuename\n```\n\n========================================\n\nComments:\n- Default http api port is 15672, not 55672, since 3.0","metadata":{"transformedAt":"2026-08-18T18:33:20.199Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":30,"estimatedTokens":214}}891{"id":"stack-26046053","source":"stackoverflow","questionId":26046053,"title":"RabbitMQ C# API: How to check if a binding exists?","tags":["c#",".net","rabbitmq","messaging"],"text":"Title: RabbitMQ C# API: How to check if a binding exists?\nTags: c#, .net, rabbitmq, messaging\nSource: Stack Overflow\n\nQuestion:\nUsing the RabbitMQ C# API, how would I check to see if a binding exists from a given queue to a given exchange? \n\nA lot of RabbitMQ calls are idempotent, so some people may say that the check is unnecessary for those cases, but I think they would be useful in testing.\n\n========================================\n\nCode:\n```text\nyour_server_name:15672/api/\n```\n\n```text\nGET\n```\n\n```text\n/api/exchanges/vhost\n```\n\n```text\n/name/bindings/destination\n```\n\n```text\n/api/bindings\n```\n\n========================================\n\nComments:\n- If amqp doesn't let you check this, you can use rabbit's rest api hg.rabbitmq.com/rabbitmq-management/raw-file/rabbitmq_v3_3_5‌​/… In particular, the `bindings` function returns a full list of existing bindings.\n- @WiktorZychla Thank you for the suggestion. I was hoping I could use the C# API to do it, but if that's not an option, I will try out your suggestion.\n- Not through the client API. But, maybe the management API: hg.rabbitmq.com/rabbitmq-management/raw-file/rabbitmq_v3_3_4‌​/…","metadata":{"transformedAt":"2026-08-18T18:33:20.199Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":38,"estimatedTokens":297}}892{"id":"stack-35148506","source":"stackoverflow","questionId":35148506,"title":"spring-amqp transaction semantics","tags":["java","spring","rabbitmq","spring-amqp"],"text":"Title: spring-amqp transaction semantics\nTags: java, spring, rabbitmq, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI am currently testing a rather simple example concerning messaging transactions in connection with database transactions with spring amqp.\n\nThe use case is as follows:\n\n- message is received\n\n- a message is sent\ndatabase is updated\n\n```\n@Transactional\npublic void handleMessage(EventPayload event) {\n MyEntity entity = new MyEntity();\n entity.setName(event.getName());\n\n rabbitTemplate.convertAndSend(\"myExchange\", \"payload.create\", payload);\n\n MyEntity savedEntity = entityRepository.save(entity);\n}\n```\n\nThe expected behavior in case of a failure during the database operation is that the received message is rolled back to the bus (DefaultRequeueRejected = false) and goes into a dead letter queue. Also the message sent should be rolled back.\n\nI can achieve this with the following configuration:\n\n```\n@Bean\npublic RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory, MessageConverter messageConverter) {\n RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);\n rabbitTemplate.setMessageConverter(messageConverter);\n rabbitTemplate.setChannelTransacted(true);\n return rabbitTemplate;\n}\n\n@Bean\n SimpleMessageListenerContainer subscriberListenerContainer(ConnectionFactory connectionFactory,\n MessageListenerAdapter listenerAdapter,\n PlatformTransactionManager transactionManager) {\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(connectionFactory);\n container.setQueueNames(SUBSCRIBER_QUEUE_NAME);\n container.setMessageListener(listenerAdapter);\n container.setChannelTransacted(true);\n container.setTransactionManager(transactionManager);\n container.setDefaultRequeueRejected(false);\n return container;\n }\n```\n\nSo this works fine - what I do not understand is that the observed behavior is exactly the same if I do not set the transaction manager on the `SimpleMessageListenerContainer`. So if I configure the following the bebavior does not change:\n\n```\n@Bean\n SimpleMessageListenerContainer subscriberListenerContainer(ConnectionFactory connectionFactory,\n MessageListenerAdapter listenerAdapter) {\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(connectionFactory);\n container.setQueueNames(SUBSCRIBER_QUEUE_NAME);\n container.setMessageListener(listenerAdapter);\n container.setDefaultRequeueRejected(false);\n return container;\n }\n```\n\nCan someone explain what is happening there? Why is the second case also working? What is different internally if the `PlatformTransactionManager` is registered on the `SimpleMessageListenerContainer`.\n\n========================================\n\nCode:\n```text\n@Transactional\npublic void handleMessage(EventPayload event) {\n MyEntity entity = new MyEntity();\n entity.setName(event.getName());\n\n rabbitTemplate.convertAndSend(\"myExchange\", \"payload.create\", payload);\n\n MyEntity savedEntity = entityRepository.save(entity);\n}\n```\n\n```text\n@Bean\npublic RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory, MessageConverter messageConverter) {\n RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);\n rabbitTemplate.setMessageConverter(messageConverter);\n rabbitTemplate.setChannelTransacted(true);\n return rabbitTemplate;\n}\n\n@Bean\n SimpleMessageListenerContainer subscriberListenerContainer(ConnectionFactory connectionFactory,\n MessageListenerAdapter listenerAdapter,\n PlatformTransactionManager transactionManager) {\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(connectionFactory);\n container.setQueueNames(SUBSCRIBER_QUEUE_NAME);\n container.setMessageListener(listenerAdapter);\n container.setChannelTransacted(true);\n container.setTransactionManager(transactionManager);\n container.setDefaultRequeueRejected(false);\n return container;\n }\n```\n\n```text\n@Bean\n SimpleMessageListenerContainer subscriberListenerContainer(ConnectionFactory connectionFactory,\n MessageListenerAdapter listenerAdapter) {\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(connectionFactory);\n container.setQueueNames(SUBSCRIBER_QUEUE_NAME);\n container.setMessageListener(listenerAdapter);\n container.setDefaultRequeueRejected(false);\n return container;\n }\n```\n\n```text\nSimpleMessageListenerContainer\n```\n\n```text\nPlatformTransactionManager\n```\n\n```text\nSimpleMessageListenerContainer\n```\n\n```text\ntransactionManager\n```\n\n```text\n@Transactional\n```\n\n========================================\n\nComments:\n- Thanks a lot for the clarification. Regarding your last sentence in the answer. What can actually go wrong between db commit and the rabbit ack?\n- Since there's only framework code there will be no code failures in that time. However, if, say, the connection to rabbitmq is lost, before the ack is sent, your rabbit template operation will roll back and the message will be requeued, but your DB transaction is committed. This applies in the other scenario too, so you should always have code to handle duplicate deliveries.","metadata":{"transformedAt":"2026-08-18T18:33:20.199Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":148,"estimatedTokens":1385}}893{"id":"stack-19793839","source":"stackoverflow","questionId":19793839,"title":"Manage RabbitMQ consumers","tags":["symfony","rabbitmq"],"text":"Title: Manage RabbitMQ consumers\nTags: symfony, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am planning to write a log processing application using RabbitMQ, Symfony2 and the RabbitMqBundle.\nThe tool I am working on has to be highly available and must process millions of entries per day, so it's important that the consumers are always up and running (short breaks are fine), otherwise my queue might overflow after a while.\n\nAre there best practices on how to manage the consumers (written in PHP), start/restart them in case of an error etc?\n\nThanks\n\n========================================\n\nTop Answer:\n### Stop consumer\n\nTo stop your consumer with name `my_consumer` use\n\n```\nkill `ps aux | less | grep 'rabbitmq:consumer my_consumer' | grep -v grep | awk '{print $2}'`\n```\n\n- `ps aux | less | grep 'rabbitmq:consumer my_consumer'` - will find all running processes of the consumer\n\n- `grep -v grep` - will exclude your own search process\n\n- `awk '{print $2}'` - get only process id from the row\n\n- `kill` - will terminate all found processes\n\n### Start consumer\n\nTo start your consumer with name `my_consumer` use\n\n```\nnohup /usr/bin/env php app/console rabbitmq:consumer consumer --env=prod &\n```\n\nI have a lot of consumers in the project and it became hard to restart them after deploy. And I started using Capistrano + Symfony plugin to deploy my project. I wrote a few custom tasks to start/stop/restart the consumers based on the yaml config. Tasks are based on the commands from above.\n\n========================================\n\nCode:\n```text\n#!/bin/bash\n\nNB_TASKS=1\nSYMFONY_ENV=\"prod\"\n\nTEXT[0]=\"app/console rabbitmq:consumer primary\"\nTEXT[1]=\"app/console rabbitmq:consumer secondary\"\n\nfor text in \"${TEXT[@]}\"\ndo\n\nNB_LAUNCHED=$(ps ax | grep \"$text\" | grep -v grep | wc -l)\n\nTASK=\"/usr/bin/env php ${text} --env=${SYMFONY_ENV}\"\n\nfor (( i=${NB_LAUNCHED}; i<${NB_TASKS}; i++ ))\ndo\n echo \"$(date +%c) - Launching a new consumer\"\n nohup $TASK &\ndone\n\ndone\n```\n\n```text\nkill `ps aux | less | grep 'rabbitmq:consumer my_consumer' | grep -v grep | awk '{print $2}'`\n```\n\n```text\nnohup /usr/bin/env php app/console rabbitmq:consumer consumer --env=prod &\n```\n\n```text\nmy_consumer\n```\n\n```text\nps aux | less | grep 'rabbitmq:consumer my_consumer'\n```\n\n```text\ngrep -v grep\n```\n\n```text\nawk '{print $2}'\n```\n\n```text\nkill\n```\n\n```text\nmy_consumer\n```\n\n========================================\n\nComments:\n- If i see correctly, the script only starts the consumers, but it does not handle the case of a dead consumer, it does not respawn it.\n- For this I set a cron task to run this script every minute to make sure it always work.\n- I also gave supervisord a try, it looks pretty well, it respawns the rabbitmq consumers in case they die etc. edvanbeinum.com/how-to-install-and-configure-supervisord\n- Sure, there are plenty of such tools (`god` is another one). I think I answered your initial question, so I would appreciate if you choose it as best answer. :)\n- @AntonBabenko, do you have any similar solution for windows?\n- Sorry, there is no windows in my life :)\n- I also use supervisord and it works great for restarting crashed workers automatically.","metadata":{"transformedAt":"2026-08-18T18:33:20.200Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":111,"estimatedTokens":791}}894{"id":"stack-21828937","source":"stackoverflow","questionId":21828937,"title":"PHP Client can't connect to RabbitMQ server on localhost","tags":["php","rabbitmq"],"text":"Title: PHP Client can't connect to RabbitMQ server on localhost\nTags: php, rabbitmq\nSource: Stack Overflow\n\nQuestion:\n**OS**: CentOS 6.4\n\nI am trying to connect to the RabitMQ server using the php client as follows,\n\n```\n$connection = new AMQPConnection('10.1.150.109', 5672, 'guest', 'guest');\n$channel = $connection->channel();\n```\n\nBut when I ran the script from the browser, it gives me this,\n\nexception 'PhpAmqpLib\\Exception\\AMQPRuntimeException' with message 'Error Connecting to server(13): Permission denied ' in /var/www/html/event/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:27\n\nnetstat show this,\n\n tcp 0 0 :::5672 :::* LISTEN 10776/beam\n\nIn this post, this guy gives the answer implicitly, Client can't connect to RabbitMQ server on localhost. But he has not described the procedure which he followed to fix the issue.\n\nI thank you in advanced for anyone who can help me in this regard.\n\n========================================\n\nTop Answer:\nSince I don't like the accepted answer, here's one I think is better.\n\nDisabling SELinux is a hack. It may work but it's probably not a good idea. What isn't immediately obvious from the question (or the other question it references) is HOW the php client is being run. I.e. from the command line or via a browser. \n\nSELinux by default won't allow httpd (i.e. apache) to connect to port 5672.\n\nIn my case, running the php script from the command line works - the connection is accepted. However, running it from a browser fails because of this SELinux policy.\n\nI imagine that \"reconfiguring the listen address from 0.0.0.0 to 127.0.0.1\" is a reference to the hostname parameter, which in my case is set to \"localhost\" rather than an explicit IP address. (For sure 0.0.0.0 is going to fail!)\n\nYou can enable httpd to access port 5672 in SELinux: https://serverfault.com/questions/563872/selinux-allow-httpd-to-connect-to-a-specific-port\n\n========================================\n\nCode:\n```text\n$connection = new AMQPConnection('10.1.150.109', 5672, 'guest', 'guest');\n$channel = $connection->channel();\n```\n\n```text\ntelnet 10.1.150.109 5672\n```\n\n========================================\n\nComments:\n- thank you for you time, but it says: Connection closed by foreign host. Is this a permission issue with the webserver(apache) as if I run the php script in command line, it works perfectly by pushing the message to the server. (php /var/www/html/event/send.php [x] Sent 'Hello World!')\n- ok, apparently you can connect to the server, the guy says on the post you linked: \"Problem was fixed with reconfiguring listen address form 0.0.0.0:5672 to 127.0.0.1:5672 and small security fixes in OS.\"\n- I was digging more into the server and managed to fix the problem by disabling selinux ($ echo 0 > /selinux/enforce). Thank you again for your time.\n- great, glad you sorted it out. bye\n- I don't see how a question can be accepted as an answer. I'm suffering from the same problem and this has left me none the wiser as to a solution. Just noticed that the person who wrote this question is complaining of exactly what I'm complaining of - no actual answer to the question... yet he accepts a solution that doesn't answer the question. Oh dear.\n- I'll rephrase for you: what happens if you telnet 10.1.150.109 5672\n- Yes, this should have been a comment and not an answer.","metadata":{"transformedAt":"2026-08-18T18:33:20.200Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":63,"estimatedTokens":835}}895{"id":"stack-26314061","source":"stackoverflow","questionId":26314061,"title":"Could one connection support multiple channels in go api for rabbitmq?","tags":["go","rabbitmq","amqp"],"text":"Title: Could one connection support multiple channels in go api for rabbitmq?\nTags: go, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\n```\npackage main\n\nimport (\n\"fmt\"\n\"github.com/streadway/amqp\"\n\"time\"\n)\n\n// Every connection should declare the topology they expect\nfunc setup(url, queue string) (*amqp.Connection, *amqp.Channel, error) {\n //setup connection\n conn, err := amqp.Dial(url)\n if err != nil {\n return nil, nil, err\n }\n //build channel in the connection\n ch, err := conn.Channel()\n if err != nil {\n return nil, nil, err\n }\n //queue declare\n if _, err := ch.QueueDeclare(queue, false, true, false, false, nil); err != nil {\n return nil, nil, err\n }\n\n return conn, ch, nil\n}\n\nfunc main() {\n //amqp url\n url := \"amqp://guest:guest@127.0.0.1:5672\";\n for i := 1; i I thought there is only one connection between the program and mq-server,\n\nbut there are two connection,one connection can only support one channel,why?\n\ncan't the two goroutine the same tcp connection?\n\nSocket descriptor can in all threads of a process in the theory.\n\nWhy the two goroutine don't one socket but have their own channel?\n\nThe model by hand:\n\nThe real model in rabbitmq:\n\n========================================\n\nCode:\n```text\npackage main\n\nimport (\n\"fmt\"\n\"github.com/streadway/amqp\"\n\"time\"\n)\n\n// Every connection should declare the topology they expect\nfunc setup(url, queue string) (*amqp.Connection, *amqp.Channel, error) {\n //setup connection\n conn, err := amqp.Dial(url)\n if err != nil {\n return nil, nil, err\n }\n //build channel in the connection\n ch, err := conn.Channel()\n if err != nil {\n return nil, nil, err\n }\n //queue declare\n if _, err := ch.QueueDeclare(queue, false, true, false, false, nil); err != nil {\n return nil, nil, err\n }\n\n return conn, ch, nil\n}\n\nfunc main() {\n //amqp url\n url := \"amqp://guest:guest@127.0.0.1:5672\";\n for i := 1; i <= 2; i++ {\n fmt.Println(\"connect \", i)\n //two goroutine \n go func() {\n //queue name\n queue := fmt.Sprintf(\"example.reconnect.%d\", i)\n //setup channel in the tcp connection\n _, pub, err := setup(url, queue)\n if err != nil {\n fmt.Println(\"err publisher setup:\", err)\n return\n }\n // Purge the queue from the publisher side to establish initial state\n if _, err := pub.QueuePurge(queue, false); err != nil {\n fmt.Println(\"err purge:\", err)\n return\n }\n //publish msg\n if err := pub.Publish(\"\", queue, false, false, amqp.Publishing{\n Body: []byte(fmt.Sprintf(\"%d\", i)),\n }); err != nil {\n fmt.Println(\"err publish:\", err)\n return\n }\n //keep running\n for{\n time.Sleep(time.Second * 20)\n }\n }()\n }\n //keep running\n for {\n time.Sleep(time.Second * 20)\n }\n}\n```\n\n```text\npackage main\n\nimport (\n \"fmt\"\n \"github.com/streadway/amqp\"\n \"os\"\n)\n\nfunc main() {\n conn, err := amqp.Dial(\"amqp://localhost\")\n e(err)\n defer conn.Close()\n fmt.Println(\"Connected\")\n rec, err := conn.Channel()\n e(err)\n\n fmt.Println(\"Setup receiver\")\n rq, err := rec.QueueDeclare(\"go-test\", false, false, false, false, nil)\n e(err)\n msgs, err := rec.Consume(rq.Name, \"\", true, false, false, false, nil)\n e(err)\n\n fmt.Println(\"Setup sender\")\n send, err := conn.Channel()\n e(err)\n sq, err := send.QueueDeclare(\"go-test\", false, false, false, false, nil)\n e(err)\n\n fmt.Println(\"Send message\")\n err = send.Publish(\"\", sq.Name, false, false, amqp.Publishing{\n ContentType: \"text/plain\",\n Body: []byte(\"This is a test\"),\n })\n e(err)\n\n msg := <-msgs\n fmt.Println(\"Received from:\", rq, \"msg:\", string(msg.Body))\n}\n\nfunc e(err error) {\n if err != nil {\n fmt.Println(err)\n os.Exit(1)\n }\n}\n```\n\n```text\n$ go run rmq.go \nConnected\nSetup receiver\nSetup sender\nSend message\nReceived from: {go-test 0 0} msg: This is a test\n```\n\n========================================\n\nComments:\n- one connection if in same goroutine. two connection if in two goroutine.I don't know why? @DavidB\n- It looks like Connection and Channel are thread safe, are you sure you can't use Connection from multiple goroutines? (once again, I haven't actually tried it myself)\n- I want to express is that How many goroutines have called amqp.Dial() deciding the number of tcp connection,the main I want to know is why design like this?Your example is only the main thread call amqp.Dial(),so there is 1 tcp connection.My example there 2 threads call amqp.Dial(),so there is 2 tcp connection.I'm sorry that I didn't express my problem clearly? But your example show that channels can one connection. @DavidB\n- I'd recommend using `panicf` instead of `os.Exit`. Otherwise, the deferred functions won't be run, which leads to an unsafe exit.","metadata":{"transformedAt":"2026-08-18T18:33:20.200Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":187,"estimatedTokens":1259}}896{"id":"stack-28027625","source":"stackoverflow","questionId":28027625,"title":"RabbitMQ with Spring redelivering message forever","tags":["spring","rabbitmq","amqp"],"text":"Title: RabbitMQ with Spring redelivering message forever\nTags: spring, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI'm using Spring with RabbitMQ and I'm trying to avoid the message redelivery in case of a runtime exception occurs. I've tried to set the `requeue-reject` to `false` in `listener-container` and configure a custom error handler that throws an `AmqpRejectAndDontRequeueException`. It seems that both of strategies failed and the message continue redelivery forever. Any ideas of the reason?\n\nThank's for help.\n\n```\n\n \n\n \n\n \n\n \n \n\n \n \n \n \n\n \n\n \n \n\n```\n\n========================================\n\nTop Answer:\nThank you very much for your answer. I made some other testes and now I have the expected behaviour with the same configuration (removed errorHandle).\n\nFYK, in one of my tests I've detected an scenario that redelivery occurs and it may be something related to what you said:\n\nFlow: `Listener` -> `Facade` -> `Service`. All transactional.\n\nIf `Service` throws a `RuntimeException` and I caught in `Facade` and don't rethrow (swallow the exception), the message is redelivered. Looks like the tx is rollbacked even I swallow the exception and the message is redelivered - ignoring the `requeue-rejected` property.\n\nThank you again.\n\n========================================\n\nCode:\n```text\n<beans xmlns=\"http://www.springframework.org/schema/beans\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:rabbit=\"http://www.springframework.org/schema/rabbit\" xsi:schemaLocation=\" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.1.xsd\">\n\n <rabbit:connection-factory id=\"rabbitMQConnectionFactory\" host=\"localhost\" port=\"5672\" username=\"guest\" password=\"guest\" />\n\n <rabbit:admin connection-factory=\"rabbitMQConnectionFactory\" />\n\n <rabbit:template id=\"amqpTemplate\" connection-factory=\"rabbitMQConnectionFactory\" />\n\n <rabbit:queue name=\"q1\" />\n <rabbit:queue name=\"q2\" />\n\n <rabbit:listener-container error-handler=\"errorHandler\" connection-factory=\"rabbitMQConnectionFactory\" concurrency=\"10\" transaction-manager=\"transactionManager\" requeue-rejected=\"false\">\n <rabbit:listener ref=\"q1Listener\" method=\"consumeMessage\" queue-names=\"q1\" />\n <rabbit:listener ref=\"q2Listener\" method=\"consumeMessage\" queue-names=\"q2\" />\n </rabbit:listener-container>\n\n <bean id=\"errorHandler\" class=\"ErrorHandler\" />\n\n <bean id=\"q1Listener\" class=\"Q1MessageConsumerBean\" />\n <bean id=\"q2Listener\" class=\"Q2MessageConsumerBean\" />\n</beans>\n```\n\n```text\nrequeue-reject\n```\n\n```text\nfalse\n```\n\n```text\nlistener-container\n```\n\n```text\nAmqpRejectAndDontRequeueException\n```\n\n```text\n<rabbit:connection-factory id=\"connectionFactory\" host=\"localhost\" />\n\n<rabbit:template id=\"amqpTemplate\" connection-factory=\"connectionFactory\"\n exchange=\"foo\" routing-key=\"foo\" />\n\n<rabbit:admin connection-factory=\"connectionFactory\" />\n\n<rabbit:queue name=\"foo\" />\n\n<rabbit:direct-exchange name=\"foo\">\n <rabbit:bindings>\n <rabbit:binding queue=\"foo\" key=\"foo\" />\n </rabbit:bindings>\n</rabbit:direct-exchange>\n\n<rabbit:listener-container connection-factory=\"connectionFactory\" auto-startup=\"false\" requeue-rejected=\"false\">\n <rabbit:listener ref=\"listener\" queue-names=\"foo\" />\n</rabbit:listener-container>\n\n<bean id=\"listener\" class=\"org.mockito.Mockito\" factory-method=\"spy\">\n <constructor-arg>\n <bean class=\"org.springframework.amqp.rabbit.listener.RejectedTests$ThrowListener\" />\n </constructor-arg>\n</bean>\n```\n\n```text\n@Autowired\nprivate RabbitTemplate rabbitTemplate;\n\n@Autowired\nprivate SimpleMessageListenerContainer container;\n\n@Autowired\nprivate ThrowListener throwListener;\n\n@Test\npublic void test() throws Exception {\n rabbitTemplate.convertAndSend(\"foo\");\n container.start();\n Thread.sleep(2000);\n Mockito.verify(throwListener).onMessage(Mockito.any(Message.class));\n}\n\npublic static class ThrowListener implements MessageListener {\n\n @Override\n public void onMessage(Message message) {\n throw new RuntimeException(\"intentional reject\");\n }\n\n}\n```\n\n```text\nfor (Long deliveryTag : deliveryTags.get(channel)) {\n try {\n channel.basicReject(deliveryTag, true);\n } catch (IOException ex) {\n throw new AmqpIOException(ex);\n }\n}\n```\n\n```text\nprivate boolean doReceiveAndExecute(BlockingQueueConsumer consumer) throws Throwable {\n\n Channel channel = consumer.getChannel();\n\n for (int i = 0; i < txSize; i++) {\n\n logger.trace(\"Waiting for message from consumer.\");\n Message message = consumer.nextMessage(receiveTimeout);\n if (message == null) {\n break;\n }\n try {\n executeListener(channel, message);\n }\n catch (ImmediateAcknowledgeAmqpException e) {\n break;\n }\n catch (Throwable ex) {\n consumer.rollbackOnExceptionIfNecessary(ex);\n throw ex;\n }\n\n }\n\n return consumer.commitIfNecessary(isChannelLocallyTransacted(channel));\n```\n\n```text\nrequeue-rejected=\"false\"\n```\n\n```text\nAmqpRejectAndDontRequeueException\n```\n\n```text\nRuntimeException\n```\n\n```text\nrequeue-rejected=\"false\"\n```\n\n```text\nMockito.verify(throwListener).onMessage(Mockito.any(Message.class));\n```\n\n```text\nonMessage\n```\n\n```text\nrequeue-rejected=\"false\"\n```\n\n```text\nRabbitResourceHolder#rollbackAll()\n```\n\n```text\nconsumer.rollbackOnExceptionIfNecessary(ex);\n```\n\n```text\nListener\n```\n\n```text\nFacade\n```\n\n```text\nService\n```\n\n```text\nService\n```\n\n```text\nRuntimeException\n```\n\n```text\nFacade\n```\n\n```text\nrequeue-rejected\n```\n\n========================================\n\nComments:\n- You need to \"Nack\" the message in order to remove it from the queue and mark it as a failure.\n- Hi, can you give an example code of errorHandler bean ?\n- So, can we get a hook of the transaction rollback so that message can be rejected without requeue ?","metadata":{"transformedAt":"2026-08-18T18:33:20.200Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":25,"totalLines":251,"estimatedTokens":1505}}897{"id":"stack-13144761","source":"stackoverflow","questionId":13144761,"title":"RabbitMQ connection dropped automatically after long idle time","tags":["rabbitmq"],"text":"Title: RabbitMQ connection dropped automatically after long idle time\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am using the .net client for connecting to RabbitMQ server running HA mode, and all queues are with the following configuration.\n\n**Queue are with the following configuration**\n\n- QueueName = \"\"; // auto generated\n\n- Exclusive = false;\n\n- AutoDelete = true;\n\n- Durable = false\n\n- Argumenets==> x-ha-policy, all (for HA server mode)\n\nI am seeing this behaviour that after the process is idled for a long time say 10 mins ish, the connection started to drop hence the queue gets deleted automatically.\n\nIs there an idle setting or timeout setting? or what are the possible reason for the connection to close automatically in RabbitMQ .net client.\n\n========================================\n\nComments:\n- I do not understand the combination of HA queues with autodelete. HA is so you can survive crashes, power outages etc which would mean there would be periods of no consumers since your apps would have to reconnect meaning the queues would be deleted.\n- Regardless of the above - have you tried setting the RequestedHeartbeat on the connection factory? See if your connections idle with this setting turned o say to 60 seconds.\n- this is just one usage of the RMQ, and maybe it was a bit misleading, not all queues are with autodelete set to true.\n- yes i did resolve the issue with setting the requestedhearbeat. thanks. The issue was caused by the load balanced dropping idle connection after 5 mins.","metadata":{"transformedAt":"2026-08-18T18:33:20.200Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":30,"estimatedTokens":381}}898{"id":"stack-31696841","source":"stackoverflow","questionId":31696841,"title":"How to inject a producer as a service into a RabbitMQBundle consumer?","tags":["php","symfony","rabbitmq"],"text":"Title: How to inject a producer as a service into a RabbitMQBundle consumer?\nTags: php, symfony, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have to modify a php system developed with Symfony and RabbitMQ as a queing system. I'm not directly using the RabbitMQ bindings with PHP, but the RabbitMQBundle for Symfony.\n\nMy problem is that I don't know how to publish a message from a consumer. Yes, I know, a consumer is designed to consume messages, not to publish messages. But I have a multi-step workflow, and I need to publish new messages after some previous messages are processed.\n\nThe \"magic\" of Symfony is making me impossible to discovering how is wired everything. I've been reading about services, but as far as I know, the \"producers\" aren't declared as services anywhere, and in my particular case I'm not using specific classes for everyone, but only binding a name to a RabbitMq exchange.\n\nIn my controllers is easy to call those producers, I only have to type something like\n\n```\n$this->get('old_sound_rabbit_mq.my_own_producer')->publish($whatever);\n```\n\nbut in consumers I have to explicitly inject every dependency, and I don't know how to inject the producer.\n\nThe declaration of my producer in the rabbitmqbundle settings is something like this:\n\n```\nmy_own:\n connection: default\n exchange_options: {name: 'my-own-channel', type: direct}\n```\n\nThe declaration of my consumer service in the services.yml file is something like:\n\n```\nmy_own_service:\n class: MyOwnBundleBundle\\Consumers\\MyOwnConsumer\n arguments: [\"@logger\", \"@doctrine_mongodb\", \"%variable1%\", \"%variable2%\"]\n tags:\n - { name: monolog.logger, channel: my_own_channel }\n```\n\nThank you for your time.\n\n========================================\n\nCode:\n```text\n$this->get('old_sound_rabbit_mq.my_own_producer')->publish($whatever);\n```\n\n```text\nmy_own:\n connection: default\n exchange_options: {name: 'my-own-channel', type: direct}\n```\n\n```text\nmy_own_service:\n class: MyOwnBundleBundle\\Consumers\\MyOwnConsumer\n arguments: [\"@logger\", \"@doctrine_mongodb\", \"%variable1%\", \"%variable2%\"]\n tags:\n - { name: monolog.logger, channel: my_own_channel }\n```\n\n```text\nmy_own_service:\n class: MyOwnBundleBundle\\Consumers\\MyOwnConsumer\n arguments: [\"@logger\", \"@doctrine_mongodb\", \"%variable1%\", \"%variable2%\", \"@old_sound_rabbit_mq.another_producer\"]\n tags:\n - { name: monolog.logger, channel: my_own_channel }\n```\n\n```text\nprotected $producer;\n\npublic function __construct($logger, $doctrine, $var1,$var2, $producer)\n{\n ...\n $this->producer=$producer;\n}\n```\n\n```text\npublic function execute(AMQPMessage $msg)\n {\n ....\n $mesassage = ....\n\n $this->producer-> publish($message);\n\n }\n```\n\n========================================\n\nComments:\n- XML service config example: and don't forget you can type-hint the dependency in your consumer class class SomeConsumerClass { public function __construct(ProducerInterface $producerService) {","metadata":{"transformedAt":"2026-08-18T18:33:20.200Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":93,"estimatedTokens":746}}899{"id":"stack-12508553","source":"stackoverflow","questionId":12508553,"title":"correlationId and temporary queues in RPC model - AMQP","tags":["rabbitmq","rpc","amqp"],"text":"Title: correlationId and temporary queues in RPC model - AMQP\nTags: rabbitmq, rpc, amqp\nSource: Stack Overflow\n\nQuestion:\nI was reading RPC-Model in AMQP with RabbitMQ. The tutorial creates a temporary queue and also `correlationId`. Temporary queues are unique, so why should we need correlationId? I'm a JMS guy, in JMS we do request/response in two ways:\n\ncreate temporary queue for each request/response\n\ncreate one response queue and use `correlationId` and message selector.\n\ncan someone explain why do we need both temporary queue and `correlationId` in AMQP RPC model? It seems AMQP does not have something like message selector. Am I right?\n\n========================================\n\nCode:\n```text\ncorrelationId\n```\n\n```text\ncorrelationId\n```\n\n```text\ncorrelationId\n```\n\n========================================\n\nComments:\n- How is discarding non-matched messages safe? What about the requestor that was expecting that response? The message is now lost because something else consumed it from the queue and threw it away. This could happen if your client is a web server and spreads parallel requests across threads. How can you guarantee that the messages aren't lost by consumers discarding in that scenario?","metadata":{"transformedAt":"2026-08-18T18:33:20.200Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":32,"estimatedTokens":305}}900{"id":"stack-29397489","source":"stackoverflow","questionId":29397489,"title":"How to attach erlang dbg to a running process?","tags":["debugging","erlang","rabbitmq","rabbitmq-exchange"],"text":"Title: How to attach erlang dbg to a running process?\nTags: debugging, erlang, rabbitmq, rabbitmq-exchange\nSource: Stack Overflow\n\nQuestion:\nHow could I attach a debugger to a running erlang process (rabbitmq)? I have the source code of the same rabbit version that's running. I would like to set a breakpoint on a source line, and attach a debugger to the running rabbit instance. I'm not sure if erlang requires debug symbols async_dirty.\n\nIn a perfect world, I would like to be able to do that both locally and remotely.\n\n========================================\n\nTop Answer:\nYou can use graphical debugger or in shell using int module. \nThe modules need to be compiled using debug_info option. \n\nThe process can be remotely debugged from the connected node using debugger:start(global) or connecting to remote shell (^G).\n\n========================================\n\nCode:\n```text\n%enable tracing capabilities\n1> dbg:tracer(). \n\n% Trace Pattern Local-scope \n% (tell the tracer to trace every call in YourModule, even unexported functions).\n2> dbg:tpl(YourModule, x). \n\n% Tell dbg to print calls from all processes calling your module.\n3> dbg:p(all,call). \n\n% Run your traced module\n4> YourModule:SomeFun(). \n\n% You should see nice(?) traces of inputs, outputs, and\n% exceptions in your shell\n```\n\n```text\nEshell V6.3 (abort with ^G)\n1> dbg:tracer(), dbg:tpl(queue, x), dbg:p(all, call).\n{ok,[{matched,nonode@nohost,26}]}\n2> X = queue:new().\n(<0.33.0>) call queue:new()\n(<0.33.0>) returned from queue:new/0 -> {[],[]}\n{[],[]}\n3> X = queue:cons(1).\n** exception error: undefined function queue:cons/1\n4> X = queue:cons(X,1).\n(<0.39.0>) call queue:cons({[],[]},1)\n(<0.39.0>) call queue:in_r({[],[]},1)\n(<0.39.0>) exception_from {queue,in_r,2} {error,badarg}\n(<0.39.0>) exception_from {queue,cons,2} {error,badarg}\n** exception error: bad argument\n in function queue:in_r/2\n called as queue:in_r({[],[]},1)\n5> X = queue:cons(1,X).\n(<0.41.0>) call queue:cons(1,{[],[]})\n(<0.41.0>) call queue:in_r(1,{[],[]})\n(<0.41.0>) returned from queue:in_r/2 -> {[],[1]}\n(<0.41.0>) returned from queue:cons/2 -> {[],[1]}\n** exception error: no match of right hand side value {[],[1]}\n6> X1 = queue:cons(1,X).\n(<0.43.0>) call queue:cons(1,{[],[]})\n(<0.43.0>) call queue:in_r(1,{[],[]})\n(<0.43.0>) returned from queue:in_r/2 -> {[],[1]}\n(<0.43.0>) returned from queue:cons/2 -> {[],[1]}\n{[],[1]}\n```\n\n```text\ndbg\n```\n\n```text\nrecon_trace\n```\n\n```text\nqueue\n```\n\n```text\nprintf\n```\n\n```text\nprintf\n```\n\n========================================\n\nComments:\n- Erlang doc pages: `dbg` reference manual (no user's guide), `debugger` reference manual and user's guide,\n- Related SO threads: Using trace and dbg in Erlang, How to debug Erlang code?,","metadata":{"transformedAt":"2026-08-18T18:33:20.200Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":95,"estimatedTokens":685}}901{"id":"stack-9179243","source":"stackoverflow","questionId":9179243,"title":"Job Dependency in RabbitMQ","tags":["dependencies","rabbitmq"],"text":"Title: Job Dependency in RabbitMQ\nTags: dependencies, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am trying to figure out how to best setup the following scenario:\n\n- Multiple A-type jobs are added into the queue\n\n- When all A-type jobs are completed, a B or C-type job will be needed (one per A-type job)\n\n- When all A, B and C type jobs are completed, a final D-type job will be needed\n\nSo basically we have some dependencies on jobs in the queue such that we don't want to start running jobs that require other jobs to be completed. Is there a guideline for setting up such a system? Should A-type jobs add B or C type jobs after their work is completed? Should all jobs be added up front and somehow tell the workers not to pull them until they are ready?\n\nThere are pros and cons of both approaches if I have to manually manage this dependency but I am curious if there is a different pattern I could use instead that might accomplish the same thing but in an easier way.\n\n========================================\n\nComments:\n- How would you recommend monitoring something like this assuming the job size of A's would be something like 3000 (thus 3000 B and Cs) and only one D? Standard table?\n- For global stats, you could use a different queue for each message type and use the queue stats. But knowing the state of each job would probably need an external data storage.","metadata":{"transformedAt":"2026-08-18T18:33:20.200Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":22,"estimatedTokens":345}}902{"id":"stack-18526571","source":"stackoverflow","questionId":18526571,"title":"How to send & consume Object in Spring AMQP?","tags":["rabbitmq","config","amqp","spring-amqp"],"text":"Title: How to send & consume Object in Spring AMQP?\nTags: rabbitmq, config, amqp, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI want to send and consume the custom object as below using Spring AMQP.\n\nProducer code\n\nRecord record = new Record(\"message1\", new Date());\n\nrabbitTemplate.convertAndSend(record);\n\nCan anyone provide spring amqp @configuration settings for sending and consuming messages as above. Thanks!!!\n\n========================================\n\nCode:\n```text\n@Bean\npublic SimpleMessageListenerContainer container() {\n SimpleMessageListenerContainer container =\n new SimpleMessageListenerContainer(connectionFactory());\n MessageListenerAdapter adapter = new MessageListenerAdapter(myListener());\n container.setMessageListener(adapter);\n container.setQueues(foo());\n return container;\n}\n\n@Bean\npublic Object myListener() {\n return new Foo();\n}\n```\n\n```text\npublic class Foo {\n\n public void handleMessage(Record foo) {\n System.out.println(foo);\n }\n}\n```\n\n```text\n@Configuration\n```\n\n========================================\n\nComments:\n- Thanks Russell, able to consume the Objects.\\\n- I would love to see an example using XML config. I've got everything working and can send/receive strings, but not objects. I can send objects, but they are never received by the app. Rabbit MQs CPU jumps to 100% after sending 1 message and stays at 100% untill I drop the queue, so it is kind of stuck.\n- See this gist for an XML version","metadata":{"transformedAt":"2026-08-18T18:33:20.200Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":54,"estimatedTokens":370}}903{"id":"stack-8371659","source":"stackoverflow","questionId":8371659,"title":"Why does RabbitMQ keep breaking from a corrupt persister log file?","tags":["django","rabbitmq","celery","django-celery"],"text":"Title: Why does RabbitMQ keep breaking from a corrupt persister log file?\nTags: django, rabbitmq, celery, django-celery\nSource: Stack Overflow\n\nQuestion:\nI'm running **Celery** in a **Django** app with **RabbitMQ** as the message broker. However, RabbitMQ keeps breaking down like so. First is the error I get from Django. The trace is mostly unimportant, because I know what is causing the error, as you will see.\n\n```\nTraceback (most recent call last):\n\n ...\n\n File \"/usr/local/lib/python2.6/dist-packages/amqplib/client_0_8/transport.py\", line 85, in __init__\n raise socket.error, msg\n\nerror: [Errno 111] Connection refused\n```\n\nI know that this is due to a corrupt **rabbit_persister.log** file. This is because after I kill all processes tied to RabbitMQ, I run \"sudo rabbitmq-server start\" to get the following crash:\n\n```\n...\n\nstarting queue recovery ...done\nstarting persister ...BOOT ERROR: FAILED\nReason: {{badmatch,{error,{{{badmatch,eof},\n [{rabbit_persister,internal_load_snapshot,2},\n {rabbit_persister,init,1},\n {gen_server,init_it,6},\n {proc_lib,init_p_do_apply,3}]},\n {child,undefined,rabbit_persister,\n {rabbit_persister,start_link,[]},\n transient,100,worker,\n [rabbit_persister]}}}},\n [{rabbit_sup,start_child,2},\n {rabbit,'-run_boot_step/1-lc$^1/1-1-',1},\n {rabbit,run_boot_step,1},\n {rabbit,'-start/2-lc$^0/1-0-',1},\n {rabbit,start,2},\n {application_master,start_it_old,4}]}\nErlang has closed\n```\n\n**My current fix:** Every time this happens, I rename the corresponding rabbit_persister.log file to something else (rabbit_persister.log.bak) and am able to restart RabbitMQ with success. But the problem keeps occurring, and I can't tell why. Any ideas?\n\nAlso, as a disclaimer, I have no experience with Erlang; I'm only using RabbitMQ because it's the broker favored by Celery.\n\nThanks in advance, this problem is really annoying me because I keep doing the same fix over and over.\n\n========================================\n\nTop Answer:\nA. Because you are running an old version of RabbitMQ earlier than 2.7.1\nB. Because RabbitMQ doesn't have enough RAM. You need to run RabbitMQ on a server all by itself and give that server enough RAM so that the RAM is 2.5 times the largest possible size of your persisted message log.\n\nYou might be able to fix this without any software changes just by adding more RAM and killing other services on the box.\n\nAnother approach to this is to build your own RabbitMQ from source and include the toke extension that persists messages using Tokyo Cabinet. Make sure you are using local hard drive and not NFS partitions because Tokyo Cabinet has corruption issues with NFS. And, of course, use version 2.7.1 for this. Depending on your message content, you might also benefit from Tokyo Cabinets compression settings to reduce the read/write activity of persisted messages.\n\n========================================\n\nCode:\n```text\nTraceback (most recent call last):\n\n ...\n\n File \"/usr/local/lib/python2.6/dist-packages/amqplib/client_0_8/transport.py\", line 85, in __init__\n raise socket.error, msg\n\nerror: [Errno 111] Connection refused\n```\n\n```text\n...\n\nstarting queue recovery ...done\nstarting persister ...BOOT ERROR: FAILED\nReason: {{badmatch,{error,{{{badmatch,eof},\n [{rabbit_persister,internal_load_snapshot,2},\n {rabbit_persister,init,1},\n {gen_server,init_it,6},\n {proc_lib,init_p_do_apply,3}]},\n {child,undefined,rabbit_persister,\n {rabbit_persister,start_link,[]},\n transient,100,worker,\n [rabbit_persister]}}}},\n [{rabbit_sup,start_child,2},\n {rabbit,'-run_boot_step/1-lc$^1/1-1-',1},\n {rabbit,run_boot_step,1},\n {rabbit,'-start/2-lc$^0/1-0-',1},\n {rabbit,start,2},\n {application_master,start_it_old,4}]}\nErlang has closed\n```\n\n```text\nrabbit_persister\n```\n\n========================================\n\nComments:\n- Thanks a bunch. Also, simple question, but is there a command to check the current version of RabbitMQ on the system?\n- I mean, aside from just running rabbitmq-server. Like a \"rabbitmqctl\" version of some sort. Anyway, turns out I had the latest version on the development server, but a rather old version on the production server! Yikes. I wondered why it never threw that sort of error on the dev server... Thanks so much. Hopefully this answer is helpful to other people too; I found very few results from searching for this problem beforehand.\n- No problem. `rabbitmqctl status` will show you the version at the top.","metadata":{"transformedAt":"2026-08-18T18:33:20.200Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":106,"estimatedTokens":1198}}904{"id":"stack-11660979","source":"stackoverflow","questionId":11660979,"title":"using rabbitmq to send a message not string but struct","tags":["rabbitmq"],"text":"Title: using rabbitmq to send a message not string but struct\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\ni read the tutorials,RabbitMQ is a message broker,and the message is a string.\nis there any idea that the message is defined as a class or a struct?so i can define my message struct.\n\n========================================\n\nCode:\n```text\npublic byte[] toBytes() {\n byte[]bytes; \n ByteArrayOutputStream baos = new ByteArrayOutputStream(); \n try{ \n ObjectOutputStream oos = new ObjectOutputStream(baos); \n oos.writeObject(this); \n oos.flush();\n oos.reset();\n bytes = baos.toByteArray();\n oos.close();\n baos.close();\n } catch(IOException e){ \n bytes = new byte[] {};\n Logger.getLogger(\"bsdlog\").error(\"Unable to write to output stream\",e); \n } \n return bytes; \n }\n```\n\n```text\npublic static Message fromBytes(byte[] body) {\n Message obj = null;\n try {\n ByteArrayInputStream bis = new ByteArrayInputStream (body);\n ObjectInputStream ois = new ObjectInputStream (bis);\n obj = (Message)ois.readObject();\n ois.close();\n bis.close();\n }\n catch (IOException e) {\n e.printStackTrace();\n }\n catch (ClassNotFoundException ex) {\n ex.printStackTrace();\n }\n return obj; \n}\n```\n\n========================================\n\nComments:\n- You can actually use JSON.NET to easily serialize/deserialize the contents as JSON.","metadata":{"transformedAt":"2026-08-18T18:33:20.200Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":55,"estimatedTokens":374}}905{"id":"stack-67020936","source":"stackoverflow","questionId":67020936,"title":"When to NOT use a message broker such as RabbitMQ in a micro-services architecture?","tags":["rabbitmq","microservices"],"text":"Title: When to NOT use a message broker such as RabbitMQ in a micro-services architecture?\nTags: rabbitmq, microservices\nSource: Stack Overflow\n\nQuestion:\nI am new to the concept of messaging brokers such as RabbitMQ and wanted to learn some best practices.\n\nRabbitMQ seems to be a great way to facilitate asynchronous communication between micro-services, however, I have a beginners question that I could not find an answer to anywhere else.\n\nWhen would one **NOT** use a message broker such as RabbitMQ in a micro-services architecture?\n\nAs an example:\n\nLet's say I have two services. Service **A** and Service **B** *(auth service)*\n\nThe client makes a request to service **A** which in turn must communicate with service **B** *(auth service)* to authenticate the user and authorize the request. (using Basic Auth)\n\n```\nInternet \nClient ----------------> Service A +-------> Service B [Authenticate/Authorization]\n HTTP request HTTP or AMQP??\n```\n\nIn my limited understanding, the issue I can foresee with using an AMQP in scenarios such as the one outlined above is service **A** being able to process the request and send a response to the client within an acceptable timeframe, given it must wait for service B to consume and respond to a message.\n\nEssentially, is it a bad idea to make Service **A** wait for a response from Service **B** via an AMQP?\n\nOr have I missed the point of an AMQP entirely??\n\n========================================\n\nCode:\n```text\nInternet \nClient ----------------> Service A +-------> Service B [Authenticate/Authorization]\n HTTP request HTTP or AMQP??\n```\n\n========================================\n\nComments:\n- I personally like to stay away from message brokers due the added complexity (less moving parts the better imho). I simply use grpc for inter-service communications in a synchronous manner mostly. when asynchrony is required, the recipent service will simply create a db record (add a task to an internal queue) and return a response instantly. for example queing up emails to be sent. only time I work with message brokers is when each microservice is maintained by its own team of developers.\n- Please explain? \"For example in your case the Auth would happen at the API gateway as its not considered best practice to leave the microservices open for all the client applications.\"\n- Again not so much of a global option. But this is explained here. Generally the whole idea of an API gateway is to act as the middleman so the outside services wont be exposed. This has disadvatanges and advatages but if you go with that pattern your API gateway handles auth issues (with the help of some services if needed).\n- Ok, so let's move away from authentication stuff (although thanks for the clarification on this). Say Service B handles something else Service A needs before it can respond to the client, would you use AMQP or HTTP? Is AMQP best used for jobs that are not essentially time-limited?\n- If Service A needs to wait for the result from Service B before it can proceed then a message queue is exactly what you don't want - a synchronous call is more suitable (such as http)","metadata":{"transformedAt":"2026-08-18T18:33:20.200Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":46,"estimatedTokens":791}}906{"id":"stack-5236195","source":"stackoverflow","questionId":5236195,"title":"Python Kombu consumer not notified of rabbitmq message (queue.get does work)","tags":["python","rabbitmq","amqp"],"text":"Title: Python Kombu consumer not notified of rabbitmq message (queue.get does work)\nTags: python, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nIf I run the following code, the callback (test) passed to the consumer is never triggered.\n\nHowever, if I keep an eye on the rabbitmq GUI, I do see that the message is retrieved (but not acknowledged). So it seems the consumer is getting the message, but not passing it on to my callback. If I set no_ack to true, the message just disappears from the queue, again without calling the callback.\n\n```\nhn = \"...\"\nusr = \"...\"\npwd = \"...\"\nvh = \"/\"\nport = 5672\nrkey = \"some.routing.key\"\nqname = \"some-queue-name\"\nexchangeName = \"MyExchange\"\n\nconnection = BrokerConnection(hostname=hn,\n userid=usr,\n password=pwd,\n virtual_host=vh,\n port=port)\n\nconnection.connect()\nch = connection.channel()\n\n# Create & the exchange\nexchange = Exchange(name=exchangeName,\n type=\"topic\",\n channel=ch,\n durable=True)\n\nexchange.declare()\n\n# Temporary channel\nch = connection.channel()\n\n# Create the queue to feed from\nbalq = Queue(name=qname,\n exchange=exchange,\n durable=True,\n auto_delete=False,\n channel=ch,\n routing_key=rkey) \n\n# Declare it on the server\nbalq.declare();\n\ndef test(b,m):\n print '** Message Arrived **'\n\n# Create a consumer\nconsumer = Consumer(channel=connection.channel(),\n queues=balq,\n auto_declare=False,\n callbacks = [test]\n )\n\n# register it on the server\nconsumer.consume(no_ack=False);\n\nprint 'Waiting for messages'\nwhile(True):\n pass\n```\n\nHowever, the following code does work properly (I can successfully get and acknowledge the message):\n\n```\nm = balq.get(no_ack=False)\nm.ack()\nprint m\n```\n\nBut the whole point was to stay asynchronous. So something must be wrong with my callback..\n\n========================================\n\nCode:\n```text\nhn = \"...\"\nusr = \"...\"\npwd = \"...\"\nvh = \"/\"\nport = 5672\nrkey = \"some.routing.key\"\nqname = \"some-queue-name\"\nexchangeName = \"MyExchange\"\n\nconnection = BrokerConnection(hostname=hn,\n userid=usr,\n password=pwd,\n virtual_host=vh,\n port=port)\n\nconnection.connect()\nch = connection.channel()\n\n# Create & the exchange\nexchange = Exchange(name=exchangeName,\n type=\"topic\",\n channel=ch,\n durable=True)\n\nexchange.declare()\n\n# Temporary channel\nch = connection.channel()\n\n# Create the queue to feed from\nbalq = Queue(name=qname,\n exchange=exchange,\n durable=True,\n auto_delete=False,\n channel=ch,\n routing_key=rkey) \n\n# Declare it on the server\nbalq.declare();\n\ndef test(b,m):\n print '** Message Arrived **'\n\n# Create a consumer\nconsumer = Consumer(channel=connection.channel(),\n queues=balq,\n auto_declare=False,\n callbacks = [test]\n )\n\n# register it on the server\nconsumer.consume(no_ack=False);\n\nprint 'Waiting for messages'\nwhile(True):\n pass\n```\n\n```text\nm = balq.get(no_ack=False)\nm.ack()\nprint m\n```\n\n```text\nconnection.drain_events()\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.200Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":149,"estimatedTokens":784}}907{"id":"stack-51844852","source":"stackoverflow","questionId":51844852,"title":"Acknowledging a message inside the consumer_callback in Pika / RabbitMQ","tags":["python","rabbitmq","pika"],"text":"Title: Acknowledging a message inside the consumer_callback in Pika / RabbitMQ\nTags: python, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI have a setup where I would like to be able to acknowledge a pika message after a couple of lines inside the consumer_callback and then carry on with some more time intensiv tasks. I have written some code that does exactly this, but it seems, that the acknowledgement only gets sent out after the consumer_callback returns. I'm using pika 10 with the SelectConnection.\n\nI'm wondering if there is a way to achieve this. The methods I've tried so far are:\n\n- Doing a regular ack in the current callback -> the ack only gets sent out after the callback returns\n\n- Doing a regular ack via a different connection / channel I create specifically for this case -> fails with \"unknown delivery tag\"\n\n- Trying to sneak in a callback via the add_timeout method on the SelectConnection, which then would be called right after the consumer_callback returned -> this somehow messes up the queue communication and very strange things happen, so I'm assuming this is not the right way.\n\nAny help is greatly appreciated. Maybe I need a different connection type?\n\n========================================\n\nCode:\n```text\n0.12.0\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.200Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":23,"estimatedTokens":315}}908{"id":"stack-13597808","source":"stackoverflow","questionId":13597808,"title":"Can I use a Request / Reply - RPC pattern in Rails 3 with AMQP?","tags":["ruby-on-rails","asynchronous","rabbitmq","amqp"],"text":"Title: Can I use a Request / Reply - RPC pattern in Rails 3 with AMQP?\nTags: ruby-on-rails, asynchronous, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nFor reasons similar to the ones in this discussion, I'm experimenting with messaging in lieu of REST for a synchronous RPC call from one Rails 3 application to another. Both apps are running on thin.\n\nThe \"server\" application has a `config/initializers/amqp.rb` file based on the Request / Reply pattern in the rubyamqp.info documentation:\n\n```\nrequire \"amqp\"\n\nEventMachine.next_tick do\n connection = AMQP.connect ENV['CLOUDAMQP_URL'] || 'amqp://guest:guest@localhost'\n channel = AMQP::Channel.new(connection)\n\n requests_queue = channel.queue(\"amqpgem.examples.services.time\", :exclusive => true, :auto_delete => true)\n requests_queue.subscribe(:ack => true) do |metadata, payload|\n puts \"[requests] Got a request #{metadata.message_id}. Sending a reply...\"\n channel.default_exchange.publish(Time.now.to_s,\n :routing_key => metadata.reply_to,\n :correlation_id => metadata.message_id,\n :mandatory => true)\n metadata.ack\n end\n\n Signal.trap(\"INT\") { connection.close { EventMachine.stop } }\nend\n```\n\nIn the 'client' application, I'd like to render the results of a synchronous call to the 'server' in a view. I realize this is a bit outside the comfort zone of an inherently asynchronous library like the amqp gem, but I'm wondering if there's a way to make it work. Here is my client `config/initializers/amqp.rb`:\n\n```\nrequire 'amqp'\n\nEventMachine.next_tick do\n AMQP.connection = AMQP.connect 'amqp://guest:guest@localhost' \n Signal.trap(\"INT\") { AMQP.connection.close { EventMachine.stop } }\nend\n```\n\nHere is the controller:\n\n```\nrequire \"amqp\"\n\nclass WelcomeController \"amqpgem.examples.services.time\",\n :message_id => Kernel.rand(10101010).to_s,\n :reply_to => WelcomeController.replies_queue.name)\n\n WelcomeController.replies_queue.subscribe do |metadata, payload|\n puts \"[response] Response for #{metadata.correlation_id}: #{payload.inspect}\"\n @message = payload.inspect\n end \n end\n\n def self.channel\n @channel ||= AMQP::Channel.new(AMQP.connection)\n end\n\n def self.replies_queue\n @replies_queue ||= channel.queue(\"reply\", :exclusive => true, :auto_delete => true)\n end\nend\n```\n\nWhen I start both applications on different ports and visit the `welcome#index` view.\n`@message` is nil in the view, since the result has not yet returned. The result arrives a few milliseconds after the view is rendered and is displayed on the console: \n\n```\n$ thin start\n>> Using rack adapter\n>> Thin web server (v1.5.0 codename Knife)\n>> Maximum connections set to 1024\n>> Listening on 0.0.0.0:3000, CTRL+C to stop\n[request] Sending a request...\n[response] Response for 3877031: \"2012-11-27 22:04:28 -0600\"\n```\n\nNo surprise here: `subscribe` is clearly not meant for synchronous calls. What is surprising is that I can't find a synchronous alternative in the AMQP gem source code or in any documentation online. Is there an alternative to `subscribe` that will give me the RPC behavior I want? Given that there are other parts of the system in which I'd want to use legitimately asynchronous calls, the bunny gem didn't seem like the right tool for the job. Should I give it another look?\n\n**edit in response to Sam Stokes**\n\nThanks to Sam for the pointer to throw :async / async.callback. I hadn't seen this technique before and this is exactly the kind of thing I was trying to learn with this experiment in the first place. `send_response.finish` is gone in Rails 3, but I was able to get his example to work for at least one request with a minor change: \n\n```\nrender :text => @message\nrendered_response = response.prepare!\n```\n\nSubsequent requests fail with `!! Unexpected error while processing request: deadlock; recursive locking`. This may have been what Sam was getting at with the comment about getting ActionController to allow concurrent requests, but the cited gist only works for Rails 2. Adding `config.allow_concurrency = true` in development.rb gets rid of this error in Rails 3, but leads to `This queue already has default consumer.` from AMQP.\n\nI think this yak is sufficiently shaven. ;-)\n\nWhile interesting, this is clearly overkill for simple RPC. Something like this Sinatra streaming example seems a more appropriate use case for client interaction with replies. Tenderlove also has a blog post about an upcoming way to stream events in Rails 4 that could work with AMQP.\n\nAs Sam points out in his discussion of the HTTP alternative, REST / HTTP makes perfect sense for the RPC portion of my system that involves two Rails apps. There are other parts of the system involving more classic asynchronous event publishing to Clojure apps. For these, the Rails app need only publish events in fire-and-forget fashion, so AMQP will work fine there using my original code without the reply queue.\n\n========================================\n\nCode:\n```text\nrequire \"amqp\"\n\nEventMachine.next_tick do\n connection = AMQP.connect ENV['CLOUDAMQP_URL'] || 'amqp://guest:guest@localhost'\n channel = AMQP::Channel.new(connection)\n\n requests_queue = channel.queue(\"amqpgem.examples.services.time\", :exclusive => true, :auto_delete => true)\n requests_queue.subscribe(:ack => true) do |metadata, payload|\n puts \"[requests] Got a request #{metadata.message_id}. Sending a reply...\"\n channel.default_exchange.publish(Time.now.to_s,\n :routing_key => metadata.reply_to,\n :correlation_id => metadata.message_id,\n :mandatory => true)\n metadata.ack\n end\n\n Signal.trap(\"INT\") { connection.close { EventMachine.stop } }\nend\n```\n\n```text\nrequire 'amqp'\n\nEventMachine.next_tick do\n AMQP.connection = AMQP.connect 'amqp://guest:guest@localhost' \n Signal.trap(\"INT\") { AMQP.connection.close { EventMachine.stop } }\nend\n```\n\n```text\nrequire \"amqp\"\n\nclass WelcomeController < ApplicationController\n def index \n puts \"[request] Sending a request...\"\n\n WelcomeController.channel.default_exchange.publish(\"get.time\",\n :routing_key => \"amqpgem.examples.services.time\",\n :message_id => Kernel.rand(10101010).to_s,\n :reply_to => WelcomeController.replies_queue.name)\n\n WelcomeController.replies_queue.subscribe do |metadata, payload|\n puts \"[response] Response for #{metadata.correlation_id}: #{payload.inspect}\"\n @message = payload.inspect\n end \n end\n\n def self.channel\n @channel ||= AMQP::Channel.new(AMQP.connection)\n end\n\n def self.replies_queue\n @replies_queue ||= channel.queue(\"reply\", :exclusive => true, :auto_delete => true)\n end\nend\n```\n\n```text\n$ thin start\n>> Using rack adapter\n>> Thin web server (v1.5.0 codename Knife)\n>> Maximum connections set to 1024\n>> Listening on 0.0.0.0:3000, CTRL+C to stop\n[request] Sending a request...\n[response] Response for 3877031: \"2012-11-27 22:04:28 -0600\"\n```\n\n```text\nrender :text => @message\nrendered_response = response.prepare!\n```\n\n```text\nconfig/initializers/amqp.rb\n```\n\n```text\nconfig/initializers/amqp.rb\n```\n\n```text\nwelcome#index\n```\n\n```text\n@message\n```\n\n```text\nsubscribe\n```\n\n```text\nsubscribe\n```\n\n```text\nsend_response.finish\n```\n\n```text\n!! Unexpected error while processing request: deadlock; recursive locking\n```\n\n```text\nconfig.allow_concurrency = true\n```\n\n```text\nThis queue already has default consumer.\n```\n\n```ruby\nrequire \"amqp\"\n\nclass WelcomeController < ApplicationController\n def index\n puts \"[request] Sending a request...\"\n\n WelcomeController.channel.default_exchange.publish(\"get.time\",\n :routing_key => \"amqpgem.examples.services.time\",\n :message_id => Kernel.rand(10101010).to_s,\n :reply_to => WelcomeController.replies_queue.name)\n\n WelcomeController.replies_queue.subscribe do |metadata, payload|\n puts \"[response] Response for #{metadata.correlation_id}: #{payload.inspect}\"\n @message = payload.inspect\n\n # Trigger Rails response rendering now we have the message.\n # Tested in Rails 2.3; may or may not work in Rails 3.x.\n rendered_response = send_response.finish\n\n # Pass the response to Thin and make it complete the request.\n # env['async.callback'] expects a Rack-style response triple:\n # [status, headers, body]\n request.env['async.callback'].call(rendered_response)\n end\n\n # This unwinds the call stack, skipping the normal Rails response\n # rendering, all the way back up to Thin, which catches it and\n # interprets as \"I'll give you the response later by calling\n # env['async.callback']\".\n throw :async\n end\n\n def self.channel\n @channel ||= AMQP::Channel.new(AMQP.connection)\n end\n\n def self.replies_queue\n @replies_queue ||= channel.queue(\"reply\", :exclusive => true, :auto_delete => true)\n end\nend\n```\n\n```text\nthrow\n```\n\n```text\nthrow\n```\n\n========================================\n\nComments:\n- Thanks for figuring out the Rails 3 equivalents, I will refer back here next time I try and do this :)\n- The \"queue already has default consumer\" error isn't a Rails 3 problem, but an actual problem with how you're setting up the reply queue: you're sharing one AMQP channel between requests, but calling `subscribe` on that channel once per request. You need to either open a channel per request, or redesign to have a single subscription to the queue (such as the Publisher singleton I mentioned below). (You're also currently leaking subscriptions - you need to unsubscribe / close the per-request channel after the response comes in.)\n- Yep, I realized the AMQP resource handling was off. I played around a bit more with the channel-per-request approach, and ended up getting messages passing between the two apps reliably with each request. Unfortunately, the async callback only rendered the view on the first request; each subsequent request hung. Looking more deeply into async-rails, I found this example from igrigorik containing a mounted async Sinatra app within the Rails app. I'm planning on digging into that next.","metadata":{"transformedAt":"2026-08-18T18:33:20.200Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":18,"totalLines":271,"estimatedTokens":2512}}909{"id":"stack-38771664","source":"stackoverflow","questionId":38771664,"title":"RabbitMQ java client stops consuming messages","tags":["java","heroku","spring-boot","rabbitmq","spring-rabbit"],"text":"Title: RabbitMQ java client stops consuming messages\nTags: java, heroku, spring-boot, rabbitmq, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nMy application consumes some messages from RabbitMQ and processes them.\nI have about 10 queues and each queue has up to ten consumers (threads). \nI have a prefetch of 5. I'm running my setup in Heroku using the CloudAMQP plugin (RabbitMQ as a service).\n\nI'm running with the default heartbeat and connection timeout settings (60 seconds).\n\nMy java application is a spring boot application using the spring-rabbit library.\n\nVersions: \n\n```\nRabbitMQ 3.5.3 \nErlang 17.5.3\nJava 1.8\nSpring boot 1.3.2.RELEASE\nSpring rabbit 1.5.3.RELEASE\n```\n\nThe problem is that for the consumers of one particular queue stop consuming messages after some time. When I restart my java application everything works fine. The other queues are being consumed normally though. No errors on the application's side. On the log stream of rabbit's side I see some entries like\n\n```\n= REPORT==== 2016-08-02 15:53:32 UTC ===\nclosing AMQP connection (SOMETHING_ELSE -> SOMETHING_ELSE_ELSE):\n{heartbeat_timeout,running}\n```\n\nI can't reproduce locally or in a testing environment in Heroku.\n\n**Update**\n\nThe code below can be found in `AMQConnection.class`\n\n```\nint heartbeat = negotiatedMaxValue(this.requestedHeartbeat,\n connTune.getHeartbeat());\n\nprivate static int negotiatedMaxValue(int clientValue, int serverValue) {\n return (clientValue == 0 || serverValue == 0) ?\n Math.max(clientValue, serverValue) :\n Math.min(clientValue, serverValue);\n}\n```\n\nI can't increase the value of the heartbeat above 60 seconds (which is what I'm getting from the server).\n\n========================================\n\nCode:\n```text\nRabbitMQ 3.5.3 \nErlang 17.5.3\nJava 1.8\nSpring boot 1.3.2.RELEASE\nSpring rabbit 1.5.3.RELEASE\n```\n\n```text\n= REPORT==== 2016-08-02 15:53:32 UTC ===\nclosing AMQP connection <SOMETHING> (SOMETHING_ELSE -> SOMETHING_ELSE_ELSE):\n{heartbeat_timeout,running}\n```\n\n```text\nint heartbeat = negotiatedMaxValue(this.requestedHeartbeat,\n connTune.getHeartbeat());\n\n\nprivate static int negotiatedMaxValue(int clientValue, int serverValue) {\n return (clientValue == 0 || serverValue == 0) ?\n Math.max(clientValue, serverValue) :\n Math.min(clientValue, serverValue);\n}\n```\n\n```text\nAMQConnection.class\n```\n\n```text\n$ heroku ps:restart\n```\n\n========================================\n\nComments:\n- Hello @rdegges. Thank you for your help. The plan is big enough to handle all the connections. Moreover (that's my bad, I wasn't clear enough) the consumers all work initially, but occasionally the consumers of this particular queue stop consuming. If I restart the app then everything works fine and the consumers start working again. I cannot reproduce it though. My app is running on one big machine (PL Web 1). I'm familiar with the nature of heroku infra (restarting etc.) and the application can handle this.\n- I was thinking that this could be due to overload which combined with the heartbeat configuration causes this. I'm waiting for this to happen again and see if this particular consumer connection is being dropped by rabbit, but the consumer remains unaware (this would explain the absence of any error logs). If this happens, then changing the heartbeat to a bigger value might fix it. But I don't know if this is possible. Check my update.\n- Ah, this makes it quite a bit more tricky to diagnose. Especially if it can't be easily reproduced :( But that consumer should restart the connection if it drops. Your heartbeat config looks fine to me.\n- What I'm thinking is that the connection is not dropped, but because of the small heartbeat window (let's assume that is small because of some unusual load) rabbit thinks that it's dropped and just discards and stops sending messages there. I believe that rabbit will NOT send some signal to its peer causing the client to be notified about this. Is that correct? That's why I'm thinking that if I increase the heartbeat interval, the client will have enough time to ping rabbit.\n- That is correct, although your heartbeat window seems fine. You said it is set to 60 seconds, correct?\n- Yes, that's the default. It seems fine to me too, but that's just speculation. If this scenario is possible, then that's why I'm only seeing this behaviour very rarely and only in this particular consumer (which is doing some heavy lifting). I would like to try increasing the interval but I can't. See stackoverflow.com/questions/38772773/….\n- Another potential workaround (if this happens rarely): use the Herkou platform API to restart your dyno if you notice the consumer is unresponsive after a certain timeout. You could run a one-off script like this via the Heroku scheduler.\n- Hi, I got the same issue but in a NodeJs environment. All of the sudden the consumer stops consuming without an error message or something. Were you able to reproduce the problem or fix it?","metadata":{"transformedAt":"2026-08-18T18:33:20.200Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":98,"estimatedTokens":1251}}910{"id":"stack-42269239","source":"stackoverflow","questionId":42269239,"title":"RabbitMQ/Spring: Will another exclusive consumer register itself, if the current exclusive deregisters?","tags":["rabbitmq","spring-rabbit","cloud-foundry"],"text":"Title: RabbitMQ/Spring: Will another exclusive consumer register itself, if the current exclusive deregisters?\nTags: rabbitmq, spring-rabbit, cloud-foundry\nSource: Stack Overflow\n\nQuestion:\nI have a spring application which runs in multiple instances on cloudfoundry.\nThese instances a database. They have a `RabbitListener` configured like so:\n\n```\n@RabbitListener(queues = \"${items.updated.queue}\", exclusive = true)\n```\n\nThe queue gets a message if a reimport of items from a certain source is required.\n\nI only want one instance to perform the import. To my understanding this can be accomplished by the exclusive flag.\n\nNow, what would happen if the current `exclusive consumer` crashes? \nWould another currently running instance register itself as the new `exclusive consumer`? Or does the registration only take place when the application starts up?\n\n========================================\n\nCode:\n```text\n@RabbitListener(queues = \"${items.updated.queue}\", exclusive = true)\n```\n\n```text\nRabbitListener\n```\n\n```text\nexclusive consumer\n```\n\n```text\nexclusive consumer\n```\n\n```text\nrecoveryInterval\n```\n\n```text\nrecoveryBackoff\n```\n\n```text\nConditionalExceptionLogger\n```\n\n```text\nConditionalExceptionLogger\n```\n\n```text\nSimpleMessageListenerContainer\n```\n\n```text\nexclusiveConsumerExceptionLogger\n```\n\n========================================\n\nComments:\n- we're implementing the `ConditionalExceptionLogger` to not log the error more than once. This way we don't mess with the recovery interval nor the backoff attempts and at the same time not pollute the logs with too many entries.","metadata":{"transformedAt":"2026-08-18T18:33:20.200Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":10,"totalLines":66,"estimatedTokens":398}}911{"id":"stack-58297986","source":"stackoverflow","questionId":58297986,"title":"Middleware with Masstransit publish","tags":["c#","asp.net","asp.net-mvc","asp.net-core","rabbitmq"],"text":"Title: Middleware with Masstransit publish\nTags: c#, asp.net, asp.net-mvc, asp.net-core, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have .net core WEB API application with MassTransit (for implement RabbitMQ message broker). RabbitMQ-MassTransit configuration is simple and done in few line code in `Startup.cs` file.\n\n```\nservices.AddMassTransit(x =>\n {\n x.AddConsumer();\n\n x.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(cfg =>\n {\n var host = cfg.Host(new Uri(\"rabbitmq://rabbitmq/\"), h =>\n {\n h.Username(\"guest\");\n h.Password(\"guest\");\n });\n\n cfg.ExchangeType = ExchangeType.Fanout;\n\n cfg.ReceiveEndpoint(host, \"ActionLog_Queue\", e =>\n {\n e.PrefetchCount = 16;\n });\n\n // or, configure the endpoints by convention\n cfg.ConfigureEndpoints(provider);\n }));\n });\n```\n\nI am using dependency injection in my project solution for better code standard. Publish messages are works fine with controller dependency injection. But when I implement a custom middle ware for log actions, Masstransit failed to publish the message properly, it was created a additional queue with `_error` in RabbitMQ web console. \n\n```\npublic class RequestResponseLoggingMiddleware\n{\n #region Private Variables\n\n /// \n /// RequestDelegate\n /// \n private readonly RequestDelegate _next;\n\n /// \n /// IActionLogPublish\n /// \n private readonly IActionLogPublish _logPublish;\n\n #endregion\n\n #region Constructor\n public RequestResponseLoggingMiddleware(RequestDelegate next, IActionLogPublish logPublish)\n {\n _next = next;\n _logPublish = logPublish;\n }\n #endregion\n\n #region PrivateMethods\n\n #region FormatRequest\n /// \n /// FormatRequest\n /// \n /// \n /// \n private async Task FormatRequest(HttpRequest request)\n {\n ActionLog actionLog = new ActionLog();\n var body = request.Body;\n request.EnableRewind();\n\n var context = request.HttpContext;\n\n var buffer = new byte[Convert.ToInt32(request.ContentLength)];\n await request.Body.ReadAsync(buffer, 0, buffer.Length);\n var bodyAsText = Encoding.UTF8.GetString(buffer);\n request.Body = body;\n\n var injectedRequestStream = new MemoryStream();\n\n var requestLog = $\"REQUEST HttpMethod: {context.Request.Method}, Path: {context.Request.Path}\";\n\n using (var bodyReader = new StreamReader(context.Request.Body))\n {\n bodyAsText = bodyReader.ReadToEnd();\n\n if (string.IsNullOrWhiteSpace(bodyAsText) == false)\n {\n requestLog += $\", Body : {bodyAsText}\";\n }\n\n var bytesToWrite = Encoding.UTF8.GetBytes(bodyAsText);\n injectedRequestStream.Write(bytesToWrite, 0, bytesToWrite.Length);\n injectedRequestStream.Seek(0, SeekOrigin.Begin);\n context.Request.Body = injectedRequestStream;\n }\n\n actionLog.Request = $\"{bodyAsText}\";\n actionLog.RequestURL = $\"{request.Scheme} {request.Host}{request.Path} {request.QueryString}\";\n\n return actionLog;\n }\n #endregion\n\n #region FormatResponse\n private async Task FormatResponse(HttpResponse response)\n {\n response.Body.Seek(0, SeekOrigin.Begin);\n var text = await new StreamReader(response.Body).ReadToEndAsync();\n response.Body.Seek(0, SeekOrigin.Begin);\n\n return $\"Response {text}\";\n }\n #endregion\n\n #endregion\n\n #region PublicMethods\n\n #region Invoke\n /// \n /// Invoke - Hits before executing any action. Actions call executes from _next(context)\n /// \n /// \n /// \n public async Task Invoke(HttpContext context)\n {\n ActionLog actionLog = new ActionLog();\n\n actionLog = await FormatRequest(context.Request);\n\n var originalBodyStream = context.Response.Body;\n\n using (var responseBody = new MemoryStream())\n {\n context.Response.Body = responseBody;\n\n await _next(context);\n\n actionLog.Response = await FormatResponse(context.Response);\n\n await _logPublish.Publish(actionLog);\n await responseBody.CopyToAsync(originalBodyStream);\n }\n }\n #endregion\n\n #endregion\n}\n```\n\nconfigure Middleware in startup\n\n```\npublic async void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime lifetime)\n {\n ............\n app.UseMiddleware();\n ....................\n }\n```\n\nIs there any additional configuration in startup for MassTransit to work with Middle Ware\n\n**Edit**\n\n**IActionLogPublish**\n\n```\npublic interface IActionLogPublish\n{\n Task Publish(ActionLog model);\n}\n```\n\n**ActionLogPublish**\n\n```\npublic class ActionLogPublish : IActionLogPublish\n{\n\n private readonly IBus _bus;\n\n public ActionLogPublish(IBus bus)\n {\n _bus = bus;\n }\n\n public async Task Publish(ActionLog actionLogData)\n {\n /* Publish values to RabbitMQ Service Bus */\n\n await _bus.Publish(actionLogData);\n\n /* Publish values to RabbitMQ Service Bus */\n }\n\n}\n```\n\n**Edit**\n\nRabbitMQ Web Console\n\nhttps://i.sstatic.net/A7lGs.png\n\n========================================\n\nTop Answer:\nIt is hard to tell from the description what error you are getting exactly. The middleware implementation looks complicated and it can be a source of the error. I would guess that you don't set stream position correctly or something. Corrections from @Nkosi may actually fix it.\n\nIf you say that `IBus` works correctly from controllers, which are created per request, you may want to try to implement `IMiddleware` interface in your middleware as described in this doc.\n\n```\npublic class RequestResponseLoggingMiddleware : IMiddleware\n{\n IActionLogPublish logPublish;\n\n public RequestResponseLoggingMiddleware(IActionLogPublish logPublish)\n {\n this.logPublish = logPublish;\n }\n\n // ...\n\n public async Task InvokeAsync(HttpContext context, RequestDelegate next)\n {\n //...\n }\n\n //...\n}\n```\n\nIn this case middleware will be registered as scoped or transient service and resolved for every request, same as controller. Which may also fix your issue if it relates to scoped services resolution.\n\n========================================\n\nCode:\n```text\nservices.AddMassTransit(x =>\n {\n x.AddConsumer<CustomLogConsume>();\n\n x.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(cfg =>\n {\n var host = cfg.Host(new Uri(\"rabbitmq://rabbitmq/\"), h =>\n {\n h.Username(\"guest\");\n h.Password(\"guest\");\n });\n\n cfg.ExchangeType = ExchangeType.Fanout;\n\n cfg.ReceiveEndpoint(host, \"ActionLog_Queue\", e =>\n {\n e.PrefetchCount = 16;\n });\n\n // or, configure the endpoints by convention\n cfg.ConfigureEndpoints(provider);\n }));\n });\n```\n\n```text\npublic class RequestResponseLoggingMiddleware\n{\n #region Private Variables\n\n /// <summary>\n /// RequestDelegate\n /// </summary>\n private readonly RequestDelegate _next;\n\n /// <summary>\n /// IActionLogPublish\n /// </summary>\n private readonly IActionLogPublish _logPublish;\n\n #endregion\n\n #region Constructor\n public RequestResponseLoggingMiddleware(RequestDelegate next, IActionLogPublish logPublish)\n {\n _next = next;\n _logPublish = logPublish;\n }\n #endregion\n\n #region PrivateMethods\n\n #region FormatRequest\n /// <summary>\n /// FormatRequest\n /// </summary>\n /// <param name=\"request\"></param>\n /// <returns></returns>\n private async Task<ActionLog> FormatRequest(HttpRequest request)\n {\n ActionLog actionLog = new ActionLog();\n var body = request.Body;\n request.EnableRewind();\n\n var context = request.HttpContext;\n\n var buffer = new byte[Convert.ToInt32(request.ContentLength)];\n await request.Body.ReadAsync(buffer, 0, buffer.Length);\n var bodyAsText = Encoding.UTF8.GetString(buffer);\n request.Body = body;\n\n var injectedRequestStream = new MemoryStream();\n\n var requestLog = $\"REQUEST HttpMethod: {context.Request.Method}, Path: {context.Request.Path}\";\n\n using (var bodyReader = new StreamReader(context.Request.Body))\n {\n bodyAsText = bodyReader.ReadToEnd();\n\n if (string.IsNullOrWhiteSpace(bodyAsText) == false)\n {\n requestLog += $\", Body : {bodyAsText}\";\n }\n\n var bytesToWrite = Encoding.UTF8.GetBytes(bodyAsText);\n injectedRequestStream.Write(bytesToWrite, 0, bytesToWrite.Length);\n injectedRequestStream.Seek(0, SeekOrigin.Begin);\n context.Request.Body = injectedRequestStream;\n }\n\n actionLog.Request = $\"{bodyAsText}\";\n actionLog.RequestURL = $\"{request.Scheme} {request.Host}{request.Path} {request.QueryString}\";\n\n return actionLog;\n }\n #endregion\n\n #region FormatResponse\n private async Task<string> FormatResponse(HttpResponse response)\n {\n response.Body.Seek(0, SeekOrigin.Begin);\n var text = await new StreamReader(response.Body).ReadToEndAsync();\n response.Body.Seek(0, SeekOrigin.Begin);\n\n return $\"Response {text}\";\n }\n #endregion\n\n #endregion\n\n #region PublicMethods\n\n #region Invoke\n /// <summary>\n /// Invoke - Hits before executing any action. Actions call executes from _next(context)\n /// </summary>\n /// <param name=\"context\"></param>\n /// <returns></returns>\n public async Task Invoke(HttpContext context)\n {\n ActionLog actionLog = new ActionLog();\n\n actionLog = await FormatRequest(context.Request);\n\n\n var originalBodyStream = context.Response.Body;\n\n using (var responseBody = new MemoryStream())\n {\n context.Response.Body = responseBody;\n\n await _next(context);\n\n actionLog.Response = await FormatResponse(context.Response);\n\n await _logPublish.Publish(actionLog);\n await responseBody.CopyToAsync(originalBodyStream);\n }\n }\n #endregion\n\n #endregion\n}\n```\n\n```text\npublic async void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime lifetime)\n {\n ............\n app.UseMiddleware<RequestResponseLoggingMiddleware>();\n ....................\n }\n```\n\n```text\npublic interface IActionLogPublish\n{\n Task Publish(ActionLog model);\n}\n```\n\n```text\npublic class ActionLogPublish : IActionLogPublish\n{\n\n private readonly IBus _bus;\n\n public ActionLogPublish(IBus bus)\n {\n _bus = bus;\n }\n\n public async Task Publish(ActionLog actionLogData)\n {\n /* Publish values to RabbitMQ Service Bus */\n\n await _bus.Publish(actionLogData);\n\n /* Publish values to RabbitMQ Service Bus */\n }\n\n}\n```\n\n```text\nStartup.cs\n```\n\n```text\n_error\n```\n\n```text\n//...omitted for brevity\n\npublic RequestResponseLoggingMiddleware(RequestDelegate next) {\n _next = next;\n}\n\n//...\n\nprivate async Task<string> FormatResponseStream(Stream stream) {\n stream.Seek(0, SeekOrigin.Begin);\n var text = await new StreamReader(stream).ReadToEndAsync();\n stream.Seek(0, SeekOrigin.Begin);\n return $\"Response {text}\";\n}\n\npublic async Task Invoke(HttpContext context, IActionLogPublish logger) {\n ActionLog actionLog = await FormatRequest(context.Request);\n //keep local copy of response stream\n var originalBodyStream = context.Response.Body;\n\n using (var responseBody = new MemoryStream()) {\n //replace stream for down stream calls\n context.Response.Body = responseBody;\n\n await _next(context);\n\n //put original stream back in the response object\n context.Response.Body = originalBodyStream; // <-- THIS IS IMPORTANT\n\n //Copy local stream to original stream\n responseBody.Position = 0;\n await responseBody.CopyToAsync(originalBodyStream);\n\n //custom logging\n actionLog.Response = await FormatResponse(responseBody);\n await logger.Publish(actionLog);\n }\n}\n```\n\n```text\nInvoke\n```\n\n```text\nInvoke\n```\n\n```text\nInvoke\n```\n\n```text\nInvoke\n```\n\n```text\nInvokeAsync\n```\n\n```text\npublic class RequestResponseLoggingMiddleware : IMiddleware\n{\n IActionLogPublish logPublish;\n\n public RequestResponseLoggingMiddleware(IActionLogPublish logPublish)\n {\n this.logPublish = logPublish;\n }\n\n // ...\n\n public async Task InvokeAsync(HttpContext context, RequestDelegate next)\n {\n //...\n }\n\n //...\n}\n```\n\n```text\nIBus\n```\n\n```text\nIMiddleware\n```\n\n========================================\n\nComments:\n- Some questions ... any kind of error in the logs and or anything that gets pushed to the _error queue . Can you also the code for IActionLogPublish\n- What error are you getting exactly? try running it with all exceptions caught..\n- Also, how does the IOC container resolve the delegate _next? I'm assuming the middleware lifetime is also managed by the IOC container","metadata":{"transformedAt":"2026-08-18T18:33:20.201Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":16,"totalLines":531,"estimatedTokens":3139}}912{"id":"stack-48244986","source":"stackoverflow","questionId":48244986,"title":"RabbitMQ security design to declare queues from server (and use from client)","tags":["rabbitmq"],"text":"Title: RabbitMQ security design to declare queues from server (and use from client)\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have a test app (first with RabbitMQ) which runs on partially trusted clients (in that i don't want them creating queues on their own), so i will look into the security permissions of the queues and credentials that the clients connect with.\n\nFor messaging there are mostly one-way broadcasts from server to clients, and sometimes a query from server to a specific client (over which the replies will be sent on a replyTo queue which is dedicated to that client on which the server listens for responses).\n\nI currently have a receive function on the server which looks out for \"Announce\" broadcast from clients:\n\n```\nagentAnnounceListener.Received += (model, ea) =>\n{\n var body = ea.Body;\n var props = ea.BasicProperties;\n var message = Encoding.UTF8.GetString(body);\n\n Console.WriteLine(\n \"[{0}] from: {1}. body: {2}\",\n DateTimeOffset.FromUnixTimeMilliseconds(ea.BasicProperties.Timestamp.UnixTime).Date,\n props.ReplyTo,\n message);\n\n // create return replyTo queue, snipped in next code section\n};\n```\n\nI am looking to create the return to topic in the above receive handler:\n\n```\nvar result = channel.QueueDeclare(\n queue: ea.BasicProperties.ReplyTo,\n durable: false,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n```\n\nAlternatively, i could store the received announcements in a database, and on a regular timer run through this list and declare a queue for each on every pass.\n\nIn both scenarioes this newly created channel would then be used at a future point by the server to send queries to the client.\n\nMy questions are please:\n\n1) Is it better to create a reply channel on the server when receiving the message from client, or if i do it externally (on a timer) are there any performance issues for declaring queues that already exist (there could be thousands of end points)?\n\n2) If a client starts to miss behave, is there any way that they can be booted (in the receive function i can look up how many messages per minute and boot if certain criteria are met)? Are there any other filters that can be defined prior to receive in the pipeline to kick clients who are sending too many messages?\n\n3) In the above example notice my messages continuously come in each run (the same old messages), how do i clear them out please?\n\n========================================\n\nTop Answer:\nI think preventing clients from creating queues just complicates the design without much security benefit.\nYou are allowing clients to create messages. In RabbitMQ, its not very easy to stop clients from flooding your server with messages.\n\nIf you want to rate-limit your clients, RabbitMQ may not be the best choice. It does rate-limiting automatically when servers starts to struggle with processing all the messages, but you can't set a strict rate limit on per-client basis on the server using out-of-the-box solution. Also, clients are normally allowed to create queues.\n\n**Approach 1 - Web App**\n\nMaybe you should try to use web application instead:\n\n- Clients authenticate with your server\n\n- To Announce, clients send a POST request to a certain endpoint, ie `/api/announce`, maybe providing some credentials that allow them to do so\n\n- To receive incoming messages, `GET /api/messages`\n\n- To acknowledge processed message: `POST /api/acknowledge`\n\nWhen client acknowledges receipt, you delete your message from database.\n\nWith this design, you can write custom logic to rate-limit or ban clients that misbehave and you have full control of your server\n\n**Approach 2 - RabbitMQ Management API**\n\nIf you still want to use RabbitMQ, you can potentially achieve what you want by using RabbitMQ Management API\n\nYou'll need to write an app that will query RabbitMQ Management API on timer basis and:\n\nGet all the current connections, and check message rate for each of them. \n\nIf message rate exceed your threshold, close connection or revoke user's permissions using `/api/permissions/vhost/user` endpoint.\n\nIn my opinion, web app may be easier if you don't need all the queueing functionality like worker queues or complicated routing that you can get out of the box with RabbitMQ.\n\n========================================\n\nCode:\n```text\nagentAnnounceListener.Received += (model, ea) =>\n{\n var body = ea.Body;\n var props = ea.BasicProperties;\n var message = Encoding.UTF8.GetString(body);\n\n Console.WriteLine(\n \"[{0}] from: {1}. body: {2}\",\n DateTimeOffset.FromUnixTimeMilliseconds(ea.BasicProperties.Timestamp.UnixTime).Date,\n props.ReplyTo,\n message);\n\n // create return replyTo queue, snipped in next code section\n};\n```\n\n```text\nvar result = channel.QueueDeclare(\n queue: ea.BasicProperties.ReplyTo,\n durable: false,\n exclusive: false,\n autoDelete: false,\n arguments: null);\n```\n\n```text\nexclusive\n```\n\n```text\nautodelete\n```\n\n```text\nexclusive\n```\n\n```text\n$clientID_to_server\n```\n\n```text\nX\n```\n\n```text\nratelimit\n```\n\n```text\n$clientID_overwhelm\n```\n\n```text\nratelimit\n```\n\n```text\n$clientID_to_server\n```\n\n```text\n$clientID_to_server\n```\n\n```text\n$clientID_overwhelm\n```\n\n```text\nX+1\n```\n\n```text\n*_overwhelm\n```\n\n```text\n$clientID_to_server\n```\n\n```text\n$clientID_overwhelm\n```\n\n```text\n/connections\n```\n\n```text\nconsume\n```\n\n```text\n/api/announce\n```\n\n```text\nGET /api/messages\n```\n\n```text\nPOST /api/acknowledge\n```\n\n```text\n/api/permissions/vhost/user\n```\n\n========================================\n\nComments:\n- `complicates the design without much security benefit. You are allowing clients to create message` very true and to the point. how are creation of a ton of queues verses creation of a ton of messages any different, the can both be abused in the same way. How about authenticating clients by certificate (with a very long life), and then revoking said certificate weblogs.asp.net/jeffreyabecker/…\n- or if we were to use a WebAPI are there any poller based and web-hook messaging libraries that you know of that do that with banning of naughty clients etc?\n- `authenticating clients using certificate` - this can work, except you still need to write custom code to monitor those clients and dynamically revoke certificates... about polling libraries - there should be, you should research for your language. The closest to those I used is Polly for .NET, but its not exactly what you are looking for though.\n- There are a couple of ways to use rabbit alone to detect misbehaving clients and kick them, but they take a little work to set up. I put a couple examples of those in my answer. Additionally, you can (though I'm not sure if you should, as Alex indicated) restrict individual clients' ability to do certain rabbit/AMQP operations (like declare queues) if you want: rabbitmq.com/access-control.html","metadata":{"transformedAt":"2026-08-18T18:33:20.201Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":23,"totalLines":207,"estimatedTokens":1710}}913{"id":"stack-58623222","source":"stackoverflow","questionId":58623222,"title":"Proper way to initialize a background service in dot net core","tags":["c#","asp.net-core","asp.net-web-api","rabbitmq"],"text":"Title: Proper way to initialize a background service in dot net core\nTags: c#, asp.net-core, asp.net-web-api, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have a service that needs to connect to another service at the `startup`.\nThe other service is a `Rabbitmq` broker. \n\nI'm listening to some event from `Rabbitmq` so I need it to be activated from the start of the application.\n\nI need to connect to two different `VHost`s, so I need to create two connections.\n\nThe problem is that when I start the application is constantly creates connections until the server crashes!\n\nIn Rabbitmq management I can see a lot of `Connection` and `Channels` are created.\n\nI can't find out why is this happening.\n\nIn general, I want to know whats is the proper way of connecting to other services in the startup of my application in dotnet core.\n\nI'm using this code to do so :\n\n```\npublic void ConfigureServices(IServiceCollection services)\n {\n .....\n\n services.AddSingleton();\n\n ...\n\n ActivatorUtilities.CreateInstance(services.BuildServiceProvider());\n }\n```\n\nAnd in the constructor of `RabbitConnectionService` I'm connecting to `Rabbitmq`.\n\n```\npublic RabbitConnectionService(IConfiguration configuration)\n { \n ServersMessageQueue = new MessageQueue(configuration.GetConnectionString(\"FirstVhost\"), \"First\");\n ClientsMessageQueue = new MessageQueue(configuration.GetConnectionString(\"SecondVhost\"), \"Second\");\n }\n```\n\nMessageQueue Class :\n\n```\npublic class MessageQueue\n {\n\n private IConnection connection;\n\n private string RabbitURI;\n private string ConnectionName;\n\n static Logger _logger = LogManager.GetCurrentClassLogger();\n\n public MessageQueue(string connectionUri, string connectionName)\n {\n ConnectionName = connectionName;\n RabbitURI = connectionUri;\n connection = CreateConnection();\n }\n\n private IConnection CreateConnection()\n {\n ConnectionFactory factory = new ConnectionFactory();\n factory.Uri = new Uri(RabbitURI);\n factory.AutomaticRecoveryEnabled = true;\n factory.RequestedHeartbeat = 10;\n return factory.CreateConnection(ConnectionName);\n }\n\n public IModel CreateChannel()\n {\n return connection.CreateModel();\n }\n\n ...\n }\n```\n\n========================================\n\nCode:\n```text\npublic void ConfigureServices(IServiceCollection services)\n {\n .....\n\n services.AddSingleton<RabbitConnectionService>();\n\n ...\n\n ActivatorUtilities.CreateInstance<RabbitConnectionService>(services.BuildServiceProvider());\n }\n```\n\n```text\npublic RabbitConnectionService(IConfiguration configuration)\n { \n ServersMessageQueue = new MessageQueue(configuration.GetConnectionString(\"FirstVhost\"), \"First\");\n ClientsMessageQueue = new MessageQueue(configuration.GetConnectionString(\"SecondVhost\"), \"Second\");\n }\n```\n\n```text\npublic class MessageQueue\n {\n\n private IConnection connection;\n\n private string RabbitURI;\n private string ConnectionName;\n\n static Logger _logger = LogManager.GetCurrentClassLogger();\n\n public MessageQueue(string connectionUri, string connectionName)\n {\n ConnectionName = connectionName;\n RabbitURI = connectionUri;\n connection = CreateConnection();\n }\n\n\n private IConnection CreateConnection()\n {\n ConnectionFactory factory = new ConnectionFactory();\n factory.Uri = new Uri(RabbitURI);\n factory.AutomaticRecoveryEnabled = true;\n factory.RequestedHeartbeat = 10;\n return factory.CreateConnection(ConnectionName);\n }\n\n public IModel CreateChannel()\n {\n return connection.CreateModel();\n }\n\n ...\n }\n```\n\n```text\nstartup\n```\n\n```text\nRabbitmq\n```\n\n```text\nRabbitmq\n```\n\n```text\nVHost\n```\n\n```text\nConnection\n```\n\n```text\nChannels\n```\n\n```text\nRabbitConnectionService\n```\n\n```text\nRabbitmq\n```\n\n```text\npublic interface IHostedService\n{\n Task StartAsync(CancellationToken cancellationToken);\n Task StopAsync(CancellationToken cancellationToken);\n}\n```\n\n```text\npublic void ConfigureServices(IServiceCollection services)\n{\n ...\n services.AddSingleton<IHostedService, DemoService>();\n ...\n}\n```\n\n```text\npublic class DemoService : BackgroundService\n{\n private readonly ILogger<DemoService> _demoservicelogger;\n private readonly DemoContext _demoContext;\n private readonly IEmailService _emailService;\n public DemoService(ILogger<DemoService> demoservicelogger, \n DemoContext demoContext, IEmailService emailService)\n {\n _demoservicelogger = demoservicelogger;\n _demoContext = demoContext;\n _emailService = emailService;\n }\n protected override async Task ExecuteAsync(CancellationToken stoppingToken)\n {\n _demoservicelogger.LogDebug(\"Demo Service is starting\");\n stoppingToken.Register(() => _demoservicelogger.LogDebug(\"Demo Service is stopping.\"));\n while (!stoppingToken.IsCancellationRequested)\n {\n _demoservicelogger.LogDebug(\"Demo Service is running in background\");\n var pendingEmailTasks = _demoContext.EmailTasks\n .Where(x => !x.IsEmailSent).AsEnumerable();\n await SendEmailsAsync(pendingEmailTasks);\n await Task.Delay(1000 * 60 * 5, stoppingToken);\n }\n _demoservicelogger.LogDebug(\"Demo service is stopping\");\n }\n}\n```\n\n```text\nIHostedService\n```\n\n```text\nStartAsync\n```\n\n```text\nStopAsync\n```\n\n```text\nIHostedService\n```\n\n```text\nBackgroundService\n```\n\n```text\nExecuteAsync\n```\n\n========================================\n\nComments:\n- You really haven't provided enough information here. For example, why are you calling`ActivatorUtilities.CreateInstance` in your `ConfigureServices`, then doing nothing with the result?\n- I'm listening to some event from Rabbitmq so I need it to be activated from the start of the application. If I do not put it in there It will not be started until the first request comes to my server.\n- Ah, I understand now. The `ConfigureServices` method in .NET Core is poorly named, it should really have been called `ConfigureDependencies` or similar. Anyway, what you are looking for is background **tasks**, and MSDN has docs on that: learn.microsoft.com/en-us/aspnet/core/fundamentals/host/…\n- Maybe my answer can help you stackoverflow.com/questions/58535975/…\n- @IanKemp Thanks, You answered my question.\n- Great answer. What if the service was listening to an endpoint and it fired events when an email was ready to be sent? You would not require a while loop or delay, but I'm not sure how the asynchronous logic would be handled in the ExecuteAsync method.\n- @Murphybro2 I'm sure you have figured out the issue by now, but for anyone else who comes along, if you just have an even listener, then you don't need to use the `BackgroundService` instead use @AminSojoudi's first suggestion, simply implement `IHostedService` then wire up your eventhandler during Start and unwire it on Stop","metadata":{"transformedAt":"2026-08-18T18:33:20.201Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":20,"totalLines":257,"estimatedTokens":1755}}914{"id":"stack-42996655","source":"stackoverflow","questionId":42996655,"title":"Celery RabbitMQ broker failover connect issue","tags":["rabbitmq","celery","failover","kombu"],"text":"Title: Celery RabbitMQ broker failover connect issue\nTags: rabbitmq, celery, failover, kombu\nSource: Stack Overflow\n\nQuestion:\nI have 3 RabbitMQ nodes in cluster in HA mode. Each node is on separate Docker container.\n\nI am using Celery version 4 and kombu version 4.\n\nI have used this command to set HA policy:\n\n```\nrabbitmqctl set_policy ha-all \"\" '{\"ha-mode\":\"all\",\"ha-sync-mode\":\"automatic\"}'\n```\n\nCelery config looks like this:\n\n```\nCELERY = dict(\n broker_url=[\n 'amqp://guest@rabbitmq1:5672',\n 'amqp://guest@rabbitmq2:5672',\n 'amqp://guest@rabbitmq3:5672',\n ],\n celery_queue_ha_policy='all',\n ...\n)\n```\n\nEverything works fine until I stop master RabbitMQ application in order to test Celery failover feature using command:\n\n```\nrabbitmqctl stop_app\n```\n\nImmediately after RabbitMQ application is stopped I started seeing errors in log bellow. Frequency of log messages is very high and it doesn't slow down with number of attempts.\n\nAccording to logs Celery tries to reconnect using next failover, but it gets interrupted by another try to reconnect to master node that was stopped. The same thing happens over and over like in infinite loop.\n\n```\n[2017-03-17 15:10:28,084: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@rabbitmq1:5672//: [Errno 111] Connection refused.\nWill retry using next failover.\n\n[2017-03-17 15:10:28,300: DEBUG/MainProcess] Start from server, version: 0.9, properties: {'information': 'Licensed under the MPL. See http://www.rabbitmq.com/', 'product': 'RabbitMQ', 'copyright': 'Copyright (C) 2007-2016 Pivotal Software, Inc.', 'capabilities': {'exchange_exchange_bindings': True, 'connection.blocked': True, 'authentication_failure_close': True, 'direct_reply_to': True, 'basic.nack': True, 'per_consumer_qos': True, 'consumer_priorities': True, 'consumer_cancel_notify': True, 'publisher_confirms': True}, 'cluster_name': 'rabbit@rabbitmq1', 'platform': 'Erlang/OTP', 'version': '3.6.6'}, mechanisms: [u'PLAIN', u'AMQPLAIN'], locales: [u'en_US']\n[2017-03-17 15:10:28,302: DEBUG/MainProcess] ^-- substep ok\n[2017-03-17 15:10:28,303: DEBUG/MainProcess] | Consumer: Starting Mingle\n[2017-03-17 15:10:28,303: INFO/MainProcess] mingle: searching for neighbors\n[2017-03-17 15:10:28,303: DEBUG/MainProcess] using channel_id: 1\n[2017-03-17 15:10:28,318: DEBUG/MainProcess] Channel open\n[2017-03-17 15:10:28,470: WARNING/MainProcess] consumer: Connection to broker lost. Trying to re-establish the connection...\nTraceback (most recent call last):\n File \"/usr/local/lib/python2.7/site-packages/celery/worker/consumer/consumer.py\", line 318, in start\n blueprint.start(self)\n File \"/usr/local/lib/python2.7/site-packages/celery/bootsteps.py\", line 119, in start\n step.start(parent)\n File \"/usr/local/lib/python2.7/site-packages/celery/worker/consumer/mingle.py\", line 38, in start\n self.sync(c)\n File \"/usr/local/lib/python2.7/site-packages/celery/worker/consumer/mingle.py\", line 42, in sync\n replies = self.send_hello(c)\n File \"/usr/local/lib/python2.7/site-packages/celery/worker/consumer/mingle.py\", line 55, in send_hello\n replies = inspect.hello(c.hostname, our_revoked._data) or {}\n File \"/usr/local/lib/python2.7/site-packages/celery/app/control.py\", line 129, in hello\n return self._request('hello', from_node=from_node, revoked=revoked)\n File \"/usr/local/lib/python2.7/site-packages/celery/app/control.py\", line 81, in _request\n timeout=self.timeout, reply=True,\n File \"/usr/local/lib/python2.7/site-packages/celery/app/control.py\", line 436, in broadcast\n limit, callback, channel=channel,\n File \"/usr/local/lib/python2.7/site-packages/kombu/pidbox.py\", line 315, in _broadcast\n serializer=serializer)\n File \"/usr/local/lib/python2.7/site-packages/kombu/pidbox.py\", line 290, in _publish\n serializer=serializer,\n File \"/usr/local/lib/python2.7/site-packages/kombu/messaging.py\", line 181, in publish\n exchange_name, declare,\n File \"/usr/local/lib/python2.7/site-packages/kombu/messaging.py\", line 187, in _publish\n channel = self.channel\n File \"/usr/local/lib/python2.7/site-packages/kombu/messaging.py\", line 209, in _get_channel\n channel = self._channel = channel()\n File \"/usr/local/lib/python2.7/site-packages/kombu/utils/functional.py\", line 38, in __call__\n value = self.__value__ = self.__contract__()\n File \"/usr/local/lib/python2.7/site-packages/kombu/messaging.py\", line 224, in \n channel = ChannelPromise(lambda: connection.default_channel)\n File \"/usr/local/lib/python2.7/site-packages/kombu/connection.py\", line 819, in default_channel\n self.connection\n File \"/usr/local/lib/python2.7/site-packages/kombu/connection.py\", line 802, in connection\n self._connection = self._establish_connection()\n File \"/usr/local/lib/python2.7/site-packages/kombu/connection.py\", line 757, in _establish_connection\n conn = self.transport.establish_connection()\n File \"/usr/local/lib/python2.7/site-packages/kombu/transport/pyamqp.py\", line 130, in establish_connection\n conn.connect()\n File \"/usr/local/lib/python2.7/site-packages/amqp/connection.py\", line 294, in connect\n self.transport.connect()\n File \"/usr/local/lib/python2.7/site-packages/amqp/transport.py\", line 120, in connect\n self._connect(self.host, self.port, self.connect_timeout)\n File \"/usr/local/lib/python2.7/site-packages/amqp/transport.py\", line 161, in _connect\n self.sock.connect(sa)\n File \"/usr/local/lib/python2.7/socket.py\", line 228, in meth\n return getattr(self._sock,name)(*args)\nerror: [Errno 111] Connection refused\n[2017-03-17 15:10:28,508: DEBUG/MainProcess] Closed channel #1\n[2017-03-17 15:10:28,570: DEBUG/MainProcess] | Consumer: Restarting event loop...\n[2017-03-17 15:10:28,572: DEBUG/MainProcess] | Consumer: Restarting Gossip...\n[2017-03-17 15:10:28,575: DEBUG/MainProcess] | Consumer: Restarting Heart...\n[2017-03-17 15:10:28,648: DEBUG/MainProcess] | Consumer: Restarting Control...\n[2017-03-17 15:10:28,655: DEBUG/MainProcess] | Consumer: Restarting Tasks...\n[2017-03-17 15:10:28,655: DEBUG/MainProcess] Canceling task consumer...\n[2017-03-17 15:10:28,655: DEBUG/MainProcess] | Consumer: Restarting Mingle...\n[2017-03-17 15:10:28,655: DEBUG/MainProcess] | Consumer: Restarting Events...\n[2017-03-17 15:10:28,672: DEBUG/MainProcess] | Consumer: Restarting Connection...\n[2017-03-17 15:10:28,673: DEBUG/MainProcess] | Consumer: Starting Connection\n[2017-03-17 15:10:28,947: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@rabbitmq1:5672//: [Errno 111] Connection refused.\nWill retry using next failover.\n\n[2017-03-17 15:10:29,345: DEBUG/MainProcess] Start from server, version: 0.9, properties: {'information': 'Licensed under the MPL. See http://www.rabbitmq.com/', 'product': 'RabbitMQ', 'copyright': 'Copyright (C) 2007-2016 Pivotal Software, Inc.', 'capabilities': {'exchange_exchange_bindings': True, 'connection.blocked': True, 'authentication_failure_close': True, 'direct_reply_to': True, 'basic.nack': True, 'per_consumer_qos': True, 'consumer_priorities': True, 'consumer_cancel_notify': True, 'publisher_confirms': True}, 'cluster_name': 'rabbit@rabbitmq1', 'platform': 'Erlang/OTP', 'version': '3.6.6'}, mechanisms: [u'PLAIN', u'AMQPLAIN'], locales: [u'en_US']\n[2017-03-17 15:10:29,506: INFO/MainProcess] Connected to amqp://guest:**@rabbitmq2:5672//\n[2017-03-17 15:10:29,535: DEBUG/MainProcess] ^-- substep ok\n[2017-03-17 15:10:29,569: DEBUG/MainProcess] | Consumer: Starting Events\n[2017-03-17 15:10:29,682: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@rabbitmq1:5672//: [Errno 111] Connection refused.\nWill retry using next failover.\n\n[2017-03-17 15:10:29,740: DEBUG/MainProcess] Start from server, version: 0.9, properties: {'information': 'Licensed under the MPL. See http://www.rabbitmq.com/', 'product': 'RabbitMQ', 'copyright': 'Copyright (C) 2007-2016 Pivotal Software, Inc.', 'capabilities': {'exchange_exchange_bindings': True, 'connection.blocked': True, 'authentication_failure_close': True, 'direct_reply_to': True, 'basic.nack': True, 'per_consumer_qos': True, 'consumer_priorities': True, 'consumer_cancel_notify': True, 'publisher_confirms': True}, 'cluster_name': 'rabbit@rabbitmq1', 'platform': 'Erlang/OTP', 'version': '3.6.6'}, mechanisms: [u'PLAIN', u'AMQPLAIN'], locales: [u'en_US']\n[2017-03-17 15:10:29,768: DEBUG/MainProcess] ^-- substep ok\n[2017-03-17 15:10:29,770: DEBUG/MainProcess] | Consumer: Starting Mingle\n[2017-03-17 15:10:29,770: INFO/MainProcess] mingle: searching for neighbors\n[2017-03-17 15:10:29,771: DEBUG/MainProcess] using channel_id: 1\n[2017-03-17 15:10:29,795: DEBUG/MainProcess] Channel open\n[2017-03-17 15:10:29,874: WARNING/MainProcess] consumer: Connection to broker lost. Trying to re-establish the connection...\nTraceback (most recent call last):\n File \"/usr/local/lib/python2.7/site-packages/celery/worker/consumer/consumer.py\", line 318, in start\n blueprint.start(self)\n File \"/usr/local/lib/python2.7/site-packages/celery/bootsteps.py\", line 119, in start\n step.start(parent)\n File \"/usr/local/lib/python2.7/site-packages/celery/worker/consumer/mingle.py\", line 38, in start\n self.sync(c)\n File \"/usr/local/lib/python2.7/site-packages/celery/worker/consumer/mingle.py\", line 42, in sync\n replies = self.send_hello(c)\n File \"/usr/local/lib/python2.7/site-packages/celery/worker/consumer/mingle.py\", line 55, in send_hello\n replies = inspect.hello(c.hostname, our_revoked._data) or {}\n File \"/usr/local/lib/python2.7/site-packages/celery/app/control.py\", line 129, in hello\n return self._request('hello', from_node=from_node, revoked=revoked)\n File \"/usr/local/lib/python2.7/site-packages/celery/app/control.py\", line 81, in _request\n timeout=self.timeout, reply=True,\n File \"/usr/local/lib/python2.7/site-packages/celery/app/control.py\", line 436, in broadcast\n limit, callback, channel=channel,\n File \"/usr/local/lib/python2.7/site-packages/kombu/pidbox.py\", line 315, in _broadcast\n serializer=serializer)\n File \"/usr/local/lib/python2.7/site-packages/kombu/pidbox.py\", line 290, in _publish\n serializer=serializer,\n File \"/usr/local/lib/python2.7/site-packages/kombu/messaging.py\", line 181, in publish\n exchange_name, declare,\n File \"/usr/local/lib/python2.7/site-packages/kombu/messaging.py\", line 187, in _publish\n channel = self.channel\n File \"/usr/local/lib/python2.7/site-packages/kombu/messaging.py\", line 209, in _get_channel\n channel = self._channel = channel()\n File \"/usr/local/lib/python2.7/site-packages/kombu/utils/functional.py\", line 38, in __call__\n value = self.__value__ = self.__contract__()\n File \"/usr/local/lib/python2.7/site-packages/kombu/messaging.py\", line 224, in \n channel = ChannelPromise(lambda: connection.default_channel)\n File \"/usr/local/lib/python2.7/site-packages/kombu/connection.py\", line 819, in default_channel\n self.connection\n File \"/usr/local/lib/python2.7/site-packages/kombu/connection.py\", line 802, in connection\n self._connection = self._establish_connection()\n File \"/usr/local/lib/python2.7/site-packages/kombu/connection.py\", line 757, in _establish_connection\n conn = self.transport.establish_connection()\n File \"/usr/local/lib/python2.7/site-packages/kombu/transport/pyamqp.py\", line 130, in establish_connection\n conn.connect()\n File \"/usr/local/lib/python2.7/site-packages/amqp/connection.py\", line 294, in connect\n self.transport.connect()\n File \"/usr/local/lib/python2.7/site-packages/amqp/transport.py\", line 120, in connect\n self._connect(self.host, self.port, self.connect_timeout)\n File \"/usr/local/lib/python2.7/site-packages/amqp/transport.py\", line 161, in _connect\n self.sock.connect(sa)\n File \"/usr/local/lib/python2.7/socket.py\", line 228, in meth\n return getattr(self._sock,name)(*args)\nerror: [Errno 111] Connection refused\n[2017-03-17 15:10:29,887: DEBUG/MainProcess] Closed channel #1\n[2017-03-17 15:10:29,907: DEBUG/MainProcess] | Consumer: Restarting event loop...\n[2017-03-17 15:10:29,908: DEBUG/MainProcess] | Consumer: Restarting Gossip...\n[2017-03-17 15:10:29,908: DEBUG/MainProcess] | Consumer: Restarting Heart...\n[2017-03-17 15:10:29,908: DEBUG/MainProcess] | Consumer: Restarting Control...\n[2017-03-17 15:10:29,909: DEBUG/MainProcess] | Consumer: Restarting Tasks...\n[2017-03-17 15:10:29,910: DEBUG/MainProcess] Canceling task consumer...\n[2017-03-17 15:10:29,911: DEBUG/MainProcess] | Consumer: Restarting Mingle...\n[2017-03-17 15:10:29,912: DEBUG/MainProcess] | Consumer: Restarting Events...\n[2017-03-17 15:10:29,953: DEBUG/MainProcess] | Consumer: Restarting Connection...\n[2017-03-17 15:10:29,954: DEBUG/MainProcess] | Consumer: Starting Connection\n[2017-03-17 15:10:30,036: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@rabbitmq1:5672//: [Errno 111] Connection refused.\nWill retry using next failover.\n```\n\nUnfortunately, Celery documentation doesn't say much about failover topic.\n\n========================================\n\nCode:\n```text\nrabbitmqctl set_policy ha-all \"\" '{\"ha-mode\":\"all\",\"ha-sync-mode\":\"automatic\"}'\n```\n\n```text\nCELERY = dict(\n broker_url=[\n 'amqp://guest@rabbitmq1:5672',\n 'amqp://guest@rabbitmq2:5672',\n 'amqp://guest@rabbitmq3:5672',\n ],\n celery_queue_ha_policy='all',\n ...\n)\n```\n\n```text\nrabbitmqctl stop_app\n```\n\n```text\n[2017-03-17 15:10:28,084: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@rabbitmq1:5672//: [Errno 111] Connection refused.\nWill retry using next failover.\n\n[2017-03-17 15:10:28,300: DEBUG/MainProcess] Start from server, version: 0.9, properties: {'information': 'Licensed under the MPL. See http://www.rabbitmq.com/', 'product': 'RabbitMQ', 'copyright': 'Copyright (C) 2007-2016 Pivotal Software, Inc.', 'capabilities': {'exchange_exchange_bindings': True, 'connection.blocked': True, 'authentication_failure_close': True, 'direct_reply_to': True, 'basic.nack': True, 'per_consumer_qos': True, 'consumer_priorities': True, 'consumer_cancel_notify': True, 'publisher_confirms': True}, 'cluster_name': 'rabbit@rabbitmq1', 'platform': 'Erlang/OTP', 'version': '3.6.6'}, mechanisms: [u'PLAIN', u'AMQPLAIN'], locales: [u'en_US']\n[2017-03-17 15:10:28,302: DEBUG/MainProcess] ^-- substep ok\n[2017-03-17 15:10:28,303: DEBUG/MainProcess] | Consumer: Starting Mingle\n[2017-03-17 15:10:28,303: INFO/MainProcess] mingle: searching for neighbors\n[2017-03-17 15:10:28,303: DEBUG/MainProcess] using channel_id: 1\n[2017-03-17 15:10:28,318: DEBUG/MainProcess] Channel open\n[2017-03-17 15:10:28,470: WARNING/MainProcess] consumer: Connection to broker lost. Trying to re-establish the connection...\nTraceback (most recent call last):\n File \"/usr/local/lib/python2.7/site-packages/celery/worker/consumer/consumer.py\", line 318, in start\n blueprint.start(self)\n File \"/usr/local/lib/python2.7/site-packages/celery/bootsteps.py\", line 119, in start\n step.start(parent)\n File \"/usr/local/lib/python2.7/site-packages/celery/worker/consumer/mingle.py\", line 38, in start\n self.sync(c)\n File \"/usr/local/lib/python2.7/site-packages/celery/worker/consumer/mingle.py\", line 42, in sync\n replies = self.send_hello(c)\n File \"/usr/local/lib/python2.7/site-packages/celery/worker/consumer/mingle.py\", line 55, in send_hello\n replies = inspect.hello(c.hostname, our_revoked._data) or {}\n File \"/usr/local/lib/python2.7/site-packages/celery/app/control.py\", line 129, in hello\n return self._request('hello', from_node=from_node, revoked=revoked)\n File \"/usr/local/lib/python2.7/site-packages/celery/app/control.py\", line 81, in _request\n timeout=self.timeout, reply=True,\n File \"/usr/local/lib/python2.7/site-packages/celery/app/control.py\", line 436, in broadcast\n limit, callback, channel=channel,\n File \"/usr/local/lib/python2.7/site-packages/kombu/pidbox.py\", line 315, in _broadcast\n serializer=serializer)\n File \"/usr/local/lib/python2.7/site-packages/kombu/pidbox.py\", line 290, in _publish\n serializer=serializer,\n File \"/usr/local/lib/python2.7/site-packages/kombu/messaging.py\", line 181, in publish\n exchange_name, declare,\n File \"/usr/local/lib/python2.7/site-packages/kombu/messaging.py\", line 187, in _publish\n channel = self.channel\n File \"/usr/local/lib/python2.7/site-packages/kombu/messaging.py\", line 209, in _get_channel\n channel = self._channel = channel()\n File \"/usr/local/lib/python2.7/site-packages/kombu/utils/functional.py\", line 38, in __call__\n value = self.__value__ = self.__contract__()\n File \"/usr/local/lib/python2.7/site-packages/kombu/messaging.py\", line 224, in <lambda>\n channel = ChannelPromise(lambda: connection.default_channel)\n File \"/usr/local/lib/python2.7/site-packages/kombu/connection.py\", line 819, in default_channel\n self.connection\n File \"/usr/local/lib/python2.7/site-packages/kombu/connection.py\", line 802, in connection\n self._connection = self._establish_connection()\n File \"/usr/local/lib/python2.7/site-packages/kombu/connection.py\", line 757, in _establish_connection\n conn = self.transport.establish_connection()\n File \"/usr/local/lib/python2.7/site-packages/kombu/transport/pyamqp.py\", line 130, in establish_connection\n conn.connect()\n File \"/usr/local/lib/python2.7/site-packages/amqp/connection.py\", line 294, in connect\n self.transport.connect()\n File \"/usr/local/lib/python2.7/site-packages/amqp/transport.py\", line 120, in connect\n self._connect(self.host, self.port, self.connect_timeout)\n File \"/usr/local/lib/python2.7/site-packages/amqp/transport.py\", line 161, in _connect\n self.sock.connect(sa)\n File \"/usr/local/lib/python2.7/socket.py\", line 228, in meth\n return getattr(self._sock,name)(*args)\nerror: [Errno 111] Connection refused\n[2017-03-17 15:10:28,508: DEBUG/MainProcess] Closed channel #1\n[2017-03-17 15:10:28,570: DEBUG/MainProcess] | Consumer: Restarting event loop...\n[2017-03-17 15:10:28,572: DEBUG/MainProcess] | Consumer: Restarting Gossip...\n[2017-03-17 15:10:28,575: DEBUG/MainProcess] | Consumer: Restarting Heart...\n[2017-03-17 15:10:28,648: DEBUG/MainProcess] | Consumer: Restarting Control...\n[2017-03-17 15:10:28,655: DEBUG/MainProcess] | Consumer: Restarting Tasks...\n[2017-03-17 15:10:28,655: DEBUG/MainProcess] Canceling task consumer...\n[2017-03-17 15:10:28,655: DEBUG/MainProcess] | Consumer: Restarting Mingle...\n[2017-03-17 15:10:28,655: DEBUG/MainProcess] | Consumer: Restarting Events...\n[2017-03-17 15:10:28,672: DEBUG/MainProcess] | Consumer: Restarting Connection...\n[2017-03-17 15:10:28,673: DEBUG/MainProcess] | Consumer: Starting Connection\n[2017-03-17 15:10:28,947: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@rabbitmq1:5672//: [Errno 111] Connection refused.\nWill retry using next failover.\n\n[2017-03-17 15:10:29,345: DEBUG/MainProcess] Start from server, version: 0.9, properties: {'information': 'Licensed under the MPL. See http://www.rabbitmq.com/', 'product': 'RabbitMQ', 'copyright': 'Copyright (C) 2007-2016 Pivotal Software, Inc.', 'capabilities': {'exchange_exchange_bindings': True, 'connection.blocked': True, 'authentication_failure_close': True, 'direct_reply_to': True, 'basic.nack': True, 'per_consumer_qos': True, 'consumer_priorities': True, 'consumer_cancel_notify': True, 'publisher_confirms': True}, 'cluster_name': 'rabbit@rabbitmq1', 'platform': 'Erlang/OTP', 'version': '3.6.6'}, mechanisms: [u'PLAIN', u'AMQPLAIN'], locales: [u'en_US']\n[2017-03-17 15:10:29,506: INFO/MainProcess] Connected to amqp://guest:**@rabbitmq2:5672//\n[2017-03-17 15:10:29,535: DEBUG/MainProcess] ^-- substep ok\n[2017-03-17 15:10:29,569: DEBUG/MainProcess] | Consumer: Starting Events\n[2017-03-17 15:10:29,682: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@rabbitmq1:5672//: [Errno 111] Connection refused.\nWill retry using next failover.\n\n[2017-03-17 15:10:29,740: DEBUG/MainProcess] Start from server, version: 0.9, properties: {'information': 'Licensed under the MPL. See http://www.rabbitmq.com/', 'product': 'RabbitMQ', 'copyright': 'Copyright (C) 2007-2016 Pivotal Software, Inc.', 'capabilities': {'exchange_exchange_bindings': True, 'connection.blocked': True, 'authentication_failure_close': True, 'direct_reply_to': True, 'basic.nack': True, 'per_consumer_qos': True, 'consumer_priorities': True, 'consumer_cancel_notify': True, 'publisher_confirms': True}, 'cluster_name': 'rabbit@rabbitmq1', 'platform': 'Erlang/OTP', 'version': '3.6.6'}, mechanisms: [u'PLAIN', u'AMQPLAIN'], locales: [u'en_US']\n[2017-03-17 15:10:29,768: DEBUG/MainProcess] ^-- substep ok\n[2017-03-17 15:10:29,770: DEBUG/MainProcess] | Consumer: Starting Mingle\n[2017-03-17 15:10:29,770: INFO/MainProcess] mingle: searching for neighbors\n[2017-03-17 15:10:29,771: DEBUG/MainProcess] using channel_id: 1\n[2017-03-17 15:10:29,795: DEBUG/MainProcess] Channel open\n[2017-03-17 15:10:29,874: WARNING/MainProcess] consumer: Connection to broker lost. Trying to re-establish the connection...\nTraceback (most recent call last):\n File \"/usr/local/lib/python2.7/site-packages/celery/worker/consumer/consumer.py\", line 318, in start\n blueprint.start(self)\n File \"/usr/local/lib/python2.7/site-packages/celery/bootsteps.py\", line 119, in start\n step.start(parent)\n File \"/usr/local/lib/python2.7/site-packages/celery/worker/consumer/mingle.py\", line 38, in start\n self.sync(c)\n File \"/usr/local/lib/python2.7/site-packages/celery/worker/consumer/mingle.py\", line 42, in sync\n replies = self.send_hello(c)\n File \"/usr/local/lib/python2.7/site-packages/celery/worker/consumer/mingle.py\", line 55, in send_hello\n replies = inspect.hello(c.hostname, our_revoked._data) or {}\n File \"/usr/local/lib/python2.7/site-packages/celery/app/control.py\", line 129, in hello\n return self._request('hello', from_node=from_node, revoked=revoked)\n File \"/usr/local/lib/python2.7/site-packages/celery/app/control.py\", line 81, in _request\n timeout=self.timeout, reply=True,\n File \"/usr/local/lib/python2.7/site-packages/celery/app/control.py\", line 436, in broadcast\n limit, callback, channel=channel,\n File \"/usr/local/lib/python2.7/site-packages/kombu/pidbox.py\", line 315, in _broadcast\n serializer=serializer)\n File \"/usr/local/lib/python2.7/site-packages/kombu/pidbox.py\", line 290, in _publish\n serializer=serializer,\n File \"/usr/local/lib/python2.7/site-packages/kombu/messaging.py\", line 181, in publish\n exchange_name, declare,\n File \"/usr/local/lib/python2.7/site-packages/kombu/messaging.py\", line 187, in _publish\n channel = self.channel\n File \"/usr/local/lib/python2.7/site-packages/kombu/messaging.py\", line 209, in _get_channel\n channel = self._channel = channel()\n File \"/usr/local/lib/python2.7/site-packages/kombu/utils/functional.py\", line 38, in __call__\n value = self.__value__ = self.__contract__()\n File \"/usr/local/lib/python2.7/site-packages/kombu/messaging.py\", line 224, in <lambda>\n channel = ChannelPromise(lambda: connection.default_channel)\n File \"/usr/local/lib/python2.7/site-packages/kombu/connection.py\", line 819, in default_channel\n self.connection\n File \"/usr/local/lib/python2.7/site-packages/kombu/connection.py\", line 802, in connection\n self._connection = self._establish_connection()\n File \"/usr/local/lib/python2.7/site-packages/kombu/connection.py\", line 757, in _establish_connection\n conn = self.transport.establish_connection()\n File \"/usr/local/lib/python2.7/site-packages/kombu/transport/pyamqp.py\", line 130, in establish_connection\n conn.connect()\n File \"/usr/local/lib/python2.7/site-packages/amqp/connection.py\", line 294, in connect\n self.transport.connect()\n File \"/usr/local/lib/python2.7/site-packages/amqp/transport.py\", line 120, in connect\n self._connect(self.host, self.port, self.connect_timeout)\n File \"/usr/local/lib/python2.7/site-packages/amqp/transport.py\", line 161, in _connect\n self.sock.connect(sa)\n File \"/usr/local/lib/python2.7/socket.py\", line 228, in meth\n return getattr(self._sock,name)(*args)\nerror: [Errno 111] Connection refused\n[2017-03-17 15:10:29,887: DEBUG/MainProcess] Closed channel #1\n[2017-03-17 15:10:29,907: DEBUG/MainProcess] | Consumer: Restarting event loop...\n[2017-03-17 15:10:29,908: DEBUG/MainProcess] | Consumer: Restarting Gossip...\n[2017-03-17 15:10:29,908: DEBUG/MainProcess] | Consumer: Restarting Heart...\n[2017-03-17 15:10:29,908: DEBUG/MainProcess] | Consumer: Restarting Control...\n[2017-03-17 15:10:29,909: DEBUG/MainProcess] | Consumer: Restarting Tasks...\n[2017-03-17 15:10:29,910: DEBUG/MainProcess] Canceling task consumer...\n[2017-03-17 15:10:29,911: DEBUG/MainProcess] | Consumer: Restarting Mingle...\n[2017-03-17 15:10:29,912: DEBUG/MainProcess] | Consumer: Restarting Events...\n[2017-03-17 15:10:29,953: DEBUG/MainProcess] | Consumer: Restarting Connection...\n[2017-03-17 15:10:29,954: DEBUG/MainProcess] | Consumer: Starting Connection\n[2017-03-17 15:10:30,036: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@rabbitmq1:5672//: [Errno 111] Connection refused.\nWill retry using next failover.\n```\n\n```text\ncelery worker -A app.tasks -l debug --without-mingle\n```\n\n```text\n--without-mingle\n```\n\n========================================\n\nComments:\n- can you please let me know why --without-mingle option will avoid the bug?","metadata":{"transformedAt":"2026-08-18T18:33:20.201Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":376,"estimatedTokens":6259}}915{"id":"stack-55570531","source":"stackoverflow","questionId":55570531,"title":"Apt-cacher-ng 403 forbidden on specific package","tags":["ubuntu","caching","rabbitmq","apt"],"text":"Title: Apt-cacher-ng 403 forbidden on specific package\nTags: ubuntu, caching, rabbitmq, apt\nSource: Stack Overflow\n\nQuestion:\nPackage: apt-cacher-ng\nVersion: 3.1-1\n\nWe've configured an apt proxy server with apt-cacher-ng, while it works for most packages, when trying to install rabbitmq-server with mentioning a specific version it fails with 403 error.\nAny attempts to use regex in the V/PfilePatternEx ended up with the same result.\n\nWe are using ubuntu 18.04.2 on both server and client\n\non the client side it looks like this:\n\n```\nErr:1 http://dl.bintray.com/rabbitmq/debian xenial/main amd64 rabbitmq-server all 3.6.15-1\n 403 Forbidden\nE: Failed to fetch http://dl.bintray.com/rabbitmq/debian/pool/rabbitmq-server/rabbitmq-server_3.6.15-1_all.deb 403 Forbidden\n\nE: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?\n```\n\nand in the /var/log/apt-cacher-ng/apt-cacher.log on the proxy server:\n\n```\n1554714729|I|436|apt-cacher-client|dl.bintray.com/rabbitmq/debian/pool/rabbitmq-server/rabbitmq-server_3.6.16-1_all.deb [HTTP error, code: 403]\n\n1554714729|E|1173|apt-cacher-client|dl.bintray.com/rabbitmq/debian/pool/rabbitmq-server/rabbitmq-server_3.6.16-1_all.deb [HTTP error, code: 403]\n```\n\nAny bug-fix we tried had the same result.\n\nAny help will be appreciated, thanks!\n\n========================================\n\nCode:\n```text\nErr:1 http://dl.bintray.com/rabbitmq/debian xenial/main amd64 rabbitmq-server all 3.6.15-1\n 403 Forbidden\nE: Failed to fetch http://dl.bintray.com/rabbitmq/debian/pool/rabbitmq-server/rabbitmq-server_3.6.15-1_all.deb 403 Forbidden\n\nE: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?\n```\n\n```text\n1554714729|I|436|apt-cacher-client|dl.bintray.com/rabbitmq/debian/pool/rabbitmq-server/rabbitmq-server_3.6.16-1_all.deb [HTTP error, code: 403]\n\n1554714729|E|1173|apt-cacher-client|dl.bintray.com/rabbitmq/debian/pool/rabbitmq-server/rabbitmq-server_3.6.16-1_all.deb [HTTP error, code: 403]\n```\n\n```text\nUserAgent: Debian APT-HTTP/1.3 (1.6.10)\n```\n\n```text\nUserAgent\n```\n\n```text\n/etc/apt-cacher-ng/acng.conf\n```\n\n========================================\n\nComments:\n- Read this my answer: stackoverflow.com/questions/62226563/…","metadata":{"transformedAt":"2026-08-18T18:33:20.201Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":68,"estimatedTokens":559}}916{"id":"stack-37873433","source":"stackoverflow","questionId":37873433,"title":"Spring Cloud Config Server + RabbitMQ","tags":["spring","spring-boot","rabbitmq","cloud-foundry"],"text":"Title: Spring Cloud Config Server + RabbitMQ\nTags: spring, spring-boot, rabbitmq, cloud-foundry\nSource: Stack Overflow\n\nQuestion:\nI created spring cloud config server and client and they work as expected. I have added @RefreshScope to my client and I am able to see the new properties getting fetched after hitting /refresh endpoint. But I was told that when I deploy it in cloud foundry environment , I must integrate it with RabbitMQ in order for all the instances to receive the refresh message. Is it possible to point me to a link which explains this problem and solution in detail?\n\n========================================\n\nTop Answer:\nSo I assume your application runs as single instance configuration. In that case, you don't need spring cloud bus based refresh and just hitting the {app}/actuator/refresh would be enough. Only if you scale out your app, we would need such setup with a queue like RabbitMQ or kakfa.","metadata":{"transformedAt":"2026-08-18T18:33:20.201Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":11,"estimatedTokens":232}}917{"id":"stack-32432018","source":"stackoverflow","questionId":32432018,"title":"None of the specified endpoints were reachable","tags":["c#",".net","rabbitmq"],"text":"Title: None of the specified endpoints were reachable\nTags: c#, .net, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nThere is intermittent issue in rabbitmq while publishing message from .net application. It is creating lots of noise in the system. \nI have tried googling but could not found root cause of an issue.\n\nHere is the error I can see in application log,\n\n```\nNone of the specified endpoints were reachable\nEndpoints attempted:\n------------------------------------------------\nendpoint=amqp-0-9://localhost:5672, attempts=1\nSystem.TimeoutException: Connection to amqp-0-9://localhost:5672 timed out\n at RabbitMQ.Client.Impl.SocketFrameHandler_0_9.Connect(TcpClient socket, AmqpTcpEndpoint endpoint, Int32 timeout)\n at RabbitMQ.Client.Impl.SocketFrameHandler_0_9..ctor(AmqpTcpEndpoint endpoint, ObtainSocket socketFactory, Int32 timeout)\n at RabbitMQ.Client.Framing.Impl.v0_9_1.ProtocolBase.CreateFrameHandler(AmqpTcpEndpoint endpoint, ObtainSocket socketFactory, Int32 timeout)\n at RabbitMQ.Client.ConnectionFactory.FollowRedirectChain(Int32 maxRedirects, IDictionary`2 connectionAttempts, IDictionary`2 connectionErrors, AmqpTcpEndpoint[]& mostRecentKnownHosts, AmqpTcpEndpoint endpoint)\n================================================\nStack trace:\n at RabbitMQ.Client.ConnectionFactory.CreateConnection(Int32 maxRedirects)\n at RabbitMQ.Client.ConnectionFactory.CreateConnection()\n```\n\n========================================\n\nCode:\n```text\nNone of the specified endpoints were reachable\nEndpoints attempted:\n------------------------------------------------\nendpoint=amqp-0-9://localhost:5672, attempts=1\nSystem.TimeoutException: Connection to amqp-0-9://localhost:5672 timed out\n at RabbitMQ.Client.Impl.SocketFrameHandler_0_9.Connect(TcpClient socket, AmqpTcpEndpoint endpoint, Int32 timeout)\n at RabbitMQ.Client.Impl.SocketFrameHandler_0_9..ctor(AmqpTcpEndpoint endpoint, ObtainSocket socketFactory, Int32 timeout)\n at RabbitMQ.Client.Framing.Impl.v0_9_1.ProtocolBase.CreateFrameHandler(AmqpTcpEndpoint endpoint, ObtainSocket socketFactory, Int32 timeout)\n at RabbitMQ.Client.ConnectionFactory.FollowRedirectChain(Int32 maxRedirects, IDictionary`2 connectionAttempts, IDictionary`2 connectionErrors, AmqpTcpEndpoint[]& mostRecentKnownHosts, AmqpTcpEndpoint endpoint)\n================================================\nStack trace:\n at RabbitMQ.Client.ConnectionFactory.CreateConnection(Int32 maxRedirects)\n at RabbitMQ.Client.ConnectionFactory.CreateConnection()\n```\n\n========================================\n\nComments:\n- are you sure the broker is running? what user name and password are you using?\n- Yes, the broker is running fine. I have other four applications running on my server, the problem is with only one application.\n- do you have a problem only with \"remote\" application? in this case could be a firewall problem\n- @Gas RabbitMQ and applications are on the same machine. So there should not be a firewall problem. Actually, the same is working fine right now, the issue is intermittent.\n- Recommended approach is to have one connection per process and on channel per thread","metadata":{"transformedAt":"2026-08-18T18:33:20.201Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":53,"estimatedTokens":778}}918{"id":"stack-29892408","source":"stackoverflow","questionId":29892408,"title":"What's wrong with RabbitMQ in Spring Boot","tags":["java","maven","rabbitmq","spring-boot"],"text":"Title: What's wrong with RabbitMQ in Spring Boot\nTags: java, maven, rabbitmq, spring-boot\nSource: Stack Overflow\n\nQuestion:\nI am trying to run the sample project from Create a RabbitMQ message receiver.But it's throwing exception\n\n```\njava.lang.IllegalArgumentException: Attribute 'exclude' is of type [Class[]], but [String[]] was expected. Cause: \n at org.springframework.core.annotation.AnnotationAttributes.doGet(AnnotationAttributes.java:117)\n at org.springframework.core.annotation.AnnotationAttributes.getStringArray(AnnotationAttributes.java:70)\n at org.springframework.boot.autoconfigure.EnableAutoConfigurationImportSelector.selectImports(EnableAutoConfigurationImportSelector.java:63)\n at org.springframework.context.annotation.ConfigurationClassParser.processImport(ConfigurationClassParser.java:386)\n at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:204)\n at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:163)\n at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:138)\n at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:284)\n at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:225)\n at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:630)\n at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)\n at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:683)\n at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)\n at org.springframework.boot.SpringApplication.run(SpringApplication.java:944)\n at org.springframework.boot.SpringApplication.run(SpringApplication.java:933)\n at Application.main(Application.java:69)\n at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n at java.lang.reflect.Method.invoke(Method.java:497)\n at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)\n```\n\nHere is my pom.xml\n\n```\n\n 4.0.0\n\n org.springframework\n gs-messaging-rabbitmq\n 0.1.0\n\n \n org.springframework.boot\n spring-boot-starter-parent\n 1.2.3.RELEASE\n \n\n \n \n \n org.springframework.boot\n spring-boot-maven-plugin\n \n \n \n\n \n \n spring-releases\n Spring Releases\n https://repo.spring.io/libs-release\n \n \n \n \n spring-releases\n Spring Releases\n https://repo.spring.io/libs-release\n \n \n\n```\n\nHere is my class file\n\n```\n@SpringBootApplication\npublic class Application implements CommandLineRunner {\n\n final static String queueName = \"spring-boot\";\n\n @Autowired\n AnnotationConfigApplicationContext context;\n\n @Autowired\n RabbitTemplate rabbitTemplate;\n\n @Bean\n Queue queue() {\n return new Queue(queueName, false);\n }\n\n @Bean\n TopicExchange exchange() {\n return new TopicExchange(\"spring-boot-exchange\");\n }\n\n @Bean\n Binding binding(Queue queue, TopicExchange exchange) {\n return BindingBuilder.bind(queue).to(exchange).with(queueName);\n }\n\n @Bean\n SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(connectionFactory);\n container.setQueueNames(queueName);\n container.setMessageListener(listenerAdapter);\n return container;\n }\n\n @Bean\n Receiver receiver() {\n return new Receiver();\n }\n\n @Bean\n MessageListenerAdapter listenerAdapter(Receiver receiver) {\n return new MessageListenerAdapter(receiver, \"receiveMessage\");\n }\n\n public static void main(String[] args) throws InterruptedException {\n SpringApplication.run(Application.class, args);\n }\n\n @Override\n public void run(String... args) throws Exception {\n System.out.println(\"Waiting five seconds...\");\n Thread.sleep(5000);\n System.out.println(\"Sending message...\");\n rabbitTemplate.convertAndSend(queueName, \"Hello from RabbitMQ!\");\n receiver().getLatch().await(10000, TimeUnit.MILLISECONDS);\n context.close();\n }\n}\n```\n\nCan anyone tell me what's wrong with me?Thanks in advance.\n\n========================================\n\nCode:\n```text\njava.lang.IllegalArgumentException: Attribute 'exclude' is of type [Class[]], but [String[]] was expected. Cause: \n at org.springframework.core.annotation.AnnotationAttributes.doGet(AnnotationAttributes.java:117)\n at org.springframework.core.annotation.AnnotationAttributes.getStringArray(AnnotationAttributes.java:70)\n at org.springframework.boot.autoconfigure.EnableAutoConfigurationImportSelector.selectImports(EnableAutoConfigurationImportSelector.java:63)\n at org.springframework.context.annotation.ConfigurationClassParser.processImport(ConfigurationClassParser.java:386)\n at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:204)\n at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:163)\n at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:138)\n at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:284)\n at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:225)\n at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:630)\n at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)\n at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:683)\n at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)\n at org.springframework.boot.SpringApplication.run(SpringApplication.java:944)\n at org.springframework.boot.SpringApplication.run(SpringApplication.java:933)\n at Application.main(Application.java:69)\n at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n at java.lang.reflect.Method.invoke(Method.java:497)\n at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)\n```\n\n```text\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project xmlns=\"http://maven.apache.org/POM/4.0.0\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n <modelVersion>4.0.0</modelVersion>\n\n <groupId>org.springframework</groupId>\n <artifactId>gs-messaging-rabbitmq</artifactId>\n <version>0.1.0</version>\n\n <parent>\n <groupId>org.springframework.boot</groupId>\n <artifactId>spring-boot-starter-parent</artifactId>\n <version>1.2.3.RELEASE</version>\n </parent>\n\n <build>\n <plugins>\n <plugin>\n <groupId>org.springframework.boot</groupId>\n <artifactId>spring-boot-maven-plugin</artifactId>\n </plugin>\n </plugins>\n </build>\n\n <repositories>\n <repository>\n <id>spring-releases</id>\n <name>Spring Releases</name>\n <url>https://repo.spring.io/libs-release</url>\n </repository>\n </repositories>\n <pluginRepositories>\n <pluginRepository>\n <id>spring-releases</id>\n <name>Spring Releases</name>\n <url>https://repo.spring.io/libs-release</url>\n </pluginRepository>\n </pluginRepositories>\n</project>\n```\n\n```text\n@SpringBootApplication\npublic class Application implements CommandLineRunner {\n\n final static String queueName = \"spring-boot\";\n\n @Autowired\n AnnotationConfigApplicationContext context;\n\n @Autowired\n RabbitTemplate rabbitTemplate;\n\n @Bean\n Queue queue() {\n return new Queue(queueName, false);\n }\n\n @Bean\n TopicExchange exchange() {\n return new TopicExchange(\"spring-boot-exchange\");\n }\n\n @Bean\n Binding binding(Queue queue, TopicExchange exchange) {\n return BindingBuilder.bind(queue).to(exchange).with(queueName);\n }\n\n @Bean\n SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(connectionFactory);\n container.setQueueNames(queueName);\n container.setMessageListener(listenerAdapter);\n return container;\n }\n\n @Bean\n Receiver receiver() {\n return new Receiver();\n }\n\n @Bean\n MessageListenerAdapter listenerAdapter(Receiver receiver) {\n return new MessageListenerAdapter(receiver, \"receiveMessage\");\n }\n\n public static void main(String[] args) throws InterruptedException {\n SpringApplication.run(Application.class, args);\n }\n\n @Override\n public void run(String... args) throws Exception {\n System.out.println(\"Waiting five seconds...\");\n Thread.sleep(5000);\n System.out.println(\"Sending message...\");\n rabbitTemplate.convertAndSend(queueName, \"Hello from RabbitMQ!\");\n receiver().getLatch().await(10000, TimeUnit.MILLISECONDS);\n context.close();\n }\n}\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.201Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":272,"estimatedTokens":2500}}919{"id":"stack-25018814","source":"stackoverflow","questionId":25018814,"title":"Websockets, SockJs, Stomp, Spring, RabbitMQ, delete User specific Queues automatically","tags":["java","spring","rabbitmq","sockjs","spring-websocket"],"text":"Title: Websockets, SockJs, Stomp, Spring, RabbitMQ, delete User specific Queues automatically\nTags: java, spring, rabbitmq, sockjs, spring-websocket\nSource: Stack Overflow\n\nQuestion:\nI hope someone can help me with this issue. I am using the Websocket support of Spring with SockJs and StompJs. I subscribed to a queue like this:\n\n```\nvar socket = new SockJS(localhost + 'websocket');\n stompClient = Stomp.over(socket);\n stompClient.connect('', '', function(frame) {\n stompClient.subscribe(\"/user/queue/gotMessage\", function(message) {\n gotMessage((JSON.parse(message.body)));\n });\n }, function(error) {\n });\n```\n\nThis works really fine with the SimpMessageSendingOperations of Spring. BUT there is one big problem. The Queue name looks like this: **gotMessage-user3w4tstcj** and it's not declared as an auto delete queue, but this is what I want. Otherwise, I have 10k unused queues. In that moment where the queue has no consumer, the queue should be deleted. How can I assume this?\n\n========================================\n\nCode:\n```text\nvar socket = new SockJS(localhost + 'websocket');\n stompClient = Stomp.over(socket);\n stompClient.connect('', '', function(frame) {\n stompClient.subscribe(\"/user/queue/gotMessage\", function(message) {\n gotMessage((JSON.parse(message.body)));\n });\n }, function(error) {\n });\n```\n\n```text\n/exchange/\n```\n\n========================================\n\nComments:\n- Looks like some library-specific problem, what did official docs says about cleaning up temporary queues?\n- the only thing that i found was: \"For example RabbitMQ creates auto-delete queue with destinations like '/exchange/amq.direct/a'\" but then there is no user specific sending possible\n- thanks ... that worked. I just forgot to add the '/exchange/' to the stomp broker relay config","metadata":{"transformedAt":"2026-08-18T18:33:20.201Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":44,"estimatedTokens":456}}920{"id":"stack-29330916","source":"stackoverflow","questionId":29330916,"title":"Excel and RabbitMQ - Process RabbitMQ Messages in Excel?","tags":["vba","excel","rabbitmq","excel-2013"],"text":"Title: Excel and RabbitMQ - Process RabbitMQ Messages in Excel?\nTags: vba, excel, rabbitmq, excel-2013\nSource: Stack Overflow\n\nQuestion:\nI would like to subscribe to a RabbitMQ message queue from Excel 2013.\n\nThe ultimate aim is to allow data contained within a MQ message to be processed within Excel and to also allow Excel to send a formatted message via a RabbitMQ message queue. Is this possible?\n\nThe message which is sent down the message queue is comprised of 7 fields, each field is delimited by a ; symbol - however the message is sent as one string over the message queue...\n\ne.g. `\"text;number;number;number;text,text,timestamp\"`\n\nI would like to be able to split the raw message as above, into formatted cells in Excel 2013. Can this be done?\n\nI have limited coding experience and I am trying to learn. Can this be done via VBA code or an Excel Add-In?\n\n========================================\n\nCode:\n```text\n\"text;number;number;number;text,text,timestamp\"\n```\n\n========================================\n\nComments:\n- Just so I understand, you want the Excel Spreadsheet to consume messages from RabbitMQ?\n- Hi Phill, that's right, ideally I'd like to be able to receive a 'string' via a MQ queue and split it into 'fields' so that I can then work with the data formatted in excel.... I'd also like to be able to do the reverse, and send the content of a number of excel cells as a string split by ; symbols, for example. Is this possible and can you give any pointers if so? Many thanks...\n- I don't think there is anything out of the box, I would point you in the direction of using an external data source with excel support.office.com/en-ca/article/… possibly something that might give you some more insight kzhendev.wordpress.com/?s=rabbitmq\n- Thank you Phill, Just checked out the links, some very useful info indeed!\n- Thank you T. I really appreciate the time and energy you have taken with your answer. I'm in the position where I'm a technical IT person, so I do actually understand what you have written (which I'm sure you'll be glad to hear given the time you have taken!)\n- ...but I don't yet have enough practical experience coding to be confidently competent. The information you have provided is excellent and will really help me to make some decisions in terms of if and where to start. This is a personal project rather than anything related to my work so it seems it will also be a good opportunity for learning. Many thanks! (ran into the 5 minute editing lockout rule with first reply :-)","metadata":{"transformedAt":"2026-08-18T18:33:20.201Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":33,"estimatedTokens":633}}921{"id":"stack-36683201","source":"stackoverflow","questionId":36683201,"title":"Is it possible to specify multiple connection points in RMQ .NET?","tags":["c#","rabbitmq"],"text":"Title: Is it possible to specify multiple connection points in RMQ .NET?\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nAs the title states I would like to provided multiple URI's for the RMQ .NET `ConnectionFactory` in the hope that it will fail over automatically to the first available one, rather than being limited to a single URI.\n\n**Setup**\n\nUsing the *Docker Quickstart Terminal* (part of *Docker Toolbox*) I have created *four containers*, each with it's on RMQ instance running on it.\nI have clustered the RMQ nodes as follows:\n\n- Downstream (node1 and node2)\n\n- Upstream (node3 and node4)\n\nThe *Downstream* nodes a Federated Queue with the *Upstream* nodes to increase the throughput.\n\n**Use**\n\nI have written a simple console application in C# that will generate and publish messages to node4 (the primary upstream RMQ instance).\n\nI would like to test the redundancy/automatic failover of my RMQ configuration as I have set the flags for `AutomaticRecoveryEnabled`(docs) and `TopologyRecoveryEnabled`(docs) and have the *Federated Queue* setup.\n\nHowever, the `ConnectionFactory` provided by the RMQ .NET library doesn't appear to support specifying multiple URI's (docs). So I have had to manually code in the handling of switching between the nodes when they go down - I do this by catching the exception thrown when a node is no longer accessible then pinging all nodes to see which is active.\n\n**Is there a way to give ConnectionFactory multiple Rabbit endpoints so that it can failover automatically?**\n\n========================================\n\nTop Answer:\nIf you look at ConnectionFactory it can create a connection with a list of hosts\n\n```\n/// \n /// Create a connection using a list of hostnames. The first reachable\n /// hostname will be used initially. Subsequent hostname picks are determined\n /// by the configured.\n /// \n /// \n /// List of hostnames to use for the initial\n /// connection and recovery.\n /// \n /// Open connection\n /// \n /// When no hostname was reachable.\n /// \n public IConnection CreateConnection(IList hostnames)\n {\n return CreateConnection(hostnames, null);\n }\n```\n\nAnd by the way the below code:\n\n```\nConnectionFactory factory = new ConnectionFactory();\nfactory.Uri = \"amqp://user:pass@hostName:port/vhost\";\nIConnection conn = factory.CreateConnection();\n```\n\nWill call `CreateConnection({UriHostname})` with a list of single element\n\nIf you need a connections list between different cluster (different vhost, username, password...), so the answer is no, you cannot do that with the pivotal client. If only the hostname change, I may works.\n\n========================================\n\nCode:\n```text\nConnectionFactory\n```\n\n```text\nAutomaticRecoveryEnabled\n```\n\n```text\nTopologyRecoveryEnabled\n```\n\n```text\nConnectionFactory\n```\n\n```text\n/// <summary>\n /// Create a connection using a list of hostnames. The first reachable\n /// hostname will be used initially. Subsequent hostname picks are determined\n /// by the <see cref=\"IHostnameSelector\" /> configured.\n /// </summary>\n /// <param name=\"hostnames\">\n /// List of hostnames to use for the initial\n /// connection and recovery.\n /// </param>\n /// <returns>Open connection</returns>\n /// <exception cref=\"BrokerUnreachableException\">\n /// When no hostname was reachable.\n /// </exception>\n public IConnection CreateConnection(IList<string> hostnames)\n {\n return CreateConnection(hostnames, null);\n }\n```\n\n```text\nConnectionFactory factory = new ConnectionFactory();\nfactory.Uri = \"amqp://user:pass@hostName:port/vhost\";\nIConnection conn = factory.CreateConnection();\n```\n\n```text\nCreateConnection({UriHostname})\n```\n\n========================================\n\nComments:\n- Using the C# client provided by pivotal, no. You will have to do exactly what you are doing Im afraid.\n- Thank you for the answer @chris.ellis. If you want to add this as an answer per se I'm happy to mark it as accepted. :-)\n- Thanks for the answer and example @Nicolas, unfortunately I need this to occur between clusters.","metadata":{"transformedAt":"2026-08-18T18:33:20.201Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":120,"estimatedTokens":1013}}922{"id":"stack-36350733","source":"stackoverflow","questionId":36350733,"title":"Run multiple Celery tasks using a topic exchange","tags":["python","rabbitmq","celery","message-queue","messaging"],"text":"Title: Run multiple Celery tasks using a topic exchange\nTags: python, rabbitmq, celery, message-queue, messaging\nSource: Stack Overflow\n\nQuestion:\nI'm replacing some homegrown code with Celery, but having a hard time replicating the current behaviour. My desired behaviour is as follows:\n\n- When creating a new user, a message should be published to the `tasks` exchange with the `user.created` routing key.\n\n- Two Celery tasks should be trigged by this message, namely `send_user_activate_email` and `check_spam`.\n\nI tried implementing this by defining a `user_created` task with a `ignore_result=True` argument, plus a task for `send_user_activate_email` and `check_spam`.\n\nIn my configuration, I added the following routes and queues definitions. While the message is delivered to the `user_created` queue, it is not delivered to the other two queues.\n\nIdeally, the message is only delivery to the `send_user_activate_email` and `check_spam` queues. When using vanilla RabbitMQ, messages are published to an exchange, to which queues can bind, but Celery seems to deliver a message to a queue directly.\n\nHow would I implement the behaviour outlined above in Celery?\n\n```\nCELERY_QUEUES = {\n 'user_created': {'binding_key':'user.created', 'exchange': 'tasks', 'exchange_type': 'topic'},\n 'send_user_activate_email': {'binding_key':'user.created', 'exchange': 'tasks', 'exchange_type': 'topic'},\n 'check_spam': {'binding_key':'user.created', 'exchange': 'tasks', 'exchange_type': 'topic'},\n}\n\nCELERY_ROUTES = {\n 'user_created': {\n 'queue': 'user_created',\n 'routing_key': 'user.created',\n 'exchange': 'tasks',\n 'exchange_type': 'topic',\n },\n 'send_user_activate_email': {\n 'queue': 'user_created',\n 'routing_key': 'user.created',\n 'exchange': 'tasks',\n 'exchange_type': 'topic',\n },\n 'check_spam': {\n 'queue': 'user_created',\n 'routing_key': 'user.created',\n 'exchange': 'tasks',\n 'exchange_type': 'topic',\n },\n}\n```\n\n========================================\n\nTop Answer:\nThe easy way to dessign and resolve your problem is usign Celery workflows.\n\nBut first of all I'd change your queue definition, setting a unique routing key per task and exchange_type with 'direct' value.\n\nAccording with celery documentation, **Direct exchanges match by exact routing keys**, so we set the same exchange to all custom tasks and consumer queues and we map routing_key (for tasks) and binding_key (for queues) like the next snippet:\n\n```\nCELERY_QUEUES = {\n 'user_created': {'binding_key':'user_created', 'exchange': 'tasks', 'exchange_type': 'direct'},\n 'send_user_activate_email': {'binding_key':'send_user_activate_email', 'exchange': 'tasks', 'exchange_type': 'direct'},\n 'check_spam': {'binding_key':'check_spam', 'exchange': 'tasks', 'exchange_type': 'direct'},\n}\n\nCELERY_ROUTES = {\n 'user_created': {\n 'queue': 'user_created',\n 'routing_key': 'user_created',\n 'exchange': 'tasks',\n 'exchange_type': 'direct',\n },\n 'send_user_activate_email': {\n 'queue': 'send_user_activate_email',\n 'routing_key': 'send_user_activate_email',\n 'exchange': 'tasks',\n 'exchange_type': 'direct',\n },\n 'check_spam': {\n 'queue': 'check_spam',\n 'routing_key': 'check_spam',\n 'exchange': 'tasks',\n 'exchange_type': 'direct',\n },\n}\n```\n\nOnce this change is done, you need to use the proper workflow for the available list (http://docs.celeryproject.org/en/latest/userguide/canvas.html#the-primitives). Reading your problem I think you need a chain, because order is needed to be preserved.\n\n```\nsequential_tasks = []\nsequential_tasks.append(user_created.s(**user_created_kwargs))\nsequential_tasks.append(send_user_activate_email.s(**send_user_activate_email_kwargs))\nsequential_tasks.append(check_spam.s(**check_spam_kwargs))\n#you can add more tasks to the chain\nchain(*sequential_tasks)()\n```\n\nCelery will handle queue-related-work transparently.\n\n========================================\n\nCode:\n```text\nCELERY_QUEUES = {\n 'user_created': {'binding_key':'user.created', 'exchange': 'tasks', 'exchange_type': 'topic'},\n 'send_user_activate_email': {'binding_key':'user.created', 'exchange': 'tasks', 'exchange_type': 'topic'},\n 'check_spam': {'binding_key':'user.created', 'exchange': 'tasks', 'exchange_type': 'topic'},\n}\n\nCELERY_ROUTES = {\n 'user_created': {\n 'queue': 'user_created',\n 'routing_key': 'user.created',\n 'exchange': 'tasks',\n 'exchange_type': 'topic',\n },\n 'send_user_activate_email': {\n 'queue': 'user_created',\n 'routing_key': 'user.created',\n 'exchange': 'tasks',\n 'exchange_type': 'topic',\n },\n 'check_spam': {\n 'queue': 'user_created',\n 'routing_key': 'user.created',\n 'exchange': 'tasks',\n 'exchange_type': 'topic',\n },\n}\n```\n\n```text\ntasks\n```\n\n```text\nuser.created\n```\n\n```text\nsend_user_activate_email\n```\n\n```text\ncheck_spam\n```\n\n```text\nuser_created\n```\n\n```text\nignore_result=True\n```\n\n```text\nsend_user_activate_email\n```\n\n```text\ncheck_spam\n```\n\n```text\nuser_created\n```\n\n```text\nsend_user_activate_email\n```\n\n```text\ncheck_spam\n```\n\n```text\n#pseudocode\ngroup(check_spam.s(... checkspam kwargs ...), send_user_activate_email.s(... active email kwargs ...)).apply_async()\n```\n\n```text\nCELERY_QUEUES = {\n 'user_created': {'binding_key':'user_created', 'exchange': 'tasks', 'exchange_type': 'direct'},\n 'send_user_activate_email': {'binding_key':'send_user_activate_email', 'exchange': 'tasks', 'exchange_type': 'direct'},\n 'check_spam': {'binding_key':'check_spam', 'exchange': 'tasks', 'exchange_type': 'direct'},\n}\n\nCELERY_ROUTES = {\n 'user_created': {\n 'queue': 'user_created',\n 'routing_key': 'user_created',\n 'exchange': 'tasks',\n 'exchange_type': 'direct',\n },\n 'send_user_activate_email': {\n 'queue': 'send_user_activate_email',\n 'routing_key': 'send_user_activate_email',\n 'exchange': 'tasks',\n 'exchange_type': 'direct',\n },\n 'check_spam': {\n 'queue': 'check_spam',\n 'routing_key': 'check_spam',\n 'exchange': 'tasks',\n 'exchange_type': 'direct',\n },\n}\n```\n\n```text\nsequential_tasks = []\nsequential_tasks.append(user_created.s(**user_created_kwargs))\nsequential_tasks.append(send_user_activate_email.s(**send_user_activate_email_kwargs))\nsequential_tasks.append(check_spam.s(**check_spam_kwargs))\n#you can add more tasks to the chain\nchain(*sequential_tasks)()\n```\n\n========================================\n\nComments:\n- Thanks for your elaborate explanation. Gathering from your answer and the docs, Celery uses the routing_key for distributing tasks across workers, rather than having multiple tasks response to a single message. This basically forces you to tightly couple the code that triggers a task and processes the task. Is this correct?\n- @joelcox, I think that's a great summary. The exceptions to this rule are Map() and Starmap(), which I believe execute a task for each element in a sequence, but only send a single message. If you want tasks to respond to one another (say, waiting for another to succeed as it needs metadata to continue), you can also look into Chain(), Chord().\n- Could you explain why I would need separate exchange for each task? The send_user_activate_email and check_spam tasks can run in parallel, if that matters.","metadata":{"transformedAt":"2026-08-18T18:33:20.202Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":15,"totalLines":224,"estimatedTokens":1820}}923{"id":"stack-34156499","source":"stackoverflow","questionId":34156499,"title":"RabbitMqBundle consumer exiting with exception \"Error reading data. Received 0 instead of expected 1 byte\" and \"Broken pipe or closed connection\"","tags":["php","symfony","rabbitmq"],"text":"Title: RabbitMqBundle consumer exiting with exception \"Error reading data. Received 0 instead of expected 1 byte\" and \"Broken pipe or closed connection\"\nTags: php, symfony, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nPreviously asked questions with same exception message did not solve my problem.\n\nI have a consumer that is called from the command line, using the standard bundle cli command:\n\n```\napp/console rabbitmq:consumer -m 120 myproject_download\n```\n\nAfter consuming a few messages and performing the task as it should, it exits with the following exception:\n\n```\n[PhpAmqpLib\\Exception\\AMQPIOException]\nError reading data. Received 0 instead of expected 1 bytes\n\nrabbitmq:consumer [-m|--messages [MESSAGES]] [-r|--route [ROUTE]] [-l|--memory-limit [MEMORY-LIMIT]] [-d|--debug] [-w|--without-signals] [--] \n\nPHP Fatal error: Uncaught exception 'PhpAmqpLib\\Exception\\AMQPIOException' with message 'Error reading data. Received 0 instead of expected 7 bytes' in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:161\nStack trace:\n#0 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(147): PhpAmqpLib\\Wire\\IO\\StreamIO->read(7)\n#1 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(105): PhpAmqpLib\\Wire\\AMQPReader->rawread(7)\n#2 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(528): PhpAmqpLib\\Wire\\AMQPReader->read(7)\n#3 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(568): PhpAmqpLib\\Connection\\AbstractConnection->wait_frame(0)\n#4 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(214): PhpAmqpLib\\Connection\\AbstractConnection->wait_channel(1, 0)\n#5 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Chan in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php on line 161\n\nFatal error: Uncaught exception 'PhpAmqpLib\\Exception\\AMQPIOException' with message 'Error reading data. Received 0 instead of expected 7 bytes' in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:161\nStack trace:\n#0 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(147): PhpAmqpLib\\Wire\\IO\\StreamIO->read(7)\n#1 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(105): PhpAmqpLib\\Wire\\AMQPReader->rawread(7)\n#2 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(528): PhpAmqpLib\\Wire\\AMQPReader->read(7)\n#3 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(568): PhpAmqpLib\\Connection\\AbstractConnection->wait_frame(0)\n#4 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(214): PhpAmqpLib\\Connection\\AbstractConnection->wait_channel(1, 0)\n#5 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Chan in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php on line 161\n```\n\nInside the consumer I also send a message to a new queue. Using the standard Symfony dependency injection. If I leave out sending this message, the following exception is shown, for the exact same procedure:\n\n```\n[PhpAmqpLib\\Exception\\AMQPRuntimeException]\nBroken pipe or closed connection\n\nrabbitmq:consumer [-m|--messages [MESSAGES]] [-r|--route [ROUTE]] [-l|--memory-limit [MEMORY-LIMIT]] [-d|--debug] [-w|--without-signals] [--] \n\nPHP Fatal error: Uncaught exception 'PhpAmqpLib\\Exception\\AMQPRuntimeException' with message 'Broken pipe or closed connection' in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:190\nStack trace:\n#0 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(336): PhpAmqpLib\\Wire\\IO\\StreamIO->write('\\x01\\x00\\x01\\x00\\x00\\x00\\v\\x00\\x14\\x00(\\x00\\x00\\x00\\x00...')\n#1 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(457): PhpAmqpLib\\Connection\\AbstractConnection->write('\\x01\\x00\\x01\\x00\\x00\\x00\\v\\x00\\x14\\x00(\\x00\\x00\\x00\\x00...')\n#2 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(223): PhpAmqpLib\\Connection\\AbstractConnection->send_channel_method_frame(1, Array, Object(PhpAmqpLib\\Wire\\AMQPWriter))\n#3 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AMQPChannel.php(170): PhpAmqpLib\\Channel\\AbstractChannel->send_method_frame(Array, Object(PhpAmqpLib\\Wire\\A in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php on line 190\n\nFatal error: Uncaught exception 'PhpAmqpLib\\Exception\\AMQPRuntimeException' with message 'Broken pipe or closed connection' in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:190\nStack trace:\n#0 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(336): PhpAmqpLib\\Wire\\IO\\StreamIO->write('\\x01\\x00\\x01\\x00\\x00\\x00\\v\\x00\\x14\\x00(\\x00\\x00\\x00\\x00...')\n#1 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(457): PhpAmqpLib\\Connection\\AbstractConnection->write('\\x01\\x00\\x01\\x00\\x00\\x00\\v\\x00\\x14\\x00(\\x00\\x00\\x00\\x00...')\n#2 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(223): PhpAmqpLib\\Connection\\AbstractConnection->send_channel_method_frame(1, Array, Object(PhpAmqpLib\\Wire\\AMQPWriter))\n#3 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AMQPChannel.php(170): PhpAmqpLib\\Channel\\AbstractChannel->send_method_frame(Array, Object(PhpAmqpLib\\Wire\\A in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php on line 190\n```\n\nStarting the consumer again, has the same effect. A few messages are consumed and then it exits again.\n\nIn php.ini max_execution_time and max_input_time are a lot higher than the time it takes for the exception to occur.\n\nAnd the Symfony config.yml looks like this:\n\n```\n# rabbitmq\nold_sound_rabbit_mq:\n connections:\n default:\n host: '192.168.99.100'\n port: 5672\n user: 'guest'\n password: 'guest'\n vhost: '/'\n lazy: false\n connection_timeout: 4\n read_write_timeout: 4\n\n # requires php-amqplib v2.4.1+ and PHP5.4+\n keepalive: false\n\n # requires php-amqplib v2.4.1+\n heartbeat: 2\n```\n\n**What is going on? And how to stop it from exiting until all messages have been consumed?**\n\n========================================\n\nCode:\n```text\napp/console rabbitmq:consumer -m 120 myproject_download\n```\n\n```text\n[PhpAmqpLib\\Exception\\AMQPIOException]\nError reading data. Received 0 instead of expected 1 bytes\n\nrabbitmq:consumer [-m|--messages [MESSAGES]] [-r|--route [ROUTE]] [-l|--memory-limit [MEMORY-LIMIT]] [-d|--debug] [-w|--without-signals] [--] <name>\n\nPHP Fatal error: Uncaught exception 'PhpAmqpLib\\Exception\\AMQPIOException' with message 'Error reading data. Received 0 instead of expected 7 bytes' in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:161\nStack trace:\n#0 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(147): PhpAmqpLib\\Wire\\IO\\StreamIO->read(7)\n#1 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(105): PhpAmqpLib\\Wire\\AMQPReader->rawread(7)\n#2 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(528): PhpAmqpLib\\Wire\\AMQPReader->read(7)\n#3 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(568): PhpAmqpLib\\Connection\\AbstractConnection->wait_frame(0)\n#4 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(214): PhpAmqpLib\\Connection\\AbstractConnection->wait_channel(1, 0)\n#5 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Chan in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php on line 161\n\nFatal error: Uncaught exception 'PhpAmqpLib\\Exception\\AMQPIOException' with message 'Error reading data. Received 0 instead of expected 7 bytes' in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:161\nStack trace:\n#0 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(147): PhpAmqpLib\\Wire\\IO\\StreamIO->read(7)\n#1 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(105): PhpAmqpLib\\Wire\\AMQPReader->rawread(7)\n#2 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(528): PhpAmqpLib\\Wire\\AMQPReader->read(7)\n#3 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(568): PhpAmqpLib\\Connection\\AbstractConnection->wait_frame(0)\n#4 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(214): PhpAmqpLib\\Connection\\AbstractConnection->wait_channel(1, 0)\n#5 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Chan in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php on line 161\n```\n\n```text\n[PhpAmqpLib\\Exception\\AMQPRuntimeException]\nBroken pipe or closed connection\n\nrabbitmq:consumer [-m|--messages [MESSAGES]] [-r|--route [ROUTE]] [-l|--memory-limit [MEMORY-LIMIT]] [-d|--debug] [-w|--without-signals] [--] <name>\n\nPHP Fatal error: Uncaught exception 'PhpAmqpLib\\Exception\\AMQPRuntimeException' with message 'Broken pipe or closed connection' in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:190\nStack trace:\n#0 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(336): PhpAmqpLib\\Wire\\IO\\StreamIO->write('\\x01\\x00\\x01\\x00\\x00\\x00\\v\\x00\\x14\\x00(\\x00\\x00\\x00\\x00...')\n#1 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(457): PhpAmqpLib\\Connection\\AbstractConnection->write('\\x01\\x00\\x01\\x00\\x00\\x00\\v\\x00\\x14\\x00(\\x00\\x00\\x00\\x00...')\n#2 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(223): PhpAmqpLib\\Connection\\AbstractConnection->send_channel_method_frame(1, Array, Object(PhpAmqpLib\\Wire\\AMQPWriter))\n#3 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AMQPChannel.php(170): PhpAmqpLib\\Channel\\AbstractChannel->send_method_frame(Array, Object(PhpAmqpLib\\Wire\\A in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php on line 190\n\nFatal error: Uncaught exception 'PhpAmqpLib\\Exception\\AMQPRuntimeException' with message 'Broken pipe or closed connection' in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:190\nStack trace:\n#0 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(336): PhpAmqpLib\\Wire\\IO\\StreamIO->write('\\x01\\x00\\x01\\x00\\x00\\x00\\v\\x00\\x14\\x00(\\x00\\x00\\x00\\x00...')\n#1 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(457): PhpAmqpLib\\Connection\\AbstractConnection->write('\\x01\\x00\\x01\\x00\\x00\\x00\\v\\x00\\x14\\x00(\\x00\\x00\\x00\\x00...')\n#2 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(223): PhpAmqpLib\\Connection\\AbstractConnection->send_channel_method_frame(1, Array, Object(PhpAmqpLib\\Wire\\AMQPWriter))\n#3 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AMQPChannel.php(170): PhpAmqpLib\\Channel\\AbstractChannel->send_method_frame(Array, Object(PhpAmqpLib\\Wire\\A in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php on line 190\n```\n\n```text\n# rabbitmq\nold_sound_rabbit_mq:\n connections:\n default:\n host: '192.168.99.100'\n port: 5672\n user: 'guest'\n password: 'guest'\n vhost: '/'\n lazy: false\n connection_timeout: 4\n read_write_timeout: 4\n\n # requires php-amqplib v2.4.1+ and PHP5.4+\n keepalive: false\n\n # requires php-amqplib v2.4.1+\n heartbeat: 2\n```\n\n```text\nconnection_timeout: 60\n read_write_timeout: 60\n\n # requires php-amqplib v2.4.1+ and PHP5.4+\n keepalive: false\n\n # requires php-amqplib v2.4.1+\n heartbeat: 30\n```\n\n========================================\n\nComments:\n- my current fix is using supervisord to restart the workers automatically. And it works, but is a very ugly hack... I really hope someone can point me in the right direction!\n- you fixed my problem and will set as answer, but why did it fix it? I read the documentation, but to no avail. I had timeouts and heartbeat in the same ratio as your fix. Any idea why it needs these greater values?","metadata":{"transformedAt":"2026-08-18T18:33:20.202Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":182,"estimatedTokens":3248}}924{"id":"stack-15251853","source":"stackoverflow","questionId":15251853,"title":"Consume AMQP messages from ASP.net MVC 4 using RabbitMQ","tags":["asp.net-mvc-4","rabbitmq"],"text":"Title: Consume AMQP messages from ASP.net MVC 4 using RabbitMQ\nTags: asp.net-mvc-4, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nLet's say that I want to consume AMQP messages from ASP.net MVC 4 using RabbitMQ. \nI store an object in *System.Web.HttpContext.Current.Application* which internally uses an instance of BackgroundWorker to listen for messages (the listener is created in *Global.asax.cs*)\n\nIs this a good way to implement this operation or should I use a static class / singleton? I am inexperienced in ASP.net MVC so I am uncertain. Maybe ASP.net MVC 4 is not the best platform choose? What would you recommend?\n\nThe goal is to be able to monitor/log message traffic, kill/create/configure consumers at will from a web interface. \n\nThis is my first stackoverflow post as I believe in good research. But, this time I would like to hear from other people, thx :)\n\n========================================\n\nComments:\n- Similar post is here It contains this link","metadata":{"transformedAt":"2026-08-18T18:33:20.202Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":18,"estimatedTokens":243}}925{"id":"stack-11241837","source":"stackoverflow","questionId":11241837,"title":"Synchronize one queue instance with multiple Redis instances","tags":["redis","message-queue","rabbitmq","amqp","zeromq"],"text":"Title: Synchronize one queue instance with multiple Redis instances\nTags: redis, message-queue, rabbitmq, amqp, zeromq\nSource: Stack Overflow\n\nQuestion:\n**The Scenario:**\nWe have multiple nodes distributed geographically on which we want to have queues collecting messages for that location. And then we want to send this collected data from every queue in every node to their corresponding queues in a central location. In the central node, we will pull out data collected in the queues (from other nodes), process it and store it persistently.\n\nConstraints:\n\n- Data is very important to us. Therefore, we have to make sure that we are not loosing data in any case.\n\n- Therefore, we need persistent queues on every node so that even if the node goes down for some random reason, when we bring it up we have the collected data safe with us and we can send it to the central node where it can be processed.\n\n- Similarly, if the central node goes down, the data must remain at all the other nodes so that when the central node comes up we can send all the data to the central node for processing.\n\n- Also, the data on the central node must not get duplicated or stored again. That is data collected on one of the nodes should be stored on the central nodes only once.\n\n- The data that we are collecting is very important to us and the order of data delivery to the central node is not an issue.\n\n**Our Solution**\nWe have considered a couple of solutions out of which I am going to list down the one that we thought would be the best. A possible solution (in our opinion) is to use Redis to maintain queues everywhere because Redis provides persistent storage. Then perhaps have a daemon running on all the geographically separated nodes which reads the data from the queue and sends it to the central node. The central node on receiving the data sends an ACK to the node it received the data from (because data is very important to us) and then on receiving the ACK, the node deletes the data from the queue. Of course, there will be timeout period in which the ACK must be received.\n\n**The Problem**\nThe above stated solution (according to us) will work fine but the issue is that we don't want to implement the whole synchronization protocol by ourselves for the simple reason that we might be wrong here. We were unable to find this particular way of synchronization in Redis. So we are open to other AMQP based queues like RabbitMQ, ZeroMQ, etc. Again we were not able to figure out if we can do this with these solutions.\n\n- Do these Message Queues or any other data store provide features that can be the solution to our problem? If yes, then how?\n\n- If not, then is our solution good enough?\n\n- Can anyone suggest a better solution?\n\n- Can there be a better way to do this?\n\n- What would be the best way to make it fail safe?\n\n- The data that we are collecting is very important to us and the order of data delivery to the central node is not an issue.\n\n========================================\n\nComments:\n- Use the right tool for the right job: RabbitMQ is definitely the right tool when you need acknowledgement, persistence and (advanced) message routing.\n- \"Also, the data on the central node must not get duplicated or stored again. That is data collected on one of the nodes should be stored on the central nodes only once.\" How do I ensure this? Consider that the ACK does not get delivered due to network issues (in our scenario). What happens in that case? The queue still is not aware of the status of the completion of the work. Does message in that case get locked? Or does another worker pick it up? If another worker picks it up, then we will have the same data worked twice, right?","metadata":{"transformedAt":"2026-08-18T18:33:20.202Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":43,"estimatedTokens":926}}926{"id":"stack-57792410","source":"stackoverflow","questionId":57792410,"title":"Celery: enqueuing multiple (100-1000) tasks at the same time via send_task?","tags":["python","rabbitmq","celery","kombu"],"text":"Title: Celery: enqueuing multiple (100-1000) tasks at the same time via send_task?\nTags: python, rabbitmq, celery, kombu\nSource: Stack Overflow\n\nQuestion:\nWe quite often have the need to enqueue many messages (we chunk them into groups of 1000) using Celery (backed by RabbitMQ). Does anyone have a way to do this? We're basically trying to \"batch\" a large group of messages in one send_task call. \n\nIf i were to guess we would need to go a step \"deeper\" and hook into `kombu` or even `py-amqp`. \n\nRegards,\n\nNiklas\n\n========================================\n\nTop Answer:\nWhat I - provisionally at least - ended up doing was making sure to keep the celery connection open, via:\n\n```\nwith celery.Celery(set_as_current=False) as celeryapp:\n ...\n with celeryapp.connection_for_write(connect_timeout=connection_timeout) as conn:\n for message in messages:\n celeryapp.send_task(...)\n```\n\nThat way I don't have to re-create connections for producing for each message.\n\n========================================\n\nCode:\n```text\nkombu\n```\n\n```text\npy-amqp\n```\n\n```text\nwith celery.Celery(set_as_current=False) as celeryapp:\n ...\n with celeryapp.connection_for_write(connect_timeout=connection_timeout) as conn:\n for message in messages:\n celeryapp.send_task(...)\n```\n\n========================================\n\nComments:\n- Good points! I would prefer not to use chunks since these are large tasks (5-25 minutes processing time) and that would require re-engineering how we process them. I will mark this as the answer and simply call send_task continuously using pooling.\n- Did you by any chance measure the improvement over send_task() in a simple loop?","metadata":{"transformedAt":"2026-08-18T18:33:20.202Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":52,"estimatedTokens":416}}927{"id":"stack-41463064","source":"stackoverflow","questionId":41463064,"title":"Check if Rabbit MQ is down","tags":["c#","rabbitmq"],"text":"Title: Check if Rabbit MQ is down\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am writing a C# Console app (Windows scheduled task) to monitor the status of Rabbit MQ. So in case the the queue is down (service down, connection timeout, or any other reason) it will send a notification mail. I have used RabbitMQ .Net client (version 4.1.1). Basically I am checking if the CreateConnection() is successfull.\n\n```\nprivate static void CheckRabbitMQStatus()\n{\n ConnectionFactory factory = new ConnectionFactory();\n factory.Uri = \"amqp://guest:guest@testserver:5672/\";\n IConnection conn = null;\n try\n {\n conn = factory.CreateConnection();\n conn.Close();\n conn.Dispose();\n }\n catch (Exception ex)\n {\n if (ex.Message == \"None of the specified endpoints were reachable\")\n {\n //send mail MQ is down\n }\n }\n}\n```\n\nIs this the right approach to achieve this? There are several tools and plugins available for Rabbit MQ but I want a simple solution in C#.\n\n========================================\n\nCode:\n```text\nprivate static void CheckRabbitMQStatus()\n{\n ConnectionFactory factory = new ConnectionFactory();\n factory.Uri = \"amqp://guest:guest@testserver:5672/\";\n IConnection conn = null;\n try\n {\n conn = factory.CreateConnection();\n conn.Close();\n conn.Dispose();\n }\n catch (Exception ex)\n {\n if (ex.Message == \"None of the specified endpoints were reachable\")\n {\n //send mail MQ is down\n }\n }\n}\n```\n\n========================================\n\nComments:\n- What is the concrete type of `ex`? Comparing the message might break in later releases ...\n- The type of the exception is `RabbitMQ.Client.Exceptions.BrokerUnreachableException` -- That being said, the message is the same as of August 2020 ¯\\_(ツ)_/¯\n- can you point me where can i find the differences why this simple reconnect queue setup works different in clustering or federation environment?","metadata":{"transformedAt":"2026-08-18T18:33:20.202Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":62,"estimatedTokens":486}}928{"id":"stack-2006147","source":"stackoverflow","questionId":2006147,"title":"requeue a sweatshop job in RabbitMQ","tags":["ruby-on-rails","ruby","message-queue","rabbitmq"],"text":"Title: requeue a sweatshop job in RabbitMQ\nTags: ruby-on-rails, ruby, message-queue, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am working on a Rails application where customer refunds are handed to a Sweatshop worker. If a refund fails (because we cannot reach the payment processor at that time) I want to requeue the job.\n\n```\nclass RefundWorker 'completed')\n else\n sleep 3\n RefundWorker.async_process_refund(job) # requeue the job\n end\nend\n```\n\nIs there any better way to do this than above? I haven't found any \"delay\" feature in RabbitMQ, and this is the best solutions I've come up with so far. I want to avoid a busy loop while requeueing.\n\n========================================\n\nTop Answer:\nHave you looked at things like Ruote and Minion?\n\nSome links here: http://delicious.com/alexisrichardson/rabbitmq+work+ruby\n\nYou could also try Celery which does not speak native Ruby but does speak HTTP+JSON.\n\nAll of the above work with RabbitMQ, so may help you.\n\nCheers\n\nalexis\n\n========================================\n\nCode:\n```text\nclass RefundWorker < Sweatshop::Worker\n\ndef process_refund(job)\n if refund\n Transaction.find(job[:transaction]).update_attributes(:status => 'completed')\n else\n sleep 3\n RefundWorker.async_process_refund(job) # requeue the job\n end\nend\n```\n\n========================================\n\nComments:\n- celery does this for tasks with an eta/countdown. It just holds on to the messages, and there's a scheduler executing the tasks when the eta is met. As the messages needs to be acknowledged, holding on to them isn't a problem, though it's kinda quirky when using QoS prefetch counts, as we have to increment the prefetch count every time a message with an eta is received, and decrement it when the eta message has been processed.\n- Thank you for the alternative clients. I really rather stick to a Ruby one whenever possible and Sweatshop/Carrot has been working great. Their doesn't seem to be a delay function in AMQP, so the re-queue seems the best option at this point. I have the code in development working as I want, just wondering if there wasn't a better way.","metadata":{"transformedAt":"2026-08-18T18:33:20.202Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":54,"estimatedTokens":531}}929{"id":"stack-4543534","source":"stackoverflow","questionId":4543534,"title":"Connection problems - Celery/Django","tags":["python","django","ubuntu","rabbitmq","celery"],"text":"Title: Connection problems - Celery/Django\nTags: python, django, ubuntu, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nlong night... can't get my second Celery/RabbitMQ setup run to work.\n\n### step 1\n\n```\nsudo rabbitmq-server\n```\n\nruns: **ok!**\n\n### step 2\n\n```\npython manage.py celeryd -l info\n```\n\nerror: `[2010-12-28 03:38:24,690: ERROR/MainProcess] CarrotListener: Connection Error: Socket closed. Trying again in 28 seconds...`\n\nI have definitely:\n\n- added rabbitmq user and vhost\n\n- updated the Django setings.py\n\n### Edit:\n\nI think it might have to with installing from a .deb instead of apt-get.\n\nAfter uninstalling the deb and installing the apt-get version I get this:\n\n```\ninvoke-rc.d: initscript rabbitmq-server, action \"start\" failed.\ndpkg: error processing rabbitmq-server (--configure):\n subprocess installed post-installation script returned error exit status 1\nErrors were encountered while processing:\n rabbitmq-server\nE: Sub-process /usr/bin/dpkg returned an error code (1)\n```\n\n### My Solution:\n\n apt-get --purge remove rabbitmq-server\n\n \n apt-get install rabbitmq-server\n\n...no comment...maybe need some sleep :)\n\nAny ideas on how I could debug this? :|\n\n========================================\n\nTop Answer:\nI did faced this issue while installing rabbitmq-server, while i was installing chef.\nThe work around for me and the solution to this problem is given as follows.\n\n```\n$ sudo vim /etc/hosts\n```\n\nThen add.\n\n```\n127.0.0.1 \n```\n\nHere is your hostname, if not sure about the hostname then run the following command:\n\n```\n$ hostname\n```\n\nthe Result is your hostname. Just add that to your /etc/hosts and then run:\n\n```\n$ sudo service rabbitmq-server start\n```\n\nAnd it was started.:)\nThis worked for me.\nThanks for your time to read.:)\n\n========================================\n\nCode:\n```text\nsudo rabbitmq-server\n```\n\n```text\npython manage.py celeryd -l info\n```\n\n```text\ninvoke-rc.d: initscript rabbitmq-server, action \"start\" failed.\ndpkg: error processing rabbitmq-server (--configure):\n subprocess installed post-installation script returned error exit status 1\nErrors were encountered while processing:\n rabbitmq-server\nE: Sub-process /usr/bin/dpkg returned an error code (1)\n```\n\n```text\n[2010-12-28 03:38:24,690: ERROR/MainProcess] CarrotListener: Connection Error: Socket closed. Trying again in 28 seconds...\n```\n\n```text\nsudo /etc/init.d/rabbitmq-server start\n```\n\n```text\nsudo tail -f /var/log/rabbit@<your-local-host>.log\n```\n\n```text\n$ sudo vim /etc/hosts\n```\n\n```text\n127.0.0.1 <hostname>\n```\n\n```text\n$ hostname\n```\n\n```text\n$ sudo service rabbitmq-server start\n```\n\n========================================\n\nComments:\n- You added a vhost and user, did you set permissions? `sudo rabbitmqctl set_permissions -p \".*\" \".*\" \".*\"`\n- I had the same issue too. You're solution of simply purging and then reinstalling worked like a charm. :)","metadata":{"transformedAt":"2026-08-18T18:33:20.202Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":140,"estimatedTokens":720}}930{"id":"stack-5870511","source":"stackoverflow","questionId":5870511,"title":"Getting result of a long running task with RabbitMQ","tags":["rabbitmq","amqp"],"text":"Title: Getting result of a long running task with RabbitMQ\nTags: rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI have a scenario where a client sends an http request to download a file. The file needs to be dynamically generated and typically takes 5-15 seconds. Therefore I am looking into a solution that splits this operation in 3 http requests.\n\n- First request triggers the generation of the file.\n\n- The client polls the server every 5 seconds to check if file is ready to download\n\n- When the response to the poll request is positive, the client starts downloading the file\n\nTo implement this I am looking into Message Queue solutions like RabbitMQ. They seem to provide a reliable framework to run long running tasks asynchronously. However after reading the tutorials on RabbitMQ, I am not sure how will I receive the result of the operation.\n\nHere is what I've in mind:\n\nA front end server receives requests from clients and it posts messages to RabbitMQ as required. This front end server will have 3 endpoints\n\n```\n/generate\n/poll\n/download\n```\n\nWhen client invokes `/generate` with a `GET` parameter say `request_uid=AAA`, the front end server will post a message to RabbitMQ with the request_uid in the payload. Any free worker will subsequently receive this message and start generating the file corresponding to `AAA`.\n\nClient will keep polling `/poll` with `request_uid=AAA` to check if task was complete.\n\nWhen task is complete client will call `/download` with `request_uid=AAA` expecting to download the file. \n\nThe question is how will the `/poll` and `/download` handlers of the front end server will come to know about the status of the file generation job? How can RabbitMQ communicate the result of the task back to the producer. Or do I have to implement such mechanism outside RabbitMQ? (Consumer putting its results in a file `/var/completed/AAA`)\n\n========================================\n\nTop Answer:\nThe easiest way to get started with AMQP, is to use a topic exchange, and to create queues which carry control messages. For instance you could have a file.ready queue and send messages with the file pathname when it is ready to pickup, and a file.error queue to report when you were unable to create a file for some reason. Then the client could use a file.generate queue to send the GET information to the server.\n\n========================================\n\nCode:\n```text\n/generate\n/poll\n/download\n```\n\n```text\n/generate\n```\n\n```text\nGET\n```\n\n```text\nrequest_uid=AAA\n```\n\n```text\nAAA\n```\n\n```text\n/poll\n```\n\n```text\nrequest_uid=AAA\n```\n\n```text\n/download\n```\n\n```text\nrequest_uid=AAA\n```\n\n```text\n/poll\n```\n\n```text\n/download\n```\n\n```text\n/var/completed/AAA\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.202Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":90,"estimatedTokens":674}}931{"id":"stack-45478431","source":"stackoverflow","questionId":45478431,"title":"Airflow Scheduler and Webserver hangs while queuing the task to run on RabbitMQ","tags":["rabbitmq","celery","airflow"],"text":"Title: Airflow Scheduler and Webserver hangs while queuing the task to run on RabbitMQ\nTags: rabbitmq, celery, airflow\nSource: Stack Overflow\n\nQuestion:\nI am struggling to make the airflow worker run tasks. I started services:\n\n```\nairflow worker --debug\nairflow webserver\nairflow scheduler\nairflow flower #to check celery queues in UI at localhost:5555\n```\n\nThese process runs fine, but when scheduler is adding the task to run to the queue or when I am trying to run a task from airflow UI the scheduler and webserver are getting hanged -continuously loading not proceeding any further - while adding the task to the queue:\nhttps://i.sstatic.net/YUGlh.png\nhttps://i.sstatic.net/BFwfZ.png\nhttps://i.sstatic.net/JloW8.png\nhttps://i.sstatic.net/0CBN7.png\nhttps://i.sstatic.net/dIjxX.png\n\nI think the issue has to do with the communication between scheduler/webserver and queue. My settings related to the broker in airflow.cfg file are: `broker_url = amqp://guest:***@ksaprice_rabbitmq:15672//` - I have also tried: `broker_url = pyamqp://guest:***@ksaprice_rabbitmq:15672//`. The rabbitmq is server is running fine and I tested the login and password credentials as well. \n\nVersion I am using are:\n\n- airflow==1.8.1\n\n- celery=4.1\n\n- rabbitmq server 3.6\n\nI am new to Airflow and Rabbitmq.\n\n**Update:**\nMy queuing problem was solved by the answer of @Jean-Sébastien Pédron but still my workers are not executing the task and flower is not displaying the worker although `airflow worker` service is running at 8793 port.\n\n**Rabbitmq report:**\n\n```\nStatus of node ksaprice_rabbitmq@4eed789778c0\n[{pid,233},\n {running_applications,\n [{rabbitmq_management,\"RabbitMQ Management Console\",\"3.6.10\"},\n {rabbitmq_web_dispatch,\"RabbitMQ Web Dispatcher\",\"3.6.10\"},\n {rabbitmq_management_agent,\"RabbitMQ Management Agent\",\"3.6.10\"},\n {amqp_client,\"RabbitMQ AMQP Client\",\"3.6.10\"},\n {cowboy,\"Small, fast, modular HTTP server.\",\"1.0.4\"},\n {cowlib,\"Support library for manipulating Web protocols.\",\"1.0.2\"},\n {inets,\"INETS CXC 138 49\",\"6.3.4\"},\n {rabbit,\"RabbitMQ\",\"3.6.10\"},\n {mnesia,\"MNESIA CXC 138 12\",\"4.14.2\"},\n {rabbit_common,\n \"Modules shared by rabbitmq-server and rabbitmq-erlang-client\",\n \"3.6.10\"},\n {compiler,\"ERTS CXC 138 10\",\"7.0.3\"},\n {os_mon,\"CPO CXC 138 46\",\"2.4.1\"},\n {ranch,\"Socket acceptor pool for TCP protocols.\",\"1.3.0\"},\n {ssl,\"Erlang/OTP SSL application\",\"8.1\"},\n {public_key,\"Public key infrastructure\",\"1.3\"},\n {crypto,\"CRYPTO\",\"3.7.2\"},\n {xmerl,\"XML parser\",\"1.3.12\"},\n {asn1,\"The Erlang ASN1 compiler version 4.0.4\",\"4.0.4\"},\n {syntax_tools,\"Syntax tools\",\"2.1.1\"},\n {sasl,\"SASL CXC 138 11\",\"3.0.2\"},\n {stdlib,\"ERTS CXC 138 10\",\"3.2\"},\n {kernel,\"ERTS CXC 138 10\",\"5.1.1\"}]},\n {os,{unix,linux}},\n {erlang_version,\n \"Erlang/OTP 19 [erts-8.2.1] [source] [64-bit] [smp:2:2] [async-threads:64] [hipe] [kernel-poll:true]\\n\"},\n {memory,\n [{total,77018832},\n {connection_readers,334888},\n {connection_writers,14640},\n {connection_channels,132040},\n {connection_other,477152},\n {queue_procs,65480},\n {queue_slave_procs,0},\n {plugins,2287080},\n {other_proc,19854000},\n {mnesia,77272},\n {metrics,239992},\n {mgmt_db,852688},\n {msg_index,44208},\n {other_ets,2577600},\n {binary,3923976},\n {code,24680786},\n {atom,1033401},\n {other_system,20660789}]},\n {alarms,[]},\n {listeners,[{clustering,25672,\"::\"},{amqp,5672,\"::\"},{http,15672,\"::\"}]},\n {vm_memory_high_watermark,0.4},\n {vm_memory_limit,830581964},\n {disk_free_limit,50000000},\n {disk_free,56083853312},\n {file_descriptors,\n [{total_limit,1048476},\n {total_used,13},\n {sockets_limit,943626},\n {sockets_used,10}]},\n {processes,[{limit,1048576},{used,420}]},\n {run_queue,0},\n {uptime,45431},\n {kernel,{net_ticktime,60}}]\n\nCluster status of node ksaprice_rabbitmq@4eed789778c0\n[{nodes,[{disc,[ksaprice_rabbitmq@4eed789778c0]}]},\n {running_nodes,[ksaprice_rabbitmq@4eed789778c0]},\n {cluster_name,>},\n {partitions,[]},\n {alarms,[{ksaprice_rabbitmq@4eed789778c0,[]}]}]\n\nApplication environment of node ksaprice_rabbitmq@4eed789778c0\n[{amqp_client,[{prefer_ipv6,false},{ssl_options,[]}]},\n {asn1,[]},\n {compiler,[]},\n {cowboy,[]},\n {cowlib,[]},\n {crypto,[]},\n {inets,[]},\n {kernel,\n [{error_logger,tty},\n {inet_default_connect_options,[{nodelay,true}]},\n {inet_dist_listen_max,25672},\n {inet_dist_listen_min,25672}]},\n {mnesia,[{dir,\"/var/lib/rabbitmq/mnesia/ksaprice_rabbitmq\"}]},\n {os_mon,\n [{start_cpu_sup,false},\n {start_disksup,false},\n {start_memsup,false},\n {start_os_sup,false}]},\n {public_key,[]},\n {rabbit,\n [{auth_backends,[rabbit_auth_backend_internal]},\n {auth_mechanisms,['PLAIN','AMQPLAIN']},\n {background_gc_enabled,false},\n {background_gc_target_interval,60000},\n {backing_queue_module,rabbit_priority_queue},\n {channel_max,0},\n {channel_operation_timeout,15000},\n {cluster_keepalive_interval,10000},\n {cluster_nodes,{[],disc}},\n {cluster_partition_handling,ignore},\n {collect_statistics,fine},\n {collect_statistics_interval,5000},\n {config_entry_decoder,\n [{cipher,aes_cbc256},\n {hash,sha512},\n {iterations,1000},\n {passphrase,undefined}]},\n {credit_flow_default_credit,{400,200}},\n {default_permissions,[>,>,>]},\n {default_user,>},\n {default_user_tags,[administrator]},\n {default_vhost,>},\n {delegate_count,16},\n {disk_free_limit,50000000},\n {disk_monitor_failure_retries,10},\n {disk_monitor_failure_retry_interval,120000},\n {enabled_plugins_file,\"/etc/rabbitmq/enabled_plugins\"},\n {error_logger,tty},\n {fhc_read_buffering,false},\n {fhc_write_buffering,true},\n {frame_max,131072},\n {halt_on_upgrade_failure,true},\n {handshake_timeout,10000},\n {heartbeat,60},\n {hipe_compile,false},\n {hipe_modules,\n [rabbit_reader,rabbit_channel,gen_server2,rabbit_exchange,\n rabbit_command_assembler,rabbit_framing_amqp_0_9_1,rabbit_basic,\n rabbit_event,lists,queue,priority_queue,rabbit_router,rabbit_trace,\n rabbit_misc,rabbit_binary_parser,rabbit_exchange_type_direct,\n rabbit_guid,rabbit_net,rabbit_amqqueue_process,\n rabbit_variable_queue,rabbit_binary_generator,rabbit_writer,\n delegate,gb_sets,lqueue,sets,orddict,rabbit_amqqueue,\n rabbit_limiter,gb_trees,rabbit_queue_index,\n rabbit_exchange_decorator,gen,dict,ordsets,file_handle_cache,\n rabbit_msg_store,array,rabbit_msg_store_ets_index,rabbit_msg_file,\n rabbit_exchange_type_fanout,rabbit_exchange_type_topic,mnesia,\n mnesia_lib,rpc,mnesia_tm,qlc,sofs,proplists,credit_flow,pmon,\n ssl_connection,tls_connection,ssl_record,tls_record,gen_fsm,ssl]},\n {lazy_queue_explicit_gc_run_operation_threshold,1000},\n {log_levels,[{connection,info}]},\n {loopback_users,[]},\n {memory_monitor_interval,2500},\n {mirroring_flow_control,true},\n {mirroring_sync_batch_size,4096},\n {mnesia_table_loading_retry_limit,10},\n {mnesia_table_loading_retry_timeout,30000},\n {msg_store_credit_disc_bound,{4000,800}},\n {msg_store_file_size_limit,16777216},\n {msg_store_index_module,rabbit_msg_store_ets_index},\n {msg_store_io_batch_size,4096},\n {num_ssl_acceptors,1},\n {num_tcp_acceptors,10},\n {password_hashing_module,rabbit_password_hashing_sha256},\n {plugins_dir,\n \"/usr/lib/rabbitmq/plugins:/usr/lib/rabbitmq/lib/rabbitmq_server-3.6.10/plugins\"},\n {plugins_expand_dir,\n \"/var/lib/rabbitmq/mnesia/ksaprice_rabbitmq-plugins-expand\"},\n {queue_explicit_gc_run_operation_threshold,1000},\n {queue_index_embed_msgs_below,4096},\n {queue_index_max_journal_entries,32768},\n {reverse_dns_lookups,false},\n {sasl_error_logger,tty},\n {server_properties,[]},\n {ssl_allow_poodle_attack,false},\n {ssl_apps,[asn1,crypto,public_key,ssl]},\n {ssl_cert_login_from,distinguished_name},\n {ssl_handshake_timeout,5000},\n {ssl_listeners,[]},\n {ssl_options,[]},\n {tcp_listen_options,\n [{backlog,128},\n {nodelay,true},\n {linger,{true,0}},\n {exit_on_close,false}]},\n {tcp_listeners,[5672]},\n {trace_vhosts,[]},\n {vm_memory_high_watermark,0.4},\n {vm_memory_high_watermark_paging_ratio,0.5}]},\n {rabbit_common,[]},\n {rabbitmq_management,\n [{cors_allow_origins,[]},\n {cors_max_age,1800},\n {http_log_dir,none},\n {listener,[{port,15672}]},\n {load_definitions,none},\n {management_db_cache_multiplier,5},\n {process_stats_gc_timeout,300000},\n {stats_event_max_backlog,250}]},\n {rabbitmq_management_agent,\n [{rates_mode,basic},\n {sample_retention_policies,\n [{global,[{605,5},{3660,60},{29400,600},{86400,1800}]},\n {basic,[{605,5},{3600,60}]},\n {detailed,[{605,5}]}]}]},\n {rabbitmq_web_dispatch,[]},\n {ranch,[]},\n {sasl,[{errlog_type,error},{sasl_error_logger,tty}]},\n {ssl,[]},\n {stdlib,[]},\n {syntax_tools,[]},\n {xmerl,[]}]\n\nConnections:\npid name port peer_port host peer_host ssl peer_cert_subject peer_cert_issuer peer_cert_validity auth_mechanismssl_protocol ssl_key_exchange ssl_cipher ssl_hash protocol user vhost timeout frame_max channel_max client_properties connected_at recv_oct recv_cnt send_oct send_cnt send_pend state channels reductions garbage_collection\n 172.25.0.2:47982 -> 172.25.0.4:5672 5672 47982 172.25.0.4 172.25.0.2 false AMQPLAIN {0,9,1} admin ksaprice_rabbitmq_vh 0 131072 65535 [{\"product\",\"py-amqp\"},{\"product_version\",\"2.2.1\"},{\"capabilities\",[{\"connection.blocked\",true},{\"authentication_failure_close\",true},{\"consumer_cancel_notify\",true}]}] 1501749265595 1897 10 606 7 0 running 1 235055 [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,170}]\n 172.25.0.2:48764 -> 172.25.0.4:5672 5672 48764 172.25.0.4 172.25.0.2 false AMQPLAIN {0,9,1} admin ksaprice_rabbitmq_vh 0 131072 65535 [{\"product\",\"py-amqp\"},{\"product_version\",\"2.2.1\"},{\"capabilities\",[{\"connection.blocked\",true},{\"authentication_failure_close\",true},{\"consumer_cancel_notify\",true}]}] 1501749346461 289 5 554 4 0 running 1 226409 [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,161}]\n 172.25.0.2:48766 -> 172.25.0.4:5672 5672 48766 172.25.0.4 172.25.0.2 false AMQPLAIN {0,9,1} admin ksaprice_rabbitmq_vh 0 131072 65535 [{\"product\",\"py-amqp\"},{\"product_version\",\"2.2.1\"},{\"capabilities\",[{\"connection.blocked\",true},{\"authentication_failure_close\",true},{\"consumer_cancel_notify\",true}]}] 1501749346494 1647 21 1030 20 0 running 1 228859 [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,171}]\n 172.25.0.2:48768 -> 172.25.0.4:5672 5672 48768 172.25.0.4 172.25.0.2 false AMQPLAIN {0,9,1} admin ksaprice_rabbitmq_vh 0 131072 65535 [{\"product\",\"py-amqp\"},{\"product_version\",\"2.2.1\"},{\"capabilities\",[{\"connection.blocked\",true},{\"authentication_failure_close\",true},{\"consumer_cancel_notify\",true}]}] 1501749346494 569 9 662 8 0 running 1 226947 [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,164}]\n 172.25.0.2:48770 -> 172.25.0.4:5672 5672 48770 172.25.0.4 172.25.0.2 false AMQPLAIN {0,9,1} admin ksaprice_rabbitmq_vh 0 131072 65535 [{\"product\",\"py-amqp\"},{\"product_version\",\"2.2.1\"},{\"capabilities\",[{\"connection.blocked\",true},{\"authentication_failure_close\",true},{\"consumer_cancel_notify\",true}]}] 1501749346495 1647 20 1030 20 0 running 1 228798 [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,167}]\n 172.25.0.2:48772 -> 172.25.0.4:5672 5672 48772 172.25.0.4 172.25.0.2 false AMQPLAIN {0,9,1} admin ksaprice_rabbitmq_vh 0 131072 65535 [{\"product\",\"py-amqp\"},{\"product_version\",\"2.2.1\"},{\"capabilities\",[{\"connection.blocked\",true},{\"authentication_failure_close\",true},{\"consumer_cancel_notify\",true}]}] 1501749346511 85953 485 1042 21 0 running 1 280680 [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,110}]\n 172.25.0.2:48774 -> 172.25.0.4:5672 5672 48774 172.25.0.4 172.25.0.2 false AMQPLAIN {0,9,1} admin ksaprice_rabbitmq_vh 0 131072 65535 [{\"product\",\"py-amqp\"},{\"product_version\",\"2.2.1\"},{\"capabilities\",[{\"connection.blocked\",true},{\"authentication_failure_close\",true},{\"consumer_cancel_notify\",true}]}] 1501749346548 665 7 566 5 0 running 1 226665 [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,168}]\n 172.25.0.2:48776 -> 172.25.0.4:5672 5672 48776 172.25.0.4 172.25.0.2 false AMQPLAIN {0,9,1} admin ksaprice_rabbitmq_vh 0 131072 65535 [{\"product\",\"py-amqp\"},{\"product_version\",\"2.2.1\"},{\"capabilities\",[{\"connection.blocked\",true},{\"authentication_failure_close\",true},{\"consumer_cancel_notify\",true}]}] 1501749346551 1647 21 1030 20 0 running 1 228859 [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,171}]\n 172.25.0.2:48780 -> 172.25.0.4:5672 5672 48780 172.25.0.4 172.25.0.2 false AMQPLAIN {0,9,1} admin ksaprice_rabbitmq_vh 0 131072 65535 [{\"product\",\"py-amqp\"},{\"product_version\",\"2.2.1\"},{\"capabilities\",[{\"connection.blocked\",true},{\"authentication_failure_close\",true},{\"consumer_cancel_notify\",true}]}] 1501749346576 1691 9 566 5 0 running 1 226936 [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,169}]\n 172.25.0.2:48778 -> 172.25.0.4:5672 5672 48778 172.25.0.4 172.25.0.2 false AMQPLAIN {0,9,1} admin ksaprice_rabbitmq_vh 0 131072 65535 [{\"product\",\"py-amqp\"},{\"product_version\",\"2.2.1\"},{\"capabilities\",[{\"connection.blocked\",true},{\"authentication_failure_close\",true},{\"consumer_cancel_notify\",true}]}] 1501749346576 1496 9 566 5 0 running 1 226885 [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,161}]\n\nChannels:\npid name connection number user vhost reductions transactional confirm consumer_count messages_unacknowledged messages_unconfirmed messages_uncommitted acks_uncommitted prefetch_count global_prefetch_count state garbage_collection\n 172.25.0.2:47982 -> 172.25.0.4:5672 (1) 1 admin ksaprice_rabbitmq_vh 4140 false false 0 0 0 0 0 0 0 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,8}]\n 172.25.0.2:48764 -> 172.25.0.4:5672 (1) 1 admin ksaprice_rabbitmq_vh 1706 false false 0 0 0 0 0 0 0 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,8}]\n 172.25.0.2:48768 -> 172.25.0.4:5672 (1) 1 admin ksaprice_rabbitmq_vh 4737 false false 1 0 0 0 0 0 0 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,6}]\n 172.25.0.2:48770 -> 172.25.0.4:5672 (1) 1 admin ksaprice_rabbitmq_vh 8608 false false 0 0 0 0 0 0 0 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,3}]\n 172.25.0.2:48766 -> 172.25.0.4:5672 (1) 1 admin ksaprice_rabbitmq_vh 7977 false false 0 0 0 0 0 0 0 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,3}]\n 172.25.0.2:48772 -> 172.25.0.4:5672 (1) 1 admin ksaprice_rabbitmq_vh 116017 false false 0 0 0 0 0 0 0 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,1}]\n 172.25.0.2:48776 -> 172.25.0.4:5672 (1) 1 admin ksaprice_rabbitmq_vh 7977 false false 0 0 0 0 0 0 0 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,3}]\n 172.25.0.2:48774 -> 172.25.0.4:5672 (1) 1 admin ksaprice_rabbitmq_vh 3048 false false 0 0 0 0 0 0 0 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,4}]\n 172.25.0.2:48778 -> 172.25.0.4:5672 (1) 1 admin ksaprice_rabbitmq_vh 2854 false false 0 0 0 0 0 0 0 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,4}]\n 172.25.0.2:48780 -> 172.25.0.4:5672 (1) 1 admin ksaprice_rabbitmq_vh 3245 false false 0 0 0 0 0 0 0 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,6}]\n\nQueues on ksaprice_rabbitmq_vh:\npid name durable auto_delete arguments owner_pid exclusive messages_ready messages_unacknowledged messages reductions policy exclusive_consumer_pid exclusive_consumer_tag consumers consumer_utilisation memory slave_pids synchronised_slave_pids recoverable_slaves state garbage_collection messages_ram messages_ready_ram messages_unacknowledged_ram messages_persistent message_bytes message_bytes_ready message_bytes_unacknowledged message_bytes_ram message_bytes_persistent head_message_timestamp disk_reads disk_writes backing_queue_status messages_paged_out message_bytes_paged_out\n default true false [] false 6 0 6 88075 0 89344 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,3}] 6 6 0 6 1231 1231 0 1231 1231 0 6 [{mode,default}, {q1,0}, {q2,0}, {delta,{delta,undefined,0,0,undefined}}, {q3,0}, {q4,6}, {len,6}, {target_ram_count,infinity}, {next_seq_id,6}, {avg_ingress_rate,9.303060867567184e-92}, {avg_egress_rate,0.0}, {avg_ack_ingress_rate,0.0}, {avg_ack_egress_rate,0.0}] 0 0\n celeryev.b957bbf3-8b97-4633-897f-a887b49e617b false true [{\"x-message-ttl\",5000},{\"x-expires\",60000}] false 0 0 0 4739 1 1.0 22160 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,8}] 0 0 0 0 0 0 0 0 0 0 0 [{mode,default}, {q1,0}, {q2,0}, {delta,{delta,undefined,0,0,undefined}}, {q3,0}, {q4,0}, {len,0}, {target_ram_count,infinity}, {next_seq_id,0}, {avg_ingress_rate,0.0}, {avg_egress_rate,0.0}, {avg_ack_ingress_rate,0.0}, {avg_ack_egress_rate,0.0}] 0 0\n\nQueues on ksaprice_rabbitmq:\n\nQueues on /:\n\nExchanges on ksaprice_rabbitmq_vh:\nname type durable auto_delete internal arguments policy\n direct true false false []\namq.direct direct true false false []\namq.fanout fanout true false false []\namq.headers headers true false false []\namq.match headers true false false []\namq.rabbitmq.trace topic true false true []\namq.topic topic true false false []\ncelery.pidbox fanout false false false []\nceleryev topic true false false []\ndefault direct true false false []\nreply.celery.pidbox direct false false false []\n\nExchanges on ksaprice_rabbitmq:\nname type durable auto_delete internal arguments policy\n direct true false false []\namq.direct direct true false false []\namq.fanout fanout true false false []\namq.headers headers true false false []\namq.match headers true false false []\namq.rabbitmq.trace topic true false true []\namq.topic topic true false false []\n\nExchanges on /:\nname type durable auto_delete internal arguments policy\n direct true false false []\namq.direct direct true false false []\namq.fanout fanout true false false []\namq.headers headers true false false []\namq.match headers true false false []\namq.rabbitmq.log topic true false true []\namq.rabbitmq.trace topic true false true []\namq.topic topic true false false []\n\nBindings on ksaprice_rabbitmq_vh:\nsource_name source_kind destination_name destination_kind routing_key arguments vhost\n exchange celeryev.b957bbf3-8b97-4633-897f-a887b49e617b queue celeryev.b957bbf3-8b97-4633-897f-a887b49e617b [] ksaprice_rabbitmq_vh\n exchange default queue default [] ksaprice_rabbitmq_vh\nceleryev exchange celeryev.b957bbf3-8b97-4633-897f-a887b49e617b queue # [] ksaprice_rabbitmq_vh\ndefault exchange default queue default [] ksaprice_rabbitmq_vh\n\nBindings on ksaprice_rabbitmq:\n\nBindings on /:\n\nConsumers on ksaprice_rabbitmq_vh:\nqueue_name channel_pid consumer_tag ack_required prefetch_count arguments\nceleryev.b957bbf3-8b97-4633-897f-a887b49e617b None4 false 0 []\n\nConsumers on ksaprice_rabbitmq:\n\nConsumers on /:\n\nPermissions on ksaprice_rabbitmq_vh:\nuser configure write read\nadmin .* .* .*\n\nPermissions on ksaprice_rabbitmq:\n\nPermissions on /:\nuser configure write read\nguest .* .* .*\n\nPolicies on ksaprice_rabbitmq_vh:\n\nPolicies on ksaprice_rabbitmq:\n\nPolicies on /:\n\nParameters on ksaprice_rabbitmq_vh:\n\nParameters on ksaprice_rabbitmq:\n\nParameters on /:\n```\n\n========================================\n\nCode:\n```text\nairflow worker --debug\nairflow webserver\nairflow scheduler\nairflow flower #to check celery queues in UI at localhost:5555\n```\n\n```text\nStatus of node ksaprice_rabbitmq@4eed789778c0\n[{pid,233},\n {running_applications,\n [{rabbitmq_management,\"RabbitMQ Management Console\",\"3.6.10\"},\n {rabbitmq_web_dispatch,\"RabbitMQ Web Dispatcher\",\"3.6.10\"},\n {rabbitmq_management_agent,\"RabbitMQ Management Agent\",\"3.6.10\"},\n {amqp_client,\"RabbitMQ AMQP Client\",\"3.6.10\"},\n {cowboy,\"Small, fast, modular HTTP server.\",\"1.0.4\"},\n {cowlib,\"Support library for manipulating Web protocols.\",\"1.0.2\"},\n {inets,\"INETS CXC 138 49\",\"6.3.4\"},\n {rabbit,\"RabbitMQ\",\"3.6.10\"},\n {mnesia,\"MNESIA CXC 138 12\",\"4.14.2\"},\n {rabbit_common,\n \"Modules shared by rabbitmq-server and rabbitmq-erlang-client\",\n \"3.6.10\"},\n {compiler,\"ERTS CXC 138 10\",\"7.0.3\"},\n {os_mon,\"CPO CXC 138 46\",\"2.4.1\"},\n {ranch,\"Socket acceptor pool for TCP protocols.\",\"1.3.0\"},\n {ssl,\"Erlang/OTP SSL application\",\"8.1\"},\n {public_key,\"Public key infrastructure\",\"1.3\"},\n {crypto,\"CRYPTO\",\"3.7.2\"},\n {xmerl,\"XML parser\",\"1.3.12\"},\n {asn1,\"The Erlang ASN1 compiler version 4.0.4\",\"4.0.4\"},\n {syntax_tools,\"Syntax tools\",\"2.1.1\"},\n {sasl,\"SASL CXC 138 11\",\"3.0.2\"},\n {stdlib,\"ERTS CXC 138 10\",\"3.2\"},\n {kernel,\"ERTS CXC 138 10\",\"5.1.1\"}]},\n {os,{unix,linux}},\n {erlang_version,\n \"Erlang/OTP 19 [erts-8.2.1] [source] [64-bit] [smp:2:2] [async-threads:64] [hipe] [kernel-poll:true]\\n\"},\n {memory,\n [{total,77018832},\n {connection_readers,334888},\n {connection_writers,14640},\n {connection_channels,132040},\n {connection_other,477152},\n {queue_procs,65480},\n {queue_slave_procs,0},\n {plugins,2287080},\n {other_proc,19854000},\n {mnesia,77272},\n {metrics,239992},\n {mgmt_db,852688},\n {msg_index,44208},\n {other_ets,2577600},\n {binary,3923976},\n {code,24680786},\n {atom,1033401},\n {other_system,20660789}]},\n {alarms,[]},\n {listeners,[{clustering,25672,\"::\"},{amqp,5672,\"::\"},{http,15672,\"::\"}]},\n {vm_memory_high_watermark,0.4},\n {vm_memory_limit,830581964},\n {disk_free_limit,50000000},\n {disk_free,56083853312},\n {file_descriptors,\n [{total_limit,1048476},\n {total_used,13},\n {sockets_limit,943626},\n {sockets_used,10}]},\n {processes,[{limit,1048576},{used,420}]},\n {run_queue,0},\n {uptime,45431},\n {kernel,{net_ticktime,60}}]\n\nCluster status of node ksaprice_rabbitmq@4eed789778c0\n[{nodes,[{disc,[ksaprice_rabbitmq@4eed789778c0]}]},\n {running_nodes,[ksaprice_rabbitmq@4eed789778c0]},\n {cluster_name,<<\"ksaprice_rabbitmq@4eed789778c0\">>},\n {partitions,[]},\n {alarms,[{ksaprice_rabbitmq@4eed789778c0,[]}]}]\n\nApplication environment of node ksaprice_rabbitmq@4eed789778c0\n[{amqp_client,[{prefer_ipv6,false},{ssl_options,[]}]},\n {asn1,[]},\n {compiler,[]},\n {cowboy,[]},\n {cowlib,[]},\n {crypto,[]},\n {inets,[]},\n {kernel,\n [{error_logger,tty},\n {inet_default_connect_options,[{nodelay,true}]},\n {inet_dist_listen_max,25672},\n {inet_dist_listen_min,25672}]},\n {mnesia,[{dir,\"/var/lib/rabbitmq/mnesia/ksaprice_rabbitmq\"}]},\n {os_mon,\n [{start_cpu_sup,false},\n {start_disksup,false},\n {start_memsup,false},\n {start_os_sup,false}]},\n {public_key,[]},\n {rabbit,\n [{auth_backends,[rabbit_auth_backend_internal]},\n {auth_mechanisms,['PLAIN','AMQPLAIN']},\n {background_gc_enabled,false},\n {background_gc_target_interval,60000},\n {backing_queue_module,rabbit_priority_queue},\n {channel_max,0},\n {channel_operation_timeout,15000},\n {cluster_keepalive_interval,10000},\n {cluster_nodes,{[],disc}},\n {cluster_partition_handling,ignore},\n {collect_statistics,fine},\n {collect_statistics_interval,5000},\n {config_entry_decoder,\n [{cipher,aes_cbc256},\n {hash,sha512},\n {iterations,1000},\n {passphrase,undefined}]},\n {credit_flow_default_credit,{400,200}},\n {default_permissions,[<<\".*\">>,<<\".*\">>,<<\".*\">>]},\n {default_user,<<\"guest\">>},\n {default_user_tags,[administrator]},\n {default_vhost,<<\"/\">>},\n {delegate_count,16},\n {disk_free_limit,50000000},\n {disk_monitor_failure_retries,10},\n {disk_monitor_failure_retry_interval,120000},\n {enabled_plugins_file,\"/etc/rabbitmq/enabled_plugins\"},\n {error_logger,tty},\n {fhc_read_buffering,false},\n {fhc_write_buffering,true},\n {frame_max,131072},\n {halt_on_upgrade_failure,true},\n {handshake_timeout,10000},\n {heartbeat,60},\n {hipe_compile,false},\n {hipe_modules,\n [rabbit_reader,rabbit_channel,gen_server2,rabbit_exchange,\n rabbit_command_assembler,rabbit_framing_amqp_0_9_1,rabbit_basic,\n rabbit_event,lists,queue,priority_queue,rabbit_router,rabbit_trace,\n rabbit_misc,rabbit_binary_parser,rabbit_exchange_type_direct,\n rabbit_guid,rabbit_net,rabbit_amqqueue_process,\n rabbit_variable_queue,rabbit_binary_generator,rabbit_writer,\n delegate,gb_sets,lqueue,sets,orddict,rabbit_amqqueue,\n rabbit_limiter,gb_trees,rabbit_queue_index,\n rabbit_exchange_decorator,gen,dict,ordsets,file_handle_cache,\n rabbit_msg_store,array,rabbit_msg_store_ets_index,rabbit_msg_file,\n rabbit_exchange_type_fanout,rabbit_exchange_type_topic,mnesia,\n mnesia_lib,rpc,mnesia_tm,qlc,sofs,proplists,credit_flow,pmon,\n ssl_connection,tls_connection,ssl_record,tls_record,gen_fsm,ssl]},\n {lazy_queue_explicit_gc_run_operation_threshold,1000},\n {log_levels,[{connection,info}]},\n {loopback_users,[]},\n {memory_monitor_interval,2500},\n {mirroring_flow_control,true},\n {mirroring_sync_batch_size,4096},\n {mnesia_table_loading_retry_limit,10},\n {mnesia_table_loading_retry_timeout,30000},\n {msg_store_credit_disc_bound,{4000,800}},\n {msg_store_file_size_limit,16777216},\n {msg_store_index_module,rabbit_msg_store_ets_index},\n {msg_store_io_batch_size,4096},\n {num_ssl_acceptors,1},\n {num_tcp_acceptors,10},\n {password_hashing_module,rabbit_password_hashing_sha256},\n {plugins_dir,\n \"/usr/lib/rabbitmq/plugins:/usr/lib/rabbitmq/lib/rabbitmq_server-3.6.10/plugins\"},\n {plugins_expand_dir,\n \"/var/lib/rabbitmq/mnesia/ksaprice_rabbitmq-plugins-expand\"},\n {queue_explicit_gc_run_operation_threshold,1000},\n {queue_index_embed_msgs_below,4096},\n {queue_index_max_journal_entries,32768},\n {reverse_dns_lookups,false},\n {sasl_error_logger,tty},\n {server_properties,[]},\n {ssl_allow_poodle_attack,false},\n {ssl_apps,[asn1,crypto,public_key,ssl]},\n {ssl_cert_login_from,distinguished_name},\n {ssl_handshake_timeout,5000},\n {ssl_listeners,[]},\n {ssl_options,[]},\n {tcp_listen_options,\n [{backlog,128},\n {nodelay,true},\n {linger,{true,0}},\n {exit_on_close,false}]},\n {tcp_listeners,[5672]},\n {trace_vhosts,[]},\n {vm_memory_high_watermark,0.4},\n {vm_memory_high_watermark_paging_ratio,0.5}]},\n {rabbit_common,[]},\n {rabbitmq_management,\n [{cors_allow_origins,[]},\n {cors_max_age,1800},\n {http_log_dir,none},\n {listener,[{port,15672}]},\n {load_definitions,none},\n {management_db_cache_multiplier,5},\n {process_stats_gc_timeout,300000},\n {stats_event_max_backlog,250}]},\n {rabbitmq_management_agent,\n [{rates_mode,basic},\n {sample_retention_policies,\n [{global,[{605,5},{3660,60},{29400,600},{86400,1800}]},\n {basic,[{605,5},{3600,60}]},\n {detailed,[{605,5}]}]}]},\n {rabbitmq_web_dispatch,[]},\n {ranch,[]},\n {sasl,[{errlog_type,error},{sasl_error_logger,tty}]},\n {ssl,[]},\n {stdlib,[]},\n {syntax_tools,[]},\n {xmerl,[]}]\n\nConnections:\npid name port peer_port host peer_host ssl peer_cert_subject peer_cert_issuer peer_cert_validity auth_mechanismssl_protocol ssl_key_exchange ssl_cipher ssl_hash protocol user vhost timeout frame_max channel_max client_properties connected_at recv_oct recv_cnt send_oct send_cnt send_pend state channels reductions garbage_collection\n<ksaprice_rabbitmq@4eed789778c0.1.7700.0> 172.25.0.2:47982 -> 172.25.0.4:5672 5672 47982 172.25.0.4 172.25.0.2 false AMQPLAIN {0,9,1} admin ksaprice_rabbitmq_vh 0 131072 65535 [{\"product\",\"py-amqp\"},{\"product_version\",\"2.2.1\"},{\"capabilities\",[{\"connection.blocked\",true},{\"authentication_failure_close\",true},{\"consumer_cancel_notify\",true}]}] 1501749265595 1897 10 606 7 0 running 1 235055 [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,170}]\n<ksaprice_rabbitmq@4eed789778c0.1.7755.0> 172.25.0.2:48764 -> 172.25.0.4:5672 5672 48764 172.25.0.4 172.25.0.2 false AMQPLAIN {0,9,1} admin ksaprice_rabbitmq_vh 0 131072 65535 [{\"product\",\"py-amqp\"},{\"product_version\",\"2.2.1\"},{\"capabilities\",[{\"connection.blocked\",true},{\"authentication_failure_close\",true},{\"consumer_cancel_notify\",true}]}] 1501749346461 289 5 554 4 0 running 1 226409 [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,161}]\n<ksaprice_rabbitmq@4eed789778c0.1.7764.0> 172.25.0.2:48766 -> 172.25.0.4:5672 5672 48766 172.25.0.4 172.25.0.2 false AMQPLAIN {0,9,1} admin ksaprice_rabbitmq_vh 0 131072 65535 [{\"product\",\"py-amqp\"},{\"product_version\",\"2.2.1\"},{\"capabilities\",[{\"connection.blocked\",true},{\"authentication_failure_close\",true},{\"consumer_cancel_notify\",true}]}] 1501749346494 1647 21 1030 20 0 running 1 228859 [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,171}]\n<ksaprice_rabbitmq@4eed789778c0.1.7767.0> 172.25.0.2:48768 -> 172.25.0.4:5672 5672 48768 172.25.0.4 172.25.0.2 false AMQPLAIN {0,9,1} admin ksaprice_rabbitmq_vh 0 131072 65535 [{\"product\",\"py-amqp\"},{\"product_version\",\"2.2.1\"},{\"capabilities\",[{\"connection.blocked\",true},{\"authentication_failure_close\",true},{\"consumer_cancel_notify\",true}]}] 1501749346494 569 9 662 8 0 running 1 226947 [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,164}]\n<ksaprice_rabbitmq@4eed789778c0.1.7770.0> 172.25.0.2:48770 -> 172.25.0.4:5672 5672 48770 172.25.0.4 172.25.0.2 false AMQPLAIN {0,9,1} admin ksaprice_rabbitmq_vh 0 131072 65535 [{\"product\",\"py-amqp\"},{\"product_version\",\"2.2.1\"},{\"capabilities\",[{\"connection.blocked\",true},{\"authentication_failure_close\",true},{\"consumer_cancel_notify\",true}]}] 1501749346495 1647 20 1030 20 0 running 1 228798 [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,167}]\n<ksaprice_rabbitmq@4eed789778c0.1.7787.0> 172.25.0.2:48772 -> 172.25.0.4:5672 5672 48772 172.25.0.4 172.25.0.2 false AMQPLAIN {0,9,1} admin ksaprice_rabbitmq_vh 0 131072 65535 [{\"product\",\"py-amqp\"},{\"product_version\",\"2.2.1\"},{\"capabilities\",[{\"connection.blocked\",true},{\"authentication_failure_close\",true},{\"consumer_cancel_notify\",true}]}] 1501749346511 85953 485 1042 21 0 running 1 280680 [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,110}]\n<ksaprice_rabbitmq@4eed789778c0.1.7806.0> 172.25.0.2:48774 -> 172.25.0.4:5672 5672 48774 172.25.0.4 172.25.0.2 false AMQPLAIN {0,9,1} admin ksaprice_rabbitmq_vh 0 131072 65535 [{\"product\",\"py-amqp\"},{\"product_version\",\"2.2.1\"},{\"capabilities\",[{\"connection.blocked\",true},{\"authentication_failure_close\",true},{\"consumer_cancel_notify\",true}]}] 1501749346548 665 7 566 5 0 running 1 226665 [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,168}]\n<ksaprice_rabbitmq@4eed789778c0.1.7815.0> 172.25.0.2:48776 -> 172.25.0.4:5672 5672 48776 172.25.0.4 172.25.0.2 false AMQPLAIN {0,9,1} admin ksaprice_rabbitmq_vh 0 131072 65535 [{\"product\",\"py-amqp\"},{\"product_version\",\"2.2.1\"},{\"capabilities\",[{\"connection.blocked\",true},{\"authentication_failure_close\",true},{\"consumer_cancel_notify\",true}]}] 1501749346551 1647 21 1030 20 0 running 1 228859 [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,171}]\n<ksaprice_rabbitmq@4eed789778c0.1.7839.0> 172.25.0.2:48780 -> 172.25.0.4:5672 5672 48780 172.25.0.4 172.25.0.2 false AMQPLAIN {0,9,1} admin ksaprice_rabbitmq_vh 0 131072 65535 [{\"product\",\"py-amqp\"},{\"product_version\",\"2.2.1\"},{\"capabilities\",[{\"connection.blocked\",true},{\"authentication_failure_close\",true},{\"consumer_cancel_notify\",true}]}] 1501749346576 1691 9 566 5 0 running 1 226936 [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,169}]\n<ksaprice_rabbitmq@4eed789778c0.1.7842.0> 172.25.0.2:48778 -> 172.25.0.4:5672 5672 48778 172.25.0.4 172.25.0.2 false AMQPLAIN {0,9,1} admin ksaprice_rabbitmq_vh 0 131072 65535 [{\"product\",\"py-amqp\"},{\"product_version\",\"2.2.1\"},{\"capabilities\",[{\"connection.blocked\",true},{\"authentication_failure_close\",true},{\"consumer_cancel_notify\",true}]}] 1501749346576 1496 9 566 5 0 running 1 226885 [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,161}]\n\nChannels:\npid name connection number user vhost reductions transactional confirm consumer_count messages_unacknowledged messages_unconfirmed messages_uncommitted acks_uncommitted prefetch_count global_prefetch_count state garbage_collection\n<ksaprice_rabbitmq@4eed789778c0.1.7706.0> 172.25.0.2:47982 -> 172.25.0.4:5672 (1) <ksaprice_rabbitmq@4eed789778c0.1.7700.0> 1 admin ksaprice_rabbitmq_vh 4140 false false 0 0 0 0 0 0 0 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,8}]\n<ksaprice_rabbitmq@4eed789778c0.1.7761.0> 172.25.0.2:48764 -> 172.25.0.4:5672 (1) <ksaprice_rabbitmq@4eed789778c0.1.7755.0> 1 admin ksaprice_rabbitmq_vh 1706 false false 0 0 0 0 0 0 0 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,8}]\n<ksaprice_rabbitmq@4eed789778c0.1.7776.0> 172.25.0.2:48768 -> 172.25.0.4:5672 (1) <ksaprice_rabbitmq@4eed789778c0.1.7767.0> 1 admin ksaprice_rabbitmq_vh 4737 false false 1 0 0 0 0 0 0 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,6}]\n<ksaprice_rabbitmq@4eed789778c0.1.7788.0> 172.25.0.2:48770 -> 172.25.0.4:5672 (1) <ksaprice_rabbitmq@4eed789778c0.1.7770.0> 1 admin ksaprice_rabbitmq_vh 8608 false false 0 0 0 0 0 0 0 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,3}]\n<ksaprice_rabbitmq@4eed789778c0.1.7793.0> 172.25.0.2:48766 -> 172.25.0.4:5672 (1) <ksaprice_rabbitmq@4eed789778c0.1.7764.0> 1 admin ksaprice_rabbitmq_vh 7977 false false 0 0 0 0 0 0 0 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,3}]\n<ksaprice_rabbitmq@4eed789778c0.1.7812.0> 172.25.0.2:48772 -> 172.25.0.4:5672 (1) <ksaprice_rabbitmq@4eed789778c0.1.7787.0> 1 admin ksaprice_rabbitmq_vh 116017 false false 0 0 0 0 0 0 0 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,1}]\n<ksaprice_rabbitmq@4eed789778c0.1.7827.0> 172.25.0.2:48776 -> 172.25.0.4:5672 (1) <ksaprice_rabbitmq@4eed789778c0.1.7815.0> 1 admin ksaprice_rabbitmq_vh 7977 false false 0 0 0 0 0 0 0 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,3}]\n<ksaprice_rabbitmq@4eed789778c0.1.7835.0> 172.25.0.2:48774 -> 172.25.0.4:5672 (1) <ksaprice_rabbitmq@4eed789778c0.1.7806.0> 1 admin ksaprice_rabbitmq_vh 3048 false false 0 0 0 0 0 0 0 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,4}]\n<ksaprice_rabbitmq@4eed789778c0.1.7854.0> 172.25.0.2:48778 -> 172.25.0.4:5672 (1) <ksaprice_rabbitmq@4eed789778c0.1.7842.0> 1 admin ksaprice_rabbitmq_vh 2854 false false 0 0 0 0 0 0 0 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,4}]\n<ksaprice_rabbitmq@4eed789778c0.1.7855.0> 172.25.0.2:48780 -> 172.25.0.4:5672 (1) <ksaprice_rabbitmq@4eed789778c0.1.7839.0> 1 admin ksaprice_rabbitmq_vh 3245 false false 0 0 0 0 0 0 0 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,6}]\n\nQueues on ksaprice_rabbitmq_vh:\npid name durable auto_delete arguments owner_pid exclusive messages_ready messages_unacknowledged messages reductions policy exclusive_consumer_pid exclusive_consumer_tag consumers consumer_utilisation memory slave_pids synchronised_slave_pids recoverable_slaves state garbage_collection messages_ram messages_ready_ram messages_unacknowledged_ram messages_persistent message_bytes message_bytes_ready message_bytes_unacknowledged message_bytes_ram message_bytes_persistent head_message_timestamp disk_reads disk_writes backing_queue_status messages_paged_out message_bytes_paged_out\n<ksaprice_rabbitmq@4eed789778c0.1.7670.0> default true false [] false 6 0 6 88075 0 89344 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,3}] 6 6 0 6 1231 1231 0 1231 1231 0 6 [{mode,default}, {q1,0}, {q2,0}, {delta,{delta,undefined,0,0,undefined}}, {q3,0}, {q4,6}, {len,6}, {target_ram_count,infinity}, {next_seq_id,6}, {avg_ingress_rate,9.303060867567184e-92}, {avg_egress_rate,0.0}, {avg_ack_ingress_rate,0.0}, {avg_ack_egress_rate,0.0}] 0 0\n<ksaprice_rabbitmq@4eed789778c0.1.7861.0> celeryev.b957bbf3-8b97-4633-897f-a887b49e617b false true [{\"x-message-ttl\",5000},{\"x-expires\",60000}] false 0 0 0 4739 1 1.0 22160 running [{max_heap_size,0}, {min_bin_vheap_size,46422}, {min_heap_size,233}, {fullsweep_after,65535}, {minor_gcs,8}] 0 0 0 0 0 0 0 0 0 0 0 [{mode,default}, {q1,0}, {q2,0}, {delta,{delta,undefined,0,0,undefined}}, {q3,0}, {q4,0}, {len,0}, {target_ram_count,infinity}, {next_seq_id,0}, {avg_ingress_rate,0.0}, {avg_egress_rate,0.0}, {avg_ack_ingress_rate,0.0}, {avg_ack_egress_rate,0.0}] 0 0\n\nQueues on ksaprice_rabbitmq:\n\nQueues on /:\n\nExchanges on ksaprice_rabbitmq_vh:\nname type durable auto_delete internal arguments policy\n direct true false false []\namq.direct direct true false false []\namq.fanout fanout true false false []\namq.headers headers true false false []\namq.match headers true false false []\namq.rabbitmq.trace topic true false true []\namq.topic topic true false false []\ncelery.pidbox fanout false false false []\nceleryev topic true false false []\ndefault direct true false false []\nreply.celery.pidbox direct false false false []\n\nExchanges on ksaprice_rabbitmq:\nname type durable auto_delete internal arguments policy\n direct true false false []\namq.direct direct true false false []\namq.fanout fanout true false false []\namq.headers headers true false false []\namq.match headers true false false []\namq.rabbitmq.trace topic true false true []\namq.topic topic true false false []\n\nExchanges on /:\nname type durable auto_delete internal arguments policy\n direct true false false []\namq.direct direct true false false []\namq.fanout fanout true false false []\namq.headers headers true false false []\namq.match headers true false false []\namq.rabbitmq.log topic true false true []\namq.rabbitmq.trace topic true false true []\namq.topic topic true false false []\n\nBindings on ksaprice_rabbitmq_vh:\nsource_name source_kind destination_name destination_kind routing_key arguments vhost\n exchange celeryev.b957bbf3-8b97-4633-897f-a887b49e617b queue celeryev.b957bbf3-8b97-4633-897f-a887b49e617b [] ksaprice_rabbitmq_vh\n exchange default queue default [] ksaprice_rabbitmq_vh\nceleryev exchange celeryev.b957bbf3-8b97-4633-897f-a887b49e617b queue # [] ksaprice_rabbitmq_vh\ndefault exchange default queue default [] ksaprice_rabbitmq_vh\n\nBindings on ksaprice_rabbitmq:\n\nBindings on /:\n\nConsumers on ksaprice_rabbitmq_vh:\nqueue_name channel_pid consumer_tag ack_required prefetch_count arguments\nceleryev.b957bbf3-8b97-4633-897f-a887b49e617b <ksaprice_rabbitmq@4eed789778c0.1.7776.0> None4 false 0 []\n\nConsumers on ksaprice_rabbitmq:\n\nConsumers on /:\n\nPermissions on ksaprice_rabbitmq_vh:\nuser configure write read\nadmin .* .* .*\n\nPermissions on ksaprice_rabbitmq:\n\nPermissions on /:\nuser configure write read\nguest .* .* .*\n\nPolicies on ksaprice_rabbitmq_vh:\n\nPolicies on ksaprice_rabbitmq:\n\nPolicies on /:\n\nParameters on ksaprice_rabbitmq_vh:\n\nParameters on ksaprice_rabbitmq:\n\nParameters on /:\n```\n\n```text\nbroker_url = amqp://guest:***@ksaprice_rabbitmq:15672//\n```\n\n```text\nbroker_url = pyamqp://guest:***@ksaprice_rabbitmq:15672//\n```\n\n```text\nairflow worker\n```\n\n```text\nbroker_url = amqp://guest:***@ksaprice_rabbitmq:15672//\n```\n\n```text\nbroker_url = amqp://guest:***@ksaprice_rabbitmq//\n```\n\n```text\nrabbitmqctl report\n```\n\n```text\ndefault\n```\n\n```text\nceleryev.b957bbf3-8b97-4633-897f-a887b49e617b\n```\n\n========================================\n\nComments:\n- Thanks alot @Jean for the answer, now the webserver and scheduler are not getting hanged while queuing. The worker is not receiving the task to execute. Your answer solved half of my problem.Although I am running airflow worker celery flower is not showing any workers in the dashboard.\n- Do you have to configure the topology (exchanges, queues and bindings) in RabbitMQ, or is it something handled internally by Airflow/Celery?\n- I think handled by Airflow internally, the only setting related to worker is `worker_log_server_port = 8793` the other worker settings in airflow.cfg file are related to: timeout, batch_size, internal and concurrency etc.All the available settings can be seen here: github.com/puckel/docker-airflow/blob/master/config/airflow.‌​cfg\n- Could you please post the output of `rabbitmqctl report` while the whole system is running?\n- updated the rabbitmqctl report, please check in the question\n- The queue:celeryev.b957bbf3-8b97-4633-897f-a887b49e617b was running because of `airflow flower` which a service to dispaly celery workers. When I stopped this service the aforementioned queue got disabled. My worker are still are not running the task. There is no consumer on the default queue for some reason.\n- Ok. The problem being outside of RabbitMQ, I won't be able to help you as I don't know Airflow, sorry :-(\n- Thanks for your @Jean, I have created another question for the issue: stackoverflow.com/questions/45485549/…","metadata":{"transformedAt":"2026-08-18T18:33:20.202Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":10,"totalLines":729,"estimatedTokens":11450}}932{"id":"stack-16355550","source":"stackoverflow","questionId":16355550,"title":"AMQP - How many consumers on a queue?","tags":["node.js","rabbitmq","amqp"],"text":"Title: AMQP - How many consumers on a queue?\nTags: node.js, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nUsing AMQP module for Node JS and RabbitMQ, is there any way to tell how many subscribers there are on a queue?\n\nWe have multiple queues on the default exchange for multiple regions. When one region is down, instead of routing messages to that queue, we'll instead route to the next-best AMQP queue (region) that is actively listening.\n\nIs there any way to count the number of subscribers on a queue?\n\nWe have a heartbeat set up so the server should be able to track accurately.\n\nThanks!\n\n========================================\n\nCode:\n```text\nvar conn = amqp.createConnection({ url: process.env.AMQP, heartbeat: 60 });\n\nconn.queue('queue-name').on('queueDeclareOk', function(args) {\n console.log('Total Consumers: ' + args.consumerCount);\n}\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.202Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":25,"estimatedTokens":214}}933{"id":"stack-14959835","source":"stackoverflow","questionId":14959835,"title":"What is the intended use of amq.topic?","tags":["rabbitmq","amqp"],"text":"Title: What is the intended use of amq.topic?\nTags: rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nWhat is the purpose of the predefined amq.topic exchange?\n\nAm I allowed to use it for my own purposes?\n\n========================================\n\nCode:\n```text\nTopic exchange\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.202Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":15,"estimatedTokens":70}}934{"id":"stack-30343887","source":"stackoverflow","questionId":30343887,"title":"PHPUnit RabbitMQ: write test for create connection function","tags":["php","phpunit","rabbitmq"],"text":"Title: PHPUnit RabbitMQ: write test for create connection function\nTags: php, phpunit, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm facing the following problem. I've wrote a function that create a connection object (AMQPConnection) given the required parameters. Now I want to write the corresponding unit test. I just don't know how to do it without having the RabbitMQ broker running. Here is the function in question:\n\n```\npublic function getConnection($hostKey, array $params)\n{\n $connection = null;\n try {\n\n $connection = new AMQPConnection(\n $params['host'],\n $params['port'],\n $params['username'],\n $params['password'],\n $params['vhost']\n );\n\n // set this server as default for next connection connectionAttempt\n $this->setDefaultHostConfig($hostKey, $params);\n\n return $connection;\n } catch (\\Exception $ex) {\n\n if ($this->isAttemptExceeded()) {\n return $connection;\n } else {\n // increment connection connectionAttempt\n $this->setConnectionAttempt($this->getConnectionAttempt() + 1);\n\n return $this->getConnection($hostKey, $params);\n }\n }\n}\n```\n\n========================================\n\nTop Answer:\nYou should add an ability to change the class being instantiated. \n\n- Add an ability to change the connector class via constructor or setter, with a default AMQPConnector class by default. Use it to create a connector object. Example\n\n- Create a mocked connector class for unit tests. Example\n\n- Use it setting the mock class via constructor or setter in tests. Example\n\nYou could also do assertions on what arguments are passed to the connector constructor. \n\nAnother way would be to use amqp interop so you are not coupled to any implementation. Much easier to tests as you deal with pure interfaces only.\n\n========================================\n\nCode:\n```php\npublic function getConnection($hostKey, array $params)\n{\n $connection = null;\n try {\n\n $connection = new AMQPConnection(\n $params['host'],\n $params['port'],\n $params['username'],\n $params['password'],\n $params['vhost']\n );\n\n // set this server as default for next connection connectionAttempt\n $this->setDefaultHostConfig($hostKey, $params);\n\n return $connection;\n } catch (\\Exception $ex) {\n\n if ($this->isAttemptExceeded()) {\n return $connection;\n } else {\n // increment connection connectionAttempt\n $this->setConnectionAttempt($this->getConnectionAttempt() + 1);\n\n return $this->getConnection($hostKey, $params);\n }\n }\n}\n```\n\n```php\n$connectionFunction = function ($params) {\n return new AMQPStreamConnection(\n $params['host'],\n $params['port'],\n $params['username'],\n $params['password'],\n $params['vhost']\n );\n };\n```\n\n```php\n/**\n * @param string $hostKey The array key of the host connection parameter set\n * @param array $params The connection parameters set\n * @return null|AMQPStreamConnection\n */\npublic function getConnection($hostKey, array $params)\n{\n $connection = null;\n try {\n $connection = call_user_func($connectionFunction, $params);\n\n // set this server as default for next connection connectionAttempt\n $this->setDefaultHostConfig($hostKey, $params);\n\n return $connection;\n } catch (\\Exception $ex) {\n\n if ($this->isAttemptExceeded()) {\n return $connection;\n } else {\n // increment connection connectionAttempt\n $this->setConnectionAttempt($this->getConnectionAttempt() + 1);\n\n return $this->getConnection($hostKey, $params);\n }\n }\n}\n```\n\n```php\n$mockConnection = $this->getMockBuilder('PhpAmqpLib\\Connection\\AMQPStreamConnection')\n ->disableOriginalConstructor()\n ->getMock();\n\n$connectionFunction = function ($params) use ($mockConnection) {\n return $mockConnection;\n};\n```\n\n```php\n$connectionFunction = function ($params) {\n throw new \\Exception;\n};\n```\n\n```text\ngetConnection()\n```\n\n```text\nAMQPStreamConnection\n```\n\n```text\nAMQPConnection\n```\n\n```text\nPhpAmqpLib\n```\n\n========================================\n\nComments:\n- Hi chozilla, Thanks for the quick reaction. This right is not related to `PDO` or `database`. Thing kind of things may be handle the same way, I just don't know. It's about RabbitMQ and connection to a broker.\n- @dickwan it's the same - you don't test connection to database, and you don't test connections to rabbitmq, just because it's not your code - it just works, trust it. Otherwise you would have to test the whole php standard library before you started using it.\n- @zerkms: Oh thank you for the clarifications. Now I wonder how I can assure that to code portion is covered.\n- @dickwan make a \"Integration\" or \"installation\" test-suite. But don't run it. Only when you install a server.\n- @chozilla: After your responses, I opted - in order to achieve good code coverage in my unit test - to use an anonymous function to return (inject) an AMQPConnection object. Thus isolating the code that create a connection to the server from the rest. I'll post later on what I changed in my code.","metadata":{"transformedAt":"2026-08-18T18:33:20.203Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":171,"estimatedTokens":1305}}935{"id":"stack-10190716","source":"stackoverflow","questionId":10190716,"title":"working with high-availability RabbitMQ server pair via WCF","tags":["wcf","message-queue","rabbitmq","high-availability","failover"],"text":"Title: working with high-availability RabbitMQ server pair via WCF\nTags: wcf, message-queue, rabbitmq, high-availability, failover\nSource: Stack Overflow\n\nQuestion:\nI'm trying to figure out what is the best solution to work with rabbitmq cluster via wcf.\n\nCurrent setup:\n\n- 2 IIS web servers (act as message produces and post messages to queue via amqp wcf client).\n\n- 2 servers with rabbitmq broker (clustered with mirrored queue, rabbit1 and rabbit2)\n\n- Windows service ( worker) with hosted amqp wcf service that listens to incoming messages.\n\nWeb role posts messages to rabbit1 node and worker listens to rabbit1 node too. If rabbit1 node fails system(both web and worker) should switch to rabbit2. And that's the question, how to implement this in more elegant way rather than handling connection failures in application code.\n\nFirst and the only approach I see now is to use wcf4 routing backup endpoints feature. This way solves problem on client side(web role) only but doesn't solve problem on wcf service side(worker role).","metadata":{"transformedAt":"2026-08-18T18:33:20.203Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":18,"estimatedTokens":259}}936{"id":"stack-24261941","source":"stackoverflow","questionId":24261941,"title":"RabbitMQ Consumer Disconnect Event","tags":["events","rabbitmq","message"],"text":"Title: RabbitMQ Consumer Disconnect Event\nTags: events, rabbitmq, message\nSource: Stack Overflow\n\nQuestion:\nIs there any way we can know when a consumer disconnects from a queue or when a queue is deleted?\n\nThe requirement is as follows:\n\nI'm building a system in which multiple clients can subscribe to certain events from the system. All clients create their own queue and registers themselves with the system using some sort of authentication. The system, as the events are generated, filters the events and forwards them to clients who are eligible for them.\n\nI have implemented a POC for most part of it and it works well. An issue that I'm not able to fix is that, if a client just disconnects from the queue (due to program termination or so), the registration still exists and the system keeps trying to push messages to that client.\n\nSo we would like to be notified when a client disconnects or a queue gets deleted so that we can remove that client's registration data and no longer push messages to him.\n\n========================================\n\nCode:\n```text\nmandatory\n```\n\n========================================\n\nComments:\n- it's a great idea. Also I found this plugin: rabbitmq_event_exchange. What are your ideas regarding using this community plugin?\n- I've never used it in production, but if they say it works why not just give a try?\n- I just implemented it in a POC and it seems to work just great. Very useful.","metadata":{"transformedAt":"2026-08-18T18:33:20.203Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":28,"estimatedTokens":359}}937{"id":"stack-26932585","source":"stackoverflow","questionId":26932585,"title":"RabbitMQ on Azure connection timeout","tags":["azure","rabbitmq"],"text":"Title: RabbitMQ on Azure connection timeout\nTags: azure, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nWe have some problems porting our software on Azure. Our solution is composed by 2 websites (frontend, backend) and a webjob (a win service when installed on our hardware). These nodes communicate using a RabbitMQ cluster (2 Ubuntu VM).\nOn premises we haven't any problems but when installed on Azure we see many errors like:\n\n```\nPublisher did not confirm message\n```\n\nor\n\n```\nPublish not confirmed before channel closed\n```\n\nor\n\n```\nSocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 104.40.186.27:5672\n```\n\nOn RabbitMQ we see these kind of errors:\n\n```\nclosing AMQP connection (100.73.204.90:61152 -> 100.73.205.2:5672):\n {handshake_timeout,handshake}\n```\n\nThe result is that often messages are not correctly received.\n\nWe use MassTransit on top of RabbitMQ for the actual messages exchange.\nHere our procedure to setup the environment:\n\nWe first create the 2 Ubuntu 14.04 virtual machines (A3: 4 cores, 7 GB) on the same cloud services.\nWe create 2 public endpoints with a load balancer for port 5672 and 15672. Our clients are hosted inside Azure websites on the same region.\n\nHere our powershel script to create the 2 VM:\n\n```\n$imageName = \"b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-14_04_1-LTS-amd64-server-20140927-en-us-30GB\"\n\n$vmc = New-AzureVMConfig -Name $machineName -InstanceSize \"Small\" -Image $imageName -AvailabilitySetName $serviceName\n\n$null = $vmc | Add-AzureProvisioningConfig -Linux -LinuxUser $user -Password $password\n$null = $vmc | New-AzureVM -ServiceName $serviceName -WaitForBoot\n\n$vm = Get-AzureVM -Name $machineName -ServiceName $serviceName\n\n$null = Add-RabbitMQEndpoint -vm $vm -port 5672 -name \"RabbitMQ-Main\"\n$null = Add-RabbitMQEndpoint -vm $vm -port 15672 -name \"RabbitMQ-Mgmt\"\n\n$null = $vm | Update-AzureVM\n\nFunction Add-RabbitMQEndpoint($vm,$port,$name)\n{\n $lbName = $name + \"_LB\"\n $null = Add-AzureEndpoint -VM $vm -LocalPort $port -PublicPort $port -Name $name -Protocol tcp -LBSetName $lbName -ProbePort $port -ProbeProtocol tcp -ProbeIntervalInSeconds 15\n}\n```\n\nThen we run following script to install RabbitMQ on both machine:\n\n```\nsudo add-apt-repository 'deb http://www.rabbitmq.com/debian/ testing main'\"\n sudo apt-get update\n sudo apt-get -q -y --force-yes install rabbitmq-server=3.4.1-1\n\n sudo invoke-rc.d rabbitmq-server stop\n echo 'MYCOOKIEVALUE' | sudo tee /var/lib/rabbitmq/.erlang.cookie\n sudo chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie\n sudo chmod 400 /var/lib/rabbitmq/.erlang.cookie\n sudo invoke-rc.d rabbitmq-server start\n\n sudo rabbitmq-plugins enable rabbitmq_management\n sudo invoke-rc.d rabbitmq-server stop\n sudo invoke-rc.d rabbitmq-server start\n\n sudo rabbitmqctl add_user user1 pwd1\n sudo rabbitmqctl set_user_tags user1 administrator\n sudo rabbitmqctl set_permissions -p / user1 '.*' '.*' '.*'\n```\n\nAnd then we create the cluster using:\n\n```\nsudo rabbitmqctl stop_app\n sudo rabbitmqctl join_cluster rabbit@$mymachinename\n sudo rabbitmqctl start_app\n sudo rabbitmqctl set_cluster_name my_cluster_name\n```\n\nWe have not opened any other port (like 4369 and 25672) because we suppose that these are only used for internal communication between nodes. It is right?\nWe connect to rabbitmq from the client using the cloud service host name. We have also tried to remove the cluster and just connect to a single RabbitMQ VM.\n\nDo you have any idea? Seems to be some kind of timeout problem? Can be a network partition problem?\n\n========================================\n\nCode:\n```text\nPublisher did not confirm message\n```\n\n```text\nPublish not confirmed before channel closed\n```\n\n```text\nSocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 104.40.186.27:5672\n```\n\n```text\nclosing AMQP connection <0.390.0> (100.73.204.90:61152 -> 100.73.205.2:5672):\n {handshake_timeout,handshake}\n```\n\n```text\n$imageName = \"b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-14_04_1-LTS-amd64-server-20140927-en-us-30GB\"\n\n$vmc = New-AzureVMConfig -Name $machineName -InstanceSize \"Small\" -Image $imageName -AvailabilitySetName $serviceName\n\n$null = $vmc | Add-AzureProvisioningConfig -Linux -LinuxUser $user -Password $password\n$null = $vmc | New-AzureVM -ServiceName $serviceName -WaitForBoot\n\n$vm = Get-AzureVM -Name $machineName -ServiceName $serviceName\n\n$null = Add-RabbitMQEndpoint -vm $vm -port 5672 -name \"RabbitMQ-Main\"\n$null = Add-RabbitMQEndpoint -vm $vm -port 15672 -name \"RabbitMQ-Mgmt\"\n\n$null = $vm | Update-AzureVM\n\nFunction Add-RabbitMQEndpoint($vm,$port,$name)\n{\n $lbName = $name + \"_LB\"\n $null = Add-AzureEndpoint -VM $vm -LocalPort $port -PublicPort $port -Name $name -Protocol tcp -LBSetName $lbName -ProbePort $port -ProbeProtocol tcp -ProbeIntervalInSeconds 15\n}\n```\n\n```text\nsudo add-apt-repository 'deb http://www.rabbitmq.com/debian/ testing main'\"\n sudo apt-get update\n sudo apt-get -q -y --force-yes install rabbitmq-server=3.4.1-1\n\n sudo invoke-rc.d rabbitmq-server stop\n echo 'MYCOOKIEVALUE' | sudo tee /var/lib/rabbitmq/.erlang.cookie\n sudo chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie\n sudo chmod 400 /var/lib/rabbitmq/.erlang.cookie\n sudo invoke-rc.d rabbitmq-server start\n\n sudo rabbitmq-plugins enable rabbitmq_management\n sudo invoke-rc.d rabbitmq-server stop\n sudo invoke-rc.d rabbitmq-server start\n\n sudo rabbitmqctl add_user user1 pwd1\n sudo rabbitmqctl set_user_tags user1 administrator\n sudo rabbitmqctl set_permissions -p / user1 '.*' '.*' '.*'\n```\n\n```text\nsudo rabbitmqctl stop_app\n sudo rabbitmqctl join_cluster rabbit@$mymachinename\n sudo rabbitmqctl start_app\n sudo rabbitmqctl set_cluster_name my_cluster_name\n```\n\n========================================\n\nComments:\n- Do you have an SSH server configured on your Ubuntu? Can you connect to one of VM's and try to connect to the second one through SSH (to see if you have any network visibility)?\n- @plentysmart Yes I have tried and seems that the connection between the machines is ok. Also because the clustet is correct and I have also tried without the cluster but using a single vm for rabbitmq but the problem persists.\n- Have same problems. Have you managed to overcome them?\n- @lakomkin I have abandoned Rabbitmq in favor of Azure Service Bus. Seems to be a better solution for my use case and more reliable.","metadata":{"transformedAt":"2026-08-18T18:33:20.203Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":7,"totalLines":175,"estimatedTokens":1650}}938{"id":"stack-13831047","source":"stackoverflow","questionId":13831047,"title":"Many subscriptions to a single queue with RabbitMQ STOMP","tags":["rabbitmq","stomp"],"text":"Title: Many subscriptions to a single queue with RabbitMQ STOMP\nTags: rabbitmq, stomp\nSource: Stack Overflow\n\nQuestion:\nIs it possible to bind a single queue to many topics using RabbitMQ STOMP client?\n\nEach time a client sending SUBSCRIBE frame server creates a new queue for it, it makes usage of \"prefetch-count\" useless for me, because it applies to each subscription individually.\n\nI am just looking for any way to get messages with many topics in the single queue via RabbitMQ Web-STOMP. Any ideas?\n\n========================================\n\nCode:\n```text\nx-queue-name\n```\n\n========================================\n\nComments:\n- can you show us some of your code?\n- There was nothing special in my code. This time I've changed design of my app, but the question is how to bind one queue to many routing keys in RabbitMQ using its STOMP adapter. Currently the server creates new queue when receives SUBSCRIBE frame, but it is not the RabbitMQ style, as far as I understand it.\n- If this can help, this two frames will cause creation of two different queues:\n- SUBSCRIBE id:worker-1 destination:/topic/topic-A ack:client-individual\n- SUBSCRIBE id:worker-1-2 destination:/topic/topic-B ack:client-individual\n- The \"id\" field is required to be unique per session.\n- This is exactly what I am looking for. Any luck since then ?\n- No, but there is node.js and web sockets, since it works fine RabbitMQ is needed no more.\n- This is the feature of version 3.5.7 released 15 December 2015, I asked in 2012, but thank you :)","metadata":{"transformedAt":"2026-08-18T18:33:20.203Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":30,"estimatedTokens":380}}939{"id":"stack-63664178","source":"stackoverflow","questionId":63664178,"title":"Celery: How to batch produce tasks?","tags":["python","rabbitmq","celery"],"text":"Title: Celery: How to batch produce tasks?\nTags: python, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI have a large loop to produce tasks:\n\n```\nfor i in range(1000):\n receiver.apply_async(args=(i), kwargs={}, exchange=topic_exchange, routing_key=topic_key)\n```\n\nAnd I found there is a module `celery.contrib.batches` before celery 3.X or `celery_batches` after celery 4.X. But this module doesn't seem to support such params. So how can I do it?\n\nI'm using celery 4.4.7 with rabbitmq.\n\n========================================\n\nCode:\n```text\nfor i in range(1000):\n receiver.apply_async(args=(i), kwargs={}, exchange=topic_exchange, routing_key=topic_key)\n```\n\n```text\ncelery.contrib.batches\n```\n\n```text\ncelery_batches\n```\n\n========================================\n\nComments:\n- How about `kwargs`, `exchange` and `routing_key`? I guess I need to slice tasks by `routing_key` first, it is not so hard, but my kwargs are different for each task... or I must convert kwargs to args?\n- You can pass those to your signatures.\n- I tried `receiver.chunks(zip(range(1000)), 100)(kwargs={something}, exchange=topic_exchange, routing_key=topic_key)`, but kwargs still not work... So sorry I don't understand what 'pass those to your signatures' mean. Can you give me a simple example?","metadata":{"transformedAt":"2026-08-18T18:33:20.203Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":38,"estimatedTokens":321}}940{"id":"stack-42422439","source":"stackoverflow","questionId":42422439,"title":"RabbitMQ cluster - best practice for updating a node in a load balanced cluster?","tags":["rabbitmq","haproxy"],"text":"Title: RabbitMQ cluster - best practice for updating a node in a load balanced cluster?\nTags: rabbitmq, haproxy\nSource: Stack Overflow\n\nQuestion:\n**Summary: What's the best practice for updating a node in a load balanced cluster?**\n\nWe use RabbitMQ Cluster behind a ha proxy load balancer to support easy clustering for our clients, as suggested in the RabbitMQ docs\n\nThough the docs suggest this, they don't describe the best way to remove a node from the cluster for upgrades, and put it back in.\n\n### Here's the process I think we should use:\n\n- remove node from cluster by running `rabbitmqctl stop_app` on the node itself, and wait for it to shutdown\n\n- put node in maint mode in haproxy\n\n- perform maint work\n\n- join node back to cluster, confirm it rejoins and sync.\n\n- remove node from maint mode in haproxy\n\nbut I've had it suggested that we should remove it from ha proxy first, basically swapping steps 1 and 2 above\n\n### Here's the process suggested by another team member:\n\n- put node in maint mode in haproxy\n\n- remove node from cluster by running `rabbitmqctl stop_app` on the node itself, and wait for it to shutdown\n\n- perform maint work\n\n- join node back to cluster, confirm it rejoins and sync.\n\n- remove node from maint mode in haproxy\n\nWhich is the best way to do this?\n\n========================================\n\nCode:\n```text\nrabbitmqctl stop_app\n```\n\n```text\nrabbitmqctl stop_app\n```\n\n========================================\n\nComments:\n- Hmmm... Good point... I guess the thing to me is I'm not convinced the \"maint\" mode of haproxy is shutting down connections nicely, while telling a node in rabbitmq to `stop_app` does shut down the connections and node nicely. Do you know if haproxy should have the node set to \"DRAIN\" instead of \"MAINT\" ?\n- @BradParks you can do that indeed! see this question over at the neighbours: serverfault.com/questions/705991/… (mind you, this is a webserver, not a rabbitmq, but the same applies)\n- Thanks for the link! I'm reading on it, but seem to be able to find very little official information on the differences between MAINT and DRAIN for haproxy. I'll continue looking!","metadata":{"transformedAt":"2026-08-18T18:33:20.203Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":56,"estimatedTokens":536}}941{"id":"stack-59287520","source":"stackoverflow","questionId":59287520,"title":"Apache Camel RabbitMQ leaving behind threads in WAIT state","tags":["kotlin","rabbitmq","apache-camel"],"text":"Title: Apache Camel RabbitMQ leaving behind threads in WAIT state\nTags: kotlin, rabbitmq, apache-camel\nSource: Stack Overflow\n\nQuestion:\nI have a set of Camel routes configured to read and write to RabbitMQ queues, more or less like this:\n\n```\nfrom(\"rabbitmq:$rabbitMQVhost?connectionFactory=#customConnectionFactory&queue=${it.rabbitMQQueue}&routingKey=${it.rabbitMQQueue}&SOME_MORE_PROPERTIES\")\n .log(\"Read message from queue ${it.rabbitMQQueue}\")\n .routeId(it.rabbitMQQueue)\n .noAutoStartup()\n .bean(it.rabbitMQBean)\n .choice()\n .`when`(PredicateBuilder.and(simple(\"$myCondition\"), isNotNull(body())))\n .split(body())\n .toD(\"rabbitmq:$rabbitMQVhost?connectionFactory=#customConnectionFactory&queue=${it.rabbitMQQueueDestination}&autoDelete=false&routingKey=${it.rabbitMQQueueDestination}&bridgeEndpoint=true\")\n .endChoice()\n .otherwise()\n end()\n```\n\nWhere `SOME_MORE_PROPERTIES` is basically `autoDelete=false&autoAck=false` and some message prefetch settings.\n\nMy ConnectionFactory is a `org.springframework.amqp.rabbit.connection.CachingConnectionFactory`.\n\nWhenever a message comes in on my source queue, a thread is started to process it; however, after the processing is completed it hangs in WAIT state, never being released or terminated, so my application memory saturates after a while and there's nothing the garbage collector can do about it.\n\nAfter some time running, my application is basically in this state:\n\nhttps://i.sstatic.net/XeFgb.png\n\nIf I manually restart the routes, the threads are terminated and the memory released.\n\nIs there something I'm doing wrong in my routes configuration that is preventing the threads from terminating properly?\n\nI'd like to avoid having to write a quartz job to restart the routes every once in a while.\n\nEdit: I also recently updated from Camel 2.24.0 to the latest RC for Camel 3, but the issue is still happening.\n\n========================================\n\nCode:\n```text\nfrom(\"rabbitmq:$rabbitMQVhost?connectionFactory=#customConnectionFactory&queue=${it.rabbitMQQueue}&routingKey=${it.rabbitMQQueue}&SOME_MORE_PROPERTIES\")\n .log(\"Read message from queue ${it.rabbitMQQueue}\")\n .routeId(it.rabbitMQQueue)\n .noAutoStartup()\n .bean(it.rabbitMQBean)\n .choice()\n .`when`(PredicateBuilder.and(simple(\"$myCondition\"), isNotNull(body())))\n .split(body())\n .toD(\"rabbitmq:$rabbitMQVhost?connectionFactory=#customConnectionFactory&queue=${it.rabbitMQQueueDestination}&autoDelete=false&routingKey=${it.rabbitMQQueueDestination}&bridgeEndpoint=true\")\n .endChoice()\n .otherwise()\n end()\n```\n\n```text\nSOME_MORE_PROPERTIES\n```\n\n```text\nautoDelete=false&autoAck=false\n```\n\n```text\norg.springframework.amqp.rabbit.connection.CachingConnectionFactory\n```\n\n```text\nfrom(\"rabbitmq:$rabbitMQVhost?threadPoolSize=5&connectionFactory=#customConnectionFactory&queue=${it.rabbitMQQueue}\n```\n\n```text\nthreadPoolSize\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.203Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":77,"estimatedTokens":725}}942{"id":"stack-42200049","source":"stackoverflow","questionId":42200049,"title":"Are prefetched tasks in celery being acknowledged?","tags":["django","rabbitmq","celery","celery-task"],"text":"Title: Are prefetched tasks in celery being acknowledged?\nTags: django, rabbitmq, celery, celery-task\nSource: Stack Overflow\n\nQuestion:\nI have following setup:\n\n- RabbitMQ broker + Django\nCelery with CELERYD_PREFETCH_MULTIPLIER=32 (I have a lot of small task \nthus prefetching them makes a lot of sense from performance standpoint)\n\n- CELERY_ACKS_LATE=False (tasks are not idempotent)\n\nI run celery in docker container, so when I rebuild docker celery workers are not gracefully shut down. This is ok, if tasks are not acknowledged as broker will sent them back once workers be up again in new docker container, but in other case they - will be lost.\n\nIn flower admin panel prefetched tasks have status received.\n\nI had carefully read official documentation and related question and intuitively I feel that prefetched tasks in my setup are acknowledged. Is it so?\n\n========================================\n\nCode:\n```text\nCELERY_ACKS_LATE=False\n```\n\n========================================\n\nComments:\n- Thats sounds reasonable, but prefetched tasks in flower are marked as 'RECEIVED' - does it mean they have not started to to be executed?\n- I guess `RECEIVED` means `Unacked` in terms of Rabbitmq. Other workers can't prefetch them because they are not `Ready`. But if worker loses connection without acknowledgment they'll become `Ready`.\n- But if I'll reboot celery server(hard reboot) how will rabbitmq know that these tasks are able to be assigned to other nodes?\n- May be this question will be useful.\n- It is done automatically by rabbitmq when consumer closes its channel.\n- another useful explanation\n- Hi, thanks for your answers, indeed prefetched tasks turned out not to be acknowledged - they return to ready state as soon as celery workers die. Also we found a way to restart docker containers in more graceful way and now everything works fine.","metadata":{"transformedAt":"2026-08-18T18:33:20.203Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":36,"estimatedTokens":465}}943{"id":"stack-33034231","source":"stackoverflow","questionId":33034231,"title":"Reasons to not use the default exchange on RabbitMQ?","tags":["rabbitmq","rabbitmq-exchange"],"text":"Title: Reasons to not use the default exchange on RabbitMQ?\nTags: rabbitmq, rabbitmq-exchange\nSource: Stack Overflow\n\nQuestion:\nI've started working with RabbitMQ and my use case is quite simple - producers putting messages on queues to to processed by consumers. Each message is processed by at most one consumer and messages are directed from producer to consumer based on queue name.\n\n`Direct` exchanges seem perfectly fine for this and the `default` exchange is a `direct` exchange.\n\nAre there any reasons (performance, management, permissioning etc.) to not use the `default` exchange and create your own one instead? For example, I will be using high-availability queues (https://www.rabbitmq.com/ha.html) and wasn't sure if there would be any negative impact on the cluster if all the HA queues were on the `default` exchange as opposed to a different exchange?\n\n========================================\n\nCode:\n```text\nDirect\n```\n\n```text\ndefault\n```\n\n```text\ndirect\n```\n\n```text\ndefault\n```\n\n```text\ndefault\n```\n\n========================================\n\nComments:\n- Thanks. I wasn't worried about performance per se (it was just an example) but more if there are any good reasons to not use the default exchange if I want direct routing. For example, I recently found out that there are limitations around the default exchange and federation.\n- I don't see a reason to use the deafult exchange unless you are doing something like RPC","metadata":{"transformedAt":"2026-08-18T18:33:20.203Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":39,"estimatedTokens":361}}944{"id":"stack-49532169","source":"stackoverflow","questionId":49532169,"title":"Poor performance in simple tasks using celery","tags":["python","rabbitmq","celery"],"text":"Title: Poor performance in simple tasks using celery\nTags: python, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI am currently facing subpar performance when executing the following usecase:\n\nI have two files - tasks.py\n\n```\n# tasks.py\nfrom celery import Celery\n\napp = Celery('tasks', broker='pyamqp://guest@localhost//', backend='rpc://',worker_prefetch_multiplier=1)\n\n@app.task\ndef task(array_of_elements):\n return [x ** 2 for x in array_of_elements]\n```\n\nand run.py\n\n```\n# run.py\nfrom celery import group\nfrom itertools import chain, repeat\nfrom tasks import task\nimport time\n\ndef grouper(n, iterable, padvalue=None):\n return zip(*[chain(iterable, repeat(padvalue, n-1))]*n)\n\ndef fun1(x):\n return x ** 2\n\nif __name__ == '__main__':\n start = time.time()\n items = [list(x) for x in grouper(10000, range(10000))]\n x = group([task.s(item) for item in items])\n r = x.apply_async()\n d = r.get()\n end = time.time()\n print(f'>celery: {end-start} seconds')\n\n start = time.time()\n res = [fun1(x) for x in range(10000)]\n end = time.time()\n print(f'>normal: {end-start} seconds')\n```\n\nWhen I am trying running celery:\n celery -A tasks worker --loglevel=info\n\nand trying to run:\n\n```\npython run.py\n```\n\nThis is the output I get:\n\n```\n>celery: 0.19174742698669434 seconds\n>normal: 0.004475116729736328 seconds\n```\n\nI have no idea why the performance is worse in celery?\n\nI am trying to understand how can I achieve map-reduce paradigm using celery like split a huge array into smaller chunks, do some processing and bring results back\n\nAm I missing some critical configuration?\n\n========================================\n\nCode:\n```text\n# tasks.py\nfrom celery import Celery\n\napp = Celery('tasks', broker='pyamqp://guest@localhost//', backend='rpc://',worker_prefetch_multiplier=1)\n\n@app.task\ndef task(array_of_elements):\n return [x ** 2 for x in array_of_elements]\n```\n\n```text\n# run.py\nfrom celery import group\nfrom itertools import chain, repeat\nfrom tasks import task\nimport time\n\ndef grouper(n, iterable, padvalue=None):\n return zip(*[chain(iterable, repeat(padvalue, n-1))]*n)\n\ndef fun1(x):\n return x ** 2\n\nif __name__ == '__main__':\n start = time.time()\n items = [list(x) for x in grouper(10000, range(10000))]\n x = group([task.s(item) for item in items])\n r = x.apply_async()\n d = r.get()\n end = time.time()\n print(f'>celery: {end-start} seconds')\n\n start = time.time()\n res = [fun1(x) for x in range(10000)]\n end = time.time()\n print(f'>normal: {end-start} seconds')\n```\n\n```text\npython run.py\n```\n\n```text\n>celery: 0.19174742698669434 seconds\n>normal: 0.004475116729736328 seconds\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.203Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":122,"estimatedTokens":657}}945{"id":"stack-33267771","source":"stackoverflow","questionId":33267771,"title":"How to modify spring-websocket to interface with broker via MQTT instead of STOMP?","tags":["rabbitmq","ibm-mq","mqtt","stomp","spring-websocket"],"text":"Title: How to modify spring-websocket to interface with broker via MQTT instead of STOMP?\nTags: rabbitmq, ibm-mq, mqtt, stomp, spring-websocket\nSource: Stack Overflow\n\nQuestion:\nI'm building a spring-websocket application that currently uses RabbitMQ as a message broker via the STOMP protocol. The rest of our organization mostly uses IBM Websphere MQ as a message broker, so we'd like to convert it away from RabbitMQ. However Websphere MQ doesn't support the STOMP protocol, which is spring-websocket's default. MQTT seems like the easiest supported protocol to use instead. Ideally our front-end web clients will continue to use STOMP, but I'm also OK with migrating them to MQTT if needed.\n\nWhat classes do I need to overwrite to make spring-websocket interface with the broker via MQTT instead of STOMP? This article provides some general guidance that I should extend `AbstractMessageBrokerConfiguration`, but I'm unclear where to begin.\n\nCurrently I'm using the standard configuration methods: `registry.enableStompBrokerRelay` and `registerStompEndpoints` in `AbstractWebSocketMessageBrokerConfigurer`\n\n========================================\n\nTop Answer:\nHere's my stab at this after reviewing the spring-websocket source code:\n\nChange WebSocketConfig:\n\n- Remove @EnableWebSocketMessageBroker\n\n- Add new annotation: @EnableMqttWebSocketMessageBroker\n\nCreate MqttBrokerMessageHandler that extends AbstractBrokerMessageHandler -- suggest we copy and edit StompBrokerRelayMessageHandler\n\n- Create a new class that EnableMqttWebSocketMessageBroker imports: DelegatingMqttWebSocketMessageBrokerConfiguration\n\n- DelegatingMqttWebSocketMessageBrokerConfiguration extends AbstractMessageBrokerConfiguration directly and routes to MqttBrokerMessageHandler\n\n========================================\n\nCode:\n```text\nAbstractMessageBrokerConfiguration\n```\n\n```text\nregistry.enableStompBrokerRelay\n```\n\n```text\nregisterStompEndpoints\n```\n\n```text\nAbstractWebSocketMessageBrokerConfigurer\n```\n\n```text\n<feature>websocket-1.1</feature>\n```\n\n========================================\n\nComments:\n- I'm looking into the same problem. Did you make any progress on this?\n- Yes - I'm not finished yet, but I can say this approach works based on what I've completed so far. The original STOMP broker has quite a bit of code, so I'm still working through how much I need to replicate as part of the transition to IBM MQ. I'm also working on whether to integrate with MQ jars directly or go through the spring integration wrapper.\n- Hi. It's 2017 and I'm trying to do the same. Were you guys able to replace STOMP? Thanks!\n- Don't think they ever proceeded with implementation, but haven't heard anything saying this approach wouldn't work.","metadata":{"transformedAt":"2026-08-18T18:33:20.203Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":58,"estimatedTokens":682}}946{"id":"stack-67265453","source":"stackoverflow","questionId":67265453,"title":"RabbitMQ Producer C# .NET Core 5.0 Memory Leak","tags":["c#",".net","memory-leaks","rabbitmq"],"text":"Title: RabbitMQ Producer C# .NET Core 5.0 Memory Leak\nTags: c#, .net, memory-leaks, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI was wondering if someone can please help with the following situation:\n\nI cannot solve **a memory leak** with a RabbitMQ Publisher written in C# and using .Net core 5.0.\n\nThis is the csproj file :\n\n```\n \n \n Exe\n net5.0\n win-x64\n \n ...\n\n```\n\nI have a .net console application running inside a virtual machine which connects to a server through an API (a registered 64 bit dll and referenced as a COM reference), gets information from that server and then tries to publish this information to a RabbitMQ machines located on an AWS cloud (a load balancer with several nodes for this RMQ instance).\n\nAccessing the API in the code is done in the following way :\n\n```\nprivate void SetUpApi () {\n Utils.log.Info (_api.SetAPIOptions (\"\"));\n _api.OnServerConnect += OnServerConnect;\n _api.OnServerDisconnect += OnServerDisconnect;\n _api.OnNewData += OnNewData; \n }\n```\n\n```\nprivate void OnNewData(string strXML){\n try{\n if (strXML.Contains(\"During **peak** business hours I get around 400 - 500 messages/second from the API. These messages come in the form of XML messages. For example, a message can contain several orders as shown in the example below. One element can contain an action to insert (to create) an Order and another to remove a certain Order.\n\n```\n\n \n \n \n ...\n \n \n \n ...\n \n```\n\nThe RabbitMQ server is configured and I connect to it using SSL (with a certificate and a key for it).\nI use to connect to the RMQ the RabbitMQ.Client v6.2.1.\nThe exchange, the queues and the bindings are already defined in RabbitMQ. My Producer application only connects to it and starts publishing.\n\nhttps://i.sstatic.net/z6JBQ.png\n\nIt is important that I use a **synchronous** publishing method as the order of messages we get is very important. For example in one message we get an action to create an Order and another message which comes immediately after which is telling to remove the same Order. If I would use an **async** method to publish to RMQ I would be possibly get the removal action before the insert action.\n\n```\n\n \n \n ...\n \n```\n\nThe removal messages:\n\n```\n\n \n \n ...\n \n```\n\nI use the following method for publishing to RMQ: the object pool (Microsoft provides a package named Microsoft.Extensions.ObjectPool) - method described in here - https://www.c-sharpcorner.com/article/publishing-rabbitmq-message-in-asp-net-core/ .\n\nI'm using here the following code:\n\n```\nclass RabbitManager : IRabbitManager\n{\n private readonly DefaultObjectPool _objectPool;\n public RabbitManager(IPooledObjectPolicy objectPolicy){\n _objectPool = new DefaultObjectPool(objectPolicy, Environment.ProcessorCount * 2);\n }\n\n public void Publish(T message, string exchangeName, string exchangeType, string routeKey) where T : class {\n if (message == null)\n return;\n\n var channel = _objectPool.Get();\n try{\n var sendBytes = Encoding.UTF8.GetBytes(message.ToString());\n var properties = channel.CreateBasicProperties();\n properties.ContentType = \"application/json\";\n properties.DeliveryMode = 1; // Doesn't persist to disk\n properties.Timestamp = new AmqpTimestamp(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds());\n\n channel.BasicPublish(exchangeName, routeKey, properties, sendBytes);\n }\n catch (Exception ex) {\n throw ex;\n }\n finally {\n _objectPool.Return(channel);\n }\n }\n}\n```\n\n```\npublic class RabbitModelPooledObjectPolicy : IPooledObjectPolicy\n{\n private readonly RabbitOptions _options;\n private readonly IConnection _connection;\n\n public RabbitModelPooledObjectPolicy(RabbitOptions _options){\n this._options = _options;\n _connection = GetConnection();\n }\n\n private IConnection GetConnection() {\n var factory = new ConnectionFactory() {\n HostName = _options.HostName,\n UserName = _options.UserName,\n Password = _options.Password,\n //Port = _options.Port,\n VirtualHost = _options.VHost,\n };\n\n if (!String.IsNullOrEmpty(_options.CertPath))\n {\n factory.RequestedConnectionTimeout = TimeSpan.FromMilliseconds(5000);\n factory.Ssl.AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateNameMismatch | SslPolicyErrors.RemoteCertificateChainErrors;\n factory.Ssl.CertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateServerCertificate);\n factory.Ssl.ServerName = _options.HostName;\n factory.Ssl.CertPath = _options.CertPath;\n factory.Ssl.CertPassphrase = _options.CertPass;\n factory.Ssl.Version = SslProtocols.Tls12;\n factory.Ssl.Enabled = true;\n }\n\n factory.RequestedHeartbeat = TimeSpan.FromSeconds(1);\n factory.AutomaticRecoveryEnabled = true; // enable automatic connection recovery\n factory.RequestedChannelMax = 32;\n\n var _connection = factory.CreateConnection();\n _connection.ConnectionShutdown += Connection_ConnectionShutdown;\n\n return _connection;\n }\n\n private void Connection_ConnectionShutdown(object sender, ShutdownEventArgs e){\n Utils.log.Info(\"Connection broke!\");\n }\n\n private bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors){\n return true;\n }\n\n public IModel Create(){\n return _connection.CreateModel();\n }\n\n public bool Return(IModel obj) {\n if (obj.IsOpen) {\n return true;\n }\n else {\n obj?.Dispose();\n return false;\n }\n }\n}\n```\n\nBelow is a screenshot with the problem - the constant memory inscrease :\n\nhttps://i.sstatic.net/UalBA.png\n\nThis is the stack trace of a memory snapshot taken just after the above screenshot :\n\nhttps://i.sstatic.net/mKvbn.png\n\nJust after the screenshot above was taken I got the following error message in my program, in the console :\n\n```\n26-04-2021 10:41:48 - OnNewData () RabbitMQ.Client.Exceptions.AlreadyClosedException: Already closed: The AMQP operation was interrupted: AMQP close-reason, initiated by Library, code=0, text='End of stream', classId=0, methodId=0, cause=System.IO.EndOfStreamException: Reached the end of the stream. Possible authentication failure.\n at RabbitMQ.Client.Impl.InboundFrame.ReadFrom(Stream reader, Byte[] frameHeaderBuffer)\n at RabbitMQ.Client.Framing.Impl.Connection.MainLoopIteration()\n at RabbitMQ.Client.Framing.Impl.Connection.MainLoop()\n at RabbitMQ.Client.Framing.Impl.Connection.EnsureIsOpen()\n at RabbitMQ.Client.Framing.Impl.AutorecoveringConnection.CreateModel()\n at RabbitModelPooledObjectPolicy.Create() in C:\\Users\\user\\Desktop\\Projects\\ConsoleCoreApp1\\RabbitMQ\\RabbitModelPooledObjectPolicy.cs:line 77\n at Microsoft.Extensions.ObjectPool.DefaultObjectPool`1.Create()\n at Microsoft.Extensions.ObjectPool.DefaultObjectPool`1.Get()\n at RabbitManager.Publish[T](T message, String exchangeName, String exchangeType, String routeKey) in C:\\Users\\user\\Desktop\\Projects\\ConsoleCoreApp1\\RabbitMQ\\RabbitManager.cs:line 32\n at ConsoleApp1.Service1.SendOrderToRMQ(JObject order) in C:\\Users\\user\\Desktop\\Projects\\ConsoleCoreApp1\\Service1.cs:line 411\n at ConsoleApp1.Service1.ParseXMLAnswer(String strOutputXML, String caller) in C:\\Users\\user\\Desktop\\Projects\\ConsoleCoreApp1\\Service1.cs:line 372\n at ConsoleApp1.Service1.OnNewData(String strXML) in C:\\Users\\user\\Desktop\\Projects\\ConsoleCoreApp1\\Service1.cs:line 348\n26-04-2021 10:41:48 - OnNewData () RabbitMQ.Client.Exceptions.AlreadyClosedException: Already closed: The AMQP operation was interrupted: AMQP close-reason, initiated by Library, code=0, text='End of stream', classId=0, methodId=0, cause=System.IO.EndOfStreamException: Reached the end of the stream. Possible authentication failure.\n at RabbitMQ.Client.Impl.InboundFrame.ReadFrom(Stream reader, Byte[] frameHeaderBuffer)\n at RabbitMQ.Client.Framing.Impl.Connection.MainLoopIteration()\n at RabbitMQ.Client.Framing.Impl.Connection.MainLoop()\n at RabbitMQ.Client.Framing.Impl.Connection.EnsureIsOpen()\n at RabbitMQ.Client.Framing.Impl.AutorecoveringConnection.CreateModel()\n at RabbitModelPooledObjectPolicy.Create() in C:\\Users\\user\\Desktop\\Projects\\ConsoleCoreApp1\\RabbitMQ\\RabbitModelPooledObjectPolicy.cs:line 77\n at Microsoft.Extensions.ObjectPool.DefaultObjectPool`1.Create()\n at Microsoft.Extensions.ObjectPool.DefaultObjectPool`1.Get()\n at RabbitManager.Publish[T](T message, String exchangeName, String exchangeType, String routeKey) in C:\\Users\\user\\Desktop\\Projects\\ConsoleCoreApp1\\RabbitMQ\\RabbitManager.cs:line 32\n at ConsoleApp1.Service1.SendOrderToRMQ(JObject order) in C:\\Users\\user\\Desktop\\Projects\\ConsoleCoreApp1\\Service1.cs:line 411\n at ConsoleApp1.Service1.ParseXMLAnswer(String strOutputXML, String caller) in C:\\Users\\user\\Desktop\\Projects\\ConsoleCoreApp1\\Service1.cs:line 372\n at ConsoleApp1.Service1.OnNewData(String strXML) in C:\\Users\\user\\Desktop\\Projects\\ConsoleCoreApp1\\Service1.cs:line 348\n```\n\nAnd this leads to the final crash of the program :\n\nhttps://i.sstatic.net/uTHoj.png\n\n**What I did to prevent the memory leak** :\n\n- The classes have the IDisposable interfaces enabled\n\n```\npublic void Dispose()\n {\n Dispose(true);\n GC.SuppressFinalize(this);\n }\n\n protected virtual void Dispose(bool disposing)\n {\n if (disposing)\n {\n // free managed resources\n _onTimePerHour.Dispose();\n _api.OnNewData -= OnNewData;\n }\n // free native resources if there are any.\n }\n```\n\n- Forced garbage collection after each message received :\n\n```\nprivate void ParseXMLAnswer(string strOutputXML, string caller) {\n ...\n doc = null;\n GC.Collect();\n GC.WaitForPendingFinalizers();\n}\n```\n\nThis helps a bit more and now the memory problem i have increases after a longer period of time.\n\n- I use the ReShaper (enter link description here) plugin for Visual Studio to give me a better understanding of the Stack Trace of the memory problem but it does not help much.\n\nhttps://i.sstatic.net/YoJGH.png\n\n**What do I think the problem is** :\n\nThe RabbitMQ Producer app gets many messages per second which are then parsed, split into several JSON messages and send to RMQ using the same channel. The following cases might occur :\n\n- I'm publishing on a single RMQ channel and somehow i should use several channels (one connection but multiple channels)\n\n- I'm receiving more messages than I can parse and send through RMQ using the RabbitMQ.Client .net library\n\n- I'm holding up some references in memory for some objects (maybe messages) which do not get freed up;\n\nDid someone had this problem before ? Because I cannot find anywhere any info on this \"**SingleProducerSingleConsumerQueue+Segment out of memory**\" issue.\n\nDoes someone know how to analyse more in depth this problem ?\n\nBig thanks !\n\n### Edit 1\n\nI guess more info is needed to solve this memory issue.\n\nI have several consumers which consume data from RabbitMQ (like NodeJS and python apps). Thus, I need to design the RabbitMQ Producer in a generic way, as each consumer needs different data. And I cannot modify and restart my RabbitMQ Producer each time I have a new consumer app. So I need to publish my messages in a generic way.\n\nFor example, each consumer has its own dedicated queue, with dedicated bindings. Let's say I have consumer1 with queue cons1 and bindings :\n\n- marketName.productName.*.1 (the productName would correspond for days).\n\nThis binding is dynamic and for now it corresponds to Monday (04.April) but tomorrow it will correspond to Tueday (05.April).\n\nSo I need to store in memory the marketNames and productNames by using\n\n```\nprivate static read-only Dictionary> sequenceItemsHashed = new Dictionary>();\nprivate static readonly Dictionary sequencesFromInstruments = new Dictionary();\n```\n\nI mention that sequenceItemsHashed corrrespond to marketNames and sequencesFromInstruments to productNames in my logic.\n\nThis way I send all the messages to RMQ and I do the sorting in RMQ afterwards using bindings.\n\n### Edit 2\n\nFrom what I understood, in order to solve my question I need something like the following architecture (enter link description here) :\n\nhttps://i.sstatic.net/9QSUj.png\n\nSo multiple threads in my single connection to the RMQ server and one channel per thread.\n\n### Edit 3\n\nImplemented successfully the pipelines, the ConcurrentQueue and the Consumer Thread which pushes to RMQ but still have memory issues:\n\n```\nprivate readonly TransformBlock orderFilter;\nprivate readonly TransformBlock xmlParser;\n//private readonly TransformBlock xmlToJsonTransformer;\nprivate readonly TransformManyBlock jsonOrderFactory;\nprivate readonly ActionBlock messageSender;\n\nConcurrentQueue concurrentQueue = new ConcurrentQueue();\n\npublic Service1 (string [] args) {\n ...\n // setup pipeline blocks\n orderFilter = new TransformBlock(FilterIncomingMessages);\n xmlParser = new TransformBlock(ParseXml);\n jsonOrderFactory = new TransformManyBlock(CreateOrderMessages);\n messageSender = new ActionBlock(SendMessage);\n\n // build your pipeline \n orderFilter.LinkTo(xmlParser, x => !string.IsNullOrEmpty(x));\n orderFilter.LinkTo(DataflowBlock.NullTarget()); // for non-order msgs\n\n xmlParser.LinkTo(jsonOrderFactory);\n jsonOrderFactory.LinkTo(messageSender, new DataflowLinkOptions { PropagateCompletion = true });\n\n Task t2 = Task.Factory.StartNew(() =>\n {\n while (true) { \n if (!concurrentQueue.IsEmpty)\n {\n JToken number;\n while (concurrentQueue.TryDequeue(out number))\n {\n _rabbitMQ.PublishMessages(\n Encoding.ASCII.GetBytes(number.ToString()),\n \"test\"\n );\n }\n } else\n {\n Thread.Sleep(1);\n }\n }\n }); \n ...\n}\n\nprivate string FilterIncomingMessages(string strXml){\n if (strXml.Contains(\" CreateOrderMessages(JObject o){\n List myList = new List();\n if (o.ContainsKey(\"GV8APIDATA\")){\n if (o[\"GV8APIDATA\"][\"ORDER\"].Type is JTokenType.Object){\n JToken order = o[\"GV8APIDATA\"][\"ORDER\"];\n myList.Add(order);\n }\n else if (o[\"GV8APIDATA\"][\"ORDER\"].Type is JTokenType.Array){\n JToken orders = o[\"GV8APIDATA\"][\"ORDER\"];\n foreach (var order in orders.Children()){\n myList.Add(order);\n }\n }\n }\n return myList.ToArray ();\n }\n\nprivate void SendMessage(JToken order){\n concurrentQueue.Enqueue(order);\n}\n```\n\nThe new solution helps to break the logic into several small parts but I still have a constant memory increase.\n\nhttps://i.sstatic.net/g7EgQ.png\n\n### Edit 4\n\nTaking into account @Fildor's answer I did the following :\n\nInstead of converting strings containing xml with elements to JSON, I deserialize XML to objects using the pipelines and the code below.\n\nI removed the part with the Thread and the ConcurrentQueue and I'm publishing directly in the last ActionBlock.\n\nThis solves my memory leak problem, but there are other problems like :\n\n- If the messages are big enough I will only be able to print around 120 messages / second. I get the rate of 1780 messages/s if I just print the simple string \"test\".\n\nhttps://i.sstatic.net/WDL5v.png\n\n```\npublic Service1 (string [] args) {\n ... \n // setup pipeline blocks\n orderFilter = new TransformBlock(FilterIncomingMessages);\n xmlParser = new TransformBlock(ParseXml);\n jsonOrderFactory = new TransformManyBlock(CreateOrderMessages);\n messageSender = new ActionBlock(SendMessage);\n\n // build your pipeline \n orderFilter.LinkTo(xmlParser, x => !string.IsNullOrEmpty(x));\n orderFilter.LinkTo(DataflowBlock.NullTarget()); // for non-order msgs\n xmlParser.LinkTo(jsonOrderFactory);\n jsonOrderFactory.LinkTo(messageSender, new DataflowLinkOptions { PropagateCompletion = true });\n\n RunAsConsole(args);\n }\n\n private readonly TransformBlock orderFilter;\n private readonly TransformBlock xmlParser;\n private readonly TransformManyBlock jsonOrderFactory;\n private readonly ActionBlock messageSender;\n\n private void OnNewData(string strXML){\n orderFilter.Post(strXML); \n } \n\n private string FilterIncomingMessages(string strXml){\n if (strXml.Contains(\" CreateOrderMessages(OrdersResponse o){\n return o.orders;\n }\n\n private void SendMessage(Order order) {\n _rabbitMQ.PublishMessages(\n Encoding.ASCII.GetBytes(order.ToString()),\n \"test\"\n );\n }\n```\n\nAnd the ORDER object looking like :\n\n```\n[Serializable()]\n [XmlRoot (ElementName = \"ORDER\")]\n public class Order : IDisposable {\n\n public void Dispose()\n {\n EngineID = null;\n PersistentOrderID = null;\n ...\n InstrumentSpecifier.Dispose();\n InstrumentSpecifier = null;\n GC.SuppressFinalize(this);\n }\n\n [XmlAttribute (AttributeName = \"EngineID\")]\n public string EngineID { get; set; }\n [XmlAttribute (AttributeName = \"PersistentOrderID\")]\n public string PersistentOrderID { get; set; }\n ... \n [XmlElement(ElementName = \"INSTSPECIFIER\")]\n public InstrumentSpecifier InstrumentSpecifier { get; set; }\n }\n```\n\nAnd my new RabbitMQ class :\n\n```\npublic class RMQ : IDisposable {\n private IConnection _connection;\n public IModel Channel { get; private set; } \n private readonly ConnectionFactory _connectionFactory;\n private readonly string _exchangeName;\n\n public RMQ (RabbitOptions _rabbitOptions){\n try{\n // _connectionFactory initialization\n _connectionFactory = new ConnectionFactory()\n {\n HostName = _rabbitOptions.HostName,\n UserName = _rabbitOptions.UserName,\n Password = _rabbitOptions.Password,\n VirtualHost = _rabbitOptions.VHost,\n };\n this._exchangeName = _rabbitOptions.ExchangeName;\n\n if (!String.IsNullOrEmpty(_rabbitOptions.CertPath)){\n _connectionFactory.RequestedConnectionTimeout = TimeSpan.FromMilliseconds(5000);\n _connectionFactory.Ssl.AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateNameMismatch | SslPolicyErrors.RemoteCertificateChainErrors;\n _connectionFactory.Ssl.CertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateServerCertificate);\n _connectionFactory.Ssl.ServerName = _rabbitOptions.HostName;\n _connectionFactory.Ssl.CertPath = _rabbitOptions.CertPath;\n _connectionFactory.Ssl.CertPassphrase = _rabbitOptions.CertPass;\n _connectionFactory.Ssl.Version = SslProtocols.Tls12;\n _connectionFactory.Ssl.Enabled = true;\n }\n\n _connectionFactory.RequestedHeartbeat = TimeSpan.FromSeconds(1);\n _connectionFactory.AutomaticRecoveryEnabled = true; // enable automatic connection recovery\n //_connectionFactory.RequestedChannelMax = 10;\n\n if (_connection == null || _connection.IsOpen == false){\n _connection = _connectionFactory.CreateConnection();\n _connection.ConnectionShutdown += Connection_ConnectionShutdown;\n }\n if (Channel == null || Channel.IsOpen == false){\n Channel = _connection.CreateModel();\n }\n Utils.log.Info(\"ConnectToRabbitMQ () Connecting to RabbitMQ. rabbitMQenvironment = \");\n }\n catch (Exception ex){\n Utils.log.Error(\"Connection to RabbitMQ failed ! HostName = \" + _rabbitOptions.HostName + \" VirtualHost = \" + _rabbitOptions.VHost);\n Utils.printException(\"ConnectToRMQ ()\", ex);\n }\n } \n\n private void Connection_ConnectionShutdown(object sender, ShutdownEventArgs e){\n Utils.log.Info (\"Connection broke!\");\n try{\n if (ReconnectToRMQ()){\n Utils.log.Info(\"Connected!\");\n }\n }\n catch (Exception ex){\n Utils.log.Info(\"Connect failed!\" + ex.Message);\n }\n }\n\n private bool ReconnectToRMQ(){\n if (_connection == null || _connection.IsOpen == false){\n _connection = _connectionFactory.CreateConnection();\n _connection.ConnectionShutdown += Connection_ConnectionShutdown; \n }\n\n if (Channel == null || Channel.IsOpen == false){\n Channel = _connection.CreateModel();\n return true;\n }\n return false;\n }\n\n private bool ValidateServerCertificate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) {\n return true;\n }\n\n public void DisconnectFromRMQ () {\n Channel.Close ();\n _connection.Close ();\n } \n\n public void Dispose(){\n try{\n Channel?.Close();\n Channel?.Dispose();\n Channel = null;\n\n _connection?.Close();\n _connection?.Dispose();\n _connection = null;\n }\n catch (Exception e){\n Utils.log.Error(\"Cannot dispose RabbitMQ channel or connection\" + e.Message);\n }\n }\n\n public void PublishMessages (byte [] message, string routingKey) { \n if (this._connection == null || ! _connection.IsOpen) {\n Utils.log.Error (\"PublishMessages(), Connect failed! this.conn == null || !conn.IsOpen \");\n ReconnectToRMQ();\n } else { \n var properties = Channel.CreateBasicProperties();\n properties.Persistent = true;\n\n Channel.BasicPublish (_exchangeName, routingKey, properties, message);\n //serviceInstance1.Publish(message, _rabbitOptions.ExchangeName, \"\", routingKey);\n }\n }\n}\n```\n\nNow the funny thing is if I publish only a small string like \"test\" to RabbitMQ to my predefined queue I can publish more than 1780 messages/second.\n\n========================================\n\nCode:\n```text\n<Project Sdk=\"Microsoft.NET.Sdk\"> \n <PropertyGroup>\n <OutputType>Exe</OutputType>\n <TargetFramework>net5.0</TargetFramework>\n <RuntimeIdentifier>win-x64</RuntimeIdentifier>\n </PropertyGroup>\n ...\n</Project>\n```\n\n```text\nprivate void SetUpApi () {\n Utils.log.Info (_api.SetAPIOptions (\"<CONNECTIONOPTIONS><CALCULATED_PRICES Enabled='true' MaximumDepth='4'/></CONNECTIONOPTIONS>\"));\n _api.OnServerConnect += OnServerConnect;\n _api.OnServerDisconnect += OnServerDisconnect;\n _api.OnNewData += OnNewData; \n }\n```\n\n```text\nprivate void OnNewData(string strXML){\n try{\n if (strXML.Contains(\"<ORDER\")){\n ParseXMLAnswer(strXML, \"OnNewData ()\");\n }\n }\n catch (Exception ex) {\n if (ex.InnerException is AlreadyClosedException || ex.InnerException is BrokerUnreachableException)\n Utils.log.Error(\"OnNewData () RabbitMQ.Client.Exceptions.AlreadyClosedException \");\n else\n Utils.printException(\"OnNewData ()\", ex);\n }\n }\n \n private void ParseXMLAnswer(string strOutputXML, string caller) {\n XmlDocument doc = new XmlDocument();\n doc.LoadXml(strOutputXML);\n string jsonText = JsonConvert.SerializeXmlNode(doc);\n var o = JObject.Parse(jsonText);\n\n if (o[\"APIDATA\"][\"ORDER\"].Type is JTokenType.Object){\n JObject order = (JObject)o[\"APIDATA\"][\"ORDER\"];\n\n SendOrderToRMQ(order);\n }\n else if (o[\"APIDATA\"][\"ORDER\"].Type is JTokenType.Array){\n JArray orders = (JArray)o[\"APIDATA\"][\"ORDER\"];\n foreach (var item in orders.Children()){\n SendOrderToRMQ((JObject)item);\n }\n }\n doc = null;\n GC.Collect();\n GC.WaitForPendingFinalizers();\n }\n\n private void SendOrderToRMQ (JObject order){\n JObject instrSpeciefier = (JObject) order[\"INSTSPECIFIER\"];\n\n var firstSeqID = instrSpeciefier.GetValue(\"@FirstSequenceID\").ToString();\n var firstSeqItemID = instrSpeciefier.GetValue(\"@FirstSequenceItemID\").ToString();\n \n if (sequenceItemsHashed.ContainsKey(firstSeqID) &&\n sequenceItemsHashed[firstSeqID].Contains(firstSeqItemID)){\n string itemName = Utils.ReplaceSensitiveCharacthers(instrSpeciefier.GetValue(\"@FirstSequenceItemName\").ToString());\n string instrumentName = Utils.ReplaceSensitiveCharacthers(instrSpeciefier.GetValue(\"@InstName\").ToString());\n\n int index = sequenceItemsHashed[firstSeqID].IndexOf(firstSeqItemID) + 1;\n var binding = instrumentName + \".\" + sequencesFromInstruments[firstSeqID] + \".\" + itemName + \".\" + index;\n\n serviceInstance1.Publish(\n order.ToString(),\n _exchangeName,\n \"\",\n binding);\n }\n order = null;\n instrSpeciefier = null; \n }\n```\n\n```text\n<?xml version=\"1.0\" encoding=\"utf-16\"?>\n <APIDATA xmlns=\"api-com\">\n <ORDER EngineID=\"0\" PersistentOrderID=\"2791\" ...>\n <INSTSPECIFIER InstID=\"287\" ... />\n ...\n </ORDER>\n <ORDER EngineID=\"0\" PersistentOrderID=\"9840\" ...>\n <INSTSPECIFIER InstID=\"288\" ... />\n ...\n </ORDER>\n```\n\n```text\n<?xml version=\"1.0\" encoding=\"utf-16\"?>\n <APIDATA xmlns=\"api-com\">\n <ORDER ... PersistentOrderID=\"2791\" OrderID=\"1234\" ... Action=\"Insert\" ...>\n ...\n </ORDER>\n```\n\n```text\n<?xml version=\"1.0\" encoding=\"utf-16\"?>\n <APIDATA xmlns=\"api-com\">\n <ORDER ... PersistentOrderID=\"2791\" OrderID=\"1234\" ... Action=\"Remove\" ...>\n ...\n </ORDER>\n```\n\n```text\nclass RabbitManager : IRabbitManager\n{\n private readonly DefaultObjectPool<IModel> _objectPool;\n public RabbitManager(IPooledObjectPolicy<IModel> objectPolicy){\n _objectPool = new DefaultObjectPool<IModel>(objectPolicy, Environment.ProcessorCount * 2);\n }\n\n public void Publish<T>(T message, string exchangeName, string exchangeType, string routeKey) where T : class {\n if (message == null)\n return;\n\n var channel = _objectPool.Get();\n try{\n var sendBytes = Encoding.UTF8.GetBytes(message.ToString());\n var properties = channel.CreateBasicProperties();\n properties.ContentType = \"application/json\";\n properties.DeliveryMode = 1; // Doesn't persist to disk\n properties.Timestamp = new AmqpTimestamp(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds());\n\n channel.BasicPublish(exchangeName, routeKey, properties, sendBytes);\n }\n catch (Exception ex) {\n throw ex;\n }\n finally {\n _objectPool.Return(channel);\n }\n }\n}\n```\n\n```text\npublic class RabbitModelPooledObjectPolicy : IPooledObjectPolicy<IModel>\n{\n private readonly RabbitOptions _options;\n private readonly IConnection _connection;\n\n public RabbitModelPooledObjectPolicy(RabbitOptions _options){\n this._options = _options;\n _connection = GetConnection();\n }\n\n private IConnection GetConnection() {\n var factory = new ConnectionFactory() {\n HostName = _options.HostName,\n UserName = _options.UserName,\n Password = _options.Password,\n //Port = _options.Port,\n VirtualHost = _options.VHost,\n };\n\n if (!String.IsNullOrEmpty(_options.CertPath))\n {\n factory.RequestedConnectionTimeout = TimeSpan.FromMilliseconds(5000);\n factory.Ssl.AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateNameMismatch | SslPolicyErrors.RemoteCertificateChainErrors;\n factory.Ssl.CertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateServerCertificate);\n factory.Ssl.ServerName = _options.HostName;\n factory.Ssl.CertPath = _options.CertPath;\n factory.Ssl.CertPassphrase = _options.CertPass;\n factory.Ssl.Version = SslProtocols.Tls12;\n factory.Ssl.Enabled = true;\n }\n\n factory.RequestedHeartbeat = TimeSpan.FromSeconds(1);\n factory.AutomaticRecoveryEnabled = true; // enable automatic connection recovery\n factory.RequestedChannelMax = 32;\n\n var _connection = factory.CreateConnection();\n _connection.ConnectionShutdown += Connection_ConnectionShutdown;\n\n return _connection;\n }\n\n private void Connection_ConnectionShutdown(object sender, ShutdownEventArgs e){\n Utils.log.Info(\"Connection broke!\");\n }\n\n private bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors){\n return true;\n }\n\n public IModel Create(){\n return _connection.CreateModel();\n }\n\n public bool Return(IModel obj) {\n if (obj.IsOpen) {\n return true;\n }\n else {\n obj?.Dispose();\n return false;\n }\n }\n}\n```\n\n```text\n26-04-2021 10:41:48 - OnNewData () RabbitMQ.Client.Exceptions.AlreadyClosedException: Already closed: The AMQP operation was interrupted: AMQP close-reason, initiated by Library, code=0, text='End of stream', classId=0, methodId=0, cause=System.IO.EndOfStreamException: Reached the end of the stream. Possible authentication failure.\n at RabbitMQ.Client.Impl.InboundFrame.ReadFrom(Stream reader, Byte[] frameHeaderBuffer)\n at RabbitMQ.Client.Framing.Impl.Connection.MainLoopIteration()\n at RabbitMQ.Client.Framing.Impl.Connection.MainLoop()\n at RabbitMQ.Client.Framing.Impl.Connection.EnsureIsOpen()\n at RabbitMQ.Client.Framing.Impl.AutorecoveringConnection.CreateModel()\n at RabbitModelPooledObjectPolicy.Create() in C:\\Users\\user\\Desktop\\Projects\\ConsoleCoreApp1\\RabbitMQ\\RabbitModelPooledObjectPolicy.cs:line 77\n at Microsoft.Extensions.ObjectPool.DefaultObjectPool`1.Create()\n at Microsoft.Extensions.ObjectPool.DefaultObjectPool`1.Get()\n at RabbitManager.Publish[T](T message, String exchangeName, String exchangeType, String routeKey) in C:\\Users\\user\\Desktop\\Projects\\ConsoleCoreApp1\\RabbitMQ\\RabbitManager.cs:line 32\n at ConsoleApp1.Service1.SendOrderToRMQ(JObject order) in C:\\Users\\user\\Desktop\\Projects\\ConsoleCoreApp1\\Service1.cs:line 411\n at ConsoleApp1.Service1.ParseXMLAnswer(String strOutputXML, String caller) in C:\\Users\\user\\Desktop\\Projects\\ConsoleCoreApp1\\Service1.cs:line 372\n at ConsoleApp1.Service1.OnNewData(String strXML) in C:\\Users\\user\\Desktop\\Projects\\ConsoleCoreApp1\\Service1.cs:line 348\n26-04-2021 10:41:48 - OnNewData () RabbitMQ.Client.Exceptions.AlreadyClosedException: Already closed: The AMQP operation was interrupted: AMQP close-reason, initiated by Library, code=0, text='End of stream', classId=0, methodId=0, cause=System.IO.EndOfStreamException: Reached the end of the stream. Possible authentication failure.\n at RabbitMQ.Client.Impl.InboundFrame.ReadFrom(Stream reader, Byte[] frameHeaderBuffer)\n at RabbitMQ.Client.Framing.Impl.Connection.MainLoopIteration()\n at RabbitMQ.Client.Framing.Impl.Connection.MainLoop()\n at RabbitMQ.Client.Framing.Impl.Connection.EnsureIsOpen()\n at RabbitMQ.Client.Framing.Impl.AutorecoveringConnection.CreateModel()\n at RabbitModelPooledObjectPolicy.Create() in C:\\Users\\user\\Desktop\\Projects\\ConsoleCoreApp1\\RabbitMQ\\RabbitModelPooledObjectPolicy.cs:line 77\n at Microsoft.Extensions.ObjectPool.DefaultObjectPool`1.Create()\n at Microsoft.Extensions.ObjectPool.DefaultObjectPool`1.Get()\n at RabbitManager.Publish[T](T message, String exchangeName, String exchangeType, String routeKey) in C:\\Users\\user\\Desktop\\Projects\\ConsoleCoreApp1\\RabbitMQ\\RabbitManager.cs:line 32\n at ConsoleApp1.Service1.SendOrderToRMQ(JObject order) in C:\\Users\\user\\Desktop\\Projects\\ConsoleCoreApp1\\Service1.cs:line 411\n at ConsoleApp1.Service1.ParseXMLAnswer(String strOutputXML, String caller) in C:\\Users\\user\\Desktop\\Projects\\ConsoleCoreApp1\\Service1.cs:line 372\n at ConsoleApp1.Service1.OnNewData(String strXML) in C:\\Users\\user\\Desktop\\Projects\\ConsoleCoreApp1\\Service1.cs:line 348\n```\n\n```text\npublic void Dispose()\n {\n Dispose(true);\n GC.SuppressFinalize(this);\n }\n\n protected virtual void Dispose(bool disposing)\n {\n if (disposing)\n {\n // free managed resources\n _onTimePerHour.Dispose();\n _api.OnNewData -= OnNewData;\n }\n // free native resources if there are any.\n }\n```\n\n```text\nprivate void ParseXMLAnswer(string strOutputXML, string caller) {\n ...\n doc = null;\n GC.Collect();\n GC.WaitForPendingFinalizers();\n}\n```\n\n```text\nprivate static read-only Dictionary<string, List<string>> sequenceItemsHashed = new Dictionary<string, List<string>>();\nprivate static readonly Dictionary<string, string> sequencesFromInstruments = new Dictionary<string, string>();\n```\n\n```text\nprivate readonly TransformBlock<string, string> orderFilter;\nprivate readonly TransformBlock<string, JObject> xmlParser;\n//private readonly TransformBlock<XmlDocument, JObject> xmlToJsonTransformer;\nprivate readonly TransformManyBlock<JObject, JToken> jsonOrderFactory;\nprivate readonly ActionBlock<JToken> messageSender;\n\nConcurrentQueue<JToken> concurrentQueue = new ConcurrentQueue<JToken>();\n\npublic Service1 (string [] args) {\n ...\n // setup pipeline blocks\n orderFilter = new TransformBlock<string, string>(FilterIncomingMessages);\n xmlParser = new TransformBlock<string, JObject>(ParseXml);\n jsonOrderFactory = new TransformManyBlock<JObject, JToken>(CreateOrderMessages);\n messageSender = new ActionBlock<JToken>(SendMessage);\n\n // build your pipeline \n orderFilter.LinkTo(xmlParser, x => !string.IsNullOrEmpty(x));\n orderFilter.LinkTo(DataflowBlock.NullTarget<string>()); // for non-order msgs\n\n xmlParser.LinkTo(jsonOrderFactory);\n jsonOrderFactory.LinkTo(messageSender, new DataflowLinkOptions { PropagateCompletion = true });\n\n Task t2 = Task.Factory.StartNew(() =>\n {\n while (true) { \n if (!concurrentQueue.IsEmpty)\n {\n JToken number;\n while (concurrentQueue.TryDequeue(out number))\n {\n _rabbitMQ.PublishMessages(\n Encoding.ASCII.GetBytes(number.ToString()),\n \"test\"\n );\n }\n } else\n {\n Thread.Sleep(1);\n }\n }\n }); \n ...\n}\n\nprivate string FilterIncomingMessages(string strXml){\n if (strXml.Contains(\"<ORDER\")) return strXml;\n return null;\n}\n\nprivate JObject ParseXml(string strXml){\n XmlDocument doc = new XmlDocument();\n doc.LoadXml(strXml);\n string jsonText = JsonConvert.SerializeXmlNode(doc);\n var o = JObject.Parse(jsonText);\n return o;\n}\n\nprivate IEnumerable<JToken> CreateOrderMessages(JObject o){\n List<JToken> myList = new List<JToken>();\n if (o.ContainsKey(\"GV8APIDATA\")){\n if (o[\"GV8APIDATA\"][\"ORDER\"].Type is JTokenType.Object){\n JToken order = o[\"GV8APIDATA\"][\"ORDER\"];\n myList.Add(order);\n }\n else if (o[\"GV8APIDATA\"][\"ORDER\"].Type is JTokenType.Array){\n JToken orders = o[\"GV8APIDATA\"][\"ORDER\"];\n foreach (var order in orders.Children()){\n myList.Add(order);\n }\n }\n }\n return myList.ToArray ();\n }\n\nprivate void SendMessage(JToken order){\n concurrentQueue.Enqueue(order);\n}\n```\n\n```text\npublic Service1 (string [] args) {\n ... \n // setup pipeline blocks\n orderFilter = new TransformBlock<string, string>(FilterIncomingMessages);\n xmlParser = new TransformBlock<string, OrdersResponse>(ParseXml);\n jsonOrderFactory = new TransformManyBlock<OrdersResponse, Order>(CreateOrderMessages);\n messageSender = new ActionBlock<Order>(SendMessage);\n\n // build your pipeline \n orderFilter.LinkTo(xmlParser, x => !string.IsNullOrEmpty(x));\n orderFilter.LinkTo(DataflowBlock.NullTarget<string>()); // for non-order msgs\n xmlParser.LinkTo(jsonOrderFactory);\n jsonOrderFactory.LinkTo(messageSender, new DataflowLinkOptions { PropagateCompletion = true });\n\n RunAsConsole(args);\n }\n\n private readonly TransformBlock<string, string> orderFilter;\n private readonly TransformBlock<string, OrdersResponse> xmlParser;\n private readonly TransformManyBlock<OrdersResponse, Order> jsonOrderFactory;\n private readonly ActionBlock<Order> messageSender;\n\n private void OnNewData(string strXML){\n orderFilter.Post(strXML); \n } \n\n private string FilterIncomingMessages(string strXml){\n if (strXml.Contains(\"<ORDER\")) return strXml;\n return null;\n }\n\n private OrdersResponse ParseXml(string strXml) {\n var rootDataObj = DeserializeOrdersFromXML(strXml);\n return rootDataObj;\n }\n\n private OrdersResponse DeserializeOrdersFromXML(string strOutputXML){\n var xsExpirations = new XmlSerializer(typeof(OrdersResponse));\n OrdersResponse rootDataObj = null;\n using (TextReader reader = new StringReader(strOutputXML)) {\n rootDataObj = (OrdersResponse)xsExpirations.Deserialize(reader);\n reader.Close();\n }\n return rootDataObj;\n }\n\n private IEnumerable<Order> CreateOrderMessages(OrdersResponse o){\n return o.orders;\n }\n\n private void SendMessage(Order order) {\n _rabbitMQ.PublishMessages(\n Encoding.ASCII.GetBytes(order.ToString()),\n \"test\"\n );\n }\n```\n\n```text\n[Serializable()]\n [XmlRoot (ElementName = \"ORDER\")]\n public class Order : IDisposable {\n\n public void Dispose()\n {\n EngineID = null;\n PersistentOrderID = null;\n ...\n InstrumentSpecifier.Dispose();\n InstrumentSpecifier = null;\n GC.SuppressFinalize(this);\n }\n\n [XmlAttribute (AttributeName = \"EngineID\")]\n public string EngineID { get; set; }\n [XmlAttribute (AttributeName = \"PersistentOrderID\")]\n public string PersistentOrderID { get; set; }\n ... \n [XmlElement(ElementName = \"INSTSPECIFIER\")]\n public InstrumentSpecifier InstrumentSpecifier { get; set; }\n }\n```\n\n```text\npublic class RMQ : IDisposable {\n private IConnection _connection;\n public IModel Channel { get; private set; } \n private readonly ConnectionFactory _connectionFactory;\n private readonly string _exchangeName;\n\n public RMQ (RabbitOptions _rabbitOptions){\n try{\n // _connectionFactory initialization\n _connectionFactory = new ConnectionFactory()\n {\n HostName = _rabbitOptions.HostName,\n UserName = _rabbitOptions.UserName,\n Password = _rabbitOptions.Password,\n VirtualHost = _rabbitOptions.VHost,\n };\n this._exchangeName = _rabbitOptions.ExchangeName;\n\n if (!String.IsNullOrEmpty(_rabbitOptions.CertPath)){\n _connectionFactory.RequestedConnectionTimeout = TimeSpan.FromMilliseconds(5000);\n _connectionFactory.Ssl.AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateNameMismatch | SslPolicyErrors.RemoteCertificateChainErrors;\n _connectionFactory.Ssl.CertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateServerCertificate);\n _connectionFactory.Ssl.ServerName = _rabbitOptions.HostName;\n _connectionFactory.Ssl.CertPath = _rabbitOptions.CertPath;\n _connectionFactory.Ssl.CertPassphrase = _rabbitOptions.CertPass;\n _connectionFactory.Ssl.Version = SslProtocols.Tls12;\n _connectionFactory.Ssl.Enabled = true;\n }\n\n _connectionFactory.RequestedHeartbeat = TimeSpan.FromSeconds(1);\n _connectionFactory.AutomaticRecoveryEnabled = true; // enable automatic connection recovery\n //_connectionFactory.RequestedChannelMax = 10;\n\n if (_connection == null || _connection.IsOpen == false){\n _connection = _connectionFactory.CreateConnection();\n _connection.ConnectionShutdown += Connection_ConnectionShutdown;\n }\n if (Channel == null || Channel.IsOpen == false){\n Channel = _connection.CreateModel();\n }\n Utils.log.Info(\"ConnectToRabbitMQ () Connecting to RabbitMQ. rabbitMQenvironment = \");\n }\n catch (Exception ex){\n Utils.log.Error(\"Connection to RabbitMQ failed ! HostName = \" + _rabbitOptions.HostName + \" VirtualHost = \" + _rabbitOptions.VHost);\n Utils.printException(\"ConnectToRMQ ()\", ex);\n }\n } \n\n private void Connection_ConnectionShutdown(object sender, ShutdownEventArgs e){\n Utils.log.Info (\"Connection broke!\");\n try{\n if (ReconnectToRMQ()){\n Utils.log.Info(\"Connected!\");\n }\n }\n catch (Exception ex){\n Utils.log.Info(\"Connect failed!\" + ex.Message);\n }\n }\n\n private bool ReconnectToRMQ(){\n if (_connection == null || _connection.IsOpen == false){\n _connection = _connectionFactory.CreateConnection();\n _connection.ConnectionShutdown += Connection_ConnectionShutdown; \n }\n\n if (Channel == null || Channel.IsOpen == false){\n Channel = _connection.CreateModel();\n return true;\n }\n return false;\n }\n\n private bool ValidateServerCertificate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) {\n return true;\n }\n\n public void DisconnectFromRMQ () {\n Channel.Close ();\n _connection.Close ();\n } \n\n public void Dispose(){\n try{\n Channel?.Close();\n Channel?.Dispose();\n Channel = null;\n\n _connection?.Close();\n _connection?.Dispose();\n _connection = null;\n }\n catch (Exception e){\n Utils.log.Error(\"Cannot dispose RabbitMQ channel or connection\" + e.Message);\n }\n }\n\n public void PublishMessages (byte [] message, string routingKey) { \n if (this._connection == null || ! _connection.IsOpen) {\n Utils.log.Error (\"PublishMessages(), Connect failed! this.conn == null || !conn.IsOpen \");\n ReconnectToRMQ();\n } else { \n var properties = Channel.CreateBasicProperties();\n properties.Persistent = true;\n\n Channel.BasicPublish (_exchangeName, routingKey, properties, message);\n //serviceInstance1.Publish(message, _rabbitOptions.ExchangeName, \"\", routingKey);\n }\n }\n}\n```\n\n```text\nTask t2 = Task.Factory.StartNew(() =>\n {\n while (true) { \n if (!concurrentQueue.IsEmpty)\n {\n JToken number;\n while (concurrentQueue.TryDequeue(out number))\n {\n _rabbitMQ.PublishMessages(\n Encoding.ASCII.GetBytes(number.ToString()),\n \"test\"\n );\n }\n } else\n {\n Thread.Sleep(1);\n }\n }\n });\n```\n\n```text\nusing Microsoft.Extensions.Logging;\nusing System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Threading.Tasks;\nusing System.Threading.Tasks.Dataflow;\nusing System.Xml.Linq;\nusing System.Xml.Serialization;\nusing Newtonsoft.Json;\nusing System.Linq;\n\nnamespace DataFlowExperiment.PipelinesLib\n{\n\n public class PipelineOne\n {\n private readonly IPipelineOneSteps steps;\n\n private readonly TransformBlock<string, XDocument> startBlock; // XML deserialize to Model\n private readonly TransformManyBlock<XDocument, string> toJsonMessagesBlock; // jsons generieren.\n private readonly ITargetBlock<string> resultCallback;\n\n public PipelineOne(IPipelineOneSteps steps, ITargetBlock<string> resultCallback = null)\n {\n this.steps = steps;\n\n startBlock = new TransformBlock<string, XDocument>(steps.Start);\n toJsonMessagesBlock = new TransformManyBlock<XDocument, string>(steps.ToJson);\n\n this.resultCallback = resultCallback ?? DataflowBlock.NullTarget<string>();\n\n startBlock.LinkTo(toJsonMessagesBlock, new DataflowLinkOptions { PropagateCompletion = true });\n toJsonMessagesBlock.LinkTo(this.resultCallback, new DataflowLinkOptions { PropagateCompletion = true }, x => !string.IsNullOrEmpty(x));\n toJsonMessagesBlock.LinkTo(DataflowBlock.NullTarget<string>(), new DataflowLinkOptions { PropagateCompletion = true });\n }\n\n public void Post(string input)\n {\n startBlock.Post(input);\n }\n\n public Task Close()\n {\n startBlock.Complete();\n return resultCallback.Completion;\n }\n }\n\n public interface IPipelineOneSteps\n {\n public XDocument Start(string input);\n public IEnumerable<string> ToJson(XDocument doc);\n }\n\n public class PipelineOneSteps : IPipelineOneSteps\n {\n private readonly JsonSerializer jsonSerializer;\n\n public PipelineOneSteps()\n {\n jsonSerializer = JsonSerializer.CreateDefault();\n }\n\n public XDocument Start(string input)\n {\n XDocument doc = XDocument.Parse(input);\n return doc;\n }\n\n public IEnumerable<string> ToJson(XDocument doc)\n {\n XNamespace ns = \"api-com\";\n var orders = doc.Root.Elements(ns + \"ORDER\");\n\n foreach (var order in orders)\n {\n yield return JsonConvert.SerializeXNode(order);\n }\n }\n }\n}\n```\n\n```text\nBenchmarkDotNet=v0.12.1, OS=Windows 10.0.19041.867 (2004/?/20H1)\nIntel Core i9-10885H CPU 2.40GHz, 1 CPU, 16 logical and 8 physical cores\n.NET Core SDK=5.0.202\n [Host] : .NET Core 3.1.14 (CoreCLR 4.700.21.16201, CoreFX 4.700.21.16208), X64 RyuJIT\n DefaultJob : .NET Core 3.1.14 (CoreCLR 4.700.21.16201, CoreFX 4.700.21.16208), X64 RyuJIT\n```\n\n```text\nusing System;\nusing System.Collections.Concurrent;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\nusing System.Threading.Tasks.Dataflow;\n\nnamespace DataFlowExperiment.PipelinesLib\n{\n public class RabbitWrapper : IDisposable\n {\n private readonly int batchSize = 10;\n\n private Thread senderThread;\n private readonly BlockingCollection<string> messages;\n private readonly ActionBlock<string> receiver;\n private readonly CancellationTokenSource stoppingToken;\n private readonly RabbitWrapperStats stats;\n\n private ITargetBlock<string> Receiver => receiver;\n\n public RabbitWrapper()\n {\n // Drop in your logging here\n stats = new RabbitWrapperStats(new Progress<string>(x => Console.WriteLine(x)));\n stoppingToken = new CancellationTokenSource();\n messages = new BlockingCollection<string>();\n receiver = new ActionBlock<string>(Receive);\n senderThread = new Thread(HandleQueue);\n senderThread.Start();\n }\n\n private void Receive(string message)\n {\n messages.Add(message);\n }\n\n private void HandleQueue()\n {\n while (!stoppingToken.Token.IsCancellationRequested)\n {\n int batchIndex = 0;\n do {\n string message = messages.Take(stoppingToken.Token);\n if (!string.IsNullOrEmpty(message))\n {\n SendToRabbit(message);\n }\n batchIndex++;\n } while (!stoppingToken.Token.IsCancellationRequested &&\n batchIndex < batchSize &&\n messages.Count > 0);\n // Check statistics every 10 messages.\n CheckStats(messages.Count);\n }\n }\n\n private void SendToRabbit(string message)\n {\n // rabbit Publish goes here.\n }\n\n private void CheckStats(int count)\n {\n stats.CheckStats(count);\n }\n\n public void Close()\n {\n this.stoppingToken.Cancel();\n senderThread.Join();\n }\n\n public void Dispose()\n {\n Close();\n }\n }\n\n internal class RabbitWrapperStats\n {\n // You may want to play around with these thresholds\n // I pulled them out of thin air ...\n const int SIZE_WARN = 500000;\n const int SIZE_CRITICAL = SIZE_WARN * 2;\n\n private int lastTenIndex = 0;\n private int[] lastTen = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };\n private int meanSizeLastTen = 0;\n private int lastMeanSize = 0;\n private int tendency = 0;\n\n private bool HasWarned = false;\n private bool HasPanicked = false;\n\n private readonly IProgress<string> progress;\n\n public RabbitWrapperStats(IProgress<string> progress)\n {\n this.progress = progress;\n }\n\n public void CheckStats(int queueSize)\n {\n UpdateLastTen(queueSize);\n\n if (!HasPanicked && queueSize > SIZE_CRITICAL)\n {\n Panic(queueSize);\n return;\n }\n\n if (!HasWarned && queueSize > SIZE_WARN)\n {\n Warn(queueSize);\n return;\n }\n\n if ((HasPanicked || HasWarned ) && meanSizeLastTen < SIZE_WARN * 0.75)\n {\n HasPanicked = false;\n HasWarned = false;\n progress?.Report($\"INFO Mean size of last 10 Samples sinks below {SIZE_WARN * 0.75} : {meanSizeLastTen}\");\n }\n }\n\n private void Warn(int size)\n {\n HasWarned = true;\n progress?.Report($\"WARNING QueueSize = {size}\");\n }\n\n private void Panic(int size)\n {\n HasPanicked = true;\n progress?.Report($\"!! CRITICAL !! QueueSize = {size}\");\n }\n\n private void UpdateLastTen(int value)\n {\n lastTen[lastTenIndex] = value;\n lastTenIndex = ++lastTenIndex % lastTen.Length;\n meanSizeLastTen = lastTen.Sum() / lastTen.Length;\n tendency = meanSizeLastTen.CompareTo(lastMeanSize);\n lastMeanSize = meanSizeLastTen;\n }\n }\n}\n```\n\n```text\nserviceInstance1\n```\n\n```text\nPublish\n```\n\n```text\nProcessor\n```\n\n```text\nserviceInstance1\n```\n\n```text\nserviceInstance1.Publish\n```\n\n========================================\n\nComments:\n- *\"Freeing myself manually the memory by using :\"* - that's not actually what you are doing. You are *suggesting* to the runtime to perform GC. If you find yourself in the place of thinking you need this, then you have a different problem. And here, it's seemingly allocations and / or references that are held for too long. So, what I'd do is rig up a benchmark with enough data to get realistic measurements. Then tweak all the identified bottlenecks (*one by one*) and compare benchmarks. Keep improvements, ditch changes that didn't improve anything.\n- And you seem to do all the stuff on the eventhandling thread. Maybe have a look into DataFlow to have your process a little more pipelined?\n- thanks for your answer @Fildor ! If I don't use the part of \"freeing the memory\" by using GC.Collect () then the GC will not be able to free up the memory and I will have that peak memory increase until it app crashes. I tried doing smth like \"var task = Task.Run(() => ParseXMLAnswer(strXML, \"OnNewData ()\")).ContinueWith(t => Utils.log.Info(\"Task done.\"));\" to parse answers on different threads but this kill the program after a 30 seconds. Also, RMQ does not like sharing channel between multiple threads - stackoverflow.com/questions/5681118/…\n- i do understand that allocations / references are help in memory for too long but how do I see which one in particular ? because from the stack trace it looks like it is something inside the RabbitMQ.Client library ...\n- I must admit I don't know enough about your project to deeply analyse that. Simply wrapping a Task around (thus pushing the whole ordeal to the Threadpool) is also not going to help, if you don't really know, what you are doing (no offense). Calling GC.Collect just buys you some time but won't solve your problem. Now ...\n- ... what I see here are some clearly distinguishable \"Steps\": 1. Receive Msg, 2. Filter Msg, 3. Transcode XML to JSON, 4. Send Msg. Now, from experience I know: Keep code that runs on an event handler short. So, first thing, I'd do is to have the eventhandler write the data to a queue (that keeps order). Done. Nothing more. Then have a (or more, perhaps) different Threads work that queue (always keeping order). Then, maybe split the following Steps into more queues. That way, you can \"fan out\" in between. For example: messages that contain more than 1 order, could be processed in parallel.\n- Is `SetUpApi` called once at most? If not, how many times is it called? If you're so memory constrained I'm also wondering why you're juggling so many strings. You go from a string to an (old) XmlDocument only to serialize it to a Json string so you can make a JObject from it. I expect you can reduce string size by just going to an XDocument once, find the order XElement node and only then call JsonConvert.SerializeXNode on that single order node. Beyond that you might still need to offload your work from the event thread as indicated by Fidor.\n- @Fildor, the solution you gave might work but I see a small problem - i still have to somehow publish to RMQ using different threads and so different channels and this is a problem from what I read or at least I don't see anywhere a working solution. Also the data volume is 2.8 MB/second of data when I publish it to RMQ\n- It's not a solution, actually. It would be a \"start\" towards a solution ;D Your problem has many layers and aspects to it. You shouldn't expect to solve it all with \"one\" strike. For the Threading: *maybe* it will be necessary to use mor than one connection but I am not RMQ savvy, so I cannot help with *that*. You also may want to check if that amount of data can actually be handled by your networking setup (it's a cloud env, right?). If your outbound is limited below what you need, of course it will always heap up ...\n- @rene - thanks for your answer ! you're right, there is a reason behind my current logic - I have multiple consumers (applications written in nodejs, python, etc) which consume data from RMQ. And these bindings are dynamic. For example, I have a dedicated queue with more than 150 bindings like - \"marketName.productName.*.1\" this 1 represents an index which is valid today for orders which have the timestamp of tomorrow. But tomorrow this index (i.e. 1) will correspond to the next day and so on, so i need to calculate it dynamically in my app. I will write an edit on my post to explain more.\n- @rene - no, i only call once the setUpApi () method. Then each time there is an event coming from the company which gave me the api the method ParseAnswer () is called\n- *\"Then each time there is an event coming from the company which gave me the api the method ParseAnswer () is called\"* Exactly. On the same thread one by one. See, where this goes?\n- Makes sense what you are saying, now in practice how will this work ? Let's say each time I have a message I will try to write to RMQ in a different thread, right ? But this won't work with a single channel, so I need to have a dedicated channel for each thread. And what happens if I get 100 messages / second ? I am allowed to create a max of 32 channels per connection. Then I need to handle those channels, to close them or return them to a pool of channels which can be an expensive operation in terms of memory. I will create an edit with launching different threads for each incoming message.\n- No, don't launch 1 thread / message. Just decouple event handling from processing.\n- I guess it makes sense what your saying @Fildor. Now, how to do it exactly and check if it works or not ... I have no clue. But will continue, as it is quite important to get this done as soon as possible. I will write here a new edit if I have some more news. thanks guys !\n- @rene Have you tried taking out 1 type of operation at a time to isolate the leak to one of the stages of your pipeline? Also, a pipeline architecture as mentioned above may help (e.g. using an internal concurrent queue with dedicated consumer thread for the transcode step), another queue for send, etc. Finally, are you sure it's a memory leak or could it be memory *pressure*. These are very different. What happens when the app reverts to a steady state (no messages for a while?)... memory freed or does it stick around?\n- @rene Looks like you made an effort to unregister event handlers... good. Did you get all of them? They're notorious for memory leaks!\n- @Kit I'm not the OP ;)\n- Oh my bad!!! @R13mus see above.\n- No @Kit I didn't try with an internal queue as I was afraid that it will cause even more memory issues as I get a lot of data in my producer from the API and I was supposing that a consumer thread would have problems with the RMQ Channels. But I have to try it out ... and post my findings afterwards here. Many thanks !\n- @R13mus This is an implementation of what I was talking about. With each block (stage, or whatever you want to call it) doing only what it needs to as fast as it can, increases the parallelism. It's counterintuitive, but this can often decrease the memory pressure because the resources aren't shared and can be reclaimed apace. It's also easier to reason about each block separately, so it may lead to an aha moment if you're actually leaking memory somewhere.\n- @Fildor - thanks ! I'm currently trying to implement your solution. So, to summarize a bit i have part one of the process - transforming and publishing orders into a BlockingCollection using the above pipelines and part two is to consume from that Collection using a dedicated thread which will then send data to RabbitMQ, right ?\n- That is what I would try, yes. It just may not be enough to solve all of the problems. But it will enable you to tweak each step, so you can further improve memory usage.\n- The last part of the pipeline does not work (i.e. TransformManyBlock -> ActionBlock). The last method (SendMessage()) does not print anything. Any clues how to fix this? I edited my post with the latest version of the code.\n- I'll add some more thoughts to the answer, but will have not much time today, so please bear with me.\n- *\"The last part of the pipeline does not work\"* - I think it's a type mismatch. If your second last block output is `IEnumerable` then the input of your last block needs to match (== be also `IEnumerable`.\n- I do understand that but what I want is to get a JObject as an output (from the JObject which contains a JArray as the input) from the TransformManyBlock and this should be the input of my ActionBlock. I edited my EDIT 3 section with the code. But still I don't get anything printer to the console in my ActionBlock method ...\n- So, this does not work - jsonOrderFactory = new TransformManyBlock((Func)CreateOrderMessages); as I get the following exception : Argument 1: cannot convert from 'System.Func' to 'System.Func>\n- ok, made it working finally (the pipelines) but i still have memory problems and now they are worst :( please see the EDIT 3 section for the latest code\n- Solved the part of the new Thread which consumes from my concurrentQueue and published to RMQ but I still have memory problems ... I will post it in my question above.\n- The part with the pipelines is not the problem, as I do not have memory problems if I just create the pipelines with all the logic (XML -> JSON) and just discard the messages in the ActionBlock. It's the part which publishes to RabbitMQ which is the issue :(\n- I dropped the second part with the Thread and it does not work, i still have the same problem, publishing to RabbitMQ (i.e. serviceInstance1.Publish) still has memory leaks on the long term ...\n- Doing some benchmarks right now and I am starting to think, this is something completely different ...\n- @R13mus Updated answer, if you want to have a look. Still not a final solution, but maybe a step.\n- I have some updates. First one is that I changed the XML parsing and conversion to JSON and used System.Xml.XmlSerializer to serialize the XML to objects. The problem with XmlDocument was that it was loading in memory all the objects and this was causing a big problem (I will create an update 4 to post my new code). Second thing is if I print something like a normal string to RMQ \"test\" i get big publishing rates (like 1750m/s). If I publish entire orders it only publishes at 120 m/s. One question which was unclear to me - when do i have to call startBlock.Complete() ? Thanks !\n- \"Complete()\" is kind of a \"Poison\". It basically tells the block to no longer accept input. So, it's for shutting down. See also IDataflowBlock.Complete Method\n- *\"If I publish entire orders it only publishes at 120 m/s*\" That would explain build-up. Now, my approach would be a) can it be sped-up? and/or b) can it be scaled up?\n- So I don't have to call Complete () as I want my app to run for days, weeks, months if possible. Or maybe when I dispose the service. I did put my answer up there EDIT 4. I need to try your EDIT 2 solution :) Big thanks for your patience and help !\n- Exactly. Just use it to shutdown garcefully.\n- Finally managed to solve the problem thanks to your help ! The pipelines helped a lot plus I switched back to using System.Text.Json instead of Newtonsoft.Json. I also reduced the length of the messages and did a bit more filtering and now I have a working solution. Cheers !!","metadata":{"transformedAt":"2026-08-18T18:33:20.204Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":25,"totalLines":1467,"estimatedTokens":15348}}947{"id":"stack-46297459","source":"stackoverflow","questionId":46297459,"title":"Celery check pending tasks number before specified taskid","tags":["python","rabbitmq","celery"],"text":"Title: Celery check pending tasks number before specified taskid\nTags: python, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nDoes celery support returning pending tasks number before given task id?\n\nFor example, without celery worker started, I push task1, task2, task3, all the three are pending, now, what I wanna is, if I give task3, it tells me there are 2 pending tasks before 3.\n\nI use celery celery 4.1, rabbitmq 3.5.4 as broker, and redis 3.2.9 as result backend.\n\nAlthough I can get rabbit queue depth by management API(e.g. get_queue_depth from pyrabbit package), this results the whole queue depth, not pending number before specified task id.\n\nAnd I know I could maintain a queue managing pushed task ids by myself. \n\nBut I wanna if there is any easy way by celery or rabbitmq itself.\n\nThanks.\n\n========================================\n\nCode:\n```text\ni = app.control.inspect()\ni.reserved()\n\n#output:\n[{'worker1.example.com':\n [{'name': 'tasks.sleeptask',\n 'id': '32666e9b-809c-41fa-8e93-5ae0c80afbbf',\n 'args': '(8,)',\n 'kwargs': '{}'}]}]\n```\n\n```text\nreserved\n```\n\n```text\nactive\n```\n\n========================================\n\nComments:\n- Got the same problem.\n- Although tasks in i.reserved() is list, but sequence is not exactly as the order be executed. So, this shouldn't work.\n- @Wesley did u try?\n- not yet... I think you wanna disable message prefetching, I need to find way to close this guy, seems set CELERYD_PREFETCH_MULTIPLIER = 1 is not enough, but first comes a problem that, set this guy to 1 will decrease performance. Don't know if there is any other way not decreasing performance\n- I'm working with celery in high load and set this one (for using priority queues) - it shouldn't be a problem. BTW you can still increase the worker concurrency..\n- stackoverflow.com/questions/16040039/… this post explain a lot about prefetching. However, we make a fatal mistake till now...that is, inspect is only for running celery workers, not for rabbitmq. We cannot get the pending tasks within rabbitmq from celery inspect. I think we have to solve the issue from the mq side. I am thinking about get_messages of pyrabbit package.\n- can u what is your goal? why do you need that info?","metadata":{"transformedAt":"2026-08-18T18:33:20.204Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":52,"estimatedTokens":559}}948{"id":"stack-26546129","source":"stackoverflow","questionId":26546129,"title":"RabbitMQ: prefetched messages processing","tags":["spring","rabbitmq","messaging","amqp"],"text":"Title: RabbitMQ: prefetched messages processing\nTags: spring, rabbitmq, messaging, amqp\nSource: Stack Overflow\n\nQuestion:\nI am using Spring AMQP to work with RabbitMQ. \nHere is my configuration:\n\n```\n\n \n\n```\n\nAs you can see the prefetchCount is 1000.\n\nI was wondering whether the the prefetched messages are processed in parallel in the consumer; that is, multiple threads calling the onMessage(Message message) method.\nOr are the messages rather processed sequentially; that is, one thread that iterates over the prefetched messages and calls on each message the onMessage(Message message) method in a sequntial manner.\n\nI should note that the order of the processing is not important for me. Just the fact that they are processed one at a time.\n\nThanks in advance.\n\n========================================\n\nCode:\n```text\n<rabbit:connection-factory id=\"connectionFactory\"\n host=\"${queue.host}\" port=\"${queue.port}\" />\n<rabbit:template id=\"amqpTemplate\" connection-factory=\"connectionFactory\" />\n<rabbit:admin connection-factory=\"connectionFactory\" />\n<rabbit:queue name=\"${queue.names}\" durable=\"true\"\n exclusive=\"false\" />\n<rabbit:listener-container\n connection-factory=\"connectionFactory\" acknowledge=\"auto\" error-handler=\"airbrakeHandler\" prefetch=\"1000\" >\n <rabbit:listener ref=\"consumer\" queue-names=\"${queue.names}\" />\n</rabbit:listener-container>\n```\n\n```text\nconcurrency: The number of concurrent consumers to start for each listener.\n```\n\n```text\n<rabbit:listener-container ... prefetch=\"1000\" concurrency=\"1\">\n <rabbit:listener ref=\"consumer\" queue-names=\"${queue.names}\" />\n</rabbit:listener-container>\n```\n\n```text\nSimpleMessageListenerContainer\n```\n\n```text\nconcurrency\n```\n\n```text\nSimpleMessageListenerContainer\n```\n\n========================================\n\nComments:\n- Thanks for the answer. However, when using concurrency > 1 each consumer thread has 1000 prefetched mesages. That implies that the concurrency parameter is not necessarily defining the behavior with the prefetch messages within one thread.","metadata":{"transformedAt":"2026-08-18T18:33:20.204Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":65,"estimatedTokens":511}}949{"id":"stack-51704022","source":"stackoverflow","questionId":51704022,"title":"RabbitMQ message signing","tags":["java","rabbitmq","spring-rabbit"],"text":"Title: RabbitMQ message signing\nTags: java, rabbitmq, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI want to use RabbitMQ to communicate between multiple applications which are deployed on different networks and are maintained by different people. As a receiver of a message (consumer) I want to be convinced that the sender of the message (producer) is who he claims to be. Best approach I can think for this would be message signing and verification of those signatures. As this is my first time doing something with RabbitMQ, I am kind of stuck on how to implement this.\n\nMessage senders and receivers are Java applications. I've decided to use Spring AMQP template to make things somewhat easier for me. In a perfect scenario **I would like to somehow intercept the message when it's already a byte array/stream, sign this blob and attach the signature as a message header. On the receiving end I would again like to intercept the message before it's deserialized, verify the signature from header against the blob and if everything is OK then deserialize it.** But I havent found any means in Spring-Rabbit for doing this. \nThere is a concept of `MessagePostProcessor` in Spring-Rabbit, but when this is invoked, the message is still not fully serialized. It seems like something that I imagined would be solved somewhere by someone as it feels like a common problem to have, but my research has left me bare handed.\n\nCurrently I am using `AmqpTemplate.convertAndSend` for message sending and `@RabbitListener` for message receiving. But I am not stuck with Spring. I can use whatever I like. It just seemed like an easy way to get going. I am using Jackson for message serialization to/from JSON. **Problem is how to intercept sending and receiving in the right place.**\n\nBackup plan is to put both data and signature in body and joint them with a wrapper but this would mean double serialization and is not as clean as I would like the solution to be.\n\nSo has anyone got experience with this stuff and can perhaps can advise me on how to approach this problem?\n\n========================================\n\nCode:\n```text\nMessagePostProcessor\n```\n\n```text\nAmqpTemplate.convertAndSend\n```\n\n```text\n@RabbitListener\n```\n\n```text\nMessagePostProcessor\n```\n\n```text\nMessagePostProcessor\n```\n\n```text\nbody\n```\n\n```text\nbyte[]\n```\n\n```text\nconvertAndSend\n```\n\n```text\nbeforeSendMessagePostProcessors\n```\n\n```text\nafterReceiveMessagePostProcessors\n```\n\n```text\nbody\n```\n\n```text\nbyte[]\n```\n\n========================================\n\nComments:\n- You are correct. My bad. I did not examine the API thoroughly enough.","metadata":{"transformedAt":"2026-08-18T18:33:20.204Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":12,"totalLines":71,"estimatedTokens":653}}950{"id":"stack-22786074","source":"stackoverflow","questionId":22786074,"title":"Scalable job queue system for large scale task scheduling","tags":["php","queue","rabbitmq","scalability","jobs"],"text":"Title: Scalable job queue system for large scale task scheduling\nTags: php, queue, rabbitmq, scalability, jobs\nSource: Stack Overflow\n\nQuestion:\n**The scenario:**\n\nTL;DR - I need a queue system for triggering jobs based on a future timestamp and NOT on the order it is inserted\n\nI have a MySQL database of entries that detail particular events that need to be performed (which will consist mostly of a series of arithmetic calculations and a database insert/update) in a precise sequence based on timestamps. The time the entry is inserted and when the event will be \"performed\" has no correlation and is determined by outside factors. The table also contains a second column of milliseconds which increases the timing precision.\n\nThis table is part of a job \"queue\" which will contain entries set to execute from anywhere between a few seconds to a few days in the future, and can potentially have up to thousands of entries added every second. The queue needs to be parsed constantly (every second?) - perhaps by doing a select of all timestamps that have expired during this second and sorting by the milliseconds, and then executing each event detailed by the entries.\n\n**The problem**\n\nCurrently the backend is completely written in PHP on an apache server with MySQL (ie standard LAMP architecture). Right now, the only way I can think of to achieve what I've specified is to write a custom PHP job queue script that will do the parsing and execution, looped every second using this method. There are no other job systems that I'm aware of which can queue jobs according to a specified timestamp/millisecond rather than the entry time.\n\nThis method however sounds rather infeasible CPU wise even on paper - I have to perform a huge MySQL query every second and execute some sort of function for each row retrieved, with the possibility of it running over a second of execution time which will start introducing delays to the parsing time and messing up the looping script.\n\nI am of course attempting to create a solution that will be scalable should there be heavy traffic on the system, which this solution fails miserably as it will continue falling behind as the number of entries get larger.\n\n**The questions**\n\nI'd prefer to stick to the standard LAMP architecture, but is there any other technology I can integrate nicely into the stack that is better equipped to deal with what I'm attempting to do here?\n\nIs there another method entirely to to accurately trigger events at a specified future date without the messy fiddling about with the constant queue checking?\n\nIf neither of the above options are suitable, is there a better way to loop the PHP script in the background? In the worst case scenario I can accept the long execution times and split the task up between multiple 'workers'. \n\n**Update**\n\nRabbitMQ was a good suggestion, but unfortunately doesn't execute the task as soon as it 'expires' - it has to go through a queue first and wait up on any tasks in front that have yet to expire. The expiry time has a wide range between a few seconds to a few days, and the queue needs to be sorted somehow each time a new event is added in so the expiry time is always in order in the queue. This isn't possible as far as I'm aware of in RabbitMQ, and doesn't sound very efficient either. Is there an alternative or a programmatic fix?\n\n========================================\n\nComments:\n- I did some research into RabbitMQ and it looked VERY promising until I came across this: rabbitmq.com/ttl.html (caveats). I need to set per message TTL to define the time when the task will be performed, but like I mentioned, it could range from seconds to days. I need the task to be executed as soon as the timer expires, but it looks like rabbitMQ will wait for the head of the queue to pop out first. I need some way to sort the queue so the tasks that will expire first are at the head of the queue and will pop out in order. Is there a solution to this?\n- Probably not, here's how I would try to handle it though: make the message itself have the execution time in it. The jobs that receive the messages could acknowledge immediately, read the time, if it's now or past, execute. If it's in the future, re-dispatch with the same time so that another job could pick it up. I would make all the workers sleep some small amount of time between grab and redispatch (1-100ms) so you don't busy-wait the queue server.","metadata":{"transformedAt":"2026-08-18T18:33:20.204Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":38,"estimatedTokens":1107}}951{"id":"stack-31995994","source":"stackoverflow","questionId":31995994,"title":"OutOfMemoryError using Akka Actors","tags":["scala","rabbitmq","akka","actor"],"text":"Title: OutOfMemoryError using Akka Actors\nTags: scala, rabbitmq, akka, actor\nSource: Stack Overflow\n\nQuestion:\nI have an application that consume messages from RabbitMQ and i'm using Actors to handle the work.\n\nHere is my approach:\n\n```\nobject QueueConsumer extends Queue {\n\n def consumeMessages = {\n setupListener(buildChannel(resultsQueueName), resultsQueueName,\n resultsCallback)\n }\n\n private def setupListener(receivingChannel: Channel, queue: String, \n f: (String) => Any) {\n Akka.system.scheduler.scheduleOnce(Duration(10, TimeUnit.SECONDS),\n Akka.system.actorOf(Props(new QueueActor(receivingChannel, queue, f))), \"\")\n }\n\n}\n\nclass QueueActor(channel:Channel, queue:String, f:(String) => Any) extends Actor{\n\n def receive = {\n case _ => startReceiving\n }\n\n def startReceiving = {\n val consumer = new QueueingConsumer(channel)\n channel.basicConsume(queue, false, consumer)\n while (true) {\n val delivery = consumer.nextDelivery()\n val msg = new String(delivery.getBody())\n context.actorOf(Props(new Actor {\n def receive = {\n case some: String => f(some)\n }\n })) ! msg\n channel.basicAck(delivery.getEnvelope.getDeliveryTag, false)\n }\n }\n\n}\n```\n\nAfter some seconds running, it throws a **java.lang.OutOfMemoryError: GC overhead limit exceeded**. \n\nI think that it's happening because i'm starting a new Actor for every message that i receive - so if i have 100000 messages, it'll create 100000 actors. Is it a good approach or should i implement something like an 'actors pool'?\n\nAnyone have an idea how can i avoid OutOfMemoryError in my scenario? \n\nThank in advance.\n\nedit1:\n\nchanged approach to:\n\n```\nclass Queue2(json:String) extends Actor {\n\n def receive = {\n case x: String =>\n val envelope = MessageEnvelopeParser.toObject(x)\n val processor = ProcessQueueServiceFactory.getProcessResultsService()\n envelope.messages.foreach(message => processor.process(message))\n }\n\n}\n\nobject Queue2 {\n def props(json: String): Props = Props(new Queue2(json))\n}\n\nclass QueueActor(channel:Channel, queue:String) extends Actor {\n\n def receive = {\n case _ => startReceiving\n }\n\n def startReceiving = {\n val consumer = new QueueingConsumer(channel)\n channel.basicConsume(queue, false, consumer)\n while (true) {\n val delivery = consumer.nextDelivery()\n val msg = new String(delivery.getBody())\n context.actorOf(Queue2.props(msg))\n channel.basicAck(delivery.getEnvelope.getDeliveryTag, false)\n }\n }\n}\n```\n\n========================================\n\nCode:\n```text\nobject QueueConsumer extends Queue {\n\n def consumeMessages = {\n setupListener(buildChannel(resultsQueueName), resultsQueueName,\n resultsCallback)\n }\n\n private def setupListener(receivingChannel: Channel, queue: String, \n f: (String) => Any) {\n Akka.system.scheduler.scheduleOnce(Duration(10, TimeUnit.SECONDS),\n Akka.system.actorOf(Props(new QueueActor(receivingChannel, queue, f))), \"\")\n }\n\n}\n\nclass QueueActor(channel:Channel, queue:String, f:(String) => Any) extends Actor{\n\n def receive = {\n case _ => startReceiving\n }\n\n def startReceiving = {\n val consumer = new QueueingConsumer(channel)\n channel.basicConsume(queue, false, consumer)\n while (true) {\n val delivery = consumer.nextDelivery()\n val msg = new String(delivery.getBody())\n context.actorOf(Props(new Actor {\n def receive = {\n case some: String => f(some)\n }\n })) ! msg\n channel.basicAck(delivery.getEnvelope.getDeliveryTag, false)\n }\n }\n\n}\n```\n\n```text\nclass Queue2(json:String) extends Actor {\n\n def receive = {\n case x: String =>\n val envelope = MessageEnvelopeParser.toObject(x)\n val processor = ProcessQueueServiceFactory.getProcessResultsService()\n envelope.messages.foreach(message => processor.process(message))\n }\n\n}\n\nobject Queue2 {\n def props(json: String): Props = Props(new Queue2(json))\n}\n\nclass QueueActor(channel:Channel, queue:String) extends Actor {\n\n def receive = {\n case _ => startReceiving\n }\n\n def startReceiving = {\n val consumer = new QueueingConsumer(channel)\n channel.basicConsume(queue, false, consumer)\n while (true) {\n val delivery = consumer.nextDelivery()\n val msg = new String(delivery.getBody())\n context.actorOf(Queue2.props(msg))\n channel.basicAck(delivery.getEnvelope.getDeliveryTag, false)\n }\n }\n}\n```\n\n```text\ncontext.stop(self)\n```\n\n========================================\n\nComments:\n- Creating a new `Actor` for each message isn't necessarily bad design. That shouldn't make you run out of memory unless you're holding on to every reference of actor or message somehow so the GCer can't collect them.\n- @Samuel How can i check it? When the actor calls the callback (f), it does some queries on SQL Server (like INSERT / SELECT but are simple commands). Is necessary to implement something to 'kill' the Actor when callback is complete? I'm new using Actors.\n- It looks like Akka holds onto references of every actor you pass to `actorOf()`. So it seems like you shouldn't be creating a new actor for each queued message. I think you should have one actor for executing the SQL commands, and have your `QueueActor` read from the queue and send the commands to your SQL executor actor. Looks like you can use Akka.system.stop() to kill an actor reference if you really wanted to do what you're doing now.\n- @Samuel I've tried another approach but same error. Could you check this edition that i've did on the topic and check if it was what you were talking about?\n- Have you tried to put the nested `Actor` outside of `QueueActor` passing `f: (String => Any)` ass constructor argument? I seem to remember someone saying that it is a bad idea to expose one `Actor`s fields by closure to another `Actor`. Also (just a hunch), instead of blocking inside `receive` you could consider using a future to receive the message and create the message actor inside `Future.onSuccess`.\n- @SaschaKolberg are you talking about approach after or before edit? Do you mean put the nested Actor inside the callback function?\n- @placplacboom ah, sorry, the edit came while I was writing. No, your edit does exactly what I meant with *putting the nested actor outside `QueueActor`*. Did it help?\n- In your edited example, `Queue2` takes the `json` parameter as a constructor argument, and then waits for a message. You don't seem to either use the json parameter or send a message after doing context.actorOf?\n- @mattinbits you are right. I'm debugging it right now and it looks like that ''Queue2'' is never being called. The code \"context.actorOf(Queue2.props(msg))\" is the correct way to start and execute a new actor?\n- Yes that's the right way to create the actor but it won't take any action once it's created, the way you currently have it. You either need to send it a message which is handled in `receive`, or override `preStart` and do the work in there.","metadata":{"transformedAt":"2026-08-18T18:33:20.204Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":191,"estimatedTokens":1711}}952{"id":"stack-32105151","source":"stackoverflow","questionId":32105151,"title":"How to serialize / parse protobuf object between Ruby and Java?","tags":["java","ruby","rabbitmq","protocol-buffers"],"text":"Title: How to serialize / parse protobuf object between Ruby and Java?\nTags: java, ruby, rabbitmq, protocol-buffers\nSource: Stack Overflow\n\nQuestion:\nWhat is the correct way to serialize a protobuf object in ruby and parse in Java? This is for automated testing, we are listening for this message on a Rabbit queue.\n\nPublisher (Ruby):\n\n```\nprotoNew = Protobuf::Request.new\nprotoNew.request = request\nprotoNew.id = id.to_i\nprotoNew.authentication = authentication\n\nreturn protoNew.serialize_to_string\n```\n\nConsumer (Java):\n\n```\n@Override\n public void onMessage(Message message, Channel channel) \n {\n ProtoRequest protoRequest;\n try {\n protoRequest = ProtoRequest.parseFrom(message.getBody());\n } catch (InvalidProtocolBufferException e1) {\n logger.error(\"Error parsing protobuf\", e1);\n }\n```\n\nHere is the error I am seeing:\n\n Error parsing protobuf: com.google.protobuf.InvalidProtocolBufferException: Protocol message end-group tag did not match expected tag.\n at com.google.protobuf.InvalidProtocolBufferException.invalidEndTag(InvalidProtocolBufferException.java:94) [protobuf-java-2.6.1.jar:]\n at com.google.protobuf.CodedInputStream.checkLastTagWas(CodedInputStream.java:174) [protobuf-java-2.6.1.jar:]\n at com.google.protobuf.AbstractParser.parsePartialFrom(AbstractParser.java:139) [protobuf-java-2.6.1.jar:]\n at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:168) [protobuf-java-2.6.1.jar:]\n at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:180) [protobuf-java-2.6.1.jar:]\n at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:185) [protobuf-java-2.6.1.jar:]\n at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:49) [protobuf-java-2.6.1.jar:]\n\n========================================\n\nCode:\n```text\nprotoNew = Protobuf::Request.new\nprotoNew.request = request\nprotoNew.id = id.to_i\nprotoNew.authentication = authentication\n\nreturn protoNew.serialize_to_string\n```\n\n```text\n@Override\n public void onMessage(Message message, Channel channel) \n {\n ProtoRequest protoRequest;\n try {\n protoRequest = ProtoRequest.parseFrom(message.getBody());\n } catch (InvalidProtocolBufferException e1) {\n logger.error(\"Error parsing protobuf\", e1);\n }\n```\n\n```text\nrequire \"base64\"\n...\nreturn Base64.encode64 protoNew.serialize_to_string\n```\n\n```text\nimport org.apache.commons.codec.binary.Base64;\n...\nprotoRequest = ProtoRequest.parseFrom(Base64.decodeBase64(message.getBody()))\n```\n\n```text\nf = File.open(\"data.dat\", \"wb\")\nf << person.serialize_to_string\nf.close\n```\n\n```text\nprotoNew.serialize_to_string\n```\n\n```text\nprotoNew.serialize_to_string\n```\n\n```text\nperson.serialize_to_string\n```\n\n========================================\n\nComments:\n- Thanks! This worked with a small change, I ended up using \"protoRequest = ProtoRequest.parseFrom( Base64.decode( new String( message.getBody() ) ) );\" on the java side, since message.getBody() was returning a byte array.\n- Similar success here but afaict `serialize_to_string` may no longer be a method. I did `Base64.strict_encode64 Prefab::Request.encode(user)` The strict leaves out the newlines which have only lead to pain for me in the past.","metadata":{"transformedAt":"2026-08-18T18:33:20.204Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":102,"estimatedTokens":802}}953{"id":"stack-38266378","source":"stackoverflow","questionId":38266378,"title":"Camel RabbitMQ connection using camel amqp","tags":["rabbitmq","apache-camel","amqp"],"text":"Title: Camel RabbitMQ connection using camel amqp\nTags: rabbitmq, apache-camel, amqp\nSource: Stack Overflow\n\nQuestion:\nI am trying to connect to rabbitmq in my camel route using camel-amqp (version 2.17) component.\n\nI have configured it as below :\n\n```\n@Bean\n CachingConnectionFactory jmsCachingConnectionFactory(){\n\n JmsConnectionFactory pool = new JmsConnectionFactory();\n pool.setRemoteURI(\"amqp://127.0.0.1:5672\");\n pool.setUsername(\"guest\");\n pool.setPassword(\"guest\");\n\n CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();\n cachingConnectionFactory.setTargetConnectionFactory(pool);\n return cachingConnectionFactory;\n }\n\n @Bean\n JmsConfiguration jmsConfig(){\n\n JmsConfiguration configuration = new JmsConfiguration();\n configuration.setConnectionFactory(jmsCachingConnectionFactory());\n // configuration.setCacheLevelName(\"CACHE_CONSUMER\");\n return configuration;\n }\n\n @Bean\n AMQPComponent amqp(){\n AMQPComponent component = new AMQPComponent();\n component.setConfiguration(jmsConfig());\n return component;\n }\n```\n\nThe error I am getting is \n\n javax.jms.JMSException: An existing connection was forcibly closed by\n the remote host\n at\n org.apache.qpid.jms.exceptions.JmsExceptionSupport.create(JmsExceptionSupport.java:66)\n ~[qpid-jms-client-0.8.0.jar:0.8.0]\n\nIn my rabbitmq log I can see the below message which I am not able to understand \n\n*\n\n```\n** Reason for termination == \n** {function_clause,\n [{rabbit_amqp1_0_link_util,'-outcomes/1-lc$^0/1-0-',\n [{list,\n [{symbol,>},\n {symbol,>},\n {symbol,>},\n {symbol,>}]}],\n [{file,\"src/rabbit_amqp1_0_link_util.erl\"},{line,49}]},\n {rabbit_amqp1_0_link_util,outcomes,1,\n [{file,\"src/rabbit_amqp1_0_link_util.erl\"},{line,49}]},\n {rabbit_amqp1_0_outgoing_link,attach,3,\n [{file,\"src/rabbit_amqp1_0_outgoing_link.erl\"},{line,41}]},\n {rabbit_amqp1_0_session_process,with_disposable_channel,2,\n [{file,\"src/rabbit_amqp1_0_session_process.erl\"},{line,377}]},\n {rabbit_amqp1_0_session_process,handle_control,2,\n [{file,\"src/rabbit_amqp1_0_session_process.erl\"},{line,197}]},\n {rabbit_amqp1_0_session_process,handle_cast,2,\n [{file,\"src/rabbit_amqp1_0_session_process.erl\"},{line,134}]},\n {gen_server2,handle_msg,2,[{file,\"src/gen_server2.erl\"},{line,1049}]},\n {proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,240}]}]}\n=ERROR REPORT==== 8-Jul-2016::17:09:27 ===\nclosing AMQP connection (127.0.0.1:55479 -> 127.0.0.1:5672):\n{handshake_error,running,,\n {{symbol,>},\n \"Session error: ~p~n~p~n\",\n [function_clause,\n [{rabbit_amqp1_0_link_util,'-outcomes/1-lc$^0/1-0-',\n [{list,\n [{symbol,>},\n {symbol,>},\n {symbol,>},\n {symbol,>}]}],\n [{file,\"src/rabbit_amqp1_0_link_util.erl\"},{line,49}]},\n {rabbit_amqp1_0_link_util,outcomes,1,\n [{file,\"src/rabbit_amqp1_0_link_util.erl\"},{line,49}]},\n {rabbit_amqp1_0_outgoing_link,attach,3,\n [{file,\"src/rabbit_amqp1_0_outgoing_link.erl\"},{line,41}]},\n {rabbit_amqp1_0_session_process,with_disposable_channel,2,\n [{file,\"src/rabbit_amqp1_0_session_process.erl\"},{line,377}]},\n {rabbit_amqp1_0_session_process,handle_control,2,\n [{file,\"src/rabbit_amqp1_0_session_process.erl\"},{line,197}]},\n {rabbit_amqp1_0_session_process,handle_cast,2,\n [{file,\"src/rabbit_amqp1_0_session_process.erl\"},{line,134}]},\n {gen_server2,handle_msg,2,[{file,\"src/gen_server2.erl\"},{line,1049}]},\n {proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,240}]}]]}}\n```\n\n*\n\nI have enabled amqp_1_0 plugin in rabbitmq.\nCan someone help me resolve this.\n\n========================================\n\nCode:\n```text\n@Bean\n CachingConnectionFactory jmsCachingConnectionFactory(){\n\n JmsConnectionFactory pool = new JmsConnectionFactory();\n pool.setRemoteURI(\"amqp://127.0.0.1:5672\");\n pool.setUsername(\"guest\");\n pool.setPassword(\"guest\");\n\n CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();\n cachingConnectionFactory.setTargetConnectionFactory(pool);\n return cachingConnectionFactory;\n }\n\n @Bean\n JmsConfiguration jmsConfig(){\n\n JmsConfiguration configuration = new JmsConfiguration();\n configuration.setConnectionFactory(jmsCachingConnectionFactory());\n // configuration.setCacheLevelName(\"CACHE_CONSUMER\");\n return configuration;\n }\n\n @Bean\n AMQPComponent amqp(){\n AMQPComponent component = new AMQPComponent();\n component.setConfiguration(jmsConfig());\n return component;\n }\n```\n\n```text\n** Reason for termination == \n** {function_clause,\n [{rabbit_amqp1_0_link_util,'-outcomes/1-lc$^0/1-0-',\n [{list,\n [{symbol,<<\"amqp:accepted:list\">>},\n {symbol,<<\"amqp:rejected:list\">>},\n {symbol,<<\"amqp:released:list\">>},\n {symbol,<<\"amqp:modified:list\">>}]}],\n [{file,\"src/rabbit_amqp1_0_link_util.erl\"},{line,49}]},\n {rabbit_amqp1_0_link_util,outcomes,1,\n [{file,\"src/rabbit_amqp1_0_link_util.erl\"},{line,49}]},\n {rabbit_amqp1_0_outgoing_link,attach,3,\n [{file,\"src/rabbit_amqp1_0_outgoing_link.erl\"},{line,41}]},\n {rabbit_amqp1_0_session_process,with_disposable_channel,2,\n [{file,\"src/rabbit_amqp1_0_session_process.erl\"},{line,377}]},\n {rabbit_amqp1_0_session_process,handle_control,2,\n [{file,\"src/rabbit_amqp1_0_session_process.erl\"},{line,197}]},\n {rabbit_amqp1_0_session_process,handle_cast,2,\n [{file,\"src/rabbit_amqp1_0_session_process.erl\"},{line,134}]},\n {gen_server2,handle_msg,2,[{file,\"src/gen_server2.erl\"},{line,1049}]},\n {proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,240}]}]}\n=ERROR REPORT==== 8-Jul-2016::17:09:27 ===\nclosing AMQP connection <0.29082.0> (127.0.0.1:55479 -> 127.0.0.1:5672):\n{handshake_error,running,<0.29104.0>,\n {{symbol,<<\"amqp:internal-error\">>},\n \"Session error: ~p~n~p~n\",\n [function_clause,\n [{rabbit_amqp1_0_link_util,'-outcomes/1-lc$^0/1-0-',\n [{list,\n [{symbol,<<\"amqp:accepted:list\">>},\n {symbol,<<\"amqp:rejected:list\">>},\n {symbol,<<\"amqp:released:list\">>},\n {symbol,<<\"amqp:modified:list\">>}]}],\n [{file,\"src/rabbit_amqp1_0_link_util.erl\"},{line,49}]},\n {rabbit_amqp1_0_link_util,outcomes,1,\n [{file,\"src/rabbit_amqp1_0_link_util.erl\"},{line,49}]},\n {rabbit_amqp1_0_outgoing_link,attach,3,\n [{file,\"src/rabbit_amqp1_0_outgoing_link.erl\"},{line,41}]},\n {rabbit_amqp1_0_session_process,with_disposable_channel,2,\n [{file,\"src/rabbit_amqp1_0_session_process.erl\"},{line,377}]},\n {rabbit_amqp1_0_session_process,handle_control,2,\n [{file,\"src/rabbit_amqp1_0_session_process.erl\"},{line,197}]},\n {rabbit_amqp1_0_session_process,handle_cast,2,\n [{file,\"src/rabbit_amqp1_0_session_process.erl\"},{line,134}]},\n {gen_server2,handle_msg,2,[{file,\"src/gen_server2.erl\"},{line,1049}]},\n {proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,240}]}]]}}\n```\n\n========================================\n\nComments:\n- There is a camel-rabbitmq component. Why don't you use that one?\n- Camel-rabbitmq works perfect but the only problem is transaction support seems missing. I don't see a way to set my tx manager in the component. That the only reason I started looking at amqp as it usages jms component which has tx support.\n- RabbitMQ discourages usage of AMQP transactions since they are very slow - in developer's own words, they **decrease throughput by a whopping factor of 250**! I know it doesn't help you with this problem but my suggestion would be to try using RabbitMQ with autoAck option off and with publisher confirms enabled. Confirms are supported by Camel as of version 2.17.0, see the RabbitMQ component's documentation for details.","metadata":{"transformedAt":"2026-08-18T18:33:20.204Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":195,"estimatedTokens":1955}}954{"id":"stack-39699727","source":"stackoverflow","questionId":39699727,"title":"What is the difference between prefetch count vs no ack in rabbitmq","tags":["rabbitmq","spring-amqp","spring-rabbit"],"text":"Title: What is the difference between prefetch count vs no ack in rabbitmq\nTags: rabbitmq, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI need to know what is the difference between prefetch count vs no ack in rabbitmq ?\n\nAlso \nWhat is the difference between following statements :-\n\nif i set prefetch count say 10 does 10 consumer threads are created ?\nOr --\n\nif i register 10 cosumers will it create 10 threads ?\n\nWhich of the above is more efficient\n\n========================================\n\nTop Answer:\nTo answer this specifically for spring-amqp.\n\n`prefetchCount=10` means the broker allows up to 10 unacked message for each consumer; it does not affect the number of threads.\n\nUse `concurrentConsumers` to create multiple consumers - which will have one thread each.\n\nauto ack means the broker doesn't require acks (so you can lose messages). Spring AMQP also blocks deliveries (to prefetch count) if the listener can't keep up.\n\n========================================\n\nCode:\n```text\nprefetchCount=10\n```\n\n```text\nconcurrentConsumers\n```\n\n```text\nbasic.get\n```\n\n```text\nbasic.consume\n```\n\n```text\nmessage = queue.get\n```\n\n```text\nqueue.subscribe do ...\n```\n\n```text\nGetResponse response = channel.basicGet(\"some.queue\", false);\n```\n\n========================================\n\nComments:\n- This is the correct answer. The accepted one is wrong. If auto-ack is set(true) broker would keep delivering messages without caring prefetch count.","metadata":{"transformedAt":"2026-08-18T18:33:20.204Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":63,"estimatedTokens":365}}955{"id":"stack-25226607","source":"stackoverflow","questionId":25226607,"title":"AMQPRuntimeException: Error reading data. Received 0 instead of expected 7 bytes","tags":["php","rabbitmq","amqp"],"text":"Title: AMQPRuntimeException: Error reading data. Received 0 instead of expected 7 bytes\nTags: php, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nIt was working, but now it's not working anymore!\n\nI'm using php-amqplib and RabbitMQ.\n\nhttps://i.sstatic.net/g0hC4.jpg\n\nwhen I'm trying to create a new AMQP connection:\n\n```\n$connection = new AMQPConnection('localhost', 5672, 'username', 'password');\n```\n\nThe code inside the library that is causing this error is:\n\n```\npublic function read($n)\n{\n $res = '';\n $read = 0;\n\n while ($read sock) &&\n (false !== ($buf = fread($this->sock, $n - $read)))) {\n\n if ($buf === '') {\n continue;\n }\n\n $read += strlen($buf);\n $res .= $buf;\n }\n\n if (strlen($res)!=$n) {\n throw new AMQPRuntimeException(\"Error reading data. Received \" .\n strlen($res) . \" instead of expected $n bytes\");\n }\n\n return $res;\n}\n```\n\nWhen I put this just before the exception:\n\n```\ndie($res.\" :\".$n);\n```\n\nthe result is:\n\n```\nÏ :7 :7\n```\n\nit is called twice, in first call $res is two null characters then \"Ï\"\n\nand in second call it's just null.\n\noh and I deleted files inside mnesia folder of rabbitmq database manually once, I don't know if that caused the problem, but the RabbitMQ Management which is a web based app running on port 15672 is working fine.\n\n========================================\n\nTop Answer:\nYou'll get this error also if port number is wrong. I was using management port 15672 instead of server port 5672 by mistake and was getting this same error.\n\nSo if user permission tweaking doesn't work then check connection parameter.\n\n========================================\n\nCode:\n```text\n$connection = new AMQPConnection('localhost', 5672, 'username', 'password');\n```\n\n```text\npublic function read($n)\n{\n $res = '';\n $read = 0;\n\n while ($read < $n && !feof($this->sock) &&\n (false !== ($buf = fread($this->sock, $n - $read)))) {\n\n if ($buf === '') {\n continue;\n }\n\n $read += strlen($buf);\n $res .= $buf;\n }\n\n if (strlen($res)!=$n) {\n throw new AMQPRuntimeException(\"Error reading data. Received \" .\n strlen($res) . \" instead of expected $n bytes\");\n }\n\n return $res;\n}\n```\n\n```text\ndie($res.\" :\".$n);\n```\n\n```text\nÏ :7 :7\n```\n\n```text\nrabbitmqctl add_user newuser <PASSWORD>\nrabbitmqctl set_permissions -p / newuser \".*\" \".*\" \".*\"\n```\n\n========================================\n\nComments:\n- Yes, this usually happens when you have the wrong credentials. I should update the lib and actually show a proper error message here.\n- yes, that would be better to show error message about credentials.\n- For our case we opened thousands of consumer connections by mistake which exhaust the server and having the same error message","metadata":{"transformedAt":"2026-08-18T18:33:20.204Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":122,"estimatedTokens":685}}956{"id":"stack-32642768","source":"stackoverflow","questionId":32642768,"title":"RabbitMQ: Is it possible to delete queues when they are empty?","tags":["javascript","node.js","rabbitmq","amqp"],"text":"Title: RabbitMQ: Is it possible to delete queues when they are empty?\nTags: javascript, node.js, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nIdeally I'd like to delete queues in RabbitMQ when they become empty. Basically, I'd like a queue to be contain a backlog of messages and then when something happens, those messages will get sent off until the queue is empty. Once the queue is empty, I'd like to delete this.\n\nIs this possible? I'm using Node.\n\n========================================\n\nCode:\n```text\nvar queueType = {durable: false, autoDelete: true, exclusive: false,\n arguments : {\n 'x-message-ttl' : messageTTL,\n 'x-expires' : queueTTL\n }\n};\n\nchannel.assertQueue (qname, queueType_Shared)\n```\n\n```text\njavascript\n```\n\n========================================\n\nComments:\n- Does \"no consumers attached to it\" also mean \"the queue finished acking all of its messages\"? What if all the worker consumers disconnected but there are still messages left to be processed in the queue? Would the queue get deleted and all of the messages lost?\n- Down vote because the question asked \"When the queue is empty\". This is a fantastic answer for a time and connection auto delete queue.","metadata":{"transformedAt":"2026-08-18T18:33:20.204Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":32,"estimatedTokens":302}}957{"id":"stack-49047458","source":"stackoverflow","questionId":49047458,"title":"RabbitMQ crash with bump_reduce_memory_use","tags":["rabbitmq"],"text":"Title: RabbitMQ crash with bump_reduce_memory_use\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am using **RabbitMQ 3.7.3** on Erlang 20.2.2 deployed on a docker (image `rabbitmq:3.7-management`).\n\nMemory is setup like this : `Memory high watermark set to 6000 MiB (6291456000 bytes) of 8192 MiB (8589934592 bytes) total`\n\nHere is the crash report that I am getting on automatic restart of RabbitMQ :\n\n CRASH REPORT Process with 0 neighbours exited with reason:\n no function clause matching\n rabbit_priority_queue:handle_info(bump_reduce_memory_use,\n {state,rabbit_variable_queue,[{10,{vqstate,{0,{[],[]}},{0,{[],[]}},{delta,undefined,0,0,undefined},...}},...],...})\n line 396 in gen_server2:terminate/3 line 1161\n\nIt seems to be due to messages posted to a queue setup like this filled with 500k+ messages :\nhttps://i.sstatic.net/7jDLi.png\n\nThanks for your help !\n\n========================================\n\nCode:\n```text\nrabbitmq:3.7-management\n```\n\n```text\nMemory high watermark set to 6000 MiB (6291456000 bytes) of 8192 MiB (8589934592 bytes) total\n```\n\n```text\n3.7.x\n```\n\n```text\nmaster\n```\n\n```text\n3.7.4\n```\n\n========================================\n\nComments:\n- You may have found a bug. Please post this information to the mailing list and include the *entire* server and crash log, which will have more information about the crash than what you have posted here. Also, please clarify what you mean by \"on automatic restart of RabbitMQ\". Thank you!","metadata":{"transformedAt":"2026-08-18T18:33:20.205Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":49,"estimatedTokens":366}}958{"id":"stack-1489429","source":"stackoverflow","questionId":1489429,"title":"Benefits of Commercial Messaging Middleware vs Open Source","tags":["activemq-classic","rabbitmq","amqp","tibco","tibco-ems"],"text":"Title: Benefits of Commercial Messaging Middleware vs Open Source\nTags: activemq-classic, rabbitmq, amqp, tibco, tibco-ems\nSource: Stack Overflow\n\nQuestion:\nI've been evaluating several opensource message queue technologies, such as RabbitMQ, ActiveMQ, OpenAMQ, etc. My question is, what benefits are gained by using a commercial technology such as Tibco EMS, WebSphereMQ, Sonic, etc. instead of something like Active or Rabbit? PHP will be the primary language involved, although Java systems will be interacting as well.\n\n========================================\n\nTop Answer:\nThose commercial technologies are good, but investment in them can be steep. Both yearly license costs and on-going support costs must be considered when making a decision. As far as vendor lock-in goes, in the commercial world there's only one vendor offering support for a given product. In the open source world, there's typically more than one vendor offering support. Consider ActiveMQ for example. Both Progress Software and SpringSource offer support agreements for ActiveMQ as well as some others.\n\nAlso, in the commercial world, you won't ever get to look a the source code yourself. For a product like ActiveMQ, anyone can grab the source code. This is pretty powerful because it means that you can add features, etc. and quite possibly get them added to the product.\n\nActiveMQ has a great community and is very widely deployed. ActiveMQ provides client APIs for many languages including C/C++, Java, .NET, Perl, PHP, Python, Ruby and more.\n\n========================================\n\nComments:\n- \"Consider ActiveMQ for example. Both Progress Software and SpringSource offer support agreements for ActiveMQ\" - if support for opensource software ultimately becomes the same cost then why not a vendor based commerical product?","metadata":{"transformedAt":"2026-08-18T18:33:20.205Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":20,"estimatedTokens":453}}959{"id":"stack-18143984","source":"stackoverflow","questionId":18143984,"title":"RabbitMQ lose message before consumer reconnect","tags":["rabbitmq","amqp"],"text":"Title: RabbitMQ lose message before consumer reconnect\nTags: rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI implemented a consumer, which will reconnect to broker automatically after a while if underlying connection is closed. My case is as below:\n\n- Launch RabbitMQ server successfully.\n\n- Launch consumer successfully.\n\n- Published a message, and consumer received it successfully.\nStop RabbitMQ server, consumer will show an exception:\n\n com.rabbitmq.client.ShutdownSignalException: connection error; reason: {#method(reply-code=541, reply-text=INTERNAL_ERROR, class-id=0, method-id=0), null, \"\"}. \n\nAnd then consumer will sleep 60 seconds before reconnect.\n\n- Launch RabbitMQ server again.\n\n- Publish a message successfully, the result of command 'list_queues' is 0\n\n- After 60 seconds, consumer connect to RabbitMQ again, however now messages received which are published at step#6.\n\n- Publish the 3rd message, consumer received it successfully.\n\nIn this case, all messages published before reconnect will be lost. \nAlso I performed another experiment.\n\n- Launch RabbitMQ, and publish a message successfully(no consumer process launched).\n\n- Stop RabbitMQ, then restart it.\n\n- Launch consumer process, receive the message published at step#1 successfully.\n\nNote:The QOS of consumer is 1.\nI have researched RabbitMQ several days, in my understanding, consumer should get the message published before reconnect. \nPls help(I ran test based on windows rabbitMQ).\n\nBelow is the PUBLISHER:\n\n```\nConnectionFactory factory = new ConnectionFactory();\nfactory.setHost(this.getHost());\nconnection = factory.newConnection();\nChannel channel = connection.createChannel(); \nchannel = conn.createChannel();\n// declare a 'topic' type of exchange\nchannel.exchangeDeclare(exchangeName, \"topic\");\n// Content-type \"application/octet-stream\", deliveryMode 2\n// (persistent), priority zero\nchannel.basicPublish(exchangeName, routingKey, MessageProperties.PERSISTENT_BASIC, message);\nconnection.close();\n```\n\nAnd the CONSUMER is as below:\n\n```\n@Override\npublic void consume(final String exchangeName, final String queueName, final String routingKey,\n final int qos) throws IOException, InterruptedException {\n ConnectionFactory factory = new ConnectionFactory();\n factory.setHost(this.getHost());\n\n while (true) {\n Connection connection = null;\n try {\n connection = factory.newConnection();\n Channel channel = connection.createChannel();\n\n channel.exchangeDeclare(exchangeName, \"topic\");\n // declare a durable, non-exclusive, non-autodelete queue.\n channel.queueDeclare(queueName, true, false, false, null);\n channel.queueBind(queueName, exchangeName, routingKey);\n // distribute workload among all consumers, consumer will\n // pre-fetch\n // {qos}\n // messages to local buffer.\n channel.basicQos(qos);\n\n logger.debug(\" [*] Waiting for messages. To exit press CTRL+C\");\n\n QueueingConsumer consumer = new QueueingConsumer(channel);\n // disable auto-ack. If enable auto-ack, RabbitMQ delivers a\n // message to\n // the customer it immediately removes it from memory.\n boolean autoAck = false;\n channel.basicConsume(queueName, autoAck, consumer);\n\n while (true) {\n QueueingConsumer.Delivery delivery = consumer.nextDelivery();\n try {\n RabbitMessageConsumer.this.consumeMessage(delivery);\n }\n catch (Exception e) {\n // the exception shouldn't affect the next message\n logger.info(\"[IGNORE]\" + e.getMessage());\n }\n channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);\n }\n }\n catch (Exception e) {\n logger.warn(e);\n }\n\n if (autoReconnect) {\n this.releaseConn(connection);\n logger.info(\"[*] Will try to reconnect to remote host(\" + this.getHost() + \") in \"\n + this.reconnectInterval / 1000 + \" seconds.\");\n Thread.sleep(this.getReconnectInterval());\n }\n else\n break;\n }\n}\n\nprivate void releaseConn(Connection conn) {\n try {\n if (conn != null)\n conn.close();\n }\n catch (Exception e) {\n // simply ignore this exception\n }\n}\n```\n\nAs it is a 'topic' exchange, no queue is declared at PUBLISHER. However at step#3 of 1st test, the durable queue has been declared, and the message is durable as well. I don't understand why message will be lost before reconnect.\n\n========================================\n\nTop Answer:\nOh, I found the cause...The message and queue are certainly durable, however the exchange isn't durable. As exchange isn't durable, the binding information between queue and exchange will be lost between RabbitMQ broker restart. \n\nNow I declare the exchange as durable, consumer can get message which published before consumer restart and after broker restart.\n\n========================================\n\nCode:\n```text\nConnectionFactory factory = new ConnectionFactory();\nfactory.setHost(this.getHost());\nconnection = factory.newConnection();\nChannel channel = connection.createChannel(); \nchannel = conn.createChannel();\n// declare a 'topic' type of exchange\nchannel.exchangeDeclare(exchangeName, \"topic\");\n// Content-type \"application/octet-stream\", deliveryMode 2\n// (persistent), priority zero\nchannel.basicPublish(exchangeName, routingKey, MessageProperties.PERSISTENT_BASIC, message);\nconnection.close();\n```\n\n```text\n@Override\npublic void consume(final String exchangeName, final String queueName, final String routingKey,\n final int qos) throws IOException, InterruptedException {\n ConnectionFactory factory = new ConnectionFactory();\n factory.setHost(this.getHost());\n\n while (true) {\n Connection connection = null;\n try {\n connection = factory.newConnection();\n Channel channel = connection.createChannel();\n\n channel.exchangeDeclare(exchangeName, \"topic\");\n // declare a durable, non-exclusive, non-autodelete queue.\n channel.queueDeclare(queueName, true, false, false, null);\n channel.queueBind(queueName, exchangeName, routingKey);\n // distribute workload among all consumers, consumer will\n // pre-fetch\n // {qos}\n // messages to local buffer.\n channel.basicQos(qos);\n\n logger.debug(\" [*] Waiting for messages. To exit press CTRL+C\");\n\n QueueingConsumer consumer = new QueueingConsumer(channel);\n // disable auto-ack. If enable auto-ack, RabbitMQ delivers a\n // message to\n // the customer it immediately removes it from memory.\n boolean autoAck = false;\n channel.basicConsume(queueName, autoAck, consumer);\n\n while (true) {\n QueueingConsumer.Delivery delivery = consumer.nextDelivery();\n try {\n RabbitMessageConsumer.this.consumeMessage(delivery);\n }\n catch (Exception e) {\n // the exception shouldn't affect the next message\n logger.info(\"[IGNORE]\" + e.getMessage());\n }\n channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);\n }\n }\n catch (Exception e) {\n logger.warn(e);\n }\n\n if (autoReconnect) {\n this.releaseConn(connection);\n logger.info(\"[*] Will try to reconnect to remote host(\" + this.getHost() + \") in \"\n + this.reconnectInterval / 1000 + \" seconds.\");\n Thread.sleep(this.getReconnectInterval());\n }\n else\n break;\n }\n}\n\nprivate void releaseConn(Connection conn) {\n try {\n if (conn != null)\n conn.close();\n }\n catch (Exception e) {\n // simply ignore this exception\n }\n}\n```\n\n```text\n/var/lib/rabbitmq/mnesia\n```\n\n```text\nchannel.queueDeclare(QUEUE_NAME, true, false, false, null);\n```\n\n```text\nchannel.queueDeclare(QUEUE_NAME, false, false, false, null);\n```\n\n========================================\n\nComments:\n- After the restart of RabbitMQ does the queue exist? Is it bound to the exchange you are publishing the message to?\n- Yes, the queue is durable. In the 2nd test, after restart rabbitMQ broker, the consumer received message successfully.\n- The result of command 'list_queues' after restart rabbitmq server and before consumer reconnect is \"Listing queues ... com.mpos.lottery.te.thirdpartyservice.amqp.RabbitMessagePubl‌​isher 0 ...done.\" That is the queue declared by consumer.","metadata":{"transformedAt":"2026-08-18T18:33:20.205Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":241,"estimatedTokens":2077}}960{"id":"stack-12594178","source":"stackoverflow","questionId":12594178,"title":"Disadvantages of MySQL Row Locking","tags":["php","mysql","sql","rabbitmq"],"text":"Title: Disadvantages of MySQL Row Locking\nTags: php, mysql, sql, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am using row locking (transactions) in MySQL for creating a job queue. Engine used is InnoDB.\n\n**SQL Query**\n\n```\nSTART TRANSACTION;\nSELECT * \nFROM mytable \nWHERE status IS NULL \nORDER BY timestamp DESC LIMIT 1 \nFOR UPDATE;\nUPDATE mytable SET status = 1;\nCOMMIT;\n```\n\nAccording to this webpage, \n\n `The problem with SELECT FOR UPDATE is that it usually creates a\n single synchronization point for all of the worker processes, and you\n see a lot of processes waiting for the locks to be released with\n COMMIT.`\n\n**Question:** Does this mean that when the first query is executed, which takes some time to finish the transaction before, when the second similar query occurs before the first transaction is committed, it will have to wait for it to finish before the query is executed? If this is true, then I do not understand why the row locking of a single row (which I assume) will affect the next transaction query that would not require reading that locked row?\n\nAdditionally, can this problem be solved (and still achieve the effect row locking does for a job queue) by doing a `UPDATE` instead of the transaction?\n\n```\nUPDATE mytable SET status = 1\nWHERE status IS NULL\nORDER BY timestamp DESC\nLIMIT 1\n```\n\n========================================\n\nCode:\n```text\nSTART TRANSACTION;\nSELECT * \nFROM mytable \nWHERE status IS NULL \nORDER BY timestamp DESC LIMIT 1 \nFOR UPDATE;\nUPDATE mytable SET status = 1;\nCOMMIT;\n```\n\n```text\nUPDATE mytable SET status = 1\nWHERE status IS NULL\nORDER BY timestamp DESC\nLIMIT 1\n```\n\n```text\nThe problem with SELECT FOR UPDATE is that it usually creates a\n single synchronization point for all of the worker processes, and you\n see a lot of processes waiting for the locks to be released with\n COMMIT.\n```\n\n```text\nUPDATE\n```\n\n```text\nUPDATE mytable SET status = 1\nWHERE status IS NULL\nORDER BY timestamp DESC\nLIMIT 1\n```\n\n```text\nUPDATE\n```\n\n```text\nLOCK IN SHARE MODE\n```\n\n```text\nupdate or delete\n```\n\n========================================\n\nComments:\n- Locking is based on the storage engine - what are you using?\n- Thanks (and 9 more chars to go)\n- Unfortunately, your `status IS NULL ORDER BY` query guarantees a full table scan of `mytable.` Indexes aren't helpful for IS NULL searches. If you could refactor your code to eliminate NULL status values, search for some other value, and use an index for that, you'd save a lot of table-scan time.\n- Will setting the default value of `status` to `0` and indexing it be better?\n- Yes, that scheme will make your 'find the next mytable row that's eligible for processing' operation much faster.","metadata":{"transformedAt":"2026-08-18T18:33:20.205Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":97,"estimatedTokens":674}}961{"id":"stack-11634407","source":"stackoverflow","questionId":11634407,"title":"Scheduled Celery tasks on RabbitMQ remain unacknowledged past their specified run time","tags":["python","heroku","rabbitmq","celery","django-celery"],"text":"Title: Scheduled Celery tasks on RabbitMQ remain unacknowledged past their specified run time\nTags: python, heroku, rabbitmq, celery, django-celery\nSource: Stack Overflow\n\nQuestion:\nHaving trouble getting scheduled tasks to run at a specified future time while using Celery and RabbitMQ. \n\nUsing Django on a Heroku server, with the RabbitMQ add-on. \n\n**The Problem:**\n\nSometimes the tasks don't run at all, sometimes they do run, but the times that they run at are off by a significant margin (like an hour).\n\n**Example task that did not run:**\n\nWhen I try to run a task with a countdown or ETA, it never actually executes. This is an example ETA task that did not run:\n\n```\n>>> dummy_task.apply_async(eta=datetime.datetime.now() + timedelta(seconds=60))\n\n```\n\nResulting Log:\n\n2012-07-24T14:03:08+00:00 app[scheduler.1]: [2012-07-24 10:03:08,909: INFO/MainProcess]\n Got task from broker: events.tasks.dummy_task[910ff406-d51c-4c29-bdd1-fec1a8168c12] \n eta:[2012-07-24 10:04:08.819528+00:00]\n\nOne minute later nothing happens. The `unacknowledged message count` in my Heroku RabbitMQ management console increases by one and stays there. \n\n**This works:**\n\nI've made sure that the celery task is properly registered and RabbitMQ is configured to accept tasks by verifying that I can run the task using the delay() method.\n\n```\n>>> dummy_task.delay()\n\n```\n\nResulting Log:\n\n2012-07-24T14:29:26+00:00 app[worker.1]: [2012-07-24 10:29:26,513: INFO/MainProcess] \n Got task from broker: events.tasks.dummy_task[1285ff04-bccc-46d9-9801-8bc9746abd1c]\n\n....\n\n2012-07-24T14:29:26+00:00 app[worker.1]: [2012-07-24 10:29:26,571: INFO/MainProcess] \n Task events.tasks.dummy_task[1285ff04-bccc-46d9-9801-8bc9746abd1c] \n succeeded in 0.0261888504028s: None\n\nAny help on this would be greatly appreciated. Thanks a lot!\n\n========================================\n\nCode:\n```text\n>>> dummy_task.apply_async(eta=datetime.datetime.now() + timedelta(seconds=60))\n<AsyncResult: 03001c1c-329e-46a3-8180-b115688e1865>\n```\n\n```text\n2012-07-24T14:03:08+00:00 app[scheduler.1]: [2012-07-24 10:03:08,909: INFO/MainProcess]\n Got task from broker: events.tasks.dummy_task[910ff406-d51c-4c29-bdd1-fec1a8168c12] \n eta:[2012-07-24 10:04:08.819528+00:00]\n```\n\n```text\n>>> dummy_task.delay()\n<AsyncResult: 1285ff04-bccc-46d9-9801-8bc9746abd1c>\n```\n\n```text\n2012-07-24T14:29:26+00:00 app[worker.1]: [2012-07-24 10:29:26,513: INFO/MainProcess] \n Got task from broker: events.tasks.dummy_task[1285ff04-bccc-46d9-9801-8bc9746abd1c]\n\n....\n\n2012-07-24T14:29:26+00:00 app[worker.1]: [2012-07-24 10:29:26,571: INFO/MainProcess] \n Task events.tasks.dummy_task[1285ff04-bccc-46d9-9801-8bc9746abd1c] \n succeeded in 0.0261888504028s: None\n```\n\n```text\nunacknowledged message count\n```\n\n========================================\n\nComments:\n- I'm having the same problem and this doesn't help. How do I handle tasks scheduled for a few minutes ahead? They seem to be executed on my local environment, but not in Heroku.\n- It could be due to a bug: github.com/celery/celery/issues/1151. I found that not setting CELERY_TIMEZONE worked","metadata":{"transformedAt":"2026-08-18T18:33:20.205Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":91,"estimatedTokens":775}}962{"id":"stack-23325743","source":"stackoverflow","questionId":23325743,"title":"purge rabbitmq queue using spring amqp template?","tags":["java","spring","rabbitmq","spring-batch","spring-amqp"],"text":"Title: purge rabbitmq queue using spring amqp template?\nTags: java, spring, rabbitmq, spring-batch, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI am adding messages to rabbitmq queue using spring amqp template in my spring batch item writer. \n\n```\npublic class AmqpAsynchRpcItemWriter implements ItemWriter {\n\n protected String exchange;\n protected String routingKey;\n protected String queue;\n protected String replyQueue;\n protected RabbitTemplate template;\n BlockingQueue blockingQueue;\n\n public void onMessage(Object msgContent) {\n\n try {\n blockingQueue.put(msgContent);\n } catch (InterruptedException e) {\n e.printStackTrace();\n }\n\n }\n\n @Override\n public void write(List items) throws Exception {\n\n for (T item : items) {\n\n Message message = MessageBuilder\n .withBody(item.toString().getBytes())\n .setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN)\n .setReplyTo(this.replyQueue)\n .setCorrelationId(item.toString().getBytes()).build();\n\n template.send(this.exchange, this.routingKey, message);\n\n }\n\n for (T item : items) {\n\n Object msg = blockingQueue.poll(60, TimeUnit.SECONDS);\n\n if (msg instanceof Exception) {\n throw (Exception) msg;\n } else if (msg == null) {\n System.out.println(\"reply timeout...\");\n break;\n } \n\n }\n }\n\n}\n```\n\nMessages are going to be processed on different remote servers. I am trying to handle the use case where if my message processing is failed (due to some exception) the step execution will be stopped. \n\nI want to purge all the remaining messages in that queue so that remaining messages in queue should not be consumed and processed as they will also be failed.\n\nIf the step is failed, my item writer will again queue all the messages, so I need to purge all remaining message on any exception. \n\nHow can I purge the queue using spring amqp ?\n\n========================================\n\nTop Answer:\nI would use RabbitAdmin instead\n\nhttp://docs.spring.io/autorepo/docs/spring-amqp-dist/1.3.4.RELEASE/api/org/springframework/amqp/rabbit/core/RabbitAdmin.html#purgeQueue%28java.lang.String,%20boolean%29\n\n@Autowired private RabbitAdmin admin;\n\n...\n\nadmin.purgeQueue(\"queueName\", false);\n\n========================================\n\nCode:\n```text\npublic class AmqpAsynchRpcItemWriter<T> implements ItemWriter<T> {\n\n protected String exchange;\n protected String routingKey;\n protected String queue;\n protected String replyQueue;\n protected RabbitTemplate template;\n BlockingQueue<Object> blockingQueue;\n\n\n public void onMessage(Object msgContent) {\n\n try {\n blockingQueue.put(msgContent);\n } catch (InterruptedException e) {\n e.printStackTrace();\n }\n\n\n }\n\n @Override\n public void write(List<? extends T> items) throws Exception {\n\n for (T item : items) {\n\n Message message = MessageBuilder\n .withBody(item.toString().getBytes())\n .setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN)\n .setReplyTo(this.replyQueue)\n .setCorrelationId(item.toString().getBytes()).build();\n\n template.send(this.exchange, this.routingKey, message);\n\n }\n\n for (T item : items) {\n\n Object msg = blockingQueue.poll(60, TimeUnit.SECONDS);\n\n if (msg instanceof Exception) {\n throw (Exception) msg;\n } else if (msg == null) {\n System.out.println(\"reply timeout...\");\n break;\n } \n\n }\n }\n\n}\n```\n\n```text\nAMQP.Queue.PurgeOk queuePurge(java.lang.String queue)\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.205Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":140,"estimatedTokens":891}}963{"id":"stack-28773527","source":"stackoverflow","questionId":28773527,"title":"Rabbitmq hello world connection only works on localhost (python)","tags":["python","rabbitmq"],"text":"Title: Rabbitmq hello world connection only works on localhost (python)\nTags: python, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have this simple code taken from the rabbitmq tutorial (http://www.rabbitmq.com/tutorials/tutorial-one-python.html)\n\n```\nimport pika\nimport logging\n\nlogging.basicConfig()\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost'))\n\nchannel = connection.channel()\n\nchannel.queue_declare(queue='hello')\n\nprint ' [*] Waiting for messages. To exit press CTRL+C'\n\ndef callback(ch, method, properties, body):\n print \" [x] Received %r\" % (body,)\n\nchannel.basic_consume(callback,\n queue='hello',\n no_ack=True)\n\nchannel.start_consuming()\n```\n\nIt works but if I change localhost with the ip of my computer from my own computer or a computer in the same network:\n\n```\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='192.168.60.126'))\n```\n\nI get this error:\n\n```\n>python rabbitMQReceiver.py\nERROR:pika.adapters.base_connection:Socket Error on fd 316: 10054\nTraceback (most recent call last):\n File \"rabbitMQReceiver.py\", line 7, in \n host='192.168.60.126'))\n File \"C:\\Python27\\lib\\site-packages\\pika\\adapters\\base_connection.py\", line 61, in __init__\n super(BaseConnection, self).__init__(parameters, on_open_callback)\n File \"C:\\Python27\\lib\\site-packages\\pika\\connection.py\", line 513, in __init__\n self._connect()\n File \"C:\\Python27\\lib\\site-packages\\pika\\connection.py\", line 804, in _connect\n self._adapter_connect()\n File \"C:\\Python27\\lib\\site-packages\\pika\\adapters\\blocking_connection.py\", line 146, in _adapter_connect\n self.process_data_events()\n File \"C:\\Python27\\lib\\site-packages\\pika\\adapters\\blocking_connection.py\", line 88, in process_data_events\n if self._handle_read():\n File \"C:\\Python27\\lib\\site-packages\\pika\\adapters\\blocking_connection.py\", line 184, in _handle_read\n super(BlockingConnection, self)._handle_read()\n File \"C:\\Python27\\lib\\site-packages\\pika\\adapters\\base_connection.py\", line 300, in _handle_read\n return self._handle_error(error)\n File \"C:\\Python27\\lib\\site-packages\\pika\\adapters\\base_connection.py\", line 264, in _handle_error\n self._handle_disconnect()\n File \"C:\\Python27\\lib\\site-packages\\pika\\adapters\\blocking_connection.py\", line 181, in _handle_disconnect\n self._on_connection_closed(None, True)\n File \"C:\\Python27\\lib\\site-packages\\pika\\adapters\\blocking_connection.py\", line 235, in _on_connection_closed\n raise exceptions.AMQPConnectionError(*self.closing)\npika.exceptions.AMQPConnectionError: (0, '')\n```\n\nI have no idea why, should I change something in the connection?\n\n========================================\n\nTop Answer:\nAs a up on @Gas response. \n\nBy default pika will connect using the default RabbitMQ credentials `guest/guest`. If you want to use your own credentials you need to provide your own `PlainCredentials` object.\n\n```\ncredentials = pika.PlainCredentials(username='my_user', password='password')\nconnection = \\\n pika.BlockingConnection(pika.ConnectionParameters(host='192.168.60.126',\n credentials=credentials))\n```\n\nOn the server you would need to add a user with the appropriate permissions. You can do this using the web interface, or by command line. More details available in the link provided by @Gas.\n\n```\nrabbitmqctl add_user my_user password\nrabbitmqctl set_permissions -p / my_user \".*\" \".*\" \".*\"\n```\n\nThese two command would give the user `my_user` all the permission it needs on virtual host `/`.\n\n========================================\n\nCode:\n```text\nimport pika\nimport logging\n\nlogging.basicConfig()\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost'))\n\nchannel = connection.channel()\n\nchannel.queue_declare(queue='hello')\n\nprint ' [*] Waiting for messages. To exit press CTRL+C'\n\ndef callback(ch, method, properties, body):\n print \" [x] Received %r\" % (body,)\n\nchannel.basic_consume(callback,\n queue='hello',\n no_ack=True)\n\nchannel.start_consuming()\n```\n\n```text\nconnection = pika.BlockingConnection(pika.ConnectionParameters(\n host='192.168.60.126'))\n```\n\n```text\n>python rabbitMQReceiver.py\nERROR:pika.adapters.base_connection:Socket Error on fd 316: 10054\nTraceback (most recent call last):\n File \"rabbitMQReceiver.py\", line 7, in <module>\n host='192.168.60.126'))\n File \"C:\\Python27\\lib\\site-packages\\pika\\adapters\\base_connection.py\", line 61, in __init__\n super(BaseConnection, self).__init__(parameters, on_open_callback)\n File \"C:\\Python27\\lib\\site-packages\\pika\\connection.py\", line 513, in __init__\n self._connect()\n File \"C:\\Python27\\lib\\site-packages\\pika\\connection.py\", line 804, in _connect\n self._adapter_connect()\n File \"C:\\Python27\\lib\\site-packages\\pika\\adapters\\blocking_connection.py\", line 146, in _adapter_connect\n self.process_data_events()\n File \"C:\\Python27\\lib\\site-packages\\pika\\adapters\\blocking_connection.py\", line 88, in process_data_events\n if self._handle_read():\n File \"C:\\Python27\\lib\\site-packages\\pika\\adapters\\blocking_connection.py\", line 184, in _handle_read\n super(BlockingConnection, self)._handle_read()\n File \"C:\\Python27\\lib\\site-packages\\pika\\adapters\\base_connection.py\", line 300, in _handle_read\n return self._handle_error(error)\n File \"C:\\Python27\\lib\\site-packages\\pika\\adapters\\base_connection.py\", line 264, in _handle_error\n self._handle_disconnect()\n File \"C:\\Python27\\lib\\site-packages\\pika\\adapters\\blocking_connection.py\", line 181, in _handle_disconnect\n self._on_connection_closed(None, True)\n File \"C:\\Python27\\lib\\site-packages\\pika\\adapters\\blocking_connection.py\", line 235, in _on_connection_closed\n raise exceptions.AMQPConnectionError(*self.closing)\npika.exceptions.AMQPConnectionError: (0, '')\n```\n\n```text\ncredentials = pika.PlainCredentials(username='my_user', password='password')\nconnection = \\\n pika.BlockingConnection(pika.ConnectionParameters(host='192.168.60.126',\n credentials=credentials))\n```\n\n```text\nrabbitmqctl add_user my_user password\nrabbitmqctl set_permissions -p / my_user \".*\" \".*\" \".*\"\n```\n\n```text\nguest/guest\n```\n\n```text\nPlainCredentials\n```\n\n```text\nmy_user\n```\n\n```text\n/\n```\n\n```text\n/usr/local/etc/rabbitmq/rabbitmq-env.conf\n```\n\n```text\nNODE_IP_ADDRESS=0.0.0.0\n```\n\n```text\nlocalhost\n```\n\n========================================\n\nComments:\n- Thanks @eanderson, I finally could set it up correctly.","metadata":{"transformedAt":"2026-08-18T18:33:20.205Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":201,"estimatedTokens":1610}}964{"id":"stack-30179322","source":"stackoverflow","questionId":30179322,"title":"Installing rabbitmq on centos7","tags":["rabbitmq"],"text":"Title: Installing rabbitmq on centos7\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am trying to install rabbotmq on centos7.\nFollowing the official instructions, I ran:\n\n```\nsudo yum install rabbitmq-server-3.5.1-1.noarch.rpm\n```\n\nand I get this error:\n\n```\nLoaded plugins: fastestmirror\nExamining rabbitmq-server-3.5.1-1.noarch.rpm: rabbitmq-server-3.5.1-1.noarch\nMarking rabbitmq-server-3.5.1-1.noarch.rpm to be installed\nResolving Dependencies\n--> Running transaction check\n---> Package rabbitmq-server.noarch 0:3.5.1-1 will be installed\n--> Processing Dependency: erlang >= R13B-03 for package: rabbitmq-server-3.5.1-1.noarch\nhttp://repos.fedorapeople.org/repos/peter/erlang/epel-7/x86_64/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found\nTrying other mirror.\nLoading mirror speeds from cached hostfile\n * base: centos.mirrors.hoobly.com\n * extras: linux.mirrors.es.net\n * updates: mirror.pac-12.org\n--> Finished Dependency Resolution\nError: Package: rabbitmq-server-3.5.1-1.noarch (/rabbitmq-server-3.5.1-1.noarch)\n Requires: erlang >= R13B-03\n You could try using --skip-broken to work around the problem\n You could try running: rpm -Va --nofiles --nodigest\n```\n\nthen I tried installing erlang with the instructions from:\nInstalling rabbitmq-server on RHEL\n\nIt seemed to have been installed, but my rabbitmq installation still fails with the same message.\nAny ideas how to fix the problem?\n\n========================================\n\nTop Answer:\nFollowing the instruction lead me to error: `No package rabbitmq-server-3.6.1-1.noarch.rpm available.` \n\nThen I simply tried: `yum install rabbitmq-server`, it works for me.\n\nOr checkout this one: Rabbitmq at Digitalocean - I used to config web monitoring on my server.\n\n========================================\n\nCode:\n```text\nsudo yum install rabbitmq-server-3.5.1-1.noarch.rpm\n```\n\n```text\nLoaded plugins: fastestmirror\nExamining rabbitmq-server-3.5.1-1.noarch.rpm: rabbitmq-server-3.5.1-1.noarch\nMarking rabbitmq-server-3.5.1-1.noarch.rpm to be installed\nResolving Dependencies\n--> Running transaction check\n---> Package rabbitmq-server.noarch 0:3.5.1-1 will be installed\n--> Processing Dependency: erlang >= R13B-03 for package: rabbitmq-server-3.5.1-1.noarch\nhttp://repos.fedorapeople.org/repos/peter/erlang/epel-7/x86_64/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found\nTrying other mirror.\nLoading mirror speeds from cached hostfile\n * base: centos.mirrors.hoobly.com\n * extras: linux.mirrors.es.net\n * updates: mirror.pac-12.org\n--> Finished Dependency Resolution\nError: Package: rabbitmq-server-3.5.1-1.noarch (/rabbitmq-server-3.5.1-1.noarch)\n Requires: erlang >= R13B-03\n You could try using --skip-broken to work around the problem\n You could try running: rpm -Va --nofiles --nodigest\n```\n\n```text\nNo package rabbitmq-server-3.6.1-1.noarch.rpm available.\n```\n\n```text\nyum install rabbitmq-server\n```\n\n```text\n- name: install epel-release\n yum: name=epel-release state=latest\n tags: erlang\n\n- name: install erlang from EPEL\n yum: name=erlang state=latest\n tags: erlang\n\n- name: install new rabbitmq\n yum: name=https://www.rabbitmq.com/releases/rabbitmq-server/v3.5.6/rabbitmq-server-3.5.6-1.noarch.rpm state=present\n```\n\n```text\ncurl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | sudo bash\nsudo yum clean all\nsudo yum makecache\nsudo yum install erlang -y\ncurl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | sudo bash\nsudo yum install rabbitmq-server -y\nrpm -qi rabbitmq-server\nsystemctl start rabbitmq-server\nsudo systemctl enable rabbitmq-server\nsudo systemctl status rabbitmq-server\n```\n\n========================================\n\nComments:\n- YES. Thanks. I had to install their version of erlang.","metadata":{"transformedAt":"2026-08-18T18:33:20.205Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":116,"estimatedTokens":945}}965{"id":"stack-42964642","source":"stackoverflow","questionId":42964642,"title":"celery one broker multiple queues and workers","tags":["python","rabbitmq","celery"],"text":"Title: celery one broker multiple queues and workers\nTags: python, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI have a python file called `tasks.py` in which I am defining 4 single tasks. I would like to configure celery in order to use 4 queues because each queue would have a different number of workers assigned. I was reading I should use **route_task** property but I tried several options and not a success. \n\nI was following this doc celery route_tasks docs\n\nMy goal would be run 4 workers, one for each task, and don't mix tasks from different workers in different queues. It's possible? It's a good approach?\n\nIf I am doing something wrong I would be happy to change my code to make it work\n\nHere is my config so far\n\ntasks.py\n\n```\napp = Celery('tasks', broker='pyamqp://guest@localhost//')\napp.conf.task_default_queue = 'default'\napp.conf.task_queues = (\n Queue('queueA', routing_key='tasks.task_1'),\n Queue('queueB', routing_key='tasks.task_2'),\n Queue('queueC', routing_key='tasks.task_3'),\n Queue('queueD', routing_key='tasks.task_4')\n)\n\n@app.task\ndef task_1():\n print \"Task of level 1\"\n\n@app.task\ndef task_2():\n print \"Task of level 2\"\n\n@app.task\ndef task_3():\n print \"Task of level 3\"\n\n@app.task\ndef task_4():\n print \"Task of level 4\"\n```\n\nRun celery one worker for each queue\n\n```\ncelery -A tasks worker --loglevel=debug -Q queueA --logfile=celery-A.log -n W1&\ncelery -A tasks worker --loglevel=debug -Q queueB --logfile=celery-B.log -n W2&\ncelery -A tasks worker --loglevel=debug -Q queueC --logfile=celery-C.log -n W3&\ncelery -A tasks worker --loglevel=debug -Q queueD --logfile=celery-D.log -n W4&\n```\n\n========================================\n\nTop Answer:\nNote: `task` and `message` are used interchangeably in the answer. It is basically a payload that the `producer` sends to RabbitMQ\n\nYou can either approach suggested by Chillar or you can define and use the `task_routes` configuration to route the messages to appropriate queue. This way you don't need to specify queue name every time you call `apply_async`.\n\nExample: Route **task1** to `QueueA` and route **task2** to `QueueB`\n\n```\napp = Celery('my_app')\napp.conf.update(\n task_routes={\n 'task1': {'queue': 'QueueA'},\n 'task2': {'queue': 'QueueB'}\n }\n)\n```\n\nSending a task to multiple queue is a bit tricky. You will have to declare an exchange, and then route your task with appropriate `routing_key`. You can get more information about type of exchange here. Let's go with `direct` for purpose of illustration.\n\nCreate Exchange\n\n```\nfrom kombu import Exchange, Queue, binding\nexchange_for_queueA_and_B = Exchange('exchange_for_queueA_and_B', type='direct')\n```\n\nCreate bindings on Queues to that exchange \n\n```\napp.conf.update(\n task_queues=(\n Queue('QueueA', [\n binding(exchange_for_queueA_and_B, routing_key='queue_a_and_b')\n ]),\n Queue('QueueB', [\n binding(exchange_for_queueA_and_B, routing_key='queue_a_and_b')\n ])\n )\n)\n```\n\nDefine the `task_route` to send **task1** to the exchange\n\n```\napp.conf.update(\n task_routes={\n 'task1': {'exchange': 'exchange_for_queueA_and_B', 'routing_key': 'queue_a_and_b'}\n }\n)\n```\n\nYou can also declare these options of `exchange` and `routing_key` in your `apply_async` method as suggested by Chillar in the above answer.\n\nAfter that, you can define your workers on same machine or different machines, to consume from those queues.\n\n```\ncelery -A my_app worker -n consume_from_QueueA_and_QueueB -Q QueueA,QueueB\ncelery -A my_app worker -n consume_from_QueueA_only -Q QueueA\n```\n\n========================================\n\nCode:\n```text\napp = Celery('tasks', broker='pyamqp://guest@localhost//')\napp.conf.task_default_queue = 'default'\napp.conf.task_queues = (\n Queue('queueA', routing_key='tasks.task_1'),\n Queue('queueB', routing_key='tasks.task_2'),\n Queue('queueC', routing_key='tasks.task_3'),\n Queue('queueD', routing_key='tasks.task_4')\n)\n\n\n@app.task\ndef task_1():\n print \"Task of level 1\"\n\n\n@app.task\ndef task_2():\n print \"Task of level 2\"\n\n\n@app.task\ndef task_3():\n print \"Task of level 3\"\n\n\n@app.task\ndef task_4():\n print \"Task of level 4\"\n```\n\n```text\ncelery -A tasks worker --loglevel=debug -Q queueA --logfile=celery-A.log -n W1&\ncelery -A tasks worker --loglevel=debug -Q queueB --logfile=celery-B.log -n W2&\ncelery -A tasks worker --loglevel=debug -Q queueC --logfile=celery-C.log -n W3&\ncelery -A tasks worker --loglevel=debug -Q queueD --logfile=celery-D.log -n W4&\n```\n\n```text\ntasks.py\n```\n\n```text\nfrom celery import celery\n\napp = Celery('tasks', broker='pyamqp://guest@localhost//')\n\n@app.task\ndef task_1():\n print \"Task of level 1\"\n\n\n@app.task\ndef task_2():\n print \"Task of level 2\"\n```\n\n```text\nIn [12]: from tasks import *\n\nIn [14]: result = task_1.apply_async(queue='queueA')\n\nIn [15]: result = task_2.apply_async(queue='queueB')\n```\n\n```text\ncelery -A tasks worker --loglevel=debug -Q queueA --logfile=celery-A.log -n W1&\ncelery -A tasks worker --loglevel=debug -Q queueB --logfile=celery-B.log -n W2&\n```\n\n```text\ntask_1\n```\n\n```text\nqueueA\n```\n\n```text\ntask_2\n```\n\n```text\nqueueB\n```\n\n```text\napp = Celery('my_app')\napp.conf.update(\n task_routes={\n 'task1': {'queue': 'QueueA'},\n 'task2': {'queue': 'QueueB'}\n }\n)\n```\n\n```text\nfrom kombu import Exchange, Queue, binding\nexchange_for_queueA_and_B = Exchange('exchange_for_queueA_and_B', type='direct')\n```\n\n```text\napp.conf.update(\n task_queues=(\n Queue('QueueA', [\n binding(exchange_for_queueA_and_B, routing_key='queue_a_and_b')\n ]),\n Queue('QueueB', [\n binding(exchange_for_queueA_and_B, routing_key='queue_a_and_b')\n ])\n )\n)\n```\n\n```text\napp.conf.update(\n task_routes={\n 'task1': {'exchange': 'exchange_for_queueA_and_B', 'routing_key': 'queue_a_and_b'}\n }\n)\n```\n\n```text\ncelery -A my_app worker -n consume_from_QueueA_and_QueueB -Q QueueA,QueueB\ncelery -A my_app worker -n consume_from_QueueA_only -Q QueueA\n```\n\n```text\ntask\n```\n\n```text\nmessage\n```\n\n```text\nproducer\n```\n\n```text\ntask_routes\n```\n\n```text\napply_async\n```\n\n```text\nQueueA\n```\n\n```text\nQueueB\n```\n\n```text\nrouting_key\n```\n\n```text\ndirect\n```\n\n```text\ntask_route\n```\n\n```text\nexchange\n```\n\n```text\nrouting_key\n```\n\n```text\napply_async\n```\n\n========================================\n\nComments:\n- Basically my problem was, a confusion with the documentation, I was using 3.x version and was using documentation of 4.x...epic fail","metadata":{"transformedAt":"2026-08-18T18:33:20.205Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":28,"totalLines":301,"estimatedTokens":1608}}966{"id":"stack-38207302","source":"stackoverflow","questionId":38207302,"title":"How to setup Elixir project to use RabbitMQ via amqp?","tags":["linux","rabbitmq","phoenix-framework","elixir"],"text":"Title: How to setup Elixir project to use RabbitMQ via amqp?\nTags: linux, rabbitmq, phoenix-framework, elixir\nSource: Stack Overflow\n\nQuestion:\nI want to use rabbitMQ from my elixir phoenix app via amqp. I followed tutorial on official website but still during `mix.deps compile`, I get an error:\n\n```\ninclude/amqp_gen_consumer_spec.hrl:30: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:31: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:32: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:34: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:35: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:36: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:37: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:38: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:39: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:42: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:30: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:31: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:32: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:34: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:35: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:36: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:37: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:38: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:39: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:42: syntax error before: '/'\nCompiling src/amqp_selective_consumer.erl failed:\nERROR: compile failed while processing /home/bmarkons/soc2016-marko/telegram/deps/amqp_client: rebar_abort\n** (Mix) Could not compile dependency :amqp_client, \"/usr/bin/rebar compile skip_deps=true deps_dir=\"/home/bmarkons/soc2016-marko/telegram/_build/dev/lib\"\" command failed. You can recompile this dependency with \"mix deps.compile amqp_client\", update it with \"mix deps.update amqp_client\" or clean it with \"mix deps.clean amqp_client\"\n```\n\nTerminal screenshot\n\nI added only :amqp and {:amqp, \"~> 0.1.4\"}, in mix.exs file:\n\n```\ndef application do\n [mod: {App, []},\n applications: [:phoenix, :phoenix_pubsub, :phoenix_html, :cowboy, :logger, :gettext,\n :phoenix_ecto, :postgrex, :amqp]]\nend\n\ndefp deps do\n [{:phoenix, \"~> 1.2.0\"},\n {:phoenix_pubsub, \"~> 1.0\"},\n {:phoenix_ecto, \"~> 3.0\"},\n {:postgrex, \">= 0.0.0\"},\n {:phoenix_html, \"~> 2.6\"},\n {:phoenix_live_reload, \"~> 1.0\", only: :dev},\n {:gettext, \"~> 0.11\"},\n {:cowboy, \"~> 1.0\"},\n {:amqp, \"~> 0.1.4\"}]\nend\n```\n\nWhat changes I need to make, to have my elixir app work with rabbitMQ?\n\nThank you\n\n========================================\n\nTop Answer:\nI had to define the dependency as follows (branch information) to get it to run:\n\n```\ndefp deps do\n[\n {:amqp_client, git: \"https://github.com/dsrosario/amqp_client.git\", branch: \"erlang_otp_19\", override: true},\n {:amqp, \"~> 0.1.4\"}\n]\n```\n\nend\n\n========================================\n\nCode:\n```text\ninclude/amqp_gen_consumer_spec.hrl:30: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:31: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:32: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:34: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:35: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:36: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:37: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:38: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:39: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:42: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:30: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:31: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:32: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:34: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:35: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:36: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:37: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:38: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:39: syntax error before: '/'\ninclude/amqp_gen_consumer_spec.hrl:42: syntax error before: '/'\nCompiling src/amqp_selective_consumer.erl failed:\nERROR: compile failed while processing /home/bmarkons/soc2016-marko/telegram/deps/amqp_client: rebar_abort\n** (Mix) Could not compile dependency :amqp_client, \"/usr/bin/rebar compile skip_deps=true deps_dir=\"/home/bmarkons/soc2016-marko/telegram/_build/dev/lib\"\" command failed. You can recompile this dependency with \"mix deps.compile amqp_client\", update it with \"mix deps.update amqp_client\" or clean it with \"mix deps.clean amqp_client\"\n```\n\n```text\ndef application do\n [mod: {App, []},\n applications: [:phoenix, :phoenix_pubsub, :phoenix_html, :cowboy, :logger, :gettext,\n :phoenix_ecto, :postgrex, :amqp]]\nend\n\ndefp deps do\n [{:phoenix, \"~> 1.2.0\"},\n {:phoenix_pubsub, \"~> 1.0\"},\n {:phoenix_ecto, \"~> 3.0\"},\n {:postgrex, \">= 0.0.0\"},\n {:phoenix_html, \"~> 2.6\"},\n {:phoenix_live_reload, \"~> 1.0\", only: :dev},\n {:gettext, \"~> 0.11\"},\n {:cowboy, \"~> 1.0\"},\n {:amqp, \"~> 0.1.4\"}]\nend\n```\n\n```text\nmix.deps compile\n```\n\n```text\ndef deps do\n [{:amqp_client, git: \"https://github.com/jbrisbin/amqp_client.git\", override: true},\n {:amqp, \"~> 0.1.4\"}]\nend\n```\n\n```text\ndefp deps do\n [{:phoenix, \"~> 1.2.0\"},\n {:phoenix_pubsub, \"~> 1.0\"},\n {:phoenix_ecto, \"~> 3.0\"},\n {:postgrex, \">= 0.0.0\"},\n {:phoenix_html, \"~> 2.6\"},\n {:phoenix_live_reload, \"~> 1.0\", only: :dev},\n {:gettext, \"~> 0.11\"},\n {:cowboy, \"~> 1.0\"},\n {:amqp_client, git: \"https://github.com/jbrisbin/amqp_client.git\", override: true},\n {:amqp, \"~> 0.1.4\"]\nend\n```\n\n```text\n:amqp\n```\n\n```text\n:amqp_client\n```\n\n```text\nAMQP\n```\n\n```text\n:amqp_client\n```\n\n```text\nAMQP\n```\n\n```text\n:amqp_client\n```\n\n```text\nAMQP\n```\n\n```text\ndefp deps do\n[\n {:amqp_client, git: \"https://github.com/dsrosario/amqp_client.git\", branch: \"erlang_otp_19\", override: true},\n {:amqp, \"~> 0.1.4\"}\n]\n```\n\n========================================\n\nComments:\n- Well, that's odd. Have you tried to clean your dependencies? `mix deps.clean --all` and then `mix deps.get` and `mix deps.compile`. Also, which version of Elixir are you using?\n- I am using Elixir 1.3.1. I tried that also but still getting an error.\n- What's the Erlang version?\n- Running erl -eval 'erlang:display(erlang:system_info(otp_release)), halt().' -noshell gives me '19'.\n- Yeah, I think there's a bug in Erlang 19. I have seen a similar problem before, but with other repository github.com/processone/ejabberd/issues/1168. I have Erlang 18 in my machine and it can compile `:amqp` without problems, so I suggest you try that as well.\n- Thank you very much, I just got the same answer on rabbitmq-users google group. Cheers :)\n- I recently updated erlang and getting this error. I followed your steps and it compiled. However, there was a small change that I had to do - I had to change {:amqp, github: \"/amqp\"} to {:amqp_client, github: \"/amqp\"} and :amqp in applications to :amqp_clients. But now it is giving this error : module AMQP is not loaded and could not be found [on this line - use AMQP ] Can you tell me what could be the reason and how to resolve this?\n- @KshitijMittal I updated the workaround for one that is currently working for me. Hope this helps :)","metadata":{"transformedAt":"2026-08-18T18:33:20.205Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":13,"totalLines":198,"estimatedTokens":1882}}967{"id":"stack-27039359","source":"stackoverflow","questionId":27039359,"title":"How to receive single message from the queue in RabbitMQ using C#","tags":["c#","rabbitmq"],"text":"Title: How to receive single message from the queue in RabbitMQ using C#\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI would like to know how I can receive only one message at a time\nthis is basic code for that\n\n```\nvar factory = new ConnectionFactory() { HostName = \"localhost\" };\nvar connection = factory.CreateConnection()\nvar channel = connection.CreateModel()\nchannel.QueueDeclare(\"hello\", false, false, false, null);\nvar consumer = new QueueingBasicConsumer(channel);\nchannel.BasicConsume(\"hello\", true, consumer);\n\nBasicDeliverEventArgs ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();\nvar body = ea.Body;\nvar message = Encoding.UTF8.GetString(body);\nResponse.Write(message + \" Received.\");\n```\n\n========================================\n\nTop Answer:\nComplementing the last message if you need the text from the message you need to convert:\n\n```\nvar data = channel.BasicGet(QueueName, true);\nvar message = System.Text.Encoding.UTF8.GetString(data.Body);\n```\n\n========================================\n\nCode:\n```text\nvar factory = new ConnectionFactory() { HostName = \"localhost\" };\nvar connection = factory.CreateConnection()\nvar channel = connection.CreateModel()\nchannel.QueueDeclare(\"hello\", false, false, false, null);\nvar consumer = new QueueingBasicConsumer(channel);\nchannel.BasicConsume(\"hello\", true, consumer);\n\nBasicDeliverEventArgs ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();\nvar body = ea.Body;\nvar message = Encoding.UTF8.GetString(body);\nResponse.Write(message + \" Received.\");\n```\n\n```text\nvar data = channel.BasicGet(queueName, true);\n```\n\n```text\nchannel.BasicConsume\n```\n\n```text\nchannel.BasicGet\n```\n\n```text\nvar data = channel.BasicGet(QueueName, true);\nvar message = System.Text.Encoding.UTF8.GetString(data.Body);\n```\n\n```text\nconst open = require('amqplib').connect('amqp://admin:password@172.17.0.1:5672?heartbeat:30')\nopen\n .then(conn => conn.createChannel())\n .then(async channel => {\n console.log('channel created')\n const msg = await channel.get('myQueue')\n if (msg) {\n console.log(msg.content.toString())\n channel.ack(msg)\n }\n })\n .catch(console.warn)\n```\n\n```text\nchannel.BasicGet\n```\n\n```text\nchannel.get\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.205Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":88,"estimatedTokens":549}}968{"id":"stack-7292935","source":"stackoverflow","questionId":7292935,"title":"celery+rabbitmq empty queue","tags":["rabbitmq","celery"],"text":"Title: celery+rabbitmq empty queue\nTags: rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI am using celery+rabbitmq. I can't find convenient way to clear queue in celery+rabbitmq. I do it with remove and create vhost.\n\n```\nrabbitmqctl delete_vhost \nrabbitmqctl add_vhost \n```\n\nIs it prefer way to clear some celery queue ?\n\n========================================\n\nTop Answer:\nIf you are facing this problem because you used rabbitmq for the result backend and as a result you got too many queues, then i would suggest using a different result backend (redis or mongodb)\n\nThis is one well known flaw with the celery. It will create a separate queue for each result if you amqp for result backend.\n\nIf you still want to stick to amqp as result backend. It will clear itself in 24 hours. You can however set it to a smaller value using `CELERY_AMQP_TASK_RESULT_EXPIRES` setting.\n\n========================================\n\nCode:\n```text\nrabbitmqctl delete_vhost <vhostpath>\nrabbitmqctl add_vhost <vhostpath>\n```\n\n```text\nfrom amqplib import client_0_8 as amqp\n\nconn = amqp.Connection(host=\"localhost:5672\", userid=\"guest\", password=\"guest\", virtual_host=\"/\", insist=False)\nconn = conn.channel()\nconn.queue_purge(\"the-target-queue\")\n```\n\n```text\nsudo rabbitmqctl list_queues -p /yourvhost name > queues.txt\n```\n\n```text\nfrom amqplib import client_0_8 as amqp\n\nconn = amqp.Connection(host=\"127.0.0.1:5672\", userid=\"guest\", password=\"guest\", virtual_host=\"/yourvhost\", insist=False)\nconn = conn.channel()\n\nqueues = None\nwith open('queues.txt', 'r') as f:\n queues = f.readlines()\n\nfor q in queues:\n if q:\n #print 'deleting %s' % q\n conn.queue_purge(q.strip())\n\nprint 'purged %d items' % len(queues)\n```\n\n```text\nCELERY_AMQP_TASK_RESULT_EXPIRES\n```\n\n========================================\n\nComments:\n- conn.queue_purge doesn't work for me. Is that an amqplib method?\n- Yes. Check the docs and this tutorial: blogs.digitar.com/jjww/2009/01/rabbits-and-warrens","metadata":{"transformedAt":"2026-08-18T18:33:20.205Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":70,"estimatedTokens":495}}969{"id":"stack-51480807","source":"stackoverflow","questionId":51480807,"title":"How to test celery with django on a windows machine","tags":["django","django-models","redis","rabbitmq","celery"],"text":"Title: How to test celery with django on a windows machine\nTags: django, django-models, redis, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI'm looking for a resource, documentation or advise on how to test django celery on my windows machine before deploying on a Linux based server.\n\nAny useful Answer would be appreciated and accepted.\n\n========================================\n\nTop Answer:\nThere are two workarounds to make Celery work (natively) on Windows - and therefore be able to test it as if it were on Linux.\n\n- use eventlet, gevent or solo concurrency pool (if your tasks as I/O and not CPU-bound)\n\n- set the environment variable FORKED_BY_MULTIPROCESS=1 (this is what actually causes the underlying billiard package to to fail under Windows since version 4)\n\nhttps://www.distributedpython.com/2018/08/21/celery-4-windows/\n\n========================================\n\nCode:\n```text\ntask_always_eager=True\n```\n\n```text\npip install celery==5.0.5\n```\n\n========================================\n\nComments:\n- As I know U can use Celery with only WSLv2... Or not?\n- It's not officially supported, but you can run Celery natively on Windows (so no WSL, Docker, etc.). Tested with the latest version 4.4.x.","metadata":{"transformedAt":"2026-08-18T18:33:20.205Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":36,"estimatedTokens":304}}970{"id":"stack-33702564","source":"stackoverflow","questionId":33702564,"title":"RabbitMQ consumer as a windows service","tags":[".net","windows-services","rabbitmq","mongodb-.net-driver"],"text":"Title: RabbitMQ consumer as a windows service\nTags: .net, windows-services, rabbitmq, mongodb-.net-driver\nSource: Stack Overflow\n\nQuestion:\nI have a rabbitmq consumer application implementing \"publish/subscribe pattern in .net, which runs perfectly as a console application but when I deploy that as a windows service it does not seem to be saving the data into mongodb.\n\n```\nprotected override void OnStart(string[] args)\n {\n try\n {\n var connectionString = \"mongodb://localhost\";\n var client = new MongoClient(connectionString);\n var factory = new ConnectionFactory() { HostName = \"localhost\" }; \n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n channel.ExchangeDeclare(exchange: \"test\", type: \"fanout\");\n var queueName = channel.QueueDeclare().QueueName;\n channel.QueueBind(queue: queueName, exchange: \"logs\", routingKey: \"\");\n\n var consumer = new EventingBasicConsumer(channel);\n consumer.Received += (model, ea) =>\n {\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n BsonDocument document = BsonDocument.Parse(message);\n var database = client.GetDatabase(\"test\");\n var collection = database.GetCollection(\"test_collection\");\n collection.InsertOneAsync(document);\n };\n channel.BasicConsume(queue: queueName, noAck: true,consumer: consumer);\n\n }\n }\n }\n catch (Exception ex)\n {\n throw;\n }\n }\n```\n\nIs there something that I'm missing?\n\n========================================\n\nTop Answer:\nToday we need made RabbitMQ consumer as a windows service and solve with Timer in method OnStart.\n\n```\nprivate Timer _timer;\n\nprotected override void OnStart(string[] args)\n\n{\n _timer = new Timer();\n _timer.Interval = 5000; \n _timer.Elapsed += new ElapsedEventHandler(this.OnTimer);\n _timer.Start();\n}\n\npublic void OnTimer(object sender, System.Timers.ElapsedEventArgs args)\n{\n _timer.Enabled = false;\n\n ...\n}\n```\n\nMany thanks for the help and hope to have helped with this solution too\n\n========================================\n\nCode:\n```text\nprotected override void OnStart(string[] args)\n {\n try\n {\n var connectionString = \"mongodb://localhost\";\n var client = new MongoClient(connectionString);\n var factory = new ConnectionFactory() { HostName = \"localhost\" }; \n using (var connection = factory.CreateConnection())\n {\n using (var channel = connection.CreateModel())\n {\n channel.ExchangeDeclare(exchange: \"test\", type: \"fanout\");\n var queueName = channel.QueueDeclare().QueueName;\n channel.QueueBind(queue: queueName, exchange: \"logs\", routingKey: \"\");\n\n var consumer = new EventingBasicConsumer(channel);\n consumer.Received += (model, ea) =>\n {\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n BsonDocument document = BsonDocument.Parse(message);\n var database = client.GetDatabase(\"test\");\n var collection = database.GetCollection<BsonDocument>(\"test_collection\");\n collection.InsertOneAsync(document);\n };\n channel.BasicConsume(queue: queueName, noAck: true,consumer: consumer);\n\n }\n }\n }\n catch (Exception ex)\n {\n throw;\n }\n }\n```\n\n```text\nprotected override void OnStart(string[] args)\n {\n\n ConnectionFactory factory = new ConnectionFactory { HostName = localhost\" };\n var connectionString = \"mongodb://localhost\";\n var client = new MongoClient(connectionString);\n\n\n using (IConnection connection = factory.CreateConnection())\n {\n using (IModel channel = connection.CreateModel())\n {\n channel.ExchangeDeclare(exchange: \"test\", type: \"fanout\");\n\n string queueName = channel.QueueDeclare();\n\n channel.QueueBind(queueName, \"test\", \"\");\n\n this.EventLog.WriteEntry(\"Waiting for messages\");\n\n QueueingBasicConsumer consumer = new QueueingBasicConsumer(channel);\n channel.BasicConsume(queueName, true, consumer);\n\n while (true)\n {\n BasicDeliverEventArgs e = (BasicDeliverEventArgs)consumer.Queue.Dequeue();\n var message = Encoding.UTF8.GetString(e.Body);\n BsonDocument document = BsonDocument.Parse(message);\n var database = client.GetDatabase(\"test\");\n var collection = database.GetCollection<BsonDocument>(\"test_collection\");\n collection.InsertOneAsync(document);\n\n }\n }\n }\n }\n```\n\n```text\nprivate Timer _timer;\n\nprotected override void OnStart(string[] args)\n\n{\n _timer = new Timer();\n _timer.Interval = 5000; \n _timer.Elapsed += new ElapsedEventHandler(this.OnTimer);\n _timer.Start();\n}\n\npublic void OnTimer(object sender, System.Timers.ElapsedEventArgs args)\n{\n _timer.Enabled = false;\n\n ...\n}\n```\n\n========================================\n\nComments:\n- Did you check the logs?\n- You aren't waiting for the result of the InsertOneAsync... anything could be happening and you'll never know... using collection.InsertOneAsync(document).GetAwaiter().GetResult()‌​;\n- @Gabriele I did try logging to see if the message is actually being received. But doesnt look like it.\n- @CraigWilson It doesn't even any messages to dump into mongoDB to begin with. Also, to verify I checked the logs of mongoDB. There is no data that is being dumped to it from this service\n- How does this service handle stopping? I.e. will it ever stop? Won't it be necessary to kill it since a) there is no condition on the while loop, and b) is the call to consumer.Queue.Dequeue() not blocking?\n- Your OnStart service never returns. If you'd like to perform work like this, start up another Thread in OnStart and then return from the OnStart method.","metadata":{"transformedAt":"2026-08-18T18:33:20.205Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":183,"estimatedTokens":1556}}971{"id":"stack-35192930","source":"stackoverflow","questionId":35192930,"title":"Unable to send a dictionary to RabbitMQ (unhashable type: 'slice')","tags":["python","python-3.x","dictionary","rabbitmq"],"text":"Title: Unable to send a dictionary to RabbitMQ (unhashable type: 'slice')\nTags: python, python-3.x, dictionary, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI want to send a messge to RabbitMQ in a dictionary format:\n\n```\nimport pika\n\n# ....\nmy_msg = {}\nmy_msg[\"a\"] = 1\nmy_msg[\"a\"][\"b\"] = 2\nchannel.basic_publish(exchange=\"\", routing_key=\"some_key\", body=my_msg)\n```\n\nAnd an error I get:\n\n```\nTypeError: unhashable type: 'slice'\n```\n\nNote that I have plenty of `my_msg` and each of them has a few keys, so I need somehow to be able to send a list dictionaries to RabbitMQ. \n\nHow can I do that? Or are there other options?\n\n========================================\n\nTop Answer:\nAccording to the documentation, `body` should be a string.\n\nYou might try `body=json.dumps(my_msg)`\n\n========================================\n\nCode:\n```text\nimport pika\n\n# ....\nmy_msg = {}\nmy_msg[\"a\"] = 1\nmy_msg[\"a\"][\"b\"] = 2\nchannel.basic_publish(exchange=\"\", routing_key=\"some_key\", body=my_msg)\n```\n\n```text\nTypeError: unhashable type: 'slice'\n```\n\n```text\nmy_msg\n```\n\n```text\nbody\n```\n\n```text\nbody=json.dumps(my_msg)\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.205Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":62,"estimatedTokens":275}}972{"id":"stack-37214404","source":"stackoverflow","questionId":37214404,"title":"Using Kombu ConsumerMixin, how to declare multiple bindings?","tags":["python","rabbitmq","amqp","kombu"],"text":"Title: Using Kombu ConsumerMixin, how to declare multiple bindings?\nTags: python, rabbitmq, amqp, kombu\nSource: Stack Overflow\n\nQuestion:\nI have a RabbitMQ topic exchange named `experiment`. I'm building a consumer where I'd like to receive all messages whose routing key begins with \"foo\" and all messages whose routing key begins with \"bar\".\n\nAccording to the RabbitMQ docs, and based on my own experimentation in the management UI, it should be possible to have one exchange, one queue, and two bindings (`foo.#` and `bar.#`) that connect them.\n\nI can't figure out how to express this using Kombu's ConsumerMixin. I feel like I should be able to do:\n\n```\nq = Queue(exchange=exchange, routing_key=['foo.#', 'bar.#'])\n```\n\n...but it does not like that at all. I've also tried:\n\n```\nq.bind_to(exchange=exchange, routing_key='foo.#')\nq.bind_to(exchange=exchange, routing_key='bar.#')\n```\n\n...but every time I try I get:\n\n```\nkombu.exceptions.NotBoundError: Can't call method on Queue not bound to a channel\n```\n\n...which I guess manes sense. However I can't see a place in the mixin's interface where I can easily hook onto the queues once they are bound to the channel. Here's the base (working) code:\n\n```\nfrom kombu import Connection, Exchange, Queue\nfrom kombu.mixins import ConsumerMixin\n\nclass Worker(ConsumerMixin):\n exchange = Exchange('experiment', type='topic')\n q = Queue(exchange=exchange, routing_key='foo.#', exclusive=True)\n\n def __init__(self, connection):\n self.connection = connection\n\n def get_consumers(self, Consumer, channel):\n return [Consumer(queues=[self.q], callbacks=[self.on_task])]\n\n def on_task(self, body, message):\n print body\n message.ack()\n\nif __name__ == '__main__':\n with Connection('amqp://guest:guest@localhost:5672//') as conn:\n worker = Worker(conn)\n worker.run()\n```\n\n...which works, but only gives me `foo` messages. Other than creating a new Queue for each routing key I'm interested in and passing them all to the Consumer, is there a clean way to do this?\n\n========================================\n\nTop Answer:\nHere is a small adjustment of the answer by smitelli. When the `bindings` parameter is used for defining bindings, the `exchange` parameter is ignored.\n\nAdjusted example:\n\n```\nfrom kombu import Exchange, Queue, binding\n\nexchange = Exchange('experiment', type='topic')\nq = Queue(bindings=[\n binding(exchange, routing_key='foo.#'),\n binding(exchange, routing_key='bar.#'),\n])\n```\n\nThe `exchange` parameter is discarded during the Queue init:\n\n```\nif self.bindings:\n self.exchange = None\n```\n\n========================================\n\nCode:\n```text\nq = Queue(exchange=exchange, routing_key=['foo.#', 'bar.#'])\n```\n\n```text\nq.bind_to(exchange=exchange, routing_key='foo.#')\nq.bind_to(exchange=exchange, routing_key='bar.#')\n```\n\n```text\nkombu.exceptions.NotBoundError: Can't call method on Queue not bound to a channel\n```\n\n```text\nfrom kombu import Connection, Exchange, Queue\nfrom kombu.mixins import ConsumerMixin\n\n\nclass Worker(ConsumerMixin):\n exchange = Exchange('experiment', type='topic')\n q = Queue(exchange=exchange, routing_key='foo.#', exclusive=True)\n\n def __init__(self, connection):\n self.connection = connection\n\n def get_consumers(self, Consumer, channel):\n return [Consumer(queues=[self.q], callbacks=[self.on_task])]\n\n def on_task(self, body, message):\n print body\n message.ack()\n\n\nif __name__ == '__main__':\n with Connection('amqp://guest:guest@localhost:5672//') as conn:\n worker = Worker(conn)\n worker.run()\n```\n\n```text\nexperiment\n```\n\n```text\nfoo.#\n```\n\n```text\nbar.#\n```\n\n```text\nfoo\n```\n\n```text\nfrom kombu import Exchange, Queue, binding\n\nexchange = Exchange('experiment', type='topic')\nq = Queue(exchange=exchange, bindings=[\n binding(exchange, routing_key='foo.#'),\n binding(exchange, routing_key='bar.#')\n], exclusive=True)\n```\n\n```text\nrouting_key\n```\n\n```text\nbindings\n```\n\n```text\nbinding\n```\n\n```text\nfrom kombu import Exchange, Queue, binding\n\nexchange = Exchange('experiment', type='topic')\nq = Queue(bindings=[\n binding(exchange, routing_key='foo.#'),\n binding(exchange, routing_key='bar.#'),\n])\n```\n\n```text\nif self.bindings:\n self.exchange = None\n```\n\n```text\nbindings\n```\n\n```text\nexchange\n```\n\n```text\nexchange\n```\n\n========================================\n\nComments:\n- You should not need to provide `exchange` param for `Queue` as you are providing as `binding` param?","metadata":{"transformedAt":"2026-08-18T18:33:20.205Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":17,"totalLines":191,"estimatedTokens":1110}}973{"id":"stack-11363512","source":"stackoverflow","questionId":11363512,"title":"Can't declare a dead letter exchange using rabbitmqadmin","tags":["rabbitmq"],"text":"Title: Can't declare a dead letter exchange using rabbitmqadmin\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am trying to setup a variety of exchanges and queues in RabbitMQ via a script calling rabbitmqadmin. While I can declare a queue, I am not able to find any way to send 'x-dead-letter-exchange' or 'x-dead-letter-routing-key' arguments in the declaration. Is this possible?\n\n========================================\n\nTop Answer:\nYes, this is possible by specifying JSON in 'arguments' argument:\n\n```\ncall rabbitmqadmin.py declare queue name=MyQueue arguments={\\\"x-dead-letter-exchange\\\":\\\"MyExchange\\\",\\\"x-dead-letter-routing-key\\\":\\\"MyRoutingKey\\\"}\n```\n\nNote: this is except from Windows batch file. (on other OS some syntax might be different)\n\n========================================\n\nCode:\n```text\ncall rabbitmqadmin.py declare queue name=MyQueue arguments={\\\"x-dead-letter-exchange\\\":\\\"MyExchange\\\",\\\"x-dead-letter-routing-key\\\":\\\"MyRoutingKey\\\"}\n```\n\n========================================\n\nComments:\n- This is the answer I was looking for.","metadata":{"transformedAt":"2026-08-18T18:33:20.205Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":29,"estimatedTokens":266}}974{"id":"stack-36175661","source":"stackoverflow","questionId":36175661,"title":"How to publish and consume make(map[string]string) in rabbitmq go lang","tags":["go","rabbitmq","rabbitmqctl"],"text":"Title: How to publish and consume make(map[string]string) in rabbitmq go lang\nTags: go, rabbitmq, rabbitmqctl\nSource: Stack Overflow\n\nQuestion:\nI have multiple objects of key-value type which i need to send to RabbitMQ and hence forward would consume them. So, after going through this RabbitMQ link. It only tells the way to publish a simple plain text message. Can anyone tell me how to publish and consume map objects in RabbitMQ go lang?\n\n```\nm := make(map[string]string)\n m[\"col1\"] = \"004999010640000\"\n m[\"col2\"] = \"awadwaw\"\n m[\"col3\"] = \"13\" \n\n err = ch.Publish(\n \"EventCaptureData-Exchange\", // exchange\n q.Name + \"Key\", // routing key\n true, // mandatory \n false, // immediate\n amqp.Publishing{\n ContentType: \"?????\",\n Body: ????,\n })\n```\n\n========================================\n\nTop Answer:\nIt's so simple. You can use json and bytes packages to serialize and deserialize messages. Prepared this example for you:\n\n```\ntype Message map[string]interface{}\n\nfunc serialize(msg Message) ([]byte, error) {\n var b bytes.Buffer\n encoder := json.NewEncoder(&b)\n err := encoder.Encode(msg)\n return b.Bytes(), err\n}\n\nfunc deserialize(b []byte) (Message, error) {\n var msg Message\n buf := bytes.NewBuffer(b)\n decoder := json.NewDecoder(buf)\n err := decoder.Decode(&msg)\n return msg, err\n}\n```\n\nYeah, basically that's it. Body field in RabbitMQ library is byte array, therefore all you need are just converting to/from your data structure to/from byte array.\n\n========================================\n\nCode:\n```text\nm := make(map[string]string)\n m[\"col1\"] = \"004999010640000\"\n m[\"col2\"] = \"awadwaw\"\n m[\"col3\"] = \"13\" \n\n err = ch.Publish(\n \"EventCaptureData-Exchange\", // exchange\n q.Name + \"Key\", // routing key\n true, // mandatory \n false, // immediate\n amqp.Publishing{\n ContentType: \"?????\",\n Body: ????,\n })\n```\n\n```text\napplication/octet-stream\n```\n\n```text\ntype Message map[string]interface{}\n\nfunc serialize(msg Message) ([]byte, error) {\n var b bytes.Buffer\n encoder := json.NewEncoder(&b)\n err := encoder.Encode(msg)\n return b.Bytes(), err\n}\n\nfunc deserialize(b []byte) (Message, error) {\n var msg Message\n buf := bytes.NewBuffer(b)\n decoder := json.NewDecoder(buf)\n err := decoder.Decode(&msg)\n return msg, err\n}\n```\n\n========================================\n\nComments:\n- `map[string]string` is a fairly simple data structure, why not use json?\n- since the type is mostly string data (`map[string]string`), json is going to be more compact than a gob in base64.\n- I agree, JSON is probably a better choice for many reasons (easier debugging, possibility to read and interpret it from another language, etc.). I just mentionned base64 here because I found an example quickly. I'm not a Go developer so I couldn't prepare a JSON-based example.\n- Works great. This should be stated somewhere in the documentation.","metadata":{"transformedAt":"2026-08-18T18:33:20.206Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":100,"estimatedTokens":748}}975{"id":"stack-35449234","source":"stackoverflow","questionId":35449234,"title":"How could I send a delayed message in rabbitmq using the rabbitmq-delayed-message-exchange plugin?","tags":["python","rabbitmq"],"text":"Title: How could I send a delayed message in rabbitmq using the rabbitmq-delayed-message-exchange plugin?\nTags: python, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have installed the plugin to send a delayed message from here rabbitmq-delayed-message-exchange.\n\nI couldn't find any help for using it in python. I've just started using rabbitmq . \n\nHere is what I've been trying:\n\n```\nimport pika \nconnection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))\nchannel = connection.channel()\nchannel.exchange_declare(\"test-x\", type=\"x-delayed-message\", arguments={\"x-delayed-type\":\"direct\"}) \nchannel.queue_declare(queue='task_queue',durable=True)\nchannel.queue_bind(queue=\"task_queue\", exchange=\"test-x\", routing_key=\"task_queue\")\nchannel.basic_publish(exchange='test-x',routing_key='task_queue',body='Hello World! Delayed',arguments={\"x-delay\":100})\nprint(\" [x] Sent 'Hello World! Delayed'\")\nconnection.close()\n```\n\nHere are the exchanges listed:\n\n```\nsudo rabbitmqctl list_exchanges\nListing exchanges ...\namq.direct direct\ntest-x x-delayed-message\namq.fanout fanout\namq.match headers\namq.headers headers\n direct\namq.rabbitmq.trace topic\namq.topic topic\namq.rabbitmq.log topic\n```\n\nI don't have a good idea how I could pass a delay argument to the basic_publish function\n\nAny help is appreciated\n\n========================================\n\nTop Answer:\nyou can actually delay message without using plugin.\nMessage in Rabbit queue can be delayed in 2 ways \n - using QUEUE TTL \n - using Message TTL\nIf all messages in queue are to be delayed for fixed time use queue TTL.\nIf each message has to be delayed by varied time use Message TTL.\nI have explained it using python3 and pika module.\npika BasicProperties argument 'expiration' in milliseconds has to be set to delay message in delay queue.\nAfter setting expiration time, publish message to a delayed_queue (\"not actual queue where consumers are waiting to consume\") , once message in delayed_queue expires, message will be routed to a actual queue using exchange 'amq.direct'\n\n```\ndef delay_publish(self, messages, queue, headers=None, expiration=0):\n \"\"\"\n Connect to RabbitMQ and publish messages to the queue\n Args:\n queue (string): queue name\n messages (list or single item): messages to publish to rabbit queue\n expiration(int): TTL in milliseconds for message\n \"\"\"\n delay_queue = \"\".join([queue, \"_delay\"])\n logging.info('Publishing To Queue: {queue}'.format(queue=delay_queue))\n logging.info('Connecting to RabbitMQ: {host}'.format(\n host=self.rabbit_host))\n credentials = pika.PlainCredentials(\n RABBIT_MQ_USER, RABBIT_MQ_PASS)\n parameters = pika.ConnectionParameters(\n rabbit_host, RABBIT_MQ_PORT,\n RABBIT_MQ_VHOST, credentials, heartbeat_interval=0)\n connection = pika.BlockingConnection(parameters)\n\n channel = connection.channel()\n channel.queue_declare(queue=queue, durable=True)\n\n channel.queue_bind(exchange='amq.direct',\n queue=queue)\n delay_channel = connection.channel()\n delay_channel.queue_declare(queue=delay_queue, durable=True,\n arguments={\n 'x-dead-letter-exchange': 'amq.direct',\n 'x-dead-letter-routing-key': queue\n })\n\n properties = pika.BasicProperties(\n delivery_mode=2, headers=headers, expiration=str(expiration))\n\n if type(messages) not in (list, tuple):\n messages = [messages]\n\n try:\n for message in messages:\n try:\n json_data = json.dumps(message)\n except Exception as err:\n logging.error(\n 'Error Jsonify Payload: {err}, {payload}'.format(\n err=err, payload=repr(message)), exc_info=True\n )\n if (type(message) is dict) and ('data' in message):\n message['data'] = {}\n message['error'] = 'Payload Invalid For JSON'\n json_data = json.dumps(message)\n else:\n raise\n\n try:\n delay_channel.basic_publish(\n exchange='', routing_key=delay_queue,\n body=json_data, properties=properties)\n except Exception as err:\n logging.error(\n 'Error Publishing Data: {err}, {payload}'.format(\n err=err, payload=json_data), exc_info=True\n )\n raise\n\n except Exception:\n raise\n\n finally:\n logging.info(\n 'Done Publishing. Closing Connection to {queue}'.format(\n queue=delay_queue\n )\n )\n connection.close()\n```\n\n========================================\n\nCode:\n```text\nimport pika \nconnection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))\nchannel = connection.channel()\nchannel.exchange_declare(\"test-x\", type=\"x-delayed-message\", arguments={\"x-delayed-type\":\"direct\"}) \nchannel.queue_declare(queue='task_queue',durable=True)\nchannel.queue_bind(queue=\"task_queue\", exchange=\"test-x\", routing_key=\"task_queue\")\nchannel.basic_publish(exchange='test-x',routing_key='task_queue',body='Hello World! Delayed',arguments={\"x-delay\":100})\nprint(\" [x] Sent 'Hello World! Delayed'\")\nconnection.close()\n```\n\n```text\nsudo rabbitmqctl list_exchanges\nListing exchanges ...\namq.direct direct\ntest-x x-delayed-message\namq.fanout fanout\namq.match headers\namq.headers headers\n direct\namq.rabbitmq.trace topic\namq.topic topic\namq.rabbitmq.log topic\n```\n\n```text\nchannel.basic_publish(\n exchange='test-x',\n routing_key='task_queue',\n body='Hello World! Delayed',\n properties=pika.BasicProperties(headers={\"x-delay\": 1000})\n)\n```\n\n```text\nx-delay\n```\n\n```text\ndef delay_publish(self, messages, queue, headers=None, expiration=0):\n \"\"\"\n Connect to RabbitMQ and publish messages to the queue\n Args:\n queue (string): queue name\n messages (list or single item): messages to publish to rabbit queue\n expiration(int): TTL in milliseconds for message\n \"\"\"\n delay_queue = \"\".join([queue, \"_delay\"])\n logging.info('Publishing To Queue: {queue}'.format(queue=delay_queue))\n logging.info('Connecting to RabbitMQ: {host}'.format(\n host=self.rabbit_host))\n credentials = pika.PlainCredentials(\n RABBIT_MQ_USER, RABBIT_MQ_PASS)\n parameters = pika.ConnectionParameters(\n rabbit_host, RABBIT_MQ_PORT,\n RABBIT_MQ_VHOST, credentials, heartbeat_interval=0)\n connection = pika.BlockingConnection(parameters)\n\n channel = connection.channel()\n channel.queue_declare(queue=queue, durable=True)\n\n channel.queue_bind(exchange='amq.direct',\n queue=queue)\n delay_channel = connection.channel()\n delay_channel.queue_declare(queue=delay_queue, durable=True,\n arguments={\n 'x-dead-letter-exchange': 'amq.direct',\n 'x-dead-letter-routing-key': queue\n })\n\n properties = pika.BasicProperties(\n delivery_mode=2, headers=headers, expiration=str(expiration))\n\n if type(messages) not in (list, tuple):\n messages = [messages]\n\n try:\n for message in messages:\n try:\n json_data = json.dumps(message)\n except Exception as err:\n logging.error(\n 'Error Jsonify Payload: {err}, {payload}'.format(\n err=err, payload=repr(message)), exc_info=True\n )\n if (type(message) is dict) and ('data' in message):\n message['data'] = {}\n message['error'] = 'Payload Invalid For JSON'\n json_data = json.dumps(message)\n else:\n raise\n\n try:\n delay_channel.basic_publish(\n exchange='', routing_key=delay_queue,\n body=json_data, properties=properties)\n except Exception as err:\n logging.error(\n 'Error Publishing Data: {err}, {payload}'.format(\n err=err, payload=json_data), exc_info=True\n )\n raise\n\n except Exception:\n raise\n\n finally:\n logging.info(\n 'Done Publishing. Closing Connection to {queue}'.format(\n queue=delay_queue\n )\n )\n connection.close()\n```\n\n========================================\n\nComments:\n- TTL is time to expire a message, delayed message is time to have message delayed as it appears in the queue. Both are different.","metadata":{"transformedAt":"2026-08-18T18:33:20.206Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":256,"estimatedTokens":2026}}976{"id":"stack-45328072","source":"stackoverflow","questionId":45328072,"title":"RabbitMQ failed install/start on Debian Stretch","tags":["rabbitmq","debian"],"text":"Title: RabbitMQ failed install/start on Debian Stretch\nTags: rabbitmq, debian\nSource: Stack Overflow\n\nQuestion:\nFollowing a \n\n```\nsudo apt-get install rabbitmq-server\n```\n\nI'm hitting errors when the service attempts to start (also when using `systemctl start`):\n\n```\n● rabbitmq-server.service - RabbitMQ Messaging Server\n Loaded: loaded (/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: enabled)\n Active: failed (Result: exit-code) since Wed 2017-07-26 15:59:41 IDT; 4min 28s ago\n Process: 17895 ExecStartPost=/usr/lib/rabbitmq/bin/rabbitmq-server-wait (code=exited, status=70)\n Process: 17894 ExecStart=/usr/sbin/rabbitmq-server (code=exited, status=1/FAILURE)\n Main PID: 17894 (code=exited, status=1/FAILURE)\n```\n\nThat's in `systemctl status`. In `journalctl -xe`:\n\n```\n-- Unit rabbitmq-server.service has begun starting up.\nJul 26 15:59:37 myhost rabbitmq[17895]: Waiting for rabbit@myhost ...\nJul 26 15:59:37 myhost rabbitmq[17895]: pid is 17903 ...\nJul 26 15:59:40 myhost systemd[1]: rabbitmq-server.service: Main process exited, code=exited, status=1/FAILURE\nJul 26 15:59:41 myhost rabbitmq[17895]: Error: process_not_running\nJul 26 15:59:41 myhost systemd[1]: rabbitmq-server.service: Control process exited, code=exited status=70\nJul 26 15:59:41 myhost systemd[1]: Failed to start RabbitMQ Messaging Server.\n-- Subject: Unit rabbitmq-server.service has failed\n-- Defined-By: systemd\n-- Support: https://www.debian.org/support\n-- \n-- Unit rabbitmq-server.service has failed.\n-- \n-- The result is failed.\nJul 26 15:59:41 myhost systemd[1]: rabbitmq-server.service: Unit entered failed state.\nJul 26 15:59:41 myhost systemd[1]: rabbitmq-server.service: Failed with result 'exit-code'.\n```\n\n========================================\n\nTop Answer:\nYou should check log files at /var/log/rabbitmq/ location\n\nSee if there is more information about why it fails. Most error details are available in the file named rabbit@.log\n\nAlso, check /etc/rabbitmq/enabled_plugins permissions and grant permissions if needed.\n\n========================================\n\nCode:\n```text\nsudo apt-get install rabbitmq-server\n```\n\n```text\n● rabbitmq-server.service - RabbitMQ Messaging Server\n Loaded: loaded (/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: enabled)\n Active: failed (Result: exit-code) since Wed 2017-07-26 15:59:41 IDT; 4min 28s ago\n Process: 17895 ExecStartPost=/usr/lib/rabbitmq/bin/rabbitmq-server-wait (code=exited, status=70)\n Process: 17894 ExecStart=/usr/sbin/rabbitmq-server (code=exited, status=1/FAILURE)\n Main PID: 17894 (code=exited, status=1/FAILURE)\n```\n\n```text\n-- Unit rabbitmq-server.service has begun starting up.\nJul 26 15:59:37 myhost rabbitmq[17895]: Waiting for rabbit@myhost ...\nJul 26 15:59:37 myhost rabbitmq[17895]: pid is 17903 ...\nJul 26 15:59:40 myhost systemd[1]: rabbitmq-server.service: Main process exited, code=exited, status=1/FAILURE\nJul 26 15:59:41 myhost rabbitmq[17895]: Error: process_not_running\nJul 26 15:59:41 myhost systemd[1]: rabbitmq-server.service: Control process exited, code=exited status=70\nJul 26 15:59:41 myhost systemd[1]: Failed to start RabbitMQ Messaging Server.\n-- Subject: Unit rabbitmq-server.service has failed\n-- Defined-By: systemd\n-- Support: https://www.debian.org/support\n-- \n-- Unit rabbitmq-server.service has failed.\n-- \n-- The result is failed.\nJul 26 15:59:41 myhost systemd[1]: rabbitmq-server.service: Unit entered failed state.\nJul 26 15:59:41 myhost systemd[1]: rabbitmq-server.service: Failed with result 'exit-code'.\n```\n\n```text\nsystemctl start\n```\n\n```text\nsystemctl status\n```\n\n```text\njournalctl -xe\n```\n\n```text\nsudo hostname --file /etc/hostname\n```\n\n```text\n/etc/hostname\n```\n\n```text\na.b.c.d\n```\n\n```text\nrabbitmq\n```\n\n```text\n/etc/rabbitmq/rabbitmq-env.conf\n```\n\n```text\nNODE=rabbit@localhost\n```\n\n```text\nsudo apt-get install --fix-broken\n```\n\n```text\nsudo rabbitmqctl status\n```\n\n========================================\n\nComments:\n- Hi! Could you please post the RabbitMQ log files, located in `/var/log/rabbitmq`?\n- @Jean-SébastienPédron Sorry, I got it working so they don't show any error now. I didn't know about them so the comment should be helpful for other people looking here.\n- Ok, great that you solved it :)\n- Beautiful, this worked for me after several hours of searching. To further clarify for anyone else arriving here, `hostname` displays the hostname but calling `hostname --file /etc/hostname` will set the hostname to whatever is in the `--file` arg.\n- Note `/etc/hostname` is the usual file on many Linux flavors your hostname is saved. If someone thinks, it's a different file, please don't edit it in replace of this name, instead, add it along side with the flavor of Linux it is relevant to.\n- Definitly one should see logs. In my case, it was not enough disk space to start RabbitMQ server.","metadata":{"transformedAt":"2026-08-18T18:33:20.206Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":14,"totalLines":140,"estimatedTokens":1222}}977{"id":"stack-43365135","source":"stackoverflow","questionId":43365135,"title":"Programmatically enable and disable certain @RabbitListener's in Spring?","tags":["java","spring","rabbitmq","integration-testing","spring-amqp"],"text":"Title: Programmatically enable and disable certain @RabbitListener's in Spring?\nTags: java, spring, rabbitmq, integration-testing, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI have a class A that publishes event E1. E1 is consumed by class B in the same application that is annotated with `@RabbitListener`. B does some things and then publishes event E2 that is consumed by C etc etc (forming a process chain).\n\nWhat I want to do is two things: \n\n- I want to test A in an integration test but while doing so I'd like to disable the `RabbitListener's` so that the entire process that is the result of E1 being published is not executed. I only want to assert that A does what it's supposed to and publishes E1. I have managed to accommodate this by setting `spring.rabbitmq.listener.auto-startup=false`.\n\n- I also want to test B in an integration test by publishing E1 to RabbitMQ so that I can be confident that I've configured B's `RabbitListerner` correctly. But again I don't want C to be called as a side-effect of E2 being published.\n\nI know I can probably do this using mocks but preferably I'd like to test the real deal and using the actual components (including sending the message to an actual RabbitMQ instance that in my case is running in Docker).\n\nCan I achieve this in a nice way in Spring Boot? Or is it perhaps recommended to use `@RabbitListenerTest` and indeed use mocks?\n\n========================================\n\nTop Answer:\nA -up idea to the accepted answer is to have some sort of abstract `BaseAmqpIntegrationTest` which does the following:\n\n```\npublic abstract class BaseAmqpIntegrationTest {\n\n @Autowired\n protected RabbitListenerEndpointRegistry rabbitListenerEndpointRegistry;\n\n @BeforeEach\n protected void setUpBeforeEach() {\n rabbitListenerEndpointRegistry.getListenerContainers()\n .forEach(Lifecycle::stop);\n\n getRequiredListenersToStart().forEach(listener -> rabbitListenerEndpointRegistry.getListenerContainer(listener)\n .start());\n }\n\n protected abstract List getRequiredListenersToStart();\n\n}\n```\n\nThis makes it reusable and ensures that all `@RabbitListener`s are disabled \"by default\" and requires each test to explicitly enable the listener(s) that it tests. The test sub classes can then simply override `getRequiredListenersToStart()` to provide the IDs of the `@RabbitListener`s which they require.\n\nPS: Cleaning it up would of course also work:\n\n```\npublic abstract class BaseAmqpIntegrationTest {\n\n @AfterEach\n protected void cleanUpAfterEach() {\n rabbitListenerEndpointRegistry.getListenerContainers()\n .forEach(Lifecycle::stop);\n }\n\n}\n```\n\nOr a bit more fine-grained:\n\n```\npublic abstract class BaseAmqpIntegrationTest {\n\n @AfterEach\n protected void cleanUpAfterEach() {\n getRequiredListenersToStart().forEach(listener -> rabbitListenerEndpointRegistry.getListenerContainer(listener)\n .stop());\n }\n\n}\n```\n\n========================================\n\nCode:\n```text\n@RabbitListener\n```\n\n```text\nRabbitListener's\n```\n\n```text\nspring.rabbitmq.listener.auto-startup=false\n```\n\n```text\nRabbitListerner\n```\n\n```text\n@RabbitListenerTest\n```\n\n```text\n/**\n * The unique identifier of the container managing for this endpoint.\n * <p>If none is specified an auto-generated one is provided.\n * @return the {@code id} for the container managing for this endpoint.\n * @see org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry#getListenerContainer(String)\n */\nString id() default \"\";\n```\n\n```text\n@RabbitListener\n```\n\n```text\nid\n```\n\n```text\nRabbitListenerEndpointRegistry#getListenerContainer(String)\n```\n\n```text\nMessageListenerContainer\n```\n\n```text\nstart()/stop()\n```\n\n```text\n@RabbitListener\n```\n\n```java\npublic abstract class BaseAmqpIntegrationTest {\n\n @Autowired\n protected RabbitListenerEndpointRegistry rabbitListenerEndpointRegistry;\n\n @BeforeEach\n protected void setUpBeforeEach() {\n rabbitListenerEndpointRegistry.getListenerContainers()\n .forEach(Lifecycle::stop);\n\n getRequiredListenersToStart().forEach(listener -> rabbitListenerEndpointRegistry.getListenerContainer(listener)\n .start());\n }\n\n protected abstract List<String> getRequiredListenersToStart();\n\n}\n```\n\n```java\npublic abstract class BaseAmqpIntegrationTest {\n\n @AfterEach\n protected void cleanUpAfterEach() {\n rabbitListenerEndpointRegistry.getListenerContainers()\n .forEach(Lifecycle::stop);\n }\n\n}\n```\n\n```java\npublic abstract class BaseAmqpIntegrationTest {\n\n @AfterEach\n protected void cleanUpAfterEach() {\n getRequiredListenersToStart().forEach(listener -> rabbitListenerEndpointRegistry.getListenerContainer(listener)\n .stop());\n }\n\n}\n```\n\n```text\nBaseAmqpIntegrationTest\n```\n\n```text\n@RabbitListener\n```\n\n```text\ngetRequiredListenersToStart()\n```\n\n```text\n@RabbitListener\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.206Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":19,"totalLines":188,"estimatedTokens":1256}}978{"id":"stack-21630860","source":"stackoverflow","questionId":21630860,"title":"Storm Topology not submit","tags":["java","log4j","rabbitmq","slf4j","apache-storm"],"text":"Title: Storm Topology not submit\nTags: java, log4j, rabbitmq, slf4j, apache-storm\nSource: Stack Overflow\n\nQuestion:\ni have configured my machine zookeeper,nimbus,supervisor are running properly and my topology working in LocalCluster\n\n```\nLocalCluster cluster = new LocalCluster();\ncluster.submitTopology(\"SendPost\", conf, builder.createTopology());\nUtils.sleep(10000000000l);\ncluster.killTopology(\"SendPost\");\ncluster.shutdown();\n```\n\nnow i want try submit my topology bt it not working\n\n```\n/usr/local/storm/bin$ ./storm jar /home/winoria/Desktop/Storm/storm-starter/target/storm-starter-0.0.1-SNAPSHOT-jar-with-dependencies.jar com.winoria.post.PostTopology Post\n```\n\ni getting following error \n\n```\nSLF4J: Class path contains multiple SLF4J bindings.\nSLF4J: Found binding in [jar:file:/usr/local/storm/lib/logback-classic-1.0.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]\nSLF4J: Found binding in [jar:file:/home/winoria/Desktop/Storm/storm-starter/target/storm-starter-0.0.1-SNAPSHOT-jar-with-dependencies.jar!/org/slf4j/impl/StaticLoggerBinder.class]\nSLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.\nRunning: java -client -Dstorm.options= -Dstorm.home=/usr/local/storm -Djava.library.path=/usr/local/lib:/opt/local/lib:/usr/lib -Dstorm.conf.file= -cp /usr/local /storm/storm-netty-0.9.0.1.jar:/usr/local/storm/storm-console-logging-0.9.0.1.jar:/usr/local/storm/storm-core-0.9.0.1.jar:/usr/local/storm/lib/httpcore-4.1.jar:/usr/local/storm/lib/carbonite-1.5.0.jar:/usr/local/storm/lib/mockito-all-1.9.5.jar:/usr/local/storm/lib/commons-io-1.4.jar:/usr/local/storm/lib/commons-fileupload-1.2.1.jar:/usr/local/storm/lib/jgrapht-0.8.3.jar:/usr/local/storm/lib/ring-jetty-adapter-0.3.11.jar:/usr/local/storm/lib/jzmq-2.1.0.jar:/usr/local/storm/lib/asm-4.0.jar:/usr/local/storm/lib/logback-core-1.0.6.jar:/usr/local/storm/lib/tools.nrepl-0.2.3.jar:/usr/local/storm/lib/compojure-1.1.3.jar:/usr/local/storm/lib/json-simple-1.1.jar:/usr/local/storm/lib/ring-devel-0.3.11.jar:/usr/local/storm/lib/commons-logging-1.1.1.jar:/usr/local/storm/lib/httpclient-4.1.1.jar:/usr/local/storm/lib/reflectasm-1.07-shaded.jar:/usr/local/storm/lib/commons-exec-1.1.jar:/usr/local/storm/lib/guava-13.0.jar:/usr/local/storm/lib/clout-1.0.1.jar:/usr/local/storm/lib/objenesis-1.2.jar:/usr/local/storm/lib/slf4j-api-1.6.5.jar:/usr/local/storm/lib/clojure-1.4.0.jar:/usr/local/storm/lib/jetty-6.1.26.jar:/usr/local/storm/lib/hiccup-0.3.6.jar:/usr/local/storm/lib/clj-stacktrace-0.2.2.jar:/usr/local/storm/lib/log4j-over-slf4j-1.6.6.jar:/usr/local/storm/lib/tools.logging-0.2.3.jar:/usr/local/storm/lib/ring-core-1.1.5.jar:/usr/local/storm/lib/zookeeper-3.3.3.jar:/usr/local/storm/lib/math.numeric-tower-0.0.1.jar:/usr/local/storm/lib/disruptor-2.10.1.jar:/usr/local/storm/lib/minlog-1.2.jar:/usr/local/storm/lib/core.incubator-0.1.0.jar:/usr/local/storm/lib/servlet-api-2.5-20081211.jar:/usr/local/storm/lib/netty-3.6.3.Final.jar:/usr/local/storm/lib/ring-servlet-0.3.11.jar:/usr/local/storm/lib/clj-time-0.4.1.jar:/usr/local/storm/lib/snakeyaml-1.11.jar:/usr/local/storm/lib/commons-codec-1.4.jar:/usr/local/storm/lib/tools.cli-0.2.2.jar:/usr/local/storm/lib/logback-classic-1.0.6.jar:/usr/local/storm/lib/servlet-api-2.5.jar:/usr/local/storm/lib/kryo-2.17.jar:/usr/local/storm/lib/joda-time-2.0.jar:/usr/local/storm/lib/curator-client-1.0.1.jar:/usr/local/storm/lib/libthrift7-0.7.0-2.jar:/usr/local/storm/lib/tools.macro-0.1.0.jar:/usr/local/storm/lib/jline-0.9.94.jar:/usr/local/storm/lib/clojure-complete-0.2.3.jar:/usr/local/storm/lib/curator-framework-1.0.1.jar:/usr/local/storm/lib/commons-lang-2.5.jar:/usr/local/storm/lib/junit-3.8.1.jar:/usr/local/storm/lib/jetty-util-6.1.26.jar:/home/winoria/Desktop/Storm/storm-starter/target/storm-starter-0.0.1-SNAPSHOT-jar-with-dependencies.jar:/usr/local/storm/conf:/usr/local/storm/bin -Dstorm.jar=/home/winoria/Desktop/Storm/storm-starter/target/storm-starter-0.0.1-SNAPSHOT-jar-with-dependencies.jar com.winoria.post.PostTopology Post\nSLF4J: Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError. \nSLF4J: See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details.\nException in thread \"main\" java.lang.ExceptionInInitializerError\nat org.apache.log4j.Logger.getLogger(Logger.java:39)\nat org.apache.log4j.Logger.getLogger(Logger.java:43)\nat com.rapportive.storm.spout.AMQPSpout.(AMQPSpout.java:67)\nat com.winoria.post.PostTopology.main(PostTopology.java:33)\nCaused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND slf4j- log4j12.jar on the class path, preempting StackOverflowError. See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details.\nat org.apache.log4j.Log4jLoggerFactory.(Log4jLoggerFactory.java:49)\n... 4 more\n```\n\nplz help me ...........\nthanks in advance\n\n========================================\n\nTop Answer:\nTry to exclude either **log4j-over-slf4j.jar** or **slf4j-log4j12.jar** from your classpath. I don't know which build tool do you use. Check the documentation of your build tool to see how to exclude a dependency.\n\nFor more reference: Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError\n\n========================================\n\nCode:\n```text\nLocalCluster cluster = new LocalCluster();\ncluster.submitTopology(\"SendPost\", conf, builder.createTopology());\nUtils.sleep(10000000000l);\ncluster.killTopology(\"SendPost\");\ncluster.shutdown();\n```\n\n```text\n/usr/local/storm/bin$ ./storm jar /home/winoria/Desktop/Storm/storm-starter/target/storm-starter-0.0.1-SNAPSHOT-jar-with-dependencies.jar com.winoria.post.PostTopology Post\n```\n\n```text\nSLF4J: Class path contains multiple SLF4J bindings.\nSLF4J: Found binding in [jar:file:/usr/local/storm/lib/logback-classic-1.0.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]\nSLF4J: Found binding in [jar:file:/home/winoria/Desktop/Storm/storm-starter/target/storm-starter-0.0.1-SNAPSHOT-jar-with-dependencies.jar!/org/slf4j/impl/StaticLoggerBinder.class]\nSLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.\nRunning: java -client -Dstorm.options= -Dstorm.home=/usr/local/storm -Djava.library.path=/usr/local/lib:/opt/local/lib:/usr/lib -Dstorm.conf.file= -cp /usr/local /storm/storm-netty-0.9.0.1.jar:/usr/local/storm/storm-console-logging-0.9.0.1.jar:/usr/local/storm/storm-core-0.9.0.1.jar:/usr/local/storm/lib/httpcore-4.1.jar:/usr/local/storm/lib/carbonite-1.5.0.jar:/usr/local/storm/lib/mockito-all-1.9.5.jar:/usr/local/storm/lib/commons-io-1.4.jar:/usr/local/storm/lib/commons-fileupload-1.2.1.jar:/usr/local/storm/lib/jgrapht-0.8.3.jar:/usr/local/storm/lib/ring-jetty-adapter-0.3.11.jar:/usr/local/storm/lib/jzmq-2.1.0.jar:/usr/local/storm/lib/asm-4.0.jar:/usr/local/storm/lib/logback-core-1.0.6.jar:/usr/local/storm/lib/tools.nrepl-0.2.3.jar:/usr/local/storm/lib/compojure-1.1.3.jar:/usr/local/storm/lib/json-simple-1.1.jar:/usr/local/storm/lib/ring-devel-0.3.11.jar:/usr/local/storm/lib/commons-logging-1.1.1.jar:/usr/local/storm/lib/httpclient-4.1.1.jar:/usr/local/storm/lib/reflectasm-1.07-shaded.jar:/usr/local/storm/lib/commons-exec-1.1.jar:/usr/local/storm/lib/guava-13.0.jar:/usr/local/storm/lib/clout-1.0.1.jar:/usr/local/storm/lib/objenesis-1.2.jar:/usr/local/storm/lib/slf4j-api-1.6.5.jar:/usr/local/storm/lib/clojure-1.4.0.jar:/usr/local/storm/lib/jetty-6.1.26.jar:/usr/local/storm/lib/hiccup-0.3.6.jar:/usr/local/storm/lib/clj-stacktrace-0.2.2.jar:/usr/local/storm/lib/log4j-over-slf4j-1.6.6.jar:/usr/local/storm/lib/tools.logging-0.2.3.jar:/usr/local/storm/lib/ring-core-1.1.5.jar:/usr/local/storm/lib/zookeeper-3.3.3.jar:/usr/local/storm/lib/math.numeric-tower-0.0.1.jar:/usr/local/storm/lib/disruptor-2.10.1.jar:/usr/local/storm/lib/minlog-1.2.jar:/usr/local/storm/lib/core.incubator-0.1.0.jar:/usr/local/storm/lib/servlet-api-2.5-20081211.jar:/usr/local/storm/lib/netty-3.6.3.Final.jar:/usr/local/storm/lib/ring-servlet-0.3.11.jar:/usr/local/storm/lib/clj-time-0.4.1.jar:/usr/local/storm/lib/snakeyaml-1.11.jar:/usr/local/storm/lib/commons-codec-1.4.jar:/usr/local/storm/lib/tools.cli-0.2.2.jar:/usr/local/storm/lib/logback-classic-1.0.6.jar:/usr/local/storm/lib/servlet-api-2.5.jar:/usr/local/storm/lib/kryo-2.17.jar:/usr/local/storm/lib/joda-time-2.0.jar:/usr/local/storm/lib/curator-client-1.0.1.jar:/usr/local/storm/lib/libthrift7-0.7.0-2.jar:/usr/local/storm/lib/tools.macro-0.1.0.jar:/usr/local/storm/lib/jline-0.9.94.jar:/usr/local/storm/lib/clojure-complete-0.2.3.jar:/usr/local/storm/lib/curator-framework-1.0.1.jar:/usr/local/storm/lib/commons-lang-2.5.jar:/usr/local/storm/lib/junit-3.8.1.jar:/usr/local/storm/lib/jetty-util-6.1.26.jar:/home/winoria/Desktop/Storm/storm-starter/target/storm-starter-0.0.1-SNAPSHOT-jar-with-dependencies.jar:/usr/local/storm/conf:/usr/local/storm/bin -Dstorm.jar=/home/winoria/Desktop/Storm/storm-starter/target/storm-starter-0.0.1-SNAPSHOT-jar-with-dependencies.jar com.winoria.post.PostTopology Post\nSLF4J: Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError. \nSLF4J: See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details.\nException in thread \"main\" java.lang.ExceptionInInitializerError\nat org.apache.log4j.Logger.getLogger(Logger.java:39)\nat org.apache.log4j.Logger.getLogger(Logger.java:43)\nat com.rapportive.storm.spout.AMQPSpout.<clinit>(AMQPSpout.java:67)\nat com.winoria.post.PostTopology.main(PostTopology.java:33)\nCaused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND slf4j- log4j12.jar on the class path, preempting StackOverflowError. See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details.\nat org.apache.log4j.Log4jLoggerFactory.<clinit>(Log4jLoggerFactory.java:49)\n... 4 more\n```\n\n```text\n<dependencies>\n<dependency>\n<groupId> org.apache.cassandra</groupId>\n<artifactId>cassandra-all</artifactId>\n<version>1.1.6</version>\n\n<exclusions>\n <exclusion> \n <groupId>org.slf4j</groupId>\n <artifactId>slf4j-log4j12</artifactId>\n </exclusion>\n <exclusion> \n <groupId>log4j</groupId>\n <artifactId>log4j</artifactId>\n </exclusion>\n</exclusions> \n\n</dependency>\n</dependencies>\n```\n\n```text\nslf4j-log4j12.jar\n```\n\n```text\nlog4j-over-slf4j.jar\n```\n\n```text\nlog4j-over-slf4j\n```\n\n```text\nstorm-core\n```\n\n```text\npom.xml\n```\n\n```text\nexclude log4j-over-slf4j\n```\n\n```text\nstorm-core\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.206Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":11,"totalLines":133,"estimatedTokens":2607}}979{"id":"stack-11040141","source":"stackoverflow","questionId":11040141,"title":"Distributed RabbitMQ Nodes don't recognize each other","tags":["erlang","distributed","rabbitmq","connectivity"],"text":"Title: Distributed RabbitMQ Nodes don't recognize each other\nTags: erlang, distributed, rabbitmq, connectivity\nSource: Stack Overflow\n\nQuestion:\nI'm working on a RabbitMQ distributed POC and I'm stuck at the basics of clustering the nodes.\n\nI'm trying to the rabbit's tutorial on clustering so this is my reference.\n\nAfter installing erlang (R14B04) and rabbit (2.8.2-1) I've copied the `.erlang.cookie` file contents from one node to the other two.\n\nI wasn't sure about how to get erlang to notice this change to I had to restart the machines themselves (pretty brute force but I don't know erlang at all).\n\nIn addtion I opened in iptables 4369 and 5 additional ports for communications and placed under `/usr/lib64/erlang/bin/sys.config` the following config: \n\n```\n{kernel,[{inet_dist_listen_min, XX00},{inet_dist_listen_max,XX05}]}]\n```\n\nThen another restart (dumb I know) to verify erlang takes these into consideration but still when I run: \n\n```\nrabbitmqctl cluster rabbit@HostName1\n```\n\nI get:\n\n```\nClustering node rabbit@HostName2 with [rabbit@HostName1] ...\nError: {no_running_cluster_nodes,[rabbit@HostName1],\n [rabbit@HostName1]}\n```\n\nThere is a chance my fiddling with the erlang.cookie or with the ports did not succeed but I don't know how to check them. I tried typing `erl` in the cmd and then `erl_epmd:names()` or other commands to get more information but I'm probably way off in erlang land. \n\nWould truly appreciate any help \n\n**Update:**\n\nI tried pinging two erlang nodes manually and got `pang` back.\n\nI did the following:\n\n Connected to two nodes, stopped rabbitmq (wasn't sure if needed but to be sure), started erlang like so (`erl -sname dilbert` and `erl -sname dilbert2`) when the erlang command line started i ran `node().` on each of them and got `dilbert@HostName1` and `dilbert2@HostName2` respectively. I then tried to run `net_adm:ping('dilbert').` and `net_adm:ping('dilbert@HostName1').` with the single quote and without them from both nodes (changed names of course) and got on all 8 cases `pang`.\n\nWhen I ran `nodes().` on one of the machines I got back an empty array.\n\nI've also tried to allow all traffic in the firewall (script) and then try to run the above commands (don't worry they're back on now) and still got back `pang`.\n\n**Update2:**\n\nFor some reason I had cookies mismatch which I needed to resolve (thanks @kjw0188 for the suggestion [I ran `erlang:get_cookie().` in the erlang command line]).\n\nThis did not help and I needed to stop iptables completely (not sure why but I'll figure it soon) and load the erlang node with `-name dilbert@my-ip` because my rackspace servers have no dns-name. This finally enabled me to get a pong and see the nodes see each other (`nodes().` returns a non-empty array after the ping).\n\nThe problem I'm facing now is how to instruct RabbitMQ to use -name instead of -sname when starting erlang.\n\n========================================\n\nTop Answer:\nOne thing to really watch out for is whitespace of any kind in the erlang cookie file, especially line breaks AFTER the contents of the cookie. So long as both are identical, things are okay, but when one has a line break and the other doesn't, thing won't work.\n\n========================================\n\nCode:\n```text\n{kernel,[{inet_dist_listen_min, XX00},{inet_dist_listen_max,XX05}]}]\n```\n\n```text\nrabbitmqctl cluster rabbit@HostName1\n```\n\n```text\nClustering node rabbit@HostName2 with [rabbit@HostName1] ...\nError: {no_running_cluster_nodes,[rabbit@HostName1],\n [rabbit@HostName1]}\n```\n\n```text\n.erlang.cookie\n```\n\n```text\n/usr/lib64/erlang/bin/sys.config\n```\n\n```text\nerl\n```\n\n```text\nerl_epmd:names()\n```\n\n```text\npang\n```\n\n```text\nerl -sname dilbert\n```\n\n```text\nerl -sname dilbert2\n```\n\n```text\nnode().\n```\n\n```text\ndilbert@HostName1\n```\n\n```text\ndilbert2@HostName2\n```\n\n```text\nnet_adm:ping('dilbert').\n```\n\n```text\nnet_adm:ping('dilbert@HostName1').\n```\n\n```text\npang\n```\n\n```text\nnodes().\n```\n\n```text\npang\n```\n\n```text\nerlang:get_cookie().\n```\n\n```text\n-name dilbert@my-ip\n```\n\n```text\nnodes().\n```\n\n```text\n/sbin/iptables -A INPUT -i eth1 -p tcp --dport ${epmd} -s ${otherNode} -j ACCEPT\n/sbin/iptables -A INPUT -i eth1 -p tcp --dport ${inet_dist_listen_min}:${inet_dist_listen_max} -s ${otherNode} -j ACCEPT\n```\n\n```text\nDEFAULT_NODE_IP_ADDRESS=auto\nDEFAULT_NODE_PORT=5672\n[ \"x\" = \"x$RABBITMQ_NODE_IP_ADDRESS\" ] && RABBITMQ_NODE_IP_ADDRESS=${NODE_IP_ADDRESS}\n[ \"x\" = \"x$RABBITMQ_NODE_PORT\" ] && RABBITMQ_NODE_PORT=${NODE_PORT}\n\n[ \"x\" = \"x$RABBITMQ_NODE_IP_ADDRESS\" ] && [ \"x\" != \"x$RABBITMQ_NODE_PORT\" ] && RABBITMQ_NODE_IP_ADDRESS=${DEFAULT_NODE_IP_ADDRESS}\n[ \"x\" != \"x$RABBITMQ_NODE_IP_ADDRESS\" ] && [ \"x\" = \"x$RABBITMQ_NODE_PORT\" ] && RABBITMQ_NODE_PORT=${DEFAULT_NODE_PORT}\n```\n\n```text\n#the ip address which rabbit should use, this is to limit rabbit to only use internal rackspace communication and not publicly accessible ports \nNODE_IP_ADDRESS=myIpAdress \n#had to change the nodename becaue otherwise rabbitmq used rabbit@Hostname and not only rabbit \nNODENAME=myCompany\n#This instructed rabbit to instruct erlang which ports it should use for its communications with other nodes \nexport SERVER_ERL_ARGS=\"$SERVER_ERL_ARGS -kernel inet_dist_listen_min somePort -kernel inet_dist_listen_max someOtherBiggerPort\"\n```\n\n```text\n.erlang.cookie\n```\n\n```text\n/root\n```\n\n```text\n/var/lib/rabbitmq/\n```\n\n```text\nepmd\n```\n\n```text\ninet_dist_listen_min\n```\n\n```text\ninet_dist_listen_max\n```\n\n```text\nempd\n```\n\n```text\n${otherNode}\n```\n\n```text\n-name\n```\n\n```text\n-sname\n```\n\n```text\n/usr/lib/rabbitmq/bin/rabbitmqctl\n```\n\n```text\nRABBITMQ_NODE_IP_ADDRESS\n```\n\n```text\n-sname ${RABBITMQ_NODENAME} \\\n```\n\n```text\n-name ${RABBITMQ_NODENAME}@${RABBITMQ_NODE_IP_ADDRESS}\\\n```\n\n```text\n/usr/lib/rabbitmq/bin/rabbitmq-server\n```\n\n```text\n-sname ${RABBITMQ_NODENAME} \\\n```\n\n```text\n-name ${RABBITMQ_NODENAME}@${RABBITMQ_NODE_IP_ADDRESS}\n```\n\n```text\n/etc/rabbitmq/rabbitmq-env.conf\n```\n\n```text\nexec erl \\\n -pa \"${RABBITMQ_HOME}/ebin\" \\\n -noinput \\\n -hidden \\\n ${RABBITMQ_CTL_ERL_ARGS} \\\n -sname rabbitmqctl$$ \\\n -s rabbit_control \\\n -nodename $RABBITMQ_NODENAME \\\n -extra \"$@\"\n```\n\n```text\nexec erl \\\n -pa \"${RABBITMQ_HOME}/ebin\" \\\n -noinput \\\n -hidden \\\n ${RABBITMQ_CTL_ERL_ARGS} \\\n -name rabbitmqctl$$ \\\n -s rabbit_control \\\n -nodename $RABBITMQ_NODENAME \\\n -extra \"$@\"\n```\n\n```text\n172.68.1.6 rabbit1\n172.68.1.7 rabbit2\n```\n\n```text\n/var/lib/rabbitmq/.erlang.cookie\n```\n\n```text\n$rabbitmqctl stop_app\n```\n\n```text\n$rabbitmqctl join_cluster rabbit@rabbit1\n```\n\n```text\nrabbitmqctl start_app\n```\n\n```text\n$rabbitmqctl cluster_status\n```\n\n========================================\n\nComments:\n- Did you see if you can start erl nodes on each machine, and see if they can ping each other?\n- @kjw0188 Haven't tried it yet (erlang noob). Do you know how I can check to see that the current node is not running? I think RabbitMQ starts a node when it loads so I'll stop it but I want to verify no node is running before I try your suggestion. Thanks\n- You shouldn't need to take down rabbit, but if you want to, you can try stopping the service `sudo /etc/init.d/rabbitmq-server stop`\n- @kjw0188 Still no luck, please see my update above. Thanks\n- Do the cookies match? Try `erlang:get_cookie().` on `dilbert` and `dogbert`, or setting the cookie manually with the `-setcookie` command line option. If they still can't ping each other, it seems like erlang can't find the other nodes for some reason. Are the hosts reachable by normal `ping`? Use the hostname for the machines for the ping, not the IP address.\n- @kjw0188 Awkwardly enough one of the cookies didn't match. For some reason I have multiple cookies on each node (might be related to rabbitMQ) and one of the cookies wasn't a match. The bad news are that even after I fixed that I still get back `pang`. I had a problem pinging between the nodes not with the IP and I think this has to do with the fact that they're Rackspace hosted. I'll try to verify it with them and update here once there is anything new. Thanks for all your help and patience.\n- I just want to add, I am working on Windows and was also having issues with the clustering. I kept getting the message \"TCP connection succeeded but Erlang distribution failed\". Turns out, the hostname is case-sensitive even in Windows so instead of rabbit@rabbitmq_node1 I had to put rabbit@RABBITMQ_NODE1 because that's how it appears in %COMPUTERNAME%\n- Thanks! I just figured it out a couple of hours ago and I'm working on compiling the full account of my problems to post as an answer (since I had several issues related to distibuted rabbitmq).\n- The link you posted `http://pearlin.info/?p=1672` is not english nor is it about programming.","metadata":{"transformedAt":"2026-08-18T18:33:20.206Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":50,"totalLines":308,"estimatedTokens":2204}}980{"id":"stack-44804018","source":"stackoverflow","questionId":44804018,"title":"Docker image for Spring/RabbitMQ tutorial results in connection refused","tags":["spring-boot","rabbitmq","docker-compose"],"text":"Title: Docker image for Spring/RabbitMQ tutorial results in connection refused\nTags: spring-boot, rabbitmq, docker-compose\nSource: Stack Overflow\n\nQuestion:\nI'm working through the Spring tutorial here;\n\nMessaging with RabbitMQ\n\nI found this question but it did not address my query regarding the `docker-compose.yml` file found in the tutorial;\n\nSpring RabbitMQ tutorial results in Connection Refused error\n\nI've completed all necessary steps up until the actual running of the application, at which point I'm getting `ConnectException` exceptions suggesting that the server is not running or not running correctly.\n\nThe docker-compose.yml file specified in the tutorial is as follows;\n\n```\nrabbitmq:\nimage: rabbitmq:management\nports:\n - \"5672:5672\"\n - \"15672:15672\"\n```\n\nBasically I am unsure what this docker-compose file actually does, because it doesn't seem to set up the RabbitMQ server as the tutorial suggests (or at least not in the way the tutorial expects). I'm quite new to Docker also so perhaps I am mistaken in thinking this file would run a new instance of the RabbitMQ server.\n\nWhen I run `docker-compose up` I get the following console output;\n\n```\nrabbitmq_1 |\nrabbitmq_1 | =INFO REPORT==== 28-Jun-2017::13:27:26 ===\nrabbitmq_1 | Starting RabbitMQ 3.6.10 on Erlang 20.0-rc2\nrabbitmq_1 | Copyright (C) 2007-2017 Pivotal Software, Inc.\nrabbitmq_1 | Licensed under the MPL. See http://www.rabbitmq.com/\nrabbitmq_1 |\nrabbitmq_1 | RabbitMQ 3.6.10. Copyright (C) 2007-2017 Pivotal Software, Inc.\nrabbitmq_1 | ## ## Licensed under the MPL. See http://www.rabbitmq.com/\nrabbitmq_1 | ## ##\nrabbitmq_1 | ########## Logs: tty\nrabbitmq_1 | ###### ## tty\nrabbitmq_1 | ##########\nrabbitmq_1 | Starting broker...\nrabbitmq_1 |\nrabbitmq_1 | =INFO REPORT==== 28-Jun-2017::13:27:26 ===\nrabbitmq_1 | node : rabbit@bd20dc3d3d2a\nrabbitmq_1 | home dir : /var/lib/rabbitmq\nrabbitmq_1 | config file(s) : /etc/rabbitmq/rabbitmq.config\nrabbitmq_1 | cookie hash : DTVsmjdKvD5KtH0o/OLVJA==\nrabbitmq_1 | log : tty\nrabbitmq_1 | sasl log : tty\nrabbitmq_1 | database dir : /var/lib/rabbitmq/mnesia/rabbit@bd20dc3d3d2a\n```\n\n...plus a load of INFO reports. This led me to believe that the RabbitMQ server was up and running, but apparently not as I cannot connect.\n\nThe only way I have gotten this to work is by manually installing Erlang and RabbitMQ (on a Windows system here) which does appear to let me complete the tutorial.\n\nWhy is Docker even mentioned in this tutorial though? The `docker-compose.yml` does not appear to do what the tutorial suggests. \n\nWhat is this file actually doing here and how would one run RabbitMQ in a docker container for the purposes of this tutorial? Is this an issue with port numbers?\n\n========================================\n\nTop Answer:\nFrom what I know, it is not possible to know all the time the IP address and you should instead of the ip address, provide the DNS which is the name of the rabbitmq server defined in your docker-compose file.\n\n========================================\n\nCode:\n```text\nrabbitmq:\nimage: rabbitmq:management\nports:\n - \"5672:5672\"\n - \"15672:15672\"\n```\n\n```text\nrabbitmq_1 |\nrabbitmq_1 | =INFO REPORT==== 28-Jun-2017::13:27:26 ===\nrabbitmq_1 | Starting RabbitMQ 3.6.10 on Erlang 20.0-rc2\nrabbitmq_1 | Copyright (C) 2007-2017 Pivotal Software, Inc.\nrabbitmq_1 | Licensed under the MPL. See http://www.rabbitmq.com/\nrabbitmq_1 |\nrabbitmq_1 | RabbitMQ 3.6.10. Copyright (C) 2007-2017 Pivotal Software, Inc.\nrabbitmq_1 | ## ## Licensed under the MPL. See http://www.rabbitmq.com/\nrabbitmq_1 | ## ##\nrabbitmq_1 | ########## Logs: tty\nrabbitmq_1 | ###### ## tty\nrabbitmq_1 | ##########\nrabbitmq_1 | Starting broker...\nrabbitmq_1 |\nrabbitmq_1 | =INFO REPORT==== 28-Jun-2017::13:27:26 ===\nrabbitmq_1 | node : rabbit@bd20dc3d3d2a\nrabbitmq_1 | home dir : /var/lib/rabbitmq\nrabbitmq_1 | config file(s) : /etc/rabbitmq/rabbitmq.config\nrabbitmq_1 | cookie hash : DTVsmjdKvD5KtH0o/OLVJA==\nrabbitmq_1 | log : tty\nrabbitmq_1 | sasl log : tty\nrabbitmq_1 | database dir : /var/lib/rabbitmq/mnesia/rabbit@bd20dc3d3d2a\n```\n\n```text\ndocker-compose.yml\n```\n\n```text\nConnectException\n```\n\n```text\ndocker-compose up\n```\n\n```text\ndocker-compose.yml\n```\n\n```text\ndocker-machine ip\n```\n\n```text\nspring.rabbitmq.host={docker-machine ip address}\nspring.rabbitmq.port=5672\nspring.rabbitmq.username=guest\nspring.rabbitmq.password=guest\n```\n\n```text\ndocker-compose\n```\n\n```text\napplication.properties\n```\n\n```text\nresources\n```\n\n```text\napplication.properties\n```\n\n```text\ndocker-compose\n```\n\n========================================\n\nComments:\n- Docker is slightly supported in windows (imo). Does docker start a virtual machine, or do you use hyper-v?\n- @Eich, This particular machine is company owned and we are told to use Docker Toolbox so I believe it uses VirtualBox as opposed to the Hyper-V of a full Windows Docker installation.","metadata":{"transformedAt":"2026-08-18T18:33:20.206Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":13,"totalLines":155,"estimatedTokens":1249}}981{"id":"stack-56079302","source":"stackoverflow","questionId":56079302,"title":"Is Publisher Confirms active by default when using MassTransit?","tags":["rabbitmq","masstransit"],"text":"Title: Is Publisher Confirms active by default when using MassTransit?\nTags: rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nI have a simple question, but I can't find evidence on the internet.\n\nI'm connecting to `RabbitMQ` with `MassTransit`, and I just wanted to know if Consumer Acknowledgements and Publisher Confirms is **active** by default if a connection has been made to the broker using `MassTansit`?\n\nIf **active** by default: Where can I find evidence about this?\n\nIf **not active** by default: How can I enable these functionalities?\n\n========================================\n\nCode:\n```text\nRabbitMQ\n```\n\n```text\nMassTransit\n```\n\n```text\nMassTansit\n```\n\n```text\nack\n```\n\n```text\nack\n```\n\n```text\n_error\n```\n\n```text\nFault<T>\n```\n\n========================================\n\nComments:\n- Thanks for the clarification Chris. I couldn't find any documentation as evidence unfortunately. Do you also know how I can disable these functionalities using MassTransit?\n- Yes, it's configurable on the host: github.com/MassTransit/MassTransit/blob/develop/src/…\n- And consumer acknowledgements?\n- I'm not sure what you're asking about consumer acknowledgements, I explained how consumers work in the answer.\n- I'm sorry, is there also a toggle for consumer acks? Can I disable an enable it using MassTransit?\n- No, nor would you need to when using MassTransit. It manages it all for you.","metadata":{"transformedAt":"2026-08-18T18:33:20.206Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":7,"totalLines":53,"estimatedTokens":351}}982{"id":"stack-49770044","source":"stackoverflow","questionId":49770044,"title":"Will rabbitmq server recover messages for queue marked as durable, when rabbitmq-server gets crashed?","tags":["rabbitmq","amqp","messagebroker"],"text":"Title: Will rabbitmq server recover messages for queue marked as durable, when rabbitmq-server gets crashed?\nTags: rabbitmq, amqp, messagebroker\nSource: Stack Overflow\n\nQuestion:\nI am going through the documentation of AMQP given by Rabbitmq official site.\nIt says that \n\n Queue Durability Durable queues are persisted to disk and thus survive\n broker restarts. Queues that are not durable are called transient. Not\n all scenarios and use cases mandate queues to be durable.\n\n \n Durability of a queue does not make messages that are routed to that\n queue durable. If broker is taken down and then brought back up,\n durable queue will be re-declared during broker startup, however, only\n persistent messages will be recovered.\n\nHowever I am confused about following scenarios, when Message broker crashes :-\n\n- Message is delivered to Message Exchange by producer, but not routed to queue marked as durable.\n\n- Message is delivered to Message Exchange by producer, which in turn routes to queue marked as durable, but message is in the queue and not consumed by consumer.\n\n- Message is delivered to Message Exchange by producer, which in turn routes to queue marked as durable, but message is in the queue and consumed by consumer, but no acknowledgement has been send by consumer to the queue.\n\nIn all the above cases, will the messages be available on next start of rabbit-mq server ?\n\nMoreover, the documentation makes distinction between normal message and persistent messages, as only persistent messages will be recovered. What's the difference between both message types ?\n\nThanks in advance.\n\n========================================\n\nComments:\n- Can you refer the link, containing the difference between persistent and non-persistent messages ?\n- What will happen when queue is non-durable and message type is persistent ?\n- Once a message is routed to a non-durable queue it gets deleted from the persistency log file and is not considered persistent anymore. Answer updated.","metadata":{"transformedAt":"2026-08-18T18:33:20.206Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":38,"estimatedTokens":496}}983{"id":"stack-1194081","source":"stackoverflow","questionId":1194081,"title":"Idempotency Barrier for messaging","tags":["java","message-queue","messaging","rabbitmq"],"text":"Title: Idempotency Barrier for messaging\nTags: java, message-queue, messaging, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nA recent presentation I saw regarding RabbitMQ mentioned the use of something called an \"idempotency barrier\" for message de-duplication. Is this just a fancy name for a message conflator or is it something more specific. If so, what exactly is it? A google search yielded results which are mostly related to RabbitMQ, with little explanation of what it was.\n\n========================================\n\nComments:\n- If I understood correctly, your last sentence seems to imply that idempotency is actually a function of the message consumer, rather than the framework. If this is the case, what does it mean for the framework to be indempotent? If the framework allows duplicates to be executed, it would be up to the client to detect duplicates and either ignore them or remain unaffected.\n- In a messaging environment, idempotent behavior can be created in one of two ways. You can encapsulate it into your message, think of tail recursion, or you can have the client implement some caching mechanism as you describe. The caching technique you are thinking of is a conceptually simple technique, but it doesn't scale well, as the cache will need to continually grow as you leave the message consumer running. This could lead to an out of memory condition if there is high throughput through the service.\n- You can implement a sliding window (similar to TCP) if you know what your SLAs are in terms of delayed messages. ie, If you create an SLA that only the last 1000 messages need to be kept in the cache, then you've got bounded memory. This type of arrangement should suffice for most situations as they will have a realistic upper bound for delays - but obviously doesn't allow \"infinite\" delays if you ever had a need for that. Bottom line, figure out your SLAs.","metadata":{"transformedAt":"2026-08-18T18:33:20.206Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":13,"estimatedTokens":473}}984{"id":"stack-45803231","source":"stackoverflow","questionId":45803231,"title":"How to publish messages on RabbitMQ with fanout exchange using Spring Boot","tags":["java","spring","spring-boot","rabbitmq","spring-rabbit"],"text":"Title: How to publish messages on RabbitMQ with fanout exchange using Spring Boot\nTags: java, spring, spring-boot, rabbitmq, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI have the following piece of code that publishes messages onto `RabbitMQ` queues using `fanout exchange`. The `exchange` is getting created but the message cannot be see in `RabbitMQ` queues. I am not seeing any error either.\n\n**BasicApplication.java**\n\n```\n@SpringBootApplication\npublic class BasicApplication {\n\n public static final String QUEUE_NAME_1 = \"helloworld.fanout.q1\";\n public static final String QUEUE_NAME_2 = \"helloworld.fanout.q2\";\n public static final String EXCHANGE_NAME = \"helloworld.fanout.x\";\n\n //here the message ==> xchange ==> queue1, queue2\n @Bean\n public List fanoutBindings() {\n Queue fanoutQueue1 = new Queue(QUEUE_NAME_1, false);\n Queue fanoutQueue2 = new Queue(QUEUE_NAME_2, false);\n FanoutExchange fanoutExchange = new FanoutExchange(EXCHANGE_NAME);\n return Arrays.asList(\n fanoutQueue1,\n fanoutQueue2,\n fanoutExchange,\n bind(fanoutQueue1).to(fanoutExchange),\n BindingBuilder.bind(fanoutQueue2).to(fanoutExchange));\n }\n\n public static void main(String[] args) {\n SpringApplication.run(BasicApplication.class, args).close();\n }\n\n}\n```\n\n**Producer.java**\n\n```\n@Component\npublic class Producer implements CommandLineRunner {\n\n @Autowired\n private RabbitTemplate rabbitTemplate;\n\n @Override\n public void run(String... args) throws Exception {\n this.rabbitTemplate.convertAndSend(EXCHANGE_NAME, \"Hello World !\");\n }\n\n}\n```\n\n========================================\n\nCode:\n```text\n@SpringBootApplication\npublic class BasicApplication {\n\n public static final String QUEUE_NAME_1 = \"helloworld.fanout.q1\";\n public static final String QUEUE_NAME_2 = \"helloworld.fanout.q2\";\n public static final String EXCHANGE_NAME = \"helloworld.fanout.x\";\n\n //here the message ==> xchange ==> queue1, queue2\n @Bean\n public List<Declarable> fanoutBindings() {\n Queue fanoutQueue1 = new Queue(QUEUE_NAME_1, false);\n Queue fanoutQueue2 = new Queue(QUEUE_NAME_2, false);\n FanoutExchange fanoutExchange = new FanoutExchange(EXCHANGE_NAME);\n return Arrays.asList(\n fanoutQueue1,\n fanoutQueue2,\n fanoutExchange,\n bind(fanoutQueue1).to(fanoutExchange),\n BindingBuilder.bind(fanoutQueue2).to(fanoutExchange));\n }\n\n public static void main(String[] args) {\n SpringApplication.run(BasicApplication.class, args).close();\n }\n\n}\n```\n\n```text\n@Component\npublic class Producer implements CommandLineRunner {\n\n @Autowired\n private RabbitTemplate rabbitTemplate;\n\n @Override\n public void run(String... args) throws Exception {\n this.rabbitTemplate.convertAndSend(EXCHANGE_NAME, \"Hello World !\");\n }\n\n}\n```\n\n```text\nRabbitMQ\n```\n\n```text\nfanout exchange\n```\n\n```text\nexchange\n```\n\n```text\nRabbitMQ\n```\n\n```text\nconvertAndSend\n```\n\n```text\nroutingKey\n```\n\n```text\nthis.rabbitTemplate.convertAndSend(EXCHANGE_NAME, \"\", \"Hello World !\");\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.206Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":9,"totalLines":129,"estimatedTokens":765}}985{"id":"stack-36332385","source":"stackoverflow","questionId":36332385,"title":"how to delete all messages from rabbitmq using node library?","tags":["node.js","rabbitmq"],"text":"Title: how to delete all messages from rabbitmq using node library?\nTags: node.js, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI want to delete all the messages from the rabbit mq queue before i start pushing data in it. How can this be achieved ? I am using https://www.npmjs.com/package/amqplib\n\n========================================\n\nTop Answer:\npurge_queue can be used to remove all undelivered messages from the queue named.\n\n```\npurgeQueue(queue, [function(err, ok) {...}])\n```\n\nRemove all undelivered messages from the queue named.messageCount, containing the number of messages purged from the queue is returned.\n\nYou can also do this using command-line:\n\n```\nsudo rabbitmqctl purge_queue queue_name\n```\n\n========================================\n\nCode:\n```text\nchannel.purgeQueue(\"some.queue\");\n```\n\n```text\npurgeQueue\n```\n\n```text\npurgeQueue(queue, [function(err, ok) {...}])\n```\n\n```text\nsudo rabbitmqctl purge_queue queue_name\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.206Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":42,"estimatedTokens":236}}986{"id":"stack-21555958","source":"stackoverflow","questionId":21555958,"title":"Re-queue rabbit AMQP messages at the tail of the queue after max attempts","tags":["spring","rabbitmq","amqp","spring-amqp","spring-rabbit"],"text":"Title: Re-queue rabbit AMQP messages at the tail of the queue after max attempts\nTags: spring, rabbitmq, amqp, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI'm currently using RabbitMQ with spring (spring-rabbit-1.2.0-RELEASE), with the configuration below :\n\n```\n\n \n \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n \n\n \n\n \n\n```\n\nI would like to requeue the message at the tail of the queue after the third attempt. But i don't find a way to perform that.\n\nIs someone has an idea?\n\nThanks in advance for your help.\n\n========================================\n\nTop Answer:\nI used this tip, but then went a slightly different direction by using a deadletter queue. For me, it was more explicit than putting the message at the end of the queue.\n\n```\n\n \n\n \n \n \n \n\n```\n\nOnce you have the dead letter queue in place, you can do whatever you want via another consumer (including adding it back to the original queue.) \n\nI also ended up using the stateless version of the interceptor Gary recommended which allowed me to not have to worry about a message id generator.\n\n```\n\n \n \n\n```\n\n========================================\n\nCode:\n```text\n<rabbit:template id=\"amqpTemplate\" connection-factory=\"connectionFactory\"/>\n<!-- Asynchronous exchanges -->\n<!-- Admin -->\n<rabbit:admin connection-factory=\"connectionFactory\"/>\n\n<!-- Error Handler -->\n<bean id=\"biErrorHandler\" class=\"my.project.sync.BiErrorHandler\" />\n<!-- Message converter -->\n<bean id=\"biMessageConverter\" class=\"my.project.sync.BiMessageConverter\"/>\n\n<bean id=\"retryInterceptor\" class=\"org.springframework.amqp.rabbit.config.StatefulRetryOperationsInterceptorFactoryBean\">\n <property name=\"messageRecoverer\" ref=\"rejectAndDontRequeueRecoverer\"/>\n <property name=\"retryOperations\" ref=\"retryTemplate\" />\n <property name=\"messageKeyGenerator\" ref=\"biKeyGenerator\" />\n</bean> \n\n<bean id=\"biKeyGenerator\" class=\"my.project.sync.BiMessageKeyGenerator\"/>\n<bean id=\"rejectAndDontRequeueRecoverer\" class=\"org.springframework.amqp.rabbit.retry.RejectAndDontRequeueRecoverer\"/>\n\n<bean id=\"retryTemplate\" class=\"org.springframework.retry.support.RetryTemplate\">\n <property name=\"backOffPolicy\">\n <bean class=\"org.springframework.retry.backoff.ExponentialBackOffPolicy\">\n <property name=\"initialInterval\" value=\"3000\" />\n <property name=\"maxInterval\" value=\"30000\" />\n </bean> \n </property>\n <property name=\"retryPolicy\">\n <bean class=\"org.springframework.retry.policy.SimpleRetryPolicy\">\n <property name=\"maxAttempts\" value=\"3\" />\n </bean> \n </property>\n</bean> \n\n <rabbit:queue id=\"biSynchronizationQueue\" name=\"BI_SYNCHRONIZATION_QUEUE\" durable=\"true\" />\n<rabbit:listener-container message-converter=\"biMessageConverter\" concurrency=\"1\" \n connection-factory=\"connectionFactory\"\n error-handler=\"biErrorHandler\"\n advice-chain=\"retryInterceptor\"\n acknowledge=\"auto\">\n <rabbit:listener queues=\"BI_SYNCHRONIZATION_QUEUE\" ref=\"biSynchronizationService\" method=\"handleMessage\"/>\n</rabbit:listener-container>\n```\n\n```text\nRejectAndDontRequeueRecoverer\n```\n\n```text\nMessageRecoverer\n```\n\n```text\nRabbitTemplate\n```\n\n```text\nAmqpRejectAndDontRequeueException\n```\n\n```text\nRejectAndDontRequeueRecoverer\n```\n\n```text\nrecover()\n```\n\n```text\nsuper.recover()\n```\n\n```text\nrecover()\n```\n\n```text\n<rabbit:queue name=\"content.variantchange.queue\" durable=\"true\" queue-arguments=\"queueArguments\"/>\n\n<util:map id=\"queueArguments\">\n <entry key=\"x-dead-letter-exchange\" value=\"content.deadletter.topic\"/>\n</util:map>\n\n <rabbit:fanout-exchange name=\"content.deadletter.topic\">\n <rabbit:bindings>\n <rabbit:binding queue=\"content.deadletter.queue\"/>\n </rabbit:bindings>\n</rabbit:fanout-exchange>\n\n<rabbit:queue name=\"content.deadletter.queue\" durable=\"true\"/>\n```\n\n```text\n<bean id=\"retryInterceptor\" class=\"org.springframework.amqp.rabbit.config.StatelessRetryOperationsInterceptorFactoryBean\">\n <property name=\"messageRecoverer\" ref=\"rejectAndDontRequeueRecoverer\"/>\n <property name=\"retryOperations\" ref=\"retryTemplate\" />\n</bean>\n```\n\n========================================\n\nComments:\n- Thanks Gary I will try it tomorrow and report back !\n- FYI, we added a `RepublishMessageRecoverer` to the upcoming 1.3 release; see the last paragraph here: docs.spring.io/spring-amqp/docs/1.3.0.BUILD-SNAPSHOT/referen‌​ce/…\n- @GaryRussell What do you see as the main benefits of RepublishMessageRecoverer over using a dead letter exchange?\n- Not much difference, really, just an alternative. However, there are a few things: 1. The republished message gets `x-exception-stacktrace` and `x-exception-message` headers. 2. You can route to different exchanges/routing keys based on message content (although that would need a little custom coding - subclass the `RabbitTemplate` and override `send(exchange, key, message)`). 3. You can further modify the message (using the same technique). 4. ... . With the `DLE` the message gets forwarded with some rabbit-specific info in the headers, but no application-level info relating to the failure.\n- Great example... but how could I set this up using annotations and on latest version, where recoverer is expected to be a `MethodInvocationRecoverer` ? This old definition I found written a year ago by @GaryRussell is no longer valid :( `.recoverer(new RejectAndDontRequeueRecoverer())`\n- I suggest you start a new question for this - include your code.","metadata":{"transformedAt":"2026-08-18T18:33:20.206Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":11,"totalLines":177,"estimatedTokens":1363}}987{"id":"stack-40490149","source":"stackoverflow","questionId":40490149,"title":"Get MassTransit message retries amount","tags":["c#","rabbitmq","masstransit"],"text":"Title: Get MassTransit message retries amount\nTags: c#, rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nI'm using Masstransit+RabbitMQ. One of the my consumers implements retry policy and I'm wondering if there any way to get message's retries amout once message is in the error queue?\n\nAlso I would like to know how MT counting retries because I didn't namage to find any related information in message's headers using RabbitMq server.\n\nThanks.\n\n========================================\n\nCode:\n```text\nconsumeContext.GetRetryAttempt()\n```\n\n```text\nMT-Fault-RetryCount\n```\n\n```text\nFault<T>\n```\n\n========================================\n\nComments:\n- Yes, but where this data is stored? In the message's header or somewhere in the middleware?\n- It's maintained in the middleware payload during message processing. It isn't persisted anywhere.\n- @ChrisPatterson: Haven't tried that with RabbitMQ, but with Azure Service Bus or in-memory transports the return value is always 0. Is this a bug? A missing feature? Or does it work for you and I am doing something wrong?\n- Hi guys. Has anyone found a solution? I'm having the same problem. And I dont found anything about it.\n- You might ask on Discord, \"same problem\" is usually close but not enough. Also, it works properly with a recent version of MassTransit so that might be a consideration.","metadata":{"transformedAt":"2026-08-18T18:33:20.206Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":34,"estimatedTokens":338}}988{"id":"stack-28744165","source":"stackoverflow","questionId":28744165,"title":"Spring-amqp two queues with different TTL","tags":["rabbitmq","spring-amqp"],"text":"Title: Spring-amqp two queues with different TTL\nTags: rabbitmq, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nIn our application, we use RabbitMQ and spring-amqp(1.4.3.RELEASE).\nWe have two Queues there. Both of them have TTL(60000 and 100000) configured.\nWhen we start the application, it gives the following errors:\n\n [pool-4-thread-1] ERROR org.springframework.amqp.rabbit.connection.CachingConnectionFactory - Channel shutdown: channel error; protocol method: #method(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'x-message-ttl' for queue 'queue1' in vhost '/': received '60000' but current is '100000', class-id=50, method-id=10)\n\nAnd then an exception is thrown when we try to send message to the queue:\n\n [http-nio-8080-exec-8] ERROR [P181786EJG755SN8I3S74584216UV1] No reply received - perhaps a timeout in the template?\n org.springframework.remoting.RemoteProxyFailureException: No reply received - perhaps a timeout in the template?\n at org.springframework.amqp.remoting.client.AmqpClientInterceptor.invoke(AmqpClientInterceptor.java:60)\n at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)\n at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)\n at com.sun.proxy.$Proxy83.getUserById(Unknown Source)\n\nSearch on the internet gave the following result:\n\nhttp://forum.spring.io/forum/spring-projects/integration/amqp/124865-unexpected-behaviour-with-rabbit-admin\nAnd especially, this bug: https://jira.spring.io/browse/AMQP-266\n\nAfter we have found that bug, we have changed TTL values for both queues to 60000, and Error is not shown anymore. And application is running fine.\nSo, it seems that there is still a bug with TTL.\n\n========================================\n\nTop Answer:\nDmitrii Semenov Response is correct, Just for a suggestion:\n\n\"Try removing queue from rabbitmq-management\"\n\nNOTE: From docker you can access to \"your ip or localhost\":15672\n\nhttps://i.sstatic.net/LJTJX.png\n\nhttps://i.sstatic.net/tBq5M.png\n\nRef:\nhttps://github.com/streadway/amqp/issues/60#issuecomment-18119437\n\n========================================\n\nCode:\n```text\ninequivalent arg 'x-message-ttl' for queue 'your-queue' in vhost '/': received the value '10000' of type 'signedint' but current is none\n```\n\n```text\nrabbitmq\n```\n\n========================================\n\nComments:\n- Haven't you tried to remove those queues from Broker and run your application one more time to populate fresh queues with with those TTL values for them?\n- Yes, I did. After changing settings of the queues, I was completely removing queues from the broker. So that spring-amqp would create fresh queues, taking into account those settings\n- Jira ticket created: jira.spring.io/browse/AMQP-483\n- So if I want to change queue TTL in a queue with content being used I production is impossible if not deleting it? It not makes sense for me. This is a rabbit limitation? Is impossible to change queue arguments of a existent queue?","metadata":{"transformedAt":"2026-08-18T18:33:20.206Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":62,"estimatedTokens":755}}989{"id":"stack-12855332","source":"stackoverflow","questionId":12855332,"title":"How could i pass parameter to pika callback","tags":["python","rabbitmq","pika"],"text":"Title: How could i pass parameter to pika callback\nTags: python, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI use pika to interact with RabbitMQ server as following:\n1. P1 send message to RabbitMQ\n2. C1 is an pyqt4 desktop tray application,which will show the above message once received.\nThe code is as following:\n\n```\nimport sip\nsip.setapi('QVariant', 2)\n\nfrom PyQt4 import QtCore, QtGui\n\nimport systray_rc\n\nclass Window(QtGui.QDialog):\n def __init__(self):\n super(Window, self).__init__()\n\n self.createIconGroupBox()\n self.createMessageGroupBox()\n\n self.iconLabel.setMinimumWidth(self.durationLabel.sizeHint().width())\n\n self.createActions()\n self.createTrayIcon()\n\n self.showMessageButton.clicked.connect(self.showMessage)\n self.showIconCheckBox.toggled.connect(self.trayIcon.setVisible)\n self.iconComboBox.currentIndexChanged.connect(self.setIcon)\n self.trayIcon.messageClicked.connect(self.messageClicked)\n self.trayIcon.activated.connect(self.iconActivated)\n\n mainLayout = QtGui.QVBoxLayout()\n mainLayout.addWidget(self.iconGroupBox)\n mainLayout.addWidget(self.messageGroupBox)\n self.setLayout(mainLayout)\n\n self.iconComboBox.setCurrentIndex(1)\n self.trayIcon.show()\n\n self.setWindowTitle(\"Systray\")\n self.resize(400, 300) \n\n def setVisible(self, visible):\n self.minimizeAction.setEnabled(visible)\n self.maximizeAction.setEnabled(not self.isMaximized())\n self.restoreAction.setEnabled(self.isMaximized() or not visible)\n super(Window, self).setVisible(visible)\n\n def closeEvent(self, event):\n if self.trayIcon.isVisible():\n QtGui.QMessageBox.information(self, \"Systray\",\n \"The program will keep running in the system tray. To \"\n \"terminate the program, choose **Quit** in the \"\n \"context menu of the system tray entry.\")\n self.hide()\n event.ignore()\n\n def setIcon(self, index):\n icon = self.iconComboBox.itemIcon(index)\n self.trayIcon.setIcon(icon)\n self.setWindowIcon(icon)\n\n self.trayIcon.setToolTip(self.iconComboBox.itemText(index))\n\n def iconActivated(self, reason):\n if reason in (QtGui.QSystemTrayIcon.Trigger, QtGui.QSystemTrayIcon.DoubleClick):\n self.iconComboBox.setCurrentIndex(\n (self.iconComboBox.currentIndex() + 1)\n % self.iconComboBox.count())\n elif reason == QtGui.QSystemTrayIcon.MiddleClick:\n self.showMessage()\n\n def showMessage(self):\n icon = QtGui.QSystemTrayIcon.MessageIcon(\n self.typeComboBox.itemData(self.typeComboBox.currentIndex()))\n# self.trayIcon.showMessage(self.titleEdit.text(),\n# self.bodyEdit.toPlainText(), icon,\n# self.durationSpinBox.value() * 1000)\n self.trayIcon.showMessage('stock alarm',\n 'test', icon,\n self.durationSpinBox.value() * 1000)\n\n def messageClicked(self):\n QtGui.QMessageBox.information(None, \"Systray\",\n \"Sorry, I already gave what help I could.\\nMaybe you should \"\n \"try asking a human?\")\n\n def createIconGroupBox(self):\n self.iconGroupBox = QtGui.QGroupBox(\"Tray Icon\")\n\n self.iconLabel = QtGui.QLabel(\"Icon:\")\n\n self.iconComboBox = QtGui.QComboBox()\n self.iconComboBox.addItem(QtGui.QIcon(':/images/bad.svg'), \"Bad\")\n self.iconComboBox.addItem(QtGui.QIcon(':/images/heart.svg'), \"Heart\")\n self.iconComboBox.addItem(QtGui.QIcon(':/images/trash.svg'), \"Trash\")\n\n self.showIconCheckBox = QtGui.QCheckBox(\"Show icon\")\n self.showIconCheckBox.setChecked(True)\n\n iconLayout = QtGui.QHBoxLayout()\n iconLayout.addWidget(self.iconLabel)\n iconLayout.addWidget(self.iconComboBox)\n iconLayout.addStretch()\n iconLayout.addWidget(self.showIconCheckBox)\n self.iconGroupBox.setLayout(iconLayout)\n\n def createMessageGroupBox(self):\n self.messageGroupBox = QtGui.QGroupBox(\"Balloon Message\")\n\n typeLabel = QtGui.QLabel(\"Type:\")\n\n self.typeComboBox = QtGui.QComboBox()\n self.typeComboBox.addItem(\"None\", QtGui.QSystemTrayIcon.NoIcon)\n self.typeComboBox.addItem(self.style().standardIcon(\n QtGui.QStyle.SP_MessageBoxInformation), \"Information\",\n QtGui.QSystemTrayIcon.Information)\n self.typeComboBox.addItem(self.style().standardIcon(\n QtGui.QStyle.SP_MessageBoxWarning), \"Warning\",\n QtGui.QSystemTrayIcon.Warning)\n self.typeComboBox.addItem(self.style().standardIcon(\n QtGui.QStyle.SP_MessageBoxCritical), \"Critical\",\n QtGui.QSystemTrayIcon.Critical)\n self.typeComboBox.setCurrentIndex(1)\n\n self.durationLabel = QtGui.QLabel(\"Duration:\")\n\n self.durationSpinBox = QtGui.QSpinBox()\n self.durationSpinBox.setRange(5, 60)\n self.durationSpinBox.setSuffix(\" s\")\n self.durationSpinBox.setValue(15)\n\n durationWarningLabel = QtGui.QLabel(\"(some systems might ignore this \"\n \"hint)\")\n durationWarningLabel.setIndent(10)\n\n titleLabel = QtGui.QLabel(\"Title:\")\n\n self.titleEdit = QtGui.QLineEdit(\"Cannot connect to network\")\n\n bodyLabel = QtGui.QLabel(\"Body:\")\n\n self.bodyEdit = QtGui.QTextEdit()\n self.bodyEdit.setPlainText(\"Don't believe me. Honestly, I don't have \"\n \"a clue.\\nClick this balloon for details.\")\n\n self.showMessageButton = QtGui.QPushButton(\"Show Message\")\n self.showMessageButton.setDefault(True)\n\n messageLayout = QtGui.QGridLayout()\n messageLayout.addWidget(typeLabel, 0, 0)\n messageLayout.addWidget(self.typeComboBox, 0, 1, 1, 2)\n messageLayout.addWidget(self.durationLabel, 1, 0)\n messageLayout.addWidget(self.durationSpinBox, 1, 1)\n messageLayout.addWidget(durationWarningLabel, 1, 2, 1, 3)\n messageLayout.addWidget(titleLabel, 2, 0)\n messageLayout.addWidget(self.titleEdit, 2, 1, 1, 4)\n messageLayout.addWidget(bodyLabel, 3, 0)\n messageLayout.addWidget(self.bodyEdit, 3, 1, 2, 4)\n messageLayout.addWidget(self.showMessageButton, 5, 4)\n messageLayout.setColumnStretch(3, 1)\n messageLayout.setRowStretch(4, 1)\n self.messageGroupBox.setLayout(messageLayout)\n\n def createActions(self):\n self.minimizeAction = QtGui.QAction(\"Mi&nimize\", self,\n triggered=self.hide)\n\n self.maximizeAction = QtGui.QAction(\"Ma&ximize\", self,\n triggered=self.showMaximized)\n\n self.restoreAction = QtGui.QAction(\"&Restore\", self,\n triggered=self.showNormal)\n\n self.quitAction = QtGui.QAction(\"&Quit\", self,\n triggered=QtGui.qApp.quit)\n\n def createTrayIcon(self):\n self.trayIconMenu = QtGui.QMenu(self)\n self.trayIconMenu.addAction(self.minimizeAction)\n self.trayIconMenu.addAction(self.maximizeAction)\n self.trayIconMenu.addAction(self.restoreAction)\n self.trayIconMenu.addSeparator()\n self.trayIconMenu.addAction(self.quitAction)\n\n self.trayIcon = QtGui.QSystemTrayIcon(self)\n self.trayIcon.setContextMenu(self.trayIconMenu)\n\ndef callback(ch, method, properties, body):\n print \" [x] %r:%r\" % (method.routing_key, body,)\n #window.showMessage = body\n #window.showMessage()\n #self.showMessage()\n\ndef subsribeRabbit():\n import pika\n import sys\n from util import settings\n\n connection = pika.BlockingConnection(pika.ConnectionParameters(\n host=settings.RABBIT_SERVER))\n channel = connection.channel()\n\n channel.exchange_declare(exchange=settings.STOCK_ALARMS_TOPIC,\n type='topic')\n\n result = channel.queue_declare(exclusive=True)\n queue_name = result.method.queue\n\n binding_keys = '#'\n\n for binding_key in binding_keys:\n channel.queue_bind(exchange=settings.STOCK_ALARMS_TOPIC,\n queue=queue_name,\n routing_key=binding_key)\n\n print ' [*] Waiting for logs. To exit press CTRL+C'\n\n channel.basic_consume(callback,\n queue=queue_name,\n no_ack=True)\n\n channel.start_consuming()\n\nif __name__ == '__main__':\n\n import sys\n from cron.realtimemonitorschedule import startMonitor \n\n app = QtGui.QApplication(sys.argv)\n\n if not QtGui.QSystemTrayIcon.isSystemTrayAvailable():\n QtGui.QMessageBox.critical(None, \"Systray\",\n \"I couldn't detect any system tray on this system.\")\n sys.exit(1)\n\n QtGui.QApplication.setQuitOnLastWindowClosed(False)\n\n window = Window()\n window.show() \n from threading import Thread\n thread = Thread(target = subsribeRabbit)\n thread.start()\n #thread.join()\n\n sys.exit(app.exec_())\n```\n\nThe question is that how could i call window.showMessage in the callback() function?Thanks in advance, i'm new to both Python and RabbitMQ.\n\n========================================\n\nTop Answer:\n*Note: This answer is using python3 so the syntax may be slightly different than the answers from three years ago.*\n\nA better answer is to wrap your callback in a lambda. Then you can pass whatever you want so long as it is accessible when you call `basic_consume`.\n\nFirst change your callback to just take the stuff you are interested in. (You could also refactor this into a class and pass in `self`.)\n\n```\ndef on_message(window, method, body):\n print(\" [x] %r:%r\" % (method.routing_key, body), end=\"\")\n```\n\nthen to consume...\n\n```\nchannel.basic_consume(on_message_callback=lambda ch, method, properties, body: on_message(window, method, body),\n queue=queue_name,\n no_ack=True)\n```\n\n========================================\n\nCode:\n```text\nimport sip\nsip.setapi('QVariant', 2)\n\nfrom PyQt4 import QtCore, QtGui\n\nimport systray_rc\n\n\nclass Window(QtGui.QDialog):\n def __init__(self):\n super(Window, self).__init__()\n\n self.createIconGroupBox()\n self.createMessageGroupBox()\n\n self.iconLabel.setMinimumWidth(self.durationLabel.sizeHint().width())\n\n self.createActions()\n self.createTrayIcon()\n\n self.showMessageButton.clicked.connect(self.showMessage)\n self.showIconCheckBox.toggled.connect(self.trayIcon.setVisible)\n self.iconComboBox.currentIndexChanged.connect(self.setIcon)\n self.trayIcon.messageClicked.connect(self.messageClicked)\n self.trayIcon.activated.connect(self.iconActivated)\n\n mainLayout = QtGui.QVBoxLayout()\n mainLayout.addWidget(self.iconGroupBox)\n mainLayout.addWidget(self.messageGroupBox)\n self.setLayout(mainLayout)\n\n self.iconComboBox.setCurrentIndex(1)\n self.trayIcon.show()\n\n self.setWindowTitle(\"Systray\")\n self.resize(400, 300) \n\n\n\n def setVisible(self, visible):\n self.minimizeAction.setEnabled(visible)\n self.maximizeAction.setEnabled(not self.isMaximized())\n self.restoreAction.setEnabled(self.isMaximized() or not visible)\n super(Window, self).setVisible(visible)\n\n def closeEvent(self, event):\n if self.trayIcon.isVisible():\n QtGui.QMessageBox.information(self, \"Systray\",\n \"The program will keep running in the system tray. To \"\n \"terminate the program, choose <b>Quit</b> in the \"\n \"context menu of the system tray entry.\")\n self.hide()\n event.ignore()\n\n def setIcon(self, index):\n icon = self.iconComboBox.itemIcon(index)\n self.trayIcon.setIcon(icon)\n self.setWindowIcon(icon)\n\n self.trayIcon.setToolTip(self.iconComboBox.itemText(index))\n\n def iconActivated(self, reason):\n if reason in (QtGui.QSystemTrayIcon.Trigger, QtGui.QSystemTrayIcon.DoubleClick):\n self.iconComboBox.setCurrentIndex(\n (self.iconComboBox.currentIndex() + 1)\n % self.iconComboBox.count())\n elif reason == QtGui.QSystemTrayIcon.MiddleClick:\n self.showMessage()\n\n def showMessage(self):\n icon = QtGui.QSystemTrayIcon.MessageIcon(\n self.typeComboBox.itemData(self.typeComboBox.currentIndex()))\n# self.trayIcon.showMessage(self.titleEdit.text(),\n# self.bodyEdit.toPlainText(), icon,\n# self.durationSpinBox.value() * 1000)\n self.trayIcon.showMessage('stock alarm',\n 'test', icon,\n self.durationSpinBox.value() * 1000)\n\n def messageClicked(self):\n QtGui.QMessageBox.information(None, \"Systray\",\n \"Sorry, I already gave what help I could.\\nMaybe you should \"\n \"try asking a human?\")\n\n def createIconGroupBox(self):\n self.iconGroupBox = QtGui.QGroupBox(\"Tray Icon\")\n\n self.iconLabel = QtGui.QLabel(\"Icon:\")\n\n self.iconComboBox = QtGui.QComboBox()\n self.iconComboBox.addItem(QtGui.QIcon(':/images/bad.svg'), \"Bad\")\n self.iconComboBox.addItem(QtGui.QIcon(':/images/heart.svg'), \"Heart\")\n self.iconComboBox.addItem(QtGui.QIcon(':/images/trash.svg'), \"Trash\")\n\n self.showIconCheckBox = QtGui.QCheckBox(\"Show icon\")\n self.showIconCheckBox.setChecked(True)\n\n iconLayout = QtGui.QHBoxLayout()\n iconLayout.addWidget(self.iconLabel)\n iconLayout.addWidget(self.iconComboBox)\n iconLayout.addStretch()\n iconLayout.addWidget(self.showIconCheckBox)\n self.iconGroupBox.setLayout(iconLayout)\n\n def createMessageGroupBox(self):\n self.messageGroupBox = QtGui.QGroupBox(\"Balloon Message\")\n\n typeLabel = QtGui.QLabel(\"Type:\")\n\n self.typeComboBox = QtGui.QComboBox()\n self.typeComboBox.addItem(\"None\", QtGui.QSystemTrayIcon.NoIcon)\n self.typeComboBox.addItem(self.style().standardIcon(\n QtGui.QStyle.SP_MessageBoxInformation), \"Information\",\n QtGui.QSystemTrayIcon.Information)\n self.typeComboBox.addItem(self.style().standardIcon(\n QtGui.QStyle.SP_MessageBoxWarning), \"Warning\",\n QtGui.QSystemTrayIcon.Warning)\n self.typeComboBox.addItem(self.style().standardIcon(\n QtGui.QStyle.SP_MessageBoxCritical), \"Critical\",\n QtGui.QSystemTrayIcon.Critical)\n self.typeComboBox.setCurrentIndex(1)\n\n self.durationLabel = QtGui.QLabel(\"Duration:\")\n\n self.durationSpinBox = QtGui.QSpinBox()\n self.durationSpinBox.setRange(5, 60)\n self.durationSpinBox.setSuffix(\" s\")\n self.durationSpinBox.setValue(15)\n\n durationWarningLabel = QtGui.QLabel(\"(some systems might ignore this \"\n \"hint)\")\n durationWarningLabel.setIndent(10)\n\n titleLabel = QtGui.QLabel(\"Title:\")\n\n self.titleEdit = QtGui.QLineEdit(\"Cannot connect to network\")\n\n bodyLabel = QtGui.QLabel(\"Body:\")\n\n self.bodyEdit = QtGui.QTextEdit()\n self.bodyEdit.setPlainText(\"Don't believe me. Honestly, I don't have \"\n \"a clue.\\nClick this balloon for details.\")\n\n self.showMessageButton = QtGui.QPushButton(\"Show Message\")\n self.showMessageButton.setDefault(True)\n\n messageLayout = QtGui.QGridLayout()\n messageLayout.addWidget(typeLabel, 0, 0)\n messageLayout.addWidget(self.typeComboBox, 0, 1, 1, 2)\n messageLayout.addWidget(self.durationLabel, 1, 0)\n messageLayout.addWidget(self.durationSpinBox, 1, 1)\n messageLayout.addWidget(durationWarningLabel, 1, 2, 1, 3)\n messageLayout.addWidget(titleLabel, 2, 0)\n messageLayout.addWidget(self.titleEdit, 2, 1, 1, 4)\n messageLayout.addWidget(bodyLabel, 3, 0)\n messageLayout.addWidget(self.bodyEdit, 3, 1, 2, 4)\n messageLayout.addWidget(self.showMessageButton, 5, 4)\n messageLayout.setColumnStretch(3, 1)\n messageLayout.setRowStretch(4, 1)\n self.messageGroupBox.setLayout(messageLayout)\n\n def createActions(self):\n self.minimizeAction = QtGui.QAction(\"Mi&nimize\", self,\n triggered=self.hide)\n\n self.maximizeAction = QtGui.QAction(\"Ma&ximize\", self,\n triggered=self.showMaximized)\n\n self.restoreAction = QtGui.QAction(\"&Restore\", self,\n triggered=self.showNormal)\n\n self.quitAction = QtGui.QAction(\"&Quit\", self,\n triggered=QtGui.qApp.quit)\n\n def createTrayIcon(self):\n self.trayIconMenu = QtGui.QMenu(self)\n self.trayIconMenu.addAction(self.minimizeAction)\n self.trayIconMenu.addAction(self.maximizeAction)\n self.trayIconMenu.addAction(self.restoreAction)\n self.trayIconMenu.addSeparator()\n self.trayIconMenu.addAction(self.quitAction)\n\n self.trayIcon = QtGui.QSystemTrayIcon(self)\n self.trayIcon.setContextMenu(self.trayIconMenu)\n\ndef callback(ch, method, properties, body):\n print \" [x] %r:%r\" % (method.routing_key, body,)\n #window.showMessage = body\n #window.showMessage()\n #self.showMessage()\n\ndef subsribeRabbit():\n import pika\n import sys\n from util import settings\n\n connection = pika.BlockingConnection(pika.ConnectionParameters(\n host=settings.RABBIT_SERVER))\n channel = connection.channel()\n\n channel.exchange_declare(exchange=settings.STOCK_ALARMS_TOPIC,\n type='topic')\n\n result = channel.queue_declare(exclusive=True)\n queue_name = result.method.queue\n\n binding_keys = '#'\n\n for binding_key in binding_keys:\n channel.queue_bind(exchange=settings.STOCK_ALARMS_TOPIC,\n queue=queue_name,\n routing_key=binding_key)\n\n print ' [*] Waiting for logs. To exit press CTRL+C'\n\n\n channel.basic_consume(callback,\n queue=queue_name,\n no_ack=True)\n\n channel.start_consuming()\n\nif __name__ == '__main__':\n\n import sys\n from cron.realtimemonitorschedule import startMonitor \n\n app = QtGui.QApplication(sys.argv)\n\n if not QtGui.QSystemTrayIcon.isSystemTrayAvailable():\n QtGui.QMessageBox.critical(None, \"Systray\",\n \"I couldn't detect any system tray on this system.\")\n sys.exit(1)\n\n QtGui.QApplication.setQuitOnLastWindowClosed(False)\n\n window = Window()\n window.show() \n from threading import Thread\n thread = Thread(target = subsribeRabbit)\n thread.start()\n #thread.join()\n\n sys.exit(app.exec_())\n```\n\n```text\nimport sip\nsip.setapi('QVariant', 2)\n\nfrom PyQt4 import QtCore, QtGui\n\nimport systray_rc\n\nwindow = Window()\nwindow.show() \n\nclass Window(QtGui.QDialog):\n def __init__(self):\n super(Window, self).__init__()\n\n self.createIconGroupBox()\n self.createMessageGroupBox()\n\n self.iconLabel.setMinimumWidth(self.durationLabel.sizeHint().width())\n\n self.createActions()\n self.createTrayIcon()\n\n self.showMessageButton.clicked.connect(self.showMessage)\n self.showIconCheckBox.toggled.connect(self.trayIcon.setVisible)\n self.iconComboBox.currentIndexChanged.connect(self.setIcon)\n self.trayIcon.messageClicked.connect(self.messageClicked)\n self.trayIcon.activated.connect(self.iconActivated)\n\n mainLayout = QtGui.QVBoxLayout()\n mainLayout.addWidget(self.iconGroupBox)\n mainLayout.addWidget(self.messageGroupBox)\n self.setLayout(mainLayout)\n\n self.iconComboBox.setCurrentIndex(1)\n self.trayIcon.show()\n\n self.setWindowTitle(\"Systray\")\n self.resize(400, 300) \n\n\n\n def setVisible(self, visible):\n self.minimizeAction.setEnabled(visible)\n self.maximizeAction.setEnabled(not self.isMaximized())\n self.restoreAction.setEnabled(self.isMaximized() or not visible)\n super(Window, self).setVisible(visible)\n\n def closeEvent(self, event):\n if self.trayIcon.isVisible():\n QtGui.QMessageBox.information(self, \"Systray\",\n \"The program will keep running in the system tray. To \"\n \"terminate the program, choose <b>Quit</b> in the \"\n \"context menu of the system tray entry.\")\n self.hide()\n event.ignore()\n\n def setIcon(self, index):\n icon = self.iconComboBox.itemIcon(index)\n self.trayIcon.setIcon(icon)\n self.setWindowIcon(icon)\n\n self.trayIcon.setToolTip(self.iconComboBox.itemText(index))\n\n def iconActivated(self, reason):\n if reason in (QtGui.QSystemTrayIcon.Trigger, QtGui.QSystemTrayIcon.DoubleClick):\n self.iconComboBox.setCurrentIndex(\n (self.iconComboBox.currentIndex() + 1)\n % self.iconComboBox.count())\n elif reason == QtGui.QSystemTrayIcon.MiddleClick:\n self.showMessage()\n\n def showMessage(self,text='test'):\n icon = QtGui.QSystemTrayIcon.MessageIcon(\n self.typeComboBox.itemData(self.typeComboBox.currentIndex()))\n# self.trayIcon.showMessage(self.titleEdit.text(),\n# self.bodyEdit.toPlainText(), icon,\n# self.durationSpinBox.value() * 1000)\n self.trayIcon.showMessage('stock alarm',\n 'test', icon,\n self.durationSpinBox.value() * 1000)\n\n def messageClicked(self):\n QtGui.QMessageBox.information(None, \"Systray\",\n \"Sorry, I already gave what help I could.\\nMaybe you should \"\n \"try asking a human?\")\n\n def createIconGroupBox(self):\n self.iconGroupBox = QtGui.QGroupBox(\"Tray Icon\")\n\n self.iconLabel = QtGui.QLabel(\"Icon:\")\n\n self.iconComboBox = QtGui.QComboBox()\n self.iconComboBox.addItem(QtGui.QIcon(':/images/bad.svg'), \"Bad\")\n self.iconComboBox.addItem(QtGui.QIcon(':/images/heart.svg'), \"Heart\")\n self.iconComboBox.addItem(QtGui.QIcon(':/images/trash.svg'), \"Trash\")\n\n self.showIconCheckBox = QtGui.QCheckBox(\"Show icon\")\n self.showIconCheckBox.setChecked(True)\n\n iconLayout = QtGui.QHBoxLayout()\n iconLayout.addWidget(self.iconLabel)\n iconLayout.addWidget(self.iconComboBox)\n iconLayout.addStretch()\n iconLayout.addWidget(self.showIconCheckBox)\n self.iconGroupBox.setLayout(iconLayout)\n\n def createMessageGroupBox(self):\n self.messageGroupBox = QtGui.QGroupBox(\"Balloon Message\")\n\n typeLabel = QtGui.QLabel(\"Type:\")\n\n self.typeComboBox = QtGui.QComboBox()\n self.typeComboBox.addItem(\"None\", QtGui.QSystemTrayIcon.NoIcon)\n self.typeComboBox.addItem(self.style().standardIcon(\n QtGui.QStyle.SP_MessageBoxInformation), \"Information\",\n QtGui.QSystemTrayIcon.Information)\n self.typeComboBox.addItem(self.style().standardIcon(\n QtGui.QStyle.SP_MessageBoxWarning), \"Warning\",\n QtGui.QSystemTrayIcon.Warning)\n self.typeComboBox.addItem(self.style().standardIcon(\n QtGui.QStyle.SP_MessageBoxCritical), \"Critical\",\n QtGui.QSystemTrayIcon.Critical)\n self.typeComboBox.setCurrentIndex(1)\n\n self.durationLabel = QtGui.QLabel(\"Duration:\")\n\n self.durationSpinBox = QtGui.QSpinBox()\n self.durationSpinBox.setRange(5, 60)\n self.durationSpinBox.setSuffix(\" s\")\n self.durationSpinBox.setValue(15)\n\n durationWarningLabel = QtGui.QLabel(\"(some systems might ignore this \"\n \"hint)\")\n durationWarningLabel.setIndent(10)\n\n titleLabel = QtGui.QLabel(\"Title:\")\n\n self.titleEdit = QtGui.QLineEdit(\"Cannot connect to network\")\n\n bodyLabel = QtGui.QLabel(\"Body:\")\n\n self.bodyEdit = QtGui.QTextEdit()\n self.bodyEdit.setPlainText(\"Don't believe me. Honestly, I don't have \"\n \"a clue.\\nClick this balloon for details.\")\n\n self.showMessageButton = QtGui.QPushButton(\"Show Message\")\n self.showMessageButton.setDefault(True)\n\n messageLayout = QtGui.QGridLayout()\n messageLayout.addWidget(typeLabel, 0, 0)\n messageLayout.addWidget(self.typeComboBox, 0, 1, 1, 2)\n messageLayout.addWidget(self.durationLabel, 1, 0)\n messageLayout.addWidget(self.durationSpinBox, 1, 1)\n messageLayout.addWidget(durationWarningLabel, 1, 2, 1, 3)\n messageLayout.addWidget(titleLabel, 2, 0)\n messageLayout.addWidget(self.titleEdit, 2, 1, 1, 4)\n messageLayout.addWidget(bodyLabel, 3, 0)\n messageLayout.addWidget(self.bodyEdit, 3, 1, 2, 4)\n messageLayout.addWidget(self.showMessageButton, 5, 4)\n messageLayout.setColumnStretch(3, 1)\n messageLayout.setRowStretch(4, 1)\n self.messageGroupBox.setLayout(messageLayout)\n\n def createActions(self):\n self.minimizeAction = QtGui.QAction(\"Mi&nimize\", self,\n triggered=self.hide)\n\n self.maximizeAction = QtGui.QAction(\"Ma&ximize\", self,\n triggered=self.showMaximized)\n\n self.restoreAction = QtGui.QAction(\"&Restore\", self,\n triggered=self.showNormal)\n\n self.quitAction = QtGui.QAction(\"&Quit\", self,\n triggered=QtGui.qApp.quit)\n\n def createTrayIcon(self):\n self.trayIconMenu = QtGui.QMenu(self)\n self.trayIconMenu.addAction(self.minimizeAction)\n self.trayIconMenu.addAction(self.maximizeAction)\n self.trayIconMenu.addAction(self.restoreAction)\n self.trayIconMenu.addSeparator()\n self.trayIconMenu.addAction(self.quitAction)\n\n self.trayIcon = QtGui.QSystemTrayIcon(self)\n self.trayIcon.setContextMenu(self.trayIconMenu)\n\ndef callback(ch, method, properties, body):\n print \" [x] %r:%r\" % (method.routing_key, body,)\n window.showMessage(body)\n\n\ndef subsribeRabbit():\n import pika\n import sys\n from util import settings\n\n connection = pika.BlockingConnection(pika.ConnectionParameters(\n host=settings.RABBIT_SERVER))\n channel = connection.channel()\n\n channel.exchange_declare(exchange=settings.STOCK_ALARMS_TOPIC,\n type='topic')\n\n result = channel.queue_declare(exclusive=True)\n queue_name = result.method.queue\n\n binding_keys = '#'\n\n for binding_key in binding_keys:\n channel.queue_bind(exchange=settings.STOCK_ALARMS_TOPIC,\n queue=queue_name,\n routing_key=binding_key)\n\n print ' [*] Waiting for logs. To exit press CTRL+C'\n\n\n channel.basic_consume(callback,\n queue=queue_name,\n no_ack=True)\n\n channel.start_consuming()\n\nif __name__ == '__main__':\n\n import sys\n from cron.realtimemonitorschedule import startMonitor \n\n app = QtGui.QApplication(sys.argv)\n\n if not QtGui.QSystemTrayIcon.isSystemTrayAvailable():\n QtGui.QMessageBox.critical(None, \"Systray\",\n \"I couldn't detect any system tray on this system.\")\n sys.exit(1)\n\n QtGui.QApplication.setQuitOnLastWindowClosed(False)\n\n\n from threading import Thread\n thread = Thread(target = subsribeRabbit)\n thread.start()\n #thread.join()\n\n sys.exit(app.exec_())\n```\n\n```text\ncallback = classObject(additional_paramters)\n\nchannel.basic_consume(callback.method,\n queue=queue_name,\n no_ack=True)\n```\n\n```text\ndef on_message(window, method, body):\n print(\" [x] %r:%r\" % (method.routing_key, body), end=\"\")\n```\n\n```text\nchannel.basic_consume(on_message_callback=lambda ch, method, properties, body: on_message(window, method, body),\n queue=queue_name,\n no_ack=True)\n```\n\n```text\nbasic_consume\n```\n\n```text\nself\n```\n\n========================================\n\nComments:\n- Please trim down your code to the minimum needed to reproduce the problem. As it is now, people will have a hard time understanding your question and helping you.","metadata":{"transformedAt":"2026-08-18T18:33:20.207Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":805,"estimatedTokens":6693}}990{"id":"stack-73745853","source":"stackoverflow","questionId":73745853,"title":"Celery send_task() method","tags":["python","redis","rabbitmq","celery"],"text":"Title: Celery send_task() method\nTags: python, redis, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI have my API, and some endpoints need to forward requests to Celery. Idea is to have specific API service that basically only instantiates Celery client and uses send_task() method, and seperate service(workers) that consume tasks. Code for task definitions should be located in that worker service. Basicaly seperating celery app (API) and celery worker to two seperate services.\nI dont want my API to know about any celery task definitions, endpoints only need to use `celery_client.send_task('some_task', (some_arguments))`. So on one service i have my API, an on other service/host I have celery code base where my celery worker will execute tasks.\n\nI came across this great article that describes what I want to do.\nhttps://medium.com/@tanchinhiong/separating-celery-application-and-worker-in-docker-containers-f70fedb1ba6d\nand this post Celery - How to send task from remote machine?\n\nI need help on how to create routes for tasks from the API? I was expecting for `celery_client.send_task()` to have `queue=` keyword, but it does not. I need to have 2 queues, and two workers that will consume content from these two queues.\n\nCommands for my workers:\n\n```\ncelery -A .celery_client worker --loglevel=info -Q queue_1\ncelery -A .celery_client worker --loglevel=info -Q queue_2\n```\n\nI have also visited celery \"Routing Tasks\" documentation, but it is still unclear to me how to establish this communication.\n\n========================================\n\nTop Answer:\nCelery does have a `queue` parameter for `send_task()` because it takes the same kwargs as `apply_async()`\n\nhttps://docs.celeryq.dev/en/stable/reference/celery.html#celery.Celery.send_task\nhttps://docs.celeryq.dev/en/stable/reference/celery.app.task.html#celery.app.task.Task.apply_async\n\n```\ncelery_client.send_task(\n 'some_task',\n args=(some_arguments,),\n queue='your_queue'\n)\n```\n\n========================================\n\nCode:\n```text\ncelery -A <path_to_my_celery_file>.celery_client worker --loglevel=info -Q queue_1\ncelery -A <path_to_my_celery_file>.celery_client worker --loglevel=info -Q queue_2\n```\n\n```text\ncelery_client.send_task('some_task', (some_arguments))\n```\n\n```text\ncelery_client.send_task()\n```\n\n```text\nqueue=\n```\n\n```text\ntask_routes = {\n 'mytasks.some_task': 'queue_1',\n 'mytasks.some_other_task': 'queue_2',\n}\n```\n\n```text\ntask1\n```\n\n```text\nqueue1\n```\n\n```text\ncelery_client\n```\n\n```text\ncelery_client.send_task(\n 'some_task',\n args=(some_arguments,),\n queue='your_queue'\n)\n```\n\n```text\nqueue\n```\n\n```text\nsend_task()\n```\n\n```text\napply_async()\n```\n\n========================================\n\nComments:\n- @mehekek did it answer your question?\n- Yes, thank you so much! (SO deleted my comment)\n- @mehekek you can thank me by upvoting & accepting the answer ;)","metadata":{"transformedAt":"2026-08-18T18:33:20.207Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":104,"estimatedTokens":718}}991{"id":"stack-50234800","source":"stackoverflow","questionId":50234800,"title":"RabbitMQ queue and routing key","tags":["java","spring","rabbitmq","queue"],"text":"Title: RabbitMQ queue and routing key\nTags: java, spring, rabbitmq, queue\nSource: Stack Overflow\n\nQuestion:\nIn documentation\nhttps://docs.spring.io/spring-amqp/reference/htmlsingle/\ni see \n\n```\n@RabbitListener(bindings = @QueueBinding(\n value = @Queue(value = \"myQueue\", durable = \"true\"),\n exchange = @Exchange(value = \"auto.exch\", ignoreDeclarationExceptions = \"true\"),\n key = \"orderRoutingKey\")\n )\n public void processOrder(Order order) {\n\n }\n\n @RabbitListener(bindings = @QueueBinding(\n value = @Queue,\n exchange = @Exchange(value = \"auto.exch\"),\n key = \"invoiceRoutingKey\")\n )\n public void processInvoice(Invoice invoice) {\n\n }\n```\n\nHere 1 queue and 2 another routing keys, everyone for his method\nBut my code doesn't get message from key!\n\n```\n@RabbitListener(bindings = @QueueBinding(\n value = @Queue(value = DRIVER_QUEUE, durable = \"true\"),\n exchange = @Exchange(value = \"exchange\", ignoreDeclarationExceptions = \"true\", autoDelete = \"true\"),\n key = \"order\")\n )\n public String getOrders(byte[] message) throws InterruptedException {\n System.out.println(\"Rout order\");\n }\n\n @RabbitListener(bindings = @QueueBinding(\n value = @Queue(value = DRIVER_QUEUE, durable = \"true\"),\n exchange = @Exchange(value = \"exchange\", ignoreDeclarationExceptions = \"true\", autoDelete = \"true\"),\n key = \"invoice\")\n )\n public String getOrders(byte[] message) throws InterruptedException {\n System.out.println(\"Rout invoice\");\n }\n```\n\nthey all get message from queue and not see key...\nsite send in queue message with key \"invoice\" and i see in console \"Route order\"\nWhats problem?? Thank a lot!\n\nrabbitmq 3.7.3\nspring 4.2.9\norg.springframework.amqp 1.7.5\n\n========================================\n\nCode:\n```text\n@RabbitListener(bindings = @QueueBinding(\n value = @Queue(value = \"myQueue\", durable = \"true\"),\n exchange = @Exchange(value = \"auto.exch\", ignoreDeclarationExceptions = \"true\"),\n key = \"orderRoutingKey\")\n )\n public void processOrder(Order order) {\n\n }\n\n @RabbitListener(bindings = @QueueBinding(\n value = @Queue,\n exchange = @Exchange(value = \"auto.exch\"),\n key = \"invoiceRoutingKey\")\n )\n public void processInvoice(Invoice invoice) {\n\n }\n```\n\n```text\n@RabbitListener(bindings = @QueueBinding(\n value = @Queue(value = DRIVER_QUEUE, durable = \"true\"),\n exchange = @Exchange(value = \"exchange\", ignoreDeclarationExceptions = \"true\", autoDelete = \"true\"),\n key = \"order\")\n )\n public String getOrders(byte[] message) throws InterruptedException {\n System.out.println(\"Rout order\");\n }\n\n @RabbitListener(bindings = @QueueBinding(\n value = @Queue(value = DRIVER_QUEUE, durable = \"true\"),\n exchange = @Exchange(value = \"exchange\", ignoreDeclarationExceptions = \"true\", autoDelete = \"true\"),\n key = \"invoice\")\n )\n public String getOrders(byte[] message) throws InterruptedException {\n System.out.println(\"Rout invoice\");\n }\n```\n\n```text\n@RabbitListener(queues = \"queue-orders\")\npublic void handleOrders(@Payload Order in,\n @Header(AmqpHeaders.RECEIVED_ROUTING_KEY) String key) {\n logger.info(\"Key: {}, msg: {}\",key,in.toString());\n}\n\n\n@RabbitListener(queues = \"queue-invoices\")\npublic void handleInvoices(@Payload Invoice in, \n @Header(AmqpHeaders.RECEIVED_ROUTING_KEY) String key) {\n logger.info(\"Key: {}, msg: {}\",key,in.toString());\n}\n```\n\n```text\n@RabbitListener(bindings = @QueueBinding(\n value = @Queue(value = \"queue-orders\", durable = \"true\"),\n exchange = @Exchange(value = \"exchange\", ignoreDeclarationExceptions = \"true\", autoDelete = \"true\"),\n key = \"invoice\")\n)\n```\n\n```text\nOrder order = new Order(...);\nrabbitTemplate.convertAndSend(\"exchange\", \"order\", order);\nInvoice invoice = new Invoice(...);\nrabbitTemplate.convertAndSent(\"exchange\", \"invoice\", invoice);\n```\n\n```text\n@SpringBootApplication\npublic class MyApplication implements RabbitListenerConfigurer {\n // other config stuff here....\n\n @Bean(\"queue1\")\n public Queue queue1() {\n return new Queue(\"queue-orders\", true);\n }\n\n @Bean(\"queue2\")\n public Queue queue2() {\n return new Queue(\"queue-invoices\", true);\n }\n\n @Bean\n public Binding binding1(@Qualifier(\"queue1\") Queue queue, TopicExchange exchange) { \n return BindingBuilder.bind(queue).to(exchange).with(\"invoice\");\n }\n\n @Bean\n public Binding binding2(@Qualifier(\"queue2\") Queue queue, TopicExchange exchange) { \n return BindingBuilder.bind(queue).to(exchange).with(\"order\");\n }\n\n @Bean\n public RabbitTemplate rabbitTemplate(final ConnectionFactory connectionFactory) {\n final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);\n rabbitTemplate.setMessageConverter(producerJackson2MessageConverter());\n return rabbitTemplate;\n }\n\n @Bean\n public Jackson2JsonMessageConverter producerJackson2MessageConverter() {\n return new Jackson2JsonMessageConverter();\n }\n\n @Bean\n public DefaultMessageHandlerMethodFactory messageHandlerMethodFactory() {\n DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();\n factory.setMessageConverter(consumerJackson2MessageConverter());\n return factory;\n }\n\n @Override\n public void configureRabbitListeners(final RabbitListenerEndpointRegistrar registrar) {\n registrar.setMessageHandlerMethodFactory(messageHandlerMethodFactory());\n }\n\n // Exchange.\n @Bean\n public TopicExchange exchange() {\n return new TopicExchange(\"exchange\");\n }\n}\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.207Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":189,"estimatedTokens":1402}}992{"id":"stack-50672590","source":"stackoverflow","questionId":50672590,"title":"Spring - Rabbit template - Bulk operation","tags":["rabbitmq","spring-rabbit"],"text":"Title: Spring - Rabbit template - Bulk operation\nTags: rabbitmq, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nAnyone knows if it is possible to send a collection of messages to a queue using Rabbit template?\n\nObviously I can send them one at a time, but I want to do it in a single bulk operation (to gain performance).\n\nThanks!\n\n========================================\n\nTop Answer:\nYou can create a bean of `BatchingRabbitTemplate` and use it. Here is a working example bean:\n\n```\n@Bean\npublic BatchingRabbitTemplate batchingRabbitTemplate(ConnectionFactory connectionFactory) {\n BatchingStrategy strategy = new SimpleBatchingStrategy(500, 25_000, 3_000);\n TaskScheduler scheduler = new ConcurrentTaskScheduler();\n BatchingRabbitTemplate template = new BatchingRabbitTemplate(strategy, scheduler);\n template.setConnectionFactory(connectionFactory);\n // ... other settings\n return template;\n}\n```\n\nNow you can inject `BatchingRabbitTemplate` in another bean and use it:\n\n```\n@Bean\npublic ApplicationRunner runner(BatchingRabbitTemplate template) {\n MessageProperties props = //...\n return args -> template.send(new Message(\"Test\").getBytes(), props);\n}\n```\n\n========================================\n\nCode:\n```text\n@Bean\npublic BatchingRabbitTemplate batchingRabbitTemplate(ConnectionFactory connectionFactory) {\n BatchingStrategy strategy = new SimpleBatchingStrategy(500, 25_000, 3_000);\n TaskScheduler scheduler = new ConcurrentTaskScheduler();\n BatchingRabbitTemplate template = new BatchingRabbitTemplate(strategy, scheduler);\n template.setConnectionFactory(connectionFactory);\n // ... other settings\n return template;\n}\n```\n\n```text\n@Bean\npublic ApplicationRunner runner(BatchingRabbitTemplate template) {\n MessageProperties props = //...\n return args -> template.send(new Message(\"Test\").getBytes(), props);\n}\n```\n\n```text\nBatchingRabbitTemplate\n```\n\n```text\nBatchingRabbitTemplate\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.207Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":68,"estimatedTokens":480}}993{"id":"stack-39472425","source":"stackoverflow","questionId":39472425,"title":"Restore Apache Flink job from checkpoint","tags":["rabbitmq","apache-flink","flink-streaming"],"text":"Title: Restore Apache Flink job from checkpoint\nTags: rabbitmq, apache-flink, flink-streaming\nSource: Stack Overflow\n\nQuestion:\nI'm using Apache Flink + RabbitMQ stack. I know about opportunity to manually trigger savepoints and restore jobs from them, but the problem is that Flink acknowledges messages after successful checkpoint, and if you want to make savepoint and restore state you're losing all data between last successful savepoint and last successful checkpoint. Is there a way to restore job from checkpoint? That would solve the problem of losing data in case of non-replayable data sources (like rabbitmq). Btw, if we have checkpoints with all their overheads, why don't let users to use them?\n\n========================================\n\nComments:\n- yes, that would solve my problem. Is there a way to shutdown job after savepoint?\n- No. This is not possible at the moment, but will be added to enable job rescaling which is an ongoing effort at the moment.","metadata":{"transformedAt":"2026-08-18T18:33:20.207Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":12,"estimatedTokens":243}}994{"id":"stack-6601887","source":"stackoverflow","questionId":6601887,"title":"How to write a custom flume OG sink","tags":["rabbitmq","flume"],"text":"Title: How to write a custom flume OG sink\nTags: rabbitmq, flume\nSource: Stack Overflow\n\nQuestion:\nWe're using flume and I need to collect some log messages into rabbitmq. I found a source implementation that reads messages from rabbitmq, but I couldn't find a sink that can write messages into rabbit. So I was thinking about writing one myself. Looking at sample implementations like logsandra made me think it shouldn't be too difficult. \n\nHowever I couldn't find any documentation on how to write a custom sink.\nI didn't find a maven repo for the flume jars, or setup instructions on how to deploy a custom sink.\n\nCan anyone his experience, or better, point me to an existing tutorial.","metadata":{"transformedAt":"2026-08-18T18:33:20.207Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":11,"estimatedTokens":173}}995{"id":"stack-72282660","source":"stackoverflow","questionId":72282660,"title":"RabbitMQ connection.start was never received, likely due to a network timeout .net Web App","tags":[".net","docker","rabbitmq"],"text":"Title: RabbitMQ connection.start was never received, likely due to a network timeout .net Web App\nTags: .net, docker, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am trying to get a .Net 4.7.2 web application to connect to a RabbitMQ server running in a (Windows) Docker container (on the same machine as the web app is running in).\n\n**UPDATE: Using a non-Docker version of RabbitMQ does not solve the problem either. The console connects to the non-Docker RabbitMQ and can publish a message, but the .Net 4.7.2 web app still fails.**\n\nI am using the RabbitMQ.Client 6.2.4 (VMWare) with the following connection code:\n\n```\nConnectionFactory connectionFactory = new ConnectionFactory();\nUri uri = new Uri(\"amqp://dan:dan@localhost:5672/\");\nconnectionFactory.Uri = uri;\nvar theConnection = connectionFactory.CreateConnection();\n```\n\n(Note I have also tried with the same results:\n\n```\nvar factory = new ConnectionFactory() { HostName = \"localhost\", Port = 5672, VirtualHost = \"/\", UserName = \"dan\", Password = \"dan\" };\nusing (var connection = factory.CreateConnection())\n)\n```\n\nUser *dan* exists as an administrator and has rights to the virtual host.\n\nI am receiving the following error:\n\n```\n{\"None of the specified endpoints were reachable\"}\nData: {System.Collections.ListDictionaryInternal}\nHResult: -2146232800\nHelpLink: null\nInnerException: {\"connection.start was never received, likely due to a network timeout\"}\nMessage: \"None of the specified endpoints were reachable\"\nSource: \"RabbitMQ.Client\"\nStackTrace: \" at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName)\\r\\n at XXXX.Common.BackgroundSubmit.SubmitBackgroundProcess.<>c.b__0_0(String connectionURI) in C:\\\\XXXX.Common\\\\BackgroundSubmit\\\\BackgroundSubmitProcess.cs:line 71\"\nTargetSite: {RabbitMQ.Client.IConnection CreateConnection(RabbitMQ.Client.IEndpointResolver, System.String)}\n```\n\nThe RabbitMQ log reports this activity:\n\n```\n2022-05-18 02:18:59.346295+00:00 [info] accepting AMQP connection (172.19.0.1:55538 -> 172.19.0.2:5672)\n2022-05-18 02:18:59.443173+00:00 [warning] closing AMQP connection (172.19.0.1:55538 -> 172.19.0.2:5672):\n2022-05-18 02:18:59.443173+00:00 [warning] client unexpectedly closed TCP connection\n```\n\nI created a small console application and that application works fine - it can connect (and subsequently produce a message to a queue). This console application is .NET 6.0.\n\nI have tried using the actual IP address of my machine as well as 127.0.0.1 and the console connects but the web app does not.\n\nI looked at several tickets and thought maybe this was a good lead:\n\n```\nhttps://stackoverflow.com/questions/68011963/factory-createconnection-generates-a-none-of-the-specified-endpoints-were-reac\n```\n\nthis said make sure that System.Threading.Tasks.Extension, System.Threading.Channels and System.Memory are all the same versions in all referenced projects, and they are.\n\nAlso tried using *rabbitmq_localdev* as the rabbit host name in the URI.\n\nAny suggestions would be greatly appreciated!\n\nThanks,\n\nD\n\nHere is the docker-compose .yaml if it helps:\n\n```\nversion: \"3.2\"\nservices:\n rabbitmq:\n image: rabbitmq:3-management-alpine\n container_name: 'rabbitmq'\n ports:\n - 5672:5672\n - 15672:15672\n # Expose 15672 for the management console, localhost:15672, guest/guest\n # Expose 5672 for the qmpq port\n \n # https://stackoverflow.com/questions/30747469/how-to-add-initial-users-when-starting-a-rabbitmq-docker-container\n hostname: rabbitmq_localdev\n volumes:\n - ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/\n - ~/.docker-conf/rabbitmq/log/:/var/log/rabbitmq\n networks:\n - rabbitmq_go_net\n\nnetworks:\n rabbitmq_go_net:\n driver: bridge\n```\n\n========================================\n\nTop Answer:\nI'll rephrase the accepted answer.\n\nIf you have a `RabbitMQ` client in the **library project**, add the reference of the `RabbitMQ.Client` Nuget package **also to the root of the main project** (MVC project, Job, WCF service, e.t.c). This will resolve the issue.\n\n========================================\n\nCode:\n```text\nConnectionFactory connectionFactory = new ConnectionFactory();\nUri uri = new Uri(\"amqp://dan:dan@localhost:5672/\");\nconnectionFactory.Uri = uri;\nvar theConnection = connectionFactory.CreateConnection();\n```\n\n```text\nvar factory = new ConnectionFactory() { HostName = \"localhost\", Port = 5672, VirtualHost = \"/\", UserName = \"dan\", Password = \"dan\" };\nusing (var connection = factory.CreateConnection())\n)\n```\n\n```text\n{\"None of the specified endpoints were reachable\"}\nData: {System.Collections.ListDictionaryInternal}\nHResult: -2146232800\nHelpLink: null\nInnerException: {\"connection.start was never received, likely due to a network timeout\"}\nMessage: \"None of the specified endpoints were reachable\"\nSource: \"RabbitMQ.Client\"\nStackTrace: \" at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName)\\r\\n at XXXX.Common.BackgroundSubmit.SubmitBackgroundProcess.<>c.<SubmitJob>b__0_0(String connectionURI) in C:\\\\XXXX.Common\\\\BackgroundSubmit\\\\BackgroundSubmitProcess.cs:line 71\"\nTargetSite: {RabbitMQ.Client.IConnection CreateConnection(RabbitMQ.Client.IEndpointResolver, System.String)}\n```\n\n```text\n2022-05-18 02:18:59.346295+00:00 [info] <0.1164.0> accepting AMQP connection <0.1164.0> (172.19.0.1:55538 -> 172.19.0.2:5672)\n2022-05-18 02:18:59.443173+00:00 [warning] <0.1164.0> closing AMQP connection <0.1164.0> (172.19.0.1:55538 -> 172.19.0.2:5672):\n2022-05-18 02:18:59.443173+00:00 [warning] <0.1164.0> client unexpectedly closed TCP connection\n```\n\n```text\nhttps://stackoverflow.com/questions/68011963/factory-createconnection-generates-a-none-of-the-specified-endpoints-were-reac\n```\n\n```text\nversion: \"3.2\"\nservices:\n rabbitmq:\n image: rabbitmq:3-management-alpine\n container_name: 'rabbitmq'\n ports:\n - 5672:5672\n - 15672:15672\n # Expose 15672 for the management console, localhost:15672, guest/guest\n # Expose 5672 for the qmpq port\n \n # https://stackoverflow.com/questions/30747469/how-to-add-initial-users-when-starting-a-rabbitmq-docker-container\n hostname: rabbitmq_localdev\n volumes:\n - ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/\n - ~/.docker-conf/rabbitmq/log/:/var/log/rabbitmq\n networks:\n - rabbitmq_go_net\n\nnetworks:\n rabbitmq_go_net:\n driver: bridge\n```\n\n```text\nRabbitMQ\n```\n\n```text\nRabbitMQ.Client\n```\n\n========================================\n\nComments:\n- As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.\n- I had the same issue. We have a local nuget that contains the RabbitMQ.Client nuget, so just the local nuget was used and not the RabbitMQ.client nuget. This worked fine with a remotely deployed instance of RabbitMQ but to get it to work with a docker container running locally I had to install the RabbitMQ.client nuget as well.","metadata":{"transformedAt":"2026-08-18T18:33:20.207Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":180,"estimatedTokens":1768}}996{"id":"stack-35397430","source":"stackoverflow","questionId":35397430,"title":"Rabbitmq cluster setup in Kubernetes","tags":["docker","rabbitmq","kubernetes"],"text":"Title: Rabbitmq cluster setup in Kubernetes\nTags: docker, rabbitmq, kubernetes\nSource: Stack Overflow\n\nQuestion:\nI successfully setup rabbitmq cluster using docker compose to understand the clustering concept. It worked fine below is docker compose file:\n\n```\nrabbit1:\n image: ipf-queue-node\n hostname: rabbit1\n cap_add:\n - ALL\n - NET_ADMIN\n - SYS_ADMIN\n ports:\n - \"5671:5671\"\n - \"5672:5672\"\n - \"15672:15672\"\n\nrabbit2:\n image: ipf-queue-node\n hostname: rabbit2\n cap_add:\n - ALL\n - NET_ADMIN\n - SYS_ADMIN\n links:\n - rabbit1\n environment: \n - CLUSTERED=true\n - CLUSTER_WITH=rabbit1\n - RAM_NODE=true\n ports:\n - \"5675:5671\"\n - \"5673:5672\"\n - \"15673:15672\"\n```\n\nDocker file content:\n\n```\nFROM queue-base\n\n# Create directories\nRUN mkdir /opt/rabbit\nRUN mkdir /opt/simulator\nRUN mkdir /opt/simulator/tools\n\n# Add the files from the local repository into the container\nADD rabbitmq.config /etc/rabbitmq/\nADD rabbitmq-env.conf /etc/rabbitmq/\nADD erlang.cookie /var/lib/rabbitmq/.erlang.cookie\nADD startclusternode.sh /opt/rabbit/\nADD debugnodes.sh /opt/rabbit/\nADD tl /bin/tl\nADD rl /bin/rl\nADD rst /bin/rst\n\n# Add the simulator tooling\nADD simulator_tools/ /opt/simulator/tools/\nADD ./testca /tmp/ssl\nADD ./server /tmp/ssl\n\n# Set the file permissions in the container\nRUN chmod 644 /etc/rabbitmq/rabbitmq.config\nRUN chmod 644 /etc/rabbitmq/rabbitmq-env.conf\nRUN chmod 400 /var/lib/rabbitmq/.erlang.cookie\nRUN chmod 777 /opt/rabbit/startclusternode.sh\nRUN chmod 777 /opt/rabbit/debugnodes.sh\nRUN chmod 777 /bin/tl\nRUN chmod 777 /bin/rl\nRUN chmod 777 /bin/rst\nRUN chmod -R 777 /opt/simulator\n\n# Set ownership permissions on files in the container\nRUN chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie\n\n# Expose ports inside the container to the host\nEXPOSE 5672\nEXPOSE 5671\nEXPOSE 15672\nEXPOSE 25672\n\n# Run this to debug the cluster nodes by allowing ssh login\n#CMD /opt/rabbit/debugnodes.sh\n\n# Run this to autostart the cluster nodes\nCMD /opt/rabbit/startclusternode.sh\n```\n\nstartclusternode.sh is the script to setup the cluster:\n\n```\n#!/bin/bash\n\nlogfile=\"/tmp/rabbitnode.log\"\nfirsttimefile=\"/tmp/firsttimerunning\"\n\ncurhostname=`hostname`\nusername=\">\"\npassword=\">\"\necho \"\" > $logfile\necho \"New Start Date:\" >> $logfile\ndate >> $logfile\necho \"\" >> $logfile\n\n( sleep 40 ; \\\nrabbitmqctl add_user $username $password ; \\\nrabbitmqctl set_user_tags $username administrator ; \\\nrabbitmqctl add_vhost $curhostname ; \\\nrabbitmqctl add_vhost localhost; \\\nrabbitmqctl set_permissions -p $curhostname $username \".*\" \".*\" \".*\" ; \\\nrabbitmqctl set_permissions -p localhost $username \".*\" \".*\" \".*\" ; \\\nrabbitmqctl set_policy ha-all \"\" '{\"ha-mode\":\"all\",\"ha-sync-mode\":\"automatic\"}'\n) & \n\nsleep 5\n\n# For version 3.5.6 the first time running the cluster needs to enable the plugins\nif [ -f $firsttimefile ]; then\n echo \"First Time Running Enabling Plugins\" >> $logfile\n /usr/sbin/rabbitmq-server -d &\n echo \"Waiting for RabbitMQ Server to start\" >> $logfile\n sleep 3\n echo \"Enabling Plugins\" >> $logfile\n /usr/sbin/rabbitmq-plugins enable rabbitmq_stomp rabbitmq_management rabbitmq_management_agent rabbitmq_management_visualiser rabbitmq_federation rabbitmq_federation_management sockjs >> $logfile\n echo \"Waiting for Plugins to finish\" >> $logfile\n sleep 1\n echo \"Stopping the RabbitMQ using stop_app\" >> $logfile\n /usr/sbin/rabbitmqctl stop_app\n echo \"Stopping the RabbitMQ using stop\" >> $logfile\n /usr/sbin/rabbitmqctl stop\n\n echo \"Stopping the RabbitMQ Server\" >> $logfile\n kill -9 `ps auwwx | grep rabbitmq-server | awk '{print $2}'`\n sleep 1\n\n echo \"Done First Time Running Enabling Plugins\" >> $logfile\n rm -f $firsttimefile >> $logfile\n echo \"Done Cleanup First Time File\" >> $logfile\n\n # Allow the cluster nodes to wait for the master to start the first time\n if [ -z \"$CLUSTERED\" ]; then\n echo \"Ignoring as this is the server node\" >> $logfile\n else\n if [ -z \"$CLUSTER_WITH\" ]; then\n echo \"Ignoring as this is the cluster master node\" >> $logfile\n else\n echo \"Waiting for the master node to start up\" >> $logfile\n sleep 5\n echo \"Done waiting for the master node to start up\" >> $logfile\n fi\n fi\nfi\n\nif [ -z \"$CLUSTERED\" ]; then\n\n echo \"Starting non-Clustered Server Instance\" >> $logfile\n # if not clustered then start it normally as if it is a single server\n /usr/sbin/rabbitmq-server >> $logfile\n echo \"Done Starting non-Clustered Server Instance\" >> $logfile\n\n # Tail to keep the foreground process active.\n tail -f /var/log/rabbitmq/*\n\nelse\n if [ -z \"$CLUSTER_WITH\" ]; then\n # If clustered, but cluster is not specified then start normally as this could be the first server in the cluster\n echo \"Starting Single Server Instance\" >> $logfile\n /usr/sbin/rabbitmq-server >> $logfile\n\n echo \"Done Starting Single Server Instance\" >> $logfile\n else\n echo \"Starting Clustered Server Instance as a DETACHED single instance\" >> $logfile\n /usr/sbin/rabbitmq-server -detached >> $logfile\n\n echo \"Stopping App with /usr/sbin/rabbitmqctl stop_app\" >> $logfile\n /usr/sbin/rabbitmqctl stop_app >> $logfile\n\n # This should attempt to join a cluster master node from the yaml file\n if [ -z \"$RAM_NODE\" ]; then\n echo \"Attempting to join as DISC node: /usr/sbin/rabbitmqctl join_cluster rabbit@$CLUSTER_WITH\" >> $logfile\n /usr/sbin/rabbitmqctl join_cluster rabbit@$CLUSTER_WITH >> $logfile\n else\n echo \"Attempting to join as RAM node: /usr/sbin/rabbitmqctl join_cluster --ram rabbit@$CLUSTER_WITH\" >> $logfile\n /usr/sbin/rabbitmqctl join_cluster --ram rabbit@$CLUSTER_WITH >> $logfile\n fi\n echo \"Starting App\" >> $logfile\n /usr/sbin/rabbitmqctl start_app >> $logfile\n\n echo \"Done Starting Cluster Node\" >> $logfile\n fi\n\n # Tail to keep the foreground process active.\n tail -f /var/log/rabbitmq/*\n\nfi\n```\n\nProblem is when I tried to do the same setup using kubernetes I am unable to connect to master from slave node. Approach that I took is, I created a pod for master node and another for slave node, passed hostname of the master (currently hard-coded) through environment variable. I also checked the log file at /tmp/rabbitmq.log, it is correctly taking all the environment variables. However it is unable to register with the master. I tried doing it manually also using rabbitmqctl command. But it did't work says host unreachable. Tried changing /etc/hosts file too.\n\nAs per my understanding pods in kubernetes communicate through services, I guess because of this, passing directly container hostname doesn't work and rabbitmq clusiering work based on hostnames.\n\nHave anybody tried any workaround? I want to run master and slaves on different nodes. Below are the content of master and slave pods:\n\n```\napiVersion: v1\nkind: Service\nmetadata:\n name: rabbitmqsvc\n labels:\n app: queue-master\nspec:\n ports:\n - port: 5672\n name: queue-rw-port\n - port: 15672\n name: queue-mgt-port\n nodePort: 31606\n - port: 5671\n name: queue-ssl\n nodePort: 32718\n selector:\n app: queue-master\n type: NodePort\n clusterIP: 10.16.0.121\n---\napiVersion: v1\nkind: ReplicationController\nmetadata:\n name: rabbitmq-controller\n labels:\n app: queue-master\nspec:\n replicas: 1\n selector:\n app: queue-master\n template:\n metadata:\n name: rabbitmq-pod\n labels:\n app: queue-master\n spec:\n nodeSelector:\n nodesize: small1\n containers:\n - name: rabbitmq-master\n image: 172.17.0.1:5000/queue-node\n ports:\n - containerPort: 5672\n name: queue-rw-port\n - containerPort: 15672\n name: queue-mgt-port\n - containerPort: 5671\n name: queue-ssl\n```\n\nSLAVE:\n\n```\napiVersion: v1\nkind: Service\nmetadata:\n name: rabbitmqsvc-slave\n labels:\n app: queue-slave\nspec:\n ports:\n - port: 5672\n name: queue-rw-port\n - port: 15672\n name: queue-mgt-port\n nodePort: 31607\n - port: 5671\n name: queue-ssl\n nodePort: 32719\n selector:\n app: queue-slave\n type: NodePort\n clusterIP: 10.16.0.122\n---\napiVersion: v1\nkind: ReplicationController\nmetadata:\n name: rabbitmq-controller-slave\n labels:\n app: queue-slave\nspec:\n replicas: 1\n selector:\n app: queue-slave\n template:\n metadata:\n name: rabbitmq-pod\n labels:\n app: queue-slave\n spec:\n nodeSelector:\n nodesize: small2\n containers:\n - name: rabbitmq-slave\n image: 172.17.0.1:5000/queue-node\n env:\n - name: CLUSTERED\n value: \"true\"\n - name: CLUSTER_WITH\n value: \"rabbitmq-controller-2ll1s\"\n - name: RAM_NODE\n value: \"true\"\n - name: HOST_NAME\n value: \"rabbit2\"\n ports:\n - containerPort: 5672\n name: queue-rw-port\n - containerPort: 15672\n name: queue-mgt-port\n - containerPort: 5671\n name: queue-ssl\n```\n\n========================================\n\nTop Answer:\nWe just open sourced a deployment ready rabbitmq cluster for kubernetes.\nIt uses StatefulSets so it requires Kubernetes 1.5.X or later.\n\nYou can find it here: https://github.com/nanit/kubernetes-rabbitmq-cluster\n\n========================================\n\nCode:\n```text\nrabbit1:\n image: ipf-queue-node\n hostname: rabbit1\n cap_add:\n - ALL\n - NET_ADMIN\n - SYS_ADMIN\n ports:\n - \"5671:5671\"\n - \"5672:5672\"\n - \"15672:15672\"\n\nrabbit2:\n image: ipf-queue-node\n hostname: rabbit2\n cap_add:\n - ALL\n - NET_ADMIN\n - SYS_ADMIN\n links:\n - rabbit1\n environment: \n - CLUSTERED=true\n - CLUSTER_WITH=rabbit1\n - RAM_NODE=true\n ports:\n - \"5675:5671\"\n - \"5673:5672\"\n - \"15673:15672\"\n```\n\n```text\nFROM queue-base\n\n# Create directories\nRUN mkdir /opt/rabbit\nRUN mkdir /opt/simulator\nRUN mkdir /opt/simulator/tools\n\n# Add the files from the local repository into the container\nADD rabbitmq.config /etc/rabbitmq/\nADD rabbitmq-env.conf /etc/rabbitmq/\nADD erlang.cookie /var/lib/rabbitmq/.erlang.cookie\nADD startclusternode.sh /opt/rabbit/\nADD debugnodes.sh /opt/rabbit/\nADD tl /bin/tl\nADD rl /bin/rl\nADD rst /bin/rst\n\n# Add the simulator tooling\nADD simulator_tools/ /opt/simulator/tools/\nADD ./testca /tmp/ssl\nADD ./server /tmp/ssl\n\n# Set the file permissions in the container\nRUN chmod 644 /etc/rabbitmq/rabbitmq.config\nRUN chmod 644 /etc/rabbitmq/rabbitmq-env.conf\nRUN chmod 400 /var/lib/rabbitmq/.erlang.cookie\nRUN chmod 777 /opt/rabbit/startclusternode.sh\nRUN chmod 777 /opt/rabbit/debugnodes.sh\nRUN chmod 777 /bin/tl\nRUN chmod 777 /bin/rl\nRUN chmod 777 /bin/rst\nRUN chmod -R 777 /opt/simulator\n\n# Set ownership permissions on files in the container\nRUN chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie\n\n# Expose ports inside the container to the host\nEXPOSE 5672\nEXPOSE 5671\nEXPOSE 15672\nEXPOSE 25672\n\n# Run this to debug the cluster nodes by allowing ssh login\n#CMD /opt/rabbit/debugnodes.sh\n\n# Run this to autostart the cluster nodes\nCMD /opt/rabbit/startclusternode.sh\n```\n\n```text\n#!/bin/bash\n\nlogfile=\"/tmp/rabbitnode.log\"\nfirsttimefile=\"/tmp/firsttimerunning\"\n\ncurhostname=`hostname`\nusername=\"<<username>>\"\npassword=\"<<password>>\"\necho \"\" > $logfile\necho \"New Start Date:\" >> $logfile\ndate >> $logfile\necho \"\" >> $logfile\n\n( sleep 40 ; \\\nrabbitmqctl add_user $username $password ; \\\nrabbitmqctl set_user_tags $username administrator ; \\\nrabbitmqctl add_vhost $curhostname ; \\\nrabbitmqctl add_vhost localhost; \\\nrabbitmqctl set_permissions -p $curhostname $username \".*\" \".*\" \".*\" ; \\\nrabbitmqctl set_permissions -p localhost $username \".*\" \".*\" \".*\" ; \\\nrabbitmqctl set_policy ha-all \"\" '{\"ha-mode\":\"all\",\"ha-sync-mode\":\"automatic\"}'\n) & \n\nsleep 5\n\n# For version 3.5.6 the first time running the cluster needs to enable the plugins\nif [ -f $firsttimefile ]; then\n echo \"First Time Running Enabling Plugins\" >> $logfile\n /usr/sbin/rabbitmq-server -d &\n echo \"Waiting for RabbitMQ Server to start\" >> $logfile\n sleep 3\n echo \"Enabling Plugins\" >> $logfile\n /usr/sbin/rabbitmq-plugins enable rabbitmq_stomp rabbitmq_management rabbitmq_management_agent rabbitmq_management_visualiser rabbitmq_federation rabbitmq_federation_management sockjs >> $logfile\n echo \"Waiting for Plugins to finish\" >> $logfile\n sleep 1\n echo \"Stopping the RabbitMQ using stop_app\" >> $logfile\n /usr/sbin/rabbitmqctl stop_app\n echo \"Stopping the RabbitMQ using stop\" >> $logfile\n /usr/sbin/rabbitmqctl stop\n\n echo \"Stopping the RabbitMQ Server\" >> $logfile\n kill -9 `ps auwwx | grep rabbitmq-server | awk '{print $2}'`\n sleep 1\n\n echo \"Done First Time Running Enabling Plugins\" >> $logfile\n rm -f $firsttimefile >> $logfile\n echo \"Done Cleanup First Time File\" >> $logfile\n\n\n # Allow the cluster nodes to wait for the master to start the first time\n if [ -z \"$CLUSTERED\" ]; then\n echo \"Ignoring as this is the server node\" >> $logfile\n else\n if [ -z \"$CLUSTER_WITH\" ]; then\n echo \"Ignoring as this is the cluster master node\" >> $logfile\n else\n echo \"Waiting for the master node to start up\" >> $logfile\n sleep 5\n echo \"Done waiting for the master node to start up\" >> $logfile\n fi\n fi\nfi\n\n\nif [ -z \"$CLUSTERED\" ]; then\n\n echo \"Starting non-Clustered Server Instance\" >> $logfile\n # if not clustered then start it normally as if it is a single server\n /usr/sbin/rabbitmq-server >> $logfile\n echo \"Done Starting non-Clustered Server Instance\" >> $logfile\n\n # Tail to keep the foreground process active.\n tail -f /var/log/rabbitmq/*\n\nelse\n if [ -z \"$CLUSTER_WITH\" ]; then\n # If clustered, but cluster is not specified then start normally as this could be the first server in the cluster\n echo \"Starting Single Server Instance\" >> $logfile\n /usr/sbin/rabbitmq-server >> $logfile\n\n echo \"Done Starting Single Server Instance\" >> $logfile\n else\n echo \"Starting Clustered Server Instance as a DETACHED single instance\" >> $logfile\n /usr/sbin/rabbitmq-server -detached >> $logfile\n\n echo \"Stopping App with /usr/sbin/rabbitmqctl stop_app\" >> $logfile\n /usr/sbin/rabbitmqctl stop_app >> $logfile\n\n # This should attempt to join a cluster master node from the yaml file\n if [ -z \"$RAM_NODE\" ]; then\n echo \"Attempting to join as DISC node: /usr/sbin/rabbitmqctl join_cluster rabbit@$CLUSTER_WITH\" >> $logfile\n /usr/sbin/rabbitmqctl join_cluster rabbit@$CLUSTER_WITH >> $logfile\n else\n echo \"Attempting to join as RAM node: /usr/sbin/rabbitmqctl join_cluster --ram rabbit@$CLUSTER_WITH\" >> $logfile\n /usr/sbin/rabbitmqctl join_cluster --ram rabbit@$CLUSTER_WITH >> $logfile\n fi\n echo \"Starting App\" >> $logfile\n /usr/sbin/rabbitmqctl start_app >> $logfile\n\n echo \"Done Starting Cluster Node\" >> $logfile\n fi\n\n # Tail to keep the foreground process active.\n tail -f /var/log/rabbitmq/*\n\nfi\n```\n\n```text\napiVersion: v1\nkind: Service\nmetadata:\n name: rabbitmqsvc\n labels:\n app: queue-master\nspec:\n ports:\n - port: 5672\n name: queue-rw-port\n - port: 15672\n name: queue-mgt-port\n nodePort: 31606\n - port: 5671\n name: queue-ssl\n nodePort: 32718\n selector:\n app: queue-master\n type: NodePort\n clusterIP: 10.16.0.121\n---\napiVersion: v1\nkind: ReplicationController\nmetadata:\n name: rabbitmq-controller\n labels:\n app: queue-master\nspec:\n replicas: 1\n selector:\n app: queue-master\n template:\n metadata:\n name: rabbitmq-pod\n labels:\n app: queue-master\n spec:\n nodeSelector:\n nodesize: small1\n containers:\n - name: rabbitmq-master\n image: 172.17.0.1:5000/queue-node\n ports:\n - containerPort: 5672\n name: queue-rw-port\n - containerPort: 15672\n name: queue-mgt-port\n - containerPort: 5671\n name: queue-ssl\n```\n\n```text\napiVersion: v1\nkind: Service\nmetadata:\n name: rabbitmqsvc-slave\n labels:\n app: queue-slave\nspec:\n ports:\n - port: 5672\n name: queue-rw-port\n - port: 15672\n name: queue-mgt-port\n nodePort: 31607\n - port: 5671\n name: queue-ssl\n nodePort: 32719\n selector:\n app: queue-slave\n type: NodePort\n clusterIP: 10.16.0.122\n---\napiVersion: v1\nkind: ReplicationController\nmetadata:\n name: rabbitmq-controller-slave\n labels:\n app: queue-slave\nspec:\n replicas: 1\n selector:\n app: queue-slave\n template:\n metadata:\n name: rabbitmq-pod\n labels:\n app: queue-slave\n spec:\n nodeSelector:\n nodesize: small2\n containers:\n - name: rabbitmq-slave\n image: 172.17.0.1:5000/queue-node\n env:\n - name: CLUSTERED\n value: \"true\"\n - name: CLUSTER_WITH\n value: \"rabbitmq-controller-2ll1s\"\n - name: RAM_NODE\n value: \"true\"\n - name: HOST_NAME\n value: \"rabbit2\"\n ports:\n - containerPort: 5672\n name: queue-rw-port\n - containerPort: 15672\n name: queue-mgt-port\n - containerPort: 5671\n name: queue-ssl\n```\n\n```text\n- name: CLUSTER_WITH\n value: \"rabbitmqsvc.svc.cluster.local\"\n```\n\n```text\nMaster service\n```\n\n```text\nMaster service\n```\n\n========================================\n\nComments:\n- Is there a description how I can install rabbitmq in kubernetes with minikube/kubectl (don't need cluster)?\n- Or use the `clusterIP` of your master service if you don't have the DNS add-on running.\n- Thanks for your quick response..I already tried using service Cluster IP, RABBITMQSVC_SERVICE_HOST nothing works. Problem is with rabbitmq cluster setup. I can't use IP, domain name of service for cluster setup it requires the hostname of the node. I think I have to setup it outside the cluster in the same vnet. Or is there any other workaround?\n- Got it working finally. Changed /etc/hosts file and mapped ip with the host-name and it started registering the nodes..Will change the script now and will try to automate this. Thanks for your help.\n- Is there a description how I can install rabbitmq in kubernetes with minikube/kubectl (don't need cluster)?\n- Getting the following error using nanit: + echo 'Waiting for RabbitMQ pod to be ready....' Waiting for RabbitMQ pod to be ready.... ++ kubectl get pods -n test2 ++ grep rabbitmq-0 ++ grep Running + [[ -n '' ]] + echo 'RabbitMQ pod still not ready...' RabbitMQ pod still not ready... + sleep 5","metadata":{"transformedAt":"2026-08-18T18:33:20.207Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":658,"estimatedTokens":4464}}997{"id":"stack-32795977","source":"stackoverflow","questionId":32795977,"title":"Spring integration pubsub vs Spring amqp RabbitMQ pubsub","tags":["java","spring","rabbitmq","spring-integration","spring-amqp"],"text":"Title: Spring integration pubsub vs Spring amqp RabbitMQ pubsub\nTags: java, spring, rabbitmq, spring-integration, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI am working on a MicroBlog spring mvc hibernate application. I need to implement a publish subscribe functionality like twitter. \n\nI am using RabbitMQ for messaging with Spring AMQP abstraction.\n\nEverywhere I see on web the pubsub examples are given involving \n\n Spring Integration\n\n \n Spring AMQP & RabbitMQ\n\nI researched a little more on Spring-Integration & found that a publish subscribe can be implemented with it even without using RabbitMQ.\n\nNow my question is \n\n**Why do I need to use Spring Integration with [Spring AMQP & RabbitMQ] to implement a pubsub functionality. Why can't I just use Spring AMQP with Rabbit to do that?**\n\n**Does Spring integration provide any additional features?**\n\nMy Spring AMQP & RabbitMQ configuration \n\n```\n\n \n \n \n\n```\n\nTest code in my controller\n\n```\n@Autowire\nprivate AmqpTemplate amqpTemplate;\n\ntry{\n amqpTemplate.convertAndSend(post);\n Post receivedPost = (Post)amqpTemplate.receiveAndConvert();\n System.out.println(\"received Post \"+receivedPost);\n }catch(AmqpException e){\n //deal with exception\n }\n```\n\n========================================\n\nCode:\n```text\n<rabbit:connection-factory id=\"connectionFactory\" virtual-host=\"/\" host=\"localhost\" \nusername=\"guest\" password=\"guest\"/>\n\n<rabbit:admin connection-factory=\"connectionFactory\" />\n\n<rabbit:queue name=\"UserPostpublishQueue\" />\n\n<fanout-exchange name=\"broadcastUserPosts\" xmlns=\"http://www.springframework.org/schema/rabbit\">\n <bindings>\n <binding queue=\"UserPostpublishQueue\"/>\n </bindings>\n</fanout-exchange>\n\n<rabbit:template id=\"amqpTemplate\" connection-factory=\"connectionFactory\" exchange=\"broadcastUserPosts\" \nqueue=\"UserPostpublishQueue\"/>\n\n</beans>\n```\n\n```text\n@Autowire\nprivate AmqpTemplate amqpTemplate;\n\ntry{\n amqpTemplate.convertAndSend(post);\n Post receivedPost = (Post)amqpTemplate.receiveAndConvert();\n System.out.println(\"received Post \"+receivedPost);\n }catch(AmqpException e){\n //deal with exception\n }\n```\n\n```text\nspring-amqp\n```\n\n========================================\n\nComments:\n- Why just don't with some Google links and don't read about both a bit?..\n- If there was enough on Google I wouldn't have put up this question in the first place. Why don't you stop downvoting questions if you don't know the answer.","metadata":{"transformedAt":"2026-08-18T18:33:20.207Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":94,"estimatedTokens":615}}998{"id":"stack-42668625","source":"stackoverflow","questionId":42668625,"title":"Mock a connection class in pytest","tags":["python","unit-testing","mocking","rabbitmq","kombu"],"text":"Title: Mock a connection class in pytest\nTags: python, unit-testing, mocking, rabbitmq, kombu\nSource: Stack Overflow\n\nQuestion:\nI have a class which inherits from `kombu.ConsumerProducerMixin` which I would like to test without an actual rabbitmq service running.\n\n```\nclass Aggregator(ConsumerProducerMixin):\n\n def __init__(self, broker_url):\n exchange_name = 'chargers'\n self.status = 0\n self.connection = Connection(broker_url)\n ...\n```\n\nIn my test file I did the following:\n\n```\nfrom unittest.mock import Mock, patch\n\nfrom aggregator import Aggregator\n\n@patch('kombu.connection.Connection')\ndef test_on_request(conn_mock):\n\n agg = Aggregator('localhost')\n m = Message(\"\", {\"action\": \"start\"}, content_type=\"application/json\")\n```\n\nStepping into the `Aggregator.__init__` with the debugger, I see that `connection` is still not patched to be a `Mock` instance:\n\n```\n(Pdb) self.connection\n\n(Pdb) Connection\n\n```\n\nMy question is how do I properly patch connection such that I don't need rabbitmq to run the tests?\n\n========================================\n\nCode:\n```text\nclass Aggregator(ConsumerProducerMixin):\n\n def __init__(self, broker_url):\n exchange_name = 'chargers'\n self.status = 0\n self.connection = Connection(broker_url)\n ...\n```\n\n```text\nfrom unittest.mock import Mock, patch\n\nfrom aggregator import Aggregator\n\n@patch('kombu.connection.Connection')\ndef test_on_request(conn_mock):\n\n agg = Aggregator('localhost')\n m = Message(\"\", {\"action\": \"start\"}, content_type=\"application/json\")\n```\n\n```text\n(Pdb) self.connection\n<Connection: amqp://guest:**@localhost:5672// at 0x7fc8b7f636d8>\n(Pdb) Connection\n<class 'kombu.connection.Connection'>\n```\n\n```text\nkombu.ConsumerProducerMixin\n```\n\n```text\nAggregator.__init__\n```\n\n```text\nconnection\n```\n\n```text\nMock\n```\n\n```text\n@patch('aggregator.aggregator.Connection')\ndef test_on_request(mock_connect):\n agg = Aggregator('localhost')\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.313Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":95,"estimatedTokens":484}}999{"id":"stack-35031787","source":"stackoverflow","questionId":35031787,"title":"RabbitMq Consumer not processing messages","tags":["rabbitmq"],"text":"Title: RabbitMq Consumer not processing messages\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have made a consumer for RabbitMQ as a console application written in C#.NET. It is programmed to listen to a queue perpetually and whenever it find a message in the queue, it processes it. The consumer processes on an average 35 messages / second. The consumers are scheduled to run at system startup in the task scheduler. The consumers run fine for 3 - 4 days. But then, they keep on running but don't process any messages although the queue has messages in it. When the consumer is stopped and again started, it again starts processing the messages properly. But, by the time you manually restart, millions of messages get queued. Can someone please help me explain this abnormal behavior. I have other queues too which are running since months together without ceasing to stop. \n\nRequesting prompt response. Thanks in advance to the experts.\n\n========================================\n\nComments:\n- I am using RabbitMQ.Client.Events.QueueingBasicConsumer to dequeue the message. Hence, probably I am facing same problem. Can you please give the sample code on how did you dequeue the message using RabbitMQ.Client.Events.EventingBasicConsumer.\n- @ShikharMaheshwari In case you didn't find it or someone else needs it. var consumer = new EventingBasicConsumer(channel); consumer.Received += (model, ea) => { //get message and do work var body = ea.Body; var bodyStr = Encoding.UTF8.GetString(body); };","metadata":{"transformedAt":"2026-08-18T18:33:20.313Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":14,"estimatedTokens":376}}1000{"id":"stack-35430106","source":"stackoverflow","questionId":35430106,"title":"Getting a queue without providing its all properties","tags":["ruby","queue","rabbitmq","message-queue","bunny"],"text":"Title: Getting a queue without providing its all properties\nTags: ruby, queue, rabbitmq, message-queue, bunny\nSource: Stack Overflow\n\nQuestion:\nI am trying to write a consumer for an existing queue.\n\nRabbbitMQ is running in a separate instance and queue named \"org-queue\" is already created and binded to an exchange. org-queue is a durable queue and it has some additional properties as well.\n\nNow I need to receive messages from this queue. \nI have use the below code to get instance of the queue\n\n```\nconn = Bunny.new\nconn.start\nch = conn.create_channel \nq = ch.queue(\"org-queue\")\n```\n\nIt throws me an error stating different durable property. It seems by default the Bunny uses durable = false. So I've added durable true as parameter. Now it states the difference between other parameters. Do I need to specify all the parameters, to connect to it? As rabbitMQ is maintained by different environment, it is hard for me to get all the properties.\n\nIs there a way to get list of queues and listening to the required queue in client instead of connecting to a queue by all parameters.\n\n========================================\n\nTop Answer:\nBased on the documentation here http://reference.rubybunny.info/Bunny/Queue.html and\nhttp://reference.rubybunny.info/Bunny/Channel.html\n\nUsing the `ch.queues()` method you could get a hash of all the queues on that channel. Then once you find the instance of the queue you are wanting to connect to you could use the `q.options()` method to find out what options are on that rabbitmq queue. \n\nSeems like a round about way to do it but might work. I haven't tested this as I don't have a rabbitmq server up at the moment.\n\n========================================\n\nCode:\n```text\nconn = Bunny.new\nconn.start\nch = conn.create_channel \nq = ch.queue(\"org-queue\")\n```\n\n```text\nch.queues()\n```\n\n```text\nq.options()\n```\n\n========================================\n\nComments:\n- Typically when you interface with a message bus you're supposed to know the contract you need to uphold - doing it dynamically as you're suggesting can create various problems and can be VERY hard to debug. I wouldn't recommend it\n- I second that. You should have the parameters used to set up the queues somewhere in an environment variable and connect to the queue/exchange using those.\n- For me ch.queues() returns an empty hash though queues are present in my rabbitMQ server","metadata":{"transformedAt":"2026-08-18T18:33:20.313Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":57,"estimatedTokens":598}}1001{"id":"stack-50390673","source":"stackoverflow","questionId":50390673,"title":"Is there a way to do \"migration\" on RabbitMQ queues, exchanges, bindings, etc?","tags":["java","spring","rabbitmq","migration","spring-rabbit"],"text":"Title: Is there a way to do \"migration\" on RabbitMQ queues, exchanges, bindings, etc?\nTags: java, spring, rabbitmq, migration, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI would like to know if there is any alternative to create / change / remove `exchanges`, `queues` and `bindings` without depending of the framework (in my case, Spring) for this and his limitations.\n\n### The problem\n\nOften I need to **change the name** of a *Routing Key*, *Queue*, or *Exchange*, and these frameworks do not allow to do this \"refined\" changes. As a consequence, the tendency is continue with the original names of queues/keys and even the **original setup** (durable, DLQ, etc). On the future, this ends up confusing the organization of the queues, because you can not easily give proper maintenance to their name, configuration, eventually reorganize them at different exchanges, etc.\n\nActually, the only way to accomplish that is manually removing them from each environment and let the framework recreate them. Or moving the messages for a temporary queue to do the same.\n\nI would like to know if there are **any alternative** to control this, something like the tools for database migration, like Liquibase, Flyway, etc.\n\nMaking a parallel situation with the database problem, currently letting the Spring create everything in RabbitMQ seems to me analogous to leaving `hbm2ddl` Hibernate option on `update` on a Production database.\n\n========================================\n\nCode:\n```text\nexchanges\n```\n\n```text\nqueues\n```\n\n```text\nbindings\n```\n\n```text\nhbm2ddl\n```\n\n```text\nupdate\n```\n\n```text\nRabbitAdmin.declareBinding()\n```\n\n```text\nremoveBinding()\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.313Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":7,"totalLines":47,"estimatedTokens":414}}1002{"id":"stack-33190592","source":"stackoverflow","questionId":33190592,"title":"RabbitMQ - Apache Camel Reading Messages what to do with failed messages","tags":["java","rabbitmq","dead-letter"],"text":"Title: RabbitMQ - Apache Camel Reading Messages what to do with failed messages\nTags: java, rabbitmq, dead-letter\nSource: Stack Overflow\n\nQuestion:\nI have the following PHP application. That publishes a user signUp to a message queue. The Java Application reads from that queue and imports it. Hopefully the diagram below will discribe it. I am only working with the Java side of things. The json messages exists on the queue already.\n\nhttps://i.sstatic.net/IztzP.png\n\n**Route (Java Consuming Side).** \n\n```\n@Component\npublic class SignUpRouting {\n\n errorHandler(deadLetterChannel(\"rabbitmq://signUpDeadLetter.exchange?username=etc..\").useOriginalMessage());\n\n from(\"rabbitmq://phpSignUp.exchange?username=etc....\")\n .routeId(\"signUpRoute\")\n .processRef(\"signUpProcessor\")\n .end();\n //....\n```\n\n**The processor..**\n\n```\n@Component\npublic class SignupProcessor implements Processor {\n\n private ObjectMapper mapper = new ObjectMapper();\n\n @Override\n public void process(Exchange exchange) throws Exception {\n\n String json = exchange.getIn().getBody(String.class);\n SignUpDto dto = mapper.readValue(json, SignUpDto.class);\n\n SignUp signUp = new SignUp();\n signUp.setWhatever(dto.getWhatever());\n //etc....\n\n // save record\n signUpDao.save(signUp);\n }\n}\n```\n\n **My question is this..** What should I do I do when the Processor fails to import the message.\n\nLets say for example there was a DAO exception. A data field may have been toolong or the import was in the incorrect format. I dont want to lose the message. I would like to see the error and retry the import. But I would not want to keep retrying the message every 30 seconds.\n\nI am thinking that I would need to create another queue.. A dead letter queue and have that indefinately retry the message every 6 hours?.. I would then view the logs see the error and upload a fix and the message would be reprocessed?\n\nHow would I implement that? Or am I on the wrong track?\n\n *EDIT* I have tried setting deadLetterExchange to see if would get things on the right direction... However it errors and says queue cannot be non null\n\n```\nrabbitmq://phpSignUp.exchange?username=etc...&deadLetterExchange=signUpDeadLetter.exchange\n```\n\n========================================\n\nTop Answer:\nYou could use onException to catch Exceptions, if there is an Exception, the message will be route to the dead letter exchange, here is the example in Spring DSL:\n\n```\n\n java.sql.SQLException\n \n\n \n\n```\n\n========================================\n\nCode:\n```text\n@Component\npublic class SignUpRouting {\n\n errorHandler(deadLetterChannel(\"rabbitmq://signUpDeadLetter.exchange?username=etc..\").useOriginalMessage());\n\n from(\"rabbitmq://phpSignUp.exchange?username=etc....\")\n .routeId(\"signUpRoute\")\n .processRef(\"signUpProcessor\")\n .end();\n //....\n```\n\n```text\n@Component\npublic class SignupProcessor implements Processor {\n\n private ObjectMapper mapper = new ObjectMapper();\n\n @Override\n public void process(Exchange exchange) throws Exception {\n\n String json = exchange.getIn().getBody(String.class);\n SignUpDto dto = mapper.readValue(json, SignUpDto.class);\n\n SignUp signUp = new SignUp();\n signUp.setWhatever(dto.getWhatever());\n //etc....\n\n // save record\n signUpDao.save(signUp);\n }\n}\n```\n\n```text\nrabbitmq://phpSignUp.exchange?username=etc...&deadLetterExchange=signUpDeadLetter.exchange\n```\n\n```text\n<from uri=\"rabbitmq://localhost/youexchange?queue=yourq1&\n exchangeType=topic&\n routingKey=user.reg.*&\n deadLetterExchange=dead.msgs&\n deadLetterExchangeType=topic&\n deadLetterRoutingKey=dead.letters&\n deadLetterQueue=dead.letters&\n autoAck=false&\n autoDelete=false\"/>\n\n <!--We can use onException to make camel to retry, and after that, dead letter queue are the fallback-->\n <onException useOriginalMessage=\"true\">\n <exception>java.lang.Exception</exception>\n <redeliveryPolicy asyncDelayedRedelivery=\"true\" maximumRedeliveries=\"3\" redeliveryDelay=\"5000\"/>\n </onException>\n```\n\n```text\n<onException useOriginalMessage=\"true\">\n <exception>java.sql.SQLException</exception>\n <redeliveryPolicy asyncDelayedRedelivery=\"true\" maximumRedeliveries=\"1\" redeliveryDelay=\"1000\"/>\n\n <inOnly uri=\"rabbitmq://localhost/dead.msgs?exchangeType=fanout&\n autoDelete=false&\n bridgeEndpoint=true\"/>\n</onException>\n```\n\n========================================\n\nComments:\n- if you are using another queue why don't you store the exact failed message along with the stack trace of the exception and then process data from that queue\n- im not sure I understand. could you provide an example?\n- If you have the luxury of a support team, I would send the message to another queue or write to a database table and then send an email to alert support staff. Create another interface that allows the support staff to modify the text of the message and reinject it into the signup processor. Whatever you do is going to require manual intervention. Design accordingly. There should be good validation on the PHP app such that his is a rare event.\n- This is a good answer and a viable solution +1. However it feels to me like its not using the rabbitmq specific dead letter headers and config. As seen camel.apache.org/rabbitmq.html\n- why do we need to set bridgeEndpoint=true. what is that for?\n- If you do not add the attribute, the target queue will not receive any messages.\n- Couple of questions. Why do we need to turn of autoAck? and what is deadLetterExchangeType=topic?\n- If the autoAck is on, camel will send basic.ack while they receive messages. There will be no possible for camel to send a basic.refuse or basic.nack upon excepions, so the deadletter attributes will be useless.\n- And the deadLetterExchangeXXX attributes are used to route dead letters to the specified exchange and queue. In the demo settings, i used topic, but you can use other exchange types.","metadata":{"transformedAt":"2026-08-18T18:33:20.314Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":159,"estimatedTokens":1532}}1003{"id":"stack-53029710","source":"stackoverflow","questionId":53029710,"title":"Using RabbitMQ from inside a Docker container","tags":["c#","docker","rabbitmq"],"text":"Title: Using RabbitMQ from inside a Docker container\nTags: c#, docker, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am trying to use Docker with an application. Everything seems to work except Rabbit MQ. Therefore in order to create a test case I have done the following:\n\n**Step 1 - Run outside Docker - works as expected**\n\n1) Create a simple ASP.NET Core 2.1 Console App:\n\n```\nusing System;\nusing RabbitMQ.Client;\n\nnamespace DockerRabbitMQ\n{\n class Program\n {\n static void Main(string[] args)\n {\n RabbitMQConnect();\n }\n\n public static void RabbitMQConnect()\n {\n var factory = new ConnectionFactory\n {\n HostName = \"localhost\",\n UserName = \"guest\",\n Password = \"guest\"\n };\n\n var rabbit = factory.CreateConnection();\n }\n }\n}\n```\n\n2) Install RabbitMQ on local PC and test it works by browsing to: http://localhost:15672. I see the management portal as expected, so it is working.\n\n3) Run the Console app. It runs and completes as expected.\n\n**Step 2 - Run inside Docker**\n\n1) Right click on the Console app and select: Add/Container Orchestration Support. The DOCKERFILE and docker-compose are added.\n\n2) Add the following to Docker Compose:\n\n```\nrabbit:\n image: rabbitmq:3-management-alpine\n hostname: rabbit\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n```\n\n3) Stop the Rabbit MQ Service running on the local PC (the service was created in step 1, part 2)\n\n4) Amend the code in step 1 part 1 to say:\n\n```\nHostName = \"Rabbit\",\n```\n\n5) Run Docker Compose in Visual Studio. Here is the error:\n\nhttps://i.sstatic.net/48NEB.png\n\nI believe my question is similar to this one: RabbitMq refuses connection when run in docker. Why am I prompted with this error?\n\n**Update**\n\nIn order to ensure RabbitMQ starts before the console app; I will amend the compose file with the following:\n\n```\ndepends_on:\n - rabbitmq\n```\n\n**Update 2**\n\nI have tried following the instructions above using an MVC app instead of a console app (in step 1). I put the connection code in the Startup constructor (just for testing) and I see this:\n\nhttps://i.sstatic.net/Olhp6.png\n\nWhy do I see an error and why is it trying to connect to: 92.242.132.15:5672? The Docker Compose fore the MVC app (and rabbit mw) looks like this:\n\n```\nversion: '3.4'\n\nservices:\n dockerrabbitmqmvc:\n environment:\n - ASPNETCORE_ENVIRONMENT=Development\n - ASPNETCORE_URLS=https://+:443;http://+:80\n - ASPNETCORE_HTTPS_PORT=44336\n ports:\n - \"54258:80\"\n - \"44336:443\"\n volumes:\n - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro\n - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro\n\n rabbitmq:\n image: rabbitmq:3-management-alpine\n hostname: rabbit\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n expose:\n - \"15672\"\n - \"5672\"\n```\n\n========================================\n\nCode:\n```text\nusing System;\nusing RabbitMQ.Client;\n\nnamespace DockerRabbitMQ\n{\n class Program\n {\n static void Main(string[] args)\n {\n RabbitMQConnect();\n }\n\n public static void RabbitMQConnect()\n {\n var factory = new ConnectionFactory\n {\n HostName = \"localhost\",\n UserName = \"guest\",\n Password = \"guest\"\n };\n\n var rabbit = factory.CreateConnection();\n }\n }\n}\n```\n\n```text\nrabbit:\n image: rabbitmq:3-management-alpine\n hostname: rabbit\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n```\n\n```text\nHostName = \"Rabbit\",\n```\n\n```text\ndepends_on:\n - rabbitmq\n```\n\n```text\nversion: '3.4'\n\nservices:\n dockerrabbitmqmvc:\n environment:\n - ASPNETCORE_ENVIRONMENT=Development\n - ASPNETCORE_URLS=https://+:443;http://+:80\n - ASPNETCORE_HTTPS_PORT=44336\n ports:\n - \"54258:80\"\n - \"44336:443\"\n volumes:\n - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro\n - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro\n\n rabbitmq:\n image: rabbitmq:3-management-alpine\n hostname: rabbit\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n expose:\n - \"15672\"\n - \"5672\"\n```\n\n```text\nrabbit:\n image: rabbitmq:3-management-alpine\n hostname: rabbit\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n expose:\n - 15672\n - 5672\n```\n\n========================================\n\nComments:\n- In your docker-compose.yml here, it looks like the `rabbitmq` service is offset one tab more than the `dockerrabbitmqmvc`. I doubt that's actually how you have it, because it wouldn't run, but just wanted to make sure everything was aligned here as it is locally for you.\n- Where does this go please?\n- Also it takes a few moments for rabbitmq to start up during which you may get a connection refused messages.\n- Thank you. That works. I guess I need to add a depends on to ensure RabbitMQ is started up first (can you see my update - is there anything else I need to do to ensure RabbitMQ is available)?\n- See if 'depends' helps to make sure rabbit starts completely. Else check out solutions suggested in stackoverflow.com/questions/31746182/… for adding a wait. Please accept answer if it solves your problem !\n- I want to make sure I fully understand this. Could you see my update 2? +1 for the hyperlink to the other question (I will upvote when I mark the answer - once I understand).\n- If I change the hostname to my PC name (for the MVC app), then it works. Why do I have to do this with the MVC app specifically?\n- Is your app also run as docker container composed using the docker compose file?\n- yes. I have posted the Docker Compose file (see latest update to question). Thanks.\n- I notice ports are not enclosed in quotes for rabbit docker compose definitions. Please change to `ports: - \"5672:5672\" - \"15672:15672\"`\n- Is adding `expose` when you have `ports` defined something specific to .NET or MVC? I run RabbitMQ in docker-compose for a Django app and definitely don't have `expose` in there.\n- @bluescores, thanks. No, I am just trying to get this to work. Do you have any suggestions? justanotherguys suggestion appears to work.\n- @justanotherguy, I have added quotes to the ports, however this has made no difference. Do you have any other suggestions? Thanks.\n- @bluescores, could you explain what you mean by: \"definitely don't have expose in there\". Do you have EXPOSE at all? Thanks.\n- @w0051977 Correct, I don't have `expose:` at all in mine. If you track down the Dockerfile for the RabbitMQ image you have here, it's exposing the ports there so you are just duplicating that declaration, it should have no effect. Also, when a port is mapped in docker-compose.yml (like `- \"15672:15672\"`) the expose is implied here, with the value on the right of the colon.","metadata":{"transformedAt":"2026-08-18T18:33:20.314Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":222,"estimatedTokens":1667}}1004{"id":"stack-44926606","source":"stackoverflow","questionId":44926606,"title":"How should I structure dockerized RabbitMQ?","tags":["symfony","docker","rabbitmq","docker-compose","amqp"],"text":"Title: How should I structure dockerized RabbitMQ?\nTags: symfony, docker, rabbitmq, docker-compose, amqp\nSource: Stack Overflow\n\nQuestion:\nI am trying to migrate our monolithic PHP Symfony app to a somewhat more scalable solution with Docker. There is some communication between the app and RabbitMQ, and I use `docker-compose` to bring all the containers up, in this case the app and the RabbitMQ server. \n\nThere is a lot of discussions around the topic that one container should spawn only one process, and the Docker best practices is somewhat vague regarding this point:\n\n While this mantra has good intentions, it is not necessarily true that\n there should be only one operating system process per container. In\n addition to the fact that containers can now be spawned with an init\n process, some programs might spawn additional processes of their own\n accord.\n\nDoes it make sense to create a separate Docker container for each RabbitMQ consumer? It kind of feels \"right\" and \"clean\" to not let rabbitmq server know of language/tools used to process the queue. I came up with (relevant parts of `docker-compose.yml`):\n\n```\napp :\n # my php-fpm app container\n\n rabbitmq_server:\n container_name: sf.rabbitmq_server\n build: .docker/rabbitmq\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n networks:\n - app_network\n\n rabbitmq_consumer:\n container_name: sf.rabbit_consumer\n extends: app\n depends_on:\n - rabbitmq_server\n working_dir: /app\n command: \"php bin/console rabbitmq:consumer test\"\n networks:\n - app_network\n```\n\nI could run several consumers in the `rabbitmq_consumer` container using `nohup` or some other way of running them in the background.\n\nI guess my questions are:\n\nCan I somehow automate the \"adding a new consumer\", so that I would not have to edit the \"build script\" of Docker (and others, like ansible) every time the new consumer is added from the code?\n\nDoes it make sense to separate RabbitMQ server from Consumers, or should I use the Rabbit server with consumers running in the background? \n\nOr should they be placed in the background of the app container?\n\n========================================\n\nCode:\n```text\napp :\n # my php-fpm app container\n\n rabbitmq_server:\n container_name: sf.rabbitmq_server\n build: .docker/rabbitmq\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n networks:\n - app_network\n\n rabbitmq_consumer:\n container_name: sf.rabbit_consumer\n extends: app\n depends_on:\n - rabbitmq_server\n working_dir: /app\n command: \"php bin/console rabbitmq:consumer test\"\n networks:\n - app_network\n```\n\n```text\ndocker-compose\n```\n\n```text\ndocker-compose.yml\n```\n\n```text\nrabbitmq_consumer\n```\n\n```text\nnohup\n```\n\n```text\n<?php\n\n// bin/consume.php\nuse App\\Infra\\SymfonyDaemon;\nuse Symfony\\Component\\Process\\ProcessBuilder;\n\nrequire __DIR__.'/../vendor/autoload.php';\n\n$workerBuilder = new ProcessBuilder(['bin/console', 'enqueue:consume', '--setup-broker', '-vvv']);\n$workerBuilder->setPrefix('php');\n$workerBuilder->setWorkingDirectory(realpath(__DIR__.'/..'));\n$daemon = new SymfonyDaemon($workerBuilder);\n$daemon->start(3);\n```\n\n```text\napp_consumer:\n restart: 'always'\n entrypoint: \"php bin/consume.php\"\n depends_on:\n - 'rabbitmq_server'\n```\n\n```text\nconsume.php\n```\n\n```text\n--queue\n```\n\n========================================\n\nComments:\n- Thank you for your insights and a gist. Having a process manager container that can handle additional queues is a great idea that solves and separates many things. And then again, PHP kinda sucks for handling long-running processes, and I'd really like to try some alternatives to swoole, maybe tackle with some python or smth.","metadata":{"transformedAt":"2026-08-18T18:33:20.314Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":9,"totalLines":130,"estimatedTokens":916}}1005{"id":"stack-34314016","source":"stackoverflow","questionId":34314016,"title":"AMQP protocol version mismach when running ActiveMQ and RabbitMQ in a same machine simultanueously","tags":["java","spring","rabbitmq","activemq-classic","amqp"],"text":"Title: AMQP protocol version mismach when running ActiveMQ and RabbitMQ in a same machine simultanueously\nTags: java, spring, rabbitmq, activemq-classic, amqp\nSource: Stack Overflow\n\nQuestion:\nI have been trying to develop a project which use both activeMQ and rabbitMQ at the same time. The dependencies which I added in pom.xml listed below:\n\n```\n\n org.springframework.amqp\n spring-rabbit\n 1.4.6.RELEASE\n \n \n org.springframework\n spring-jms\n 4.2.3.RELEASE\n \n \n org.apache.activemq\n activemq-broker\n 5.13.0\n \n```\n\nAlso, I run the apache-activemq-5.13.0 and rabbitmq-server-3.5.6 at the same time.\nBut unfortunately, I faced an error which is related to the AMQP and demonstrated below:\n\n```\njava.io.IOException\n at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:106)\n at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:102)\n at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:350)\n at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:648)\n at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:678)\n at org.hafiz.framework.common.rabbit.filter.ReceiveRabbitMessageFilter.init(ReceiveRabbitMessageFilter.java:33)\n at org.hafiz.common.filter.PrmTarrifTypeMessageFilter.init(PrmTarrifTypeMessageFilter.java:21)\n\n at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)\n at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)\n at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:105)\n at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4854)\n at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5546)\n at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)\n at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)\n at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)\n at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)\n\n at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1263)\n\n at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1948)\n at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)\n at java.util.concurrent.FutureTask.run(FutureTask.java:262)\n at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)\n at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)\n at java.lang.Thread.run(Thread.java:745)\nCaused by: com.rabbitmq.client.ShutdownSignalException: connection error\n at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67)\n at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:37)\n\n at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:367)\n at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:293)\n ... 20 more\nCaused by: com.rabbitmq.client.MalformedFrameException: AMQP protocol version mismatch; we are version 0-9-1, server sent signature 0,1,0,0\n at com.rabbitmq.client.impl.Frame.protocolVersionMismatch(Frame.java:174)\n at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:111)\n\n at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:139)\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:536)\n ... 1 more\njava.lang.NullPointerException\n at org.hafiz.framework.common.rabbit.filter.ReceiveRabbitMessageFilter.receiveMessage(ReceiveRabbitMessageFilter.java:61)\n at org.hafiz.common.filter.PrmTarrifTypeMessageFilter$1.run(PrmTarrifTypeMessageFilter.java:29)\n at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)\n at java.util.concurrent.FutureTask.run(FutureTask.java:262)\n at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)\n at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)\n at java.lang.Thread.run(Thread.java:745)\n```\n\nI will be appreciate if any one help me tackle this error.\n\n========================================\n\nTop Answer:\nProtocol AMQP works on port 5672, both the message brokers support for this protocol. Just move one of them to another machine.\n\n========================================\n\nCode:\n```text\n<dependency>\n <groupId>org.springframework.amqp</groupId>\n <artifactId>spring-rabbit</artifactId>\n <version>1.4.6.RELEASE</version>\n </dependency>\n <dependency>\n <groupId>org.springframework</groupId>\n <artifactId>spring-jms</artifactId>\n <version>4.2.3.RELEASE</version>\n </dependency>\n <dependency>\n <groupId>org.apache.activemq</groupId>\n <artifactId>activemq-broker</artifactId>\n <version>5.13.0</version>\n </dependency>\n```\n\n```text\njava.io.IOException\n at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:106)\n at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:102)\n at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:350)\n at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:648)\n at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:678)\n at org.hafiz.framework.common.rabbit.filter.ReceiveRabbitMessageFilter.init(ReceiveRabbitMessageFilter.java:33)\n at org.hafiz.common.filter.PrmTarrifTypeMessageFilter.init(PrmTarrifTypeMessageFilter.java:21)\n\n at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)\n at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)\n at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)\n at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4854)\n at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5546)\n at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)\n at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)\n at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)\n at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)\n\n at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1263)\n\n at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1948)\n at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)\n at java.util.concurrent.FutureTask.run(FutureTask.java:262)\n at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)\n at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)\n at java.lang.Thread.run(Thread.java:745)\nCaused by: com.rabbitmq.client.ShutdownSignalException: connection error\n at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67)\n at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:37)\n\n at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:367)\n at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:293)\n ... 20 more\nCaused by: com.rabbitmq.client.MalformedFrameException: AMQP protocol version mismatch; we are version 0-9-1, server sent signature 0,1,0,0\n at com.rabbitmq.client.impl.Frame.protocolVersionMismatch(Frame.java:174)\n at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:111)\n\n at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:139)\n at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:536)\n ... 1 more\njava.lang.NullPointerException\n at org.hafiz.framework.common.rabbit.filter.ReceiveRabbitMessageFilter.receiveMessage(ReceiveRabbitMessageFilter.java:61)\n at org.hafiz.common.filter.PrmTarrifTypeMessageFilter$1.run(PrmTarrifTypeMessageFilter.java:29)\n at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)\n at java.util.concurrent.FutureTask.run(FutureTask.java:262)\n at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)\n at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)\n at java.lang.Thread.run(Thread.java:745)\n```\n\n========================================\n\nComments:\n- Have you configured them to use different ports?\n- @Kenney I have already looked for the config file in the etc folder of the rabbitMQ installation directory. But the only file I found named \"rabbitmq.config.example\". So, I changed the port number in that file to 5673. However I think it is not the right file to change.\n- Have you seen rabbitmq configure - seems to use environment variables. If that fails, you could change the activemq transport configuration. Only one of them need to be changed, after all.\n- @Kenney Thank you for your response, I changed the RabbitMQ port just like the instructions in the link you told. Unfortunately the error has not changed yet.\n- @Kenney I finally succeeded tackling the problem. I don't know why but I couldn't change the RabbitMQ port. Because of that, I changed the default port of ActiveMQ instead. thanks for your help.\n- Thanks for your invaluable answer, but just like I told @Kenney, although I have done what you suggested already, the error has not changed.\n- I finally succeeded in this issue by changing the default port number of ActiveMQ just like you said. thank you very much. @Reza","metadata":{"transformedAt":"2026-08-18T18:33:20.314Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":170,"estimatedTokens":2396}}1006{"id":"stack-40330878","source":"stackoverflow","questionId":40330878,"title":"Celery send_task doesn't send tasks","tags":["python","rabbitmq","celery"],"text":"Title: Celery send_task doesn't send tasks\nTags: python, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI have a server running Celery with RabbitMQ. But when I try to send tasks using send_task, it just returns with an AsyncResult object.\n\nBut the actual task is not running (even though the workers and the queues are empty)\n\n```\nc = Celery(\"tasks\", broker=\"amqp://guest@127.0.0.1//\")\nc.send_task(\"tasks.printing.test_print\", (100), queue=\"print_queue\", routing_key=\"printing.test_print\")\n```\n\nMy celery configuration is:\n\n```\nCELERY_QUEUES = (\n Queue('default', routing_key='task.#'),\n Queue('print_queue', routing_key='printing.#'),\n)\nCELERY_DEFAULT_EXCHANGE = 'tasks'\nCELERY_ROUTES = {\n 'tasks.printing.test_print': {\n 'queue': 'print_queue',\n 'routing_key': 'printing.test_print',\n }}\nBROKER_URL = 'amqp://'\n```\n\nI execute only one worker:\n\n```\ncelery -A celerymain worker --loglevel=debug\n```\n\nThis is it's initial log:\n\n```\n- ** ---------- [config]\n- ** ---------- .> app: __main__:0x7eff96903b50\n- ** ---------- .> transport: amqp://guest:**@localhost:5672//\n- ** ---------- .> results: amqp://\n- *** --- * --- .> concurrency: 4 (prefork)\n-- ******* ---- \n--- ***** ----- [queues] -------------- .> default exchange=tasks(topic) key=task.#\n .> print_queue exchange=tasks(topic) key=printing.#\n\n[tasks] . test_print\n```\n\nThis is the task:\n\n```\nclass test_print(Task):\n\n name = \"test_print\"\n\n def run(self,a):\n log.info(\"running\")\n print a\n```\n\nThe rabbitMQ queue 'print_queue' stays empty and there is nothing new in the rabbitMQ logs.\n\nI have 4 GB free space so it's not a disk space problem.\n\nWhat can be the problem here?\n\n========================================\n\nTop Answer:\n```\n@app.task(name=\"test_print\")\nclass test_print(Task):\n\n name = \"test_print\"\n\n def run(self,a):\n log.info(\"running\")\n print a\n```\n\n========================================\n\nCode:\n```text\nc = Celery(\"tasks\", broker=\"amqp://guest@127.0.0.1//\")\nc.send_task(\"tasks.printing.test_print\", (100), queue=\"print_queue\", routing_key=\"printing.test_print\")\n```\n\n```text\nCELERY_QUEUES = (\n Queue('default', routing_key='task.#'),\n Queue('print_queue', routing_key='printing.#'),\n)\nCELERY_DEFAULT_EXCHANGE = 'tasks'\nCELERY_ROUTES = {\n 'tasks.printing.test_print': {\n 'queue': 'print_queue',\n 'routing_key': 'printing.test_print',\n }}\nBROKER_URL = 'amqp://'\n```\n\n```text\ncelery -A celerymain worker --loglevel=debug\n```\n\n```text\n- ** ---------- [config]\n- ** ---------- .> app: __main__:0x7eff96903b50\n- ** ---------- .> transport: amqp://guest:**@localhost:5672//\n- ** ---------- .> results: amqp://\n- *** --- * --- .> concurrency: 4 (prefork)\n-- ******* ---- \n--- ***** ----- [queues] -------------- .> default exchange=tasks(topic) key=task.#\n .> print_queue exchange=tasks(topic) key=printing.#\n\n[tasks] . test_print\n```\n\n```text\nclass test_print(Task):\n\n name = \"test_print\"\n\n def run(self,a):\n log.info(\"running\")\n print a\n```\n\n```text\n@app.task(name=\"test_print\")\nclass test_print(Task):\n\n name = \"test_print\"\n\n def run(self,a):\n log.info(\"running\")\n print a\n```\n\n========================================\n\nComments:\n- What are you trying to say?","metadata":{"transformedAt":"2026-08-18T18:33:20.314Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":147,"estimatedTokens":813}}1007{"id":"stack-39773289","source":"stackoverflow","questionId":39773289,"title":"Implementing Publish Only Bus in MassTransit v3 with C# and RabbitMQ","tags":["c#","rabbitmq","masstransit"],"text":"Title: Implementing Publish Only Bus in MassTransit v3 with C# and RabbitMQ\nTags: c#, rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nI am trying to implement a publish only bus in MassTransit v3 with C# and RabbitMQ where the bus has no consumer. The concept is messages will be published and queued, then a separate microservice will consume messages from the queue. Looking at this SO answer, receive endpoints must be specified so that messages are actually queued. However this appears to contradict the common gotchas in the MassTransit docs, which states `If you need to only send or publish messages, don’t create any receive endpoints`.\n\nHere is some sample code:\n\n```\npublic class Program\n {\n static void Main(string[] args)\n {\n var bus = BusConfigurator.ConfigureBus();\n\n bus.Start();\n\n bus.Publish(new ItemToQueue { Text = \"Hello World\" }).Wait();\n\n Console.ReadKey();\n\n bus.Stop();\n }\n }\n\n public static class BusConfigurator\n {\n public static IBusControl ConfigureBus()\n {\n var bus = Bus.Factory.CreateUsingRabbitMq(cfg =>\n {\n var host = cfg.Host(new Uri(\"rabbitmq://localhost/\"), hst =>\n {\n hst.Username(\"guest\");\n hst.Password(\"guest\");\n });\n\n cfg.ReceiveEndpoint(host, \"queuename\", e =>\n {\n e.Consumer();\n });\n });\n\n return bus;\n }\n }\n\n public interface IItemToQueue\n {\n string Text { get; set; }\n }\n\n public class ItemToQueue : IItemToQueue\n {\n public string Text { get; set; }\n }\n\n public class MyConsumer : IConsumer\n {\n public async Task Consume(ConsumeContext context)\n {\n await Console.Out.WriteLineAsync(context.Message.Text);\n }\n }\n```\n\nIn this sample, I receive the message in the RabbitMQ queue as expected, and this is consumed by `MyConsumer` which writes Hello World to the console and the message is then removed from the Queue.\n\nHowever, when I remove the following code from the above and re-run the sample:\n\n```\ncfg.ReceiveEndpoint(host, RabbitMqConstants.ValidationQueue, e =>\n{\n e.Consumer();\n});\n```\n\nA temporary queue is created (with a generated name) and the message never seems to be placed into the temporary queue. This queue is then removed when the bus is stopped.\n\nThe problem I have is with a ReceiveEndpoint specified, the messages will be consumed and removed from the queue in the publisher program (meaning the consumer microservice wouldn't process queued items). Without a RecieveEndpoint specified, a temporary queue is used (and the consumer microservice would not know the name of this temporary queue), the message never seems to get queued and the queue is deleted when the bus is stopped which wouldn't be good if the program went down. \n\nThere is an example of a send only bus in the MassTransit docs but it is pretty basic so I was wondering if anyone had any suggestions?\n\n========================================\n\nCode:\n```text\npublic class Program\n {\n static void Main(string[] args)\n {\n var bus = BusConfigurator.ConfigureBus();\n\n bus.Start();\n\n bus.Publish<IItemToQueue>(new ItemToQueue { Text = \"Hello World\" }).Wait();\n\n Console.ReadKey();\n\n bus.Stop();\n }\n }\n\n public static class BusConfigurator\n {\n public static IBusControl ConfigureBus()\n {\n var bus = Bus.Factory.CreateUsingRabbitMq(cfg =>\n {\n var host = cfg.Host(new Uri(\"rabbitmq://localhost/\"), hst =>\n {\n hst.Username(\"guest\");\n hst.Password(\"guest\");\n });\n\n cfg.ReceiveEndpoint(host, \"queuename\", e =>\n {\n e.Consumer<MyConsumer>();\n });\n });\n\n return bus;\n }\n }\n\n public interface IItemToQueue\n {\n string Text { get; set; }\n }\n\n public class ItemToQueue : IItemToQueue\n {\n public string Text { get; set; }\n }\n\n public class MyConsumer : IConsumer<IItemToQueue>\n {\n public async Task Consume(ConsumeContext<IItemToQueue> context)\n {\n await Console.Out.WriteLineAsync(context.Message.Text);\n }\n }\n```\n\n```text\ncfg.ReceiveEndpoint(host, RabbitMqConstants.ValidationQueue, e =>\n{\n e.Consumer<MyConsumer>();\n});\n```\n\n```text\nIf you need to only send or publish messages, don’t create any receive endpoints\n```\n\n```text\nMyConsumer\n```\n\n========================================\n\nComments:\n- While you don't need receive endpoints for publishers/senders, you do need them someplace or else there are no queues bound to the message exchanges, and the messages are not routed anywhere -- and thus gone.\n- Is it simply a matter of getting RabbitMQ set up in the first place? I am in a similar situation and I need to guarantee that the receiver queue receives messages as soon as the application starts sending messages, regardless of the service being up and running at that point, as long as they are being saved and will eventually get processed. If running the service once gets things set up to satisfy this requirement, that's fine. This is an area the documentation could use some examples of. Assuming this works, I'd be happy to write it up.\n- There is an issue in GitHub for this, essentially a don't start but create the topology in RabbitMQ. The issues that come from the wire it up yourself approach is that subtle nuances in the type system may not be manually setup correctly that can cause errors at startup. If you are sending to a specific queue, however, there is a query string parameter to for the sender to bind the exchange to the queue. It's either bind or bindQueue = true.\n- thanks. Can you provide the issue link? I was finally able to get things going this morning. Once I started up once with a consumer, I was able to remove it and still keep the messages on a subsequent run. I'm in dev/explore mode, obviously not a plan for production :) You do raise some questions about types and versioning messages that I've been thinking about, but that's a subject for another post after I play a bit more","metadata":{"transformedAt":"2026-08-18T18:33:20.314Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":167,"estimatedTokens":1508}}1008{"id":"stack-2362560","source":"stackoverflow","questionId":2362560,"title":"RabbitMQ and DB transactions","tags":["database","transactions","rabbitmq"],"text":"Title: RabbitMQ and DB transactions\nTags: database, transactions, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nDoes RabbitMQ support a scenario where a received message acknowledgement is sent on the DB transaction commit?\n\nCurrently we send ack after DB transaction commit. If service fails inbetween, we'll get data duplication - service will get the same message again.\n\nIs there a pattern for this problem?\n\nThanks!\n\n========================================\n\nComments:\n- Take a look at Spring's Support of RabbitMQ (spring-amqp) as it will integrate Rabbit's transactions with your database transactions.","metadata":{"transformedAt":"2026-08-18T18:33:20.314Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":17,"estimatedTokens":152}}1009{"id":"stack-46522329","source":"stackoverflow","questionId":46522329,"title":"Is that safe to send sensitive data via RabbitMQ messages?","tags":["security","ssl","encryption","rabbitmq"],"text":"Title: Is that safe to send sensitive data via RabbitMQ messages?\nTags: security, ssl, encryption, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI need to send sensitive data via RabbitMQ. How messages are stored in queue, when ssl is used? Is it guaranteed that noone can get access messages without certificate or i need to somehow encrypt messages before insert?\n\n========================================\n\nComments:\n- I faced the same issue. Did you find an answer for this?","metadata":{"transformedAt":"2026-08-18T18:33:20.314Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":11,"estimatedTokens":119}}1010{"id":"stack-24784622","source":"stackoverflow","questionId":24784622,"title":"Request-response pattern using Spring amqp library","tags":["spring","rabbitmq","spring-amqp"],"text":"Title: Request-response pattern using Spring amqp library\nTags: spring, rabbitmq, spring-amqp\nSource: Stack Overflow\n\nQuestion:\neveryone. I have an HTTP API for posting messages in a RabbitMQ broker and I need to implement the request-response pattern in order to receive the responses from the server. So I am something like a bridge between the clients and the server. I push the messages to the broker with specific routing-key and there is a Consumer for that messages, which is publishing back massages as response and my API must consume the response for every request. So the diagram is something like this:\n\nSo what I do is the following- For every HTTP session I create a temporary responseQueue(which is bound to the default exchange, with routing key the name of that queue), after that I set the replyTo header of the message to be the name of the response queue(where I will wait for the response) and also set the template replyQueue to that queue. Here is my code:\n\n```\npublic void sendMessage(AbstractEvent objectToSend, final String routingKey) {\n final Queue responseQueue = rabbitAdmin.declareQueue();\n byte[] messageAsBytes = null;\n try {\n messageAsBytes = new ObjectMapper().writeValueAsBytes(objectToSend);\n } catch (JsonProcessingException e) {\n e.printStackTrace();\n }\n MessageProperties properties = new MessageProperties();\n properties.setHeader(\"ContentType\", MessageBodyFormat.JSON);\n properties.setReplyTo(responseQueue.getName());\n requestTemplate.setReplyQueue(responseQueue);\n\n Message message = new Message(messageAsBytes, properties);\n Message receivedMessage = (Message)requestTemplate.convertSendAndReceive(routingKey, message);\n}\n```\n\nSo what is the problem: The message is sent, after that it is consumed by the Consumer and its response is correctly sent to the right queue, but for some reason it is not taken back in the convertSendAndReceived method and after the set timeout my receivedMessage is null. So I tried to do several things- I started to inspect the spring code(by the way it's a real nightmare to do that) and saw that is I don't declare the response queue it creates a temporal for me, and the replyTo header is set to the name of the queue(the same what I do). The result was the same- the receivedMessage is still null. After that I decided to use another template which uses the default exchange, because the responseQueue is bound to that exchange:\n\n```\nrequestTemplate.send(routingKey, message);\nMessage receivedMessage = receivingTemplate.receive(responseQueue.getName());\n```\n\nThe result was the same- the responseMessage is still null. \nThe versions of the amqp and rabbit are respectively 1.2.1 and 1.2.0. So I am sure that I miss something, but I don't know what is it, so if someone can help me I would be extremely grateful.\n\n========================================\n\nCode:\n```text\npublic void sendMessage(AbstractEvent objectToSend, final String routingKey) {\n final Queue responseQueue = rabbitAdmin.declareQueue();\n byte[] messageAsBytes = null;\n try {\n messageAsBytes = new ObjectMapper().writeValueAsBytes(objectToSend);\n } catch (JsonProcessingException e) {\n e.printStackTrace();\n }\n MessageProperties properties = new MessageProperties();\n properties.setHeader(\"ContentType\", MessageBodyFormat.JSON);\n properties.setReplyTo(responseQueue.getName());\n requestTemplate.setReplyQueue(responseQueue);\n\n Message message = new Message(messageAsBytes, properties);\n Message receivedMessage = (Message)requestTemplate.convertSendAndReceive(routingKey, message);\n}\n```\n\n```text\nrequestTemplate.send(routingKey, message);\nMessage receivedMessage = receivingTemplate.receive(responseQueue.getName());\n```\n\n```text\nSimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\ncontainer.setConnectionFactory(rabbitConnectionFactory);\ncontainer.setQueues(responseQueue);\ncontainer.setMessageListener(requestTemplate);\n```\n\n```text\nRabbitTemplate\n```\n\n```text\ndoSendAndReceiveWithFixed\n```\n\n```text\nrequestTemplate.setReplyQueue(responseQueue)\n```\n\n```text\nReplyQueue\n```\n\n```text\nreply\n```\n\n```text\nListenerContainer\n```\n\n```text\ncorrelation\n```\n\n```text\nRabbitTemplate.sendAndReceive\n```\n\n```text\ncorrelationId\n```\n\n```text\nresponseQueue\n```\n\n```text\ncorrelationId\n```\n\n```text\nMessage\n```\n\n```text\nJackson2JsonMessageConverter\n```\n\n```text\nRabbitTemplate\n```\n\n```text\nobjectToSend\n```\n\n========================================\n\nComments:\n- Yeah, the important part which I was missing was the correlationId as you mentioned. I forgot to set it when I was sending back the response. Thanks a lot!","metadata":{"transformedAt":"2026-08-18T18:33:20.314Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":18,"totalLines":136,"estimatedTokens":1157}}1011{"id":"stack-5290126","source":"stackoverflow","questionId":5290126,"title":"offline web application design recommendation","tags":["ruby-on-rails","offline","rabbitmq"],"text":"Title: offline web application design recommendation\nTags: ruby-on-rails, offline, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI want to know which is the best architecture to adopt for this case :\n\n- I have many shops that connect to a web application developed using Ruby on Rails.\n\n- internet is not reachable all the time\n\n- The solution was to develop an offline system which requires installing a local copy of the distant database.\n\nAll this wad already developed.\nNow what I want to do :\n\n- Work always on the local copy of the database.\n\n- Any change on the local database should be synchronized with distant database.\n\n- All the local copies should have the same data in other local copies.\n\nTo resolve this problem I thought about using a JMS like software eventually Rabbit MQ.\nThis consists on pushing any sql request into a JMS queue that will be executed on the distant instance of the application which will insert into the distant DB and push the insert or SQL statement into another queue that will be read by all the local instances. This seems complicated and should slow down the application.\n\nIs there a design or recommendation that I must apply to resolve this kind of problem ?\n\n========================================\n\nTop Answer:\nYou can do that but essentially you are developing your own replication engine. Those things can be a bit tricky to get right (what happens if m1 and m3 are executed on replica r1, but m2 isn't?) I wouldn't want to develop something like that unless you are sure you have the resources to make it work.\n\nI would look into existing off-the shelf replication solution. If you are already using a SQL DB it probably has some support for it. Look here for more details if you are using MySQL\n\nAlternatively, if you are willing to explore other backends, I heard that CouchDB has great support for replication. I also heard of people using git libraries to do that sort of thing.\n\n**Update**: After your comment, I realize you already use MySql replication and are looking for solution for re-syncing the databases after being offline. \n\nEven in that case RabbitMQ doesn't help you at all since it requires constant connection to work, so you are back to square one. Easiest solution would be to just write all the changes (SQL commands) into a text file at a remote location, then when you get connection back copy that file (scp, ftp, emaill or whatever) to master server, run all the commands there and then just resync all the replicas.\n\nDepending on your specific project you may also need to make sure there are no conflicts when running commands from different remote location but there is no general technical solution to this. Again, depending on the project, you may want to cancel one of the transactions, notify the users that it happened and so on.\n\n========================================\n\nComments:\n- BTW RabbitMQ requires constant connection to work. You can work around this by creating a local buffer of messages and then pushing them all to server once you have connection.\n- Agreed. Also, there has to be a conflict resolution code. What happens if client 1 and client 2 have modified record 1 offline and then synced? Whose change \"wins\"? If manual resolution is required, how's that handled?\n- thx for you help, I'm using mysql replication, but when I go into offline mode, i'm obliged to stop replication, since the slave (witch is the mysql local copy). Now this replication is very slow specially with a big database. don't know rabbitmq is the good solution or no ?\n- You welcome, I guess I am not entirely clear on what exactly is the issue you are facing. I don't see how RabbitMQ can help since it won't work offline either. I've added a general solution to my answer above, if it is not what you are looking for, can you please clarify? Especially you mention that the process is slow - what exactly is slow? We use mysql replication all the time and it works reasonably fast for a lot of data.\n- Just to clarify - how often this resync needs to happen? Once a day? Or every minute?\n- the database is big (4Go) and sometimes it doesn't replication. rabbitmq we will only use the online mode . I want to do : work always on the local copy of the database and any change on the local database should be synchronized with distant database. after the system supports the distribution of the message to different subscribers\n- thanks for your reply, actually the application is already developed with mysql during 2 years and I can't change to couchDB now\n- you think the PostgreSQL replication is better than mysql ? and that it is easy to convert the database into \"PostgreSQL\"?\n- I'm not a DBA, so I can't really answer that question. Both PostgreSQL and MySQL have replication, what you want is more complex though. You need a distributed replication engine with multiple write nodes. This is a lot harder to accomplish.","metadata":{"transformedAt":"2026-08-18T18:33:20.314Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":54,"estimatedTokens":1226}}1012{"id":"stack-15059083","source":"stackoverflow","questionId":15059083,"title":"Is there an easy way to subscribe to the default error queue in EasyNetQ?","tags":["rabbitmq","easynetq"],"text":"Title: Is there an easy way to subscribe to the default error queue in EasyNetQ?\nTags: rabbitmq, easynetq\nSource: Stack Overflow\n\nQuestion:\nIn my test application I can see messages that were processed with an exception being automatically inserted into the default EasyNetQ_Default_Error_Queue, which is great. I can then successfully dump or requeue these messages using the Hosepipe, which also works fine, but requires dropping down to the command line and calling against both Hosepipe and the RabbitMQ API to purge the queue of retried messages.\n\nSo I'm thinking the easiest approach for my application is to simply subscribe to the error queue, so I can re-process them using the same infrastructure. But in EastNetQ, the error queue seems to be special. We need to subscribe using a proper type and routing ID, so I'm not sure what these values should be for the error queue:\n\n`bus.Subscribe(\"and-this\", ReprocessErrorMessage);`\n\nCan I use the simple API to subscribe to the error queue, or do I need to dig into the advanced API?\n\nIf the type of my original message was `TestMessage`, then I'd like to be able to do something like this:\n\n`bus.Subscribe>(\"???\", ReprocessErrorMessage);`\n\nwhere `ErrorMessage` is a class provided by EasyNetQ to wrap all errors. Is this possible?\n\n========================================\n\nTop Answer:\nCode that works:\n(I took a guess)\n\nThe screwyness with the 'foo' is because if I just pass that function HandleErrorMessage2 into the Consume call, it can't figure out that it returns a void and not a Task, so can't figure out which overload to use. (VS 2012)\nAssigning to a var makes it happy.\nYou will want to catch the return value of the call to be able to unsubscribe by disposing the object.\n\nAlso note that Someone used a System Object name (Queue) instead of making it a EasyNetQueue or something, so you have to add the using clarification for the compiler, or fully specify it.\n\n```\nusing Queue = EasyNetQ.Topology.Queue;\n\n private const string QueueName = \"EasyNetQ_Default_Error_Queue\";\n public static void Should_be_able_to_subscribe_to_error_messages(IBus bus)\n {\n Action , MessageReceivedInfo> foo = HandleErrorMessage2;\n\n IQueue queue = new Queue(QueueName,false);\n bus.Advanced.Consume(queue, foo);\n }\n\n private static void HandleErrorMessage2(IMessage msg, MessageReceivedInfo info)\n {\n }\n```\n\n========================================\n\nCode:\n```text\nbus.Subscribe<WhatShouldThisBe>(\"and-this\", ReprocessErrorMessage);\n```\n\n```text\nTestMessage\n```\n\n```text\nbus.Subscribe<ErrorMessage<TestMessage>>(\"???\", ReprocessErrorMessage);\n```\n\n```text\nErrorMessage\n```\n\n```text\n[Test]\n[Explicit(\"Requires a RabbitMQ server on localhost\")]\npublic void Should_be_able_to_subscribe_to_error_messages()\n{\n var errorQueueName = new Conventions().ErrorQueueNamingConvention();\n var queue = Queue.DeclareDurable(errorQueueName);\n var autoResetEvent = new AutoResetEvent(false);\n\n bus.Advanced.Subscribe<SystemMessages.Error>(queue, (message, info) =>\n {\n var error = message.Body;\n\n Console.Out.WriteLine(\"error.DateTime = {0}\", error.DateTime);\n Console.Out.WriteLine(\"error.Exception = {0}\", error.Exception);\n Console.Out.WriteLine(\"error.Message = {0}\", error.Message);\n Console.Out.WriteLine(\"error.RoutingKey = {0}\", error.RoutingKey);\n\n autoResetEvent.Set();\n return Task.Factory.StartNew(() => { });\n });\n\n autoResetEvent.WaitOne(1000);\n}\n```\n\n```text\nusing Queue = EasyNetQ.Topology.Queue;\n\n private const string QueueName = \"EasyNetQ_Default_Error_Queue\";\n public static void Should_be_able_to_subscribe_to_error_messages(IBus bus)\n {\n Action <IMessage<Error>, MessageReceivedInfo> foo = HandleErrorMessage2;\n\n IQueue queue = new Queue(QueueName,false);\n bus.Advanced.Consume<Error>(queue, foo);\n }\n\n private static void HandleErrorMessage2(IMessage<Error> msg, MessageReceivedInfo info)\n {\n }\n```\n\n========================================\n\nComments:\n- Thanks for your help Mike. Do you think it would be a good idea to expose a friendly wrapper for this? By default, the simple API writes to this error queue, so to me it makes sense for it to have a mechanism to transparently consume these errors too. Even with your code above, I think I need to have some kind of switch statement in the error message handler (`switch (error.BasicProperties.Type)`), which will then allow me to deserialize the original message to the correct type, which is a bit ugly. It would be nice if I could subscribe to the specific type of error in which I am interested.\n- BTW I love the EastNetQ library. Thanks for your hard work and great documentation.\n- Thanks for the kind words! I've added your suggestion to the issues list github.com/mikehadlow/EasyNetQ/issues/71 but I'm not completely convinced.\n- The code above no longer compiles, the link to the source is no longer valid, and I can't find anything that answers the question anywhere. Was this rewritten in the last year so it followed the naming convention? How is it done now?\n- @TraderhutGames Yes, the API has been considerably changed since then. You still have to use the advanced API to directly access the queue though.","metadata":{"transformedAt":"2026-08-18T18:33:20.314Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":118,"estimatedTokens":1303}}1013{"id":"stack-23557473","source":"stackoverflow","questionId":23557473,"title":"Configure External Broker(RabbitMQ) In Spring4+STOMP+SockJS Application","tags":["rabbitmq","stomp","sockjs","spring-4"],"text":"Title: Configure External Broker(RabbitMQ) In Spring4+STOMP+SockJS Application\nTags: rabbitmq, stomp, sockjs, spring-4\nSource: Stack Overflow\n\nQuestion:\nI am working on a chat application developed using Spring4 Messaging and STOMP implemented with SockJS. The application works fine when I use the **Simple Message Broker** :\n\n```\nconfig.enableSimpleBroker(\"/queue/\", \"/topic/\");\n```\n\nBut, now we have a requirement to use an external broker(RabbitMQ) with the same application. For that, I changed the above code with the following:\n\n```\n// config.enableSimpleBroker(\"/queue/\", \"/topic/\");\nconfig.enableStompBrokerRelay(\"/queue\", \"/topic\");\n```\n\nMy client side is connecting using STOMP client as below:\n\n```\nstompClient.connect({}, function(frame) {\n // subscribe to topics or queues and other stuff\n});\n```\n\nBut, I got the following exception:\n\n```\n2014-05-09 11:13:13,567 ERROR o.s.s.support.TaskUtils$LoggingErrorHandler - Unexpected error occurred in scheduled task.\norg.springframework.messaging.MessageDeliveryException: Message broker is not active.\nat org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler.handleMessageInternal(StompBrokerRelayMessageHandler.java:378) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler.handleMessage(AbstractBrokerMessageHandler.java:171) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat org.springframework.messaging.support.ExecutorSubscribableChannel.sendInternal(ExecutorSubscribableChannel.java:64) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat org.springframework.messaging.support.AbstractMessageChannel.send(AbstractMessageChannel.java:116) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat org.springframework.messaging.support.AbstractMessageChannel.send(AbstractMessageChannel.java:98) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat org.springframework.messaging.simp.SimpMessagingTemplate.doSend(SimpMessagingTemplate.java:129) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat org.springframework.messaging.simp.SimpMessagingTemplate.doSend(SimpMessagingTemplate.java:48) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:93) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat org.springframework.messaging.core.AbstractMessageSendingTemplate.convertAndSend(AbstractMessageSendingTemplate.java:146) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat org.springframework.messaging.core.AbstractMessageSendingTemplate.convertAndSend(AbstractMessageSendingTemplate.java:112) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat org.springframework.messaging.core.AbstractMessageSendingTemplate.convertAndSend(AbstractMessageSendingTemplate.java:106) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat com.attomic.chat.service.ActiveUserPinger.pingUsers(ActiveUserPinger.java:24) ~[ActiveUserPinger.class:na]\nat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_05]\nat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_05]\nat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_05]\nat java.lang.reflect.Method.invoke(Method.java:601) ~[na:1.7.0_05]\nat org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [na:1.7.0_05]\nat java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351) [na:1.7.0_05]\nat java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178) [na:1.7.0_05]\nat java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) [na:1.7.0_05]\nat java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.7.0_05]\nat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [na:1.7.0_05]\nat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [na:1.7.0_05]\nat java.lang.Thread.run(Thread.java:722) [na:1.7.0_05]\n```\n\nI checked RabbitMQ and it is up and running. The **STOMP plugin** is also installed and working fine in RabbitMQ.I also tried the following:\n\n```\n1. config.enableStompBrokerRelay(\"/queue\", \"/topic\").setSystemLogin(\"guest\").setSystemPasscode(\"guest\");\n2. config.enableStompBrokerRelay(\"/queue\", \"/topic\").setClientLogin(\"guest\").setClientPasscode(\"guest\");\n3. config.enableStompBrokerRelay(\"/queue\", \"/topic\").setRelayHost(\"localhost\").setRelayPort(\"15672\");\n```\n\nI have done quite a bit of search but still unable to resolve this. Can somebody throw some light on this?\n\n========================================\n\nCode:\n```text\nconfig.enableSimpleBroker(\"/queue/\", \"/topic/\");\n```\n\n```text\n// config.enableSimpleBroker(\"/queue/\", \"/topic/\");\nconfig.enableStompBrokerRelay(\"/queue\", \"/topic\");\n```\n\n```text\nstompClient.connect({}, function(frame) {\n // subscribe to topics or queues and other stuff\n});\n```\n\n```text\n2014-05-09 11:13:13,567 ERROR o.s.s.support.TaskUtils$LoggingErrorHandler - Unexpected error occurred in scheduled task.\norg.springframework.messaging.MessageDeliveryException: Message broker is not active.\nat org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler.handleMessageInternal(StompBrokerRelayMessageHandler.java:378) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler.handleMessage(AbstractBrokerMessageHandler.java:171) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat org.springframework.messaging.support.ExecutorSubscribableChannel.sendInternal(ExecutorSubscribableChannel.java:64) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat org.springframework.messaging.support.AbstractMessageChannel.send(AbstractMessageChannel.java:116) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat org.springframework.messaging.support.AbstractMessageChannel.send(AbstractMessageChannel.java:98) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat org.springframework.messaging.simp.SimpMessagingTemplate.doSend(SimpMessagingTemplate.java:129) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat org.springframework.messaging.simp.SimpMessagingTemplate.doSend(SimpMessagingTemplate.java:48) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:93) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat org.springframework.messaging.core.AbstractMessageSendingTemplate.convertAndSend(AbstractMessageSendingTemplate.java:146) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat org.springframework.messaging.core.AbstractMessageSendingTemplate.convertAndSend(AbstractMessageSendingTemplate.java:112) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat org.springframework.messaging.core.AbstractMessageSendingTemplate.convertAndSend(AbstractMessageSendingTemplate.java:106) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat com.attomic.chat.service.ActiveUserPinger.pingUsers(ActiveUserPinger.java:24) ~[ActiveUserPinger.class:na]\nat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_05]\nat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_05]\nat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_05]\nat java.lang.reflect.Method.invoke(Method.java:601) ~[na:1.7.0_05]\nat org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]\nat java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [na:1.7.0_05]\nat java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351) [na:1.7.0_05]\nat java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178) [na:1.7.0_05]\nat java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) [na:1.7.0_05]\nat java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.7.0_05]\nat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [na:1.7.0_05]\nat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [na:1.7.0_05]\nat java.lang.Thread.run(Thread.java:722) [na:1.7.0_05]\n```\n\n```text\n1. config.enableStompBrokerRelay(\"/queue\", \"/topic\").setSystemLogin(\"guest\").setSystemPasscode(\"guest\");\n2. config.enableStompBrokerRelay(\"/queue\", \"/topic\").setClientLogin(\"guest\").setClientPasscode(\"guest\");\n3. config.enableStompBrokerRelay(\"/queue\", \"/topic\").setRelayHost(\"localhost\").setRelayPort(\"15672\");\n```\n\n```text\nstompClient.connect({}, function(frame) {\n // subscribe to topics or queues and other stuff\n});\n```\n\n```text\nstompClient.connect('guest', 'guest', function(frame) {\n // subscribe to topics or queues and other stuff\n});\n```\n\n========================================\n\nComments:\n- If that is the only thing you changed you are missing several other properties. See also stackoverflow.com/questions/20747283/… and the javadoc\n- I have tried all the properties(edited the question). I think there is something missing on the client side, but don't know what.\n- While slightly old, it might be worth while to mention that you can avoid passing in the user name and password with the connect if you specify the client login credentials from Spring AND set the default user for the RabbitMQ stomp plugin. See the Default User Section for more details","metadata":{"transformedAt":"2026-08-18T18:33:20.315Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":7,"totalLines":142,"estimatedTokens":2547}}1014{"id":"stack-64183725","source":"stackoverflow","questionId":64183725,"title":"Separate dead letter exchange necessary in RabbitMQ?","tags":["architecture","rabbitmq","dead-letter"],"text":"Title: Separate dead letter exchange necessary in RabbitMQ?\nTags: architecture, rabbitmq, dead-letter\nSource: Stack Overflow\n\nQuestion:\nI've set up a dead letter routing with my queue to requeue rejected messages with a delay of several seconds, preventing temporary consumer errors to clog up the queue. I've set this up so both the work queue and the dead letter queue are bound to the same exchange:\n\nhttps://i.sstatic.net/TeYPd.png\n\nExternally produced, incoming messages are routed to the exchange, which places them in the work queue. During processing the message, a consumer might fail due to some temporary errors (think a crawler receiving an error 500 from a website).\n\nInstead of rejecting the message and having it\nplaced at the head of the queue again (leading to an infinite loop), we route rejected messages (with `requeue=0`) to the exchange, adding the dead letter queue as the routing key. Here, every message receives a TTL of X seconds, after which it will be rejected, and therefore routed back to the exchange with the routing key se to the original work queue.\n\nHowever, looking at literature and examples online, everyone seems to recommend routing to a separate dead letter exchange:\n\nhttps://i.sstatic.net/AogEr.png\n\nExternally produced, incoming messages are routed to the work exchange, which places them in the work queue. If a consumer fails, messages are rejected (with `requeue=0`) and will be routed to the dead letter exchange. The dead letter exchange routes the messages to the dead letter queue, where the message TTL will expire, and the again-rejected messages will be routed back to the work exchange.\n\nAre there some crucial advantage of the second design compared to the first? I cannot identify any, but then again I'm not too confident with RabbitMQ.\n\n========================================\n\nCode:\n```text\nrequeue=0\n```\n\n```text\nrequeue=0\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.315Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":32,"estimatedTokens":473}}1015{"id":"stack-42694242","source":"stackoverflow","questionId":42694242,"title":"Never ending messages with RabbitMQ","tags":["c#","rabbitmq","masstransit"],"text":"Title: Never ending messages with RabbitMQ\nTags: c#, rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nWe are using MassTransit(3.5.2) together with RabbitMQ(3.6.6). We are having a problem with a message that never gets removed from the queue (even if we have read and consumed the message).\nTo read from the queue we have implemented an IConsumer class. \n\nThe only thing we are doing is closing the sender (abrupt). \nAfter that the message never gets acknowledged and rabbitmq is continuing to send the same message to our consumer all the time.\n\nHave anyone else got the same problem and how did you solve this issue?\n\n:: Update from comments ::\n\nWe had already checked the log files and it says: \"closing AMQP connection ([::1]:57008 -> [::1]:5672): client unexpectedly closed TCP connection \". \nThat doesnt feel that wierd since i am actually closing the tcp connection unexpectedly with killing the .exe file :)\n\nRegarding the log files from masstransit we have also done that and we do not get any error, we only gets two debug messages. \nOne that we have received and one that we are sending the result. \nDEBUG 47 MassTransit.Messages - RECEIVE rabbitmq://localhost/[VirtualHost]/[ConsumerName] N/A ContractCommand CommandConsumer(00:00:00.0364932) \nDEBUG 30 MassTransit.Messages - SEND rabbitmq://localhost/[VirtualHost]/bus-[ComputerName]-[SenderName].Server.vshost-4bayyydsf9rfs3qzbdkgx8bbr1?durable=false&autodelete=true d0700000-762f-c85b-f03a-08d4679c39d4 Result\n\nOne observation that I have made in my consumer is that at the same time as I am force closing my sender I get an MessageNotConfirmedException followed by some AlreadyClosedException from RabbitMQ. \nAnd it's after that we get in the infinite loop when MT does not set the ACK/NACK. (and in the infinite loop I do not get any MessagenNotConfirmedException). \nAlso for my consumer to properly work again I need to restart my consumer then it will be ACK/NACKed. \n\nMessageNotConfirmedMessage: \"'MassTransit.RabbitMqTransport.MessageNotConfirmedException' in mscorlib.dll Additional information: rabbitmq://localhost/[VirtualHost]/bus-[ComputerName]-[Service].Server.vshost-4bayyydsf9rfsf3ybdkgxg5h8b => The message was not confirmed by RabbitMQ\n'RabbitMQ.Client.Exceptions.AlreadyClosedException' Additional information: Already closed: The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=404, text=\"NOT_FOUND - no exchange 'bus-[ComputerName]-[ServiceName].Server.vshost-4bayyydsf9rfs3qzbdkgx8bbr1' in vhost '[VirtualHost]'\", classId=60, methodId=40, cause=\n\n========================================\n\nTop Answer:\nWhen you are done processing your queue object, you can mark it as successful by `BasicAck(e.DeliveryTag, false)`\n\n========================================\n\nCode:\n```text\nBasicAck(e.DeliveryTag, false)\n```\n\n========================================\n\nComments:\n- Which version of MT?\n- Consumer code would help. Not sure what is (abrupt)\n- I have updated the versions in the question now (3.5.2 for MT and 3.6.6 for RabbitMQ). Regarding Consumer code it does just perform an validation and then returning. If I wasnt clear it's the SENDER that I close abrupt(just killing the .exe) and it's the consumer that gets the same message again and again after I have closed the sender. If I would close the sender in a controlled fashion (when not sending messages) I do not get any problem. So it's ONLY when killing the process at the same time as I am sending messages.\n- You should add a logging library to your consumer service, and set the logging level to debug, and see what comes out of it. Because there will be an error logged someplace explaining the issue. I'm guessing it can't create the _error queue to move the bad message. Also check the RabbitMQ broker log file for invalid/inconsistent exchanges and/or bindings.\n- Thanks for your input Chris, We had already checked the log files and it says: \"closing AMQP connection ([::1]:57008 -> [::1]:5672): client unexpectedly closed TCP connection \". That doesnt feel that wierd since i am actually closing the tcp connection unexpectedly with killing the .exe file :)\n- Regarding the log files from masstransit we have also done that and we do not get any error, we only gets two debug messages. One that we have received and one that we are sending the result. DEBUG 47 MassTransit.Messages - RECEIVE rabbitmq://localhost/[VirtualHost]/[ConsumerName] N/A ContractCommand CommandConsumer(00:00:00.0364932) DEBUG 30 MassTransit.Messages - SEND rabbitmq://localhost/[VirtualHost]/bus-[ComputerName]-[Sende‌​rName].Server.vshost‌​-4bayyydsf9rfs3qzbdk‌​gx8bbr1?durable=fals‌​e&autodelete=true d0700000-762f-c85b-f03a-08d4679c39d4 Result\n- One observation that I have made in my consumer is that at the same time as I am force closing my sender I get an MessageNotConfirmedException followed by some AlreadyClosedException from RabbitMQ. And it's after that we get in the infinite loop when MT does not set the ACK/NACK. (and in the infinite loop I do not get any MessagenNotConfirmedException). Also for my consumer to properly work again I need to restart my consumer then it will be ACK/NACKed.\n- MessageNotConfirmedMessage: \"'MassTransit.RabbitMqTransport.MessageNotConfirmedException‌​' in mscorlib.dll Additional information: rabbitmq://localhost/[VirtualHost]/bus-[ComputerName]-[Servi‌​ce].Server.vshost-4b‌​ayyydsf9rfsf3ybdkgxg‌​5h8b => The message was not confirmed by RabbitMQ\"\n- 'RabbitMQ.Client.Exceptions.AlreadyClosedException' Additional information: Already closed: The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=404, text=\"NOT_FOUND - no exchange 'bus-[ComputerName]-[ServiceName].Server.vshost-4bayyydsf9rf‌​s3qzbdkgx8bbr1' in vhost '[VirtualHost]'\", classId=60, methodId=40, cause=\n- Thats what MT should be doing in the background. So it doesn't feel like an acceptable solution to hack in on my own.","metadata":{"transformedAt":"2026-08-18T18:33:20.315Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":55,"estimatedTokens":1511}}1016{"id":"stack-37724046","source":"stackoverflow","questionId":37724046,"title":"RabbitMQ. Java client. Is it possible to acknowledge message not on the same thread it was received?","tags":["java","multithreading","rabbitmq"],"text":"Title: RabbitMQ. Java client. Is it possible to acknowledge message not on the same thread it was received?\nTags: java, multithreading, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI want to fetch several messages, handle them and ack them all together after that. So basically I receive a message, put it in some queue and continue receiving messages from rabbit. Different thread will monitor this queue with received messages and process them when amount is sufficient. All I've been able to found about ack contains examples only for one message which processed on the same thread. Like this(from official docs):\n\n```\nchannel.basicQos(1);\n\nfinal Consumer consumer = new DefaultConsumer(channel) {\n @Override\n public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {\n String message = new String(body, \"UTF-8\");\n\n System.out.println(\" [x] Received '\" + message + \"'\");\n try {\n doWork(message);\n } finally {\n System.out.println(\" [x] Done\");\n channel.basicAck(envelope.getDeliveryTag(), false);\n }\n }\n};\n```\n\nAnd also documentation says this:\n\n Channel instances must not be shared between threads. Applications\n should prefer using a Channel per thread instead of sharing the same\n Channel across multiple threads. While some operations on channels are\n safe to invoke concurrently, some are not and will result in incorrect\n frame interleaving on the wire.\n\nSo I'm confused here. If I'm acking some message and at the same time the channel is receiving another message from rabbit, is it considered to be two operations at the time? It seems to me like yes. \n\nI've tried to acknowledge message on the same channel from different thread and it seems to work, but documentation says that I should not channels between threads. So I've tried to do acknowledgment on different thread with different channel, but it fails, because delivery tag is unknown for this channel.\n\nIs it possible to acknowledge message not on the same thread it was received?\n\n**UPD**\nExample piece of code of what I want. It's in scala, but I think it's straightforward.\n\n```\ncase class AmqpMessage(envelope: Envelope, msgBody: String)\n\n val queue = new ArrayBlockingQueue[AmqpMessage](100)\n\n val consumeChannel = connection.createChannel()\n consumeChannel.queueDeclare(queueName, true, false, true, null)\n consumeChannel.basicConsume(queueName, false, new DefaultConsumer(consumeChannel) {\n override def handleDelivery(consumerTag: String,\n envelope: Envelope,\n properties: BasicProperties,\n body: Array[Byte]): Unit = {\n queue.put(new AmqpMessage(envelope, new String(body)))\n }\n })\n\n Future {\n // this is different thread\n val channel = connection.createChannel()\n while (true) {\n try {\n val amqpMessage = queue.take()\n channel.basicAck(amqpMessage.envelope.getDeliveryTag, false) // doesn't work\n consumeChannel.basicAck(amqpMessage.envelope.getDeliveryTag, false) // works, but seems like not thread safe\n } catch {\n case e: Exception => e.printStackTrace()\n }\n }\n }\n```\n\n========================================\n\nTop Answer:\nFor me your solution is correct. You are not sharing channels across thread.\nYou never pass your channel object to another thread, you use it on the same thread that receives the messages.\n\nIt is not possible that you are\n\n'*acking some message and at the same time the channel is receiving another message from rabbit*'\n\nIf your are in *handleDelivery* method, that thread is blocked by your code and has no chance of receiving another message.\n\nAs you found out, you cannot acknowledge message using channel other than channel that was used to receive message.\n\nYou must acknowledge using same channel, and you must do that on the same thread that was receiving message. So you may pass channel object to other methods, classes but you must be careful not to pass it to another thread.\n\nI use this solution in my project It uses RabbitMQ listner and Spring Integration. For every AMQP message, one org.springframework.integration.Message is created. That message has AMPQ message body as payload, and AMQP channel and delivery tag as headers of my org.springframework.integration.Message.\n\nIf you want to acknowledge several messages, and they were delivered on the same channel, you should use \n\n```\nchannel.basicAck(envelope.getDeliveryTag(), true);\n```\n\nFor multiple channels, efficient algorithm is\n\n- Lets say you have 100 messages, delivered using 10 channels\n\n- you need to find max deliveryTag for each channel.\n\n- invoke *channel.basicAck(maxDeliveryTagForThatChannel, true);*\n\nThis way, you need 10 basicAck (network roundtrips) not 100.\n\n========================================\n\nCode:\n```text\nchannel.basicQos(1);\n\nfinal Consumer consumer = new DefaultConsumer(channel) {\n @Override\n public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {\n String message = new String(body, \"UTF-8\");\n\n System.out.println(\" [x] Received '\" + message + \"'\");\n try {\n doWork(message);\n } finally {\n System.out.println(\" [x] Done\");\n channel.basicAck(envelope.getDeliveryTag(), false);\n }\n }\n};\n```\n\n```text\ncase class AmqpMessage(envelope: Envelope, msgBody: String)\n\n val queue = new ArrayBlockingQueue[AmqpMessage](100)\n\n val consumeChannel = connection.createChannel()\n consumeChannel.queueDeclare(queueName, true, false, true, null)\n consumeChannel.basicConsume(queueName, false, new DefaultConsumer(consumeChannel) {\n override def handleDelivery(consumerTag: String,\n envelope: Envelope,\n properties: BasicProperties,\n body: Array[Byte]): Unit = {\n queue.put(new AmqpMessage(envelope, new String(body)))\n }\n })\n\n Future {\n // this is different thread\n val channel = connection.createChannel()\n while (true) {\n try {\n val amqpMessage = queue.take()\n channel.basicAck(amqpMessage.envelope.getDeliveryTag, false) // doesn't work\n consumeChannel.basicAck(amqpMessage.envelope.getDeliveryTag, false) // works, but seems like not thread safe\n } catch {\n case e: Exception => e.printStackTrace()\n }\n }\n }\n```\n\n```text\nchannel.basicAck(envelope.getDeliveryTag(), true);\n```\n\n```text\nArrayBlockingQueue\n```\n\n```text\nArrayBlockingQueue\n```\n\n========================================\n\nComments:\n- Could you please elaborate on this part `I want to fetch several messages, handle them and ack them all together after that. So basically I receive a message, put it in some **queue** and continue receiving messages from rabbit.` What is the queue between **? Another RMQ queue or something else?\n- @cantSleepNow just simple java in-memory blocking queue. I've posted example to clarify. Sorry for misleading.\n- \"Is it possible to acknowledge message not on the same thread it was received?\" the answer is \"yes\"\n- It's not my solution, it's example from documentation to illustrate how rabbit team suggests to handle ack. But it's not suitable for my needs. Probably I need to post example what I want to do.\n- It seems like it's ok to ack from different channel. But thank you anyway.\n- Yes, it's there, but it's not processed. I want to ack after I process several messages(take them from java queue, do some stuff, ack), not after I put them in java queue.\n- So, process them once you receive and than do a multiple ACK. From the consuming thread","metadata":{"transformedAt":"2026-08-18T18:33:20.315Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":183,"estimatedTokens":1885}}1017{"id":"stack-49521257","source":"stackoverflow","questionId":49521257,"title":"How to publish a AMQP message with Spring to a parking lot queue, after a loop in dead letter queue and TTL in a specific scenario?","tags":["java","spring","rabbitmq","amqp","spring-amqp"],"text":"Title: How to publish a AMQP message with Spring to a parking lot queue, after a loop in dead letter queue and TTL in a specific scenario?\nTags: java, spring, rabbitmq, amqp, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI would like to achieve following scenario in my application:\n\n- If a business error occurs, the message should be send from the incomingQueue to the deadLetter Queue and delayed there for 10 seconds\n\n- The step number 1 should be repeated 3 times\n\n- The message should be published to the parkingLot Queue\n\nhttps://i.sstatic.net/ihLAI.png\n\nhttps://i.sstatic.net/3bLvB.png\n\nI am able (see the code below) to delay the message for a certain amount of time in a deadLetter Queue. And the message is looped infinitely between the incoming Queue and the deadLetter Queue. So far so good.\n\n**The main question:** How can I intercept the process and manually route the message (as described in the step 3) to the parkingLot Queue for later further analysis?\n\n**A secondary question:** Can I achieve the same process with only one exchange?\n\nHere is a shortened version of my two classes:\n\n**Configuration class**\n\n```\n@Configuration\npublic class MailRabbitMQConfig {\n\n @Bean\n TopicExchange incomingExchange() {\n TopicExchange incomingExchange = new TopicExchange(incomingExchangeName);\n return incomingExchange;\n }\n\n @Bean\n TopicExchange dlExchange() {\n TopicExchange dlExchange = new TopicExchange(deadLetterExchangeName);\n return dlExchange;\n }\n\n @Bean\n Queue incomingQueue() {\n\n return QueueBuilder.durable(incomingQueueName)\n .withArgument(\n \"x-dead-letter-exchange\",\n dlExchange().getName()\n )\n .build();\n }\n\n @Bean\n public Queue parkingLotQueue() {\n return new Queue(parkingLotQueueName);\n }\n\n @Bean\n Binding incomingBinding() {\n return BindingBuilder\n .bind(incomingQueue())\n .to(incomingExchange())\n .with(\"#\");\n }\n\n @Bean\n public Queue dlQueue() {\n return QueueBuilder\n .durable(deadLetterQueueName)\n .withArgument(\"x-message-ttl\", 10000)\n .withArgument(\"x-dead-letter-exchange\", incomingExchange()\n .getName())\n .build();\n }\n\n @Bean\n Binding dlBinding() {\n return BindingBuilder\n .bind(dlQueue())\n .to(dlExchange())\n .with(\"#\");\n }\n\n @Bean\n public Binding bindParkingLot(\n Queue parkingLotQueue,\n TopicExchange dlExchange\n ) {\n\n return BindingBuilder.bind(parkingLotQueue)\n .to(dlExchange)\n .with(parkingLotRoutingKeyName);\n }\n}\n```\n\n**Consumer class**\n\n```\n@Component\npublic class Consumer {\n\n private final Logger logger = LoggerFactory.getLogger(Consumer.class);\n\n @RabbitListener(queues = \"${mail.rabbitmq.queue.incoming}\")\n public Boolean receivedMessage(MailDataExternalTemplate mailDataExternalTemplate) throws Exception {\n\n try {\n // business logic here\n } catch (Exception e) {\n throw new AmqpRejectAndDontRequeueException(\"Failed to handle a business logic\");\n }\n\n return Boolean.TRUE;\n }\n}\n```\n\n**I know I could define an additional listener for a deadLetter Queue in a Consumer class like that:**\n\n```\n@RabbitListener(queues = \"${mail.rabbitmq.queue.deadletter}\")\npublic void receivedMessageFromDlq(Message failedMessage) throws Exception {\n // Logic to count x-retries header property value and send a failed message manually\n // to the parkingLot Queue\n}\n```\n\nHowever it does not work as expected because this listener is called as soon as the message arrives the head of the deadLetter Queue without to be delayed.\n\nThank you in advance.\n\n**EDIT: I was able with @ArtemBilan and @GaryRussell help to solve the problem. The main solution hints are within their comments in the accepted answer. Thank you guys for the help! Below you will find a new diagram that shows the messaging process and the Configuration and the Consumer classes. The main changes were:**\n\n- The definition of the routes between the incoming exchange -> incoming queue and the dead letter exchange -> dead letter queue in the `MailRabbitMQConfig` class.\n\n- The loop handling with the manual publishing of the message to the parking lot queue in the `Consumer` class\n\nhttps://i.sstatic.net/NckLM.png\n\n**Configuration class**\n\n```\n@Configuration\npublic class MailRabbitMQConfig {\n @Autowired\n public MailConfigurationProperties properties;\n\n @Bean\n TopicExchange incomingExchange() {\n TopicExchange incomingExchange = new TopicExchange(properties.getRabbitMQ().getExchange().getIncoming());\n return incomingExchange;\n }\n\n @Bean\n TopicExchange dlExchange() {\n TopicExchange dlExchange = new TopicExchange(properties.getRabbitMQ().getExchange().getDeadletter());\n return dlExchange;\n }\n\n @Bean\n Queue incomingQueue() {\n return QueueBuilder.durable(properties.getRabbitMQ().getQueue().getIncoming())\n .withArgument( \n properties.getRabbitMQ().getQueue().X_DEAD_LETTER_EXCHANGE_HEADER,\n dlExchange().getName()\n )\n .withArgument(\n properties.getRabbitMQ().getQueue().X_DEAD_LETTER_ROUTING_KEY_HEADER,\n properties.getRabbitMQ().getRoutingKey().getDeadLetter()\n )\n .build();\n }\n\n @Bean\n public Queue parkingLotQueue() {\n return new Queue(properties.getRabbitMQ().getQueue().getParkingLot());\n }\n\n @Bean\n Binding incomingBinding() {\n return BindingBuilder\n .bind(incomingQueue())\n .to(incomingExchange())\n .with(properties.getRabbitMQ().getRoutingKey().getIncoming());\n }\n\n @Bean\n public Queue dlQueue() {\n return QueueBuilder\n .durable(properties.getRabbitMQ().getQueue().getDeadLetter())\n .withArgument( \n properties.getRabbitMQ().getMessages().X_MESSAGE_TTL_HEADER,\n properties.getRabbitMQ().getMessages().getDelayTime()\n )\n .withArgument(\n properties.getRabbitMQ().getQueue().X_DEAD_LETTER_EXCHANGE_HEADER,\n incomingExchange().getName()\n )\n .withArgument(\n properties.getRabbitMQ().getQueue().X_DEAD_LETTER_ROUTING_KEY_HEADER,\n properties.getRabbitMQ().getRoutingKey().getIncoming()\n )\n .build();\n }\n\n @Bean\n Binding dlBinding() {\n return BindingBuilder\n .bind(dlQueue())\n .to(dlExchange())\n .with(properties.getRabbitMQ().getRoutingKey().getDeadLetter());\n }\n\n @Bean\n public Binding bindParkingLot(\n Queue parkingLotQueue,\n TopicExchange dlExchange\n ) {\n return BindingBuilder.bind(parkingLotQueue)\n .to(dlExchange)\n .with(properties.getRabbitMQ().getRoutingKey().getParkingLot());\n }\n}\n```\n\n**Consumer class**\n\n```\n@Component\npublic class Consumer {\n private final Logger logger = LoggerFactory.getLogger(Consumer.class);\n\n @Autowired\n public MailConfigurationProperties properties;\n\n @Autowired\n protected EmailClient mailJetEmailClient;\n\n @Autowired\n private RabbitTemplate rabbitTemplate;\n\n @RabbitListener(queues = \"${mail.rabbitmq.queue.incoming}\")\n public Boolean receivedMessage(\n @Payload MailDataExternalTemplate mailDataExternalTemplate,\n Message amqpMessage\n ) {\n logger.info(\"Received message\");\n\n try {\n final EmailTransportWrapper emailTransportWrapper = mailJetEmailClient.convertFrom(mailDataExternalTemplate);\n\n mailJetEmailClient.sendEmailUsing(emailTransportWrapper);\n logger.info(\"Successfully sent an E-Mail\");\n } catch (Exception e) {\n int count = getXDeathCountFromHeader(amqpMessage);\n logger.debug(\"x-death count: \" + count);\n\n if (count >= properties.getRabbitMQ().getMessages().getRetryCount()) {\n this.rabbitTemplate.send(\n properties.getRabbitMQ().getExchange().getDeadletter(),\n properties.getRabbitMQ().getRoutingKey().getParkingLot(),\n amqpMessage\n );\n return Boolean.TRUE;\n }\n\n throw new AmqpRejectAndDontRequeueException(\"Failed to send an E-Mail\");\n }\n\n return Boolean.TRUE;\n }\n\n private int getXDeathCountFromHeader(Message message) {\n Map headers = message.getMessageProperties().getHeaders();\n if (headers.get(properties.getRabbitMQ().getMessages().X_DEATH_HEADER) == null) {\n return 0;\n }\n\n //noinspection unchecked\n ArrayList> xDeath = (ArrayList>) headers\n .get(properties.getRabbitMQ().getMessages().X_DEATH_HEADER);\n Long count = (Long) xDeath.get(0).get(\"count\");\n return count.intValue();\n }\n```\n\n========================================\n\nCode:\n```text\n@Configuration\npublic class MailRabbitMQConfig {\n\n @Bean\n TopicExchange incomingExchange() {\n TopicExchange incomingExchange = new TopicExchange(incomingExchangeName);\n return incomingExchange;\n }\n\n @Bean\n TopicExchange dlExchange() {\n TopicExchange dlExchange = new TopicExchange(deadLetterExchangeName);\n return dlExchange;\n }\n\n @Bean\n Queue incomingQueue() {\n\n return QueueBuilder.durable(incomingQueueName)\n .withArgument(\n \"x-dead-letter-exchange\",\n dlExchange().getName()\n )\n .build();\n }\n\n @Bean\n public Queue parkingLotQueue() {\n return new Queue(parkingLotQueueName);\n }\n\n @Bean\n Binding incomingBinding() {\n return BindingBuilder\n .bind(incomingQueue())\n .to(incomingExchange())\n .with(\"#\");\n }\n\n @Bean\n public Queue dlQueue() {\n return QueueBuilder\n .durable(deadLetterQueueName)\n .withArgument(\"x-message-ttl\", 10000)\n .withArgument(\"x-dead-letter-exchange\", incomingExchange()\n .getName())\n .build();\n }\n\n @Bean\n Binding dlBinding() {\n return BindingBuilder\n .bind(dlQueue())\n .to(dlExchange())\n .with(\"#\");\n }\n\n @Bean\n public Binding bindParkingLot(\n Queue parkingLotQueue,\n TopicExchange dlExchange\n ) {\n\n return BindingBuilder.bind(parkingLotQueue)\n .to(dlExchange)\n .with(parkingLotRoutingKeyName);\n }\n}\n```\n\n```text\n@Component\npublic class Consumer {\n\n private final Logger logger = LoggerFactory.getLogger(Consumer.class);\n\n @RabbitListener(queues = \"${mail.rabbitmq.queue.incoming}\")\n public Boolean receivedMessage(MailDataExternalTemplate mailDataExternalTemplate) throws Exception {\n\n try {\n // business logic here\n } catch (Exception e) {\n throw new AmqpRejectAndDontRequeueException(\"Failed to handle a business logic\");\n }\n\n return Boolean.TRUE;\n }\n}\n```\n\n```text\n@RabbitListener(queues = \"${mail.rabbitmq.queue.deadletter}\")\npublic void receivedMessageFromDlq(Message failedMessage) throws Exception {\n // Logic to count x-retries header property value and send a failed message manually\n // to the parkingLot Queue\n}\n```\n\n```text\n@Configuration\npublic class MailRabbitMQConfig {\n @Autowired\n public MailConfigurationProperties properties;\n\n @Bean\n TopicExchange incomingExchange() {\n TopicExchange incomingExchange = new TopicExchange(properties.getRabbitMQ().getExchange().getIncoming());\n return incomingExchange;\n }\n\n @Bean\n TopicExchange dlExchange() {\n TopicExchange dlExchange = new TopicExchange(properties.getRabbitMQ().getExchange().getDeadletter());\n return dlExchange;\n }\n\n @Bean\n Queue incomingQueue() {\n return QueueBuilder.durable(properties.getRabbitMQ().getQueue().getIncoming())\n .withArgument( \n properties.getRabbitMQ().getQueue().X_DEAD_LETTER_EXCHANGE_HEADER,\n dlExchange().getName()\n )\n .withArgument(\n properties.getRabbitMQ().getQueue().X_DEAD_LETTER_ROUTING_KEY_HEADER,\n properties.getRabbitMQ().getRoutingKey().getDeadLetter()\n )\n .build();\n }\n\n @Bean\n public Queue parkingLotQueue() {\n return new Queue(properties.getRabbitMQ().getQueue().getParkingLot());\n }\n\n @Bean\n Binding incomingBinding() {\n return BindingBuilder\n .bind(incomingQueue())\n .to(incomingExchange())\n .with(properties.getRabbitMQ().getRoutingKey().getIncoming());\n }\n\n @Bean\n public Queue dlQueue() {\n return QueueBuilder\n .durable(properties.getRabbitMQ().getQueue().getDeadLetter())\n .withArgument( \n properties.getRabbitMQ().getMessages().X_MESSAGE_TTL_HEADER,\n properties.getRabbitMQ().getMessages().getDelayTime()\n )\n .withArgument(\n properties.getRabbitMQ().getQueue().X_DEAD_LETTER_EXCHANGE_HEADER,\n incomingExchange().getName()\n )\n .withArgument(\n properties.getRabbitMQ().getQueue().X_DEAD_LETTER_ROUTING_KEY_HEADER,\n properties.getRabbitMQ().getRoutingKey().getIncoming()\n )\n .build();\n }\n\n @Bean\n Binding dlBinding() {\n return BindingBuilder\n .bind(dlQueue())\n .to(dlExchange())\n .with(properties.getRabbitMQ().getRoutingKey().getDeadLetter());\n }\n\n @Bean\n public Binding bindParkingLot(\n Queue parkingLotQueue,\n TopicExchange dlExchange\n ) {\n return BindingBuilder.bind(parkingLotQueue)\n .to(dlExchange)\n .with(properties.getRabbitMQ().getRoutingKey().getParkingLot());\n }\n}\n```\n\n```text\n@Component\npublic class Consumer {\n private final Logger logger = LoggerFactory.getLogger(Consumer.class);\n\n @Autowired\n public MailConfigurationProperties properties;\n\n @Autowired\n protected EmailClient mailJetEmailClient;\n\n @Autowired\n private RabbitTemplate rabbitTemplate;\n\n @RabbitListener(queues = \"${mail.rabbitmq.queue.incoming}\")\n public Boolean receivedMessage(\n @Payload MailDataExternalTemplate mailDataExternalTemplate,\n Message amqpMessage\n ) {\n logger.info(\"Received message\");\n\n try {\n final EmailTransportWrapper emailTransportWrapper = mailJetEmailClient.convertFrom(mailDataExternalTemplate);\n\n mailJetEmailClient.sendEmailUsing(emailTransportWrapper);\n logger.info(\"Successfully sent an E-Mail\");\n } catch (Exception e) {\n int count = getXDeathCountFromHeader(amqpMessage);\n logger.debug(\"x-death count: \" + count);\n\n if (count >= properties.getRabbitMQ().getMessages().getRetryCount()) {\n this.rabbitTemplate.send(\n properties.getRabbitMQ().getExchange().getDeadletter(),\n properties.getRabbitMQ().getRoutingKey().getParkingLot(),\n amqpMessage\n );\n return Boolean.TRUE;\n }\n\n throw new AmqpRejectAndDontRequeueException(\"Failed to send an E-Mail\");\n }\n\n return Boolean.TRUE;\n }\n\n private int getXDeathCountFromHeader(Message message) {\n Map<String, Object> headers = message.getMessageProperties().getHeaders();\n if (headers.get(properties.getRabbitMQ().getMessages().X_DEATH_HEADER) == null) {\n return 0;\n }\n\n //noinspection unchecked\n ArrayList<Map<String, ?>> xDeath = (ArrayList<Map<String, ?>>) headers\n .get(properties.getRabbitMQ().getMessages().X_DEATH_HEADER);\n Long count = (Long) xDeath.get(0).get(\"count\");\n return count.intValue();\n }\n```\n\n```text\nMailRabbitMQConfig\n```\n\n```text\nConsumer\n```\n\n```text\n/**\n * Send a message to a default exchange with a specific routing key.\n *\n * @param routingKey the routing key\n * @param message a message to send\n * @throws AmqpException if there is a problem\n */\nvoid send(String routingKey, Message message) throws AmqpException;\n```\n\n```text\nDelayedExchange\n```\n\n```text\nparkingLot\n```\n\n```text\nRabbitTemplate\n```\n\n========================================\n\nComments:\n- Thank you Artem for the quick response. I have read about the Delayed Message Exchange Plugin (DME) already and tried it. As I thought my scenario is simple and does not need different message delay times, I should use a simple approach with the dead letter queue. Do you think it is safe to use the DME Plugin in production? The next thing is: How can I intercept the loop between the incoming queue and the deadLetter queue to publish manually the message to the parkingLot queue as suggested by you with: void send(String routingKey, Message message) throws AmqpException;\n- That's fine to use DME as far as I know. If you worry about that, then you definitely can stick with the `TTL` for messages in the `deadLetter`.\n- The Spring Cloud Stream documentation talks about a similar mechanism. It is in the context of processing messages in the DLQ and routing them back to the main queue. In your case, the logic can be in your main listener, with the first leg of the `if` could route the message to the DLQ with the retries header and a TTL. It also has a delayed exchange example.\n- And right: you shouldn't consume that `deadLetter` queue.\n- You are confusing me a bit the manual part, since according your diagram you don't need to do that as far as your `deadLetter Exchange` is a topic, so you route the same message to several queues. You can route to some other exchange from there, bind queue to it, consume and send to the `parkingLot` queue, but all of this sounds for me as an overhead. You have Topic exchange and you place the same message to several queues. Nothing more to do in between exception and dead letter queue.\n- Thank you Gary for the response. To use the interception within the incoming queue listener I will need to change the method signature from my custom type **MailDataExternalTemplate** to the native amqp **Message** type, like that: *public Boolean receivedMessage(Message mailDataExternalTemplate) throws Exception* So this way I would have an access to the Message Properties / Headers. However I need my object *mailDataExternalTemplate* to handle the further business logic in the application. How can I cast between the **Message** and the **MailDataExternalTemplate** types?\n- You can use both arguments on your listener method: `receivedMessage(@Payload MailDataExternalTemplate mailDataExternalTemplate, Message amqpMessage)`\n- @ArtemBilan Good to know. Thank you. If I understand your previous answer correctly you mean I can achieve the same scenario with only one exchange, right?\n- Well, I would stick with a separate exchange for the dead letters. And bind that `parkingLot` Queue in parallel with the `deadLetter` Queue. In other words: your picture is an instruction for me to go. There is nothing else to add or overcomplicate.\n- @GaryRussell Yeah, I got the Idea with the parking lot in my scenario from the Spring Cloud Stream documentation documentation. However I was not sure I can use the same approach because the documentation refers to the Spring Cloud Stream (I am new in the Spring world)\n- With newer versions (2.0.x), you can separate this logic from your business listener method with a RabbitListenerErrorHandler.","metadata":{"transformedAt":"2026-08-18T18:33:20.315Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":11,"totalLines":579,"estimatedTokens":4657}}1018{"id":"stack-50829934","source":"stackoverflow","questionId":50829934,"title":"SpringBoot + RabbitMQ throwing error : java.net.ConnectException: Connection refused","tags":["java","spring-boot","rabbitmq","yaml"],"text":"Title: SpringBoot + RabbitMQ throwing error : java.net.ConnectException: Connection refused\nTags: java, spring-boot, rabbitmq, yaml\nSource: Stack Overflow\n\nQuestion:\nI have hosted a multimodule project on heroku and receiving the following error when trying to run my Spring Boot Application.\n\n```\n2018-06-13T05:34:47.611296+00:00 app[web.1]: 2018-06-13 05:34:47.611 INFO 4 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'rabbitConnectionFactory' has been autodetected for JMX exposure\n2018-06-13T05:34:47.617422+00:00 app[web.1]: 2018-06-13 05:34:47.617 INFO 4 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'rabbitConnectionFactory': registering with JMX server as MBean [org.springframework.amqp.rabbit.connection:name=rabbitConnectionFactory,type=CachingConnectionFactory]\n2018-06-13T05:34:47.646470+00:00 app[web.1]: 2018-06-13 05:34:47.646 INFO 4 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483647\n2018-06-13T05:34:47.660578+00:00 app[web.1]: 2018-06-13 05:34:47.660 INFO 4 --- [ container-1] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]\n2018-06-13T05:34:47.680639+00:00 app[web.1]: 2018-06-13 05:34:47.679 ERROR 4 --- [ container-1] o.s.a.r.l.SimpleMessageListenerContainer : Failed to check/redeclare auto-delete queue(s).\n2018-06-13T05:34:47.680646+00:00 app[web.1]: \n2018-06-13T05:34:47.680648+00:00 app[web.1]: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)\n2018-06-13T05:34:47.680650+00:00 app[web.1]: at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:62) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:34:47.680651+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:476) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:34:47.680656+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:614) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:34:47.680658+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:240) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:34:47.680659+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1797) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n```\n\nThe issue I see is, it is trying to connect some localhost whereas I have my addon `CloudAMQP\nLittle Lemur` added in heroku and I have added these to my both Application.yml file:\n\n```\nspring:\n profiles: heroku\n mvc:\n async:\n request-timeout: 3600000\n rabbitmq:\n addresses: amqp://****:*****@puma.rmq.cloudamqp.com/uyjgxslh\n host: puma.rmq.cloudamqp.com\n port: 1883\n username: ****:****\n password: *****\n```\n\nIn my webModule I have this code:\n\n```\n@SpringBootApplication\npublic class SpringBootHerokuExampleApplication {\n\n public final static String PDF_MERGE_QUEUE= \"pdf-merge-queue\";\n\n @Bean\n Queue queue(){\n return new Queue(PDF_MERGE_QUEUE, false);\n }\n\n @Bean\n TopicExchange exchange(){\n return new TopicExchange(\"pdf-nerge-exchange\");\n }\n\n @Bean\n Binding binding(Queue queue, TopicExchange topicExchange){\n return BindingBuilder.bind(queue).to(topicExchange).with(PDF_MERGE_QUEUE);\n }\n\n @Bean\n SimpleMessageListenerContainer container(ConnectionFactory connectionFactory,\n MessageListenerAdapter listenerAdapter){\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(connectionFactory);\n container.setQueueNames(PDF_MERGE_QUEUE);\n container.setMessageListener(listenerAdapter);\n return container;\n }\n\n @Bean\n MessageListenerAdapter listenerAdapter(RabbitMQListener rabbitMQListener){\n return new MessageListenerAdapter(rabbitMQListener, \"receiveMessage\");\n }\n\n public static void main(String[] args) {\n SpringApplication.run(SpringBootHerokuExampleApplication.class, args);\n }\n}\n```\n\nand in my worker module main method:\n\n```\npublic class SpringBootHerokuExampleApplication {\n public final static String PDF_MERGE_QUEUE= \"pdf-merge-queue\";\n public static void main(String[] args) {\n SpringApplication.run(SpringBootHerokuExampleApplication.class, args);\n }\n}\n```\n\nPlease find below some more stack trace from Heroku logs :\n\n```\nhandler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]\n2018-06-13T05:54:13.871350+00:00 app[worker.1]: 2018-06-13 05:54:13.870 INFO 4 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'\n2018-06-13T05:54:13.897860+00:00 app[worker.1]: 2018-06-13 05:54:13.897 INFO 4 --- [ main] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped \"{[/actuator/health],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}\" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map)\n2018-06-13T05:54:13.899632+00:00 app[worker.1]: 2018-06-13 05:54:13.899 INFO 4 --- [ main] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped \"{[/actuator/info],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}\" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map)\n2018-06-13T05:54:13.901591+00:00 app[worker.1]: 2018-06-13 05:54:13.901 INFO 4 --- [ main] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped \"{[/actuator],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}\" onto protected java.util.Map> org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping.links(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)\n2018-06-13T05:54:14.128560+00:00 app[worker.1]: 2018-06-13 05:54:14.128 INFO 4 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup\n2018-06-13T05:54:14.145677+00:00 app[worker.1]: 2018-06-13 05:54:14.145 INFO 4 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'rabbitConnectionFactory' has been autodetected for JMX exposure\n2018-06-13T05:54:14.154055+00:00 app[worker.1]: 2018-06-13 05:54:14.153 INFO 4 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'rabbitConnectionFactory': registering with JMX server as MBean [org.springframework.amqp.rabbit.connection:name=rabbitConnectionFactory,type=CachingConnectionFactory]\n2018-06-13T05:54:14.199050+00:00 app[worker.1]: 2018-06-13 05:54:14.197 INFO 4 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483647\n2018-06-13T05:54:14.230846+00:00 app[worker.1]: 2018-06-13 05:54:14.230 INFO 4 --- [cTaskExecutor-1] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]\n2018-06-13T05:54:14.425996+00:00 app[worker.1]: 2018-06-13 05:54:14.425 INFO 4 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''\n2018-06-13T05:54:14.437981+00:00 app[worker.1]: 2018-06-13 05:54:14.435 INFO 4 --- [ main] o.e.SpringBootHerokuExampleApplication : Started SpringBootHerokuExampleApplication in 13.198 seconds (JVM running for 14.523)\n2018-06-13T05:54:14.969935+00:00 app[web.1]: 2018-06-13 05:54:14.969 WARN 4 --- [ container-2] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)\n2018-06-13T05:54:14.970343+00:00 app[web.1]: 2018-06-13 05:54:14.970 INFO 4 --- [ container-2] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer@362d89d0: tags=[{}], channel=null, acknowledgeMode=AUTO local queue size=0\n2018-06-13T05:54:14.971125+00:00 app[web.1]: 2018-06-13 05:54:14.971 INFO 4 --- [ container-3] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]\n2018-06-13T05:54:14.971946+00:00 app[web.1]: 2018-06-13 05:54:14.971 ERROR 4 --- [ container-3] o.s.a.r.l.SimpleMessageListenerContainer : Failed to check/redeclare auto-delete queue(s).\n2018-06-13T05:54:14.971948+00:00 app[web.1]: \n2018-06-13T05:54:14.971951+00:00 app[web.1]: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)\n2018-06-13T05:54:14.971952+00:00 app[web.1]: at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:62) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:14.971953+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:476) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:14.971956+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:614) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:14.971957+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:240) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:14.971958+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1797) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:14.971959+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1771) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:14.971960+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1752) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:14.971961+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:338) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:14.971962+00:00 app[web.1]: at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.redeclareElementsIfNecessary(AbstractMessageListenerContainer.java:1604) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:14.971964+00:00 app[web.1]: at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:963) [spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:14.971965+00:00 app[web.1]: at java.lang.Thread.run(Thread.java:748) [na:1.8.0_171-heroku]\n2018-06-13T05:54:14.971967+00:00 app[web.1]: Caused by: java.net.ConnectException: Connection refused (Connection refused)\n2018-06-13T05:54:14.971969+00:00 app[web.1]: at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:14.971971+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:14.971972+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:14.971973+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:14.971974+00:00 app[web.1]: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:14.971975+00:00 app[web.1]: at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:14.971976+00:00 app[web.1]: at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:60) ~[amqp-client-5.1.2.jar!/:5.1.2]\n2018-06-13T05:54:14.971977+00:00 app[web.1]: at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:955) ~[amqp-client-5.1.2.jar!/:5.1.2]\n2018-06-13T05:54:14.971978+00:00 app[web.1]: at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:907) ~[amqp-client-5.1.2.jar!/:5.1.2]\n2018-06-13T05:54:14.971979+00:00 app[web.1]: at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:847) ~[amqp-client-5.1.2.jar!/:5.1.2]\n2018-06-13T05:54:14.971980+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:449) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:14.971981+00:00 app[web.1]: ... 9 common frames omitted\n2018-06-13T05:54:14.971982+00:00 app[web.1]: \n2018-06-13T05:54:14.972042+00:00 app[web.1]: 2018-06-13 05:54:14.971 INFO 4 --- [ container-3] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]\n2018-06-13T05:54:19.262272+00:00 app[worker.1]: 2018-06-13 05:54:19.261 WARN 4 --- [cTaskExecutor-1] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)\n2018-06-13T05:54:19.264406+00:00 app[worker.1]: 2018-06-13 05:54:19.264 INFO 4 --- [cTaskExecutor-1] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer@793be5ca: tags=[{}], channel=null, acknowledgeMode=AUTO local queue size=0\n2018-06-13T05:54:19.272605+00:00 app[worker.1]: 2018-06-13 05:54:19.272 INFO 4 --- [cTaskExecutor-2] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]\n2018-06-13T05:54:19.976366+00:00 app[web.1]: 2018-06-13 05:54:19.976 WARN 4 --- [ container-3] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)\n2018-06-13T05:54:19.976491+00:00 app[web.1]: 2018-06-13 05:54:19.976 INFO 4 --- [ container-3] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer@42d37ed7: tags=[{}], channel=null, acknowledgeMode=AUTO local queue size=0\n2018-06-13T05:54:19.977274+00:00 app[web.1]: 2018-06-13 05:54:19.977 INFO 4 --- [ container-4] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]\n2018-06-13T05:54:19.978248+00:00 app[web.1]: 2018-06-13 05:54:19.978 ERROR 4 --- [ container-4] o.s.a.r.l.SimpleMessageListenerContainer : Failed to check/redeclare auto-delete queue(s).\n2018-06-13T05:54:19.978251+00:00 app[web.1]: \n2018-06-13T05:54:19.978252+00:00 app[web.1]: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)\n2018-06-13T05:54:19.978253+00:00 app[web.1]: at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:62) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:19.978255+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:476) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:19.978256+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:614) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:19.978257+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:240) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:19.978258+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1797) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:19.978259+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1771) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:19.978260+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1752) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:19.978261+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:338) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:19.978263+00:00 app[web.1]: at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.redeclareElementsIfNecessary(AbstractMessageListenerContainer.java:1604) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:19.978264+00:00 app[web.1]: at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:963) [spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:19.978265+00:00 app[web.1]: at java.lang.Thread.run(Thread.java:748) [na:1.8.0_171-heroku]\n2018-06-13T05:54:19.978267+00:00 app[web.1]: Caused by: java.net.ConnectException: Connection refused (Connection refused)\n2018-06-13T05:54:19.978268+00:00 app[web.1]: at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:19.978269+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:19.978270+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:19.978271+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:19.978272+00:00 app[web.1]: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:19.978273+00:00 app[web.1]: at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:19.978274+00:00 app[web.1]: at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:60) ~[amqp-client-5.1.2.jar!/:5.1.2]\n2018-06-13T05:54:19.978275+00:00 app[web.1]: at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:955) ~[amqp-client-5.1.2.jar!/:5.1.2]\n2018-06-13T05:54:19.978276+00:00 app[web.1]: at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:907) ~[amqp-client-5.1.2.jar!/:5.1.2]\n2018-06-13T05:54:19.978277+00:00 app[web.1]: at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:847) ~[amqp-client-5.1.2.jar!/:5.1.2]\n2018-06-13T05:54:19.978278+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:449) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:19.978279+00:00 app[web.1]: ... 9 common frames omitted\n2018-06-13T05:54:19.978280+00:00 app[web.1]: \n2018-06-13T05:54:19.978370+00:00 app[web.1]: 2018-06-13 05:54:19.978 INFO 4 --- [ container-4] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]\n2018-06-13T05:54:24.281046+00:00 app[worker.1]: 2018-06-13 05:54:24.280 WARN 4 --- [cTaskExecutor-2] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)\n2018-06-13T05:54:24.281735+00:00 app[worker.1]: 2018-06-13 05:54:24.281 INFO 4 --- [cTaskExecutor-2] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer@7170b3b5: tags=[{}], channel=null, acknowledgeMode=AUTO local queue size=0\n2018-06-13T05:54:24.291703+00:00 app[worker.1]: 2018-06-13 05:54:24.291 INFO 4 --- [cTaskExecutor-3] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]\n```\n\nWhy is it trying to connect to localhost when I have specified host name explicitly in yml file? Any Idea?\n\n========================================\n\nTop Answer:\nIf you are using spring boot you can configure Rabbit by spring cloud stream.\nIn this case you dont have to configure the beans and the configuration is much easier:\n\n```\nspring:\n#---------------- RabbitMQ -----------------#\n rabbitmq:\n #Default username ans pass\n dynamic: true\n host: localhost\n port: 5672\n username: guest\n password: guest\n\n#---------------------------- RabbitMQ properties Commons ------------------------------#\n cloud:\n stream:\n bindings:\n springCloudBusInput:\n destination: InputExchange\n group: Queue\n producer:\n exchangeAutoDelete: false\n springCloudBusOutput:\n destination: InputExchange\n group: Queue\n consumer:\n exchangeAutoDelete: false\n```\n\nThen you have to create the listener:\n\n```\n@Component\npublic class RemoteEventListener implements ApplicationListener {\n\n @Override\n public void onApplicationEvent(InputEvent inputEvent) {\n\n //whatever you want to do when a InputEvent Type is received in the queue\n\n }\n}\n```\n\n In this case My app is writing and receiving from the same exchange\n and queue (Because of testing so stuff)\n\nIf you want to configure rabbit the way you shown, try to create a configuration class with the beans of the queue, exchange and biding with @Configuration. Dont declare the beans in your app class.\n\nIt seems it can not read the autodelete property of the queue, but if I'm not wrong I should take the default.\n**Maybe You have network issues**\n**Check the rabbitmq and restart it**\n\nCan you acces to rabbitMq administrator interface?\n\nAbout the comment about whi is trying to connect with localhost add this to your bean definition:\n\n```\n@Autowired\n private ConnectionFactory rabbitConnectionFactory\n\n@Bean\n public RabbitTemplate rubeExchangeTemplate() {\n RabbitTemplate r = new RabbitTemplate(rabbitConnectionFactory);\n r.setExchange(\"rmq.rube.exchange\");\n r.setRoutingKey(\"rube.key\");\n r.setConnectionFactory(rabbitConnectionFactory);\n return r;\n }\n```\n\nalso remove addresses of your application.yml\n\n========================================\n\nCode:\n```text\n2018-06-13T05:34:47.611296+00:00 app[web.1]: 2018-06-13 05:34:47.611 INFO 4 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'rabbitConnectionFactory' has been autodetected for JMX exposure\n2018-06-13T05:34:47.617422+00:00 app[web.1]: 2018-06-13 05:34:47.617 INFO 4 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'rabbitConnectionFactory': registering with JMX server as MBean [org.springframework.amqp.rabbit.connection:name=rabbitConnectionFactory,type=CachingConnectionFactory]\n2018-06-13T05:34:47.646470+00:00 app[web.1]: 2018-06-13 05:34:47.646 INFO 4 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483647\n2018-06-13T05:34:47.660578+00:00 app[web.1]: 2018-06-13 05:34:47.660 INFO 4 --- [ container-1] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]\n2018-06-13T05:34:47.680639+00:00 app[web.1]: 2018-06-13 05:34:47.679 ERROR 4 --- [ container-1] o.s.a.r.l.SimpleMessageListenerContainer : Failed to check/redeclare auto-delete queue(s).\n2018-06-13T05:34:47.680646+00:00 app[web.1]: \n2018-06-13T05:34:47.680648+00:00 app[web.1]: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)\n2018-06-13T05:34:47.680650+00:00 app[web.1]: at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:62) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:34:47.680651+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:476) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:34:47.680656+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:614) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:34:47.680658+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:240) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:34:47.680659+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1797) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n```\n\n```text\nspring:\n profiles: heroku\n mvc:\n async:\n request-timeout: 3600000\n rabbitmq:\n addresses: amqp://****:*****@puma.rmq.cloudamqp.com/uyjgxslh\n host: puma.rmq.cloudamqp.com\n port: 1883\n username: ****:****\n password: *****\n```\n\n```text\n@SpringBootApplication\npublic class SpringBootHerokuExampleApplication {\n\n public final static String PDF_MERGE_QUEUE= \"pdf-merge-queue\";\n\n @Bean\n Queue queue(){\n return new Queue(PDF_MERGE_QUEUE, false);\n }\n\n @Bean\n TopicExchange exchange(){\n return new TopicExchange(\"pdf-nerge-exchange\");\n }\n\n @Bean\n Binding binding(Queue queue, TopicExchange topicExchange){\n return BindingBuilder.bind(queue).to(topicExchange).with(PDF_MERGE_QUEUE);\n }\n\n @Bean\n SimpleMessageListenerContainer container(ConnectionFactory connectionFactory,\n MessageListenerAdapter listenerAdapter){\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(connectionFactory);\n container.setQueueNames(PDF_MERGE_QUEUE);\n container.setMessageListener(listenerAdapter);\n return container;\n }\n\n @Bean\n MessageListenerAdapter listenerAdapter(RabbitMQListener rabbitMQListener){\n return new MessageListenerAdapter(rabbitMQListener, \"receiveMessage\");\n }\n\n public static void main(String[] args) {\n SpringApplication.run(SpringBootHerokuExampleApplication.class, args);\n }\n}\n```\n\n```text\npublic class SpringBootHerokuExampleApplication {\n public final static String PDF_MERGE_QUEUE= \"pdf-merge-queue\";\n public static void main(String[] args) {\n SpringApplication.run(SpringBootHerokuExampleApplication.class, args);\n }\n}\n```\n\n```text\nhandler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]\n2018-06-13T05:54:13.871350+00:00 app[worker.1]: 2018-06-13 05:54:13.870 INFO 4 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'\n2018-06-13T05:54:13.897860+00:00 app[worker.1]: 2018-06-13 05:54:13.897 INFO 4 --- [ main] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped \"{[/actuator/health],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}\" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.String>)\n2018-06-13T05:54:13.899632+00:00 app[worker.1]: 2018-06-13 05:54:13.899 INFO 4 --- [ main] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped \"{[/actuator/info],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}\" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.String>)\n2018-06-13T05:54:13.901591+00:00 app[worker.1]: 2018-06-13 05:54:13.901 INFO 4 --- [ main] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped \"{[/actuator],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}\" onto protected java.util.Map<java.lang.String, java.util.Map<java.lang.String, org.springframework.boot.actuate.endpoint.web.Link>> org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping.links(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)\n2018-06-13T05:54:14.128560+00:00 app[worker.1]: 2018-06-13 05:54:14.128 INFO 4 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup\n2018-06-13T05:54:14.145677+00:00 app[worker.1]: 2018-06-13 05:54:14.145 INFO 4 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'rabbitConnectionFactory' has been autodetected for JMX exposure\n2018-06-13T05:54:14.154055+00:00 app[worker.1]: 2018-06-13 05:54:14.153 INFO 4 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'rabbitConnectionFactory': registering with JMX server as MBean [org.springframework.amqp.rabbit.connection:name=rabbitConnectionFactory,type=CachingConnectionFactory]\n2018-06-13T05:54:14.199050+00:00 app[worker.1]: 2018-06-13 05:54:14.197 INFO 4 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483647\n2018-06-13T05:54:14.230846+00:00 app[worker.1]: 2018-06-13 05:54:14.230 INFO 4 --- [cTaskExecutor-1] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]\n2018-06-13T05:54:14.425996+00:00 app[worker.1]: 2018-06-13 05:54:14.425 INFO 4 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''\n2018-06-13T05:54:14.437981+00:00 app[worker.1]: 2018-06-13 05:54:14.435 INFO 4 --- [ main] o.e.SpringBootHerokuExampleApplication : Started SpringBootHerokuExampleApplication in 13.198 seconds (JVM running for 14.523)\n2018-06-13T05:54:14.969935+00:00 app[web.1]: 2018-06-13 05:54:14.969 WARN 4 --- [ container-2] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)\n2018-06-13T05:54:14.970343+00:00 app[web.1]: 2018-06-13 05:54:14.970 INFO 4 --- [ container-2] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer@362d89d0: tags=[{}], channel=null, acknowledgeMode=AUTO local queue size=0\n2018-06-13T05:54:14.971125+00:00 app[web.1]: 2018-06-13 05:54:14.971 INFO 4 --- [ container-3] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]\n2018-06-13T05:54:14.971946+00:00 app[web.1]: 2018-06-13 05:54:14.971 ERROR 4 --- [ container-3] o.s.a.r.l.SimpleMessageListenerContainer : Failed to check/redeclare auto-delete queue(s).\n2018-06-13T05:54:14.971948+00:00 app[web.1]: \n2018-06-13T05:54:14.971951+00:00 app[web.1]: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)\n2018-06-13T05:54:14.971952+00:00 app[web.1]: at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:62) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:14.971953+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:476) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:14.971956+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:614) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:14.971957+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:240) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:14.971958+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1797) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:14.971959+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1771) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:14.971960+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1752) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:14.971961+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:338) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:14.971962+00:00 app[web.1]: at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.redeclareElementsIfNecessary(AbstractMessageListenerContainer.java:1604) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:14.971964+00:00 app[web.1]: at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:963) [spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:14.971965+00:00 app[web.1]: at java.lang.Thread.run(Thread.java:748) [na:1.8.0_171-heroku]\n2018-06-13T05:54:14.971967+00:00 app[web.1]: Caused by: java.net.ConnectException: Connection refused (Connection refused)\n2018-06-13T05:54:14.971969+00:00 app[web.1]: at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:14.971971+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:14.971972+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:14.971973+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:14.971974+00:00 app[web.1]: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:14.971975+00:00 app[web.1]: at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:14.971976+00:00 app[web.1]: at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:60) ~[amqp-client-5.1.2.jar!/:5.1.2]\n2018-06-13T05:54:14.971977+00:00 app[web.1]: at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:955) ~[amqp-client-5.1.2.jar!/:5.1.2]\n2018-06-13T05:54:14.971978+00:00 app[web.1]: at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:907) ~[amqp-client-5.1.2.jar!/:5.1.2]\n2018-06-13T05:54:14.971979+00:00 app[web.1]: at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:847) ~[amqp-client-5.1.2.jar!/:5.1.2]\n2018-06-13T05:54:14.971980+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:449) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:14.971981+00:00 app[web.1]: ... 9 common frames omitted\n2018-06-13T05:54:14.971982+00:00 app[web.1]: \n2018-06-13T05:54:14.972042+00:00 app[web.1]: 2018-06-13 05:54:14.971 INFO 4 --- [ container-3] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]\n2018-06-13T05:54:19.262272+00:00 app[worker.1]: 2018-06-13 05:54:19.261 WARN 4 --- [cTaskExecutor-1] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)\n2018-06-13T05:54:19.264406+00:00 app[worker.1]: 2018-06-13 05:54:19.264 INFO 4 --- [cTaskExecutor-1] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer@793be5ca: tags=[{}], channel=null, acknowledgeMode=AUTO local queue size=0\n2018-06-13T05:54:19.272605+00:00 app[worker.1]: 2018-06-13 05:54:19.272 INFO 4 --- [cTaskExecutor-2] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]\n2018-06-13T05:54:19.976366+00:00 app[web.1]: 2018-06-13 05:54:19.976 WARN 4 --- [ container-3] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)\n2018-06-13T05:54:19.976491+00:00 app[web.1]: 2018-06-13 05:54:19.976 INFO 4 --- [ container-3] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer@42d37ed7: tags=[{}], channel=null, acknowledgeMode=AUTO local queue size=0\n2018-06-13T05:54:19.977274+00:00 app[web.1]: 2018-06-13 05:54:19.977 INFO 4 --- [ container-4] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]\n2018-06-13T05:54:19.978248+00:00 app[web.1]: 2018-06-13 05:54:19.978 ERROR 4 --- [ container-4] o.s.a.r.l.SimpleMessageListenerContainer : Failed to check/redeclare auto-delete queue(s).\n2018-06-13T05:54:19.978251+00:00 app[web.1]: \n2018-06-13T05:54:19.978252+00:00 app[web.1]: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)\n2018-06-13T05:54:19.978253+00:00 app[web.1]: at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:62) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:19.978255+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:476) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:19.978256+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:614) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:19.978257+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:240) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:19.978258+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1797) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:19.978259+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1771) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:19.978260+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1752) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:19.978261+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:338) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:19.978263+00:00 app[web.1]: at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.redeclareElementsIfNecessary(AbstractMessageListenerContainer.java:1604) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:19.978264+00:00 app[web.1]: at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:963) [spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:19.978265+00:00 app[web.1]: at java.lang.Thread.run(Thread.java:748) [na:1.8.0_171-heroku]\n2018-06-13T05:54:19.978267+00:00 app[web.1]: Caused by: java.net.ConnectException: Connection refused (Connection refused)\n2018-06-13T05:54:19.978268+00:00 app[web.1]: at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:19.978269+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:19.978270+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:19.978271+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:19.978272+00:00 app[web.1]: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:19.978273+00:00 app[web.1]: at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_171-heroku]\n2018-06-13T05:54:19.978274+00:00 app[web.1]: at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:60) ~[amqp-client-5.1.2.jar!/:5.1.2]\n2018-06-13T05:54:19.978275+00:00 app[web.1]: at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:955) ~[amqp-client-5.1.2.jar!/:5.1.2]\n2018-06-13T05:54:19.978276+00:00 app[web.1]: at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:907) ~[amqp-client-5.1.2.jar!/:5.1.2]\n2018-06-13T05:54:19.978277+00:00 app[web.1]: at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:847) ~[amqp-client-5.1.2.jar!/:5.1.2]\n2018-06-13T05:54:19.978278+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:449) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]\n2018-06-13T05:54:19.978279+00:00 app[web.1]: ... 9 common frames omitted\n2018-06-13T05:54:19.978280+00:00 app[web.1]: \n2018-06-13T05:54:19.978370+00:00 app[web.1]: 2018-06-13 05:54:19.978 INFO 4 --- [ container-4] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]\n2018-06-13T05:54:24.281046+00:00 app[worker.1]: 2018-06-13 05:54:24.280 WARN 4 --- [cTaskExecutor-2] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)\n2018-06-13T05:54:24.281735+00:00 app[worker.1]: 2018-06-13 05:54:24.281 INFO 4 --- [cTaskExecutor-2] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer@7170b3b5: tags=[{}], channel=null, acknowledgeMode=AUTO local queue size=0\n2018-06-13T05:54:24.291703+00:00 app[worker.1]: 2018-06-13 05:54:24.291 INFO 4 --- [cTaskExecutor-3] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]\n```\n\n```text\nCloudAMQP\nLittle Lemur\n```\n\n```text\nspring:\n#---------------- RabbitMQ -----------------#\n rabbitmq:\n #Default username ans pass\n dynamic: true\n host: localhost\n port: 5672\n username: guest\n password: guest\n\n#---------------------------- RabbitMQ properties Commons ------------------------------#\n cloud:\n stream:\n bindings:\n springCloudBusInput:\n destination: InputExchange\n group: Queue\n producer:\n exchangeAutoDelete: false\n springCloudBusOutput:\n destination: InputExchange\n group: Queue\n consumer:\n exchangeAutoDelete: false\n```\n\n```text\n@Component\npublic class RemoteEventListener implements ApplicationListener<InputEvent> {\n\n @Override\n public void onApplicationEvent(InputEvent inputEvent) {\n\n //whatever you want to do when a InputEvent Type is received in the queue\n\n }\n}\n```\n\n```text\n@Autowired\n private ConnectionFactory rabbitConnectionFactory\n\n@Bean\n public RabbitTemplate rubeExchangeTemplate() {\n RabbitTemplate r = new RabbitTemplate(rabbitConnectionFactory);\n r.setExchange(\"rmq.rube.exchange\");\n r.setRoutingKey(\"rube.key\");\n r.setConnectionFactory(rabbitConnectionFactory);\n return r;\n }\n```\n\n========================================\n\nComments:\n- Clearly whatever you are trying to connect to is not listening where you are sending the connect requests. Have you independently verified that the server is running where you expect it to be?\n- The server is up and running as its a heroku addon. When we click on the heroku addon then it redirects us to the page where I can see the Rabbit MQ details screen.\n- I can see in logs `o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]` this line, why is it trying to connect to localhost.\n- Just found out that in yml file I have a profile named as heroku, when I removed it , it connected to the RabbitMQ in the given host.\n- Rabbit MQ is installed on Heroku as addon.\n- I have eddited the post. I think it should be network issues because it seems everything is fine. try to restart rabbit\n- I reinstalled the addon, deleted the old rabbitMQ instance, still does not work. The Spring boot app which I am running has multiple applications in it. One web application and one worker application.\n- Why is it trying to connect to localhost when I have specified host name explicitly in yml file? Any Idea?\n- dzone.com/articles/spring-configuration-rabbitmq, try to add the Connection Factory and RabbitTemplate, I have edited the post again with more info\n- I found out that in yml file I have a profile named as heroku, when I removed it , it connected to the RabbitMQ in the given host.","metadata":{"transformedAt":"2026-08-18T18:33:20.316Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":500,"estimatedTokens":11385}}1019{"id":"stack-26370861","source":"stackoverflow","questionId":26370861,"title":"RabbitMQ back up messages in specific queue","tags":["rabbitmq","rabbitmq-exchange"],"text":"Title: RabbitMQ back up messages in specific queue\nTags: rabbitmq, rabbitmq-exchange\nSource: Stack Overflow\n\nQuestion:\nI have a service that consumes messages from a RabbitMQ queue (posting to the queue is done through a topic exchange). Assuming that the service can theoretically fail and lose its state, possibility to back up all the messages for disaster recovery would come in handy.\n\nThe first idea that comes to mind is adding another binding for the topic exchange so that the messages are also posted to another queue, and creating a custom service for backing up messages that would listen on that queue. But this sounds much like a potential reinvention of the wheel. Is there a simpler way to do this with RabbitMQ (plugin/existing service/etc)?\n\n========================================\n\nTop Answer:\nRabbitMQ cluster, as specified in Clustering Guide and Highly Available Queues will do what you want in the right way.\n\n========================================\n\nComments:\n- I don't think we're talking about the same thing. It's not the RabbitMQ whose failure or availability I'm concerned with. I want to basically back up traffic going through certain queues for future, not to solve any immediate availability problems.\n- Then duplicating messages to backup queue as you noted in question is the most appropriate way. P.S. \"service can theoretically fail\" in question really sounds like broker failure. If not - please specify what do you mean.","metadata":{"transformedAt":"2026-08-18T18:33:20.316Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":19,"estimatedTokens":366}}1020{"id":"stack-56868230","source":"stackoverflow","questionId":56868230,"title":"How to save message into database and send response into topic eventually consistent?","tags":["java","transactions","rabbitmq","messagebroker","eventual-consistency"],"text":"Title: How to save message into database and send response into topic eventually consistent?\nTags: java, transactions, rabbitmq, messagebroker, eventual-consistency\nSource: Stack Overflow\n\nQuestion:\nI have the following rabbitMq consumer:\n\n```\nConsumer consumer = new DefaultConsumer(channel) {\n @Override\n public void handleDelivery(String consumerTag, Envelope envelope, MQP.BasicProperties properties, byte[] body) throws IOException {\n String message = new String(body, \"UTF-8\");\n sendNotificationIntoTopic(message);\n saveIntoDatabase(message);\n }\n};\n```\n\nFollowing situation can occur:\n\n- Message was send into topic successfully\n\n- Connection to database was lost so database insert was failed.\n\nAs a result we have data inconsistency.\n\nExpected result either both action were successfully executed or both were not executed at all.\n\nAny solutions how can I achieve it?\n\n### P.S.\n\nCurrently I have following idea(please comment upon)\n\nWe can suppose that broker doesn't lose any messages.\n\nWe have to be subscribed on topic we want to send.\n\n- Save entry into database and set field `status` with value 'pending'\n\n- Attempt to send data to topic. If send was successfull - update field `status` with value 'success'\nWe have to have a sheduled job which have to check rows with pending status. At the moment 2 cases are possible:\n\n3.1 Notification wasn't send at all\n\n3.2 Notification was send but save into database was failed(probability is very low but it is possible) \n\nSo we have to distinquish that 2 cases somehow: we may store messages from topic in the collection and job can check if the message was accepted or not. So if job found a message which corresponds the database row we have to update status to \"success\". Otherwise we have to remove entry from database.\n\nI think my idea has some weaknesses(for example if we have multinode application we have to store messages in hazelcast(or analogs) but it is additional point of hypothetical failure)\n\n========================================\n\nTop Answer:\n- In the listener save database row with field staus='pending'\nAnother job(separated thread) will obtain all pending rows from DB and following for each row:\n\n2.1 send data to topic\n\n2.2 save into database\n\n**If we failured on the step 1** - everything is ok - data in consistent state because job won't know anything about that data\n\n**if we failured on the step 2.1** - no problem, next job invocation will attempt to handle it \n\n**if we failured on the step 2.2** - If we failured here - it means that next job invocation will handle the same data again. From the first glance you can think that it is a problem. But your consumer has to be idempotent - it means that it has to understand that message was already processed and skip the processing. This requirement is a consequence that all message brokers have guarantees that message will be delivered AT LEAST ONCE. So our consumers have to be ready for duplicated messages anyway. No problem again.\n\n========================================\n\nCode:\n```text\nConsumer consumer = new DefaultConsumer(channel) {\n @Override\n public void handleDelivery(String consumerTag, Envelope envelope, MQP.BasicProperties properties, byte[] body) throws IOException {\n String message = new String(body, \"UTF-8\");\n sendNotificationIntoTopic(message);\n saveIntoDatabase(message);\n }\n};\n```\n\n```text\nstatus\n```\n\n```text\nstatus\n```\n\n```text\n//Start a transaction\n try {\n String message = new String(body, \"UTF-8\");\n // Ordering is important here as I'm assuming the database has commit and rollback capabilities, but the messaging system doesnt. \n saveIntoDatabase(message);\n sendNotificationIntoTopic(message);\n\n } catch (MessageDeliveryException) {\n // rollback the transaction\n // Throw a domain specific exception\n }\n //commit the transaction\n```\n\n========================================\n\nComments:\n- @user7294900 we have limited count of retries. If the broker is down we can exhaust all attempts and we again have data inconsistency\n- @user7294900 I don't know) But I didn't encounter systems with 1 billions retry attempts\n- The solution is to use a messaging system that supports JMS and XA transactions, and to use an XA transaction manager. Or to have business logic that is tolerant to inconsistencies.\n- @JB Nizet when someone hear smth about XA transaction he usually becomes nervous)\n- @JB Nizet it sounds interesting but I can't imagine how to do it\n- @JB Nizet I've added some thoughts\n- @JBNizet I don|t think XA is nessesary here. There are various compensation options. XA can be justified if you need a really high degree of consistency which I don't think is a so usual case.\n- It won't work if we can't commit topic as you mentioned. It can't be considered as a solution\n- Database can fail during rollback\n- @gstackoverflow in that case, the transaction isnt commited yet, so its safe\n- @gstackoverflow it is more detailed. You don't consider the possibility that you may post to a queue and still the message not being delivered to the recipient, or being delivered but not processes-ed due to application error or validation rule or something else... Posting successfully on a que does no necessarily means success.\n- @gstackoverflow also you are not taking into account diverse compansating scenarious that may occure in case of error.\n- job is self compensated. It will restart in case of failure\n- @gstackoverflow it is not. Successfull post on a queue does not mean there is NO error. You can end up in a situation where the message is consumed and yet the operation on the recipient side has not completed in a good way. How are you going to capture this ? Following your 3 steps you will write to the database Success after successfull message post. Your algorithm does no guarantee consistent state accross recipient and sender.\n- there might be a topic. I might don't want to check that all topic subscribers were able to handle message\n- @gstackoverflow then it is fine. The solution complexity depends on how much consistancy and guarantees you want to achieve.","metadata":{"transformedAt":"2026-08-18T18:33:20.316Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":123,"estimatedTokens":1546}}1021{"id":"stack-30370469","source":"stackoverflow","questionId":30370469,"title":"How to get properly all queue messages from RabbitMQ in Spring?","tags":["spring","rabbitmq","mqtt","stomp","spring-websocket"],"text":"Title: How to get properly all queue messages from RabbitMQ in Spring?\nTags: spring, rabbitmq, mqtt, stomp, spring-websocket\nSource: Stack Overflow\n\nQuestion:\nI am using Spring, Spring-Websocket, STOMP for my application, and RabbitMQ as broker. I need to log all messages going through RabbitMQ to Postgresql tables. \nI know that I can write @MessageMapping in Spring and log there, but my problem is that some clients talk to RabbitMQ directly through MQTT protocol, and Spring does not support it yet (https://jira.spring.io/browse/SPR-12581). Moreover browser clients talk through Spring to RabbitMQ using STOMP protocol.\n\nRabbitMQ allows to track all messages using Firehose tracer. How to properly listen to amq.rabbitmq.trace topic from Spring? Or do I need to write separate Java app as consumer?\n\n========================================\n\nCode:\n```text\nqueue\n```\n\n```text\namq.rabbitmq.trace\n```\n\n```text\npublish.#\n```\n\n```text\nSimpleMessageListenerContainer\n```\n\n```text\n@EnableRabbit\n```\n\n```text\n@RabbitListener\n```\n\n```text\nBinding\n```\n\n```text\n@Bean\n```\n\n========================================\n\nComments:\n- i don't understand you need to do it with spring. just configure rabbitmq to do it..\n- I need to write to DB to different tables\n- hmm.. then IMO you need an application to do it. you can certainly also put this consumer among other consumers. the docu from rabbitmq describes pretty well (rabbitmq.com/firehose.html), have a look, if your question is if spring amqp has this feature out of box, then the answer is no.\n- Well. I'm not good in the Spring WebSocket Broker Relay and not sure that it will work, but you can try to `subscribe` like this: `/topic/exchange/amq.rabbitmq.trace/publish.#`\n- Is it ok to use AMQP to listen to Rabbit, and Stomp Broker relay to serve clients in one application?\n- Exactly! Spring STOMP support just takes care about WebSocket part in your applicaiton, but with Spring AMQP you do hard work around Broker queues and others.","metadata":{"transformedAt":"2026-08-18T18:33:20.316Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":54,"estimatedTokens":500}}1022{"id":"stack-18126768","source":"stackoverflow","questionId":18126768,"title":"how to use multiple configuration files for RabbitMQ / Erlang","tags":["erlang","rabbitmq","rabbitmq-shovel"],"text":"Title: how to use multiple configuration files for RabbitMQ / Erlang\nTags: erlang, rabbitmq, rabbitmq-shovel\nSource: Stack Overflow\n\nQuestion:\nI am trying to setup a Spring based Java application which uses a locally installed RabbitMQ server for delivering messages between nodes. As some of you already know, the rabbitmq.config file can be used to configure various parameters and is loaded by the underlying Erlang node which the Rabbit server runs on.\n\nMy problem is that I have a requirement that some of the configuration needs to be **static** and some needs to be **dynamic**, specifically, I need to be able to reconfigure the shovels running on the Rabbit server from time to time as a result of user interaction (i.e. I need to modify the configuration file programmatic-ally and reboot the rabbit server for it to take affect), but, I **don't** want to rewrite the static configuration every time (especially because I don't want the java code to read it).\n\nI thought I had a solution from reading the Erlang configuration file manual (http://www.erlang.org/doc/man/config.html) which explains how to use one configuration file that points to another such that the configuration of both files will be merged by Erlang. Unfortunately, it doesn't seem to work at all and I could not find any reference to this problem online.\n\nI am testing this on Windows 7 x64 OS using RabbitMQ 3.1.3 and Erlang 5.10/OTP R16.\n\n1st config file:\n\n```\n[\n{'rabbit', [\n {'tcp_listeners', [\n 5672\n ]},\n {'default_vhost', >}\n]}, \"C:\\\\Users\\\\itay\\\\Desktop\\\\RabbitMQ\\\\rabbitmq2.config\"\n].\n```\n\n2nd config file:\n\n```\n[\n{'rabbit', [\n {'default_user', >},\n {'default_pass', >}\n]}\n].\n```\n\nI tried to use single backslash or bit-string for the path as well but it didn't seem to matter.\n\nThe output from running the server in cmd is:\n\n```\n{\"could not start kernel pid\",application_controller,\"invalid config data: invalid application name: \\\"C:\\\\Users\\\\itay\\\\Desktop\\\\RabbitMQ\\\\rabbitmq2.config\\\"\"}\n\nCrash dump was written to: erl_crash.dump\ncould not start kernel pid (application_controller) (invalid config data: invalid application name: \"C:\\\\Users\\\\itay\\\\Desktop\\\\RabbitMQ\\\\rabbitmq2.config\")\n```\n\nAny kind of solution or assistance will be appreciated,\n\nThanks.\n\n========================================\n\nCode:\n```text\n[\n{'rabbit', [\n {'tcp_listeners', [\n 5672\n ]},\n {'default_vhost', <<\"/\">>}\n]}, \"C:\\\\Users\\\\itay\\\\Desktop\\\\RabbitMQ\\\\rabbitmq2.config\"\n].\n```\n\n```text\n[\n{'rabbit', [\n {'default_user', <<\"guest\">>},\n {'default_pass', <<\"guest\">>}\n]}\n].\n```\n\n```text\n{\"could not start kernel pid\",application_controller,\"invalid config data: invalid application name: \\\"C:\\\\Users\\\\itay\\\\Desktop\\\\RabbitMQ\\\\rabbitmq2.config\\\"\"}\n\nCrash dump was written to: erl_crash.dump\ncould not start kernel pid (application_controller) (invalid config data: invalid application name: \"C:\\\\Users\\\\itay\\\\Desktop\\\\RabbitMQ\\\\rabbitmq2.config\")\n```\n\n```text\nsys.config\n```\n\n```text\nsys.config\n```\n\n```text\n-config\n```\n\n```text\n-config second_file\n```\n\n```text\n-App Par Val\n```\n\n```text\n-rabbit default_user '<<\"guest\">>' -rabbit default_pass '<<\"guest\">>'\n```\n\n```text\nRABBITMQ_SERVER_START_ARGS\n```\n\n========================================\n\nComments:\n- OK so as I understand when Erlang runs in **embedded** mode it always looks for sys.config and ignores the `-config` option. Therefore, it was made possible to have the sys.config file point to another file which will be merged with it. In **interactive** mode, the `-config` option is used and no merging is supported. Is this a correct description?\n- I have tried to add another `-config` flag with a second config file but the node will not start - I get this output: `Conflicting -start_erl and -config options` Seems like only one config file is supported... This is bad for me since it is not practical to configure the shovels using only the `-App Par Val` arguments.\n- start_erl is a Windows-specific tool to start Erlang in **embedded** mode. The error message implies you are passing `-config` with your second config file in a command line where there was no `-config` option at all, i.e. probably not at the proper place. Did you modify the script or did you use `RABBITMQ_SERVER_START_ARGS`?\n- I used the start args variable. I can also see that rabbit uses -config to set the default rabbitmq.config file in the command line. However, your other suggestion might work well for me since it is possible to use the `-args_file` option and load the shovels from a separate file containing a single `-rabbit 'shovels' ` argument. I can even use the backslash character for adding line breaks to make this long expression humanly readable.","metadata":{"transformedAt":"2026-08-18T18:33:20.316Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":10,"totalLines":117,"estimatedTokens":1175}}1023{"id":"stack-12180461","source":"stackoverflow","questionId":12180461,"title":"How to delete or postpone a message in the AMQP queue","tags":["python","twisted","rabbitmq","amqp"],"text":"Title: How to delete or postpone a message in the AMQP queue\nTags: python, twisted, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI am using txamqp python library to connect to an AMQP broker (RabbitMQ) and i have a consumer with the following callback:\n\n```\n@defer.inlineCallbacks\ndef message_callback(self, message, queue, chan):\n \"\"\"This callback is a queue listener\n it is called whenever a message was consumed from queue\n c.f. test_amqp.ConsumeTestCase for use cases\n \"\"\"\n\n # The callback should be redefined here to keep getting further messages from queue\n queue.get().addCallback(self.message_callback, queue, chan).addErrback(self.message_errback) \n\n print \" [x] Received a valid message: [%r]\" % (message.content.body,)\n\n yield self.smpp.sendDataRequest(SubmitSmPDU)\n\n # ACK the message in queue, this will remove it from the queue\n chan.basic_ack(message.delivery_tag)\n```\n\nWhen \"ack\"ing a message, it will be deleted (to confirm ?) from the queue, but what happens when the message is not \"ack\"ed ? i need to get a \"retry\" mechanism where i can postpone the message to be callbacked again later on and to keep track of how much retries did it take.\n\nAnd how can i list/delete messages from a queue ?\n\n========================================\n\nTop Answer:\nRabbitMQ has a nice management plugin, however that doesn't even allow one to delete messages from queues. \n\nYou basically would have to write your own application, or figure out which of these 3rd party management applications can delete messaages.\n\n========================================\n\nCode:\n```text\n@defer.inlineCallbacks\ndef message_callback(self, message, queue, chan):\n \"\"\"This callback is a queue listener\n it is called whenever a message was consumed from queue\n c.f. test_amqp.ConsumeTestCase for use cases\n \"\"\"\n\n # The callback should be redefined here to keep getting further messages from queue\n queue.get().addCallback(self.message_callback, queue, chan).addErrback(self.message_errback) \n\n print \" [x] Received a valid message: [%r]\" % (message.content.body,)\n\n yield self.smpp.sendDataRequest(SubmitSmPDU)\n\n # ACK the message in queue, this will remove it from the queue\n chan.basic_ack(message.delivery_tag)\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.316Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":58,"estimatedTokens":560}}1024{"id":"stack-11045280","source":"stackoverflow","questionId":11045280,"title":"Pika basic_publish hangs when publishing on multiple queues","tags":["python","rabbitmq","amqp","pika"],"text":"Title: Pika basic_publish hangs when publishing on multiple queues\nTags: python, rabbitmq, amqp, pika\nSource: Stack Overflow\n\nQuestion:\nI need to setup multiple queues on an exchange. I would like to create a single connection, then declare multiple queues (this works) then, publish messages on the multiple queues (this does not work).\n\nI setup some test code to do this, but it gets hung up on the 2nd publish everytime. I think it does not like publishing on multiple queues without closing the connection, as this code works when I publish on a single queue (even multiple messages on a single queue).\n\nIs there something I need to add to make this work? I would really like to not have to close the connection between publishes. Also, when I have my consumers up, they do not see anything when I send to basic_publish()'s when sending on multiple queues. I do see messages appear almost instantly when I am publishing on a single queue.\n\n```\n#!/usr/bin/env python\nimport pika\n\nqueue_names = ['1a', '2b', '3c', '4d']\n\n# Variables to hold our connection and channel\nconnection = None\nchannel = None\n\n# Called when our connection to RabbitMQ is closed\ndef on_closed(frame):\n global connection\n # connection.ioloop is blocking, this will stop and exit the app\n connection.ioloop.stop()\n\ndef on_connected(connection):\n \"\"\"\n Called when we have connected to RabbitMQ\n This creates a channel on the connection\n \"\"\"\n global channel #TODO: Test removing this global call\n\n connection.add_on_close_callback(on_closed)\n\n # Create a channel on our connection passing the on_channel_open callback\n connection.channel(on_channel_open)\n\ndef on_channel_open(channel_):\n \"\"\"\n Called when channel opened\n Declare a queue on the channel\n \"\"\"\n global channel\n\n # Our usable channel has been passed to us, assign it for future use\n channel = channel_\n\n # Declare a set of queues on this channel\n for queue_name in reversed(queue_names):\n channel.queue_declare(queue=queue_name, durable=True,\n exclusive=False, auto_delete=False,\n callback=on_queue_declared)\n #print \"done making hash\"\n\ndef on_queue_declared(frame):\n \"\"\"\n Called when a queue is declared\n \"\"\"\n global channel\n\n print \"Sending 'Hello World!' on \", frame.method.queue\n\n # Send a message\n channel.basic_publish(exchange='',\n routing_key=frame.method.queue,\n body='Hello World!')\n\n# Create our connection parameters and connect to RabbitMQ\nconnection = pika.SelectConnection(pika.ConnectionParameters('localhost'), \\\n on_connected)\n\n# Start our IO/Event loop\ntry:\n connection.ioloop.start()\nexcept KeyboardInterrupt:\n print \"interrupt\"\n # Gracefully close the connection\n connection.close()\n # Loop until we're fully closed, will stop on its own\n #connection.ioloop.start()\n```\n\n========================================\n\nCode:\n```text\n#!/usr/bin/env python\nimport pika\n\n\nqueue_names = ['1a', '2b', '3c', '4d']\n\n\n# Variables to hold our connection and channel\nconnection = None\nchannel = None\n\n\n# Called when our connection to RabbitMQ is closed\ndef on_closed(frame):\n global connection\n # connection.ioloop is blocking, this will stop and exit the app\n connection.ioloop.stop()\n\n\n\ndef on_connected(connection):\n \"\"\"\n Called when we have connected to RabbitMQ\n This creates a channel on the connection\n \"\"\"\n global channel #TODO: Test removing this global call\n\n connection.add_on_close_callback(on_closed)\n\n # Create a channel on our connection passing the on_channel_open callback\n connection.channel(on_channel_open)\n\n\n\ndef on_channel_open(channel_):\n \"\"\"\n Called when channel opened\n Declare a queue on the channel\n \"\"\"\n global channel\n\n # Our usable channel has been passed to us, assign it for future use\n channel = channel_\n\n\n # Declare a set of queues on this channel\n for queue_name in reversed(queue_names):\n channel.queue_declare(queue=queue_name, durable=True,\n exclusive=False, auto_delete=False,\n callback=on_queue_declared)\n #print \"done making hash\"\n\ndef on_queue_declared(frame):\n \"\"\"\n Called when a queue is declared\n \"\"\"\n global channel\n\n print \"Sending 'Hello World!' on \", frame.method.queue\n\n # Send a message\n channel.basic_publish(exchange='',\n routing_key=frame.method.queue,\n body='Hello World!')\n\n\n# Create our connection parameters and connect to RabbitMQ\nconnection = pika.SelectConnection(pika.ConnectionParameters('localhost'), \\\n on_connected)\n\n# Start our IO/Event loop\ntry:\n connection.ioloop.start()\nexcept KeyboardInterrupt:\n print \"interrupt\"\n # Gracefully close the connection\n connection.close()\n # Loop until we're fully closed, will stop on its own\n #connection.ioloop.start()\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.316Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":168,"estimatedTokens":1206}}1025{"id":"stack-14091700","source":"stackoverflow","questionId":14091700,"title":"Do I have to copy my django project to another machine to perform celery tasks on it?","tags":["python","django","rabbitmq","celery"],"text":"Title: Do I have to copy my django project to another machine to perform celery tasks on it?\nTags: python, django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nHere is the problem - I have a server with my django project on it. \n\nI have to perform a lot of tasks so I use celery+rabbitmq to deal with them. \n\nRecently I discovered that server is running out of memory so I've decided to move all tasks to another dedicated server. Following this guide I've created rabbitmq cluster without copying my django project. \n\nI am able to send tasks to celery on my new dedicated server, however celery says that tasks are unregistered e.g.\n\n`Received unregistered task of type 'djangoapp.tasks.taskname'. The message has been ignored and discarded.`\n\nSo what should I do - just copy my django project or something else?\n\n========================================\n\nTop Answer:\neach celery worker server should be running a copy of the same code, yes\n\n========================================\n\nCode:\n```text\nReceived unregistered task of type 'djangoapp.tasks.taskname'. The message has been ignored and discarded.\n```\n\n```text\ndjangoapp.tasks\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.316Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":32,"estimatedTokens":286}}1026{"id":"stack-13816435","source":"stackoverflow","questionId":13816435,"title":"App crashing after too many missed heartbeats","tags":["rabbitmq","pika"],"text":"Title: App crashing after too many missed heartbeats\nTags: rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI have an app that is distributing load on a bunch of workers. So far all workers are running on the same VM, have not needed to scale up yet.\nMy problem is that, like every 3-4 days, the worker crashes with the error message below - no contact between the client and the rabbitmq server in 1200 secs (I guess).\n\n```\nTraceback (most recent call last):\n File \"/var/www/vhosts/niklas/workers/builder.py\", line 170, in \n BuildWorker().main()\n File \"/var/www/vhosts/niklas/lib/worker.py\", line 29, in main\n self.msgs.ch.start_consuming()\n File \"/usr/local/lib/python2.6/dist-packages/pika/adapters/blocking_connection.py\", line 722, in start_consuming\n self.connection.process_data_events()\n File \"/usr/local/lib/python2.6/dist-packages/pika/adapters/blocking_connection.py\", line 93, in process_data_events\n self.process_timeouts()\n File \"/usr/local/lib/python2.6/dist-packages/pika/adapters/blocking_connection.py\", line 99, in process_timeouts\n self._call_timeout_method(self._timeouts.pop(timeout_id))\n File \"/usr/local/lib/python2.6/dist-packages/pika/adapters/blocking_connection.py\", line 164, in _call_timeout_method\n timeout_value['method']()\n File \"/usr/local/lib/python2.6/dist-packages/pika/heartbeat.py\", line 85, in send_and_check\n return self._close_connection()\n File \"/usr/local/lib/python2.6/dist-packages/pika/heartbeat.py\", line 106, in _close_connection\n HeartbeatChecker._STALE_CONNECTION % duration)\n File \"/usr/local/lib/python2.6/dist-packages/pika/adapters/blocking_connection.py\", line 75, in close\n self.process_data_events()\n File \"/usr/local/lib/python2.6/dist-packages/pika/adapters/blocking_connection.py\", line 91, in process_data_events\n self._handle_timeout()\n File \"/usr/local/lib/python2.6/dist-packages/pika/adapters/blocking_connection.py\", line 198, in _handle_timeout\n self._on_connection_closed(None, True)\n File \"/usr/local/lib/python2.6/dist-packages/pika/adapters/blocking_connection.py\", line 235, in _on_connection_closed\n raise exceptions.AMQPConnectionError(*self.closing)\npika.exceptions.AMQPConnectionError: (320, 'Too Many Missed Heartbeats, No reply in 1200 seconds')\n```\n\nMy question is, what could possibly cause this?\nThis only happen to ~1 out of three workers, the others are running fine without any error message or warning (again, all workers and rabbitmq-server on the same VM).\nI'm using the standard method in Python library pika, start_consuming(), to retrieve new requests. The code is way to big too attach here, and considering the error message, it seems to be out of my code or a system issue.\n\nI'm using:\n\n- Python Pika 0.9.8\n\n- Rabbitmq 3.0.0\n\n- Debian 6.0\n\n- All workers are started inside screen\n\n- VM hosted at Linode, 512MB memory\n\n========================================\n\nCode:\n```text\nTraceback (most recent call last):\n File \"/var/www/vhosts/niklas/workers/builder.py\", line 170, in <module>\n BuildWorker().main()\n File \"/var/www/vhosts/niklas/lib/worker.py\", line 29, in main\n self.msgs.ch.start_consuming()\n File \"/usr/local/lib/python2.6/dist-packages/pika/adapters/blocking_connection.py\", line 722, in start_consuming\n self.connection.process_data_events()\n File \"/usr/local/lib/python2.6/dist-packages/pika/adapters/blocking_connection.py\", line 93, in process_data_events\n self.process_timeouts()\n File \"/usr/local/lib/python2.6/dist-packages/pika/adapters/blocking_connection.py\", line 99, in process_timeouts\n self._call_timeout_method(self._timeouts.pop(timeout_id))\n File \"/usr/local/lib/python2.6/dist-packages/pika/adapters/blocking_connection.py\", line 164, in _call_timeout_method\n timeout_value['method']()\n File \"/usr/local/lib/python2.6/dist-packages/pika/heartbeat.py\", line 85, in send_and_check\n return self._close_connection()\n File \"/usr/local/lib/python2.6/dist-packages/pika/heartbeat.py\", line 106, in _close_connection\n HeartbeatChecker._STALE_CONNECTION % duration)\n File \"/usr/local/lib/python2.6/dist-packages/pika/adapters/blocking_connection.py\", line 75, in close\n self.process_data_events()\n File \"/usr/local/lib/python2.6/dist-packages/pika/adapters/blocking_connection.py\", line 91, in process_data_events\n self._handle_timeout()\n File \"/usr/local/lib/python2.6/dist-packages/pika/adapters/blocking_connection.py\", line 198, in _handle_timeout\n self._on_connection_closed(None, True)\n File \"/usr/local/lib/python2.6/dist-packages/pika/adapters/blocking_connection.py\", line 235, in _on_connection_closed\n raise exceptions.AMQPConnectionError(*self.closing)\npika.exceptions.AMQPConnectionError: (320, 'Too Many Missed Heartbeats, No reply in 1200 seconds')\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.316Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":84,"estimatedTokens":1182}}1027{"id":"stack-5086803","source":"stackoverflow","questionId":5086803,"title":"RabbitMQ management plugin with local cluster","tags":["rabbitmq"],"text":"Title: RabbitMQ management plugin with local cluster\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nIs there any reason that the rabbitmq-management plugin wouldn't work when I'm using 'rabbitmq-multi' to spin up a cluster of nodes on my desktop? Or, more precisely, that the management plugin would cause that spinup to fail?\n\nI get `Error: {node_start_failed,normal}` when rabbitmq-multi starts rabbit_1@localhost\nThe first node, rabbit@localhost seems to start okay though.\n\nIf I take out the management plugins, all the nodes start up (and then cluster) fine. I think I'm using a recent enough Erlang version (5.8/OTP R14A according to the README in my erl5.8.2 folder). I'm using all the plugins that are listed as required on the plugins page, including mochiweb, webmachine, amqp_client, rabbitmq-mochiweb, rabbitmq-management-agent, and rabbitmq-management. Those plugins, and only those plugins.\n\n========================================\n\nCode:\n```text\nError: {node_start_failed,normal}\n```\n\n```text\n#!/bin/sh \nRABBITMQ_NODE_PORT=$1 RABBITMQ_NODENAME=$2 \\ \nRABBITMQ_MNESIA_DIR=/tmp/rabbitmq-$2-mnesia \\ \nRABBITMQ_PLUGINS_EXPAND_DIR=/tmp/rabbitmq-$2-plugins-scratch \\ \nRABBITMQ_LOG_BASE=/tmp \\ \nRABBITMQ_SERVER_START_ARGS=\"-rabbit_mochiweb port 5$1\" \\ \n/path/to/rabbitmq-server -detached\n```\n\n```text\nstart-node.sh 5672 rabbit\nstart-node.sh 5673 hare\n```\n\n========================================\n\nComments:\n- rabbitmq-multi has been very useful for me to understand clustering, so I would be a little disappointed to see it go away","metadata":{"transformedAt":"2026-08-18T18:33:20.316Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":38,"estimatedTokens":386}}1028{"id":"stack-70947346","source":"stackoverflow","questionId":70947346,"title":"How to enqueue old messages into a new queue in RabbitMQ Exchange?","tags":["rabbitmq"],"text":"Title: How to enqueue old messages into a new queue in RabbitMQ Exchange?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have an exchange with a type of `topic` that only redirects messages to queue `payments`\n\nSomewhere in the future, I will decide to add another queue `payment_analyze` to analyze all old and new messages that have been enqueued.\n\ndurable exchanges and queues survive rabbit MQ restarts, persistent messages get written to disk but when binding a new queue to an old durable exchange, old messages do not get redirected (only new ones do get redirected)\n\nFrom my understanding, this is the intended behavior as exchanges do not store messages and only act as a \"proxy\"\n\nHow do I achieve this?\n\n**Possible Solution**\n\nCreating a queue named `parking` and adding every enqueued message to it, whenever a new queue is added, consume messages from `parking` without acknowledging to keep the new queue \"semi\" up to date.\n\n========================================\n\nCode:\n```text\ntopic\n```\n\n```text\npayments\n```\n\n```text\npayment_analyze\n```\n\n```text\nparking\n```\n\n```text\nparking\n```\n\n```text\npayments\n```\n\n```text\npayment_analyze\n```\n\n```text\npayment_analyze\n```\n\n```text\npayments\n```\n\n```text\npayment_analyze\n```\n\n```text\npayments\n```\n\n```text\npayment_analyze\n```\n\n```text\npayment_analyze\n```\n\n```text\npayments\n```\n\n```text\npayments\n```\n\n========================================\n\nComments:\n- Thanks a lot for the well-detailed answer. I am actually coming from Kafka and unfortunately, Kafka is not affordable for us right now (both in terms of deployment knowledge and expenses)","metadata":{"transformedAt":"2026-08-18T18:33:20.316Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":15,"totalLines":86,"estimatedTokens":400}}1029{"id":"stack-59529531","source":"stackoverflow","questionId":59529531,"title":"RabbitMQ Federate to Virtual Host on Same Server","tags":["rabbitmq"],"text":"Title: RabbitMQ Federate to Virtual Host on Same Server\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have a RabbitMQ server which receives messages to an exchange within a virtual host called \"ce_func\", this exchange is bound to a queue called \"azure_trigger\".\n\nI'd like to use Azure Functions new RabbitMQ binding to collect from Rabbit. Unfortunately, this is limited to collecting only from virtual host '/' . I was hoping that I could use Rabbit's federation functionality to automatically route to an \"azure_trigger\" queue within the \"/\" virtual host of the same server but so far I've failed.\n\nI created a Rabbit \"upstream\" and \"policy\" applied to that upstream but I can't figure out the configuration. I have a Federation Status of \"Running\" but it's only checking the \"ce_func\" virtual host, I can't see where I can set the target exchange as the \"/\" virtual host.\n\nDoes anyone have any pointers please?\n\nhttps://i.sstatic.net/TEYpo.png\n\nhttps://i.sstatic.net/rDCn8.png\n\nhttps://i.sstatic.net/iXi8x.png\n\n========================================\n\nTop Answer:\nIt is possible to reference any virtual host (vhost) in the in the `uri` field of the federation-upstream's configuration in the form:\n\n```\n\"amqp://\" [ username [ \":\" password ] \"@\" ] host [ \":\" port ] [ \"/\" vhost ]\n```\n\nSo in simple terms you can wack the vhost on the end of the uri e.g. `amqp://localhost:5672/myvhost`... if your vhost name is blank then just make sure you include the trailing slash '/' e.g. `amqp://localhost:5672/`.\n\nA note specific to the blank vhost from the rabbitmq docs (https://www.rabbitmq.com/uri-spec.html)\n\nThe vhost component may be absent; this is indicated by the lack of a\n\"/\" character following the amqp_authority. An absent vhost component\nis not equivalent to an empty (i.e. zero-length) vhost name.\n\n========================================\n\nCode:\n```text\n\"amqp://\" [ username [ \":\" password ] \"@\" ] host [ \":\" port ] [ \"/\" vhost ]\n```\n\n```text\nuri\n```\n\n```text\namqp://localhost:5672/myvhost\n```\n\n```text\namqp://localhost:5672/\n```\n\n========================================\n\nComments:\n- There's no way to adjust the connection parameter to use a different vhost? This seems like a pretty severe limitation... have you tried changing the URI of the connection??","metadata":{"transformedAt":"2026-08-18T18:33:20.316Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":59,"estimatedTokens":569}}1030{"id":"stack-10731495","source":"stackoverflow","questionId":10731495,"title":"MassTransit with RabbitMQ - what address to RecieveFrom","tags":["c#","rabbitmq","esb","masstransit"],"text":"Title: MassTransit with RabbitMQ - what address to RecieveFrom\nTags: c#, rabbitmq, esb, masstransit\nSource: Stack Overflow\n\nQuestion:\nWe have configured an active/active cluster of RabbitMQ's in our test environment.\n\nWe connect using MassTransit specifying ReceiveFrom(\"rabbitmq://cluster_machine_a/some_queue?ha=true\").\n\nObviously, this is utilizing a specific cluster node and thus provides no failover.\n\nWhat is the correct method of informing MassTransit about cluster node(s) so that failover occurs?\n\nRabbitMQ documentation indicates that clients should use a traditional load-balancer to farm the traffic, however will this work with RabbitMQ? (last section - http://www.rabbitmq.com/clustering.html)","metadata":{"transformedAt":"2026-08-18T18:33:20.316Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":14,"estimatedTokens":177}}1031{"id":"stack-22465666","source":"stackoverflow","questionId":22465666,"title":"Difference between vFabric RabbitMQ and plain old RabbitMQ","tags":["rabbitmq","vmware"],"text":"Title: Difference between vFabric RabbitMQ and plain old RabbitMQ\nTags: rabbitmq, vmware\nSource: Stack Overflow\n\nQuestion:\nWhat are the key differences between the vFabric RabbitMQ and RabbitMQ besides that vFabric is commercially supported by VMWare?\n\n========================================\n\nComments:\n- so it means when I buy vFabric RabbitMQ, I'm just buying some support?\n- Yeah and all the other \"components\" that come with it, for example if you buy the Pivotal suite. You can tell that they are not very clear on their website as they want to sell you the support. Also they have a per CPU limit and that's so they can support you.\n- The ASL does not enforce \"open sourceness\" - it allows binary only distribution.","metadata":{"transformedAt":"2026-08-18T18:33:20.316Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":13,"estimatedTokens":181}}1032{"id":"stack-65940177","source":"stackoverflow","questionId":65940177,"title":"Asyncio: Fastapi with aio-pika, consumer ignores Await","tags":["websocket","async-await","rabbitmq","python-asyncio","fastapi"],"text":"Title: Asyncio: Fastapi with aio-pika, consumer ignores Await\nTags: websocket, async-await, rabbitmq, python-asyncio, fastapi\nSource: Stack Overflow\n\nQuestion:\nI am trying to hook my websocket endpoint with rabbitmq (aio-pika). Goal is to have listener in that endpoint and on any new message from queue pass the message to browser client over websockets.\n\nI tested the consumer with asyncio in a script with asyncio loop. Works as I followed and used **aio-pika** documentation. (source: https://aio-pika.readthedocs.io/en/latest/rabbitmq-tutorial/2-work-queues.html, **worker.py**)\n\nHowever, when I use it in **fastapi** in websockets endpoint, I cant make it work. Somehow the listener:\n\n```\nawait queue.consume(on_message)\n```\n\nis completely ignored.\n\nThis is my attempt (I put it all in one function, so its more readable):\n\n```\n@app.websocket(\"/ws\")\nasync def websocket_endpoint(websocket: WebSocket):\n print(\"Entering websockets\")\n await manager.connect(websocket)\n print(\"got connection\")\n\n # params\n queue_name = \"task_events\"\n routing_key = \"user_id.task\"\n\n con = \"amqp://rabbitmq:rabbitmq@rabbit:5672/\"\n connection = await connect(con)\n channel = await connection.channel()\n\n await channel.set_qos(prefetch_count=1)\n\n exchange = await channel.declare_exchange(\n \"topic_logs\",\n ExchangeType.TOPIC,\n )\n\n # Declaring queue\n queue = await channel.declare_queue(queue_name)\n\n # Binding the queue to the exchange\n await queue.bind(exchange, routing_key)\n\n async def on_message(message: IncomingMessage):\n async with message.process():\n # here will be the message passed over websockets to browser client\n print(\"sent\", message.body)\n\n \n\n \n try:\n \n ######### Not working as expected ###########\n # await does not await and websockets finishes, as there is no loop\n await queue.consume(on_message) \n #############################################\n\n ################ This Alternative code atleast receives some messages #############\n # If I use this part, I atleast get some messages, when I trigger a backend task that publishes new messages to the queue. \n # It seems like the messages are somehow stuck and new task releases all stucked messages, but does not release new one. \n while True: \n await queue.consume(on_message)\n await asyncio.sleep(1)\n ################## one part #############\n\n except WebSocketDisconnect:\n manager.disconnect(websocket)\n```\n\nI am quite new to async in python. I am not sure where is the problem and I cannot somehow implement async consuming loop while getting inspired with worker.py from aio-pika.\n\n========================================\n\nTop Answer:\nYou could use an async iterator, which is the second canonical way to consume messages from a queue.\n\nIn your case, this means:\n\n```\nasync with queue.iterator() as iter:\n async for message in iter:\n async with message.process():\n # do something with message\n```\n\nIt will block as long as no message is received and will be suspended again after processing a message.\n\n========================================\n\nCode:\n```text\nawait queue.consume(on_message)\n```\n\n```text\n@app.websocket(\"/ws\")\nasync def websocket_endpoint(websocket: WebSocket):\n print(\"Entering websockets\")\n await manager.connect(websocket)\n print(\"got connection\")\n\n # params\n queue_name = \"task_events\"\n routing_key = \"user_id.task\"\n\n\n con = \"amqp://rabbitmq:rabbitmq@rabbit:5672/\"\n connection = await connect(con)\n channel = await connection.channel()\n\n\n await channel.set_qos(prefetch_count=1)\n\n exchange = await channel.declare_exchange(\n \"topic_logs\",\n ExchangeType.TOPIC,\n )\n\n # Declaring queue\n queue = await channel.declare_queue(queue_name)\n\n # Binding the queue to the exchange\n await queue.bind(exchange, routing_key)\n\n async def on_message(message: IncomingMessage):\n async with message.process():\n # here will be the message passed over websockets to browser client\n print(\"sent\", message.body)\n\n \n\n \n try:\n \n ######### Not working as expected ###########\n # await does not await and websockets finishes, as there is no loop\n await queue.consume(on_message) \n #############################################\n\n ################ This Alternative code atleast receives some messages #############\n # If I use this part, I atleast get some messages, when I trigger a backend task that publishes new messages to the queue. \n # It seems like the messages are somehow stuck and new task releases all stucked messages, but does not release new one. \n while True: \n await queue.consume(on_message)\n await asyncio.sleep(1)\n ################## one part #############\n\n except WebSocketDisconnect:\n manager.disconnect(websocket)\n```\n\n```text\nconsumer_tag = await queue.consume(on_message, no_ack=True)\n```\n\n```text\nawait queue.cancel(consumer_tag)\n```\n\n```text\nwhile True:\n data = await websocket.receive_text()\n x = await manager.send_message(data, websocket)\n```\n\n```py\nasync with queue.iterator() as iter:\n async for message in iter:\n async with message.process():\n # do something with message\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.316Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":176,"estimatedTokens":1295}}1033{"id":"stack-58771445","source":"stackoverflow","questionId":58771445,"title":"Can I prevent amqp.Channel closing on errors?","tags":["go","rabbitmq"],"text":"Title: Can I prevent amqp.Channel closing on errors?\nTags: go, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI try to create multiple AMQP queue consumers on a single channel in Go.\n\nThe problem I am facing is that when creating multiple consumers, if the first fails, the channel gets closed right away, preventing further operations.\n\nIs there a way to avoid this or do I have to re-create the channel?\n\n### Example\n\nAssuming that the queue \"client-a\" does not exist, this will result in an error when creating a queue consumer for \"client-b\" because the channel has been closed at that point. The error would be `Exception (504) Reason: \"channel/connection is not open\"`\n\n```\npackage main\n\nimport (\n \"github.com/streadway/amqp\"\n \"log\"\n)\n\nfunc check(err error) {\n if err != nil {\n panic(err)\n }\n}\n\nfunc TestChannelProblems() {\n // Setup AMQP stuff\n connection, err := amqp.Dial(\"amqp://guest:guest@localhost:5672/\")\n check(err)\n log.Println(\"Queue connection ok\")\n\n channel, err := connection.Channel()\n check(err)\n log.Println(\"Queue channel ok\")\n\n queuesToConnectTo := []string{\"client-a\", \"client-b\"}\n\n for i, _ := range queuesToConnectTo {\n queueName := queuesToConnectTo[i]\n\n _, err := channel.Consume(queueName, \"\", false, false, false, false, nil)\n if err != nil {\n log.Printf(\"Connecting to queue %v failed: %v\", queueName, err.Error())\n }\n\n // ... Here would be the logic to use the return value of channel.Consume\n }\n}\n```\n\n========================================\n\nTop Answer:\nI try to create multiple amqp queue consumers on a single channel in Go.\n\nThis is generally not recommended. If one of your consumers encounters an error, it will shut down the other two as well. You should open one channel for each consumer. Even though opening a channel is relatively costly, as it is a network roundtrip, this is unlikely to become an issue in practice.\n\nIs there a way to prevent this or do I have to re-create the channel?\n\nYou have to recreate the channel. The library `streadway/amqp` closes the delivery channel anyway (channel = the Go type `You can check this thread for details about how to handle AMQP errors and possibly recover them. In essence, you use `NotifyClose` to listen for close events:\n\n```\n// c is an *amqp.Channel\nerrC := c.NotifyClose(make(chan *amqp.Error, 10))\ngo func() {\n for err := range errC {\n if err != nil {\n // error-handling\n }\n }\n}()\n```\n\n========================================\n\nCode:\n```text\npackage main\n\nimport (\n \"github.com/streadway/amqp\"\n \"log\"\n)\n\nfunc check(err error) {\n if err != nil {\n panic(err)\n }\n}\n\nfunc TestChannelProblems() {\n // Setup AMQP stuff\n connection, err := amqp.Dial(\"amqp://guest:guest@localhost:5672/\")\n check(err)\n log.Println(\"Queue connection ok\")\n\n channel, err := connection.Channel()\n check(err)\n log.Println(\"Queue channel ok\")\n\n queuesToConnectTo := []string{\"client-a\", \"client-b\"}\n\n for i, _ := range queuesToConnectTo {\n queueName := queuesToConnectTo[i]\n\n _, err := channel.Consume(queueName, \"\", false, false, false, false, nil)\n if err != nil {\n log.Printf(\"Connecting to queue %v failed: %v\", queueName, err.Error())\n }\n\n // ... Here would be the logic to use the return value of channel.Consume\n }\n}\n```\n\n```text\nException (504) Reason: \"channel/connection is not open\"\n```\n\n```text\n// c is an *amqp.Channel\nerrC := c.NotifyClose(make(chan *amqp.Error, 10))\ngo func() {\n for err := range errC {\n if err != nil {\n // error-handling\n }\n }\n}()\n```\n\n```text\nstreadway/amqp\n```\n\n```text\n<-chan amqp.Delivery\n```\n\n```text\nNotifyClose\n```\n\n========================================\n\nComments:\n- Why is the channel closed? Please show a minimal reproducible example\n- Will do, might take a monent. Sorry for missing that\n- Done. I am sure there is a way to handle this scenario myself by coding some resilient solution. What I am asking my self is if there is a way to have RabbitMQ not close the channel on exceptions like this one\n- Not sure if I understand your question. `Channel.Consume` itself returns a read-only channel of `Delivery`, which in turn can be read of for new messages. So you want the same connection to handle multiple queues? And what prevents you from using `Channel.QueueDeclare`, as suggested in the documentation?\n- Using `QueueDeclare` would of course be the correct option. Sadly I am not in control of that since my software is just a minor part of a monolithic system where the queues may not be created by me... *sigh*","metadata":{"transformedAt":"2026-08-18T18:33:20.316Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":155,"estimatedTokens":1140}}1034{"id":"stack-49289923","source":"stackoverflow","questionId":49289923,"title":"MassTransit.RabbitMQ - Connect Failed: Broker unreachable","tags":["rabbitmq","masstransit"],"text":"Title: MassTransit.RabbitMQ - Connect Failed: Broker unreachable\nTags: rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nAfter updating MassTransit packages to the latest version (4.1.0.1426-develop) I experience problems with registering more then 26 queues. For example, code below crushes with error\n\n [20:51:06 ERR] RabbitMQ Connect Failed: Broker unreachable:\n guest@localhost:5672/test\n\n```\nstatic void Main(string[] args)\n{\n var builder = new ConfigurationBuilder()\n .AddJsonFile(\"appsettings.json\", true, true);\n\n var configuration = builder.Build();\n\n Log.Logger = new LoggerConfiguration()\n .MinimumLevel.Debug()\n .WriteTo.Console()\n .ReadFrom.Configuration(configuration)\n .CreateLogger();\n\n Log.Information(\"Starting Receiver...\");\n\n var services = new ServiceCollection();\n\n services.AddSingleton(context => Bus.Factory.CreateUsingRabbitMq(x =>\n {\n IRabbitMqHost host = x.Host(new Uri(\"rabbitmq://guest:guest@localhost:5672/test\"), h => { });\n\n for (var i = 0; i \n {\n e.Consumer();\n });\n }\n\n x.UseSerilog();\n }));\n\n var container = services.BuildServiceProvider();\n\n var busControl = container.GetRequiredService();\n\n busControl.Start();\n\n Log.Information(\"Receiver started...\");\n}\n```\n\nSo, it can't register 27 queues. However it works if I decrease the number to 26 :)\n\nIf I downgrade MT NuGet packages to the latest stable 4.0.1 version it perfectly works and I can register up to 50 queues. \n\nAlso, another observation - with 4.1.0.1426-develop versions it takes much longer to start this very tiny app. However when I test it with latest stable 4.0.1 and try to create 50 queues it starts almost immediately. \n\nAny ideas where this limitation came from and how to avoid it?\n\n========================================\n\nTop Answer:\nI know this has been marked as resolved but I ran into a similar issue.\n\nfail: MassTransit[0] partners.moneytransfer | RabbitMQ Connect Failed:\nserviceUser@rabbitmq:5672/\n\nThe only way I was able to resolve is, is by adding the user to the rabbitmq database with its username and password as specified in the Bus configuration.\n\n========================================\n\nCode:\n```text\nstatic void Main(string[] args)\n{\n var builder = new ConfigurationBuilder()\n .AddJsonFile(\"appsettings.json\", true, true);\n\n var configuration = builder.Build();\n\n Log.Logger = new LoggerConfiguration()\n .MinimumLevel.Debug()\n .WriteTo.Console()\n .ReadFrom.Configuration(configuration)\n .CreateLogger();\n\n Log.Information(\"Starting Receiver...\");\n\n var services = new ServiceCollection();\n\n services.AddSingleton(context => Bus.Factory.CreateUsingRabbitMq(x =>\n {\n IRabbitMqHost host = x.Host(new Uri(\"rabbitmq://guest:guest@localhost:5672/test\"), h => { });\n\n for (var i = 0; i < 27; i++)\n {\n x.ReceiveEndpoint(host, $\"receiver_queue{i}\", e =>\n {\n e.Consumer<TestHandler>();\n });\n }\n\n x.UseSerilog();\n }));\n\n var container = services.BuildServiceProvider();\n\n var busControl = container.GetRequiredService<IBusControl>();\n\n busControl.Start();\n\n Log.Information(\"Receiver started...\");\n}\n```\n\n========================================\n\nComments:\n- I suggest creating a reproduction repository on Github and opening an issue in MT repository.\n- Yeah, this is weird. I wonder why it would do such a thing. Limitations on Task.WhenAll perhaps? Hmm.\n- I opened issue here github.com/MassTransit/MassTransit/issues/1078 as @Alexey Zimarev suggested\n- Thank you a lot for such a quick fix!","metadata":{"transformedAt":"2026-08-18T18:33:20.316Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":122,"estimatedTokens":895}}1035{"id":"stack-59137109","source":"stackoverflow","questionId":59137109,"title":"How do I hook into TransactionScope on completing \"event\"?","tags":["c#","rabbitmq","transactionscope","masstransit"],"text":"Title: How do I hook into TransactionScope on completing \"event\"?\nTags: c#, rabbitmq, transactionscope, masstransit\nSource: Stack Overflow\n\nQuestion:\nI want to know if there's a way to hook into a currently running transaction and have stuff be done when that transaction completes. \n\nCurrently I'm in the process of implementing an `EventPublisher` that uses MassTransit/RabbitMQ to publish messages, but I want to only have those messages be published when a TransactionScope is getting completed. \n\nI would check inside the `EventPublisher.PublishEvent()` method if there's currently a transaction running, if no, then fire off the messages, if yes, then collect the messages and wait for the transaction to complete to send them off. \n\n```\nvar ep = container.GetInstance();\n\nusing(var scope = new TransactionScope())\n{\n ... do some stuff \n SaveEntity(entity);\n ep.PublishEvent(new EntitySaved(entity.Id));\n\n ... do some more stuff ...\n\n UpdateEntity(differentEntity);\n ep.PublishEvent(new EntityUpdated(differentEntity.Id));\n\n ... do even more stuff ...\n\n ep.PublishEvent(new UnrelatedMessage(someData));\n\n scope.Complete(); // I found this `TransactionCompleted` Event here https://learn.microsoft.com/en-us/dotnet/api/system.transactions.transaction.transactioncompleted \nBut it seems to only be fired after the `scope.Complete()` bits are over and done. \n\nI could use this to check if the transaction status is completed and then like actually fire off those messages I collected during the transaction. But my problem is that the connection to RabbitMQ could be down. And then I wouldn't be able to send those messages, but all the work above has been done already, but I never was able to send off those messages. \n\nWhat I actually want is to somehow hook into the bit where the transaction is currently completing and during that process I fire off my messages and if that fails I can throw an exception and have that still running transaction go out the window. \n\nMaybe there's a way to do that with MassTransit, but the documentation isn't really forthcoming there. \n\nHere's some example code showing the problem.\n\n```\ninternal class Program\n {\n private static void Main(string[] args)\n {\n const string connectionString = \"Data Source=.;Initial Catalog=MyDatabase;Integrated Security=True\";\n\n var sql = @\"insert into [SomeTable] (\n [Id]\n ,[Name]\n ,[Index]\n ,[RelationId]\n ) values (@param1, @param2, @param3, @param4) \";\n\n using (var scope = new TransactionScope())\n {\n Transaction.Current.TransactionCompleted += CurrentOnTransactionCompleted;\n using (var con = new SqlConnection(connectionString))\n {\n con.Open();\n\n using (var cmd = new SqlCommand(sql, con))\n {\n cmd.Parameters.Add(\"@param1\", SqlDbType.UniqueIdentifier).Value = Guid.NewGuid();\n cmd.Parameters.Add(\"@param2\", SqlDbType.NVarChar, 128).Value = \"Blah\";\n cmd.Parameters.Add(\"@param3\", SqlDbType.SmallInt).Value = 1;\n cmd.Parameters.Add(\"@param4\", SqlDbType.UniqueIdentifier).Value = Guid.Parse(\"a401866d-3bdd-48a4-a78b-d40864c8471b\");\n cmd.CommandType = CommandType.Text;\n cmd.ExecuteNonQuery();\n }\n }\n\n scope.Complete();\n }\n }\n\n private static void CurrentOnTransactionCompleted(object sender, TransactionEventArgs e)\n {\n // I want to do stuff here but if this stuff fails I need the whole transaction to roll back.\n ... do some stuff that can fail ...\n\n e.Transaction.Rollback(new Exception(\"Bad transaction!\"));\n\n // or\n throw new Exception(\"Bad transaction!\"); \n\n }\n }\n```\n\n========================================\n\nCode:\n```text\nvar ep = container.GetInstance<IEventPublisher>();\n\nusing(var scope = new TransactionScope())\n{\n ... do some stuff \n SaveEntity(entity);\n ep.PublishEvent(new EntitySaved(entity.Id));\n\n ... do some more stuff ...\n\n UpdateEntity(differentEntity);\n ep.PublishEvent(new EntityUpdated(differentEntity.Id));\n\n ... do even more stuff ...\n\n ep.PublishEvent(new UnrelatedMessage(someData));\n\n scope.Complete(); // <- only want the actual sending off to RabbitMQ to happen here.\n}\n```\n\n```text\ninternal class Program\n {\n private static void Main(string[] args)\n {\n const string connectionString = \"Data Source=.;Initial Catalog=MyDatabase;Integrated Security=True\";\n\n var sql = @\"insert into [SomeTable] (\n [Id]\n ,[Name]\n ,[Index]\n ,[RelationId]\n ) values (@param1, @param2, @param3, @param4) \";\n\n using (var scope = new TransactionScope())\n {\n Transaction.Current.TransactionCompleted += CurrentOnTransactionCompleted;\n using (var con = new SqlConnection(connectionString))\n {\n con.Open();\n\n using (var cmd = new SqlCommand(sql, con))\n {\n cmd.Parameters.Add(\"@param1\", SqlDbType.UniqueIdentifier).Value = Guid.NewGuid();\n cmd.Parameters.Add(\"@param2\", SqlDbType.NVarChar, 128).Value = \"Blah\";\n cmd.Parameters.Add(\"@param3\", SqlDbType.SmallInt).Value = 1;\n cmd.Parameters.Add(\"@param4\", SqlDbType.UniqueIdentifier).Value = Guid.Parse(\"a401866d-3bdd-48a4-a78b-d40864c8471b\");\n cmd.CommandType = CommandType.Text;\n cmd.ExecuteNonQuery();\n }\n }\n\n scope.Complete();\n }\n }\n\n private static void CurrentOnTransactionCompleted(object sender, TransactionEventArgs e)\n {\n // I want to do stuff here but if this stuff fails I need the whole transaction to roll back.\n ... do some stuff that can fail ...\n\n e.Transaction.Rollback(new Exception(\"Bad transaction!\"));\n\n // or\n throw new Exception(\"Bad transaction!\"); \n\n }\n }\n```\n\n```text\nEventPublisher\n```\n\n```text\nEventPublisher.PublishEvent()\n```\n\n```text\nTransactionCompleted\n```\n\n```text\nscope.Complete()\n```\n\n```text\nIEnlistmentNotification\n```\n\n```text\nForceRollback\n```\n\n========================================\n\nComments:\n- I believe the outbox feature does what you need and it has nothing to do with transactions. It just collects all the messages that you want to send or publish and does it only if the message is successfully consumed masstransit-project.com/usage/exceptions.html#outbox\n- The thing is, I'm not inside a consumer here. All the message consumers are part of one or multiple dedicated other processes. This here is specifically only using MT to send messages to RabbitMQ. So no ReceiveEndpoint configured there.\n- Can't you use the Transaction.Rollback() method in case the RabbitMQ is down.... As in once in the TransactionCompleted event you check and find RabbitMQ is down you can call eventArg.Transaction.Rollback()\n- Sadly this doesn't work. You get a `System.Transactions.TransactionException: 'The operation is not valid for the state of the transaction.'` exception when trying to rollback the transaction from inside the event. Reason being that the transaction is already completed.\n- So would it make sense to create a TransactionOutbox that would release the messages to the broker once the transaction is committed? Similar to InMemory, but triggered by the transaction.\n- Yes. Exactly that. I will be doing that myself, but I guess it would be cool if MassTransit would support that scenario ootb.\n- If you get it working and want to the solution/code back to the project, that would be great.","metadata":{"transformedAt":"2026-08-18T18:33:20.317Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":199,"estimatedTokens":1877}}1036{"id":"stack-57140039","source":"stackoverflow","questionId":57140039,"title":"How to fix ListenerExecutionFailedException: Listener threw exception amqp.AmqpRejectAndDontRequeueException: Reply received after timeout","tags":["spring-boot","rabbitmq","spring-rabbit"],"text":"Title: How to fix ListenerExecutionFailedException: Listener threw exception amqp.AmqpRejectAndDontRequeueException: Reply received after timeout\nTags: spring-boot, rabbitmq, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI set up rabbbitMQ on my java spring-boot application and it works properly (it seems), but after running for a while and somehow with same time interval It throws below exception.\n\n```\norg.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Listener threw exception\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.wrapToListenerExecutionFailedExceptionIfNeeded(AbstractMessageListenerContainer.java:1646) ~[spring-rabbit-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1550) ~[spring-rabbit-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1473) ~[spring-rabbit-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1461) ~[spring-rabbit-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:1456) ~[spring-rabbit-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1405) ~[spring-rabbit-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]\n at org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer$SimpleConsumer.callExecuteListener(DirectMessageListenerContainer.java:995) [spring-rabbit-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]\n at org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer$SimpleConsumer.handleDelivery(DirectMessageListenerContainer.java:955) [spring-rabbit-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]\n at com.rabbitmq.client.impl.ConsumerDispatcher$5.run(ConsumerDispatcher.java:149) [amqp-client-5.4.3.jar!/:5.4.3]\n at com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable.run(ConsumerWorkService.java:104) [amqp-client-5.4.3.jar!/:5.4.3]\n at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_201]\n at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_201]\n at java.lang.Thread.run(Thread.java:748) [na:1.8.0_201]\nCaused by: org.springframework.amqp.AmqpRejectAndDontRequeueException: Reply received after timeout\n at org.springframework.amqp.rabbit.core.RabbitTemplate.onMessage(RabbitTemplate.java:2523) ~[spring-rabbit-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]\n at org.springframework.amqp.rabbit.listener.DirectReplyToMessageListenerContainer.lambda$setMessageListener$1(DirectReplyToMessageListenerContainer.java:115) ~[spring-rabbit-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1547) ~[spring-rabbit-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]\n ... 11 common frames omitted\n```\n\nbelow you can find the consumer code for rabbit configuration \n\n```\n@Bean\n public DirectExchange exchange() {\n return new DirectExchange(\"rpc\");\n }\n\n @Bean\n @Qualifier(\"Consumer\")\n public Queue queue() {\n return new Queue(RoutingEngine.class.getSimpleName()+\"_\"+config.getDatasetName());\n }\n\n @Bean\n public Binding binding(Queue queue, DirectExchange exchange) {\n return BindingBuilder.bind(queue).to(exchange).with(Consumer.class.getSimpleName()+\"_\"+config.getDatasetName());\n }\n\n @Bean\n @Qualifier(\"ConsumerExport\")\n public AmqpInvokerServiceExporter exporter(RabbitTemplate template, Consumer service) {\n AmqpInvokerServiceExporter exporter = new AmqpInvokerServiceExporter();\n exporter.setAmqpTemplate(template);\n exporter.setService(service);\n exporter.setServiceInterface(Consumer.class);\n return exporter;\n }\n\n @Bean\n public SimpleMessageListenerContainer container(ConnectionFactory connectionFactory,@Qualifier(\"consumer\") Queue queue,\n @Qualifier(\"RoutingEngineExport\") AmqpInvokerServiceExporter exporter) {\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);\n container.setPrefetchCount(5);\n container.setQueues(queue);\n container.setMessageListener(exporter);\n logger.info(\"initialize rabbitmq with {} Consumers\",config.getCount());\n container.setConcurrency(1+\"-\"+config.getCount());\n return container;\n }\n\n @Bean\n public FanoutExchange fanoutExchange(){\n return new FanoutExchange(\"event\");\n }\n\n @Bean\n @Qualifier(\"reinitialize\")\n public Queue reInitQueue() {\n return new Queue(\"bus.\"+config.getConsumerName(),false,true,true);\n }\n\n @Bean\n public Binding topicBinding(@Qualifier(\"reinitialize\") Queue queue, FanoutExchange fanoutExchangee) {\n return BindingBuilder\n .bind(queue)\n .to(fanoutExchangee);\n }\n\n @Bean\n public MessageListener messageListener(RabbitTemplate rabbitTemplate,Consumer target){\n return new MessageListener<>(rabbitTemplate, target, \"engine\", config.getConsumerName());\n }\n```\n\nand also producer configuration code is \n\n```\n@Bean\n public AmqpProxyFactoryBean rerouteProxy(RabbitTemplate template) {\n AmqpProxyFactoryBean proxy = new AmqpProxyFactoryBean();\n proxy.setAmqpTemplate(template);\n proxy.setServiceInterface(ConsumerService.class);\n proxy.setRoutingKey(ConsumerService.class.getSimpleName());\n return proxy;\n }\n\n @Bean\n public Map consumerEngines( RabbitTemplate template){\n Map ret= new ConcurrentHashMap<>();\n //FIXme read from config\n List lst = Arrays.asList(config.getEngines());\n lst.parallelStream().forEach(k->{\n AmqpProxyFactoryBean proxy = new AmqpProxyFactoryBean();\n template.setReceiveTimeout(400);\n template.setReplyTimeout(400);\n proxy.setAmqpTemplate(template);\n proxy.setServiceInterface(Consumer.class);\n proxy.setRoutingKey(Consumer.class.getSimpleName() + \"_\" + k);\n proxy.afterPropertiesSet();\n ret.put(k, (Consumer) proxy.getObject());\n });\n return ret;\n }\n```\n\nwhat causes this problem and how to fix it?\n\nNOTE 1: I have 3 producers and 3 consumers on different servers, and rabbit is running on another server\n\nٔNOTE 2: Consumers are very fast, their response time is less than 100 miliseconds\n\n========================================\n\nCode:\n```text\norg.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Listener threw exception\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.wrapToListenerExecutionFailedExceptionIfNeeded(AbstractMessageListenerContainer.java:1646) ~[spring-rabbit-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1550) ~[spring-rabbit-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1473) ~[spring-rabbit-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1461) ~[spring-rabbit-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:1456) ~[spring-rabbit-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1405) ~[spring-rabbit-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]\n at org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer$SimpleConsumer.callExecuteListener(DirectMessageListenerContainer.java:995) [spring-rabbit-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]\n at org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer$SimpleConsumer.handleDelivery(DirectMessageListenerContainer.java:955) [spring-rabbit-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]\n at com.rabbitmq.client.impl.ConsumerDispatcher$5.run(ConsumerDispatcher.java:149) [amqp-client-5.4.3.jar!/:5.4.3]\n at com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable.run(ConsumerWorkService.java:104) [amqp-client-5.4.3.jar!/:5.4.3]\n at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_201]\n at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_201]\n at java.lang.Thread.run(Thread.java:748) [na:1.8.0_201]\nCaused by: org.springframework.amqp.AmqpRejectAndDontRequeueException: Reply received after timeout\n at org.springframework.amqp.rabbit.core.RabbitTemplate.onMessage(RabbitTemplate.java:2523) ~[spring-rabbit-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]\n at org.springframework.amqp.rabbit.listener.DirectReplyToMessageListenerContainer.lambda$setMessageListener$1(DirectReplyToMessageListenerContainer.java:115) ~[spring-rabbit-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]\n at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1547) ~[spring-rabbit-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]\n ... 11 common frames omitted\n```\n\n```text\n@Bean\n public DirectExchange exchange() {\n return new DirectExchange(\"rpc\");\n }\n\n\n @Bean\n @Qualifier(\"Consumer\")\n public Queue queue() {\n return new Queue(RoutingEngine.class.getSimpleName()+\"_\"+config.getDatasetName());\n }\n\n @Bean\n public Binding binding(Queue queue, DirectExchange exchange) {\n return BindingBuilder.bind(queue).to(exchange).with(Consumer.class.getSimpleName()+\"_\"+config.getDatasetName());\n }\n\n\n @Bean\n @Qualifier(\"ConsumerExport\")\n public AmqpInvokerServiceExporter exporter(RabbitTemplate template, Consumer service) {\n AmqpInvokerServiceExporter exporter = new AmqpInvokerServiceExporter();\n exporter.setAmqpTemplate(template);\n exporter.setService(service);\n exporter.setServiceInterface(Consumer.class);\n return exporter;\n }\n\n @Bean\n public SimpleMessageListenerContainer container(ConnectionFactory connectionFactory,@Qualifier(\"consumer\") Queue queue,\n @Qualifier(\"RoutingEngineExport\") AmqpInvokerServiceExporter exporter) {\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);\n container.setPrefetchCount(5);\n container.setQueues(queue);\n container.setMessageListener(exporter);\n logger.info(\"initialize rabbitmq with {} Consumers\",config.getCount());\n container.setConcurrency(1+\"-\"+config.getCount());\n return container;\n }\n\n\n\n\n @Bean\n public FanoutExchange fanoutExchange(){\n return new FanoutExchange(\"event\");\n }\n\n @Bean\n @Qualifier(\"reinitialize\")\n public Queue reInitQueue() {\n return new Queue(\"bus.\"+config.getConsumerName(),false,true,true);\n }\n\n @Bean\n public Binding topicBinding(@Qualifier(\"reinitialize\") Queue queue, FanoutExchange fanoutExchangee) {\n return BindingBuilder\n .bind(queue)\n .to(fanoutExchangee);\n }\n\n @Bean\n public MessageListener<Consumer> messageListener(RabbitTemplate rabbitTemplate,Consumer target){\n return new MessageListener<>(rabbitTemplate, target, \"engine\", config.getConsumerName());\n }\n```\n\n```text\n@Bean\n public AmqpProxyFactoryBean rerouteProxy(RabbitTemplate template) {\n AmqpProxyFactoryBean proxy = new AmqpProxyFactoryBean();\n proxy.setAmqpTemplate(template);\n proxy.setServiceInterface(ConsumerService.class);\n proxy.setRoutingKey(ConsumerService.class.getSimpleName());\n return proxy;\n }\n\n @Bean\n public Map<String,Consumer> consumerEngines( RabbitTemplate template){\n Map<String,Consumer> ret= new ConcurrentHashMap<>();\n //FIXme read from config\n List<String> lst = Arrays.asList(config.getEngines());\n lst.parallelStream().forEach(k->{\n AmqpProxyFactoryBean proxy = new AmqpProxyFactoryBean();\n template.setReceiveTimeout(400);\n template.setReplyTimeout(400);\n proxy.setAmqpTemplate(template);\n proxy.setServiceInterface(Consumer.class);\n proxy.setRoutingKey(Consumer.class.getSimpleName() + \"_\" + k);\n proxy.afterPropertiesSet();\n ret.put(k, (Consumer) proxy.getObject());\n });\n return ret;\n }\n```\n\n```text\nnull\n```\n\n========================================\n\nComments:\n- I am somehow sure that my reply does not take too long to arrive. so could you please tell me if it is the second reason how can I debug it ?\n- If you turn on DEBUG logging for the template, all reply messages will be logged. You will also see this WARN log message `logger.warn(\"Reply received after timeout for \" + messageTag)`. `messageTag` comes from the `correlationId` message property so you should see one of the DEBUG messages with the same `correlationId` property.","metadata":{"transformedAt":"2026-08-18T18:33:20.317Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":262,"estimatedTokens":3329}}1037{"id":"stack-50895900","source":"stackoverflow","questionId":50895900,"title":"Cannot send messages between several RabbitMQ exchanges","tags":["java","rabbitmq"],"text":"Title: Cannot send messages between several RabbitMQ exchanges\nTags: java, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI want to route multiple messages between several RabbitMQ exchanges. This is the routing table that I want to use:\n\n```\n// | exchange | type | routing key | queue |\n// |-----------------------------------------------------------------|\n// | processing | topic | processing.event.transaction | processing.transaction.queue |\n// | database | topic | database.event.transaction | database.transaction.queue |\n// | database | topic | database.event.api_attempts | database.api_attempts.queue |\n// | database | topic | database.event.event_logs | database.event_logs.queue |\n```\n\nI have 3 modules which I want to configure to send messages this way:\n\n```\nREST API Module -> Gateway module\nREST API Module -> Database Module\n```\n\nREST API Module configuration\n\n```\nString QUEUE_PROCESSING_TRANSACTION = \"processing.transaction.queue\";\nString QUEUE_DATABASE_TRANSACTION = \"database.transaction.queue\"; \nString QUEUE_DATABASE_API_ATTEMPT = \"database.api_attempts.queue\";\nString QUEUE_DATABASE_EVENT_LOGS = \"database.event_logs.queue\"; \nString EXCHANGE_PROCESSING = \"processing\";\nString EXCHANGE_DATABASE = \"database\"; \nString ROUTING_KEY_PROCESSING = \"processing.event.transaction\";\nString ROUTING_KEY_DATABASE = \"database.event.transaction\"; \nString ROUTING_KEY_API_ATTEMPTS = \"database.event.api_attempts\";\nString ROUTING_KEY_EVENT_LOGS = \"database.event.event_logs\";\n\nchannel = connection.createChannel();\nchannel.exchangeDeclare(EXCHANGE_PROCESSING, BuiltinExchangeType.TOPIC);\nchannel.exchangeDeclare(EXCHANGE_DATABASE, BuiltinExchangeType.TOPIC);\n\nchannel.queueDeclare(QUEUE_PROCESSING_TRANSACTION, false, false, false, null);\nchannel.queueDeclare(QUEUE_DATABASE_TRANSACTION, false, false, false, null); \nchannel.queueDeclare(QUEUE_DATABASE_API_ATTEMPT, false, false, false, null);\nchannel.queueDeclare(QUEUE_DATABASE_EVENT_LOGS, false, false, false, null);\n\nchannel.queueBind(QUEUE_PROCESSING_TRANSACTION, EXCHANGE_PROCESSING, ROUTING_KEY_PROCESSING);\nchannel.queueBind(QUEUE_DATABASE_TRANSACTION, EXCHANGE_DATABASE, ROUTING_KEY_DATABASE);\nchannel.queueBind(QUEUE_DATABASE_API_ATTEMPT, EXCHANGE_DATABASE, ROUTING_KEY_API_ATTEMPTS);\nchannel.queueBind(QUEUE_DATABASE_EVENT_LOGS, EXCHANGE_DATABASE, ROUTING_KEY_EVENT_LOGS);\n```\n\nSending Java objects to other modules:\n\n```\nTransactionsBean obj = new TransactionsBean();\nobj.setId(Long.valueOf(111222333));\nchannel.basicPublish(EXCHANGE_PROCESSING, ROUTING_KEY_PROCESSING, null, SerializationUtils.serialize(obj));\nchannel.basicPublish(EXCHANGE_DATABASE, ROUTING_KEY_DATABASE, null, SerializationUtils.serialize(obj));\n\nApiAttemptsBean obj = new ApiAttemptsBean();\nobj.setId(Long.valueOf(2332));\nchannel.basicPublish(EXCHANGE_DATABASE, ROUTING_KEY_API_ATTEMPTS, null, SerializationUtils.serialize(obj));\n\nEventLogsBean obj = new EventLogsBean();\nobj.setId(Long.valueOf(111222));\nchannel.basicPublish(EXCHANGE_DATABASE, ROUTING_KEY_EVENT_LOGS, null, SerializationUtils.serialize(obj));\n```\n\nModule Gateway configuration:\n\n```\nString QUEUE_PROCESSING_TRANSACTION = \"processing.transaction.queue\";\nString QUEUE_DATABASE_TRANSACTION = \"database.transaction.queue\"; \nString QUEUE_DATABASE_API_ATTEMPT = \"database.api_attempts.queue\";\nString QUEUE_DATABASE_EVENT_LOGS = \"database.event_logs.queue\"; \nString EXCHANGE_DATABASE = \"database\"; \nString ROUTING_KEY_DATABASE = \"database.event.transaction\"; \nString ROUTING_KEY_API_ATTEMPTS = \"database.event.api_attempts\";\nString ROUTING_KEY_EVENT_LOGS = \"database.event.event_logs\";\n\nchannel = connection.createChannel();\nchannel.exchangeDeclare(EXCHANGE_PROCESSING, BuiltinExchangeType.TOPIC);\nchannel.queueDeclare(QUEUE_PROCESSING_TRANSACTION, false, false, false, null);\nchannel.queueBind(QUEUE_PROCESSING_TRANSACTION, EXCHANGE_PROCESSING, ROUTING_KEY_PROCESSING);\n\nMap> queueToConsumer = new HashMap<>();\n queueToConsumer.put(QUEUE_DATABASE_TRANSACTION, this::process_transaction);\n queueToConsumer.put(QUEUE_DATABASE_API_ATTEMPT, this::process_api_attempt);\n queueToConsumer.put(QUEUE_DATABASE_EVENT_LOGS, this::process_event_logs);\n\n queueToConsumer.forEach((queueName, consumer) -> {\n try {\n channel.basicConsume(queueName, true, new DefaultConsumer(channel) {\n @Override\n public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,\n byte[] body) throws IOException {\n consumer.accept(body);\n }\n });\n } catch (IOException e) {\n e.printStackTrace();\n }\n });\n }\n\nprivate void process_transaction(byte[] object) {\n TransactionsBean obj = (TransactionsBean) SerializationUtils.deserialize(object);\n System.out.println(\"!!!! Received id \" + obj.getId() + \" in gateway\");\n }\n\n private void process_api_attempt(byte[] object) {\n ApiAttemptsBean obj = (ApiAttemptsBean) SerializationUtils.deserialize(object);\n System.out.println(\"!!!! Received id \" + obj.getId() + \" in gateway\");\n }\n\n private void process_event_logs(byte[] object) {\n EventLogsBean obj = (EventLogsBean) SerializationUtils.deserialize(object);\n System.out.println(\"!!!! Received id \" + obj.getId() + \" in gateway\");\n }\n```\n\nModule Database:\n\n```\nString QUEUE_PROCESSING_TRANSACTION = \"processing.transaction.queue\";\nString QUEUE_DATABASE_TRANSACTION = \"database.transaction.queue\";\nString QUEUE_DATABASE_API_ATTEMPT = \"database.api_attempts.queue\";\nString QUEUE_DATABASE_EVENT_LOGS = \"database.event_logs.queue\";\nString EXCHANGE_DATABASE = \"database\"; \nString ROUTING_KEY_PROCESSING = \"processing.event.transaction\";\nString ROUTING_KEY_DATABASE = \"database.event.transaction\"; \nString ROUTING_KEY_API_ATTEMPTS = \"database.event.api_attempts\";\nString ROUTING_KEY_EVENT_LOGS = \"database.event.event_logs\";\n\nchannel = connection.createChannel();\nchannel.exchangeDeclare(EXCHANGE_DATABASE, BuiltinExchangeType.TOPIC);\nchannel.queueDeclare(QUEUE_DATABASE_TRANSACTION, false, false, false, null); \nchannel.queueDeclare(QUEUE_DATABASE_API_ATTEMPT, false, false, false, null);\nchannel.queueDeclare(QUEUE_DATABASE_EVENT_LOGS, false, false, false, null);\nchannel.queueBind(QUEUE_DATABASE_TRANSACTION, EXCHANGE_DATABASE, ROUTING_KEY_DATABASE);\nchannel.queueBind(QUEUE_DATABASE_API_ATTEMPT, EXCHANGE_DATABASE, ROUTING_KEY_API_ATTEMPTS);\nchannel.queueBind(QUEUE_DATABASE_EVENT_LOGS, EXCHANGE_DATABASE, ROUTING_KEY_EVENT_LOGS);\n\nMap> queueToConsumer = new HashMap<>();\nqueueToConsumer.put(QUEUE_DATABASE_TRANSACTION, this::process_transaction);\nqueueToConsumer.put(QUEUE_DATABASE_API_ATTEMPT, this::process_api_attempt);\nqueueToConsumer.put(QUEUE_DATABASE_EVENT_LOGS, this::process_event_logs);\n\nqueueToConsumer.forEach((queueName, consumer) -> {\n try {\n channel.basicConsume(queueName, true, new DefaultConsumer(channel) {\n @Override\n public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,\n byte[] body) throws IOException {\n consumer.accept(body);\n }\n });\n } catch (IOException e) {\n e.printStackTrace();\n }\n });\n\nprivate void process_transaction(byte[] object) { \n TransactionsBean obj = (TransactionsBean) SerializationUtils.deserialize(object);\n System.out.println(\"!!!! Received id \" + obj.getId() + \" in database\");\n}\n\nprivate void process_api_attempt(byte[] object) {\n ApiAttemptsBean obj = (ApiAttemptsBean) SerializationUtils.deserialize(object);\n System.out.println(\"!!!! Received id \" + obj.getId() + \" in database\");\n}\n\nprivate void process_event_logs(byte[] object) {\n EventLogsBean obj = (EventLogsBean) SerializationUtils.deserialize(object);\n System.out.println(\"!!!! Received id \" + obj.getId() + \" in database\");\n}\n```\n\nBut messages are delivered not properly:\n\n```\n11:33:00,783 ERROR [com.rabbitmq.client.impl.ForgivingExceptionHandler] (pool-17-thread-6) Consumer org.database.context.ContextServer$1@6fee6ab4 (amq.ctag-arvcrYNc61cslclCTAnpDQ) method handleDelivery for channel AMQChannel(amqp://guest@127.0.0.1:5672/,1) threw an exception for channel AMQChannel(amqp://guest@127.0.0.1:5672/,1): java.lang.ClassCastException: deployment.db.war//plugin.factories.TransactionsBean cannot be cast to deployment.database.war//org.plugin.factories.EventLogsBean\n```\n\nLooks like messages are not properly routed probably because my routing table is not correct. \n\nCan you give me some guide how I can fix this issue? \n\nEDIT:\nError stack:\n\n```\n22:19:26,584 ERROR [com.rabbitmq.client.impl.ForgivingExceptionHandler] (pool-19-thread-6) Consumer org.database.context.ContextServer$1@49ee659f (amq.ctag-vjArBDtmtruIgeCMLipHGQ) method handleDelivery for channel AMQChannel(amqp://guest@127.0.0.1:5672/,1) threw an exception for channel AMQChannel(amqp://guest@127.0.0.1:5672/,1): java.lang.ClassCastException: deployment.db.war//org.plugin.database.bean.TransactionsBean cannot be cast to deployment.db.war//org.plugin.database.bean.ApiAttemptsBean\n at deployment.db.war//org.database.context.ContextServer.process_api_attempt(ContextServer.java:79)\n at deployment.db.war//org.database.context.ContextServer$1.handleDelivery(ContextServer.java:64)\n at deployment.db.war//com.rabbitmq.client.impl.ConsumerDispatcher$5.run(ConsumerDispatcher.java:149)\n at deployment.db.war//com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable.run(ConsumerWorkService.java:104)\n at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)\n at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)\n at java.base/java.lang.Thread.run(Thread.java:844)\n\n22:19:26,586 INFO [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 111) Initializing Mojarra 2.2.13.SP5 for context '/rest_api'\n22:19:26,619 INFO [stdout] (pool-21-thread-6) !!!! Received id 2332 in gateway\n22:19:26,667 ERROR [com.rabbitmq.client.impl.ForgivingExceptionHandler] (pool-19-thread-6) Consumer org.database.context.ContextServer$1@29ba98e4 (amq.ctag-RMVncG2xQn3KBJ561F9HNQ) method handleDelivery for channel AMQChannel(amqp://guest@127.0.0.1:5672/,1) threw an exception for channel AMQChannel(amqp://guest@127.0.0.1:5672/,1): java.lang.ClassCastException: deployment.db.war//org.plugin.database.bean.TransactionsBean cannot be cast to deployment.db.war//org.plugin.database.bean.EventLogsBean\n at deployment.db.war//org.database.context.ContextServer.process_event_logs(ContextServer.java:84)\n at deployment.db.war//org.database.context.ContextServer$1.handleDelivery(ContextServer.java:64)\n at deployment.db.war//com.rabbitmq.client.impl.ConsumerDispatcher$5.run(ConsumerDispatcher.java:149)\n at deployment.db.war//com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable.run(ConsumerWorkService.java:104)\n at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)\n at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)\n at java.base/java.lang.Thread.run(Thread.java:844)\n\n22:19:26,669 INFO [stdout] (pool-21-thread-6) !!!! Received id 111222 in gateway\n```\n\n========================================\n\nCode:\n```text\n// | exchange | type | routing key | queue |\n// |-----------------------------------------------------------------|\n// | processing | topic | processing.event.transaction | processing.transaction.queue |\n// | database | topic | database.event.transaction | database.transaction.queue |\n// | database | topic | database.event.api_attempts | database.api_attempts.queue |\n// | database | topic | database.event.event_logs | database.event_logs.queue |\n```\n\n```text\nREST API Module -> Gateway module\nREST API Module -> Database Module\n```\n\n```text\nString QUEUE_PROCESSING_TRANSACTION = \"processing.transaction.queue\";\nString QUEUE_DATABASE_TRANSACTION = \"database.transaction.queue\"; \nString QUEUE_DATABASE_API_ATTEMPT = \"database.api_attempts.queue\";\nString QUEUE_DATABASE_EVENT_LOGS = \"database.event_logs.queue\"; \nString EXCHANGE_PROCESSING = \"processing\";\nString EXCHANGE_DATABASE = \"database\"; \nString ROUTING_KEY_PROCESSING = \"processing.event.transaction\";\nString ROUTING_KEY_DATABASE = \"database.event.transaction\"; \nString ROUTING_KEY_API_ATTEMPTS = \"database.event.api_attempts\";\nString ROUTING_KEY_EVENT_LOGS = \"database.event.event_logs\";\n\nchannel = connection.createChannel();\nchannel.exchangeDeclare(EXCHANGE_PROCESSING, BuiltinExchangeType.TOPIC);\nchannel.exchangeDeclare(EXCHANGE_DATABASE, BuiltinExchangeType.TOPIC);\n\nchannel.queueDeclare(QUEUE_PROCESSING_TRANSACTION, false, false, false, null);\nchannel.queueDeclare(QUEUE_DATABASE_TRANSACTION, false, false, false, null); \nchannel.queueDeclare(QUEUE_DATABASE_API_ATTEMPT, false, false, false, null);\nchannel.queueDeclare(QUEUE_DATABASE_EVENT_LOGS, false, false, false, null);\n\nchannel.queueBind(QUEUE_PROCESSING_TRANSACTION, EXCHANGE_PROCESSING, ROUTING_KEY_PROCESSING);\nchannel.queueBind(QUEUE_DATABASE_TRANSACTION, EXCHANGE_DATABASE, ROUTING_KEY_DATABASE);\nchannel.queueBind(QUEUE_DATABASE_API_ATTEMPT, EXCHANGE_DATABASE, ROUTING_KEY_API_ATTEMPTS);\nchannel.queueBind(QUEUE_DATABASE_EVENT_LOGS, EXCHANGE_DATABASE, ROUTING_KEY_EVENT_LOGS);\n```\n\n```text\nTransactionsBean obj = new TransactionsBean();\nobj.setId(Long.valueOf(111222333));\nchannel.basicPublish(EXCHANGE_PROCESSING, ROUTING_KEY_PROCESSING, null, SerializationUtils.serialize(obj));\nchannel.basicPublish(EXCHANGE_DATABASE, ROUTING_KEY_DATABASE, null, SerializationUtils.serialize(obj));\n\nApiAttemptsBean obj = new ApiAttemptsBean();\nobj.setId(Long.valueOf(2332));\nchannel.basicPublish(EXCHANGE_DATABASE, ROUTING_KEY_API_ATTEMPTS, null, SerializationUtils.serialize(obj));\n\nEventLogsBean obj = new EventLogsBean();\nobj.setId(Long.valueOf(111222));\nchannel.basicPublish(EXCHANGE_DATABASE, ROUTING_KEY_EVENT_LOGS, null, SerializationUtils.serialize(obj));\n```\n\n```text\nString QUEUE_PROCESSING_TRANSACTION = \"processing.transaction.queue\";\nString QUEUE_DATABASE_TRANSACTION = \"database.transaction.queue\"; \nString QUEUE_DATABASE_API_ATTEMPT = \"database.api_attempts.queue\";\nString QUEUE_DATABASE_EVENT_LOGS = \"database.event_logs.queue\"; \nString EXCHANGE_DATABASE = \"database\"; \nString ROUTING_KEY_DATABASE = \"database.event.transaction\"; \nString ROUTING_KEY_API_ATTEMPTS = \"database.event.api_attempts\";\nString ROUTING_KEY_EVENT_LOGS = \"database.event.event_logs\";\n\nchannel = connection.createChannel();\nchannel.exchangeDeclare(EXCHANGE_PROCESSING, BuiltinExchangeType.TOPIC);\nchannel.queueDeclare(QUEUE_PROCESSING_TRANSACTION, false, false, false, null);\nchannel.queueBind(QUEUE_PROCESSING_TRANSACTION, EXCHANGE_PROCESSING, ROUTING_KEY_PROCESSING);\n\nMap<String, Consumer<byte[]>> queueToConsumer = new HashMap<>();\n queueToConsumer.put(QUEUE_DATABASE_TRANSACTION, this::process_transaction);\n queueToConsumer.put(QUEUE_DATABASE_API_ATTEMPT, this::process_api_attempt);\n queueToConsumer.put(QUEUE_DATABASE_EVENT_LOGS, this::process_event_logs);\n\n queueToConsumer.forEach((queueName, consumer) -> {\n try {\n channel.basicConsume(queueName, true, new DefaultConsumer(channel) {\n @Override\n public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,\n byte[] body) throws IOException {\n consumer.accept(body);\n }\n });\n } catch (IOException e) {\n e.printStackTrace();\n }\n });\n }\n\nprivate void process_transaction(byte[] object) {\n TransactionsBean obj = (TransactionsBean) SerializationUtils.deserialize(object);\n System.out.println(\"!!!! Received id \" + obj.getId() + \" in gateway\");\n }\n\n private void process_api_attempt(byte[] object) {\n ApiAttemptsBean obj = (ApiAttemptsBean) SerializationUtils.deserialize(object);\n System.out.println(\"!!!! Received id \" + obj.getId() + \" in gateway\");\n }\n\n private void process_event_logs(byte[] object) {\n EventLogsBean obj = (EventLogsBean) SerializationUtils.deserialize(object);\n System.out.println(\"!!!! Received id \" + obj.getId() + \" in gateway\");\n }\n```\n\n```text\nString QUEUE_PROCESSING_TRANSACTION = \"processing.transaction.queue\";\nString QUEUE_DATABASE_TRANSACTION = \"database.transaction.queue\";\nString QUEUE_DATABASE_API_ATTEMPT = \"database.api_attempts.queue\";\nString QUEUE_DATABASE_EVENT_LOGS = \"database.event_logs.queue\";\nString EXCHANGE_DATABASE = \"database\"; \nString ROUTING_KEY_PROCESSING = \"processing.event.transaction\";\nString ROUTING_KEY_DATABASE = \"database.event.transaction\"; \nString ROUTING_KEY_API_ATTEMPTS = \"database.event.api_attempts\";\nString ROUTING_KEY_EVENT_LOGS = \"database.event.event_logs\";\n\nchannel = connection.createChannel();\nchannel.exchangeDeclare(EXCHANGE_DATABASE, BuiltinExchangeType.TOPIC);\nchannel.queueDeclare(QUEUE_DATABASE_TRANSACTION, false, false, false, null); \nchannel.queueDeclare(QUEUE_DATABASE_API_ATTEMPT, false, false, false, null);\nchannel.queueDeclare(QUEUE_DATABASE_EVENT_LOGS, false, false, false, null);\nchannel.queueBind(QUEUE_DATABASE_TRANSACTION, EXCHANGE_DATABASE, ROUTING_KEY_DATABASE);\nchannel.queueBind(QUEUE_DATABASE_API_ATTEMPT, EXCHANGE_DATABASE, ROUTING_KEY_API_ATTEMPTS);\nchannel.queueBind(QUEUE_DATABASE_EVENT_LOGS, EXCHANGE_DATABASE, ROUTING_KEY_EVENT_LOGS);\n\nMap<String, Consumer<byte[]>> queueToConsumer = new HashMap<>();\nqueueToConsumer.put(QUEUE_DATABASE_TRANSACTION, this::process_transaction);\nqueueToConsumer.put(QUEUE_DATABASE_API_ATTEMPT, this::process_api_attempt);\nqueueToConsumer.put(QUEUE_DATABASE_EVENT_LOGS, this::process_event_logs);\n\nqueueToConsumer.forEach((queueName, consumer) -> {\n try {\n channel.basicConsume(queueName, true, new DefaultConsumer(channel) {\n @Override\n public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,\n byte[] body) throws IOException {\n consumer.accept(body);\n }\n });\n } catch (IOException e) {\n e.printStackTrace();\n }\n });\n\nprivate void process_transaction(byte[] object) { \n TransactionsBean obj = (TransactionsBean) SerializationUtils.deserialize(object);\n System.out.println(\"!!!! Received id \" + obj.getId() + \" in database\");\n}\n\nprivate void process_api_attempt(byte[] object) {\n ApiAttemptsBean obj = (ApiAttemptsBean) SerializationUtils.deserialize(object);\n System.out.println(\"!!!! Received id \" + obj.getId() + \" in database\");\n}\n\nprivate void process_event_logs(byte[] object) {\n EventLogsBean obj = (EventLogsBean) SerializationUtils.deserialize(object);\n System.out.println(\"!!!! Received id \" + obj.getId() + \" in database\");\n}\n```\n\n```text\n11:33:00,783 ERROR [com.rabbitmq.client.impl.ForgivingExceptionHandler] (pool-17-thread-6) Consumer org.database.context.ContextServer$1@6fee6ab4 (amq.ctag-arvcrYNc61cslclCTAnpDQ) method handleDelivery for channel AMQChannel(amqp://guest@127.0.0.1:5672/,1) threw an exception for channel AMQChannel(amqp://guest@127.0.0.1:5672/,1): java.lang.ClassCastException: deployment.db.war//plugin.factories.TransactionsBean cannot be cast to deployment.database.war//org.plugin.factories.EventLogsBean\n```\n\n```text\n22:19:26,584 ERROR [com.rabbitmq.client.impl.ForgivingExceptionHandler] (pool-19-thread-6) Consumer org.database.context.ContextServer$1@49ee659f (amq.ctag-vjArBDtmtruIgeCMLipHGQ) method handleDelivery for channel AMQChannel(amqp://guest@127.0.0.1:5672/,1) threw an exception for channel AMQChannel(amqp://guest@127.0.0.1:5672/,1): java.lang.ClassCastException: deployment.db.war//org.plugin.database.bean.TransactionsBean cannot be cast to deployment.db.war//org.plugin.database.bean.ApiAttemptsBean\n at deployment.db.war//org.database.context.ContextServer.process_api_attempt(ContextServer.java:79)\n at deployment.db.war//org.database.context.ContextServer$1.handleDelivery(ContextServer.java:64)\n at deployment.db.war//com.rabbitmq.client.impl.ConsumerDispatcher$5.run(ConsumerDispatcher.java:149)\n at deployment.db.war//com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable.run(ConsumerWorkService.java:104)\n at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)\n at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)\n at java.base/java.lang.Thread.run(Thread.java:844)\n\n22:19:26,586 INFO [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 111) Initializing Mojarra 2.2.13.SP5 for context '/rest_api'\n22:19:26,619 INFO [stdout] (pool-21-thread-6) !!!! Received id 2332 in gateway\n22:19:26,667 ERROR [com.rabbitmq.client.impl.ForgivingExceptionHandler] (pool-19-thread-6) Consumer org.database.context.ContextServer$1@29ba98e4 (amq.ctag-RMVncG2xQn3KBJ561F9HNQ) method handleDelivery for channel AMQChannel(amqp://guest@127.0.0.1:5672/,1) threw an exception for channel AMQChannel(amqp://guest@127.0.0.1:5672/,1): java.lang.ClassCastException: deployment.db.war//org.plugin.database.bean.TransactionsBean cannot be cast to deployment.db.war//org.plugin.database.bean.EventLogsBean\n at deployment.db.war//org.database.context.ContextServer.process_event_logs(ContextServer.java:84)\n at deployment.db.war//org.database.context.ContextServer$1.handleDelivery(ContextServer.java:64)\n at deployment.db.war//com.rabbitmq.client.impl.ConsumerDispatcher$5.run(ConsumerDispatcher.java:149)\n at deployment.db.war//com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable.run(ConsumerWorkService.java:104)\n at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)\n at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)\n at java.base/java.lang.Thread.run(Thread.java:844)\n\n22:19:26,669 INFO [stdout] (pool-21-thread-6) !!!! Received id 111222 in gateway\n```\n\n```text\nchannel.queueBind(QUEUE_DATABASE_TRANSACTION, EXCHANGE_DATABASE, ROUTING_KEY_DATABASE);\nchannel.queueBind(QUEUE_DATABASE_API_ATTEMPT, EXCHANGE_DATABASE, ROUTING_KEY_DATABASE);\nchannel.queueBind(QUEUE_DATABASE_EVENT_LOGS, EXCHANGE_DATABASE, ROUTING_KEY_DATABASE);\n```\n\n```text\nchannel.queueBind(QUEUE_DATABASE_TRANSACTION, EXCHANGE_DATABASE, ROUTING_KEY_DATABASE);\nchannel.queueBind(QUEUE_DATABASE_API_ATTEMPT, EXCHANGE_DATABASE, ROUTING_KEY_API_ATTEMPTS);\nchannel.queueBind(QUEUE_DATABASE_EVENT_LOGS, EXCHANGE_DATABASE, ROUTING_KEY_EVENT_LOGS);\n```\n\n```text\npublic void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {\n consumer.accept(body);\n }\n```\n\n```text\nSystem.out.println(\"!!!! Received id \" + obj.getId() + \" in database\");\n```\n\n```text\nSystem.out.println(\"process_transaction: Received id \" + obj.getId() + \" in database\");\n```\n\n```text\nModule Database\n```\n\n```text\nenvelope\n```\n\n```text\nenvelope.getExchange()\n```\n\n```text\nenvelope. getRoutingKey()\n```\n\n========================================\n\nComments:\n- Do you get any output before that message (I see you have many printlns along the way). Also, did you debug it and know in which line does it happens?\n- Yes, I get only in gateway module output. I suppose that my routing configuration is not correct.\n- Maybe you didn't add the processing event transaction in the gateway config: `Map> queueToConsumer = new HashMap<>(); queueToConsumer.put(QUEUE_DATABASE_TRANSACTION, this::process_transaction); queueToConsumer.put(QUEUE_DATABASE_API_ATTEMPT, this::process_api_attempt); queueToConsumer.put(QUEUE_DATABASE_EVENT_LOGS, this::process_event_logs);` and it piks up the first available?\n- I updated the code but this fixes some of the issues. Please see the attached stack trace.\n- The general issue is that TransactionsBean cannot be cast to ApiAttemptsBean and I can't find why the messages are not properly routed.\n- @PeterPenzov - I add some steps that should help you validate the root of this weird behaviour.\n- For example I added `System.out.println(\"?????????????? Exchange \" + envelope.getExchange() + \" Exchange \" + envelope.getExchange());` into handleDelivery. The result: ?????????????? Exchange database Exchange database\n- @PeterPenzov - it seems like a problem that should be easy to fix when you on the code, kinda hard to do that from a distance. I added more tips for debugging. I hope they will help you. can't help you more than that. Good luck (:","metadata":{"transformedAt":"2026-08-18T18:33:20.317Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":17,"totalLines":462,"estimatedTokens":6127}}1038{"id":"stack-55889630","source":"stackoverflow","questionId":55889630,"title":"Spring Boot AMQP @RabbitListener not receiving messages","tags":["java","spring-boot","junit","rabbitmq","spring-rabbit"],"text":"Title: Spring Boot AMQP @RabbitListener not receiving messages\nTags: java, spring-boot, junit, rabbitmq, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI have a Spring Boot application, and I am trying to send and receive messages via RabbitMQ.\n\n**Problem**\n\nI can send the messages successfully to the queue (i.e. I see them on the queue in the RabbitMQ Manager), however my **Receiver** does not receive the messages.\n\nI have a RESTful endpoint I call from JUnit that in turn calls the **Sender**. While this JUnit test is running the Spring context is loaded as expected, and the **Sender** is invoked that adds the messages to the queue successfully.\n\n**Question**\n\nIs there something more I need to do in order to get the **Receiver** to register so that it will listen for messages? (I suspect that because I am just running the JUnit test, it finishes before the **Receiver** can listen for messages). Is there a way to keep the test up an running so that the **Receiver** can consume the messages before it ends?\n\n**Code**\n\nSender\n\n```\n@Service\npublic class RabbitMQSender {\n\n @Autowired\n private AmqpTemplate rabbitTemplate;\n\n @Value(\"${rabbitmq.exchangename}\")\n private String exchange;\n\n @Value(\"${rabbitmq.routingkeyname}\")\n private String routingkey; \n\n public void send(String uuid) {\n rabbitTemplate.convertAndSend(exchange, routingkey, uuid);\n System.out.println(\"Send RabbitMQ (\"+exchange+\" \"+routingkey+\") msg = \" + uuid); \n }\n}\n```\n\nReceiver\n\n```\npublic class RabbitMQReceiver {\n\n @RabbitListener(queues = \"${rabbitmq.queuename}\")\n public void receive(String in) {\n System.out.println(\"Received RabbitMQ msg = \" + in); \n }\n}\n```\n\nConfiguration\n\n```\n@Configuration\npublic class RabbitMQConfig {\n\n @Value(\"${rabbitmq.queuename}\")\n String queueName;\n\n @Value(\"${rabbitmq.exchangename}\")\n String exchange;\n\n @Value(\"${rabbitmq.routingkeyname}\")\n String routingkey;\n\n @Bean\n Queue queue() {\n return new Queue(queueName, false);\n }\n\n @Bean\n DirectExchange exchange() {\n return new DirectExchange(exchange);\n }\n\n @Bean\n Binding binding(Queue queue, DirectExchange exchange) {\n return BindingBuilder.bind(queue).to(exchange).with(routingkey);\n }\n\n @Profile(\"receiver\")\n @Bean\n public RabbitMQReceiver receiver() {\n return new RabbitMQReceiver();\n }\n\n @Profile(\"sender\")\n @Bean\n public RabbitMQSender sender() {\n return new RabbitMQSender();\n }\n}\n```\n\n========================================\n\nTop Answer:\nyuo need add @Component or @Service for RabbitMQReceiver class\n\n========================================\n\nCode:\n```text\n@Service\npublic class RabbitMQSender {\n\n @Autowired\n private AmqpTemplate rabbitTemplate;\n\n @Value(\"${rabbitmq.exchangename}\")\n private String exchange;\n\n @Value(\"${rabbitmq.routingkeyname}\")\n private String routingkey; \n\n public void send(String uuid) {\n rabbitTemplate.convertAndSend(exchange, routingkey, uuid);\n System.out.println(\"Send RabbitMQ (\"+exchange+\" \"+routingkey+\") msg = \" + uuid); \n }\n}\n```\n\n```text\npublic class RabbitMQReceiver {\n\n @RabbitListener(queues = \"${rabbitmq.queuename}\")\n public void receive(String in) {\n System.out.println(\"Received RabbitMQ msg = \" + in); \n }\n}\n```\n\n```text\n@Configuration\npublic class RabbitMQConfig {\n\n @Value(\"${rabbitmq.queuename}\")\n String queueName;\n\n @Value(\"${rabbitmq.exchangename}\")\n String exchange;\n\n @Value(\"${rabbitmq.routingkeyname}\")\n String routingkey;\n\n @Bean\n Queue queue() {\n return new Queue(queueName, false);\n }\n\n @Bean\n DirectExchange exchange() {\n return new DirectExchange(exchange);\n }\n\n @Bean\n Binding binding(Queue queue, DirectExchange exchange) {\n return BindingBuilder.bind(queue).to(exchange).with(routingkey);\n }\n\n @Profile(\"receiver\")\n @Bean\n public RabbitMQReceiver receiver() {\n return new RabbitMQReceiver();\n }\n\n @Profile(\"sender\")\n @Bean\n public RabbitMQSender sender() {\n return new RabbitMQSender();\n }\n}\n```\n\n```text\n@ActivesProfiles({\"sender\", \"receiver\"})\n```\n\n```text\n@ActiveProfiles\n```\n\n========================================\n\nComments:\n- Your sender and receiver doesn't belong to the same profile ! did you run your Junit test with `@ActivesProfiles({\"sender\", \"receiver\"})` ?\n- @AbdelghaniRoussi - thank you! That works now.\n- Welcome @Richard ! I will add a response to this Q, so that other people find the solution in the response section\n- Thanks, I will mark it as the answer, so that you get the points.","metadata":{"transformedAt":"2026-08-18T18:33:20.317Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":192,"estimatedTokens":1131}}1039{"id":"stack-49364102","source":"stackoverflow","questionId":49364102,"title":"RabbitMQ or Redis exploding Celery queues with Django 2.0","tags":["python","django","redis","rabbitmq","celery"],"text":"Title: RabbitMQ or Redis exploding Celery queues with Django 2.0\nTags: python, django, redis, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI am encountering a problem with celery and Django 2. I have two running environments:\n\nProduction: requirements.txt => No Issue \n\n- amqp==2.2.2\n\n- django==1.11.6\n\n- celery==4.1.0\n\n- django-celery-beat==1.0.1\n\n- django-celery-monitor==1.1.2\n\n- kombu==4.1.0\n\n- redis==2.10.6\n\nDevelopment: requirements.txt =>Issue Present\n\n- amqp==2.2.2\n\n- django==2.0.3\n\n- celery==4.1.0\n\n- django-celery-beat==1.1.1\n\n- django-celery-monitor==1.1.2\n\n- kombu==4.1.0\n\n- redis==2.10.6\n\nThe production environment should be migrated to Django 2.0 as soon as possible.\nHowever, I can't do it without fixing this issue with Celery. My development environment is here to insure that everything is running fine before upgrading production servers.\n\n### The question\n\nWhat changed with Django 2 to make a system, which was stable with Django 1.11, unstable with exploding queue sizes, with the same effect in RabbitMQ and Redis?\n\nIf any task is not consumed, how could it be automatically deleted by Redis/RabbitMQ ? \n\n### Celery Worker is launched as followed\n\nThe exact same command is used for both environment. \n\n```\ncelery beat -A application --loglevel=info --detach \ncelery events -A application --loglevel=info --camera=django_celery_monitor.camera.Camera --frequency=2.0 --detach\ncelery worker -A application -l info --events\n```\n\n### Application Settings\n\nSince I migrate my development environment to Django 2, my RabbitMQ queues or Redis queues are litterally exploding in size and my database instances keep on scaling up. It seems like the tasks are not removed anymore from the queues. \n\nI have to manually cleanup the celery queue which contains after a few days more 250k tasks. It seems that the TTL is set to \"-1\" however I can't figure out how to set it from django.\n\nAfter a few hours, I have more than 220k tasks waiting to be processed and growing.\n\nI use the following settings: available in file settings.py\n\n**Warning:** The names used might not be the correct ones for celery, a remap has been to correctly assign the values with the file celery.py\n\n```\n# Celery Configuration\nbroker_url = \"borker_url\" # Redis or RabbitMQ, it doesn't change anything. \nbroker_use_ssl=True\n\naccept_content = ['application/json']\n\nworker_concurrency = 3\n\nresult_serializer = 'json'\nresult_expires=7*24*30*30\n\ntask_serializer = 'json'\ntask_acks_late=True # Acknoledge pool when task is over\ntask_reject_on_worker_lost=True\ntask_time_limit=90\ntask_soft_time_limit=60\ntask_always_eager = False\ntask_queues=[\n Queue(\n 'celery',\n Exchange('celery'),\n routing_key = 'celery',\n queue_arguments = {\n 'x-message-ttl': 60 * 1000 # 60 000 ms = 60 secs.\n }\n )\n]\n\nevent_queue_expires=60\nevent_queue_ttl=5\n\nbeat_scheduler = 'django_celery_beat.schedulers:DatabaseScheduler'\nbeat_max_loop_interval=10\nbeat_sync_every=1\n\nmonitors_expire_success = timedelta(hours=1)\nmonitors_expire_error = timedelta(days=3)\nmonitors_expire_pending = timedelta(days=5)\n\nbeat_schedule = {\n 'refresh_all_rss_subscribers_count': {\n 'task': 'feedcrunch.tasks.refresh_all_rss_subscribers_count',\n 'schedule': crontab(hour=0, minute=5), # Everyday at midnight + 5 mins\n 'options': {'expires': 20 * 60} # 20 minutes\n },\n 'clean_unnecessary_rss_visits': {\n 'task': 'feedcrunch.tasks.clean_unnecessary_rss_visits',\n 'schedule': crontab(hour=0, minute=20), # Everyday at midnight + 20 mins\n 'options': {'expires': 20 * 60} # 20 minutes\n },\n 'celery.backend_cleanup': {\n 'task': 'celery.backend_cleanup',\n 'schedule': crontab(minute='30'), # Every hours when minutes = 30 mins\n 'options': {'expires': 50 * 60} # 50 minutes\n },\n 'refresh_all_rss_feeds': {\n 'task': 'feedcrunch.tasks.refresh_all_rss_feeds',\n 'schedule': crontab(minute='40'), # Every hours when minutes = 40 mins\n 'options': {'expires': 30 * 60} # 30 minutes\n },\n}\n```\n\n### Worker Logs examples\n\nhttps://i.sstatic.net/nGrGU.png\n\nSome idea : Is it normal that \"expires\" and \"timelimit\" settings are set to None (see image above).\n\n========================================\n\nCode:\n```text\ncelery beat -A application --loglevel=info --detach \ncelery events -A application --loglevel=info --camera=django_celery_monitor.camera.Camera --frequency=2.0 --detach\ncelery worker -A application -l info --events\n```\n\n```text\n# Celery Configuration\nbroker_url = \"borker_url\" # Redis or RabbitMQ, it doesn't change anything. \nbroker_use_ssl=True\n\naccept_content = ['application/json']\n\nworker_concurrency = 3\n\nresult_serializer = 'json'\nresult_expires=7*24*30*30\n\ntask_serializer = 'json'\ntask_acks_late=True # Acknoledge pool when task is over\ntask_reject_on_worker_lost=True\ntask_time_limit=90\ntask_soft_time_limit=60\ntask_always_eager = False\ntask_queues=[\n Queue(\n 'celery',\n Exchange('celery'),\n routing_key = 'celery',\n queue_arguments = {\n 'x-message-ttl': 60 * 1000 # 60 000 ms = 60 secs.\n }\n )\n]\n\nevent_queue_expires=60\nevent_queue_ttl=5\n\nbeat_scheduler = 'django_celery_beat.schedulers:DatabaseScheduler'\nbeat_max_loop_interval=10\nbeat_sync_every=1\n\nmonitors_expire_success = timedelta(hours=1)\nmonitors_expire_error = timedelta(days=3)\nmonitors_expire_pending = timedelta(days=5)\n\nbeat_schedule = {\n 'refresh_all_rss_subscribers_count': {\n 'task': 'feedcrunch.tasks.refresh_all_rss_subscribers_count',\n 'schedule': crontab(hour=0, minute=5), # Everyday at midnight + 5 mins\n 'options': {'expires': 20 * 60} # 20 minutes\n },\n 'clean_unnecessary_rss_visits': {\n 'task': 'feedcrunch.tasks.clean_unnecessary_rss_visits',\n 'schedule': crontab(hour=0, minute=20), # Everyday at midnight + 20 mins\n 'options': {'expires': 20 * 60} # 20 minutes\n },\n 'celery.backend_cleanup': {\n 'task': 'celery.backend_cleanup',\n 'schedule': crontab(minute='30'), # Every hours when minutes = 30 mins\n 'options': {'expires': 50 * 60} # 50 minutes\n },\n 'refresh_all_rss_feeds': {\n 'task': 'feedcrunch.tasks.refresh_all_rss_feeds',\n 'schedule': crontab(minute='40'), # Every hours when minutes = 40 mins\n 'options': {'expires': 30 * 60} # 30 minutes\n },\n}\n```\n\n```text\ngit+https://github.com/celery/celery.git@be55de6#egg=celery\n```\n\n========================================\n\nComments:\n- Are the jobs actually getting executed?\n- @DanielRoseman, I have done an extensive checks and yes it seems like the tasks are consumed. My previous statement was incorrect. I have edited my post with logs from the workers if it can help.","metadata":{"transformedAt":"2026-08-18T18:33:20.317Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":222,"estimatedTokens":1653}}1040{"id":"stack-49841474","source":"stackoverflow","questionId":49841474,"title":"Django tasks, reminders, notifications","tags":["python","django","redis","rabbitmq","celery"],"text":"Title: Django tasks, reminders, notifications\nTags: python, django, redis, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI have a fairly simple web app in Django (Apache, Ubuntu) for keeping some meetings documentation. Meetings have their appointment time stored in database (postgres) in datetime format. Now, I'd like to have a custom reminder module that would enable to user to setup their preferred reminders. \n\nFor example:\n\nMeeting will be held at a certain date (let's say 25th of April 2018, 8:00 PM) and user should be able to setup a custom reminder (via SMS for example but the question is not about the sending texts or emails - I got this covered) to be fired up 24h before the time of meeting. \n\nIt got me thinking that this requires some kind of a permanent process browsing through the meetings table and checking if now() is the appointment time -24h and if yes then perform the reminder. \n\nI started with rabbitmq and celery but these look a bit complicated at first glance (here's one of the tutorials I found) and looks like it's not designed for what I need. \n\nSo, question is - how to setup a permanent process that would check if a set reminder time is now and if yes - perform the reminder task?\n\nEDIT: some errors after trying to the tutorial in answer. Got stuck at step 3:\n\n```\n(dj2_env) adrian@dev:~$ celery -A dj2 worker -l info\nTraceback (most recent call last):\n File \"/home/adrian/dj2_env/lib/python3.5/site-packages/celery/app/utils.py\", line 361, in find_app\n found = sym.app\nAttributeError: module 'dj2' has no attribute 'app'\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/home/adrian/dj2_env/bin/celery\", line 11, in \n sys.exit(main())\n File \"/home/adrian/dj2_env/lib/python3.5/site-packages/celery/__main__.py\", line 14, in main\n _main()\n File \"/home/adrian/dj2_env/lib/python3.5/site-packages/celery/bin/celery.py\", line 326, in main\n cmd.execute_from_commandline(argv)\n File \"/home/adrian/dj2_env/lib/python3.5/site-packages/celery/bin/celery.py\", line 488, in execute_from_commandline\n super(CeleryCommand, self).execute_from_commandline(argv)))\n File \"/home/adrian/dj2_env/lib/python3.5/site-packages/celery/bin/base.py\", line 279, in execute_from_commandline\n argv = self.setup_app_from_commandline(argv)\n File \"/home/adrian/dj2_env/lib/python3.5/site-packages/celery/bin/base.py\", line 481, in setup_app_from_commandline\n self.app = self.find_app(app)\n File \"/home/adrian/dj2_env/lib/python3.5/site-packages/celery/bin/base.py\", line 503, in find_app\n return find_app(app, symbol_by_name=self.symbol_by_name)\n File \"/home/adrian/dj2_env/lib/python3.5/site-packages/celery/app/utils.py\", line 366, in find_app\n found = sym.celery\nAttributeError: module 'dj2' has no attribute 'celery'\n```\n\nOk, got the above error figured out - it's weird however, as when I ran the worker command from dj2 (project) directory it worked 8|\n\n========================================\n\nTop Answer:\nA Celery periodic task may be the best solution for this, however a simpler alternative may be a Django custom management command running from a crontab.\n\nThe management command would automatically have access to the Django ORM and could thus perform the database check and send the reminders. You could run it from the crontab such as:\n\n```\n# Run the command every 15 minutes\n*/15 * * * * python /path/to/manage.py your_command_name\n```\n\nUsing a management command would also give you the ability to execute the reminder process manually from the command line should you ever have to.\n\n========================================\n\nCode:\n```text\n(dj2_env) adrian@dev:~$ celery -A dj2 worker -l info\nTraceback (most recent call last):\n File \"/home/adrian/dj2_env/lib/python3.5/site-packages/celery/app/utils.py\", line 361, in find_app\n found = sym.app\nAttributeError: module 'dj2' has no attribute 'app'\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/home/adrian/dj2_env/bin/celery\", line 11, in <module>\n sys.exit(main())\n File \"/home/adrian/dj2_env/lib/python3.5/site-packages/celery/__main__.py\", line 14, in main\n _main()\n File \"/home/adrian/dj2_env/lib/python3.5/site-packages/celery/bin/celery.py\", line 326, in main\n cmd.execute_from_commandline(argv)\n File \"/home/adrian/dj2_env/lib/python3.5/site-packages/celery/bin/celery.py\", line 488, in execute_from_commandline\n super(CeleryCommand, self).execute_from_commandline(argv)))\n File \"/home/adrian/dj2_env/lib/python3.5/site-packages/celery/bin/base.py\", line 279, in execute_from_commandline\n argv = self.setup_app_from_commandline(argv)\n File \"/home/adrian/dj2_env/lib/python3.5/site-packages/celery/bin/base.py\", line 481, in setup_app_from_commandline\n self.app = self.find_app(app)\n File \"/home/adrian/dj2_env/lib/python3.5/site-packages/celery/bin/base.py\", line 503, in find_app\n return find_app(app, symbol_by_name=self.symbol_by_name)\n File \"/home/adrian/dj2_env/lib/python3.5/site-packages/celery/app/utils.py\", line 366, in find_app\n found = sym.celery\nAttributeError: module 'dj2' has no attribute 'celery'\n```\n\n```text\n# Run the command every 15 minutes\n*/15 * * * * python /path/to/manage.py your_command_name\n```\n\n========================================\n\nComments:\n- The specified tutorial does not contain information about periodic tasks which is what you need.\n- I was just thinking if this is some sort of \"hard-coding\" the task? Doesn't seem to be very flexible and/or adjustable by the user, or am I wrong?\n- This is a valid solution that is simpler than needing to setup celery or rabbitmq. Less moving pieces if you just setup a crontab job that runs a python script which implements all the logic.","metadata":{"transformedAt":"2026-08-18T18:33:20.317Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":2,"totalLines":107,"estimatedTokens":1444}}1041{"id":"stack-69661696","source":"stackoverflow","questionId":69661696,"title":"How to setup Django + RabbitMQ + Celery with Docker?","tags":["django","docker","docker-compose","rabbitmq","celery"],"text":"Title: How to setup Django + RabbitMQ + Celery with Docker?\nTags: django, docker, docker-compose, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI'm trying to setup my Django app to have push notification functionality. For scheduling notifications I'm trying to use Celery, for the message broker I chose RabbitMQ. My app is running in Docker containers and I'm struggling to get the RabbitMQ to work. I get an error message `Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 111] Connection refused.` when running `docker-compose up`. Here are my `celery` and `rabbitmq3` services from my `docker-compose.yml`:\n\n```\ncelery:\n restart: always\n build:\n context: .\n command: celery -A test_celery worker -l info\n volumes:\n - .:/test_celery\n env_file:\n - ./.env\n depends_on:\n - app\n - rabbitmq3\n \nrabbitmq3:\n container_name: \"rabbitmq\"\n image: rabbitmq:3-management-alpine\n ports:\n - 5672:5672\n - 15672:15672\n```\n\nIn my `test_celery` -app I have a file called `celery.py` which contains the following:\n\n```\nimport os\nfrom celery import Celery\n\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_celery.settings')\n\napp = Celery('test_celery')\napp.config_from_object('django.conf:settings', namespace='CELERY')\napp.autodiscover_tasks()\n```\n\nAnd finally, in my `settings.py` I have this: `CELERY_BROKER_URL = 'amqp://localhost'`.\n\nShould I define the `CELERY_BROKER_URL` somehow different? Is there something wrong with my docker-compose file? Would appreciate any help with this, what is wrong with my setup?\n\n========================================\n\nTop Answer:\nIn **settings.py** define:\n\n```\nRABBITMQ = {\n \"PROTOCOL\": \"amqp\", # in prod change with \"amqps\"\n \"HOST\": os.getenv(\"RABBITMQ_HOST\", \"localhost\"),\n \"PORT\": os.getenv(\"RABBITMQ_PORT\", 5672),\n \"USER\": os.getenv(\"RABBITMQ_USER\", \"guest\"),\n \"PASSWORD\": os.getenv(\"RABBITMQ_PASSWORD\", \"guest\"),\n}\n\nCELERY_BROKER_URL = f\"{RABBITMQ['PROTOCOL']}://{RABBITMQ['USER']}:{RABBITMQ['PASSWORD']}@{RABBITMQ['HOST']}:{RABBITMQ['PORT']}\"\n```\n\n========================================\n\nCode:\n```text\ncelery:\n restart: always\n build:\n context: .\n command: celery -A test_celery worker -l info\n volumes:\n - .:/test_celery\n env_file:\n - ./.env\n depends_on:\n - app\n - rabbitmq3\n \nrabbitmq3:\n container_name: \"rabbitmq\"\n image: rabbitmq:3-management-alpine\n ports:\n - 5672:5672\n - 15672:15672\n```\n\n```text\nimport os\nfrom celery import Celery\n\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_celery.settings')\n\napp = Celery('test_celery')\napp.config_from_object('django.conf:settings', namespace='CELERY')\napp.autodiscover_tasks()\n```\n\n```text\nCannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 111] Connection refused.\n```\n\n```text\ndocker-compose up\n```\n\n```text\ncelery\n```\n\n```text\nrabbitmq3\n```\n\n```text\ndocker-compose.yml\n```\n\n```text\ntest_celery\n```\n\n```text\ncelery.py\n```\n\n```text\nsettings.py\n```\n\n```text\nCELERY_BROKER_URL = 'amqp://localhost'\n```\n\n```text\nCELERY_BROKER_URL\n```\n\n```text\nCELERY_BROKER_URL=amqp://guest:guest@rabbitmq3:5672/\n```\n\n```text\nCELERY_BROKER_URL=amqp://guest:guest@rabbitmq3:5672/vhost\n```\n\n```text\nRABBITMQ = {\n \"PROTOCOL\": \"amqp\", # in prod change with \"amqps\"\n \"HOST\": os.getenv(\"RABBITMQ_HOST\", \"localhost\"),\n \"PORT\": os.getenv(\"RABBITMQ_PORT\", 5672),\n \"USER\": os.getenv(\"RABBITMQ_USER\", \"guest\"),\n \"PASSWORD\": os.getenv(\"RABBITMQ_PASSWORD\", \"guest\"),\n}\n\nCELERY_BROKER_URL = f\"{RABBITMQ['PROTOCOL']}://{RABBITMQ['USER']}:{RABBITMQ['PASSWORD']}@{RABBITMQ['HOST']}:{RABBITMQ['PORT']}\"\n```\n\n========================================\n\nComments:\n- Also sometimes celery can try to connect to rabbitmq when rabbitmq is not ready, so I wait for celery to retry until it's connected","metadata":{"transformedAt":"2026-08-18T18:33:20.317Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":15,"totalLines":163,"estimatedTokens":936}}1042{"id":"stack-64365257","source":"stackoverflow","questionId":64365257,"title":"RabbitMQ -- list consumer names for a queue","tags":["rabbitmq","rabbitmqctl"],"text":"Title: RabbitMQ -- list consumer names for a queue\nTags: rabbitmq, rabbitmqctl\nSource: Stack Overflow\n\nQuestion:\nIs there way to list names of consumers subscribed to a queue? With \"*rabbitmqctl list_queues -p test name,consumers*\" I could get the number of consumers to a queue but not their names.\n\nI see two consumers where I expect one. I need to figure out who the other consumer is.\n\n========================================\n\nCode:\n```text\nrabbitmqctl list_consumers -p [vhost]\n```\n\n```text\nqueue_name channel_pid consumer_tag ack_required prefetch_count active arguments\ndb_weibo_users <rabbit@host> None86 true 300 true []\ndb_weibo_users <rabbit@host> None88 true 300 true []\ndb_weibo_users <rabbit@host> None85 true 300 true []\ndb_weibo_users <rabbit@host> None85 true 300 true []\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.317Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":23,"estimatedTokens":219}}1043{"id":"stack-56582336","source":"stackoverflow","questionId":56582336,"title":"Permission for sockets - android manifest","tags":["java","android","sockets","rabbitmq","connection"],"text":"Title: Permission for sockets - android manifest\nTags: java, android, sockets, rabbitmq, connection\nSource: Stack Overflow\n\nQuestion:\nI've made a simple test application for reading RabbitMQ queues using java amqp lib (`implementation 'com.rabbitmq:amqp-client:5.7.1'`).\n\nBut im having trouble when connecting to my rabbit server due to Android permissions (socket)\n\nHere is the error message:\n\n**W/System.err: java.net.SocketException: socket failed: EPERM (Operation not permitted)**\n\nI've tried, successless, to add `android.permission.INTERNET` to the manifest. Here is what it looks like:\n\n```\n\n \n\n \n \n \n \n\n \n \n \n \n\n```\n\nWhat am I missing?\n\n**Edit**\n\nAs requested, here is the full error stacktrace: https://pastebin.com/WAh2B4rP\n\nAnd the code that triggers this error:\n\n```\nConnectionFactory factory = new ConnectionFactory();\nfactory.setUsername(\"myuser\");\nfactory.setPassword(\"mypass\");\nfactory.setVirtualHost(\"/\");\nfactory.setHost(\"myhost.io\");\nfactory.setPort(5672);\n\nconnection = factory.newConnection(); //Error triggers here\nchannel = connection.createChannel();\n```\n\n========================================\n\nCode:\n```text\n<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n package=\"com.example.androidwebsocket\">\n\n <uses-permission android:name=\"android.permission.INTERNET\" />\n\n <application\n android:allowBackup=\"true\"\n android:icon=\"@mipmap/ic_launcher\"\n android:label=\"@string/app_name\"\n android:roundIcon=\"@mipmap/ic_launcher_round\"\n android:supportsRtl=\"true\"\n android:theme=\"@style/AppTheme\">\n <activity android:name=\".MainActivity\">\n <intent-filter>\n <action android:name=\"android.intent.action.MAIN\" />\n\n <category android:name=\"android.intent.category.LAUNCHER\" />\n </intent-filter>\n </activity>\n </application>\n\n</manifest>\n```\n\n```text\nConnectionFactory factory = new ConnectionFactory();\nfactory.setUsername(\"myuser\");\nfactory.setPassword(\"mypass\");\nfactory.setVirtualHost(\"/\");\nfactory.setHost(\"myhost.io\");\nfactory.setPort(5672);\n\nconnection = factory.newConnection(); //Error triggers here\nchannel = connection.createChannel();\n```\n\n```text\nimplementation 'com.rabbitmq:amqp-client:5.7.1'\n```\n\n```text\nandroid.permission.INTERNET\n```\n\n```text\n<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\" />\n```\n\n========================================\n\nComments:\n- I recommend that you edit your question and provide the full stack trace plus the code that is triggering the crash.\n- @CommonsWare done\n- Are you doing this work on a background thread?\n- @CommonsWare yes. I did use it in the ui thread at first, but that triggered another exception. (ConnectionOnMainThreadException, i think, or something like that)","metadata":{"transformedAt":"2026-08-18T18:33:20.317Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":111,"estimatedTokens":710}}1044{"id":"stack-54588341","source":"stackoverflow","questionId":54588341,"title":"How to utilize prefetch count for consumer with .NET RabbitMQ client","tags":["c#","rabbitmq","messaging"],"text":"Title: How to utilize prefetch count for consumer with .NET RabbitMQ client\nTags: c#, rabbitmq, messaging\nSource: Stack Overflow\n\nQuestion:\nIts states the following in the RabbitMQ documentatation \n\n \"As a rule of thumb, sharing Channel instances between threads is\n something to be avoided. Applications should prefer using a Channel\n per thread instead of sharing the same Channel across multiple\n threads.\"\n\nCurrently we are looking at the prefetch count where it has been recommended that if you have a small number of consumers and autoack=false, then we should consume many messages at once. However we find that the prefetch has not effect if the consumer sends manual acknowledgements back using a single thread of execution. However if we wrap the consumer processing in a Task, we find that the prefetch count does matter and substantially improves consumer performance.\n\nSee the following example where we are wrapping the consumption of the message by the consumer in a Task object:\n\n```\nclass Program\n{\n public static void Main()\n {\n var factory = new ConnectionFactory()\n {\n HostName = \"172.20.20.13\",\n UserName = \"billy\",\n Password = \"guest\",\n Port = 5671,\n VirtualHost = \"/\",\n Ssl = new SslOption\n {\n Enabled = true,\n ServerName = \"rabbit.blah.com\",\n Version = System.Security.Authentication.SslProtocols.Tls12\n }\n };\n var connection = factory.CreateConnection();\n var channel = connection.CreateModel();\n channel.BasicQos(0, 100, false);\n channel.ExchangeDeclare(exchange: \"logs\", type: \"fanout\");\n var queueName = channel.QueueDeclare().QueueName;\n Console.WriteLine(\" [*] Waiting for logs.\");\n\n var consumer = new EventingBasicConsumer(channel);\n consumer.Received += (model, ea) =>\n {\n var _result = new Task(() => {\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n System.Threading.Thread.Sleep(80);\n\n channel.BasicAck(ea.DeliveryTag, false);\n });\n _result.Start();\n };\n channel.BasicConsume(queue: \"test.queue.1\", autoAck: false, consumer: consumer);\n\n Console.WriteLine(\" Press [enter] to exit.\");\n Console.ReadLine();\n }\n}\n```\n\nThe question I have is how do people implement consumers with the .NET rabbitmq client that avail of prefetch counts?, Do you have to manual ack using a Task of some sort?, is it safe\n\n========================================\n\nTop Answer:\nSource: https://www.rabbitmq.com/api-guide.html\n\n When manual acknowledgements are used, it is important to consider\n what thread does the acknowledgement. If it's different from the\n thread that received the delivery (e.g. Consumer#handleDelivery\n delegated delivery handling to a different thread), acknowledging with\n the multiple parameter set to true is unsafe and will result in\n double-acknowledgements, and therefore a channel-level protocol\n exception that closes the channel. Acknowledging a single message at a\n time can be safe.\n\n`channel.basicAck(tag, false)` is thread safe\n\nbut `consumerChannel.basicAck(tag, true)` is not.\n\nAlso some good points mentioned at RabbitMQ and channels Java thread safety\n\n========================================\n\nCode:\n```text\nclass Program\n{\n public static void Main()\n {\n var factory = new ConnectionFactory()\n {\n HostName = \"172.20.20.13\",\n UserName = \"billy\",\n Password = \"guest\",\n Port = 5671,\n VirtualHost = \"/\",\n Ssl = new SslOption\n {\n Enabled = true,\n ServerName = \"rabbit.blah.com\",\n Version = System.Security.Authentication.SslProtocols.Tls12\n }\n };\n var connection = factory.CreateConnection();\n var channel = connection.CreateModel();\n channel.BasicQos(0, 100, false);\n channel.ExchangeDeclare(exchange: \"logs\", type: \"fanout\");\n var queueName = channel.QueueDeclare().QueueName;\n Console.WriteLine(\" [*] Waiting for logs.\");\n\n var consumer = new EventingBasicConsumer(channel);\n consumer.Received += (model, ea) =>\n {\n var _result = new Task(() => {\n var body = ea.Body;\n var message = Encoding.UTF8.GetString(body);\n System.Threading.Thread.Sleep(80);\n\n channel.BasicAck(ea.DeliveryTag, false);\n });\n _result.Start();\n };\n channel.BasicConsume(queue: \"test.queue.1\", autoAck: false, consumer: consumer);\n\n Console.WriteLine(\" Press [enter] to exit.\");\n Console.ReadLine();\n }\n}\n```\n\n```text\n5.1\n```\n\n```text\nReceived\n```\n\n```text\nchannel.BasicQos(0, 1, false)\n```\n\n```text\nBasicAck\n```\n\n```text\nReceived\n```\n\n```text\nIModel\n```\n\n```text\nBasicAck\n```\n\n```text\nchannel.basicAck(tag, false)\n```\n\n```text\nconsumerChannel.basicAck(tag, true)\n```\n\n========================================\n\nComments:\n- Personally, I hate RabbitMQ API, you find much more bugs along the way (for example even if you say in options that you need to consume one by one message it still consumes multiple messages! damn!). Better to use some message bus API like MassTransit. It hides this hilarious Channel manipulations, Queue management and connection corruptions which can lead to deadlocks. It also has support to mock rabbitmq for testing.\n- More here - stackoverflow.com/questions/12296787/…\n- @eocron - the RabbitMQ .NET client is open source, and we (the RabbitMQ team) regularly receive pull requests to fix bugs and improve the code. Rather than making claims on stack overflow, why not contribute your apparent expertise to the project?\n- @LukeBakken Is the only way to take advantage of the prefetch count performance benefits by using Tasks to send acks back?\n- That is the Java guide, and the person asking this question is using .NET. There are differences between the libraries.\n- Thanks for the response and apologies, I have updated my example to have a prefetch count equal to 100. (this was a typo)\n- Does this mean that you are recommending that we use the same thread of execution to perform BasicAck, but set multiple to true?\n- @LukeBakken \"I recommend implementing ... ensures that BasicAck is called on the same thread on which the connection is created.\" Did you mean to say on the same thread *that created the channel*, or really the thread that created the connection?","metadata":{"transformedAt":"2026-08-18T18:33:20.317Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":180,"estimatedTokens":1575}}1045{"id":"stack-25072527","source":"stackoverflow","questionId":25072527,"title":"AMQP RabbitMQ consumers blocking eachother?","tags":["c","rabbitmq","amqp","librabbitmq"],"text":"Title: AMQP RabbitMQ consumers blocking eachother?\nTags: c, rabbitmq, amqp, librabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have coded up a C (rabbitmq-c) worker app which consumes a queue published by a Python script (pika).\n\nI have the following strange behaviour which I can't seem to solve:\n\n- Starting all the workers before messages are published to the queue works as expected\n\n- Starting 1 worker after the queue has been published works as expected\n\n- HOWEVER: Starting additional workers after a worker has started consuming from the queue means that those workers don't see any messages on the queue (message count=0) and therefore just wait (eventhough there are meant to be many messages still on the queue). Killing the first worker will suddently start messages flowing to all the other (waiting) consumers.\n\nAny ideas what could be going on?\n\nI've tried making sure that each consumer has it's own channel (is this necessary?) but still the same behaviour...\n\nHere's the code for the consumer (worker):\n\n```\nconn = amqp_new_connection();\nsock = (amqp_socket_t *)(uint64_t)amqp_tcp_socket_new(conn);\namqp_socket_open(sock, \"localhost\", 5672);\namqp_login(conn,\n \"/\",\n 0,\n 131072,\n 0,\n AMQP_SASL_METHOD_PLAIN,\n \"guest\",\n \"guest\");\n\nif (amqp_channel_open(conn, chan) == NULL)\n LOG_ERR(\" [!] Failed to open amqp channel!\\n\");\n\nif ((q = amqp_queue_declare(conn,\n chan,\n amqp_cstring_bytes(\"ranges\"),\n 0,\n 0,\n 0,\n 0,\n amqp_empty_table)) == NULL)\n LOG_ERR(\" [!] Failed to declare queue!\\n\");\n\nLOG_INFO(\" [x] Queue (message count = %d)\\n\", q->message_count);\n\namqp_queue_bind(conn, chan, amqp_cstring_bytes(\"ranges\"), amqp_empty_bytes, amqp_empty_table);\namqp_basic_consume(conn, chan, amqp_cstring_bytes(\"ranges\"), amqp_empty_bytes, 0, 0, 0, amqp_empty_table);\n\nwhile(1) {\n amqp_maybe_release_buffers(conn);\n amqp_consume_message(conn, &e, NULL, 0);\n\n {\n int n;\n amqp_frame_t f;\n unsigned char buf[8];\n unsigned char *pbuf = buf;\n\n amqp_simple_wait_frame(conn, &f); // METHOD frame\n amqp_simple_wait_frame(conn, &f); // HEADER frame\n\n n = f.payload.properties.body_size;\n if (n != sizeof(range_buf))\n LOG_ERR(\" [!] Invalid message size!\");\n\n while (n) {\n amqp_simple_wait_frame(conn, &f); // BODY frame\n memcpy(pbuf,\n f.payload.body_fragment.bytes,\n f.payload.body_fragment.len);\n n -= f.payload.body_fragment.len;\n pbuf += f.payload.body_fragment.len;\n }\n\n // do something with buf\n\n LOG_INFO(\" [x] Message recevied from queue\\n\");\n }\n\n amqp_destroy_envelope(&e);\n\n amqp_maybe_release_buffers(conn);\n}\n```\n\n========================================\n\nTop Answer:\nThis might help you \n\nMessage acknowledgment\n\nDoing a task can take a few seconds. You may wonder what happens if one of the consumers starts a long task and dies with it only partly done. With our current code, once RabbitMQ delivers a message to the customer it immediately removes it from memory. In this case, if you kill a worker we will lose the message it was just processing. We'll also lose all the messages that were dispatched to this particular worker but were not yet handled.\n\nBut we don't want to lose any tasks. If a worker dies, we'd like the task to be delivered to another worker.\n\nIn order to make sure a message is never lost, RabbitMQ supports message acknowledgments. An ack(nowledgement) is sent back from the consumer to tell RabbitMQ that a particular message has been received, processed and that RabbitMQ is free to delete it.\n\nIf a consumer dies without sending an ack, RabbitMQ will understand that a message wasn't processed fully and will redeliver it to another consumer. That way you can be sure that no message is lost, even if the workers occasionally die.\n\nThere aren't any message timeouts; RabbitMQ will redeliver the message only when the worker connection dies. It's fine even if processing a message takes a very, very long time.\n\nMessage acknowledgments are turned on by default.\n\n========================================\n\nCode:\n```c\nconn = amqp_new_connection();\nsock = (amqp_socket_t *)(uint64_t)amqp_tcp_socket_new(conn);\namqp_socket_open(sock, \"localhost\", 5672);\namqp_login(conn,\n \"/\",\n 0,\n 131072,\n 0,\n AMQP_SASL_METHOD_PLAIN,\n \"guest\",\n \"guest\");\n\nif (amqp_channel_open(conn, chan) == NULL)\n LOG_ERR(\" [!] Failed to open amqp channel!\\n\");\n\nif ((q = amqp_queue_declare(conn,\n chan,\n amqp_cstring_bytes(\"ranges\"),\n 0,\n 0,\n 0,\n 0,\n amqp_empty_table)) == NULL)\n LOG_ERR(\" [!] Failed to declare queue!\\n\");\n\nLOG_INFO(\" [x] Queue (message count = %d)\\n\", q->message_count);\n\namqp_queue_bind(conn, chan, amqp_cstring_bytes(\"ranges\"), amqp_empty_bytes, amqp_empty_table);\namqp_basic_consume(conn, chan, amqp_cstring_bytes(\"ranges\"), amqp_empty_bytes, 0, 0, 0, amqp_empty_table);\n\nwhile(1) {\n amqp_maybe_release_buffers(conn);\n amqp_consume_message(conn, &e, NULL, 0);\n\n {\n int n;\n amqp_frame_t f;\n unsigned char buf[8];\n unsigned char *pbuf = buf;\n\n amqp_simple_wait_frame(conn, &f); // METHOD frame\n amqp_simple_wait_frame(conn, &f); // HEADER frame\n\n n = f.payload.properties.body_size;\n if (n != sizeof(range_buf))\n LOG_ERR(\" [!] Invalid message size!\");\n\n while (n) {\n amqp_simple_wait_frame(conn, &f); // BODY frame\n memcpy(pbuf,\n f.payload.body_fragment.bytes,\n f.payload.body_fragment.len);\n n -= f.payload.body_fragment.len;\n pbuf += f.payload.body_fragment.len;\n }\n\n // do something with buf\n\n LOG_INFO(\" [x] Message recevied from queue\\n\");\n }\n\n amqp_destroy_envelope(&e);\n\n amqp_maybe_release_buffers(conn);\n}\n```\n\n========================================\n\nComments:\n- I'm experiencing the SAME behavior using the Pika 0.9.14 client. No leads yet, unfortunately.\n- did you check `prefetch_count` ?\n- Yes, I know about eessage acknowledgement. The issue here is that the otehr workers simply don't get ANY messages delivered to them. If they inspect the queue message count it's zero but as soon as I kill the first worker, the other works suddenly start getting served messages.\n- This was exactly the problem (someone fromt he mailing list pointed it out). I used QOS to limit consumer to fetching 1 message at a time (exactly what I wanted). I also manually ack the messages.","metadata":{"transformedAt":"2026-08-18T18:33:20.318Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":186,"estimatedTokens":1644}}1046{"id":"stack-60812042","source":"stackoverflow","questionId":60812042,"title":"RabbitMQ fails to start after restart Kubernetes cluster","tags":["kubernetes","rabbitmq","kubernetes-statefulset"],"text":"Title: RabbitMQ fails to start after restart Kubernetes cluster\nTags: kubernetes, rabbitmq, kubernetes-statefulset\nSource: Stack Overflow\n\nQuestion:\nI'm running RabbitMQ on Kubernetes. This is my sts YAML file:\n\n```\napiVersion: v1\nkind: Service\nmetadata:\n name: rabbitmq-management\n labels:\n app: rabbitmq\nspec:\n ports:\n - port: 15672\n name: http\n selector:\n app: rabbitmq\n type: NodePort\n---\napiVersion: v1\nkind: Service\nmetadata:\n name: rabbitmq\n labels:\n app: rabbitmq\nspec:\n ports:\n - port: 5672\n name: amqp\n - port: 4369\n name: epmd\n - port: 25672\n name: rabbitmq-dist\n - port: 61613\n name: stomp\n clusterIP: None\n selector:\n app: rabbitmq\n---\napiVersion: apps/v1\nkind: StatefulSet\nmetadata:\n name: rabbitmq\nspec:\n serviceName: \"rabbitmq\"\n replicas: 3\n selector:\n matchLabels:\n app: rabbitmq\n template:\n metadata:\n labels:\n app: rabbitmq\n spec:\n containers:\n - name: rabbitmq\n image: rabbitmq:management-alpine\n lifecycle:\n postStart:\n exec:\n command:\n - /bin/sh\n - -c\n - >\n rabbitmq-plugins enable rabbitmq_stomp;\n if [ -z \"$(grep rabbitmq /etc/resolv.conf)\" ]; then\n sed \"s/^search \\([^ ]\\+\\)/search rabbitmq.\\1 \\1/\" /etc/resolv.conf > /etc/resolv.conf.new;\n cat /etc/resolv.conf.new > /etc/resolv.conf;\n rm /etc/resolv.conf.new;\n fi;\n until rabbitmqctl node_health_check; do sleep 1; done;\n if [[ \"$HOSTNAME\" != \"rabbitmq-0\" && -z \"$(rabbitmqctl cluster_status | grep rabbitmq-0)\" ]]; then\n rabbitmqctl stop_app;\n rabbitmqctl join_cluster rabbit@rabbitmq-0;\n rabbitmqctl start_app;\n fi;\n rabbitmqctl set_policy ha-all \".\" '{\"ha-mode\":\"exactly\",\"ha-params\":3,\"ha-sync-mode\":\"automatic\"}'\n env:\n - name: RABBITMQ_ERLANG_COOKIE\n valueFrom:\n secretKeyRef:\n name: rabbitmq-config\n key: erlang-cookie\n ports:\n - containerPort: 5672\n name: amqp\n - containerPort: 61613\n name: stomp\n volumeMounts:\n - name: rabbitmq\n mountPath: /var/lib/rabbitmq\n volumeClaimTemplates:\n - metadata:\n name: rabbitmq\n annotations:\n volume.alpha.kubernetes.io/storage-class: do-block-storage\n spec:\n accessModes: [ \"ReadWriteOnce\" ]\n resources:\n requests:\n storage: 10Gi\n```\n\nand I created the cookie with this command:\n\n```\nkubectl create secret generic rabbitmq-config --from-literal=erlang-cookie=c-is-for-cookie-thats-good-enough-for-me\n```\n\nall of my Kubernetes cluster nodes are ready:\n\n```\nkubectl get nodes\nNAME STATUS ROLES AGE VERSION\nkubernetes-master Ready master 14d v1.17.3\nkubernetes-slave-1 Ready 14d v1.17.3\nkubernetes-slave-2 Ready 14d v1.17.3\n```\n\nbut after restarting the cluster, the RabbitMQ didn't start. I tried to scale down and up the sts but the problem already exist. The output of `kubectl describe pod rabbitmq-0`:\n\n```\nkubectl describe pod rabbitmq-0\nName: rabbitmq-0\nNamespace: default\nPriority: 0\nNode: kubernetes-slave-1/192.168.0.179\nStart Time: Tue, 24 Mar 2020 22:31:04 +0000\nLabels: app=rabbitmq\n controller-revision-hash=rabbitmq-6748869f4b\n statefulset.kubernetes.io/pod-name=rabbitmq-0\nAnnotations: \nStatus: Running\nIP: 10.244.1.163\nIPs:\n IP: 10.244.1.163\nControlled By: StatefulSet/rabbitmq\nContainers:\n rabbitmq:\n Container ID: docker://d5108f818525030b4fdb548eb40f0dc000dd2cec473ebf8cead315116e3efbd3\n Image: rabbitmq:management-alpine\n Image ID: docker-pullable://rabbitmq@sha256:6f7c8d01d55147713379f5ca26e3f20eca63eb3618c263b12440b31c697ee5a5\n Ports: 5672/TCP, 61613/TCP\n Host Ports: 0/TCP, 0/TCP\n State: Waiting\n Reason: PostStartHookError: command '/bin/sh -c rabbitmq-plugins enable rabbitmq_stomp; if [ -z \"$(grep rabbitmq /etc/resolv.conf)\" ]; then\n sed \"s/^search \\([^ ]\\+\\)/search rabbitmq.\\1 \\1/\" /etc/resolv.conf > /etc/resolv.conf.new;\n cat /etc/resolv.conf.new > /etc/resolv.conf;\n rm /etc/resolv.conf.new;\nfi; until rabbitmqctl node_health_check; do sleep 1; done; if [[ \"$HOSTNAME\" != \"rabbitmq-0\" && -z \"$(rabbitmqctl cluster_status | grep rabbitmq-0)\" ]]; then\n rabbitmqctl stop_app;\n rabbitmqctl join_cluster rabbit@rabbitmq-0;\n rabbitmqctl start_app;\nfi; rabbitmqctl set_policy ha-all \".\" '{\"ha-mode\":\"exactly\",\"ha-params\":3,\"ha-sync-mode\":\"automatic\"}'\n' exited with 137: Error: unable to perform an operation on node 'rabbit@rabbitmq-0'. Please see diagnostics information and suggestions below.\n\nMost common reasons for this are:\n\n * Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)\n * CLI tool fails to authenticate with the server (e.g. due to CLI tool's Erlang cookie not matching that of the server)\n * Target node is not running\n\nIn addition to the diagnostics info below:\n\n * See the CLI, clustering and networking guides on https://rabbitmq.com/documentation.html to learn more\n * Consult server logs on node rabbit@rabbitmq-0\n * If target node is configured to use long node names, don't forget to use --longnames with CLI tools\n\nDIAGNOSTICS\n===========\n\nattempted to contact: ['rabbit@rabbitmq-0']\n\nrabbit@rabbitmq-0:\n * connected to epmd (port 4369) on rabbitmq-0\n * epmd reports: node 'rabbit' not running at all\n no other nodes on rabbitmq-0\n * suggestion: start the node\n\nCurrent node details:\n * node name: 'rabbitmqcli-575-rabbit@rabbitmq-0'\n * effective user's home directory: /var/lib/rabbitmq\n * Erlang cookie hash: P1XNOe5pN3Ug2FCRFzH7Xg==\n\nError: this command requires the 'rabbit' app to be running on the target node. Start it with 'rabbitmqctl start_app'.\nArguments given:\n node_health_check\n\nUsage\n\nrabbitmqctl [--node ] [--longnames] [--quiet] node_health_check [--timeout ]\nError:\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\"$1\", :_, :_}, [], [:\"$1\"]}]]}}\n\nDIAGNOSTICS\n===========\n\nattempted to contact: ['rabbit@rabbitmq-0']\n\nrabbit@rabbitmq-0:\n * connected to epmd (port 4369) on rabbitmq-0\n * epmd reports: node 'rabbit' not running at all\n no other nodes on rabbitmq-0\n * suggestion: start the node\n\nCurrent node details:\n * node name: 'rabbitmqcli-10397-rabbit@rabbitmq-0'\n * effective user's home directory: /var/lib/rabbitmq\n * Erlang cookie hash: P1XNOe5pN3Ug2FCRFzH7Xg==\n\n Last State: Terminated\n Reason: Completed\n Exit Code: 0\n Started: Tue, 24 Mar 2020 22:46:09 +0000\n Finished: Tue, 24 Mar 2020 22:58:28 +0000\n Ready: False\n Restart Count: 1\n Environment:\n RABBITMQ_ERLANG_COOKIE: Optional: false\n Mounts:\n /var/lib/rabbitmq from rabbitmq (rw)\n /var/run/secrets/kubernetes.io/serviceaccount from default-token-bbl9c (ro)\nConditions:\n Type Status\n Initialized True\n Ready False\n ContainersReady False\n PodScheduled True\nVolumes:\n rabbitmq:\n Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)\n ClaimName: rabbitmq-rabbitmq-0\n ReadOnly: false\n default-token-bbl9c:\n Type: Secret (a volume populated by a Secret)\n SecretName: default-token-bbl9c\n Optional: false\nQoS Class: BestEffort\nNode-Selectors: \nTolerations: node.kubernetes.io/not-ready:NoExecute for 300s\n node.kubernetes.io/unreachable:NoExecute for 300s\nEvents:\n Type Reason Age From Message\n ---- ------ ---- ---- -------\n Normal Scheduled 31m default-scheduler Successfully assigned default/rabbitmq-0 to kubernetes-slave-1\n Normal Pulled 31m kubelet, kubernetes-slave-1 Container image \"rabbitmq:management-alpine\" already present on machine\n Normal Created 31m kubelet, kubernetes-slave-1 Created container rabbitmq\n Normal Started 31m kubelet, kubernetes-slave-1 Started container rabbitmq\n Normal SandboxChanged 16m (x9 over 17m) kubelet, kubernetes-slave-1 Pod sandbox changed, it will be killed and re-created.\n Normal Pulled 3m58s (x2 over 16m) kubelet, kubernetes-slave-1 Container image \"rabbitmq:management-alpine\" already present on machine\n Warning FailedPostStartHook 3m58s kubelet, kubernetes-slave-1 Exec lifecycle hook ([/bin/sh -c rabbitmq-plugins enable rabbitmq_stomp; if [ -z \"$(grep rabbitmq /etc/resolv.conf)\" ]; then\n sed \"s/^search \\([^ ]\\+\\)/search rabbitmq.\\1 \\1/\" /etc/resolv.conf > /etc/resolv.conf.new;\n cat /etc/resolv.conf.new > /etc/resolv.conf;\n rm /etc/resolv.conf.new;\nfi; until rabbitmqctl node_health_check; do sleep 1; done; if [[ \"$HOSTNAME\" != \"rabbitmq-0\" && -z \"$(rabbitmqctl cluster_status | grep rabbitmq-0)\" ]]; then\n rabbitmqctl stop_app;\n rabbitmqctl join_cluster rabbit@rabbitmq-0;\n rabbitmqctl start_app;\nfi; rabbitmqctl set_policy ha-all \".\" '{\"ha-mode\":\"exactly\",\"ha-params\":3,\"ha-sync-mode\":\"automatic\"}'\n]) for Container \"rabbitmq\" in Pod \"rabbitmq-0_default(2e561153-a830-4d30-ab1e-71c80d10c9e9)\" failed - error: command '/bin/sh -c rabbitmq-plugins enable rabbitmq_stomp; if [ -z \"$(grep rabbitmq /etc/resolv.conf)\" ]; then\n sed \"s/^search \\([^ ]\\+\\)/search rabbitmq.\\1 \\1/\" /etc/resolv.conf > /etc/resolv.conf.new;\n cat /etc/resolv.conf.new > /etc/resolv.conf;\n rm /etc/resolv.conf.new;\nfi; until rabbitmqctl node_health_check; do sleep 1; done; if [[ \"$HOSTNAME\" != \"rabbitmq-0\" && -z \"$(rabbitmqctl cluster_status | grep rabbitmq-0)\" ]]; then\n rabbitmqctl stop_app;\n rabbitmqctl join_cluster rabbit@rabbitmq-0;\n rabbitmqctl start_app;\nfi; rabbitmqctl set_policy ha-all \".\" '{\"ha-mode\":\"exactly\",\"ha-params\":3,\"ha-sync-mode\":\"automatic\"}'\n' exited with 137: Error: unable to perform an operation on node 'rabbit@rabbitmq-0'. Please see diagnostics information and suggestions below.\n\nMost common reasons for this are:\n\n * Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)\n * CLI tool fails to authenticate with the server (e.g. due to CLI tool's Erlang cookie not matching that of the server)\n * Target node is not running\n\nIn addition to the diagnostics info below:\n\n * See the CLI, clustering and networking guides on https://rabbitmq.com/documentation.html to learn more\n * Consult server logs on node rabbit@rabbitmq-0\n * If target node is configured to use long node names, don't forget to use --longnames with CLI tools\n\nDIAGNOSTICS\n===========\n\nattempted to contact: ['rabbit@rabbitmq-0']\n\nrabbit@rabbitmq-0:\n * connected to epmd (port 4369) on rabbitmq-0\n * epmd reports: node 'rabbit' not running at all\n other nodes on rabbitmq-0: [rabbitmqprelaunch1]\n * suggestion: start the node\n\nCurrent node details:\n * node name: 'rabbitmqcli-433-rabbit@rabbitmq-0'\n * effective user's home directory: /var/lib/rabbitmq\n * Erlang cookie hash: P1XNOe5pN3Ug2FCRFzH7Xg==\n\nError: unable to perform an operation on node 'rabbit@rabbitmq-0'. Please see diagnostics information and suggestions below.\n\nMost common reasons for this are:\n\n * Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)\n * CLI tool fails to authenticate with the server (e.g. due to CLI tool's Erlang cookie not matching that of the server)\n * Target node is not running\n\nIn addition to the diagnostics info below:\n\n * See the CLI, clustering and networking guides on https://rabbitmq.com/documentation.html to learn more\n * Consult server logs on node rabbit@rabbitmq-0\n * If target node is configured to use long node names, don't forget to use --longnames with CLI tools\n\nDIAGNOSTICS\n===========\n\nattempted to contact: ['rabbit@rabbitmq-0']\n\nrabbit@rabbitmq-0:\n * connected to epmd (port 4369) on rabbitmq-0\n * epmd reports: node 'rabbit' not running at all\n no other nodes on rabbitmq-0\n * suggestion: start the node\n\nCurrent node details:\n * node name: 'rabbitmqcli-575-rabbit@rabbitmq-0'\n * effective user's home directory: /var/lib/rabbitmq\n * Erlang cookie hash: P1XNOe5pN3Ug2FCRFzH7Xg==\n\nError: this command requires the 'rabbit' app to be running on the target node. Start it with 'rabbitmqctl start_app'.\nArguments given:\n node_health_check\n\n, message: \"Enabling plugins on node rabbit@rabbitmq-0:\\nrabbitmq_stomp\\nThe following plugins have been configured:\\n rabbitmq_management\\n rabbitmq_management_agent\\n rabbitmq_stomp\\n rabbitmq_web_dispatch\\nApplying plugin configuration to rabbit@rabbitmq-0...\\nThe following plugins have been enabled:\\n rabbitmq_stomp\\n\\nset 4 plugins.\\nOffline change; changes will take effect at broker restart.\\nTimeout: 70 seconds ...\\nChecking health of node rabbit@rabbitmq-0 ...\\nTimeout: 70 seconds ...\\nChecking health of node rabbit@rabbitmq-0 ...\\nTimeout: 70 seconds ...\\nChecking health of node rabbit@rabbitmq-0 ...\\nTimeout: 70 seconds ...\\nChecking health of node rabbit@rabbitmq-0 ...\\nTimeout: 70 seconds ...\\\nError:\\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\\\"$1\\\", :_, :_}, [], [:\\\"$1\\\"]}]]}}\\nError:\\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\\\"$1\\\", :_, :_}, [], [:\\\"$1\\\"]}]]}}\\nError:\\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\\\"$1\\\", :_, :_}, [], [:\\\"$1\\\"]}]]}}\\nError:\\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\\\"$1\\\", :_, :_}, [], [:\\\"$1\\\"]}]]}}\\nError:\\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\\\"$1\\\", :_, :_}, [], [:\\\"$1\\\"]}]]}}\\nError:\\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\\\"$1\\\", :_, :_}, [], [:\\\"$1\\\"]}]]}}\\nError:\\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\\\"$1\\\", :_, :_}, [], [:\\\"$1\\\"]}]]}}\\nError:\\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\\\"$1\\\", :_, :_}, [], [:\\\"$1\\\"]}]]}}\\nError:\\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\\\"$1\\\", :_, :_}, [], [:\\\"$1\\\"]}]]}}\\nError:\\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\\\"$1\\\", :_, :_}, [], [:\\\"$1\\\"]}]]}}\\nError: unable to perform an operation on node 'rabbit@rabbitmq-0'. Please see diagnostics information and suggestions below.\\n\\nMost common reasons for this are:\\n\\n * Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)\\n * CLI tool fails to authenticate with the server (e.g. due to CLI tool's Erlang cookie not matching that of the server)\\n * Target node is not running\\n\\nIn addition to the diagnostics info below:\\n\\n * See the CLI, clustering and networking guides on https://rabbitmq.com/documentation.html to learn more\\n * Consult server logs on node rabbit@rabbitmq-0\\n * If target node is configured to use long node names, don't forget to use --longnames with CLI tools\\n\\nDIAGNOSTICS\\n===========\\n\\nattempted to contact: ['rabbit@rabbitmq-0']\\n\\nrabbit@rabbitmq-0:\\n * connected to epmd (port 4369) on rabbitmq-0\\n * epmd reports: node 'rabbit' not running at all\\n no other nodes on rabbitmq-0\\n * suggestion: start the node\\n\\nCurrent node details:\\n * node name: 'rabbitmqcli-10397-rabbit@rabbitmq-0'\\n * effective user's home directory: /var/lib/rabbitmq\\n * Erlang cookie hash: P1XNOe5pN3Ug2FCRFzH7Xg==\\n\\n\"\n Normal Killing 3m58s kubelet, kubernetes-slave-1 FailedPostStartHook\n Normal Created 3m57s (x2 over 16m) kubelet, kubernetes-slave-1 Created container rabbitmq\n Normal Started 3m57s (x2 over 16m) kubelet, kubernetes-slave-1 Started container rabbitmq\n```\n\nThe output of `kubectl get sts`:\n\n```\nkubectl get sts\nNAME READY AGE\nconsul 3/3 15d\nhazelcast 2/3 15d\nkafka 2/3 15d\nrabbitmq 0/3 13d\nzk 3/3 15d\n```\n\nand this is pod log that I copied from Kubernetes dashboard:\n\n```\n2020-03-24 22:58:41.402 [info] Feature flags: list of feature flags found:\n2020-03-24 22:58:41.402 [info] Feature flags: [x] drop_unroutable_metric\n2020-03-24 22:58:41.402 [info] Feature flags: [x] empty_basic_get_metric\n2020-03-24 22:58:41.402 [info] Feature flags: [x] implicit_default_bindings\n2020-03-24 22:58:41.402 [info] Feature flags: [x] quorum_queue\n2020-03-24 22:58:41.402 [info] Feature flags: [x] virtual_host_metadata\n2020-03-24 22:58:41.402 [info] Feature flags: feature flag states written to disk: yes\n2020-03-24 22:58:43.979 [info] ra: meta data store initialised. 0 record(s) recovered\n2020-03-24 22:58:43.980 [info] WAL: recovering [\"/var/lib/rabbitmq/mnesia/rabbit@rabbitmq-0/quorum/rabbit@rabbitmq-0/00000262.wal\"]\n2020-03-24 22:58:43.982 [info] \n Starting RabbitMQ 3.8.2 on Erlang 22.2.8\n Copyright (c) 2007-2019 Pivotal Software, Inc.\n Licensed under the MPL 1.1. Website: https://rabbitmq.com\n\n ## ## RabbitMQ 3.8.2\n ## ##\n ########## Copyright (c) 2007-2019 Pivotal Software, Inc.\n ###### ##\n ########## Licensed under the MPL 1.1. Website: https://rabbitmq.com\n\n Doc guides: https://rabbitmq.com/documentation.html\n Support: https://rabbitmq.com/contact.html\n Tutorials: https://rabbitmq.com/getstarted.html\n Monitoring: https://rabbitmq.com/monitoring.html\n\n Logs: \n\n Config file(s): /etc/rabbitmq/rabbitmq.conf\n\n Starting broker...2020-03-24 22:58:43.983 [info] \n node : rabbit@rabbitmq-0\n home dir : /var/lib/rabbitmq\n config file(s) : /etc/rabbitmq/rabbitmq.conf\n cookie hash : P1XNOe5pN3Ug2FCRFzH7Xg==\n log(s) : \n database dir : /var/lib/rabbitmq/mnesia/rabbit@rabbitmq-0\n2020-03-24 22:58:43.997 [info] Running boot step pre_boot defined by app rabbit\n2020-03-24 22:58:43.997 [info] Running boot step rabbit_core_metrics defined by app rabbit\n2020-03-24 22:58:43.998 [info] Running boot step rabbit_alarm defined by app rabbit\n2020-03-24 22:58:44.002 [info] Memory high watermark set to 1200 MiB (1258889216 bytes) of 3001 MiB (3147223040 bytes) total\n2020-03-24 22:58:44.014 [info] Enabling free disk space monitoring\n2020-03-24 22:58:44.014 [info] Disk free limit set to 50MB\n2020-03-24 22:58:44.018 [info] Running boot step code_server_cache defined by app rabbit\n2020-03-24 22:58:44.018 [info] Running boot step file_handle_cache defined by app rabbit\n2020-03-24 22:58:44.019 [info] Limiting to approx 1048479 file handles (943629 sockets)\n2020-03-24 22:58:44.019 [info] FHC read buffering: OFF\n2020-03-24 22:58:44.019 [info] FHC write buffering: ON\n2020-03-24 22:58:44.020 [info] Running boot step worker_pool defined by app rabbit\n2020-03-24 22:58:44.021 [info] Will use 2 processes for default worker pool\n2020-03-24 22:58:44.021 [info] Starting worker pool 'worker_pool' with 2 processes in it\n2020-03-24 22:58:44.021 [info] Running boot step database defined by app rabbit\n2020-03-24 22:58:44.041 [info] Waiting for Mnesia tables for 30000 ms, 9 retries left\n2020-03-24 22:59:14.042 [warning] Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_durable_queue]}\n2020-03-24 22:59:14.042 [info] Waiting for Mnesia tables for 30000 ms, 8 retries left\n2020-03-24 22:59:44.043 [warning] Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_durable_queue]}\n2020-03-24 22:59:44.043 [info] Waiting for Mnesia tables for 30000 ms, 7 retries left\n2020-03-24 23:00:14.044 [warning] Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_durable_queue]}\n2020-03-24 23:00:14.044 [info] Waiting for Mnesia tables for 30000 ms, 6 retries left\n2020-03-24 23:00:44.045 [warning] Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_durable_queue]}\n2020-03-24 23:00:44.045 [info] Waiting for Mnesia tables for 30000 ms, 5 retries left\n2020-03-24 23:01:14.046 [warning] Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_durable_queue]}\n2020-03-24 23:01:14.046 [info] Waiting for Mnesia tables for 30000 ms, 4 retries left\n2020-03-24 23:01:44.047 [warning] Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_durable_queue]}\n2020-03-24 23:01:44.047 [info] Waiting for Mnesia tables for 30000 ms, 3 retries left\n2020-03-24 23:02:14.048 [warning] Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_durable_queue]}\n2020-03-24 23:02:14.048 [info] Waiting for Mnesia tables for 30000 ms, 2 retries left\n2020-03-24 23:02:44.049 [warning] Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_durable_queue]}\n2020-03-24 23:02:44.049 [info] Waiting for Mnesia tables for 30000 ms, 1 retries left\n2020-03-24 23:03:14.050 [warning] Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_durable_queue]}\n2020-03-24 23:03:14.050 [info] Waiting for Mnesia tables for 30000 ms, 0 retries left\n2020-03-24 23:03:44.051 [error] Feature flag `quorum_queue`: migration function crashed: {error,{timeout_waiting_for_tables,[rabbit_durable_queue]}}\n[{rabbit_table,wait,3,[{file,\"src/rabbit_table.erl\"},{line,117}]},{rabbit_core_ff,quorum_queue_migration,3,[{file,\"src/rabbit_core_ff.erl\"},{line,60}]},{rabbit_feature_flags,run_migration_fun,3,[{file,\"src/rabbit_feature_flags.erl\"},{line,1486}]},{rabbit_feature_flags,'-verify_which_feature_flags_are_actually_enabled/0-fun-2-',3,[{file,\"src/rabbit_feature_flags.erl\"},{line,2128}]},{maps,fold_1,3,[{file,\"maps.erl\"},{line,232}]},{rabbit_feature_flags,verify_which_feature_flags_are_actually_enabled,0,[{file,\"src/rabbit_feature_flags.erl\"},{line,2126}]},{rabbit_feature_flags,sync_feature_flags_with_cluster,3,[{file,\"src/rabbit_feature_flags.erl\"},{line,1947}]},{rabbit_mnesia,ensure_feature_flags_are_in_sync,2,[{file,\"src/rabbit_mnesia.erl\"},{line,631}]}]\n2020-03-24 23:03:44.051 [info] Waiting for Mnesia tables for 30000 ms, 9 retries left\n2020-03-24 23:04:14.052 [warning] Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]}\n2020-03-24 23:04:14.052 [info] Waiting for Mnesia tables for 30000 ms, 8 retries left\n2020-03-24 23:04:44.053 [warning] Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]}\n2020-03-24 23:04:44.053 [info] Waiting for Mnesia tables for 30000 ms, 7 retries left\n2020-03-24 23:05:14.055 [warning] Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]}\n2020-03-24 23:05:14.055 [info] Waiting for Mnesia tables for 30000 ms, 6 retries left\n2020-03-24 23:05:44.056 [warning] Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]}\n2020-03-24 23:05:44.056 [info] Waiting for Mnesia tables for 30000 ms, 5 retries left\n2020-03-24 23:06:14.057 [warning] Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]}\n2020-03-24 23:06:14.057 [info] Waiting for Mnesia tables for 30000 ms, 4 retries left\n2020-03-24 23:06:44.058 [warning] Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]}\n2020-03-24 23:06:44.058 [info] Waiting for Mnesia tables for 30000 ms, 3 retries left\n2020-03-24 23:07:14.059 [warning] Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]}\n2020-03-24 23:07:14.059 [info] Waiting for Mnesia tables for 30000 ms, 2 retries left\n2020-03-24 23:07:44.060 [warning] Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]}\n2020-03-24 23:07:44.060 [info] Waiting for Mnesia tables for 30000 ms, 1 retries left\n2020-03-24 23:08:14.061 [warning] Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]}\n2020-03-24 23:08:14.061 [info] Waiting for Mnesia tables for 30000 ms, 0 retries left\n2020-03-24 23:08:44.062 [error] CRASH REPORT Process with 0 neighbours exited with reason: {{timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]},{rabbit,start,[normal,[]]}} in application_master:init/4 line 138\n2020-03-24 23:08:44.063 [info] Application rabbit exited with reason: {{timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]},{rabbit,start,[normal,[]]}}\n{\"Kernel pid terminated\",application_controller,\"{application_start_failure,rabbit,{{timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]},{rabbit,start,[normal,[]]}}}\"}\nKernel pid terminated (application_controller) ({application_start_failure,rabbit,{{timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_r\n\nCrash dump is being written to: /var/log/rabbitmq/erl_crash.dump...done\n```\n\n========================================\n\nTop Answer:\nTo complete @Vincent Gerris answer, I strongly recommend you to use the Bitnami rabbitMQ Docker image.\n\nThey have included an env variable called `RABBITMQ_FORCE_BOOT`:\n\nhttps://github.com/bitnami/bitnami-docker-rabbitmq/blob/2c38682053dd9b3e88ab1fb305355d2ce88c2ccb/3.9/debian-10/rootfs/opt/bitnami/scripts/librabbitmq.sh#L760\n\n```\nif is_boolean_yes \"$RABBITMQ_FORCE_BOOT\" && ! is_dir_empty \"${RABBITMQ_DATA_DIR}/${RABBITMQ_NODE_NAME}\"; then\n # ref: https://www.rabbitmq.com/rabbitmqctl.8.html#force_boot\n warn \"Forcing node to start...\"\n debug_execute \"${RABBITMQ_BIN_DIR}/rabbitmqctl\" force_boot\n fi\n```\n\nthis will force boot the node at entrypoint.\n\n========================================\n\nCode:\n```text\napiVersion: v1\nkind: Service\nmetadata:\n name: rabbitmq-management\n labels:\n app: rabbitmq\nspec:\n ports:\n - port: 15672\n name: http\n selector:\n app: rabbitmq\n type: NodePort\n---\napiVersion: v1\nkind: Service\nmetadata:\n name: rabbitmq\n labels:\n app: rabbitmq\nspec:\n ports:\n - port: 5672\n name: amqp\n - port: 4369\n name: epmd\n - port: 25672\n name: rabbitmq-dist\n - port: 61613\n name: stomp\n clusterIP: None\n selector:\n app: rabbitmq\n---\napiVersion: apps/v1\nkind: StatefulSet\nmetadata:\n name: rabbitmq\nspec:\n serviceName: \"rabbitmq\"\n replicas: 3\n selector:\n matchLabels:\n app: rabbitmq\n template:\n metadata:\n labels:\n app: rabbitmq\n spec:\n containers:\n - name: rabbitmq\n image: rabbitmq:management-alpine\n lifecycle:\n postStart:\n exec:\n command:\n - /bin/sh\n - -c\n - >\n rabbitmq-plugins enable rabbitmq_stomp;\n if [ -z \"$(grep rabbitmq /etc/resolv.conf)\" ]; then\n sed \"s/^search \\([^ ]\\+\\)/search rabbitmq.\\1 \\1/\" /etc/resolv.conf > /etc/resolv.conf.new;\n cat /etc/resolv.conf.new > /etc/resolv.conf;\n rm /etc/resolv.conf.new;\n fi;\n until rabbitmqctl node_health_check; do sleep 1; done;\n if [[ \"$HOSTNAME\" != \"rabbitmq-0\" && -z \"$(rabbitmqctl cluster_status | grep rabbitmq-0)\" ]]; then\n rabbitmqctl stop_app;\n rabbitmqctl join_cluster rabbit@rabbitmq-0;\n rabbitmqctl start_app;\n fi;\n rabbitmqctl set_policy ha-all \".\" '{\"ha-mode\":\"exactly\",\"ha-params\":3,\"ha-sync-mode\":\"automatic\"}'\n env:\n - name: RABBITMQ_ERLANG_COOKIE\n valueFrom:\n secretKeyRef:\n name: rabbitmq-config\n key: erlang-cookie\n ports:\n - containerPort: 5672\n name: amqp\n - containerPort: 61613\n name: stomp\n volumeMounts:\n - name: rabbitmq\n mountPath: /var/lib/rabbitmq\n volumeClaimTemplates:\n - metadata:\n name: rabbitmq\n annotations:\n volume.alpha.kubernetes.io/storage-class: do-block-storage\n spec:\n accessModes: [ \"ReadWriteOnce\" ]\n resources:\n requests:\n storage: 10Gi\n```\n\n```text\nkubectl create secret generic rabbitmq-config --from-literal=erlang-cookie=c-is-for-cookie-thats-good-enough-for-me\n```\n\n```text\nkubectl get nodes\nNAME STATUS ROLES AGE VERSION\nkubernetes-master Ready master 14d v1.17.3\nkubernetes-slave-1 Ready <none> 14d v1.17.3\nkubernetes-slave-2 Ready <none> 14d v1.17.3\n```\n\n```text\nkubectl describe pod rabbitmq-0\nName: rabbitmq-0\nNamespace: default\nPriority: 0\nNode: kubernetes-slave-1/192.168.0.179\nStart Time: Tue, 24 Mar 2020 22:31:04 +0000\nLabels: app=rabbitmq\n controller-revision-hash=rabbitmq-6748869f4b\n statefulset.kubernetes.io/pod-name=rabbitmq-0\nAnnotations: <none>\nStatus: Running\nIP: 10.244.1.163\nIPs:\n IP: 10.244.1.163\nControlled By: StatefulSet/rabbitmq\nContainers:\n rabbitmq:\n Container ID: docker://d5108f818525030b4fdb548eb40f0dc000dd2cec473ebf8cead315116e3efbd3\n Image: rabbitmq:management-alpine\n Image ID: docker-pullable://rabbitmq@sha256:6f7c8d01d55147713379f5ca26e3f20eca63eb3618c263b12440b31c697ee5a5\n Ports: 5672/TCP, 61613/TCP\n Host Ports: 0/TCP, 0/TCP\n State: Waiting\n Reason: PostStartHookError: command '/bin/sh -c rabbitmq-plugins enable rabbitmq_stomp; if [ -z \"$(grep rabbitmq /etc/resolv.conf)\" ]; then\n sed \"s/^search \\([^ ]\\+\\)/search rabbitmq.\\1 \\1/\" /etc/resolv.conf > /etc/resolv.conf.new;\n cat /etc/resolv.conf.new > /etc/resolv.conf;\n rm /etc/resolv.conf.new;\nfi; until rabbitmqctl node_health_check; do sleep 1; done; if [[ \"$HOSTNAME\" != \"rabbitmq-0\" && -z \"$(rabbitmqctl cluster_status | grep rabbitmq-0)\" ]]; then\n rabbitmqctl stop_app;\n rabbitmqctl join_cluster rabbit@rabbitmq-0;\n rabbitmqctl start_app;\nfi; rabbitmqctl set_policy ha-all \".\" '{\"ha-mode\":\"exactly\",\"ha-params\":3,\"ha-sync-mode\":\"automatic\"}'\n' exited with 137: Error: unable to perform an operation on node 'rabbit@rabbitmq-0'. Please see diagnostics information and suggestions below.\n\nMost common reasons for this are:\n\n * Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)\n * CLI tool fails to authenticate with the server (e.g. due to CLI tool's Erlang cookie not matching that of the server)\n * Target node is not running\n\nIn addition to the diagnostics info below:\n\n * See the CLI, clustering and networking guides on https://rabbitmq.com/documentation.html to learn more\n * Consult server logs on node rabbit@rabbitmq-0\n * If target node is configured to use long node names, don't forget to use --longnames with CLI tools\n\n\nDIAGNOSTICS\n===========\n\nattempted to contact: ['rabbit@rabbitmq-0']\n\nrabbit@rabbitmq-0:\n * connected to epmd (port 4369) on rabbitmq-0\n * epmd reports: node 'rabbit' not running at all\n no other nodes on rabbitmq-0\n * suggestion: start the node\n\nCurrent node details:\n * node name: 'rabbitmqcli-575-rabbit@rabbitmq-0'\n * effective user's home directory: /var/lib/rabbitmq\n * Erlang cookie hash: P1XNOe5pN3Ug2FCRFzH7Xg==\n\nError: this command requires the 'rabbit' app to be running on the target node. Start it with 'rabbitmqctl start_app'.\nArguments given:\n node_health_check\n\nUsage\n\nrabbitmqctl [--node <node>] [--longnames] [--quiet] node_health_check [--timeout <timeout>]\nError:\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\"$1\", :_, :_}, [], [:\"$1\"]}]]}}\n\nDIAGNOSTICS\n===========\n\nattempted to contact: ['rabbit@rabbitmq-0']\n\nrabbit@rabbitmq-0:\n * connected to epmd (port 4369) on rabbitmq-0\n * epmd reports: node 'rabbit' not running at all\n no other nodes on rabbitmq-0\n * suggestion: start the node\n\nCurrent node details:\n * node name: 'rabbitmqcli-10397-rabbit@rabbitmq-0'\n * effective user's home directory: /var/lib/rabbitmq\n * Erlang cookie hash: P1XNOe5pN3Ug2FCRFzH7Xg==\n\n\n Last State: Terminated\n Reason: Completed\n Exit Code: 0\n Started: Tue, 24 Mar 2020 22:46:09 +0000\n Finished: Tue, 24 Mar 2020 22:58:28 +0000\n Ready: False\n Restart Count: 1\n Environment:\n RABBITMQ_ERLANG_COOKIE: <set to the key 'erlang-cookie' in secret 'rabbitmq-config'> Optional: false\n Mounts:\n /var/lib/rabbitmq from rabbitmq (rw)\n /var/run/secrets/kubernetes.io/serviceaccount from default-token-bbl9c (ro)\nConditions:\n Type Status\n Initialized True\n Ready False\n ContainersReady False\n PodScheduled True\nVolumes:\n rabbitmq:\n Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)\n ClaimName: rabbitmq-rabbitmq-0\n ReadOnly: false\n default-token-bbl9c:\n Type: Secret (a volume populated by a Secret)\n SecretName: default-token-bbl9c\n Optional: false\nQoS Class: BestEffort\nNode-Selectors: <none>\nTolerations: node.kubernetes.io/not-ready:NoExecute for 300s\n node.kubernetes.io/unreachable:NoExecute for 300s\nEvents:\n Type Reason Age From Message\n ---- ------ ---- ---- -------\n Normal Scheduled 31m default-scheduler Successfully assigned default/rabbitmq-0 to kubernetes-slave-1\n Normal Pulled 31m kubelet, kubernetes-slave-1 Container image \"rabbitmq:management-alpine\" already present on machine\n Normal Created 31m kubelet, kubernetes-slave-1 Created container rabbitmq\n Normal Started 31m kubelet, kubernetes-slave-1 Started container rabbitmq\n Normal SandboxChanged 16m (x9 over 17m) kubelet, kubernetes-slave-1 Pod sandbox changed, it will be killed and re-created.\n Normal Pulled 3m58s (x2 over 16m) kubelet, kubernetes-slave-1 Container image \"rabbitmq:management-alpine\" already present on machine\n Warning FailedPostStartHook 3m58s kubelet, kubernetes-slave-1 Exec lifecycle hook ([/bin/sh -c rabbitmq-plugins enable rabbitmq_stomp; if [ -z \"$(grep rabbitmq /etc/resolv.conf)\" ]; then\n sed \"s/^search \\([^ ]\\+\\)/search rabbitmq.\\1 \\1/\" /etc/resolv.conf > /etc/resolv.conf.new;\n cat /etc/resolv.conf.new > /etc/resolv.conf;\n rm /etc/resolv.conf.new;\nfi; until rabbitmqctl node_health_check; do sleep 1; done; if [[ \"$HOSTNAME\" != \"rabbitmq-0\" && -z \"$(rabbitmqctl cluster_status | grep rabbitmq-0)\" ]]; then\n rabbitmqctl stop_app;\n rabbitmqctl join_cluster rabbit@rabbitmq-0;\n rabbitmqctl start_app;\nfi; rabbitmqctl set_policy ha-all \".\" '{\"ha-mode\":\"exactly\",\"ha-params\":3,\"ha-sync-mode\":\"automatic\"}'\n]) for Container \"rabbitmq\" in Pod \"rabbitmq-0_default(2e561153-a830-4d30-ab1e-71c80d10c9e9)\" failed - error: command '/bin/sh -c rabbitmq-plugins enable rabbitmq_stomp; if [ -z \"$(grep rabbitmq /etc/resolv.conf)\" ]; then\n sed \"s/^search \\([^ ]\\+\\)/search rabbitmq.\\1 \\1/\" /etc/resolv.conf > /etc/resolv.conf.new;\n cat /etc/resolv.conf.new > /etc/resolv.conf;\n rm /etc/resolv.conf.new;\nfi; until rabbitmqctl node_health_check; do sleep 1; done; if [[ \"$HOSTNAME\" != \"rabbitmq-0\" && -z \"$(rabbitmqctl cluster_status | grep rabbitmq-0)\" ]]; then\n rabbitmqctl stop_app;\n rabbitmqctl join_cluster rabbit@rabbitmq-0;\n rabbitmqctl start_app;\nfi; rabbitmqctl set_policy ha-all \".\" '{\"ha-mode\":\"exactly\",\"ha-params\":3,\"ha-sync-mode\":\"automatic\"}'\n' exited with 137: Error: unable to perform an operation on node 'rabbit@rabbitmq-0'. Please see diagnostics information and suggestions below.\n\nMost common reasons for this are:\n\n * Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)\n * CLI tool fails to authenticate with the server (e.g. due to CLI tool's Erlang cookie not matching that of the server)\n * Target node is not running\n\nIn addition to the diagnostics info below:\n\n * See the CLI, clustering and networking guides on https://rabbitmq.com/documentation.html to learn more\n * Consult server logs on node rabbit@rabbitmq-0\n * If target node is configured to use long node names, don't forget to use --longnames with CLI tools\n\nDIAGNOSTICS\n===========\n\nattempted to contact: ['rabbit@rabbitmq-0']\n\nrabbit@rabbitmq-0:\n * connected to epmd (port 4369) on rabbitmq-0\n * epmd reports: node 'rabbit' not running at all\n other nodes on rabbitmq-0: [rabbitmqprelaunch1]\n * suggestion: start the node\n\nCurrent node details:\n * node name: 'rabbitmqcli-433-rabbit@rabbitmq-0'\n * effective user's home directory: /var/lib/rabbitmq\n * Erlang cookie hash: P1XNOe5pN3Ug2FCRFzH7Xg==\n\nError: unable to perform an operation on node 'rabbit@rabbitmq-0'. Please see diagnostics information and suggestions below.\n\nMost common reasons for this are:\n\n * Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)\n * CLI tool fails to authenticate with the server (e.g. due to CLI tool's Erlang cookie not matching that of the server)\n * Target node is not running\n\nIn addition to the diagnostics info below:\n\n * See the CLI, clustering and networking guides on https://rabbitmq.com/documentation.html to learn more\n * Consult server logs on node rabbit@rabbitmq-0\n * If target node is configured to use long node names, don't forget to use --longnames with CLI tools\n\nDIAGNOSTICS\n===========\n\nattempted to contact: ['rabbit@rabbitmq-0']\n\nrabbit@rabbitmq-0:\n * connected to epmd (port 4369) on rabbitmq-0\n * epmd reports: node 'rabbit' not running at all\n no other nodes on rabbitmq-0\n * suggestion: start the node\n\nCurrent node details:\n * node name: 'rabbitmqcli-575-rabbit@rabbitmq-0'\n * effective user's home directory: /var/lib/rabbitmq\n * Erlang cookie hash: P1XNOe5pN3Ug2FCRFzH7Xg==\n\nError: this command requires the 'rabbit' app to be running on the target node. Start it with 'rabbitmqctl start_app'.\nArguments given:\n node_health_check\n\n, message: \"Enabling plugins on node rabbit@rabbitmq-0:\\nrabbitmq_stomp\\nThe following plugins have been configured:\\n rabbitmq_management\\n rabbitmq_management_agent\\n rabbitmq_stomp\\n rabbitmq_web_dispatch\\nApplying plugin configuration to rabbit@rabbitmq-0...\\nThe following plugins have been enabled:\\n rabbitmq_stomp\\n\\nset 4 plugins.\\nOffline change; changes will take effect at broker restart.\\nTimeout: 70 seconds ...\\nChecking health of node rabbit@rabbitmq-0 ...\\nTimeout: 70 seconds ...\\nChecking health of node rabbit@rabbitmq-0 ...\\nTimeout: 70 seconds ...\\nChecking health of node rabbit@rabbitmq-0 ...\\nTimeout: 70 seconds ...\\nChecking health of node rabbit@rabbitmq-0 ...\\nTimeout: 70 seconds ...\\\nError:\\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\\\"$1\\\", :_, :_}, [], [:\\\"$1\\\"]}]]}}\\nError:\\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\\\"$1\\\", :_, :_}, [], [:\\\"$1\\\"]}]]}}\\nError:\\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\\\"$1\\\", :_, :_}, [], [:\\\"$1\\\"]}]]}}\\nError:\\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\\\"$1\\\", :_, :_}, [], [:\\\"$1\\\"]}]]}}\\nError:\\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\\\"$1\\\", :_, :_}, [], [:\\\"$1\\\"]}]]}}\\nError:\\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\\\"$1\\\", :_, :_}, [], [:\\\"$1\\\"]}]]}}\\nError:\\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\\\"$1\\\", :_, :_}, [], [:\\\"$1\\\"]}]]}}\\nError:\\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\\\"$1\\\", :_, :_}, [], [:\\\"$1\\\"]}]]}}\\nError:\\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\\\"$1\\\", :_, :_}, [], [:\\\"$1\\\"]}]]}}\\nError:\\n{:aborted, {:no_exists, [:rabbit_vhost, [{{:vhost, :\\\"$1\\\", :_, :_}, [], [:\\\"$1\\\"]}]]}}\\nError: unable to perform an operation on node 'rabbit@rabbitmq-0'. Please see diagnostics information and suggestions below.\\n\\nMost common reasons for this are:\\n\\n * Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)\\n * CLI tool fails to authenticate with the server (e.g. due to CLI tool's Erlang cookie not matching that of the server)\\n * Target node is not running\\n\\nIn addition to the diagnostics info below:\\n\\n * See the CLI, clustering and networking guides on https://rabbitmq.com/documentation.html to learn more\\n * Consult server logs on node rabbit@rabbitmq-0\\n * If target node is configured to use long node names, don't forget to use --longnames with CLI tools\\n\\nDIAGNOSTICS\\n===========\\n\\nattempted to contact: ['rabbit@rabbitmq-0']\\n\\nrabbit@rabbitmq-0:\\n * connected to epmd (port 4369) on rabbitmq-0\\n * epmd reports: node 'rabbit' not running at all\\n no other nodes on rabbitmq-0\\n * suggestion: start the node\\n\\nCurrent node details:\\n * node name: 'rabbitmqcli-10397-rabbit@rabbitmq-0'\\n * effective user's home directory: /var/lib/rabbitmq\\n * Erlang cookie hash: P1XNOe5pN3Ug2FCRFzH7Xg==\\n\\n\"\n Normal Killing 3m58s kubelet, kubernetes-slave-1 FailedPostStartHook\n Normal Created 3m57s (x2 over 16m) kubelet, kubernetes-slave-1 Created container rabbitmq\n Normal Started 3m57s (x2 over 16m) kubelet, kubernetes-slave-1 Started container rabbitmq\n```\n\n```text\nkubectl get sts\nNAME READY AGE\nconsul 3/3 15d\nhazelcast 2/3 15d\nkafka 2/3 15d\nrabbitmq 0/3 13d\nzk 3/3 15d\n```\n\n```text\n2020-03-24 22:58:41.402 [info] <0.8.0> Feature flags: list of feature flags found:\n2020-03-24 22:58:41.402 [info] <0.8.0> Feature flags: [x] drop_unroutable_metric\n2020-03-24 22:58:41.402 [info] <0.8.0> Feature flags: [x] empty_basic_get_metric\n2020-03-24 22:58:41.402 [info] <0.8.0> Feature flags: [x] implicit_default_bindings\n2020-03-24 22:58:41.402 [info] <0.8.0> Feature flags: [x] quorum_queue\n2020-03-24 22:58:41.402 [info] <0.8.0> Feature flags: [x] virtual_host_metadata\n2020-03-24 22:58:41.402 [info] <0.8.0> Feature flags: feature flag states written to disk: yes\n2020-03-24 22:58:43.979 [info] <0.319.0> ra: meta data store initialised. 0 record(s) recovered\n2020-03-24 22:58:43.980 [info] <0.324.0> WAL: recovering [\"/var/lib/rabbitmq/mnesia/rabbit@rabbitmq-0/quorum/rabbit@rabbitmq-0/00000262.wal\"]\n2020-03-24 22:58:43.982 [info] <0.328.0> \n Starting RabbitMQ 3.8.2 on Erlang 22.2.8\n Copyright (c) 2007-2019 Pivotal Software, Inc.\n Licensed under the MPL 1.1. Website: https://rabbitmq.com\n\n ## ## RabbitMQ 3.8.2\n ## ##\n ########## Copyright (c) 2007-2019 Pivotal Software, Inc.\n ###### ##\n ########## Licensed under the MPL 1.1. Website: https://rabbitmq.com\n\n Doc guides: https://rabbitmq.com/documentation.html\n Support: https://rabbitmq.com/contact.html\n Tutorials: https://rabbitmq.com/getstarted.html\n Monitoring: https://rabbitmq.com/monitoring.html\n\n Logs: <stdout>\n\n Config file(s): /etc/rabbitmq/rabbitmq.conf\n\n Starting broker...2020-03-24 22:58:43.983 [info] <0.328.0> \n node : rabbit@rabbitmq-0\n home dir : /var/lib/rabbitmq\n config file(s) : /etc/rabbitmq/rabbitmq.conf\n cookie hash : P1XNOe5pN3Ug2FCRFzH7Xg==\n log(s) : <stdout>\n database dir : /var/lib/rabbitmq/mnesia/rabbit@rabbitmq-0\n2020-03-24 22:58:43.997 [info] <0.328.0> Running boot step pre_boot defined by app rabbit\n2020-03-24 22:58:43.997 [info] <0.328.0> Running boot step rabbit_core_metrics defined by app rabbit\n2020-03-24 22:58:43.998 [info] <0.328.0> Running boot step rabbit_alarm defined by app rabbit\n2020-03-24 22:58:44.002 [info] <0.334.0> Memory high watermark set to 1200 MiB (1258889216 bytes) of 3001 MiB (3147223040 bytes) total\n2020-03-24 22:58:44.014 [info] <0.336.0> Enabling free disk space monitoring\n2020-03-24 22:58:44.014 [info] <0.336.0> Disk free limit set to 50MB\n2020-03-24 22:58:44.018 [info] <0.328.0> Running boot step code_server_cache defined by app rabbit\n2020-03-24 22:58:44.018 [info] <0.328.0> Running boot step file_handle_cache defined by app rabbit\n2020-03-24 22:58:44.019 [info] <0.339.0> Limiting to approx 1048479 file handles (943629 sockets)\n2020-03-24 22:58:44.019 [info] <0.340.0> FHC read buffering: OFF\n2020-03-24 22:58:44.019 [info] <0.340.0> FHC write buffering: ON\n2020-03-24 22:58:44.020 [info] <0.328.0> Running boot step worker_pool defined by app rabbit\n2020-03-24 22:58:44.021 [info] <0.329.0> Will use 2 processes for default worker pool\n2020-03-24 22:58:44.021 [info] <0.329.0> Starting worker pool 'worker_pool' with 2 processes in it\n2020-03-24 22:58:44.021 [info] <0.328.0> Running boot step database defined by app rabbit\n2020-03-24 22:58:44.041 [info] <0.328.0> Waiting for Mnesia tables for 30000 ms, 9 retries left\n2020-03-24 22:59:14.042 [warning] <0.328.0> Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_durable_queue]}\n2020-03-24 22:59:14.042 [info] <0.328.0> Waiting for Mnesia tables for 30000 ms, 8 retries left\n2020-03-24 22:59:44.043 [warning] <0.328.0> Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_durable_queue]}\n2020-03-24 22:59:44.043 [info] <0.328.0> Waiting for Mnesia tables for 30000 ms, 7 retries left\n2020-03-24 23:00:14.044 [warning] <0.328.0> Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_durable_queue]}\n2020-03-24 23:00:14.044 [info] <0.328.0> Waiting for Mnesia tables for 30000 ms, 6 retries left\n2020-03-24 23:00:44.045 [warning] <0.328.0> Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_durable_queue]}\n2020-03-24 23:00:44.045 [info] <0.328.0> Waiting for Mnesia tables for 30000 ms, 5 retries left\n2020-03-24 23:01:14.046 [warning] <0.328.0> Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_durable_queue]}\n2020-03-24 23:01:14.046 [info] <0.328.0> Waiting for Mnesia tables for 30000 ms, 4 retries left\n2020-03-24 23:01:44.047 [warning] <0.328.0> Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_durable_queue]}\n2020-03-24 23:01:44.047 [info] <0.328.0> Waiting for Mnesia tables for 30000 ms, 3 retries left\n2020-03-24 23:02:14.048 [warning] <0.328.0> Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_durable_queue]}\n2020-03-24 23:02:14.048 [info] <0.328.0> Waiting for Mnesia tables for 30000 ms, 2 retries left\n2020-03-24 23:02:44.049 [warning] <0.328.0> Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_durable_queue]}\n2020-03-24 23:02:44.049 [info] <0.328.0> Waiting for Mnesia tables for 30000 ms, 1 retries left\n2020-03-24 23:03:14.050 [warning] <0.328.0> Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_durable_queue]}\n2020-03-24 23:03:14.050 [info] <0.328.0> Waiting for Mnesia tables for 30000 ms, 0 retries left\n2020-03-24 23:03:44.051 [error] <0.328.0> Feature flag `quorum_queue`: migration function crashed: {error,{timeout_waiting_for_tables,[rabbit_durable_queue]}}\n[{rabbit_table,wait,3,[{file,\"src/rabbit_table.erl\"},{line,117}]},{rabbit_core_ff,quorum_queue_migration,3,[{file,\"src/rabbit_core_ff.erl\"},{line,60}]},{rabbit_feature_flags,run_migration_fun,3,[{file,\"src/rabbit_feature_flags.erl\"},{line,1486}]},{rabbit_feature_flags,'-verify_which_feature_flags_are_actually_enabled/0-fun-2-',3,[{file,\"src/rabbit_feature_flags.erl\"},{line,2128}]},{maps,fold_1,3,[{file,\"maps.erl\"},{line,232}]},{rabbit_feature_flags,verify_which_feature_flags_are_actually_enabled,0,[{file,\"src/rabbit_feature_flags.erl\"},{line,2126}]},{rabbit_feature_flags,sync_feature_flags_with_cluster,3,[{file,\"src/rabbit_feature_flags.erl\"},{line,1947}]},{rabbit_mnesia,ensure_feature_flags_are_in_sync,2,[{file,\"src/rabbit_mnesia.erl\"},{line,631}]}]\n2020-03-24 23:03:44.051 [info] <0.328.0> Waiting for Mnesia tables for 30000 ms, 9 retries left\n2020-03-24 23:04:14.052 [warning] <0.328.0> Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]}\n2020-03-24 23:04:14.052 [info] <0.328.0> Waiting for Mnesia tables for 30000 ms, 8 retries left\n2020-03-24 23:04:44.053 [warning] <0.328.0> Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]}\n2020-03-24 23:04:44.053 [info] <0.328.0> Waiting for Mnesia tables for 30000 ms, 7 retries left\n2020-03-24 23:05:14.055 [warning] <0.328.0> Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]}\n2020-03-24 23:05:14.055 [info] <0.328.0> Waiting for Mnesia tables for 30000 ms, 6 retries left\n2020-03-24 23:05:44.056 [warning] <0.328.0> Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]}\n2020-03-24 23:05:44.056 [info] <0.328.0> Waiting for Mnesia tables for 30000 ms, 5 retries left\n2020-03-24 23:06:14.057 [warning] <0.328.0> Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]}\n2020-03-24 23:06:14.057 [info] <0.328.0> Waiting for Mnesia tables for 30000 ms, 4 retries left\n2020-03-24 23:06:44.058 [warning] <0.328.0> Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]}\n2020-03-24 23:06:44.058 [info] <0.328.0> Waiting for Mnesia tables for 30000 ms, 3 retries left\n2020-03-24 23:07:14.059 [warning] <0.328.0> Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]}\n2020-03-24 23:07:14.059 [info] <0.328.0> Waiting for Mnesia tables for 30000 ms, 2 retries left\n2020-03-24 23:07:44.060 [warning] <0.328.0> Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]}\n2020-03-24 23:07:44.060 [info] <0.328.0> Waiting for Mnesia tables for 30000 ms, 1 retries left\n2020-03-24 23:08:14.061 [warning] <0.328.0> Error while waiting for Mnesia tables: {timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]}\n2020-03-24 23:08:14.061 [info] <0.328.0> Waiting for Mnesia tables for 30000 ms, 0 retries left\n2020-03-24 23:08:44.062 [error] <0.327.0> CRASH REPORT Process <0.327.0> with 0 neighbours exited with reason: {{timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]},{rabbit,start,[normal,[]]}} in application_master:init/4 line 138\n2020-03-24 23:08:44.063 [info] <0.43.0> Application rabbit exited with reason: {{timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]},{rabbit,start,[normal,[]]}}\n{\"Kernel pid terminated\",application_controller,\"{application_start_failure,rabbit,{{timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_route,rabbit_durable_exchange,rabbit_runtime_parameters,rabbit_durable_queue]},{rabbit,start,[normal,[]]}}}\"}\nKernel pid terminated (application_controller) ({application_start_failure,rabbit,{{timeout_waiting_for_tables,[rabbit_user,rabbit_user_permission,rabbit_topic_permission,rabbit_vhost,rabbit_durable_r\n\nCrash dump is being written to: /var/log/rabbitmq/erl_crash.dump...done\n```\n\n```text\nkubectl describe pod rabbitmq-0\n```\n\n```text\nkubectl get sts\n```\n\n```text\nrabbitmqctl stop_app\nrabbitmqctl force_boot\n```\n\n```text\nif is_boolean_yes \"$RABBITMQ_FORCE_BOOT\" && ! is_dir_empty \"${RABBITMQ_DATA_DIR}/${RABBITMQ_NODE_NAME}\"; then\n # ref: https://www.rabbitmq.com/rabbitmqctl.8.html#force_boot\n warn \"Forcing node to start...\"\n debug_execute \"${RABBITMQ_BIN_DIR}/rabbitmqctl\" force_boot\n fi\n```\n\n```text\nRABBITMQ_FORCE_BOOT\n```\n\n========================================\n\nComments:\n- Hi Amir, it would be a good idea post this on the kubernetes-users slack channel, have you signed up for that? Also it would be useful if you provided a reference to any guide that you are following to set this cluster up.\n- Can you please post your `kubectl get pods` ? when the app says the node is not running it's probably refering to rabbidmq nodes (pods). just to check if they are running before we dive into conclusions.\n- @RobKielty I'm not joined to that channel, how I can join? I up and run my cluster with this guide: vitux.com/install-and-deploy-kubernetes-on-ubuntu\n- @willrof Sorry I can't add `kubectl get pods` here because of limitation on the number of characters, I attached the output in my question after the command I entered for creating Erlang cookie.\n- @AmirSoleimani sure, on the comments is not recommended. Make an edit to your original question and add to the end the output of the command.\n- @willrof I added it to the end of my question.\n- @amir visit slack.kubernetes.io\n- @AmirSoleimani It took me some time to realize that was a \"normal\" `kubectl get pods`. I'm researching this issue, but since it's with an error `PostStartHookError` it would be valuable to get the output of `kubectl describe pod rabbitmq-0` I'm waiting for your reply.\n- @willrof There is a limitation on the number of characters in the question section too, I had to remove some lines of the outputs that I think those weren't helpful.\n- Hi Amir, could you please how did you install rabbitmq-ha in your cluster (installation source, links), from what I can see from logs it seems to be app specific problem. There are various implementations of rabbitmq for Kubernetes platform, so it would be good set workload specific context for your issue, for further troubleshooting.\n- @Nepomucen I used this wesmorgan.svbtle.com/… and I added `rabbitmq-plugins enable rabbitmq_stomp;` because I need stomp for our project.\n- Possible duplicate: stackoverflow.com/questions/60407082/…\n- Try by disabled the `rabbitmq-plugins enable rabbitmq_stomp` If should work!","metadata":{"transformedAt":"2026-08-18T18:33:20.318Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":11,"totalLines":960,"estimatedTokens":13765}}1047{"id":"stack-45764747","source":"stackoverflow","questionId":45764747,"title":"Spring boot rabbitmq queue count?","tags":["spring-boot","rabbitmq"],"text":"Title: Spring boot rabbitmq queue count?\nTags: spring-boot, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am trying to get a count of the number of messages on my rabbit queue and then purge the queue in my test. Looking around it seems to suggest I need to use RabbitAdmin to get the counts but unsure how to autowire this into my test? any ideas?\n\n```\n@Configuration\npublic class MyConfig {\n\n@Value(\"${queue.producer.name}\")\nprivate String queueName;\n\n@Bean\npublic Jackson2JsonMessageConverter jsonMessageConverter(){\n Jackson2JsonMessageConverter con= new Jackson2JsonMessageConverter();\n return con;\n}\n\n@Autowired\nprivate ConnectionFactory rabbitConnectionFactory;\n\n@Bean\npublic Queue queue() {\n return new Queue(queueName, true);\n}\n\n@Bean\npublic RabbitTemplate rabbitTemplate() {\n RabbitTemplate r = new RabbitTemplate(rabbitConnectionFactory);\n r.setMessageConverter(jsonMessageConverter());\n r.setConnectionFactory(rabbitConnectionFactory);\n return r;\n}\n```\n\ntest class:\n\n```\n@RunWith(SpringRunner.class)\n@SpringBootTest\npublic class TestIT {\n\n@Resource\nprivate RabbitAdmin admin;\n\n@Test\npublic void testQueue() throws IOException, InterruptedException{\n\n System.out.println(getQueueCount(\"publish\"));\n\n admin.purgeQueue(\"publish\",true);\n\n}\n\nprotected int getQueueCount(final String name) {\n AMQP.Queue.DeclareOk declareOk = admin.getRabbitTemplate().execute(new ChannelCallback() {\n public AMQP.Queue.DeclareOk doInRabbit(Channel channel) throws Exception {\n return channel.queueDeclarePassive(name);\n }\n });\n return declareOk.getMessageCount();\n}\n\n}\n```\n\n========================================\n\nCode:\n```text\n@Configuration\npublic class MyConfig {\n\n@Value(\"${queue.producer.name}\")\nprivate String queueName;\n\n\n@Bean\npublic Jackson2JsonMessageConverter jsonMessageConverter(){\n Jackson2JsonMessageConverter con= new Jackson2JsonMessageConverter();\n return con;\n}\n\n@Autowired\nprivate ConnectionFactory rabbitConnectionFactory;\n\n@Bean\npublic Queue queue() {\n return new Queue(queueName, true);\n}\n\n@Bean\npublic RabbitTemplate rabbitTemplate() {\n RabbitTemplate r = new RabbitTemplate(rabbitConnectionFactory);\n r.setMessageConverter(jsonMessageConverter());\n r.setConnectionFactory(rabbitConnectionFactory);\n return r;\n}\n```\n\n```text\n@RunWith(SpringRunner.class)\n@SpringBootTest\npublic class TestIT {\n\n\n@Resource\nprivate RabbitAdmin admin;\n\n@Test\npublic void testQueue() throws IOException, InterruptedException{\n\n System.out.println(getQueueCount(\"publish\"));\n\n admin.purgeQueue(\"publish\",true);\n\n\n}\n\nprotected int getQueueCount(final String name) {\n AMQP.Queue.DeclareOk declareOk = admin.getRabbitTemplate().execute(new ChannelCallback<AMQP.Queue.DeclareOk>() {\n public AMQP.Queue.DeclareOk doInRabbit(Channel channel) throws Exception {\n return channel.queueDeclarePassive(name);\n }\n });\n return declareOk.getMessageCount();\n}\n\n}\n```\n\n```text\n<dependency>\n <groupId>org.springframework.boot</groupId>\n <artifactId>spring-boot-starter-amqp</artifactId>\n</dependency>\n```\n\n```text\n@RunWith(SpringRunner.class)\n@SpringBootTest\npublic class RabbitmqTests {\n\n @Autowired\n private AmqpAdmin amqpAdmin;\n\n @Test\n public void purgeQueue() throws Exception {\n Integer count = (Integer) amqpAdmin.getQueueProperties(\"publish\").get(\"QUEUE_MESSAGE_COUNT\");\n amqpAdmin.purgeQueue(\"publish\", true);\n }\n\n}\n```\n\n```text\nAmqpAdmin\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.318Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":160,"estimatedTokens":856}}1048{"id":"stack-44240148","source":"stackoverflow","questionId":44240148,"title":"Migrate Celery Tasks from Redis to RabbitMQ","tags":["python","redis","rabbitmq","celery"],"text":"Title: Migrate Celery Tasks from Redis to RabbitMQ\nTags: python, redis, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI'm changing my Celery backend from redis to rabbitmq. I can get the new broker working with changing my BROKER_URL. However I'm wondering how to migrate existing scheduled tasks from redis to rabbitmq broker?\n\nI would like to do this by Python script if possible.\n\n========================================\n\nCode:\n```text\ncelery -b \"redis://<url>:<port>/<db>\" inspect scheduled > scheduled_tasks.txt\ncelery migrate \"redis://<url>:<port>/<db>\" \"amqp://<username>:<password>@<url>:<port>/<vhost>\"\ncelery -b \"amqp://<username>:<password>@<url>:<port>/<vhost>\" inspect scheduled > post_migration_scheduled_tasks.txt\ndiff scheduled_tasks.txt post_migration_scheduled_tasks.txt\n```\n\n========================================\n\nComments:\n- Is there anything you've tried or dug up in your search for an answer to this?\n- Apparently there is tool for celery called 'migrate'. It should do the trick. Haven't been able to verify it yet though. If it works I'll make an answer about it.","metadata":{"transformedAt":"2026-08-18T18:33:20.318Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":24,"estimatedTokens":275}}1049{"id":"stack-47144255","source":"stackoverflow","questionId":47144255,"title":"amqp assertQueue bork a connection meaning","tags":["node.js","rabbitmq","amqp"],"text":"Title: amqp assertQueue bork a connection meaning\nTags: node.js, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nIn amqp's assertQueue API Documentation, it states:\n\n*Assert a queue into existence. This operation is idempotent given identical arguments; however, it will bork the channel if the queue already exists but has different properties (values supplied in the arguments field may or may not count for borking purposes; check the borker's, I mean broker's, documentation).*\n\nhttp://www.squaremobius.net/amqp.node/channel_api.html#channel_assertQueue\n\nI am asking what it means by bork(ing) the channel. I tried google but can't find anything relevant.\n\n========================================\n\nTop Answer:\nBork: English meaning is to obstruct something.\n\nAs per the documentation in the question, it says\n\nhowever, it will bork the channel if the queue already exists but has\ndifferent properties\n\nthis means if you try to create a channel which has the same properties of a channel which already exits, nothing would happen cause it is idempotent (meaning repeating the same action with no different result, e.g. a REST API GET request which fetches data for id say 123, will return the same data every time unless updated, a pretty funny video explaining the impotent concept), but if you try to create a channel with the same name but different properties, the channel creation shall be \"borked\" i.e. obstructed.\n\nIn the code below, we create the channel again,\n\n```\nvar ok0 = ch.assertQueue(q, {durable: false});// creating the first time\n var ok1 = ch.assertQueue(q, {durable: true});// creating the second time again with different durable property value\n```\n\nit **throws an error**\n\n\"PRECONDITION_FAILED - inequivalent arg 'durable' for queue 'hello' in\nvhost '/': received 'true' but current is 'false'\"\n\nThis means the you are trying to make the same channel with different properties, i.e. the durable property is different to the existing channel and hence it has been borked.\n\n[2]: Answer by @Like Bakken\n\n========================================\n\nCode:\n```text\n#!/usr/bin/env node\n\nvar amqp = require('amqplib');\n\namqp.connect('amqp://localhost').then(function(conn) {\n return conn.createChannel().then(function(ch) {\n var q = 'hello';\n var ok0 = ch.assertQueue(q, {durable: false});\n return ok0.then(function(_qok) {\n var ok1 = ch.assertQueue(q, {durable: true});\n return ok1.then(function(got) {\n console.log(\" [x] got '%s'\", got);\n return ch.close();\n });\n });\n }).finally(function() { conn.close(); });\n}).catch(console.warn);\n```\n\n```text\n$ node examples/tutorials/assert-borked.js\nevents.js:183\n throw er; // Unhandled 'error' event\n ^\n\nError: Channel closed by server: 406 (PRECONDITION-FAILED) with message \"PRECONDITION_FAILED - inequivalent arg 'durable' for queue 'hello' in vhost '/': received 'true' but current is 'false'\"\n at Channel.C.accept\n```\n\n```text\nassertQueue\n```\n\n```text\nvar ok0 = ch.assertQueue(q, {durable: false});// creating the first time\n var ok1 = ch.assertQueue(q, {durable: true});// creating the second time again with different durable property value\n```\n\n========================================\n\nComments:\n- This does not answer the question, actually. What does \"bork\" mean?\n- Brilliant answer! This should be the accepted answer since it, unlike the currently accepted answer, actually answers the question asked by the OP. On a side note, I appreciate humor in the generally humorless realm of technical documentation, but in this instance it has actually derailed me from coding since I'm having to look up a term that doesn't really bring any value to the documentation.\n- What is missing in this answer is: if one catches the error generated by the second assertion, will the queue go on working as it did or we will see some side-effects?","metadata":{"transformedAt":"2026-08-18T18:33:20.318Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":89,"estimatedTokens":969}}1050{"id":"stack-23207812","source":"stackoverflow","questionId":23207812,"title":"logstash rabbitmq output never posts to exchange","tags":["rabbitmq","logstash"],"text":"Title: logstash rabbitmq output never posts to exchange\nTags: rabbitmq, logstash\nSource: Stack Overflow\n\nQuestion:\nI've got logstash running, and successfully reading in a file\n\n- rabbitmq is running, I'm watching the log, and I can see the web interface\n\n- I've configured logstash to output to a rabbitmq exchange... I think!\n\nHere's the problem: nothing ever gets posted to the exchange, as seen in the web interface.\n\nAny ideas?\n\nMy output config:\n\n```\noutput {\n rabbitmq {\n codec => plain\n host => localhost\n exchange => yomtvraps\n exchange_type => direct\n }\n\n file { path => \"/tmp/heartbeat-from-logstash.log\" }\n}\n```\n\nUPDATE: I'm watching the rabbit log with\n`tail -F /usr/local/var/log/rabbitmq/rabbit\\@localhost.log`\n\nAs it turns out, the problem was that there was no routing key set for the exchange and queue.\n\nA working config is:\n\n```\noutput { \n rabbitmq {\n codec => plain\n host => localhost\n exchange => yomtvraps\n exchange_type => direct\n key => yomtvraps\n\n # these are defaults but you never know...\n durable => true\n port => 5672\n user => \"guest\"\n password => \"guest\"\n }\n}\n```\n\nHere's a sample receiver code (using ruby \"Bunny\")\n\n```\nrequire \"bunny\"\n\nconn = Bunny.new(:automatically_recover => false)\nconn.start\n\nch = conn.create_channel\nq = ch.queue(\"yomtvraps\")\n\nexchange = ch.direct(\"yomtvraps\", :durable => true)\n\nbegin\n puts \" [*] Waiting for messages. To exit press CTRL+C\"\n q.bind(exchange, :routing_key => \"yomtvraps\").subscribe(:block => true) do |delivery_info, properties, body|\n puts \" [x] Received #{body}\"\n end\nrescue Interrupt => _\n conn.close\n\n exit(0)\nend\n```\n\n========================================\n\nCode:\n```text\noutput {\n rabbitmq {\n codec => plain\n host => localhost\n exchange => yomtvraps\n exchange_type => direct\n }\n\n file { path => \"/tmp/heartbeat-from-logstash.log\" }\n}\n```\n\n```text\noutput { \n rabbitmq {\n codec => plain\n host => localhost\n exchange => yomtvraps\n exchange_type => direct\n key => yomtvraps\n\n # these are defaults but you never know...\n durable => true\n port => 5672\n user => \"guest\"\n password => \"guest\"\n }\n}\n```\n\n```text\nrequire \"bunny\"\n\nconn = Bunny.new(:automatically_recover => false)\nconn.start\n\nch = conn.create_channel\nq = ch.queue(\"yomtvraps\")\n\nexchange = ch.direct(\"yomtvraps\", :durable => true)\n\nbegin\n puts \" [*] Waiting for messages. To exit press CTRL+C\"\n q.bind(exchange, :routing_key => \"yomtvraps\").subscribe(:block => true) do |delivery_info, properties, body|\n puts \" [x] Received #{body}\"\n end\nrescue Interrupt => _\n conn.close\n\n exit(0)\nend\n```\n\n```text\ntail -F /usr/local/var/log/rabbitmq/rabbit\\@localhost.log\n```\n\n```text\nps -ef|grep erl\n```\n\n========================================\n\nComments:\n- The problem seems to be my exchange is never publishing to my queue, so it's not really a logstash problem after all\n- 1. :) I'll try that! 2. I removed it for this example, but I am doing that and see incoming logs 3. :) I'll make a note, thanks 4. I'm doing a: \"tail -F /usr/local/var/log/rabbitmq/rabbit\\@localhost.log\" ... I see the connections from both ends, but nothing else\n- I think that your problem may be in the rabbitmq's configuration and test. And 4 steps have been added into the above post.","metadata":{"transformedAt":"2026-08-18T18:33:20.318Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":151,"estimatedTokens":841}}1051{"id":"stack-7365340","source":"stackoverflow","questionId":7365340,"title":"RabbitMQ Wcf Binding","tags":["wcf","wcf-binding","rabbitmq"],"text":"Title: RabbitMQ Wcf Binding\nTags: wcf, wcf-binding, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nwhat is the point on having RabbitMQ with WCF Binding instead of plain WCF?\nIs there any advantage when using RabbitMQ except for using it?\nregards,\n\n========================================\n\nComments:\n- what are the benefits of using rabbitmq wcf instead of lets say net.tcp wcf?\n- Messages are guaranteed to be delivered with either MSMQ or Rabbit MQ but not over other WCF bindings. That and not having to install MSMQ are pretty much the only reasons you'd pick Rabbit MQ over other WCF bindings.\n- I think WCF has a reliable session somewhere that guaratees delivery.\n- Actually, WCF reliable sessions **do not** guarantee delivery. Guaranteed delivery means that if the server that hosts your WCF service suddenly crashes for some reason then a message sent through the Rabbit MQ binding (or netMsmqBinding) while it is down will be still delivered when the server comes back up. Reliable sessions simply go away when a server crashes.\n- This is because the message is send to the queue and the host picks it up from there. But what happens to the \"session\" of the client? Can the host after a restart send the reply to the same client? Will the channel not be faulted?\n- The Rabbit MQ binding supports reliable session and duplex services which netMsmqBinding does not. The netMsmqBinding only supports one-way messages. I'm not sure if the Rabbit MQ binding sessions are \"durable\" meaning they can survive a service crash. All the capabilities of the Rabbit MQ binding are described in this document.","metadata":{"transformedAt":"2026-08-18T18:33:20.318Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":18,"estimatedTokens":401}}1052{"id":"stack-11414019","source":"stackoverflow","questionId":11414019,"title":"RabbitMQ in a WCF webservice, model usage and performance","tags":["c#","wcf","rabbitmq"],"text":"Title: RabbitMQ in a WCF webservice, model usage and performance\nTags: c#, wcf, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI need to call a RabbitMQ RPC Service from within a C# WCF Web service hosted in IIS.\nWe have this working OK, but being a good little soldier I was reading the RabbitMQ client documentation and it states the following **\"IModel should not be shared between threads\"**. \n\nMy understanding is that in RabbitMQ an **IModel** is actually a socket connection.\nthis would mean that for every call the WCF service makes it's needs to create an IModel and dispose of it once completed.\n\nThis would seem to me to be somewhat excessive on performance and socket usage and I am wondering if my understanding is actually correct, or if there are other options available like using a connection pool of IModels between threads.\n\nAny suggestions would be gratefully received. Here's a sample of the code I'm using below, the rabbitMQ connection is actually initialized in the Global.asax, I just have it there to you can see the usage.\n\n```\nvar connectionFactory = new ConnectionFactory();\n connectionFactory.HostName = \"SampleHostName\";\n connectionFactory.UserName = \"SampleUserName\";\n connectionFactory.Password = \"SamplePassword\";\n IConnection connection = connectionFactory.CreateConnection();\n // Code below is what we actually have in the service method.\n var model = connection.CreateModel();\n using (model)\n {\n model.ExchangeDeclare(\"SampleExchangeName\", ExchangeType.Direct, false);\n model.QueueDeclare(\"SampleQueueName\", false, false, false, null);\n model.QueueBind(\"SampleQueueName\", \"SampleExchangeName\", \"routingKey\" , null);\n // Do stuff, like post messages to queues\n }\n```\n\n========================================\n\nTop Answer:\nYou need a single IModel object for each session. This is pretty normal for network-based API's. For example the Azure Table Storage client is exactly the same.\nWhy, well you can't have a single Channel with multiple concurrent communication streams running over them. \n\nI would expect that a certain level of caching to occur (e.g. DNS) which would reduce the overhead of creating subsequent IModel instances.\n\nPerformance is alright when doing the same thing with Azure Tables so it should be perfectly fine with IModel. Only attempt to optimise this when you can prove you have a real need.\n\n========================================\n\nCode:\n```text\nvar connectionFactory = new ConnectionFactory();\n connectionFactory.HostName = \"SampleHostName\";\n connectionFactory.UserName = \"SampleUserName\";\n connectionFactory.Password = \"SamplePassword\";\n IConnection connection = connectionFactory.CreateConnection();\n // Code below is what we actually have in the service method.\n var model = connection.CreateModel();\n using (model)\n {\n model.ExchangeDeclare(\"SampleExchangeName\", ExchangeType.Direct, false);\n model.QueueDeclare(\"SampleQueueName\", false, false, false, null);\n model.QueueBind(\"SampleQueueName\", \"SampleExchangeName\", \"routingKey\" , null);\n // Do stuff, like post messages to queues\n }\n```\n\n========================================\n\nComments:\n- Thanks for the update Alistair. I'm presuming that what I'm doing is very similar to a single use proxy pattern that WCF uses. I was unsure as to where the rabbit libraries would actually cache connections; or if that was an operation of the OS. As for performance; things seem to work nicely in our environments. I'm more worried about external hosting environments and the potential for issues there where we have very little idea or control over what the system in running on. So just just trying to squeeze out the last possible bit of performance where I can. Cheers Noel.\n- Thanks Vadmin, this is the information I required. I'm not too worried about the overhead of the Model management; just once using the Rabbit .NET client did not not have to create a socket on every request. Which I know is an intensive operation.","metadata":{"transformedAt":"2026-08-18T18:33:20.318Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":67,"estimatedTokens":1011}}1053{"id":"stack-38933035","source":"stackoverflow","questionId":38933035,"title":"What's the proper way to scrape asynchronously and store my results using django celery and redis and store my?","tags":["python","django","queue","rabbitmq","django-celery"],"text":"Title: What's the proper way to scrape asynchronously and store my results using django celery and redis and store my?\nTags: python, django, queue, rabbitmq, django-celery\nSource: Stack Overflow\n\nQuestion:\nI have been trying to understand what my problem is when I try to scrape using a function I created in my django app. The function goes to a website gathers data and stores it in my database. At first I tried using rq and redis for a while but I kept getting an error message. So someone thought I should try and use celery,and I did. But I see now that rq nor celery is the problem. For I am getting the same error message as I was before. I tired importing it, but still got the error message, and then I thought well maybe If I have the actual function in my tasks.py file that it would make a difference but it didn't. Heres my function I tried to use in my tasks.py\n\n```\nimport requests\nfrom bs4 import BeautifulSoup\nfrom src.blog.models import Post\nimport random\nimport re\nfrom django.contrib.auth.models import User\nimport os\n\n@app.tasks\ndef p_panties():\n def swappo():\n user_one = ' \"Mozilla/5.0 (Windows NT 6.0; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0\" '\n user_two = ' \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5)\" '\n user_thr = ' \"Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko\" '\n user_for = ' \"Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:10.0) Gecko/20100101 Firefox/10.0\" '\n\n agent_list = [user_one, user_two, user_thr, user_for]\n a = random.choice(agent_list)\n return a\n\n headers = {\n \"user-agent\": swappo(),\n \"accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\",\n \"accept-charset\": \"ISO-8859-1,utf-8;q=0.7,*;q=0.3\",\n \"accept-encoding\": \"gzip,deflate,sdch\",\n \"accept-language\": \"en-US,en;q=0.8\",\n }\n\n pan_url = 'http://www.example.org'\n shtml = requests.get(pan_url, headers=headers)\n soup = BeautifulSoup(shtml.text, 'html5lib')\n video_row = soup.find_all('div', {'class': 'post-start'})\n name = 'pan videos'\n\n if os.getenv('_system_name') == 'OSX':\n author = User.objects.get(id=2)\n else:\n author = User.objects.get(id=3)\n\n def youtube_link(url):\n youtube_page = requests.get(url, headers=headers)\n soupdata = BeautifulSoup(youtube_page.text, 'html5lib')\n video_row = soupdata.find_all('p')[0]\n entries = [{'text': div,\n } for div in video_row]\n tubby = str(entries[0]['text'])\n urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', tubby)\n cleaned_url = urls[0].replace('?&autoplay=1', '')\n return cleaned_url\n\n def yt_id(code):\n the_id = code\n youtube_id = the_id.replace('https://www.youtube.com/embed/', '')\n return youtube_id\n\n def strip_hd(hd, move):\n str = hd\n new_hd = str.replace(move, '')\n return new_hd\n\n entries = [{'href': div.a.get('href'),\n 'text': strip_hd(strip_hd(div.h2.text, '– Official video HD'), '– Oficial video HD').lstrip(),\n 'embed': youtube_link(div.a.get('href')), #embed\n 'comments': strip_hd(strip_hd(div.h2.text, '– Official video HD'), '– Oficial video HD').lstrip(),\n 'src': 'https://i.ytimg.com/vi/' + yt_id(youtube_link(div.a.get('href'))) + '/maxresdefault.jpg', #image\n 'name': name,\n 'url': div.a.get('href'),\n 'author': author,\n 'video': True\n\n } for div in video_row][:13]\n\n for entry in entries:\n post = Post()\n post.title = entry['text']\n title = post.title\n if not Post.objects.filter(title=title):\n post.title = entry['text']\n post.name = entry['name']\n post.url = entry['url']\n post.body = entry['comments']\n post.image_url = entry['src']\n post.video_path = entry['embed']\n post.author = entry['author']\n post.video = entry['video']\n post.status = 'draft'\n post.save()\n post.tags.add(\"video\", \"Musica\")\n return entries\n```\n\nand In the python shell if I run\n\n```\nfrom tasks import *\n```\n\nI get\n\n```\nTraceback (most recent call last):\n File \"\", line 1, in \n File \"/Users/ray/Desktop/myheroku/practice/tasks.py\", line 5, in \n from src.blog.models import Post\n File \"/Users/ray/Desktop/myheroku/practice/src/blog/models.py\", line 3, in \n from taggit.managers import TaggableManager\n File \"/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/taggit/managers.py\", line 7, in \n from django.contrib.contenttypes.models import ContentType\n File \"/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/django/contrib/contenttypes/models.py\", line 159, in \n class ContentType(models.Model):\n File \"/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/django/contrib/contenttypes/models.py\", line 160, in ContentType\n app_label = models.CharField(max_length=100)\n File \"/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/django/db/models/fields/__init__.py\", line 1072, in __init__\n super(CharField, self).__init__(*args, **kwargs)\n File \"/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/django/db/models/fields/__init__.py\", line 166, in __init__\n self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE\n File \"/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/django/conf/__init__.py\", line 55, in __getattr__\n self._setup(name)\n File \"/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/django/conf/__init__.py\", line 41, in _setup\n % (desc, ENVIRONMENT_VARIABLE))\ndjango.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.\n```\n\nwhich is the exact same traceback I got using rq and redis. I found that If I modify the imports like this\n\n```\nimport requests\nfrom bs4 import BeautifulSoup\n# from src.blog.models import Post\nimport random\nimport re\n# from django.contrib.auth.models import User\nimport os\n```\n\nand modify my function like this\n\n```\n@app.task\ndef p_panties():\n def swappo():\n user_one = ' \"Mozilla/5.0 (Windows NT 6.0; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0\" '\n user_two = ' \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5)\" '\n user_thr = ' \"Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko\" '\n user_for = ' \"Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:10.0) Gecko/20100101 Firefox/10.0\" '\n\n agent_list = [user_one, user_two, user_thr, user_for]\n a = random.choice(agent_list)\n return a\n\n headers = {\n \"user-agent\": swappo(),\n \"accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\",\n \"accept-charset\": \"ISO-8859-1,utf-8;q=0.7,*;q=0.3\",\n \"accept-encoding\": \"gzip,deflate,sdch\",\n \"accept-language\": \"en-US,en;q=0.8\",\n }\n\n pan_url = 'http://www.example.org'\n shtml = requests.get(pan_url, headers=headers)\n soup = BeautifulSoup(shtml.text, 'html5lib')\n video_row = soup.find_all('div', {'class': 'post-start'})\n name = 'pan videos'\n\n # if os.getenv('_system_name') == 'OSX':\n # author = User.objects.get(id=2)\n # else:\n # author = User.objects.get(id=3)\n\n def youtube_link(url):\n youtube_page = requests.get(url, headers=headers)\n soupdata = BeautifulSoup(youtube_page.text, 'html5lib')\n video_row = soupdata.find_all('p')[0]\n entries = [{'text': div,\n } for div in video_row]\n tubby = str(entries[0]['text'])\n urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', tubby)\n cleaned_url = urls[0].replace('?&autoplay=1', '')\n return cleaned_url\n\n def yt_id(code):\n the_id = code\n youtube_id = the_id.replace('https://www.youtube.com/embed/', '')\n return youtube_id\n\n def strip_hd(hd, move):\n str = hd\n new_hd = str.replace(move, '')\n return new_hd\n\n entries = [{'href': div.a.get('href'),\n 'text': strip_hd(strip_hd(div.h2.text, '– Official video HD'), '– Oficial video HD').lstrip(),\n 'embed': youtube_link(div.a.get('href')), #embed\n 'comments': strip_hd(strip_hd(div.h2.text, '– Official video HD'), '– Oficial video HD').lstrip(),\n 'src': 'https://i.ytimg.com/vi/' + yt_id(youtube_link(div.a.get('href'))) + '/maxresdefault.jpg', #image\n 'name': name,\n 'url': div.a.get('href'),\n # 'author': author,\n 'video': True\n\n } for div in video_row][:13]\n #\n # for entry in entries:\n # post = Post()\n # post.title = entry['text']\n # title = post.title\n # if not Post.objects.filter(title=title):\n # post.title = entry['text']\n # post.name = entry['name']\n # post.url = entry['url']\n # post.body = entry['comments']\n # post.image_url = entry['src']\n # post.video_path = entry['embed']\n # post.author = entry['author']\n # post.video = entry['video']\n # post.status = 'draft'\n # post.save()\n # post.tags.add(\"video\", \"Musica\")\n return entries\n```\n\nIt works, as this is my output\n\n```\n[2016-08-13 08:31:17,222: INFO/MainProcess] Received task: tasks.p_panties[e196c6bf-2b87-4bb2-ae11-452e3c41434f]\n[2016-08-13 08:31:17,238: INFO/Worker-4] Starting new HTTP connection (1): www.example.org\n[2016-08-13 08:31:17,582: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:18,314: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:18,870: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:19,476: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:20,089: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:20,711: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:21,218: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:21,727: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:22,372: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:22,785: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:23,375: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:23,983: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:24,396: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:25,003: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:25,621: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:26,029: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:26,446: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:27,261: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:27,671: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:28,082: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:28,694: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:29,311: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:29,922: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:30,535: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:31,154: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:31,765: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:32,387: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:32,992: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:33,611: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:34,030: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:34,635: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:35,041: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:35,659: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:36,278: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:36,886: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:37,496: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:37,913: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:38,564: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:39,143: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:39,754: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:40,409: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:40,992: INFO/MainProcess] Task tasks.p_panties[e196c6bf-2b87-4bb2-ae11-452e3c41434f] succeeded in 23.767645187006565s: [{'src': 'https://i.ytimg.com/vi/3bU-AtShW7Y/maxresdefault.jpg', 'name': 'pan videos', 'url':...\n```\n\nIt seems some type of authorization is needed to interact with my Post model. I just don't know how. I have been scouring the net for examples on how to scrape and save data into the database. oddly I have come across none. Any advice tips doc's i could read would be a great help.\n\n### EDIT\n\nMy File structure\n\n```\nenviron\\\n |-src\\\n |-blog\\\n |-migrations\\\n |-static\\\n |-templates\\\n |-templatetags\\\n |-__init__.py\n |-admin.py\n |-forms.py\n |-models\n |-tasks\n |-urls\n |-views\n```\n\n========================================\n\nCode:\n```text\nimport requests\nfrom bs4 import BeautifulSoup\nfrom src.blog.models import Post\nimport random\nimport re\nfrom django.contrib.auth.models import User\nimport os\n\n@app.tasks\ndef p_panties():\n def swappo():\n user_one = ' \"Mozilla/5.0 (Windows NT 6.0; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0\" '\n user_two = ' \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5)\" '\n user_thr = ' \"Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko\" '\n user_for = ' \"Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:10.0) Gecko/20100101 Firefox/10.0\" '\n\n agent_list = [user_one, user_two, user_thr, user_for]\n a = random.choice(agent_list)\n return a\n\n headers = {\n \"user-agent\": swappo(),\n \"accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\",\n \"accept-charset\": \"ISO-8859-1,utf-8;q=0.7,*;q=0.3\",\n \"accept-encoding\": \"gzip,deflate,sdch\",\n \"accept-language\": \"en-US,en;q=0.8\",\n }\n\n pan_url = 'http://www.example.org'\n shtml = requests.get(pan_url, headers=headers)\n soup = BeautifulSoup(shtml.text, 'html5lib')\n video_row = soup.find_all('div', {'class': 'post-start'})\n name = 'pan videos'\n\n if os.getenv('_system_name') == 'OSX':\n author = User.objects.get(id=2)\n else:\n author = User.objects.get(id=3)\n\n def youtube_link(url):\n youtube_page = requests.get(url, headers=headers)\n soupdata = BeautifulSoup(youtube_page.text, 'html5lib')\n video_row = soupdata.find_all('p')[0]\n entries = [{'text': div,\n } for div in video_row]\n tubby = str(entries[0]['text'])\n urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', tubby)\n cleaned_url = urls[0].replace('?&autoplay=1', '')\n return cleaned_url\n\n def yt_id(code):\n the_id = code\n youtube_id = the_id.replace('https://www.youtube.com/embed/', '')\n return youtube_id\n\n def strip_hd(hd, move):\n str = hd\n new_hd = str.replace(move, '')\n return new_hd\n\n entries = [{'href': div.a.get('href'),\n 'text': strip_hd(strip_hd(div.h2.text, '– Official video HD'), '– Oficial video HD').lstrip(),\n 'embed': youtube_link(div.a.get('href')), #embed\n 'comments': strip_hd(strip_hd(div.h2.text, '– Official video HD'), '– Oficial video HD').lstrip(),\n 'src': 'https://i.ytimg.com/vi/' + yt_id(youtube_link(div.a.get('href'))) + '/maxresdefault.jpg', #image\n 'name': name,\n 'url': div.a.get('href'),\n 'author': author,\n 'video': True\n\n } for div in video_row][:13]\n\n for entry in entries:\n post = Post()\n post.title = entry['text']\n title = post.title\n if not Post.objects.filter(title=title):\n post.title = entry['text']\n post.name = entry['name']\n post.url = entry['url']\n post.body = entry['comments']\n post.image_url = entry['src']\n post.video_path = entry['embed']\n post.author = entry['author']\n post.video = entry['video']\n post.status = 'draft'\n post.save()\n post.tags.add(\"video\", \"Musica\")\n return entries\n```\n\n```text\nfrom tasks import *\n```\n\n```text\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\n File \"/Users/ray/Desktop/myheroku/practice/tasks.py\", line 5, in <module>\n from src.blog.models import Post\n File \"/Users/ray/Desktop/myheroku/practice/src/blog/models.py\", line 3, in <module>\n from taggit.managers import TaggableManager\n File \"/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/taggit/managers.py\", line 7, in <module>\n from django.contrib.contenttypes.models import ContentType\n File \"/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/django/contrib/contenttypes/models.py\", line 159, in <module>\n class ContentType(models.Model):\n File \"/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/django/contrib/contenttypes/models.py\", line 160, in ContentType\n app_label = models.CharField(max_length=100)\n File \"/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/django/db/models/fields/__init__.py\", line 1072, in __init__\n super(CharField, self).__init__(*args, **kwargs)\n File \"/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/django/db/models/fields/__init__.py\", line 166, in __init__\n self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE\n File \"/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/django/conf/__init__.py\", line 55, in __getattr__\n self._setup(name)\n File \"/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/django/conf/__init__.py\", line 41, in _setup\n % (desc, ENVIRONMENT_VARIABLE))\ndjango.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.\n```\n\n```text\nimport requests\nfrom bs4 import BeautifulSoup\n# from src.blog.models import Post\nimport random\nimport re\n# from django.contrib.auth.models import User\nimport os\n```\n\n```text\n@app.task\ndef p_panties():\n def swappo():\n user_one = ' \"Mozilla/5.0 (Windows NT 6.0; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0\" '\n user_two = ' \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5)\" '\n user_thr = ' \"Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko\" '\n user_for = ' \"Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:10.0) Gecko/20100101 Firefox/10.0\" '\n\n agent_list = [user_one, user_two, user_thr, user_for]\n a = random.choice(agent_list)\n return a\n\n headers = {\n \"user-agent\": swappo(),\n \"accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\",\n \"accept-charset\": \"ISO-8859-1,utf-8;q=0.7,*;q=0.3\",\n \"accept-encoding\": \"gzip,deflate,sdch\",\n \"accept-language\": \"en-US,en;q=0.8\",\n }\n\n pan_url = 'http://www.example.org'\n shtml = requests.get(pan_url, headers=headers)\n soup = BeautifulSoup(shtml.text, 'html5lib')\n video_row = soup.find_all('div', {'class': 'post-start'})\n name = 'pan videos'\n\n # if os.getenv('_system_name') == 'OSX':\n # author = User.objects.get(id=2)\n # else:\n # author = User.objects.get(id=3)\n\n def youtube_link(url):\n youtube_page = requests.get(url, headers=headers)\n soupdata = BeautifulSoup(youtube_page.text, 'html5lib')\n video_row = soupdata.find_all('p')[0]\n entries = [{'text': div,\n } for div in video_row]\n tubby = str(entries[0]['text'])\n urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', tubby)\n cleaned_url = urls[0].replace('?&autoplay=1', '')\n return cleaned_url\n\n def yt_id(code):\n the_id = code\n youtube_id = the_id.replace('https://www.youtube.com/embed/', '')\n return youtube_id\n\n def strip_hd(hd, move):\n str = hd\n new_hd = str.replace(move, '')\n return new_hd\n\n entries = [{'href': div.a.get('href'),\n 'text': strip_hd(strip_hd(div.h2.text, '– Official video HD'), '– Oficial video HD').lstrip(),\n 'embed': youtube_link(div.a.get('href')), #embed\n 'comments': strip_hd(strip_hd(div.h2.text, '– Official video HD'), '– Oficial video HD').lstrip(),\n 'src': 'https://i.ytimg.com/vi/' + yt_id(youtube_link(div.a.get('href'))) + '/maxresdefault.jpg', #image\n 'name': name,\n 'url': div.a.get('href'),\n # 'author': author,\n 'video': True\n\n } for div in video_row][:13]\n #\n # for entry in entries:\n # post = Post()\n # post.title = entry['text']\n # title = post.title\n # if not Post.objects.filter(title=title):\n # post.title = entry['text']\n # post.name = entry['name']\n # post.url = entry['url']\n # post.body = entry['comments']\n # post.image_url = entry['src']\n # post.video_path = entry['embed']\n # post.author = entry['author']\n # post.video = entry['video']\n # post.status = 'draft'\n # post.save()\n # post.tags.add(\"video\", \"Musica\")\n return entries\n```\n\n```text\n[2016-08-13 08:31:17,222: INFO/MainProcess] Received task: tasks.p_panties[e196c6bf-2b87-4bb2-ae11-452e3c41434f]\n[2016-08-13 08:31:17,238: INFO/Worker-4] Starting new HTTP connection (1): www.example.org\n[2016-08-13 08:31:17,582: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:18,314: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:18,870: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:19,476: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:20,089: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:20,711: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:21,218: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:21,727: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:22,372: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:22,785: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:23,375: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:23,983: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:24,396: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:25,003: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:25,621: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:26,029: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:26,446: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:27,261: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:27,671: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:28,082: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:28,694: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:29,311: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:29,922: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:30,535: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:31,154: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:31,765: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:32,387: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:32,992: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:33,611: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:34,030: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:34,635: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:35,041: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:35,659: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:36,278: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:36,886: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:37,496: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:37,913: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:38,564: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:39,143: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:39,754: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:40,409: INFO/Worker-4] Starting new HTTP connection (1): example.org\n[2016-08-13 08:31:40,992: INFO/MainProcess] Task tasks.p_panties[e196c6bf-2b87-4bb2-ae11-452e3c41434f] succeeded in 23.767645187006565s: [{'src': 'https://i.ytimg.com/vi/3bU-AtShW7Y/maxresdefault.jpg', 'name': 'pan videos', 'url':...\n```\n\n```text\nenviron\\\n |-src\\\n |-blog\\\n |-migrations\\\n |-static\\\n |-templates\\\n |-templatetags\\\n |-__init__.py\n |-admin.py\n |-forms.py\n |-models\n |-tasks\n |-urls\n |-views\n```\n\n```text\nos.environ.setdefault(\"DJANGO_SETTINGS_MODULE\", \"myapp.settings\")\n```\n\n```text\nos.environ.setdefault(\"DJANGO_SETTINGS_MODULE\", DEFAULT_SETTINGS_MODULE)\n```\n\n```text\nimport sys, os\nsys.path.insert(0, \"/path/to/parent/of/src\") # /home/projects/my-crawler\n\nfrom manage import DEFAULT_SETTINGS_MODULE\nos.environ.setdefault(\"DJANGO_SETTINGS_MODULE\", DEFAULT_SETTINGS_MODULE)\n\nimport django\ndjango.setup() \n... The rest of your script ...\n```\n\n```text\nfrom redis import StrictRedis\n\nredis = StrictRedis(host='localhost', port=6379, db=0)\n\nredis.set(\"scraping:tasks:results:TASK-ID-HERE\", json.dumps(entries))\n```\n\n```text\nwith redis.pipeline() as pipe:\n for item in entries:\n pipe.rpush(\"scraping:tasks:results\", json.dumps(item))\n pipe.execute()\n```\n\n```text\n@celery_app.task\ndef handle_scraping_results(entries):\n you do whatever you want with the entries array now\n```\n\n```text\nhandle_scraping_results.delay(entries)\n```\n\n```text\nredis_keys = redis.get(\"scraping:tasks:results:*\")\n\nfor key in redis_keys:\n value_of_redis_key = redis.get(key)\n entries = json.loads(entries)\n for entry in entries:\n post = Post()\n post.title = entry['text']\n title = post.title\n if not Post.objects.filter(title=title):\n post.title = entry['text']\n post.name = entry['name']\n post.url = entry['url']\n post.body = entry['comments']\n post.image_url = entry['src']\n post.video_path = entry['embed']\n post.author = entry['author']\n post.video = entry['video']\n post.status = 'draft'\n post.save()\n post.tags.add(\"video\", \"Musica\")\n```\n\n```text\n.delay()\n```\n\n```text\n.apply_async()\n```\n\n========================================\n\nComments:\n- Did you try running `settings.configure()`? I have seen similar errors in the past and they are usually a result of trying to import django objects outside of the django shell. Basically, Django needs to be able to set up everything through settings.py in order for anything to work. So if you need to interact with the shell, you should do it through `python manage.py shell`.\n- i am currently using rabbitmq after much research I was told this was the best to use. How can I make it work with rabbitmq? and how can I store the results from the scrape and access them. above the most important part is commented out. Thats the part I want to work. I need to be able to access the reultes from my scrape. And can you point me to where I can read how to do this. Not the docs though. The explanatons are matter of factly and confusing to me\n- Im also using a django backend\n- @losee I've already told you how to store your results, you just do them at the end of your task, I have also written the code for Redis on how you'd do this. Notice that RabbitMQ, is not a storage engine, its a message broker implementing the AMQP, you cannot store anything in RabbitMQ, instead, you can send a message that contains your data, using rabbitmq, to a celery worker. So basically I've already told you what to do in this part : **you can also call another celery task to take care of the results and pass entries to it).**\n- You really need to take a look at the docs for celery and what it actually does. It basically renders a simple function call, to a distributed message passing environment in which everything can be done async-ly, and by different processes (not just the process that called the function). I'll edit my answer just to guide you alittle bit.\n- I read what you had above. I need torun this process in the background becuase otherwise I get server errors because it takes longer than 30-45 seconds. Not only that. For what I'm going to do I can't do manually. it needs to be auto matic. I was actually suggested to use celery and reddismq. Sorry for the confusion but I'm not trying to store anything in reddis. I'm trying to store my scraped results into my database every few hours using the django backend suggested by the docs.\n- **You are trying to store them every few hours** : So, if your task runs in like 30-45 seconds, but you're not going to store it in the db for the next several hours, where do you intend to keep this intermediate result ? People mostly keep them in redis, I'd suggest you do the same. Then after the few hours, just do a redis.get() on the keys where you store your results and persist them to your django database. It should be absolutely clear by now and I suggest you read and think through what you've been provided here more, but as a last effort, I'll add the code to do what's I've described\n- I just saw your post, when i try to uncomment my code I get this new error Parent module '' not loaded, cannot perform relative import. see here stackoverflow.com/questions/39442206/…\n- I have given you about 4 different solutions and all of them, theoretically and practically, do work. You need to wrap your head around how things work in django and celery, how celery tasks work, how to setup django properly, how to write celery tasks and how to run them using a worker and ...","metadata":{"transformedAt":"2026-08-18T18:33:20.319Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":17,"totalLines":671,"estimatedTokens":7776}}1054{"id":"stack-53859327","source":"stackoverflow","questionId":53859327,"title":"How to configure multiple exchanges in laravel-queue-rabbitmq?","tags":["laravel","laravel-5","rabbitmq","laravel-queue"],"text":"Title: How to configure multiple exchanges in laravel-queue-rabbitmq?\nTags: laravel, laravel-5, rabbitmq, laravel-queue\nSource: Stack Overflow\n\nQuestion:\nI have found famous library for using RabbitMQ in Laravel.\n\nIn configuration `config/queue.php` \nI can specify only one exchange and queue name.\nDoes it \nsupport multiple exchanges?\n\n========================================\n\nTop Answer:\nOr another ugly way could be to set config like this\n\n```\nConfig::set('queue.connections.rabbitmq.options.queue.exchange', 'exchange_two');\n```\n\nbefore dispatching the job to the new exchange. In this way you dont have to create a duplicate connection just setting new exchange name before dispatching the job to the new exchange.\n\n========================================\n\nCode:\n```text\nconfig/queue.php\n```\n\n```text\n'conn_one' => [\n\n 'driver' => 'rabbitmq',\n 'queue' => env('RABBITMQ_QUEUE', 'default'),\n 'connection' => PhpAmqpLib\\Connection\\AMQPLazyConnection::class,\n\n 'hosts' => [\n [\n 'host' => env('RABBITMQ_HOST', '127.0.0.1'),\n 'port' => env('RABBITMQ_PORT', 5672),\n 'user' => env('RABBITMQ_USER', 'guest'),\n 'password' => env('RABBITMQ_PASSWORD', 'guest'),\n 'vhost' => env('RABBITMQ_VHOST', '/'),\n ],\n ],\n\n 'options' => [\n 'ssl_options' => [\n 'cafile' => env('RABBITMQ_SSL_CAFILE', null),\n 'local_cert' => env('RABBITMQ_SSL_LOCALCERT', null),\n 'local_key' => env('RABBITMQ_SSL_LOCALKEY', null),\n 'verify_peer' => env('RABBITMQ_SSL_VERIFY_PEER', true),\n 'passphrase' => env('RABBITMQ_SSL_PASSPHRASE', null),\n ],\n 'queue' => [\n 'job' => VladimirYuldashev\\LaravelQueueRabbitMQ\\Queue\\Jobs\\RabbitMQJob::class,\n 'exchange' => 'exchange_two',\n 'exchange_type' => 'fanout',\n ],\n ],\n\n ],\n\n 'conn_two' => [\n 'driver' => 'rabbitmq',\n 'queue' => env('RABBITMQ_QUEUE', 'default'),\n 'connection' => PhpAmqpLib\\Connection\\AMQPLazyConnection::class,\n\n 'hosts' => [\n [\n 'host' => env('RABBITMQ_HOST', '127.0.0.1'),\n 'port' => env('RABBITMQ_PORT', 5672),\n 'user' => env('RABBITMQ_USER', 'guest'),\n 'password' => env('RABBITMQ_PASSWORD', 'guest'),\n 'vhost' => env('RABBITMQ_VHOST', '/'),\n ],\n ],\n\n 'options' => [\n 'ssl_options' => [\n 'cafile' => env('RABBITMQ_SSL_CAFILE', null),\n 'local_cert' => env('RABBITMQ_SSL_LOCALCERT', null),\n 'local_key' => env('RABBITMQ_SSL_LOCALKEY', null),\n 'verify_peer' => env('RABBITMQ_SSL_VERIFY_PEER', true),\n 'passphrase' => env('RABBITMQ_SSL_PASSPHRASE', null),\n ],\n 'queue' => [\n 'job' => VladimirYuldashev\\LaravelQueueRabbitMQ\\Queue\\Jobs\\RabbitMQJob::class,\n 'exchange' => 'exchange_two',\n 'exchange_type' => 'fanout',\n ],\n ],\n ],\n```\n\n```text\nExampleJob::dispach($data)->onConnection('conn_one');\nExampleJob::dispach($data)->onConnection('conn_two');\n```\n\n```text\nonConnection\n```\n\n```text\nConfig::set('queue.connections.rabbitmq.options.queue.exchange', 'exchange_two');\n```\n\n========================================\n\nComments:\n- I mean register some exchange in server side using Laravel, cause now config provides only one exchange name\n- In RabbitMQ you always post messages on an exchange and consume messages from a queue. Still not clear what you mean. I think Laravel refers to exchanges (which are solely a RabbitMQ concept) as Queues in general (SQS, Redis etc.). Did you have a look at this: laravel.com/docs/5.7/queues#connections-vs-queues ?\n- Okay, what does mean exchange configuration in setting of this library?\n- I know I ask why in configuration of this drive there is only one exchange?\n- `'options' => [ 'exchange' => [ 'name' => env('RABBITMQ_EXCHANGE_NAME'),....`\n- Sure, that is question, why this driver supports only one exchange and queue?\n- Maybe you can recommend another more flexible library for Laravel","metadata":{"transformedAt":"2026-08-18T18:33:20.319Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":119,"estimatedTokens":1072}}1055{"id":"stack-25565769","source":"stackoverflow","questionId":25565769,"title":"EasyNetQ with asp.net web api as subscriber","tags":["asp.net-web-api","rabbitmq","easynetq"],"text":"Title: EasyNetQ with asp.net web api as subscriber\nTags: asp.net-web-api, rabbitmq, easynetq\nSource: Stack Overflow\n\nQuestion:\nI have to implement a asp.net web api which acts as a subscriber to rabbitMQ. The windows service is going to publish message to the web api services. There will be more than one instance of web api running on production enviornment. I am not sure how to open up the subscriber channel on web api and keep it open untill the IIS restarts. There will be one publisher and several consumer. \n\nCan anyone please guide with some sample code to start with?\n\nAny help will hugely appreciated\n\n========================================\n\nComments:\n- Excellent reply. just to the point. Thanks very much for the reply. I need to open the subscription in web api on IIS because it acts as a push service for rest of the application. When you say during application_end dispose of objects you mean the subscriberbus.Dispose?\n- Also does ll subscribers with the same objecttype i.e. bus.subscribe(\"localhost\") will get the message when publisher publish with the same object type?\n- Yes, EasyNetQ routes by message type, so subscribers of a type will get all published messages of that type.\n- and subscriber.dispose() does all the magic when application ends? or I need to do anything else?\n- You need to bus.Dispose(); when your application exits. That will shut down all the consumers (subscribers) too.\n- Excellent. Thanks very much for clearing all the doubts\n- you would have an example on github to have a base, because I'm using a Web Api core I don't know how to call the bus.Receive (\"my.paymentsqueue\", ... ?","metadata":{"transformedAt":"2026-08-18T18:33:20.319Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":21,"estimatedTokens":409}}1056{"id":"stack-67047637","source":"stackoverflow","questionId":67047637,"title":"Is it better to keep a Kafka Producer open or to create a new one for each message?","tags":["apache-kafka","rabbitmq","kafka-producer-api"],"text":"Title: Is it better to keep a Kafka Producer open or to create a new one for each message?\nTags: apache-kafka, rabbitmq, kafka-producer-api\nSource: Stack Overflow\n\nQuestion:\nI have data coming in through RabbitMQ. The data is coming in constantly, multiple messages per second.\nI need to forward that data to Kafka.\n\nIn my RabbitMQ delivery callback where I am getting the data from RabbitMQ I have a Kafka producer that immediately sends the recevied messages to Kafka.\nMy question is very simple. Is it better to create a Kafka producer outside of the callback method and use that one producer for all messages or should I create the producer inside the callback method and close it after the message is sent, which means that I am creating a new producer for each message?\n\nIt might be a naive question but I am new to Kafka and so far I did not find a definitive answer on the internet.\n\nEDIT : I am using a Java Kafka client.\n\n========================================\n\nTop Answer:\nKafka producer is stateful. It contains meta info(periodical synced from brokers), send message buffer etc. So create producer for each message is impracticable.\n\n========================================\n\nCode:\n```text\nlibrdkafka\n```\n\n========================================\n\nComments:\n- Which Kafka client are you using, Java, .NET, Go etc.?\n- @ndogac I am using Java. Silly thing to forget to mention..\n- A question. If I am creating a singleton instance of Kafka producer (say in my test framework), when and how do I close it? To give some context, I am using Junit5 and there could be say 10 test classes each having multiple tests that use the same producer. If I use the @AfterAll method, it will close the producer after first test class finishes. So that would not work. Or would it automatically close at the end of test run?\n- @PramodYadav I think this should be a question instead of a comment. One suggestion you can consider in this scenario is to use a counter in your test class to keep track of the producer usage. When the counter gets to `0` in your `AfterAll` method, you can close the producer. Remember to cover error handling (what if `createProducer` fails?) and handle concurrency (`usageCount` variable needs to be safely incremented and decremented across threads).\n- Thanks for your reply @ndogac. I found an answer for this question here: stackoverflow.com/questions/43282798/…","metadata":{"transformedAt":"2026-08-18T18:33:20.319Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":35,"estimatedTokens":600}}1057{"id":"stack-46251855","source":"stackoverflow","questionId":46251855,"title":"Docker service start after server restart","tags":["ubuntu","docker","service","rabbitmq"],"text":"Title: Docker service start after server restart\nTags: ubuntu, docker, service, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm struggling with dockers (17) on Ubuntu(14). I have to run rabbitMQ on a couple of machines using docker technology. I managed to do that on one of them using\n\n```\nsudo docker service create -d --hostname my-rabbit --name some-rabbit -e RABBITMQ_DEFAULT_USER=user -e RABBITMQ_DEFAULT_PASS=password rabbitmq:3-management\n```\n\nbut i encounter a problem on others. When i run Rabbit as a docker service everything is OK, but the problem starts after restarting the machine. After server reboot the docker is started automaticaly- i run \n\n```\nsudo docker service list\nsudo docker ps\n```\n\nto check that. But when I want to connect to the rabbitServer using the browser nothing happens. When i use curl or wget inside the servier it waits for the response and nothing happens. when i run \n\n```\nsudo service docker restart\n```\n\nthen everything starts to work like it should. the ports are open all the time, and the info is saved so after restart i dont have to reopen them. One of the machines does not have this problem and everything works even after restart\n\n========================================\n\nTop Answer:\nI believe it is because your docker daemon and / or containers doesn't start when you reboot the machine. To achieve that you should do something as follows:\n\n```\nsudo systemctl enable docker\n```\n\nThis should start the Docker daemon after you reboot the host. Then what you will have to do is when you run the service is to pass\n\n```\n--restart-condition:any\n```\n\nWhich should start your containers in case or a system failure or reboot in this case.\n\n========================================\n\nCode:\n```text\nsudo docker service create -d --hostname my-rabbit --name some-rabbit -e RABBITMQ_DEFAULT_USER=user -e RABBITMQ_DEFAULT_PASS=password rabbitmq:3-management\n```\n\n```text\nsudo docker service list\nsudo docker ps\n```\n\n```text\nsudo service docker restart\n```\n\n```text\nsudo systemctl enable docker\n```\n\n```text\n--restart-condition:any\n```\n\n========================================\n\nComments:\n- after restart when i run **sudo docker service list** the rabbit server is in the result, also when i run **sudo docker ps** the rabbit is there too. doesn't it mean the the deamon is running after server restart?\n- @TajnosAgentos well I believe if after rebooting and once you run those commands then yes the docker daemon has successfully started as well as the rabbit container(s).\n- `docker ps` automatically starts the docker service. @sergiu on docs.docker.com/engine/install/linux-postinstall/… they recommend `sudo systemctl enable docker.service` and `sudo systemctl enable containerd.service`. Could you explain the difference?\n- @velop the differences between those 2 is that: containerd is a kernel abstraction which allows other software projects to use it and run containers, whereas Docker is a high level interface that allows you to build images and run containers from the terminal. Docker uses containerd as the container runtime.","metadata":{"transformedAt":"2026-08-18T18:33:20.319Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":74,"estimatedTokens":772}}1058{"id":"stack-60985922","source":"stackoverflow","questionId":60985922,"title":"RabbitMQ : Difference between \"message-ttl\" and \"expiration\"","tags":["rabbitmq"],"text":"Title: RabbitMQ : Difference between \"message-ttl\" and \"expiration\"\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nWhat is the real difference between `expiration` and `message-ttl` in RabbitMQ?\n\nI've read the documentation (https://www.rabbitmq.com/ttl.html) but still isn't clear.\n\n========================================\n\nCode:\n```text\nexpiration\n```\n\n```text\nmessage-ttl\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.319Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":19,"estimatedTokens":96}}1059{"id":"stack-50625793","source":"stackoverflow","questionId":50625793,"title":"MassTransit with RabbitMQ: messages deduplication","tags":["rabbitmq","messaging","masstransit"],"text":"Title: MassTransit with RabbitMQ: messages deduplication\nTags: rabbitmq, messaging, masstransit\nSource: Stack Overflow\n\nQuestion:\nI am using `MassTransit` with `RabbitMQ` at transport layer, and faced the need of messages deduplication.\n\nAdding new massage to the queue should be skipped if duplicated message already queued (even if that message is processing by consumer). Duplicates could be identified by content of message for example.\n\nSending `DoWork1, DoWork2, DoWork3` could be processed in parallel, but sending `DoWork1, DoWork2, DoWork2` - duplicate should be skipped, and as far as `DoWork1, DoWork2` processed same messages could be enqueued and should not be supposed as duplicates.\n\nSolution 1: use \"RabbitMQ Message Deduplication Plugin\" at the exchange layer, ideal as for me, but not sure that solves described problem.\n\nSolution 2: implement custom middleware with third party data storage.\n\nIs there any better solution for described problem?\n\nThanks for help in advance!\n\n========================================\n\nCode:\n```text\nMassTransit\n```\n\n```text\nRabbitMQ\n```\n\n```text\nDoWork1, DoWork2, DoWork3\n```\n\n```text\nDoWork1, DoWork2, DoWork2\n```\n\n```text\nDoWork1, DoWork2\n```\n\n```text\nx-deduplication-header\n```\n\n========================================\n\nComments:\n- How are the duplicates being generated?\n- For example when publisher sends several same messages\n- These aren't \"same messages\" then since they have different message ids\n- @AlexeyZimarev technically, they aren't, logically, they are. interested in how to solve something similar.\n- I've tried to use the above plugin, also with MassTransit, but cannot get it to work at the queue level without turning off PublisherConfirmation. If PublisherConfirmation is on then the Send operation just hangs when it strikes a duplicate. It looks like this was a known issue (github.com/noxdafox/rabbitmq-message-deduplication/issues/2‌​1) but still doesn't seem to be working. Are other people having a similar problem?\n- github.com/noxdafox/rabbitmq-message-deduplication/issues/…","metadata":{"transformedAt":"2026-08-18T18:33:20.319Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":55,"estimatedTokens":519}}1060{"id":"stack-18844799","source":"stackoverflow","questionId":18844799,"title":"MassTransit RabbitMQ Node distribution","tags":["rabbitmq","esb","masstransit"],"text":"Title: MassTransit RabbitMQ Node distribution\nTags: rabbitmq, esb, masstransit\nSource: Stack Overflow\n\nQuestion:\nI'm investigating using MassTransit with RabbitMQ in our application as an ESB. The main benefit I'm looking for is adding durable asynchronous messaging processing to the incoming data stream.\n\nOur application profile has two parts:\n\nIncoming data stream\n\n- One way messaging\n\n- Processed asynchronously\n\n- 10k+ messages per minute\n\nWebsite activity\n\n- Two way\n\n- Ideally use c# async await language features but requires data in both directions\n\n- \n\nThe web app messaging isn't a necessity but would be nice to the same mechanism to full abstract away data access through the ESB.\n\n**Questions:**\n\nFrom what I've read; an ESB node should not know or care about any other node on the bus, it should just do it's own work and send messages onto the bus, waiting for replies if/when required. To me that means each web / app server would have it's own local clustered queue.\nIs this assumption correct?\n\nIf that is correct; how would I programmatically add machines to the cluster? Are there any gotchas I need to be aware of?\n\nIf this is not correct; how would I manage the queue cluster? Creating a dedicated cluster has it's own problems such as DNS entries, load-balancing for redundancy / offline nodes, etc\n\nI'm down with the functionality ESBs can add along with MassTransit's implementation however I am a little clouded with the logistics of the best practices of where / how to set it up in a durable configuration.\n\nThanks for any feedback & advice\n\n**Update**\nWe are utilising EC2 for machine infrastructure, in particular we use availability zones to minimise any data center outages. With this configuration we have 3 zones, each zone has a web server, app server and db server (Couchbase). We also utilise EC2's load balancers to load between the zones.\n\n@Travis: Do you have any experience / advice of using MT / RMQ within Amazon's EC2?\n\n========================================\n\nTop Answer:\nWe run a different approach to Travis.\nEvery machine that has a service that consumes/processes or publishes messages are also nodes in the RabbitMq cluster.\nEvery machine then only has to address RabbitMq via localhost\n\nEach service is on more than one machine\nTo achieve this we are using Competing consumers (i.e. multiple machines will be reading from the same clustered queue (but via localhost))\nSo your architecture has to allow for parallel processing of messages.\n\nIf a machine goes down, there is at least another one that has the dead machines services. \n\nIf lots of machines go down, there are other machines with all the messages stored and you can deploy the services to them.\n\n========================================\n\nComments:\n- I don't have any experience with EC2 and RabbitMQ. We have a private data center for our software. Clustered RabbitMQ instances sound like what you need though. Then your application only am cares about the central location of your RabbitMQ cluster. App parts won't care about where they live.\n- Yeah, that is the same point I've arrived at too. I'll be looking at a mirrored clustered configuration to use HA message durability. I need to figure out if it's worth trying a grid approach where RabbitMQ will be installed on each machine that will host a process that interacts with the cluster, or if a hub and spoke approach with dedicated messaging servers behind a load balancer (as your example) would be best. Thanks for your input @Travis.\n- I took too long on my edit and had to make another comment. I'll updated my question with a few more details to try and give you a clearer picture of what my environment is.\n- Hey Mike, did you end up going with the \"local cluster nodes\" example that Adam suggested, or the cluster behind a load-balanced setup that Travis uses? Travis, do you mind weighing in on Adam's suggestion, and why you went with the load balanced cluster instead? I'm assuming to reduce the cluster synchronization traffic to all the nodes giving better scale, right?\n- Mike's setup does work. But if a machine is lost connection to the cluster it's useless anyways - at least to us. Besides we have websites that we want lightweight as possible instead of having RMQ on those machines.\n- Hi Adam - thanks for your reply. I've come up with a very similar pattern as I like allowing my services to talk to the service bus via local host.\n- I know this is a fairly old question, but having spent a few months trying to use this approach, I found that cluster partitions were very hard to avoid with so many nodes running on production machines. Do you see that too, or do you just have an exceptionally reliable network between machines?\n- we only ever had 4 nodes. Wasnt a problem for us, they are all in the same datacenter? I.e. not over VPN's or anything.\n- We had 2 disk nodes on dedicated machines and 8 ram nodes for the various servers. All in the same datacenter. I wasn't ever able to find a good reason why some nodes would lose visibility of others, and it didn't happen very often. But when it did happen the recovery was often way harder than I expected, and all the time my live application(s) had no message bus. We've fallen back to using a small number of core disk nodes and I'm looking at setting up a load balancer now, which is how I came across this question again","metadata":{"transformedAt":"2026-08-18T18:33:20.319Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":72,"estimatedTokens":1344}}1061{"id":"stack-56999451","source":"stackoverflow","questionId":56999451,"title":"How to add a timeout to method start_consuming() on pika library","tags":["python","rabbitmq","pika"],"text":"Title: How to add a timeout to method start_consuming() on pika library\nTags: python, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI have a `BlockingConnection`, and I the examples of pika documentation. But in all of them, the example of code to start consuming messages are:\n\n```\nconnection = pika.BlockingConnection()\nchannel = connection.channel()\nchannel.basic_consume('test', on_message)\ntry:\n channel.start_consuming()\nexcept KeyboardInterrupt:\n channel.stop_consuming()\nconnection.close()\n```\n\n(with more or less details).\n\nI have to code many scripts, and I want to run one after another (for test/research purposes). But the above code require that I added ^C in each one.\n\nI try to add some timeouts explained in the documentation, but I haven't luck. For example, if I find a parameter for set if client don't consuming any message in the last X seconds, then script finish. Is this posible in pika lib? or I have to change the approach?\n\n========================================\n\nTop Answer:\nIt's too late but perhaps someone gets benefited from that. You can use `blocked_connection_timeout` argument in `pika.ConnectionParameters()` as follows,\n\n```\nconnection = pika.BlockingConnection(\n pika.ConnectionParameters(\n heartbeat=600,\n blocked_connection_timeout=600,\n host=self.queue_host,\n port=constants.RABBTIMQ_PORT,\n virtual_host=self.rabbitmq_virtual_host,\n credentials=pika.PlainCredentials(\n username=self.rabbitmq_username,\n password=self.rabbitmq_password\n )\n )\n )\n```\n\n========================================\n\nCode:\n```py\nconnection = pika.BlockingConnection()\nchannel = connection.channel()\nchannel.basic_consume('test', on_message)\ntry:\n channel.start_consuming()\nexcept KeyboardInterrupt:\n channel.stop_consuming()\nconnection.close()\n```\n\n```text\nBlockingConnection\n```\n\n```text\nstart_consuming\n```\n\n```text\nSelectConnection\n```\n\n```text\nconsume\n```\n\n```text\nconsume\n```\n\n```py\nimport pika\n\nparameters = pika.ConnectionParameters(host=\"localhost\")\nconnection = pika.BlockingConnection(parameters)\nchannel = connection.channel()\n\ndef ack_message(channel, method):\n \"\"\"Note that `channel` must be the same pika channel instance via which\n the message being ACKed was retrieved (AMQP protocol constraint).\n \"\"\"\n if channel.is_open:\n channel.basic_ack(method.delivery_tag)\n else:\n # Channel is already closed, so we can't ACK this message;\n # log and/or do something that makes sense for your app in this case.\n pass\n\ndef callback(channel,method, properties, body):\n ack_message(channel,method)\n print(\"body\",body, flush=True)\n\nchannel.basic_consume(\n queue=\"hello\", on_message_callback=callback)\n\nchannel.start_consuming()\nconnection.close()\n```\n\n```text\nconnection = pika.BlockingConnection(\n pika.ConnectionParameters(\n heartbeat=600,\n blocked_connection_timeout=600,\n host=self.queue_host,\n port=constants.RABBTIMQ_PORT,\n virtual_host=self.rabbitmq_virtual_host,\n credentials=pika.PlainCredentials(\n username=self.rabbitmq_username,\n password=self.rabbitmq_password\n )\n )\n )\n```\n\n```text\nblocked_connection_timeout\n```\n\n```text\npika.ConnectionParameters()\n```\n\n========================================\n\nComments:\n- You want your code to automatically kill the consumer after a certain amount of time. Is that right?\n- @bumblebee Ok, thats could be an option. But this \"amount of time\" should be after don't exists more message in the queue. For Example, in C++ client you can to set a timeout.","metadata":{"transformedAt":"2026-08-18T18:33:20.319Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":137,"estimatedTokens":903}}1062{"id":"stack-76152741","source":"stackoverflow","questionId":76152741,"title":"Amazon MQ: Using RabbitMQ with Stomp","tags":["amazon-web-services","rabbitmq","amazon-mq"],"text":"Title: Amazon MQ: Using RabbitMQ with Stomp\nTags: amazon-web-services, rabbitmq, amazon-mq\nSource: Stack Overflow\n\nQuestion:\nIs there a way to configure Amazon MQs RabbitMQ to work with the Stomp protocol? I know you need a plugin for RabbitMQ to be able to use Stomp, but I can't find how I would install the plugin on the Amazon MQ instance.","metadata":{"transformedAt":"2026-08-18T18:33:20.319Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":6,"estimatedTokens":86}}1063{"id":"stack-66462079","source":"stackoverflow","questionId":66462079,"title":"Celery task does not get send to broker","tags":["python","docker","rabbitmq","celery","kombu"],"text":"Title: Celery task does not get send to broker\nTags: python, docker, rabbitmq, celery, kombu\nSource: Stack Overflow\n\nQuestion:\nWhen I try to send my task to broker (RabbitMQ) it hangs.\n\n```\n# python shell\npromise = foo.s(first_arg=\"2\").apply_async()\n# blocking indefinitely. I expected a promise object.\n```\n\nIf I run the task synchronously it works as expected.\n\n```\n# python shell\npromise = foo.s(first_arg=\"2\").apply()\n>>> hello argument 2\n```\n\nIf I interrupt `.apply_async()` with ctrl+c I get a traceback with some clues:\n\n```\nTraceback (most recent call last):\n File \"/usr/local/lib/python3.7/site-packages/kombu/utils/functional.py\", line 32, in __call__\n return self.__value__\nAttributeError: 'ChannelPromise' object has no attribute '__value__'\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/usr/local/lib/python3.7/site-packages/amqp/transport.py\", line 173, in _connect\n host, port, family, socket.SOCK_STREAM, SOL_TCP)\n File \"/usr/local/lib/python3.7/socket.py\", line 752, in getaddrinfo\n for res in _socket.getaddrinfo(host, port, family, type, proto, flags):\nsocket.gaierror: [Errno -9] Address family for hostname not supported\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/usr/local/lib/python3.7/site-packages/kombu/utils/functional.py\", line 325, in retry_over_time\n return fun(*args, **kwargs)\n File \"/usr/local/lib/python3.7/site-packages/kombu/connection.py\", line 866, in _connection_factory\n self._connection = self._establish_connection()\n File \"/usr/local/lib/python3.7/site-packages/kombu/connection.py\", line 801, in _establish_connection\n conn = self.transport.establish_connection()\n File \"/usr/local/lib/python3.7/site-packages/kombu/transport/pyamqp.py\", line 128, in establish_connection\n conn.connect()\n File \"/usr/local/lib/python3.7/site-packages/amqp/connection.py\", line 323, in connect\n self.transport.connect()\n File \"/usr/local/lib/python3.7/site-packages/amqp/transport.py\", line 113, in connect\n self._connect(self.host, self.port, self.connect_timeout)\n File \"/usr/local/lib/python3.7/site-packages/amqp/transport.py\", line 184, in _connect\n \"failed to resolve broker hostname\"))\n File \"/usr/local/lib/python3.7/site-packages/amqp/transport.py\", line 197, in _connect\n self.sock.connect(sa)\nConnectionRefusedError: [Errno 111] Connection refused\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"\", line 1, in \n File \"/usr/local/lib/python3.7/site-packages/celery/canvas.py\", line 225, in apply_async\n return _apply(args, kwargs, **options)\n File \"/usr/local/lib/python3.7/site-packages/celery/app/task.py\", line 565, in apply_async\n **options\n File \"/usr/local/lib/python3.7/site-packages/celery/app/base.py\", line 749, in send_task\n amqp.send_task_message(P, name, message, **options)\n File \"/usr/local/lib/python3.7/site-packages/celery/app/amqp.py\", line 532, in send_task_message\n **properties\n File \"/usr/local/lib/python3.7/site-packages/kombu/messaging.py\", line 178, in publish\n exchange_name, declare,\n File \"/usr/local/lib/python3.7/site-packages/kombu/connection.py\", line 525, in _ensured\n return fun(*args, **kwargs)\n File \"/usr/local/lib/python3.7/site-packages/kombu/messaging.py\", line 184, in _publish\n channel = self.channel\n File \"/usr/local/lib/python3.7/site-packages/kombu/messaging.py\", line 206, in _get_channel\n channel = self._channel = channel()\n File \"/usr/local/lib/python3.7/site-packages/kombu/utils/functional.py\", line 34, in __call__\n value = self.__value__ = self.__contract__()\n File \"/usr/local/lib/python3.7/site-packages/kombu/messaging.py\", line 221, in \n channel = ChannelPromise(lambda: connection.default_channel)\n File \"/usr/local/lib/python3.7/site-packages/kombu/connection.py\", line 884, in default_channel\n self._ensure_connection(**conn_opts)\n File \"/usr/local/lib/python3.7/site-packages/kombu/connection.py\", line 439, in _ensure_connection\n callback, timeout=timeout\n File \"/usr/local/lib/python3.7/site-packages/kombu/utils/functional.py\", line 339, in retry_over_time\n sleep(1.0)\n```\n\nThe broker connection string looks like this in the system:\n\n```\n~$ env | grep BROKER\nCELERY_BROKER=pyamqp://guest@172.23.0.3//\n```\n\nThe broker connection string in python:\n\n```\n# python shell\nfrom src.celery import app\napp.pool.connection\n>>> Connection: amqp://guest:**@localhost:5672//\n```\n\nBefore you suggest that RabbitMQ is not running, or the connection string is bad; my celery worker (consumer) process is able to connect with the same connection string.\n\n```\n-------------- celery@f9ab48fc6b63 v5.0.5 (singularity)\n--- ***** -----\n-- ******* ---- Linux-4.15.0-20-generic-x86_64-with-debian-9.12 2021-03-05 07:56:29\n- *** --- * ---\n- ** ---------- [config]\n- ** ---------- .> app: celery_statst_api:0x7f15b6de0450\n- ** ---------- .> transport: amqp://guest:**@my-rabbit:5672//\n- ** ---------- .> results: postgresql://docker:**@pg_db:5432/\n- *** --- * --- .> concurrency: 16 (prefork)\n-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)\n--- ***** -----\n -------------- [queues]\n .> celery exchange=celery(direct) key=celery\n\n[tasks]\n . foo_task\n . (long list of tasks)\n\n[2021-03-05 07:56:30,564: INFO/MainProcess] Connected to amqp://guest:**@my-rabbit:5672//\n[2021-03-05 07:56:30,581: INFO/MainProcess] mingle: searching for neighbors\n[2021-03-05 07:56:31,622: INFO/MainProcess] mingle: all alone\n[2021-03-05 07:56:31,647: INFO/MainProcess] celery@f9ab48fc6b63 ready.\n```\n\nThis is how I connect app/producer to the broker.\nThe file celeryconfig.py contains setup for broker url backend, concurrency, etc.\n\n```\n# celery_tasks.py\n# imports...\napp = Celery('celery_statst_api')\napp.config_from_object(celeryconfig) # import config file\n\n@app.task(name=\"foo\")\ndef foo(first_arg: str) -> str:\n print(f\"thanks for {first_arg}\")\n return \"OK\"\n```\n\n========================================\n\nCode:\n```py\n# python shell\npromise = foo.s(first_arg=\"2\").apply_async()\n# blocking indefinitely. I expected a promise object.\n```\n\n```py\n# python shell\npromise = foo.s(first_arg=\"2\").apply()\n>>> hello argument 2\n```\n\n```text\nTraceback (most recent call last):\n File \"/usr/local/lib/python3.7/site-packages/kombu/utils/functional.py\", line 32, in __call__\n return self.__value__\nAttributeError: 'ChannelPromise' object has no attribute '__value__'\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/usr/local/lib/python3.7/site-packages/amqp/transport.py\", line 173, in _connect\n host, port, family, socket.SOCK_STREAM, SOL_TCP)\n File \"/usr/local/lib/python3.7/socket.py\", line 752, in getaddrinfo\n for res in _socket.getaddrinfo(host, port, family, type, proto, flags):\nsocket.gaierror: [Errno -9] Address family for hostname not supported\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/usr/local/lib/python3.7/site-packages/kombu/utils/functional.py\", line 325, in retry_over_time\n return fun(*args, **kwargs)\n File \"/usr/local/lib/python3.7/site-packages/kombu/connection.py\", line 866, in _connection_factory\n self._connection = self._establish_connection()\n File \"/usr/local/lib/python3.7/site-packages/kombu/connection.py\", line 801, in _establish_connection\n conn = self.transport.establish_connection()\n File \"/usr/local/lib/python3.7/site-packages/kombu/transport/pyamqp.py\", line 128, in establish_connection\n conn.connect()\n File \"/usr/local/lib/python3.7/site-packages/amqp/connection.py\", line 323, in connect\n self.transport.connect()\n File \"/usr/local/lib/python3.7/site-packages/amqp/transport.py\", line 113, in connect\n self._connect(self.host, self.port, self.connect_timeout)\n File \"/usr/local/lib/python3.7/site-packages/amqp/transport.py\", line 184, in _connect\n \"failed to resolve broker hostname\"))\n File \"/usr/local/lib/python3.7/site-packages/amqp/transport.py\", line 197, in _connect\n self.sock.connect(sa)\nConnectionRefusedError: [Errno 111] Connection refused\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\n File \"/usr/local/lib/python3.7/site-packages/celery/canvas.py\", line 225, in apply_async\n return _apply(args, kwargs, **options)\n File \"/usr/local/lib/python3.7/site-packages/celery/app/task.py\", line 565, in apply_async\n **options\n File \"/usr/local/lib/python3.7/site-packages/celery/app/base.py\", line 749, in send_task\n amqp.send_task_message(P, name, message, **options)\n File \"/usr/local/lib/python3.7/site-packages/celery/app/amqp.py\", line 532, in send_task_message\n **properties\n File \"/usr/local/lib/python3.7/site-packages/kombu/messaging.py\", line 178, in publish\n exchange_name, declare,\n File \"/usr/local/lib/python3.7/site-packages/kombu/connection.py\", line 525, in _ensured\n return fun(*args, **kwargs)\n File \"/usr/local/lib/python3.7/site-packages/kombu/messaging.py\", line 184, in _publish\n channel = self.channel\n File \"/usr/local/lib/python3.7/site-packages/kombu/messaging.py\", line 206, in _get_channel\n channel = self._channel = channel()\n File \"/usr/local/lib/python3.7/site-packages/kombu/utils/functional.py\", line 34, in __call__\n value = self.__value__ = self.__contract__()\n File \"/usr/local/lib/python3.7/site-packages/kombu/messaging.py\", line 221, in <lambda>\n channel = ChannelPromise(lambda: connection.default_channel)\n File \"/usr/local/lib/python3.7/site-packages/kombu/connection.py\", line 884, in default_channel\n self._ensure_connection(**conn_opts)\n File \"/usr/local/lib/python3.7/site-packages/kombu/connection.py\", line 439, in _ensure_connection\n callback, timeout=timeout\n File \"/usr/local/lib/python3.7/site-packages/kombu/utils/functional.py\", line 339, in retry_over_time\n sleep(1.0)\n```\n\n```sh\n~$ env | grep BROKER\nCELERY_BROKER=pyamqp://guest@172.23.0.3//\n```\n\n```py\n# python shell\nfrom src.celery import app\napp.pool.connection\n>>> Connection: amqp://guest:**@localhost:5672//\n```\n\n```text\n-------------- celery@f9ab48fc6b63 v5.0.5 (singularity)\n--- ***** -----\n-- ******* ---- Linux-4.15.0-20-generic-x86_64-with-debian-9.12 2021-03-05 07:56:29\n- *** --- * ---\n- ** ---------- [config]\n- ** ---------- .> app: celery_statst_api:0x7f15b6de0450\n- ** ---------- .> transport: amqp://guest:**@my-rabbit:5672//\n- ** ---------- .> results: postgresql://docker:**@pg_db:5432/\n- *** --- * --- .> concurrency: 16 (prefork)\n-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)\n--- ***** -----\n -------------- [queues]\n .> celery exchange=celery(direct) key=celery\n\n\n[tasks]\n . foo_task\n . (long list of tasks)\n\n[2021-03-05 07:56:30,564: INFO/MainProcess] Connected to amqp://guest:**@my-rabbit:5672//\n[2021-03-05 07:56:30,581: INFO/MainProcess] mingle: searching for neighbors\n[2021-03-05 07:56:31,622: INFO/MainProcess] mingle: all alone\n[2021-03-05 07:56:31,647: INFO/MainProcess] celery@f9ab48fc6b63 ready.\n```\n\n```py\n# celery_tasks.py\n# imports...\napp = Celery('celery_statst_api')\napp.config_from_object(celeryconfig) # import config file\n\n@app.task(name=\"foo\")\ndef foo(first_arg: str) -> str:\n print(f\"thanks for {first_arg}\")\n return \"OK\"\n```\n\n```text\n.apply_async()\n```\n\n```text\nbroker_url\n```\n\n```text\namqp://guest:**@localhost:5672//\n```\n\n========================================\n\nComments:\n- Bonus info: Celery consumer and producer is running in Docker container A. RabbitMQ is running in container B. Container A and B are on the same docker network. I could replace 172.23.0.3 with `my-rabbit` as the amqp address.\n- There should be few more logs after that showing that the connection succeeds, something like: `Connected to amqp://guest:**@172.23.0.3:5672//`. Do you see that?\n- How is the producer connecting to the broker?\n- I have added details on producer connection and also the celery worker log to my first post.\n- I have created a parallel issue on github: github.com/celery/celery/issues/6661\n- A pull request with an informative warning has been accepted. github.com/celery/kombu/pull/1311","metadata":{"transformedAt":"2026-08-18T18:33:20.319Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":10,"totalLines":303,"estimatedTokens":3075}}1064{"id":"stack-34926012","source":"stackoverflow","questionId":34926012,"title":"How to Achieve Concurrency With a Non-Thread-Safe MessageListener","tags":["rabbitmq","spring-amqp","spring-rabbit"],"text":"Title: How to Achieve Concurrency With a Non-Thread-Safe MessageListener\nTags: rabbitmq, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nThe answer to this question explains how to use prototype scope with `` in Spring AMQP when the listener is not thread-safe.\n\nAnother user asked (in a comment) how to configure the same environment using only Java Configuration.\n\n========================================\n\nCode:\n```text\n<rabbit:listener-container/>\n```\n\n```text\n@Bean\npublic SimpleMessageListenerContainer container1() {\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory());\n container.setQueueNames(\"test.mismatch\");\n container.setMessageListener(new MessageListenerAdapter(listener()));\n container.setMismatchedQueuesFatal(true);\n return container;\n}\n\n...\n\n@Bean\npublic SimpleMessageListenerContainer containerN() {\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory());\n container.setQueueNames(\"test.mismatch\");\n container.setMessageListener(new MessageListenerAdapter(listener()));\n container.setMismatchedQueuesFatal(true);\n return container;\n}\n\n@Bean\n@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)\npublic MyNotThreadSafeListener listener() {\n return new MyNotThreadSafeListener();\n}\n```\n\n```text\n@Prototype\n```\n\n```text\nMyNotThreadSafeListener\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.319Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":51,"estimatedTokens":350}}1065{"id":"stack-53124583","source":"stackoverflow","questionId":53124583,"title":"Send celery task message to rabbitmq","tags":["python","django","redis","rabbitmq","celery"],"text":"Title: Send celery task message to rabbitmq\nTags: python, django, redis, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI usually use celery with Django and run shared tasks in Django.\n\nBut for specific case, I want to add task queue to rabbitmq manually without running Django or celerybeat.\n\nIs there any simple python script or shell cmd to do that?\n\n========================================\n\nCode:\n```text\nfrom celery import Celery\n\napp = Celery('app_name', broker='pyamqp://guest@localhost//')\napp.send_task('namespace.my_task', kwargs={\n 'arg1': 'value1',\n 'arg2': 'value2',\n})\n```\n\n```text\nsend_task\n```\n\n========================================\n\nComments:\n- Ah. nice solution. I'll try it and let you know the result.","metadata":{"transformedAt":"2026-08-18T18:33:20.319Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":32,"estimatedTokens":184}}1066{"id":"stack-50587227","source":"stackoverflow","questionId":50587227,"title":"Multiple bindingRoutingKey's for a consumer with Spring Cloud Stream using RabbitMQ","tags":["spring","spring-boot","rabbitmq","spring-cloud-stream"],"text":"Title: Multiple bindingRoutingKey's for a consumer with Spring Cloud Stream using RabbitMQ\nTags: spring, spring-boot, rabbitmq, spring-cloud-stream\nSource: Stack Overflow\n\nQuestion:\nI'd like to configure an input channel in Spring Cloud Stream to be bound to the same exchange (destination) with multiple routing keys. I've managed to get this working with a single routing key like this:\n\n```\nspring:\n cloud:\n stream:\n rabbit:\n bindings:\n input1:\n consumer:\n bindingRoutingKey: key1.#\n bindings:\n input1:\n binder: rabbit\n group: group1\n destination: dest-group1\n```\n\nBut I cannot seem to get it working for multiple keys. I've tried this:\n\n```\nspring:\n cloud:\n stream:\n rabbit:\n bindings:\n input1:\n consumer:\n bindingRoutingKey: key1.#,key2.#\n bindings:\n input1:\n binder: rabbit\n group: group1\n destination: dest-group1\n```\n\nBut this doesn't seem to work.\n\nI'm using Spring Boot 2.0.1 and Spring cloud dependencies are imported from:\n\n```\n\n org.springframework.cloud\n spring-cloud-dependencies\n Finchley.RC1\n pom\n import\n\n```\n\nDoes anyone know how to achieve this?\n\n========================================\n\nTop Answer:\nIt can't be done with properties; but you can declare the additional bindings as beans; see this answer.\n\nThere is also a third party \"advanced\" boot starter that allows you to add declarations in a yaml file. I haven't tried it, but it looks interesting.\n\n========================================\n\nCode:\n```text\nspring:\n cloud:\n stream:\n rabbit:\n bindings:\n input1:\n consumer:\n bindingRoutingKey: key1.#\n bindings:\n input1:\n binder: rabbit\n group: group1\n destination: dest-group1\n```\n\n```text\nspring:\n cloud:\n stream:\n rabbit:\n bindings:\n input1:\n consumer:\n bindingRoutingKey: key1.#,key2.#\n bindings:\n input1:\n binder: rabbit\n group: group1\n destination: dest-group1\n```\n\n```text\n<dependency>\n <groupId>org.springframework.cloud</groupId>\n <artifactId>spring-cloud-dependencies</artifactId>\n <version>Finchley.RC1</version>\n <type>pom</type>\n <scope>import</scope>\n</dependency>\n```\n\n```text\nspring.cloud.stream.rabbit.bindings.<channel-name>.consumer.binding-routing-key-delimiter=,\n```\n\n```text\nspring.cloud.stream.rabbit.bindings.<channel-name>.consumer.binding-routing-key=key1,key2,key3\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.319Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":116,"estimatedTokens":603}}1067{"id":"stack-61137733","source":"stackoverflow","questionId":61137733,"title":"How to retain RabbitMQ user accounts in Docker","tags":["docker","rabbitmq"],"text":"Title: How to retain RabbitMQ user accounts in Docker\nTags: docker, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am having trouble persisting dockerized RabbitMQ user accounts set up through the management panel. Upon restart they disappear and I believe it is related to new *mnesia* databases being created on each restart.\n\nI tried binding a docker volume to `/var/lib/rabbitmq`:\n\n```\nversion: '3.1'\n\nservices:\n\n rabbitmq:\n image: rabbitmq:management-alpine\n volumes:\n - rabbitdata1:/var/lib/rabbitmq/\n ports:\n - \"5672:5672\"\n - \"15672:15672\"\n\nvolumes:\n rabbitdata1:\n driver: local\n```\n\nWhen I look at the contents of the mounted directory, I get:\n\n```\n$ docker exec -ti local_rabbitmq_1 /bin/bash\nbash-5.0# ls /var/lib/rabbitmq/mnesia/\nrabbit@0eceaaa217c8 rabbit@0eceaaa217c8-plugins-expand\nrabbit@0eceaaa217c8-feature_flags rabbit@0eceaaa217c8.pid\n```\n\nBut when I restart the service, it seems like a new instance gets created for the new PID and all changes are lost:\n\n```\n$ docker exec -ti local_rabbitmq_1 /bin/bash\nbash-5.0# ls /var/lib/rabbitmq/mnesia/\nrabbit@0eceaaa217c8 rabbit@ac5afbef3c81\nrabbit@0eceaaa217c8-feature_flags rabbit@ac5afbef3c81-feature_flags\nrabbit@0eceaaa217c8-plugins-expand rabbit@ac5afbef3c81-plugins-expand\nrabbit@0eceaaa217c8.pid rabbit@ac5afbef3c81.pid\n```\n\nI also tried setting the `RABBITMQ_NODENAME` environment variable so that instead of the above `rabbit@0eceaaa217c8` and `rabbit@ac5afbef3c81` I get a constant string for `.pid` and *mnesia* directories but then RabbitMQ would not even restart:\n\n```\n2020-04-10 10:41:34.657 [info] Running boot step database defined by app rabbit\n2020-04-10 10:41:34.685 [error] CRASH REPORT Process with 0 neighbours exited with reason: {{failed_to_cluster_with,[foo@190e6343c238],\"Mnesia could not connect to any nodes.\"},{rabbit,start,[normal,[]]}} in application_master:init/4 line 138\n2020-04-10 10:41:34.686 [info] Application rabbit exited with reason: {{failed_to_cluster_with,[foo@190e6343c238],\"Mnesia could not connect to any nodes.\"},{rabbit,start,[normal,[]]}}\n{\"Kernel pid terminated\",application_controller,\"{application_start_failure,rabbit,{{failed_to_cluster_with,[foo@190e6343c238],\\\"Mnesia could not connect to any nodes.\\\"},{rabbit,start,[normal,[]]}}}\"}\nKernel pid terminated (application_controller) ({application_start_failure,rabbit,{{failed_to_cluster_with,[foo@190e6343c238],\"Mnesia could not connect to any nodes.\"},{rabbit,start,[normal,[]]}}})\n```\n\n**Is there any other way to retain changes between RabbitMQ docker service restarts?**\n\nMaybe there is some other directory that could do the trick?\n\nI checked for other potential candidates but only found `/etc/rabbitmq/` and `/opt/rabbitmq/` which seem like configuration and installation directories respectively:\n\n```\nbash-5.0# find . -name 'rabbitmq'\n./etc/rabbitmq\n./var/log/rabbitmq\n./var/lib/rabbitmq\n./opt/rabbitmq\n./opt/rabbitmq/etc/rabbitmq\n```\n\n========================================\n\nTop Answer:\nCreate Two folders, data and etc\n\nhttps://i.sstatic.net/OqIiA.png\n\nenabled_plugins\n\n```\n[rabbitmq_management,rabbitmq_prometheus].\n```\n\nrabbitmq.conf\n\n```\nauth_mechanisms.1 = PLAIN\n auth_mechanisms.2 = AMQPLAIN\n loopback_users.guest = false\n listeners.tcp.default = 5672\n #default_pass = admin\n #default_user = admin\n hipe_compile = false\n #management.listener.port = 15672\n #management.listener.ssl = false\n management.tcp.port = 15672\n management.load_definitions = /etc/rabbitmq/definitions.json\n```\n\ndefinitions.json\n\n```\n{\n \"users\": [\n {\n \"name\": \"admin\",\n \"password\": \"admin\",\n \"tags\": \"administrator\"\n }\n ],\n \"vhosts\": [\n {\n \"name\": \"/\"\n }\n ],\n \"policies\": [\n {\n \"vhost\": \"/\",\n \"name\": \"ha\",\n \"pattern\": \"\",\n \"apply-to\": \"all\",\n \"definition\": {\n \"ha-mode\": \"all\",\n \"ha-sync-batch-size\": 256,\n \"ha-sync-mode\": \"automatic\"\n },\n \"priority\": 0\n }\n ],\n \"permissions\": [\n {\n \"user\": \"admin\",\n \"vhost\": \"/\",\n \"configure\": \".*\",\n \"write\": \".*\",\n \"read\": \".*\"\n }\n ],\n \"queues\": [\n {\n \"name\": \"job-import.triggered.queue\",\n \"vhost\": \"/\",\n \"durable\": true,\n \"auto_delete\": false,\n \"arguments\": {}\n }\n ],\n \"exchanges\": [\n {\n \"name\": \"lob-proj-dx\",\n \"vhost\": \"/\",\n \"type\": \"direct\",\n \"durable\": true,\n \"auto_delete\": false,\n \"internal\": false,\n \"arguments\": {}\n }\n ],\n \"bindings\": [\n {\n \"source\": \"lob-proj-dx\",\n \"vhost\": \"/\",\n \"destination\": \"job-import.triggered.queue\",\n \"destination_type\": \"queue\",\n \"routing_key\": \"job-import.event.triggered\",\n \"arguments\": {}\n }\n ]\n }\n```\n\nRun Docker\n\n```\ndocker run --restart=always -d -p 5672:5672 -p 15672:15672 --mount type=bind,source=E:\\docker\\rabbit\\data,target=/var/lib/rabbitmq/ --mount type=bind,source=E:\\docker\\rabbit\\etc,target=/etc/rabbitmq/ --name rabbitmq --hostname my-rabbit rabbitmq:3.7.28-management\n```\n\nThings would be persisted across restarts\n\nhttps://i.sstatic.net/4etky.png\n\nTaken from here\n\n========================================\n\nCode:\n```text\nversion: '3.1'\n\nservices:\n\n rabbitmq:\n image: rabbitmq:management-alpine\n volumes:\n - rabbitdata1:/var/lib/rabbitmq/\n ports:\n - \"5672:5672\"\n - \"15672:15672\"\n\nvolumes:\n rabbitdata1:\n driver: local\n```\n\n```text\n$ docker exec -ti local_rabbitmq_1 /bin/bash\nbash-5.0# ls /var/lib/rabbitmq/mnesia/\nrabbit@0eceaaa217c8 rabbit@0eceaaa217c8-plugins-expand\nrabbit@0eceaaa217c8-feature_flags rabbit@0eceaaa217c8.pid\n```\n\n```text\n$ docker exec -ti local_rabbitmq_1 /bin/bash\nbash-5.0# ls /var/lib/rabbitmq/mnesia/\nrabbit@0eceaaa217c8 rabbit@ac5afbef3c81\nrabbit@0eceaaa217c8-feature_flags rabbit@ac5afbef3c81-feature_flags\nrabbit@0eceaaa217c8-plugins-expand rabbit@ac5afbef3c81-plugins-expand\nrabbit@0eceaaa217c8.pid rabbit@ac5afbef3c81.pid\n```\n\n```text\n2020-04-10 10:41:34.657 [info] <0.309.0> Running boot step database defined by app rabbit\n2020-04-10 10:41:34.685 [error] <0.308.0> CRASH REPORT Process <0.308.0> with 0 neighbours exited with reason: {{failed_to_cluster_with,[foo@190e6343c238],\"Mnesia could not connect to any nodes.\"},{rabbit,start,[normal,[]]}} in application_master:init/4 line 138\n2020-04-10 10:41:34.686 [info] <0.44.0> Application rabbit exited with reason: {{failed_to_cluster_with,[foo@190e6343c238],\"Mnesia could not connect to any nodes.\"},{rabbit,start,[normal,[]]}}\n{\"Kernel pid terminated\",application_controller,\"{application_start_failure,rabbit,{{failed_to_cluster_with,[foo@190e6343c238],\\\"Mnesia could not connect to any nodes.\\\"},{rabbit,start,[normal,[]]}}}\"}\nKernel pid terminated (application_controller) ({application_start_failure,rabbit,{{failed_to_cluster_with,[foo@190e6343c238],\"Mnesia could not connect to any nodes.\"},{rabbit,start,[normal,[]]}}})\n```\n\n```text\nbash-5.0# find . -name 'rabbitmq'\n./etc/rabbitmq\n./var/log/rabbitmq\n./var/lib/rabbitmq\n./opt/rabbitmq\n./opt/rabbitmq/etc/rabbitmq\n```\n\n```text\n/var/lib/rabbitmq\n```\n\n```text\nRABBITMQ_NODENAME\n```\n\n```text\nrabbit@0eceaaa217c8\n```\n\n```text\nrabbit@ac5afbef3c81\n```\n\n```text\n.pid\n```\n\n```text\n/etc/rabbitmq/\n```\n\n```text\n/opt/rabbitmq/\n```\n\n```yaml\nservices:\n rabbitmq:\n image: rabbitmq:management-alpine\n hostname: rabbitmq # <-----\n volumes:\n - rabbitdata1:/var/lib/rabbitmq/\n ports:\n - \"5672:5672\"\n - \"15672:15672\"\n```\n\n```text\nrabbitmq\n```\n\n```text\n-h\n```\n\n```text\n--hostname\n```\n\n```text\nhostname:\n```\n\n```text\nhostname:\n```\n\n```text\n[rabbitmq_management,rabbitmq_prometheus].\n```\n\n```text\nauth_mechanisms.1 = PLAIN\n auth_mechanisms.2 = AMQPLAIN\n loopback_users.guest = false\n listeners.tcp.default = 5672\n #default_pass = admin\n #default_user = admin\n hipe_compile = false\n #management.listener.port = 15672\n #management.listener.ssl = false\n management.tcp.port = 15672\n management.load_definitions = /etc/rabbitmq/definitions.json\n```\n\n```text\n{\n \"users\": [\n {\n \"name\": \"admin\",\n \"password\": \"admin\",\n \"tags\": \"administrator\"\n }\n ],\n \"vhosts\": [\n {\n \"name\": \"/\"\n }\n ],\n \"policies\": [\n {\n \"vhost\": \"/\",\n \"name\": \"ha\",\n \"pattern\": \"\",\n \"apply-to\": \"all\",\n \"definition\": {\n \"ha-mode\": \"all\",\n \"ha-sync-batch-size\": 256,\n \"ha-sync-mode\": \"automatic\"\n },\n \"priority\": 0\n }\n ],\n \"permissions\": [\n {\n \"user\": \"admin\",\n \"vhost\": \"/\",\n \"configure\": \".*\",\n \"write\": \".*\",\n \"read\": \".*\"\n }\n ],\n \"queues\": [\n {\n \"name\": \"job-import.triggered.queue\",\n \"vhost\": \"/\",\n \"durable\": true,\n \"auto_delete\": false,\n \"arguments\": {}\n }\n ],\n \"exchanges\": [\n {\n \"name\": \"lob-proj-dx\",\n \"vhost\": \"/\",\n \"type\": \"direct\",\n \"durable\": true,\n \"auto_delete\": false,\n \"internal\": false,\n \"arguments\": {}\n }\n ],\n \"bindings\": [\n {\n \"source\": \"lob-proj-dx\",\n \"vhost\": \"/\",\n \"destination\": \"job-import.triggered.queue\",\n \"destination_type\": \"queue\",\n \"routing_key\": \"job-import.event.triggered\",\n \"arguments\": {}\n }\n ]\n }\n```\n\n```text\ndocker run --restart=always -d -p 5672:5672 -p 15672:15672 --mount type=bind,source=E:\\docker\\rabbit\\data,target=/var/lib/rabbitmq/ --mount type=bind,source=E:\\docker\\rabbit\\etc,target=/etc/rabbitmq/ --name rabbitmq --hostname my-rabbit rabbitmq:3.7.28-management\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.320Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":22,"totalLines":390,"estimatedTokens":2418}}1068{"id":"stack-70439261","source":"stackoverflow","questionId":70439261,"title":"How does Concurrency Limit work in MassTransit RabbitMQ?","tags":["c#","rabbitmq","masstransit"],"text":"Title: How does Concurrency Limit work in MassTransit RabbitMQ?\nTags: c#, rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nI am reading about Concurrency Limit in MassTransit RabbitMQ, but I am still not understanding how it really works.\n\nSupposing I have 4 consumers and I configure the queues with concurrency limit to 1 `config.UseConcurrencyLimit(1);`. When a producer dispatch 4 messages at the same time, what will happen? Just one message will be consumed in just one consumer and all other 3 messages will be discarted?\n\nCould someone explain me how does it work?\n\n========================================\n\nCode:\n```text\nconfig.UseConcurrencyLimit(1);\n```\n\n========================================\n\nComments:\n- It would be a pretty lame - not to mention useless! - message queueing system if it just discarded messages. This is a *concurrency* limit: how many messages can be \"in process\" at a time. When you hit the limit the other messages are kept in the queue until a worker frees up.\n- Though w.r.t. 4 consumers w/ concurrency limit 1 - that doc you linked implies that you couldn't have created 4 consumers if the concurrency limit is 1. Someone who knows more can answer that (or you could experiment and report back).\n- So it also limits the number of concurrent consumers I have consuming the messages? Then If I have 4 consumers and concurrency limit to 1, only one consumer will be consuming the messages at a time. Once a message is consumed, the next one will be consumed and go on.","metadata":{"transformedAt":"2026-08-18T18:33:20.320Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":24,"estimatedTokens":378}}1069{"id":"stack-68952297","source":"stackoverflow","questionId":68952297,"title":"RabbitMQ Delivery Acknowledgement Timeout","tags":["java","amazon-web-services","spring-boot","rabbitmq","amazon-mq"],"text":"Title: RabbitMQ Delivery Acknowledgement Timeout\nTags: java, amazon-web-services, spring-boot, rabbitmq, amazon-mq\nSource: Stack Overflow\n\nQuestion:\nI am using a managed RabbitMQ cluster through AWS Amazon-MQ. If the consumers finish their work quickly then everything is working fine. However, depending on few scenarios few consumers are taking more than 30 mins to complete the processing.\nIn that scenarios, RabbitMQ deletes the consumer and makes the same messages visible again in the queue. Becasue of this another consumer picks it up and starts processing. It is happing in the loop. Therefore the same transaction is getting executed again and I am loosing the consumer as well.\nI am not using any **AcknowledgeMode** so I believe it's AUTO by default and it has 30 mins limit.\nIs there any way to increase the Delivery Acknowledgement Timeout for AUTO mode?\nOr please let me know if anyone has any other solutions for this.\n\n========================================\n\nTop Answer:\nReply From AWS Support:\n\nConsumer timeout is now configurable but can be done only by the service team. The change will be permanent irrespective of any version.\n\nSo you may update RabbitMQ to latest, and no need to stick with 3.8.11. Provide your broker details and desired timeout, they should be able to do it for you.\n\n========================================\n\nCode:\n```text\nconsumer_timeout\n```\n\n========================================\n\nComments:\n- As of now, there does not seem to be a way to change the configuration (rabbitmq.conf) of a managed aws rabbitmq instance. I have tried rabbitmqadmin. There is another tool called rabbitmqctl but I looked at the documentation and there doesn't seem to be an option to modify configuration either. Do you have an option of setting up rabbitmq on an EC2 instance? Then you can modify the rabbitmq.conf directly... # 30 minutes in milliseconds consumer_timeout = 1800000\n- Your other option is to acknowledge messages right away, and then process them...but the problem with that is what happens if a message does not process correctly? It will be not be resent by AMQ again\n- Thank you! This is very helpful, I'll raise an AWS support ticket and see if they have any option to change this.\n- Hope you get an answer and if you do please update us here :). Good luck","metadata":{"transformedAt":"2026-08-18T18:33:20.320Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":34,"estimatedTokens":577}}1070{"id":"stack-69567270","source":"stackoverflow","questionId":69567270,"title":"RabbitMQ pod is crashing unexpectedly","tags":["kubernetes","rabbitmq"],"text":"Title: RabbitMQ pod is crashing unexpectedly\nTags: kubernetes, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have a pod running RabbitMQ. Below is the deployment manifest:\n\n```\napiVersion: v1\nkind: Service\nmetadata:\n name: service-rabbitmq\nspec:\n selector:\n app: service-rabbitmq\n ports:\n - port: 5672\n targetPort: 5672\n---\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: deployment-rabbitmq\nspec:\n selector:\n matchLabels:\n app: deployment-rabbitmq\n template:\n metadata:\n labels:\n app: deployment-rabbitmq\n spec:\n containers:\n - name: rabbitmq\n image: rabbitmq:latest\n volumeMounts:\n - name: rabbitmq-data-volume\n mountPath: /var/lib/rabbitmq\n resources:\n requests:\n cpu: 250m\n memory: 128Mi\n limits:\n cpu: 750m\n memory: 256Mi\n volumes:\n - name: rabbitmq-data-volume\n persistentVolumeClaim:\n claimName: rabbitmq-pvc\n```\n\nWhen I deploy it in my local cluster, I see the pod running for a while and then crashing afterwards. So basically it goes under crash-loop. Following is the logs I got from the pod:\n\n```\n$ kubectl logs deployment-rabbitmq-649b8479dc-kt9s4\n2021-10-14 06:46:36.182390+00:00 [info] Feature flags: list of feature flags found:\n2021-10-14 06:46:36.221717+00:00 [info] Feature flags: [ ] implicit_default_bindings\n2021-10-14 06:46:36.221768+00:00 [info] Feature flags: [ ] maintenance_mode_status\n2021-10-14 06:46:36.221792+00:00 [info] Feature flags: [ ] quorum_queue\n2021-10-14 06:46:36.221813+00:00 [info] Feature flags: [ ] stream_queue\n2021-10-14 06:46:36.221916+00:00 [info] Feature flags: [ ] user_limits\n2021-10-14 06:46:36.221933+00:00 [info] Feature flags: [ ] virtual_host_metadata\n2021-10-14 06:46:36.221953+00:00 [info] Feature flags: feature flag states written to disk: yes\n2021-10-14 06:46:37.018537+00:00 [noti] Application syslog exited with reason: stopped\n2021-10-14 06:46:37.018646+00:00 [noti] Logging: switching to configured handler(s); following messages may not be visible in this log output\n2021-10-14 06:46:37.045601+00:00 [noti] Logging: configured log handlers are now ACTIVE\n2021-10-14 06:46:37.635024+00:00 [info] ra: starting system quorum_queues\n2021-10-14 06:46:37.635139+00:00 [info] starting Ra system: quorum_queues in directory: /var/lib/rabbitmq/mnesia/rabbit@deployment-rabbitmq-649b8479dc-kt9s4/quorum/rabbit@deployment-rabbitmq-649b8479dc-kt9s4\n2021-10-14 06:46:37.849041+00:00 [info] ra: meta data store initialised for system quorum_queues. 0 record(s) recovered\n2021-10-14 06:46:37.877504+00:00 [noti] WAL: ra_log_wal init, open tbls: ra_log_open_mem_tables, closed tbls: ra_log_closed_mem_tables\n```\n\nThis log isn't helpful too much, I can't find any error message from here. The only useful line here could be `Application syslog exited with reason: stopped`, only but it's not as far as I understand. The event log isn't helpful too:\n\n```\n$ kubectl describe pods deployment-rabbitmq-649b8479dc-kt9s4\nName: deployment-rabbitmq-649b8479dc-kt9s4\nNamespace: default\nPriority: 0\nNode: docker-desktop/192.168.65.4\nStart Time: Thu, 14 Oct 2021 12:45:03 +0600\nLabels: app=deployment-rabbitmq\n pod-template-hash=649b8479dc\n skaffold.dev/run-id=7af5e1bb-e0c8-4021-a8a0-0c8bf43630b6\nAnnotations: \nStatus: Running\nIP: 10.1.5.138\nIPs:\n IP: 10.1.5.138\nControlled By: ReplicaSet/deployment-rabbitmq-649b8479dc\nContainers:\n rabbitmq:\n Container ID: docker://de309f94163c071afb38fb8743d106923b6bda27325287e82bc274e362f1f3be\n Image: rabbitmq:latest\n Image ID: docker-pullable://rabbitmq@sha256:d8efe7b818e66a13fdc6fdb84cf527984fb7d73f52466833a20e9ec298ed4df4\n Port: \n Host Port: \n State: Waiting\n Reason: CrashLoopBackOff\n Last State: Terminated\n Reason: OOMKilled\n Exit Code: 0\n Started: Thu, 14 Oct 2021 13:56:29 +0600\n Finished: Thu, 14 Oct 2021 13:56:39 +0600\n Ready: False\n Restart Count: 18\n Limits:\n cpu: 750m\n memory: 256Mi\n Requests:\n cpu: 250m\n memory: 128Mi\n Environment: \n Mounts:\n /var/lib/rabbitmq from rabbitmq-data-volume (rw)\n /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-9shdv (ro)\nConditions:\n Type Status\n Initialized True\n Ready False\n ContainersReady False\n PodScheduled True\nVolumes:\n rabbitmq-data-volume:\n Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)\n ClaimName: rabbitmq-pvc\n ReadOnly: false\n kube-api-access-9shdv:\n Type: Projected (a volume that contains injected data from multiple sources)\n TokenExpirationSeconds: 3607\n ConfigMapName: kube-root-ca.crt\n ConfigMapOptional: \n DownwardAPI: true\nQoS Class: Burstable\nNode-Selectors: \nTolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s\n node.kubernetes.io/unreachable:NoExecute op=Exists for 300s\nEvents:\n Type Reason Age From Message\n ---- ------ ---- ---- -------\n Normal Pulled 23m (x6 over 50m) kubelet (combined from similar events): Successfully pulled image \"rabbitmq:latest\" in 4.267310231s\n Normal Pulling 18m (x16 over 73m) kubelet Pulling image \"rabbitmq:latest\"\n Warning BackOff 3m45s (x307 over 73m) kubelet Back-off restarting failed container\n```\n\nWhat could be the reason for this crash-loop?\n\n**NOTE:** `rabbitmq-pvc` is successfully bound. No issue there.\n\n### Update:\n\nThis answer indicates that RabbitMQ should be deployed as **StatefulSet**. So I adjusted the manifest like so:\n\n```\napiVersion: v1\nkind: Service\nmetadata:\n name: service-rabbitmq\nspec:\n selector:\n app: service-rabbitmq\n ports:\n - name: rabbitmq-amqp\n port: 5672\n - name: rabbitmq-http\n port: 15672\n---\napiVersion: apps/v1\nkind: StatefulSet\nmetadata:\n name: statefulset-rabbitmq\nspec:\n selector:\n matchLabels:\n app: statefulset-rabbitmq\n serviceName: service-rabbitmq\n template:\n metadata:\n labels:\n app: statefulset-rabbitmq\n spec:\n containers:\n - name: rabbitmq\n image: rabbitmq:latest\n volumeMounts:\n - name: rabbitmq-data-volume\n mountPath: /var/lib/rabbitmq/mnesia\n resources:\n requests:\n cpu: 250m\n memory: 128Mi\n limits:\n cpu: 750m\n memory: 256Mi\n volumes:\n - name: rabbitmq-data-volume\n persistentVolumeClaim:\n claimName: rabbitmq-pvc\n```\n\nThe pod still undergoes crash-loop, but the logs are slightly different.\n\n```\n$ kubectl logs statefulset-rabbitmq-0\n2021-10-14 09:38:26.138224+00:00 [info] Feature flags: list of feature flags found:\n2021-10-14 09:38:26.158953+00:00 [info] Feature flags: [x] implicit_default_bindings\n2021-10-14 09:38:26.159015+00:00 [info] Feature flags: [x] maintenance_mode_status\n2021-10-14 09:38:26.159037+00:00 [info] Feature flags: [x] quorum_queue\n2021-10-14 09:38:26.159078+00:00 [info] Feature flags: [x] stream_queue\n2021-10-14 09:38:26.159183+00:00 [info] Feature flags: [x] user_limits\n2021-10-14 09:38:26.159236+00:00 [info] Feature flags: [x] virtual_host_metadata\n2021-10-14 09:38:26.159270+00:00 [info] Feature flags: feature flag states written to disk: yes\n2021-10-14 09:38:26.830814+00:00 [noti] Application syslog exited with reason: stopped\n2021-10-14 09:38:26.830925+00:00 [noti] Logging: switching to configured handler(s); following messages may not be visible in this log output\n2021-10-14 09:38:26.852048+00:00 [noti] Logging: configured log handlers are now ACTIVE\n2021-10-14 09:38:33.754355+00:00 [info] ra: starting system quorum_queues\n2021-10-14 09:38:33.754526+00:00 [info] starting Ra system: quorum_queues in directory: /var/lib/rabbitmq/mnesia/rabbit@statefulset-rabbitmq-0/quorum/rabbit@statefulset-rabbitmq-0\n2021-10-14 09:38:33.760365+00:00 [info] ra: meta data store initialised for system quorum_queues. 0 record(s) recovered\n2021-10-14 09:38:33.761023+00:00 [noti] WAL: ra_log_wal init, open tbls: ra_log_open_mem_tables, closed tbls: ra_log_closed_mem_tables\n```\n\nThe feature flags are now marked as it's seen. No other notable changes. So I still need help.\n\n### ! New Issue !\n\nHead over here.\n\n========================================\n\nCode:\n```yaml\napiVersion: v1\nkind: Service\nmetadata:\n name: service-rabbitmq\nspec:\n selector:\n app: service-rabbitmq\n ports:\n - port: 5672\n targetPort: 5672\n---\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: deployment-rabbitmq\nspec:\n selector:\n matchLabels:\n app: deployment-rabbitmq\n template:\n metadata:\n labels:\n app: deployment-rabbitmq\n spec:\n containers:\n - name: rabbitmq\n image: rabbitmq:latest\n volumeMounts:\n - name: rabbitmq-data-volume\n mountPath: /var/lib/rabbitmq\n resources:\n requests:\n cpu: 250m\n memory: 128Mi\n limits:\n cpu: 750m\n memory: 256Mi\n volumes:\n - name: rabbitmq-data-volume\n persistentVolumeClaim:\n claimName: rabbitmq-pvc\n```\n\n```text\n$ kubectl logs deployment-rabbitmq-649b8479dc-kt9s4\n2021-10-14 06:46:36.182390+00:00 [info] <0.222.0> Feature flags: list of feature flags found:\n2021-10-14 06:46:36.221717+00:00 [info] <0.222.0> Feature flags: [ ] implicit_default_bindings\n2021-10-14 06:46:36.221768+00:00 [info] <0.222.0> Feature flags: [ ] maintenance_mode_status\n2021-10-14 06:46:36.221792+00:00 [info] <0.222.0> Feature flags: [ ] quorum_queue\n2021-10-14 06:46:36.221813+00:00 [info] <0.222.0> Feature flags: [ ] stream_queue\n2021-10-14 06:46:36.221916+00:00 [info] <0.222.0> Feature flags: [ ] user_limits\n2021-10-14 06:46:36.221933+00:00 [info] <0.222.0> Feature flags: [ ] virtual_host_metadata\n2021-10-14 06:46:36.221953+00:00 [info] <0.222.0> Feature flags: feature flag states written to disk: yes\n2021-10-14 06:46:37.018537+00:00 [noti] <0.44.0> Application syslog exited with reason: stopped\n2021-10-14 06:46:37.018646+00:00 [noti] <0.222.0> Logging: switching to configured handler(s); following messages may not be visible in this log output\n2021-10-14 06:46:37.045601+00:00 [noti] <0.222.0> Logging: configured log handlers are now ACTIVE\n2021-10-14 06:46:37.635024+00:00 [info] <0.222.0> ra: starting system quorum_queues\n2021-10-14 06:46:37.635139+00:00 [info] <0.222.0> starting Ra system: quorum_queues in directory: /var/lib/rabbitmq/mnesia/rabbit@deployment-rabbitmq-649b8479dc-kt9s4/quorum/rabbit@deployment-rabbitmq-649b8479dc-kt9s4\n2021-10-14 06:46:37.849041+00:00 [info] <0.259.0> ra: meta data store initialised for system quorum_queues. 0 record(s) recovered\n2021-10-14 06:46:37.877504+00:00 [noti] <0.264.0> WAL: ra_log_wal init, open tbls: ra_log_open_mem_tables, closed tbls: ra_log_closed_mem_tables\n```\n\n```text\n$ kubectl describe pods deployment-rabbitmq-649b8479dc-kt9s4\nName: deployment-rabbitmq-649b8479dc-kt9s4\nNamespace: default\nPriority: 0\nNode: docker-desktop/192.168.65.4\nStart Time: Thu, 14 Oct 2021 12:45:03 +0600\nLabels: app=deployment-rabbitmq\n pod-template-hash=649b8479dc\n skaffold.dev/run-id=7af5e1bb-e0c8-4021-a8a0-0c8bf43630b6\nAnnotations: <none>\nStatus: Running\nIP: 10.1.5.138\nIPs:\n IP: 10.1.5.138\nControlled By: ReplicaSet/deployment-rabbitmq-649b8479dc\nContainers:\n rabbitmq:\n Container ID: docker://de309f94163c071afb38fb8743d106923b6bda27325287e82bc274e362f1f3be\n Image: rabbitmq:latest\n Image ID: docker-pullable://rabbitmq@sha256:d8efe7b818e66a13fdc6fdb84cf527984fb7d73f52466833a20e9ec298ed4df4\n Port: <none>\n Host Port: <none>\n State: Waiting\n Reason: CrashLoopBackOff\n Last State: Terminated\n Reason: OOMKilled\n Exit Code: 0\n Started: Thu, 14 Oct 2021 13:56:29 +0600\n Finished: Thu, 14 Oct 2021 13:56:39 +0600\n Ready: False\n Restart Count: 18\n Limits:\n cpu: 750m\n memory: 256Mi\n Requests:\n cpu: 250m\n memory: 128Mi\n Environment: <none>\n Mounts:\n /var/lib/rabbitmq from rabbitmq-data-volume (rw)\n /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-9shdv (ro)\nConditions:\n Type Status\n Initialized True\n Ready False\n ContainersReady False\n PodScheduled True\nVolumes:\n rabbitmq-data-volume:\n Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)\n ClaimName: rabbitmq-pvc\n ReadOnly: false\n kube-api-access-9shdv:\n Type: Projected (a volume that contains injected data from multiple sources)\n TokenExpirationSeconds: 3607\n ConfigMapName: kube-root-ca.crt\n ConfigMapOptional: <nil>\n DownwardAPI: true\nQoS Class: Burstable\nNode-Selectors: <none>\nTolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s\n node.kubernetes.io/unreachable:NoExecute op=Exists for 300s\nEvents:\n Type Reason Age From Message\n ---- ------ ---- ---- -------\n Normal Pulled 23m (x6 over 50m) kubelet (combined from similar events): Successfully pulled image \"rabbitmq:latest\" in 4.267310231s\n Normal Pulling 18m (x16 over 73m) kubelet Pulling image \"rabbitmq:latest\"\n Warning BackOff 3m45s (x307 over 73m) kubelet Back-off restarting failed container\n```\n\n```yaml\napiVersion: v1\nkind: Service\nmetadata:\n name: service-rabbitmq\nspec:\n selector:\n app: service-rabbitmq\n ports:\n - name: rabbitmq-amqp\n port: 5672\n - name: rabbitmq-http\n port: 15672\n---\napiVersion: apps/v1\nkind: StatefulSet\nmetadata:\n name: statefulset-rabbitmq\nspec:\n selector:\n matchLabels:\n app: statefulset-rabbitmq\n serviceName: service-rabbitmq\n template:\n metadata:\n labels:\n app: statefulset-rabbitmq\n spec:\n containers:\n - name: rabbitmq\n image: rabbitmq:latest\n volumeMounts:\n - name: rabbitmq-data-volume\n mountPath: /var/lib/rabbitmq/mnesia\n resources:\n requests:\n cpu: 250m\n memory: 128Mi\n limits:\n cpu: 750m\n memory: 256Mi\n volumes:\n - name: rabbitmq-data-volume\n persistentVolumeClaim:\n claimName: rabbitmq-pvc\n```\n\n```text\n$ kubectl logs statefulset-rabbitmq-0\n2021-10-14 09:38:26.138224+00:00 [info] <0.222.0> Feature flags: list of feature flags found:\n2021-10-14 09:38:26.158953+00:00 [info] <0.222.0> Feature flags: [x] implicit_default_bindings\n2021-10-14 09:38:26.159015+00:00 [info] <0.222.0> Feature flags: [x] maintenance_mode_status\n2021-10-14 09:38:26.159037+00:00 [info] <0.222.0> Feature flags: [x] quorum_queue\n2021-10-14 09:38:26.159078+00:00 [info] <0.222.0> Feature flags: [x] stream_queue\n2021-10-14 09:38:26.159183+00:00 [info] <0.222.0> Feature flags: [x] user_limits\n2021-10-14 09:38:26.159236+00:00 [info] <0.222.0> Feature flags: [x] virtual_host_metadata\n2021-10-14 09:38:26.159270+00:00 [info] <0.222.0> Feature flags: feature flag states written to disk: yes\n2021-10-14 09:38:26.830814+00:00 [noti] <0.44.0> Application syslog exited with reason: stopped\n2021-10-14 09:38:26.830925+00:00 [noti] <0.222.0> Logging: switching to configured handler(s); following messages may not be visible in this log output\n2021-10-14 09:38:26.852048+00:00 [noti] <0.222.0> Logging: configured log handlers are now ACTIVE\n2021-10-14 09:38:33.754355+00:00 [info] <0.222.0> ra: starting system quorum_queues\n2021-10-14 09:38:33.754526+00:00 [info] <0.222.0> starting Ra system: quorum_queues in directory: /var/lib/rabbitmq/mnesia/rabbit@statefulset-rabbitmq-0/quorum/rabbit@statefulset-rabbitmq-0\n2021-10-14 09:38:33.760365+00:00 [info] <0.290.0> ra: meta data store initialised for system quorum_queues. 0 record(s) recovered\n2021-10-14 09:38:33.761023+00:00 [noti] <0.302.0> WAL: ra_log_wal init, open tbls: ra_log_open_mem_tables, closed tbls: ra_log_closed_mem_tables\n```\n\n```text\nApplication syslog exited with reason: stopped\n```\n\n```text\nrabbitmq-pvc\n```\n\n========================================\n\nComments:\n- Which version of Kubernetes did you use and how did you set up the cluster? Did you use bare metal installation or some cloud providor? It is important to reproduce your problem.\n- Client: 1.22. Server: 1.21. Cluster is in my local machine, running Windows 10 Pro and WSL2 (Debian). Just copy the above manifest and apply it to the cluster. Then watch the pod. You'll see **Running**-**OOMKilled**-**CrashLoopBackOff** states cycling through.\n- for the new issue, please create separate question.\n- Done. Feel free to check it out. Link in the question above.\n- How much resources should I allocate? Right now it's set to `250m` - `750m` for CPU and `128Mi` - `256Mi` for RAM. I couldn't find any recommended values anywhere.\n- Try doubling the values. A rabbitmq normally requires 256 mb but it seems that it is to less in your case.\n- An issue, sir, with the pod. Now I adjusted the resources and it's successfully running now, I'm having another issue. I've edited the original question, and now I'm waiting for you to edit your answer by solving the issue I've put. Thanks in advance - I really appreciate your help.\n- Ask a new question please.. Do not change or extend your question if it is answered\n- I thought it's related, so I extended. Well, I'll drop a new question then.","metadata":{"transformedAt":"2026-08-18T18:33:20.320Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":7,"totalLines":450,"estimatedTokens":4290}}1071{"id":"stack-48851467","source":"stackoverflow","questionId":48851467,"title":"Why is HTTP not a messaging protocol? (according to RabbitMQ)","tags":["http","rabbitmq","amqp","stomp"],"text":"Title: Why is HTTP not a messaging protocol? (according to RabbitMQ)\nTags: http, rabbitmq, amqp, stomp\nSource: Stack Overflow\n\nQuestion:\nIn this RabbitMQ documentation, MQTT, AMQP and STOMP are referred to as supported message protocols. If you consider the differences between MQTT, AMQP and STOMP, this is completely understandable to me. \nHowever, at the end of this article it becomes confusing. That's about HTTP. This paragraph states that \"HTTP is not a course not a messaging protocol\". I had thought that HTTP would also be directly supported by RabbitMQ in one way or another, but is only supported for 'low volume messaging purposes' ( diagnostics for example) and for direct use in HTML. \nIf half the world uses HTTP web api services, why HTTP could not be shared among the messaging protocols. Why is HTTP not a messaging protocol and what is the definition RabbitMQ uses of a messaging protocol?\n\n========================================\n\nComments:\n- Thanks for the answer. The categorization synchronous request-response versus asynchronous message passing protocols I was looking for. Can I simply state that HTTP is synchronous communication between one sender and one receiver and that *messaging* is asynchronous communication between one sender and one or multiple recipients, where a broker or a stack on both sides provides mechanisms like queuing, acknowledgements, time outs ... on top of the protocol ?\n- From the standpoint of the protocol, they are different. HTTP often (though not always) creates a new TCP connection with each successive request to the server, and it has its own handshake, etc. AMQP, for example, is much different down at the actual protocol (bits/bytes) level and how it manages the socket. Which is one reason why you're gonna have a tough time with firewalls.\n- @CoffeCold right, a messaging product will handle the local storage (queuing) and retry/reliability out-of-the-box. And speaking of firewalls, they are *the* reason why sometimes one uses HTTP/S as the transport protocol for higher layer messaging protocols. Outbound HTTP/S connectivity is ubiquitous.","metadata":{"transformedAt":"2026-08-18T18:33:20.320Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":15,"estimatedTokens":529}}1072{"id":"stack-47331469","source":"stackoverflow","questionId":47331469,"title":"Easiest way to construct @RabbitListener at runtime","tags":["java","rabbitmq","spring-integration","amqp","spring-amqp"],"text":"Title: Easiest way to construct @RabbitListener at runtime\nTags: java, rabbitmq, spring-integration, amqp, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nWhat would be the easiest way to construct this at runtime?\n\n```\n@RabbitListener(bindings = @QueueBinding(\n value = @Queue(value = \"providedAtRuntime\", durable = \"true\"),\n exchange = @Exchange(value = \"providedAtRuntime\", ignoreDeclarationExceptions = \"true\"),\n key = \"providedAtRuntime\"), containerFactory = \"cFac\")\npublic class RabbitProcessor {\n @RabbitHandler\n public void receive (String smth){\n System.out.println(smth);\n }\n}\n```\n\nI would like to define the listener, but provide exchange, queue name and binding at runtime. Also this listener should not start automatically, but when called by start() method. At same time it should auto-declare bindings and queues etc. When called stop(), it should just stop consuming.\n\n========================================\n\nCode:\n```text\n@RabbitListener(bindings = @QueueBinding(\n value = @Queue(value = \"providedAtRuntime\", durable = \"true\"),\n exchange = @Exchange(value = \"providedAtRuntime\", ignoreDeclarationExceptions = \"true\"),\n key = \"providedAtRuntime\"), containerFactory = \"cFac\")\npublic class RabbitProcessor {\n @RabbitHandler\n public void receive (String smth){\n System.out.println(smth);\n }\n}\n```\n\n```text\npublic static AbstractMessageListenerContainer startListening(RabbitAdmin rabbitAdmin, Queue queue, Exchange exchange, String key, MessageListener messageListener) {\n rabbitAdmin.declareBinding(BindingBuilder.bind(queue).to(exchange).with(key).noargs());\n SimpleMessageListenerContainer listener = new SimpleMessageListenerContainer(rabbitAdmin.getRabbitTemplate().getConnectionFactory());\n listener.addQueues(queue);\n listener.setMessageListener(messageListener);\n listener.start();\n\n return listener;\n}\n```\n\n```text\nConfigurableApplicationContext ctx = SpringApplication.run(DemoApplication.class, args);\n\n ConnectionFactory connectionFactory = ctx.getBean(ConnectionFactory.class);\n RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);\n AbstractMessageListenerContainer container = startListening(rabbitAdmin, rabbitAdmin.declareQueue(),\n new DirectExchange(\"amq.direct\"), \"testRoute\", message -> {\n System.out.println(new String(message.getBody()));\n });\n```\n\n```text\nSimpleMessageListenerContainer\n```\n\n```text\nAbstractMessageListenerContainer.destroy()\n```\n\n```text\nAbstractMessageListenerContainer.stop()\n```\n\n========================================\n\nComments:\n- this? stackoverflow.com/questions/14268981/…\n- Thanks. I knew about this approach. I just wanted to check if there is something even easier than this - without using rabbitAdmin directly.\n- No, there is nothing because it's just impossible or won't be efficient.\n- @Artem Bilan - is there guarantee that queues, exchanges and bindings will be redeclared on connection lost? also will listener container reconnect automatically?\n- It is done if everything are beans in the application context and `RabbitAdmin` really takes care about recreation entities on connection reconnect. See this JIRA for more info: jira.spring.io/browse/AMQP-758\n- here is an old link from spring forum. it may be helpful. forum.spring.io/forum/spring-projects/integration/amqp/…","metadata":{"transformedAt":"2026-08-18T18:33:20.320Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":82,"estimatedTokens":835}}1073{"id":"stack-62392316","source":"stackoverflow","questionId":62392316,"title":"RabbitMq check if message exists in queue","tags":["c#","rabbitmq"],"text":"Title: RabbitMq check if message exists in queue\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm looking the best way for know if a RabbitMq message is processed or exists in queue. I have my Web Management that sends messages to my queue with a loot of traffic. My app checks in the database, during 1 minute if the consumer insert the new data on the database but if is not inserted the app shows a error, that the data is not inserted. The problem is in the case of high demand the delay can be a lot of time, and the data can be inserted after of the delay and the user of the Web Management don´t know if the data was inserted and the user can try to send another message to the queue. I need to know if is possible **check if a message exists in the queue** or know if the message was processed.","metadata":{"transformedAt":"2026-08-18T18:33:20.320Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":6,"estimatedTokens":203}}1074{"id":"stack-48133417","source":"stackoverflow","questionId":48133417,"title":"AWS classic LB changing IPs/dropping connections results in lost messages on RabbitMQ","tags":["amazon-web-services","rabbitmq","load-balancing","amqp","amazon-elb"],"text":"Title: AWS classic LB changing IPs/dropping connections results in lost messages on RabbitMQ\nTags: amazon-web-services, rabbitmq, load-balancing, amqp, amazon-elb\nSource: Stack Overflow\n\nQuestion:\nI run a rabbit HA cluster with 3 nodes and a classic AWS load-balancer(LB) in front of them. There are two apps, one that publishes and the other one that consumes through the LB. \nhttps://i.sstatic.net/vJsfo.png\nWhen publisher app starts sending 3 million messages, after short period of time its connection is put into Flow Control state. After the publishing is finished, in publisher app logs I can see that all 3 million messages are sent. On the other hand in consumer app log I can only see 500K - 1M messages (varies between runs), which means that the large number of messages is lost.\n\nSo what is happening is that in the middle of a run, classic LB decides to change its IP address or drop connections, thus loosing a lot of messages (see my update for more details).\n\nThe issue does not occur if I skip LB and hit the nodes directly, doing load-balancing on app side. Of course in this case I lose all the benefits of ELB.\n\nMy question are:\n\n- Why is LB changing IP addresses and dropping connections, is that related to high message rate from publisher or Flow Control state?\n\n- How to configure LB, so that this issue doesn't occur?\n\n**UPDATE:**\n\nThis is my understanding what is happening:\nI use AMQP 0-9-1 and publish without '*publish confirms*', so message is considered sent as soon as it's put on a wire. Also, the connection on rabbitmq node is between LB and a node, not Publisher app and a node. \n\nBefore the communication enters Flow Control, messages are passed from LB to a node immediately\nhttps://i.sstatic.net/O35Ld.png\n\nThen the connection between LB and a node enters Flow Control, Publisher App connection is not blocked and thus it continues to publish at the same rate. That causes messages to pile up on LB.\nhttps://i.sstatic.net/KrBpM.png\n\nThen LB decides to change IP(s) or drop the connection for whatever reasons and create a new one, causing all the piled messages to be lost. This is clearly visible from the RabbitMQ logs:\n\n=WARNING REPORT==== 6-Jan-2018::10:35:50 ===\nclosing AMQP connection (10.1.1.250:29564 -> 10.1.1.223:5672):\nclient unexpectedly closed TCP connection\n\n=INFO REPORT==== 6-Jan-2018::10:35:51 ===\naccepting AMQP connection (10.1.1.22:1886 -> 10.1.1.223:5672)\n\nhttps://i.sstatic.net/Yqptw.png\n\n========================================\n\nTop Answer:\nELBs will change their addresses when they scale in reaction to traffic. New nodes come up, and appear in DNS, and then old nodes may go away eventually, or they may stay online.\n\nIt increases capacity by utilizing either larger resources (resources with higher performance characteristics) or more individual resources. The Elastic Load Balancing service will update the Domain Name System (DNS) record of the load balancer when it scales so that the new resources have their respective IP addresses registered in DNS. The DNS record that is created includes a Time-to-Live (TTL) setting of 60 seconds, **with the expectation that clients will re-lookup the DNS at least every 60 seconds.** *(emphasis added)*\n\n— from “Best Practices in Evaluating Elastic Load Balancing”\n\nYou may find more useful information in that \"best practices\" guide, including the concept of pre-warming a balancer with the help of AWS support, and how to ramp up your test traffic in a way that the balancer's scaling can keep up.\n\nThe behavior of a classic ELB is automatic, and not configurable by the user.\n\nBut it also sounds as if you have configuration issues with your queue, because it seems like it should be more resilient to dropped connections.\n\nNote also that an AWS **Network Load Balancer** does not change its IP addresses and does not need to scale by replacing resources the way ELB does, because unlike ELB, it doesn't appear to run on hidden instances -- it's part of the network infrastructure, or at least appears that way. This might be a viable alternative.\n\n========================================\n\nComments:\n- using Network LB does fix the problem. I updated my question with explanation. Thanks","metadata":{"transformedAt":"2026-08-18T18:33:20.320Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":62,"estimatedTokens":1052}}1075{"id":"stack-20550313","source":"stackoverflow","questionId":20550313,"title":"How to get number of messages in queue with node-amqp","tags":["node.js","rabbitmq","amqp"],"text":"Title: How to get number of messages in queue with node-amqp\nTags: node.js, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI'm using node-amqp as a queueing system in a node application. I'd like to be able to monitor the state of the queue to figure out if we have enough workers runnning, i.e. if the queue size is increasing we know we are starting to fall behind.\n\nI know that from the command line you can use something like;\n\n```\nrabbitmqctl list_queues\n```\n\nWhich gives me the exact information I need, but I was wondering if there is anyway to do this from node-amqp itself?\n\nThanks in advance.\n\n**EDIT**\n\nIn the end, I just used the command line tool rabbitmqctl to get the information I need, its not a great solution but here is what I did;\n\n```\nvar Logger = require('arsenic-logger');\n\ngetQueueMeta(function(info){\n Logger.info(info);\n});\n\n/**\n* Returns a sparse array with the queue names as the indices\n* and the number of messages as the value, e.g.;\n*\n* info = [ my-queue: 9, my-other-queue: 1 ]\n* \n* @param callback\n*/\nfunction getQueueMeta(callback){\n\n var sys = require('sys')\n var exec = require('child_process').exec;\n\n exec(\"/usr/local/sbin/rabbitmqctl list_queues\", function(error, stdout, stderr) {\n\n var info = [];\n\n if (!error){\n\n var lines = stdout.split(/\\n/);\n\n if (lines.length > 1){\n\n for (var i=1; i<lines.length-2; i++){\n var temp = lines[i].split(/\\s/);\n info[temp[0].trim()] = parseInt(temp[1]);\n }\n\n }\n\n }\n\n callback(info);\n\n });\n\n}\n```\n\n========================================\n\nTop Answer:\nSo RabbitMQ supports AMQP up to 0.9.1. You can see the docs directly here.\n\nA quick scan through the docs will reveal that AMQP only covers things like connections, exchanges and basic queuing / dequeuing. However many feature in `rabbitmqctl` are simply not accessible via AMQP spec. In that way `rabbitmqctl` is much closer to a \"management\" tool where the AMQP connection is basically a \"consumer\" tool.\n\nThat stated, you may be in luck. Take a look at the `connection.queue()` method.\n\n```\nvar q = connection.queue('my-queue', function (queue) {\n console.log('Queue ' + queue.name + ' is open');\n});\n```\n\nIn the .NET implementation it looks like that `queue` variable includes not just the name, but also the Count of Consumers and Messages. I'm not clear what's available in the node.js, you may have to dig in.\n\n========================================\n\nCode:\n```text\nrabbitmqctl list_queues\n```\n\n```text\nvar Logger = require('arsenic-logger');\n\ngetQueueMeta(function(info){\n Logger.info(info);\n});\n\n/**\n* Returns a sparse array with the queue names as the indices\n* and the number of messages as the value, e.g.;\n*\n* info = [ my-queue: 9, my-other-queue: 1 ]\n* \n* @param callback\n*/\nfunction getQueueMeta(callback){\n\n var sys = require('sys')\n var exec = require('child_process').exec;\n\n exec(\"/usr/local/sbin/rabbitmqctl list_queues\", function(error, stdout, stderr) {\n\n var info = [];\n\n if (!error){\n\n var lines = stdout.split(/\\n/);\n\n if (lines.length > 1){\n\n for (var i=1; i<lines.length-2; i++){\n var temp = lines[i].split(/\\s/);\n info[temp[0].trim()] = parseInt(temp[1]);\n }\n\n }\n\n }\n\n callback(info);\n\n });\n\n}\n```\n\n```text\nvar connection = require(\"amqp\").createConnection();\nconnection.exchange(\"exampleExchange\", {/*...*/}, function(exchange) {\n connection.queue(\"exampleQueue\", {/*...*/}, function(queue, messageCount, consumerCount){\n console.log(\"Message count\", messageCount);\n console.log(\"Consumer count\", consumerCount);\n });\n});\n```\n\n```text\nvar q = connection.queue('my-queue', function (queue) {\n console.log('Queue ' + queue.name + ' is open');\n});\n```\n\n```text\nrabbitmqctl\n```\n\n```text\nrabbitmqctl\n```\n\n```text\nconnection.queue()\n```\n\n```text\nqueue\n```\n\n========================================\n\nComments:\n- Thanks, looking at the source code for node-amqp and inspecting the queue object sadly there is no message or consumer count (that I can see)\n- Yes, I looked at the code in node-AMQP and it's not populating. That stated, if the .NET and Java libraries are capable of pulling it, it's quite likely that the data exists and is simply not being exposed.\n- Not sure why but I'm using version 0.5.2 and it doesn't expose those properties.\n- @HoangTrinh sorry, node-amqp library on NPM used to point to this repository and my comment was referring to it: github.com/postwait/node-amqp\n- This works, but I needed to set \"passive: true\" inside the queue option.","metadata":{"transformedAt":"2026-08-18T18:33:20.320Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":177,"estimatedTokens":1143}}1076{"id":"stack-35008083","source":"stackoverflow","questionId":35008083,"title":"CentOS running RabbitMQ failed to create a trace file and log on other vhost remotely","tags":["linux","rabbitmq"],"text":"Title: CentOS running RabbitMQ failed to create a trace file and log on other vhost remotely\nTags: linux, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nWe have installed and run RabbitMQ on a CentOS server. Although it is OK to create a trace file using Firehose tracer from the management console on another computer remotely in the vhost that is under permission ofthe guest user, it is failed to create the same log file remotely in the other vhosts which are not under permission of the guest user. \n\nFor instance, in the figure below, we simply create the testLogTracer on the test vhost but it is failed to create the same log file testLogTracer2 on test2 vhost. The only difference between the two vhosts is that the guest user has permission over the test vhost.\n\nhttps://i.sstatic.net/YHhpx.png\n\nUpdate:\n\nThe latest server error which is added to the file rabbit@server79.log at the time of creating the trace file represented below:\n\n```\n=ERROR REPORT==== 26-Jan-2016::13:13:19 ===\nwebmachine error: path=\"/api/traces/hafizTest/newTraceFile\"\n\"Bad Request\"\n```\n\nAlso user \"moha\" has full permission like user \"guest\" over both vhost \"test\" and \"test2\". The permission over both virtual hosts represented in figures below.\n\nhttps://i.sstatic.net/tHOq8.png\nhttps://i.sstatic.net/A7LQJ.png\n\n========================================\n\nTop Answer:\nIt seems a permission problem.\n\nPlease read this post: https://groups.google.com/d/msg/rabbitmq-users/uA9qmADgpSo/Cib3fEFwDgAJ \n\n Please check the permission on your virtualhost, this error can\n happens if you don't have the right permission.\n\n \n here is and example:\n\n```\n=INFO REPORT==== 4-Jan-2016::15:49:38 ===\nAdding vhost 'myvhost'\n\n=INFO REPORT==== 4-Jan-2016::15:49:57 ===\nEnabling tracing for vhost 'myvhost'\n\n=ERROR REPORT==== 4-Jan-2016::15:49:57 ===\nwebmachine error: path=\"/api/traces/myvhost/myvhostlog\"\n\"Bad Request\"\n\n=INFO REPORT==== 4-Jan-2016::15:50:04 ===\nSetting permissions for 'guest' in 'myvhost' to '.*', '.*', '.*'\n\n=INFO REPORT==== 4-Jan-2016::15:50:08 ===\nDisabling tracing for vhost 'myvhost'\n\n=INFO REPORT==== 4-Jan-2016::15:50:18 ===\nEnabling tracing for vhost 'myvhost'\n\n=INFO REPORT==== 4-Jan-2016::15:50:18 ===\nTracer opened log file \"/var/tmp/rabbitmq-tracing/myvhostlog.log\"\n\n-\nGabriele\n```\n\n========================================\n\nCode:\n```text\n=ERROR REPORT==== 26-Jan-2016::13:13:19 ===\nwebmachine error: path=\"/api/traces/hafizTest/newTraceFile\"\n\"Bad Request\"\n```\n\n```text\n{rabbitmq_tracing, \n [{username, \"user\"},\n {password, \"pass\"}]\n },\n```\n\n```text\nrabbitmq_tracing.username\n```\n\n```text\nrabbitmq_tracing.password\n```\n\n```text\n/etc/rabbitmq\n```\n\n```text\n=INFO REPORT==== 4-Jan-2016::15:49:38 ===\nAdding vhost 'myvhost'\n\n=INFO REPORT==== 4-Jan-2016::15:49:57 ===\nEnabling tracing for vhost 'myvhost'\n\n=ERROR REPORT==== 4-Jan-2016::15:49:57 ===\nwebmachine error: path=\"/api/traces/myvhost/myvhostlog\"\n\"Bad Request\"\n\n=INFO REPORT==== 4-Jan-2016::15:50:04 ===\nSetting permissions for 'guest' in 'myvhost' to '.*', '.*', '.*'\n\n=INFO REPORT==== 4-Jan-2016::15:50:08 ===\nDisabling tracing for vhost 'myvhost'\n\n=INFO REPORT==== 4-Jan-2016::15:50:18 ===\nEnabling tracing for vhost 'myvhost'\n\n=INFO REPORT==== 4-Jan-2016::15:50:18 ===\nTracer opened log file \"/var/tmp/rabbitmq-tracing/myvhostlog.log\"\n\n-\nGabriele\n```\n\n```text\n2018-07-10 20:37:34 =SUPERVISOR REPORT====\n Supervisor: {<0.11027.6>,rabbit_tracing_consumer_sup}\n Context: start_error\n Reason: {{badmatch,{error,not_allowed}},[{rabbit_tracing_consumer,init,1,[{file,\"src/rabbit_tracing_consumer.erl\"},{line,58}]},{gen_server,init_it,2,[{file,\"gen_server.erl\"},{line,365}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,333}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,247}]}]}\n Offender: [{pid,undefined},{name,consumer},{mfargs,{rabbit_tracing_consumer,start_link,[[{vhost,<<\"my_vhost\">>},{name,<<\"my_log_file\">>},{format,<<\"text\">>},{pattern,<<\"#\">>},{<<\"format\">>,<<\"text\">>},{<<\"name\">>,<<\"my_log_file\">>},{<<\"pattern\">>,<<\"#\">>},{<<\"vhost\">>,<<\"my_vhost\">>}]]}},{restart_type,transient},{shutdown,30000},{child_type,worker}\n```\n\n```text\nnot_allowed\n```\n\n```text\nguest\n```\n\n========================================\n\nComments:\n- `gues` user is valid only in localhost ! try with another user\n- @Gabriele I know what you said. But it is a different situation. I can't create a log file remotely in order to trace messages in a specified vhost, unless guest user has permission over that vhost.\n- Could you post the server log?\n- It is the only error which is added to the file rabbit@server79.log in Linux.\n- I have updated my question again, I want to know if it is mandatory to grant user guest all permissions over any virtual host?\n- Before the 3.6.0, Tracing connection has credentials hardcoded to \"guest\". Please read here:github.com/rabbitmq/rabbitmq-tracing/issues/1\n- Dear @Gabriele , tnx for your patience in advance, I've checked the RabbitMQ version just right now and it is 3.6.0, so it shouldn't face this problem. It is obvious from the first screenshot attached to the question.","metadata":{"transformedAt":"2026-08-18T18:33:20.320Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":147,"estimatedTokens":1274}}1077{"id":"stack-39370162","source":"stackoverflow","questionId":39370162,"title":"EasyNetQ Field Not Found 'RabbitMQ.Client.ConnectionFactory.AutomaticRecoveryEnabled'","tags":["c#","rabbitmq","easynetq"],"text":"Title: EasyNetQ Field Not Found 'RabbitMQ.Client.ConnectionFactory.AutomaticRecoveryEnabled'\nTags: c#, rabbitmq, easynetq\nSource: Stack Overflow\n\nQuestion:\nWith EasyNetQ v0.63.0.448, RabbitMqClient v4.0.2 and RabbitMq server 3.6.5 when I try to create a bus like so...\n\n```\nbus = RabbitHutch.CreateBus(new ConnectionConfiguration()\n {\n Hosts = new[] { new HostConfiguration() { Host = hostName, Port = port } },\n UserName = username,\n Password = password,\n }, x => { }).Advanced;\n```\n\nI'm getting the Error:\n\n\"Field Not Found 'RabbitMQ.Client.ConnectionFactory.AutomaticRecoveryEnabled'.\"\n\nIs this an underlying incompatibility between easynetq and this version of Rabbit or is there a change in the API somewhere that I need to reflect?\n\n========================================\n\nCode:\n```text\nbus = RabbitHutch.CreateBus(new ConnectionConfiguration()\n {\n Hosts = new[] { new HostConfiguration() { Host = hostName, Port = port } },\n UserName = username,\n Password = password,\n }, x => { }).Advanced;\n```\n\n========================================\n\nComments:\n- This solved it for me. Nuget automatically updated my app to use RabbitMQ.Client 4.1.0 which doesn't work with my app. I rolled back to 3.6.5 and everything was good again.\n- This is unfortunate, as version 4.1 has some serious performance enhancements (github.com/rabbitmq/rabbitmq-dotnet-client/issues/251).","metadata":{"transformedAt":"2026-08-18T18:33:20.320Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":39,"estimatedTokens":359}}1078{"id":"stack-5341244","source":"stackoverflow","questionId":5341244,"title":"Ruby AMQP persistent message is deleted after restarting RabbitMQ","tags":["ruby","rabbitmq","amqp"],"text":"Title: Ruby AMQP persistent message is deleted after restarting RabbitMQ\nTags: ruby, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI have a ruby script that creates a message using AMQP in RabbitMQ.\n\n```\n# above code sets up config for connecting to RabbitMQ via APMQ\nAMQP.start(:host => 'localhost') do\n amq = MQ.new\n amq.queue('initiate', :durable => true).publish(message_id, :persistent => true)\n AMQP.stop{ EM.stop }\nend\n```\n\nIf the RabbitMQ server is restarted, the message is no longer in the initiate queue (or any queue, for that matter). What am I doing wrong that the message is not persistent? I've also tried explicitly creating a durable exchange, and binding the queue to that exchange, but the message is still deleted after RabbitMQ restart.\n\n========================================\n\nTop Answer:\nAs already mentioned, if you just mark messages as persistent they will not necessarily get persisted straight away, so if the server shuts down unexpectedly they may never end up on disk.\n\nSo what do you do if you **really** need the message to be on disk, even if the server crashes?\n\nThere are two things you can do. One is to wrap your publish in a transaction. When you have committed the transaction, the message will be on disk (if it's not already delivered to a consumer of course). However, this adds a synchronous call to the server, so it can slow you down. If you know you're going to publish a lot of messages, you can wrap a bunch of publishes in a transaction, then when you commit you know they're all on disk.\n\nThe other (higher performance) alternative is to use publish confirms. But these are new in the 2.3.1 server and I don't think any Ruby clients support them yet.\n\nFinally, RabbitMQ will anyway periodically flush persistent messages to disk even in the absence of confirms, transactions and controlled shutdowns. However there's a bug in 2.2.0 which means that this sometimes doesn't happen for a long time, so upgrading to 2.3.1 might be worthwhile.\n\n========================================\n\nCode:\n```text\n# above code sets up config for connecting to RabbitMQ via APMQ\nAMQP.start(:host => 'localhost') do\n amq = MQ.new\n amq.queue('initiate', :durable => true).publish(message_id, :persistent => true)\n AMQP.stop{ EM.stop }\nend\n```\n\n========================================\n\nComments:\n- What version of RabbitMQ are you running? What options are you running it with?\n- RabbitMQ version is 2.2.0; default options.\n- Think I have my answer... was running \"rabbitmq-server start\" rather than using rabbitmqctl or the RedHat init script to stop server. Apparently the first version runs in foreground, and a control-C stops the server without initiating a flush of cached messages. Seems like using the control scripts does.\n- Thanks, this solves my problem. Oddly enough, after stopping the server via `sudo rabbitmqctl stop` once, a subsequent start of the rabbitmq-server and abort via control-C persists the messages.","metadata":{"transformedAt":"2026-08-18T18:33:20.320Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":50,"estimatedTokens":742}}1079{"id":"stack-25808165","source":"stackoverflow","questionId":25808165,"title":"Loss of messages in RabbitMQ","tags":["java","persistence","rabbitmq","message-queue"],"text":"Title: Loss of messages in RabbitMQ\nTags: java, persistence, rabbitmq, message-queue\nSource: Stack Overflow\n\nQuestion:\nI try to build persistent message queue with some delay per message. In Java-code it's looks like this:\n\n```\nConnectionFactory factory = new ConnectionFactory();\n factory.setHost(\"localhost\");\n Connection connection = factory.newConnection();\n Channel channel = connection.createChannel();\n\n channel.exchangeDeclare(\"WorkExchange\", \"direct\");\n channel.queueDeclare(\"WorkQueue\", true, false, false, null);\n channel.queueBind(\"WorkQueue\", \"WorkExchange\", \"\");\n\n Map args = new HashMap<>();\n args.put(\"x-dead-letter-exchange\", \"WorkExchange\");\n\n channel.exchangeDeclare(\"RetryExchange\", \"direct\");\n channel.queueDeclare(\"RetryQueue\", true, false, false, args);\n channel.queueBind(\"RetryQueue\", \"RetryExchange\", \"\");\n\n channel.confirmSelect();\n BasicProperties properties = new BasicProperties();\n properties.setDeliveryMode(2);\n properties.setExpiration(\"120000\");\n channel.basicPublish(\"RetryExchange\", \"\", properties, \"Hello world!\".getBytes());\n channel.waitForConfirmsOrDie();\n connection.close();\n```\n\nHowever, I have some problem with persistency. When I stop server, wait some time and start it again, messages which have to move to WorkQueue just disappear. What I do wrong? Or it's by design?\n\n========================================\n\nCode:\n```text\nConnectionFactory factory = new ConnectionFactory();\n factory.setHost(\"localhost\");\n Connection connection = factory.newConnection();\n Channel channel = connection.createChannel();\n\n channel.exchangeDeclare(\"WorkExchange\", \"direct\");\n channel.queueDeclare(\"WorkQueue\", true, false, false, null);\n channel.queueBind(\"WorkQueue\", \"WorkExchange\", \"\");\n\n Map<String, Object> args = new HashMap<>();\n args.put(\"x-dead-letter-exchange\", \"WorkExchange\");\n\n channel.exchangeDeclare(\"RetryExchange\", \"direct\");\n channel.queueDeclare(\"RetryQueue\", true, false, false, args);\n channel.queueBind(\"RetryQueue\", \"RetryExchange\", \"\");\n\n channel.confirmSelect();\n BasicProperties properties = new BasicProperties();\n properties.setDeliveryMode(2);\n properties.setExpiration(\"120000\");\n channel.basicPublish(\"RetryExchange\", \"\", properties, \"Hello world!\".getBytes());\n channel.waitForConfirmsOrDie();\n connection.close();\n```\n\n```text\nchannel.basicPublish(\"\", \"task_queue\", \n MessageProperties.PERSISTENT_TEXT_PLAIN,\n message.getBytes());\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.320Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":69,"estimatedTokens":618}}1080{"id":"stack-12569324","source":"stackoverflow","questionId":12569324,"title":"Rabbitmq + web stomp plugin with rpc - reply-to","tags":["rabbitmq","rpc","stomp"],"text":"Title: Rabbitmq + web stomp plugin with rpc - reply-to\nTags: rabbitmq, rpc, stomp\nSource: Stack Overflow\n\nQuestion:\nI'm trying to perform an RPC with RabbitMQ's STOMP adapter. As the client lib I'm using the STOMP over WebSocket (https://github.com/jmesnil/stomp-websocket/) library.\n\nFrom the documentation (http://www.rabbitmq.com/stomp.html#d.tqd) I see that I have to set the reply-to header. I've done that by specifying something like \"reply-to: /temp-queue/foo\" and I saw in my server-side client (node-amqp) that the replyTo header is set correctly (example: replyTo: '/reply-queue/amq.gen-w2jykNGp4DNDBADm3C4Cdx'). Still in my server-side client, I can reply to the message just by publishing a message to \"/reply-queue/amq.gen-w2jykNGp4DNDBADm3C4Cdx\".\n\nHowever, how do I get this reply it in my client code where the RPC call was initiated? The documentation states \"SEND and SUBSCRIBE frames must not contain /temp-queue destinations (...) subscriptions to reply queues are created automatically.\"\n\nSo, how do I subscribe to the reply-to queue? How can I get the results of RPC calls?\n\nThanks in advance.\n\n========================================\n\nTop Answer:\nThe answer to the original question:\n\n However, how do I get this reply it in my client code where the RPC\n call was initiated? The documentation states \"SEND and SUBSCRIBE\n frames must not contain /temp-queue destinations (...) subscriptions\n to reply queues are created automatically.\"\n\n \n So, how do I subscribe to the reply-to queue? How can I get the\n results of RPC calls?\n\nRabbit automatically subscribes the current STOMP session to the temp queue. The client doesn't know the temp queue name and cannot subscribe to it. However, when Rabbit sends a STOMP MESSAGE frame it sets the subscription header to the \"reply-to\" value (e.g. \"/temp-queue/foo\"). Although the STOMP over WebSocket client wasn't written with this in mind, a subscription could be registered as follows:\n\n```\nstompClient.subscriptions['/temp-queue/foo'] = function(message) {\n // ...\n};\n```\n\nI'd be happy to hear if there is another solution.\n\n========================================\n\nCode:\n```text\nreplyTo: '/reply-queue/[queue_name]'\n```\n\n```text\nfunction onRpcReceived(message, headers, deliveryInfo, m) {\n var reply_to = m.replyTo.toString().substr(13, m.replyTo.toString().length);\n\n connection.publish(reply_to, {response:\"OK\", reply:\"The time is 13h35m\"}, {\n contentType:'application/json',\n contentEncoding:'utf-8',\n correlationId:m. correlationId\n });\n}\n```\n\n```text\nreplyTo:'/reply-queue/amqp.fe43gggr5g54g54ggfd_'\n```\n\n```text\namqp.fe43gggr5g54g54ggfd_\n```\n\n```text\nstompClient.subscriptions['/temp-queue/foo'] = function(message) {\n // ...\n};\n```\n\n========================================\n\nComments:\n- This doesnot answer to the question but stackoverflow.com/a/16824437/3102264 did","metadata":{"transformedAt":"2026-08-18T18:33:20.321Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":76,"estimatedTokens":725}}1081{"id":"stack-33611453","source":"stackoverflow","questionId":33611453,"title":"Spring AMQP StatefulRetryOperationsInterceptor not used","tags":["java","spring","rabbitmq","spring-amqp","spring-retry"],"text":"Title: Spring AMQP StatefulRetryOperationsInterceptor not used\nTags: java, spring, rabbitmq, spring-amqp, spring-retry\nSource: Stack Overflow\n\nQuestion:\nI am trying configure spring amqp to only retry a message a defined amount of times. Currently a message that fails e.g. because of a `DataIntegrityViolationException` is redelivered indefinitely.\n\nAccording to the documentation here I came up with the following configuration\n\n```\n@Bean\n public StatefulRetryOperationsInterceptor statefulRetryOperationsInterceptor() {\n return RetryInterceptorBuilder.stateful()\n .backOffOptions(1000, 2.0, 10000) // initialInterval, multiplier, maxInterval\n .maxAttempts(3)\n .messageKeyGenerator(message -> UUID.randomUUID().toString())\n .build();\n }\n```\n\nThis does not seem to be applied - the messages are still tried indefinitely.\n\nFeels like I am missing something here.\n\nHere is my remaining configuration regarding AMQP:\n\n```\n@Bean\n Queue testEventSubscriberQueue() {\n final boolean durable = true;\n return new Queue(\"testEventSubscriberQueue\", durable);\n }\n\n @Bean\n Binding binding(TopicExchange topicExchange) {\n return BindingBuilder.bind(testEventSubscriberQueue()).to(topicExchange).with(\"payload.event-create\");\n }\n\n @Bean\n SimpleMessageListenerContainer messageListenerContainer(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(connectionFactory);\n container.setQueueNames(testEventSubscriberQueue().getName());\n container.setMessageListener(listenerAdapter);\n container.setChannelTransacted(true);\n return container;\n }\n\n @Bean\n MessageListenerAdapter listenerAdapter(MessageConverter messageConverter, SubscriberHandler subscriberHandler) {\n MessageListenerAdapter listenerAdapter = new MessageListenerAdapter(subscriberHandler);\n listenerAdapter.setMessageConverter(messageConverter);\n return listenerAdapter;\n }\n\n @Bean\n public MessageConverter messageConverter(ObjectMapper objectMapper) {\n final Jackson2JsonMessageConverter jsonMessageConverter = new Jackson2JsonMessageConverter();\n jsonMessageConverter.setJsonObjectMapper(objectMapper);\n DefaultClassMapper defaultClassMapper = new DefaultClassMapper();\n defaultClassMapper.setDefaultType(EventPayload.class);\n jsonMessageConverter.setClassMapper(defaultClassMapper);\n final ContentTypeDelegatingMessageConverter messageConverter = new ContentTypeDelegatingMessageConverter(jsonMessageConverter);\n messageConverter.addDelgate(MessageProperties.CONTENT_TYPE_JSON, jsonMessageConverter);\n return messageConverter;\n }\n\n @Bean\n public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory, MessageConverter messageConverter) {\n RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);\n rabbitTemplate.setMessageConverter(messageConverter);\n //rabbitTemplate.setChannelTransacted(true);\n return rabbitTemplate;\n }\n\n@Bean\n public TopicExchange testExchange() {\n final boolean durable = true;\n final boolean autoDelete = false;\n return new TopicExchange(EXCHANGE_NAME, durable, autoDelete);\n }\n```\n\nI am using spring-amqp 1.5.1.RELEASE.\n\nAny help is appreciated.\n\n========================================\n\nCode:\n```text\n@Bean\n public StatefulRetryOperationsInterceptor statefulRetryOperationsInterceptor() {\n return RetryInterceptorBuilder.stateful()\n .backOffOptions(1000, 2.0, 10000) // initialInterval, multiplier, maxInterval\n .maxAttempts(3)\n .messageKeyGenerator(message -> UUID.randomUUID().toString())\n .build();\n }\n```\n\n```text\n@Bean\n Queue testEventSubscriberQueue() {\n final boolean durable = true;\n return new Queue(\"testEventSubscriberQueue\", durable);\n }\n\n @Bean\n Binding binding(TopicExchange topicExchange) {\n return BindingBuilder.bind(testEventSubscriberQueue()).to(topicExchange).with(\"payload.event-create\");\n }\n\n @Bean\n SimpleMessageListenerContainer messageListenerContainer(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {\n SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();\n container.setConnectionFactory(connectionFactory);\n container.setQueueNames(testEventSubscriberQueue().getName());\n container.setMessageListener(listenerAdapter);\n container.setChannelTransacted(true);\n return container;\n }\n\n\n @Bean\n MessageListenerAdapter listenerAdapter(MessageConverter messageConverter, SubscriberHandler subscriberHandler) {\n MessageListenerAdapter listenerAdapter = new MessageListenerAdapter(subscriberHandler);\n listenerAdapter.setMessageConverter(messageConverter);\n return listenerAdapter;\n }\n\n @Bean\n public MessageConverter messageConverter(ObjectMapper objectMapper) {\n final Jackson2JsonMessageConverter jsonMessageConverter = new Jackson2JsonMessageConverter();\n jsonMessageConverter.setJsonObjectMapper(objectMapper);\n DefaultClassMapper defaultClassMapper = new DefaultClassMapper();\n defaultClassMapper.setDefaultType(EventPayload.class);\n jsonMessageConverter.setClassMapper(defaultClassMapper);\n final ContentTypeDelegatingMessageConverter messageConverter = new ContentTypeDelegatingMessageConverter(jsonMessageConverter);\n messageConverter.addDelgate(MessageProperties.CONTENT_TYPE_JSON, jsonMessageConverter);\n return messageConverter;\n }\n\n @Bean\n public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory, MessageConverter messageConverter) {\n RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);\n rabbitTemplate.setMessageConverter(messageConverter);\n //rabbitTemplate.setChannelTransacted(true);\n return rabbitTemplate;\n }\n\n@Bean\n public TopicExchange testExchange() {\n final boolean durable = true;\n final boolean autoDelete = false;\n return new TopicExchange(EXCHANGE_NAME, durable, autoDelete);\n }\n```\n\n```text\nDataIntegrityViolationException\n```\n\n```text\ncontainer.setAdviceChain(new Advice[] { statefulRetryOperationsInterceptor() });\n```\n\n========================================\n\nComments:\n- Note that using a random UUID as the message key is not very useful - we can't track the number of retries; the message key needs to be something unique in the message. If the originating system is Spring AMQP, it can be configured to set a message id in the message headers. If you don't have a unique id, consider using stateless retry, which does not involve redelivery.\n- Do you know, why there is no example code in the documentation?\n- There's a code example for creating a retry interceptor and the text says to add it to the container's advice chain; open a GitHub issue if you feel further clarification is required. github.com/spring-projects/spring-amqp/issues","metadata":{"transformedAt":"2026-08-18T18:33:20.321Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":173,"estimatedTokens":1737}}1082{"id":"stack-9300521","source":"stackoverflow","questionId":9300521,"title":"Is it possible to host a RabbitMQ Server publicly over the internet?","tags":[".net","messaging","rabbitmq"],"text":"Title: Is it possible to host a RabbitMQ Server publicly over the internet?\nTags: .net, messaging, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI need a Messaging system to be accessible to remote distributed clients over the Internet.\nIt needs to be secure and encrypted (SSL?). Does RabbitMQ support this natively or will I need to use a WCF Wrapper? Both the Server and the Clients are .Net on Windows.\n\n========================================\n\nComments:\n- Hi Ravi - this was a while ago, but did you end up going with RabbitMQ for this implementation or something different? I have a similar problem only using Java and related technologies.\n- In this instance I used WCF with MSMQ binding. But I have since, used rabbitmq for other applications and would recommend it. In this context though, I would not be publicly exposing the rabbit server but would rather proxy it through a web service.\n- thanks. but it does seem open-ssl needs to be installed as an add-on in windows.\n- If open-ssl is a problem for you then set up a RabbitMQ server on Linux. You could even use a HyperV VM for that. Then when you need to scale beyond a single server for the MQ broker, you can just clone that HyperV VM onto multiple servers and set them up as a cluster.\n- P.S. on UNIX/Linux always use the latest binary installs from rabbitmq.com. Do not use their default package install because it is not mean for serious production use.\n- @driis, If the clients are in different platforms says iOS and android, what could be your answer? I can post that as a separate question, if you want. Thanks.","metadata":{"transformedAt":"2026-08-18T18:33:20.321Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":17,"estimatedTokens":396}}1083{"id":"stack-55685418","source":"stackoverflow","questionId":55685418,"title":"Get queue size from rabbitmq consumer's callback with PhpAmqpLib","tags":["php","rabbitmq","queue","php-amqplib"],"text":"Title: Get queue size from rabbitmq consumer's callback with PhpAmqpLib\nTags: php, rabbitmq, queue, php-amqplib\nSource: Stack Overflow\n\nQuestion:\nI want to log working status from workers' callbacks and include a number of messages in the queue left.\n\nThe only solution I found so far is getting the second member of `queue_declare` result array, but this should be called once per worker launch, and I need info to be updated every new message.\n\n**UPD**:\nSolution based on IMSoP's answer:\n\n```\nchannel();\n$channel->queue_declare('test1');\necho \"[*] Waiting for messages. To exit press CTRL+C\\n\";\n$callback = function ($msg) use ($channel) {\n list (, $cn) = $channel->queue_declare('test1', true);\n echo ' [x] Received ', $msg->body, \" $cn left\";\n for ($i = 0; $i body; ++$i) {\n sleep(1);\n echo '.';\n }\n echo \"\\n\";\n};\n$channel->basic_qos(null, 1, null);\n$channel->basic_consume('test1', '', false, true, false, false, $callback);\nwhile (count($channel->callbacks)) {\n $channel->wait();\n}\n```\n\nFor some reason always gives 0 as message count.\n\n========================================\n\nCode:\n```text\n<?php\nrequire_once __DIR__ . '/../vendor/autoload.php';\nuse PhpAmqpLib\\Connection\\AMQPStreamConnection;\n$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');\n$channel = $connection->channel();\n$channel->queue_declare('test1');\necho \"[*] Waiting for messages. To exit press CTRL+C\\n\";\n$callback = function ($msg) use ($channel) {\n list (, $cn) = $channel->queue_declare('test1', true);\n echo ' [x] Received ', $msg->body, \" $cn left\";\n for ($i = 0; $i < $msg->body; ++$i) {\n sleep(1);\n echo '.';\n }\n echo \"\\n\";\n};\n$channel->basic_qos(null, 1, null);\n$channel->basic_consume('test1', '', false, true, false, false, $callback);\nwhile (count($channel->callbacks)) {\n $channel->wait();\n}\n```\n\n```text\nqueue_declare\n```\n\n```php\nforeach ( $this->registeredQueues as $queueName ) {\n // The second parameter to queue_declare is $passive\n // When set to true, everything else is ignored, so need not be passed\n list($queueName, $messageCount, $consumerCount)\n = $this->rabbitChannel->queue_declare($queueName, true);\n\n $this->logger->info(\n \"Queue $queueName has $messageCount messages and $consumerCount active consumers.\"\n );\n}\n```\n\n```text\nqueue_declare\n```\n\n```text\nDeclare-Ok\n```\n\n```text\nqueue\n```\n\n```text\nmessage-count\n```\n\n```text\nconsumer-count\n```\n\n========================================\n\nComments:\n- It might be better to record this separately then, you could increment/decrement a counter in memcached or redis.\n- I just noticed that your title says \"PhpAmqp\" but your tags include \"php-amqplib\". There are two different AMQP libraries for PHP, one is an extension, the other a PHP implementation. The features are pretty much the same, but the classes and functions are named differently, so you might want to clarify which you are using.\n- I think I found the reason. You will have to set the noAck to false in `basic_consume` and manually do ack in message handling in order to get the correct messageCount. The library will ignore the qos prefetch_count setting if noAck is set to true.\n- For some reason always gives 0 as message count. I updated question with code example.\n- I am having the exact same problem as the passive true result always give `$messageCount === 0`, despite `rabbitmqctl list_queues` giving positive number. It's hard to imagine something this important is not supported.\n- I think I found the reason. You will have to set the noAck to false in `basic_consume` and manually do ack in message handling in order to get the correct messageCount.","metadata":{"transformedAt":"2026-08-18T18:33:20.321Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":8,"totalLines":107,"estimatedTokens":915}}1084{"id":"stack-10585598","source":"stackoverflow","questionId":10585598,"title":"RabbitMQ messaging - initializing consumer","tags":["rabbitmq"],"text":"Title: RabbitMQ messaging - initializing consumer\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI want to use RabbitMQ to broadcast the state of an object continuously to any consumers which maybe listening. I want to set it up so when a consumer subscribes it will pick up the last available state...\nIs this possible?\n\n========================================\n\nTop Answer:\nIt is possible with the Recent History Custom Exchange. It says that it will put the last 20 messages in the queue, so if it configurable you may be able to change that to the last 1 message and you are done.\n\nIf that doesn't work, ie the number is fixed at 20, then you may have to process the first 19 messages off the queue and take the status from the 20th. This is a bit of an annoying work around but as you know the parameter is always 20 this should be fine.\n\nFinally if this doesn't suit you perhaps you will set you consumer to wait until the first status is receive, presuming that the status is broadcast reasonably frequently. Once the first status is received then start the rest of the application. I am assuming here that you need the status before doing something else.\n\n========================================\n\nComments:\n- It would be helpful if you gave a bit more detail, ie why you need the last state any why you cannot wait until the next state is broadcast. How are you setting up your queues are the messages persistent are the queues autodelete? More info = more helpful answers.\n- Why do you need to know why I need the last state? I'm not setting up any queues I'm asking how to do it...I'm an MQ newbie. Thxs.\n- @robthewolf seems a bit more aligned with my original question. thanks for the help anyway.\n- I had a look at it and I agree. I was also looking for this functionality so this looks better, as it is exactly the last message.","metadata":{"transformedAt":"2026-08-18T18:33:20.321Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":24,"estimatedTokens":461}}1085{"id":"stack-54533103","source":"stackoverflow","questionId":54533103,"title":"Dynamic support for multi RabbitMq virtual hosts in spring boot","tags":["java","spring-boot","rabbitmq","spring-amqp","spring-rabbit"],"text":"Title: Dynamic support for multi RabbitMq virtual hosts in spring boot\nTags: java, spring-boot, rabbitmq, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\ni am trying to implement support for multi tenant spring boot application where each tenant application is sending data to the spring boot application via RabbitMq. Each tenant is connected to its own RabbitMq virtual host. This could be shown in the figure below\nhttps://i.sstatic.net/xLgRS.png\n\nThis problem has been asked many times such as \n\n- How to use multiple vhosts in a Spring RabbitMQ project?\n\n- configuring multiple Vhosts in AMQP in rabbitmq configuration spring boot\n\n- RabbitMQ RPC across multiple rabbitMQ instances\n\nThe solution seems to be creating multiple connectionFactory beans for each virtual host. These are completely hard coded solutions. I want something more manageable. \n\nIn my case, the exchange name and binding keys are same for each virtual host. So far the spring boot application is able to connect to one virtual host. \n\nI want my spring boot application to handle all those virtual hosts along with the required credentials to be done in the spring profile rather than creating a seperate bean for each connection factory.\n\nIs there a way to implement support for multiple vhosts in spring profile or if possible is there any other better way to solve this problem which I along with many other developers are facing?\n\nThanks\n\n========================================\n\nComments:\n- stackoverflow.com/questions/53497244/…","metadata":{"transformedAt":"2026-08-18T18:33:20.321Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":30,"estimatedTokens":383}}1086{"id":"stack-54258150","source":"stackoverflow","questionId":54258150,"title":"Azure Devops - Docker Compose Build Image Not Found","tags":["docker-compose","rabbitmq"],"text":"Title: Azure Devops - Docker Compose Build Image Not Found\nTags: docker-compose, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am having an issue getting an image to build in Azure Devops from a docker-compose file.\n\nIt appears that the first issue is that the image does not build.\n\nhttps://i.sstatic.net/0OmEP.png\n\nThis is, I believe, causing the push step to fail, as there is no created image, it is just running an existing image.\n\nhttps://i.sstatic.net/efu6o.png\n\nWhat can I do to \"force\" the process to build an image off of this to pass into our repo? Here is our current docker compose file\n version: '3.4'\n\n```\nservices:\n rabbit:\n image: rabbitmq:3.6.16-management\n labels:\n NAME: \"rabbit\"\n environment:\n - \"RabbitMq/Host=localhost\"\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n container_name: rabbit\n restart: on-failure:5\n```\n\nHere's the build and push steps (truncating the top which doesn't really matter)\nBuild:\nhttps://i.sstatic.net/qkLDf.png\nPush:\nhttps://i.sstatic.net/WwpX4.png\n\n========================================\n\nCode:\n```text\nservices:\n rabbit:\n image: rabbitmq:3.6.16-management\n labels:\n NAME: \"rabbit\"\n environment:\n - \"RabbitMq/Host=localhost\"\n ports:\n - \"15672:15672\"\n - \"5672:5672\"\n container_name: rabbit\n restart: on-failure:5\n```\n\n========================================\n\nComments:\n- While we had other issues, this does indeed solve the problem outlined in this question, thanks.\n- I have 2 task one Run a Docker Compose Command with command up --build --no-start for create my images and have other task with Push services images. And got it. thanks @meshtron","metadata":{"transformedAt":"2026-08-18T18:33:20.321Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":62,"estimatedTokens":414}}1087{"id":"stack-15811831","source":"stackoverflow","questionId":15811831,"title":"Spring integration - Queue/Poller seems to exhaust threadpool without any action","tags":["java","spring","rabbitmq","amqp","spring-integration"],"text":"Title: Spring integration - Queue/Poller seems to exhaust threadpool without any action\nTags: java, spring, rabbitmq, amqp, spring-integration\nSource: Stack Overflow\n\nQuestion:\nI have a Spring integration app, attached to an AMQP broker.\n\nI want to receive messages from an amqp-queue, and update db records.\n\nIn order to improve performance, I have a pool of workers allowing multiple updates to occur concurrently.\n\nI have the following configuration:\n\n```\n\n \n\n \n\n```\n\nIf I start this running, with no inbound messages to process on the AMQP channel, I quickly see the thredpool get exhausted, and start rejecting.\n\nHere's the logs:\n\n```\n[Thu Apr 2013 23:41:51.153] DEBUG [] (org.springframework.amqp.rabbit.listener.BlockingQueueConsumer:185) - Retrieving delivery for Consumer: tag=[amq.ctag-w4qPp60jVEQOIEovR4cERv], channel=Cached Rabbit Channel: AMQChannel(amqp://guest@127.0.0.1:5672/,1), acknowledgeMode=AUTO local queue size=0\n[Thu Apr 2013 23:41:51.160] DEBUG [] (org.springframework.amqp.rabbit.listener.BlockingQueueConsumer:185) - Retrieving delivery for Consumer: tag=[amq.ctag-Q3Lq4R9g9E8WBNVLYzaFmq], channel=Cached Rabbit Channel: AMQChannel(amqp://guest@127.0.0.1:5672/,2), acknowledgeMode=AUTO local queue size=0\n[Thu Apr 2013 23:41:51.166] DEBUG [] (org.springframework.amqp.rabbit.listener.BlockingQueueConsumer:185) - Retrieving delivery for Consumer: tag=[amq.ctag-w8bg7ltEV2mot8QXDPCmfK], channel=Cached Rabbit Channel: AMQChannel(amqp://guest@127.0.0.1:5672/,3), acknowledgeMode=AUTO local queue size=0\n[Thu Apr 2013 23:41:51.170] DEBUG [] (org.springframework.amqp.rabbit.listener.BlockingQueueConsumer:185) - Retrieving delivery for Consumer: tag=[amq.ctag-A-0KdqhFjpc-Hvjmv7aZAc], channel=Cached Rabbit Channel: AMQChannel(amqp://guest@127.0.0.1:5672/,4), acknowledgeMode=AUTO local queue size=0\n[Thu Apr 2013 23:41:51.180] DEBUG [] (org.springframework.integration.endpoint.PollingConsumer:71) - Received no Message during the poll, returning 'false'\n[Thu Apr 2013 23:41:51.180] DEBUG [] (org.springframework.integration.endpoint.PollingConsumer:71) - Received no Message during the poll, returning 'false'\n[Thu Apr 2013 23:41:51.199] DEBUG [] (org.springframework.integration.endpoint.PollingConsumer:71) - Received no Message during the poll, returning 'false'\n[Thu Apr 2013 23:41:51.200] DEBUG [] (org.springframework.integration.endpoint.PollingConsumer:71) - Received no Message during the poll, returning 'false'\n[Thu Apr 2013 23:41:51.220] DEBUG [] (org.springframework.integration.endpoint.PollingConsumer:71) - Received no Message during the poll, returning 'false'\n```\n\nPretty quickly, the thread pool starts rejecting the executions:\n\n```\n[Thu Apr 2013 23:47:15.363] ERROR [] (org.springframework.integration.handler.LoggingHandler:126) - org.springframework.core.task.TaskRejectedException: Executor [java.util.concurrent.ThreadPoolExecutor@6ff3cb0e] did not accept task: org.springframework.integration.util.ErrorHandlingTaskExecutor$1@78615c8b\n at org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.execute(ThreadPoolTaskExecutor.java:244)\n at org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:49)\n at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller.run(AbstractPollingEndpoint.java:231)\n at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:53)\n at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)\n at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)\n at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)\n at java.util.concurrent.FutureTask.run(FutureTask.java:138)\n at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)\n at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)\n at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)\n at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)\n at java.lang.Thread.run(Thread.java:680)\nCaused by: java.util.concurrent.RejectedExecutionException\n at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1768)\n at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:767)\n at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:658)\n at org.springframework.sched\n```\n\nuling.concurrent.ThreadPoolTaskExecutor.execute(ThreadPoolTaskExecutor.java:241)\n ... 12 more\n\nI suspect that the culprit lies here: `BlockingQueueConsumer` - indicating that each poll for a message blocks the thread until a message arrives ... leading to the threadpool being exhausted quickly.\n\nWhat's the correct way to configure this?\n\n========================================\n\nTop Answer:\nIt appears I needed a bridge to map between the amqp-inbound queue (which is a pub/sub style queue), and a queue-channel.\n\n```\n\n \n\n \n\n```\n\nThis seems like a LOT of code to achieve a fairly trivial task - so if anyone has better solutions, or suggestions for improvements, I'd love to see them.\n\n========================================\n\nCode:\n```text\n<int-amqp:inbound-channel-adapter queue-names=\"pricehub.fixtures.priceUpdates.queue\" \n channel=\"pricehub.fixtures.priceUpdates.channel\"\n message-converter=\"jsonMessageConverter\"/>\n\n<int:channel id=\"pricehub.fixtures.priceUpdates.channel\">\n <int:queue />\n</int:channel>\n\n<int:service-activator ref=\"updatePriceAction\" \n method=\"updatePrices\" \n input-channel=\"pricehub.instruments.priceUpdates.channel\">\n <int:poller fixed-delay=\"50\" time-unit=\"MILLISECONDS\" task-executor=\"taskExecutor\" />\n</int:service-activator>\n\n<task:executor id=\"taskExecutor\" pool-size=\"5-50\" keep-alive=\"120\" queue-capacity=\"500\"/>\n```\n\n```text\n[Thu Apr 2013 23:41:51.153] DEBUG [] (org.springframework.amqp.rabbit.listener.BlockingQueueConsumer:185) - Retrieving delivery for Consumer: tag=[amq.ctag-w4qPp60jVEQOIEovR4cERv], channel=Cached Rabbit Channel: AMQChannel(amqp://guest@127.0.0.1:5672/,1), acknowledgeMode=AUTO local queue size=0\n[Thu Apr 2013 23:41:51.160] DEBUG [] (org.springframework.amqp.rabbit.listener.BlockingQueueConsumer:185) - Retrieving delivery for Consumer: tag=[amq.ctag-Q3Lq4R9g9E8WBNVLYzaFmq], channel=Cached Rabbit Channel: AMQChannel(amqp://guest@127.0.0.1:5672/,2), acknowledgeMode=AUTO local queue size=0\n[Thu Apr 2013 23:41:51.166] DEBUG [] (org.springframework.amqp.rabbit.listener.BlockingQueueConsumer:185) - Retrieving delivery for Consumer: tag=[amq.ctag-w8bg7ltEV2mot8QXDPCmfK], channel=Cached Rabbit Channel: AMQChannel(amqp://guest@127.0.0.1:5672/,3), acknowledgeMode=AUTO local queue size=0\n[Thu Apr 2013 23:41:51.170] DEBUG [] (org.springframework.amqp.rabbit.listener.BlockingQueueConsumer:185) - Retrieving delivery for Consumer: tag=[amq.ctag-A-0KdqhFjpc-Hvjmv7aZAc], channel=Cached Rabbit Channel: AMQChannel(amqp://guest@127.0.0.1:5672/,4), acknowledgeMode=AUTO local queue size=0\n[Thu Apr 2013 23:41:51.180] DEBUG [] (org.springframework.integration.endpoint.PollingConsumer:71) - Received no Message during the poll, returning 'false'\n[Thu Apr 2013 23:41:51.180] DEBUG [] (org.springframework.integration.endpoint.PollingConsumer:71) - Received no Message during the poll, returning 'false'\n[Thu Apr 2013 23:41:51.199] DEBUG [] (org.springframework.integration.endpoint.PollingConsumer:71) - Received no Message during the poll, returning 'false'\n[Thu Apr 2013 23:41:51.200] DEBUG [] (org.springframework.integration.endpoint.PollingConsumer:71) - Received no Message during the poll, returning 'false'\n[Thu Apr 2013 23:41:51.220] DEBUG [] (org.springframework.integration.endpoint.PollingConsumer:71) - Received no Message during the poll, returning 'false'\n```\n\n```text\n[Thu Apr 2013 23:47:15.363] ERROR [] (org.springframework.integration.handler.LoggingHandler:126) - org.springframework.core.task.TaskRejectedException: Executor [java.util.concurrent.ThreadPoolExecutor@6ff3cb0e] did not accept task: org.springframework.integration.util.ErrorHandlingTaskExecutor$1@78615c8b\n at org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.execute(ThreadPoolTaskExecutor.java:244)\n at org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:49)\n at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller.run(AbstractPollingEndpoint.java:231)\n at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:53)\n at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)\n at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)\n at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)\n at java.util.concurrent.FutureTask.run(FutureTask.java:138)\n at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)\n at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)\n at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)\n at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)\n at java.lang.Thread.run(Thread.java:680)\nCaused by: java.util.concurrent.RejectedExecutionException\n at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1768)\n at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:767)\n at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:658)\n at org.springframework.sched\n```\n\n```text\nBlockingQueueConsumer\n```\n\n```text\n<xsd:attribute name=\"concurrent-consumers\" type=\"xsd:string\">\n <xsd:annotation>\n <xsd:documentation>\nSpecify the number of concurrent consumers to create. Default is 1.\nRaising the number of concurrent consumers is recommended in order to scale the consumption of messages coming in\nfrom a queue. However, note that any ordering guarantees are lost once multiple consumers are registered. In\ngeneral, stick with 1 consumer for low-volume queues.\n </xsd:documentation>\n </xsd:annotation>\n </xsd:attribute>\n```\n\n```text\nQueueChannel\n```\n\n```text\nconcurrent-consumers\n```\n\n```text\n<queue/>\n```\n\n```text\n<poller/>\n```\n\n```text\n%t\n```\n\n```text\nreceive-timeout\n```\n\n```text\nQueueChannel\n```\n\n```text\nreceive-timeout\n```\n\n```text\n0\n```\n\n```text\n<poller/>\n```\n\n```text\n<int-amqp:inbound-channel-adapter queue-names=\"pricehub.fixtures.priceUpdates.queue\" \n channel=\"pricehub.fixtures.priceUpdates.subpub\"\n message-converter=\"jsonMessageConverter\"/>\n\n<int:publish-subscribe-channel id=\"pricehub.fixtures.priceUpdates.subpub\" />\n<int:bridge input-channel=\"pricehub.fixtures.priceUpdates.subpub\" \n output-channel=\"pricehub.fixtures.priceUpdates.channel\" />\n\n<int:channel id=\"pricehub.fixtures.priceUpdates.channel\">\n <int:queue />\n</int:channel>\n\n<int:service-activator ref=\"updatePriceAction\" \n method=\"updatePrices\" \n input-channel=\"pricehub.instruments.priceUpdates.channel\">\n <int:poller fixed-delay=\"50\" time-unit=\"MILLISECONDS\" task-executor=\"taskExecutor\" />\n</int:service-activator>\n\n<task:executor id=\"taskExecutor\" pool-size=\"5-50\" keep-alive=\"120\" queue-capacity=\"500\"/>\n```\n\n========================================\n\nComments:\n- The `BlockingQueueConsumer` is not polled by your `task-executor`. The adapter uses its own internal task executor for that.","metadata":{"transformedAt":"2026-08-18T18:33:20.321Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":16,"totalLines":221,"estimatedTokens":2952}}1088{"id":"stack-56238090","source":"stackoverflow","questionId":56238090,"title":"Persist headers when redelivering a RabbitMq message using MassTransit","tags":["c#","rabbitmq","quartz.net","masstransit"],"text":"Title: Persist headers when redelivering a RabbitMq message using MassTransit\nTags: c#, rabbitmq, quartz.net, masstransit\nSource: Stack Overflow\n\nQuestion:\n**Purpose**: I need to keep track of headers when I redeliver a message.\n\n**Configuration**: \n\n- RabbitMQ 3.7.9\n\n- Erlang 21.2\n\n- MassTransit 5.1.5\n\n- MySql 8.0 for the Quartz database\n\n**What I've tried without success:**\n\nfirst attempt:\n\n```\nawait context.Redeliver(TimeSpan.FromSeconds(5), (consumeCtx, sendCtx) => {\n if (consumeCtx.Headers.TryGetHeader(\"SenderApp\", out object sender))\n {\n sendCtx.Headers.Set(\"SenderApp\", sender);\n }\n}).ConfigureAwait(false);\n```\n\nsecond attempt:\n\n```\nprotected Task ScheduleSend(Uri rabbitUri, double delay)\n{\n return GetBus().ScheduleSend(\n rabbitUri,\n TimeSpan.FromSeconds(delay),\n _Data,\n new HeaderPipe(_SenderApp, 0));\n}\n\npublic class HeaderPipe : IPipe\n{\n private readonly byte _Priority;\n private readonly string _SenderApp;\n\n public HeaderPipe (byte priority)\n {\n _Priority = priority;\n _SenderApp = Assembly.GetEntryAssembly()?.GetName()?.Name ?? \"Default\";\n }\n\n public HeaderPipe (string senderApp, byte priority)\n {\n _Priority = priority;\n _SenderApp = senderApp;\n }\n\n public void Probe (ProbeContext context)\n { }\n\n public Task Send (SendContext context)\n {\n context.Headers.Set(\"SenderApp\", _SenderApp);\n context.SetPriority(_Priority);\n return Task.CompletedTask;\n }\n}\n```\n\n**Expected**: FinQuest.Robot.DBProcess\n\n**Result**: null\n\nI log in Consume method my SenderApp. The first time it's look like this\n\n```\nInitial trigger checking returns true for FinQuest.Robots.OrganisationLinkedinFeed (id: 001ae487-ad3d-4619-8d34-367881ec91ba, sender: FinQuest.Robot.DBProcess, modif: LinkedIn)\n```\n\nand looks like this after the redelivery\n\n```\nInitial trigger checking returns true for FinQuest.Robots.OrganisationLinkedinFeed (id: 001ae487-ad3d-4619-8d34-367881ec91ba, sender: , modif: LinkedIn)\n```\n\nWhat I'm doing wrong ? I don't want to use the Retry feature due to its maximum number of retry (I don't want to be limited).\n\nThanks in advance.\n\n========================================\n\nCode:\n```text\nawait context.Redeliver(TimeSpan.FromSeconds(5), (consumeCtx, sendCtx) => {\n if (consumeCtx.Headers.TryGetHeader(\"SenderApp\", out object sender))\n {\n sendCtx.Headers.Set(\"SenderApp\", sender);\n }\n}).ConfigureAwait(false);\n```\n\n```text\nprotected Task ScheduleSend(Uri rabbitUri, double delay)\n{\n return GetBus().ScheduleSend<IProcessOrganisationUpdate>(\n rabbitUri,\n TimeSpan.FromSeconds(delay),\n _Data,\n new HeaderPipe(_SenderApp, 0));\n}\n\npublic class HeaderPipe : IPipe<SendContext>\n{\n private readonly byte _Priority;\n private readonly string _SenderApp;\n\n public HeaderPipe (byte priority)\n {\n _Priority = priority;\n _SenderApp = Assembly.GetEntryAssembly()?.GetName()?.Name ?? \"Default\";\n }\n\n public HeaderPipe (string senderApp, byte priority)\n {\n _Priority = priority;\n _SenderApp = senderApp;\n }\n\n public void Probe (ProbeContext context)\n { }\n\n public Task Send (SendContext context)\n {\n context.Headers.Set(\"SenderApp\", _SenderApp);\n context.SetPriority(_Priority);\n return Task.CompletedTask;\n }\n}\n```\n\n```text\nInitial trigger checking returns true for FinQuest.Robots.OrganisationLinkedinFeed (id: 001ae487-ad3d-4619-8d34-367881ec91ba, sender: FinQuest.Robot.DBProcess, modif: LinkedIn)\n```\n\n```text\nInitial trigger checking returns true for FinQuest.Robots.OrganisationLinkedinFeed (id: 001ae487-ad3d-4619-8d34-367881ec91ba, sender: , modif: LinkedIn)\n```\n\n```text\npublic static void TransferConsumeContextHeaders(this SendContext sendContext, ConsumeContext consumeContext)\n```\n\n```text\nawait context.Redeliver(TimeSpan.FromSeconds(5), (consumeCtx, sendCtx) => {\n sendCtx.TransferConsumeContextHeaders(consumeCtx);\n});\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.321Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":159,"estimatedTokens":952}}1089{"id":"stack-71021119","source":"stackoverflow","questionId":71021119,"title":"Can't connect RabbitMQ to my app from docker","tags":["asp.net","docker","docker-compose","rabbitmq","masstransit"],"text":"Title: Can't connect RabbitMQ to my app from docker\nTags: asp.net, docker, docker-compose, rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nI am currently stuck with this problem for about a week and really can't find an appropriate solution. The problem is that when I try to connect to dockerized RabbitMQ it gives me the same error every time:\n\n```\nwordofthedayapp-wordofthedayapp-1 | [40m[1m[33mwarn[39m[22m[49m: MassTransit[0]\nwordofthedayapp-wordofthedayapp-1 | Connection Failed: rabbitmq://localhost/\nwordofthedayapp-wordofthedayapp-1 | RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were\n reachable\nwordofthedayapp-wordofthedayapp-1 | ---> System.AggregateException: One or more errors occurred. (Connection failed)\nwordofthedayapp-wordofthedayapp-1 | ---> RabbitMQ.Client.Exceptions.ConnectFailureException: Connection failed\nwordofthedayapp-wordofthedayapp-1 | ---> System.TimeoutException: The operation has timed out.\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.Impl.TaskExtensions.TimeoutAfter(Task task, TimeSpan timeout)\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectOrFail(ITcpClient socket, AmqpTcpEndpo\nint endpoint, TimeSpan timeout)\nwordofthedayapp-wordofthedayapp-1 | --- End of inner exception stack trace ---\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectOrFail(ITcpClient socket, AmqpTcpEndpo\nint endpoint, TimeSpan timeout)\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectUsingAddressFamily(AmqpTcpEndpoint end\npoint, Func`2 socketFactory, TimeSpan timeout, AddressFamily family)\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectUsingIPv4(AmqpTcpEndpoint endpoint, Fu\nnc`2 socketFactory, TimeSpan timeout)\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.Impl.SocketFrameHandler..ctor(AmqpTcpEndpoint endpoint, Func`2 socket\nFactory, TimeSpan connectionTimeout, TimeSpan readTimeout, TimeSpan writeTimeout)\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.Framing.Impl.IProtocolExtensions.CreateFrameHandler(IProtocol protoco\nl, AmqpTcpEndpoint endpoint, Func`2 socketFactory, TimeSpan connectionTimeout, TimeSpan readTimeout, TimeSpan writeTimeout)\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.ConnectionFactory.CreateFrameHandler(AmqpTcpEndpoint endpoint)\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.EndpointResolverExtensions.SelectOne[T](IEndpointResolver resolver, F\nunc`2 selector)\nwordofthedayapp-wordofthedayapp-1 | --- End of inner exception stack trace ---\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.EndpointResolverExtensions.SelectOne[T](IEndpointResolver resolver, F\nunc`2 selector)\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver\n, String clientProvidedName)\nwordofthedayapp-wordofthedayapp-1 | --- End of inner exception stack trace ---\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver\n, String clientProvidedName)\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.ConnectionFactory.CreateConnection(IList`1 hostnames, String clientPr\novidedName)\nwordofthedayapp-wordofthedayapp-1 | at MassTransit.RabbitMqTransport.Integration.ConnectionContextFactory.CreateConnection(I\nSupervisor supervisor)\n```\n\nHere you can find my docker-compose.yml:\n\n```\nversion: '3.9'\nservices:\n rabbitmq:\n image: rabbitmq:3.9-management\n hostname: rabbitmq\n volumes:\n - \"~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/\"\n - \"~/.docker-conf/rabbitmq/log/:/var/log/rabbitmq\"\n ports:\n - 5672:5672\n - 15672:15672\n expose:\n - 5672\n - 15672\n environment:\n - RABBITMQ_DEFAULT_USER=guest\n - RABBITMQ_DEFAULT_PASS=guest\n healthcheck:\n test: [ \"CMD\", \"rabbitmqctl\", \"status\", \"-f\", \"http://localhost:15672\"]\n interval: 5s\n timeout: 20s\n retries: 5\n networks:\n - app\n\n ms-sql-server:\n container_name: ms-sql-server\n image: mcr.microsoft.com/mssql/server:2019-latest\n user: root\n volumes:\n - \"appdb:/var/opt/mssql/data\"\n environment:\n ACCEPT_EULA: \"Y\"\n SA_PASSWORD: \"Password123!\"\n MSSQL_PID: Express\n ports:\n - 1433:1433\n healthcheck:\n test: [\"CMD\" ,\"ping\", \"-h\", \"localhost\"]\n timeout: 20s\n retries: 10\n networks:\n - app\n\n wordofthedayapp:\n build:\n dockerfile: WordOfTheDay.Api/Dockerfile\n image: wordofthedayapp\n environment:\n DbServer: \"ms-sql-server\"\n DbPort: \"1433\"\n DbUser: \"sa\"\n Password: \"Password123!\"\n Database: \"appdb\"\n ports:\n - 5001:80\n restart: on-failure\n depends_on:\n - rabbitmq\n networks:\n - app\n\nvolumes:\n appdb:\n\nnetworks:\n app:\n```\n\nMy appsettings string:\n\n```\n{\n \"Logging\": {\n \"LogLevel\": {\n \"Default\": \"Information\",\n \"Microsoft\": \"Warning\",\n \"Microsoft.Hosting.Lifetime\": \"Information\"\n }\n },\n \"AllowedHosts\": \"*\",\n \"ConnectionStrings\": {\n \"WordContext\": \"Server=ms-sql-server;Database=master;User=sa;Password=Password123!;MultipleActiveResultSets=true;Integrated Security=false;TrustServerCertificate=true\",\n \"RabbitMQHost\": \"amqp://elias:123456@localhost:5672\"\n }\n}\n```\n\nThis is how it works in the app using MassTransit:\n\n```\npublic static void AddConfiguredMassTransit(this IServiceCollection services, string host)\n {\n services.AddMassTransit(Configuration =>\n {\n Configuration.UsingRabbitMq((context, config) =>\n {\n config.Host(host);\n });\n });\n\n services.AddMassTransitHostedService();\n }\n```\n\n```\nservices.AddConfiguredMassTransit(Configuration.GetConnectionString(\"RabbitMQHost\"));\n```\n\nI hope at least anyone knows what is wrong with this code because I really tired trying to fix it and browsing internet for solution. Thank you in advance!\n\nP.S. Important information! Everything works perfect when I test it locally without a docker, but when I try to dockerize the app this happens.\n\n========================================\n\nCode:\n```text\nwordofthedayapp-wordofthedayapp-1 | [40m[1m[33mwarn[39m[22m[49m: MassTransit[0]\nwordofthedayapp-wordofthedayapp-1 | Connection Failed: rabbitmq://localhost/\nwordofthedayapp-wordofthedayapp-1 | RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were\n reachable\nwordofthedayapp-wordofthedayapp-1 | ---> System.AggregateException: One or more errors occurred. (Connection failed)\nwordofthedayapp-wordofthedayapp-1 | ---> RabbitMQ.Client.Exceptions.ConnectFailureException: Connection failed\nwordofthedayapp-wordofthedayapp-1 | ---> System.TimeoutException: The operation has timed out.\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.Impl.TaskExtensions.TimeoutAfter(Task task, TimeSpan timeout)\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectOrFail(ITcpClient socket, AmqpTcpEndpo\nint endpoint, TimeSpan timeout)\nwordofthedayapp-wordofthedayapp-1 | --- End of inner exception stack trace ---\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectOrFail(ITcpClient socket, AmqpTcpEndpo\nint endpoint, TimeSpan timeout)\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectUsingAddressFamily(AmqpTcpEndpoint end\npoint, Func`2 socketFactory, TimeSpan timeout, AddressFamily family)\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectUsingIPv4(AmqpTcpEndpoint endpoint, Fu\nnc`2 socketFactory, TimeSpan timeout)\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.Impl.SocketFrameHandler..ctor(AmqpTcpEndpoint endpoint, Func`2 socket\nFactory, TimeSpan connectionTimeout, TimeSpan readTimeout, TimeSpan writeTimeout)\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.Framing.Impl.IProtocolExtensions.CreateFrameHandler(IProtocol protoco\nl, AmqpTcpEndpoint endpoint, Func`2 socketFactory, TimeSpan connectionTimeout, TimeSpan readTimeout, TimeSpan writeTimeout)\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.ConnectionFactory.CreateFrameHandler(AmqpTcpEndpoint endpoint)\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.EndpointResolverExtensions.SelectOne[T](IEndpointResolver resolver, F\nunc`2 selector)\nwordofthedayapp-wordofthedayapp-1 | --- End of inner exception stack trace ---\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.EndpointResolverExtensions.SelectOne[T](IEndpointResolver resolver, F\nunc`2 selector)\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver\n, String clientProvidedName)\nwordofthedayapp-wordofthedayapp-1 | --- End of inner exception stack trace ---\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver\n, String clientProvidedName)\nwordofthedayapp-wordofthedayapp-1 | at RabbitMQ.Client.ConnectionFactory.CreateConnection(IList`1 hostnames, String clientPr\novidedName)\nwordofthedayapp-wordofthedayapp-1 | at MassTransit.RabbitMqTransport.Integration.ConnectionContextFactory.CreateConnection(I\nSupervisor supervisor)\n```\n\n```text\nversion: '3.9'\nservices:\n rabbitmq:\n image: rabbitmq:3.9-management\n hostname: rabbitmq\n volumes:\n - \"~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/\"\n - \"~/.docker-conf/rabbitmq/log/:/var/log/rabbitmq\"\n ports:\n - 5672:5672\n - 15672:15672\n expose:\n - 5672\n - 15672\n environment:\n - RABBITMQ_DEFAULT_USER=guest\n - RABBITMQ_DEFAULT_PASS=guest\n healthcheck:\n test: [ \"CMD\", \"rabbitmqctl\", \"status\", \"-f\", \"http://localhost:15672\"]\n interval: 5s\n timeout: 20s\n retries: 5\n networks:\n - app\n\n ms-sql-server:\n container_name: ms-sql-server\n image: mcr.microsoft.com/mssql/server:2019-latest\n user: root\n volumes:\n - \"appdb:/var/opt/mssql/data\"\n environment:\n ACCEPT_EULA: \"Y\"\n SA_PASSWORD: \"Password123!\"\n MSSQL_PID: Express\n ports:\n - 1433:1433\n healthcheck:\n test: [\"CMD\" ,\"ping\", \"-h\", \"localhost\"]\n timeout: 20s\n retries: 10\n networks:\n - app\n\n wordofthedayapp:\n build:\n dockerfile: WordOfTheDay.Api/Dockerfile\n image: wordofthedayapp\n environment:\n DbServer: \"ms-sql-server\"\n DbPort: \"1433\"\n DbUser: \"sa\"\n Password: \"Password123!\"\n Database: \"appdb\"\n ports:\n - 5001:80\n restart: on-failure\n depends_on:\n - rabbitmq\n networks:\n - app\n\nvolumes:\n appdb:\n\nnetworks:\n app:\n```\n\n```text\n{\n \"Logging\": {\n \"LogLevel\": {\n \"Default\": \"Information\",\n \"Microsoft\": \"Warning\",\n \"Microsoft.Hosting.Lifetime\": \"Information\"\n }\n },\n \"AllowedHosts\": \"*\",\n \"ConnectionStrings\": {\n \"WordContext\": \"Server=ms-sql-server;Database=master;User=sa;Password=Password123!;MultipleActiveResultSets=true;Integrated Security=false;TrustServerCertificate=true\",\n \"RabbitMQHost\": \"amqp://elias:123456@localhost:5672\"\n }\n}\n```\n\n```text\npublic static void AddConfiguredMassTransit(this IServiceCollection services, string host)\n {\n services.AddMassTransit(Configuration =>\n {\n Configuration.UsingRabbitMq((context, config) =>\n {\n config.Host(host);\n });\n });\n\n services.AddMassTransitHostedService();\n }\n```\n\n```text\nservices.AddConfiguredMassTransit(Configuration.GetConnectionString(\"RabbitMQHost\"));\n```\n\n```cs\nbool IsRunningInContainer => bool.TryParse(Environment.GetEnvironmentVariable(\"DOTNET_RUNNING_IN_CONTAINER\"), out var inDocker) && inDocker;\n```\n\n```text\nlocalhost\n```\n\n```text\nrabbitmq\n```\n\n```text\nlocalhost\n```\n\n```text\nConnection Failed: rabbitmq://localhost/\n```\n\n```text\nvar host = IsRunningInContainer ? \"rabbitmq\" : \"localhost\";\n```\n\n========================================\n\nComments:\n- In the same way you use the Compose service name `ms-sql-server` as a host name to connect to the database, you need to use the Compose service name `rabbitmq` as a host name to connect to the message queue in the `RabbitMQHost` setting. `localhost` in Docker usually means \"the current container\".","metadata":{"transformedAt":"2026-08-18T18:33:20.321Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":11,"totalLines":338,"estimatedTokens":3071}}1090{"id":"stack-58661518","source":"stackoverflow","questionId":58661518,"title":"SimpleMessageListener vs DirectMessageListener","tags":["java","spring","rabbitmq","spring-rabbit"],"text":"Title: SimpleMessageListener vs DirectMessageListener\nTags: java, spring, rabbitmq, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI'm trying to see difference between `DirectMessageListener` and `SimpleMessageListener`. I have this drawing just to ask if it is correct.\n\nLet me try to describe how I understood it and maybe you tell me if it is correct. \n\nIn front of `spring-rabbit` there is `rabbit-client` java library, that is connecting to rabbit-mq server and delivering messages to spring-rabbit library. This client has some `ThreadPoolExecutor` (which has in this case I think - 16 threads). So, it does not matter how many queues are there in rabbit - if there is a single connection, I get 16 threads. These same threads are reused if I use `DirectMessageListener` - and this handler method `listen` is executed in all of these 16 threads when messages arrive. So if I do something complex in handler, `rabbit-client` must wait for thread to get free in order to get next message using this thread. Also if I increase `setConsumersPerQueue` to lets say 20, It will create 20 consumer per queue, but not threads. These 20*5 consumers in my case will all reuse these 16 threads offered by `ThreadPoolExecutor`?\n\n`SimpleMessageListener` on the other hand, would have its own threads. If concurrent consumers == 1 (I guess default as in my case) it has only one thread. Whenever there is a message on any of `secondUseCase*` queues, `rabbit-client` java library will use one of its 16 threads in my case, to forward message to single internal thread that I have in `SimpleMessageListener`. As soon as it is forwarded, `rabbit-client` java library thread is freed and it can go back fetching more messages from rabbit server.\n\nhttps://i.sstatic.net/0yE7T.jpg\n\n========================================\n\nCode:\n```text\nDirectMessageListener\n```\n\n```text\nSimpleMessageListener\n```\n\n```text\nspring-rabbit\n```\n\n```text\nrabbit-client\n```\n\n```text\nThreadPoolExecutor\n```\n\n```text\nDirectMessageListener\n```\n\n```text\nlisten\n```\n\n```text\nrabbit-client\n```\n\n```text\nsetConsumersPerQueue\n```\n\n```text\nThreadPoolExecutor\n```\n\n```text\nSimpleMessageListener\n```\n\n```text\nsecondUseCase*\n```\n\n```text\nrabbit-client\n```\n\n```text\nSimpleMessageListener\n```\n\n```text\nrabbit-client\n```\n\n========================================\n\nComments:\n- Possible dup? stackoverflow.com/q/56438819/42962\n- @hooknc it does not contain all the information from that post.\n- Thanks for confirmation.\n- @gary-russell is this true even if I instantiate `N` `DirectMessageListenerContainer`s, they will all still the default threadpool on the `amqp-client`? Is there any difference if I instantiate `N x DirectMessageListenerContainer` with `consumersPerQueue x 1` or `1 x DirectMessageListenerContainer` with `consumersPerQueue x N`? (assuming there's 1 queue)\n- Consumers per queue has no bearing on threading, it just enables the use of multiple channels to consume. Using N/1 Vs 1/N will likely need more memory.","metadata":{"transformedAt":"2026-08-18T18:33:20.321Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":15,"totalLines":86,"estimatedTokens":746}}1091{"id":"stack-51045689","source":"stackoverflow","questionId":51045689,"title":"Message Broker (Kafka, RabbitMQ) VS Service Bus (nServiceBus)","tags":[".net","wcf","apache-kafka","rabbitmq","nservicebus"],"text":"Title: Message Broker (Kafka, RabbitMQ) VS Service Bus (nServiceBus)\nTags: .net, wcf, apache-kafka, rabbitmq, nservicebus\nSource: Stack Overflow\n\nQuestion:\nI've read a lot about the three mentioned systems. But I am still not sure what to use. They all seem to accomplish what I need:\n\nI want a client service/services to be updated when another service fires an event/command/message. I am currently running `WCF` Services and a client service can actively ask for updated data from other services. This should be changed with a message broker/service bus. \nI also don't care if the client goes offline and doesn't receive updates, since when going online it automatically gets the latest data via `WCF` anyway. \nThat's why I am thinking `Kafka` is the wrong approach. On the other hand I deploy this software in a security related context at other companies. And since this is a legacy application (no docker or easy deployment), needing to install Erlang, open all ports for `RabbitMQ` is not an option. This leaves me with `NServiceBus`.\n\nDo I miss out on anything crucial when running only `NServiceBus`, instead of the often seen `RabbitMQ+NServiceBus` variant?\n\nIt seems as long as I am using the `.net` stack exclusively, I am good with `NServiceBus`?\n\nSince I already have `WCF` to poll for updated data, should you only send a command to initiate the `WCF` call. Or should you send the updated data itself via the messaging system directly?\n\n========================================\n\nCode:\n```text\nWCF\n```\n\n```text\nWCF\n```\n\n```text\nKafka\n```\n\n```text\nRabbitMQ\n```\n\n```text\nNServiceBus\n```\n\n```text\nNServiceBus\n```\n\n```text\nRabbitMQ+NServiceBus\n```\n\n```text\n.net\n```\n\n```text\nNServiceBus\n```\n\n```text\nWCF\n```\n\n```text\nWCF\n```\n\n```text\ntransport\n```\n\n========================================\n\nComments:\n- Thank you. Is there a tutorial or project in which a webClient is updated via NServiceBus? I found the eShopOnContainers from Microsoft so far.\n- eShopOnContainers is quite difficult and we don't agree completely on the chosen architecture. Perhaps you're looking for this show case sample, where the front-end is asynchronously updated via messaging and SignalR. docs.particular.net/samples/showcase","metadata":{"transformedAt":"2026-08-18T18:33:20.321Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":12,"totalLines":73,"estimatedTokens":554}}1092{"id":"stack-55626750","source":"stackoverflow","questionId":55626750,"title":"Is it possible to wait until celery group done?","tags":["python","django","rabbitmq","celery","messagebroker"],"text":"Title: Is it possible to wait until celery group done?\nTags: python, django, rabbitmq, celery, messagebroker\nSource: Stack Overflow\n\nQuestion:\nI am trying to do group tasks and wait until all the group subtasks finished then run the last task. But when I call task it calls group and last tasks but the last task finished before group finish. Is it possible to wait until all the tasks inside group finish?\n\n```\n@shared_task(name=\"print\")\ndef print_order():\n print(\"PRINT #1\")\n mylist = [(1, 2), (4, 6), (1, 4)]\n group([(add.s(*i) | order_id_print.s()) for i in mylist]).delay()\n\n@shared_task(name=\"print.add\")\ndef add(x,y):\n print(\"ADD #2\")\n chain(add_task1.s(x, y, 'task id') | add_task2.si(x, y, \"task_id\")).delay()\n return x+y\n\n@shared_task(name=\"add_task_1\")\ndef add_task1(order_id, ftype, task_id):\n print(\"ADD task #2-1\")\n print(\"add tasks task1 order_id {} {} {}\".format(order_id, ftype, task_id))\n\n@shared_task(name=\"add_task_2\")\ndef add_task2(order_id, ftype, task_id):\n print(\"ADD task #2-2\")\n print(\"add tasks task2 order_id {} {} {}\".format(order_id, ftype, task_id))\n\n@shared_task(name=\"print.order_id_print\")\ndef order_id_print(id):\n print(\"ORDER #3\")\n print(\"order id is {}\".format(id))\n```\n\n========================================\n\nTop Answer:\nFor this there is 2 options: **''group'' and \"chord\"(Chord does not work with rpc)** . Both are celery constructs that allow you to run multiple tasks in parallel and then wait until all tasks have completed.\n\nwith chord it is possible to define a ''callback'' task and do the whole process asynchronously. If your server needs to wait for tasks before return to the client then group may be the best option\n\n**Group:**\n\n```\ntasks = [get_foods.s(x,y), get_drinks.s(z,w)]\nresults = group(tasks)().get() #lock until everything done\nfor result in results:\n print(result)\n```\n\n**Chord:**\n\n```\nchord([get_foods.s(x,y), get_drinks.s(x,y)], finish_order.s()).delay()\n```\n\n========================================\n\nCode:\n```text\n@shared_task(name=\"print\")\ndef print_order():\n print(\"PRINT #1\")\n mylist = [(1, 2), (4, 6), (1, 4)]\n group([(add.s(*i) | order_id_print.s()) for i in mylist]).delay()\n\n\n@shared_task(name=\"print.add\")\ndef add(x,y):\n print(\"ADD #2\")\n chain(add_task1.s(x, y, 'task id') | add_task2.si(x, y, \"task_id\")).delay()\n return x+y\n\n@shared_task(name=\"add_task_1\")\ndef add_task1(order_id, ftype, task_id):\n print(\"ADD task #2-1\")\n print(\"add tasks task1 order_id {} {} {}\".format(order_id, ftype, task_id))\n\n@shared_task(name=\"add_task_2\")\ndef add_task2(order_id, ftype, task_id):\n print(\"ADD task #2-2\")\n print(\"add tasks task2 order_id {} {} {}\".format(order_id, ftype, task_id))\n\n\n@shared_task(name=\"print.order_id_print\")\ndef order_id_print(id):\n print(\"ORDER #3\")\n print(\"order id is {}\".format(id))\n```\n\n```py\ntasks = [get_foods.s(x,y), get_drinks.s(z,w)]\nresults = group(tasks)().get() #lock until everything done\nfor result in results:\n print(result)\n```\n\n```text\nchord([get_foods.s(x,y), get_drinks.s(x,y)], finish_order.s()).delay()\n```\n\n========================================\n\nComments:\n- Not so long ago I was asking the same question on the Celery IRC channel at FreeNode. They explained to me that the best thing to do is to make a chain out of your group and add a task that collects the data (or processes the results of a group).\n- So in my case, if i use chord, after all the `add` task finished then `order_id_print` will invoke?\n- correct. something like `chord([add.s(*i) for i in mylist], order_id_print.s()).delay()` will asynchronously run all the `add` tasks. When all `add` tasks are finished, it will asynchronously invoke your `order_id_print` task. Beware that Celery will pass all individual `add` results to `order_id_print` as a list so you have to add some tasks arguments.\n- I did exactly as it is, but in celery, it shows `ADD task #2-2` right after `order_id_print`. Got the celery results like this [2019-04-11 17:14:45,475: WARNING/ForkPoolWorker-3] ORDER #3 [2019-04-11 17:14:45,476: WARNING/ForkPoolWorker-3] order id is [5, 3, 10] [2019-04-11 17:14:45,476: INFO/ForkPoolWorker-3] Task print.order_id_print[77b50397-a2bb-4141-8380-e86aa1c04642] succeeded in 0.0006398810000973754s: None [2019-04-11 17:14:45,476: INFO/MainProcess] Received task: add_task_2[30fbbf70-cae8-482c-81fd-fdc17a816f48]\n- that is because you *asynchronously* trigger another task (chain) within your `add` task. If this is not what you want, you need to rearrange your workflows.\n- Oh, i get it. So instead of calling `add` i have to call `add_task1` and `add_task2` in chord right? so that way there wont be any third async process ??? but it needed to be inside for loop so inside `chord` there should be group ? like `chord([(add_task1(*i), add_task2(*i)) for i in my_list], order_id_print.s()).delay()`\n- correct, you have to call `add_task1` and `add_task2` in the header (the first part of the chord). As to your second question, I have never tried to invoke chains in a group or a chord header, so I'd say give it a try and report back here! If it does not work, there's always an alternative (e.g. as an alternatively to a chain, asynchronously call the next task from within your first task, that kind of stuff. It all depends on your exact requirements.\n- How am i going to call this task automatically after some N minutes ? like after all the tasks finished i want to call this task like 5 minutes for example. I perceived that using celery beat does not suit for this kind of job because sometimes current job might not finished at that time when celerybeat starts","metadata":{"transformedAt":"2026-08-18T18:33:20.321Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":114,"estimatedTokens":1401}}1093{"id":"stack-62339688","source":"stackoverflow","questionId":62339688,"title":"How to unacknowledge message when I run a celery task?","tags":["python","rabbitmq","celery"],"text":"Title: How to unacknowledge message when I run a celery task?\nTags: python, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nNow I have some sync jobs, which are stateful, so if the task failed, I must unacknowledge message then let them go to the front of `RabbitMQ`. But when I try to raise an error, I found celery still acknowledges this message, and the queue has been cleared.\n\n```\n@celery.task(bind=True)\ndef my_task(self, *args, **kwargs):\n raise ValueError\n```\n\nAnd I found celery task has a method called `retry`, but it will add the task to the back of the queue. This is not what I want.\n\n```\n@celery.task(bind=True)\ndef my_task(self, *args, **kwargs):\n try:\n raise ValueError\n except Exception:\n self.retry(countdown=15)\n```\n\nEven I can't do that with a kill signal:\n\n```\nos.kill(os.getpid(), signal.SIGKILL)\n```\n\nWhat should I do? Did celery provide some error so I can raise this error to notify celery don't acknowledge my message?\n\n========================================\n\nTop Answer:\nOn the documentation https://docs.celeryproject.org/en/stable/userguide/configuration.html I found that :\n\n`task_acks_on_failure_or_timeout` is by default `enabled` .\n\nSo I think you should try a combination of \n\n`task_acks_late=True` + `task_acks_on_failure_or_timeout=False`\n\nto achieve `NO acknowledgement when a task fails`.\n\n========================================\n\nCode:\n```text\n@celery.task(bind=True)\ndef my_task(self, *args, **kwargs):\n raise ValueError\n```\n\n```text\n@celery.task(bind=True)\ndef my_task(self, *args, **kwargs):\n try:\n raise ValueError\n except Exception:\n self.retry(countdown=15)\n```\n\n```text\nos.kill(os.getpid(), signal.SIGKILL)\n```\n\n```text\nRabbitMQ\n```\n\n```text\nretry\n```\n\n```text\n@celery.task(bind=True)\ndef my_task(self, *args, **kwargs):\n try:\n raise ValueError\n except Exception:\n self.retry(countdown=15, priority=9)\n```\n\n```text\n@celery.task(bind=True)\ndef my_task(self, *args, **kwargs):\n try:\n raise ValueError\n except Exception:\n self.retry(countdown=15, queue='prioritized_queue_name')\n```\n\n```text\ntask_acks_on_failure_or_timeout\n```\n\n```text\nenabled\n```\n\n```text\ntask_acks_late=True\n```\n\n```text\ntask_acks_on_failure_or_timeout=False\n```\n\n```text\nNO acknowledgement when a task fails\n```\n\n========================================\n\nComments:\n- try using `retry` in conjunction with `acks_late`. There is more detail in the Celery's official FAQ docs.celeryproject.org/en/stable/… For failed tasks, you could try setting setting the task priority (not sure how you'll do that with `retry`... as I have not tried out this feature yet). docs.celeryproject.org/en/stable/userguide/routing.html\n- @teng `retry` with `acks_late` was not helpful. It will add the task to the back of the queue.\n- I have tried this option but looks like not work fine. If my task failed, it will not acknowledge my message, but didn't let the message back. So I can't try to fix this task by any other way except kill this worker.\n- And, I tried it again, another big problem, if I prefetch 10 messages, and the first one failed, it will not stop here, it will continue to run next tasks, until these 10 messages done, then wait here. That means, the second message, third message... will be consumed before the first one.\n- if are looking to process tasks in sequential order in which they are submitted, then i am afraid celery is not designed for those use cases. But if can chain all these tasks together upfront you check about chaining celery tasks\n- I guess it is the nearest way to solve my problem, I didn't find any other solution.\n- But, to be honest, if I put a message to another queue, it was still break the queue's order --- the messages after this message will be consumed first. The first solution may need specify `--prefetch-multiplier=1` to promise the highest priority message will be consumed first. It was slower. So I think I'd better implement my own task scheduling system by amql.","metadata":{"transformedAt":"2026-08-18T18:33:20.322Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":12,"totalLines":123,"estimatedTokens":1000}}1094{"id":"stack-50288608","source":"stackoverflow","questionId":50288608,"title":"@RabbitListener for the same queue in multiple classes","tags":["rabbitmq","amqp","spring-amqp","spring-rabbit"],"text":"Title: @RabbitListener for the same queue in multiple classes\nTags: rabbitmq, amqp, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI was wondering if it is possible in Spring AMQP to receive messages from the same queue in multiple classes depending on the payload type.\n\nI am aware of using the @RabbitListener annotation in class and then putting @RabbitHandler on methods, but I would like to split complexity of message handling in multiple classes while keeping a single queue.\n\nVersion currently in use: Spring AMQP v2.0.3 along with RabbitMQ.\n\n========================================\n\nTop Answer:\nYes you can, but it takes a little different approach:\nYou need lo listen to the generic Message Type, do some switching, and your own deserialisation. You can of course completly hide that code somewhere (baseclass, annotations...)\n\nExample below can be extended to listen to whatever types extra.\nThe example above would be to filter on A and B DTO types.\n\n```\nvoid receive(ADTO dto)\n{\n System.out.print(dto.url);\n}\n\nvoid receive(BDTO dto)\n{\n System.out.print(dto.url);\n}\n@RabbitListener(queues = \"your.queue.name\")\npublic void listenMesssage(Message message) \n {\n try \n {\n String typeId = message.getMessageProperties().getHeaders().get(\"__TypeId__\").toString();\n String contentType = message.getMessageProperties().getContentType();\n if (contentType != \"application/json\" || typeId == null || !typeId.contains(ADTO.class.toString()))\n {\n //TODO log warning\n System.out.print(\"type not supported by this service\");\n return;\n }\n Object receivedObject = new Jackson2JsonMessageConverter().fromMessage(message);\n\n if (receivedObject instanceof ADTO)\n {\n receive((ADTO)receivedObject);\n System.out.print(\"ADTO\");\n }\n //else\n```\n\nAlternatively, you can also do the serialisation like this:\n\n```\n....\nString typeId = message.getMessageProperties().getHeaders().get(\"__TypeId__\").toString();\nbyte[] binMsg = message.getBody();\nString strMsg = new String(binMsg, StandardCharsets.UTF_8);\nObjectMapper mapper = new ObjectMapper();\nif (typeId.contains(\"ADTO\"))\n{\n receive(mapper.readValue(strMsg, ADTO.class ));\n}\nelse\n...\n```\n\n========================================\n\nCode:\n```java\n@RabbitListener(queues = \"foo\")\n public class MyListener {\n\n private final ServiceA serviceA;\n\n private final ServiceB serviceB;\n\n public MyListener(ServiceA serviceA, ServiceB serviceB) {\n this.serviceA = serviceA;\n this.serviceB = serviceB;\n }\n\n\n @RabbitHandler\n public void handleA(A a) {\n this.serviceA.handle(a);\n }\n\n @RabbitHandler\n public void handleB(B b) {\n this.serviceB.handle(b);\n }\n }\n```\n\n```text\npayload\n```\n\n```text\n@RabbitListener\n```\n\n```text\nvoid receive(ADTO dto)\n{\n System.out.print(dto.url);\n}\n\nvoid receive(BDTO dto)\n{\n System.out.print(dto.url);\n}\n@RabbitListener(queues = \"your.queue.name\")\npublic void listenMesssage(Message message) \n {\n try \n {\n String typeId = message.getMessageProperties().getHeaders().get(\"__TypeId__\").toString();\n String contentType = message.getMessageProperties().getContentType();\n if (contentType != \"application/json\" || typeId == null || !typeId.contains(ADTO.class.toString()))\n {\n //TODO log warning\n System.out.print(\"type not supported by this service\");\n return;\n }\n Object receivedObject = new Jackson2JsonMessageConverter().fromMessage(message);\n\n if (receivedObject instanceof ADTO)\n {\n receive((ADTO)receivedObject);\n System.out.print(\"ADTO\");\n }\n //else\n```\n\n```text\n....\nString typeId = message.getMessageProperties().getHeaders().get(\"__TypeId__\").toString();\nbyte[] binMsg = message.getBody();\nString strMsg = new String(binMsg, StandardCharsets.UTF_8);\nObjectMapper mapper = new ObjectMapper();\nif (typeId.contains(\"ADTO\"))\n{\n receive(mapper.readValue(strMsg, ADTO.class ));\n}\nelse\n...\n```\n\n```text\n@RabbitListener(id=\"multi\", queues = \"somequeuename\")\npublic class SomeService \n{\n @RabbitHandler\n public void handleADTO(@Payload ADTO adto) {\n System.out.print(adto.url);\n }\n\n @RabbitHandler\n public void handleADTO2(@Payload ADTO2 adto) {\n System.out.print(adto.url);\n }\n}\n```\n\n```text\n@Bean\npublic SimpleRabbitListenerContainerFactory myFactory(\n SimpleRabbitListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory) {\n SimpleRabbitListenerContainerFactory factory =\n new SimpleRabbitListenerContainerFactory();\n configurer.configure(factory, connectionFactory);\n return factory;\n}\n\n@Bean\nJackson2JsonMessageConverter jsonMessageConverter() {\n return new Jackson2JsonMessageConverter();\n}\n\n@Bean\nRabbitTemplate rabbitTemplate(Jackson2JsonMessageConverter converter, ConnectionFactory connectionFactory) {\n RabbitTemplate template = new RabbitTemplate(connectionFactory);\n template.setMessageConverter(new Jackson2JsonMessageConverter());\n return template;\n}\n```\n\n========================================\n\nComments:\n- This is what I was already doing, just needed to verify there is no other way. I think the issue in Spring AMQP is that you cannot have multiple consumers on the same queue.\n- You can, but then they are going to be *competing consumers* and there won't be a way to control messages distribution for their payload type. You need to consume message, convert its `byte[]` into a desired type, and only after that your will be able to route the result to the appropriate method to process. But that is already out side of the AMQP protocol and that already will be an issue do not the protocol in the Spring AMQP. You can consider to use different queues for different payloads though and route them on the Broker level vial `routing key`.","metadata":{"transformedAt":"2026-08-18T18:33:20.322Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":197,"estimatedTokens":1472}}1095{"id":"stack-46128546","source":"stackoverflow","questionId":46128546,"title":"Masstransit error queue is consuming, but still is not empty","tags":[".net","rabbitmq","masstransit"],"text":"Title: Masstransit error queue is consuming, but still is not empty\nTags: .net, rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nI am using Mastransit 3.5.0 with RabbitMq. If queue consumers throws exception, its is handled by default MoveExceptionToTransportFilter and moved to _error queue. For _error queue I have seperate consumer:\n Consume(ConsumeContext> context)\n\nBehavior of Fault is rather different. Part of errors are handled and removed from _error queue, but part of error message still remain in error queue and do not consumed by this consumer. As I understand If I have Fault consumer then _error queue should be empty.\n\nI can not find explanation, why errors are still in queue. Maybe because these faults were once consumed, but I cant find any indication in the headers or else where?\n\n========================================\n\nCode:\n```text\nFaut<T>\n```\n\n```text\nFault\n```\n\n```text\nFault<T>\n```\n\n========================================\n\nComments:\n- Chris just posted a video about another way to handle messages in error queues: youtube.com/watch?v=h5gcHWizS7o&ab_channel=ChrisPatterson\n- Is there no way to properly consume the error queue, say in a second time, once the receiving hand has been corrected ?\n- You can use the Shovel plugin to move messages from the error queue back to the normal queue.\n- @AlexeyZimarev This answer should be in the MassTransit docs. None of this is obvious to a first-time user.\n- The docs have been updated to include that: masstransit.io/documentation/concepts/…","metadata":{"transformedAt":"2026-08-18T18:33:20.322Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":35,"estimatedTokens":384}}1096{"id":"stack-43996051","source":"stackoverflow","questionId":43996051,"title":"Configuring socket timeout on amqplib connect","tags":["node.js","rabbitmq","amqp","node-amqplib"],"text":"Title: Configuring socket timeout on amqplib connect\nTags: node.js, rabbitmq, amqp, node-amqplib\nSource: Stack Overflow\n\nQuestion:\nI'm running a cluster of 2 RabbitMQ servers (could be any number) and I have implemented a failover where my app loops the list of RabbitMQs and tries to reconnect when a connection drops.\n\nIf the RabbitMQ instance is down which I'm trying to connect to, it takes about 60 seconds to timeout before trying to the next one, which is a very long time. Is there a way to configure the timeout or some other way to make it fail faster. This is causing an unnecessary long downtime. The heartbeat takes care of detecting a failure on an existing connection, but the problem is the initial connect attempt.\n\nHere is my code used for connecting:\n\n```\nconnect(callback) {\n const self = this;\n\n amqp.connect(rabbitInstances[rabbitInstance] + \"?heartbeat=10\").then(conn => {\n conn.on(\"error\", function(err) {\n setTimeout(() => self.reconnect(callback), 5000));\n return;\n });\n\n conn.on(\"close\", function() {\n setTimeout(() => self.reconnect(callback), 5000));\n return;\n });\n\n connection = conn;\n whenConnected(callback);\n })\n .catch(err => {\n setTimeout(() => self.reconnect(callback), 5000));\n });\n}\n\nreconnect(callback) {\n this.rabbitInstance === (rabbitInstances.length - 1) ? this.rabbitInstance = 0 : this.rabbitInstance++;\n this.connect(callback)\n}\n```\n\n========================================\n\nCode:\n```text\nconnect(callback) {\n const self = this;\n\n amqp.connect(rabbitInstances[rabbitInstance] + \"?heartbeat=10\").then(conn => {\n conn.on(\"error\", function(err) {\n setTimeout(() => self.reconnect(callback), 5000));\n return;\n });\n\n conn.on(\"close\", function() {\n setTimeout(() => self.reconnect(callback), 5000));\n return;\n });\n\n connection = conn;\n whenConnected(callback);\n })\n .catch(err => {\n setTimeout(() => self.reconnect(callback), 5000));\n });\n}\n\nreconnect(callback) {\n this.rabbitInstance === (rabbitInstances.length - 1) ? this.rabbitInstance = 0 : this.rabbitInstance++;\n this.connect(callback)\n}\n```\n\n```text\nconst amqp = require('amqplib');\n\nconst connection = await amqp.connect('amqp://localhost', {\n timeout: 2000,\n servername: 'localhost',\n});\n```\n\n```text\namqplib\n```\n\n```text\nconnect\n```\n\n```text\namqplib\n```\n\n========================================\n\nComments:\n- Did you manage to work this out?\n- No I haven't found a solution. If I figure out something I will post it here. However I'm currently working on something else so this is not something I'm actively looking at.\n- Great! Haven't been working with amqplib for a couple of years, but it does seem that this has been added to the socket options already a while ago: link to PR. It's just missing from the documentation. Thanks for figuring this out!\n- Anyone coming back to this answer, the timeout is only on the handshake timeout, not on a connect timeout.","metadata":{"transformedAt":"2026-08-18T18:33:20.322Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":100,"estimatedTokens":746}}1097{"id":"stack-36454573","source":"stackoverflow","questionId":36454573,"title":"Handshake timeout ERROR with ssl connection in RabbitMQ","tags":["ssl","openssl","rabbitmq"],"text":"Title: Handshake timeout ERROR with ssl connection in RabbitMQ\nTags: ssl, openssl, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am this tutorial of RabbitMQ with ssl connections.\n\nI have configured the 5672 port for ssl connections and I am launching openssl tool\n\nfor testing the connection to the port in local(Is a offical docker container of RabbitMQ).\n\nMy rabbitmq.config is:\n\n```\n[{rabbit, [ {loopback_users, []},\n {tcp_listeners, [5671]},\n {ssl_listeners, [5672]},\n {auth_mechanisms, ['EXTERNAL','PLAIN']},\n {handshake_timeout, 60000},\n {ssl_options, [\n {cacertfile, \"/etc/rabbitmq/ssl/ca/cacert.pem\" },\n {certfile, \"/etc/rabbitmq/ssl/server/server.cert.pem\" },\n {keyfile, \"/etc/rabbitmq/ssl/server/server.key.pem\" },\n {verify, verify_peer},\n {ssl_cert_login_from, common_name},\n {fail_if_no_peer_cert, true }]}]}].\n```\n\nThen I execute this command:\n\n```\nopenssl s_client -connect localhost:5672 -cert ../client/client.pem -key ../client/client.key.pem -CAfile ../ca/cacert.pem\n```\n\nAnd I get this error in the RabbitMQ logs:\n\n```\n=INFO REPORT==== 6-Apr-2016::14:16:06 ===\naccepting AMQP connection (127.0.0.1:34977 -> 127.0.0.1:5672)\n\n=ERROR REPORT==== 6-Apr-2016::14:16:06 ===\nclosing AMQP connection (127.0.0.1:34977 -> 127.0.0.1:5672):\n{handshake_timeout,handshake}\n```\n\n========================================\n\nCode:\n```text\n[{rabbit, [ {loopback_users, []},\n {tcp_listeners, [5671]},\n {ssl_listeners, [5672]},\n {auth_mechanisms, ['EXTERNAL','PLAIN']},\n {handshake_timeout, 60000},\n {ssl_options, [\n {cacertfile, \"/etc/rabbitmq/ssl/ca/cacert.pem\" },\n {certfile, \"/etc/rabbitmq/ssl/server/server.cert.pem\" },\n {keyfile, \"/etc/rabbitmq/ssl/server/server.key.pem\" },\n {verify, verify_peer},\n {ssl_cert_login_from, common_name},\n {fail_if_no_peer_cert, true }]}]}].\n```\n\n```text\nopenssl s_client -connect localhost:5672 -cert ../client/client.pem -key ../client/client.key.pem -CAfile ../ca/cacert.pem\n```\n\n```text\n=INFO REPORT==== 6-Apr-2016::14:16:06 ===\naccepting AMQP connection <0.696.0> (127.0.0.1:34977 -> 127.0.0.1:5672)\n\n=ERROR REPORT==== 6-Apr-2016::14:16:06 ===\nclosing AMQP connection <0.696.0> (127.0.0.1:34977 -> 127.0.0.1:5672):\n{handshake_timeout,handshake}\n```\n\n```text\n{handshake_timeout, handshake}\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.322Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":79,"estimatedTokens":578}}1098{"id":"stack-54012421","source":"stackoverflow","questionId":54012421,"title":"Defining a Message Passing domain with very many message types","tags":["reflection","f#","rabbitmq","domain-driven-design","message-queue"],"text":"Title: Defining a Message Passing domain with very many message types\nTags: reflection, f#, rabbitmq, domain-driven-design, message-queue\nSource: Stack Overflow\n\nQuestion:\nMost F# Message Passing examples I've seen so far are working with 2-4 message types, and are able to utilize pattern matching to direct each message to its proper handler function. \n\nFor my application, I need hundreds of unique message types due to the different nature of their handling and required parameters. So far, each message type is its own record type with a marker interface attached, because including hundreds of types in a single discriminated union would not be very pretty - and neither would the pattern matching of these be. As a result, I'm currently using reflection to find the correct handler functions of messages.\n\nIs there a better, and more functional way of doing this? Perhaps even a smarter way to define such a domain? I'd like to enforce as much correctness as possible at compile time, but currently I'm finding the handler functions based on a custom attribute, as well as checking their signature at run time. \n\nAs far as I know, I cannot enforce a function's signature with a .NET custom attribute, and since there are too many types to realistically pattern match, I can't (to my knowledge) use a single generic message handler function either. I tried using a generic wrapper function as an \"interface\" for all handlers, and only attaching the custom attribute to this one, but this didn't grant the wrapped functions the attribute and make them visible through reflection based on that attribute (I'm very new to .NET).\n\nI have thought about the possibility of attaching the handler functions to their respective record type as a member, which would circumvent the need for reflection and enforce some additional correctness at compile time. However, it doesn't make much sense to have all those functions present client side.\n\n========================================\n\nCode:\n```text\ntype MessageType = MessageType of string\ntype Message<'T> = {\n messageType : MessageType\n message : 'T\n}\n```\n\n```text\ntype HandlerResult = Result<string, string>\ntype MessageHandler<'T> = {\n messageType : MessageType\n handlerF : Message<'T> -> HandlerResult\n}\n```\n\n```text\nlet Handlers = System.Collections.Generic.Dictionary<MessageType, MessageHandler<obj>>()\n```\n\n```text\nlet ofMessageGen (msg: Message<obj>) : Message<_> = {\n messageType = msg.messageType\n message = unbox msg.message\n}\n```\n\n```text\nlet registerHandler (handlerF:Message<'T> -> HandlerResult) = \n let handler = {\n messageType = MessageType <| (typeof<'T>).FullName\n handlerF = ofMessageGen >> handlerF\n }\n Handlers.Add(handler.messageType, handler )\n```\n\n```text\nregisterHandler (fun msg -> sprintf \"String message: %s\" msg.message |> Ok )\nregisterHandler (fun msg -> sprintf \"int message: %d\" msg.message |> Ok )\nregisterHandler (fun msg -> sprintf \"float message: %f\" msg.message |> Ok )\n```\n\n```text\nlet genericHandler (msg:Message<obj>) : HandlerResult =\n match Handlers.TryGetValue msg.messageType with\n | false, _ -> Error <| sprintf \"No Handler for message: %A\" msg\n | true , handler -> handler.handlerF msg\n```\n\n```text\nlet createMessage (m:'T) = {\n messageType = MessageType <| (typeof<'T>).FullName\n message = box m\n}\n```\n\n```text\ncreateMessage \"Hello\" |> genericHandler |> printfn \"%A\" \ncreateMessage 123 |> genericHandler |> printfn \"%A\" \ncreateMessage 123.4 |> genericHandler |> printfn \"%A\" \ncreateMessage true |> genericHandler |> printfn \"%A\" \n\n// Ok \"String message: Hello\"\n// Ok \"int message: 123\"\n// Ok \"float message: 123.400000\" \n// Error\n// \"No Handler for message: {messageType = MessageType \"System.Boolean\";\n// message = true;}\"\n```\n\n```text\nmessageId\n```\n\n```text\nsender\n```\n\n```text\nreceiver\n```\n\n```text\nMessageHandler<obj>\n```\n\n```text\n<'T>\n```\n\n```text\n<obj>\n```\n\n```text\n<obj>\n```\n\n========================================\n\nComments:\n- Very interesting approach that definitely achieves more checking of correctness compile time than my reflection implementation. Thanks a lot! I've tested it a little just now and tried to add some of my own app features. Going to have to continue tomorrow as it's 4 am where I live, but this looks very promising.\n- I am glad you like it :)","metadata":{"transformedAt":"2026-08-18T18:33:20.322Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":16,"totalLines":121,"estimatedTokens":1098}}1099{"id":"stack-41853686","source":"stackoverflow","questionId":41853686,"title":"Using RabbitMQ in for communication between different Docker container","tags":["docker","rabbitmq","message-queue","microservices"],"text":"Title: Using RabbitMQ in for communication between different Docker container\nTags: docker, rabbitmq, message-queue, microservices\nSource: Stack Overflow\n\nQuestion:\nI want to communicate between 2 apps stored in different docker containers, both part of the same docker network. I'll be using a message queue for this ( RabbitMQ )\n\nShould I make a 3rd Docker container that will run as my RabbitMQ server, and then just make a channel on it for those 2 specific containers ? So that later on I can make more channels if I need for example a 3rd app that needs to communicate with the other 2?\n\nRegards!\n\n========================================\n\nTop Answer:\nIf you started using containers, than it's the right way to go. But if you your app is deployed in cloud (AWS, Azure and so on) it's better to use cloud queue service which is already configured, is updated automatically, has monitoring and so on.\n\nI'd like also to point out that docker containers it's only a way to deploy your application components. Application shouldn't take care about how your components (services, dbs, queues and so on) are deployed. For app service a message queue is simply a service located somewhere, accessible by connection parameters.\n\n========================================\n\nComments:\n- Hi! I've already started, it's kind off an experimental project so I'll go on with it the way I started. Thanks for the hookup though!","metadata":{"transformedAt":"2026-08-18T18:33:20.322Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":22,"estimatedTokens":354}}1100{"id":"stack-10767037","source":"stackoverflow","questionId":10767037,"title":"control rabbitmq 'name' not 'sname'","tags":["crash","erlang","osx-lion","rabbitmq","startup"],"text":"Title: control rabbitmq 'name' not 'sname'\nTags: crash, erlang, osx-lion, rabbitmq, startup\nSource: Stack Overflow\n\nQuestion:\nOn lion OS, after installation, when running, error happens. \nAt first, not using `rabbitmq-env.config file`, starting by `\"sudo rabbitmq-server\"`, the following message shows:\n\n```\nyus-iMac:rabbitmq yuchen$ sudo rabbitmq-server\nActivating RabbitMQ plugins ...\n\n********************************************************************************\n********************************************************************************\n\n0 plugins activated:\n\nERROR: epmd error for host \"yus-iMac\": address (unable to establish tcp connection)\n```\n\nThen I add `rabbitmq-env.conf` file. The content is as follows:\n\n```\nRABBITMQ_NODENAME=rabbitb@yus-iMac.local\n\nWhen starting, another error message is given:\n\nyus-iMac:rabbitmq yuchen$ sudo rabbitmq-server\nActivating RabbitMQ plugins ...\n\n********************************************************************************\n********************************************************************************\n\n0 plugins activated:\n\n{error_logger,{{2012,5,26},{21,47,13}},\"Can't set short node name!\\n Please check your configuration\\n\",[]}\n```\n\nI think the message means short node can't be used. But I don't know how to control `rabbitmq-server` for using `name`, rather than `sname`?\n\n========================================\n\nCode:\n```text\nyus-iMac:rabbitmq yuchen$ sudo rabbitmq-server\nActivating RabbitMQ plugins ...\n\n********************************************************************************\n********************************************************************************\n\n0 plugins activated:\n\nERROR: epmd error for host \"yus-iMac\": address (unable to establish tcp connection)\n```\n\n```text\nRABBITMQ_NODENAME=rabbitb@yus-iMac.local\n\nWhen starting, another error message is given:\n\nyus-iMac:rabbitmq yuchen$ sudo rabbitmq-server\nActivating RabbitMQ plugins ...\n\n********************************************************************************\n********************************************************************************\n\n0 plugins activated:\n\n{error_logger,{{2012,5,26},{21,47,13}},\"Can't set short node name!\\n Please check your configuration\\n\",[]}\n```\n\n```text\nrabbitmq-env.config file\n```\n\n```text\n\"sudo rabbitmq-server\"\n```\n\n```text\nrabbitmq-env.conf\n```\n\n```text\nrabbitmq-server\n```\n\n```text\nname\n```\n\n```text\nsname\n```\n\n```text\n##\n# Host Database\n#\n# localhost is used to configure the loopback interface\n# when the system is booting. Do not change this entry.\n##\n127.0.0.1 localhost rs-mbp\n255.255.255.255 broadcasthost\n::1 localhost\nfe80::1%lo0 localhost\n```\n\n========================================\n\nComments:\n- Due to chinese country's firewall, the above link of wordpress.com can't be visited. After finding rabbitmq-server is a script file, I opened the file, and find in the last paragprah, -sname is hardcoded. After modifying the source code of 'rabbitmq-server, the problem has been solved.\n- I feel sorry for that. The part of the blog had been updated in the answer.\n- Where do you find your \"machine name\"?\n- The machine name could be find by executing the command `hostname` in shell.","metadata":{"transformedAt":"2026-08-18T18:33:20.322Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":9,"totalLines":115,"estimatedTokens":801}}1101{"id":"stack-48744428","source":"stackoverflow","questionId":48744428,"title":"Proxying internal traffic to Azure Service Bus","tags":["rabbitmq","azureservicebus","rabbitmq-shovel"],"text":"Title: Proxying internal traffic to Azure Service Bus\nTags: rabbitmq, azureservicebus, rabbitmq-shovel\nSource: Stack Overflow\n\nQuestion:\nWhat I'm trying to achieve is interoperability between RabbitMQ clients in an internal network, and Azure Service Bus consumers running in Azure.\n\nThe RabbitMQ clients need to publish and subscribe, as do the Azure Service Bus consumers - so I need some kind of 'bi-directional proxy'. A diagram of what I'm trying to achieve:\n\n```\n+\n Internal network | Azure\n |\n |\n+--------+ | +----------+\n| Client +---+ | +---+ Consumer |\n+--------+ | | | +----------+\n | | |\n | +-----------------+ | +-------------------+ |\n +-+ RabbitMQ Broker +---------+ Azure Service Bus +--+\n | +-----------------+ | +-------------------+ |\n | | |\n+--------+ | | | +----------+\n| Client +---+ | +---+ Consumer |\n+--------+ | +----------+\n |\n |\n |\n +\n```\n\nAFAIK, both the RabbitMQ broker and Azure Service Bus can do AMQP 1.0. I've looked at the rabbit shovel plugin, but I *think* this would only handle publishing of messages from the internal clients to Azure, and wouldn't allow the clients to subscribe to messages published by the Azure consumers? Or have I got this wrong, and shovel will work for this?\n\nIf shovel won't work, is there any other way to achieve this\n\n========================================\n\nCode:\n```text\n+\n Internal network | Azure\n |\n |\n+--------+ | +----------+\n| Client +---+ | +---+ Consumer |\n+--------+ | | | +----------+\n | | |\n | +-----------------+ | +-------------------+ |\n +-+ RabbitMQ Broker +---------+ Azure Service Bus +--+\n | +-----------------+ | +-------------------+ |\n | | |\n+--------+ | | | +----------+\n| Client +---+ | +---+ Consumer |\n+--------+ | +----------+\n |\n |\n |\n +\n```\n\n```text\nGroupId\n```\n\n```text\namqpMessage.Properties.GroupId = mySessionId\n```\n\n```text\nx-opt-partition-key\n```\n\n```text\namqpMessage.MessageAnnotations[new Symbol(\"x-opt-partition-key\")] = myPartitionKey\n```\n\n========================================\n\nComments:\n- docs.particular.net/nservicebus/bridge is designed for exactly these kinds of scenarios\n- @RobBowman in theory it should work, but I couldn't get it to. I spent a lot of time messing with the Shovel plugin, but never got it to even connect to Service Bus. I see there have been some relevant PRs since, and various questions over on rabbitmq-users where it looks like others have got it working\n- This answer has helped me a lot. I've followed Microsoft guide and it worked for me :)","metadata":{"transformedAt":"2026-08-18T18:33:20.322Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":82,"estimatedTokens":805}}1102{"id":"stack-34282982","source":"stackoverflow","questionId":34282982,"title":"Is it possible to pass JSON object to the RabbitMQ queue using java application?","tags":["java","json","spring-boot","rabbitmq","spring-rabbit"],"text":"Title: Is it possible to pass JSON object to the RabbitMQ queue using java application?\nTags: java, json, spring-boot, rabbitmq, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI want to pass JSON object to the RabbitMQ queue. \n\nIn the below code, I am using `obj.toJSONString().getBytes()` for converting Json object in to string, Is it possible to pass JSON object in the queue instead passing as string.\n\n\r\n\r\n\n```\nJSONObject obj = new JSONObject();\r\nobj.put(\"Transaction\",\"Test value\"); \r\nchannel.basicPublish(\"\", queueName, null, obj.toJSONString().getBytes()); \r\nSystem.out.println(\" [x] Sent '\" + obj.toJSONString() + \"'\");\n```\n\n========================================\n\nTop Answer:\nNo Its not possible\nIn Rabbit MQ you can pass objects if object type is implementing Serializable interface.\n\nThere is another way you can write is using apache-commons jar's to serialize your object:\n\n```\nSerializationUtils.serialize(obj);\n```\n\nThis Guy will Serializes an Object to a byte array for storage.\n\n========================================\n\nCode:\n```html\nJSONObject obj = new JSONObject();\nobj.put(\"Transaction\",\"Test value\");\t\t\t\t\t\t\t\t\nchannel.basicPublish(\"\", queueName, null, obj.toJSONString().getBytes()); \nSystem.out.println(\" [x] Sent '\" + obj.toJSONString() + \"'\");\n```\n\n```text\nobj.toJSONString().getBytes()\n```\n\n```text\nobj.toJSONString().getBytes()\n```\n\n```text\nSerializationUtils.serialize(obj);\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.322Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":54,"estimatedTokens":353}}1103{"id":"stack-47875771","source":"stackoverflow","questionId":47875771,"title":"NodeJS, Rabbitmq & Docker: the service using Seneca seems to start before RabbitMQ","tags":["node.js","rabbitmq","docker-compose","seneca"],"text":"Title: NodeJS, Rabbitmq & Docker: the service using Seneca seems to start before RabbitMQ\nTags: node.js, rabbitmq, docker-compose, seneca\nSource: Stack Overflow\n\nQuestion:\nI am using Docker to create multiple containers, one of which contains a RabbitMQ instance and another contains the node.js action that should respond to queue activity. Traversing the docker-compose logs, I see a lot of ECONNREFUSED errors, before I see where the line begins indicating that RabbitMQ has started in its container. This seems to indicate that RabbitMQ seems to be starting after the service that needs it.\n\nAs a sidebar, just to eliminate any other possible causes here is the connection string for node.js to connect to RabbitMQ:\n\n```\namqp://rabbitmq:5672\n```\n\nand here is the entry for RabbitMQ in the docker-compose.yaml file:\n\n```\nrabbitmq:\ncontainer_name: \"myapp_rabbitmq\"\n tty: true\n image: rabbitmq:management\n ports:\n - 15672:15672\n - 15671:15671\n - 5672:5672\n volumes:\n - /rabbitmq/lib:/var/lib/rabbitmq\n - /rabbitmq/log:/var/log/rabbitmq\n - /rabbitmq/conf:/etc/rabbitmq/\nservice1:\n container_name: \"service1\"\n build:\n context: .\n dockerfile: ./service1.dockerfile\n links:\n - mongo\n - rabbitmq\n depends_on:\n - mongo\n - rabbitmq\nservice2:\n container_name: \"service2\"\n build:\n context: .\n dockerfile: ./service2/dockerfile\n links:\n - mongo\n - rabbitmq\n depends_on:\n - mongo\n - rabbitmq\n```\n\nWhat is the fix for this timing issue?\n\nHow could I get RabbitMQ to start before the consuming container starts?\n\nMight this not be a timing issue, but a configuration issue in the docker-compose.yml entry I have listed?\n\n========================================\n\nTop Answer:\nIt doesn't look like you have included a complete docker-compose file. I would expect to also see your node container in the compose. I think the problem is that you need a \n\n```\ndepends_on:\n - \"rabbitmq\"\n```\n\nIn the node container part of your docker compose\n\nMore info on compose dependancies here: https://docs.docker.com/compose/startup-order/\n\nnote, as this page suggests you should do this in conjunction with making your app resilient to outages on external services.\n\n========================================\n\nCode:\n```text\namqp://rabbitmq:5672\n```\n\n```text\nrabbitmq:\ncontainer_name: \"myapp_rabbitmq\"\n tty: true\n image: rabbitmq:management\n ports:\n - 15672:15672\n - 15671:15671\n - 5672:5672\n volumes:\n - /rabbitmq/lib:/var/lib/rabbitmq\n - /rabbitmq/log:/var/log/rabbitmq\n - /rabbitmq/conf:/etc/rabbitmq/\nservice1:\n container_name: \"service1\"\n build:\n context: .\n dockerfile: ./service1.dockerfile\n links:\n - mongo\n - rabbitmq\n depends_on:\n - mongo\n - rabbitmq\nservice2:\n container_name: \"service2\"\n build:\n context: .\n dockerfile: ./service2/dockerfile\n links:\n - mongo\n - rabbitmq\n depends_on:\n - mongo\n - rabbitmq\n```\n\n```text\nwait-for-it.sh rabbitmq:5672 -t 90 -- command with args to launch service1\n```\n\n```text\nwait-for-it.sh\n```\n\n```text\nservice1\n```\n\n```text\ndepends_on:\n - \"rabbitmq\"\n```\n\n========================================\n\nComments:\n- I added the other services that depend on rabbitmq. I added a depends_on for both of them.\n- I added the script and am getting \"ERROR: for app_myapp Cannot start service my app: oci runtime error: container_linux.go:265: starting container process caused \"exec: \\\"./wait-for-it.sh\\\": stat ./wait-for-it.sh: no such file or directory\". This is strange as the docker_compose.yaml file is in the same folder as the wait-for-it.sh file. This is the command line I added, \"command: [\"./wait-for-it.sh\", \"rabbitmq:5672\", \"-t\", \"90\"]\"","metadata":{"transformedAt":"2026-08-18T18:33:20.322Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":140,"estimatedTokens":912}}1104{"id":"stack-35540645","source":"stackoverflow","questionId":35540645,"title":"Is it safe to expose rabbitmq amqp port over the internet?","tags":["rabbitmq","iot"],"text":"Title: Is it safe to expose rabbitmq amqp port over the internet?\nTags: rabbitmq, iot\nSource: Stack Overflow\n\nQuestion:\nI have a lot of different machines in multiple geographical locations. I need to command them from my backend and get data from them. I was thinking about connecting them all to a rabbitmq amqps connection to enable the bi-directionnel communication of my machines.\n\nIs it a good approach? Is rabbitmq secure enough to do that?\n\n========================================\n\nComments:\n- Are usernames / passwords implemented through RabbitMQ, or do you need some third party security layer?","metadata":{"transformedAt":"2026-08-18T18:33:20.322Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":13,"estimatedTokens":152}}1105{"id":"stack-15911588","source":"stackoverflow","questionId":15911588,"title":"Message bus: sender must wait for acknowledgements from multiple recipients","tags":["rabbitmq","message-bus"],"text":"Title: Message bus: sender must wait for acknowledgements from multiple recipients\nTags: rabbitmq, message-bus\nSource: Stack Overflow\n\nQuestion:\nIn our application the publisher creates a message and sends it to a topic.\n\nIt then needs to wait, when all of the topic's subscribers ack the message.\n\nIt does not appear, the message bus implementations can do this automatically. So we are leaning towards making each subscriber send their own new message for the client, when they are done.\n\nNow, the client can receive all such messages and, when it got one from each destination, do whatever clean-ups it has to do. But what if the client (sender) crashes part way through the stream of acknowledgments? To handle such a misfortune, I need to (re)implement, what the buses already implement, on the client -- save the incoming acknowledgments until I get enough of them.\n\nI don't believe, our needs are that esoteric -- how would you handle the situation, where the sender (publisher) must wait for confirmations from *multiple* recipients (subscribers)? Sort of like requesting (and awaiting) Return-Receipts from each subscriber to a mailing list...\n\nWe are using RabbitMQ, if it matters. Thanks!\n\n========================================\n\nComments:\n- Thanks, Chris. Yes, this is what've done: each consumer sends its own message \"back\" -- to a separate queue, which was specified by the original publisher. It works -- and, perhaps, better than using RPCs would, because the aggregator of these confirmations does not have to be online at the same time as the confirming consumer. But the aggregator's code reimplements some of the functionality (such as reboot-tolerance) already found in the broker and I was hoping to leverage the latter for the purpose...","metadata":{"transformedAt":"2026-08-18T18:33:20.322Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":21,"estimatedTokens":441}}1106{"id":"stack-21333318","source":"stackoverflow","questionId":21333318,"title":"Server-defined exchanges vs User-defined exchanges","tags":["rabbitmq"],"text":"Title: Server-defined exchanges vs User-defined exchanges\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nAre there any advantages in creating your own exchanges in RabbitMQ?\n\nE.g. using \"amq.direct\" vs \"my_direct_exchange\" of type=direct.\n\n========================================\n\nCode:\n```text\namq.*\n```\n\n```text\namq.*\n```\n\n```text\namq.*\n```\n\n```text\namq.\n```\n\n```text\namq.*\n```\n\n```text\namq.rabbitmq.{trace,log}\n```\n\n```text\namq.*\n```\n\n```text\namq.*\n```\n\n```text\namq.topic\n```\n\n```text\namq.rabbitmq.log\n```\n\n```text\namq.rabbitmq.trace\n```\n\n```text\namq.match\n```\n\n```text\namq.headers\n```\n\n```text\nheaders\n```\n\n```text\namq.match\n```\n\n========================================\n\nComments:\n- Could you elaborate on the \"special needs\" ?\n- Updated my answer. You can also ask this question on IRC or mailing list or even in twitter (see rabbitmq.com/contact.html)\n- Does the exchange choice somehow affect the performance (as other apps might be using the server-defined exchange) ?\n- There are no different between predefined an user-defined queues AFIK. But if your messages flow intersect you may get unexpected messages in your queue which may cause both consumer failure. E.g. you publish to `amq.topic` exchange to queue `fruits` only apples and pears, but some other publish will also utilize `amq.topic` and also send somethng to `fruits`, let say oranges and apricot. As you can see now all four types will be in the same queue. Sometimes (I guess they are rare like Citroen C1 in sport coupe) it's expected behavior, but mostly we use project-specific exchanges and queues.\n- Well I had in mind the scenario where the same exchange is used by multiple apps which publish/consume from their respective queues (i.e. different apps use different queues but route through the same exchange).\n- You should not worry about performance, RabbitMQ smart enough to use various techniques to minimize route costs. So it less likes that you'll ever have bottleneck in low routing performance.","metadata":{"transformedAt":"2026-08-18T18:33:20.322Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":15,"totalLines":81,"estimatedTokens":497}}1107{"id":"stack-22939697","source":"stackoverflow","questionId":22939697,"title":"How can I tell two JSON objects apart on one RabbitMQ queue?","tags":["c#","json","rabbitmq","deserialization"],"text":"Title: How can I tell two JSON objects apart on one RabbitMQ queue?\nTags: c#, json, rabbitmq, deserialization\nSource: Stack Overflow\n\nQuestion:\nI want to be able to send two different JSON messages on one queue. How do I, in C#, determine what type of message was received so that I can deserialize the message to the proper object? Should I use a message header or create another queue? A queue per message type seems excessive to me. Thanks!\n\nExtra Details:\nI have a Windows service that processes \"runs\". A run ID is assigned by another system and the ID is dropped on a queue. My service picks up the ID and starts work. An object is created for each run. Right now, if I want to cancel work, I have to stop the service. But, that stops all work. I wanted to add a CancelRun type method, but all I need to the run ID. So, I could use the exact same JSON (so same class). Two queues wouldn't be horrible, but I thought it might be clever to add the type or something to a custom header.\n\n========================================\n\nTop Answer:\nIf an order or receiving and processing of these messages is not an issue I would like to suggest using separate queues for each type, it's not a problem for rabbit to handle tons of queues.\nIf not, the order is crucial for you, you can put marker in header of the message defining it's type, however this will bind your Business Logic with transportation layer. In case you will want to change the transportation layer later in your application, you will have to adopt this section of code to keep it work. Instead of this you can make some sort of wrapper for both of those object types which hides the internal content, looks the same and can desalinize itself in type it contains.\n\n========================================\n\nCode:\n```text\nIBasicProperties props = model.CreateBasicProperties();\nprops.Headers = new Dictionary<string, object>();\nprops.Headers.Add(\"RequestType\", \"CancelRunRequest\");\n```\n\n```text\n// Raise message received event\nvar args = new MessageReceivedArgs();\nargs.CorrelationId = response.BasicProperties.CorrelationId;\nargs.Message = Encoding.UTF8.GetString(response.Body);\nargs.Exchange = response.Exchange;\nargs.RoutingKey = response.RoutingKey;\n\nif (response.BasicProperties.Headers != null && response.BasicProperties.Headers.ContainsKey(\"RequestType\"))\n{\nargs.RequestType = Encoding.UTF8.GetString((byte[])response.BasicProperties.Headers[\"RequestType\"]);\n}\n\nMessageReceived(this, args);\nmodel.BasicAck(response.DeliveryTag, false);\n```\n\n```text\nprivate void NewRunIdReceived(object p, MessageReceivedArgs e)\n{\n\nif(e.RequestType.ToUpper() == \"CANCELRUNREQUEST\")\n{\n // This is a cancellation request\n CancelRun(e);\n}\nelse\n{\n // Default to startrun request for backwards compatibility.\n StartRun(e);\n}\n}\n```\n\n```text\nObjectType1 : HaveType \n\npublic class HaveType { public string Type { get { this.GetType(); }}}\n```\n\n```text\n[{Type: 'ObjectType1', ...[other object stuff]},{Type : 'ObjectType2',...}]\n```\n\n========================================\n\nComments:\n- Since the type isn't in the JSON, would adding the type to the message header be appropriate?\n- I thought about that, too. I could add a bool for CancelRun and have it be false for new work and true for work to cancel, but that seemed kind of janky to me.\n- I have no idea why no one marked this correct answer, its the best way, keep message body clean, and use the metadata as one should do. right answer for me. Well done\n- @sacha Thanks! I didn't want to accept my own answer without some other input first. I appreciate the feedback!\n- I did consider separate queues, but that seemed excessive to me at the time. I really like your idea of a wrapper class that can figure out the correct object to generate. Sounds a bit like a factory pattern.\n- Handling multiple queues for rabbit is not a problem in terms of performance, until it's something bounded not continuously growing.\n- I wasn't worried about a performance issue. I didn't want to get in the habit of making a new queue each time I defined a new message class.\n- If performance not an issue - just focus on good design and code layout. Keep in mind that probably later on you would like to send third type of JSON object via same pipe in your system, just make it easier to add without changing lots of code.","metadata":{"transformedAt":"2026-08-18T18:33:20.322Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":80,"estimatedTokens":1081}}1108{"id":"stack-53837302","source":"stackoverflow","questionId":53837302,"title":"How to use RabbitMQ message as a \"Rest Api\" to find entities?","tags":["rest","rabbitmq","message-queue"],"text":"Title: How to use RabbitMQ message as a \"Rest Api\" to find entities?\nTags: rest, rabbitmq, message-queue\nSource: Stack Overflow\n\nQuestion:\nI'm having a problem to solve in an application. I'll show an example about it.\n\nI have a rabbitmq queue on a system that is responsable to return Orders, called by another systems (the communication among these systems is only throught message). Until then, **the only possible Order search was by the order code**.\n\nIt works well. When I search by order code, I also filter by the order with contracts and deleted (logically). So, if the order has no contracts or it was deleted, the query doesn't return registers. \n\n**Now, one of that systems needs to find Orders without contracts and/or deleted.**\n\nBasically, I believe I need to build the same logic used in an API rest like this one, but using a queue message:\n\n```\n/api/orders?id=123455?deleted=true&hasContracts=true\n```\n\nDo that it's easy with message. I just need send a message with this format. \n\n```\n{\n \"code\": 123,\n \"deleted\": true,\n \"hasContract\": true\n}\n```\n\nMapping the values for `Long` and `Boolean` classes. If the information was `null`, this filter will be ignored by the query, except the `code` that's mandatory.\n\nThe doubt is: is this makes sense? I didn't find anything about this subject on the Internet. Create a queue for each case is not an option, because it will be hard for us to implement many queues.\n\n========================================\n\nCode:\n```text\n/api/orders?id=123455?deleted=true&hasContracts=true\n```\n\n```text\n{\n \"code\": 123,\n \"deleted\": true,\n \"hasContract\": true\n}\n```\n\n```text\nLong\n```\n\n```text\nBoolean\n```\n\n```text\nnull\n```\n\n```text\ncode\n```\n\n========================================\n\nComments:\n- Could you please specify how the acquiring system will figure out that some particular order in queue is what it was asking for? I mean, there are plenty of orders in the queue, don't you want only some particular be handled?\n- I'm not sure to get exactly your use case. When you say \"I have a RabbitMQ queue that is responsible to return Orders\", do you mean you have one queue and many consumers on it? Today, how do other systems query your API? And how do they get back the answer?\n- We have a more than one micro service that ask for Orders and one microservice responsable for return the asked Order (we call him as `order-service`). The communication is synchronous (RPC - Remote Procedure Call) using RabbitMQ: the service send a order code in a message for a queue and the `order-service` get the message from the queue and return de Order for the service that requested it.\n- Hello, can I somehow get messages with HTTP API by filtering it ? For example, I want to get messages by some properties or headers ?\n- Not sure to understand your question: what HTTP API? The RabbitMQ admin API? It is not a good way to use RabbitMQ if you mean it.","metadata":{"transformedAt":"2026-08-18T18:33:20.322Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":72,"estimatedTokens":726}}1109{"id":"stack-6369190","source":"stackoverflow","questionId":6369190,"title":"What open source message queuing software provides durability with strict ordering?","tags":["c#","message-queue","rabbitmq","messagebroker"],"text":"Title: What open source message queuing software provides durability with strict ordering?\nTags: c#, message-queue, rabbitmq, messagebroker\nSource: Stack Overflow\n\nQuestion:\nWhat we need is RabbitMQ that actually works as a queue and doesn't do this. Messages should stay at the head of a queue untill client dequeues them explicitly.\n\nIt seems like a very straightforward scenario, but for some reason I can't find any broker to support it.. A broker should run on Windows OS.\n\n========================================\n\nTop Answer:\nIf it is only one message that is the problem, why not write it to a file (and flush the file) before you process the message. After acking the message, delete the file. \n\nAnd if you are concerned about the message broker crashing, first step is to upgrade it to RabbitMQ 2.4.1 running on Erlang R14B02. Second step is to cluster it so that you have multiple servers acting as the MQ broker. And only then, change your app to track the messages that have been processed, either by timestamp or by saving message IDs. Then, if RabbitMQ requeues a message, you will already have it and will process it and remember it. When it comes around a second time you will ignore it.\n\nYou may need to set prefetch to 0 for this to work right.\n\nAnd there is another alternative too. You could consider writing your own RabbitMQ plugin to provide the exact behaviour that you need. Erlang may look complex at first sight, but it really isn't that hard to learn for an experienced programmer who has already learned a few languages. In particular, if you have anyone with functional programming experience in languages like Haskell or CAML, they will quickly pick up enough Erlang to do the job.\n\nBecause of Erlang's internal model of message-passing processes, RabbitMQ plugins can essentially do anything that they want. There is no specific limited plugin API that they need to conform to. \n\nIn other words, if RabbitMQ only does 99% of what you need, consider yourself lucky that with a small amount of work, you can leverage that 99% and achieve everything that you need. But in order to do this you have to get away from the idea that RabbitMQ is yet another package that you install with your system's package installation tools. In cases like yours RabbitMQ should be considered to be a mission critical tool, and you should install Erlang and RabbitMQ from source, and configure them to your needs without letting your OS limit you.\n\n========================================\n\nComments:\n- What is your real business / application scenario? Also WCF can be configured to use queues.\n- your link seems to be broken, what are you referring to?","metadata":{"transformedAt":"2026-08-18T18:33:20.322Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":29,"estimatedTokens":667}}1110{"id":"stack-3735482","source":"stackoverflow","questionId":3735482,"title":"RabbitMQ Question - Is there a way to print log message to console?","tags":["rabbitmq"],"text":"Title: RabbitMQ Question - Is there a way to print log message to console?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am running RabbitMQ on windows 7 ( currently for debug reasons).\nI want to see the messages on the open console each time I send a message.\nIs there a way to rout the logs to the open console? \n10x\n\n========================================\n\nTop Answer:\nYou can do it in, the programming language you are using to Publish and consume messages from RabbitMQ.","metadata":{"transformedAt":"2026-08-18T18:33:20.322Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":14,"estimatedTokens":121}}1111{"id":"stack-75425922","source":"stackoverflow","questionId":75425922,"title":"RabbitMQ: None of the specified endpoints were reachable?","tags":["rabbitmq","masstransit"],"text":"Title: RabbitMQ: None of the specified endpoints were reachable?\nTags: rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nTrying to publish a message to RabbitMQ using Masstransit but its failing.\n\nI've looked at a few SO posts on this but none have a concrete answer. I've tried different ways of formatting the connection string, hard coding, etc but nothing seems to work.\n\nIf I connect outside of the app just via the browser, everything works fine.\n\nIn my app though, it just can't connect?\n\n```\n[09:09:46 WRN] Connection Failed: rabbitmq://{host}:15672/\nRabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable\n ---> System.IO.IOException: connection.start was never received, likely due to a network timeout\n```\n\nI'm registering it like:\n\n```\nserviceCollection.AddMassTransit(x =>\n {\n x.UsingRabbitMq((rabbitContext, rabbitConfig) =>\n {\n rabbitConfig.Host(new Uri(\"amqps://{host}:15672/\"), h =>\n {\n h.Username(\"admin\");\n h.Password(\"...\");\n });\n \n rabbitConfig.ConfigureEndpoints(rabbitContext);\n rabbitConfig.Durable = true;\n });\n });\n```\n\nIf I just use the RabbitMQ library it also connects fine, so Masstransit seems to be the issue here?\n\n/var/log/rabbitmq/rabbit@mg.log only logs failed connections via the management panel it seems, at least its not logging for failed app connects.\n\n========================================\n\nCode:\n```text\n[09:09:46 WRN] Connection Failed: rabbitmq://{host}:15672/\nRabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable\n ---> System.IO.IOException: connection.start was never received, likely due to a network timeout\n```\n\n```text\nserviceCollection.AddMassTransit(x =>\n {\n x.UsingRabbitMq((rabbitContext, rabbitConfig) =>\n {\n rabbitConfig.Host(new Uri(\"amqps://{host}:15672/\"), h =>\n {\n h.Username(\"admin\");\n h.Password(\"...\");\n });\n \n rabbitConfig.ConfigureEndpoints(rabbitContext);\n rabbitConfig.Durable = true;\n });\n });\n```\n\n========================================\n\nComments:\n- Thanks! You saved me a ton of time, the issue was it was using port 5672, not 15672.","metadata":{"transformedAt":"2026-08-18T18:33:20.322Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":72,"estimatedTokens":574}}1112{"id":"stack-8180596","source":"stackoverflow","questionId":8180596,"title":"Set Timeout for Pika ioloop async (RabbitMQ)","tags":["python","rabbitmq","pika"],"text":"Title: Set Timeout for Pika ioloop async (RabbitMQ)\nTags: python, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI need to be able to gracefully stop a consumer (worker) who works in a Pika ioloop. The worker should stop after 60 seconds. Currently processed messages should be finished. \n\nI tried to put a `connection.close()` inside the callback function but that only stopped the current thread and not the complete ioloop. And it gave a terrible error output. \n\nPlease see line 16 and following in my code: I used the (basic example about Pika ioloop http://pika.github.com/connecting.html#cps-example:\n\n```\nfrom pika.adapters import SelectConnection\n channel = None\n def on_connected(connection):\n connection.channel(on_channel_open)\n\n def on_channel_open(new_channel):\n global channel\n channel = new_channel\n channel.queue_declare(queue=\"test\", durable=True, exclusive=False, auto_delete=False, callback=on_queue_declared)\n\n def on_queue_declared(frame):\n channel.basic_consume(handle_delivery, queue='test')\n\n def handle_delivery(channel, method, header, body):\n print body\n\n # timer stuff which did NOT work\n global start_time, timeout, connection\n time_diff = time.time()-start_time\n if time_diff > timeout:\n #raise KeyboardInterrupt\n connection.close()\n\n timeout = 60\n start_time = time.time()\n\n connection = SelectConnection(parameters, on_connected)\n\n try:\n connection.ioloop.start()\n except KeyboardInterrupt:\n connection.close()\n connection.ioloop.start()\n```\n\n========================================\n\nTop Answer:\nYou can try to use:\n\n```\nconnection.ioloop.stop()\n```\n\n========================================\n\nCode:\n```text\nfrom pika.adapters import SelectConnection\n channel = None\n def on_connected(connection):\n connection.channel(on_channel_open)\n\n def on_channel_open(new_channel):\n global channel\n channel = new_channel\n channel.queue_declare(queue=\"test\", durable=True, exclusive=False, auto_delete=False, callback=on_queue_declared)\n\n def on_queue_declared(frame):\n channel.basic_consume(handle_delivery, queue='test')\n\n def handle_delivery(channel, method, header, body):\n print body\n\n # timer stuff which did NOT work\n global start_time, timeout, connection\n time_diff = time.time()-start_time\n if time_diff > timeout:\n #raise KeyboardInterrupt\n connection.close()\n\n timeout = 60\n start_time = time.time()\n\n connection = SelectConnection(parameters, on_connected)\n\n try:\n connection.ioloop.start()\n except KeyboardInterrupt:\n connection.close()\n connection.ioloop.start()\n```\n\n```text\nconnection.close()\n```\n\n```text\ntimeout = 60\n\ndef on_timeout():\n global connection\n connection.close()\n\nconnection.add_timeout(timeout, on_timeout)\n```\n\n```text\nconnection.ioloop.stop()\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.322Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":112,"estimatedTokens":712}}1113{"id":"stack-76216586","source":"stackoverflow","questionId":76216586,"title":"RabbitMQ - Use case for non-durable queues","tags":["rabbitmq"],"text":"Title: RabbitMQ - Use case for non-durable queues\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI don't really get the use case of non-durable queues. So I have a service that should run permanently and that consumes messages of RabbitMQ. I don't care if some messages are getting lost. As far as I understood, non-durable queues won't be recreated if the RabbitMQ server is restarted. So for example if my service has a non-durable queue and RabbitMQ crashes and is getting restarted, my service would only throw exceptions since the queue is not available anymore, right?\n\nSo the only use case I can imagine for non-durable queues is for testing services because in that case you don't care about deleted queues or messages.\n\n========================================\n\nTop Answer:\nTransient (non-durable) queues provide some latency benefits in scenarios when queue lifetime is very short. For example, when a temporary queue is created per user connection to a web server. That's from the RabbitMQ documentation:\n\nThroughput and latency of a queue is not affected by whether a queue is durable or not in most cases. **Only environments with very high queue or binding churn — that is, where queues are deleted and re-declared hundreds or more times a second — will see latency improvements for some operations, namely on bindings**. The choice between durable and transient queues therefore comes down to the semantics of the use case.\n\n**Temporary queues can be a reasonable choice for workloads with transient clients**, for example, temporary WebSocket connections in user interfaces, mobile applications and devices that are expected to go offline or use switch identities. Such clients usually have inherently transient state that should be replaced when the client reconnects\n\n========================================\n\nComments:\n- One use case is using Rabbit as a real time event hub, with multiple subscriber processes. When a consumer starts, it will create a non-durable queue on the fly, and adding bindings for the messages that it is interested in. While active, each consumer will receive a copy of the message on its queue. But if the subscriber quits, then the queue, and its bindings, are dropped.\n- But if the queue is created and by accident RabbitMQ crashes just a few seconds after that, nothing will be restored after the restart and my queue is lost, right?\n- @MatthewDarton Right. That's the point of non-durable queue. But it depends on your system architecture if this is acceptable. For example, if a queue is associated with some client socket, you might choose to just drop the connection and let the client reconnect. The tradeoff might be between preformance of usual flow vs minor drawback in rare case of RabbitMQ crash.","metadata":{"transformedAt":"2026-08-18T18:33:20.322Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":24,"estimatedTokens":690}}1114{"id":"stack-18247632","source":"stackoverflow","questionId":18247632,"title":"basicAck does not remove message from broker - RabbitMQ","tags":["java","rabbitmq","amqp"],"text":"Title: basicAck does not remove message from broker - RabbitMQ\nTags: java, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI'm doing following flow in my application:\n\nget 1 message from broker(manual acknowledge)\n\ndo some processing\n\nstart transaction on database and broker\n\ninsert some records in database and publish some messages on\n broker(different queue)\n\ncommit database and broker\n\nack message that you got from broker in step 1.\n\nAll operation on broker is done via a single channel. here is the preparation code:\n\n```\nConnection brokerConnection = factory.newConnection(); \nChannel channel = brokerConnection.createChannel();\nchannel.basicQos(1);\nQueueingConsumer consumer = new QueueingConsumer(channel);\nchannel.basicConsume(\"receive-queue\", false, consumer);\n```\n\nFollowing is my code. I have removed `try`, `catch` parts to make it clear. I log all exceptions to file.\nStep 1:\n\n```\nQueueingConsumer.Delivery delivery = consumer.nextDelivery();\nRequest request = (Request) SerializationUtils.deserialize(delivery.getBody());\n```\n\nStep 2, 3, 4, 5:\n\n```\ndbConnection.setAutoCommit(false);\nchannel.txSelect();\n\nstmt = dbConnection.prepareStatement(query);\n/* set paramteres */\nstmt.executeUpdate();\nchannel.basicPublish(/* exchange name */, \"KEY\", MessageProperties.PERSISTENT_BASIC, /* result */ result);\n\ndbConnection.commit();\nchannel.txCommit();\ndbConnection.setAutoCommit(true);\n```\n\nStep 6:\n\n```\nchannel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);\n```\n\nAfter one iteration I can see records in database and broker(means it is working fine until step 5). The problem is the message on receive queue is not removed after step 6 and management plug-in shows one un-acked message. Also I don't see any exception in log file. Can anyone help?\n\n**[UPDATE1]**\n\nNow I create one channel for publishing and another channel for receiving. This is working now. So how to use a single channel for receiving and publishing(with transactions)? I have used a single channel for receiving and publishing before but that was without transactions.\n\n**[UPDATE2]**\n\nI moved step 6 inside transaction and it is working now.\n\n```\ndbConnection.setAutoCommit(false);\nchannel.txSelect();\n\nstmt = dbConnection.prepareStatement(query);\n/* set paramteres */\nstmt.executeUpdate();\nchannel.basicPublish(/* exchange name */, \"KEY\", MessageProperties.PERSISTENT_BASIC, /* result */ result);\n\nchannel.basicAck(delivery.getEnvelope().getDeliveryTag(), false); \n\ndbConnection.commit();\nchannel.txCommit();\ndbConnection.setAutoCommit(true);\n```\n\nI'm a bit confused. I just want the publish section to be inside transaction.\n\n========================================\n\nCode:\n```text\nConnection brokerConnection = factory.newConnection(); \nChannel channel = brokerConnection.createChannel();\nchannel.basicQos(1);\nQueueingConsumer consumer = new QueueingConsumer(channel);\nchannel.basicConsume(\"receive-queue\", false, consumer);\n```\n\n```text\nQueueingConsumer.Delivery delivery = consumer.nextDelivery();\nRequest request = (Request) SerializationUtils.deserialize(delivery.getBody());\n```\n\n```text\ndbConnection.setAutoCommit(false);\nchannel.txSelect();\n\nstmt = dbConnection.prepareStatement(query);\n/* set paramteres */\nstmt.executeUpdate();\nchannel.basicPublish(/* exchange name */, \"KEY\", MessageProperties.PERSISTENT_BASIC, /* result */ result);\n\ndbConnection.commit();\nchannel.txCommit();\ndbConnection.setAutoCommit(true);\n```\n\n```text\nchannel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);\n```\n\n```text\ndbConnection.setAutoCommit(false);\nchannel.txSelect();\n\nstmt = dbConnection.prepareStatement(query);\n/* set paramteres */\nstmt.executeUpdate();\nchannel.basicPublish(/* exchange name */, \"KEY\", MessageProperties.PERSISTENT_BASIC, /* result */ result);\n\nchannel.basicAck(delivery.getEnvelope().getDeliveryTag(), false); \n\ndbConnection.commit();\nchannel.txCommit();\ndbConnection.setAutoCommit(true);\n```\n\n```text\ntry\n```\n\n```text\ncatch\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.322Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":7,"totalLines":145,"estimatedTokens":990}}1115{"id":"stack-73097067","source":"stackoverflow","questionId":73097067,"title":"NestJS Mock RabbitMQ in Jest","tags":["jestjs","rabbitmq","nestjs"],"text":"Title: NestJS Mock RabbitMQ in Jest\nTags: jestjs, rabbitmq, nestjs\nSource: Stack Overflow\n\nQuestion:\nI have an AppModule file as follows:\n\n```\nimport { Module } from '@nestjs/common'\nimport { RabbitMQModule } from '@golevelup/nestjs-rabbitmq'\n\n@Module({\n imports: [\n RabbitMQModule.forRoot(RabbitMQModule, {\n exchanges: [\n {\n name: 'my_rabbit',\n type: 'direct',\n },\n ],\n uri: process.env.RABBITMQ_URI,\n connectionInitOptions: { wait: true },\n }),\n ],\n})\nexport class AppModule {}\n```\n\nI have tried to mock rabbitmq using `@golevelup/nestjs-rabbitmq` like this:\n\n```\nimport { Module } from '@nestjs/common'\nimport { RabbitMQModule } from '@golevelup/nestjs-rabbitmq'\n\nbeforeEach(async () => {\n const module: TestingModule = await Test.createTestingModule({\n imports: [\n AppModule\n ],\n })\n .overrideProvider(AmqpConnection)\n .useValue(createMock())\n .compile()\n })\n```\n\nThis is giving me error:\n\n```\n[Nest] 2745 - 24/07/2022, 17:02:54 ERROR [AmqpConnection] Disconnected from RabbitMQ broker (default)\nError: connect ECONNREFUSED 127.0.0.1:5672\n```\n\nIf i mock the whole rabbitmq module like:\n\n```\njest.mock('@golevelup/nestjs-rabbitmq')\n```\n\nI will get errors like:\n\n```\nNest cannot create the AppModule instance.\n The module at index [0] of the AppModule \"imports\" array is undefined.\n```\n\nHas anyone successfully mocked RabbitMQ? Please assist if possible.\n\n========================================\n\nTop Answer:\nI solve this problem mocking an AmqpConnection like this.\n\n```\nimport { AmqpConnection } from \"@nestjs-plus/rabbitmq\";\n import { TestingModule, Test } from \"@nestjs/testing\";\n import { IntegrationQueueService } from \"./integration-queue.service\";\n\n describe('IntegrationQueueService', () => {\n\n type MockType = {\n [P in keyof T]?: jest.Mock;\n };\n \n\n const mockFactory: () => MockType = jest.fn(() => ({\n publish: jest.fn(() => AmqpConnection),\n }))\n\n \n let service: IntegrationQueueService;\n\n beforeEach(async () => {\n const module: TestingModule = await Test.createTestingModule({\n providers: [\n IntegrationQueueService,\n {\n provide: AmqpConnection,\n useFactory: mockFactory,\n },\n ],\n\n })\n .compile();\n\n service = module.get (IntegrationQueueService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n\n})\n```\n\n========================================\n\nCode:\n```js\nimport { Module } from '@nestjs/common'\nimport { RabbitMQModule } from '@golevelup/nestjs-rabbitmq'\n\n@Module({\n imports: [\n RabbitMQModule.forRoot(RabbitMQModule, {\n exchanges: [\n {\n name: 'my_rabbit',\n type: 'direct',\n },\n ],\n uri: process.env.RABBITMQ_URI,\n connectionInitOptions: { wait: true },\n }),\n ],\n})\nexport class AppModule {}\n```\n\n```js\nimport { Module } from '@nestjs/common'\nimport { RabbitMQModule } from '@golevelup/nestjs-rabbitmq'\n\nbeforeEach(async () => {\n const module: TestingModule = await Test.createTestingModule({\n imports: [\n AppModule\n ],\n })\n .overrideProvider(AmqpConnection)\n .useValue(createMock<AmqpConnection>())\n .compile()\n })\n```\n\n```text\n[Nest] 2745 - 24/07/2022, 17:02:54 ERROR [AmqpConnection] Disconnected from RabbitMQ broker (default)\nError: connect ECONNREFUSED 127.0.0.1:5672\n```\n\n```js\njest.mock('@golevelup/nestjs-rabbitmq')\n```\n\n```text\nNest cannot create the AppModule instance.\n The module at index [0] of the AppModule \"imports\" array is undefined.\n```\n\n```text\n@golevelup/nestjs-rabbitmq\n```\n\n```js\nimport { AmqpConnection } from '@golevelup/nestjs-rabbitmq'\nimport { mock } from 'jest-mock-extended'\n\nbeforeEach(async () => {\n const module = await Test.createTestingModule({\n imports: [],\n providers: [\n { provide: AmqpConnection, useValue: mock<AmqpConnection>() }\n })\n .compile()\n})\n```\n\n```js\nimport { mock } from 'jest-mock-extended'\n\n// create a deeply mocked module\nconst rmq = jest.createMockFromModule<typeof import('@golevelup/nestjs-rabbitmq')>(\n '@golevelup/nestjs-rabbitmq',\n)\n\n// all the mocked methods from #createMockFromModule will return undefined\n// but in this case, #forRoot needs to return mocked providers\n// specifically AmqpConnection, and this is how it is done:\nrmq.RabbitMQModule.forRoot = jest.fn(() => ({\n module: rmq.RabbitMQModule,\n providers: [\n {\n provide: rmq.AmqpConnection,\n useValue: mock<typeof rmq.AmqpConnection>(),\n },\n ],\n exports: [rmq.AmqpConnection],\n}))\n\nmodule.exports = rmq\n```\n\n```js\nimport { AmqpConnection } from '@golevelup/nestjs-rabbitmq'\nimport { mock } from 'jest-mock-extended'\nimport { GenericContainer } from 'testcontainers'\n\nconst rmq = jest.createMockFromModule<typeof import('@golevelup/nestjs-rabbitmq')>(\n '@golevelup/nestjs-rabbitmq',\n)\n\nrmq.RabbitMQModule.forRoot = jest.fn(() => ({\n module: rmq.RabbitMQModule,\n providers: [\n {\n provide: rmq.AmqpConnection,\n useFactory: async () => {\n const RABBITMQ_DEFAULT_USER = 'RABBITMQ_DEFAULT_USER'\n const RABBITMQ_DEFAULT_PASS = 'RABBITMQ_DEFAULT_PASS'\n const PORT = 5672\n\n const rmqContainer = new GenericContainer('rabbitmq:3.11.6-alpine')\n .withEnvironment({\n RABBITMQ_DEFAULT_USER,\n RABBITMQ_DEFAULT_PASS,\n })\n .withExposedPorts(PORT)\n\n const rmqInstance = await rmqContainer.start()\n const port = rmqInstance.getMappedPort(PORT)\n\n return new AmqpConnection({\n uri: `amqp://${RABBITMQ_DEFAULT_USER}:${RABBITMQ_DEFAULT_PASS}@localhost:${port}`,\n })\n },\n },\n ],\n exports: [rmq.AmqpConnection],\n}))\n\nmodule.exports = rmq\n```\n\n```text\nAppModule\n```\n\n```text\nRabbitMQModule\n```\n\n```text\noverrideProvider\n```\n\n```text\nRabbitMQModule\n```\n\n```text\nAppModule\n```\n\n```text\nAppModule\n```\n\n```text\nRabbitMQModule\n```\n\n```text\nAmqpConnection\n```\n\n```text\n__mocks__\n```\n\n```text\n@golevelup/nestjs-rabbitmq\n```\n\n```text\nsrc/__mocks__/@golevelup/nestjs-rabbitmq.ts\n```\n\n```text\n__mocks__\n```\n\n```text\nnode_modules\n```\n\n```text\nsrc/__mocks__/@golevelup/nestjs-rabbitmq.ts\n```\n\n```js\nimport { AmqpConnection } from \"@nestjs-plus/rabbitmq\";\n import { TestingModule, Test } from \"@nestjs/testing\";\n import { IntegrationQueueService } from \"./integration-queue.service\";\n\n describe('IntegrationQueueService', () => {\n\n type MockType<T> = {\n [P in keyof T]?: jest.Mock<{}>;\n };\n \n\n const mockFactory: () => MockType<AmqpConnection> = jest.fn(() => ({\n publish: jest.fn(() => AmqpConnection),\n }))\n\n \n let service: IntegrationQueueService;\n\n beforeEach(async () => {\n const module: TestingModule = await Test.createTestingModule({\n providers: [\n IntegrationQueueService,\n {\n provide: AmqpConnection,\n useFactory: mockFactory,\n },\n ],\n\n })\n .compile();\n\n service = module.get<IntegrationQueueService> (IntegrationQueueService);\n });\n\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n\n})\n```\n\n```text\nimport { AmqpConnection } from '@golevelup/nestjs-rabbitmq';\n\nAmqpConnection.prototype.init = jest.fn();\nAmqpConnection.prototype.close = jest.fn();\n\ndescribe('AppController (e2e)', () => {\n```\n\n========================================\n\nComments:\n- Did you solve this? The answer below didn't quite work for me.\n- @Scott-MEARN-Developer I just posted my answer. Please see below\n- @Scott-MEARN-Developer I just found a simple solution for it - see my answer below\n- Thanks for exploring this. Have you tried to see if this will run into memory leaks? Jest has the problem of memory leaks if modules are monkey patched like this.\n- @Calvintwr thanks for the info. Yes, I've applied it at the same time I posted this solution and so far so good on our side.","metadata":{"transformedAt":"2026-08-18T18:33:20.323Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":25,"totalLines":369,"estimatedTokens":2037}}1116{"id":"stack-12637411","source":"stackoverflow","questionId":12637411,"title":"MassTransit Saga - Errors & Inconsistencies","tags":["rabbitmq","messaging","servicebus","masstransit","saga"],"text":"Title: MassTransit Saga - Errors & Inconsistencies\nTags: rabbitmq, messaging, servicebus, masstransit, saga\nSource: Stack Overflow\n\nQuestion:\nI've implemented a masstransit saga that works as should, a lot of times. However, there are times when the messages go to the error queue or just seem to disappear. I'm using RabbitMQ.\n\nI'd like to know:\n1. How do I get the reason/exception message that causes a message to go to the error queue? (NOTE: My handler logic is within a try-catch block so apparently these errors happen even before the handler logic is called)\n2. What could be responsible for the lost messages?\n\nThanks in advance.\n\n========================================\n\nComments:\n- I did some research and I see I can configure logging using either NLog or Log4Net but I can't seem to see any example of how to configure the logging. Help any one?\n- The mailing list is likely a better place for questions: groups.google.com/forum/#!masstransit-discuss. You can also take a look at the docs site: masstransit.readthedocs.org/en/master\n- Thanks @Travis. However, like I noted in my answer below, the docs site doesn't seem to include instructions on how to configure logging using NLog.\n- If you feel up to making a pull request to include that documentation, we'd be happy to accept updates to the docs to cover this.\n- Correct, use the NHibernate repository if you want them to live beyond the process lifetime.\n- Thank you for posting this. Took me way too long to discover how to use that.","metadata":{"transformedAt":"2026-08-18T18:33:20.323Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":22,"estimatedTokens":376}}1117{"id":"stack-5424419","source":"stackoverflow","questionId":5424419,"title":"rabbitmq error when connect","tags":["php","queue","message-queue","rabbitmq"],"text":"Title: rabbitmq error when connect\nTags: php, queue, message-queue, rabbitmq\nSource: Stack Overflow\n\nQuestion:\ni got this error when i try to connect using php-amqp:\nFatal error: Class 'AMQPConnection' not found in\n\n```\n$credentials =array('host' => 'localhost','port' => 5672);\n$cnn = new AMQPConnection($credentials);\n$cnn->connect();\n```\n\n========================================\n\nCode:\n```text\n$credentials =array('host' => 'localhost','port' => 5672);\n$cnn = new AMQPConnection($credentials);\n$cnn->connect();\n```\n\n```text\npecl\n```\n\n========================================\n\nComments:\n- Your link is broken, could you please edit and give a more detailed explanation of how you can download this extension?\n- Wow, they've completely nuked *all* of the documentation for that extension. Without documentation, I'd be really hesitant to actually advise anyone to use that extension at this point. There are numerous pure-PHP AMQP and STOMP libraries now, and anyone reading this old question should use one of those instead of the PECL extension.","metadata":{"transformedAt":"2026-08-18T18:33:20.323Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":32,"estimatedTokens":263}}1118{"id":"stack-8840633","source":"stackoverflow","questionId":8840633,"title":"Scheduling many jobs to be executed by timestamp","tags":["php","scheduled-tasks","rabbitmq"],"text":"Title: Scheduling many jobs to be executed by timestamp\nTags: php, scheduled-tasks, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have a producer that reads from a twitter stream and places tasks on a queue using rabbitmq as the message broker.\n\nThe jobs usually takes around 3-5 seconds to execute and at the end of the job I would notify the user when it is done. However, I would also like to remind them in 10 minutes/30 minutes/60 minutes after their job is done by sending the user more messages.\n\nI cannot figure out the best way to schedule these additional messages. I thought of creating cron jobs to run a message script at those specific timestamps, but that seemed wrong with thousands of jobs an hour. Another idea was to run a daemon that would poll a database or read from queue and checks the scheduled timestamp and current time before sending out. \n\nIdeally if this could be done on the message broker side through delayed messages it would make it much cleaner, but I read that RabbitMQ does not support something like that. \n\nWhat would be the best way to go about scheduling many jobs that needs to be executed by timestamp?\n\n========================================\n\nComments:\n- a cron job seems the right option to me.\n- If I wanted more granularity, would running cron job every few seconds to check be excessive? Is there a better way than that?\n- Well, first of all, you can't run cron jobs more than once a minute unless you stagger them by sleeping. You don't have to schedule a cron job for each message - what about a script which sends out 50 messages at once?","metadata":{"transformedAt":"2026-08-18T18:33:20.323Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":21,"estimatedTokens":398}}1119{"id":"stack-60657549","source":"stackoverflow","questionId":60657549,"title":"How to connect to the rabbitMQ docker container?","tags":["python","docker","rabbitmq"],"text":"Title: How to connect to the rabbitMQ docker container?\nTags: python, docker, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am spawning a rabbitMQ container with the command - \n\n```\ndocker run -d --hostname localhost --name rabbit-tox rabbitmq:3\n```\n\nand this is the docker ps -a output -\n\n```\nCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES\n6d95830a43d9 rabbitmq:3 \"docker-entrypoint...\" 6 minutes ago Up 6 minutes 4369/tcp, 5671-5672/tcp, 25672/tcp rabbit-tox\n```\n\ndocker inspect 6d95830a43d9 output -- \n\n```\n[\n {\n \"Id\": \"6d95830a43d90557009a783779442927ca4bf211198f5c4eb420b7bb78b5de08\",\n \"Created\": \"2020-03-12T15:34:12.661119753Z\",\n \"Path\": \"docker-entrypoint.sh\",\n \"Args\": [\n \"rabbitmq-server\"\n ],\n \"State\": {\n \"Status\": \"running\",\n \"Running\": true,\n\n. . . \n\n\"EndpointID\": \"\",\n \"Gateway\": \"172.17.0.1\",\n \"GlobalIPv6Address\": \"\",\n \"GlobalIPv6PrefixLen\": 0,\n \"IPAddress\": \"172.17.0.2\",\n \"IPPrefixLen\": 16,\n \"IPv6Gateway\": \"\",\n \"MacAddress\": \"02:42:ac:11:00:02\",\n \"Networks\": {\n \"bridge\": {\n \"IPAMConfig\": null,\n \"Links\": null,\n \"Aliases\": null,\n \"NetworkID\": \"\",\n \"EndpointID\": \"\",\n \"Gateway\": \"172.17.0.1\",\n \"IPAddress\": \"172.17.0.2\",\n \"IPPrefixLen\": 16,\n \"IPv6Gateway\": \"\",\n \"GlobalIPv6Address\": \"\",\n \"GlobalIPv6PrefixLen\": 0,\n```\n\nI am trying to connect to the container using the code - \n\n```\n#!/usr/bin/env python\nimport pika\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters('127.0.0.1'))\nchannel = connection.channel()\n\nchannel.queue_declare(queue='hello')\nchannel.basic_publish(exchange='',\n routing_key='hello',\n body='Hello World!')\nprint(\" [x] Sent 'Hello World!'\")\nconnection.close()\n```\n\nbut it gives out the error - \n\n```\nTraceback (most recent call last):\n File \"rmqtest.py\", line 4, in \n connection = pika.BlockingConnection(pika.ConnectionParameters('127.0.0.1'))\n File \"/home/mlokur/venv/lib/python3.7/site-packages/pika/adapters/blocking_connection.py\", line 359, in __init__\n self._impl = self._create_connection(parameters, _impl_class)\n File \"/home/mlokur/venv/lib/python3.7/site-packages/pika/adapters/blocking_connection.py\", line 450, in _create_connection\n raise self._reap_last_connection_workflow_error(error)\npika.exceptions.AMQPConnectionError\n```\n\nSorry, I am new to rabbitMQ, any help would be appreciated.\n\nThanks.\n\n========================================\n\nCode:\n```text\ndocker run -d --hostname localhost --name rabbit-tox rabbitmq:3\n```\n\n```text\nCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES\n6d95830a43d9 rabbitmq:3 \"docker-entrypoint...\" 6 minutes ago Up 6 minutes 4369/tcp, 5671-5672/tcp, 25672/tcp rabbit-tox\n```\n\n```text\n[\n {\n \"Id\": \"6d95830a43d90557009a783779442927ca4bf211198f5c4eb420b7bb78b5de08\",\n \"Created\": \"2020-03-12T15:34:12.661119753Z\",\n \"Path\": \"docker-entrypoint.sh\",\n \"Args\": [\n \"rabbitmq-server\"\n ],\n \"State\": {\n \"Status\": \"running\",\n \"Running\": true,\n\n. . . \n\n\"EndpointID\": \"\",\n \"Gateway\": \"172.17.0.1\",\n \"GlobalIPv6Address\": \"\",\n \"GlobalIPv6PrefixLen\": 0,\n \"IPAddress\": \"172.17.0.2\",\n \"IPPrefixLen\": 16,\n \"IPv6Gateway\": \"\",\n \"MacAddress\": \"02:42:ac:11:00:02\",\n \"Networks\": {\n \"bridge\": {\n \"IPAMConfig\": null,\n \"Links\": null,\n \"Aliases\": null,\n \"NetworkID\": \"\",\n \"EndpointID\": \"\",\n \"Gateway\": \"172.17.0.1\",\n \"IPAddress\": \"172.17.0.2\",\n \"IPPrefixLen\": 16,\n \"IPv6Gateway\": \"\",\n \"GlobalIPv6Address\": \"\",\n \"GlobalIPv6PrefixLen\": 0,\n```\n\n```text\n#!/usr/bin/env python\nimport pika\n\nconnection = pika.BlockingConnection(pika.ConnectionParameters('127.0.0.1'))\nchannel = connection.channel()\n\nchannel.queue_declare(queue='hello')\nchannel.basic_publish(exchange='',\n routing_key='hello',\n body='Hello World!')\nprint(\" [x] Sent 'Hello World!'\")\nconnection.close()\n```\n\n```text\nTraceback (most recent call last):\n File \"rmqtest.py\", line 4, in <module>\n connection = pika.BlockingConnection(pika.ConnectionParameters('127.0.0.1'))\n File \"/home/mlokur/venv/lib/python3.7/site-packages/pika/adapters/blocking_connection.py\", line 359, in __init__\n self._impl = self._create_connection(parameters, _impl_class)\n File \"/home/mlokur/venv/lib/python3.7/site-packages/pika/adapters/blocking_connection.py\", line 450, in _create_connection\n raise self._reap_last_connection_workflow_error(error)\npika.exceptions.AMQPConnectionError\n```\n\n```text\nFROM rabbitmq:management\n\n# Define environment variables.\nENV RABBITMQ_DEFAULT_USER user\nENV RABBITMQ_DEFAULT_PASS password\n\nADD init.sh /init.sh\n\nRUN [\"chmod\", \"+x\", \"/init.sh\"]\n\nEXPOSE 15672\n\n# Define default command\nCMD [\"/init.sh\"]\n```\n\n```sh\n#!/bin/sh\n\n# Create Rabbitmq user\n( sleep 10 ; \\\nrabbitmqctl add_user user password ; \\\nrabbitmqctl set_user_tags user administrator ; \\\nrabbitmqctl set_permissions -p / user \".*\" \".*\" \".*\" ; \\\necho \"*** User 'user' with password 'password' completed. ***\" ; \\\necho \"*** Log in the WebUI at port 15672 (example: http:/localhost:15672) ***\") &\n\n# $@ is used to pass arguments to the rabbitmq-server command.\n# For example if you use it like this: docker run -d rabbitmq arg1 arg2,\n# it will be as you run in the container rabbitmq-server arg1 arg2\nrabbitmq-server $@\n```\n\n```text\nDockerfile\n```\n\n```text\ninit.sh\n```\n\n```text\nDockerfile\n```\n\n```text\ninit.sh\n```\n\n```text\ndocker build -t 'my_rabbit' .\n```\n\n```text\ndocker run -p5672:5672 -p15672:15672 my_rabbit\n```\n\n```text\n5672\n```\n\n```text\n15672\n```\n\n```text\nlocalhost:15672\n```\n\n```text\nuser\n```\n\n```text\npassword\n```\n\n========================================\n\nComments:\n- You need to bind the ports rabbit uses or use `--net=host`\n- Given the output of docker inspect, the ip on which you should try to bind is 172.17.0.2, not 127.0.0.1\n- Yeah, thanks for your answers. I figured I have to use 172.17.0.2 as soon as I posted this, I feel so lame.\n- @Groot221, i would suggest using docker-compose\n- @Eitank I wish to run this container within tox for integration tests. I am already spawing postgres inside tox as another container. Is it possible to use docker -compose inside tox?\n- i have no idea, never heard of Tox so i can't help with it :(","metadata":{"transformedAt":"2026-08-18T18:33:20.323Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":18,"totalLines":255,"estimatedTokens":1633}}1120{"id":"stack-51969050","source":"stackoverflow","questionId":51969050,"title":"MassTransit- The host path must be empty or contain a single virtual host name","tags":["c#","rabbitmq","masstransit"],"text":"Title: MassTransit- The host path must be empty or contain a single virtual host name\nTags: c#, rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nI'm totally new to RabbitMQ and MassTransit. I just have a code that worked in dev environment but in production I get the error mentioned in the title.\nCurrently the configuration is as follows:\n\n```\n\n \n \n \n '\n```\n\nJust to check I decompiled MassTransit DLL and found that it's because the `\"/ProdRabbitCluster/MDB\"` has more than one `\"/\"` separated segment. \n\nSo is this URL format simply invalid and should be changed? That value was given by customer's admins and I have no idea about their whole infrastructure and servers.\n\n========================================\n\nCode:\n```text\n<source name=\"mdb\" switchValue=\"All\">\n <listeners>\n <add name=\"MM\" type=\"Comp.MyTraceListener, Comp.Diagnostics\"\n initializeData=\"rabbitmq://server.xxx.int/ProdRabbitCluster/MDB\"\n username=\"prod\" password=\"xxxxx\" />\n </listeners>\n </source>'\n```\n\n```text\n\"/ProdRabbitCluster/MDB\"\n```\n\n```text\n\"/\"\n```\n\n```text\nrabbitmq://hostname[:port]/virtual_host\n```\n\n========================================\n\nComments:\n- Oh, and rather than decompile, you could just look at the source code: github.com/MassTransit/MassTransit","metadata":{"transformedAt":"2026-08-18T18:33:20.323Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":49,"estimatedTokens":322}}1121{"id":"stack-47407888","source":"stackoverflow","questionId":47407888,"title":"RabbitMQ multiple acknowledges to same message closes the consumer","tags":["go","rabbitmq"],"text":"Title: RabbitMQ multiple acknowledges to same message closes the consumer\nTags: go, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nIf I acknowledge the same message twice using the Delivery.Ack method, my consumer channel just closes by itself.\n\nIs this expected behaviour? Has anyone experienced this ? \n\nThe reason I am acknowledging the same message twice is a special case where I have to break the original message into copies and process them on the consumer. Once the consumer processes everything, it loops and acks everything. Since there are copies of the entity, it acks the same message twice and my consumer channel shuts down\n\n========================================\n\nCode:\n```text\nException (406) Reason: \"PRECONDITION_FAILED - unknown delivery tag ?\"\n```\n\n```text\nAck(...)\n```\n\n========================================\n\nComments:\n- It seems to me it is an expected behavior, but i cant find any proof :-).\n- Yeah..I tried to look for proof but couldn't find any.","metadata":{"transformedAt":"2026-08-18T18:33:20.323Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":27,"estimatedTokens":244}}1122{"id":"stack-48124335","source":"stackoverflow","questionId":48124335,"title":"Is there any specific way for Axon migration from 2.4.3 version to 3.1.1","tags":["java","spring","rabbitmq","cqrs","axon"],"text":"Title: Is there any specific way for Axon migration from 2.4.3 version to 3.1.1\nTags: java, spring, rabbitmq, cqrs, axon\nSource: Stack Overflow\n\nQuestion:\nI am new to axon and doing migration from Axon 2.4.3 to 3.1.1 but I am not able to find any migration guide which is available for other version?\nCan you please your experience on how to do the same.\nI am facing a lot problem, some classes have been removed, some packages have been changed.\nFor some classes I am even not able to find replacements, so please help me with some suggestion.\nIf there is a guide for same please provide me with link of that.\n\nThanks in Advance\n\nAcctually I am not able to find replacement for these which were there in axon 2.4.3\nClusteringEventBus-\nDefaultClusterSelector-\nEventBusTerminal-\nSimpleCluster-\nSpringAMQPTerminal-\nSpringAMQPConsumerConfiguration-\nListenerContainerLifecycleManager-\n\n========================================\n\nCode:\n```text\nAbstractAnnotatedAggregateRoot\n```\n\n```text\nAggregateLifecycle.apply()\n```\n\n```text\nAbstractAnnotatedSaga\n```\n\n```text\n@Aggregate\n```\n\n```text\n@Saga\n```\n\n```text\ndomain_event_entry\n```\n\n```text\nglobalIndex\n```\n\n```text\nSubscribingEventProcessor\n```\n\n```text\nTrackingEventProcessor\n```\n\n```text\nConfigurer\n```\n\n```text\n@EnableAxon\n```\n\n```text\naxon-spring-boot-starter\n```\n\n```text\nClusteringEventBus\n```\n\n```text\nClusteringEventBus\n```\n\n```text\nEventBus\n```\n\n```text\nSubscribingEventProcessor\n```\n\n```text\nTrackingEventProcessor\n```\n\n```text\nDefaultClusterSelector\n```\n\n```text\n@ProcessingGroup({processing-group-name})\n```\n\n```text\nSimpleCluster\n```\n\n```text\nSimpleCluster\n```\n\n```text\nEventProcessor\n```\n\n```text\nEventBusTerminal\n```\n\n```text\nEventBusTerminal\n```\n\n```text\nEventBus\n```\n\n```text\nTrackingEventProcessor\n```\n\n```text\nEventStore\n```\n\n```text\nEventBusTerminal\n```\n\n```text\nSpringAMQPTerminal\n```\n\n```text\nEventBusTerminal\n```\n\n```text\nSpringAMQPPublisher\n```\n\n```text\nSpringAMQPConsumerConfiguration\n```\n\n```text\naxon-amqp\n```\n\n```text\nListenerContainers\n```\n\n```text\nSpringAMQPConsumerConfiguration\n```\n\n```text\nListenerContainerLifecycleManager\n```\n\n```text\nSpringAMQPMessageSource\n```\n\n========================================\n\nComments:\n- A list of the classes you're missing, thus can't find a correct replacement for might help others answer your questions quicker.\n- Steven I updated question, can you please have a look, I am still not able to find a fix for these classes which were there in Axon 2.4.3\n- pls help I really need it.\n- View the update section for a more concise answer to the exact classes you're missing.\n- thanks @Steven ...that really worked for now on query side...most of the replacement that you suggested I tried to implement them and it's good now....I can get to you If I need further help??\n- Great to hear it helped you out! If it fixed your issues, would you mind marking my question as the answer? And, if you've got any questions in the future, just drop them here or on the Axon Framework usergroup. I'm active in both to be able to help people with using it.\n- Thanks! It would be helpful to write a guide for migrating from 3.x version to the newest 4.0.\n- @rsb2097 we have this migration guide in the pipeline, so no worries! :)","metadata":{"transformedAt":"2026-08-18T18:33:20.323Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":37,"totalLines":184,"estimatedTokens":806}}1123{"id":"stack-57622069","source":"stackoverflow","questionId":57622069,"title":"RabbitMQ queue consumption behaviour","tags":["java","spring-boot","rabbitmq","apache-camel"],"text":"Title: RabbitMQ queue consumption behaviour\nTags: java, spring-boot, rabbitmq, apache-camel\nSource: Stack Overflow\n\nQuestion:\nWe have a Spring Boot (2.1) application using Apache Camel (2.24) to consume from a RabbitMQ server (3.7.15).\n\nThe application appears to be consuming correctly (message-by-message, as they are placed on the queue), but in the RabbitMQ monitor it appears as those the messages are consumed 'in bulk' (see the sharp drop then flatline, even though we see in the logs that messages are being processed by the app).\n\nWe haven't set any sort of 'prefetch' behaviour that I can see. Can someone explain what's happening? Why isn't the queue count decreasing smoothly?\n\nhttps://i.sstatic.net/wGWLt.png\n\n========================================\n\nTop Answer:\nfrom(\"rabbitmq://localhost:5672/delete.Tenant?queue=tenant&declare=false&autoAck=false&threadPoolSize=20&concurrentConsumers=20&prefetchEnabled=true&prefetchCount=100\")\n\n========================================\n\nCode:\n```text\nprefetchEnabled\n```\n\n```text\nfalse\n```\n\n```text\nopenChannel\n```\n\n```text\nprefetchEnabled\n```\n\n```text\nlimitPrefetch\n```\n\n```text\nprefetchEnabled\n```\n\n========================================\n\nComments:\n- Thanks burki, but even if the default \"prefetch amount\" is unlimited, isn't the prefetch behaviour itself disabled by default?\n- At least in our usage it appears to be, according to org.apache.camel.component.rabbitmq.springboot.RabbitMQCompo‌​nentConfiguration#pr‌​efetchEnabled\n- I extended my answer. `prefetchEnabled = false` is probably misleading.\n- what exactly do you want to convey?","metadata":{"transformedAt":"2026-08-18T18:33:20.323Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":52,"estimatedTokens":405}}1124{"id":"stack-51720663","source":"stackoverflow","questionId":51720663,"title":"Cannot load PHP class when running Symfony command","tags":["php","symfony","docker","rabbitmq","amqp"],"text":"Title: Cannot load PHP class when running Symfony command\nTags: php, symfony, docker, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI would appreciate any help I can get with following issue.\n\nI've set up Symfony Messenger to use AMQP and RabbitMQ. I can dispatch message and make use of AMQPConnection within my project.\n\nBut when I try to consume the message I get following:\n\n $ php bin/console messenger:consume-messages amqp\n\n Attempted to load class \"AMQPConnection\" from the global namespace.\n Did you forget a \"use\" statement for \"PhpAmqpLib\\Connection\\AMQPConnection\"?\n\nThe console command calls a method within `AmqpFactory.php`\n\n public function createConnection(array $credentials): \\AMQPConnection\n {\n return new \\AMQPConnection($credentials);\n }\n\nSo when I run the project from the browser, everything works fine. I can use AMQPConnection and all. But when running from terminal, it cannot find the AMQPConnection class.\n\nFrom within my composer.json I also have the amqplib installed\n\n \"php-amqplib/php-amqplib\": \"^2.7\",\n\nI use Docker and the Dockerfile contains:\n\n FROM php:7-apache\n\n RUN usermod -u 1000 www-data &&\\\n a2dissite 000-default &&\\\n apt-get update &&\\\n apt-get install -y \\\n zlib1g-dev \\\n libicu-dev \\\n g++ \\\n libfreetype6-dev \\\n libssh-dev \\\n libjpeg62-turbo-dev \\\n libmcrypt-dev \\\n librabbitmq-dev \\\n libpng-dev &&\\\n docker-php-ext-configure intl &&\\\n docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ &&\\\n docker-php-ext-install -j$(nproc) gd pdo_mysql intl opcache zip pcntl exif bcmath sockets &&\\\n a2enmod rewrite\n\n RUN pecl install amqp \\\n && docker-php-ext-enable amqp\n\n COPY docker/apache2.conf /etc/apache2/apache2.conf\n\n WORKDIR /var/www/project\n\n**UPDATE!**\nI've printed the phpinfo() and when dispatching the message I have version 7.2.8 and when executing the terminal command I have 7.2.7. So terminal is not using the Docker instance of PHP when executing the command.\n\n========================================\n\nTop Answer:\nWhen using Docker, Symfony commands needs to be executed inside needed container.\n\nThe problem come from trying to execute php from the local host:\n\n```\n$ php bin/console messenger:consume-messages amqp\n```\n\nwhereas the local host does **not** have the necessary dependencies, `RabbitMQ` in this case.\n\nInstead the command should be run using the right container:\n\n```\n$ docker exec -ti container_name sh -c \"cd /var/www/project/ && php bin/console messenger:consume-messages amqp\"\n```\n\n`container_name` being the name of the container having the `RabbitMQ` dependencies.\n\n========================================\n\nCode:\n```text\n$ php bin/console messenger:consume-messages amqp\n\n Attempted to load class \"AMQPConnection\" from the global namespace.\n Did you forget a \"use\" statement for \"PhpAmqpLib\\Connection\\AMQPConnection\"?\n```\n\n```text\npublic function createConnection(array $credentials): \\AMQPConnection\n {\n return new \\AMQPConnection($credentials);\n }\n```\n\n```text\n\"php-amqplib/php-amqplib\": \"^2.7\",\n```\n\n```text\nFROM php:7-apache\n\n RUN usermod -u 1000 www-data &&\\\n a2dissite 000-default &&\\\n apt-get update &&\\\n apt-get install -y \\\n zlib1g-dev \\\n libicu-dev \\\n g++ \\\n libfreetype6-dev \\\n libssh-dev \\\n libjpeg62-turbo-dev \\\n libmcrypt-dev \\\n librabbitmq-dev \\\n libpng-dev &&\\\n docker-php-ext-configure intl &&\\\n docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ &&\\\n docker-php-ext-install -j$(nproc) gd pdo_mysql intl opcache zip pcntl exif bcmath sockets &&\\\n a2enmod rewrite\n\n RUN pecl install amqp \\\n && docker-php-ext-enable amqp\n\n COPY docker/apache2.conf /etc/apache2/apache2.conf\n\n WORKDIR /var/www/project\n```\n\n```text\nAmqpFactory.php\n```\n\n```text\ndocker exec -ti container_name sh -c \"cd /var/www/project/ && php bin/console messenger:consume-messages amqp\"\n```\n\n```text\nlibrabbitmq4\n```\n\n```text\nRUN apt-get update --fix-missing && apt-get update && apt-get install php-amqp\n```\n\n```sh\n$ php bin/console messenger:consume-messages amqp\n```\n\n```sh\n$ docker exec -ti container_name sh -c \"cd /var/www/project/ && php bin/console messenger:consume-messages amqp\"\n```\n\n```text\nRabbitMQ\n```\n\n```text\ncontainer_name\n```\n\n```text\nRabbitMQ\n```\n\n========================================\n\nComments:\n- Did you forget a \"use\" statement for \"PhpAmqpLib\\Connection\\AMQPConnection\"?\n- Missed to add that part. Updated question above. The console command uses this method: return new \\AMQPConnection($credentials);. It works to create the message, but not to consume it. Difference is when consuming I use Symfony console command.\n- But do you have a use statement in your console command code ? Can you add the relevant code of the Command class ?\n- @JeroenI added the statement which uses the AMQPConnection. It's really strange, same method is used when creating the message and that works just fine. When working with the terminal and activate the command to actual consume, I get this error. The credentials passed to connect is also correct\n- Thank you! That makes sense! Appreciate it..awarding bounty and +1","metadata":{"transformedAt":"2026-08-18T18:33:20.323Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":13,"totalLines":176,"estimatedTokens":1319}}1125{"id":"stack-57541541","source":"stackoverflow","questionId":57541541,"title":"Configure MassTransit for testing with WebApplicationFactory","tags":[".net-core","rabbitmq","integration-testing","masstransit","rawrabbit"],"text":"Title: Configure MassTransit for testing with WebApplicationFactory\nTags: .net-core, rabbitmq, integration-testing, masstransit, rawrabbit\nSource: Stack Overflow\n\nQuestion:\nI have an ASP.NET Core web app and test setup using `WebApplicationFactory` to test my controller actions. I used RawRabbit before and it was easy enough for me to mock the `IBusClient` and add it to the DI container as a singleton. Within the `WebApplicationFactory.CreateWebHostBuilder()` I call this extension method to add my mocked `IBusClient` instance like so;\n\n```\n/// \n/// Configures the service bus.\n/// \n/// The web host builder.\n/// A web host builder.\npublic static IWebHostBuilder ConfigureTestServiceBus(this IWebHostBuilder webHostBuilder)\n{\n webHostBuilder.ConfigureTestServices(services =>\n {\n services.AddSingleton\n });\n\n return webHostBuilder;\n}\n```\n\nBut there are gaps in RawRabbit right now that made me decide to move over to MassTransit. However, I am wondering if there's already a better way to register the `IBus` into my container without mocking it inside my test. Not sure if `InMemoryTestFixture`, `BusTestFixture`, or `BusTestHarness` is the solution to my problem. Not sure how to use them together and what they do.\n\nBy the way, in my ASP.NET Core app, I have a reusable extension method setup like the code below to hook me up to RabbitMQ on startup.\n\n```\n/// \n/// Adds the service bus.\n/// \n/// The services.\n/// The configurator.\n/// A service collection.\npublic static IServiceCollection AddServiceBus(this IServiceCollection services, Action configurator)\n{\n var rabbitMqConfig = new ConfigurationBuilder()\n .AddJsonFile(\"/app/configs/service-bus.json\", optional: false, reloadOnChange: true)\n .Build();\n\n // Setup DI for MassTransit.\n services.AddMassTransit(x =>\n {\n configurator(x);\n\n // Get the json configuration and use it to setup connection to RabbitMQ.\n var rabbitMQConfig = rabbitMqConfig.GetSection(ServiceBusOptionsKey).Get();\n\n // Add bus to the container.\n x.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(cfg =>\n {\n cfg.Host(\n new Uri(rabbitMQConfig.Host),\n hostConfig =>\n {\n hostConfig.Username(rabbitMQConfig.Username);\n hostConfig.Password(rabbitMQConfig.Password);\n hostConfig.Heartbeat(rabbitMQConfig.Heartbeat);\n });\n\n cfg.ConfigureEndpoints(provider);\n\n // Add Serilog logging.\n cfg.UseSerilog();\n }));\n });\n\n // Add the hosted service that starts and stops the BusControl.\n services.AddSingleton();\n services.AddSingleton();\n services.AddSingleton(provider => provider.GetRequiredService());\n services.AddSingleton();\n\n return services;\n}\n```\n\n========================================\n\nTop Answer:\nA MassTransit config defined during Startup could be replaced with a new configuration with custom WebApplicationFactory by removing services from MassTransit namespace, e.g.\n\n```\npublic class CustomWebApplicationFactory : WebApplicationFactory \n{ \n protected override void ConfigureWebHost(IWebHostBuilder builder) \n {\n builder.ConfigureServices(services => \n {\n var massTransitHostedService = services.FirstOrDefault(d => d.ServiceType == typeof(IHostedService) &&\n d.ImplementationFactory != null &&\n d.ImplementationFactory.Method.ReturnType == typeof(MassTransitHostedService)\n );\n services.Remove(massTransitHostedService);\n var descriptors = services.Where(d => \n d.ServiceType.Namespace.Contains(\"MassTransit\",StringComparison.OrdinalIgnoreCase))\n .ToList();\n foreach (var d in descriptors) \n {\n services.Remove(d);\n } \n\n services.AddMassTransitInMemoryTestHarness(x =>\n {\n //add your consumers (again)\n });\n });\n }\n}\n```\n\nThen your test could look like\n\n```\npublic class TestClass : IClassFixture \n {\n private readonly CustomApplicationFactoryfactory;\n\n public TestClass(CustomApplicationFactoryfactory)\n {\n this.factory = factory;\n }\n\n [Fact] \n public async Task TestName()\n { \n CancellationToken cancellationToken = new CancellationTokenSource(5000).Token; \n var harness = factory.Services.GetRequiredService();\n await harness.Start();\n\n var bus = factory.Services.GetRequiredService();\n try\n {\n await bus.Publish(...some message...); \n \n bool consumed = await harness.Consumed.Any(cancellationToken);\n //do your asserts\n }\n finally\n {\n await harness.Stop();\n }\n } \n }\n```\n\n========================================\n\nCode:\n```cs\n/// <summary>\n/// Configures the service bus.\n/// </summary>\n/// <param name=\"webHostBuilder\">The web host builder.</param>\n/// <returns>A web host builder.</returns>\npublic static IWebHostBuilder ConfigureTestServiceBus(this IWebHostBuilder webHostBuilder)\n{\n webHostBuilder.ConfigureTestServices(services =>\n {\n services.AddSingleton<IBusClient, MY_MOCK_INSTANCE>\n });\n\n return webHostBuilder;\n}\n```\n\n```cs\n/// <summary>\n/// Adds the service bus.\n/// </summary>\n/// <param name=\"services\">The services.</param>\n/// <param name=\"configurator\">The configurator.</param>\n/// <returns>A service collection.</returns>\npublic static IServiceCollection AddServiceBus(this IServiceCollection services, Action<IServiceCollectionConfigurator> configurator)\n{\n var rabbitMqConfig = new ConfigurationBuilder()\n .AddJsonFile(\"/app/configs/service-bus.json\", optional: false, reloadOnChange: true)\n .Build();\n\n // Setup DI for MassTransit.\n services.AddMassTransit(x =>\n {\n configurator(x);\n\n // Get the json configuration and use it to setup connection to RabbitMQ.\n var rabbitMQConfig = rabbitMqConfig.GetSection(ServiceBusOptionsKey).Get<RabbitMQOptions>();\n\n // Add bus to the container.\n x.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(cfg =>\n {\n cfg.Host(\n new Uri(rabbitMQConfig.Host),\n hostConfig =>\n {\n hostConfig.Username(rabbitMQConfig.Username);\n hostConfig.Password(rabbitMQConfig.Password);\n hostConfig.Heartbeat(rabbitMQConfig.Heartbeat);\n });\n\n cfg.ConfigureEndpoints(provider);\n\n // Add Serilog logging.\n cfg.UseSerilog();\n }));\n });\n\n // Add the hosted service that starts and stops the BusControl.\n services.AddSingleton<IMessageDataRepository, EncryptedMessageDataRepository>();\n services.AddSingleton<IEndpointNameFormatter, EndpointNameFormatter>();\n services.AddSingleton<IBus>(provider => provider.GetRequiredService<IBusControl>());\n services.AddSingleton<IHostedService, BusHostedService>();\n\n return services;\n}\n```\n\n```text\nWebApplicationFactory\n```\n\n```text\nIBusClient\n```\n\n```text\nWebApplicationFactory<TStartup>.CreateWebHostBuilder()\n```\n\n```text\nIBusClient\n```\n\n```text\nIBus\n```\n\n```text\nInMemoryTestFixture\n```\n\n```text\nBusTestFixture\n```\n\n```text\nBusTestHarness\n```\n\n```text\npublic void ConfigureTestServiceBus(Action<IServiceCollectionConfigurator> configurator)\n {\n this._configurator = configurator;\n }\n```\n\n```text\npublic Intg_GetCustomers(WebApplicationTestFactory<Startup> factory)\n : base(factory)\n {\n factory.ConfigureTestServiceBus(c =>\n {\n c.AddConsumer<TestGetProductConsumer>();\n });\n }\n```\n\n```text\npublic static IWebHostBuilder ConfigureTestServiceBus(this IWebHostBuilder webHostBuilder, Action<IServiceCollectionConfigurator> configurator)\n{\n return webHostBuilder\n .ConfigureTestServices(services =>\n {\n // UseInMemoryServiceBus DI for MassTransit.\n services.AddMassTransit(c =>\n {\n configurator?.Invoke(c);\n\n // Add bus to the container.\n c.AddBus(provider =>\n {\n var control = Bus.Factory.CreateUsingInMemory(cfg =>\n {\n cfg.ConfigureEndpoints(provider);\n });\n\n control.Start();\n\n return control;\n });\n });\n\n services.AddSingleton<IMessageDataRepository, InMemoryMessageDataRepository>();\n });\n}\n```\n\n```cs\n[TestFixture]\npublic class When_a_consumer_is_being_tested\n{\n InMemoryTestHarness _harness;\n ConsumerTestHarness<Testsumer> _consumer;\n\n [OneTimeSetUp]\n public async Task A_consumer_is_being_tested()\n {\n _harness = new InMemoryTestHarness();\n _consumer = _harness.Consumer<Testsumer>();\n\n await _harness.Start();\n\n await _harness.InputQueueSendEndpoint.Send(new A());\n }\n\n [OneTimeTearDown]\n public async Task Teardown()\n {\n await _harness.Stop();\n }\n\n [Test]\n public void Should_have_called_the_consumer_method()\n {\n _consumer.Consumed.Select<A>().Any().ShouldBe(true);\n }\n\n\n class Testsumer :\n IConsumer<A>\n {\n public async Task Consume(ConsumeContext<A> context)\n {\n await context.RespondAsync(new B());\n }\n }\n\n\n class A\n {\n }\n\n\n class B\n {\n }\n}\n```\n\n```text\nInMemoryTestHarness\n```\n\n```text\npublic class CustomWebApplicationFactory : WebApplicationFactory<Startup> \n{ \n protected override void ConfigureWebHost(IWebHostBuilder builder) \n {\n builder.ConfigureServices(services => \n {\n var massTransitHostedService = services.FirstOrDefault(d => d.ServiceType == typeof(IHostedService) &&\n d.ImplementationFactory != null &&\n d.ImplementationFactory.Method.ReturnType == typeof(MassTransitHostedService)\n );\n services.Remove(massTransitHostedService);\n var descriptors = services.Where(d => \n d.ServiceType.Namespace.Contains(\"MassTransit\",StringComparison.OrdinalIgnoreCase))\n .ToList();\n foreach (var d in descriptors) \n {\n services.Remove(d);\n } \n\n services.AddMassTransitInMemoryTestHarness(x =>\n {\n //add your consumers (again)\n });\n });\n }\n}\n```\n\n```text\npublic class TestClass : IClassFixture<CustomApplicationFactory> \n {\n private readonly CustomApplicationFactoryfactory;\n\n public TestClass(CustomApplicationFactoryfactory)\n {\n this.factory = factory;\n }\n\n [Fact] \n public async Task TestName()\n { \n CancellationToken cancellationToken = new CancellationTokenSource(5000).Token; \n var harness = factory.Services.GetRequiredService<InMemoryTestHarness>();\n await harness.Start();\n\n var bus = factory.Services.GetRequiredService<IBusControl>();\n try\n {\n await bus.Publish<MessageClass>(...some message...); \n \n bool consumed = await harness.Consumed.Any<MessageClass>(cancellationToken);\n //do your asserts\n }\n finally\n {\n await harness.Stop();\n }\n } \n }\n```\n\n```cs\n[TestClass]\npublic class TastyTests\n{\n private readonly WebApplicationFactory<Startup> factory;\n private readonly InMemoryTestHarness harness = new();\n\n public TastyTests()\n {\n factory = new WebApplicationFactory<Startup>().WithWebHostBuilder(builder =>\n {\n builder.ConfigureTestServices(services =>\n {\n services.AddSingleton<IPublishEndpoint>(serviceProvider =>\n {\n return harness.Bus;\n });\n });\n });\n }\n\n [TestMethod]\n public async Task Test()\n {\n await harness.Start();\n try\n {\n var client = factory.CreateClient();\n const string url = \"/endpoint-that-publish-message\";\n\n var content = new StringContent(\"\", Encoding.UTF8, \"application/json\");\n var response = await client.PostAsync(url, content);\n (await harness.Published.Any<IMessage>()).Should().BeTrue();\n }\n finally\n {\n await harness.Stop();\n }\n }\n}\n```\n\n========================================\n\nComments:\n- Also, fyi, this is already added by MT: `services.AddSingleton(provider => provider.GetRequiredService());`\n- @PlatypusMaximus did you figure this out? I am also in the same situation as you were. I am using WebApplicationFactory and my API startup has my MassTransit config. I need to replace that config with the test harness but I don't know how to do that and cannot find anything online that shows me how to do it. Any help would be appreciated!\n- @frank-hale, did you solve this?\n- @mslot I was able to get this to work. I will post my repo here later. I need to set it up on GH.\n- @mslot, no I didn't solve it\n- @RyanMAd please do!!\n- Clone my project repo and checkout this file. This will show you how I got my stuff wired up easily for testing and for production using `IBusRegistry`. This is my framework for building microservices using .NET Core 5.0.\n- Sorry, updated link here\n- Let me know if you need more help.\n- I see this being useful when testing individual components. But is `InMemoryTestHarness` something that can be used for integration testing with a `WebApplicationFactory`?\n- I have an integration test runs an instance of my ASP.NET Core web app from `WebApplicationFactory` and then execute `GET`, `POST`, `PUT`, and `DELETE` through an HttpClient. The example above illustrates how I'd mock-up `IBusClient` from `RawRabbit` and then register it into my container using `IWebHostBuilder.ConfigureTestServices` method. I am wondering if I should just do the same thing for `IBus`. I was just wondering if that is something that is already available.\n- I'll probably create a new version of AddServiceBus like the one above that uses the In-Memory Bus\n- I guess I don't entirely understand what `InMemoryBus` is and how to utilize it.\n- I'd suggest looking at the unit tests in MassTransit (one of them is linked above). It's a fully functional bus instance, but entirely in-memory for unit testing.\n- @PlatypusMaximus did you figure this out? I am also in the same situation as you were. I am using WebApplicationFactory and my API startup has my MassTransit config. I need to replace that config with the test harness but I don't know how to do that and cannot find anything online that shows me how to do it. Any help would be appreciated!\n- @FrankHale did you find out? In my case I actually want to use a container instead of the harness but the IBus doesnt seem to start so the messages are never consumed.\n- @sharpc, I did not figure it out.\n- But how do you replace the Bus registered in the application with the in-memory one? As you can only call `services.AddMassTransit` once.","metadata":{"transformedAt":"2026-08-18T18:33:20.323Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":18,"totalLines":478,"estimatedTokens":3642}}1126{"id":"stack-21920323","source":"stackoverflow","questionId":21920323,"title":"Django 1.6 + RabbitMQ 3.2.3 + Celery 3.1.9 - why does my celery worker die with: WorkerLostError: Worker exited prematurely: signal 11 (SIGSEGV)","tags":["django","rabbitmq","celery","celery-task","celerybeat"],"text":"Title: Django 1.6 + RabbitMQ 3.2.3 + Celery 3.1.9 - why does my celery worker die with: WorkerLostError: Worker exited prematurely: signal 11 (SIGSEGV)\nTags: django, rabbitmq, celery, celery-task, celerybeat\nSource: Stack Overflow\n\nQuestion:\nThis seems to address a very similar issue, but doesn't give me quite enough insight: https://github.com/celery/billiard/issues/101 Sounds like it might be a good idea to try a non-SQLite database...\n\nI have a straightforward celery setup with my django app. In my `settings.py` file I set a task to run as follows:\n\n```\nCELERYBEAT_SCHEDULE = {\n 'sync_database': {\n 'task': 'apps.data.tasks.celery_sync_database',\n 'schedule': timedelta(minutes=5)\n }\n}\n```\n\nI have followed the instructions here: http://celery.readthedocs.org/en/latest/django/first-steps-with-django.html\n\nI am able to open two new terminal windows and run celery processes as follows:\n\nONE - the celery beat process which is required for scheduled tasks and will put the task on the queue:\n\n```\nPROMPT> celery -A myproj beat\ncelery beat v3.1.9 (Cipater) is starting.\n__ - ... __ - _\nConfiguration ->\n . broker -> amqp://myproj@localhost:5672//\n . loader -> celery.loaders.app.AppLoader\n . scheduler -> djcelery.schedulers.DatabaseScheduler\n\n . logfile -> [stderr]@%INFO\n . maxinterval -> now (0s)\n[2014-02-20 16:15:20,085: INFO/MainProcess] beat: Starting...\n[2014-02-20 16:15:20,086: INFO/MainProcess] Writing entries...\n[2014-02-20 16:15:20,143: INFO/MainProcess] DatabaseScheduler: Schedule changed.\n[2014-02-20 16:15:20,143: INFO/MainProcess] Writing entries...\n[2014-02-20 16:20:20,143: INFO/MainProcess] Scheduler: Sending due task sync_database (apps.data.tasks.celery_sync_database)\n[2014-02-20 16:20:20,161: INFO/MainProcess] Writing entries...\n```\n\nTWO - the celery worker, which should take the task off the queue and run it:\n\n```\nPROMPT> celery -A myproj worker -l info\n\n -------------- celery@Jons-MacBook.local v3.1.9 (Cipater)\n---- **** -----\n--- * *** * -- Darwin-13.0.0-x86_64-i386-64bit\n-- * - **** ---\n- ** ---------- [config]\n- ** ---------- .> app: myproj:0x1105a1050\n- ** ---------- .> transport: amqp://myproj@localhost:5672//\n- ** ---------- .> results: djcelery.backends.database:DatabaseBackend\n- *** --- * --- .> concurrency: 4 (prefork)\n-- ******* ----\n--- ***** ----- [queues]\n -------------- .> celery exchange=celery(direct) key=celery\n\n[tasks]\n . apps.data.tasks.celery_sync_database\n . myproj.celery.debug_task\n\n[2014-02-20 16:15:29,402: INFO/MainProcess] Connected to amqp://myproj@127.0.0.1:5672//\n[2014-02-20 16:15:29,419: INFO/MainProcess] mingle: searching for neighbors\n[2014-02-20 16:15:30,440: INFO/MainProcess] mingle: all alone\n[2014-02-20 16:15:30,474: WARNING/MainProcess] celery@Jons-MacBook.local ready.\n```\n\nWhen the task gets sent, however, it appears that about 50% of the time the worker runs the task and the other 50% of the time I get the following error:\n\n```\n[2014-02-20 16:35:20,159: INFO/MainProcess] Received task: apps.data.tasks.celery_sync_database[960bcb6c-d6a5-4e32-8267-cfbe2b411b25]\n[2014-02-20 16:36:54,561: ERROR/MainProcess] Process 'Worker-4' pid:19500 exited with exitcode -11\n[2014-02-20 16:36:54,580: ERROR/MainProcess] Task apps.data.tasks.celery_sync_database[960bcb6c-d6a5-4e32-8267-cfbe2b411b25] raised unexpected: WorkerLostError('Worker exited prematurely: signal 11 (SIGSEGV).',)\nTraceback (most recent call last):\n File \"/Users/jon/dev/vpe/VAN/lib/python2.7/site-packages/billiard/pool.py\", line 1168, in mark_as_worker_lost\n human_status(exitcode)),\nWorkerLostError: Worker exited prematurely: signal 11 (SIGSEGV).\n```\n\nI am developing on a Macbook Pro running Mavericks.\n\nCelery version 3.1.9\nRabbitMQ 3.2.3\nDjango 1.6\n\nNote that I am using django-celery 3.1.9 and have the djcelery app enabled.\n\n========================================\n\nCode:\n```text\nCELERYBEAT_SCHEDULE = {\n 'sync_database': {\n 'task': 'apps.data.tasks.celery_sync_database',\n 'schedule': timedelta(minutes=5)\n }\n}\n```\n\n```text\nPROMPT> celery -A myproj beat\ncelery beat v3.1.9 (Cipater) is starting.\n__ - ... __ - _\nConfiguration ->\n . broker -> amqp://myproj@localhost:5672//\n . loader -> celery.loaders.app.AppLoader\n . scheduler -> djcelery.schedulers.DatabaseScheduler\n\n . logfile -> [stderr]@%INFO\n . maxinterval -> now (0s)\n[2014-02-20 16:15:20,085: INFO/MainProcess] beat: Starting...\n[2014-02-20 16:15:20,086: INFO/MainProcess] Writing entries...\n[2014-02-20 16:15:20,143: INFO/MainProcess] DatabaseScheduler: Schedule changed.\n[2014-02-20 16:15:20,143: INFO/MainProcess] Writing entries...\n[2014-02-20 16:20:20,143: INFO/MainProcess] Scheduler: Sending due task sync_database (apps.data.tasks.celery_sync_database)\n[2014-02-20 16:20:20,161: INFO/MainProcess] Writing entries...\n```\n\n```text\nPROMPT> celery -A myproj worker -l info\n\n -------------- celery@Jons-MacBook.local v3.1.9 (Cipater)\n---- **** -----\n--- * *** * -- Darwin-13.0.0-x86_64-i386-64bit\n-- * - **** ---\n- ** ---------- [config]\n- ** ---------- .> app: myproj:0x1105a1050\n- ** ---------- .> transport: amqp://myproj@localhost:5672//\n- ** ---------- .> results: djcelery.backends.database:DatabaseBackend\n- *** --- * --- .> concurrency: 4 (prefork)\n-- ******* ----\n--- ***** ----- [queues]\n -------------- .> celery exchange=celery(direct) key=celery\n\n\n[tasks]\n . apps.data.tasks.celery_sync_database\n . myproj.celery.debug_task\n\n[2014-02-20 16:15:29,402: INFO/MainProcess] Connected to amqp://myproj@127.0.0.1:5672//\n[2014-02-20 16:15:29,419: INFO/MainProcess] mingle: searching for neighbors\n[2014-02-20 16:15:30,440: INFO/MainProcess] mingle: all alone\n[2014-02-20 16:15:30,474: WARNING/MainProcess] celery@Jons-MacBook.local ready.\n```\n\n```text\n[2014-02-20 16:35:20,159: INFO/MainProcess] Received task: apps.data.tasks.celery_sync_database[960bcb6c-d6a5-4e32-8267-cfbe2b411b25]\n[2014-02-20 16:36:54,561: ERROR/MainProcess] Process 'Worker-4' pid:19500 exited with exitcode -11\n[2014-02-20 16:36:54,580: ERROR/MainProcess] Task apps.data.tasks.celery_sync_database[960bcb6c-d6a5-4e32-8267-cfbe2b411b25] raised unexpected: WorkerLostError('Worker exited prematurely: signal 11 (SIGSEGV).',)\nTraceback (most recent call last):\n File \"/Users/jon/dev/vpe/VAN/lib/python2.7/site-packages/billiard/pool.py\", line 1168, in mark_as_worker_lost\n human_status(exitcode)),\nWorkerLostError: Worker exited prematurely: signal 11 (SIGSEGV).\n```\n\n```text\nsettings.py\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.323Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":162,"estimatedTokens":1620}}1127{"id":"stack-59949210","source":"stackoverflow","questionId":59949210,"title":"MassTransit - best practices to initialize complex messages","tags":[".net","rabbitmq","messaging","masstransit"],"text":"Title: MassTransit - best practices to initialize complex messages\nTags: .net, rabbitmq, messaging, masstransit\nSource: Stack Overflow\n\nQuestion:\nLet's say I have an ASP.NET Core Web API application, and one of my action methods receives `IEnumerable addresses`, where `AddressModel` looks like:\n\n```\npublic class AddressModel\n{\n public string Street { get; set; }\n public string ZipCode { get; set; }\n public string City { get; set; }\n public string Country { get; set; }\n}\n```\n\nI'd like to use it to construct a more complex message object and to send it via MassTransit - `Addresses` will be a nested property and I'll set more fields:\n\n```\npublic interface ICreateContact\n{\n ContactTypeEnum Type { get; }\n List Addresses { get; }\n}\n\npublic interface IAddress\n{\n string Street { get; }\n string ZipCode { get; }\n string City { get; }\n string Country { get; }\n}\n```\n\nSo, how to create such message in the most convenient readable way? I see a few options, but all of them have drawbacks:\n\n- The most straightforward option:\n\n```\nawait _messageBus.Send(new {\n Type = ContactTypeEnum.Single,\n Addresses = addresses.Select(a => new\n {\n Street = a.Street,\n ZipCode = a.ZipCode,\n City = a.City,\n Country = a.Country\n })\n});\n```\n\nWill work, but I don't want to write a lot of code to assign each property and I can't use Automapper, because there're no setters in `ICreateContact/IAddress`.\n\n- Intermediate class:\n\n```\npublic class CreateContact\n{\n public ContactTypeEnum Type { get; set; }\n public List Addresses { get; set; }\n\n public class Address\n {\n public string Street { get; set; }\n public string ZipCode { get; set; }\n public string City { get; set; }\n public string Country { get; set; }\n }\n}\n```\n\n```\nvar command = new CreateContact\n{\n Type = ContactTypeEnum.Single,\n Addresses = addresses.Select(a => _mapper.Map(a)).ToList()\n};\n\nawait _messageBus.Send(command);\n```\n\nLooks better, but what if I want it implement `ICreateContact/IAddress`, so compiler will tell if I construct the message incorrectly? I can't do that, because if I write `CreateContact : ICreateContact`, my `Addresses` field must be of type `List` (even if I make `Address` implement `IAddress`).\n\nSo to summarize my questions:\n\n- Is it possible to avoid intermediate class and use option 1 with automatic mapping of the properties (with or without Automapper)?\n\n- Is it a good idea to create a strongly-typed classes for message contracts in every service?\n\n- If so - how to deal with nested properties of interface types?\n\n- If not - what to do if a message contract has 30 fields, one of them is renamed and you need to know which one without documentation?\n\n========================================\n\nCode:\n```text\npublic class AddressModel\n{\n public string Street { get; set; }\n public string ZipCode { get; set; }\n public string City { get; set; }\n public string Country { get; set; }\n}\n```\n\n```text\npublic interface ICreateContact\n{\n ContactTypeEnum Type { get; }\n List<IAddress> Addresses { get; }\n}\n\npublic interface IAddress\n{\n string Street { get; }\n string ZipCode { get; }\n string City { get; }\n string Country { get; }\n}\n```\n\n```text\nawait _messageBus.Send<ICreateContact>(new {\n Type = ContactTypeEnum.Single,\n Addresses = addresses.Select(a => new\n {\n Street = a.Street,\n ZipCode = a.ZipCode,\n City = a.City,\n Country = a.Country\n })\n});\n```\n\n```text\npublic class CreateContact\n{\n public ContactTypeEnum Type { get; set; }\n public List<Address> Addresses { get; set; }\n\n public class Address\n {\n public string Street { get; set; }\n public string ZipCode { get; set; }\n public string City { get; set; }\n public string Country { get; set; }\n }\n}\n```\n\n```text\nvar command = new CreateContact\n{\n Type = ContactTypeEnum.Single,\n Addresses = addresses.Select(a => _mapper.Map<CreateContact.Address>(a)).ToList()\n};\n\nawait _messageBus.Send<ICreateContact>(command);\n```\n\n```text\nIEnumerable<AddressModel> addresses\n```\n\n```text\nAddressModel\n```\n\n```text\nAddresses\n```\n\n```text\nICreateContact/IAddress\n```\n\n```text\nICreateContact/IAddress\n```\n\n```text\nCreateContact : ICreateContact\n```\n\n```text\nAddresses\n```\n\n```text\nList<IAddress>\n```\n\n```text\nAddress\n```\n\n```text\nIAddress\n```\n\n```text\nawait _messageBus.Send<ICreateContact>(new {\n Type = ContactTypeEnum.Single,\n Addresses = addresses\n});\n```\n\n========================================\n\nComments:\n- docs.automapper.org/en/latest/Construction.html","metadata":{"transformedAt":"2026-08-18T18:33:20.323Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":16,"totalLines":213,"estimatedTokens":1127}}1128{"id":"stack-29293350","source":"stackoverflow","questionId":29293350,"title":"Cannot login in RabbitMQ Management web console","tags":["security","rabbitmq"],"text":"Title: Cannot login in RabbitMQ Management web console\nTags: security, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have installed RabbitMQ Server installed in CentOS 6.6 and I have also installed and enabled Management plugin. If I run the command `rabbitmq-plugins list` this is what I get at console:\n\n```\nConfigured: E = explicitly enabled; e = implicitly enabled\n | Status: * = running on rabbit@pdone-staging\n |/\n[e*] amqp_client 3.5.0\n[ ] cowboy 0.5.0-rmq3.5.0-git4b93c2d\n[ ] eldap 3.5.0-gite309de4\n[e*] mochiweb 2.7.0-rmq3.5.0-git680dba8\n[ ] rabbitmq_amqp1_0 3.5.0\n[ ] rabbitmq_auth_backend_ldap 3.5.0\n[ ] rabbitmq_auth_mechanism_ssl 3.5.0\n[ ] rabbitmq_consistent_hash_exchange 3.5.0\n[ ] rabbitmq_federation 3.5.0\n[ ] rabbitmq_federation_management 3.5.0\n[E*] rabbitmq_management 3.5.0\n[e*] rabbitmq_management_agent 3.5.0\n[ ] rabbitmq_management_visualiser 3.5.0\n[ ] rabbitmq_mqtt 3.5.0\n[ ] rabbitmq_shovel 3.5.0\n[ ] rabbitmq_shovel_management 3.5.0\n[ ] rabbitmq_stomp 3.5.0\n[ ] rabbitmq_test 3.5.0\n[ ] rabbitmq_tracing 3.5.0\n[e*] rabbitmq_web_dispatch 3.5.0\n[ ] rabbitmq_web_stomp 3.5.0\n[ ] rabbitmq_web_stomp_examples 3.5.0\n[ ] sockjs 0.3.4-rmq3.5.0-git3132eb9\n[e*] webmachine 1.10.3-rmq3.5.0-gite9359c7\n```\n\nI'm trying to access with `guest` default user after change it password through `rabbitmqctl change_password guest ` but any time I try to login at `http://localhost:15672/` I got `Login failed` message. I have check `guest` permissions and apparently are right ones:\n\n```\nrabbitmqctl list_user_permissions guest\nListing permissions for user \"guest\" ...\n/ .* .* .*\n```\n\nSo, what I'm missing here? Why I cannot login into Management console?\n\n========================================\n\nCode:\n```text\nConfigured: E = explicitly enabled; e = implicitly enabled\n | Status: * = running on rabbit@pdone-staging\n |/\n[e*] amqp_client 3.5.0\n[ ] cowboy 0.5.0-rmq3.5.0-git4b93c2d\n[ ] eldap 3.5.0-gite309de4\n[e*] mochiweb 2.7.0-rmq3.5.0-git680dba8\n[ ] rabbitmq_amqp1_0 3.5.0\n[ ] rabbitmq_auth_backend_ldap 3.5.0\n[ ] rabbitmq_auth_mechanism_ssl 3.5.0\n[ ] rabbitmq_consistent_hash_exchange 3.5.0\n[ ] rabbitmq_federation 3.5.0\n[ ] rabbitmq_federation_management 3.5.0\n[E*] rabbitmq_management 3.5.0\n[e*] rabbitmq_management_agent 3.5.0\n[ ] rabbitmq_management_visualiser 3.5.0\n[ ] rabbitmq_mqtt 3.5.0\n[ ] rabbitmq_shovel 3.5.0\n[ ] rabbitmq_shovel_management 3.5.0\n[ ] rabbitmq_stomp 3.5.0\n[ ] rabbitmq_test 3.5.0\n[ ] rabbitmq_tracing 3.5.0\n[e*] rabbitmq_web_dispatch 3.5.0\n[ ] rabbitmq_web_stomp 3.5.0\n[ ] rabbitmq_web_stomp_examples 3.5.0\n[ ] sockjs 0.3.4-rmq3.5.0-git3132eb9\n[e*] webmachine 1.10.3-rmq3.5.0-gite9359c7\n```\n\n```text\nrabbitmqctl list_user_permissions guest\nListing permissions for user \"guest\" ...\n/ .* .* .*\n```\n\n```text\nrabbitmq-plugins list\n```\n\n```text\nguest\n```\n\n```text\nrabbitmqctl change_password guest <newpassword>\n```\n\n```text\nhttp://localhost:15672/\n```\n\n```text\nLogin failed\n```\n\n```text\nguest\n```\n\n```text\nsudo rabbitmqctl add_user myuser mypass\nsudo rabbitmqctl set_permissions -p / myuser \".*\" \".*\" \".*\"\nsudo rabbitmqctl set_user_tags myuser administrator\n```\n\n========================================\n\nComments:\n- I do this and setup a \"test\" user, but I cannot see any of my Queues that are running","metadata":{"transformedAt":"2026-08-18T18:33:20.327Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":9,"totalLines":120,"estimatedTokens":908}}1129{"id":"stack-45986687","source":"stackoverflow","questionId":45986687,"title":"How to set per message TTL with RabbitTemplate?","tags":["java","spring","spring-boot","rabbitmq"],"text":"Title: How to set per message TTL with RabbitTemplate?\nTags: java, spring, spring-boot, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm using spring-boot with rabbitMQ and I'm wondering if I can use per message TTL using RabbitTemplate. So far I have :\n\n```\n@Autowired\n private RabbitTemplate rabbit;\n\n public void produce() {\n\n rabbit.convertAndSend(\"My.Queue\", routingKey, message);\n }\n```\n\n========================================\n\nTop Answer:\n```\nrabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE,\n RabbitMqConfig.RK,\n String.valueOf(body),\n message -> {\n message.getMessageProperties().setExpiration(String.valueOf(1000));\n return message;\n });\n```\n\n========================================\n\nCode:\n```text\n@Autowired\n private RabbitTemplate rabbit;\n\n public void produce() {\n\n rabbit.convertAndSend(\"My.Queue\", routingKey, message);\n }\n```\n\n```text\nfinal String message = \"message\";\nfinal MessagePostProcessor messagePostProcessor = new MyMessagePostProcessor(10000);\nrabbitTemplate.convertAndSend(\"my.queue\", \"routingKey\", message, messagePostProcessor);\n```\n\n```text\npublic class MyMessagePostProcessor implements MessagePostProcessor {\n\n private final Integer ttl;\n\n public MyMessagePostProcessor(final Integer ttl) {\n this.ttl = ttl;\n }\n\n @Override\n public Message postProcessMessage(final Message message) throws AmqpException {\n message.getMessageProperties().getHeaders().put(\"expiration\", ttl.toString());\n return message;\n }\n}\n```\n\n```text\nMessagePostProcessor\n```\n\n```text\nrabbitTemplate\n```\n\n```text\n@Autowired\n private RabbitTemplate rabbit;\n\n @Autowired\n private MessageConverter jsonMessageConverter;\n\n public void produce() {\n\n rabbit.setExchange(\"My.Exchange\");\n rabbit.setRoutingKey(\"R.K\");\n rabbit.setMessageConverter(jsonMessageConverter);\n MessageProperties props = new MessageProperties();\n props.setExpiration(Long.toString(expiration));\n Message toSend = new Message(message.toString().getBytes(), props);\n rabbit.send(toSend);\n }\n```\n\n```text\nmessage.getMessageProperties().setExpiration(ttl.toString());\n```\n\n```text\nMessagePostProcessor\n```\n\n```text\nrabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE,\n RabbitMqConfig.RK,\n String.valueOf(body),\n message -> {\n message.getMessageProperties().setExpiration(String.valueOf(1000));\n return message;\n });\n```\n\n========================================\n\nComments:\n- This method didn't work. It works if I change it to `message.getMessageProperties().setExpiration(ttl.toString())‌​;` From answer of @Zhecker","metadata":{"transformedAt":"2026-08-18T18:33:20.327Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":115,"estimatedTokens":677}}1130{"id":"stack-33984894","source":"stackoverflow","questionId":33984894,"title":"Mixing of Pub/Sub with workqueues in RabbitMQ","tags":["c#","rabbitmq"],"text":"Title: Mixing of Pub/Sub with workqueues in RabbitMQ\nTags: c#, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am evaluating using RabbitMQ as message queue/message bus and have been looking at the example tutorials on the RabbitMQ page. \n\nI am looking for a specific scenario not covered by the tutorials and I am not sure if and how it would be possible to do via RabbitMQ. \n\n**The setup**:\n\nLet's assume I got a service, let's call it \"purchase orders\" and I have to other services called \"logistics\" and \"accounting\". \n\nWhen an order is sent, I want to send it as a message via RabbitMQ. \n\nThere 2 \"account\" and 3 \"logistic\" services\n\nWhat would be the correct way to ensure that \"account\" and \"logistic\" will process the message only once? Using pub/sub will cause the messages to be processed twice (account) or trice (logistics) if i understand it correctly.\n\nWith work queues and prefetch=1 it would assure that only one gets it, but I have 2 services and want each type of service to get one. \n\nIs there a way to combine both and have a work queues for each of the service, without sending 2 separate events/messages to two different exchanges?\n\n========================================\n\nComments:\n- Wouldn't topics imply that I specifically have to address the services? Sending a topic like \"order.logistic.account\" and have the services filter for \"*.logistic.*\" and/or \"*.*.account\"? That would imply that each time I add a new type of service (maybe \"ordernotification\", I would have to edit the topics to add it? I was hoping for something more agnostic approach, so the broadcasting service doesn't have to know who the receiver are or if they are any\n- the message producer doesn't know if anyone is there to receive the message... but that doesn't mean you can just toss things over a fence. if you want an order notification processor to receive order notification messages, there has to be some connection - in this case, the routing between a rabbitmq exchange and queue. without proper routing, everyone receives all messages and you end up re-building routing logic in your code instead of taking advantage of rabbitmq doing it for you","metadata":{"transformedAt":"2026-08-18T18:33:20.327Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":28,"estimatedTokens":539}}1131{"id":"stack-50679145","source":"stackoverflow","questionId":50679145,"title":"How to match the routing key with binding pattern for RabbitMQ topic exchange using python regex?","tags":["python","regex","rabbitmq"],"text":"Title: How to match the routing key with binding pattern for RabbitMQ topic exchange using python regex?\nTags: python, regex, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am basically working on RabbitMQ. I am writing a python code wherein I am trying to see if the routing key matches with the binding pattern in case of topic exchange. I came across this link- https://www.rabbitmq.com/tutorials/tutorial-five-java.html where it says- \"However there are two important special cases for binding keys:\n\n```\n* (star) can substitute for exactly one word.\n\n# (hash) can substitute for zero or more words.\n```\n\nSo how do I match the routing key of message with binding pattern of queue? For example routing key of message is \"my.routing.key\" and the queue is bound to topic exchange with binding pattern - \"my.#.*\". In general, how do I match these string patterns for topic exchange, preferably I am looking to use python regex.\n\n========================================\n\nTop Answer:\nThis is an almost direct port of the node lib amqp-match:\n\n```\nimport re\n\ndef amqp_match(key: str, pattern: str) -> bool:\n if key == pattern:\n return True\n replaced = pattern.replace(r'*', r'([^.]+)').replace(r'#', r'([^.]+.?)+')\n regex_string = f\"^{replaced}$\"\n match = re.search(regex_string, key)\n return match is not None\n```\n\n========================================\n\nCode:\n```text\n* (star) can substitute for exactly one word.\n\n# (hash) can substitute for zero or more words.\n```\n\n```java\nPattern toRegex(String pattern) {\n // case sensitive word\n final String word = \"[a-zA-Z]+\";\n\n // replace duplicate # (this makes things simpler)\n pattern = pattern.replaceAll(\"#(?:\\\\.#)+\", \"#\");\n\n // replace *\n pattern = pattern.replaceAll(\"\\\\*\", word);\n\n // replace #\n\n // lone #\n if (\"#\".equals(pattern)) return Pattern.compile(\"(?:\" + word + \"(?:\\\\.\" + word + \")*)?\");\n\n pattern = pattern.replaceFirst(\"^#\\\\.\", \"(?:\" + word + \"\\\\.)*\");\n pattern = pattern.replaceFirst(\"\\\\.#\", \"(?:\\\\.\" + word + \")*\");\n\n // escape dots that aren't escapes already\n pattern = pattern.replaceAll(\"(?<!\\\\\\\\)\\\\.\", \"\\\\\\\\.\");\n\n return Pattern.compile(\"^\" + pattern + \"$\");\n}\n```\n\n```text\nimport re\n\ndef amqp_match(key: str, pattern: str) -> bool:\n if key == pattern:\n return True\n replaced = pattern.replace(r'*', r'([^.]+)').replace(r'#', r'([^.]+.?)+')\n regex_string = f\"^{replaced}$\"\n match = re.search(regex_string, key)\n return match is not None\n```\n\n```text\nfrom typing import Pattern\n\ndef convert(pattern: str) -> Pattern:\n pattern = (\n pattern\n .replace('*', r'([^.]+)')\n .replace('.#', r'(\\.[^.]+)*')\n .replace('#.', r'([^.]+\\.)*')\n )\n return re.compile(f\"^{pattern}$\")\n```\n\n```text\npublic boolean matchRoutingPatterns(String routingTopic, String routingKey)\n{\n // replace duplicates\n routingTopic = routingTopic.replaceAll(\"#(?:\\\\.#)+\", \"#\").replaceAll(\"([#*])\\\\1{2,}\", \"$1\");\n routingKey = routingKey.replaceAll(\"#(?:\\\\.#)+\", \"#\").replaceAll(\"([#*])\\\\1{2,}\", \"$1\");\n\n String[] routingTopicPath = Strings.splitList( routingTopic.replace('.', ','));\n String[] routingKeyPath = Strings.splitList( routingKey.replace('.', ','));\n\n int i=0;\n int j=0;\n while (i<routingTopicPath.length && j<routingKeyPath.length)\n {\n if (\"#\".equals(routingTopicPath[i]) || \"#\".equals(routingKeyPath[j]))\n {\n if (routingTopicPath.length-i > routingKeyPath.length-j)\n { i++; }\n else\n if (routingTopicPath.length-i < routingKeyPath.length-j)\n { j++; }\n else\n { i++; j++; }\n }\n else\n if (\"*\".equals(routingTopicPath[i]) || \"*\".equals(routingKeyPath[j]))\n {\n i++; j++;\n }\n else\n if (routingTopicPath[i].equals(routingKeyPath[j]))\n {\n i++; j++;\n }\n else\n {\n return false;\n }\n }\n\n return true;\n}\n```\n\n```cs\nusing System.Collections.Concurrent;\nusing System.Text.RegularExpressions;\n\npublic static class AmqpTopicMatch\n{\n // If unbounded patterns is a concern, consider nuget package BitFaster.Caching\n private static readonly ConcurrentDictionary<string, Regex> MemorizedPatterns = new();\n\n public static bool IsMatch(string pattern, string key)\n {\n var regex = MemorizedPatterns.GetOrAdd(pattern, ConvertTopicPatternToRegex);\n\n return regex.IsMatch(key);\n }\n\n private static Regex ConvertTopicPatternToRegex(string pattern)\n {\n string regexPattern;\n if (pattern == \"#\")\n {\n regexPattern = @\"^.+$\";\n }\n else\n {\n regexPattern = $\"^{Regex.Escape(pattern)}$\";\n regexPattern = regexPattern.Replace(@\"\\*\", @\"[^.]+\");\n regexPattern = regexPattern.Replace(@\"\\.\\#\", @\"(?:\\.[^.]+)*\");\n regexPattern = regexPattern.Replace(@\"\\#\\.\", @\"(?:[^.]+\\.)*\");\n }\n\n return new Regex(regexPattern, RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.NonBacktracking);\n }\n}\n```\n\n```cs\nusing NUnit.Framework;\n\n[TestFixture]\npublic class AmqpTopicMatch_Test\n{\n [Test]\n [TestCase(\"this.key\", \"this.key\")]\n [TestCase(\"this.*.key\", \"this.new.key\")]\n [TestCase(\"this.*\", \"this.key\")]\n [TestCase(\"*.key\", \"this.key\")]\n [TestCase(\"*\", \"this\")]\n [TestCase(\"this.#.key\", \"this.new.kinda.key\")]\n [TestCase(\"this.#.key\", \"this.key\")]\n [TestCase(\"#.key\", \"this.key\")]\n [TestCase(\"#.key\", \"key\")]\n [TestCase(\"this.#\", \"this.key\")]\n [TestCase(\"this.#\", \"this\")]\n [TestCase(\"#\", \"this.key\")]\n [TestCase(\"#\", \"this\")]\n public void ShouldMatch(string pattern, string key)\n {\n Assert.That(AmqpTopicMatch.IsMatch(pattern, key), Is.True);\n }\n\n [Test]\n [TestCase(\"this.key\", \"this.other.key\")]\n [TestCase(\"this.*.key\", \"this.new.other.key\")]\n [TestCase(\"this.*.key\", \"this.key\")]\n [TestCase(\"this.*\", \"this\")]\n [TestCase(\"*.key\", \"key\")]\n [TestCase(\"this.#.key\", \"some.new.kinda.key\")]\n [TestCase(\"#.key\", \"some.new.kinda.key.value\")]\n [TestCase(\"this.#\", \"some.key\")]\n public void ShouldNotMatch(string pattern, string key)\n {\n Assert.That(AmqpTopicMatch.IsMatch(pattern, key), Is.False);\n }\n}\n```\n\n========================================\n\nComments:\n- could you provide input and desired output examples?\n- input = \"my.routing.key\" , pattern = \"my.#.* , output = true, here # means zero or more words, * means exactly one word.\n- maybe i wasn't clear enough. you receive random strings and have to say if it matches \"my.routing.key\"? if so, you don't even need regex. just `string_to_test==\"my.routing.key\"` and you're done\n- No, the input string has to match the pattern (wildcard match)\n- my.routing.key has to match the pattern my.#.*\n- that pattern doesn't mean anything in python `re`. have a look in the docs, show us what you got and you'll get some help\n- guys, he has a wildcard pattern that he wants to be converted into a regex pattern. so he wants a functions converting 'my.#' into 'my.*' that he can use the regex to match. the alternative would be a function that returns whether the input matches the wildcard pattern.\n- Nice! I found a couple of possible undesirable matches such as `amqp_match('a.b.c.', '*.b.#')` and `amqp_match('a..c', '#.*')` (though they're not problematic if your keys are sensible in the first place :)\n- Can you provide a conversion to C# or VB .NET?\n- @DavidP sry regex is for me write only code. don't know who invented that syntax, but i don't even try to understand what's going on when seeing the pattern, even if i wrote them myself. nvm gl to u","metadata":{"transformedAt":"2026-08-18T18:33:20.327Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":226,"estimatedTokens":1928}}1132{"id":"stack-39400010","source":"stackoverflow","questionId":39400010,"title":"Serialization and Deserialization through message queue","tags":["java","serialization","spring-boot","rabbitmq","deserialization"],"text":"Title: Serialization and Deserialization through message queue\nTags: java, serialization, spring-boot, rabbitmq, deserialization\nSource: Stack Overflow\n\nQuestion:\nI have an `Employee` class as below:\n\n```\npackage com.mypackage.rabbitmq.model\nimport java.io.Serializable;\n\nimport javax.xml.bind.annotation.XmlRootElement;\n\n@XmlRootElement\npublic class Employee implements Serializable{\n\n /**\n * \n */\n private static final long serialVersionUID = -2736911235490297622L;\n private int EmpNo;\n private String FirstName;\n private String LastName;\n private int age;\n private String gender;\n private String skill;\n private long phone;\n private String email;\n private double salary;\n //getters and setters\n```\n\nI published the list of employee in rabbit MQ as below:\n\n```\npackage com.mypackage.rabbitmq.client.publisher;\n\n//imports\n\npublic class Publisher {\n\n public static void main(String[] args) throws IOException {\n ConnectionFactory factory = new ConnectionFactory();\n\n Connection con = factory.newConnection(\"localhost\");\n Channel channel = con.createChannel();\n\n Gson gson = new GsonBuilder().create();\n Employee employee = null;\n\n List empList = new ArrayList<>();\n ByteArrayOutputStream bos = new ByteArrayOutputStream();\n ObjectOutputStream oos = new ObjectOutputStream(bos);\n\n String queueName = \"TestQueue\";\n for(int i=1; iFrom a separate spring boot application I tried to consume the list of employee. In the consumer application I have the same employee class structure. However the package is different.\n\n```\npackage org.springboot.consumer.model;\n\nimport java.io.Serializable;\n\npublic class Employee implements Serializable{\n //fields and getters-setters here\n}\n```\n\nIn brief consumer code is as bellow:\n\n```\npublic class SDPRabbitMQConsumer implements MessageListener {\n\n @Override\n public void onMessage(Message message) {\n Gson gson = new GsonBuilder().create();\n try {\n ByteArrayOutputStream os = new ByteArrayOutputStream();\n os.write(message.getBody(), 0, message.getBody().length);\n ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());\n ObjectInputStream objInputStream = new ObjectInputStream(is);\n System.out.println(\"objInputStream.readObject().toString()\"+objInputStream.readObject().toString());\n Employee[] employeeArray = gson.fromJson(objInputStream.readObject().toString(), Employee[].class);\n List employeeList = new ArrayList(Arrays.asList(employeeArray));\n for(Employee employee: employeeList){\n System.out.println(employee);\n }\n } catch (Exception e) {\n e.printStackTrace();\n }\n\n }\n\n}\n```\n\nBut I am getting the below exception:\n\n```\njava.lang.ClassNotFoundException: com.mypackage.rabbitmq.model.Employee\n```\n\nIt seems it's a Serialization and Deserialization issue.\n\nMy questions are:\n\n- If I publish Employee instead of List I don't even need to serialize the class. Then why I need to serialize in case of List?\n\n- Why this Exception? Do we need to maintain same package structure for a serialized class in both end?\n\n- In the consumer side do we need to have serialVersionUID? If yes, should it match with that of publisher's side?\n\nThanks in advance.\n\n========================================\n\nCode:\n```text\npackage com.mypackage.rabbitmq.model\nimport java.io.Serializable;\n\nimport javax.xml.bind.annotation.XmlRootElement;\n\n\n@XmlRootElement\npublic class Employee implements Serializable{\n\n /**\n * \n */\n private static final long serialVersionUID = -2736911235490297622L;\n private int EmpNo;\n private String FirstName;\n private String LastName;\n private int age;\n private String gender;\n private String skill;\n private long phone;\n private String email;\n private double salary;\n //getters and setters\n```\n\n```text\npackage com.mypackage.rabbitmq.client.publisher;\n\n//imports\n\npublic class Publisher {\n\n public static void main(String[] args) throws IOException {\n ConnectionFactory factory = new ConnectionFactory();\n\n Connection con = factory.newConnection(\"localhost\");\n Channel channel = con.createChannel();\n\n Gson gson = new GsonBuilder().create();\n Employee employee = null;\n\n List<Employee> empList = new ArrayList<>();\n ByteArrayOutputStream bos = new ByteArrayOutputStream();\n ObjectOutputStream oos = new ObjectOutputStream(bos);\n\n String queueName = \"TestQueue\";\n for(int i=1; i<=10; i++){\n employee = newEmp(i);\n\n String message =gson.toJson(employee);\n System.out.println(\"queueName: \"+queueName);\n empList.add(employee);\n\n }\n oos.writeObject(empList);\n channel.basicPublish(1, \"\", queueName, null, bos.toByteArray());\n System.out.println(\"[X], sent '\"+empList+\"'\");\n\n channel.close(0, queueName);\n con.close(0, queueName);\n }\n\n public static Employee newEmp(int i){\n\n //logic here\n }\n}\n```\n\n```text\npackage org.springboot.consumer.model;\n\nimport java.io.Serializable;\n\npublic class Employee implements Serializable{\n //fields and getters-setters here\n}\n```\n\n```text\npublic class SDPRabbitMQConsumer implements MessageListener {\n\n @Override\n public void onMessage(Message message) {\n Gson gson = new GsonBuilder().create();\n try {\n ByteArrayOutputStream os = new ByteArrayOutputStream();\n os.write(message.getBody(), 0, message.getBody().length);\n ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());\n ObjectInputStream objInputStream = new ObjectInputStream(is);\n System.out.println(\"objInputStream.readObject().toString()\"+objInputStream.readObject().toString());\n Employee[] employeeArray = gson.fromJson(objInputStream.readObject().toString(), Employee[].class);\n List<Employee> employeeList = new ArrayList<Employee>(Arrays.asList(employeeArray));\n for(Employee employee: employeeList){\n System.out.println(employee);\n }\n } catch (Exception e) {\n e.printStackTrace();\n }\n\n }\n\n}\n```\n\n```text\njava.lang.ClassNotFoundException: com.mypackage.rabbitmq.model.Employee\n```\n\n```text\nEmployee\n```\n\n========================================\n\nComments:\n- Thanks. I have one doubt though. As I mentioned, instead of List, if I publish byte array of employee object without serialize the Employee class, I can construct it at the consumer end. How is that possible?\n- \"byte array of employee object without serializing the Employee class\" doesn't make sense, a byte array can only contain bytes. You're sending bytes down the channel, the channel always takes bytes the way you present it, you're adding the serialization layer on top.\n- Well, previously I did not serialized the Employee class and published in the channel as following `String message =gson.toJson(employee); channel.basicPublish(1, \"\", queueName, null, message.getBytes());` In consumer side I was able to get the object as following `String msg = new String(message.getBody()); Employee employee = gson.fromJson(msg, Employee.class);`\n- Yeah that way your not using Java serialization but Json serialization. At the end of the day the queue is not aware of what you're sending, just taking bytes from one end and putting them in the other end is up to you how you want to encode that information to be meaningful\n- Oh okay. I got it. Thanks @Ulises","metadata":{"transformedAt":"2026-08-18T18:33:20.327Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":238,"estimatedTokens":1844}}1133{"id":"stack-45967365","source":"stackoverflow","questionId":45967365,"title":"How do use RabbitMQ policies to set an exchange as durable","tags":["rabbitmq"],"text":"Title: How do use RabbitMQ policies to set an exchange as durable\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nUsing RabbitMQ, how do I create a policy that will make an existing exchange durable? At this point, I believe I have to delete the exchange and then declare it again setting `durable:true`.\n\nSecondary related question: Could a policy be created to set `durable:true` for declared exchanges even if the client didn't specify that parameter?\n\n========================================\n\nCode:\n```text\ndurable:true\n```\n\n```text\ndurable:true\n```\n\n```text\ndurable:true\n```\n\n```text\ndurable\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.327Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":27,"estimatedTokens":151}}1134{"id":"stack-39853762","source":"stackoverflow","questionId":39853762,"title":"Spring rabbit retries to deliver rejected message..is it OK?","tags":["spring-boot","rabbitmq","spring-amqp","spring-rabbit"],"text":"Title: Spring rabbit retries to deliver rejected message..is it OK?\nTags: spring-boot, rabbitmq, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI have the following configuration\n\n```\nspring.rabbitmq.listener.prefetch=1\nspring.rabbitmq.listener.concurrency=1\nspring.rabbitmq.listener.retry.enabled=true\nspring.rabbitmq.listener.retry.max-attempts=3\nspring.rabbitmq.listener.retry.max-interval=1000\nspring.rabbitmq.listener.default-requeue-rejected=false //I have also changed it to true but the same behavior still happens\n```\n\nand in my listener I throw the exception **AmqpRejectAndDontRequeueException** **to reject the message and enforce rabbit not to try to redeliver it**...But rabbit redilvers it for 3 times then finally route it to dead letter queue.\n\nIs that the standard behavior according to my provided configuration or do I miss something?\n\n========================================\n\nTop Answer:\nThe other answers posted here didn't work me when using Spring Boot 2.3.5 and Spring AMQP Starter 2.2.12, but for these versions I was able to customize the retry policy to not retry AmqpRejectAndDontRequeueException exceptions:\n\n```\n@Configuration\npublic class RabbitConfiguration {\n\n@Bean\npublic RabbitRetryTemplateCustomizer customizeRetryPolicy(\n @Value(\"${spring.rabbitmq.listener.simple.retry.max-attempts}\") int maxAttempts) {\n SimpleRetryPolicy policy = new SimpleRetryPolicy(maxAttempts, Map.of(AmqpRejectAndDontRequeueException.class, false), true, true);\n return (target, retryTemplate) -> retryTemplate.setRetryPolicy(policy);\n}\n```\n\n}\n\nThis lets the retry policy skip retries for AmqpRejectAndDontRequeueExceptions but retries all other exceptions as usual.\n\nConfigured this way, it traverses the causes of an exception, and skips retries if it finds an AmqpRejectAndDontRequeueException.\n\nTraversing the causes is needed as `org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter#invokeHandler` wraps all exceptions as a `ListenerExecutionFailedException`\n\n========================================\n\nCode:\n```text\nspring.rabbitmq.listener.prefetch=1\nspring.rabbitmq.listener.concurrency=1\nspring.rabbitmq.listener.retry.enabled=true\nspring.rabbitmq.listener.retry.max-attempts=3\nspring.rabbitmq.listener.retry.max-interval=1000\nspring.rabbitmq.listener.default-requeue-rejected=false //I have also changed it to true but the same behavior still happens\n```\n\n```text\n@SpringBootApplication\npublic class So39853762Application {\n\n public static void main(String[] args) throws Exception {\n ConfigurableApplicationContext context = SpringApplication.run(So39853762Application.class, args);\n Thread.sleep(60000);\n context.close();\n }\n\n @RabbitListener(queues = \"foo\")\n public void foo(String foo) {\n System.out.println(foo);\n if (\"foo\".equals(foo)) {\n throw new AmqpRejectAndDontRequeueException(\"foo\"); // won't be retried.\n }\n else {\n throw new IllegalStateException(\"bar\"); // will be retried\n }\n }\n\n @Bean\n public ListenerRetryAdviceCustomizer retryCustomizer(SimpleRabbitListenerContainerFactory containerFactory,\n RabbitProperties rabbitPropeties) {\n return new ListenerRetryAdviceCustomizer(containerFactory, rabbitPropeties);\n }\n\n public static class ListenerRetryAdviceCustomizer implements InitializingBean {\n\n private final SimpleRabbitListenerContainerFactory containerFactory;\n\n private final RabbitProperties rabbitPropeties;\n\n public ListenerRetryAdviceCustomizer(SimpleRabbitListenerContainerFactory containerFactory,\n RabbitProperties rabbitPropeties) {\n this.containerFactory = containerFactory;\n this.rabbitPropeties = rabbitPropeties;\n }\n\n @Override\n public void afterPropertiesSet() throws Exception {\n ListenerRetry retryConfig = this.rabbitPropeties.getListener().getRetry();\n if (retryConfig.isEnabled()) {\n RetryInterceptorBuilder<?> builder = (retryConfig.isStateless()\n ? RetryInterceptorBuilder.stateless()\n : RetryInterceptorBuilder.stateful());\n Map<Class<? extends Throwable>, Boolean> retryableExceptions = new HashMap<>();\n retryableExceptions.put(AmqpRejectAndDontRequeueException.class, false);\n retryableExceptions.put(IllegalStateException.class, true);\n SimpleRetryPolicy policy =\n new SimpleRetryPolicy(retryConfig.getMaxAttempts(), retryableExceptions, true);\n ExponentialBackOffPolicy backOff = new ExponentialBackOffPolicy();\n backOff.setInitialInterval(retryConfig.getInitialInterval());\n backOff.setMultiplier(retryConfig.getMultiplier());\n backOff.setMaxInterval(retryConfig.getMaxInterval());\n builder.retryPolicy(policy)\n .backOffPolicy(backOff)\n .recoverer(new RejectAndDontRequeueRecoverer());\n this.containerFactory.setAdviceChain(builder.build());\n }\n }\n\n }\n\n}\n```\n\n```text\nrequeue-rejected\n```\n\n```text\nAmqpRejectAndDontRequeueException\n```\n\n```text\n@Configuration\npublic class RabbitConfiguration {\n\n@Bean\npublic RabbitRetryTemplateCustomizer customizeRetryPolicy(\n @Value(\"${spring.rabbitmq.listener.simple.retry.max-attempts}\") int maxAttempts) {\n SimpleRetryPolicy policy = new SimpleRetryPolicy(maxAttempts, Map.of(AmqpRejectAndDontRequeueException.class, false), true, true);\n return (target, retryTemplate) -> retryTemplate.setRetryPolicy(policy);\n}\n```\n\n```text\norg.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter#invokeHandler\n```\n\n```text\nListenerExecutionFailedException\n```\n\n========================================\n\nComments:\n- Thanks for the post @GaryRussell - I could not figure out why AmqpRejectAndDontRequeueException I was throwing inside of my consumer containers were being retried. Now I get it - RetryPolicy governs this.","metadata":{"transformedAt":"2026-08-18T18:33:20.327Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":156,"estimatedTokens":1529}}1135{"id":"stack-35894549","source":"stackoverflow","questionId":35894549,"title":"Can we speed up publishing messages via RabbitMQ","tags":["python-3.x","rabbitmq","ubuntu-14.04"],"text":"Title: Can we speed up publishing messages via RabbitMQ\nTags: python-3.x, rabbitmq, ubuntu-14.04\nSource: Stack Overflow\n\nQuestion:\nI am running some tests on my Ubuntu workstation. These benchmarks start with populating a queue, which runs very slowly:\n\n```\nimport pika\nimport datetime\n\nif __name__ == '__main__':\n try:\n connection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost'))\n channel = connection.channel()\n\n channel.queue_declare(queue='hello_durable', durable=True)\n started_at = datetime.datetime.now()\n properties = pika.BasicProperties(delivery_mode=2)\n for i in range(0, 100000):\n channel.basic_publish(exchange='',\n routing_key='hello',\n body='Hello World!',\n properties=properties)\n if i%10000 == 0:\n duration = datetime.datetime.now() - started_at\n print(i, duration.total_seconds())\n print(\" [x] Sent 'Hello World!'\")\n connection.close()\n now = datetime.datetime.now()\n duration = now - started_at\n print(duration.total_seconds())\n except Exception as e:\n print(e)\n```\n\nIt takes more than 30 seconds to send 10K messages. The workstation has 12 cores, which are not busy, according to top command. There are over 8Gb of free memory. It does not matter much whether the queue is durable.\n\nHow can we speed up sending messages?\n\n========================================\n\nTop Answer:\nAm assuming that you don't run any consumers `These benchmarks start with populating a queue`.\nSince you are only publishing messages, the rabbitmq switches to flow state. To be more precise, your exchanges and/or queues go to flow state. \nQuote from rabbitmq blog\n\n This (roughly) means that the client is being rate-limited; it would\n like to publish faster but the server can't keep up\n\nI'm sure that if you look close enough, you will see that the first portion of the messages (on initial setup, with empty queue) goes fast, but the sending rate drops drastically at some point.\n\n========================================\n\nCode:\n```text\nimport pika\nimport datetime\n\nif __name__ == '__main__':\n try:\n connection = pika.BlockingConnection(pika.ConnectionParameters(\n host='localhost'))\n channel = connection.channel()\n\n channel.queue_declare(queue='hello_durable', durable=True)\n started_at = datetime.datetime.now()\n properties = pika.BasicProperties(delivery_mode=2)\n for i in range(0, 100000):\n channel.basic_publish(exchange='',\n routing_key='hello',\n body='Hello World!',\n properties=properties)\n if i%10000 == 0:\n duration = datetime.datetime.now() - started_at\n print(i, duration.total_seconds())\n print(\" [x] Sent 'Hello World!'\")\n connection.close()\n now = datetime.datetime.now()\n duration = now - started_at\n print(duration.total_seconds())\n except Exception as e:\n print(e)\n```\n\n```text\nimport pika\n\n# Step #3\ndef on_open(connection):\n\n connection.channel(on_channel_open)\n\n# Step #4\ndef on_channel_open(channel):\n\n channel.basic_publish('test_exchange',\n 'test_routing_key',\n 'message body value',\n pika.BasicProperties(content_type='text/plain',\n delivery_mode=1))\n\n connection.close()\n\n# Step #1: Connect to RabbitMQ\nparameters = pika.URLParameters('amqp://guest:guest@localhost:5672/%2F')\n\nconnection = pika.SelectConnection(parameters=parameters,\n on_open_callback=on_open)\n\ntry:\n\n # Step #2 - Block on the IOLoop\n connection.ioloop.start()\n\n# Catch a Keyboard Interrupt to make sure that the connection is closed cleanly\nexcept KeyboardInterrupt:\n\n # Gracefully close the connection\n connection.close()\n\n # Start the IOLoop again so Pika can communicate, it will stop on its own when the connection is closed\n connection.ioloop.start()\n```\n\n```text\nThese benchmarks start with populating a queue\n```\n\n========================================\n\nComments:\n- Publishing in multi-threading ?\n- I have the same problem, I don't understand in your last example how you can send content of a logfilce by example ?","metadata":{"transformedAt":"2026-08-18T18:33:20.327Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":135,"estimatedTokens":1073}}1136{"id":"stack-46093735","source":"stackoverflow","questionId":46093735,"title":"RabbitMQ - How to override the replyTimeout for sendAndReceive?","tags":["rabbitmq","amqp","spring-amqp"],"text":"Title: RabbitMQ - How to override the replyTimeout for sendAndReceive?\nTags: rabbitmq, amqp, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI am configuring the amqp template using the spring amqp definition like \n\n```\n\n```\n\nNow, while calling the `amqpTemplate.sendAndReceive(\"COR.QUEUE\", message)`, can I change the replyTimeout for specific requests?\n\n========================================\n\nCode:\n```text\n<rabbit:template id=\"amqpTemplate\" connection-factory=\"connectionFactory\" reply-timeout=\"45000\" />\n```\n\n```text\namqpTemplate.sendAndReceive(\"COR.QUEUE\", message)\n```\n\n```text\nprivate final Map<Long, RabbitTemplate> templates = new HashMap<>();\n\npublic Message sendAndReceive(String rk, Message message, long timeout) {\n // lookup a template for the requested timeout, or add one to the map\n return lookedupTemplate.sendAndReceive(rk, message);\n}\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.327Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":32,"estimatedTokens":217}}1137{"id":"stack-39601398","source":"stackoverflow","questionId":39601398,"title":"Message types : how much information should messages contain?","tags":["rabbitmq","domain-driven-design","message-queue","integration-patterns"],"text":"Title: Message types : how much information should messages contain?\nTags: rabbitmq, domain-driven-design, message-queue, integration-patterns\nSource: Stack Overflow\n\nQuestion:\nWe are currently starting to broadcast events from one central applications to other possibly interested consumer applications, and we have different options among members of our team about **how much we should put in our published messages**.\n\nThe general idea/architecture is the following :\n\nIn the **producer application** :\n\n- the user interacts with some entities (Aggregate Roots in the DDD sense) that can be created/modified/deleted\n\n- Based on what is happening, Domain Events are raised (ex : EntityXCreated, EntityYDeleted, EntityZTransferred etc ... i.e. not only CRUD, but mostly )\n\n- Raised events are translated/converted into messages that we send to a RabbitMQ Exchange\n\nin **RabbitMQ** *(we are using RabbitMQ but I believe the question is actually technology-independent)*: \n\n- we define a queue for each consuming application\n\n- bindings connect the exchange to the consumer queues (possibly with message filtering)\n\nIn the **consuming application(s)**\n\n- application consumes and process messages from its queue\n\nBased on Enterprise Integration Patterns we are trying to define the *Canonical format* for our published messages, and are hesitating between 2 approaches : \n\n**Minimalist messages** / **event-store-ish** : for each event published by the Domain Model, generate a message that contains only the parts of the Aggregate Root that are relevant (for instance, when an update is done, only publish information about the updated section of the aggregate root, more or less matching the process the end-user goes through when using our application)\n\n**Pros**\n\n- small message size\n\n- very specialized message types\n\n- close to the \"Domain Events\"\n\n**Cons**\n\n- problematic if delivery order is not guaranteed (i.e. what if Update message is received before Create message ? )\n\n- consumers need to know which message types to subscribe to (possibly a big list / domain knowledge is needed)\n\n- what if consumer state and producer state get out of sync ?\n\n- how to handle new consumer that registers in the future, but does not have knowledge of all the past events\n\n**Fully-contained idempotent-ish messages** : for each event published by the Domain Model, generate a message that contains a full snapshot of the Aggregate Root at that point in time, hence handling in reality only 2 kind of messages \"Create or Update\" and \"Delete\" (+metadata with more specific info if necessary)\n\n**Pros**\n\n- idempotent (declarative messages stating \"this is what the truth is like, synchronize yourself however you can\")\n\n- lower number of message formats to maintain/handle\n\n- allow to progressively correct synchronization errors of consumers\n\n- consumer automagically handle new Domain Events as long as the resulting message follows canonical data model\n\n**Cons**\n\n- bigger message payload\n\n- less *pure*\n\nWould you recommend an approach over the other ?\n\nIs there another approach we should consider ?\n\n========================================\n\nComments:\n- - \"...your events carry identifiers, so that interested parties can know that an entity ... has changed, and can query the authority for updates...\" -> that makes sense, but are we not over-coupling consumers to the producer in that case ? (i.e. producer must be up and running for consumers to do their job properly )\n- \"any change to the representation of the aggregate also implies a change to the message schema, which is part of the API\" -> but it's not an issue as long as we are only adding to the schemas, right ? not all parts of the aggregate need to be in the message\n- \"If a consumer needs state, ..., then it should be fetching that view from the producer, \" -> makes sense ! I'll wait a few days for other answers before accepting any ;)\n- I'll accept the answer, as I did not get any other ones :-/","metadata":{"transformedAt":"2026-08-18T18:33:20.328Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":78,"estimatedTokens":992}}1138{"id":"stack-37854973","source":"stackoverflow","questionId":37854973,"title":"Pika: Consume the next message even the last message was not acknowledged","tags":["python","multithreading","rabbitmq","pika"],"text":"Title: Pika: Consume the next message even the last message was not acknowledged\nTags: python, multithreading, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nFor server automation, we're trying to develop a tool, which can handle and execute a lot of tasks on different servers. We send the task and the server hostname into a queue. The queue is then consumed from a requester, which give the information to the ansible api. To achieve that we can execute more then one task at once, we're using threading.\n\nNow we're stuck with the acknowledge of the message...\n\nWhat we have done so far:\n\nThe `requester.py` consumes the queue and starts then a thread, in which the ansible task is running. The result is then sended into another queue. So each new messages creates a new thread. Is the task finished, the thread dies.\n\nBut now comes difficult part. We have to made the messages persistent, in case our server dies. So each message should be acknowledged **after** the result from ansible was sended back.\n\nOur problem is now, when we try to acknowledged the message in the thread itselfs, there is no more \"simultaneously\" work done, because the `consume` of pika waits for the acknowledge. So how we can achieve, that the `consume` consumes messages and dont wait for the acknowledge? Or how we can work around or improve our little programm?\n\n**requester.py**\n\n```\n#!/bin/python\n\n from worker import *\n import ansible.inventory\n import ansible.runner\n import threading\n\n class Requester(Worker):\n def __init__(self):\n Worker.__init__(self)\n self.connection(self.selfhost, self.from_db)\n self.receive(self.from_db)\n\n def send(self, result, ch, method):\n self.channel.basic_publish(exchange='',\n routing_key=self.to_db,\n body=result,\n properties=pika.BasicProperties(\n delivery_mode=2,\n ))\n\n print \"[x] Sent \\n\" + result\n ch.basic_ack(delivery_tag = method.delivery_tag)\n\n def callAnsible(self, cmd, ch, method):\n #call ansible api pre 2.0\n\n result = json.dumps(result, sort_keys=True, indent=4, separators=(',', ': '))\n self.send(result, ch, method)\n\n def callback(self, ch, method, properties, body):\n print(\" [x] Received by requester %r\" % body)\n t = threading.Thread(target=self.callAnsible, args=(body,ch,method,))\n t.start()\n```\n\n**worker.py**\n\n```\nimport pika\n import ConfigParser\n import json\n import os\n\n class Worker(object):\n def __init__(self):\n #read some config files\n\n def callback(self, ch, method, properties, body):\n raise Exception(\"Call method in subclass\")\n\n def receive(self, queue):\n self.channel.basic_qos(prefetch_count=1)\n self.channel.basic_consume(self.callback,queue=queue)\n self.channel.start_consuming()\n\n def connection(self,server,queue):\n self.connection = pika.BlockingConnection(pika.ConnectionParameters(\n host=server,\n credentials=self.credentials))\n self.channel = self.connection.channel()\n self.channel.queue_declare(queue=queue, durable=True)\n```\n\nWe're working with Python 2.7 and pika 0.10.0.\n\nAnd yes, we noticed in the pika FAQ: http://pika.readthedocs.io/en/0.10.0/faq.html\n\nthat pika is not thread safe.\n\n========================================\n\nCode:\n```text\n#!/bin/python\n\n from worker import *\n import ansible.inventory\n import ansible.runner\n import threading\n\n class Requester(Worker):\n def __init__(self):\n Worker.__init__(self)\n self.connection(self.selfhost, self.from_db)\n self.receive(self.from_db)\n\n def send(self, result, ch, method):\n self.channel.basic_publish(exchange='',\n routing_key=self.to_db,\n body=result,\n properties=pika.BasicProperties(\n delivery_mode=2,\n ))\n\n print \"[x] Sent \\n\" + result\n ch.basic_ack(delivery_tag = method.delivery_tag)\n\n def callAnsible(self, cmd, ch, method):\n #call ansible api pre 2.0\n\n result = json.dumps(result, sort_keys=True, indent=4, separators=(',', ': '))\n self.send(result, ch, method)\n\n def callback(self, ch, method, properties, body):\n print(\" [x] Received by requester %r\" % body)\n t = threading.Thread(target=self.callAnsible, args=(body,ch,method,))\n t.start()\n```\n\n```text\nimport pika\n import ConfigParser\n import json\n import os\n\n class Worker(object):\n def __init__(self):\n #read some config files\n\n def callback(self, ch, method, properties, body):\n raise Exception(\"Call method in subclass\")\n\n def receive(self, queue):\n self.channel.basic_qos(prefetch_count=1)\n self.channel.basic_consume(self.callback,queue=queue)\n self.channel.start_consuming()\n\n def connection(self,server,queue):\n self.connection = pika.BlockingConnection(pika.ConnectionParameters(\n host=server,\n credentials=self.credentials))\n self.channel = self.connection.channel()\n self.channel.queue_declare(queue=queue, durable=True)\n```\n\n```text\nrequester.py\n```\n\n```text\nconsume\n```\n\n```text\nconsume\n```\n\n```text\nchannel.basic_qos(prefetch_count=1)\n```\n\n========================================\n\nComments:\n- Awesome! Thank you! How can I overlock this prefetch count. This does all the magic.\n- @Rumpli I have added this to the answer. Now I'm gonna go on my own damage here, but since you are new here I'll explain shortly about upvoting and accepting answers: If the answer helps you, give it an up vote. If it solves you problem, give it an upvote and accept. Here you have only accepted without upvote, but you didn't try it to is if it works :) Maybe just upvote for now, and once you verify accept as well. Someone please correct me if I didn't explain this voting/accepting correctly.\n- Thanks for your explanation. I tried this out and with setting the 'channel.basic_qos(prefetch_count=1)' to more then '1', it does more then one task at the time. And i tried to upvote your answer to, but as long as I dont have 15 reputation, it will not display it... :(","metadata":{"transformedAt":"2026-08-18T18:33:20.328Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":178,"estimatedTokens":1529}}1139{"id":"stack-62340859","source":"stackoverflow","questionId":62340859,"title":"RabbitMQ poor performance","tags":["rabbitmq","erlang","rabbitmqctl"],"text":"Title: RabbitMQ poor performance\nTags: rabbitmq, erlang, rabbitmqctl\nSource: Stack Overflow\n\nQuestion:\nWe are facing bad performance in our **RabbitMQ** clusters. Even when idle.\n\nOnce installed the rabbitmq-top plugin, we see many processes with very high **reductions/sec**. 100k and more!\n\n**Questions:**\n\n- What does it mean?\n\n- How to control it?\n\n- What might be causing such slowness without any errors?\n\n**Notes:**\n\n- Our clusters are running on Kubernetes 1.15.11\n\n- We allocated 3 nodes, each with 8 CPU and 8 GB limits. Set vm_watermark to 7G. Actual usage is ~1.5 CPU and 1 GB RAM\n\n- RabbitMQ 3.8.2. Erlang 22.1\n\n- We don't have many consumers and producers. The slowness is also on a fairly idle environment\n\n- The `rabbitmqctl status` is very slow to return details (sometimes 2 minutes) but **does not show** any errors\n\n========================================\n\nCode:\n```text\nrabbitmqctl status\n```\n\n```text\naliveness-test\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.328Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":39,"estimatedTokens":236}}1140{"id":"stack-16498966","source":"stackoverflow","questionId":16498966,"title":"Django Celery - How to start a task with a delay of n - seconds - countdown flag is ignored","tags":["django","thread-safety","rabbitmq","celery","django-celery"],"text":"Title: Django Celery - How to start a task with a delay of n - seconds - countdown flag is ignored\nTags: django, thread-safety, rabbitmq, celery, django-celery\nSource: Stack Overflow\n\nQuestion:\nIn my Django project I'm running some asynchronous tasks using Celery (docs), Django-Celery and RabbitMQ as the broker. Whereas it works in general, I have two problems with my setup:\n\na) the task execution seems to be joined with my request thread. Thus the user http request seems to wait until the task has been executed\n\nb) the task execution seems to ignore the countdown flag\n\nFor testing purposes I have setup a simple TestTask:\n\n```\nfrom celery.task import Task\nfrom celery.registry import tasks\n\n#in project_management.tasks.py\nclass TestTask(Task):\n def run(self, x, y):\n print \"running TestTask\"\n return x + y\n\ntasks.register(TestTask)\n```\n\nRunning this task from within the console gives me the following result:\n\n```\npython manage.py shell\nfrom project_management.tasks import TestTask\nresult = TestTask.apply_async(args=[5, 5], kwargs={}, countdown=10)#immediately outputs \"running TestTask\"\nresult.result -> immediately returns 10\nresult.ready() -> immediately returns True\n```\n\nThus the countdown flag set to 10 is totally ignored. Any idea what could be wrong with my setup? \n\nI'm starting Celery and RabbitMQ with the following commands:\n\n```\nRABBITMQ_NODE_PORT=5672 rabbitmq-server\npython manage.py celeryd --loglevel=info\n```\n\nUpdate:\n\nI think this problem relates somehow to timezone settings. See this thread for more info. Anyhow not sure how to circumvent it. I executed this tests, always having the same result that the result is immediately available:\n\n```\n>>> from project_management.tasks import add\n>>> from datetime import timedelta, datetime\n>>> eta = datetime.now() + timedelta(seconds=60)\n>>> result = add.apply_async(args=[5, 5], kwargs={}, eta=eta)\n>>> result.ready()\nTrue\n>>> eta = datetime.utcnow() + timedelta(seconds=60)\n>>> result = add.apply_async(args=[5, 5], kwargs={}, eta=eta)\n>>> result.ready()\nTrue\n```\n\n========================================\n\nCode:\n```text\nfrom celery.task import Task\nfrom celery.registry import tasks\n\n#in project_management.tasks.py\nclass TestTask(Task):\n def run(self, x, y):\n print \"running TestTask\"\n return x + y\n\ntasks.register(TestTask)\n```\n\n```text\npython manage.py shell\nfrom project_management.tasks import TestTask\nresult = TestTask.apply_async(args=[5, 5], kwargs={}, countdown=10)#immediately outputs \"running TestTask\"\nresult.result -> immediately returns 10\nresult.ready() -> immediately returns True\n```\n\n```text\nRABBITMQ_NODE_PORT=5672 rabbitmq-server\npython manage.py celeryd --loglevel=info\n```\n\n```text\n>>> from project_management.tasks import add\n>>> from datetime import timedelta, datetime\n>>> eta = datetime.now() + timedelta(seconds=60)\n>>> result = add.apply_async(args=[5, 5], kwargs={}, eta=eta)\n>>> result.ready()\nTrue\n>>> eta = datetime.utcnow() + timedelta(seconds=60)\n>>> result = add.apply_async(args=[5, 5], kwargs={}, eta=eta)\n>>> result.ready()\nTrue\n```\n\n```text\nCELERY_ALWAYS_EAGER\n```\n\n========================================\n\nComments:\n- Have you tried to get the value also using `result.get()`? does it returns the value immediately?\n- Yes, immediately. Just verified it once more.","metadata":{"transformedAt":"2026-08-18T18:33:20.328Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":113,"estimatedTokens":826}}1141{"id":"stack-50485141","source":"stackoverflow","questionId":50485141,"title":"First message to RabbitMQ queue causes channel shutdown","tags":["rabbitmq","spring-rabbit"],"text":"Title: First message to RabbitMQ queue causes channel shutdown\nTags: rabbitmq, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nThe first message to my queue always fails.\nFrom the second one, **everything works just fine!**\n\nhttps://i.sstatic.net/3V2xE.png\n\nNot sure if that's readable so :\n\n```\nCreated new connection: rabbitConnectionFactory#1b940034:0/SimpleConnection@2c52fbff [delegate=amqp://guest@10.0.0.10:5672/, localPort= 36370]\n\nChannel shutdown: channel error; protocol method: #method(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'auto_delete' for exchange 'rabbitmq_exchange' in vhost '/': received 'false' but current is 'true', class-id=40, method-id=10)\n```\n\nI'm not sure why this is happening, because I launch this on a fresh VM (AWS EC2 instance) every single time. How could \"current be true\"?\n\nI suppose something is badly configured in the Spring Boot publisher:\n\nhttps://i.sstatic.net/yIWFS.png\n\nNot sure if that's readable so :\n\n```\n@Configuration\npublic class RabbitMqConfig {\n @Bean\n Queue queue() {\n return new Queue(System.getenv(\"RABBITMQ_QUEUE_NAME\"), true,false, false);\n }\n\n @Bean\n DirectExchange exchange() {\n return new DirectExchange(System.getenv(\"RABBITMQ_EXCHANGE_NAME\"), true, false);\n }\n\n @Bean\n Binding binding(Queue queue, DirectExchange exchange) {\n return BindingBuilder.bind(queue).to(exchange).with(System.getenv(\"RABBITMQ_ROUTING_KEY\"));\n }\n\n @Bean\n public MessageConverter jsonMessageConverter(){\n return new Jackson2JsonMessageConverter();\n }\n\n public AmqpTemplate rabbitTemplate(ConnectionFactory connectionFactory) {\n final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);\n rabbitTemplate.setMessageConverter(jsonMessageConverter());\n return rabbitTemplate;\n }\n}\n```\n\nSo what's going wrong here?\nThanks!\n\n========================================\n\nTop Answer:\nDefine a queue as below.\n\n```\ndeclare queue name=YourQueName durable=false --vhost=\"YourVirtualHostName\" -u UsernameOfYourQueue -p PasswordOfYourQueue\n```\n\n========================================\n\nCode:\n```text\nCreated new connection: rabbitConnectionFactory#1b940034:0/SimpleConnection@2c52fbff [delegate=amqp://guest@10.0.0.10:5672/, localPort= 36370]\n\nChannel shutdown: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'auto_delete' for exchange 'rabbitmq_exchange' in vhost '/': received 'false' but current is 'true', class-id=40, method-id=10)\n```\n\n```text\n@Configuration\npublic class RabbitMqConfig {\n @Bean\n Queue queue() {\n return new Queue(System.getenv(\"RABBITMQ_QUEUE_NAME\"), true,false, false);\n }\n\n @Bean\n DirectExchange exchange() {\n return new DirectExchange(System.getenv(\"RABBITMQ_EXCHANGE_NAME\"), true, false);\n }\n\n @Bean\n Binding binding(Queue queue, DirectExchange exchange) {\n return BindingBuilder.bind(queue).to(exchange).with(System.getenv(\"RABBITMQ_ROUTING_KEY\"));\n }\n\n @Bean\n public MessageConverter jsonMessageConverter(){\n return new Jackson2JsonMessageConverter();\n }\n\n public AmqpTemplate rabbitTemplate(ConnectionFactory connectionFactory) {\n final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);\n rabbitTemplate.setMessageConverter(jsonMessageConverter());\n return rabbitTemplate;\n }\n}\n```\n\n```text\n@Bean\nQueue queue() {\n return new Queue(System.getenv(\"RABBITMQ_QUEUE_NAME\"), true, false, false);\n}\n```\n\n```text\n@Bean\nQueue queue() {\n return new Queue(System.getenv(\"RABBITMQ_QUEUE_NAME\"), true, false, true);\n}\n```\n\n```text\ndeclare queue name=YourQueName durable=false --vhost=\"YourVirtualHostName\" -u UsernameOfYourQueue -p PasswordOfYourQueue\n```\n\n```text\napplication.properties\n```\n\n```text\nspring.rabbitmq.virtual-host=<correct-vhost>\n```\n\n========================================\n\nComments:\n- Yes my knowledge of RabbitMQ is quite limited. Explicitly setting the autoDelete and durable option on my Apache Camel consuming route did it for me, thank you!","metadata":{"transformedAt":"2026-08-18T18:33:20.328Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":139,"estimatedTokens":1010}}1142{"id":"stack-30103029","source":"stackoverflow","questionId":30103029,"title":"Django Celery Directory Structure and Layout","tags":["python","django","rabbitmq","celery","django-celery"],"text":"Title: Django Celery Directory Structure and Layout\nTags: python, django, rabbitmq, celery, django-celery\nSource: Stack Overflow\n\nQuestion:\nI have a django project using the following directory structure.\n\n```\nproject/\n account/\n models.py\n views.py \n blog/\n models.py\n views.py\n mediakit/\n models.py\n views.py\n reports/\n celery.py Here's the contents of celery.py derived from the celery tutorial (http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html).\n\n```\nfrom __future__ import absolute_import\n\nimport os\n\nfrom celery import Celery\n\n# set the default Django settings module for the 'celery' program.\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')\n\nfrom django.conf import settings\n\n# app = Celery('reports')\napp = Celery('reports',\n backend='djcelery.backends.database:DatabaseBackend',\n broker='amqp://guest:guest@localhost:5672//')\n\n# Using a string here means the worker will not have to\n# pickle the object when using Windows.\napp.config_from_object('django.conf:settings')\napp.autodiscover_tasks(lambda: settings.INSTALLED_APPS)\n\n@app.task(bind=True)\ndef debug_task(self):\n print('Request: {0!r}'.format(self.request))\n```\n\nSome of my apps are shared across projects. reports, for example might be used in 4 different projects, so \nI can see how tasks.py should live in the reports app so when it's added to a new project the \ntasks come along. What I don't quite understand is why celery.py needs to live within the reports app\ntoo. When I go to add some tasks to the account app, I'm basically building the same celery.py file\nreplacing 'reports' with 'account'. Shouldn't I have one celery file that lives at the same level\nas manage.py? Any help or suggestions would be greatly appreciated.\n\n========================================\n\nTop Answer:\nYou only need one celery file. It is recommended that you place it in the main project directory, or where your settings are, as long as the `__init__` file is in the same folder and has the required calls.\n\n========================================\n\nCode:\n```text\nproject/\n account/\n models.py\n views.py \n blog/\n models.py\n views.py\n mediakit/\n models.py\n views.py\n reports/\n celery.py <-- new\n models.py\n tasks.py <-- new\n views.py\n settings/\n __init__.py <-- project settings file\n system/\n cron/\n mongodb/\n redis/\n manage.py\n```\n\n```text\nfrom __future__ import absolute_import\n\nimport os\n\nfrom celery import Celery\n\n# set the default Django settings module for the 'celery' program.\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')\n\nfrom django.conf import settings\n\n# app = Celery('reports')\napp = Celery('reports',\n backend='djcelery.backends.database:DatabaseBackend',\n broker='amqp://guest:guest@localhost:5672//')\n\n# Using a string here means the worker will not have to\n# pickle the object when using Windows.\napp.config_from_object('django.conf:settings')\napp.autodiscover_tasks(lambda: settings.INSTALLED_APPS)\n\n\n@app.task(bind=True)\ndef debug_task(self):\n print('Request: {0!r}'.format(self.request))\n```\n\n```text\nproject/\n project/\n settings.py\n celery.py <- new, shown in the docs, also add __init__.py\n urls.py\n account/\n models.py\n views.py \n blog/\n models.py\n views.py\n mediakit/\n models.py\n tasks.py <-- tasks for the me\n views.py\n reports/\n models.py\n tasks.py <-- tasks for the reports app\n views.py\n manage.py\n```\n\n```text\nfrom celery import shared_task\n\n@shared_task\ndef my_add_task(a, b):\n return a + b\n```\n\n```text\nshared_task\n```\n\n```text\napp.task\n```\n\n```text\n__init__\n```\n\n========================================\n\nComments:\n- Accepted @qwattash answer because it got me where I was going. But is this really the standard? I have system and settings \"apps\" for each project, does celery.py belong in one of those? Seems like it's just a matter of preference, but if there's a definitive standard I'd like to it.\n- Could you expand on this? I tried adding it to /project/__init__.py but ended up with all sorts of import errors. The celery tutorial says to put it at /projects/reports/__init__.py (docs.celeryproject.org/en/latest/django/…)\n- It's likely an issue with your directory structure, because I'm using it that way across multiple apps, with celery.py in my 'core' app which also contains my settings. Where are your manage.py/settings files?\n- Updated post. My settings are in /settings/__init__.py\n- Also note you're putting celery.py in the 2nd level project folder and calling it like this \"celery -A project worker -l info\" where project refers to that 2nd level folder.","metadata":{"transformedAt":"2026-08-18T18:33:20.328Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":7,"totalLines":167,"estimatedTokens":1176}}1143{"id":"stack-27416319","source":"stackoverflow","questionId":27416319,"title":"Connect to RabbitMQ on EC2 from external client","tags":["amazon-ec2","rabbitmq","java-client"],"text":"Title: Connect to RabbitMQ on EC2 from external client\nTags: amazon-ec2, rabbitmq, java-client\nSource: Stack Overflow\n\nQuestion:\nSimilar questions have been asked \nRabbitMQ on Amazon EC2 Instance & Locally?\nand\ncant connect from my desktop to rabbitmq on ec2\nBut they get different error messages. \n\nI have a RabbitMQ server running on my linux EC2 instance which is set up correctly. I have created custom users and given them permissions to read/write to queues. Using a local client I am able to correctly receive messages. I have set up the security groups on EC2 so that ports (5672/25672) are open and can telnet to those ports. I also have set up rabbitmq.conf like this.\n\n```\n[\n {rabbit, [\n {tcp_listeners, [{\"0.0.0.0\",5672}]},\n {loopback_users, []},\n {log_levels, [{connection, info}]}\n ]\n }\n].\n```\n\nAt the moment I have a client on the server publishing to the queue.\n\nI have another client running on a server outside of EC2 which needs to consume data from the same queue (I can't run both on EC2 as the consume does a lot of plotting/graphical manipulation). \n\nWhen I try to connect however from the external client using some test code \n\n```\ntry {\n ConnectionFactory factory = new ConnectionFactory();\n factory.setUri(\"amqp://****:****@****:5672/\");\n connection = factory.newConnection();\n} catch (IOException e) {\n e.printStackTrace();\n```\n\n}\n\nI get the following error.\n\n com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED -\n Login was refused using authentication mechanism PLAIN. For details\n see the broker logfile.\n\nHowever there is nothing in the broker logfile as if I never tried to connect.\nI've tried connecting using the individual getter/setter methods of factory, I've tried using different ports (along with opening them up).\n\nI was wondering if I need to use SSL or not to connect to EC2 but from reading around the web it seems like it should just work but I'm not exactly sure. I cannot find any examples of people successfully achieving what I'm trying to do and documenting it.\n\nThanks in advance\n\n========================================\n\nCode:\n```text\n[\n {rabbit, [\n {tcp_listeners, [{\"0.0.0.0\",5672}]},\n {loopback_users, []},\n {log_levels, [{connection, info}]}\n ]\n }\n].\n```\n\n```text\ntry {\n ConnectionFactory factory = new ConnectionFactory();\n factory.setUri(\"amqp://****:****@****:5672/\");\n connection = factory.newConnection();\n} catch (IOException e) {\n e.printStackTrace();\n```\n\n========================================\n\nComments:\n- your rabbitmq.config works for me thx\n- If I run Flask directly I can connect to RabbitMQ, but If I run Apache2 I can't connect to RabbitMq","metadata":{"transformedAt":"2026-08-18T18:33:20.328Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":82,"estimatedTokens":673}}1144{"id":"stack-23090526","source":"stackoverflow","questionId":23090526,"title":"Where can i find the php-amqp documentation?","tags":["php","rabbitmq","amqp"],"text":"Title: Where can i find the php-amqp documentation?\nTags: php, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nWe are planning to use RabbitMQ from PHP, and we decided to go with php-amqp, because it supports PHP 5.2. The only problem is i can't find a proper documentation for this PECL library\n\n========================================\n\nTop Answer:\nThe official RabbitMQ site hosts a great tutorial, but unfortunately the included code examples are using the php-amqplib library, which is a pure PHP implementation of a RabbitMQ client.\n\nFortunately, the same examples are available for a variety of languages and libraries on the rabbitmq-tutorials GitHub repository, even included php-amqp, the PECL extension mentioned in the above question.\n\n========================================\n\nCode:\n```text\nphp-amqp\n```\n\n========================================\n\nComments:\n- Define \"proper documentation?\" For what exactly are you looking?\n- API documentation and examples\n- Yes, this is it. But it is outdated (github.com/pdezwart/php-amqp/issues/17), so read stubs too.\n- @zaq178miami I have used methods for sending and receiving messages. It is working on terminal properly. but When I try to run on web browser receiving code does not response it continuously waits.","metadata":{"transformedAt":"2026-08-18T18:33:20.328Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":1,"totalLines":28,"estimatedTokens":318}}1145{"id":"stack-26160938","source":"stackoverflow","questionId":26160938,"title":"Django celery always returns false when checking if data is ready","tags":["python","django","rabbitmq","celery"],"text":"Title: Django celery always returns false when checking if data is ready\nTags: python, django, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\nI have setup Django with Celery running with rabbitmq.\n\nI have implemented following example in my project: http://docs.celeryproject.org/en/master/django/first-steps-with-django.html\n\nWhen i run a simple test in two terminal windows the results are as following:\n\n```\n# Terminal 1\n>>> from Exercise.tasks import *\n>>> result = add.delay(2,3)\n>>> result\n\n>>> result.ready()\nFalse\n\n# Terminal 2\n$ celery -A Website3 worker -l info\n[2014-10-02 14:39:59,269: INFO/MainProcess] Received task: Exercise.tasks.add[464249dd-ab89-4099-badd-9190a147310f]\n[2014-10-02 14:39:59,271: INFO/MainProcess] Task Exercise.tasks.add[464249dd-ab89-4099-badd-9190a147310f] succeeded in 0.0010875929147s: 5\n```\n\nObviously the data is completed, but i am not able to receive this data.\n\nWhat am i doing wrong here?\n\n========================================\n\nCode:\n```text\n# Terminal 1\n>>> from Exercise.tasks import *\n>>> result = add.delay(2,3)\n>>> result\n<AsyncResult: e6c92297-eea2-4f99-8902-1446ac74a6bb>\n>>> result.ready()\nFalse\n\n# Terminal 2\n$ celery -A Website3 worker -l info\n[2014-10-02 14:39:59,269: INFO/MainProcess] Received task: Exercise.tasks.add[464249dd-ab89-4099-badd-9190a147310f]\n[2014-10-02 14:39:59,271: INFO/MainProcess] Task Exercise.tasks.add[464249dd-ab89-4099-badd-9190a147310f] succeeded in 0.0010875929147s: 5\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.328Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":47,"estimatedTokens":367}}1146{"id":"stack-23566170","source":"stackoverflow","questionId":23566170,"title":"rabbitMQ clustering VS federation VS shovel","tags":["rabbitmq","load-balancing","federation"],"text":"Title: rabbitMQ clustering VS federation VS shovel\nTags: rabbitmq, load-balancing, federation\nSource: Stack Overflow\n\nQuestion:\nI am setting up something like \"rabbitMQ cluster\" on machines in different locations, which is not good with RabbitMQ Clustering (since it is required to work with machines in a single location);\n\nso I am looking at rabbitMQ Federation, but it is a directed network of nodes, if the first node is down, could it automatically move on to write to the next node?\n\nMy goal is able to have logs/data still flow through even tho some nodes are down, with machines in different locations\n\n(\ncan we use rabbitMQ Federation, to make it go both direction?\nFor example, we have node1 and node2, and set node1 is both upstream and downstream of node2, node2 is also both upstream and downstream of node1. So this is just like a cluster, but can work with machines in different locations\n)\n\n========================================\n\nCode:\n```text\n[ \"amqp://fred:secret@host1.domain/my_vhost\"\n , \"amqp://john:secret@host2.domain/my_vhost\"\n]\n```\n\n```text\nmax_hops=1\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.328Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":28,"estimatedTokens":271}}1147{"id":"stack-25496882","source":"stackoverflow","questionId":25496882,"title":"Why is rabbitmq keep logging unknown delivery tag 'basic.ack'?","tags":["java","rabbitmq"],"text":"Title: Why is rabbitmq keep logging unknown delivery tag 'basic.ack'?\nTags: java, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nRabbitMQ keep logging\n\n```\n=ERROR REPORT==== 24-Aug-2014::06:25:07 ===\nconnection , channel 1 - soft error:\n{amqp_error,precondition_failed,\"unknown delivery tag 1\",'basic.ack'}\n```\n\nthe log file is quite large.\n\n========================================\n\nTop Answer:\nIn my case, my consumer had `autoAck` enabled and was also manually acknowledging the message after processing. The manual acknowledgment threw the same error you're encountering.\n\nOnce I removed the manual acknowledgment, I did not see the error again.\n\nTo add to @pinepain 's answer, double acknowledgements throw an exception and close the channel per these relavant RabbitMQ docs:\n\n```\nWhen manual acknowledgements are used, it is important to consider what thread does the acknowledgement. If it's different from the thread that received the delivery (e.g. Consumer#handleDelivery delegated delivery handling to a different thread), acknowledging with the multiple parameter set to true is unsafe and will result in double-acknowledgements, and therefore a channel-level protocol exception that closes the channel. Acknowledging a single message at a time can be safe.\n```\n\n========================================\n\nCode:\n```text\n=ERROR REPORT==== 24-Aug-2014::06:25:07 ===\nconnection <0.109.6880>, channel 1 - soft error:\n{amqp_error,precondition_failed,\"unknown delivery tag 1\",'basic.ack'}\n```\n\n```text\nWhen manual acknowledgements are used, it is important to consider what thread does the acknowledgement. If it's different from the thread that received the delivery (e.g. Consumer#handleDelivery delegated delivery handling to a different thread), acknowledging with the multiple parameter set to true is unsafe and will result in double-acknowledgements, and therefore a channel-level protocol exception that closes the channel. Acknowledging a single message at a time can be safe.\n```\n\n```text\nautoAck\n```\n\n========================================\n\nComments:\n- Adding to the answer, a common problem is the application accessing the channel from a different thread.\n- Its Due to ack error,sending wrong acknowledge then this error occur.","metadata":{"transformedAt":"2026-08-18T18:33:20.328Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":50,"estimatedTokens":561}}1148{"id":"stack-21920919","source":"stackoverflow","questionId":21920919,"title":"Celery timeout exception on Amazon Elastic Beanstalk using RabbitMQ","tags":["django","amazon-web-services","rabbitmq","celery","amazon-elastic-beanstalk"],"text":"Title: Celery timeout exception on Amazon Elastic Beanstalk using RabbitMQ\nTags: django, amazon-web-services, rabbitmq, celery, amazon-elastic-beanstalk\nSource: Stack Overflow\n\nQuestion:\nI'm trying to use Celery on my Beanstalk environment (this is the final piece in order to complete the technology stack of my project :P).\nThis is what I've done so far:\n\n- Since, RabbitMQ is the best broker for Celery and Amazon does not provide a dedicated service I created a custom AMI based on Ubuntu 13 64bit\n\n- installed RabbitMQ\n\n- removed the default user guest/guest\n\n- created a custom user\n\n- created a custom virtual host\n\n- installed admin plugins\n\n- tested my configuration using the http API in order to confirm that my RabbitMQ server is up and running.\n\nSo far so good! Then in my beanstalk **.config** file I added a couple of commands for celery:\n\n```\n04_celery_periodic_tasks:\n command: \"celery worker --app=com.cygora --loglevel=info --beat --autoreload -n period_tasks_worker.%h\"\n leader_only: true\n05_celery_standard_worker:\n command: \"celery worker --app=com.cygora --loglevel=info --autoreload -n worker_1.%h\"\n```\n\nOnce I deployed my app, I didn't find any error related to celery (so I'm assuming it's all ok, from \"the Python/Django side\")... but as soon as I use a feature of my site that requires sending a message to Rabbit via Celery I get a timeout exception:\n\n```\n[Thu Feb 20 22:01:24 2014] [error] File \"/opt/python/run/venv/lib/python2.7/site-packages/kombu/transport/pyamqp.py\", line 111, in establish_connection\n[Thu Feb 20 22:01:24 2014] [error] conn = self.Connection(**opts)\n[Thu Feb 20 22:01:24 2014] [error] File \"/opt/python/run/venv/lib/python2.7/site-packages/amqp/connection.py\", line 165, in __init__\n[Thu Feb 20 22:01:24 2014] [error] self.transport = create_transport(host, connect_timeout, ssl)\n[Thu Feb 20 22:01:24 2014] [error] File \"/opt/python/run/venv/lib/python2.7/site-packages/amqp/transport.py\", line 274, in create_transport\n[Thu Feb 20 22:01:24 2014] [error] return TCPTransport(host, connect_timeout)\n[Thu Feb 20 22:01:24 2014] [error] File \"/opt/python/run/venv/lib/python2.7/site-packages/amqp/transport.py\", line 89, in __init__\n[Thu Feb 20 22:01:24 2014] [error] raise socket.error(last_err)\n[Thu Feb 20 22:01:24 2014] [error] error: timed out\n```\n\nI specified the broker url in settings as:\n\n```\nBROKER_URL = \"amqp://myuser:mypassword@myelasticip:5672/myvirtualhost\"\n```\n\nWhat I'm missing or what I did wrong? Why the socket connection can't be established?\n\n========================================\n\nCode:\n```text\n04_celery_periodic_tasks:\n command: \"celery worker --app=com.cygora --loglevel=info --beat --autoreload -n period_tasks_worker.%h\"\n leader_only: true\n05_celery_standard_worker:\n command: \"celery worker --app=com.cygora --loglevel=info --autoreload -n worker_1.%h\"\n```\n\n```text\n[Thu Feb 20 22:01:24 2014] [error] File \"/opt/python/run/venv/lib/python2.7/site-packages/kombu/transport/pyamqp.py\", line 111, in establish_connection\n[Thu Feb 20 22:01:24 2014] [error] conn = self.Connection(**opts)\n[Thu Feb 20 22:01:24 2014] [error] File \"/opt/python/run/venv/lib/python2.7/site-packages/amqp/connection.py\", line 165, in __init__\n[Thu Feb 20 22:01:24 2014] [error] self.transport = create_transport(host, connect_timeout, ssl)\n[Thu Feb 20 22:01:24 2014] [error] File \"/opt/python/run/venv/lib/python2.7/site-packages/amqp/transport.py\", line 274, in create_transport\n[Thu Feb 20 22:01:24 2014] [error] return TCPTransport(host, connect_timeout)\n[Thu Feb 20 22:01:24 2014] [error] File \"/opt/python/run/venv/lib/python2.7/site-packages/amqp/transport.py\", line 89, in __init__\n[Thu Feb 20 22:01:24 2014] [error] raise socket.error(last_err)\n[Thu Feb 20 22:01:24 2014] [error] error: timed out\n```\n\n```text\nBROKER_URL = \"amqp://myuser:mypassword@myelasticip:5672/myvirtualhost\"\n```\n\n========================================\n\nComments:\n- Could you maybe your solution for running celery as a daemon? I am curious to see how you set it up. I came up with a solution, as I described in the following answer and would be interested to compare to what you did stackoverflow.com/questions/14761468/…\n- I'm curious too, and I would like to have a little discussion with you... can I have your email? (my is: davidezanotti (at) gmail.com)\n- Ditto, would also like to hear details on daemonizing celery in EB.","metadata":{"transformedAt":"2026-08-18T18:33:20.328Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":87,"estimatedTokens":1101}}1149{"id":"stack-27692786","source":"stackoverflow","questionId":27692786,"title":"RabbitMQ SSL handshake failure on any connection attempt with certificate authentication","tags":["java","ssl","rabbitmq"],"text":"Title: RabbitMQ SSL handshake failure on any connection attempt with certificate authentication\nTags: java, ssl, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI'm currently trying to migrate some Java components at to have RabbitMQ connection authentication be performed through SSL client certificates instead of the PLAIN method but, after several days, am still struggling with it as all java component connection attempts are met with handshake errors.\nLooking into RabbitMQ: handshake error when attempting to use SSL certificates or RabbitMQ SSL giving handshake failure when using SpringAMQP has unfortunately not wielded any results for me.\n\nThe environment I'm trying to make this work is an \"inherited\" VirtualBox VM running Ubuntu LTS 14.04 that represents pretty much the environment I want to deploy to.\n\nThe output of *rabbitmqctl report* is as follows:\n\n```\nStatus of node 'rabbit@developer-VirtualBox' ...\n[{pid,23352},\n {running_applications,\n [{rabbitmq_management,\"RabbitMQ Management Console\",\"3.4.2\"},\n {rabbitmq_web_dispatch,\"RabbitMQ Web Dispatcher\",\"3.4.2\"},\n {webmachine,\"webmachine\",\"1.10.3-rmq3.4.2-gite9359c7\"},\n {mochiweb,\"MochiMedia Web Server\",\"2.7.0-rmq3.4.2-git680dba8\"},\n {rabbitmq_management_agent,\"RabbitMQ Management Agent\",\"3.4.2\"},\n {rabbit,\"RabbitMQ\",\"3.4.2\"},\n {ssl,\"Erlang/OTP SSL application\",\"5.3.2\"},\n {public_key,\"Public key infrastructure\",\"0.21\"},\n {crypto,\"CRYPTO version 2\",\"3.2\"},\n {asn1,\"The Erlang ASN1 compiler version 2.0.4\",\"2.0.4\"},\n {os_mon,\"CPO CXC 138 46\",\"2.2.14\"},\n {inets,\"INETS CXC 138 49\",\"5.9.7\"},\n {rabbitmq_auth_mechanism_ssl,\n \"RabbitMQ SSL authentication (SASL EXTERNAL)\",\"3.4.2\"},\n {amqp_client,\"RabbitMQ AMQP Client\",\"3.4.2\"},\n {xmerl,\"XML parser\",\"1.3.5\"},\n {mnesia,\"MNESIA CXC 138 12\",\"4.11\"},\n {sasl,\"SASL CXC 138 11\",\"2.3.4\"},\n {stdlib,\"ERTS CXC 138 10\",\"1.19.4\"},\n {kernel,\"ERTS CXC 138 10\",\"2.16.4\"}]},\n {os,{unix,linux}},\n {erlang_version,\n \"Erlang R16B03 (erts-5.10.4) [source] [64-bit] [async-threads:30] [kernel-poll:true]\\n\"},\n {memory,\n [{total,42662672},\n {connection_readers,0},\n {connection_writers,0},\n {connection_channels,0},\n {connection_other,5264},\n {queue_procs,2632},\n {queue_slave_procs,0},\n {plugins,411368},\n {other_proc,14374616},\n {mnesia,59360},\n {mgmt_db,124224},\n {msg_index,34312},\n {other_ets,1135040},\n {binary,42680},\n {code,21795549},\n {atom,793505},\n {other_system,3884122}]},\n {alarms,[]},\n {listeners,[{clustering,25672,\"::\"},{amqp,5672,\"::\"},{'amqp/ssl',5671,\"::\"}]},\n {vm_memory_high_watermark,0.4},\n {vm_memory_limit,1658211532},\n {disk_free_limit,50000000},\n {disk_free,43703377920},\n {file_descriptors,\n [{total_limit,924},{total_used,4},{sockets_limit,829},{sockets_used,2}]},\n {processes,[{limit,1048576},{used,191}]},\n {run_queue,0},\n {uptime,12}]\n\nCluster status of node 'rabbit@developer-VirtualBox' ...\n[{nodes,[{disc,['rabbit@developer-VirtualBox']}]},\n {running_nodes,['rabbit@developer-VirtualBox']},\n {cluster_name,>},\n {partitions,[]}]\n\nApplication environment of node 'rabbit@developer-VirtualBox' ...\n[{amqp_client,[{prefer_ipv6,false},{ssl_options,[]}]},\n {asn1,[]},\n {crypto,[]},\n {inets,[]},\n {kernel,\n [{error_logger,tty},\n {inet_default_connect_options,[{nodelay,true}]},\n {inet_dist_listen_max,25672},\n {inet_dist_listen_min,25672}]},\n {mnesia,[{dir,\"/var/lib/rabbitmq/mnesia/rabbit@developer-VirtualBox\"}]},\n {mochiweb,[]},\n {os_mon,\n [{start_cpu_sup,false},\n {start_disksup,false},\n {start_memsup,false},\n {start_os_sup,false}]},\n {public_key,[]},\n {rabbit,\n [{auth_backends,[rabbit_auth_backend_internal]},\n {auth_mechanisms,['EXTERNAL']},\n {backing_queue_module,rabbit_variable_queue},\n {channel_max,0},\n {cluster_keepalive_interval,10000},\n {cluster_nodes,{[],disc}},\n {cluster_partition_handling,ignore},\n {collect_statistics,fine},\n {collect_statistics_interval,5000},\n {default_permissions,[>,>,>]},\n {default_user,>},\n {default_user_tags,[administrator]},\n {default_vhost,>},\n {delegate_count,16},\n {disk_free_limit,50000000},\n {enabled_plugins_file,\"/etc/rabbitmq/enabled_plugins\"},\n {error_logger,\n {file,\"/var/log/rabbitmq/rabbit@developer-VirtualBox.log\"}},\n {frame_max,131072},\n {halt_on_upgrade_failure,true},\n {handshake_timeout,10000},\n {heartbeat,580},\n {hipe_compile,false},\n {hipe_modules,\n [rabbit_reader,rabbit_channel,gen_server2,rabbit_exchange,\n rabbit_command_assembler,rabbit_framing_amqp_0_9_1,rabbit_basic,\n rabbit_event,lists,queue,priority_queue,rabbit_router,rabbit_trace,\n rabbit_misc,rabbit_binary_parser,rabbit_exchange_type_direct,\n rabbit_guid,rabbit_net,rabbit_amqqueue_process,\n rabbit_variable_queue,rabbit_binary_generator,rabbit_writer,\n delegate,gb_sets,lqueue,sets,orddict,rabbit_amqqueue,\n rabbit_limiter,gb_trees,rabbit_queue_index,\n rabbit_exchange_decorator,gen,dict,ordsets,file_handle_cache,\n rabbit_msg_store,array,rabbit_msg_store_ets_index,rabbit_msg_file,\n rabbit_exchange_type_fanout,rabbit_exchange_type_topic,mnesia,\n mnesia_lib,rpc,mnesia_tm,qlc,sofs,proplists,credit_flow,pmon,\n ssl_connection,tls_connection,ssl_record,tls_record,gen_fsm,ssl]},\n {log_levels,[{connection,info}]},\n {loopback_users,[>]},\n {mnesia_table_loading_timeout,30000},\n {msg_store_file_size_limit,16777216},\n {msg_store_index_module,rabbit_msg_store_ets_index},\n {plugins_dir,\n \"/usr/lib/rabbitmq/lib/rabbitmq_server-3.4.2/sbin/../plugins\"},\n {plugins_expand_dir,\n \"/var/lib/rabbitmq/mnesia/rabbit@developer-VirtualBox-plugins-expand\"},\n {queue_index_max_journal_entries,65536},\n {reverse_dns_lookups,false},\n {sasl_error_logger,\n {file,\"/var/log/rabbitmq/rabbit@developer-VirtualBox-sasl.log\"}},\n {server_properties,[]},\n {ssl_allow_poodle_attack,false},\n {ssl_apps,[asn1,crypto,public_key,ssl]},\n {ssl_cert_login_from,distinguished_name},\n {ssl_handshake_timeout,5000},\n {ssl_listeners,[5671]},\n {ssl_options,\n [{cacertfile,\"/home/developer/rabbitmqcert/devcafiles/cacert.pem\"},\n {certfile,\"/home/developer/rabbitmqcert/rabbitmq.public.pem\"},\n {keyfile,\"/home/developer/rabbitmqcert/rabbitmq.private.pem\"},\n {verify,verify_peer},\n {ssl_cert_login_from,organization},\n {fail_if_no_peer_cert,true}]},\n {tcp_listen_options,\n [binary,\n {packet,raw},\n {reuseaddr,true},\n {backlog,128},\n {nodelay,true},\n {linger,{true,0}},\n {exit_on_close,false}]},\n {tcp_listeners,[5672]},\n {trace_vhosts,[]},\n {vm_memory_high_watermark,0.4},\n {vm_memory_high_watermark_paging_ratio,0.5}]},\n {rabbitmq_auth_mechanism_ssl,[{name_from,distinguished_name}]},\n {rabbitmq_management,\n [{http_log_dir,none},\n {listener,[{port,15672}]},\n {load_definitions,none},\n {rates_mode,basic},\n {sample_retention_policies,\n [{global,[{605,5},{3660,60},{29400,600},{86400,1800}]},\n {basic,[{605,5},{3600,60}]},\n {detailed,[{10,5}]}]}]},\n {rabbitmq_management_agent,[]},\n {rabbitmq_web_dispatch,[]},\n {sasl,[{errlog_type,error},{sasl_error_logger,false}]},\n {ssl,\n [{protocol_version,['tlsv1.2','tlsv1.1',tlsv1,sslv3]},\n {versions,['tlsv1.2','tlsv1.1']}]},\n {stdlib,[]},\n {webmachine,[{error_handler,rabbit_webmachine_error_handler}]},\n {xmerl,[]}]\n\nConnections:\n\nChannels:\n\nQueues on /:\n\nExchanges on /:\nname type durable auto_delete internal arguments policy\n direct true false false [] \namq.direct direct true false false [] \namq.fanout fanout true false false [] \namq.headers headers true false false [] \namq.match headers true false false [] \namq.rabbitmq.log topic true false true [] \namq.rabbitmq.trace topic true false true [] \namq.topic topic true false false [] \n\nBindings on /:\n\nConsumers on /:\n\nPermissions on /:\nuser configure write read\nO=dev,CN=rules .* .* .*\nguest .* .* .*\n\nPolicies on /:\n\nParameters on /:\n```\n\nGoing through it I can see that:\n\n- The _rabbitmq_auth_mechanism_ssl_ plugin is active\n\n- I am listening for SSL connections on port 5671\n\n- The only accepted auth mechanism is EXTERNAL\n\n- I am only accepting TLS v1.1 and TLS v1.2\n\n- There is a user _O=dev,CN=rules_ defined, matching the subject in the client certificate. This user has no password associated (cleared it using _sudo rabbitmqctl clear_password \"O=dev,CN=rules\"_ and the management screen reflects that)\n\n- CA cert file is read from _/home/developer/rabbitmqcert/devcafiles/cacert.pem_. This corresponds to a CA created for dev purposes, with all public keys (server and client alike) used in this being signed by it\n\nFor simplicity (and sanity), I've tried connecting to the RabbitMQ instance using the following Java code:\n\n```\npackage com.rabbitmq.sample;\n\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.security.KeyManagementException;\nimport java.security.KeyStore;\nimport java.security.KeyStoreException;\nimport java.security.NoSuchAlgorithmException;\nimport java.security.UnrecoverableKeyException;\nimport java.security.cert.CertificateException;\nimport java.security.cert.X509Certificate;\n\nimport javax.net.ssl.KeyManager;\nimport javax.net.ssl.KeyManagerFactory;\nimport javax.net.ssl.SSLContext;\nimport javax.net.ssl.TrustManager;\nimport javax.net.ssl.X509TrustManager;\n\nimport com.rabbitmq.client.Channel;\nimport com.rabbitmq.client.Connection;\nimport com.rabbitmq.client.ConnectionFactory;\nimport com.rabbitmq.client.DefaultSaslConfig;\nimport com.rabbitmq.client.QueueingConsumer;\n\npublic class CertificateAuthenticatedRabbitMQClientExample {\n\n private static final String CLIENT_CERTIFICATE_PASSWORD = \"MySecretPassword\";\n private static final String QUEUE_USED = \"sampleQueue\";\n public static void main(String[] args) throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, IOException, CertificateException, KeyManagementException, InterruptedException {\n SSLContext sslContext = SSLContext.getInstance(\"TLSv1.2\");\n KeyManager[] clientKeyManagerList = null;\n try(FileInputStream clientCertificateInputStream = new FileInputStream(new File(\"/home/developer/rabbitmqcert/ruleprocessing.password.p12\"))) {\n KeyStore clientKeStore = KeyStore.getInstance(\"PKCS12\"); //Create a clean KeyStore\n clientKeStore.load(clientCertificateInputStream, CLIENT_CERTIFICATE_PASSWORD.toCharArray()); //Load the client's certificate into the keystore\n KeyManagerFactory clientSSLKeyManagerFactory = KeyManagerFactory.getInstance(\"SunX509\");\n clientSSLKeyManagerFactory.init(clientKeStore, CLIENT_CERTIFICATE_PASSWORD.toCharArray());\n clientKeyManagerList = clientSSLKeyManagerFactory.getKeyManagers(); //Get list of key managers (in essence, only the keystore with the client certificate)\n }\n TrustManager[] clientTrustManagerList = {\n new X509TrustManager() {\n //Dummy trust store that trusts any server you connect to.\n //For demo purposes only\n @Override\n public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {}\n @Override\n public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {}\n @Override\n public X509Certificate[] getAcceptedIssuers() { return null;}\n }\n };\n sslContext.init(clientKeyManagerList, clientTrustManagerList, null); //Initialize SSL context with the key and trust managers we've created/loaded before\n\n ConnectionFactory rabbitMqConnectionFactory = new ConnectionFactory(); //Create factory\n rabbitMqConnectionFactory.setHost(\"localhost\");\n rabbitMqConnectionFactory.setPort(5671);\n rabbitMqConnectionFactory.setSaslConfig(DefaultSaslConfig.EXTERNAL); //Set authentication method as SSL auth\n rabbitMqConnectionFactory.useSslProtocol(sslContext); //Set the created SSL context as the one to use\n Connection rabbitMqOutboundConnection = null;\n Channel rabbitMqOutboundChannel = null;\n try {\n rabbitMqOutboundConnection = rabbitMqConnectionFactory.newConnection();\n rabbitMqOutboundChannel = rabbitMqOutboundConnection.createChannel();\n rabbitMqOutboundChannel.queueDeclare(QUEUE_USED, false, false, false, null);\n rabbitMqOutboundChannel.basicPublish(\"\", QUEUE_USED, null, \"This is a sample message\".getBytes());\n System.out.println(\"Message successfully sent to queue\");\n }finally{\n if(rabbitMqOutboundChannel != null) {\n rabbitMqOutboundChannel.close();\n }\n if(rabbitMqOutboundConnection != null) {\n rabbitMqOutboundConnection.close();\n }\n }\n Connection rabbitMqInboundConnection = null;\n Channel rabbitMqInboundChannel = null;\n try {\n rabbitMqInboundConnection = rabbitMqConnectionFactory.newConnection();\n rabbitMqInboundChannel = rabbitMqInboundConnection.createChannel();\n rabbitMqInboundChannel.queueDeclare(QUEUE_USED, false, false, false, null);\n QueueingConsumer rabbitMqQueueConsumer = new QueueingConsumer(rabbitMqInboundChannel);\n rabbitMqInboundChannel.basicConsume(QUEUE_USED, true, rabbitMqQueueConsumer);\n QueueingConsumer.Delivery deliveryResult = rabbitMqQueueConsumer.nextDelivery();\n System.out.println(\"Message read from the queue: \" + new String(deliveryResult.getBody()));\n }finally{\n if(rabbitMqInboundChannel != null) {\n rabbitMqInboundChannel.close();\n }\n if(rabbitMqInboundConnection != null) {\n rabbitMqInboundConnection.close();\n }\n }\n }\n\n}\n```\n\nI am, however, always greeted with a *Exception in thread \"main\" java.net.SocketException: Broken pipe* error on execution and, looking at the RabbitMQ server log, I see:\n\n```\n=INFO REPORT==== 29-Dec-2014::15:55:30 ===\naccepting AMQP connection (127.0.0.1:35299 -> 127.0.0.1:5671)\n\n=ERROR REPORT==== 29-Dec-2014::15:55:30 ===\nSSL: certify: ssl_handshake.erl:1343:Fatal error: handshake failure\n```\n\nBased on what I've seen around the internet and here, I've tried changing the *verify* value to verify_none but, when doing do, I get the following instead:\n\n```\n=INFO REPORT==== 29-Dec-2014::14:51:13 ===\naccepting AMQP connection (127.0.0.1:35271 -> 127.0.0.1:5671)\n\n=ERROR REPORT==== 29-Dec-2014::14:51:17 ===\nclosing AMQP connection (127.0.0.1:35271 -> 127.0.0.1:5671):\n{handshake_error,starting,0,\n {amqp_error,access_refused,\n \"EXTERNAL login refused: no peer certificate\",\n 'connection.start_ok'}}\n```\n\nAs per the advice given under the SSL troubleshooting page, I have tried performing an s_client connection to the server with, once again, different results depending on the value of *verify*.\nIf *verify* is set to verify_peer, I get the following:\n\n```\ndeveloper@developer-VirtualBox:~/rabbitmqcert$ openssl s_client -tls1_2 -connect localhost:5671 -cert ruleprocessing.public.pem -key ruleprocessing.private.pem -CAfile devcafiles/cacert.pem \nCONNECTED(00000003)\ndepth=1 CN = RabbitMQCA\nverify return:1\ndepth=0 CN = rabbitmq, O = dev\nverify return:1\n139797055162016:error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure:s3_pkt.c:1260:SSL alert number 40\n139797055162016:error:1409E0E5:SSL routines:SSL3_WRITE_BYTES:ssl handshake failure:s3_pkt.c:596:\n---\nCertificate chain\n 0 s:/CN=rabbitmq/O=dev\n i:/CN=RabbitMQCA\n 1 s:/CN=RabbitMQCA\n i:/CN=RabbitMQCA\n---\nServer certificate\n-----BEGIN CERTIFICATE-----\n>\n-----END CERTIFICATE-----\nsubject=/CN=rabbitmq/O=dev\nissuer=/CN=RabbitMQCA\n---\nAcceptable client certificate CA names\n/CN=RabbitMQCA\n---\nSSL handshake has read 1646 bytes and written 2103 bytes\n---\nNew, TLSv1/SSLv3, Cipher is AES256-SHA256\nServer public key is 2048 bit\nSecure Renegotiation IS NOT supported\nCompression: NONE\nExpansion: NONE\nSSL-Session:\n Protocol : TLSv1.2\n Cipher : AES256-SHA256\n Session-ID: FC972B9A5D3EC359DC0467C8F02410E3AD66DA151C4411C0D5892115A439431A\n Session-ID-ctx: \n Master-Key: E4FE793C71692852F6F3C4E9C5CB17774D8A50511338EF2E75691DC0DC2119F56611FC959C12429BBAFD46EC760ED713\n Key-Arg : None\n PSK identity: None\n PSK identity hint: None\n SRP username: None\n Start Time: 1419871438\n Timeout : 7200 (sec)\n Verify return code: 0 (ok)\n---\n```\n\nAs you can see, a handshake error happens at the start but then seems to be recovered.\n\nIf *verify* is set to verify_none, I get the following:\n\n```\nCONNECTED(00000003)\ndepth=1 CN = RabbitMQCA\nverify return:1\ndepth=0 CN = rabbitmq, O = dev\nverify return:1\n---\nCertificate chain\n 0 s:/CN=rabbitmq/O=dev\n i:/CN=RabbitMQCA\n 1 s:/CN=RabbitMQCA\n i:/CN=RabbitMQCA\n---\nServer certificate\n-----BEGIN CERTIFICATE-----\n>\n-----END CERTIFICATE-----\nsubject=/CN=rabbitmq/O=dev\nissuer=/CN=RabbitMQCA\n---\nNo client certificate CA names sent\n---\nSSL handshake has read 1666 bytes and written 663 bytes\n---\nNew, TLSv1/SSLv3, Cipher is AES256-SHA256\nServer public key is 2048 bit\nSecure Renegotiation IS NOT supported\nCompression: NONE\nExpansion: NONE\nSSL-Session:\n Protocol : TLSv1.2\n Cipher : AES256-SHA256\n Session-ID: C4156551790BA116DC38A981728A71768D0B53AAEBEE969A4DA150746E5373FB\n Session-ID-ctx: \n Master-Key: 3470DD0C0247B94EA784C3CEF94888C160205E9F06C14869B564A00AF5E4F7FAF5B4FC977E290B80DBCD140133F75AC0\n Key-Arg : None\n PSK identity: None\n PSK identity hint: None\n SRP username: None\n Start Time: 1419871570\n Timeout : 7200 (sec)\n Verify return code: 0 (ok)\n---\n```\n\nThis time, the handshake error does not occur occur at the start. \n\nAs a side note, since I am not very sure about \"cleanliness\" of the VM I got, I've actually tried creating a new VM (same Ubuntu version), installed RabbitMQ (same version), configured it in pretty much the same way (the only thing changing was certificate locations) and ran the same client code (certificate path modified). The final result was a success. Unfortunately I cannot do much with regards to getting this VM to be used as the dev VM at this time.\n\n**TL;DR;** After configuring a RabbitMQ server running on an Ubuntu VM to accept SSL connections from a Java client using certificate authentication, all connection attempts fail with an *handshake failure* as reason if *verify*=verify_peer, or *EXTERNAL login refused: no peer certificate* if *verify*=verify_none\n\n========================================\n\nCode:\n```text\nStatus of node 'rabbit@developer-VirtualBox' ...\n[{pid,23352},\n {running_applications,\n [{rabbitmq_management,\"RabbitMQ Management Console\",\"3.4.2\"},\n {rabbitmq_web_dispatch,\"RabbitMQ Web Dispatcher\",\"3.4.2\"},\n {webmachine,\"webmachine\",\"1.10.3-rmq3.4.2-gite9359c7\"},\n {mochiweb,\"MochiMedia Web Server\",\"2.7.0-rmq3.4.2-git680dba8\"},\n {rabbitmq_management_agent,\"RabbitMQ Management Agent\",\"3.4.2\"},\n {rabbit,\"RabbitMQ\",\"3.4.2\"},\n {ssl,\"Erlang/OTP SSL application\",\"5.3.2\"},\n {public_key,\"Public key infrastructure\",\"0.21\"},\n {crypto,\"CRYPTO version 2\",\"3.2\"},\n {asn1,\"The Erlang ASN1 compiler version 2.0.4\",\"2.0.4\"},\n {os_mon,\"CPO CXC 138 46\",\"2.2.14\"},\n {inets,\"INETS CXC 138 49\",\"5.9.7\"},\n {rabbitmq_auth_mechanism_ssl,\n \"RabbitMQ SSL authentication (SASL EXTERNAL)\",\"3.4.2\"},\n {amqp_client,\"RabbitMQ AMQP Client\",\"3.4.2\"},\n {xmerl,\"XML parser\",\"1.3.5\"},\n {mnesia,\"MNESIA CXC 138 12\",\"4.11\"},\n {sasl,\"SASL CXC 138 11\",\"2.3.4\"},\n {stdlib,\"ERTS CXC 138 10\",\"1.19.4\"},\n {kernel,\"ERTS CXC 138 10\",\"2.16.4\"}]},\n {os,{unix,linux}},\n {erlang_version,\n \"Erlang R16B03 (erts-5.10.4) [source] [64-bit] [async-threads:30] [kernel-poll:true]\\n\"},\n {memory,\n [{total,42662672},\n {connection_readers,0},\n {connection_writers,0},\n {connection_channels,0},\n {connection_other,5264},\n {queue_procs,2632},\n {queue_slave_procs,0},\n {plugins,411368},\n {other_proc,14374616},\n {mnesia,59360},\n {mgmt_db,124224},\n {msg_index,34312},\n {other_ets,1135040},\n {binary,42680},\n {code,21795549},\n {atom,793505},\n {other_system,3884122}]},\n {alarms,[]},\n {listeners,[{clustering,25672,\"::\"},{amqp,5672,\"::\"},{'amqp/ssl',5671,\"::\"}]},\n {vm_memory_high_watermark,0.4},\n {vm_memory_limit,1658211532},\n {disk_free_limit,50000000},\n {disk_free,43703377920},\n {file_descriptors,\n [{total_limit,924},{total_used,4},{sockets_limit,829},{sockets_used,2}]},\n {processes,[{limit,1048576},{used,191}]},\n {run_queue,0},\n {uptime,12}]\n\nCluster status of node 'rabbit@developer-VirtualBox' ...\n[{nodes,[{disc,['rabbit@developer-VirtualBox']}]},\n {running_nodes,['rabbit@developer-VirtualBox']},\n {cluster_name,<<\"rabbit@developer-VirtualBox\">>},\n {partitions,[]}]\n\nApplication environment of node 'rabbit@developer-VirtualBox' ...\n[{amqp_client,[{prefer_ipv6,false},{ssl_options,[]}]},\n {asn1,[]},\n {crypto,[]},\n {inets,[]},\n {kernel,\n [{error_logger,tty},\n {inet_default_connect_options,[{nodelay,true}]},\n {inet_dist_listen_max,25672},\n {inet_dist_listen_min,25672}]},\n {mnesia,[{dir,\"/var/lib/rabbitmq/mnesia/rabbit@developer-VirtualBox\"}]},\n {mochiweb,[]},\n {os_mon,\n [{start_cpu_sup,false},\n {start_disksup,false},\n {start_memsup,false},\n {start_os_sup,false}]},\n {public_key,[]},\n {rabbit,\n [{auth_backends,[rabbit_auth_backend_internal]},\n {auth_mechanisms,['EXTERNAL']},\n {backing_queue_module,rabbit_variable_queue},\n {channel_max,0},\n {cluster_keepalive_interval,10000},\n {cluster_nodes,{[],disc}},\n {cluster_partition_handling,ignore},\n {collect_statistics,fine},\n {collect_statistics_interval,5000},\n {default_permissions,[<<\".*\">>,<<\".*\">>,<<\".*\">>]},\n {default_user,<<\"guest\">>},\n {default_user_tags,[administrator]},\n {default_vhost,<<\"/\">>},\n {delegate_count,16},\n {disk_free_limit,50000000},\n {enabled_plugins_file,\"/etc/rabbitmq/enabled_plugins\"},\n {error_logger,\n {file,\"/var/log/rabbitmq/rabbit@developer-VirtualBox.log\"}},\n {frame_max,131072},\n {halt_on_upgrade_failure,true},\n {handshake_timeout,10000},\n {heartbeat,580},\n {hipe_compile,false},\n {hipe_modules,\n [rabbit_reader,rabbit_channel,gen_server2,rabbit_exchange,\n rabbit_command_assembler,rabbit_framing_amqp_0_9_1,rabbit_basic,\n rabbit_event,lists,queue,priority_queue,rabbit_router,rabbit_trace,\n rabbit_misc,rabbit_binary_parser,rabbit_exchange_type_direct,\n rabbit_guid,rabbit_net,rabbit_amqqueue_process,\n rabbit_variable_queue,rabbit_binary_generator,rabbit_writer,\n delegate,gb_sets,lqueue,sets,orddict,rabbit_amqqueue,\n rabbit_limiter,gb_trees,rabbit_queue_index,\n rabbit_exchange_decorator,gen,dict,ordsets,file_handle_cache,\n rabbit_msg_store,array,rabbit_msg_store_ets_index,rabbit_msg_file,\n rabbit_exchange_type_fanout,rabbit_exchange_type_topic,mnesia,\n mnesia_lib,rpc,mnesia_tm,qlc,sofs,proplists,credit_flow,pmon,\n ssl_connection,tls_connection,ssl_record,tls_record,gen_fsm,ssl]},\n {log_levels,[{connection,info}]},\n {loopback_users,[<<\"guest\">>]},\n {mnesia_table_loading_timeout,30000},\n {msg_store_file_size_limit,16777216},\n {msg_store_index_module,rabbit_msg_store_ets_index},\n {plugins_dir,\n \"/usr/lib/rabbitmq/lib/rabbitmq_server-3.4.2/sbin/../plugins\"},\n {plugins_expand_dir,\n \"/var/lib/rabbitmq/mnesia/rabbit@developer-VirtualBox-plugins-expand\"},\n {queue_index_max_journal_entries,65536},\n {reverse_dns_lookups,false},\n {sasl_error_logger,\n {file,\"/var/log/rabbitmq/rabbit@developer-VirtualBox-sasl.log\"}},\n {server_properties,[]},\n {ssl_allow_poodle_attack,false},\n {ssl_apps,[asn1,crypto,public_key,ssl]},\n {ssl_cert_login_from,distinguished_name},\n {ssl_handshake_timeout,5000},\n {ssl_listeners,[5671]},\n {ssl_options,\n [{cacertfile,\"/home/developer/rabbitmqcert/devcafiles/cacert.pem\"},\n {certfile,\"/home/developer/rabbitmqcert/rabbitmq.public.pem\"},\n {keyfile,\"/home/developer/rabbitmqcert/rabbitmq.private.pem\"},\n {verify,verify_peer},\n {ssl_cert_login_from,organization},\n {fail_if_no_peer_cert,true}]},\n {tcp_listen_options,\n [binary,\n {packet,raw},\n {reuseaddr,true},\n {backlog,128},\n {nodelay,true},\n {linger,{true,0}},\n {exit_on_close,false}]},\n {tcp_listeners,[5672]},\n {trace_vhosts,[]},\n {vm_memory_high_watermark,0.4},\n {vm_memory_high_watermark_paging_ratio,0.5}]},\n {rabbitmq_auth_mechanism_ssl,[{name_from,distinguished_name}]},\n {rabbitmq_management,\n [{http_log_dir,none},\n {listener,[{port,15672}]},\n {load_definitions,none},\n {rates_mode,basic},\n {sample_retention_policies,\n [{global,[{605,5},{3660,60},{29400,600},{86400,1800}]},\n {basic,[{605,5},{3600,60}]},\n {detailed,[{10,5}]}]}]},\n {rabbitmq_management_agent,[]},\n {rabbitmq_web_dispatch,[]},\n {sasl,[{errlog_type,error},{sasl_error_logger,false}]},\n {ssl,\n [{protocol_version,['tlsv1.2','tlsv1.1',tlsv1,sslv3]},\n {versions,['tlsv1.2','tlsv1.1']}]},\n {stdlib,[]},\n {webmachine,[{error_handler,rabbit_webmachine_error_handler}]},\n {xmerl,[]}]\n\nConnections:\n\nChannels:\n\nQueues on /:\n\nExchanges on /:\nname type durable auto_delete internal arguments policy\n direct true false false [] \namq.direct direct true false false [] \namq.fanout fanout true false false [] \namq.headers headers true false false [] \namq.match headers true false false [] \namq.rabbitmq.log topic true false true [] \namq.rabbitmq.trace topic true false true [] \namq.topic topic true false false [] \n\nBindings on /:\n\nConsumers on /:\n\nPermissions on /:\nuser configure write read\nO=dev,CN=rules .* .* .*\nguest .* .* .*\n\nPolicies on /:\n\nParameters on /:\n```\n\n```text\npackage com.rabbitmq.sample;\n\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.security.KeyManagementException;\nimport java.security.KeyStore;\nimport java.security.KeyStoreException;\nimport java.security.NoSuchAlgorithmException;\nimport java.security.UnrecoverableKeyException;\nimport java.security.cert.CertificateException;\nimport java.security.cert.X509Certificate;\n\nimport javax.net.ssl.KeyManager;\nimport javax.net.ssl.KeyManagerFactory;\nimport javax.net.ssl.SSLContext;\nimport javax.net.ssl.TrustManager;\nimport javax.net.ssl.X509TrustManager;\n\nimport com.rabbitmq.client.Channel;\nimport com.rabbitmq.client.Connection;\nimport com.rabbitmq.client.ConnectionFactory;\nimport com.rabbitmq.client.DefaultSaslConfig;\nimport com.rabbitmq.client.QueueingConsumer;\n\npublic class CertificateAuthenticatedRabbitMQClientExample {\n\n private static final String CLIENT_CERTIFICATE_PASSWORD = \"MySecretPassword\";\n private static final String QUEUE_USED = \"sampleQueue\";\n public static void main(String[] args) throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, IOException, CertificateException, KeyManagementException, InterruptedException {\n SSLContext sslContext = SSLContext.getInstance(\"TLSv1.2\");\n KeyManager[] clientKeyManagerList = null;\n try(FileInputStream clientCertificateInputStream = new FileInputStream(new File(\"/home/developer/rabbitmqcert/ruleprocessing.password.p12\"))) {\n KeyStore clientKeStore = KeyStore.getInstance(\"PKCS12\"); //Create a clean KeyStore\n clientKeStore.load(clientCertificateInputStream, CLIENT_CERTIFICATE_PASSWORD.toCharArray()); //Load the client's certificate into the keystore\n KeyManagerFactory clientSSLKeyManagerFactory = KeyManagerFactory.getInstance(\"SunX509\");\n clientSSLKeyManagerFactory.init(clientKeStore, CLIENT_CERTIFICATE_PASSWORD.toCharArray());\n clientKeyManagerList = clientSSLKeyManagerFactory.getKeyManagers(); //Get list of key managers (in essence, only the keystore with the client certificate)\n }\n TrustManager[] clientTrustManagerList = {\n new X509TrustManager() {\n //Dummy trust store that trusts any server you connect to.\n //For demo purposes only\n @Override\n public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {}\n @Override\n public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {}\n @Override\n public X509Certificate[] getAcceptedIssuers() { return null;}\n }\n };\n sslContext.init(clientKeyManagerList, clientTrustManagerList, null); //Initialize SSL context with the key and trust managers we've created/loaded before\n\n ConnectionFactory rabbitMqConnectionFactory = new ConnectionFactory(); //Create factory\n rabbitMqConnectionFactory.setHost(\"localhost\");\n rabbitMqConnectionFactory.setPort(5671);\n rabbitMqConnectionFactory.setSaslConfig(DefaultSaslConfig.EXTERNAL); //Set authentication method as SSL auth\n rabbitMqConnectionFactory.useSslProtocol(sslContext); //Set the created SSL context as the one to use\n Connection rabbitMqOutboundConnection = null;\n Channel rabbitMqOutboundChannel = null;\n try {\n rabbitMqOutboundConnection = rabbitMqConnectionFactory.newConnection();\n rabbitMqOutboundChannel = rabbitMqOutboundConnection.createChannel();\n rabbitMqOutboundChannel.queueDeclare(QUEUE_USED, false, false, false, null);\n rabbitMqOutboundChannel.basicPublish(\"\", QUEUE_USED, null, \"This is a sample message\".getBytes());\n System.out.println(\"Message successfully sent to queue\");\n }finally{\n if(rabbitMqOutboundChannel != null) {\n rabbitMqOutboundChannel.close();\n }\n if(rabbitMqOutboundConnection != null) {\n rabbitMqOutboundConnection.close();\n }\n }\n Connection rabbitMqInboundConnection = null;\n Channel rabbitMqInboundChannel = null;\n try {\n rabbitMqInboundConnection = rabbitMqConnectionFactory.newConnection();\n rabbitMqInboundChannel = rabbitMqInboundConnection.createChannel();\n rabbitMqInboundChannel.queueDeclare(QUEUE_USED, false, false, false, null);\n QueueingConsumer rabbitMqQueueConsumer = new QueueingConsumer(rabbitMqInboundChannel);\n rabbitMqInboundChannel.basicConsume(QUEUE_USED, true, rabbitMqQueueConsumer);\n QueueingConsumer.Delivery deliveryResult = rabbitMqQueueConsumer.nextDelivery();\n System.out.println(\"Message read from the queue: \" + new String(deliveryResult.getBody()));\n }finally{\n if(rabbitMqInboundChannel != null) {\n rabbitMqInboundChannel.close();\n }\n if(rabbitMqInboundConnection != null) {\n rabbitMqInboundConnection.close();\n }\n }\n }\n\n}\n```\n\n```text\n=INFO REPORT==== 29-Dec-2014::15:55:30 ===\naccepting AMQP connection <0.644.0> (127.0.0.1:35299 -> 127.0.0.1:5671)\n\n=ERROR REPORT==== 29-Dec-2014::15:55:30 ===\nSSL: certify: ssl_handshake.erl:1343:Fatal error: handshake failure\n```\n\n```text\n=INFO REPORT==== 29-Dec-2014::14:51:13 ===\naccepting AMQP connection <0.311.0> (127.0.0.1:35271 -> 127.0.0.1:5671)\n\n=ERROR REPORT==== 29-Dec-2014::14:51:17 ===\nclosing AMQP connection <0.311.0> (127.0.0.1:35271 -> 127.0.0.1:5671):\n{handshake_error,starting,0,\n {amqp_error,access_refused,\n \"EXTERNAL login refused: no peer certificate\",\n 'connection.start_ok'}}\n```\n\n```text\ndeveloper@developer-VirtualBox:~/rabbitmqcert$ openssl s_client -tls1_2 -connect localhost:5671 -cert ruleprocessing.public.pem -key ruleprocessing.private.pem -CAfile devcafiles/cacert.pem \nCONNECTED(00000003)\ndepth=1 CN = RabbitMQCA\nverify return:1\ndepth=0 CN = rabbitmq, O = dev\nverify return:1\n139797055162016:error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure:s3_pkt.c:1260:SSL alert number 40\n139797055162016:error:1409E0E5:SSL routines:SSL3_WRITE_BYTES:ssl handshake failure:s3_pkt.c:596:\n---\nCertificate chain\n 0 s:/CN=rabbitmq/O=dev\n i:/CN=RabbitMQCA\n 1 s:/CN=RabbitMQCA\n i:/CN=RabbitMQCA\n---\nServer certificate\n-----BEGIN CERTIFICATE-----\n<<OMMITED>>\n-----END CERTIFICATE-----\nsubject=/CN=rabbitmq/O=dev\nissuer=/CN=RabbitMQCA\n---\nAcceptable client certificate CA names\n/CN=RabbitMQCA\n---\nSSL handshake has read 1646 bytes and written 2103 bytes\n---\nNew, TLSv1/SSLv3, Cipher is AES256-SHA256\nServer public key is 2048 bit\nSecure Renegotiation IS NOT supported\nCompression: NONE\nExpansion: NONE\nSSL-Session:\n Protocol : TLSv1.2\n Cipher : AES256-SHA256\n Session-ID: FC972B9A5D3EC359DC0467C8F02410E3AD66DA151C4411C0D5892115A439431A\n Session-ID-ctx: \n Master-Key: E4FE793C71692852F6F3C4E9C5CB17774D8A50511338EF2E75691DC0DC2119F56611FC959C12429BBAFD46EC760ED713\n Key-Arg : None\n PSK identity: None\n PSK identity hint: None\n SRP username: None\n Start Time: 1419871438\n Timeout : 7200 (sec)\n Verify return code: 0 (ok)\n---\n```\n\n```text\nCONNECTED(00000003)\ndepth=1 CN = RabbitMQCA\nverify return:1\ndepth=0 CN = rabbitmq, O = dev\nverify return:1\n---\nCertificate chain\n 0 s:/CN=rabbitmq/O=dev\n i:/CN=RabbitMQCA\n 1 s:/CN=RabbitMQCA\n i:/CN=RabbitMQCA\n---\nServer certificate\n-----BEGIN CERTIFICATE-----\n<<OMMITED>>\n-----END CERTIFICATE-----\nsubject=/CN=rabbitmq/O=dev\nissuer=/CN=RabbitMQCA\n---\nNo client certificate CA names sent\n---\nSSL handshake has read 1666 bytes and written 663 bytes\n---\nNew, TLSv1/SSLv3, Cipher is AES256-SHA256\nServer public key is 2048 bit\nSecure Renegotiation IS NOT supported\nCompression: NONE\nExpansion: NONE\nSSL-Session:\n Protocol : TLSv1.2\n Cipher : AES256-SHA256\n Session-ID: C4156551790BA116DC38A981728A71768D0B53AAEBEE969A4DA150746E5373FB\n Session-ID-ctx: \n Master-Key: 3470DD0C0247B94EA784C3CEF94888C160205E9F06C14869B564A00AF5E4F7FAF5B4FC977E290B80DBCD140133F75AC0\n Key-Arg : None\n PSK identity: None\n PSK identity hint: None\n SRP username: None\n Start Time: 1419871570\n Timeout : 7200 (sec)\n Verify return code: 0 (ok)\n---\n```\n\n========================================\n\nComments:\n- very helpful,absolutely answer my problem. many thanks toryu. :)","metadata":{"transformedAt":"2026-08-18T18:33:20.329Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":892,"estimatedTokens":8478}}1150{"id":"stack-13449243","source":"stackoverflow","questionId":13449243,"title":"Slowing Down Rabbit MQ Delivery Rate","tags":["java","rabbitmq"],"text":"Title: Slowing Down Rabbit MQ Delivery Rate\nTags: java, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am using Rabbit MQ for my application. Sometimes I need to stop my consumers due to maintenance. So, there will be thousands of messages waiting on the queue. After I restart my consumers, the message delivery rate is high (500-600 messages per second). At that rate, one of my consumers cannot handle the messages and break down the server. \n\nI will change consumer code in the future, but now I need an quick soluton. \n\nSo, is there a way to slow down the delivery rate? I tried basicQos method, but it did not work. \n\nNote: I am using Java for consumers.\n\n========================================\n\nCode:\n```text\nchannel.basicConsume(queueName, false, consumer);\nchannel.basicQos(50);\n\nconsumer.getChannel().basicAck(delivery.getEnvelope().getDeliveryTag(), false);\n```\n\n========================================\n\nComments:\n- You can call `Thread.sleep()` in consumer. It will decrease delivery rate if number of consumers is limited. But it is only palliative.","metadata":{"transformedAt":"2026-08-18T18:33:20.329Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":1,"totalLines":27,"estimatedTokens":266}}1151{"id":"stack-15502037","source":"stackoverflow","questionId":15502037,"title":"PHP AMQP Consume() fork to do actual work","tags":["php","rabbitmq","amqp"],"text":"Title: PHP AMQP Consume() fork to do actual work\nTags: php, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI'm looking to have a PHP script that consumes (using the PECL AMQP module) from a RabbitMQ queue and then forks off to do the actual work.\n\nI've got code @ https://gist.github.com/giggsey/6666e67bb0e090eeb5f0\n\nBut when I run it, I get:\n\n11296 Key: USER.12392 ObjectLength: 74 Forked 11296 at 2013-03-19\n\n14:16:22 11277 ack() PHP Fatal error: Uncaught exception\n\n'AMQPConnectionException' with message 'Connection reset by peer' in tmp/forking.php:10\n\nStack trace:\n\n0 tmp/forking.php(10): AMQPQueue->consume(Array)\n\n1 tmp/forking.php(102): test->run()\n\n2 {main} thrown in tmp/forking.php on line 10\n\nFatal error: Uncaught exception 'AMQPConnectionException' with message\n'Connection reset by peer' in tmp/forking.php on line 10\n\nAMQPConnectionException: Connection reset by peer in tmp/forking.php on line 10\n\nCall Stack:\n\n```\n0.0006 665008 1. {main}() tmp/forking.php:0\n\n0.0007 665456 2. test->run() tmp/forking.php:102\n\n0.0359 670504 3. AMQPQueue->consume() tmp/forking.php:10\n```\n\n========================================\n\nCode:\n```text\n0.0006 665008 1. {main}() tmp/forking.php:0\n\n0.0007 665456 2. test->run() tmp/forking.php:102\n\n0.0359 670504 3. AMQPQueue->consume() tmp/forking.php:10\n```\n\n```text\n$connection->connect();\n```\n\n```text\n$connection->pconnect();\n```\n\n========================================\n\nComments:\n- Did you try this without the fork stuff?\n- @mzedeler Yeah, it works fine without the forking.\n- You are running from the CLI?\n- @Bubba Yup. PHP 5.3 with Peck AMQP 1.0.9\n- Duh. Reading is essential. It appears that the children are likely killing your connection though. I'll play with it when I have some time - it's a fun puzzle.\n- Aight, I wrote a functioning example and updated the submitted answer, hope that works for you!\n- I think I misdirected you with my question. What I was trying to do was have the consume in the parent, and then it will fork off a child and do some potential heavy work.\n- Yer killing me! ;-) So you want to run a script, in that script you want to instantiate a queue that consumes ... then you want the call back to fork (blocking the parent) until some work is done, at which pont the child dies, and the parent script continues to monitor the queue for something else to consume?\n- Correct :) Similar to how php-resque (and I think normal resque) works, but using Rabbit\n- I think I fixed it, I used your script, just change $connection->connect(); to $connection->pconnect(); Before that change, I would could reproduce your error, after that change, it is working fine for me. If you confirm, I'll update the answer.\n- I'm happy with that. If you update your answer, I'll award the bounty.\n- That was fun! Thanks for letting me play.","metadata":{"transformedAt":"2026-08-18T18:33:20.329Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":74,"estimatedTokens":706}}1152{"id":"stack-11067924","source":"stackoverflow","questionId":11067924,"title":"How to stop binding to AMQP default exchange?","tags":["javascript","node.js","rabbitmq","amqp"],"text":"Title: How to stop binding to AMQP default exchange?\nTags: javascript, node.js, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nEvery time I bind an AMQP queue to an exchange it automatically seems to bind to the 'default' direct exchange.\n\nHere's the code in using a rabbitMQ server and node.js:\n\n```\nvar amqp = require('amqp');\n\nvar connection = amqp.createConnection({host:'localhost'});\n\nconnection.on('ready', function(){\n var q = connection.queue('test_queue_name');\n var exc = connection.exchange('test_exchange', { autoDelete:true });\n q.bind('test_exchange', 'test.key');\n});\n```\n\nHere's the console output when using the \"rabbitmqctl list_bindings\" command:\n\n```\nListing bindings ...\n exchange test_queue_name queue test_queue_name []\ntest_exchange exchange test_queue_name queue test.key []\n...done.\n```\n\n========================================\n\nCode:\n```text\nvar amqp = require('amqp');\n\nvar connection = amqp.createConnection({host:'localhost'});\n\nconnection.on('ready', function(){\n var q = connection.queue('test_queue_name');\n var exc = connection.exchange('test_exchange', { autoDelete:true });\n q.bind('test_exchange', 'test.key');\n});\n```\n\n```text\nListing bindings ...\n exchange test_queue_name queue test_queue_name []\ntest_exchange exchange test_queue_name queue test.key []\n...done.\n```\n\n========================================\n\nComments:\n- Thanks. Are you sure that the default exchange is bound to even if another binding is named? In the tutorials when 'rabbitmqctl list_bindings' is used it doesn't show the default exchange to have a binding...\n- I took the extra `...` in the tutorial to mean they omitted some information. (assuming you're looking at this one: rabbitmq.com/tutorials/tutorial-three-python.html)\n- The AMQP spec talks about \"automatic mode\", where the broker must provide a default exchange, and that queues have a default binding to it. It doesn't appear to take a position about whether this is *required* for queues with specified bindings.\n- When opening the management UI, under \"default exchange\", it clearly says \"The default exchange is implicitly bound to every queue, with a routing key equal to the queue name. It is not possible to explicitly bind to, or unbind from the default exchange. It also cannot be deleted.\"","metadata":{"transformedAt":"2026-08-18T18:33:20.329Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":59,"estimatedTokens":580}}1153{"id":"stack-13770323","source":"stackoverflow","questionId":13770323,"title":"Bus Configuration with Autofac: Issue with RabbitMQ vs Loopback?","tags":["rabbitmq","autofac","masstransit"],"text":"Title: Bus Configuration with Autofac: Issue with RabbitMQ vs Loopback?\nTags: rabbitmq, autofac, masstransit\nSource: Stack Overflow\n\nQuestion:\nFor some reason I can not post to the masstransit google group, even though I joined, I am told that I do not have permission to post to this group. So I am going to post here...\n\nNow for my problem:\n\nI am using MassTransit v2.7.2, with AutoFac v2.6.3. I am trying to configure Autofac to scan an assembly and register my consumers; all types that implement the IConsumer interface. This seems to work.\n\nI am using the MassTransit.AutofacIntegration assembly and the `LoadFrom(...)` extension method to register the consumers from the container with MassTransit when I configure the bus. Here is the code:\n\n```\nvar builder = new ContainerBuilder();\nbuilder\n .RegisterAssemblyTypes(typeof (CreateElectionCommandHandler).Assembly)\n .Where(type => type.Implements())\n .AsSelf();\nvar container = builder.Build();\n\nvar localBus = ServiceBusFactory.New(configurator =>\n {\n //configurator.ReceiveFrom(\"loopback://localhost/testqueue\");\n configurator.ReceiveFrom(\"rabbitmq://localhost/commandqueue\");\n configurator.UseRabbitMq();\n configurator.Subscribe(sbc => sbc.LoadFrom(container));\n });\n\nAssert.IsTrue(container.IsRegistered());\nAssert.IsTrue(container.IsRegistered());\nAssert.AreEqual(1, localBus.HasSubscription().Count());\nAssert.AreEqual(1, localBus.HasSubscription().Count());\n```\n\nIf I run the above code using the loopback\n\n```\nconfigurator.ReceiveFrom(\"loopback://localhost/testqueue\");\n```\n\nconfiguration (comment out the rabbitmq conifig), the test will pass.\n\nIf I comment out the \"loopback\" config and comment in the \n\n```\nconfigurator.ReceiveFrom(\"rabbitmq://localhost/commandqueue\");\n configurator.UseRabbitMq();\n```\n\nconfig, the test will fail. (Note: The rabbitmq queue is already up and running - I have been using it as part of my POC). Specifically, it will fail on the assertion:\n\n```\nAssert.AreEqual(1, localBus.HasSubscription().Count());\nAssert.AreEqual(1, localBus.HasSubscription().Count());\n```\n\nCan anybody help me understand what is going on here? I am new to MT so fully anticipating that I am missing something, or not configuring something correctly. \n\nAm I correct to assume that if there are no message subscriptions registered, then the bus will not be able to deliver to any of my consumers (even though the consumers are registered)?\n\nAny help much appreciated!\n\n========================================\n\nTop Answer:\nI would check to see if MassTransit creates an exchange the message types in question. Messages are sent to the exchange and all consumer queues are bound to the exchange. You can look at the Rabbit config to see if that's happened or not as well. And with no consumers registered, no messages will be delivered. Chris has been working on adding options to error is there's consumers so you can handle it in your code.\n\nI would join the mailing list https://groups.google.com/forum/?fromgroups=#!forum/masstransit-discuss to get help. There's a lot more people that can ask the right questions to get you where you need to be.\n\n========================================\n\nCode:\n```text\nvar builder = new ContainerBuilder();\nbuilder\n .RegisterAssemblyTypes(typeof (CreateElectionCommandHandler).Assembly)\n .Where(type => type.Implements<IConsumer>())\n .AsSelf();\nvar container = builder.Build();\n\nvar localBus = ServiceBusFactory.New(configurator =>\n {\n //configurator.ReceiveFrom(\"loopback://localhost/testqueue\");\n configurator.ReceiveFrom(\"rabbitmq://localhost/commandqueue\");\n configurator.UseRabbitMq();\n configurator.Subscribe(sbc => sbc.LoadFrom(container));\n });\n\nAssert.IsTrue(container.IsRegistered<CreateElectionCommandHandler>());\nAssert.IsTrue(container.IsRegistered<TerminateElectionCommandHandler>());\nAssert.AreEqual(1, localBus.HasSubscription<CreateElection>().Count());\nAssert.AreEqual(1, localBus.HasSubscription<TerminateElection>().Count());\n```\n\n```text\nconfigurator.ReceiveFrom(\"loopback://localhost/testqueue\");\n```\n\n```text\nconfigurator.ReceiveFrom(\"rabbitmq://localhost/commandqueue\");\n configurator.UseRabbitMq();\n```\n\n```text\nAssert.AreEqual(1, localBus.HasSubscription<CreateElection>().Count());\nAssert.AreEqual(1, localBus.HasSubscription<TerminateElection>().Count());\n```\n\n```text\nLoadFrom(...)\n```\n\n========================================\n\nComments:\n- the .AsSelf() style of registration is the way to go, the docs are wrong about the IConsumer version of registering a consumer.\n- Then I can easily remove that from my response. Thanks Chris.\n- Thanks @Travis - I have actually joined that group, but for some reason I am told that I do not have permissions to post - any ideas why that would be?\n- Seems once again Google Groups lost the moderation flag for new users and is just blocking them once they join. I'll try and get this cleaned up.\n- Apologies - late response due to vacation. Thanks @Chris Patterson for the explanation; adding a call to Publish() on the bus (configured with RabbitMQ) caused the test to pass.","metadata":{"transformedAt":"2026-08-18T18:33:20.329Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":5,"totalLines":121,"estimatedTokens":1331}}1154{"id":"stack-13275884","source":"stackoverflow","questionId":13275884,"title":"Django Celery Periodic Tasks Run But RabbitMQ Queues Aren't Consumed","tags":["python","django","heroku","rabbitmq","celery"],"text":"Title: Django Celery Periodic Tasks Run But RabbitMQ Queues Aren't Consumed\nTags: python, django, heroku, rabbitmq, celery\nSource: Stack Overflow\n\nQuestion:\n### Question\n\nAfter running tasks via celery's periodic task scheduler, beat, why do I have so many unconsumed queues remaining in RabbitMQ?\n\n### Setup\n\n- Django web app running on Heroku\n\n- Tasks scheduled via celery beat\n\n- Tasks run via celery worker\n\n- Message broker is RabbitMQ from ClouldAMQP\n\n### Procfile\n\n```\nweb: gunicorn --workers=2 --worker-class=gevent --bind=0.0.0.0:$PORT project_name.wsgi:application\nscheduler: python manage.py celery worker --loglevel=ERROR -B -E --maxtasksperchild=1000\nworker: python manage.py celery worker -E --maxtasksperchild=1000 --loglevel=ERROR\n```\n\n### settings.py\n\n```\nCELERYBEAT_SCHEDULE = {\n 'do_some_task': {\n 'task': 'project_name.apps.appname.tasks.some_task',\n 'schedule': datetime.timedelta(seconds=60 * 15),\n 'args': ''\n },\n}\n```\n\n### tasks.py\n\n```\n@celery.task\ndef some_task()\n # Get some data from external resources\n # Save that data to the database\n # No return value specified\n```\n\n### Result\n\nEvery time the task runs, I get (via the RabbitMQ web interface):\n\n- An additional message in the \"Ready\" state under my \"Queued Messages\"\nAn additional queue with a single message in the \"ready\" state\n\n- This queue has no listed consumers\n\n========================================\n\nTop Answer:\nLooks like you are getting back responses from your consumed tasks.\n\nYou can avoid that by doing:\n\n```\n@celery.task(ignore_result=True)\n```\n\n========================================\n\nCode:\n```text\nweb: gunicorn --workers=2 --worker-class=gevent --bind=0.0.0.0:$PORT project_name.wsgi:application\nscheduler: python manage.py celery worker --loglevel=ERROR -B -E --maxtasksperchild=1000\nworker: python manage.py celery worker -E --maxtasksperchild=1000 --loglevel=ERROR\n```\n\n```text\nCELERYBEAT_SCHEDULE = {\n 'do_some_task': {\n 'task': 'project_name.apps.appname.tasks.some_task',\n 'schedule': datetime.timedelta(seconds=60 * 15),\n 'args': ''\n },\n}\n```\n\n```text\n@celery.task\ndef some_task()\n # Get some data from external resources\n # Save that data to the database\n # No return value specified\n```\n\n```text\nCELERY_RESULT_BACKEND = 'amqp'\n```\n\n```text\nCELERY_RESULT_BACKEND = 'database'\n```\n\n```text\n# Delete result records (\"tombstones\") from database after 4 hours\n# http://docs.celeryproject.org/en/latest/configuration.html#celery-task-result-expires\nCELERY_TASK_RESULT_EXPIRES = 14400\n```\n\n```text\n########## CELERY CONFIGURATION\nimport djcelery\n# https://github.com/celery/django-celery/\ndjcelery.setup_loader()\n\nINSTALLED_APPS = INSTALLED_APPS + (\n 'djcelery',\n)\n\n# Compress all the messages using gzip\n# http://celery.readthedocs.org/en/latest/userguide/calling.html#compression\nCELERY_MESSAGE_COMPRESSION = 'gzip'\n\n# See: http://docs.celeryproject.org/en/latest/configuration.html#broker-transport\nBROKER_TRANSPORT = 'amqplib'\n\n# Set this number to the amount of allowed concurrent connections on your AMQP\n# provider, divided by the amount of active workers you have.\n#\n# For example, if you have the 'Little Lemur' CloudAMQP plan (their free tier),\n# they allow 3 concurrent connections. So if you run a single worker, you'd\n# want this number to be 3. If you had 3 workers running, you'd lower this\n# number to 1, since 3 workers each maintaining one open connection = 3\n# connections total.\n#\n# See: http://docs.celeryproject.org/en/latest/configuration.html#broker-pool-limit\nBROKER_POOL_LIMIT = 3\n\n# See: http://docs.celeryproject.org/en/latest/configuration.html#broker-connection-max-retries\nBROKER_CONNECTION_MAX_RETRIES = 0\n\n# See: http://docs.celeryproject.org/en/latest/configuration.html#broker-url\nBROKER_URL = os.environ.get('CLOUDAMQP_URL')\n\n# Previously, had this set to 'amqp', this resulted in many read / unconsumed\n# queues and messages in RabbitMQ\n# See: http://docs.celeryproject.org/en/latest/configuration.html#celery-result-backend\nCELERY_RESULT_BACKEND = 'database'\n\n# Delete result records (\"tombstones\") from database after 4 hours\n# http://docs.celeryproject.org/en/latest/configuration.html#celery-task-result-expires\nCELERY_TASK_RESULT_EXPIRES = 14400\n########## END CELERY CONFIGURATION\n```\n\n```text\nCELERY_RESULT_BACKEND\n```\n\n```text\n@celery.task(ignore_result=True)\n```\n\n========================================\n\nComments:\n- Hi, i´m trying to implement the same stack on my app but i can´t get it right, would you be so kind as to post all your settings related to celery and rabbitmq? i would appreciate it very much and it would help other newbies out there.\n- Sure, added. It's based on the excellent django-skel recommendations.\n- This is correct. I had the same problem. Question and answer here: stackoverflow.com/questions/30327670/…","metadata":{"transformedAt":"2026-08-18T18:33:20.329Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":170,"estimatedTokens":1211}}1155{"id":"stack-47344882","source":"stackoverflow","questionId":47344882,"title":"Why Spring Boot Application logs that it started twice after adding spring-cloud-bus dependency","tags":["spring-boot","rabbitmq","spring-amqp","spring-rabbit","spring-cloud-bus"],"text":"Title: Why Spring Boot Application logs that it started twice after adding spring-cloud-bus dependency\nTags: spring-boot, rabbitmq, spring-amqp, spring-rabbit, spring-cloud-bus\nSource: Stack Overflow\n\nQuestion:\nThis is simple code in my Spring boot application:\n\n```\npackage com.maxxton.SpringBootHelloWorld;\n\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\n\n@SpringBootApplication\npublic class SpringBootHelloWorldApplication {\n\n public static void main(String[] args) {\n SpringApplication.run(SpringBootHelloWorldApplication.class, args);\n }\n}\n```\n\nAnd a ApplicationListener class to listen to ApplicationEvent:\n\n```\npackage com.maxxton.SpringBootHelloWorld;\n\nimport org.springframework.context.ApplicationEvent;\nimport org.springframework.context.ApplicationListener;\nimport org.springframework.stereotype.Component;\n\n@Component\npublic class Test implements ApplicationListener {\n\n @Override\n public void onApplicationEvent(ApplicationEvent event) {\n if (event.getClass().getSimpleName().equals(\"ApplicationReadyEvent\")) {\n System.out.println(\"-------------------------------------\");\n System.out.println(event.getClass().getSimpleName());\n System.out.println(\"-------------------------------------\");\n }\n }\n}\n```\n\nbuild.gradle contains these dependencies:\n\n```\ndependencies {\n\n compile(\"org.springframework.boot:spring-boot-starter-amqp\")\n compile(\"org.springframework.cloud:spring-cloud-starter-bus-amqp\")\n\n compile('org.springframework.boot:spring-boot-starter-web')\n compile('org.springframework.boot:spring-boot-starter')\n compile(\"org.springframework.cloud:spring-cloud-starter\")\n compile(\"org.springframework.cloud:spring-cloud-starter-security\")\n compile(\"org.springframework.cloud:spring-cloud-starter-eureka\")\n testCompile('org.springframework.boot:spring-boot-starter-test')\n}\n```\n\nNow, when I run this spring boot application, I see this log printed twice:\n\n```\n[main] c.m.S.SpringBootHelloWorldApplication : Started SpringBootHelloWorldApplication in ... seconds (JVM running for ...)\n```\n\nUsually, this log get printed only once, but it get printed twice if I add these dependencies:\n\n```\ncompile(\"org.springframework.boot:spring-boot-starter-amqp\")\ncompile(\"org.springframework.cloud:spring-cloud-starter-bus-amqp\")\n```\n\nThis is complete log:\n\n```\n2017-11-17 15:44:07.372 INFO 5976 --- [ main] o.s.c.support.GenericApplicationContext : Refreshing org.springframework.context.support.GenericApplicationContext@31c7c281: startup date [Fri Nov 17 15:44:07 IST 2017]; root of context hierarchy\n-------------------------------------\nApplicationReadyEvent\n-------------------------------------\n2017-11-17 15:44:07.403 INFO 5976 --- [ main] c.m.S.SpringBootHelloWorldApplication : Started SpringBootHelloWorldApplication in 1.19 seconds (JVM running for 10.231)\n2017-11-17 15:44:09.483 WARN 5976 --- [ main] o.s.amqp.rabbit.core.RabbitAdmin : Failed to declare exchange: Exchange [name=springCloudBus, type=topic, durable=true, autoDelete=false, internal=false, arguments={}], continuing... org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect\n2017-11-17 15:44:09.492 INFO 5976 --- [ main] o.s.integration.channel.DirectChannel : Channel 'a-bootiful-client.springCloudBusOutput' has 1 subscriber(s).\n2017-11-17 15:44:09.493 INFO 5976 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0\n2017-11-17 15:44:09.530 INFO 5976 --- [ main] o.s.i.endpoint.EventDrivenConsumer : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel\n2017-11-17 15:44:09.530 INFO 5976 --- [ main] o.s.i.channel.PublishSubscribeChannel : Channel 'a-bootiful-client.errorChannel' has 1 subscriber(s).\n2017-11-17 15:44:09.530 INFO 5976 --- [ main] o.s.i.endpoint.EventDrivenConsumer : started _org.springframework.integration.errorLogger\n2017-11-17 15:44:09.530 INFO 5976 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147482647\n2017-11-17 15:44:09.539 INFO 5976 --- [ main] c.s.b.r.p.RabbitExchangeQueueProvisioner : declaring queue for inbound: springCloudBus.anonymous.kZ1vvxHaRfChKe1TncH-MQ, bound to: springCloudBus\n2017-11-17 15:44:11.562 WARN 5976 --- [ main] o.s.amqp.rabbit.core.RabbitAdmin : Failed to declare exchange: Exchange [name=springCloudBus, type=topic, durable=true, autoDelete=false, internal=false, arguments={}], continuing... org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect\n2017-11-17 15:44:13.587 WARN 5976 --- [ main] o.s.amqp.rabbit.core.RabbitAdmin : Failed to declare queue: Queue [name=springCloudBus.anonymous.kZ1vvxHaRfChKe1TncH-MQ, durable=false, autoDelete=true, exclusive=true, arguments={}], continuing... org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect\n2017-11-17 15:44:15.611 WARN 5976 --- [ main] o.s.amqp.rabbit.core.RabbitAdmin : Failed to declare binding: Binding [destination=springCloudBus.anonymous.kZ1vvxHaRfChKe1TncH-MQ, exchange=springCloudBus, routingKey=#], continuing... org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect\n2017-11-17 15:44:17.662 INFO 5976 --- [ main] o.s.i.a.i.AmqpInboundChannelAdapter : started inbound.springCloudBus.anonymous.kZ1vvxHaRfChKe1TncH-MQ\n2017-11-17 15:44:17.662 INFO 5976 --- [ main] o.s.i.endpoint.EventDrivenConsumer : Adding {message-handler:inbound.springCloudBus.default} as a subscriber to the 'bridge.springCloudBus' channel\n2017-11-17 15:44:17.662 INFO 5976 --- [ main] o.s.i.endpoint.EventDrivenConsumer : started inbound.springCloudBus.default\n2017-11-17 15:44:17.663 INFO 5976 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483647\n2017-11-17 15:44:17.714 INFO 5976 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)\n-------------------------------------\nApplicationReadyEvent\n-------------------------------------\n2017-11-17 15:44:17.717 INFO 5976 --- [ main] c.m.S.SpringBootHelloWorldApplication : Started SpringBootHelloWorldApplication in 20.131 seconds (JVM running for 20.545)\n```\n\nAs you can see, ApplicationReadyEvent is happening twice.\n\nWhy is this happening?\nIs there any way to avoid this?\n\n========================================\n\nTop Answer:\nAre u using multiple binders rabbitmq configuration in your application.yml/.xml ?\n\nIf it's a yes, then u can try to exclude RabbitAutoConfiguration.\n\n```\n@EnableDiscoveryClient\n@EnableAutoConfiguration(exclude = {RabbitAutoConfiguration.class})\n@SpringBootApplication\npublic class SpringBootHelloWorldApplication {\n\n public static void main(String[] args) {\n SpringApplication.run(SpringBootHelloWorldApplication.class, args);\n }\n}\n```\n\n========================================\n\nCode:\n```text\npackage com.maxxton.SpringBootHelloWorld;\n\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\n\n@SpringBootApplication\npublic class SpringBootHelloWorldApplication {\n\n public static void main(String[] args) {\n SpringApplication.run(SpringBootHelloWorldApplication.class, args);\n }\n}\n```\n\n```text\npackage com.maxxton.SpringBootHelloWorld;\n\nimport org.springframework.context.ApplicationEvent;\nimport org.springframework.context.ApplicationListener;\nimport org.springframework.stereotype.Component;\n\n@Component\npublic class Test implements ApplicationListener {\n\n @Override\n public void onApplicationEvent(ApplicationEvent event) {\n if (event.getClass().getSimpleName().equals(\"ApplicationReadyEvent\")) {\n System.out.println(\"-------------------------------------\");\n System.out.println(event.getClass().getSimpleName());\n System.out.println(\"-------------------------------------\");\n }\n }\n}\n```\n\n```text\ndependencies {\n\n compile(\"org.springframework.boot:spring-boot-starter-amqp\")\n compile(\"org.springframework.cloud:spring-cloud-starter-bus-amqp\")\n\n compile('org.springframework.boot:spring-boot-starter-web')\n compile('org.springframework.boot:spring-boot-starter')\n compile(\"org.springframework.cloud:spring-cloud-starter\")\n compile(\"org.springframework.cloud:spring-cloud-starter-security\")\n compile(\"org.springframework.cloud:spring-cloud-starter-eureka\")\n testCompile('org.springframework.boot:spring-boot-starter-test')\n}\n```\n\n```text\n[main] c.m.S.SpringBootHelloWorldApplication : Started SpringBootHelloWorldApplication in ... seconds (JVM running for ...)\n```\n\n```text\ncompile(\"org.springframework.boot:spring-boot-starter-amqp\")\ncompile(\"org.springframework.cloud:spring-cloud-starter-bus-amqp\")\n```\n\n```text\n2017-11-17 15:44:07.372 INFO 5976 --- [ main] o.s.c.support.GenericApplicationContext : Refreshing org.springframework.context.support.GenericApplicationContext@31c7c281: startup date [Fri Nov 17 15:44:07 IST 2017]; root of context hierarchy\n-------------------------------------\nApplicationReadyEvent\n-------------------------------------\n2017-11-17 15:44:07.403 INFO 5976 --- [ main] c.m.S.SpringBootHelloWorldApplication : Started SpringBootHelloWorldApplication in 1.19 seconds (JVM running for 10.231)\n2017-11-17 15:44:09.483 WARN 5976 --- [ main] o.s.amqp.rabbit.core.RabbitAdmin : Failed to declare exchange: Exchange [name=springCloudBus, type=topic, durable=true, autoDelete=false, internal=false, arguments={}], continuing... org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect\n2017-11-17 15:44:09.492 INFO 5976 --- [ main] o.s.integration.channel.DirectChannel : Channel 'a-bootiful-client.springCloudBusOutput' has 1 subscriber(s).\n2017-11-17 15:44:09.493 INFO 5976 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0\n2017-11-17 15:44:09.530 INFO 5976 --- [ main] o.s.i.endpoint.EventDrivenConsumer : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel\n2017-11-17 15:44:09.530 INFO 5976 --- [ main] o.s.i.channel.PublishSubscribeChannel : Channel 'a-bootiful-client.errorChannel' has 1 subscriber(s).\n2017-11-17 15:44:09.530 INFO 5976 --- [ main] o.s.i.endpoint.EventDrivenConsumer : started _org.springframework.integration.errorLogger\n2017-11-17 15:44:09.530 INFO 5976 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147482647\n2017-11-17 15:44:09.539 INFO 5976 --- [ main] c.s.b.r.p.RabbitExchangeQueueProvisioner : declaring queue for inbound: springCloudBus.anonymous.kZ1vvxHaRfChKe1TncH-MQ, bound to: springCloudBus\n2017-11-17 15:44:11.562 WARN 5976 --- [ main] o.s.amqp.rabbit.core.RabbitAdmin : Failed to declare exchange: Exchange [name=springCloudBus, type=topic, durable=true, autoDelete=false, internal=false, arguments={}], continuing... org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect\n2017-11-17 15:44:13.587 WARN 5976 --- [ main] o.s.amqp.rabbit.core.RabbitAdmin : Failed to declare queue: Queue [name=springCloudBus.anonymous.kZ1vvxHaRfChKe1TncH-MQ, durable=false, autoDelete=true, exclusive=true, arguments={}], continuing... org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect\n2017-11-17 15:44:15.611 WARN 5976 --- [ main] o.s.amqp.rabbit.core.RabbitAdmin : Failed to declare binding: Binding [destination=springCloudBus.anonymous.kZ1vvxHaRfChKe1TncH-MQ, exchange=springCloudBus, routingKey=#], continuing... org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect\n2017-11-17 15:44:17.662 INFO 5976 --- [ main] o.s.i.a.i.AmqpInboundChannelAdapter : started inbound.springCloudBus.anonymous.kZ1vvxHaRfChKe1TncH-MQ\n2017-11-17 15:44:17.662 INFO 5976 --- [ main] o.s.i.endpoint.EventDrivenConsumer : Adding {message-handler:inbound.springCloudBus.default} as a subscriber to the 'bridge.springCloudBus' channel\n2017-11-17 15:44:17.662 INFO 5976 --- [ main] o.s.i.endpoint.EventDrivenConsumer : started inbound.springCloudBus.default\n2017-11-17 15:44:17.663 INFO 5976 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483647\n2017-11-17 15:44:17.714 INFO 5976 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)\n-------------------------------------\nApplicationReadyEvent\n-------------------------------------\n2017-11-17 15:44:17.717 INFO 5976 --- [ main] c.m.S.SpringBootHelloWorldApplication : Started SpringBootHelloWorldApplication in 20.131 seconds (JVM running for 20.545)\n```\n\n```text\n@Component\npublic class Test implements ApplicationListener<ApplicationReadyEvent>, \n ApplicationContextAware {\n\n private ApplicationContext applicationContext;\n\n @Override\n public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {\n this.applicationContext = applicationContext;\n }\n\n @Override\n public void onApplicationEvent(ApplicationReadyEvent event) {\n if (event.getApplicationContext().equals(this.applicationContext)) {\n System.out.println(\"-------------------------------------\");\n System.out.println(event.getClass().getSimpleName());\n System.out.println(\"-------------------------------------\");\n }\n }\n\n}\n```\n\n```text\n@EnableDiscoveryClient\n@EnableAutoConfiguration(exclude = {RabbitAutoConfiguration.class})\n@SpringBootApplication\npublic class SpringBootHelloWorldApplication {\n\n public static void main(String[] args) {\n SpringApplication.run(SpringBootHelloWorldApplication.class, args);\n }\n}\n```\n\n========================================\n\nComments:\n- Never used Spring Cloud Bus but it looks like it might be causing that. According to the docs, you can enable tracing, so you could have a look and check if there is something wrong there. A crazy idea might be that the application is listening to its own state changes, therefore consuming its own event and duplicating the output...\n- No, I am not using multiple binders.\n- So, you are saying, @gary-russell If we use spring-cloud-bus dependency, \"Started SpringBootHelloWorldApplication in ...\" will be logged twice, Because spring-cloud-bus uses spring-cloud-stream which puts the binder in a separate boot child.\n- It will be logged twice only if you don't take my advice and make your listener aware of which application context it is declared int.\n- I have made changes as per your suggestions, now listener aware is printing only once, But \"Started SpringBootHelloWorldApplication in ...\" is still logged twice.","metadata":{"transformedAt":"2026-08-18T18:33:20.329Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":264,"estimatedTokens":3748}}1156{"id":"stack-21123886","source":"stackoverflow","questionId":21123886,"title":"RabbitMQ truncates to 50,000 bytes when viewed?","tags":["rabbitmq"],"text":"Title: RabbitMQ truncates to 50,000 bytes when viewed?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am considering going to RabbitMQ from MSMQ.\n\nI was playing around it with and wanted to see the messages in the queue (usually easy with MSMQ).\n\nIt is a bit harder with RabbitMQ, but I made it work. But the help text says:\n\n Furthermore, message payloads will be truncated to 50000 bytes.\n\nThat is less that 0.05 MB! My payloads are much much larger than that.\n\nSo here is my question, **does it truncate just for viewing, or for the message that is put back in the queue too?**\n\n**Also, can this limit be configured?** When debugging, I would frequently need to see the full message.\n\n========================================\n\nComments:\n- Can you link to where you've read this... also take a look at stackoverflow.com/questions/18353898/… and comments.gmane.org/gmane.comp.networking.rabbitmq.general/14‌​665,\n- also this rabbitmq.com/blog/2012/04/25/…\n- @kzhen - It was in the queue page for the Management Pugin for RabbitMQ (rabbitmq.com/management.html). If click on the ? next to the Warning under Get messages.\n- Use the Rest API, and specify a large 'truncate' value stackoverflow.com/a/38390174/1181624","metadata":{"transformedAt":"2026-08-18T18:33:20.329Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":26,"estimatedTokens":311}}1157{"id":"stack-4140653","source":"stackoverflow","questionId":4140653,"title":"rabbitmq HA cluster","tags":["rabbitmq","high-availability"],"text":"Title: rabbitmq HA cluster\nTags: rabbitmq, high-availability\nSource: Stack Overflow\n\nQuestion:\nI am wanting to setup RabbitMQ as a two (or more) node cluster with HA. \n\nUse case: a client producer app (C#.NET) knows that the cluster has two nodes and publishes to the cluster. Various consumer apps (also C#.NET) connect to the cluster and get all messages generated by the producer. So long as at least one node is up and running the producer and consumers will all continue to work without error. Supposing nodes A and B are running and B dies for a while, then gets restarted, then a while later A dies, the clients all continue to function without receiving an error since at all times at least one node is up.\n\nCan it be made to work like this out of the box?\n\nAre there any other MQs that would be more appropriate (commercial ok) for a Windows/.NET application environment?\n\n========================================\n\nTop Answer:\nRabbitMQ v2.6.0 now supports high-availability queues using active/active clustering. Microsoft and a number of other companies have collaborated on Apache QPid which has C# bindings and which also supports active/active HA clustering.\n\n========================================\n\nComments:\n- So, after the client detects that the connection is dead (is this the AlreadyClosedException?) it should just try reconnecting to the cluster and one of the remaining nodes should automatically be assigned for it to use?\n- More or less, yes. The slight wrinkle is that you need to connect to a different node in the cluster (since the original is down); you could do this with a load-balancer. After that, it's business as usual. From the client's point of view, it will see the same configuration (same queues, exchanges).\n- So with a load balancer there would just appear to be one IP address to the clients but the erlang nodes themselves would all use their real IP address?\n- Did you have success with this? I'm about to attempt to do something similar.","metadata":{"transformedAt":"2026-08-18T18:33:20.329Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":25,"estimatedTokens":497}}1158{"id":"stack-51096003","source":"stackoverflow","questionId":51096003,"title":"How to install rabbitmq plugin on kubernetes?","tags":["kubernetes","rabbitmq","rabbitmqctl"],"text":"Title: How to install rabbitmq plugin on kubernetes?\nTags: kubernetes, rabbitmq, rabbitmqctl\nSource: Stack Overflow\n\nQuestion:\nI have a Kubernetes environment with a rabbitmq servirve who deploys 2 pods of rabbitmq.\n\nI need to install a plugin on rabbitmq, (Delayed Message Plugin) but I don't like the \"manual\" way, so if the pod is deleted, I have to install the plugin again.\n\nI want to know which is the recommended way of achieving this. \n\nFYI: the manual way is to copy a file into the plugins folder, and then launch the following command: \n\n```\nrabbitmq-plugins enable rabbitmq_delayed_message_exchange\n```\n\n========================================\n\nTop Answer:\nI've ended mounting a persistent volumen to a shared hard driven, and using the life cycle hooks to copy the file to the correct path\n\n```\nlifecycle:\n postStart:\n exec:\n command: ['sh', '-c', 'cp /data/rabbitmq_delayed_message_exchange-20171201-3.7.x.ez /opt/rabbitmq/plugins/']\n```\n\nBefore, I was using the lifecycle to throw a wget to the download url and then unzip and copy the file, but I think the above is more \"elegant\"\n\n```\nlifecycle:\n postStart:\n exec:\n command: ['sh', '-c', 'wget https://dl.bintray.com/rabbitmq/community-plugins/3.7.x/rabbitmq_delayed_message_exchange/rabbitmq_delayed_message_exchange-20171201-3.7.x.zip && unzip rabbitmq_delayed_message_exchange-20171201-3.7.x.zip -d /opt/rabbitmq/plugins/']\n```\n\n========================================\n\nCode:\n```text\nrabbitmq-plugins enable rabbitmq_delayed_message_exchange\n```\n\n```text\napiVersion: v1\nkind: ConfigMap\nmetadata:\n name: rabbitmq-config\n namespace: rabbitmq\ndata:\n enabled_plugins: |\n [rabbitmq_management,rabbitmq_peer_discovery_k8s].\n rabbitmq.conf: |\n ...\n definitions.json: |\n ...\n```\n\n```text\napiVersion: apps/v1beta1\nkind: StatefulSet\nmetadata:\n name: rabbitmq\n namespace: rabbitmq\nspec:\n replicas: 3\n ...\n template:\n ...\n spec:\n containers:\n - image: rabbitmq:3.7.4-management-alpine\n imagePullPolicy: IfNotPresent\n name: rabbitmq\n volumeMounts:\n - name: config-volume\n mountPath: /etc/rabbitmq\n ...\n volumes:\n - name: config-volume\n configMap:\n name: rabbitmq-config\n items:\n - key: rabbitmq.conf\n path: rabbitmq.conf\n - key: enabled_plugins\n path: enabled_plugins\n - key: definitions.json\n path: definitions.json\n ...\n```\n\n```text\nlifecycle:\n postStart:\n exec:\n command: ['sh', '-c', 'cp /data/rabbitmq_delayed_message_exchange-20171201-3.7.x.ez /opt/rabbitmq/plugins/']\n```\n\n```text\nlifecycle:\n postStart:\n exec:\n command: ['sh', '-c', 'wget https://dl.bintray.com/rabbitmq/community-plugins/3.7.x/rabbitmq_delayed_message_exchange/rabbitmq_delayed_message_exchange-20171201-3.7.x.zip && unzip rabbitmq_delayed_message_exchange-20171201-3.7.x.zip -d /opt/rabbitmq/plugins/']\n```\n\n```text\nlifecycle:\n postStart:\n exec:\n command: [\"/bin/sh\", \"-c\", \"rabbitmq-plugins --offline enable rabbitmq_management rabbitmq_peer_discovery_k8s rabbitmq_prometheus\"]\n```\n\n```text\n---\napiVersion: v1\nkind: Service\nmetadata:\n name: rabbitmq\n namespace: develop\nspec:\n type: ClusterIP\n selector:\n app: rabbitmq\n tier: core\n ports:\n - name: port-5672-tcp\n port: 5672\n - name: port-15672-tcp\n port: 15672\n\n---\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: rabbitmq\n namespace: develop\nspec:\n replicas: 2\n selector:\n matchLabels:\n app: rabbitmq\n tier: core\n template:\n metadata:\n labels:\n app: rabbitmq\n tier: core\n spec:\n restartPolicy: Always\n terminationGracePeriodSeconds: 30\n volumes:\n - name: rabbitmq-storage\n persistentVolumeClaim:\n claimName: rabbitmq-pvc\n containers:\n - name: rabbitmq\n image: rabbitmq:3.8-management\n lifecycle:\n postStart:\n exec:\n command: [\"/bin/sh\", \"-c\", \"rabbitmq-plugins --offline enable rabbitmq_management rabbitmq_peer_discovery_k8s rabbitmq_prometheus\"]\n resources:\n requests:\n memory: 2Gi\n cpu: 1\n limits:\n memory: 2Gi\n cpu: 1\n imagePullPolicy: IfNotPresent\n ports:\n - containerPort: 5672\n - containerPort: 15672\n volumeMounts:\n - name: rabbitmq-storage\n mountPath: \"/var/lib/rabbitmq/\"\n env:\n - name: RABBITMQ_DEFAULT_USER\n valueFrom:\n secretKeyRef:\n name: rabbitmq-username\n key: RABBITMQ__USERNAME\n - name: RABBITMQ_DEFAULT_PASS\n valueFrom:\n secretKeyRef:\n name: rabbitmq-password\n key: RABBITMQ__PASSWORD\n nodeSelector:\n type: ultrafastest\n```\n\n```text\n--offline\n```\n\n```text\n/etc/rabbitmq\n```\n\n========================================\n\nComments:\n- You can mount the content of a ConfigMap into your container. Add ConfigMap data to a volume\n- thanks. I'll take a look to that\n- I've read the docs but still can understand how to upload the file to k8s. Can you explain me a little more?\n- yes, I understand that, but how can I upload the binary file of the plugin?\n- I see. Maybe it makes sense to adjust the image so it is already in? Alternatively you could utilize Kubernetes life cycle hooks to download the file pre start. Here is an example of postStart\n- I've ended mounting a persistent volumen to a shared hard driven, and using the life cycle hooks to copy the file to the correct path\n- Let me add my comment to the answer then if it helped to solve your problem.","metadata":{"transformedAt":"2026-08-18T18:33:20.329Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":211,"estimatedTokens":1462}}1159{"id":"stack-27448347","source":"stackoverflow","questionId":27448347,"title":"How to parse rabbitmq status output?","tags":["rabbitmq","data-formats","rabbitmqctl"],"text":"Title: How to parse rabbitmq status output?\nTags: rabbitmq, data-formats, rabbitmqctl\nSource: Stack Overflow\n\nQuestion:\nI installed RabbitMQ on Linux, it's a great piece of software. \n\nWhen I run this command:\n\n```\nsudo rabbitmqctl status\n```\n\nI get a mess of output:\n\n```\n[{pid,18665},\n {running_applications,\n [{rabbitmq_management,\"RabbitMQ Management Console\",\"3.1.5\"},\n {rabbitmq_web_dispatch,\"RabbitMQ Web Dispatcher\",\"3.1.5\"},\n {webmachine,\"webmachine\",\"1.10.3-rmq3.1.5-gite9359c7\"},\n {mochiweb,\"MochiMedia Web Server\",\"2.7.0-rmq3.1.5-git680dba8\"},\n {rabbitmq_management_agent,\"RabbitMQ Management Agent\",\"3.1.5\"},\n {rabbit,\"RabbitMQ\",\"3.1.5\"},\n {os_mon,\"CPO CXC 138 46\",\"2.2.7\"},\n {inets,\"INETS CXC 138 49\",\"5.7.1\"},\n {xmerl,\"XML parser\",\"1.2.10\"},\n {mnesia,\"MNESIA CXC 138 12\",\"4.5\"},\n {amqp_client,\"RabbitMQ AMQP Client\",\"3.1.5\"},\n {sasl,\"SASL CXC 138 11\",\"2.1.10\"},\n {stdlib,\"ERTS CXC 138 10\",\"1.17.5\"},\n {kernel,\"ERTS CXC 138 10\",\"2.14.5\"}]},\n {os,{unix,linux}},\n {erlang_version,\n \"Erlang R14B04 (erts-5.8.5) [source] [64-bit] [rq:1] [async-threads:30] [kernel-poll:true]\\n\"},\n {memory,\n [{total,179426464},\n {connection_procs,300224},\n {queue_procs,14434024},\n {plugins,474968},\n {other_proc,9607952},\n {mnesia,89264},\n {mgmt_db,1539936},\n {msg_index,85175152},\n {other_ets,29060560},\n {binary,18243208},\n {code,17504466},\n {atom,1602617},\n {other_system,1394093}]},\n {vm_memory_high_watermark,0.4},\n {vm_memory_limit,1522479923},\n {disk_free_limit,1000000000},\n {disk_free,58396659712},\n {file_descriptors,\n [{total_limit,924},{total_used,17},{sockets_limit,829},{sockets_used,4}]},\n {processes,[{limit,1048576},{used,233}]},\n {run_queue,0},\n {uptime,5169640}]\n```\n\nIt looks like JSON, but it's not.\n\nWhat data format is this? And how did you find out? \n\nClosest thing I can find is this: http://erlang.org/doc/man/yecc.html\n\n========================================\n\nTop Answer:\nrather than querying the rabbitctrl process I suggest querying the REST api which will return JSON.\n\n```\nGET: http://localhost:15672/api/overview\n```\n\nHere is the documentation:\n\nhttp://hg.rabbitmq.com/rabbitmq-management/raw-file/3646dee55e02/priv/www-api/help.html\n\n========================================\n\nCode:\n```text\nsudo rabbitmqctl status\n```\n\n```text\n[{pid,18665},\n {running_applications,\n [{rabbitmq_management,\"RabbitMQ Management Console\",\"3.1.5\"},\n {rabbitmq_web_dispatch,\"RabbitMQ Web Dispatcher\",\"3.1.5\"},\n {webmachine,\"webmachine\",\"1.10.3-rmq3.1.5-gite9359c7\"},\n {mochiweb,\"MochiMedia Web Server\",\"2.7.0-rmq3.1.5-git680dba8\"},\n {rabbitmq_management_agent,\"RabbitMQ Management Agent\",\"3.1.5\"},\n {rabbit,\"RabbitMQ\",\"3.1.5\"},\n {os_mon,\"CPO CXC 138 46\",\"2.2.7\"},\n {inets,\"INETS CXC 138 49\",\"5.7.1\"},\n {xmerl,\"XML parser\",\"1.2.10\"},\n {mnesia,\"MNESIA CXC 138 12\",\"4.5\"},\n {amqp_client,\"RabbitMQ AMQP Client\",\"3.1.5\"},\n {sasl,\"SASL CXC 138 11\",\"2.1.10\"},\n {stdlib,\"ERTS CXC 138 10\",\"1.17.5\"},\n {kernel,\"ERTS CXC 138 10\",\"2.14.5\"}]},\n {os,{unix,linux}},\n {erlang_version,\n \"Erlang R14B04 (erts-5.8.5) [source] [64-bit] [rq:1] [async-threads:30] [kernel-poll:true]\\n\"},\n {memory,\n [{total,179426464},\n {connection_procs,300224},\n {queue_procs,14434024},\n {plugins,474968},\n {other_proc,9607952},\n {mnesia,89264},\n {mgmt_db,1539936},\n {msg_index,85175152},\n {other_ets,29060560},\n {binary,18243208},\n {code,17504466},\n {atom,1602617},\n {other_system,1394093}]},\n {vm_memory_high_watermark,0.4},\n {vm_memory_limit,1522479923},\n {disk_free_limit,1000000000},\n {disk_free,58396659712},\n {file_descriptors,\n [{total_limit,924},{total_used,17},{sockets_limit,829},{sockets_used,4}]},\n {processes,[{limit,1048576},{used,233}]},\n {run_queue,0},\n {uptime,5169640}]\n```\n\n```text\nsudo rabbitmqctl status --formatter json | jq .disk_free_limit\n50000000\n```\n\n```text\nrabbitmqctl\n```\n\n```text\n--formatter\n```\n\n```text\nGET: http://localhost:15672/api/overview\n```\n\n```text\nfrom erl_terms import decode\nfrom os import getuid\nfrom re import sub\nfrom subprocess import check_output\n\n\ncheck_command = ['/usr/sbin/rabbitmqctl', '-q', 'status']\n\nif getuid() != 0:\n check_command.insert(0, '/usr/bin/sudo')\n\nstatus = check_output(check_command)\n\n## Join into a single line string then add a period at the end to make it a valid erlang term\nstatus = ''.join(status.splitlines()) + '.'\n# Remove any literal \\n's since the erlang_version item has one in it\nstatus = sub('(?:\\\\\\\\n)+', '', status)\n\n# Decode this into a python object\nstatus = decode(status)\n\n# And now let's find just mem_stat for mgmt_db\nfor item in status[0]:\n if 'memory' in item:\n for mem_stat in item[1]:\n if 'mgmt_db' in mem_stat:\n print mem_stat[1]\n```\n\n```text\nrabbitmqctl\n```\n\n```text\nimport re\nimport subprocess\nimport yaml\n\n\ndef fix_dicts(json_str_list, pos):\n '''this recursive function puts all comma-separted values into square\n brackets to make data look like normal 'key: value' dicts'''\n quoted_string = False\n value = True\n value_pos = 0\n commas = False\n is_list = False\n in_list = 0\n while pos < len(json_str_list):\n if not quoted_string:\n if json_str_list[pos] == '{':\n json_str_list, pos = fix_dicts(json_str_list, pos+1)\n elif json_str_list[pos] == '\"':\n quoted_string = True\n elif json_str_list[pos] == ':':\n value = True\n value_pos = pos + 1\n elif json_str_list[pos] == '[':\n if value and not commas:\n is_list = True\n in_list += 1\n elif json_str_list[pos] == ']':\n in_list -= 1\n elif json_str_list[pos] == ',':\n commas = True\n if not in_list:\n is_list = False\n elif json_str_list[pos] == '}':\n if not is_list and commas:\n json_str_list = (json_str_list[:value_pos] + ['['] +\n json_str_list[value_pos:pos] + [']'] +\n json_str_list[pos:])\n pos += 2\n return json_str_list, pos\n elif json_str_list[pos] == '\"':\n quoted_string = False\n pos += 1\n return json_str_list, pos\n\n\ndef squash_dicts(input_data):\n # recursively converts [{a:1},{b:2},{c:3}...] into {a:1, b:2, c:3}'''\n if type(input_data) is list:\n for i in range(len(input_data)):\n input_data[i] = squash_dicts(input_data[i]) \n if all([type(e) is dict for e in input_data]):\n input_data = dict([(k,v) for e in input_data for k,v in e.items()])\n elif type(input_data) is dict:\n for k, v in input_data.items():\n input_data[k] = squash_dicts(v)\n return input_data\n\n\ntext = subprocess.check_output(['rabbitmqctl','status'])\ntext = text.splitlines()\ntext = text[1:] # skip the first line \"Status of node...\"\ntext = ''.join(text) # back into string for regex processing\n# quote strings\nbad_yaml = re.sub(r'([,{])([a-z_A-Z]+)([,}])', r'\\1\"\\2\"\\3', text)\n# change first element into a key - replacing ',' with ':'\nbad_yaml = re.sub(r'({[^,]+),',r'\\1:', bad_yaml)\nbad_yaml_list = list(bad_yaml) # into a list for another fix\ngood_yaml, _ = fix_dicts(bad_yaml_list, 0)\nstatus_list = yaml.load(''.join(good_yaml))\nstatus_dict = squash_dicts(status_list)\n# now we can use \"status_dict\" - it's an ordinary dict\nprint(yaml.safe_dump(status_dict, default_flow_style=False))\n```\n\n```text\n// assume file RmqStatus.txt includes the outputof the rabbitmqctl status command and that the node name is 'serverx'\nvar statusLines = File.ReadAllText(\"RmqStatus.txt\");\nRabbitStatusParser parser = new RabbitStatusParser();\nvar res = parser.ParseText(statusLines.Replace(Environment.NewLine,string.Empty)); \nvar keyWord1 = \"Status of node 'serverx@serverx'.memory.mgmt_db\"\nvar mgmtDbMem = res[keyWord1];\nvar keyWord2 = \"Status of node 'serverx@serverx'.file_descriptors.sockets_used\"\nvar socketsUsed = res[keyWord2];\n```\n\n========================================\n\nComments:\n- It's erlang's property list. Erlang's equivalent of dictionary.\n- link has broken\n- For convenience table, csv options are there.","metadata":{"transformedAt":"2026-08-18T18:33:20.329Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":275,"estimatedTokens":2078}}1160{"id":"stack-1878306","source":"stackoverflow","questionId":1878306,"title":"RabbitMQ gives a \"access refused, login refused for user\" error when attempting to the celery tutorial","tags":["python","django","rabbitmq","amqp","celery"],"text":"Title: RabbitMQ gives a \"access refused, login refused for user\" error when attempting to the celery tutorial\nTags: python, django, rabbitmq, amqp, celery\nSource: Stack Overflow\n\nQuestion:\nI'm attempting to the celery tutorial, but I run into a problem when I run `python manage.py celeryd`: my RabbitMQ server (installed on a virtual machine on my dev box) won't let my user login.\n\nI get the following on my Django management console:\n\n```\n[ERROR/MainProcess] AMQP Listener: Connection Error: Socket closed. Trying again in 2 seconds...\n```\n\nand this shows up in my `rabbit.log` file on my RabbitMQ server:\n\n```\nexception on TCP connection from $DJANGO_BOX_IP\n{channel0_error,starting,{amqp,access_refused,\"login refused for user '$CONFIGURED_USER'\",'connection.start_ok'}}\n```\n\nI've double-checked my user, permissions, and vhost info, and they all seem to match up. Any help troubleshooting is greatly appreciated.\n\nUPDATE: Following the advice of @asksol I get the following traceback:\n\n```\n$MY_VIRTUAL_ENV/lib/python2.6/site-packages/carrot/connection.pyc in connection(self)\n 118 return\n 119 if not self._connection:\n--> 120 self._connection = self._establish_connection()\n 121 self._closed = False\n 122 return self._connection\n\n$MY_VIRTUAL_ENV/lib/python2.6/site-packages/carrot/connection.pyc in _establish_connection(self)\n 131 \n 132 def _establish_connection(self):\n--> 133 return self.create_backend().establish_connection()\n 134 \n 135 def get_backend_cls(self):\n\n$MY_VIRTUAL_ENV/lib/python2.6/site-packages/carrot/backends/pyamqplib.pyc in establish_connection(self)\n 110 insist=conninfo.insist,\n 111 ssl=conninfo.ssl,\n--> 112 connect_timeout=conninfo.connect_timeout)\n 113 \n 114 def close_connection(self, connection):\n\n$MY_VIRTUAL_ENV/lib/python2.6/site-packages/amqplib/client_0_8/connection.pyc in __init__(self, host, userid, password, login_method, login_response, virtual_host, locale, client_properties, ssl, insist, connect_timeout, **kwargs)\n 138 self.wait(allowed_methods=[\n 139 (10, 20), # secure\n--> 140 (10, 30), # tune\n 141 ])\n 142 \n\n$MY_VIRTUAL_ENV/lib/python2.6/site-packages/amqplib/client_0_8/abstract_channel.pyc in wait(self, allowed_methods)\n 88 method_sig, args, content = self.connection._wait_method(\n---> 89 self.channel_id, allowed_methods)\n 90 \n 91 if content \\\n\n$MY_VIRTUAL_ENV/lib/python2.6/site-packages/amqplib/client_0_8/connection.pyc in _wait_method(self, channel_id, allowed_methods)\n 196 while True:\n 197 channel, method_sig, args, content = \\\n--> 198 self.method_reader.read_method()\n 199 \n 200 if (channel == channel_id) \\\n\n$MY_VIRTUAL_ENV/lib/python2.6/site-packages/amqplib/client_0_8/method_framing.pyc in read_method(self)\n 213 m = self.queue.get()\n 214 if isinstance(m, Exception):\n--> 215 raise m\n 216 return m\n 217 \n\nIOError: Socket closed\n```\n\n========================================\n\nCode:\n```text\n[ERROR/MainProcess] AMQP Listener: Connection Error: Socket closed. Trying again in 2 seconds...\n```\n\n```text\nexception on TCP connection <0.5814.0> from $DJANGO_BOX_IP\n{channel0_error,starting,{amqp,access_refused,\"login refused for user '$CONFIGURED_USER'\",'connection.start_ok'}}\n```\n\n```text\n$MY_VIRTUAL_ENV/lib/python2.6/site-packages/carrot/connection.pyc in connection(self)\n 118 return\n 119 if not self._connection:\n--> 120 self._connection = self._establish_connection()\n 121 self._closed = False\n 122 return self._connection\n\n$MY_VIRTUAL_ENV/lib/python2.6/site-packages/carrot/connection.pyc in _establish_connection(self)\n 131 \n 132 def _establish_connection(self):\n--> 133 return self.create_backend().establish_connection()\n 134 \n 135 def get_backend_cls(self):\n\n$MY_VIRTUAL_ENV/lib/python2.6/site-packages/carrot/backends/pyamqplib.pyc in establish_connection(self)\n 110 insist=conninfo.insist,\n 111 ssl=conninfo.ssl,\n--> 112 connect_timeout=conninfo.connect_timeout)\n 113 \n 114 def close_connection(self, connection):\n\n$MY_VIRTUAL_ENV/lib/python2.6/site-packages/amqplib/client_0_8/connection.pyc in __init__(self, host, userid, password, login_method, login_response, virtual_host, locale, client_properties, ssl, insist, connect_timeout, **kwargs)\n 138 self.wait(allowed_methods=[\n 139 (10, 20), # secure\n--> 140 (10, 30), # tune\n 141 ])\n 142 \n\n$MY_VIRTUAL_ENV/lib/python2.6/site-packages/amqplib/client_0_8/abstract_channel.pyc in wait(self, allowed_methods)\n 88 method_sig, args, content = self.connection._wait_method(\n---> 89 self.channel_id, allowed_methods)\n 90 \n 91 if content \\\n\n$MY_VIRTUAL_ENV/lib/python2.6/site-packages/amqplib/client_0_8/connection.pyc in _wait_method(self, channel_id, allowed_methods)\n 196 while True:\n 197 channel, method_sig, args, content = \\\n--> 198 self.method_reader.read_method()\n 199 \n 200 if (channel == channel_id) \\\n\n$MY_VIRTUAL_ENV/lib/python2.6/site-packages/amqplib/client_0_8/method_framing.pyc in read_method(self)\n 213 m = self.queue.get()\n 214 if isinstance(m, Exception):\n--> 215 raise m\n 216 return m\n 217 \n\nIOError: Socket closed\n```\n\n```text\npython manage.py celeryd\n```\n\n```text\nrabbit.log\n```\n\n```text\n>>> from carrot.connection import DjangoBrokerConnection\n>>> c = DjangoBrokerConnection()\n>>> c.connection\n```\n\n```text\n>>> from carrot.connection import DjangoBrokerConnection\n>>> c = DjangoBrokerConnection()\n>>> for n in (\"host\", \"userid\", \"password\", \"virtual_host\", \"ssl\"):\n... print(\"%s -> %s\" % (n, repr(getattr(c, n, None))))\n```\n\n========================================\n\nComments:\n- I am running Django. Doing the above from the Django shell gives me a fairly long traceback and results in the following error: `IOError: Socket closed`. I'll update the question with the traceback.\n- Ok, There must be something in the configuration that is wrong, host, vhost, permissions, username, password and so on. See updates to my answer for more troubleshooting.\n- Thanks. The login info was wrong: I got my virtualhost value in the setting for the password.","metadata":{"transformedAt":"2026-08-18T18:33:20.329Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":7,"totalLines":167,"estimatedTokens":1584}}1161{"id":"stack-17302442","source":"stackoverflow","questionId":17302442,"title":"Celery - RabbitMQ - execution order","tags":["rabbitmq","celery","django-celery"],"text":"Title: Celery - RabbitMQ - execution order\nTags: rabbitmq, celery, django-celery\nSource: Stack Overflow\n\nQuestion:\nIm running some long tasks where I need to ensure that the queued tasks execute in order of reception. What I've found in my first tests is that when I reach the max number of workers (CELERYD_CONCURRENCY), the following tasks that are sent are queued, and then the first of those to be executed is actually the latest one to be received. \n\nOf course the opposite behavior is what Im after, that the oldest messages are the first to be executed when there is a free worker.\n\nWhat is the explanation for this behavior and how can it be changed?","metadata":{"transformedAt":"2026-08-18T18:33:20.329Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":10,"estimatedTokens":165}}1162{"id":"stack-67400962","source":"stackoverflow","questionId":67400962,"title":"How to restart rabbitmq inside docker","tags":["docker","rabbitmq"],"text":"Title: How to restart rabbitmq inside docker\nTags: docker, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am using rabbitmq docker image https://hub.docker.com/_/rabbitmq\nI wanted to make changes in rabbitmq.conf file inside container for testing a config, so I tried\n\n```\nrabbitmqctl stop\n```\n\nafter making the changes. But this stops the whole docker container.\nI even tried\n\n```\nrabbitmq-server restart\n```\n\nbut that too doesn't work saying ports are in use.\nHow do I restart the service without restarting the whole container?\n\n========================================\n\nCode:\n```text\nrabbitmqctl stop\n```\n\n```text\nrabbitmq-server restart\n```\n\n```text\n# Copy config from the container to your machine\ndocker cp <insert container name>:/etc/rabbitmq/rabbitmq.config .\n\n# (optional) make changes to the copied rabbitmq.config\n...\n\n# Start a new container with the config mounted inside (substitute /host/path\n# with a full path to your local config file)\ndocker run -v /host/path/rabbitmq.config:/etc/rabbitmq/rabbitmq.config <insert image name here>\n\n# Now local config appears inside the container and so all changes \n# are available immediately. You can restart the container to restart the application.\n```\n\n```text\nrabbimq\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.329Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":51,"estimatedTokens":308}}1163{"id":"stack-62888633","source":"stackoverflow","questionId":62888633,"title":"ACCESS_REFUSED - Login was refused using authentication mechanism AMQPLAIN","tags":["php","linux","server","rabbitmq","laravel-7"],"text":"Title: ACCESS_REFUSED - Login was refused using authentication mechanism AMQPLAIN\nTags: php, linux, server, rabbitmq, laravel-7\nSource: Stack Overflow\n\nQuestion:\nWe got an error form laravel 7, when rabbitMQ Connection in server.\nThe same server Laravel 5.8 working fine, We use same login details\nfor both 5.8 and 7. But 7 version only we that issue\n\nACCESS_REFUSED - Login was refused using the authentication mechanism AMQPLAIN. For details see the broker logfile.(0, 0) vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php:745\n\n========================================\n\nTop Answer:\nI also got this error, and just to clarify the OP's answer, it was an issue with authentication.. Double check your credentials and connection parameters (username, password, host, port, vhost, etc...).","metadata":{"transformedAt":"2026-08-18T18:33:20.330Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":0,"totalLines":15,"estimatedTokens":203}}1164{"id":"stack-69042598","source":"stackoverflow","questionId":69042598,"title":"Why consume method does not execute using MassTransit, RabbitMQ broker and .Net in a microservice-based application?","tags":["c#",".net","rabbitmq","microservices","masstransit"],"text":"Title: Why consume method does not execute using MassTransit, RabbitMQ broker and .Net in a microservice-based application?\nTags: c#, .net, rabbitmq, microservices, masstransit\nSource: Stack Overflow\n\nQuestion:\nI am building a microservice-based application that contains two microservices which are communicating over a RabbitMQ broker. An event is published whenever a book is created, updated or deleted. Publishing from the first microservice is working fine, but nothing is consumed in the other microservice. Nothing is put into the queues although the queues are up and running. I am using MassTransit and RabbitMQ with a .Net application using Visual Studio 2019. The following is my configurations code in Startup.cs\n\n```\nservices.AddMassTransit(x =>\n {\n x.AddConsumer();\n x.AddConsumer();\n x.AddConsumer();\n\n x.UsingRabbitMq((context, configurator) =>\n {\n var rabbitMQSettings = Configuration.GetSection(nameof(RabbitMQSettings)).Get();\n configurator.Host(rabbitMQSettings.Host);\n\n configurator.ReceiveEndpoint(\"BookCreation-Queue\", c =>\n {\n c.ConfigureConsumer(context);\n });\n\n configurator.ReceiveEndpoint(\"BookUpdating-Queue\", c =>\n {\n c.ConfigureConsumer(context);\n });\n\n configurator.ReceiveEndpoint(\"BookDeletion-Queue\", c =>\n {\n c.ConfigureConsumer(context);\n });\n });\n });\n \n services.AddMassTransitHostedService();\n```\n\nI Implemented the consumer classes to inherit from IConsumer MassTransit interface. Even though, the receiver microservice is not consuming messages. Consume method is not hit at all! The following is the code for the creation event consumer:\n\n```\npublic class BookCreationConsumer : IConsumer\n{\n private readonly IBooksInfoRepository repository;\n\n public BookCreationConsumer(IBooksInfoRepository repository)\n {\n this.repository = repository;\n }\n\n public async Task Consume(ConsumeContext context)\n {\n var message = context.Message;\n\n var book = await repository.GetBookInfo(message.BookID);\n\n if (book != null)\n return;\n\n book = new BookInfo\n {\n id = message.BookID,\n Title = message.Title,\n Author = message.Author,\n Edition = message.Edition,\n NumberOfPages = message.NumOfPages,\n BookURL = message.BookURL \n };\n\n await repository.AddBookInfo(book);\n }\n```\n\nWhat could be the cause for the non-consuming of messages?\n\nThanks\n\n========================================\n\nCode:\n```text\nservices.AddMassTransit(x =>\n {\n x.AddConsumer<BookCreationConsumer>();\n x.AddConsumer<BookUpdatingConsumer>();\n x.AddConsumer<BookDeletionConsumer>();\n\n x.UsingRabbitMq((context, configurator) =>\n {\n var rabbitMQSettings = Configuration.GetSection(nameof(RabbitMQSettings)).Get<RabbitMQSettings>();\n configurator.Host(rabbitMQSettings.Host);\n\n configurator.ReceiveEndpoint(\"BookCreation-Queue\", c =>\n {\n c.ConfigureConsumer<BookCreationConsumer>(context);\n });\n\n configurator.ReceiveEndpoint(\"BookUpdating-Queue\", c =>\n {\n c.ConfigureConsumer<BookUpdatingConsumer>(context);\n });\n\n configurator.ReceiveEndpoint(\"BookDeletion-Queue\", c =>\n {\n c.ConfigureConsumer<BookDeletionConsumer>(context);\n });\n });\n });\n \n services.AddMassTransitHostedService();\n```\n\n```text\npublic class BookCreationConsumer : IConsumer<BookCreationEvent>\n{\n private readonly IBooksInfoRepository repository;\n\n public BookCreationConsumer(IBooksInfoRepository repository)\n {\n this.repository = repository;\n }\n\n public async Task Consume(ConsumeContext<BookCreationEvent> context)\n {\n var message = context.Message;\n\n var book = await repository.GetBookInfo(message.BookID);\n\n if (book != null)\n return;\n\n book = new BookInfo\n {\n id = message.BookID,\n Title = message.Title,\n Author = message.Author,\n Edition = message.Edition,\n NumberOfPages = message.NumOfPages,\n BookURL = message.BookURL \n };\n\n await repository.AddBookInfo(book);\n }\n```\n\n========================================\n\nComments:\n- If you have RabbitMQ Management Plugin installed you can check the queue mappings there.\n- Yes you are right Mr. Alexey. I used different namespaces for the publisher and the consumer contracts, that is why the binding was incorrect between them. Now it is working fine. Thank you so much, I really appreciate your help.","metadata":{"transformedAt":"2026-08-18T18:33:20.330Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":151,"estimatedTokens":1150}}1165{"id":"stack-66173551","source":"stackoverflow","questionId":66173551,"title":"Configure TCP Port on Nginx Ingress on Azure Kubernetes Cluster (AKS)","tags":["nginx","kubernetes","rabbitmq","azure-aks","nginx-ingress"],"text":"Title: Configure TCP Port on Nginx Ingress on Azure Kubernetes Cluster (AKS)\nTags: nginx, kubernetes, rabbitmq, azure-aks, nginx-ingress\nSource: Stack Overflow\n\nQuestion:\nI need to configure a TCP port on my AKS Cluster to allow RabbitMQ to work\n\nI have installed nginx-ingress with helm as follows:\n\n```\nkubectl create namespace ingress-basic\n\nhelm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx\n\nhelm install nginx-ingress ingress-nginx/ingress-nginx \\\n --namespace ingress-basic \\\n --set controller.replicaCount=2 \\\n --set controller.nodeSelector.\"beta\\.kubernetes\\.io/os\"=linux \\\n --set defaultBackend.nodeSelector.\"beta\\.kubernetes\\.io/os\"=linux \\\n --set controller.admissionWebhooks.patch.nodeSelector.\"beta\\.kubernetes\\.io/os\"=linux\n```\n\nI have setup an A record with our DNS provider to point to the public IP of the ingress controller.\n\nI have created a TLS secret (to enable https)\n\nI have created an ingress route with:\n\n```\napiVersion: networking.k8s.io/v1beta1\nkind: Ingress\nmetadata:\n name: rabbit-ingress\n namespace: default\n annotations:\n kubernetes.io/ingress.class: nginx\n nginx.ingress.kubernetes.io/use-regex: \"true\"\n nginx.ingress.kubernetes.io/rewrite-target: /$1\nspec:\n tls:\n - hosts:\n - my.domain.com\n secretName: tls-secret\n rules:\n - http:\n paths:\n - backend:\n serviceName: rabbitmq-cluster\n servicePort: 15672\n path: /(.*)\n```\n\nI can navigate to my cluster via the domain name from outside and see the control panel (internally on 15672) with valid https. So the ingress is up and running, and I can create queues etc... so rabbitmq is working correctly.\n\nHowever, I can't get the TCP part to work to post to the queues from outside the cluster.\n\nI have edited the yaml of the what I believe is the configmap (azure - cluster - configuration - nginx-ingress-ingress-nginx-controller) for the controller (nginx-ingress-ingress-nginx-controller) via the azure portal interface and added this to the end\n\n```\ndata:\n '5672': 'default/rabbitmq-cluster:5672'\n```\n\nI have then edited they yaml for the service itself via the azure portal and added this to the end\n\n```\n- name: amqp\n protocol: TCP\n port: 5672\n```\n\nHowever, when I try to hit my domain using a test client the request just times out. (The client worked when I used a LoadBalancer and just hit the external IP of the cluster, so I know the client code should work)\n\nIs there another step that I should be doing?\n\n========================================\n\nCode:\n```text\nkubectl create namespace ingress-basic\n\nhelm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx\n\nhelm install nginx-ingress ingress-nginx/ingress-nginx \\\n --namespace ingress-basic \\\n --set controller.replicaCount=2 \\\n --set controller.nodeSelector.\"beta\\.kubernetes\\.io/os\"=linux \\\n --set defaultBackend.nodeSelector.\"beta\\.kubernetes\\.io/os\"=linux \\\n --set controller.admissionWebhooks.patch.nodeSelector.\"beta\\.kubernetes\\.io/os\"=linux\n```\n\n```yaml\napiVersion: networking.k8s.io/v1beta1\nkind: Ingress\nmetadata:\n name: rabbit-ingress\n namespace: default\n annotations:\n kubernetes.io/ingress.class: nginx\n nginx.ingress.kubernetes.io/use-regex: \"true\"\n nginx.ingress.kubernetes.io/rewrite-target: /$1\nspec:\n tls:\n - hosts:\n - my.domain.com\n secretName: tls-secret\n rules:\n - http:\n paths:\n - backend:\n serviceName: rabbitmq-cluster\n servicePort: 15672\n path: /(.*)\n```\n\n```yaml\ndata:\n '5672': 'default/rabbitmq-cluster:5672'\n```\n\n```yaml\n- name: amqp\n protocol: TCP\n port: 5672\n```\n\n```yaml\nhelm install nginx-ingress ingress-nginx/ingress-nginx \\\n --namespace ingress-basic \\\n --set controller.replicaCount=2 \\\n --set controller.nodeSelector.\"beta\\.kubernetes\\.io/os\"=linux \\\n --set defaultBackend.nodeSelector.\"beta\\.kubernetes\\.io/os\"=linux \\\n --set controller.admissionWebhooks.patch.nodeSelector.\"beta\\.kubernetes\\.io/os\"=linux \\\n --set tcp.5672=\"default/rabbitmq-cluster:5672\"\n```\n\n```yaml\napiVersion: networking.k8s.io/v1\nkind: Ingress\nmetadata:\n name: rabbit-ingress\n namespace: default\n annotations:\n kubernetes.io/ingress.class: nginx\n nginx.ingress.kubernetes.io/use-regex: \"true\"\n nginx.ingress.kubernetes.io/rewrite-target: /$1\nspec:\n tls:\n - hosts:\n - my.domain.com\n secretName: tls-secret\n rules:\n - host: my.domain.com\n http:\n paths:\n - path: /(.*)\n pathType: Prefix\n backend:\n service:\n name: rabbitmq-cluster\n port:\n number: 15672\n```\n\n========================================\n\nComments:\n- @MarkMcGooking Hi Mark can you please help me I am facing similar issue, and I will try your approach to re-install using the helm. But I need to preserve the same External IP for my Ingress C. Service- how I can do it? Because for that IP on Azure they configured reverse proxy to be accessible from outside since AKS cluster is not reachable. Could you please assist me on this?I would try `helm install nginx-ingress ... --set tcp.9000=\"default/serviceName:9000` stackoverflow.com/questions/66190275/…\n- I have run: `helm upgrade nginx-ingress ingress-nginx/ingress-nginx -f internal-ingress.yaml --set tcp.9000=\"default/frontarena-ads-aks-test:9000\"` but still cannot access my service...\n- @MarkMcGooking can you please check on my question and to see if I am doing something wrong? I really checked many aspects and it seems to me they are working.\n- @AndreyDonald - I’m no expert on this myself, hence the question. Are you sure your service is accessible on that port? You could try port forwarding to your local machine with kubectl (kubernetes.io/docs/tasks/access-application-cluster/…) to ensure that everything is working on 9000 to start with. You can go into azure > cluster and look at the config yaml files for everything (and edit them) maybe there is some clue in there?\n- Cheers for this that helped me massively. Sorry to hijack but do you know if there is a way I can limit what IP's have access to this port? What I would like to do is make sure only internal services can access the port, while still enabling ports 80 and 443.","metadata":{"transformedAt":"2026-08-18T18:33:20.330Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":172,"estimatedTokens":1548}}1166{"id":"stack-12458175","source":"stackoverflow","questionId":12458175,"title":"MassTransit Losing Messages - Rabbit MQ - When publisher and consumer endpoint names are the same,","tags":["rabbitmq","masstransit"],"text":"Title: MassTransit Losing Messages - Rabbit MQ - When publisher and consumer endpoint names are the same,\nTags: rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nWe've encountered a situation where MassTransit is losing messages if you create a publisher and consumer using the same endpoint name.\n\nNote the code below; if I use a different endpoint name for either the consumer or publisher (e.g. \"rabbitmq://localhost/mtlossPublised\" for the publisher) then the message counts both published and consumed match; if I use the same endpoint name (as in the sample) then I get less messages consumed than published.\n\nIs this expected behaviour? or am I doing something wrong, working sample code below.\n\n```\nusing MassTransit;\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace MTMessageLoss\n{\n class Program\n {\n static void Main(string[] args)\n {\n var consumerBus = ServiceBusFactory.New(b =>\n {\n b.UseRabbitMq();\n b.UseRabbitMqRouting();\n b.ReceiveFrom(\"rabbitmq://localhost/mtloss\");\n });\n var publisherBus = ServiceBusFactory.New(b =>\n {\n b.UseRabbitMq();\n b.UseRabbitMqRouting();\n b.ReceiveFrom(\"rabbitmq://localhost/mtloss\");\n });\n consumerBus.SubscribeConsumer(() => new MessageConsumer());\n for (int i = 0; i \n {\n string Message { get; }\n }\n public class SimpleMessage : ISimpleMessage\n {\n public Guid CorrelationId { get; set; }\n public string Message { get; set; }\n }\n public class MessageConsumer : Consumes.All\n {\n public static int Count = 0;\n public void Consume(ISimpleMessage message)\n {\n System.Threading.Interlocked.Increment(ref Count);\n }\n }\n}\n```\n\n========================================\n\nTop Answer:\nWhat's happening is that in giving the same Receiver Uri you're telling MT to load balance consumption on the two busses, however you've only one bus listening to the messages.\n\nIf you get it to keep track of *which* messages are received you'll see it's (nearly) every second one.\n\nHaving tweaked your sample code I get\n\n```\nWe consumed 6 simple messages. Press Enter to terminate the applicaion.\nReceived 0\nReceived 3\nReceived 5\nReceived 6\nReceived 7\nReceived 8\n```\n\nStart a consumer on the other bus and you'll get them all\n\n```\nWe consumed 10 simple messages. Press Enter to terminate the applicaion.\nReceived 0\nReceived 1\nReceived 2\nReceived 3\nReceived 4\nReceived 5\nReceived 6\nReceived 7\nReceived 8\nReceived 9\n```\n\n**So yes, I'd say this is expected behaviour.**\n\nHere's the tweaked sample code with two subscribers\n\n```\nusing MassTransit;\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace MTMessageLoss\n{\n class Program\n {\n internal static bool[] msgReceived = new bool[10];\n static void Main(string[] args)\n {\n var consumerBus = ServiceBusFactory.New(b =>\n {\n b.UseRabbitMq();\n b.UseRabbitMqRouting();\n b.ReceiveFrom(\"rabbitmq://localhost/mtloss\");\n });\n var publisherBus = ServiceBusFactory.New(b =>\n {\n b.UseRabbitMq();\n b.UseRabbitMqRouting();\n b.ReceiveFrom(\"rabbitmq://localhost/mtloss\");\n });\n publisherBus.SubscribeConsumer(() => new MessageConsumer());\n consumerBus.SubscribeConsumer(() => new MessageConsumer());\n for (int i = 0; i \n {\n int MsgId { get; }\n }\n public class SimpleMessage : ISimpleMessage\n {\n public Guid CorrelationId { get; set; }\n public int MsgId { get; set; }\n }\n public class MessageConsumer : Consumes.All\n {\n public static int Count = 0;\n public void Consume(ISimpleMessage message)\n {\n Program.msgReceived[message.MsgId] = true;\n System.Threading.Interlocked.Increment(ref Count);\n }\n }\n}\n```\n\n========================================\n\nCode:\n```text\nusing MassTransit;\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace MTMessageLoss\n{\n class Program\n {\n static void Main(string[] args)\n {\n var consumerBus = ServiceBusFactory.New(b =>\n {\n b.UseRabbitMq();\n b.UseRabbitMqRouting();\n b.ReceiveFrom(\"rabbitmq://localhost/mtloss\");\n });\n var publisherBus = ServiceBusFactory.New(b =>\n {\n b.UseRabbitMq();\n b.UseRabbitMqRouting();\n b.ReceiveFrom(\"rabbitmq://localhost/mtloss\");\n });\n consumerBus.SubscribeConsumer(() => new MessageConsumer());\n for (int i = 0; i < 10; i++)\n publisherBus.Publish(new SimpleMessage() { CorrelationId = Guid.NewGuid(), Message = string.Format(\"This is message {0}\", i) });\n Console.WriteLine(\"Press ENTER Key to see how many you consumed\");\n Console.ReadLine();\n Console.WriteLine(\"We consumed {0} simple messages. Press Enter to terminate the applicaion.\", MessageConsumer.Count);\n Console.ReadLine();\n consumerBus.Dispose();\n publisherBus.Dispose();\n }\n }\n public interface ISimpleMessage : CorrelatedBy<Guid>\n {\n string Message { get; }\n }\n public class SimpleMessage : ISimpleMessage\n {\n public Guid CorrelationId { get; set; }\n public string Message { get; set; }\n }\n public class MessageConsumer : Consumes<ISimpleMessage>.All\n {\n public static int Count = 0;\n public void Consume(ISimpleMessage message)\n {\n System.Threading.Interlocked.Increment(ref Count);\n }\n }\n}\n```\n\n```text\nWe consumed 6 simple messages. Press Enter to terminate the applicaion.\nReceived 0\nReceived 3\nReceived 5\nReceived 6\nReceived 7\nReceived 8\n```\n\n```text\nWe consumed 10 simple messages. Press Enter to terminate the applicaion.\nReceived 0\nReceived 1\nReceived 2\nReceived 3\nReceived 4\nReceived 5\nReceived 6\nReceived 7\nReceived 8\nReceived 9\n```\n\n```text\nusing MassTransit;\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace MTMessageLoss\n{\n class Program\n {\n internal static bool[] msgReceived = new bool[10];\n static void Main(string[] args)\n {\n var consumerBus = ServiceBusFactory.New(b =>\n {\n b.UseRabbitMq();\n b.UseRabbitMqRouting();\n b.ReceiveFrom(\"rabbitmq://localhost/mtloss\");\n });\n var publisherBus = ServiceBusFactory.New(b =>\n {\n b.UseRabbitMq();\n b.UseRabbitMqRouting();\n b.ReceiveFrom(\"rabbitmq://localhost/mtloss\");\n });\n publisherBus.SubscribeConsumer(() => new MessageConsumer());\n consumerBus.SubscribeConsumer(() => new MessageConsumer());\n for (int i = 0; i < 10; i++)\n consumerBus.Publish(new SimpleMessage()\n {CorrelationId = Guid.NewGuid(), MsgId = i});\n Console.WriteLine(\"Press ENTER Key to see how many you consumed\");\n Console.ReadLine();\n Console.WriteLine(\"We consumed {0} simple messages. Press Enter to terminate the applicaion.\",\n MessageConsumer.Count);\n for (int i = 0; i < 10; i++)\n if (msgReceived[i])\n Console.WriteLine(\"Received {0}\", i);\n Console.ReadLine();\n consumerBus.Dispose();\n publisherBus.Dispose();\n\n }\n }\n public interface ISimpleMessage : CorrelatedBy<Guid>\n {\n int MsgId { get; }\n }\n public class SimpleMessage : ISimpleMessage\n {\n public Guid CorrelationId { get; set; }\n public int MsgId { get; set; }\n }\n public class MessageConsumer : Consumes<ISimpleMessage>.All\n {\n public static int Count = 0;\n public void Consume(ISimpleMessage message)\n {\n Program.msgReceived[message.MsgId] = true;\n System.Threading.Interlocked.Increment(ref Count);\n }\n }\n}\n```\n\n========================================\n\nComments:\n- OK That does explain it to a degree; but there were no subscriptions in the original sample on the publisher bus; so they could never have been consumed by the publisher bus anyway so why load balance. Also I'm not sure you explanation stacks up; because those messages should never have been lost; they should always have been consumed. In our example there was only one consumer; the endpoint configuration should not determine load balancing; it's the registered consumers that should determine that.\n- It's not the bus instance that consumptions get associated with, it's the Receiver URI (which is how MT gives you load balancing across services in the first place). It makes perfect sense to me that MT would see this configuration and say \"Ah I have two instances of the same bus (same Uri), and I've been told that that *type* of bus consumes message x, ergo I'll load balance the messages between them\". tl;dr **If you don't want to load balance two busses, give them different names**\n- If that is how MT does load balancing then I'll guess I'll just \"Have to suck that Lemon.\". But from a publishing perspective it does not make sense at all. The Publisher should not give a \"Monkeys Uncle\" who, what, when, where or how the message will be consumed; it should just Publish the damned thing. So we're now tying the consumer and publisher together using a URI; we means consumer logic in the publishing. Yuck!. Really the publishing URI should have no endpoint name other than how to connect to the queuing infrastructure.\n- I don't see how this ties the publisher and consumer together at all. You're tying two busses together by giving them the same Uri. MT assumes that both will have the same subscribers. The publisher **doesn't** give a monkeys who subscribes the message. Is your *real* problem here that you've to give a \"publish only\" bus a ReceiverUri? Also, I'm rationalising all the behaviour from what I've seen myself and what I've read in the docs. Really you should raise this on the MT Discussion group, Chris & Dru are very active and you'd probably get a canonical answer within 24 hours.\n- \"Is your real problem here that you've to give a \"publish only\" bus a ReceiverUri?\" Yes that is indeed the main issue; just does not make sense to me; unless like you say it's how MT does load balancing. But you'd think that would be just a bit of different configuration on the Consumer, rather than on the producer.\n- Even though there's no subscribers you registered, a bus will still read messages off the queue in an attempt to consume them. Which is why you were losing messages. This is the expected behaviour. All bus instances will read incase there's meta data need to be consumed. If you want to \"publish only\" then you need to write directly to a queue or exchange and not publish. There's notes on the mailing list about direct sends or in the Docs.\n- To be more instructional, it might be better if you kept track of which consumer consumed which message in the example, not sure which messages got consumed. But regardless you'll see the two consumers competing for messages.\n- @travis You say \"**Even though there's no subscribers registered, a bus will still read messages off the queue in an attempt to consume them**\". Ergo persistent consumers should always be registered as the bus is initialised?\n- @BinaryWorrier Yes, registering consumers as the bus is initialized is best. While you can dynamically register them, you could lose some messages that were already in the queue. It's why we support that in the configurator.\n- @travis Is it possible to retrieve the UnsubscribeAction if you register the bus and the consumer at the same time? I don't see a way to access it when I initialize them both together.\n- @mikebridge I don't think so. I'm still using an older version, I think you need to explicitly register the consumer to get the UnsubscribeAction. You can do *?temporary=true as the queue name to create a temp. queue for that consumer though.\n- @travis Thanks, I set it up to explicitly register the consumer after the bus is created. In this case I'm not worried about missing a message, but it would be nice to be able to initialize the bus, the consumer, and the unsubscribe token simultaneously.\n- That's a legitimate request, add an issue to github and maybe we can that in soon.\n- Travis, Binary Worrier. Thanks to you both for your inputs. Thanks for that link to the documentation Travis; I had not seen that before; and I had thought I had read all of the documentation on the site. All of it obviously did not sink in :)\n- @Bigtoe There's a lot to absorb, if you have any thoughts on how to make anything you missed the first time through more explicit, we'd be happy to hear your comments. Whatever can allow people easier access to MT is great.\n- Link is now dead","metadata":{"transformedAt":"2026-08-18T18:33:20.330Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":316,"estimatedTokens":3222}}1167{"id":"stack-55991826","source":"stackoverflow","questionId":55991826,"title":"How to gracefully stop consuming messages with @RabbitListener","tags":["java","spring","rabbitmq","spring-amqp","spring-rabbit"],"text":"Title: How to gracefully stop consuming messages with @RabbitListener\nTags: java, spring, rabbitmq, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nIs there a way to gracefully stop a `ListenerContainer`, and its associated `Consumers`.\n\n**What I'm trying to achieve.**\n\n- Stop consuming messages.\n\n- Gracefully stop `ListenerContainer`.\n\n- Await long running consumers, and ack when finished.\n\nI'm able to stop the `ListenerContainers` using `consumer.stop()`, but active long running consumers won't complete successfully, and processed messages won't be acked and will therefore be processed again, once the ListenerContainer has been resumed.\n\n**Output**\n\n```\nWaiting for workers to finish.\nWorkers not finished.\nClosing channel for unresponsive consumer: Consumer@6d229b1c\n```\n\nThe message was processed, but not acked.\n\nI might be able to achieve a graceful shutdown using `setForceCloseChannel(false)`, but is it possible to verify if the cancelled consumers has finished? SimpleMessageListenerContainer.doShutDown() has a local scoped List \"canceledConsumers\".\n\n========================================\n\nTop Answer:\nTo complete @user634545's last comment, we have to deal with 2 properties :\n\n- shutdownTimeout\n\n- prefetchCount\n\nThese parameters must be ajusted in order to validate the following :\n\n```\nprefetchCount It would mean that after receiving the shutdown order, the consumer should be able to consume and aknowledge every prefetched messages.\n\n========================================\n\nCode:\n```text\nWaiting for workers to finish.\nWorkers not finished.\nClosing channel for unresponsive consumer: Consumer@6d229b1c\n```\n\n```text\nListenerContainer\n```\n\n```text\nConsumers\n```\n\n```text\nListenerContainer\n```\n\n```text\nListenerContainers\n```\n\n```text\nconsumer.stop()\n```\n\n```text\nsetForceCloseChannel(false)\n```\n\n```text\n/**\n * The time to wait for workers in milliseconds after the container is stopped. If any\n * workers are active when the shutdown signal comes they will be allowed to finish\n * processing as long as they can finish within this timeout. Defaults\n * to 5 seconds.\n * @param shutdownTimeout the shutdown timeout to set\n */\npublic void setShutdownTimeout(long shutdownTimeout) {\n```\n\n```text\nforceStop\n```\n\n```text\nprefetchCount < (shutdownTimeout / consumerExecutionTimePerMessage)\n```\n\n========================================\n\nComments:\n- Thanks for the reply. Even with setShutdownTimeout, the last consumed message might not be acked. I believe the best option is to use setForceCloseChannel(false), but then I cannot determine if the canceled consumers has finished or not. I might have to extend the SimpleRabbitListenerContainerFactory, and re-implement/extend the SimpleMessageListenerContainer to get hold of the canceledConsumers.\n- `>Even with setShutdownTimeout, the last consumed message might not be acked` Why do you say that? Make the timeout a large value; `stop()` will block until the last consumer thread completes. You can add an `ApplicationListener` (or an `@EventListener`method) to get an event as each consumer thread exits). See Consumer Events. You can also set the force close to false as extra protection if you want.\n- No matter how high we set `setShutdownTimeout`, the consumer will continue to process newly arrived messages, until the timeout has been reached. So, if the consumer start processing a message just before the timeout has been reached, the message won't be acked. I can put together an example on github.\n- No it will not; `doShutdown()` cancels the consumer so no more messages will arrive for it. Furthermore, the consumer runs in a loop `while(isActive()...` and `shutDown()` sets `active` to false before calling `doShutDown()`.\n- You are correct, my mistake. The \"issue\" might only occur if the `setShutdownTimeout` is less than the initial `numberOfMessages` * `consumerExecutionTimePerMessage`. I'm fine with that. Thanks.\n- There is now a new property `forceStop` to stop the container after the current message is processed, requeueing other prefetched messages. docs.spring.io/spring-amqp/docs/current/reference/html/…\n- Shouldn't the formula be `prefetchCount < (shutdownTimeout / consumerExecutionTimePerMessage)`?\n- Absolutely, you're rigtht, I edit the formula.\n- There is now a new property `forceStop` to stop the container after the current message is processed, requeueing other prefetched messages. docs.spring.io/spring-amqp/docs/current/reference/html/…","metadata":{"transformedAt":"2026-08-18T18:33:20.330Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":10,"totalLines":107,"estimatedTokens":1122}}1168{"id":"stack-8439753","source":"stackoverflow","questionId":8439753,"title":"AMQP v.1.0 Exchange Definition missing","tags":["rabbitmq","amqp"],"text":"Title: AMQP v.1.0 Exchange Definition missing\nTags: rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI was reading RabbitMQ specification on the AMQP 0-9-1 implementation and followed along the examples from the tutorial page which were helpful on explaining Exchanges and Queues. \nThe new latest and major release of the AMQP spec v. 1.0 has been out for two months and according to this wikipedia article the definition of Exchange/fanout/direct/topic bindings have been removed. Here is the full spec for AMQP v1.0.\n\nI've been reading the full v1.0 spec but it's very technical and has no general explanation of how it can be used in a scenario for example a Producer and consumer application or how it's different from 0-10 and how to correlate the old Binding and Exchange notion to the new one.\n\nHow does all this Exchange functionality fit in the new protocol. If there are example usages with code example of some lib implementation that would be helpful.\n\n========================================\n\nComments:\n- Side note: the early access edition of RabbitMQ in Action is well worth reading if you want to get up to speed on RabbitMQ quickly.\n- I was wondering why the spec didn't have these specification. btw, I thought RabbitMQ latest one is 0-10 ( I realized that 1.0 is not the same as 1.0). So nodes would essentially send msgs to each other and each device that wants to send messages would have to be a node itself?\n- yes 0.10 is (not very popular) iteration of 0.9x protocol version, while 1.0 is completely different beast.\n- I also think that 1.0 will need to describe behavior of brokers in order to become more widely accepted, and substitute 0.9x family. As far I have been told, AMQP group wanted to concentrate on core of the protocol first, and work on behavior later. Anyway, we have to see if work on broker behavior will start to heat up now that the core of the protocol is done.\n- I've been reading the 0-10 spec and implementations of Qpid and MRG (red hat) it seems good and complete. but you don't agree with this?\n- I have no direct experience with 0.10, my comment (that it is not very popular) was based on RabbitMQ which is my kind of lacmus test, is not implementing it.\n- I see. Well thank you very much your time to put in comments, they have been most certainly helpful.","metadata":{"transformedAt":"2026-08-18T18:33:20.330Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":22,"estimatedTokens":578}}1169{"id":"stack-58241174","source":"stackoverflow","questionId":58241174,"title":"Is it possible with RabbitMQ to preserve direct exchange message without any queues present?","tags":["rabbitmq","amqp"],"text":"Title: Is it possible with RabbitMQ to preserve direct exchange message without any queues present?\nTags: rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI wonder if the following scenario is possible:\n\n- Create an exchange of type `direct`\n\n- Publish a message to that exchange with routing key `rk1`\nAfter that:\n\n- Create a queue which accepts messages with routing key `rk1`\n\n- Consume message published to exchange\n\nIt seems like if there is no queue present, the message is dropped and there is no way to receive it.\n\nSo basically I want to be able to produce messages when there are no consumers present. And consume them some time later.\n\n========================================\n\nTop Answer:\nThe entity queue is the one that is supposed to hold the messages , so without a queue the messages will be lost.\n\nHowever in case you do not create any exchange with appropriate routing key you may leverage dead lettering feature in rabbitmq.\n\n========================================\n\nCode:\n```text\ndirect\n```\n\n```text\nrk1\n```\n\n```text\nrk1\n```\n\n```text\nbasic.return\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.330Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":4,"totalLines":45,"estimatedTokens":268}}1170{"id":"stack-59639632","source":"stackoverflow","questionId":59639632,"title":"How to listen to a dynamically created queue?","tags":["java","rabbitmq","amqp","spring-amqp","spring-rabbit"],"text":"Title: How to listen to a dynamically created queue?\nTags: java, rabbitmq, amqp, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI have a rabbitListener which continuously listens to user messages of a queue \"user-messages\" asynchronously. Everything is OK until unless queue is loaded with bulk messages. When messages in bulk published to queue, messages of the **same user** are processing first thereby messages of other users are waiting for their turn. \n\nI can't use **Priority Queue** because all the users have equal priority. So I want to create new queues and listen to them at **runtime**. All the queues will be short-lived as soon as messages consumed. (the queue will be deleted)\n\nOn browsing, I found a queue can be dynamically created using **RabbitAdmin**. But the issues are\n\n- How can I make my listener listen to a new short-live (TTL) queue created at runtime?\n\n- How can I make the listener stop listening to a deleted queue (after TTL time) to avoid exceptions?\n\nCurrently, I'm using SimpleMessageListenerContainerFactory. I've no issues to use DirectMessageListenerContainer as well. My only concern is **how to communicate about dynamic queue creation & deletion to Listener**. Thinking about to https://www.rabbitmq.com/event-exchange.html (event exchange plugin). \n\nIs there any way that spring-amqp supporting **start/stop** listening dynamic queues. Thanks in advance.\n\n```\n@Bean\n public SimpleRabbitListenerContainerFactory myRabbitListenerContainerFactory() {\n SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();\n factory.setConnectionFactory(config.getConnectionFactory());\n factory.setAcknowledgeMode(AcknowledgeMode.MANUAL);\n factory.setConcurrentConsumers(1);\n factory.setMaxConcurrentConsumers(3);\n return factory;\n }\n\n @RabbitListener(id = \"listener\", queues = {\n \"#{receiver.queues()}\" }, containerFactory = \"myRabbitListenerContainerFactory\")\n public void listen(QueueMessage message, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag,\n MessageHeaders headers) {\n //process message\n }\n\n [1]: https://www.rabbitmq.com/event-exchange.html\n```\n\n========================================\n\nCode:\n```text\n@Bean\n public SimpleRabbitListenerContainerFactory myRabbitListenerContainerFactory() {\n SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();\n factory.setConnectionFactory(config.getConnectionFactory());\n factory.setAcknowledgeMode(AcknowledgeMode.MANUAL);\n factory.setConcurrentConsumers(1);\n factory.setMaxConcurrentConsumers(3);\n return factory;\n }\n\n @RabbitListener(id = \"listener\", queues = {\n \"#{receiver.queues()}\" }, containerFactory = \"myRabbitListenerContainerFactory\")\n public void listen(QueueMessage message, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag,\n MessageHeaders headers) {\n //process message\n }\n\n\n [1]: https://www.rabbitmq.com/event-exchange.html\n```\n\n```java\n@Configuration\npublic class RabbitMqConfiguration implements RabbitListenerConfigurer {\n @Autowired\n private ConnectionFactory connectionFactory;\n @Bean\n public Jackson2JsonMessageConverter producerJackson2MessageConverter() {\n return new Jackson2JsonMessageConverter();\n }\n @Bean\n public MappingJackson2MessageConverter consumerJackson2MessageConverter() {\n return new MappingJackson2MessageConverter();\n }\n @Bean\n public RabbitTemplate rabbitTemplate() {\n final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);\n rabbitTemplate.setMessageConverter(producerJackson2MessageConverter());\n return rabbitTemplate;\n }\n @Bean\n public RabbitAdmin rabbitAdmin() {\n return new RabbitAdmin(connectionFactory);\n }\n @Bean\n public RabbitListenerEndpointRegistry rabbitListenerEndpointRegistry() {\n return new RabbitListenerEndpointRegistry();\n }\n @Bean\n public DefaultMessageHandlerMethodFactory messageHandlerMethodFactory() {\n DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();\n factory.setMessageConverter(consumerJackson2MessageConverter());\n return factory;\n }\n @Bean\n public MessageConverter jsonMessageConverter() {\n return new Jackson2JsonMessageConverter();\n }\n @Override\n public void configureRabbitListeners(final RabbitListenerEndpointRegistrar registrar) {\n SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();\n factory.setPrefetchCount(1);\n factory.setConsecutiveActiveTrigger(1);\n factory.setConsecutiveIdleTrigger(1);\n factory.setConnectionFactory(connectionFactory);\n registrar.setContainerFactory(factory);\n registrar.setEndpointRegistry(rabbitListenerEndpointRegistry());\n registrar.setMessageHandlerMethodFactory(messageHandlerMethodFactory());\n }\n}\n```\n\n```java\npublic interface RabbitQueueService {\n void addNewQueue(String queueName,String exchangeName,String routingKey);\n void addQueueToListener(String listenerId,String queueName);\n void removeQueueFromListener(String listenerId,String queueName);\n Boolean checkQueueExistOnListener(String listenerId,String queueName);\n}\n```\n\n```java\n@Service\n@Log4j2\npublic class RabbitQueueServiceImpl implements RabbitQueueService {\n @Autowired\n private RabbitAdmin rabbitAdmin;\n @Autowired\n private RabbitListenerEndpointRegistry rabbitListenerEndpointRegistry;\n\n @Override\n public void addNewQueue(String queueName, String exchangeName, String routingKey) {\n Queue queue = new Queue(queueName, true, false, false);\n Binding binding = new Binding(\n queueName,\n Binding.DestinationType.QUEUE,\n exchangeName,\n routingKey,\n null\n );\n rabbitAdmin.declareQueue(queue);\n rabbitAdmin.declareBinding(binding);\n this.addQueueToListener(exchangeName,queueName);\n }\n\n @Override\n public void addQueueToListener(String listenerId, String queueName) {\n log.info(\"adding queue : \" + queueName + \" to listener with id : \" + listenerId);\n if (!checkQueueExistOnListener(listenerId,queueName)) {\n this.getMessageListenerContainerById(listenerId).addQueueNames(queueName);\n log.info(\"queue \");\n } else {\n log.info(\"given queue name : \" + queueName + \" not exist on given listener id : \" + listenerId);\n }\n }\n\n @Override\n public void removeQueueFromListener(String listenerId, String queueName) {\n log.info(\"removing queue : \" + queueName + \" from listener : \" + listenerId);\n if (checkQueueExistOnListener(listenerId,queueName)) {\n this.getMessageListenerContainerById(listenerId).removeQueueNames(queueName);\n log.info(\"deleting queue from rabbit management\");\n this.rabbitAdmin.deleteQueue(queueName);\n } else {\n log.info(\"given queue name : \" + queueName + \" not exist on given listener id : \" + listenerId);\n }\n }\n\n @Override\n public Boolean checkQueueExistOnListener(String listenerId, String queueName) {\n try {\n log.info(\"checking queueName : \" + queueName + \" exist on listener id : \" + listenerId);\n log.info(\"getting queueNames\");\n String[] queueNames = this.getMessageListenerContainerById(listenerId).getQueueNames();\n log.info(\"queueNames : \" + new Gson().toJson(queueNames));\n if (queueNames != null) {\n log.info(\"checking \" + queueName + \" exist on active queues\");\n for (String name : queueNames) {\n log.info(\"name : \" + name + \" with checking name : \" + queueName);\n if (name.equals(queueName)) {\n log.info(\"queue name exist on listener, returning true\");\n return Boolean.TRUE;\n }\n }\n return Boolean.FALSE;\n } else {\n log.info(\"there is no queue exist on listener\");\n return Boolean.FALSE;\n }\n } catch (Exception e) {\n log.error(\"Error on checking queue exist on listener\");\n log.error(\"error message : \" + ExceptionUtils.getMessage(e));\n log.error(\"trace : \" + ExceptionUtils.getStackTrace(e));\n return Boolean.FALSE;\n }\n }\n\n private AbstractMessageListenerContainer getMessageListenerContainerById(String listenerId) {\n log.info(\"getting message listener container by id : \" + listenerId);\n return ((AbstractMessageListenerContainer) this.rabbitListenerEndpointRegistry\n .getListenerContainer(listenerId)\n );\n }\n}\n```\n\n========================================\n\nComments:\n- hi man, you can read my article at medium. link : karadenizfaruk28.medium.com/…","metadata":{"transformedAt":"2026-08-18T18:33:20.330Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":214,"estimatedTokens":2257}}1171{"id":"stack-70134943","source":"stackoverflow","questionId":70134943,"title":"RabbitMQ Queue Length is always 0","tags":["go","rabbitmq","amqp"],"text":"Title: RabbitMQ Queue Length is always 0\nTags: go, rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI was writing an application and I had this issue, looking the code over and over, nothing seems to be wrong, tested with the below basic snippet and the issue is reproducible .... RabbitMQ is saying the queue is always empty when it is not.\n\nThe below Golang snippet shows a producer sending messages more often than the consumer consuming them. The consumer is always active but sleeping longer to make the queue have messages in its backlog. Result? The consumer fetches messages each time it tries however the API is always saying there are no messages -> message count is 0.\n\n```\npackage main\n\nimport (\n \"encoding/json\"\n \"fmt\"\n \"github.com/streadway/amqp\"\n \"io/ioutil\"\n \"net/http\"\n \"testing\"\n \"time\"\n)\nfunc main() {\n\n username := \"guest\"\n password := \"guest\"\n scheme := \"amqp\"\n rabbitMqHost := \"localhost\"\n port := \"5672\"\n\n connectionString := fmt.Sprintf(\"%s://%s:%s@%s:%s/\", scheme, username, password, rabbitMqHost, port)\n\n conn, err := amqp.Dial(connectionString)\n\n if err != nil {\n panic(err)\n }\n\n ch, err := conn.Channel()\n if err != nil {\n panic(err)\n }\n\n exchangeName := \"my-exchange\"\n // Declare exchange\n err = ch.ExchangeDeclare(\n exchangeName, // name\n \"fanout\", // type\n true, // durable\n true, // auto-deleted\n false, // internal\n false, // no-wait\n nil, // arguments\n )\n\n if err != nil {\n panic(err)\n }\n\n // Create first Queue\n queueName := \"my-queue\"\n q, err := ch.QueueDeclare(\n queueName, // name\n true, // durable\n true, // delete when unsused\n false, // exclusive\n false, // no-wait\n nil, // arguments\n )\n\n if err != nil {\n panic(err)\n }\n\n // Bind Exchange to Queue\n err = ch.QueueBind(\n q.Name, // queue name\n \"\", // routing key\n exchangeName, // exchange\n false,\n nil,\n )\n\n // Listen\n eventQueue, err := ch.Consume(\n q.Name, // queue\n \"\", // consumer\n true, // auto-ack\n false, // exclusive\n false, // no-local\n false, // no-wait\n nil, // args\n )\n\n if err != nil {\n panic(err)\n }\n\n go func() {\n for a := range eventQueue {\n fmt.Printf(\"Received Event %s\\n\", string(a.Body))\n time.Sleep(time.Second * 4)\n }\n }()\n\n go func() {\n count := 0\n for {\n err = ch.Publish(exchangeName, \"\", false, false, amqp.Publishing{\n ContentType: \"application/json\",\n Body: []byte(fmt.Sprintf(\"Message %d\", count)),\n })\n\n fmt.Printf(\"Sent Message %d\\n\", count)\n count++\n if err != nil {\n panic(err)\n }\n time.Sleep(time.Second * 2)\n }\n }()\n\n for {\n httpRes, err := http.Get(\"http://guest:guest@localhost:15672/api/queues/%2f/my-queue\")\n if err != nil {\n panic(err)\n }\n\n var resJson map[string]interface{}\n content, err := ioutil.ReadAll(httpRes.Body)\n if err != nil {\n panic(err)\n }\n httpRes.Body.Close()\n err = json.Unmarshal(content, &resJson)\n\n if err != nil {\n panic(err)\n }\n\n q2, err := ch.QueueDeclarePassive(\n queueName, // name\n true, // durable\n true, // delete when unsused\n false, // exclusive\n false, // no-wait\n nil,\n )\n fmt.Printf(\"Queue Len: %f - %d\\n\", resJson[\"messages\"], q2.Messages)\n time.Sleep(time.Second)\n }\n\n}\n```\n\nYou can test with the following RabbitMQ Server:\n\n```\ndocker run --rm --hostname my-rabbit --name some-rabbit -p 5672:5672 -p 15672:15672 rabbitmq:3-management\n```\n\nOutput:\n\n```\nSent Message 0\nReceived Event Message 0\nQueue Len: %!f() - 0\nQueue Len: %!f() - 0\nSent Message 1\nQueue Len: 0.000000 - 0\nQueue Len: 0.000000 - 0\nReceived Event Message 1\nSent Message 2\nQueue Len: 0.000000 - 0\nQueue Len: 0.000000 - 0\nSent Message 3\nQueue Len: 0.000000 - 0\nQueue Len: 0.000000 - 0\nReceived Event Message 2\nSent Message 4\nQueue Len: 0.000000 - 0\nQueue Len: 0.000000 - 0\nSent Message 5\nQueue Len: 0.000000 - 0\nQueue Len: 0.000000 - 0\nReceived Event Message 3\nSent Message 6\nQueue Len: 0.000000 - 0\nQueue Len: 0.000000 - 0\nSent Message 7\nQueue Len: 0.000000 - 0\nQueue Len: 0.000000 - 0\nReceived Event Message 4\nSent Message 8\nQueue Len: 0.000000 - 0\nQueue Len: 0.000000 - 0\nSent Message 9\nQueue Len: 0.000000 - 0\nQueue Len: 0.000000 - 0\nReceived Event Message 5\nSent Message 10\n....\n....\n```\n\nNot a single time the Que Len has said it is not 0. In my application when I put a bunch of messages I may catch it saying X, but quickly it becomes 0, I thought I had a hidden consumer in the app, but no, the API is giving some results that either are not accurate, or I should be looking somewhere else to get the length.\n\n### Update\n\nThe above only happens when there is a consumer, if the queue does not have a consumer, it works as expected, just comment the `.Consume` code:\n\n```\n/*\neventQueue, err := ch.Consume(\n...\ngo func(){\nfor a := range eventQueue {\n..\n}()\n*/\n```\n\nAnd now it \"improves\", but first, it is not what I am looking for, second, it is still strange output =S:\n\n```\nSent Message 0\nQueue Len: 0.000000 - 1\nQueue Len: 0.000000 - 1\nSent Message 1\nQueue Len: 0.000000 - 2\nQueue Len: 0.000000 - 2\nSent Message 2\nQueue Len: 0.000000 - 3\nQueue Len: 1.000000 - 3\nSent Message 3\nQueue Len: 1.000000 - 4\nQueue Len: 1.000000 - 4\nSent Message 4\nQueue Len: 1.000000 - 5\nQueue Len: 1.000000 - 5\nSent Message 5\nQueue Len: 4.000000 - 6\nQueue Len: 4.000000 - 6\nSent Message 6\nQueue Len: 4.000000 - 7\nQueue Len: 4.000000 - 7\nSent Message 7\nQueue Len: 4.000000 - 8\nQueue Len: 6.000000 - 8\nSent Message 8\nQueue Len: 6.000000 - 9\nQueue Len: 6.000000 - 9\nSent Message 9\nQueue Len: 6.000000 - 10\nQueue Len: 6.000000 - 10\nSent Message 10\nQueue Len: 9.000000 - 11\nQueue Len: 9.000000 - 11\n```\n\n========================================\n\nTop Answer:\nThe accepted solution will be blackgreen's. The proof is the below replacement, just replace the consumer and publisher code in the question section by:\n\n```\n// Listen\n eventQueue, err := ch.Consume(\n q.Name, // queue\n \"\", // consumer\n false, // auto-ack = 20 { // Output:\n\n```\n.... The increase in the queue length\nSent Message 13\nQueue Len: 8.000000 - 0\nQueue Len: 8.000000 - 0\nReceived Event Message 4\nSent Message 14\nQueue Len: 8.000000 - 0\nQueue Len: 9.000000 - 0\nSent Message 15\nQueue Len: 9.000000 - 0\nQueue Len: 9.000000 - 0\nReceived Event Message 5\nSent Message 16\nQueue Len: 9.000000 - 0\nQueue Len: 9.000000 - 0\nSent Message 17\nQueue Len: 11.000000 - 0\nQueue Len: 11.000000 - 0\nReceived Event Message 6\nSent Message 18\nQueue Len: 11.000000 - 0\nQueue Len: 11.000000 - 0\nSent Message 19\nQueue Len: 11.000000 - 0\nQueue Len: 12.000000 - 0\nReceived Event Message 7\nQueue Len: 12.000000 - 0\nQueue Len: 12.000000 - 0\nQueue Len: 12.000000 - 0\nQueue Len: 12.000000 - 0\nReceived Event Message 8\nQueue Len: 12.000000 - 0\nQueue Len: 12.000000 - 0\nQueue Len: 12.000000 - 0\nQueue Len: 12.000000 - 0\nReceived Event Message 9\nQueue Len: 12.000000 - 0\nQueue Len: 11.000000 - 0\nQueue Len: 11.000000 - 0\nQueue Len: 11.000000 - 0\nReceived Event Message 10\nQueue Len: 11.000000 - 0\nQueue Len: 11.000000 - 0\nQueue Len: 10.000000 - 0\nQueue Len: 10.000000 - 0\nReceived Event Message 11\nQueue Len: 10.000000 - 0\nQueue Len: 10.000000 - 0\nQueue Len: 10.000000 - 0\nQueue Len: 9.000000 - 0\nReceived Event Message 12\n....\nAs publisher exits it decreases, the consumer catches up and message len decreases:\nReceived Event Message 16\nQueue Len: 5.000000 - 0\nQueue Len: 5.000000 - 0\nQueue Len: 5.000000 - 0\nQueue Len: 4.000000 - 0\nReceived Event Message 17\nQueue Len: 4.000000 - 0\nQueue Len: 4.000000 - 0\nQueue Len: 4.000000 - 0\nQueue Len: 4.000000 - 0\nReceived Event Message 18\nQueue Len: 2.000000 - 0\nQueue Len: 2.000000 - 0\nQueue Len: 2.000000 - 0\nQueue Len: 2.000000 - 0\nReceived Event Message 19\nQueue Len: 2.000000 - 0\nQueue Len: 1.000000 - 0\n```\n\n========================================\n\nCode:\n```golang\npackage main\n\nimport (\n \"encoding/json\"\n \"fmt\"\n \"github.com/streadway/amqp\"\n \"io/ioutil\"\n \"net/http\"\n \"testing\"\n \"time\"\n)\nfunc main() {\n\n username := \"guest\"\n password := \"guest\"\n scheme := \"amqp\"\n rabbitMqHost := \"localhost\"\n port := \"5672\"\n\n connectionString := fmt.Sprintf(\"%s://%s:%s@%s:%s/\", scheme, username, password, rabbitMqHost, port)\n\n conn, err := amqp.Dial(connectionString)\n\n if err != nil {\n panic(err)\n }\n\n ch, err := conn.Channel()\n if err != nil {\n panic(err)\n }\n\n exchangeName := \"my-exchange\"\n // Declare exchange\n err = ch.ExchangeDeclare(\n exchangeName, // name\n \"fanout\", // type\n true, // durable\n true, // auto-deleted\n false, // internal\n false, // no-wait\n nil, // arguments\n )\n\n if err != nil {\n panic(err)\n }\n\n // Create first Queue\n queueName := \"my-queue\"\n q, err := ch.QueueDeclare(\n queueName, // name\n true, // durable\n true, // delete when unsused\n false, // exclusive\n false, // no-wait\n nil, // arguments\n )\n\n if err != nil {\n panic(err)\n }\n\n // Bind Exchange to Queue\n err = ch.QueueBind(\n q.Name, // queue name\n \"\", // routing key\n exchangeName, // exchange\n false,\n nil,\n )\n\n // Listen\n eventQueue, err := ch.Consume(\n q.Name, // queue\n \"\", // consumer\n true, // auto-ack\n false, // exclusive\n false, // no-local\n false, // no-wait\n nil, // args\n )\n\n if err != nil {\n panic(err)\n }\n\n go func() {\n for a := range eventQueue {\n fmt.Printf(\"Received Event %s\\n\", string(a.Body))\n time.Sleep(time.Second * 4)\n }\n }()\n\n go func() {\n count := 0\n for {\n err = ch.Publish(exchangeName, \"\", false, false, amqp.Publishing{\n ContentType: \"application/json\",\n Body: []byte(fmt.Sprintf(\"Message %d\", count)),\n })\n\n fmt.Printf(\"Sent Message %d\\n\", count)\n count++\n if err != nil {\n panic(err)\n }\n time.Sleep(time.Second * 2)\n }\n }()\n\n for {\n httpRes, err := http.Get(\"http://guest:guest@localhost:15672/api/queues/%2f/my-queue\")\n if err != nil {\n panic(err)\n }\n\n var resJson map[string]interface{}\n content, err := ioutil.ReadAll(httpRes.Body)\n if err != nil {\n panic(err)\n }\n httpRes.Body.Close()\n err = json.Unmarshal(content, &resJson)\n\n if err != nil {\n panic(err)\n }\n\n q2, err := ch.QueueDeclarePassive(\n queueName, // name\n true, // durable\n true, // delete when unsused\n false, // exclusive\n false, // no-wait\n nil,\n )\n fmt.Printf(\"Queue Len: %f - %d\\n\", resJson[\"messages\"], q2.Messages)\n time.Sleep(time.Second)\n }\n\n}\n```\n\n```text\ndocker run --rm --hostname my-rabbit --name some-rabbit -p 5672:5672 -p 15672:15672 rabbitmq:3-management\n```\n\n```text\nSent Message 0\nReceived Event Message 0\nQueue Len: %!f(<nil>) - 0\nQueue Len: %!f(<nil>) - 0\nSent Message 1\nQueue Len: 0.000000 - 0\nQueue Len: 0.000000 - 0\nReceived Event Message 1\nSent Message 2\nQueue Len: 0.000000 - 0\nQueue Len: 0.000000 - 0\nSent Message 3\nQueue Len: 0.000000 - 0\nQueue Len: 0.000000 - 0\nReceived Event Message 2\nSent Message 4\nQueue Len: 0.000000 - 0\nQueue Len: 0.000000 - 0\nSent Message 5\nQueue Len: 0.000000 - 0\nQueue Len: 0.000000 - 0\nReceived Event Message 3\nSent Message 6\nQueue Len: 0.000000 - 0\nQueue Len: 0.000000 - 0\nSent Message 7\nQueue Len: 0.000000 - 0\nQueue Len: 0.000000 - 0\nReceived Event Message 4\nSent Message 8\nQueue Len: 0.000000 - 0\nQueue Len: 0.000000 - 0\nSent Message 9\nQueue Len: 0.000000 - 0\nQueue Len: 0.000000 - 0\nReceived Event Message 5\nSent Message 10\n....\n....\n```\n\n```text\n/*\neventQueue, err := ch.Consume(\n...\ngo func(){\nfor a := range eventQueue {\n..\n}()\n*/\n```\n\n```text\nSent Message 0\nQueue Len: 0.000000 - 1\nQueue Len: 0.000000 - 1\nSent Message 1\nQueue Len: 0.000000 - 2\nQueue Len: 0.000000 - 2\nSent Message 2\nQueue Len: 0.000000 - 3\nQueue Len: 1.000000 - 3\nSent Message 3\nQueue Len: 1.000000 - 4\nQueue Len: 1.000000 - 4\nSent Message 4\nQueue Len: 1.000000 - 5\nQueue Len: 1.000000 - 5\nSent Message 5\nQueue Len: 4.000000 - 6\nQueue Len: 4.000000 - 6\nSent Message 6\nQueue Len: 4.000000 - 7\nQueue Len: 4.000000 - 7\nSent Message 7\nQueue Len: 4.000000 - 8\nQueue Len: 6.000000 - 8\nSent Message 8\nQueue Len: 6.000000 - 9\nQueue Len: 6.000000 - 9\nSent Message 9\nQueue Len: 6.000000 - 10\nQueue Len: 6.000000 - 10\nSent Message 10\nQueue Len: 9.000000 - 11\nQueue Len: 9.000000 - 11\n```\n\n```text\n.Consume\n```\n\n```text\nhttp://localhost:15672/api/queues/vhost/queue_name\n```\n\n```text\nq2.Messages\n```\n\n```text\nautoAck = true\n```\n\n```text\nnoAck\n```\n\n```text\nmessage_stats\n```\n\n```golang\n// Listen\n eventQueue, err := ch.Consume(\n q.Name, // queue\n \"\", // consumer\n false, // auto-ack <-- Difference\n false, // exclusive\n false, // no-local\n false, // no-wait\n nil, // args\n )\n\n if err != nil {\n panic(err)\n }\n\n go func() {\n\n for a := range eventQueue {\n err = ch.Ack(a.DeliveryTag, false) // <-- Difference\n if err != nil {\n panic(err)\n }\n fmt.Printf(\"Received Event %s\\n\", string(a.Body))\n time.Sleep(time.Second * 4)\n }\n }()\n\n go func() {\n count := 0\n for {\n err = ch.Publish(exchangeName, \"\", false, false, amqp.Publishing{\n ContentType: \"application/json\",\n Body: []byte(fmt.Sprintf(\"Message %d\", count)),\n })\n\n fmt.Printf(\"Sent Message %d\\n\", count)\n count++\n if err != nil {\n panic(err)\n }\n if count >= 20 { // <-- Difference\n break\n }\n time.Sleep(time.Second * 2)\n }\n }()\n```\n\n```text\n.... The increase in the queue length\nSent Message 13\nQueue Len: 8.000000 - 0\nQueue Len: 8.000000 - 0\nReceived Event Message 4\nSent Message 14\nQueue Len: 8.000000 - 0\nQueue Len: 9.000000 - 0\nSent Message 15\nQueue Len: 9.000000 - 0\nQueue Len: 9.000000 - 0\nReceived Event Message 5\nSent Message 16\nQueue Len: 9.000000 - 0\nQueue Len: 9.000000 - 0\nSent Message 17\nQueue Len: 11.000000 - 0\nQueue Len: 11.000000 - 0\nReceived Event Message 6\nSent Message 18\nQueue Len: 11.000000 - 0\nQueue Len: 11.000000 - 0\nSent Message 19\nQueue Len: 11.000000 - 0\nQueue Len: 12.000000 - 0\nReceived Event Message 7\nQueue Len: 12.000000 - 0\nQueue Len: 12.000000 - 0\nQueue Len: 12.000000 - 0\nQueue Len: 12.000000 - 0\nReceived Event Message 8\nQueue Len: 12.000000 - 0\nQueue Len: 12.000000 - 0\nQueue Len: 12.000000 - 0\nQueue Len: 12.000000 - 0\nReceived Event Message 9\nQueue Len: 12.000000 - 0\nQueue Len: 11.000000 - 0\nQueue Len: 11.000000 - 0\nQueue Len: 11.000000 - 0\nReceived Event Message 10\nQueue Len: 11.000000 - 0\nQueue Len: 11.000000 - 0\nQueue Len: 10.000000 - 0\nQueue Len: 10.000000 - 0\nReceived Event Message 11\nQueue Len: 10.000000 - 0\nQueue Len: 10.000000 - 0\nQueue Len: 10.000000 - 0\nQueue Len: 9.000000 - 0\nReceived Event Message 12\n....\nAs publisher exits it decreases, the consumer catches up and message len decreases:\nReceived Event Message 16\nQueue Len: 5.000000 - 0\nQueue Len: 5.000000 - 0\nQueue Len: 5.000000 - 0\nQueue Len: 4.000000 - 0\nReceived Event Message 17\nQueue Len: 4.000000 - 0\nQueue Len: 4.000000 - 0\nQueue Len: 4.000000 - 0\nQueue Len: 4.000000 - 0\nReceived Event Message 18\nQueue Len: 2.000000 - 0\nQueue Len: 2.000000 - 0\nQueue Len: 2.000000 - 0\nQueue Len: 2.000000 - 0\nReceived Event Message 19\nQueue Len: 2.000000 - 0\nQueue Len: 1.000000 - 0\n```\n\n========================================\n\nComments:\n- I thought on that for a sec, but did not test, but still, I guess there must be a way to get the number of messages in the queue, even auto-ack, from what I know, even if auto-ack is set to true, if I don't read the message from the queue, my application does not have it, RabbitMQ does, so how to get that count of messages RabbitMQ has and my application does not\n- @Melardev the issue is much more complicated than “rabbit has it, my app doesn’t”, and it’s related with how the smart broker dumb consumer model is implemented. Anyway I guess that’s a limitation (feature?) of the protocol\n- I accept your answer, I have indeed been able to fix this by setting autoAck to false as you indicated, Published my snippet if somebody needs it too, thanks for help!","metadata":{"transformedAt":"2026-08-18T18:33:20.330Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":13,"totalLines":739,"estimatedTokens":4113}}1172{"id":"stack-54685215","source":"stackoverflow","questionId":54685215,"title":"Multiple Consumers of the same message type on one receive endpoint","tags":["c#","rabbitmq","masstransit"],"text":"Title: Multiple Consumers of the same message type on one receive endpoint\nTags: c#, rabbitmq, masstransit\nSource: Stack Overflow\n\nQuestion:\nIs it a valid solution to use different consumers of the same message type on a single receive endpoint or should we use a receive endpoint for each consumer?\n\n```\ncfg.ReceiveEndpoint(host, \"MyQueue\", e =>\n {\n logger.LogInformation(\"Consuming enabled.\");\n\n //register consumers with middleware components\n e.Consumer(context);\n e.Consumer(context);\n })\n\npublic class MyConsumer : IConsumer {}\n\npublic class MyOtherConsumer : IConsumer {}\n```\n\nThe solution above works, each consumer receives the message. Even if one fails (exception).\n\nWhy do I ask this? Our current solution is that we have a single consumer for each message type. The consumer passes the received message to an internal custom extensible pipeline for processing. If the above solution is viable we could drop or own custom pipeline an use MassTransit instead.\n\n========================================\n\nCode:\n```text\ncfg.ReceiveEndpoint(host, \"MyQueue\", e =>\n {\n logger.LogInformation(\"Consuming enabled.\");\n\n //register consumers with middleware components\n e.Consumer<MyConsumer>(context);\n e.Consumer<MyOtherConsumer>(context);\n })\n\npublic class MyConsumer : IConsumer<MyMessage> {}\n\npublic class MyOtherConsumer : IConsumer<MyMessage> {}\n```\n\n```text\nec.Consumer<MyConsumer>(context, c => c.UseRetry(r => r.Interval(2,1000)));\nec.Consumer<MyOtherConsumer>(context, c => c.UseRetry(r => None()));\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.330Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":48,"estimatedTokens":399}}1173{"id":"stack-61485919","source":"stackoverflow","questionId":61485919,"title":"How to implement a request-response pattern on Google Cloud PubSub?","tags":["google-cloud-platform","rabbitmq","publish-subscribe","google-cloud-pubsub","request-response"],"text":"Title: How to implement a request-response pattern on Google Cloud PubSub?\nTags: google-cloud-platform, rabbitmq, publish-subscribe, google-cloud-pubsub, request-response\nSource: Stack Overflow\n\nQuestion:\nI have multiple clients A (main application) and multiple clients B (payments service).\n\nIf I publish a message from client A that will be processed and answered on client B (publishing an answer in another topic), how to capture this answer on client A?\n\nThe problem is that client A has multiple instances, so I can't guarantee that the exactly same instance that triggered the request will receive the response (PubSub will randomly pick one instance).\n\nSaw that other brokers like RabbitMQ have \"reply-to\" option. Is there anything similar on Google PubSub?\n\nThat way, I could simulate a \"synchronous\" operation on client A and only answer to the user when processing/response is finished, instead of dealing with this check on front-end every time.\n\nThank you!","metadata":{"transformedAt":"2026-08-18T18:33:20.331Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":16,"estimatedTokens":243}}1174{"id":"stack-56241950","source":"stackoverflow","questionId":56241950,"title":"RabbitMQ LDAP on the Management Plugin","tags":["active-directory","ldap","rabbitmq"],"text":"Title: RabbitMQ LDAP on the Management Plugin\nTags: active-directory, ldap, rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI am new to RabbitMQ. I have it installed on Windows 10 Enterpise for development purposes. We have Active Directory running. Trying to set up LDAP for the management plugin, so that any user with the right password can login as administrator. \n\nMy latest config:\n\n```\n[\n{\n rabbit,\n [\n {\n auth_backends, [\n {rabbit_auth_backend_ldap, rabbit_auth_backend_internal},\n rabbit_auth_backend_internal\n ]\n }\n ]\n},\n{\n rabbitmq_auth_backend_ldap,\n [\n { \n servers, [\n \"WLNC0DS23N.na.mycompany.com\",\"WBRD0DS21N.na.mycompany.com\"\n ]\n },\n {\n dn_lookup_attribute, \"userPrincipalName\"\n },\n {\n dn_lookup_base, \"DC=na,DC=mycompany,DC=com\"\n },\n {\n user_dn_pattern, \"${username}@mycompany.com\"\n },\n {\n use_ssl, false\n },\n {\n port, 389\n }, \n {\n log, true\n },\n {\n vhost_access_query, {in_group_nested, \"CN=NA_WHS,OU=GroupsAndContacts,OU=Exchange,DC=na,DC=mycompany,DC=com\",\"member\"}\n },\n {\n resource_access_query, {in_group_nested, \"CN=NA_WHS,OU=GroupsAndContacts,OU=Exchange,DC=na,DC=mycompany,DC=com\",\"member\"}\n },\n {\n topic_access_query, {in_group_nested, \"CN=NA_WHS,OU=GroupsAndContacts,OU=Exchange,DC=na,DC=mycompany,DC=com\",\"member\"}\n },\n {\n tag_queries, [\n {\n administrator, {in_group_nested,\"CN=NA_WHS,OU=GroupsAndContacts,OU=Exchange,DC=na,DC=mycompany,DC=com\",\"member\"}\n }\n ]\n }\n ]\n}\n```\n\n].\n\nUnfortunately, while LDAP seems to check me out ok, I am not able to login in and get this error in the log:\n\n```\n2019-05-28 16:04:14.662 [info] LDAP CHECK: login for perryda\n2019-05-28 16:04:14.663 [info] LDAP filling template \"${username}@mycompany.com\" with\n [{username,>}]\n2019-05-28 16:04:14.663 [info] LDAP template result: \"perryda@mycompany.com\"\n2019-05-28 16:04:14.750 [info] LDAP bind succeeded: xxxx\n2019-05-28 16:04:14.750 [info] LDAP filling template \"${username}@mycompany.com\" with\n [{username,>}]\n2019-05-28 16:04:14.751 [info] LDAP template result: \"perryda@mycompany.com\"\n2019-05-28 16:04:14.753 [info] LDAP DN lookup: perryda -> CN=Perry\\, David,OU=Users,OU=WLNC-Wilmington,OU=OC,OU=IT-SD,DC=na,DC=mycompany,DC=com\n2019-05-28 16:04:14.753 [info] LDAP CHECK: does perryda have tag administrator?\n2019-05-28 16:04:14.753 [info] LDAP evaluating query: {in_group_nested,\"CN=NA_WHS,OU=GroupsAndContacts,OU=Exchange,DC=na,DC=mycompany,DC=com\",\"member\"}\n2019-05-28 16:04:14.753 [info] LDAP evaluating query: {in_group_nested,\"CN=NA_WHS,OU=GroupsAndContacts,OU=Exchange,DC=na,DC=mycompany,DC=com\",\"member\",subtree}\n2019-05-28 16:04:14.754 [info] LDAP filling template \"CN=NA_WHS,OU=GroupsAndContacts,OU=Exchange,DC=na,DC=mycompany,DC=com\" with\n [{username,>},{user_dn,\"CN=Perry\\\\, David,OU=Users,OU=WLNC-Wilmington,OU=OC,OU=IT-SD,DC=na,DC=mycompany,DC=com\"}]\n2019-05-28 16:04:14.754 [info] LDAP template result: \"CN=NA_WHS,OU=GroupsAndContacts,OU=Exchange,DC=na,DC=mycompany,DC=com\"\n2019-05-28 16:04:14.759 [info] LDAP DECISION: does perryda have tag administrator? true\n2019-05-28 16:04:14.759 [info] LDAP DECISION: login for perryda: ok\n2019-05-28 16:04:14.759 [warning] HTTP access denied: user 'perryda' - invalid credentials\n```\n\nDoes anyone have a clueon what the problem is, and how to fix?\n\n========================================\n\nTop Answer:\nTrying to set it up so AD users that belong to a particular AD Group\nare just instantly logged in when they access the management plugin\nfrom IE or Edge.\n\nThe management UI doesn't support this. You will have to provide a username and password to log in using AD credentials.\n\n========================================\n\nCode:\n```text\n[\n{\n rabbit,\n [\n {\n auth_backends, [\n {rabbit_auth_backend_ldap, rabbit_auth_backend_internal},\n rabbit_auth_backend_internal\n ]\n }\n ]\n},\n{\n rabbitmq_auth_backend_ldap,\n [\n { \n servers, [\n \"WLNC0DS23N.na.mycompany.com\",\"WBRD0DS21N.na.mycompany.com\"\n ]\n },\n {\n dn_lookup_attribute, \"userPrincipalName\"\n },\n {\n dn_lookup_base, \"DC=na,DC=mycompany,DC=com\"\n },\n {\n user_dn_pattern, \"${username}@mycompany.com\"\n },\n {\n use_ssl, false\n },\n {\n port, 389\n }, \n {\n log, true\n },\n {\n vhost_access_query, {in_group_nested, \"CN=NA_WHS,OU=GroupsAndContacts,OU=Exchange,DC=na,DC=mycompany,DC=com\",\"member\"}\n },\n {\n resource_access_query, {in_group_nested, \"CN=NA_WHS,OU=GroupsAndContacts,OU=Exchange,DC=na,DC=mycompany,DC=com\",\"member\"}\n },\n {\n topic_access_query, {in_group_nested, \"CN=NA_WHS,OU=GroupsAndContacts,OU=Exchange,DC=na,DC=mycompany,DC=com\",\"member\"}\n },\n {\n tag_queries, [\n {\n administrator, {in_group_nested,\"CN=NA_WHS,OU=GroupsAndContacts,OU=Exchange,DC=na,DC=mycompany,DC=com\",\"member\"}\n }\n ]\n }\n ]\n}\n```\n\n```text\n2019-05-28 16:04:14.662 [info] <0.678.0> LDAP CHECK: login for perryda\n2019-05-28 16:04:14.663 [info] <0.678.0> LDAP filling template \"${username}@mycompany.com\" with\n [{username,<<\"perryda\">>}]\n2019-05-28 16:04:14.663 [info] <0.678.0> LDAP template result: \"perryda@mycompany.com\"\n2019-05-28 16:04:14.750 [info] <0.317.0> LDAP bind succeeded: xxxx\n2019-05-28 16:04:14.750 [info] <0.317.0> LDAP filling template \"${username}@mycompany.com\" with\n [{username,<<\"perryda\">>}]\n2019-05-28 16:04:14.751 [info] <0.317.0> LDAP template result: \"perryda@mycompany.com\"\n2019-05-28 16:04:14.753 [info] <0.317.0> LDAP DN lookup: perryda -> CN=Perry\\, David,OU=Users,OU=WLNC-Wilmington,OU=OC,OU=IT-SD,DC=na,DC=mycompany,DC=com\n2019-05-28 16:04:14.753 [info] <0.317.0> LDAP CHECK: does perryda have tag administrator?\n2019-05-28 16:04:14.753 [info] <0.317.0> LDAP evaluating query: {in_group_nested,\"CN=NA_WHS,OU=GroupsAndContacts,OU=Exchange,DC=na,DC=mycompany,DC=com\",\"member\"}\n2019-05-28 16:04:14.753 [info] <0.317.0> LDAP evaluating query: {in_group_nested,\"CN=NA_WHS,OU=GroupsAndContacts,OU=Exchange,DC=na,DC=mycompany,DC=com\",\"member\",subtree}\n2019-05-28 16:04:14.754 [info] <0.317.0> LDAP filling template \"CN=NA_WHS,OU=GroupsAndContacts,OU=Exchange,DC=na,DC=mycompany,DC=com\" with\n [{username,<<\"perryda\">>},{user_dn,\"CN=Perry\\\\, David,OU=Users,OU=WLNC-Wilmington,OU=OC,OU=IT-SD,DC=na,DC=mycompany,DC=com\"}]\n2019-05-28 16:04:14.754 [info] <0.317.0> LDAP template result: \"CN=NA_WHS,OU=GroupsAndContacts,OU=Exchange,DC=na,DC=mycompany,DC=com\"\n2019-05-28 16:04:14.759 [info] <0.317.0> LDAP DECISION: does perryda have tag administrator? true\n2019-05-28 16:04:14.759 [info] <0.678.0> LDAP DECISION: login for perryda: ok\n2019-05-28 16:04:14.759 [warning] <0.678.0> HTTP access denied: user 'perryda' - invalid credentials\n```\n\n```text\n{rabbit,\n [\n .......\n {auth_backends, [rabbit_auth_backend_ldap, rabbit_auth_backend_internal]},\n .......\n ]}\n```\n\n========================================\n\nComments:\n- By 'instantly logged in' do you mean SSO? Using Kerberos? RabbitMQ does not support this. You can use username/password pairs or X.509 certificates. See rabbitmq.com/access-control.html#authentication\n- It sounds a bit related to stackoverflow.com/questions/56208101/…. I don't know how works the management plugin but you may have landed into in the same situation: group authorization needs to match user DNs so you need a lookup to occur *before* the authentication.\n- I see that now and I am just trying to login using my AD user and password. I am seemingly able to query LDAP correct for group membership, but am still getting an error. I have updated the question. Could you please take a look.\n- You really should just post to the `rabbitmq-users` list as that is where the core team (including myself) monitors questions. Posting to multiple places just increases confusion. groups.google.com/d/msg/rabbitmq-users/5hshoFy-QEM/V62Bba9TB‌​AAJ\n- Ok - will do that in the future now that I know.","metadata":{"transformedAt":"2026-08-18T18:33:20.331Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":3,"totalLines":204,"estimatedTokens":2010}}1175{"id":"stack-52703087","source":"stackoverflow","questionId":52703087,"title":"How to install RabbitMQ on EC2 instance (ubuntu)?","tags":["linux","amazon-ec2","rabbitmq","erlang","ubuntu-16.04"],"text":"Title: How to install RabbitMQ on EC2 instance (ubuntu)?\nTags: linux, amazon-ec2, rabbitmq, erlang, ubuntu-16.04\nSource: Stack Overflow\n\nQuestion:\nI am facing problem while installing Rabbit MQ on Amazon EC2 instance in Ubuntu-xenial-16.04 environment.\nI am following this link to install\n Install Rabbit MQ\n\nAnd when I go to 4th step \"sudo apt-get install erlang erlang-nox\", seems some problem with dependencies.\n\nhttps://i.sstatic.net/7JbZN.jpg\n\nCould anyone help to install it?\n\n========================================\n\nCode:\n```text\n# This repository provides Erlang packages\ndeb https://dl.bintray.com/rabbitmq-erlang/debian xenial erlang\n# This repository provides RabbitMQ packages\ndeb https://dl.bintray.com/rabbitmq/debian xenial main\n```\n\n```text\nsudo apt-get update\nsudo apt-get install erlang-nox\nsudo apt-get install rabbitmq-server\n```\n\n```text\nwget -O - \"https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc\" | sudo apt-key add -\n```\n\n```text\nsudo apt-get install apt-transport-https\n```\n\n```text\n/etc/apt/sources.list.d/bintray.rabbitmq.list\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.331Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":42,"estimatedTokens":277}}1176{"id":"stack-57320040","source":"stackoverflow","questionId":57320040,"title":"Can RabbitMQ cluster be used as a single endpoint by application?","tags":["rabbitmq"],"text":"Title: Can RabbitMQ cluster be used as a single endpoint by application?\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\n- There are three nodes in a RabbitMQ cluster as below.\n\n- Within RabbitMQ, there are two queues, `q1` and `q2`.\n\n- The master replica of `q1` and `q2` are distributed on different nodes. Both queues are mirrored by other nodes.\n\n- There is a load balancer in front of three nodes.\n\n- AMQP(node port 5672) and Management HTTP API(node port 15672) are exposed by load balancer.\n\nhttps://i.sstatic.net/m5u1G.jpg\n\nWhen application establishes a connection through load balancer, it could reach a random RabbitMQ node behind. And this is invisible to application.\n\n**Question**: \n\nIs it ok for application to consume both queues in **a single AMQP channel over a single connection** no matter which RabbitMQ node it reaches?\n\nIt is ok for application to call management HTTP API no matter which RabbitMQ node its request hits?\n\n========================================\n\nCode:\n```text\nq1\n```\n\n```text\nq2\n```\n\n```text\nq1\n```\n\n```text\nq2\n```\n\n```text\nq1\n```\n\n```text\nNode #1\n```\n\n========================================\n\nComments:\n- 1. Yes. In general practice same channel is used to consume from multiple queues. What exactly do you mean by \"which RabbitMQ node it reaches?\" 2. Yes. The management information is kept in mnesia inside each node so the request to any node will suffice\n- stackoverflow.com/questions/18418936/… -> check this out for more clarity\n- Thanks @bumblebee, I may not make myself clear :) So application establishes a single connection to cluster. Over this connection, application creates only one channel. It is ok to consume both queues via this single channel, right? P.S. I am using RabbitMQ .NET Client.\n- A connection can have multiple channels which might be used by multiple queues to connect to the broker. With each queue using its own connection there will be multiple TCP connections required which is not good for any system.","metadata":{"transformedAt":"2026-08-18T18:33:20.331Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":59,"estimatedTokens":497}}1177{"id":"stack-48845714","source":"stackoverflow","questionId":48845714,"title":"How to move messages from one queue to another in RabbitMQ","tags":["rabbitmq","message-queue","spring-amqp","messagebroker","rabbitmq-exchange"],"text":"Title: How to move messages from one queue to another in RabbitMQ\nTags: rabbitmq, message-queue, spring-amqp, messagebroker, rabbitmq-exchange\nSource: Stack Overflow\n\nQuestion:\nIn RabbitMQ,I have a failure queue, in which I have all the failed messages from different Queues. Now I want to give the functionality of 'Retry', so that administrator can again move the failed messages to their respective queue. The idea is something like that:\n\nhttps://i.sstatic.net/8Nb15.png\n\nAbove diagram is structure of my failure queue. After click on Retry link, message should move into original queue i.e. queue1, queue2 etc.\n\n========================================\n\nTop Answer:\nIt's not straight forward consume and publish. RabbitMQ is not designed in that way. it takes into consideration that exchange and queue both could be temporary and can be deleted. This is embedded in the channel to close the connection after single publish.\n\nAssumptions:\n - You have a durable queue and exchange for destination ( to send to)\n - You have a durable queue for target ( to take from )\n\nHere is the code to do so:\n\n```\nimport com.rabbitmq.client.Channel;\n import com.rabbitmq.client.QueueingConsumer;\n import org.apache.commons.lang.StringUtils;\n import org.slf4j.Logger;\n import org.slf4j.LoggerFactory;\n import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; \n\n public object shovelMessage(\n String exchange,\n String targetQueue,\n String destinationQueue,\n String host,\n Integer port,\n String user,\n String pass,\n int count) throws IOException, TimeoutException, InterruptedException {\n\n if(StringUtils.isEmpty(exchange) || StringUtils.isEmpty(targetQueue) || StringUtils.isEmpty(destinationQueue)) {\n return null;\n }\n\n CachingConnectionFactory factory = new CachingConnectionFactory();\n factory.setHost(StringUtils.isEmpty(host)?internalHost.split(\":\")[0]:host);\n factory.setPort(port>0 ? port: Integer.parseInt(internalPort.split(\":\")[1]));\n factory.setUsername(StringUtils.isEmpty(user)? this.user: user);\n factory.setPassword(StringUtils.isEmpty(pass)? this.pass: pass);\n Channel tgtChannel = null;\n try {\n org.springframework.amqp.rabbit.connection.Connection connection = factory.createConnection();\n\n tgtChannel = connection.createChannel(false);\n tgtChannel.queueDeclarePassive(targetQueue);\n\n QueueingConsumer consumer = new QueueingConsumer(tgtChannel);\n tgtChannel.basicQos(1);\n tgtChannel.basicConsume(targetQueue, false, consumer);\n\n for (int i = 0; i < count; i++) {\n QueueingConsumer.Delivery msg = consumer.nextDelivery(500);\n if(msg == null) {\n // if no message found, break from the loop.\n break;\n }\n //Send it to destination Queue\n // This repetition is required as channel looses the connection with \n //queue after single publish and start throwing queue or exchange not \n //found connection.\n Channel destChannel = connection.createChannel(false);\n try {\n destChannel.queueDeclarePassive(destinationQueue);\n SerializerMessageConverter serializerMessageConverter = new SerializerMessageConverter();\n Message message = new Message(msg.getBody(), new MessageProperties());\n Object o = serializerMessageConverter.fromMessage(message);\n// for some reason msg.getBody() writes byte array which is read as a byte array // on the consumer end due to which this double conversion.\n destChannel.basicPublish(exchange, destinationQueue, null, serializerMessageConverter.toMessage(o, new MessageProperties()).getBody());\n tgtChannel.basicAck(msg.getEnvelope().getDeliveryTag(), false);\n } catch (Exception ex) {\n // Send Nack if not able to publish so that retry is attempted\n tgtChannel.basicNack(msg.getEnvelope().getDeliveryTag(), true, true);\n log.error(\"Exception while producing message \", ex);\n } finally {\n try {\n destChannel.close();\n } catch (Exception e) {\n log.error(\"Exception while closing destination channel \", e);\n }\n\n }\n }\n\n } catch (Exception ex) {\n log.error(\"Exception while creating consumer \", ex);\n } finally {\n try {\n tgtChannel.close();\n } catch (Exception e) {\n log.error(\"Exception while closing destination channel \", e);\n }\n }\n\n return null;\n\n }\n```\n\n========================================\n\nCode:\n```text\nimport com.rabbitmq.client.Channel;\n import com.rabbitmq.client.QueueingConsumer;\n import org.apache.commons.lang.StringUtils;\n import org.slf4j.Logger;\n import org.slf4j.LoggerFactory;\n import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; \n\n public object shovelMessage(\n String exchange,\n String targetQueue,\n String destinationQueue,\n String host,\n Integer port,\n String user,\n String pass,\n int count) throws IOException, TimeoutException, InterruptedException {\n\n if(StringUtils.isEmpty(exchange) || StringUtils.isEmpty(targetQueue) || StringUtils.isEmpty(destinationQueue)) {\n return null;\n }\n\n CachingConnectionFactory factory = new CachingConnectionFactory();\n factory.setHost(StringUtils.isEmpty(host)?internalHost.split(\":\")[0]:host);\n factory.setPort(port>0 ? port: Integer.parseInt(internalPort.split(\":\")[1]));\n factory.setUsername(StringUtils.isEmpty(user)? this.user: user);\n factory.setPassword(StringUtils.isEmpty(pass)? this.pass: pass);\n Channel tgtChannel = null;\n try {\n org.springframework.amqp.rabbit.connection.Connection connection = factory.createConnection();\n\n tgtChannel = connection.createChannel(false);\n tgtChannel.queueDeclarePassive(targetQueue);\n\n QueueingConsumer consumer = new QueueingConsumer(tgtChannel);\n tgtChannel.basicQos(1);\n tgtChannel.basicConsume(targetQueue, false, consumer);\n\n for (int i = 0; i < count; i++) {\n QueueingConsumer.Delivery msg = consumer.nextDelivery(500);\n if(msg == null) {\n // if no message found, break from the loop.\n break;\n }\n //Send it to destination Queue\n // This repetition is required as channel looses the connection with \n //queue after single publish and start throwing queue or exchange not \n //found connection.\n Channel destChannel = connection.createChannel(false);\n try {\n destChannel.queueDeclarePassive(destinationQueue);\n SerializerMessageConverter serializerMessageConverter = new SerializerMessageConverter();\n Message message = new Message(msg.getBody(), new MessageProperties());\n Object o = serializerMessageConverter.fromMessage(message);\n// for some reason msg.getBody() writes byte array which is read as a byte array // on the consumer end due to which this double conversion.\n destChannel.basicPublish(exchange, destinationQueue, null, serializerMessageConverter.toMessage(o, new MessageProperties()).getBody());\n tgtChannel.basicAck(msg.getEnvelope().getDeliveryTag(), false);\n } catch (Exception ex) {\n // Send Nack if not able to publish so that retry is attempted\n tgtChannel.basicNack(msg.getEnvelope().getDeliveryTag(), true, true);\n log.error(\"Exception while producing message \", ex);\n } finally {\n try {\n destChannel.close();\n } catch (Exception e) {\n log.error(\"Exception while closing destination channel \", e);\n }\n\n }\n }\n\n } catch (Exception ex) {\n log.error(\"Exception while creating consumer \", ex);\n } finally {\n try {\n tgtChannel.close();\n } catch (Exception e) {\n log.error(\"Exception while closing destination channel \", e);\n }\n }\n\n return null;\n\n }\n```\n\n```text\ndo {\n val movedToQueue = rabbitTemplate.receiveAndReply<String, String>(dlq, { it }, \"\", queue)\n} while (movedToQueue)\n```\n\n```text\nreceiveAndReply\n```\n\n```text\ndlq\n```\n\n```text\nqueue\n```\n\n```text\ndlq\n```\n\n```text\n{ it }\n```\n\n```text\n\"\"\n```\n\n```text\nqueue\n```\n\n========================================\n\nComments:\n- I don't know what you are looking for here. You have to write code to do this, and somewhere you're going to have to publish the message.\n- And I don't know how many times you really want to try dividing by zero, but you're never going to get a different answer there 😜\n- Hi, I just want to move messages from one queue to another. I just wanted to check, if it's possible in rabbitMQ to move any message from one queue to another. I know that Shovel plugin would help but it move entire queue in another queue. I need to move them randomly one by one. If it's possible then I am looking Java implementation for that.\n- I think you need to get yourself familiar with DLX: rabbitmq.com/dlx.html\n- Not sure why this question is -1\n- Is it possible to move message #2 from my failure queue without removing message #1? I haven't found any way to do that.\n- RabbitMQ is not designed in that way, if you know how a Queue is supposed to work, you will understand that. A producer produces messages into a queue and a consumer consumes messages from that queue, everything in FIFO way. So, what you are saying is that RabbitMQ should be implemented through a different data structure, which is not the current case.\n- Thanks Arpan. the same thing which I was thinking.","metadata":{"transformedAt":"2026-08-18T18:33:20.331Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":242,"estimatedTokens":2523}}1178{"id":"stack-37695995","source":"stackoverflow","questionId":37695995,"title":"Remove a consumer in RabbitMQ with nodeJS","tags":["javascript","node.js","rabbitmq","sails.js"],"text":"Title: Remove a consumer in RabbitMQ with nodeJS\nTags: javascript, node.js, rabbitmq, sails.js\nSource: Stack Overflow\n\nQuestion:\nI am trying to my listener to listen the queue only 1 message after what i want to remove my consumer instantly. How can i achieve this.\nhere is the code.\n\n```\nqueueListener:function(Queue,timeOut){\n var deferred=sails.promise.defer(),timer,data;\n sails.amqp.connect('amqp://localhost', function(err, conn) {\n conn.createConfirmChannel(function(err, ch) {\n if(err){\n conn.close();\n deferred.reject(err);\n }else{\n ch.assertQueue(Queue, {durable: true});\n ch.prefetch(1);\n ch.consume(Queue,function(msg){\n data=msg.content.toString();\n clearTimeout(timer);\n ch.ack(msg);\n setTimeout(function(){\n conn.close();\n deferred.resolve(data);\n },0);\n },{noAck: false});\n }\n });\n timer=setTimeout(function(){\n conn.close();\n deferred.reject(new Error(\"Nothing in the Queue.\"));\n },timeOut-5);\n });\n return deferred.promise;\n }\n```\n\nin the above **Queue** is the queue it will be listening and timeOut represents how long my listener will be listening.\nIf it listens a message i want to stop listening.And for further listening i will be invoking the function **queueListner** next time.\nThough i have made `conn.close()` but at the UI it still shows consumer.\nhttps://i.sstatic.net/tKS19.png\n\n========================================\n\nCode:\n```text\nqueueListener:function(Queue,timeOut){\n var deferred=sails.promise.defer(),timer,data;\n sails.amqp.connect('amqp://localhost', function(err, conn) {\n conn.createConfirmChannel(function(err, ch) {\n if(err){\n conn.close();\n deferred.reject(err);\n }else{\n ch.assertQueue(Queue, {durable: true});\n ch.prefetch(1);\n ch.consume(Queue,function(msg){\n data=msg.content.toString();\n clearTimeout(timer);\n ch.ack(msg);\n setTimeout(function(){\n conn.close();\n deferred.resolve(data);\n },0);\n },{noAck: false});\n }\n });\n timer=setTimeout(function(){\n conn.close();\n deferred.reject(new Error(\"Nothing in the Queue.\"));\n },timeOut-5);\n });\n return deferred.promise;\n }\n```\n\n```text\nconn.close()\n```\n\n```text\nch.get(\"queue-name\").then(messageHandlerFunction)\n```\n\n```text\nconsume\n```\n\n```text\nget\n```\n\n========================================\n\nComments:\n- You can also ask on the RabbitMQ-users group at groups.google.com/forum/#!forum/rabbitmq-users, also check release notes for fixed bugs (in case you are using an older version)\n- I have asked there groups.google.com/forum/#!topic/rabbitmq-users/VlSKlfSWT7g but if anyone have a solution please .\n- Will i need to close the connection if i use get method.\n- yes. the connection is separate from anything you do on the channel. you will still have to manage the connection the same way\n- Thanks @Derick That helped me a lot.\n- i receive TypeError: cb is not a function","metadata":{"transformedAt":"2026-08-18T18:33:20.331Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":103,"estimatedTokens":745}}1179{"id":"stack-40176907","source":"stackoverflow","questionId":40176907,"title":"Integrating Spring Cloud Sleuth with Spring boot amqp","tags":["spring-boot","rabbitmq","amqp","spring-cloud-sleuth"],"text":"Title: Integrating Spring Cloud Sleuth with Spring boot amqp\nTags: spring-boot, rabbitmq, amqp, spring-cloud-sleuth\nSource: Stack Overflow\n\nQuestion:\nLooking for an example that shows integrating spring cloud sleuth with spring boot amqp (rabbit) publisher and subscriber. \n\nI do see the following messages in the log\n\n2016-10-21 08:35:15.708 INFO [producer,9148f56490e5742f,943ed050691842ab,false] 30928 --- [nio-8080-exec-1] a.b.c.controllers.MessagingController : Received Request to pulish with Activity OrderShipped \n2016-10-21 08:35:15.730 INFO [producer,9148f56490e5742f,943ed050691842ab,false] 30928 --- [nio-8080-exec-1] a.b.c.service.ProducerService : Message published\n\nWhen I look at messages on Queue, I don't see traceId or any other details added to the header. Should I use MessagePostProcessor to add these to the header?\n\nAlso what should be done on the receiving service?\n\n========================================\n\nTop Answer:\nUsing Spring AMQP you can set `MessagePostProcessor` on the `RabbitTemplate`using the setBeforePublishPostProcessors method.\n\nWe implemented the `org.springframework.amqp.core.MessagePostProcessor` and Overrided the `postProcessMessage` method this way:\n\n```\n@Override\npublic org.springframework.amqp.core.Message postProcessMessage(org.springframework.amqp.core.Message message)\n throws AmqpException {\n MessagingMessageConverter converter = new MessagingMessageConverter();\n MessageBuilder mb = MessageBuilder.fromMessage((Message) converter.fromMessage(message));\n inject(tracer.getCurrentSpan(), mb);\n return converter.toMessage(mb.build(), message.getMessageProperties());\n}\n```\n\nThe `inject` method can now set all the required headers on the message, and it will be passed to the rabbitMq with the changes.\n\nYou have a great example of how to implement such `inject` method in `org.springframework.cloud.sleuth.instrument.messaging.MessagingSpanInjector`\n\nWe are using v1.1.1 of spring-cloud-sleuth-stream so my example is based on this version, in next release(1.2) it will be easier.\n\n========================================\n\nCode:\n```text\n@Override\npublic org.springframework.amqp.core.Message postProcessMessage(org.springframework.amqp.core.Message message)\n throws AmqpException {\n MessagingMessageConverter converter = new MessagingMessageConverter();\n MessageBuilder<?> mb = MessageBuilder.fromMessage((Message<?>) converter.fromMessage(message));\n inject(tracer.getCurrentSpan(), mb);\n return converter.toMessage(mb.build(), message.getMessageProperties());\n}\n```\n\n```text\nMessagePostProcessor\n```\n\n```text\nRabbitTemplate\n```\n\n```text\norg.springframework.amqp.core.MessagePostProcessor\n```\n\n```text\npostProcessMessage\n```\n\n```text\ninject\n```\n\n```text\ninject\n```\n\n```text\norg.springframework.cloud.sleuth.instrument.messaging.MessagingSpanInjector\n```\n\n========================================\n\nComments:\n- If we are using Spring Boot 2.x and Sleuth, it just enough to enable the property `spring.sleuth.messaging.rabbit.enabled=true` for this purpose.\n- Hi Marcin - thank you. I wouldn't mind writing the code. Is are some samples on how to integrate.\n- We have a concept of SpanInjector and SpanExtractor. You can take a look at those used in messaging - github.com/spring-cloud/spring-cloud-sleuth/blob/master/… and github.com/spring-cloud/spring-cloud-sleuth/blob/master/… . They take care of retreiving and passing of tracing info in messages.\n- Marcin - If I implement my own version of SpanInjector, how the inject method get called?\n- Made some progress. Able to publish the info, but it would be nice, if I could do it in a interceptor\n- Try to file an issue in the Spring AMQP project. BTW Can we mark this as answered?\n- @MarcinGrzejszczak can you please fix the links, they are broken\n- They aren't broken - they are old. Currently in master we have a different version that no longer supports this concept. This is the old approach cloud.spring.io/spring-cloud-sleuth/1.1.x/#_customizations and this is the current new one cloud.spring.io/spring-cloud-sleuth/…\n- We ended up doing similar stuff.\n- @yuval-simhon - care for a PR to Sleuth? :)","metadata":{"transformedAt":"2026-08-18T18:33:20.331Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":8,"totalLines":95,"estimatedTokens":1039}}1180{"id":"stack-37508457","source":"stackoverflow","questionId":37508457,"title":"AMQP/RabbitMQ - Only real-time messages/passthrough queue","tags":["rabbitmq","amqp"],"text":"Title: AMQP/RabbitMQ - Only real-time messages/passthrough queue\nTags: rabbitmq, amqp\nSource: Stack Overflow\n\nQuestion:\nI am building a website which receives real-time updates about soccer matches. I am using RabbitMQ to send the updates to the clients (JS website and Android/iOS apps).\n\n**The clients should only receive real-time updates.** In other words, a client should only receive updates when the user is logged in. No history is kept.\n\nTo achieve this behavior, I was thinking about the following architecture:\n\n- A fanout exchange in RabbitMQ.\n\n- Each user has a dedicated queue, which is bound to the exchange. This queue is created when the user account is created.\n\n- For these queues, the queue property `x-message-ttl` with value of 0 is set. See below.\n\n- When the user logs in, the client consumes the queue of the corresponding user.\n\n- Messages are sent to the exchange by the backend, and forwarded to all queues. When a user is not logged in, the message will be discarded immediately, as `x-message-ttl` is set to 0.\n\nIs this a correct usage of AMQP/RabbitMQ to achieve real-time notifications?\n\n========================================\n\nCode:\n```text\nx-message-ttl\n```\n\n```text\nx-message-ttl\n```\n\n```text\nIn other words, a client should only receive updates when the user is logged in.\n```\n\n```text\nEach user has a dedicated queue, which is bound to the exchange. This queue is created when the user account is created.\n```\n\n```text\nWhen a user is not logged in, the message will be discarded immediately\n```\n\n```text\nMessages are sent to the exchange by the backend, and forwarded to all queues\n```\n\n========================================\n\nComments:\n- If the queue is created after logging in, does this mean that the queue should be declared as `auto-delable`?\n- By logging in do you mean logging in to your website, or logging in - establishing connection to RMQ? If you don't want the user to the messages that he missed while logged out (from the website/webapp) than make it auto-delete.\n- Thank you, got it now. I did not understand that queues are meant to be created/deleted on the fly. I thought that queues should be more or less static. I will try it out.\n- YOu are welcome. Well they could be, but it's up to the use case.","metadata":{"transformedAt":"2026-08-18T18:33:20.331Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":57,"estimatedTokens":566}}1181{"id":"stack-46157864","source":"stackoverflow","questionId":46157864,"title":"RabbitMQ not serialize message, error convert","tags":["jackson","rabbitmq","spring-amqp","spring-rabbit"],"text":"Title: RabbitMQ not serialize message, error convert\nTags: jackson, rabbitmq, spring-amqp, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI've seen some related questions here, but none worked for me, the rabbit will not serialize my message coming from another application.\n\n```\nCaused by: org.springframework.amqp.AmqpException: No method found for class [B\n```\n\nBelow my configuration class to receive the messages.\n\n```\n@Configuration\npublic class RabbitConfiguration implements RabbitListenerConfigurer{\n\n public final static String EXCHANGE_NAME = \"wallet-accounts\"; \n public final static String QUEUE_PAYMENT = \"wallet-accounts.payment\";\n public final static String QUEUE_RECHARGE = \"wallet-accounts.recharge\";\n\n @Bean\n public List ds() {\n return queues(QUEUE_PAYMENT, QUEUE_RECHARGE);\n }\n\n @Autowired\n private ConnectionFactory rabbitConnectionFactory;\n\n @Bean\n public AmqpAdmin amqpAdmin() {\n return new RabbitAdmin(rabbitConnectionFactory);\n }\n\n @Bean\n public TopicExchange exchange() {\n return new TopicExchange(EXCHANGE_NAME);\n }\n\n private List queues(String ... names){\n List result = new ArrayList<>();\n\n for (int i = 0; i Using this other configuration, the error is almost the same:\n\n```\nCaused by: org.springframework.amqp.support.converter.MessageConversionException: failed to resolve class name. Class not found [br.com.beblue.wallet.payment.application.accounts.PaymentEntryCommand]\n```\n\nConfiguration: \n\n```\n@Configuration\npublic class RabbitConfiguration {\n\n public final static String EXCHANGE_NAME = \"wallet-accounts\"; \n\n public final static String QUEUE_PAYMENT = \"wallet-accounts.payment\";\n public final static String QUEUE_RECHARGE = \"wallet-accounts.recharge\";\n\n @Bean\n public List ds() {\n return queues(QUEUE_PAYMENT, QUEUE_RECHARGE);\n }\n\n @Autowired\n private ConnectionFactory rabbitConnectionFactory;\n\n @Bean\n public AmqpAdmin amqpAdmin() {\n return new RabbitAdmin(rabbitConnectionFactory);\n }\n\n @Bean\n public TopicExchange exchange() {\n return new TopicExchange(EXCHANGE_NAME);\n }\n\n @Bean\n public MessageConverter jsonMessageConverter() {\n return new Jackson2JsonMessageConverter();\n }\n\n private List queues(String ... names){\n List result = new ArrayList<>();\n\n for (int i = 0; i Can anyone tell me what's wrong with these settings, or what's missing?\n\n========================================\n\nCode:\n```text\nCaused by: org.springframework.amqp.AmqpException: No method found for class [B\n```\n\n```text\n@Configuration\npublic class RabbitConfiguration implements RabbitListenerConfigurer{\n\n public final static String EXCHANGE_NAME = \"wallet-accounts\"; \n public final static String QUEUE_PAYMENT = \"wallet-accounts.payment\";\n public final static String QUEUE_RECHARGE = \"wallet-accounts.recharge\";\n\n @Bean\n public List<Declarable> ds() {\n return queues(QUEUE_PAYMENT, QUEUE_RECHARGE);\n }\n\n @Autowired\n private ConnectionFactory rabbitConnectionFactory;\n\n @Bean\n public AmqpAdmin amqpAdmin() {\n return new RabbitAdmin(rabbitConnectionFactory);\n }\n\n @Bean\n public TopicExchange exchange() {\n return new TopicExchange(EXCHANGE_NAME);\n }\n\n private List<Declarable> queues(String ... names){\n List<Declarable> result = new ArrayList<>();\n\n for (int i = 0; i < names.length; i++) {\n result.add(makeQueue(names[i]));\n result.add(makeBinding(names[i]));\n }\n return result;\n }\n\n private static Binding makeBinding(String queueName){\n return new Binding(queueName, DestinationType.QUEUE, EXCHANGE_NAME, queueName, null);\n }\n\n private static Queue makeQueue(String name){\n return new Queue(name);\n }\n\n @Bean\n public MappingJackson2MessageConverter jackson2Converter() {\n MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();\n return converter;\n }\n\n @Bean\n public DefaultMessageHandlerMethodFactory myHandlerMethodFactory() {\n DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();\n factory.setMessageConverter(jackson2Converter());\n return factory;\n }\n\n @Override\n public void configureRabbitListeners(RabbitListenerEndpointRegistrar registrar) {\n registrar.setMessageHandlerMethodFactory(myHandlerMethodFactory());\n }\n}\n```\n\n```text\nCaused by: org.springframework.amqp.support.converter.MessageConversionException: failed to resolve class name. Class not found [br.com.beblue.wallet.payment.application.accounts.PaymentEntryCommand]\n```\n\n```text\n@Configuration\npublic class RabbitConfiguration {\n\n public final static String EXCHANGE_NAME = \"wallet-accounts\"; \n\n public final static String QUEUE_PAYMENT = \"wallet-accounts.payment\";\n public final static String QUEUE_RECHARGE = \"wallet-accounts.recharge\";\n\n @Bean\n public List<Declarable> ds() {\n return queues(QUEUE_PAYMENT, QUEUE_RECHARGE);\n }\n\n @Autowired\n private ConnectionFactory rabbitConnectionFactory;\n\n @Bean\n public AmqpAdmin amqpAdmin() {\n return new RabbitAdmin(rabbitConnectionFactory);\n }\n\n @Bean\n public TopicExchange exchange() {\n return new TopicExchange(EXCHANGE_NAME);\n }\n\n @Bean\n public MessageConverter jsonMessageConverter() {\n return new Jackson2JsonMessageConverter();\n }\n\n private List<Declarable> queues(String ... names){\n List<Declarable> result = new ArrayList<>();\n\n for (int i = 0; i < names.length; i++) {\n result.add(makeQueue(names[i]));\n result.add(makeBinding(names[i]));\n }\n return result;\n }\n\n private static Binding makeBinding(String queueName){\n return new Binding(queueName, DestinationType.QUEUE, EXCHANGE_NAME, queueName, null);\n }\n\n private static Queue makeQueue(String name){\n return new Queue(name);\n }\n}\n```\n\n```text\nSimpleMessageConverter\n```\n\n```text\napplication/json\n```\n\n```text\ncontent-type\n```\n\n```text\nbyte[]\n```\n\n```text\nJackson2JsonMessageConverter\n```\n\n```text\napplication/json\n```\n\n```text\n__TypeId__\n```\n\n```text\nDefaultMessageHandlerMethodFactory\n```\n\n```text\nSimpleRabbitListenerContainerFactory\n```\n\n```text\nsetMessageConverter\n```\n\n```text\norg.springframework.amqp.support.converter.MessageConverter\n```\n\n```text\nSimpleRabbitListenerContainerFactoryConfigurer\n```\n\n========================================\n\nComments:\n- Ty Artem, the problem is that I was not configuring the factory in the consumer method: @RabbitListener(id = \"listenerPayment\", queues = RabbitConfiguration.QUEUE_PAYMENT, containerFactory=\"myFactory\")","metadata":{"transformedAt":"2026-08-18T18:33:20.331Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":16,"totalLines":266,"estimatedTokens":1649}}1182{"id":"stack-45699396","source":"stackoverflow","questionId":45699396,"title":"MassTransit Activity Fault with parameters","tags":["c#","rabbitmq","message-queue","masstransit"],"text":"Title: MassTransit Activity Fault with parameters\nTags: c#, rabbitmq, message-queue, masstransit\nSource: Stack Overflow\n\nQuestion:\nI am currently using Masstransit in with the Courier pattern.\n\nI´ve set up an Activity which may fail, and I want to be able to subscribe to this failure and act accordingly.\n\nMy problem is, even though I can subscribe to the failure, and even see the exception that caused the failure, I am unable to pass any arguments to it.\n\nFor testing purposes, supose I have the following activity:\n\n```\npublic class MyActivity : ExecuteActivity\n{\n public Task Execute(ExecuteContext context)\n {\n try\n {\n // .... some code\n throw new FaultException(\n new RegistrationRefusedData(RegistrationRefusedReason.ItemUnavailable));\n // .... some code\n }\n catch (Exception ex)\n {\n return Task.FromResult(context.Faulted(ex));\n }\n }\n}\n```\n\nThe problem is in the reason (`RegistrationRefusedReason`) I am passing as a argument of the exception. If I subscribe a `RoutingSlipActivityFaulted` consumer, I can *almost* get all the information I need:\n\n```\npublic class ActivityFaultedConsumer : IMessageConsumer\n{\n public void Consume(RoutingSlipActivityFaulted message)\n {\n string exceptionMessage = message.ExceptionInfo.Message; // OK\n string messageType = message.ExceptionInfo.ExceptionType; // OK\n RegistrationRefusedReason reason = ??????;\n }\n}\n```\n\nI feel like I am missing something important here, (maybe misusing the pattern?).\n\nIs there any other way to get parameters from a faulted activity ?\n\n========================================\n\nTop Answer:\nKinda raising this from the dead, but I really haven't found a neat solution to this.\n\n**Here is my scenario:**\n\n- I want to implement a request/response, but I want to wait for the execution of a routing slip.\n\n- As Fabio, I want to compensate for any previous activities and I want to pass data back to the request client in case of a fault.\n\nConveniently, Chris provided a `RoutingSlipRequestProxy`/`RoutingSlipResponseProxy` which does just that. I've found 2 approaches, but both of them seem very hacky to me.\n\n**Approach 1:**\n\n- The request client waits for `ISimpleResponse` or `ISimpleFailResponse`.\n\n- `RoutingSlipRequestProxy` sets the `ResponseAddress` in the variables.\n\n- The activity sends `ISimpleFailResponse` to the `ResponseAddress`.\n\n- The client waits for either response\n\n- The `RoutingSlipResponseProxy` sends back `Fault` to the `ResponseAddress`.\n\nFrom what I see the hackiness comes from step 4/5 and their order. I am pretty sure it works, but it could easily stop working in case messages are consumed out-of-order.\n\n*Sample code*: https://github.com/steliyan/Sample-RequestResponse/commit/3fcb196804d9db48617a49c7a8f8c276b47b03ef\n\n**Approach 2:**\n\n- The request client waits for `ISimpleResponse` or `ISimpleFailResponse`.\n\n- The activity calls `ReviseItirery` with the variables and adds a faulty activity.*\n\n- The faulty activity faults\n\n- The `RoutingSlipResponseProxy2` get the `ValidationErrors` and sends back `ISimpleFailResponse` to the `ResponseAddress`.\n\n* The activity needs to be `Activity` and not `ExecuteActivity` because there is no overload of `ReviseItinerary` with variables but with no activity log.\n\nThis approach seems hacky because an additional fault activity is added to the itinerary, just to be able to add a variable to the routing slip.\n\n*Sample code*: https://github.com/steliyan/Sample-RequestResponse/commit/e9644fa683255f2bda8ae33d8add742f6ffe3817\n\n**Conclusion:**\nLooking at MassTransit code, it doesn't seem like a problem to add a `FaultedWithVariables` overload. However, I think Chris' point is that there should be a better way to design the workflow, but I am not sure about that.\n\n========================================\n\nCode:\n```text\npublic class MyActivity : ExecuteActivity<MyMessage>\n{\n public Task<ExecutionResult> Execute(ExecuteContext<MyMessage> context)\n {\n try\n {\n // .... some code\n throw new FaultException<RegistrationRefusedData>(\n new RegistrationRefusedData(RegistrationRefusedReason.ItemUnavailable));\n // .... some code\n }\n catch (Exception ex)\n {\n return Task.FromResult(context.Faulted(ex));\n }\n }\n}\n```\n\n```text\npublic class ActivityFaultedConsumer : IMessageConsumer<RoutingSlipActivityFaulted>\n{\n public void Consume(RoutingSlipActivityFaulted message)\n {\n string exceptionMessage = message.ExceptionInfo.Message; // OK\n string messageType = message.ExceptionInfo.ExceptionType; // OK\n RegistrationRefusedReason reason = ??????;\n }\n}\n```\n\n```text\nRegistrationRefusedReason\n```\n\n```text\nRoutingSlipActivityFaulted\n```\n\n```text\ncontext.Publish<RegistrationRefused>(new {\n CustomerId = xxx,\n ItemId = xxxx,\n Reason = \"Item was unavailable\"\n });\n\ncontext.Terminate();\n```\n\n```text\nFault\n```\n\n```text\nPublish\n```\n\n```text\nRoutingSlipTerminated\n```\n\n```text\nRoutingSlipRequestProxy\n```\n\n```text\nRoutingSlipResponseProxy\n```\n\n```text\nISimpleResponse\n```\n\n```text\nISimpleFailResponse\n```\n\n```text\nRoutingSlipRequestProxy\n```\n\n```text\nResponseAddress\n```\n\n```text\nISimpleFailResponse\n```\n\n```text\nResponseAddress\n```\n\n```text\nRoutingSlipResponseProxy\n```\n\n```text\nFault<ISimpleResponse>\n```\n\n```text\nResponseAddress\n```\n\n```text\nISimpleResponse\n```\n\n```text\nISimpleFailResponse\n```\n\n```text\nReviseItirery\n```\n\n```text\nRoutingSlipResponseProxy2\n```\n\n```text\nValidationErrors\n```\n\n```text\nISimpleFailResponse\n```\n\n```text\nResponseAddress\n```\n\n```text\nActivity\n```\n\n```text\nExecuteActivity\n```\n\n```text\nReviseItinerary\n```\n\n```text\nFaultedWithVariables\n```\n\n========================================\n\nComments:\n- I guess if I had a `context.FaultedWithVariables` at the activity that would work...\n- I guess that makes sense. But, will the `Terminate` method start compensating previous activities ? I need the whole routing slip to have a consistent transaction...\n- Just tested... it doesn´t . Should I send the message, & use Faulted() in this case, or am i misusing it ? (great job on mt btw)\n- Yes, if you want to compensate, throw an exception and still publish your event to have the business context.","metadata":{"transformedAt":"2026-08-18T18:33:20.331Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":30,"totalLines":259,"estimatedTokens":1554}}1183{"id":"stack-26744781","source":"stackoverflow","questionId":26744781,"title":"Using Ninject With EasyNetQ/RabbitMQ Message Handlers","tags":["c#",".net","rabbitmq","ninject","easynetq"],"text":"Title: Using Ninject With EasyNetQ/RabbitMQ Message Handlers\nTags: c#, .net, rabbitmq, ninject, easynetq\nSource: Stack Overflow\n\nQuestion:\nI'm attempting to use EasyNetQ with Ninject to log messages. \n\nI've managed to setup Ninject as the EasyNetQ DI (I think), but when a message comes to a handler without a parameterless constructor (e.g. I need a repository bound in there), it doesn't resolve. Or atleast I believe that's the issue as I get a pretty generic error on the console. \n\nI tell EasyNetQ to use Ninject like so : \n\n```\nRabbitHutch.SetContainerFactory(() => new NinjectAdapter(container));\n```\n\nI think this is all I need to set it up. The Ninject Adapter is the one from EasyNetQ. \n\nMy handler looks like the following : \n\n```\npublic class ProfileDeactivatedUpdateHandler : IConsume\n{\n private readonly IProfileRepository _profileRepository;\n\n public ProfileDeactivatedUpdateHandler(IProfileRepository profileRepository)\n {\n _profileRepository = profileRepository;\n }\n\n public void Consume(ProfileDeactivatedUpdate message)\n { \n //Do Stuff. \n }\n}\n```\n\nIf I add a parameterless constructor, and instead setup Ninject to be available through the ServiceLocator (Ugh), then it works. The handler is called fine, and I can find my repository via the ServiceLocator, So I know that atleast Ninject knows about the repository. \n\nThe error that pops up when it tries to handle a message is. \n\n```\nSystem.AggregateException: One or more errors occurred. ---> System.Exception: E\nxception of type 'System.Exception' was thrown.\n at EasyNetQ.ReflectionHelpers.DefaultFactories`1.Get()\n at EasyNetQ.ReflectionHelpers.CreateInstance[T]()\n at EasyNetQ.AutoSubscribe.DefaultAutoSubscriberMessageDispatcher.Dispatch[TMe\nssage,TConsumer](TMessage message)\n at EasyNetQ.RabbitBus.<>c__DisplayClass6`1.b__5(T msg)\n --- End of inner exception stack trace ---\n---> (Inner Exception #0) System.Exception: Exception of type 'System.Exception'\n was thrown.\n at EasyNetQ.ReflectionHelpers.DefaultFactories`1.Get()\n at EasyNetQ.ReflectionHelpers.CreateInstance[T]()\n at EasyNetQ.AutoSubscribe.DefaultAutoSubscriberMessageDispatcher.Dispatch[TMe\nssage,TConsumer](TMessage message)\n at EasyNetQ.RabbitBus.<>c__DisplayClass6`1.b__5(T msg)<---\n```\n\n========================================\n\nCode:\n```text\nRabbitHutch.SetContainerFactory(() => new NinjectAdapter(container));\n```\n\n```text\npublic class ProfileDeactivatedUpdateHandler : IConsume<ProfileDeactivatedUpdate>\n{\n private readonly IProfileRepository _profileRepository;\n\n public ProfileDeactivatedUpdateHandler(IProfileRepository profileRepository)\n {\n _profileRepository = profileRepository;\n }\n\n public void Consume(ProfileDeactivatedUpdate message)\n { \n //Do Stuff. \n }\n}\n```\n\n```text\nSystem.AggregateException: One or more errors occurred. ---> System.Exception: E\nxception of type 'System.Exception' was thrown.\n at EasyNetQ.ReflectionHelpers.DefaultFactories`1.Get()\n at EasyNetQ.ReflectionHelpers.CreateInstance[T]()\n at EasyNetQ.AutoSubscribe.DefaultAutoSubscriberMessageDispatcher.Dispatch[TMe\nssage,TConsumer](TMessage message)\n at EasyNetQ.RabbitBus.<>c__DisplayClass6`1.<Subscribe>b__5(T msg)\n --- End of inner exception stack trace ---\n---> (Inner Exception #0) System.Exception: Exception of type 'System.Exception'\n was thrown.\n at EasyNetQ.ReflectionHelpers.DefaultFactories`1.Get()\n at EasyNetQ.ReflectionHelpers.CreateInstance[T]()\n at EasyNetQ.AutoSubscribe.DefaultAutoSubscriberMessageDispatcher.Dispatch[TMe\nssage,TConsumer](TMessage message)\n at EasyNetQ.RabbitBus.<>c__DisplayClass6`1.<Subscribe>b__5(T msg)<---\n```\n\n```text\n//Bind Message Dispatcher to Ninject event message dispatcher\nNinjectMessageDispatcher messageDispatcher = new NinjectMessageDispatcher(Kernel);\nBind<IAutoSubscriberMessageDispatcher>().ToConstant(messageDispatcher);\n```\n\n```text\nvar subscriber = new AutoSubscriber(_serviceBus, \"ProfileServices\");\nsubscriber.AutoSubscriberMessageDispatcher = _dispatcher;\nsubscriber.Subscribe(Assembly.GetExecutingAssembly());\n```\n\n========================================\n\nComments:\n- Thanks for coming back to answer the question. Pull request merged!","metadata":{"transformedAt":"2026-08-18T18:33:20.331Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":116,"estimatedTokens":1046}}1184{"id":"stack-43645143","source":"stackoverflow","questionId":43645143,"title":"If rabbitmq can't be used as a locking service, then what can?","tags":["rabbitmq","message-queue","distributed-system"],"text":"Title: If rabbitmq can't be used as a locking service, then what can?\nTags: rabbitmq, message-queue, distributed-system\nSource: Stack Overflow\n\nQuestion:\nThe two main issues are:\n\n- Not resilient to network partitions\n\n- Not resilient to network failures\n\nThis article says why it can be used as a locking service: https://www.rabbitmq.com/blog/2014/02/19/distributed-semaphores-with-rabbitmq/\n\nThis article goes into more depth explaining why it can't be used as one due to the issues listed above: https://aphyr.com/posts/315-jepsen-rabbitmq\n\nSo to recap, if rabbitmq can't be used as a locking service, then what can?","metadata":{"transformedAt":"2026-08-18T18:33:20.331Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":16,"estimatedTokens":155}}1185{"id":"stack-46922056","source":"stackoverflow","questionId":46922056,"title":"Failed to start bean 'org.springframework.amqp.rabbit.config.internalRabbitListenerEndpointRegistry'","tags":["spring-boot","rabbitmq","spring-rabbit"],"text":"Title: Failed to start bean 'org.springframework.amqp.rabbit.config.internalRabbitListenerEndpointRegistry'\nTags: spring-boot, rabbitmq, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\nI have a simple spring-boot application with a rabbit sender and a receiver. I want to write some receiver tests where I am running a **rabbitmq docker** instance as Junit Class Rule (RabbitContainerRule)and then sending a message using rabbitTemplate and the test verifies if the receiver receives the same message. But I am getting the following exception:\n\n```\nCaused by: org.springframework.context.ApplicationContextException: Failed to start bean 'org.springframework.amqp.rabbit.config.internalRabbitListenerEndpointRegistry'; nested exception is org.springframework.amqp.AmqpIllegalStateException: Fatal exception on listener startup\nat org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178)\n\nCaused by: org.springframework.amqp.rabbit.listener.QueuesNotAvailableException: Cannot prepare queue for listener. Either the queue doesn't exist or the broker will not allow us to use it.\n at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:599)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1424)\n\nCaused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method(reply-code=404, reply-text=NOT_FOUND - no queue 'my-message-queue' in vhost '/', class-id=50, method-id=10)\n at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66)\n```\n\n*If I create the queue manually(by stopping at a breakpoint) in the docker instance using admin console, my test passes.* \n\nAlso, if I test it manually using the docker rabbit instance, my spring boot application creates queue successfully. So what is causing it to not create in the test? \n\nI am using **spring-amqp 1.7.4 RELEASE**\n\nReceiver code:\n\n```\n@RabbitListener(bindings = @QueueBinding(\n value = @Queue(value = \"my-message-queue\", durable = \"true\",\n arguments = {\n @Argument(name = \"x-dead-letter-exchange\", value = \"my-message-exchange-dead-letter\"),\n @Argument(name = \"x-dead-letter-routing-key\", value = \"my-message-queue\")}),\n exchange = @Exchange(value = \"my-message-exchange\", type = \"topic\", durable = \"true\"),\n key = \"my-message-rk\")\n)\npublic void handleMessage(MyMessage message) {\n MESSAGE_LOG.info(\"Receiving message: \" + message);\n}\n```\n\nAlso I am not creating any @Bean for *my-message-queue* in Configurations and rely on **@RabbitListener** to create one for me. But I am creating ConnectionFactory, RabbitTemplate and SimpleRabbitListenerContainerFactory beans in my config.\n\n========================================\n\nTop Answer:\nThe class where you are building your queues should be annotated with @Configuration annotation, otherwise, spring will not be able to create the queues at the time of start up\n\n========================================\n\nCode:\n```text\nCaused by: org.springframework.context.ApplicationContextException: Failed to start bean 'org.springframework.amqp.rabbit.config.internalRabbitListenerEndpointRegistry'; nested exception is org.springframework.amqp.AmqpIllegalStateException: Fatal exception on listener startup\nat org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178)\n\nCaused by: org.springframework.amqp.rabbit.listener.QueuesNotAvailableException: Cannot prepare queue for listener. Either the queue doesn't exist or the broker will not allow us to use it.\n at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:599)\n at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1424)\n\nCaused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'my-message-queue' in vhost '/', class-id=50, method-id=10)\n at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66)\n```\n\n```text\n@RabbitListener(bindings = @QueueBinding(\n value = @Queue(value = \"my-message-queue\", durable = \"true\",\n arguments = {\n @Argument(name = \"x-dead-letter-exchange\", value = \"my-message-exchange-dead-letter\"),\n @Argument(name = \"x-dead-letter-routing-key\", value = \"my-message-queue\")}),\n exchange = @Exchange(value = \"my-message-exchange\", type = \"topic\", durable = \"true\"),\n key = \"my-message-rk\")\n)\npublic void handleMessage(MyMessage message) {\n MESSAGE_LOG.info(\"Receiving message: \" + message);\n}\n```\n\n```text\n@EnableRabbit\n```\n\n```text\n@Configuration\n```\n\n```text\n@RabbitListener\n```\n\n```text\nRabbitAdmin\n```\n\n========================================\n\nComments:\n- Do you have `RabbitAdmin` bean?\n- How about just with us the whole application somewhere in GitHub?\n- Thanks Artem. Adding the RabbitAdmin bean in the test config solved this problem. Also, @EnableRabbit was missing on my configuration file.\n- All this while I was thinking how did it work when running this spring boot app, until I found out that the spring boot application creates it (RabbitAdmin) magically using this property \"spring.rabbitmq.dynamic=true\". Thank you once again.\n- Done. Thank you. Really appreciate your help @ArtemBilan","metadata":{"transformedAt":"2026-08-18T18:33:20.332Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":6,"totalLines":101,"estimatedTokens":1378}}1186{"id":"stack-25260223","source":"stackoverflow","questionId":25260223,"title":"RabbitMQ in Java using Protobuf. Parse received data","tags":["java","rabbitmq","message-queue","protocol-buffers","spring-amqp"],"text":"Title: RabbitMQ in Java using Protobuf. Parse received data\nTags: java, rabbitmq, message-queue, protocol-buffers, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI am currently using springAMQP to communicate between java and my RabbitMQ node.\nI am sending Protobuf data.\n\nI would like to convert/cast/parse the received Message into the respective ProtoClass. \n\nHere is the snippet from my Converter:\n\n```\n@Override\nprotected Message createMessage(Object object, MessageProperties messageProperties) {\n Preconditions.checkNotNull(object, \"Object to send is null !\");\n\n if (!com.google.protobuf.Message.class.isAssignableFrom(object.getClass())) {\n throw new MessageConversionException(\"Message wasn't a protobuf\");\n } else {\n com.google.protobuf.Message protobuf = (com.google.protobuf.Message) object;\n byte[] byteArray = protobuf.toByteArray();\n\n messageProperties.setContentLength(byteArray.length);\n messageProperties.setContentType(ProtobufMessageConverter.CONTENT_TYPE_PROTOBUF);\n messageProperties.setHeader(ProtobufMessageConverter.MESSAGE_TYPE_NAME, protobuf.getDescriptorForType().getName());\n\n return new Message(byteArray, messageProperties);\n }\n}\n\n@Override\npublic Object fromMessage(Message message) throws MessageConversionException {\n\n com.google.protobuf.Message parsedMessage = null;\n try {\n if(ProtobufMessageConverter.CONTENT_TYPE_PROTOBUF.equals(message.getMessageProperties().getContentType())) {\n String typeName = getMessageTypeName(message);\n Descriptors.Descriptor messageType = fileDescriptor.findMessageTypeByName(typeName);\n parsedMessage = DynamicMessage.parseFrom(messageType, message.getBody());\n }\n } catch (Exception e) {\n throw new AmqpRejectAndDontRequeueException(\"Cannot convert, unknown message type %s\".format(getMessageTypeName(message)));\n }\n return parsedMessage;\n}\n```\n\nWhat do I have to do to be able to build the object?\n\nHere is my proto file:\n\n```\nmessage queueReply {\n required string identifier = 1; cycle\n required uint32 keyId = 2;\n required bool success = 3; \n required bytes result = 4; \n}\n```\n\nI would like to obtain the class queueReply from template.receiveAndConvert()\n\n========================================\n\nCode:\n```text\n@Override\nprotected Message createMessage(Object object, MessageProperties messageProperties) {\n Preconditions.checkNotNull(object, \"Object to send is null !\");\n\n if (!com.google.protobuf.Message.class.isAssignableFrom(object.getClass())) {\n throw new MessageConversionException(\"Message wasn't a protobuf\");\n } else {\n com.google.protobuf.Message protobuf = (com.google.protobuf.Message) object;\n byte[] byteArray = protobuf.toByteArray();\n\n messageProperties.setContentLength(byteArray.length);\n messageProperties.setContentType(ProtobufMessageConverter.CONTENT_TYPE_PROTOBUF);\n messageProperties.setHeader(ProtobufMessageConverter.MESSAGE_TYPE_NAME, protobuf.getDescriptorForType().getName());\n\n return new Message(byteArray, messageProperties);\n }\n}\n\n@Override\npublic Object fromMessage(Message message) throws MessageConversionException {\n\n com.google.protobuf.Message parsedMessage = null;\n try {\n if(ProtobufMessageConverter.CONTENT_TYPE_PROTOBUF.equals(message.getMessageProperties().getContentType())) {\n String typeName = getMessageTypeName(message);\n Descriptors.Descriptor messageType = fileDescriptor.findMessageTypeByName(typeName);\n parsedMessage = DynamicMessage.parseFrom(messageType, message.getBody());\n }\n } catch (Exception e) {\n throw new AmqpRejectAndDontRequeueException(\"Cannot convert, unknown message type %s\".format(getMessageTypeName(message)));\n }\n return parsedMessage;\n}\n```\n\n```text\nmessage queueReply {\n required string identifier = 1; cycle\n required uint32 keyId = 2;\n required bool success = 3; \n required bytes result = 4; \n}\n```\n\n```text\nDynamicMessage o = (DynamicMessage)template.receiveAndConvert(\"queueName\");\nProtoObject request = ProtoObject.parseFrom(o.toByteArray());\n```\n\n========================================\n\nComments:\n- Do you have the full code somewhere? I'm trying to integrate this with Spring Boot but it is not working yet.\n- i might still have a copy somewhere. not open source though.\n- I have the code (id is public on github somewhere) but it does not get called. Do you have some code for receiving protobuf messages? I'm talking about the `MessageListener` here.\n- think i was using the amqptemplate in SpringAMQP\n- And where does `fileDescriptor` come from in your code?\n- that is the protobuf file descrptor developers.google.com/protocol-buffers/docs/reference/java/c‌​om/…\n- I know its type but there is no reference to it","metadata":{"transformedAt":"2026-08-18T18:33:20.332Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":126,"estimatedTokens":1184}}1187{"id":"stack-31918800","source":"stackoverflow","questionId":31918800,"title":"Spring AMPQ rabbit-template publish confirmation","tags":["spring","spring-boot","rabbitmq","spring-rabbit"],"text":"Title: Spring AMPQ rabbit-template publish confirmation\nTags: spring, spring-boot, rabbitmq, spring-rabbit\nSource: Stack Overflow\n\nQuestion:\ni am trying to use RabbitMq with the help of RabbitTemplate(i am using spring boot application) .i am able to do the communication part and it is working fine with me but i have one issue.\n\n**Issue:** how can i get acknowledgement after publishing message? i have not seen any method in **RabbitTemplate**,i need it because i have encountered the problem that some times my messages do not reach the server and that is a problem for me . \n\n****************EDIT*********************\n\nAs Artem Bilan suggested i have implemented but still some how its not working . Please see my code.\n\n```\npublic boolean sendMessage() {\n try {\n String jsonMessage = convertMessageToJson(message);\n template.setQueue(\"test_queue\");\n template.setRoutingKey(\"test_queue\");\n template.convertAndSend(null, \"test_queue\", jsonMessage,\n new CorrelationData(UUID.randomUUID().toString()));\n // template.convertAndSend(jsonMessage + counter.incrementAndGet());\n new AnnotationConfigApplicationContext(\n TestMessageConfiguration.class);\n } catch (Exception e) {\n return false;\n }\n return true;\n}\n```\n\n**And**\n\n**My bean**\n\n```\n@Bean\npublic RabbitTemplate rabbitTemplate() {\n RabbitTemplate template = new RabbitTemplate(connectionFactory());\n RetryTemplate retryTemplate = new RetryTemplate();\n ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();\n backOffPolicy.setInitialInterval(500);\n backOffPolicy.setMultiplier(10.0);\n backOffPolicy.setMaxInterval(10000);\n retryTemplate.setBackOffPolicy(backOffPolicy);\n template.setRetryTemplate(retryTemplate);\n\n template.setReturnCallback(new ReturnCallback() {\n @Override\n public void returnedMessage(Message message, int replyCode,\n String replyText, String exchange, String routingKey) {\n System.out.println(\"Received returnedMessage with result {}\"\n + routingKey);\n log.info(\"Received returnedMessage with result {}\", routingKey);\n\n }\n });\n\n template.setConfirmCallback(new ConfirmCallback() {\n @Override\n public void confirm(CorrelationData correlationData, boolean ack,\n String cause) {\n System.out\n .println(\"*************************************************************************************\"\n + ack);\n log.info(\"Received confirm with result {}\", ack);\n\n }\n });\n template.setMandatory(true);\n\n return template;\n}\n```\n\nwhen i setCallback and ConfirmCallback before sending actual message \ni am getting exception \n\n```\n`java.lang.IllegalStateException: Channel does not support confirms or returns; is the connection factory configured for confirms or returns?\n at org.springframework.amqp.rabbit.core.RabbitTemplate.addListener(RabbitTemplate.java:1189)\n at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1039)\n at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1028)\n at org.springframework.amqp.rabbit.core.RabbitTemplate.send(RabbitTemplate.java:540)\n at org.springframework.amqp.rabbit.core.RabbitTemplate.convertAndSend(RabbitTemplate.java:605)\n at com.xx.yy.backend.messaging.MessageSenderTest.sendMessage(MessageSenderTest.java:88)\n at com.xx.yy.backend.messaging.MessageSenderTest.sendMessageTest(MessageSenderTest.java:51)\n at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n at java.lang.reflect.Method.invoke(Method.java:497)\n at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)\n at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)\n at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)\n at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)\n at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73)\n at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)\n at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:73)\n at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)\n at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:224)\n at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)\n at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)\n at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)\n at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)\n at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)\n at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)\n at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)\n at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68)\n at org.junit.runners.ParentRunner.run(ParentRunner.java:363)\n at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)\n at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)\n at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)\n at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)\n at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)\n at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)\n at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)\n\n`\n```\n\n========================================\n\nCode:\n```text\npublic boolean sendMessage() {\n try {\n String jsonMessage = convertMessageToJson(message);\n template.setQueue(\"test_queue\");\n template.setRoutingKey(\"test_queue\");\n template.convertAndSend(null, \"test_queue\", jsonMessage,\n new CorrelationData(UUID.randomUUID().toString()));\n // template.convertAndSend(jsonMessage + counter.incrementAndGet());\n new AnnotationConfigApplicationContext(\n TestMessageConfiguration.class);\n } catch (Exception e) {\n return false;\n }\n return true;\n}\n```\n\n```text\n@Bean\npublic RabbitTemplate rabbitTemplate() {\n RabbitTemplate template = new RabbitTemplate(connectionFactory());\n RetryTemplate retryTemplate = new RetryTemplate();\n ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();\n backOffPolicy.setInitialInterval(500);\n backOffPolicy.setMultiplier(10.0);\n backOffPolicy.setMaxInterval(10000);\n retryTemplate.setBackOffPolicy(backOffPolicy);\n template.setRetryTemplate(retryTemplate);\n\n template.setReturnCallback(new ReturnCallback() {\n @Override\n public void returnedMessage(Message message, int replyCode,\n String replyText, String exchange, String routingKey) {\n System.out.println(\"Received returnedMessage with result {}\"\n + routingKey);\n log.info(\"Received returnedMessage with result {}\", routingKey);\n\n }\n });\n\n template.setConfirmCallback(new ConfirmCallback() {\n @Override\n public void confirm(CorrelationData correlationData, boolean ack,\n String cause) {\n System.out\n .println(\"*************************************************************************************\"\n + ack);\n log.info(\"Received confirm with result {}\", ack);\n\n }\n });\n template.setMandatory(true);\n\n return template;\n}\n```\n\n```text\n`java.lang.IllegalStateException: Channel does not support confirms or returns; is the connection factory configured for confirms or returns?\n at org.springframework.amqp.rabbit.core.RabbitTemplate.addListener(RabbitTemplate.java:1189)\n at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1039)\n at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1028)\n at org.springframework.amqp.rabbit.core.RabbitTemplate.send(RabbitTemplate.java:540)\n at org.springframework.amqp.rabbit.core.RabbitTemplate.convertAndSend(RabbitTemplate.java:605)\n at com.xx.yy.backend.messaging.MessageSenderTest.sendMessage(MessageSenderTest.java:88)\n at com.xx.yy.backend.messaging.MessageSenderTest.sendMessageTest(MessageSenderTest.java:51)\n at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n at java.lang.reflect.Method.invoke(Method.java:497)\n at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)\n at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)\n at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)\n at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)\n at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73)\n at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)\n at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:73)\n at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)\n at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:224)\n at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)\n at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)\n at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)\n at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)\n at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)\n at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)\n at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)\n at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68)\n at org.junit.runners.ParentRunner.run(ParentRunner.java:363)\n at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)\n at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)\n at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)\n at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)\n at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)\n at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)\n at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)\n\n`\n```\n\n```text\nRabbitTemplate\n```\n\n```text\nPublisherCallbackChannel.Listener\n```\n\n========================================\n\nComments:\n- thanks for your comment. Could you please see my modified code and provide your feedback because some how its still not working for me .\n- While adding listener i am getting illegalstateexception\n- Docs link has been fixed.","metadata":{"transformedAt":"2026-08-18T18:33:20.332Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":237,"estimatedTokens":2944}}1188{"id":"stack-42137216","source":"stackoverflow","questionId":42137216,"title":"I can't connect to Rabbitmq server port 5672","tags":["docker","rabbitmq","symfony"],"text":"Title: I can't connect to Rabbitmq server port 5672\nTags: docker, rabbitmq, symfony\nSource: Stack Overflow\n\nQuestion:\nwith this command \n\n```\nphp bin/console rabbitmq:consumer -w upload_picture\n```\n\nI have this problem .\n\n```\n[ErrorException]\nstream_socket_client(): unable to connect to tcp://localhost:5672 (Aucune\n connexion n'a pu etre établie car l'ordinateur cible lÆa expressÚment\n refusée.\n```\n\nSo I can't connect to server rabbitmq\n\nconfig.yml\n\n```\nold_sound_rabbit_mq:\nconnections:\n default:\n host: 'localhost' # hostname and port of the rabbitmq server\n port: 5672\n user: 'guest'\n password: 'guest'\n vhost: '/'\n lazy: true # a lazy connection avoids unnecessary connections to the broker on every request\n connection_timeout: 3\n read_write_timeout: 3\n keepalive: false\n heartbeat: 0\nproducers:\n upload_picture:\n connection: default # connects to the default connection configured above\n exchange_options: {name: 'upload_picture', type: direct}\nconsumers:\n upload_picture:\n connection: default # connects to the default connection configured above\n exchange_options: {name: 'upload_picture', type: direct}\n queue_options: {name: 'upload_picture'}\n callback: upload_picture_service # the UploadPictureConsumer defined below\n```\n\n========================================\n\nTop Answer:\nYou can find directly the port you need to connect with \n\n`docker inspect --format '{{ (index (index .NetworkSettings.Ports \"5672/tcp\") 0).HostPort }}' rabbitmq_container`\n\nSee How to get ENV variable when doing Docker Inspect for more details on how to get a specific value from `docker inspect`\n\n========================================\n\nCode:\n```text\nphp bin/console rabbitmq:consumer -w upload_picture\n```\n\n```text\n[ErrorException]\nstream_socket_client(): unable to connect to tcp://localhost:5672 (Aucune\n connexion n'a pu etre établie car l'ordinateur cible lÆa expressÚment\n refusée.\n```\n\n```text\nold_sound_rabbit_mq:\nconnections:\n default:\n host: 'localhost' # hostname and port of the rabbitmq server\n port: 5672\n user: 'guest'\n password: 'guest'\n vhost: '/'\n lazy: true # a lazy connection avoids unnecessary connections to the broker on every request\n connection_timeout: 3\n read_write_timeout: 3\n keepalive: false\n heartbeat: 0\nproducers:\n upload_picture:\n connection: default # connects to the default connection configured above\n exchange_options: {name: 'upload_picture', type: direct}\nconsumers:\n upload_picture:\n connection: default # connects to the default connection configured above\n exchange_options: {name: 'upload_picture', type: direct}\n queue_options: {name: 'upload_picture'}\n callback: upload_picture_service # the UploadPictureConsumer defined below\n```\n\n```text\n7c01193b2f74 projecttest_queue \"docker-entrypoint...\" 24 hours ago Up 5 hours 4369/tcp, 5671/tcp, 25672/tcp, 0.0.0.0:55672->5672/tcp, 0.0.0.0:32768->15672/tcp\n```\n\n```text\n0.0.0.0:55672->5672/tcp\n```\n\n```text\nlocalhost:55672\n```\n\n```text\nlocalhost:5672\n```\n\n```text\ndocker inspect --format '{{ (index (index .NetworkSettings.Ports \"5672/tcp\") 0).HostPort }}' rabbitmq_container\n```\n\n```text\ndocker inspect\n```\n\n========================================\n\nComments:\n- your command connects to localhost, if your port 5672 is not published by the container on the host, it will fail. Show `docker port your_rabbitmq_container` , here is the doc docs.docker.com/engine/reference/commandline/port\n- On the rabbitmq machine, type `netstat -a` and make sure it is listening on that port and not only on a unix socket.\n- the port 5672 not exist in the list ( netstat -a )\n- with is command **docker ps** 7c01193b2f74 projecttest_queue \"docker-entrypoint...\" 24 hours ago Up 5 hours 4369/tcp, 5671/tcp, 25672/tcp, 0.0.0.0:55672->5672/tcp, 0.0.0.0:32768->15672/tcp projecttest_queue_1\n- replace localhost with the name of the container (from your comment seems projecttest_queue)\n- It does not work stream_socket_client(): php_network_getaddresses: getaddrinfo failed:\n- Unfortunately the same problem with 55672\n- In that case check what IP the rabbitmq server is listening on. If the `config.yml` you provided is from the rabbitmq server, then you need to change the host to `0.0.0.0` so that rabbitmq **DOES NOT** listen on `localhost` because it will not be accessible from outside the docker container","metadata":{"transformedAt":"2026-08-18T18:33:20.332Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":9,"totalLines":134,"estimatedTokens":1111}}1189{"id":"stack-52451587","source":"stackoverflow","questionId":52451587,"title":"MockBean Tests and Multiple Consumers\\App Contexts with Spring AMQP","tags":["spring-boot","rabbitmq","mockito","spring-amqp"],"text":"Title: MockBean Tests and Multiple Consumers\\App Contexts with Spring AMQP\nTags: spring-boot, rabbitmq, mockito, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI'm currently facing an issue with testing RabbitMQ consumers with mocks. The issue seems to be that one test class runs with an application context without any mocks, as expected. The next test class to run sets up some mocks that it expects the consumers to use, however when the test runs and a message is sent and it gets picked up by the non-mocked consumers from the application context created for the first test class. As a result my second test fails.\n\nHere is the first test:\n\n```\n@SpringBootTest\npublic class DemoApplicationTests extends AbstractTestNGSpringContextTests {\n\n @Autowired\n private RabbitAdmin rabbitAdmin;\n\n private Logger logger = LoggerFactory.getLogger(this.getClass());\n\n @Test(priority = 1)\n public void contextLoads() {\n logger.info(\"=============== CONSUMERS: \" + rabbitAdmin.getQueueProperties(USER_MESSAGING_QUEUE).get(RabbitAdmin.QUEUE_CONSUMER_COUNT));\n }\n}\n```\n\nSecond test:\n\n```\n@SpringBootTest\npublic class UserServiceTests extends AbstractTestNGSpringContextTests {\n\n @Autowired\n private UserService userService;\n\n @Autowired\n private UserMessageConsumer userMessageConsumer;\n\n @MockBean\n @Autowired\n private ThirdPartyUserDataClient thirdPartyUserDataClient;\n\n @Autowired\n private UserRepository userRepository;\n\n @Autowired\n private RabbitAdmin rabbitAdmin;\n\n @Test(priority = 2)\n public void createUpdateUserTest() {\n\n logger.info(\"=============== CONSUMERS: \" + rabbitAdmin.getQueueProperties(USER_MESSAGING_QUEUE).get(RabbitAdmin.QUEUE_CONSUMER_COUNT));\n\n String additionalData = org.apache.commons.lang3.RandomStringUtils.random(5);\n Mockito.when(thirdPartyUserDataClient.getAdditionalUserData(ArgumentMatchers.anyLong())).thenReturn(additionalData);\n\n User user = new User();\n user.setName(\"Test User\");\n user.setState(UserState.PENDING);\n\n user = userService.createUser(user);\n\n Assert.assertNotNull(user.getId());\n\n User finalUser = user;\n Awaitility.await().until(() -> {\n User user2 = userService.getUserById(finalUser.getId());\n return finalUser != null && additionalData.equals(user2.getAdditionalData());\n });\n\n user.setState(UserState.CREATED);\n user = userService.updateUser(user);\n\n Assert.assertEquals(UserState.CREATED, user.getState());\n\n }\n\n}\n```\n\nThe consumer:\n\n```\n@Component\npublic class UserMessageConsumer {\n\n private Logger logger = LoggerFactory.getLogger(this.getClass());\n\n public static final String FAILED_TO_GET_ADDITIONAL_DATA = \"FAILED_TO_GET_ADDITIONAL_DATA\";\n\n @Autowired\n private UserService userService;\n\n @Autowired\n private ThirdPartyUserDataClient thirdPartyUserDataClient;\n\n public void handleUserCreatedMessage(UserCreatedMessage userCreatedMessage) {\n\n Long userId = userCreatedMessage.getUserId();\n User user = userService.getUserById(userId);\n\n if (user != null) {\n String additionalData;\n\n try {\n additionalData = thirdPartyUserDataClient.getAdditionalUserData(userId);\n logger.info(\"Successfully retrieved additional data [{}] for user [{}].\", additionalData, userId);\n } catch (HttpClientErrorException ex) {\n additionalData = FAILED_TO_GET_ADDITIONAL_DATA;\n logger.warn(\"Failed to retrieve additional data for user [{}].\", userId, ex);\n }\n\n user.setAdditionalData(additionalData);\n userService.updateUser(user);\n }\n\n }\n\n}\n```\n\nThis brings up two related questions:\n\nHow am I supposed to properly do mock bean testing with consumers in\nSpring? \nIt looks like Spring is bringing up a new a\nApplicationContext for each test class, indicated by the consumer count increasing on the subsequent test runs. It appears\nthat @MockBean affects the cache key of the ApplicationContext (see:\nMocking and Spying Beans in Spring Boot) and likely explains why there are multiple application contexts.\nBut how do I stop the consumers in the other stale application contexts from\nconsuming my test messages?\n\nI've bugjar'd this issue here: RabbitMQ MockBean BugJar\n\n========================================\n\nCode:\n```text\n@SpringBootTest\npublic class DemoApplicationTests extends AbstractTestNGSpringContextTests {\n\n @Autowired\n private RabbitAdmin rabbitAdmin;\n\n private Logger logger = LoggerFactory.getLogger(this.getClass());\n\n @Test(priority = 1)\n public void contextLoads() {\n logger.info(\"=============== CONSUMERS: \" + rabbitAdmin.getQueueProperties(USER_MESSAGING_QUEUE).get(RabbitAdmin.QUEUE_CONSUMER_COUNT));\n }\n}\n```\n\n```text\n@SpringBootTest\npublic class UserServiceTests extends AbstractTestNGSpringContextTests {\n\n @Autowired\n private UserService userService;\n\n @Autowired\n private UserMessageConsumer userMessageConsumer;\n\n @MockBean\n @Autowired\n private ThirdPartyUserDataClient thirdPartyUserDataClient;\n\n @Autowired\n private UserRepository userRepository;\n\n @Autowired\n private RabbitAdmin rabbitAdmin;\n\n @Test(priority = 2)\n public void createUpdateUserTest() {\n\n logger.info(\"=============== CONSUMERS: \" + rabbitAdmin.getQueueProperties(USER_MESSAGING_QUEUE).get(RabbitAdmin.QUEUE_CONSUMER_COUNT));\n\n String additionalData = org.apache.commons.lang3.RandomStringUtils.random(5);\n Mockito.when(thirdPartyUserDataClient.getAdditionalUserData(ArgumentMatchers.anyLong())).thenReturn(additionalData);\n\n User user = new User();\n user.setName(\"Test User\");\n user.setState(UserState.PENDING);\n\n user = userService.createUser(user);\n\n Assert.assertNotNull(user.getId());\n\n User finalUser = user;\n Awaitility.await().until(() -> {\n User user2 = userService.getUserById(finalUser.getId());\n return finalUser != null && additionalData.equals(user2.getAdditionalData());\n });\n\n user.setState(UserState.CREATED);\n user = userService.updateUser(user);\n\n Assert.assertEquals(UserState.CREATED, user.getState());\n\n }\n\n}\n```\n\n```text\n@Component\npublic class UserMessageConsumer {\n\n private Logger logger = LoggerFactory.getLogger(this.getClass());\n\n public static final String FAILED_TO_GET_ADDITIONAL_DATA = \"FAILED_TO_GET_ADDITIONAL_DATA\";\n\n @Autowired\n private UserService userService;\n\n @Autowired\n private ThirdPartyUserDataClient thirdPartyUserDataClient;\n\n public void handleUserCreatedMessage(UserCreatedMessage userCreatedMessage) {\n\n Long userId = userCreatedMessage.getUserId();\n User user = userService.getUserById(userId);\n\n if (user != null) {\n String additionalData;\n\n try {\n additionalData = thirdPartyUserDataClient.getAdditionalUserData(userId);\n logger.info(\"Successfully retrieved additional data [{}] for user [{}].\", additionalData, userId);\n } catch (HttpClientErrorException ex) {\n additionalData = FAILED_TO_GET_ADDITIONAL_DATA;\n logger.warn(\"Failed to retrieve additional data for user [{}].\", userId, ex);\n }\n\n user.setAdditionalData(additionalData);\n userService.updateUser(user);\n }\n\n }\n\n}\n```\n\n```text\n@DirtiesContext\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.332Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":246,"estimatedTokens":1789}}1190{"id":"stack-33817230","source":"stackoverflow","questionId":33817230,"title":"Celery: @shared_task and non-standard BROKER_URL","tags":["python","rabbitmq","celery-task"],"text":"Title: Celery: @shared_task and non-standard BROKER_URL\nTags: python, rabbitmq, celery-task\nSource: Stack Overflow\n\nQuestion:\nI have a Celery 3.1.19 setup which uses a BROKER_URL including a virtual host. \n\n```\n# in settings.py\nBROKER_URL = 'amqp://guest:guest@localhost:5672/yard'\n```\n\nCelery starts normally, loads the tasks, and the tasks I define within the @app.task decorator work fine. I assume that my rabbitmq and celery configuration at this end are correct.\n\nTasks, I define with @shared_tasks and load with app.autodiscover_tasks are still loading correctly upon start. However, if I call the task the message ends up in the (still existing) amqp://guest:guest@localhost:5672/ virtual host. \n\n**Question**: What am I missing here? Where do shared tasks get their actual configuration from.\n\n**And here some more details**:\n\n```\n# celery_app.py\n\nfrom celery import Celery\n\ncelery_app = Celery('celery_app')\ncelery_app.config_from_object('settings')\n\ncelery_app.autodiscover_tasks(['connectors'])\n\n@celery_app.task\ndef i_do_work():\n print 'this works'\n```\n\nAnd in connectors/tasks.py (with an `__init__.py` in the same folder):\n\n```\n# in connectors/tasks.py\n\nfrom celery import shared_task\n\n@shared_task\ndef I_do_not_work():\n print 'bummer'\n```\n\nAnd again the *shared* task gets also picked up by the Celery instance. It just lacks somehow the context to send messages to the right BROKER_URL.\n\nBtw. why are shared_tasks so purely documented. Do they rely on some Django context? I am not using Django.\n\nOr do I need additional parameters in my settings?\n\nThanks a lot.\n\n========================================\n\nCode:\n```text\n# in settings.py\nBROKER_URL = 'amqp://guest:guest@localhost:5672/yard'\n```\n\n```text\n# celery_app.py\n\nfrom celery import Celery\n\ncelery_app = Celery('celery_app')\ncelery_app.config_from_object('settings')\n\ncelery_app.autodiscover_tasks(['connectors'])\n\n@celery_app.task\ndef i_do_work():\n print 'this works'\n```\n\n```text\n# in connectors/tasks.py\n\nfrom celery import shared_task\n\n@shared_task\ndef I_do_not_work():\n print 'bummer'\n```\n\n```text\n__init__.py\n```\n\n```text\nfrom __future__ import absolute_import\n\ntry:\n from .celery_app import celery_app\nexcept ImportError:\n # just in case someone develops application without \n # celery running \n pass\n```\n\n```text\n__init__.py\n```\n\n========================================\n\nComments:\n- The problem does not seem to be limited to shared tasks. Just tasks in a separate file seem to behave the same. The question is rather where do tasks get there context from.","metadata":{"transformedAt":"2026-08-18T18:33:20.332Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":6,"totalLines":111,"estimatedTokens":640}}1191{"id":"stack-31767150","source":"stackoverflow","questionId":31767150,"title":"RabbitMQ consumer connection dies after 90 seconds idle","tags":["python","rabbitmq","pika"],"text":"Title: RabbitMQ consumer connection dies after 90 seconds idle\nTags: python, rabbitmq, pika\nSource: Stack Overflow\n\nQuestion:\nI have a RabbitMQ task queue and a Pika consumer to consume these tasks (with acks). The problem is that the connection dies after 90 seconds Idle but my tasks will often take longer than that. That means that while tasks are still being computed they are returned to the task queue and never acked. \n\nUsing RabbitMQ 3.5.3 and Pika 0.9.14 with the *channel.basic_consume()* method. The connection has a *heartbeat_interval* of 30 seconds.\n\nConsume code:\n\n```\nimport pika\nfrom time import sleep\n\nRABBITMQ_URL = \"amqp://user:pass@my-host.com/my_virtual_host?heartbeat_interval=30\"\nQUEUE_NAME = \"my_queue\"\n\ndef callback(ch, method, properties, body):\n print body\n sleep(91) # if sleep value Traceback:\n\n```\nTraceback (most recent call last):\n File \"main.py\", line 19, in \n channel.basic_consume(callback, queue=QUEUE_NAME)\n File \"/usr/local/lib/python2.7/site-packages/pika/channel.py\", line 221, in basic_consume\n {'consumer_tag': consumer_tag})])\n File \"/usr/local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py\", line 1143, in _rpc\n self.connection.process_data_events()\n File \"/usr/local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py\", line 240, in process_data_events\n if self._handle_read():\n File \"/usr/local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py\", line 347, in _handle_read\n if self._read_poller.ready():\n File \"/usr/local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py\", line 43, in inner\n return f(*args, **kwargs)\n File \"/usr/local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py\", line 89, in ready\n self.poll_timeout)\nselect.error: (9, 'Bad file descriptor')\n```\n\n========================================\n\nCode:\n```text\nimport pika\nfrom time import sleep\n\nRABBITMQ_URL = \"amqp://user:pass@my-host.com/my_virtual_host?heartbeat_interval=30\"\nQUEUE_NAME = \"my_queue\"\n\n\ndef callback(ch, method, properties, body):\n print body\n sleep(91) # if sleep value < 90 this code works (even 89)\n ch.basic_ack(delivery_tag=method.delivery_tag)\n\n\nparameters = pika.URLParameters(RABBITMQ_URL)\nconnection = pika.BlockingConnection(parameters)\nchannel = connection.channel()\nchannel.queue_declare(queue=QUEUE_NAME, durable=True)\nchannel.basic_qos(prefetch_count=1)\nchannel.basic_consume(callback, queue=QUEUE_NAME)\nchannel.start_consuming()\n```\n\n```text\nTraceback (most recent call last):\n File \"main.py\", line 19, in <module>\n channel.basic_consume(callback, queue=QUEUE_NAME)\n File \"/usr/local/lib/python2.7/site-packages/pika/channel.py\", line 221, in basic_consume\n {'consumer_tag': consumer_tag})])\n File \"/usr/local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py\", line 1143, in _rpc\n self.connection.process_data_events()\n File \"/usr/local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py\", line 240, in process_data_events\n if self._handle_read():\n File \"/usr/local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py\", line 347, in _handle_read\n if self._read_poller.ready():\n File \"/usr/local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py\", line 43, in inner\n return f(*args, **kwargs)\n File \"/usr/local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py\", line 89, in ready\n self.poll_timeout)\nselect.error: (9, 'Bad file descriptor')\n```\n\n```text\ndef amqp_sleep(connection, time_to_sleep=20):\n remaining = time_to_sleep\n while remaining > 0:\n connection.process_data_events()\n time.sleep(5)\n remaining -= 5\n```\n\n```text\nprocess_data_events()\n```\n\n========================================\n\nComments:\n- please post the code that reproduces the problem\n- @DerickBailey Thanks for the quick reply. this is my code and my traceback\n- Can you trap the exact network connection error and post it?\n- Updated code and error to be more general and reproducible. @joshuad2 can you elaborate?\n- Amazing. I'm surprised that the pika documentation doesn't mention this. I'll definitely try these libraries next time I'm using rabbitmq. For this project I've already abandoned rabbitmq in favor of a simple redis queue.","metadata":{"transformedAt":"2026-08-18T18:33:20.332Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":107,"estimatedTokens":1070}}1192{"id":"stack-36419994","source":"stackoverflow","questionId":36419994,"title":"RabbitMQ consumer in Go","tags":["go","rabbitmq","rabbitmq-exchange","rabbitmqctl"],"text":"Title: RabbitMQ consumer in Go\nTags: go, rabbitmq, rabbitmq-exchange, rabbitmqctl\nSource: Stack Overflow\n\nQuestion:\nI am trying to write a RabbitMQ Consumer in Go. Which is suppose to take the 5 objects at a time from the queue and process them. Moreover, it is suppose to acknowledge if successfully processed else send to the dead-letter queue for 5 times and then discard, it should be running infinitely and handling the cancellation event of the consumer. \nI have few questions :\n\n- Is there any concept of `BasicConsumer` vs `EventingBasicConsumer` in RabbitMq-go Reference?\n\n- What is `Model` in RabbitMQ and is it there in RabbitMq-go?\n\n- How to send the objects when failed to dead-letter queue and again re-queue them after `ttl`\n\n- What is the significance of `consumerTag` argument in the `ch.Consume` function in the below code\n\n- Should we use the `channel.Get()` or `channel.Consume()` for this scenario?\n\nWhat are the changes i need to make in the below code to meet above requirement. I am asking this because i couldn't find decent documentation of RabbitMq-Go.\n\n```\nfunc main() {\n\n consumer() \n }\n\n func consumer() {\n\n objConsumerConn := &rabbitMQConn{queueName: \"EventCaptureData\", conn: nil} \n initializeConn(&objConsumerConn.conn)\n\n ch, err := objConsumerConn.conn.Channel()\n failOnError(err, \"Failed to open a channel\")\n defer ch.Close()\n\n msgs, err := ch.Consume(\n objConsumerConn.queueName, // queue\n \"demo1\", // consumerTag\n false, // auto-ack\n false, // exclusive\n false, // no-local\n false, // no-wait\n nil, // args\n )\n failOnError(err, \"Failed to register a consumer\")\n\n forever := make(chan bool)\n\n go func() {\n for d := range msgs { \n k := new(EventCaptureData)\n b := bytes.Buffer{}\n b.Write(d.Body)\n dec := gob.NewDecoder(&b) \n err := dec.Decode(&k)\n d.Ack(true) \n\n if err != nil { fmt.Println(\"failed to fetch the data from consumer\", err); }\n fmt.Println(k) \n }\n }() \n\n log.Printf(\" Waiting for Messages to process. To exit press CTRL+C \")\n **Edited question:**\n\nI have delayed the processing of the messages as suggested in the links link1 link2. But the problem is messages are getting back to their original queue from dead-lettered queue even after ttl. I am using `RabbitMQ 3.0.0`. Can anyone point out what is the problem?\n\n========================================\n\nCode:\n```text\nfunc main() {\n\n consumer() \n }\n\n func consumer() {\n\n objConsumerConn := &rabbitMQConn{queueName: \"EventCaptureData\", conn: nil} \n initializeConn(&objConsumerConn.conn)\n\n\n ch, err := objConsumerConn.conn.Channel()\n failOnError(err, \"Failed to open a channel\")\n defer ch.Close()\n\n msgs, err := ch.Consume(\n objConsumerConn.queueName, // queue\n \"demo1\", // consumerTag\n false, // auto-ack\n false, // exclusive\n false, // no-local\n false, // no-wait\n nil, // args\n )\n failOnError(err, \"Failed to register a consumer\")\n\n forever := make(chan bool)\n\n go func() {\n for d := range msgs { \n k := new(EventCaptureData)\n b := bytes.Buffer{}\n b.Write(d.Body)\n dec := gob.NewDecoder(&b) \n err := dec.Decode(&k)\n d.Ack(true) \n\n if err != nil { fmt.Println(\"failed to fetch the data from consumer\", err); }\n fmt.Println(k) \n }\n }() \n\n log.Printf(\" Waiting for Messages to process. To exit press CTRL+C \")\n <-forever\n\n }\n```\n\n```text\nBasicConsumer\n```\n\n```text\nEventingBasicConsumer\n```\n\n```text\nModel\n```\n\n```text\nttl\n```\n\n```text\nconsumerTag\n```\n\n```text\nch.Consume\n```\n\n```text\nchannel.Get()\n```\n\n```text\nchannel.Consume()\n```\n\n```text\nRabbitMQ 3.0.0\n```\n\n```text\nChannel.Get\n```\n\n```text\nChannel.Consume\n```\n\n```text\nChannel.Get\n```\n\n```text\nok=false\n```\n\n```text\nChannel.Consume\n```\n\n```text\nIModel\n```\n\n```text\nConnection.CreateModel\n```\n\n```text\nrequeue=false\n```\n\n```text\nConsumerTag\n```\n\n```text\nchannel.Consume\n```\n\n```text\nConsumerTag\n```\n\n```text\nchannel.Get()\n```\n\n```text\nchannel.Consume()\n```\n\n```text\nchannel.Get()\n```\n\n```text\nchannel.Consume()\n```\n\n```text\nchannel.Get\n```\n\n```text\nmultiple=true\n```\n\n```text\ndelivery.Headers[\"x-death\"]\n```\n\n========================================\n\nComments:\n- Try the amqp package to interact with rabbit, also it has a very decent documentation godoc.org/github.com/streadway/amqp\n- @PerroVerd That's what i am using.\n- Thanking you so much for detailed explanation.\n- @Pedro..I am having one problem. If i use d.Ack(true) or d.Ack(false) it is not publishing the messages in dead-lettered-queue. Where as in case of d.Nack(true, false) it publishes. But then after ttl it drops the messages from there. So, what are the values to achieve the same\n- @Naresh That's a new RabbitMQ question, unrelated to the Go question here. You should create a new question with that.\n- I have created new question. Could you please tell me why it is exhibiting this behaviour `http://stackoverflow.com/questions/36503804/dead-letterred-m‌​essages-not-getting-‌​requeue-to-original-‌​queue-after-ttl`","metadata":{"transformedAt":"2026-08-18T18:33:20.332Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":28,"totalLines":236,"estimatedTokens":1332}}1193{"id":"stack-53546545","source":"stackoverflow","questionId":53546545,"title":"Can't convert Message object from RabbitMQ to java class","tags":["java","spring","rabbitmq","spring-amqp"],"text":"Title: Can't convert Message object from RabbitMQ to java class\nTags: java, spring, rabbitmq, spring-amqp\nSource: Stack Overflow\n\nQuestion:\nI created my RabbitListener to get messages from RabbitMQ queue. \n\nMy rabbitMQ message:\n\n```\nProperties \npriority: 0\ndelivery_mode: 2\nheaders: \n__TypeId__: com.kmb.bank.models.Transfer\ncontent_encoding: UTF-8\ncontent_type: application/json\nPayload\n356 bytes\nEncoding: string\n\n{\"userAccountNumber\":\"1111444422221111\",\"title\":\"123\",\"recipientName\":\"123\",\"recipientAccountNumber\":\"1234123412341234\",\"amount\":123.0,\"localDateTime\":{\"nano\":526106200,\"year\":2018,\"monthValue\":11,\"dayOfMonth\":29,\"hour\":20,\"minute\":43,\"second\":0,\"month\":\"NOVEMBER\",\"dayOfWeek\":\"THURSDAY\",\"dayOfYear\":333,\"chronology\":{\"id\":\"ISO\",\"calendarType\":\"iso8601\"}}}\n```\n\nMy Listener method:\n\n```\n@Autowired\nprivate Jackson2JsonMessageConverter jackson2JsonMessageConverter;\n\n@RabbitListener(queues = \"kolejka\")\npublic void listen(Message message) {\n try {\n Transfer transfer = (Transfer) jackson2JsonMessageConverter.fromMessage(message);\n log.info(transfer);\n } catch (Exception e) {\n log.debug(\"Error thrown while listening + \" + e.getMessage());\n }\n\n}\n```\n\nBean config:\n @Bean\n public ObjectMapper objectMapper() {\n return new ObjectMapper();\n }\n\n```\n@Bean\npublic Jackson2JsonMessageConverter jackson2JsonMessageConverter() {\n return new Jackson2JsonMessageConverter(objectMapper());\n}\n```\n\nAnd Transfer class:\n\n```\npackage com.kmb.transactionlogger.models;\n\n@AllArgsConstructor\npublic class Transfer {\n @Getter @Setter\n private String userAccountNumber;\n @Getter @Setter\n private String title;\n @Getter @Setter\n private String recipientName;\n @Getter @Setter\n private String recipientAccountNumber;\n @Getter @Setter\n private double amount;\n @Getter @Setter\n private LocalDateTime localDateTime;\n\n}\n```\n\nUnfortunately the exception is being thrown while converting from Message to Transfer transfer object.\n\n```\nCaused by: org.springframework.amqp.support.converter.MessageConversionException: failed to resolve class name. Class not found [com.kmb.bank.models.Transfer]\n2018-11-29 20:47:01.615 WARN 13688 --- [cTaskExecutor-1] ingErrorHandler$DefaultExceptionStrategy : Fatal message conversion error; message rejected; it will be dropped or routed to a dead letter exchange, if so configured: (Body:'{\"userAccountNumber\":\"1111444422221111\",\"title\":\"123\",\"recipientName\":\"123\",\"recipientAccountNumber\":\"1234123412341234\",\"amount\":123.0,\"localDateTime\":{\"nano\":599669800,\"year\":2018,\"monthValue\":11,\"dayOfMonth\":29,\"hour\":20,\"minute\":47,\"second\":1,\"month\":\"NOVEMBER\",\"dayOfWeek\":\"THURSDAY\",\"dayOfYear\":333,\"chronology\":{\"id\":\"ISO\",\"calendarType\":\"iso8601\"}}}' MessageProperties [headers={__TypeId__=com.kmb.bank.models.Transfer}, contentType=application/json, contentEncoding=UTF-8, contentLength=0, receivedDeliveryMode=PERSISTENT, priority=0, redelivered=false, receivedExchange=bank, receivedRoutingKey=, deliveryTag=2, consumerTag=amq.ctag-sLNqW-_WhDWLWJk6MCQcjg, consumerQueue=kolejka])\n```\n\nWhole message log:\nhttps://pastebin.com/raw/47Lq7dYD\n\n========================================\n\nTop Answer:\nI had this issue and when i tried using custom message converters, some would throw errors while trying to resolve to the class specified on the header by the spring producer. I ended up converting the object class to a json string using `ObjectMapper` class.\n\nOne thing i would like to point is that, doing that will send the content to rabbit MQ as a stringified `JSON`. So you can receive it on the consumer class as a string, map it to another custom class using `objectMapper.read(stringType, mappedToClass)`.\n\nAnother advantage i have gotten is that i can directly read it in other consumers written in `python` or `nodejs`\n\nIn summary\nIn springboot when sending,\n\n`rabbitTemplate.convertAndSend(exchange, key, objectMapper.writeValueAsString())`.\n\nIn springboot consumer when reading to a custom object that does not have to\nmatch the consumer object.\n\n`CustomObj obj = objectMapper.read(incomingString, CustomObj.class)`.\n\nA point to note is that, make sure to `ignoreUnknown` fields in the custom object class,\n\n========================================\n\nCode:\n```text\nProperties \npriority: 0\ndelivery_mode: 2\nheaders: \n__TypeId__: com.kmb.bank.models.Transfer\ncontent_encoding: UTF-8\ncontent_type: application/json\nPayload\n356 bytes\nEncoding: string\n\n\n{\"userAccountNumber\":\"1111444422221111\",\"title\":\"123\",\"recipientName\":\"123\",\"recipientAccountNumber\":\"1234123412341234\",\"amount\":123.0,\"localDateTime\":{\"nano\":526106200,\"year\":2018,\"monthValue\":11,\"dayOfMonth\":29,\"hour\":20,\"minute\":43,\"second\":0,\"month\":\"NOVEMBER\",\"dayOfWeek\":\"THURSDAY\",\"dayOfYear\":333,\"chronology\":{\"id\":\"ISO\",\"calendarType\":\"iso8601\"}}}\n```\n\n```text\n@Autowired\nprivate Jackson2JsonMessageConverter jackson2JsonMessageConverter;\n\n@RabbitListener(queues = \"kolejka\")\npublic void listen(Message message) {\n try {\n Transfer transfer = (Transfer) jackson2JsonMessageConverter.fromMessage(message);\n log.info(transfer);\n } catch (Exception e) {\n log.debug(\"Error thrown while listening + \" + e.getMessage());\n }\n\n}\n```\n\n```text\n@Bean\npublic Jackson2JsonMessageConverter jackson2JsonMessageConverter() {\n return new Jackson2JsonMessageConverter(objectMapper());\n}\n```\n\n```text\npackage com.kmb.transactionlogger.models;\n\n@AllArgsConstructor\npublic class Transfer {\n @Getter @Setter\n private String userAccountNumber;\n @Getter @Setter\n private String title;\n @Getter @Setter\n private String recipientName;\n @Getter @Setter\n private String recipientAccountNumber;\n @Getter @Setter\n private double amount;\n @Getter @Setter\n private LocalDateTime localDateTime;\n\n}\n```\n\n```text\nCaused by: org.springframework.amqp.support.converter.MessageConversionException: failed to resolve class name. Class not found [com.kmb.bank.models.Transfer]\n2018-11-29 20:47:01.615 WARN 13688 --- [cTaskExecutor-1] ingErrorHandler$DefaultExceptionStrategy : Fatal message conversion error; message rejected; it will be dropped or routed to a dead letter exchange, if so configured: (Body:'{\"userAccountNumber\":\"1111444422221111\",\"title\":\"123\",\"recipientName\":\"123\",\"recipientAccountNumber\":\"1234123412341234\",\"amount\":123.0,\"localDateTime\":{\"nano\":599669800,\"year\":2018,\"monthValue\":11,\"dayOfMonth\":29,\"hour\":20,\"minute\":47,\"second\":1,\"month\":\"NOVEMBER\",\"dayOfWeek\":\"THURSDAY\",\"dayOfYear\":333,\"chronology\":{\"id\":\"ISO\",\"calendarType\":\"iso8601\"}}}' MessageProperties [headers={__TypeId__=com.kmb.bank.models.Transfer}, contentType=application/json, contentEncoding=UTF-8, contentLength=0, receivedDeliveryMode=PERSISTENT, priority=0, redelivered=false, receivedExchange=bank, receivedRoutingKey=, deliveryTag=2, consumerTag=amq.ctag-sLNqW-_WhDWLWJk6MCQcjg, consumerQueue=kolejka])\n```\n\n```text\nJackson2JsonMessageConverter\n```\n\n```text\ntransfer\n```\n\n```text\nTransfer\n```\n\n```text\npublic void listen(Transfer transfer)\n```\n\n```text\nObjectMapper\n```\n\n```text\nJSON\n```\n\n```text\nobjectMapper.read(stringType, mappedToClass)\n```\n\n```text\npython\n```\n\n```text\nnodejs\n```\n\n```text\nrabbitTemplate.convertAndSend(exchange, key, objectMapper.writeValueAsString())\n```\n\n```text\nCustomObj obj = objectMapper.read(incomingString, CustomObj.class)\n```\n\n```text\nignoreUnknown\n```\n\n```html\n// 1. producer converter config\n\n @Bean(\"Jackson2JsonMessageConverter\")\n Jackson2JsonMessageConverter jackson2JsonMessageConverter() {\n return new Jackson2JsonMessageConverter();\n }\n\n @Bean\n public RabbitTemplate rabbitTemplate(final ConnectionFactory connectionFactory, Jackson2JsonMessageConverter jackson2JsonMessageConverter) {\n final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);\n rabbitTemplate.setMessageConverter(jackson2JsonMessageConverter);\n return rabbitTemplate;\n }\n\n// 2. consumer converter config\n\n@RabbitListener(queues = RabbitMQConfig.queueName, messageConverter = \"Jackson2JsonMessageConverter\")\npublic void receiveMessage(Object message) {\n if (message instanceof Object) {\n LOG.info(\"receiveMessage\" + message.toString());\n }\n}\n\n\n// 3. send message which is an Java Object\n\nrabbitTemplate.convertAndSend(\"topicExchangeName\", \"routing.key.test\", Object);\n```\n\n```html\n<dependency>\n <groupId>org.springframework.boot</groupId>\n <artifactId>spring-boot-starter-amqp</artifactId>\n </dependency>\n <dependency>\n <groupId>org.springframework.amqp</groupId>\n <artifactId>spring-rabbit-test</artifactId>\n <scope>test</scope>\n </dependency>\n <dependency>\n <groupId>org.springframework.boot</groupId>\n <artifactId>spring-boot-starter-json</artifactId>\n </dependency>\n```\n\n========================================\n\nComments:\n- Can you provide more detailed log (stacktrace)?\n- I think it's a problem that it's different Transfer class, package is different from **TypeId**, but I don't know the solution\n- You have to set up the type mapping in the receiving `jackson2JsonMessageConverter`'s type mapper to map to a different class. Alternatively, the framework will infer the type from the parameter if you use `public void listen(Transfer transfer)` if you wire the converter into the listener container factory. If it's a Boot app, that will happen automatically.\n- It helped a little, but now I am getting error connected with LocalDateTime:Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionExceptio‌​n: Cannot construct instance of `java.time.LocalDateTime` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator) at\n- You need a custom Jackson deserializer applied to the ObjectMapper - here's one question that has answers about it: stackoverflow.com/questions/29956175/…","metadata":{"transformedAt":"2026-08-18T18:33:20.332Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":19,"totalLines":279,"estimatedTokens":2463}}1194{"id":"stack-49302659","source":"stackoverflow","questionId":49302659,"title":"RabbitMQ to Azure Event Hub: AMQP 0.9.1 compatibility with AMQP 1.0","tags":["azure","rabbitmq","amqp","azure-eventhub"],"text":"Title: RabbitMQ to Azure Event Hub: AMQP 0.9.1 compatibility with AMQP 1.0\nTags: azure, rabbitmq, amqp, azure-eventhub\nSource: Stack Overflow\n\nQuestion:\nI have a component that currently integrated with RabbitMQ. I would like to swap out RabbitMQ for Azure Event Hub as we are now in the cloud. Is AMQP 0.9.1 compatible with AMQP 1.0? Will the swap work seamlessly?","metadata":{"transformedAt":"2026-08-18T18:33:20.332Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":0,"totalLines":6,"estimatedTokens":92}}1195{"id":"stack-50759737","source":"stackoverflow","questionId":50759737,"title":"Getting RabbitMQ authentication failing even with cookie is set","tags":["rabbitmq"],"text":"Title: Getting RabbitMQ authentication failing even with cookie is set\nTags: rabbitmq\nSource: Stack Overflow\n\nQuestion:\nI have recently installed rabbitmq with ErlanOTP on Windows 10 running on lattePanda\n\nI ran rabbitmqctl status and got the following error:\n\nC:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.7.5\\sbin>rabbitmqctl status\n\nStatus of node rabbit@DESKTOP-V6GQ6RF ...\n\nError: unable to perform an operation on node 'rabbit@DESKTOP-V6GQ6RF'. Please see diagnostics information and suggestions below.\n\nMost common reasons for this are:\n\n- Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)\n\n- CLI tool fails to authenticate with the server (e.g. due to CLI tool's Erlang cookie not matching that of the server)\n\n- Target node is not running\n\nIn addition to the diagnostics info below:\n\n- See the CLI, clustering and networking guides on http://rabbitmq.com/documentation.html to learn more\n\n- Consult server logs on node rabbit@DESKTOP-V6GQ6RF\n\nDIAGNOSTICS\n\nattempted to contact: ['rabbit@DESKTOP-V6GQ6RF']\n\nrabbit@DESKTOP-V6GQ6RF:\n\n- connected to epmd (port 4369) on DESKTOP-V6GQ6RF\n\n- epmd reports node 'rabbit' uses port 25672 for inter-node and CLI tool traffic\n\n- TCP connection succeeded but Erlang distribution failed\n\n- Authentication failed (rejected by the remote node), please check the Erlang cookie\n\nCurrent node details:\n\n- node name: 'rabbitmqcli2@DESKTOP-V6GQ6RF'\n\n- effective user's home directory: C:\\Users\\LattePanda\n\n- Erlang cookie hash: 8Kq9f/AaeixMvahU4G2v8A==\n\nHow can I get RabbitMQ up and running?\n\nWhile trouble-shooting I discovered this thread https://groups.google.com/forum/#!topic/rabbitmq-users/a6sqrAUX_Fg\n\nand set the environment variable to Erlang Cookie I found in `%HOMEDRIVE%%HOMEPATH%\\.erlang.cookie` but it still doesn't seem to work.\n\n========================================\n\nCode:\n```text\n%HOMEDRIVE%%HOMEPATH%\\.erlang.cookie\n```\n\n```text\nC:\\WINDOWS\\system32\\config\\systemprofile\\.erlang.cookie\n```\n\n```text\n%HOMEDRIVE%%HOMEPATH%\\.erlang.cookie\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.332Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":71,"estimatedTokens":513}}1196{"id":"stack-52291495","source":"stackoverflow","questionId":52291495,"title":"Node.js amqplib - not able to implement the reconnect in case of connection close","tags":["node.js","rabbitmq","node-amqp","node-amqplib"],"text":"Title: Node.js amqplib - not able to implement the reconnect in case of connection close\nTags: node.js, rabbitmq, node-amqp, node-amqplib\nSource: Stack Overflow\n\nQuestion:\nI am trying to implement a reconnect mechanism when the connection fails to the rabbitmq queue server.This code is only for consuming messages, Below is my code ( the channel Init function takes care of initialising the consumer and binding to the queue ).\n\n```\nconnect() {\n let conn = amqp.connect(queueConfig.QUEUE_SERVER_URL + \"?heartbeat=60\");\n return conn;\n}\n\ncreateConnection(){\n console.log(\"Trying to connect amqp\");\n let self = this;\n self.connection = this.connect()\n .then(function(connection){\n console.log(\"[AMQP] connected\");\n connection.on(\"error\",function(err){\n if (err.message !== \"Connection closing\") {\n console.error(\"[AMQP] conn error\", err.message);\n }\n });\n connection.on(\"close\", function() {\n console.error(\"[AMQP] reconnecting\");\n return setTimeout(createConnection, 1000);\n });\n return connection.createConfirmChannel();\n })\n .then(self.channelInit);\n}\n```\n\nOn connection failure I am successfully getting the prompt \"[AMQP] reconnecting\", but after that queue is not getting reconnected, no other prompts are coming in console log.\n\nPlease help.\n\n========================================\n\nCode:\n```text\nconnect() {\n let conn = amqp.connect(queueConfig.QUEUE_SERVER_URL + \"?heartbeat=60\");\n return conn;\n}\n\ncreateConnection(){\n console.log(\"Trying to connect amqp\");\n let self = this;\n self.connection = this.connect()\n .then(function(connection){\n console.log(\"[AMQP] connected\");\n connection.on(\"error\",function(err){\n if (err.message !== \"Connection closing\") {\n console.error(\"[AMQP] conn error\", err.message);\n }\n });\n connection.on(\"close\", function() {\n console.error(\"[AMQP] reconnecting\");\n return setTimeout(createConnection, 1000);\n });\n return connection.createConfirmChannel();\n })\n .then(self.channelInit);\n}\n```\n\n```text\nsetTimeout(createConnection, 1000);\n```\n\n```text\nsetTimeout(createConnection(), 1000);\n```\n\n========================================\n\nComments:\n- It should be `return setTimeout(createConnection, 1000);`\n- I just changed that typo and tried, still not working.\n- Try this one: `return setTimeout(self.createConnection, 1000);`\n- thanks for answering. I just tried with the change you suggested, still not working.\n- Mmmmmm... `setTimeout(createConnection,1000)` to `setTimeout(createConnection.bind(self),1000)`\n- any idea on where can i inject the code to reinitialize channels and rebind the queue ?","metadata":{"transformedAt":"2026-08-18T18:33:20.332Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":3,"totalLines":85,"estimatedTokens":666}}1197{"id":"stack-44809230","source":"stackoverflow","questionId":44809230,"title":"RabbitMQ - Is there a way to limit the number of messages in a queue?","tags":["rabbitmq","message-queue","amqp"],"text":"Title: RabbitMQ - Is there a way to limit the number of messages in a queue?\nTags: rabbitmq, message-queue, amqp\nSource: Stack Overflow\n\nQuestion:\nIs there a way to limit the maximum number of messages a queue can hold in RabbitMQ?\n\nFor example, if this number is set to 10 and the current size is 10, the oldest message will be discarded when a new message is pushed to the queue (FIFO).\n\n========================================\n\nCode:\n```text\nMap<String, Object> args = new HashMap<String, Object>();\nargs.put(\"x-max-length\", 10);\nchannel.queueDeclare(\"myqueue\", false, false, false, args);\n```\n\n```text\nrabbitmqctl set_policy Ten \".*\" '{\"max-length\":10}' --apply-to queues\n```","metadata":{"transformedAt":"2026-08-18T18:33:20.332Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":2,"totalLines":21,"estimatedTokens":170}}1198{"id":"stack-49619839","source":"stackoverflow","questionId":49619839,"title":"Catching events prior to subscription with FromEventPattern","tags":["c#",".net","rabbitmq","system.reactive"],"text":"Title: Catching events prior to subscription with FromEventPattern\nTags: c#, .net, rabbitmq, system.reactive\nSource: Stack Overflow\n\nQuestion:\nI'm writing a listener for messages using the Rx framework.\n\nThe problem I'm facing is that the library I'm using uses a consumer that publishes events whenever a message has arrived.\n\nI've managed to consume the incoming messages via `Observable.FromEventPattern` but I have a problem with the messages that are already in the server.\n\nAt the moment I have the following chain of commands\n\n- Create a consumer\n\n- Create an observable sequence with `FromEventPattern` and apply needed transformations\n\n- Tell the consumer to start\n\n- Subscribe to the sequence\n\nThe easiest solution would be to swap steps 3. and 4. but since they happen in different components of the system, it's very hard for me to do so.\n\nIdeally I would like to execute step 3 when step 4 happens (like a `OnSubscribe` method).\n\nThanks for your help :)\n\nPS: to add more details, the events are coming from a RabbitMQ queue and I am using the `EventingBasicConsumer` class found in the RabbitMQ.Client package.\n\nHere you can find the library I am working on. Specifically, this is the class/method giving me problems.\n\n**Edit**\n\nHere is a stripped version of the problematic code\n\n```\nvoid Main()\n{\n var engine = new Engine();\n\n var messages = engine.Start();\n\n messages.Subscribe(m => m.Dump());\n\n Console.ReadLine();\n\n engine.Stop();\n}\n\npublic class Engine\n{\n IConnection _connection;\n IModel _channel;\n\n public IObservable Start()\n {\n var connectionFactory = new ConnectionFactory();\n\n _connection = connectionFactory.CreateConnection();\n _channel = _connection.CreateModel();\n\n EventingBasicConsumer consumer = new EventingBasicConsumer(_channel);\n\n var observable = Observable.FromEventPattern(\n a => consumer.Received += a, \n a => consumer.Received -= a)\n .Select(e => e.EventArgs);\n\n _channel.BasicConsume(\"a_queue\", false, consumer);\n\n return observable.Select(Transform);\n }\n\n private Message Transform(BasicDeliverEventArgs args) => new Message();\n\n public void Stop()\n {\n _channel.Dispose();\n _connection.Dispose();\n }\n}\n\npublic class Message { }\n```\n\nThe symptom I experience is that since I invoke BasicConsume before subscribing to the sequence, any message that is in the RabbitMQ queue is fetched but not passed down the pipeline.\n\nSince I don't have \"autoack\" on, the messages are returned to the queue as soon as the program stops.\n\n========================================\n\nTop Answer:\nI think there is no need to actually subscribe to rabbit queue (via `BasicConsume`) until you have subscribers to your observable. Right now you are starting rabbit subscription right away and push items to observable even if no one has subscribed to it. \n\nSuppose we have this sample class:\n\n```\nclass Events {\n public event Action MessageArrived;\n\n Timer _timer;\n public void Start()\n {\n Console.WriteLine(\"Timer starting\");\n int i = 0;\n _timer = new Timer(_ => {\n this.MessageArrived?.Invoke(i.ToString());\n i++;\n }, null, TimeSpan.Zero, TimeSpan.FromSeconds(1));\n }\n\n public void Stop() {\n _timer?.Dispose();\n Console.WriteLine(\"Timer stopped\");\n }\n}\n```\n\nWhat you are doing now is basically:\n\n```\nvar ev = new Events();\nvar ob = Observable.FromEvent(x => ev.MessageArrived += x, x => ev.MessageArrived -= x); \nev.Start(); \nreturn ob;\n```\n\nWhat you need instead is observable which does exactly that, but only when someone subscribes:\n\n```\nreturn Observable.Create(observer =>\n{\n var ev = new Events();\n var ob = Observable.FromEvent(x => ev.MessageArrived += x, x => ev.MessageArrived -= x);\n // first subsribe\n var sub = ob.Subscribe(observer);\n // then start\n ev.Start();\n // when subscription is disposed - unsubscribe from rabbit\n return new CompositeDisposable(sub, Disposable.Create(() => ev.Stop()));\n});\n```\n\nGood, but now every subscription to observable will result in separate subscription to rabbit queues, which is not what we need. We can solve that with `Publish().RefCount()`:\n\n```\nreturn Observable.Create(observer => {\n var ev = new Events();\n var ob = Observable.FromEvent(x => ev.MessageArrived += x, x => ev.MessageArrived -= x);\n var sub = ob.Subscribe(observer); \n ev.Start(); \n return new CompositeDisposable(sub, Disposable.Create(() => ev.Stop()));\n}).Publish().RefCount();\n```\n\nNow what will happen is when first subscriber subscribes to observable (ref count goes from 0 to 1) - code from `Observable.Create` body is invoked and subscribes to rabbit queue. This subscription is then shared by all subsequent subscribers. When last unsubscribes (ref count goes to zero) - subscription is disposed, `ev.Stop` is called, and we unsubscribe from rabbit queue.\n\nIf so happens that you call `Start()` (which creates observable in your code) and never subscribe to it - nothing happens and no subscriptions to rabbit is made at all.\n\n========================================\n\nCode:\n```text\nvoid Main()\n{\n var engine = new Engine();\n\n var messages = engine.Start();\n\n messages.Subscribe(m => m.Dump());\n\n Console.ReadLine();\n\n engine.Stop();\n}\n\npublic class Engine\n{\n IConnection _connection;\n IModel _channel;\n\n public IObservable<Message> Start()\n {\n var connectionFactory = new ConnectionFactory();\n\n _connection = connectionFactory.CreateConnection();\n _channel = _connection.CreateModel();\n\n EventingBasicConsumer consumer = new EventingBasicConsumer(_channel);\n\n var observable = Observable.FromEventPattern<BasicDeliverEventArgs>(\n a => consumer.Received += a, \n a => consumer.Received -= a)\n .Select(e => e.EventArgs);\n\n _channel.BasicConsume(\"a_queue\", false, consumer);\n\n return observable.Select(Transform);\n }\n\n private Message Transform(BasicDeliverEventArgs args) => new Message();\n\n public void Stop()\n {\n _channel.Dispose();\n _connection.Dispose();\n }\n}\n\npublic class Message { }\n```\n\n```text\nObservable.FromEventPattern\n```\n\n```text\nFromEventPattern\n```\n\n```text\nOnSubscribe\n```\n\n```text\nEventingBasicConsumer\n```\n\n```text\nusing System;\nusing System.Collections.Generic;\nusing System.Reactive.Concurrency;\nusing System.Reactive.Linq;\nusing System.Reactive.Subjects;\nusing RabbitMQ.Client;\n\nnamespace com.rabbitmq.consumers\n{\n public sealed class ObservableConsumer : IBasicConsumer\n {\n private readonly List<string> _consumerTags = new List<string>();\n private readonly object _consumerTagsLock = new object();\n private readonly Subject<Message> _subject = new Subject<Message>();\n\n public ushort PrefetchCount { get; set; }\n public IEnumerable<string> ConsumerTags { get { return new List<string>(_consumerTags); } }\n\n /// <summary>\n /// Registers this consumer on the given queue. \n /// </summary>\n /// <returns>The consumer tag assigned.</returns>\n public string ConsumeFrom(IModel channel, string queueName)\n {\n Model = channel;\n return Model.BasicConsume(queueName, false, this);\n }\n\n /// <summary>\n /// Contains an observable of the incoming messages where messages are processed on a thread pool thread.\n /// </summary>\n public IObservable<Message> IncomingMessages\n {\n get { return _subject.ObserveOn(Scheduler.ThreadPool); }\n }\n\n ///<summary>Retrieve the IModel instance this consumer is\n ///registered with.</summary>\n public IModel Model { get; private set; }\n\n ///<summary>Returns true while the consumer is registered and\n ///expecting deliveries from the broker.</summary>\n public bool IsRunning\n {\n get { return _consumerTags.Count > 0; }\n }\n\n /// <summary>\n /// Run after a consumer is cancelled.\n /// </summary>\n /// <param name=\"consumerTag\"></param>\n private void OnConsumerCanceled(string consumerTag)\n {\n\n }\n\n /// <summary>\n /// Run after a consumer is added.\n /// </summary>\n /// <param name=\"consumerTag\"></param>\n private void OnConsumerAdded(string consumerTag)\n {\n\n }\n\n public void HandleBasicConsumeOk(string consumerTag)\n {\n lock (_consumerTagsLock) {\n if (!_consumerTags.Contains(consumerTag))\n _consumerTags.Add(consumerTag);\n }\n }\n\n public void HandleBasicCancelOk(string consumerTag)\n {\n lock (_consumerTagsLock) {\n if (_consumerTags.Contains(consumerTag)) {\n _consumerTags.Remove(consumerTag);\n OnConsumerCanceled(consumerTag);\n }\n }\n }\n\n public void HandleBasicCancel(string consumerTag)\n {\n lock (_consumerTagsLock) {\n if (_consumerTags.Contains(consumerTag)) {\n _consumerTags.Remove(consumerTag);\n OnConsumerCanceled(consumerTag);\n }\n }\n }\n\n public void HandleModelShutdown(IModel model, ShutdownEventArgs reason)\n {\n //Don't need to do anything.\n }\n\n public void HandleBasicDeliver(string consumerTag,\n ulong deliveryTag,\n bool redelivered,\n string exchange,\n string routingKey,\n IBasicProperties properties,\n byte[] body)\n {\n //Hack - prevents the broker from sending too many messages.\n //if (PrefetchCount > 0 && _unackedMessages.Count > PrefetchCount) {\n // Model.BasicReject(deliveryTag, true);\n // return;\n //}\n\n var message = new Message(properties.HeaderFromBasicProperties()) { Content = body };\n var deliveryData = new MessageDeliveryData()\n {\n ConsumerTag = consumerTag,\n DeliveryTag = deliveryTag,\n Redelivered = redelivered,\n };\n\n message.Tag = deliveryData;\n\n if (AckMode != AcknowledgeMode.AckWhenReceived) {\n message.Acknowledged += messageAcknowledged;\n message.Failed += messageFailed;\n }\n\n _subject.OnNext(message);\n }\n\n void messageFailed(Message message, Exception ex, bool requeue)\n {\n try {\n message.Acknowledged -= messageAcknowledged;\n message.Failed -= messageFailed;\n\n if (message.Tag is MessageDeliveryData) {\n Model.BasicNack((message.Tag as MessageDeliveryData).DeliveryTag, false, requeue);\n }\n }\n catch {}\n }\n\n void messageAcknowledged(Message message)\n {\n try {\n message.Acknowledged -= messageAcknowledged;\n message.Failed -= messageFailed;\n\n if (message.Tag is MessageDeliveryData) {\n var ackMultiple = AckMode == AcknowledgeMode.AckAfterAny;\n Model.BasicAck((message.Tag as MessageDeliveryData).DeliveryTag, ackMultiple);\n }\n }\n catch {}\n }\n }\n}\n```\n\n```text\nclass Events {\n public event Action<string> MessageArrived;\n\n Timer _timer;\n public void Start()\n {\n Console.WriteLine(\"Timer starting\");\n int i = 0;\n _timer = new Timer(_ => {\n this.MessageArrived?.Invoke(i.ToString());\n i++;\n }, null, TimeSpan.Zero, TimeSpan.FromSeconds(1));\n }\n\n public void Stop() {\n _timer?.Dispose();\n Console.WriteLine(\"Timer stopped\");\n }\n}\n```\n\n```text\nvar ev = new Events();\nvar ob = Observable.FromEvent<string>(x => ev.MessageArrived += x, x => ev.MessageArrived -= x); \nev.Start(); \nreturn ob;\n```\n\n```text\nreturn Observable.Create<string>(observer =>\n{\n var ev = new Events();\n var ob = Observable.FromEvent<string>(x => ev.MessageArrived += x, x => ev.MessageArrived -= x);\n // first subsribe\n var sub = ob.Subscribe(observer);\n // then start\n ev.Start();\n // when subscription is disposed - unsubscribe from rabbit\n return new CompositeDisposable(sub, Disposable.Create(() => ev.Stop()));\n});\n```\n\n```text\nreturn Observable.Create<string>(observer => {\n var ev = new Events();\n var ob = Observable.FromEvent<string>(x => ev.MessageArrived += x, x => ev.MessageArrived -= x);\n var sub = ob.Subscribe(observer); \n ev.Start(); \n return new CompositeDisposable(sub, Disposable.Create(() => ev.Stop()));\n}).Publish().RefCount();\n```\n\n```text\nBasicConsume\n```\n\n```text\nPublish().RefCount()\n```\n\n```text\nObservable.Create\n```\n\n```text\nev.Stop\n```\n\n```text\nStart()\n```\n\n========================================\n\nComments:\n- You mean you miss some messages because you are subscribing too late?\n- Precisely! Should I fix the question?\n- That part seems clear, but as you said yourself - the most reasonable thing is to subscribe before starting. Why you cannot do that while you control all the code is not that clear to me. Maybe just pass optional subscription callback to that `Start`? You can also use `Replay()` but it will cache all messages, which might not be a good idea (depending on number of those messages).\n- I didn't think of a callback, but I wonder if there is a Rx way to solve the issue. As for the split, the Host and the Engine have different responsibilities and mixing them up would be not nice.\n- ’Replay’ wouldn't do. I was looking at ’Publish’ but I'm not sure I understand how it works and where it should be used.\n- I'm a little fuzzy on the issue. Can you put code and/or the specific error or problem? Links to the code base are insufficient and a basis for closure.\n- @theMayer i added the specific code and a better explaination of the issue.\n- Thanks @Evk for your answer. I will check it when I get home this evening and let you know!\n- This code is fragile in the sense that a RabbitMQ consumer is a transient object. What happens when the consumer is disconnected?\n- But this is just a sample targeting specific question (about late subsciption leading to missing messages), not a robust rabbitmq listener implementation. Anyway if consumer is disconnected - the most natural thing seems to end observable stream.\n- This answer reminds me that I need to work on getting my re-implementation of RabbitMQ .NET Client up into github so others can use it... and you can help make it better. :)\n- Thanks! this one worked exactly as I wanted! I had to change the Subject to be a ReplaySubject. Otherwise your solution worked like a charm.\n- A ReplaySubject has specific behaviors which you may find undesirable...","metadata":{"transformedAt":"2026-08-18T18:33:20.333Z","totalAnswersIncluded":1,"totalCodeBlocksIncluded":15,"totalLines":478,"estimatedTokens":3769}}1199{"id":"stack-48033118","source":"stackoverflow","questionId":48033118,"title":"Temporarily stop consuming RabbitMQ messages and resume later","tags":["java","rabbitmq","amqp","amqp-client"],"text":"Title: Temporarily stop consuming RabbitMQ messages and resume later\nTags: java, rabbitmq, amqp, amqp-client\nSource: Stack Overflow\n\nQuestion:\nI use Java's rabbitmq-client (https://mvnrepository.com/artifact/com.rabbitmq/amqp-client) and I need to implement the following scenario:\n\n- While receiving Rabbit messages, I may need to pause Rabbitmq consumption from particular queues if I suspect that all awaiting data will not fit in memory.\n\n- After I processed some messages, I need to open consumption again for the following set of messages.\n\n- Repeat as needed.\n\nWhat would be the best way to implement pause/resume of listening from a RabbitMQ queue using the amqp-client Java library?\n\n========================================\n\nCode:\n```text\nbasicConsume\n```\n\n```text\nbasicCancel\n```\n\n```text\nbasicConsume\n```\n\n```text\nbasicQos\n```\n\n========================================\n\nComments:\n- I'd love to know how to do the same using Spring-rabbit (without touching amqp-client directly). Any idea?\n- I suggest searching the code (github.com/spring-projects/spring-amqp) or asking a question on the various support channels. Several Spring developers are active on stack overflow.\n- Were you able to find out how we can do this with spring-amqp?","metadata":{"transformedAt":"2026-08-18T18:33:20.333Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":4,"totalLines":40,"estimatedTokens":312}}1200{"id":"stack-45950987","source":"stackoverflow","questionId":45950987,"title":"How to configure Wildfly to connect to RabbitMQ?","tags":["jakarta-ee","rabbitmq","jms","wildfly","message-driven-bean"],"text":"Title: How to configure Wildfly to connect to RabbitMQ?\nTags: jakarta-ee, rabbitmq, jms, wildfly, message-driven-bean\nSource: Stack Overflow\n\nQuestion:\nI'm having difficulty configuring JB EAP7 to use RabbitMQ as a message broker.\nI have created a rabbitmq module and defined it as a global module in my standalone-ha.xml.\n\nmodules/system/layers/base/com/rabbitmq/main/module.xml:\n\n```\n\n \n \n \n \n \n \n \n \n \n\n```\n\nJB7 starts without issues. But I see the following in my server.log, showing that the MDB is trying to bind to an ActiveMQ connection (the default provider in Wildfly I guess):\n\n```\n2017-08-29 17:24:09,193 INFO [org.jboss.as.ejb3]WFLYEJB0042: Started message driven bean 'Subscriber' with 'activemq-ra' resource adapter\n2017-08-29 17:24:09,368 INFO [javax.enterprise.resource.webcontainer.jsf.config]Initializing Mojarra 2.2.12-jbossorg-2 for context '/webapp-0.0.1-SNAPSHOT'\n2017-08-29 17:24:09,462 INFO [org.apache.activemq.artemis.ra]AMQ151000: awaiting topic/queue creation java:/global/mq/kodo\n2017-08-29 17:24:10,103 INFO [org.wildfly.extension.undertow]WFLYUT0021: Registered web context: /webapp-0.0.1-SNAPSHOT\n2017-08-29 17:24:10,285 INFO [org.jboss.as.server]WFLYSRV0010: Deployed \"webapp-0.0.1-SNAPSHOT.war\" (runtime-name : \"webapp-0.0.1-SNAPSHOT.war\")\n2017-08-29 17:24:10,286 INFO [org.jboss.as.server]WFLYSRV0010: Deployed \"kodo-jdo.rar\" (runtime-name : \"kodo-jdo.rar\")\n2017-08-29 17:24:11,465 INFO [org.apache.activemq.artemis.ra]AMQ151001: Attempting to reconnect org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec(ra=org.apache.activemq.artemis.ra.ActiveMQResourceAdapter@78712571 destination=java:/global/mq/kodo destinationType=javax.jms.Queue ack=Auto-acknowledge durable=false clientID=null user=null maxSession=15)\n```\n\nI'm not sure how to identify in my MDB that I want the MDB to use my RabbitMQ defined ConnectionFactory. My MDB is defined as:\n\n```\n@MessageDriven(\n activationConfig = {\n @ActivationConfigProperty(propertyName = \"destinationType\", propertyValue = \"javax.jms.Queue\"),\n @ActivationConfigProperty(propertyName = \"destinationLookup\", propertyValue = \"java:/global/mq/kodo\") })\npublic class Subscriber implements MessageListener {\n\n public void onMessage(final Message message) {\n try {\n System.out.println(message.getBody(Object.class).toString());\n } catch (JMSException e) {\n // TODO Auto-generated catch block\n throw new RuntimeException(e);\n }\n }\n}\n```\n\nbut I cannot find documentation where/how to specify the ConnectionFactory. I've tried adding a `@JMSConnectionFactory( String JNDI)` annotation to my class and I'm still getting the same result.\n\nAm I missing something in my RabbitMQ module definition? Is my MDB not annotated correctly? What do I need to do in order to configure my MDB to use my RabbitMQ ConnectionFactory to connect to the Message Broker?\n\n========================================\n\nCode:\n```text\n<module xmlns=\"urn:jboss:module:1.1\" name=\"com.rabbitmq\">\n <resources>\n <resource-root path=\"rabbitmq-jms-1.7.0.jar\"/>\n <resource-root path=\"amqp-client-4.2.0.jar\" />\n </resources>\n <dependencies>\n <module name=\"javax.api\" />\n <module name=\"javax.transaction.api\"/>\n <module name=\"org.slf4j\"/>\n </dependencies>\n</module>\n```\n\n```text\n2017-08-29 17:24:09,193 INFO [org.jboss.as.ejb3]WFLYEJB0042: Started message driven bean 'Subscriber' with 'activemq-ra' resource adapter\n2017-08-29 17:24:09,368 INFO [javax.enterprise.resource.webcontainer.jsf.config]Initializing Mojarra 2.2.12-jbossorg-2 for context '/webapp-0.0.1-SNAPSHOT'\n2017-08-29 17:24:09,462 INFO [org.apache.activemq.artemis.ra]AMQ151000: awaiting topic/queue creation java:/global/mq/kodo\n2017-08-29 17:24:10,103 INFO [org.wildfly.extension.undertow]WFLYUT0021: Registered web context: /webapp-0.0.1-SNAPSHOT\n2017-08-29 17:24:10,285 INFO [org.jboss.as.server]WFLYSRV0010: Deployed \"webapp-0.0.1-SNAPSHOT.war\" (runtime-name : \"webapp-0.0.1-SNAPSHOT.war\")\n2017-08-29 17:24:10,286 INFO [org.jboss.as.server]WFLYSRV0010: Deployed \"kodo-jdo.rar\" (runtime-name : \"kodo-jdo.rar\")\n2017-08-29 17:24:11,465 INFO [org.apache.activemq.artemis.ra]AMQ151001: Attempting to reconnect org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec(ra=org.apache.activemq.artemis.ra.ActiveMQResourceAdapter@78712571 destination=java:/global/mq/kodo destinationType=javax.jms.Queue ack=Auto-acknowledge durable=false clientID=null user=null maxSession=15)\n```\n\n```text\n@MessageDriven(\n activationConfig = {\n @ActivationConfigProperty(propertyName = \"destinationType\", propertyValue = \"javax.jms.Queue\"),\n @ActivationConfigProperty(propertyName = \"destinationLookup\", propertyValue = \"java:/global/mq/kodo\") })\npublic class Subscriber implements MessageListener {\n\n public void onMessage(final Message message) {\n try {\n System.out.println(message.getBody(Object.class).toString());\n } catch (JMSException e) {\n // TODO Auto-generated catch block\n throw new RuntimeException(e);\n }\n }\n}\n```\n\n```text\n@JMSConnectionFactory( String JNDI)\n```\n\n```text\n<mdb>\n <resource-adapter-ref resource-adapter-name=\"${ejb.resource-adapter-name:activemq-ra.rar}\"/>\n <bean-instance-pool-ref pool-name=\"mdb-strict-max-pool\"/>\n</mdb>\n```\n\n========================================\n\nComments:\n- Thanks. I gave up on the idea of MDBs, and am just using message listeners and CDI (retrieving the ConnectionFactory and Queue definition from the standalone-ha.xml).\n- Now, I'm having trouble with auto-recovery, or how to handle timeouts using the JMS client. see stackoverflow.com/q/46007414/827480 Have you figured out how to deal with Exception handling by the JMS client at all?\n- Could this technically be implemented in the JMS client or is AMQP inherently incapable of some MDB requirements in JMS? And what is the specific JMS feature that we're talking about?\n- All features listed in RabbitMQ JMS Compliance page could be added to the RabbitMQ JMS client. These features would permit to enable JEE MDBs using RabbitMQ JMS Client. Without that, it's also possible to implement a JCA Resource adapter using AMQP, which would enable MDB in JEE apps, such as ActiveMQ Resource adapter (documentation for TomEE). Currently, RabbitMQ provides only a partial JMS impl and no resource adapter for JEE apps.\n- Is there a public example of someone connecting RabbitMQ through AMQP with MDBs using ActiveMQ resource adapters?","metadata":{"transformedAt":"2026-08-18T18:33:20.333Z","totalAnswersIncluded":0,"totalCodeBlocksIncluded":5,"totalLines":124,"estimatedTokens":1616}}