1"use strict";(self.webpackChunkrabbitmq_website=self.webpackChunkrabbitmq_website||[]).push([["12666"],{37901(e,i,n){n.r(i),n.d(i,{metadata:()=>r,default:()=>u,frontMatter:()=>o,contentTitle:()=>c,toc:()=>l,assets:()=>a});var r=JSON.parse('{"id":"consumer-priority","title":"Consumer Priorities","description":"\x3c!--","source":"@site/versioned_docs/version-4.1/consumer-priority.md","sourceDirName":".","slug":"/consumer-priority","permalink":"/docs/4.1/consumer-priority","draft":false,"unlisted":false,"editUrl":"https://github.com/rabbitmq/rabbitmq-website/tree/main/versioned_docs/version-4.1/consumer-priority.md","tags":[],"version":"4.1","frontMatter":{"title":"Consumer Priorities"},"sidebar":"docsSidebar","previous":{"title":"Consumer Prefetch","permalink":"/docs/4.1/consumer-prefetch"},"next":{"title":"Negative Acknowledgements","permalink":"/docs/4.1/nack"}}'),s=n(74848),t=n(28453);let o={title:"Consumer Priorities"},c="Consumer Priorities",a={},l=[{value:"Overview",id:"overview",level:2},{value:"Definition of Active Consumers",id:"definitions",level:2},{value:"Using Consumer Priorities",id:"how-to-use",level:2}];function h(e){let i={a:"a",code:"code",h1:"h1",h2:"h2",header:"header",li:"li",ol:"ol",p:"p",pre:"pre",...(0,t.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(i.header,{children:(0,s.jsx)(i.h1,{id:"consumer-priorities",children:"Consumer Priorities"})}),"\n",(0,s.jsx)(i.h2,{id:"overview",children:"Overview"}),"\n",(0,s.jsx)(i.p,{children:"Consumer priorities allow you to ensure that high priority\nconsumers receive messages while they are active, with messages\nonly going to lower priority consumers when the high priority\nconsumers block."}),"\n",(0,s.jsx)(i.p,{children:"Normally, active consumers connected to a queue receive messages\nfrom it in a round-robin fashion. When consumer priorities are\nin use, messages are delivered round-robin if multiple active\nconsumers exist with the same high priority."}),"\n",(0,s.jsx)(i.h2,{id:"definitions",children:"Definition of Active Consumers"}),"\n",(0,s.jsxs)(i.p,{children:["The above paragraphs refer to consumers as being ",(0,s.jsx)("i",{children:"active"}),"\nor ",(0,s.jsx)("i",{children:"blocked"}),". At any moment, any given consumer is either\none or the other. An active consumer is one which could receive\na message without waiting. A consumer becomes blocked if it\ncannot receive messages - because its channel has reached the\nmaximum number of unacknowledged messages after issuing\n",(0,s.jsx)(i.code,{children:"basic.qos"}),", or simply because of network congestion."]}),"\n",(0,s.jsx)(i.p,{children:"Therefore for each queue, at least one of three things must be true:"}),"\n",(0,s.jsxs)(i.ol,{children:["\n",(0,s.jsx)(i.li,{children:"There are no active consumers"}),"\n",(0,s.jsx)(i.li,{children:"The queue is empty"}),"\n",(0,s.jsx)(i.li,{children:"The queue is busy delivering messages to consumers"}),"\n"]}),"\n",(0,s.jsxs)(i.p,{children:["Note that consumers can switch between active and blocked many\ntimes per second. We therefore don't expose whether a consumer\nis active or blocked through the management plugin or\n",(0,s.jsx)(i.a,{href:"./cli",children:"rabbitmqctl"}),"."]}),"\n",(0,s.jsx)(i.p,{children:"When consumer priorities are in use, you can expect your highest\npriority consumers to receive all the messages until they become\nblocked, at which point lower priority consumers will start to\nreceive some. It's important to understand that RabbitMQ will\nstill prioritise delivering messages - it will not wait for a\nhigh priority blocked consumer to become unblocked if there is\nan active lower priority consumer ready."}),"\n",(0,s.jsx)(i.h2,{id:"how-to-use",children:"Using Consumer Priorities"}),"\n",(0,s.jsxs)(i.p,{children:["Set the ",(0,s.jsx)(i.code,{children:"x-priority"})," argument in the\n",(0,s.jsx)(i.code,{children:"basic.consume"})," method to an integer value. Consumers\nwhich do not specify a value have priority 0. Larger numbers\nindicate higher priority, and both positive and negative numbers\ncan be used."]}),"\n",(0,s.jsx)(i.p,{children:"For example (in Java):"}
1),"\n",(0,s.jsx)(i.pre,{children:(0,s.jsx)(i.code,{className:"language-java",children:'Channel channel = ...;\nConsumer consumer = ...;\nMap<String, Object> args = new HashMap<String, Object>();\nargs.put("x-priority", 10);\nchannel.basicConsume("my-queue", false, args, consumer);\n'})}),"\n",(0,s.jsx)(i.p,{children:"This creates a new consumer with priority 10."})]})}function u(e={}){let{wrapper:i}={...(0,t.R)(),...e.components};return i?(0,s.jsx)(i,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},28453(e,i,n){n.d(i,{R:()=>o,x:()=>c});var r=n(96540);let s={},t=r.createContext(s);function o(e){let i=r.useContext(t);return r.useMemo(function(){return"function"==typeof e?e(i):{...i,...e}},[i,e])}function c(e){let i;return i=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:o(e.components),r.createElement(t.Provider,{value:i},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.