1"use strict";(self.webpackChunkrabbitmq_website=self.webpackChunkrabbitmq_website||[]).push([["21357"],{72047(e,n,o){o.r(n),o.d(n,{metadata:()=>i,default:()=>h,frontMatter:()=>s,contentTitle:()=>d,toc:()=>r,assets:()=>l});var i=JSON.parse('{"id":"connection-blocked","title":"Blocked Connection Notifications","description":"\x3c!--","source":"@site/versioned_docs/version-3.13/connection-blocked.md","sourceDirName":".","slug":"/connection-blocked","permalink":"/docs/3.13/connection-blocked","draft":false,"unlisted":false,"editUrl":"https://github.com/rabbitmq/rabbitmq-website/tree/main/versioned_docs/version-3.13/connection-blocked.md","tags":[],"version":"3.13","frontMatter":{"title":"Blocked Connection Notifications"},"sidebar":"docsSidebar","previous":{"title":"Direct reply-to","permalink":"/docs/3.13/direct-reply-to"},"next":{"title":"Exchange to Exchange Bindings","permalink":"/docs/3.13/e2e"}}'),t=o(74848),c=o(28453);let s={title:"Blocked Connection Notifications"},d="Blocked Connection Notifications",l={},r=[{value:"Overview",id:"overview",level:2},{value:"When Notifications are Sent",id:"notifications",level:2},{value:"Using Blocked Connection Notifications with Java Client",id:"java",level:2},{value:"Using Blocked Connection Notifications with .NET Client",id:"dotnet",level:2}];function a(e){let n={a:"a",code:"code",h1:"h1",h2:"h2",header:"header",p:"p",pre:"pre",strong:"strong",...(0,c.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.header,{children:(0,t.jsx)(n.h1,{id:"blocked-connection-notifications",children:"Blocked Connection Notifications"})}),"\n",(0,t.jsx)(n.h2,{id:"overview",children:"Overview"}),"\n",(0,t.jsxs)(n.p,{children:["It is sometimes desirable for clients to receive a notification\nwhen their connection gets ",(0,t.jsx)(n.a,{href:"./alarms",children:"blocked"}),"\ndue to the broker running low on resources (memory or disk)."]}),"\n",(0,t.jsxs)(n.p,{children:["A protocol extension to AMQP 0-9-1 has been introduced, enabling the broker to notify the client when\na connection is blocked or unblocked. The broker sends a ",(0,t.jsx)(n.code,{children:"connection.blocked"})," method when the\nconnection is blocked, and a ",(0,t.jsx)(n.code,{children:"connection.unblocked"})," method when it is unblocked."]}),"\n",(0,t.jsxs)(n.p,{children:["To receive these notifications, the client must present a\n",(0,t.jsx)(n.code,{children:"capabilities"})," table in its ",(0,t.jsx)(n.code,{children:"client-properties"})," in which there is a key\n",(0,t.jsx)(n.code,{children:"connection.blocked"})," and a boolean value ",(0,t.jsx)(n.code,{children:"true"}),"."]}),"\n",(0,t.jsxs)(n.p,{children:["See the ",(0,t.jsx)(n.a,{href:"./connections#capabilities",children:"capabilities"})," section for further\ndetails on this. Supported clients advertise this capability by default and provide mechanisms to register handlers\nfor the ",(0,t.jsx)(n.code,{children:"connection.blocked"})," and ",(0,t.jsx)(n.code,{children:"connection.unblocked"})," methods."]}),"\n",(0,t.jsx)(n.h2,{id:"notifications",children:"When Notifications are Sent"}),"\n",(0,t.jsxs)(n.p,{children:["A ",(0,t.jsx)(n.code,{children:"connection.blocked"})," notification is sent to\npublishing connections the first time RabbitMQ is low on a\nresource. For example, when a RabbitMQ node detects that it\nis low on RAM, it sends\n",(0,t.jsx)(n.code,{children:"connection.blocked"})," to all connected publishing\nclients supporting this feature. If before the connections\nare unblocked the node also starts running low on disk space,\nanother ",(0,t.jsx)(n.code,{children:"connection.blocked"})," will not be sent."]}),"\n",(0,t.jsxs)(n.p,{children:["A ",(0,t.jsx)(n.code,{children:"connection.unblocked"})," is sent when ",(0,t.jsx)(n.strong,{children:"all"}),"\nresource alarms have cleared and the connection is fully\nunblocked."]}),"\n",(0,t.jsx)(n.h2,{id:"java",children:"Using Blocked Connection Notifications with Java Client"}),"\n",(0,t.jsxs)(n.p,{children:["With the ",(0,t.jsx)(n.a,{href:"/client-libraries/java-api-guide",children:"official Java client"}),", blocked connection\nnotifications are handled by ",(0,t.jsx)(n.code,{children:"BlockedListener"}),"\ninterface implementations. They can be registered on a\n",(0,t.jsx)(n.code,{children:"Connection"})," using the\n",(0,t.jsx)(n.code,{children:"Connection.addBlockedListener"})," method:"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-java",children:"ConnectionFactory factory = new ConnectionFactory();\nConnection connection = factory.newConnection();\nconnection.addBlockedListener(new BlockedListener() {\n public void handleBlocked(String reason) throws IOException {\n // Connection is now blocked\n }\n\n public void handleUnblocked() throws IOException {\n // Connection is now unblocked\n }\n});\n"})}),"\n",(0,t.jsx)(n.h2,{id:"dotnet",children:"Using Blocked Connection Notifications with .NET Client"}),"\n",(0,t.jsxs)(n.p,{children:["With the ",(0,t.jsx)(n.a,{href:"/client-libraries/dotnet-api-guide",children:"official .NET client"}),", blocked connection\nnotifications can be received by registering for the\n",(0,t.jsx)(n.code,{children:"ConnectionBlocked"})," and ",(0,t.jsx)(n.code,{children:"ConnectionUnblocked"})," events in ",(0,t.jsx)(n.code,{children:"IConnection"}),":"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-csharp",children:" public void HandleBlocked(object sender, ConnectionBlockedEventArgs args)\n {\n // Connection is now blocked\n }\n\n public void HandleUnblocked(object sender, EventArgs args)\n {\n // Connection is now unblocked\n }\n\nConn.ConnectionBlocked += HandleBlocked;\nConn.ConnectionUnblocked += HandleUnblocked;\n"})})]})}function h(e={}){let{wrapper:n}={...(0,c.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(a,{...e})}):a(e)}},28453(e,n,o){o.d(n,{R:()=>s,x:()=>d});var i=o(96540);let t={},c=i.createContext(t);function s(e){let n=i.useContext(c);return i.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function d(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:s(e.components),i.createElement(c.Provider,{value:n},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.